function domain_content_form in Domain Access 5
Same name and namespace in other branches
- 6.2 domain_content/domain_content.admin.inc \domain_content_form()
- 7.3 domain_content/domain_content.admin.inc \domain_content_form()
- 7.2 domain_content/domain_content.admin.inc \domain_content_form()
Rewrites node_admin_nodes() to use db_rewrite_sql().
Return value
A form array according to the FormsAPI.
2 string references to 'domain_content_form'
- domain_content_admin in domain_content/
domain_content.module - Content admin page callback.
- domain_source_form_alter in domain_source/
domain_source.module - Implement hook_form_alter()
File
- domain_content/
domain_content.module, line 196 - Editorial overview module.
Code
function domain_content_form() {
global $user, $_domain;
$filter = node_build_filter_query();
// Bypass the superuser permissions by forcing an AND on {node_access}.
$filter['join'] .= " INNER JOIN {node_access} nac ON nac.nid = n.nid ";
$arg = arg(3);
if ($arg != 'all') {
// In this case, we must check the domain_id grant.
// We use intval() here for security, since we are not filtering the query parameter otherwise.
if (empty($filter['where'])) {
$filter['where'] = " WHERE nac.realm = 'domain_id' AND nac.gid = " . intval($_domain['domain_id']) . " ";
}
else {
$filter['where'] .= " AND nac.realm = 'domain_id' AND nac.gid = " . intval($_domain['domain_id']) . " ";
}
}
else {
// Or check the domain_site grant.
if (empty($filter['where'])) {
$filter['where'] = " WHERE nac.realm = 'domain_site' AND nac.gid = 0 ";
}
else {
$filter['where'] .= " AND nac.realm = 'domain_site' AND nac.gid = 0 ";
}
}
$result = pager_query(db_rewrite_sql('SELECT n.*, u.name, u.uid FROM {node} n ' . $filter['join'] . ' INNER JOIN {users} u ON n.uid = u.uid ' . $filter['where'] . ' ORDER BY n.changed DESC'), 50, 0, NULL, $filter['args']);
$destination = drupal_get_destination();
$check = array();
// Some existing permissions alter the node access rules.
$message = FALSE;
$set = 0;
$all = FALSE;
if (user_access('administer nodes') || user_access('set domain access')) {
$all = TRUE;
$message = TRUE;
}
// Loop through the nodes to build the form
while ($node = db_fetch_object($result)) {
// Can the user edit all nodes of this type?
if (user_access('edit ' . $node->type . ' nodes')) {
$message = TRUE;
}
// Flag a message if user has extra permissions
if ($message) {
$check[$node->nid] = TRUE;
}
$form['title'][$node->nid] = array(
'#value' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', node_mark($node->nid, $node->changed)),
);
$form['name'][$node->nid] = array(
'#value' => check_plain(node_get_types('name', $node)),
);
$form['username'][$node->nid] = array(
'#value' => theme('username', $node),
);
$form['status'][$node->nid] = array(
'#value' => $node->status ? t('published') : t('not published'),
);
// This routine controls if the editor can see the 'edit' link.
// Load the domain_access rules directly from domain_nodeapi().
domain_nodeapi($node, 'load');
$node_domains = array();
if (!empty($node->domains)) {
foreach ($node->domains as $domain) {
// Can the user edit this node. We use += here since this is an array loop.
$check[$node->nid] += domain_content_check($domain, $all);
// The root domain is stored as -1, but cast as zero in the global variable.
$key = $domain == -1 ? 0 : $domain;
// Convert the domain ids to data so we can print them.
$node_domains[] = domain_lookup($key);
}
}
// If we have multiple domains, print them.
$items = array();
if ($node->domain_site) {
$items[-1] = t('All affiliates');
}
if (!empty($node_domains)) {
foreach ($node_domains as $item) {
$items[$item['domain_id']] = check_plain($item['sitename']);
}
}
if (module_exists('domain_source')) {
$source = NULL;
$source = db_fetch_object(db_query("SELECT domain_id FROM {domain_source} WHERE nid = %d", $node->nid));
if (!empty($source) && isset($items[$source->domain_id])) {
$items[$source->domain_id] .= '*';
}
}
$form['domains'][$node->nid] = array(
'#value' => theme('item_list', $items),
);
if (!empty($check[$node->nid])) {
$form['operations'][$node->nid] = array(
'#value' => l(t('edit'), 'node/' . $node->nid . '/edit', array(), $destination),
);
$nodes[$node->nid] = '';
}
}
// Privileged users can make global changes to Domain Access permissions.
if (user_access('set domain access')) {
$options = array();
foreach (domain_domains() as $data) {
// Cannot pass zero in checkboxes.
$data['domain_id'] == 0 ? $key = -1 : ($key = $data['domain_id']);
// The domain must be valid.
if ($data['valid'] || user_access('administer domains')) {
$options[$key] = check_plain($data['sitename']);
}
}
// If the user is a site admin, show the form, otherwise pass it silently.
if (user_access('set domain access')) {
$form['domain'] = array(
'#type' => 'fieldset',
'#title' => t('Affiliate publishing options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#prefix' => '<div class="description">' . t('If you select <em>Change affiliate publishing options</em> above, you should confirm the <em>Affiliate publishing options</em> settings below.') . '</div>',
);
$form['domain']['domain_site'] = array(
'#type' => 'checkbox',
'#prefix' => t('<p><b>Publishing options:</b>'),
'#suffix' => '</p>',
'#title' => t('Send to all affiliates'),
'#required' => FALSE,
'#description' => t('Select if this content can be shown to all affiliates. This setting will override the options below.'),
'#default_value' => variable_get('domain_behavior', DOMAIN_INSTALL_RULE),
);
$form['domain']['domains'] = array(
'#type' => 'checkboxes',
'#title' => t('Publish to'),
'#options' => $options,
'#required' => FALSE,
'#description' => t('Select which affiliates can access this content.'),
'#default_value' => array(
$_domain['domain_id'] == 0 ? -1 : $_domain['domain_id'],
),
);
}
}
// Users must have passed at least one access check to have batch options.
if (!empty($check)) {
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Update options'),
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
'#weight' => -1,
);
$options = array();
foreach (module_invoke_all('node_operations') as $operation => $array) {
$options[$operation] = $array['label'];
}
$form['options']['operation'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => 'approve',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
);
$form['nodes'] = array(
'#type' => 'checkboxes',
'#options' => $nodes,
);
}
$form['pager'] = array(
'#value' => theme('pager', NULL, 50, 0),
);
$form['#theme'] = 'domain_content_admin_nodes';
$form['#validate']['node_admin_nodes_validate'] = array();
$form['#submit']['node_admin_nodes_submit'] = array();
$form['#submit']['domain_content_update_nodes'] = array();
return $form;
}