'Affiliated content', 'description' => 'Administer content by domain.', 'page callback' => 'domain_content_list', 'access callback' => 'domain_content_menu_check', 'file' => 'domain_content.admin.inc', ); $items['admin/domain/content/all'] = array( 'title' => 'Content assigned to all affiliates', 'page callback' => 'domain_content_view', 'page arguments' => array(NULL, TRUE), 'access callback' => 'domain_content_menu_check', 'file' => 'domain_content.admin.inc', 'description' => 'View content assigned to all affiliate sites.', 'weight' => -10 ); // Generate the list of active domains as menu items. // We must wrap this check, otherwise the uninstall fails. // See http://drupal.org/node/1003430. if (module_exists('domain')) { $domains = domain_domains(); if (count($domains) <= variable_get('domain_list_size', DOMAIN_LIST_SIZE)) { foreach ($domains as $domain) { $items['admin/domain/content/' . $domain['domain_id']] = array( 'title' => check_plain($domain['sitename']) .' content', 'page callback' => 'domain_content_view', 'page arguments' => array($domain['domain_id'], FALSE), 'access callback' => 'domain_content_check', 'access arguments' => array($domain['domain_id']), 'file' => 'domain_content.admin.inc', 'description' => 'View content assigned to '. filter_xss_admin($domain['subdomain']), 'weight' => $domain['domain_id'] ); } } else { $items['admin/domain/content/list'] = array( 'title' => 'Affiliate site list', 'page callback' => 'domain_content_list', 'access callback' => 'domain_content_menu_check', 'file' => 'domain_content.admin.inc', 'description' => 'View your list of affiliates', 'weight' => -10 ); $items['admin/domain/content/%'] = array( 'title' => 'Affiliate site list', 'page callback' => 'domain_content_view', 'page arguments' => array(3, TRUE), 'access callback' => 'domain_content_check', 'access arguments' => array(3), 'file' => 'domain_content.admin.inc', 'description' => 'Content list for a domain', 'weight' => -10 ); } } return $items; } /** * Implements hook_permission(). */ function domain_content_permission() { $permissions = array( 'review content for all domains' => array( 'title' => t('Review content for all domains'), 'restrict access' => TRUE, ), ); return $permissions; } /** * Access control for menu items. There may be another way to do this in Drupal 6. * * @param $check * The access check value passed from hook_menu(). */ function domain_content_menu_check() { if (user_access('administer nodes')) { return TRUE; } if (user_access('edit domain nodes') || user_access('review content for all domains')) { return TRUE; } return FALSE; } /** * Access checking routine for menu and node editing checks. * * @param $domain_id * An id representing the currently active domain record. */ function domain_content_check($domain_id) { global $user; // If the user can administer nodes, just return TRUE. if (user_access('administer nodes') || user_access('review content for all domains')) { return TRUE; } $rule = user_access('edit domain nodes'); // Otherwise, the user must be able to edit domain nodes. if (!$rule) { return FALSE; } $domains = domain_get_user_domains($user); // Can this user see the active site? if ($domain_id == $domains[$domain_id]) { return TRUE; } return FALSE; } /** * Implement hook_node_operations() */ function domain_content_node_operations() { // Only privileged users can perform this operation. // Do not show this on the default node editing form. if (user_access('set domain access')) { $operations = array( 'domain' => array( 'label' => t('Change affiliate publishing options'), 'callback' => 'domain_content_node_operations_process', 'configurable' => TRUE, ), ); return $operations; } } /** * Callback for domain_content_node_operations(). * * This callback is required, but we actually do our action inside * of domain_content_process_nodes(). */ function domain_content_node_operations_process($nodes) { } /** * The multiple delete form issues a redirect in its submit function. * So we must supply the proper path as a form element. * * @link http://drupal.org/node/336218 */ function domain_content_form_node_multiple_delete_confirm_alter(&$form, &$form_state) { $form['#redirect'] = $_GET['q']; } /** * Allow domain assignment to be made from the default content form. */ function domain_content_form_node_admin_content_alter(&$form, &$form_state) { // Privileged users can make global changes to Domain Access permissions. if (!user_access('set domain access')) { return; } // Add our form elements. domain_content_add_form_widget($form); $form['admin']['#weight'] = 4; $form['domain']['#weight'] = 2; $form['admin']['options']['submit']['#submit'][] = 'domain_content_process_nodes'; } /** * Abstraction function for selecting domains for batch operations. */ function domain_content_add_form_widget(&$form) { global $_domain; // We have different settings for the two form contexts. // A blank form comes from core. $prefix = '
'. t('If you select Change affiliate publishing options, you should confirm the Affiliate publishing options settings below.') .'
'; $collapsed = TRUE; if (empty($form)) { $prefix = ''; $collapsed = FALSE; } $options = array(); $format = domain_select_format(); foreach (domain_domains() as $data) { // The domain must be valid. if ($data['valid'] || user_access('access inactive domains')) { // Filter checkboxes but not select lists. $options[$data['domain_id']] = empty($format) ? check_plain($data['sitename']) : $data['sitename']; } } $form['domain'] = array( '#type' => 'fieldset', '#title' => t('Affiliate publishing options'), '#collapsible' => TRUE, '#collapsed' => $collapsed, '#prefix' => $prefix, ); $form['domain']['behavior'] = array( '#type' => 'radios', '#title' => t('Update behavior'), '#options' => array(0 => t('Replace old values with new settings'), 1 => t('Add new settings to existing values'), 2 => t('Remove selected domains from existing values')), '#description' => t('Defines how new grants will be applied to the updated nodes.'), '#default_value' => 0, ); $form['domain']['domain_site'] = array( '#type' => 'checkbox', '#prefix' => t('

