t('Virtual sites'), 'description' => t('Create new virtual sites, much like Drupals multi-site feature does.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('virtual_site_list_form'), 'access arguments' => array('administer virtual sites'), 'file' => 'virtual_site.admin.inc', ); $items['admin/build/sites/list'] = array( 'title' => t('List'), 'file' => 'virtual_site.admin.inc', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items['admin/build/sites/add'] = array( 'title' => t('Add'), 'page callback' => 'drupal_get_form', 'page arguments' => array('virtual_site_edit_form'), 'access arguments' => array('administer virtual sites'), 'file' => 'virtual_site.admin.inc', 'type' => MENU_LOCAL_TASK, ); $items['admin/build/sites/%virtual_site/edit'] = array( 'title' => t('Edit'), 'page callback' => 'drupal_get_form', 'page arguments' => array('virtual_site_edit_form', 3), 'access arguments' => array('administer virtual sites'), 'file' => 'virtual_site.admin.inc', 'type' => MENU_CALLBACK, ); $features = virtual_site_features(); if (count($features)) { $items['admin/build/sites/%virtual_site/edit/default'] = array( 'title' => t('Site'), 'file' => 'virtual_site.admin.inc', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); foreach ($features as $feature) { $items['admin/build/sites/%virtual_site/edit/'.$feature['callback']] = array( 'title' => t($feature['name']), 'page callback' => 'drupal_get_form', 'page arguments' => array('virtual_site_edit_feature_form', 3, 5), 'access arguments' => array('administer virtual sites'), 'file' => 'virtual_site.admin.inc', 'type' => MENU_LOCAL_TASK, ); } } $items['admin/build/sites/%virtual_site/delete'] = array( 'title' => t('Delete'), 'page callback' => 'drupal_get_form', 'page arguments' => array('virtual_site_delete_form', 3), 'access arguments' => array('administer virtual sites'), 'file' => 'virtual_site.admin.inc', 'type' => MENU_CALLBACK, ); return $items; } /** * Implementation of hook_perm(). */ function virtual_site_perm() { return array('administer virtual sites'); } /** * Implementation of hook_perm(). */ function virtual_site_help($path, $arg) { switch ($path) { case 'admin/build/sites': return '
'.t('Virtual sites offer almost the same (and more) functionality as the Drupal !multisite feature without the need for FTP or SSH. Depending on conditions (e.g. requested url or user role) handeld by the !condition module, you can override theme, site information, menu\'s and more to virtually present the visitor with a different website.', array('!multisite' => l(t('multi-site'), 'http://drupal.org/node/43816', array('attributes' => array('target' => '_blank'))), '!condition' => l(t('Condition'), 'admin/settings/condition'))).'
'.t('The first listed site that matches the specified conditions will be used. You can change the order by dragging the rows.').'
'; case 'admin/build/sites/%/edit': return ''.t('When to show this virtual site is decided by the !conditions module. Add a condition (e.g. to match for the url sub.example.com) and check the condition(s) to show this site for, in the form below. Edit the sites features (e.g. theme) using the tabs. If you see no tabs, first install and enable some !feature.', array('!conditions' => l(t('Conditions'), 'admin/settings/condition'), '!feature' => l(t('Virtual site feature module'), 'admin/build/modules/', array('fragment' => 'edit-status-virtual-site-variables-wrapper')))).'
'; } } /** * Implementation of hook_theme(). */ function virtual_site_theme() { return array( 'virtual_site_list_form' => array('arguments' => array('form' => NULL)), 'virtual_site_edit_form' => array('arguments' => array('form' => NULL)), 'virtual_site_edit_feature_form' => array('arguments' => array('form' => NULL)), ); } /** * Implementation of hook_init(). */ function virtual_site_init() { if ($site = virtual_site_load_active()) { $features = virtual_site_features(); if (is_array($features) && count($features)) { foreach ($features as $feature) { if (isset($site->features[$feature['callback']])) { $context = $site->features[$feature['callback']]; $context['site'] = $site; $feature['callback']($context); } } } } } /** * Get all features */ function virtual_site_features() { static $features; if (is_null($features)) { $features = (array) module_invoke_all('feature_info'); foreach ($features as $feature => $info) { $features[$feature]['callback'] = function_exists($feature) ? $feature : NULL; $features[$feature]['form'] = function_exists($feature.'_form') ? $feature.'_form' : NULL; $features[$feature]['submit'] = function_exists($feature.'_submit') ? $feature.'_submit' : NULL; if (!isset($features[$feature]['callback'], $features[$feature]['form'], $features[$feature]['submit'])) { unset($features[$feature]); } } } return $features; } /** * Implementation of hook_load */ function virtual_site_load($sid = NULL, $refresh = FALSE) { static $sites; if (!is_array($sites) || $refresh) { if (is_numeric($sid)) { $site = db_fetch_object(db_query("SELECT * FROM {virtual_sites} WHERE sid = %d", $sid)); $site->conditions = (array) unserialize($site->conditions); $site->features = (array) unserialize($site->features); return $site; } else { $result = db_query("SELECT * FROM {virtual_sites} ORDER BY weight ASC"); $sites = array(); while ($site = db_fetch_object($result)) { $site->conditions = (array) unserialize($site->conditions); $site->features = (array) unserialize($site->features); $sites[$site->sid] = $site; } } } if (is_array($sites)) { if (is_numeric($sid)) { return $sites[$sid]; } elseif (is_array($sid)) { return array_intersect_key($sites, array_flip($sid)); } else { return $sites; } } } /** * Finds active virtual site and returns the data object. */ function virtual_site_load_active() { static $active; if (!is_object($active)) { $sites = virtual_site_load(); foreach ($sites as $site) { if (!$site->status) { continue; } if (module_invoke('condition', 'selection_validate', $site->conditions)) { $active = $site; break; } } } return $active; } /** * Save one or more virtual sites. */ function virtual_site_save($site) { if (is_array($site)) { foreach (array_keys($site) as $key) { $site[$key]->saved = virtual_site_save($site[$key]); } return $site; } $site->conditions = serialize(is_array($site->conditions) ? $site->conditions : array()); $site->features = serialize(is_array($site->features) ? $site->features : array()); return drupal_write_record('virtual_sites', $site, $site->sid ? 'sid' : array()); } /** * Delete one or more conditions. */ function virtual_site_delete($site) { if (is_array($site)) { foreach (array_keys($site) as $key) { $site[$key]->deleted = virtual_site_delete($site[$key]); } return $site; } $sid = is_object($site) ? $site->sid : $site; return db_query("DELETE FROM {virtual_sites} WHERE sid = %d", $sid); } ?>