';
$items['domain'] = array('title' => t('Domain settings'),
'value' => $output,
);
return array(t('Domain status') => $items);
}
break;
}
}
/**
* Implements hook_cron()
*
* This function invokes hook_domaincron() and allows
* Domain Access modules to run functions for all active affiliates.
*
* @ingroup drupal
*/
function domain_cron() {
global $_domain;
// Check to see if this function is needed at all.
$modules = module_implements('domaincron');
if (!empty($modules)) {
// Store the current $_domain global.
$_temp = $_domain;
// Get the domain list.
$domains = domain_domains();
// Run the hook for each active domain.
foreach ($domains as $domain) {
// Set the global to the current $domain.
$_domain = $domain;
foreach ($modules as $module) {
module_invoke($module, 'domaincron', $domain);
}
}
// Set the $_domain global back.
$_domain = $_temp;
}
}
/**
* Router function to call various administration tasks
*
* @param $action
* The function to be performed.
* @param $id
* The domain_id of the record to be acted upon.
*
* @ingroup domain
*/
function domain_admin($action, $id = NULL) {
include_once('domain_admin.inc');
$func = 'domain_'. $action;
return $func($id);
}
/**
* Runs a lookup against the {domain} table. One of the two values must be present
*
* This function also calls hook_domainload(), which lets module developers overwrite
* or add to the $domain array.
*
* @param $domain_id
* The domain_id taken from {domain}. Optional.
* @param $subdomain
* The string representation of a {domain} entry. Optional.
* @param $clear
* A boolean flag to clear the static variable if necessary.
* @return
* An array containing the requested row from the {domain} table, plus the
* elements added by hook_domainload(). Returns -1 on failure.
*
* @ingroup domain
*/
function domain_lookup($domain_id = NULL, $subdomain = NULL, $clear = FALSE) {
static $domains;
// If both are NULL, no lookup can be run.
if (is_null($domain_id) && is_null($subdomain)) {
return -1;
}
// Create a unique key so we can static cache all requests.
else {
$key = $domain_id . $subdomain;
}
if ($clear || !isset($domains[$key])) {
if ($domain_id === 0) {
$domain = domain_default();
}
else if ($domain_id) {
$domain = db_fetch_array(db_query("SELECT domain_id, subdomain, sitename, scheme, valid FROM {domain} WHERE domain_id = %d", $domain_id));
}
else if ($subdomain) {
$domain = db_fetch_array(db_query("SELECT domain_id, subdomain, sitename, scheme, valid FROM {domain} WHERE subdomain = '%s'", $subdomain));
}
if (!is_null($domain['domain_id'])) {
// Let submodules overwrite the defaults, if they wish.
$extra = module_invoke_all('domainload', $domain);
$domain = array_merge($domain, $extra);
$domains[$key] = $domain;
}
else {
$domains[$key] = -1;
}
}
return $domains[$key];
}
/**
* Assigns the default settings to domain 0, the root domain.
*
* This value is used throughout the modules, so needed abstraction.
*
* @ingroup domain
*/
function domain_default() {
static $default;
if (empty($default)) {
$default['domain_id'] = 0;
$default['sitename'] = variable_get('domain_sitename', variable_get('sitename', 'Drupal'));
$default['subdomain'] = variable_get('domain_root', '');
$default['scheme'] = variable_get('domain_scheme', 'http');
// Set the valid flag.
$default['valid'] = TRUE;
// Let submodules overwrite the defaults, if they wish.
$extra = module_invoke_all('domainload', $default);
$default = array_merge($default, $extra);
}
return $default;
}
/**
* Return all active domains (including the default) as an array.
*
* @ingroup domain
*/
function domain_domains() {
static $domains;
if (empty($domains)) {
$domains = array();
$domains[] = domain_default();
// Query the db for active domain records.
$result = db_query("SELECT domain_id FROM {domain}");
while ($data = db_fetch_array($result)) {
$domain = domain_lookup($data['domain_id']);
$domains[] = $domain;
}
}
$sort = variable_get('domain_sort', 'id');
uasort($domains, '_domain_'. $sort .'_sort');
return $domains;
}
/**
* Helper sort function
*
* @ingroup domain
*/
function _domain_id_sort($a, $b) {
return ($a['domain_id'] < $b['domain_id']) ? -1 : 1;
}
/**
* Helper sort function
*
* @ingroup domain
*/
function _domain_name_sort($a, $b) {
return strcmp($a['sitename'], $b['sitename']);
}
/**
* Helper sort function
*
* @ingroup domain
*/
function _domain_url_sort($a, $b) {
return strcmp($a['subdomain'], $b['subdomain']);
}
/**
* Helper sort function
*
* @ingroup domain
*/
function _domain_rid_sort($a, $b) {
return ($a['domain_id'] > $b['domain_id']) ? -1 : 1;
}
/**
* Helper sort function
*
* @ingroup domain
*/
function _domain_rname_sort($a, $b) {
return strcmp($b['sitename'], $a['sitename']);
}
/**
* Helper sort function
*
* @ingroup domain
*/
function _domain_rurl_sort($a, $b) {
return strcmp($a['subdomain'], $b['subdomain']);
}
/**
* Implements hook_domainload()
*
* Adds the home page 'path' and 'site_grant' boolean.
*
* @ingroup domain
*/
function domain_domainload(&$domain) {
// Get the path to the home page for this domain.
$domain['path'] = domain_get_path($domain);
// Grant access to all affiliates.
$domain['site_grant'] = DOMAIN_SITE_GRANT;
return $domain;
}
/**
* Determine an absolute path for a domain
*
* @param $domain
* The currently active $domain array, provided by domain_lookup().
*
* @ingroup domain
*/
function domain_get_path($domain) {
global $base_url;
$_url = parse_url($base_url);
// We need a trailing slash at the end of the path
if (substr($_url['path'], -1) != '/') {
$_url['path'] .= '/';
}
$path = $domain['scheme'] .'://'. $domain['subdomain'] . $_url['path'];
return $path;
}
/**
* Determine an absolute path to the current page
*/
function domain_get_uri($domain) {
global $base_url;
$_url = parse_url($base_url);
$path = $domain['scheme'] .'://'. $domain['subdomain'] . request_uri();
return $path;
}
/**
* Determine if we must switch the active domain.
*
* This function will execute a drupal_goto() to pop users to the correct
* domain.
*
* @param $domain
* The currently active $domain array, provided by domain_lookup().
*
* @ingroup domain
*/
function domain_goto($domain) {
global $_domain;
// We must be on the proper domain, see http://drupal.org/node/186153.
if ($domain != -1 && $_domain['domain_id'] != $domain['domain_id']) {
$path = domain_get_uri($domain);
drupal_goto($path);
}
}
/**
* Implements hook_nodeapi().
*
* This function is used to provide debugging information and to prep values from
* the {node_access} table when editing nodes. Since not all users can see the
* domain access editing checkboxes, we pass some node_access values as hidden elements.
*
* @ingroup node
*/
function domain_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'prepare':
case 'load':
// Append the domain grants to the node for editing.
$node->domains = array();
$node->editors = array();
$node->domain_site = FALSE;
$node->url = 'test';
$result = db_query("SELECT gid, realm, grant_view, grant_update, grant_delete FROM {node_access} WHERE nid = %d AND (realm = '%s' OR realm = '%s' OR realm = '%s')", $node->nid, 'domain_id', 'domain_site', 'domain_editor');
while ($data = db_fetch_object($result)) {
// Transform the 0 to -1, since {node_access} is unsigned.
($data->gid == 0) ? $gid = -1 : $gid = $data->gid;
if ($data->realm == 'domain_id') {
$node->domains[] = $gid;
if ($gid > 0) {
$domain = domain_lookup($gid);
$node->subdomains[] = $domain['sitename'];
}
else {
$node->subdomains[] = variable_get('domain_sitename', variable_get('sitename', 'Drupal'));
}
}
else if ($data->realm == 'domain_site') {
$node->domain_site = TRUE;
$node->subdomains[] = t('All affiliates');
}
else if ($data->realm == 'domain_editor') {
$node->domain_editor = TRUE;
if ($gid > 0) {
$domain = domain_lookup($gid);
$node->editors[] = $domain['sitename'];
}
else {
$node->editors[] = variable_get('domain_sitename', variable_get('sitename', 'Drupal'));
}
}
}
break;
case 'view':
// Search module casts both $a3 and $a4 as FALSE, not NULL.
// We check that to hide this data from search and other nodeapi
// calls that are neither a teaser nor a page view.
if ($a3 !== FALSE || $a4 !== FALSE) {
$output = '';
$debug = variable_get('domain_debug', 0);
if ($debug && user_access('set domain access')) {
if (!empty($node->subdomains)) {
$output .= '
Subdomains
';
foreach($node->subdomains as $name) {
$output .= '
';
foreach($node->editors as $name) {
$output .= '
'. $name .'
';
}
$output .= '
';
$node->content['editors'] = array('#value' => $output, '#weight' => 21);
}
if (empty($output)) {
$node->content['domain'] = array('#value' => t('This node is not assigned to a domain.'), '#weight' => 22);
}
}
}
break;
}
}
/**
* Implements hook_node_grants.
*
* Informs the node access system what permissions the user has. By design
* all users are in the realm defined by the currently active domain_id.
*
* @ingroup node
*/
function domain_node_grants($account, $op) {
global $_domain;
// Do we need to use complex rules?
$rules = variable_get('domain_access_rules', FALSE);
// By design, all users can see content sent to all affiliates,
// but the $_domain['site_grant'] can be set to FALSE.
if ($op == 'view') {
if ($_domain['site_grant']) {
$grants['domain_site'][] = 0;
if ($rules) {
$grants['domain_site']['group'] = 'domain';
}
}
// Grant based on active subdomain.
$grants['domain_id'][] = $_domain['domain_id'];
if ($rules) {
$grants['domain_id']['group'] = 'domain';
}
// In special cases, we grant the ability to view all nodes. That is,
// we simply get out of the way of other node_access rules.
// We do this with the universal 'domain_all' grant.
if ($op == 'view' && domain_grant_all()) {
// If no other node access modules are present, return our grant.
// Otherwise, we just step out of the way.
if ($rules) {
return array();
}
else {
return array('domain_all' => array(0));
}
}
}
else {
// Special permissions for editors
$editors = variable_get('domain_editors', DOMAIN_EDITOR_RULE);
if ($editors && user_access('edit domain nodes', $account)) {
if (!empty($account->domain_user)) {
foreach ($account->domain_user as $id) {
if (abs($id) > 0) {
if ($id > 0) {
$grants['domain_editor'][] = $id;
}
else {
$grants['domain_editor'][] = 0;
}
// Advanced rules let us access check unpublished nodes for editing.
if ($rules) {
$grants['domain_editor']['check'] = TRUE;
}
}
}
}
}
}
// Let Domain Access module extensions act to override the defaults.
static $_modules;
if (!isset($_modules)) {
$_modules = module_implements('domaingrants');
}
if (!empty($_modules)) {
foreach ($_modules as $module) {
// Cannot use module_invoke_all() since these are passed by reference.
$function = $module . '_domaingrants';
$function($grants, $account, $op);
}
}
return $grants;
}
/**
* Implements hook_node_access_records()
*
* Set permissions for a node to be written to the database. By design
* if no options are selected, the node is assigned to the main site.
*
* @ingroup node
*/
function domain_node_access_records($node) {
if (domain_disabling()) {
return;
}
// How is core content handled for this site? We need to run this
// check when the module is first enabled.
$behavior = variable_get('domain_behavior', DOMAIN_INSTALL_RULE);
if (domain_enabling() && $behavior == 1) {
$node->domain_site = TRUE;
}
// Define the $grants array.
$grants = array();
// If the form is hidden, we are passed the 'domains_raw' variable.
// We need to append unique values from this variable to the existing
// stored values. See the logic for 'view domain publshing' in domain_form_alter().
if (is_array($node->domains_raw)) {
if (!isset($node->domains)) {
$node->domains = array();
}
foreach ($node->domains_raw as $value) {
// Only add this if it is not present already.
if (!in_array($value, $node->domains)) {
$node->domains[$value] = $value;
}
}
}
// If set, grant access to the core site, otherwise
// The grant must be explicitly given to a domain.
if ($node->domain_site) {
$grants[] = array(
'realm' => 'domain_site',
'gid' => 0,
'grant_view' => TRUE,
'grant_update' => FALSE,
'grant_delete' => FALSE,
'priority' => 0, // If this value is > 0, then other grants will not be recorded
);
}
// Special permissions for editors, if activated.
$editors = variable_get('domain_editors', DOMAIN_EDITOR_RULE);
if (!empty($node->domains)) {
foreach($node->domains as $key => $value) {
// We can't use a 0 value in an $options list, so convert -1 to 0.
if (abs($value) > 0) {
($key == -1) ? $key = 0 : $key = $key;
$grants[] = array(
'realm' => 'domain_id',
'gid' => $key,
'grant_view' => TRUE,
'grant_update' => FALSE,
'grant_delete' => FALSE,
'priority' => 0,
);
if ($editors) {
$grants[] = array(
'realm' => 'domain_editor',
'gid' => $key,
'grant_view' => FALSE,
'grant_update' => TRUE,
'grant_delete' => TRUE,
'priority' => 0,
);
}
}
}
}
// At least one option must be present, and it is the default site
// this prevents null values in the form.
// If we are enabling the module for the first time, we set the
// default domain of all existing nodes to the root domain.
if (empty($grants) || domain_enabling()) {
$grants[] = array(
'realm' => 'domain_id',
'gid' => 0,
'grant_view' => TRUE,
'grant_update' => FALSE,
'grant_delete' => FALSE,
'priority' => 0,
);
if ($editors) {
$grants[] = array(
'realm' => 'domain_editor',
'gid' => 0,
'grant_view' => FALSE,
'grant_update' => TRUE,
'grant_delete' => TRUE,
'priority' => 0,
);
}
}
// Let Domain Access module extensions act to override the defaults.
static $_modules;
if (!isset($_modules)) {
$_modules = module_implements('domainrecords');
}
if (!empty($_modules)) {
foreach ($_modules as $module) {
// Cannot use module_invoke_all() since these are passed by reference.
$function = $module . '_domainrecords';
$function($grants, $node);
}
}
return $grants;
}
/**
* Upon enabling this module, store the default view grant
* in the {node_access} table.
* @see domain_grant_all()
*
* @ingroup domain
*/
function domain_enable() {
domain_enabling(TRUE);
$modules = module_implements('node_grants');
// If this is the only node access module, delete all records from {node_access}
if (count($modules) == 1 && $modules[0] == 'domain') {
db_query("DELETE FROM {node_access}");
}
// Rebuild the node access table with our rules.
node_access_rebuild();
// Clean up the {node_access} table and add our default grant.
$check = db_result(db_query("SELECT COUNT(nid) FROM {node_access} WHERE realm = 'domain_all' AND gid = 0"));
db_query("DELETE FROM {node_access} WHERE nid = 0 AND realm = 'all'");
if (!$check) {
db_query("INSERT INTO {node_access} VALUES (0, 0, 'domain_all', 1, 0, 0)");
}
}
/**
* Writes the default grants when the module is first enabled.
*
* @ingroup node
*/
function domain_enabling($set = NULL) {
static $enabling = FALSE;
if ($set !== NULL) {
$enabling = $set;
}
return $enabling;
}
/**
* Implements hook_disable()
*
* @ingroup node
*/
function domain_disable() {
domain_disabling(TRUE);
// Delete our all access row from {node_access}.
db_query("DELETE FROM {node_access} WHERE realm = 'domain_all' AND gid = 0");
// This lets us control how the module updates the {node_access} table.
variable_del('domain_behavior');
variable_del('domain_editors');
$modules = module_implements('node_grants');
// If this is the only node access module, delete all records from {node_access}
if (count($modules) == 1 && $modules[0] == 'domain') {
db_query("DELETE FROM {node_access}");
db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)");
}
else {
node_access_rebuild();
}
}
/**
* Simple function to make sure we don't respond with grants when disabling ourselves.
*
* @ingroup node
*/
function domain_disabling($set = NULL) {
static $disabling = FALSE;
if ($set !== NULL) {
$disabling = $set;
}
return $disabling;
}
/**
* Implements hook_form_alter()
*
* This function is crucial, as it appends our node access elements to the node edit form.
* For users without the "set domain access" permission, this happens silently.
*
* @ingroup node
*/
function domain_form_alter($form_id, &$form) {
// If SEO is turned on, then form actions need to be absolute paths
// to the currently active domain. See http://drupal.org/node/196217.
$seo = variable_get('domain_seo', 0);
if ($seo) {
global $_domain;
$action = parse_url($form['#action']);
if ($action['query']) {
$action['path'] .= '?';
}
$form['#action'] = $_domain['scheme'] .'://'. $_domain['subdomain'] . $action['path'] . $action['query'];
}
// Apply to all node editing forms, but make sure we are not on the CCK field configuration form.
if ($form['#id'] == 'node-form' && !$form['#node']->cck_dummy_node_form) {
global $_domain, $user;
// By default, the requesting domain is assigned.
$default = array($_domain['domain_id']);
// How is core content handled for this site?
$behavior = variable_get('domain_behavior', DOMAIN_INSTALL_RULE);
if ($behavior == 1 || $_domain['domain_id'] == 0) {
$default[] = -1;
}
// Some options will be passed as hidden values, we need to run some checks on those.
if ($form['#node']->nid) {
$raw = $form['#node']->domains;
}
else {
$raw = $default;
}
$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] = $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('Domain access options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
$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' => ($form['#node']->nid) ? $form['#node']->domain_site : variable_get('domain_node_'. $form['#node']->type, $behavior),
);
$form['domain']['domains'] = array(
'#type' => 'checkboxes',
'#title' => t('Publish to'),
'#options' => $options,
'#required' => TRUE,
'#description' => t('Select which affiliates can access this content.'),
'#default_value' => ($form['#node']->nid) ? $form['#node']->domains : $default,
);
}
// If the user has limited permissions, show that form or obey the settings.
else {
if (user_access('view domain publishing')) {
$action = variable_get('domain_options', 0);
$user_domains = array();
foreach ($user->domain_user as $key => $value) {
if (abs($value) > 0) {
$user_domains[] = $value;
}
}
$first_domain = current($user_domains);
$user_options = array();
foreach ($options as $key => $value) {
if (in_array($key, $user_domains)) {
$user_options[$key] = $value;
}
}
// Raw data checks for published nodes.
foreach ($raw as $key => $value) {
if (in_array($value, $user_domains)) {
$default_options[] = $value;
}
// This is only used in case 3, below. It means that some options
// are present that the user cannot access but that must be preserved.
else {
$raw_options[] = $value;
}
}
// Act on the behavior desired by the site admin.
switch ($action) {
// 1 == go to the default domain.
case 1:
$root = domain_default();
if ($root['domain_id'] != $_domain['domain_id']) {
domain_goto($root);
}
break;
// 2 == go to the user's assigned domain.
case 2:
$domain = domain_lookup($first_domain);
if ($domain['domain_id'] != $_domain['domain_id']) {
domain_goto($domain);
}
break;
// 3 == show checkboxes of available domains.
case 3:
$form['domain'] = array(
'#type' => 'fieldset',
'#title' => t('Affiliate publishing options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
// We must preserve publishing options that the user cannot access, but only for
// existing nodes.
if ($form['#node']->nid) {
$raw = $raw_options;
}
else {
$raw = array();
}
// If the raw options are being passed, then no input is technically required.
(empty($raw)) ? $required = TRUE : $required = FALSE;
$form['domain']['domains'] = array(
'#type' => 'checkboxes',
'#title' => t('Publish to'),
'#options' => $user_options,
'#required' => $required,
'#description' => t('Select which affiliates can access this content.'),
'#default_value' => ($form['#node']->nid) ? $form['#node']->domains : $default_options,
);
// Show the options that cannot be changed.
$list = array();
if ($form['#node']->domain_site) {
$list[]['data'] = t('All affiliates');
}
if (!empty($raw)) {
foreach ($raw as $did) {
($did == -1) ? $id = 0 : $id = $did;
$raw_domains = domain_lookup($id);
$list[]['data'] = $raw_domains['sitename'];
}
}
if (!empty($list)) {
$form['domain']['domains_notes'] = array(
'#value' => ''. theme('item_list', $list) .'
'. t('This content has also been published to these affiliates.') .'
',
);
}
break;
}
}
// These form elements are hidden from non-privileged users, by design.
$form['domain_site'] = array(
'#type' => 'value',
'#value' => ($form['#node']->nid) ? $form['#node']->domain_site : variable_get('domain_node_'. $form['#node']->type, $behavior),
);
// Domains that have been assigned and cannot be changed.
$form['domains_raw'] = array(
'#type' => 'value',
'#value' => $raw,
);
}
// THIS SECTION BREAKS CCK if we don't check for cck_dummy_node_form! See http://drupal.org/node/186624
// Some editors cannot administer nodes, so we have to add these form elements.
if (variable_get('domain_editors', DOMAIN_EDITOR_RULE) == 1 && user_access('edit domain nodes')) {
$access = variable_get('domain_form_elements', array('options', 'delete', 'comment_settings', 'path'));
foreach ($access as $item) {
$form[$item]['#access'] = TRUE;
}
}
}
}
/**
* Implements hook_url_alter().
*
* Forces absolute paths for domains when needed.
* We run this in all cases, if we exclude $absolute = TRUE, node_search fails.
*/
function domain_url_alter(&$path, &$query, &$fragment, &$absolute) {
global $_domain;
// Set static variables for the node lookups, to remove redundant queries.
static $domain_site, $domain, $nodepaths;
// Check to see that this function is installed.
$skip = FALSE;
$arg = arg(0);
if ($arg == 'admin' && ($path == 'domain_access_test_path' || $path == 'domain_access_path_test')) {
$path = 'yes';
$skip = TRUE;
}
// This routine only needs to be run from certain urls or if we want to
// force all links to go to a single domain for SEO.
// See http://drupal.org/node/195366 for the background.
$check = domain_grant_all();
$seo = variable_get('domain_seo', 0);
if (TRUE || !$skip && ($check || $seo)) {
// Check to see if this is a node or comment link and set $nid accordingly.
// We static the $nid results to make this more efficient.
$pattern = explode('/', $path);
// Advanced pattern matching, we find the node id based on token %n in the path string.
if (!isset($nodepaths)) {
$pathdata = variable_get('domain_paths', "node/%n\r\ncomment/reply/%n\r\nnode/add/book/parent/%n\r\nbook/export/html/%n");
$path_match = preg_replace('/(\r\n?|\n)/', '|', $pathdata);
$nodepaths = explode("|", $path_match);
}
$nid = FALSE;
foreach ($nodepaths as $match) {
$match_array = explode('/', $match);
$placeholder = array_search('%n', $match_array);
$match_array[$placeholder] = $pattern[$placeholder];
if (is_numeric($pattern[$placeholder]) && $match_array == $pattern) {
$nid = (int) $pattern[$placeholder];
break;
}
}
// This path has matched a node id, so it may need to be rewritten.
if ($nid) {
$root = domain_default();
// Remove redundancy from the domain_site check.
if (!isset($domain_site[$nid])) {
// If this check works, we don't need to rewrite the path unless SEO rules demand it.
$domain_site[$nid] = db_result(db_query("SELECT grant_view FROM {node_access} WHERE nid = %d AND gid = 0 AND realm = '%s'", $nid, 'domain_site'));
}
if (!$domain_site[$nid]) {
// Remove rendundancy from the domain_id check.
if (!isset($domain[$nid])) {
// Load the domain data for this node -- but we're only taking the first match.
$id = db_result(db_query_range("SELECT gid FROM {node_access} WHERE nid = %d AND realm = '%s' AND grant_view = 1", $nid, 'domain_id', 0, 1));
$domain[$nid] = domain_lookup($id);
}
// Can we and do we need to rewrite this path?
if ($domain[$nid] != -1 && $domain[$nid]['domain_id'] != $_domain['domain_id']) {
$absolute = TRUE;
$path = $domain[$nid]['path'] . $path;
}
}
// If strict SEO rules are enabled, we set "all affiliate" links to the root domain.
// Only needed if we are not on the root domain.
else if ($seo && $_domain['domain_id'] != $root['domain_id']) {
$absolute = TRUE;
$path = $root['path'] . $path;
}
}
}
}
/**
* Activate the hidden grant for searches.
*
* @param $rest
* A boolean flag indicating whether to reset the static variable or not.
* @return
* TRUE or FALSE, depending on whether the grants should be executed for this page.
* @ingroup domain
*/
function domain_grant_all($reset= FALSE) {
static $grant;
if (!isset($grant) || $reset) {
// Search is the easy case, so we check it first.
$search = variable_get('domain_search', 0);
if ($search && arg(0) == 'search') {
$grant = TRUE;
}
else {
// We check the paths registered by the special pages setting.
$grant = FALSE;
$pages = variable_get('domain_grant_all', "user/*/track");
$path = drupal_get_path_alias($_GET['q']);
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($pages, '/')) .')$/';
// Compare with the internal and path alias (if any).
$page_match = preg_match($regexp, $path);
if ($path != $_GET['q']) {
$page_match || preg_match($regexp, $_GET['q']);
}
if ($page_match) {
$grant = TRUE;
}
}
}
return $grant;
}
/**
* Implements hook_domaininstall()
*/
function domain_domaininstall() {
// Check to see if the hook_url_alter() patch is installed.
if (url('domain_access_test_path') != url('domain_access_path_test')) {
drupal_set_message(t('The hook_url_rewrite() patch is not installed. Some features are not available. See the Patches to Drupal Core section of README.txt', array('!url' => drupal_get_path('module', 'domain') .'/README.txt')));
}
}
/**
* Implements hook_domainupdate()
*/
function domain_domainupdate($op, $domain = array(), $edit = array()) {
switch ($op) {
case 'delete':
if ($domain != -1) {
// Remove domain-specific entries from the {node_access} table and clear the cache.
db_query("DELETE FROM {node_access} WHERE realm = 'domain_id' AND gid = %d", $domain['domain_id']);
db_query("DELETE FROM {node_access} WHERE realm = 'domain_editor' AND gid = %d", $domain['domain_id']);
cache_clear_all();
}
break;
}
}