'Sections', 'description' => 'Define sections of your site and apply themes to them.', 'page callback' => 'drupal_get_form', 'page arguments' => array('sections_admin_display_form'), 'access arguments' => $access, 'file' => 'sections.admin.inc', 'type' => MENU_NORMAL_ITEM ); $items['admin/build/sections/list'] = array( 'title' => 'List', 'page callback' => 'drupal_get_form', 'page arguments' => array('sections_admin_display_form'), '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_theme() */ function sections_theme() { return array( 'sections_admin_display_form' => array( 'file' => 'sections.admin.inc', 'arguments' => array('form' => NULL), ), ); } /** * 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; } } } } /** * 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) { global $user; $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. $rids = array_keys($user->roles); $res = db_query(db_rewrite_sql('SELECT DISTINCT s.* FROM {sections_data} s LEFT JOIN {sections_roles} r ON s.sid = r.sid WHERE s.status = 1 AND (r.rid IN ('. db_placeholders($rids) .') OR r.rid IS NULL) ORDER BY s.weight', 's', 'sid'), $rids); while ($row = db_fetch_object($res)) { if ($row->visibility < 2) { $path = drupal_get_path_alias($_GET['q']); // Compare with the internal and path alias (if any). $page_match = drupal_match_path($path, $row->path); if ($path != $_GET['q']) { $page_match = $page_match || drupal_match_path($_GET['q'], $row->path); } // When $row->visibility has a value of 0, the block is displayed on // all pages except those listed in $row->path. When set to 1, it // is displayed only on those pages listed in $row->path. if ($page_match = !($row->visibility xor $page_match)) { $output = $row; } } else { if (drupal_eval($row->path)) { $output = $row; } } } } return $output; } /** * Add template suggestion for page templates. */ function sections_preprocess_page(&$variables) { // Add multiple suggestions. if ($section = _sections_in_section()) { // Try to find a page template with section id. $variables['template_files'][] = 'sections-page-'. $section->sid; // Try to find a page template named like the section. $filter = '![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s'; $string_clean = preg_replace($filter, '-', drupal_strtolower($section->name)); $variables['template_files'][] = 'sections-page-'. $string_clean; } }