diff --git a/sites/all/modules/unl/cron.php b/sites/all/modules/unl/cron.php index 3ecaf98eb2d8ec53583442dc376cd912fa66e221..c5df327bb7bd3d71add7aed1d5bb2a5a319ea345 100644 --- a/sites/all/modules/unl/cron.php +++ b/sites/all/modules/unl/cron.php @@ -1,4 +1,13 @@ <?php +/** + * 'installed' database number codes (also seen in modules/unl/unl_site_creation.php) + * 0: 'Scheduled for creation.' + * 1: 'Curently being created.' + * 2: 'In production.' + * 3: 'Scheduled for removal.' + * 4: 'Currently being removed.' + * 5: 'Failure/Unknown.' + */ if (PHP_SAPI != 'cli') { echo 'This script must be run from the shell!'; @@ -22,7 +31,7 @@ unl_add_page_aliases(); function unl_add_sites() { $query = db_query('SELECT * FROM {unl_sites} WHERE installed=0'); - + while ($row = $query->fetchAssoc()) { db_update('unl_sites') ->fields(array('installed' => 1)) @@ -71,7 +80,7 @@ function unl_add_aliases() { $query->fields('a', array('site_alias_id', 'base_uri', 'path')); $query->condition('a.installed', 0); $results = $query->execute()->fetchAll(); - + foreach ($results as $row) { db_update('unl_sites_aliases') ->fields(array('installed' => 1)) @@ -97,7 +106,7 @@ function unl_remove_aliases() { $query->fields('a', array('site_alias_id', 'base_uri', 'path')); $query->condition('a.installed', 3); $results = $query->execute()->fetchAll(); - + foreach ($results as $row) { db_update('unl_sites_aliases') ->fields(array('installed' => 4)) @@ -122,7 +131,7 @@ function unl_add_page_aliases() { $query->fields('a', array('page_alias_id', 'from_uri', 'to_uri')); $query->condition('a.installed', 0); $results = $query->execute()->fetchAll(); - + foreach ($results as $row) { db_update('unl_page_aliases') ->fields(array('installed' => 1)) @@ -148,7 +157,7 @@ function unl_remove_page_aliases() { $query->fields('a', array('page_alias_id')); $query->condition('a.installed', 3); $results = $query->execute()->fetchAll(); - + foreach ($results as $row) { db_update('unl_page_aliases') ->fields(array('installed' => 4)) @@ -175,19 +184,19 @@ function unl_add_site($site_path, $uri, $clean_url, $db_prefix, $site_id) { if (substr($site_path, -1) == '/') { $site_path = substr($site_path, 0, -1); } - + $sites_subdir = unl_get_sites_subdir($uri); - + $database = $GLOBALS['databases']['default']['default']; $db_url = $database['driver'] . '://' . $database['username'] . ':' . $database['password'] . '@' . $database['host'] - . ($database['port'] ? ':' . $database['port'] : '') + . ($database['port'] ? ':' . $database['port'] : '') . '/' . $database['database'] ; $db_prefix .= '_' . $database['prefix']; - + $php_path = escapeshellarg($_SERVER['_']); $drupal_root = escapeshellarg(DRUPAL_ROOT); $uri = escapeshellarg($uri); @@ -195,15 +204,15 @@ function unl_add_site($site_path, $uri, $clean_url, $db_prefix, $site_id) { $db_url = escapeshellarg($db_url); $db_prefix = escapeshellarg($db_prefix); $site_mail = escapeshellarg(variable_get('site_mail')); - + $command = "$php_path sites/all/modules/drush/drush.php -y --uri=$uri site-install unl_profile --sites-subdir=$sites_subdir --db-url=$db_url --db-prefix=$db_prefix --clean-url=$clean_url"; if ($site_mail) { - $command .= " --site-mail=$site_mail"; + $command .= " --site-mail=$site_mail"; } echo shell_exec($command); - + unl_add_site_to_htaccess($site_id, $site_path, FALSE); - + return TRUE; } @@ -212,20 +221,20 @@ function unl_remove_site($site_path, $uri, $db_prefix, $site_id) { $schema = drupal_get_schema(NULL, TRUE); $tables = array_keys($schema); sort($tables); - + $database = $GLOBALS['databases']['default']['default']; $db_prefix .= '_' . $database['prefix']; - - + + $sites_subdir = unl_get_sites_subdir($uri); $sites_subdir = DRUPAL_ROOT . '/sites/' . $sites_subdir; $sites_subdir = realpath($sites_subdir); - + // A couple checks to make sure we aren't deleting something we shouldn't be. if (substr($sites_subdir, 0, strlen(DRUPAL_ROOT . '/sites/')) != DRUPAL_ROOT . '/sites/') { return FALSE; } - + if (strlen($sites_subdir) <= strlen(DRUPAL_ROOT . '/sites/')) { return FALSE; } @@ -239,19 +248,19 @@ function unl_remove_site($site_path, $uri, $db_prefix, $site_id) { // probably already gone? } } - + // Do our best to remove the sites shell_exec('chmod -R u+w ' . escapeshellarg($sites_subdir)); shell_exec('rm -rf ' . escapeshellarg($sites_subdir)); - + // Remove the rewrite rules from .htaccess for this site. unl_remove_site_from_htaccess($site_id, FALSE); - + // If we were using memcache, flush its cache so new sites don't have stale data. if (class_exists('MemCacheDrupal', FALSE)) { dmemcache_flush(); } - + return TRUE; } @@ -260,11 +269,11 @@ function unl_add_alias($site_uri, $base_uri, $path, $alias_id) { $real_config_dir = unl_get_sites_subdir($site_uri); $alias_config_dir = unl_get_sites_subdir($alias_uri, FALSE); $result = symlink($real_config_dir, DRUPAL_ROOT . '/sites/' . $alias_config_dir); - + if ($path) { unl_add_site_to_htaccess($alias_id, $path, TRUE); } - + return TRUE; } @@ -272,24 +281,24 @@ function unl_remove_alias($base_uri, $path, $alias_id) { $alias_uri = $base_uri . $path; $alias_config_dir = unl_get_sites_subdir($alias_uri, FALSE); unlink(DRUPAL_ROOT . '/sites/' . $alias_config_dir); - + unl_remove_site_from_htaccess($alias_id, TRUE); - + return TRUE; } function unl_add_page_alias($from_uri, $to_uri, $alias_id) { $host = parse_url($from_uri, PHP_URL_HOST); $path = parse_url($from_uri, PHP_URL_PATH); - + unl_add_page_alias_to_htaccess($alias_id, $host, $path, $to_uri); - + return TRUE; } function unl_remove_page_alias($alias_id) { unl_remove_page_alias_from_htaccess($alias_id); - + return TRUE; } @@ -300,7 +309,7 @@ function unl_add_site_to_htaccess($site_id, $site_path, $is_alias) { else { $site_or_alias = 'SITE'; } - + if (substr($site_path, -1) != '/') { $site_path .= '/'; } @@ -316,10 +325,10 @@ function unl_add_site_to_htaccess($site_id, $site_path, $is_alias) { foreach (array('misc', 'modules', 'sites', 'themes') as $drupal_dir) { $new_htaccess .= " RewriteRule $site_path$drupal_dir/(.*) $drupal_dir/$1\n"; } - $new_htaccess .= " # %UNL_END_{$site_or_alias}_ID_{$site_id}%\n\n" + $new_htaccess .= " # %UNL_END_{$site_or_alias}_ID_{$site_id}%\n\n" . $stub_token . substr($htaccess, $stub_pos + strlen($stub_token)); - + file_put_contents(DRUPAL_ROOT . '/.htaccess', $new_htaccess); } @@ -330,14 +339,14 @@ function unl_remove_site_from_htaccess($site_id, $is_alias) { else { $site_or_alias = 'SITE'; } - + $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess'); $site_start_token = "\n # %UNL_START_{$site_or_alias}_ID_{$site_id}%"; $site_end_token = " # %UNL_END_{$site_or_alias}_ID_{$site_id}%\n"; - + $start_pos = strpos($htaccess, $site_start_token); $end_pos = strpos($htaccess, $site_end_token); - + if ($start_pos === FALSE || $end_pos === FALSE) { return FALSE; } @@ -359,10 +368,10 @@ function unl_add_page_alias_to_htaccess($site_id, $host, $path, $to_uri) { . " RewriteCond %{HTTP_HOST} ^{$host}$\n" . " RewriteCond %{REQUEST_URI} ^{$path}$\n" . " RewriteRule (.*) {$to_uri} [R,L]\n" - . " # %UNL_END_PAGE_ALIAS_ID_{$site_id}%\n\n" + . " # %UNL_END_PAGE_ALIAS_ID_{$site_id}%\n\n" . $stub_token . substr($htaccess, $stub_pos + strlen($stub_token)); - + file_put_contents(DRUPAL_ROOT . '/.htaccess', $new_htaccess); } @@ -370,10 +379,10 @@ function unl_remove_page_alias_from_htaccess($site_id) { $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess'); $site_start_token = "\n # %UNL_START_PAGE_ALIAS_ID_{$site_id}%"; $site_end_token = " # %UNL_END_PAGE_ALIAS_ID_{$site_id}%\n"; - + $start_pos = strpos($htaccess, $site_start_token); $end_pos = strpos($htaccess, $site_end_token); - + if ($start_pos === FALSE || $end_pos === FALSE) { return FALSE; } @@ -382,15 +391,3 @@ function unl_remove_page_alias_from_htaccess($site_id) { ; file_put_contents(DRUPAL_ROOT . '/.htaccess', $new_htaccess); } - - - - - - - - - - - - diff --git a/sites/all/modules/unl/unl.module b/sites/all/modules/unl/unl.module index 02381dd33437f39a89be7ec74a25bd009d908ffe..13e9abe45c15c9af4ac0334cbbd4e1d30d4337ea 100644 --- a/sites/all/modules/unl/unl.module +++ b/sites/all/modules/unl/unl.module @@ -206,6 +206,9 @@ function unl_wysiwyg_plugin($editor) { } } +/** + * Implementation of hook_permission(). + */ function unl_permission() { return array( 'unl migration' => array( @@ -243,7 +246,7 @@ function unl_permission() { } /** - * Adds UNL Migration Tool to the Content menu for admin + * Implementation of hook_menu(). */ function unl_menu() { global $user; @@ -267,6 +270,7 @@ function unl_menu() { 'file' => 'technical_feedback.php' ); + // Adds UNL Migration Tool to the Content menu for admin $items['admin/content/unl/migration'] = array( 'title' => 'UNL Migration Tool', 'description' => 'Migrate a static UNL template page into drupal', @@ -384,7 +388,12 @@ function unl_menu() { return $items; } +/** + * Implementation of hook_menu_alter(). + */ function unl_menu_alter(&$items) { + // This duplicates the form at admin/appearance/settings/unl_wdn for roles that can't 'administer themes' but have 'unl theme settings' permission. + // For these users the Appearance link is changed to point to admin/themes foreach (array('module', 'file', 'page arguments') as $key) { $items['admin/themes'][$key] = $items['admin/appearance/settings/' . variable_get('theme_default')][$key]; } @@ -453,9 +462,7 @@ function unl_form_alter(&$form, &$form_state, $form_id) { } } - /** - * Modify the Permissions and Roles forms for non-administrators - */ + // Modifications for non-administrators $admin_role_id = unl_shared_variable_get('user_admin_role', -1); if (!in_array($admin_role_id, array_keys($GLOBALS['user']->roles))) { switch ($form_id) { @@ -596,9 +603,10 @@ function unl_form_alter(&$form, &$form_state, $form_id) { } /** - * When a node is modified, update its menu link to be hidden or not based on the user input. + * Implementation of hook_node_form_submit(). */ function unl_node_form_submit($form, &$form_state) { + // When a node is modified, update its menu link to be hidden or not based on the user input. $menu_data = $form_state['values']['menu']; if ($menu_data['mlid']) { @@ -622,6 +630,9 @@ function unl_node_form_submit($form, &$form_state) { menu_link_save($menu_link); } +/** + * Implementation of hook_system_settings_form_submit(). + */ function unl_system_settings_form_submit($form, &$form_state) { variable_set('https', (bool) $form_state['values']['https']); if ($form_state['values']['unl_primary_base_url'] != '_null') { @@ -632,6 +643,9 @@ function unl_system_settings_form_submit($form, &$form_state) { } } +/** + * Implementation of hook_theme(). + */ function unl_theme() { return array( 'unl_table' => array( @@ -640,6 +654,9 @@ function unl_theme() { ); } +/** + * Implementation of hook_url_outbound_alter(). + */ function unl_url_outbound_alter(&$path, &$options, $original_path) { $path_parts = parse_url($path); if (isset($path_parts['scheme']) || $path == 'user/cas') { @@ -663,6 +680,10 @@ function unl_url_outbound_alter(&$path, &$options, $original_path) { $options['https'] = (bool) (variable_get('https', 0) && !$generic_user); } +/** + * Custom function for implementing user_access for multiple permissions. + * Feature request: http://drupal.org/node/216897 + */ function unl_user_access($permissions, $account = NULL) { foreach ($permissions as $permission) { if (substr($permission, 0, 1) == '!') { @@ -672,17 +693,15 @@ function unl_user_access($permissions, $account = NULL) { else { $result = user_access($permission, $account); } - if (!$result) { return FALSE; } } - return TRUE; } /** - * Additional validation on the user_admin_role form (admin/people/permissions/roles/edit/%) + * Custom function for additional validation on the user_admin_role form (admin/people/permissions/roles/edit/%) * to prevent a user from deleting the administrator role. (This is not needed if permissions are shared and only administrators can edit roles.) */ function unl_user_admin_role_validate($form, &$form_state) { @@ -696,6 +715,9 @@ function unl_user_admin_role_validate($form, &$form_state) { } } +/** + * Implementation of hook_cron(). + */ function unl_cron() { _unl_cron_migration_step(); _unl_cron_import_wdn_registry_sites(); @@ -804,7 +826,9 @@ function _unl_cron_import_wdn_registry_sites() { } } -// Creates a db_prefix short enough to not go over MySQL's max table name length +/** + * Custom function that creates a db_prefix short enough to not go over MySQL's max table name length. + */ function unl_create_db_prefix($site_name) { $parent_prefix = '_' . $GLOBALS['databases']['default']['default']['prefix']; @@ -844,6 +868,9 @@ function unl_sanitize_url_part($url_part) { return $url_part; } +/** + * Custom function. + */ function unl_get_alternate_base_uris() { $shared_prefix = unl_get_shared_db_prefix(); if (is_array($GLOBALS['databases']['default']['default']['prefix'])) { @@ -854,7 +881,7 @@ function unl_get_alternate_base_uris() { return array(); } $rows = db_query( - "SELECT s.uri, a.base_uri, a.path " + "SELECT s.uri, a.base_uri, a.path " . "FROM {$shared_prefix}unl_sites AS s " . "LEFT JOIN {$shared_prefix}unl_sites_aliases AS a " . " ON s.site_id = a.site_id " @@ -876,6 +903,9 @@ function unl_get_alternate_base_uris() { return $uris; } +/** + * Implementation of hook_init(). + */ function unl_init() { $primary_base_url = variable_get('unl_primary_base_url'); if ($primary_base_url) { @@ -893,6 +923,9 @@ function unl_init() { } } +/** + * Implementation of hook_mail(). + */ function unl_mail($key, &$message, $params) { if ($key == 'site_created') { $site = $params['site']; @@ -925,6 +958,9 @@ EOF; } } +/** + * Custom function. + */ function unl_send_site_created_email($site = NULL) { $shared_prefix = unl_get_shared_db_prefix(); @@ -978,9 +1014,10 @@ function unl_send_site_created_email($site = NULL) { } } -// A simple "I'm still alive" page to check to see that drupal is working. -function unl_still_alive() -{ +/** + * Custom function that outputs a simple "I'm still alive" page to check to see that drupal is working. + */ +function unl_still_alive() { header('Content-type: text/plain'); echo '200 Still Alive'; }