TRUE
(PHP-mode, experts only).');
$description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => ''));
}
$form['page_vis_settings']['visibility'] = array(
'#type' => 'radios',
'#title' => t('Activate section on the specific pages'),
'#options' => $options,
'#default_value' => $visibility,
);
$form['page_vis_settings']['path'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
'#default_value' => $edit['path'],
'#description' => $description,
'#wysiwyg' => FALSE,
);
}
if ($edit['sid']) {
//we are updating
drupal_set_title(t('Edit section %name', array('%name' => $section->name)));
$form['sid'] = array('#type' => 'hidden', '#value' => $edit['sid']);
$form['submit'] = array('#type' => 'submit', '#value' => t('Save section'));
}
else {
//we are adding
drupal_set_title(t('Add section'));
$form['submit'] = array('#type' => 'submit', '#value' => t('Add section'));
}
return $form;
}
function sections_admin_settings_form_submit($id, $edit) {
switch ($_POST['op']) {
case t('Save section'):
db_query("UPDATE {sections_data} SET name = '%s', status = %d, visibility = %d, theme = '%s', path = '%s', weight = %d WHERE sid = %d", $edit['name'], $edit['status'], $edit['visibility'], $edit['theme'], $edit['path'], $edit['weight'], $edit['sid']);
drupal_set_message(t('The sections configuration has been saved.'));
cache_clear_all();
menu_rebuild();
drupal_goto('admin/build/sections');
break;
case t('Add section'):
db_query("INSERT INTO {sections_data} (name, status, visibility, path, theme, weight) VALUES ('%s', %d, %d, '%s', '%s', %d)", $edit['name'], $edit['status'], $edit['visibility'], $edit['path'], $edit['theme'], $edit['weight']);
drupal_set_message(t('The sections configuration has been saved.'));
cache_clear_all();
menu_rebuild();
drupal_goto('admin/build/sections');
break;
}
}
function _sections_delete($section) {
$op = $_POST['op'];
switch ($op) {
case t('Delete'):
db_query("DELETE FROM {sections_data} WHERE sid = %d", $section->sid);
drupal_set_message(t('The section %name has been deleted.', array('%name' => $section->name)));
cache_clear_all();
drupal_goto('admin/build/sections');
break;
default:
$output = drupal_get_form('_sections_delete_confirm', $section);
break;
}
return $output;
}
function _sections_delete_confirm($section) {
return confirm_form(
array(),
t('Delete section %name', array('%name' => $section->name)),
'admin/build/sections',
''. t('Are you sure you want to delete the section %name?', array('%name' => $section->name)) .'
', t('Delete'), t('Cancel') ); } function _sections_load() { $res = db_query("SELECT * FROM {sections_data} ORDER BY weight"); $sections = array(); while ($row = db_fetch_object($res)) { $sections[] = $row; } return $sections; } /** * Loads the section names */ function _section_load($section_name) { return db_fetch_object(db_query("SELECT * FROM {sections_data} WHERE name = '%s' ORDER BY weight", $section_name)); } /** * Loads the options for the themes select form element */ function _sections_theme_select() { $options = array(); $options[0] = '<'. t('System default') .'>'; foreach (list_themes() as $key => $theme) { $options[$theme->name] = t('@name (@status)', array('@name' => $theme->name, '@status' => ($theme->status ? t('Enabled') : t('Disabled')))); } return $options; } /** * 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) { if (is_string($section)) { // caller wants to know if shes in the section she provided. if($section == sections_in_section()) { return TRUE; } } else { // caller wants to know in which section she is. $res = db_query('SELECT sid, name, path, status, visibility, theme, weight FROM {sections_data} WHERE status = %d ORDER BY weight', 1); 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 = _sections_match_path($path, $row->path); if ($path != $_GET['q']) { $page_match = $page_match || _sections_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. Prevent // the admin theme switching on block admin pages. if ($page_match = !($row->visibility xor $page_match) && !(_sections_match_path($path, "admin/build/block\nadmin/build/block/list/*"))) { return $row; } } else { if (drupal_eval($row->path)) { return $row; } } } } // No section has been found, return FALSE. return FALSE; } /** * D6 backport of drupal_match_path(). */ function _sections_match_path($path, $patterns) { static $regexps; if (!isset($regexps[$patterns])) { $regexps[$patterns] = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\