'Sections', 'description' => 'Define sections of your site and apply themes to them.', 'page callback' => '_sections_list', 'access arguments' => $access, 'file' => 'sections.admin.inc', 'type' => MENU_NORMAL_ITEM ); $items['admin/build/sections/list'] = array( 'title' => 'List', 'page callback' => '_sections_list', 'access arguments' => $access, 'weight' => -10, 'file' => 'sections.admin.inc', 'type' => MENU_DEFAULT_LOCAL_TASK ); $items['admin/build/sections/add'] = array( 'title' => 'Add section', 'page callback' => 'drupal_get_form', 'page arguments' => array('sections_admin_settings_form'), 'access arguments' => $access, 'file' => 'sections.admin.inc', 'type' => MENU_LOCAL_TASK ); $items['admin/build/sections/edit/%section'] = array( 'title' => 'Edit section', 'page callback' => 'drupal_get_form', 'page arguments' => array('sections_admin_settings_form', 4), 'access arguments' => $access, 'file' => 'sections.admin.inc', 'type' => MENU_CALLBACK ); $items['admin/build/sections/delete/%section'] = array( 'title' => 'Delete section', 'page callback' => 'drupal_get_form', 'page arguments' => array('sections_delete_form', 4), 'access arguments' => $access, 'file' => 'sections.admin.inc', 'type' => MENU_CALLBACK ); return $items; } /** * Implementation of hook_init(). */ function sections_init() { if ($section = _sections_in_section()) { // only switch to custom theme if theme is active, to prohibit a destroyed site foreach (list_themes() as $key => $theme) { if ($theme->status == 1 && $theme->name == $section->theme) { global $custom_theme; $custom_theme = $section->theme; } } } } function _sections_load() { $res = db_query('SELECT * FROM {sections_data}'); $sections = array(); while ($row = db_fetch_object($res)) { $sections[] = $row; } return $sections; } /** * Menu helper function to verify if section exists. */ function section_load($section) { return db_fetch_object(db_query("SELECT * FROM {sections_data} WHERE sid = %d", $section)); } /** * An API for modules that want to know about sections. * * This API is a function that lets you find out about settings. * * @param * Optional $setting a string containing the section you wnat to test against. * * @return * Depends on the parameter. * If you do not give $section, it will return the section object, if found. * If you give $section, it will return TRUE if you are in that section * Otherwise it will return FALSE */ function _sections_in_section($section = NULL) { $output = FALSE; if (is_string($section)) { // caller wants to know if shes in the section she provided. if ($section == _sections_in_section()) { $output = TRUE; } } else { // caller wants to know in which section she is. $res = db_query('SELECT path, status, visibility, theme, weight FROM {sections_data} WHERE status=1 ORDER BY weight'); while ($row = db_fetch_object($res)) { if ($row->visibility == 1) { // This bizarre bit of magic courtesy of block.module $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($row->path, '/')) .')$/'; if (preg_match($regexp, $path) && !($path == 'admin/block')) { $output = $row; } } else { if (drupal_eval($row->path)) { $output = $row; } } } } return $output; }