Publishing options:'), '#suffix' => '

', '#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' => empty($format) ? 'checkboxes' : 'select', '#title' => t('Publish to'), '#options' => $options, '#required' => FALSE, '#description' => t('Select which affiliates can access this content.'), '#default_value' => array($_domain['domain_id']), ); if ($format) { $form['domain']['domains']['#multiple'] = TRUE; $form['domain']['domains']['#size'] = count($options) > 10 ? 10 : count($options); } } /** * Process the form submission. * * This callback works for the normal operations callback. */ function domain_content_process_nodes($form, &$form_state) { if ($form_state['values']['operation'] != 'domain') { return; } $options = array(); $options['domain_site'] = FALSE; if ($form_state['values']['domain_site']) { $options['domain_site'] = TRUE; } $options['domain_id'] = array_filter($form_state['values']['domains']); $nids = array_filter($form_state['values']['nodes']); $options['behavior'] = $form_state['values']['behavior']; domain_content_update_nodes($nids, $options); } /** * Abstraction function that lets us update access rules. */ function domain_content_update_nodes($nids, $options) { // If our operation is run, then we have to manually change the // {node_access} table. The rest of the process will clear the cache, // so this should be a safe operation. $domain_site = $options['domain_site']; $domains = $options['domain_id']; $behavior = $options['behavior']; foreach ($nids as $nid) { // Other modules need to respond, we have to load the full node. $node = node_load($nid); // Make sure the node is valid. if ($node->nid > 0) { // If modifying values, do so here. if (!empty($behavior)) { $current = domain_get_node_domains($node->nid); // Add values to the current set. if ($behavior == 1) { if (!empty($current['domain_site'])) { $domain_site = TRUE; } $domains += $current['domain_id']; } // Remove values from the current set. else { foreach ($domains as $domain_id) { if (isset($current['domain_id'][$domain_id])) { unset($current['domain_id'][$domain_id]); } } $domains = $current['domain_id']; // If all affiliates is selected, remove it. if ($domain_site) { $domain_site = FALSE; } } } // Use our new options, as set above. $node->domain_site = $domain_site; $node->domains = $domains; // Delete our grants and rebuild. node_access_acquire_grants($node); } } // Clear the cache. cache_clear_all(); }