### Eclipse Workspace Patch 1.0
#P drupal-contrib-cvs
Index: modules/sections/sections.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sections/sections.module,v
retrieving revision 1.16
diff -u -r1.16 sections.module
--- modules/sections/sections.module	8 Dec 2006 23:46:52 -0000	1.16
+++ modules/sections/sections.module	21 Jul 2007 22:20:10 -0000
@@ -17,6 +17,93 @@
 }
 
 /**
+ * Implementation of hook_perm().
+ *
+ * Since the access to our new custom pages will be granted based on
+ * special permissions, we need to define what those permissions are here.
+ * This ensures that they are available to enable on the user role
+ * administration pages.
+ */
+function sections_perm() {
+  return array('administer sections');
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function sections_menu($may_cache) {
+  // Never *ever* use t() with %name in hook_menu OR init_theme() get's fired for theme_placeholder
+  // by theme_get_function function and theme switch will fail for anonymous users in cached mode 
+  // with subthemes!
+
+  // admin/build/sections/ show the summary
+  // admin/build/sections/list show the summary
+  // admin/build/sections/add show an empty form
+  // admin/build/sections/edit/XX show edit form for XX
+
+  $items = array();
+  if ($may_cache) {
+    $access = user_access('administer sections');
+
+    // This is the minimum information you can provide for a menu item.
+    $items[] = array(
+      'path' => 'admin/build/sections',
+      'title' => t('Sections'),
+      'description' => t('Define sections of your site and apply themes to them.'),
+      'callback' => 'sections_list',
+      'access' => $access
+    );
+    $items[] = array(
+      'path' => 'admin/build/sections/list',
+      'title' => t('List'),
+      'callback' => 'sections_list',
+      'access' => $access,
+      'weight' => -10,
+      'type' => MENU_DEFAULT_LOCAL_TASK
+    );
+    $items[] = array(
+      'path' => 'admin/build/sections/add',
+      'title' => t('Add section'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('sections_admin_settings_form'),
+      'access' => $access,
+      'type' => MENU_LOCAL_TASK
+    );
+
+    foreach (_sections_load() as $section) {
+      $items[] = array(
+        'path' => 'admin/build/sections/edit/'. $section->sid,
+        'title' => t('Edit section'),
+        'callback' => 'drupal_get_form',
+        'callback arguments' => array('sections_admin_settings_form', NULL, $section),
+        'access' => $access,
+        'type' => MENU_CALLBACK
+      );
+      $items[] = array(
+        'path' => 'admin/build/sections/delete/'. $section->sid,
+        'title' => t('Delete section'),
+        'callback' => '_sections_delete',
+        'callback arguments' => array($section),
+        'access' => $access,
+        'type' => MENU_CALLBACK
+      );
+    }
+
+  }
+  else 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->template) {
+        global $custom_theme;
+        $custom_theme = $section->template;
+      }
+    }
+  }
+
+  return $items;
+}
+
+/**
  * Declare administrative settings for a module.
  *
  * This hook provides an administrative interface for controlling various
@@ -34,22 +121,29 @@
  * define your own administration page and link to it using hook_menu().
  */
 function sections_list() {
-  $header = array(t('Section'), t('Enabled'), t('Template'), t('Weight'), array('data' => t('Operations')) );
+  $header = array(
+    t('Section'),
+    t('Status'),
+    t('Theme'),
+    t('Weight'),
+    array('data' => t('Operations'))
+  );
 
   foreach(_sections_load() as $section) {
-     $rows[] = array(
-        $section->name,
-        $section->status ?  t('enabled') : t('disabled'),
-        $section->template,
-        $section->weight,
-        l(t('edit'),'admin/settings/sections/edit/'.$section->sid) ." ".
-        l(t('delete'),'admin/settings/sections/delete/'.$section->sid));
+    $rows[] = array(
+      $section->name,
+      $section->status ? t('Enabled') : t('Disabled'),
+      $section->template,
+      $section->weight,
+      l(t('Edit'), 'admin/build/sections/edit/'. $section->sid) ." | ". l(t('Delete'), 'admin/build/sections/delete/'. $section->sid)
+    );
   }
 
   $output = theme('table', $header, $rows);
-  return $output;}
+  return $output;
+}
 
-function sections_settings_form($edit = NULL, $section = NULL) {
+function sections_admin_settings_form($edit = NULL, $section = NULL) {
   if ($section) {
     $edit = (array)$section;
   }
@@ -57,41 +151,41 @@
   $form = array();
 
   $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'));
-  $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => theme('placeholder', 'blog'), '%blog-wildcard' =>  theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>')));
+  $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
 
   if ($access) {
     $options[] = t('Show if the following PHP code returns <code>TRUE</code> (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' => theme('placeholder', '<?php ?>')));
+    $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' => '<?php ?>'));
   }
 
   $form['section_settings'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Section settings'),
+    '#title' => t('Section settings')
   );
 
   $form['section_settings']['name'] = array(
     '#type' => 'textfield',
     '#title' => t('Name'),
-    '#default_value' =>  $edit['name'],
+    '#default_value' => $edit['name'],
     '#size' => 40,
     '#maxlength' => 64,
-    '#description' => t('Give the name of the section'),
+    '#description' => t('Give the name of the section')
   );
 
   $form['section_settings']['visibility'] = array(
     '#type' => 'radios',
     '#title' => t('Activate section on the specific pages'),
     '#options' => $options,
-    '#default_value' => $edit['visibility'],
+    '#default_value' => $edit['visibility'] ? $edit['visibility'] : 0
   );
 
   $form['section_settings']['path'] = array(
     '#type' => 'textarea',
     '#title' => t('Pages'),
-    '#default_value' =>  $edit['path'],
+    '#default_value' => $edit['path'],
     '#cols' => 40,
     '#rows' => 5,
-    '#description' => $description,
+    '#description' => $description
   );
 
   $form['section_settings']['status'] = array(
@@ -103,10 +197,10 @@
 
   $form['section_settings']['template'] = array(
     '#type' => 'select',
-    '#title' => t('Select template'),
+    '#title' => t('Select theme'),
     '#default_value' => $edit['template'],
     '#options' => _sections_theme_select(),
-    '#description' => t('Select the template you want to use for this section'),
+    '#description' => t('Select the theme you want to use for this section')
   );
 
   $form['section_settings']['weight'] = array(
@@ -117,33 +211,35 @@
 
   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'));
   }
 
-  print theme('page', drupal_get_form('section_settings', $form));
+  return $form;
 }
 
-
-function section_settings_submit($id, $edit) {
+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', template = '%s', path = '%s', weight = %d WHERE sid = '%d'", $edit['name'], $edit['status'], $edit['visibility'], $edit['template'], $edit['path'], $edit['weight'], $edit['sid']);
-      drupal_set_message('The sections configuration has been saved.');
+      db_query("UPDATE {sections_data} SET name = '%s', status = %d, visibility = %d, template = '%s', path = '%s', weight = %d WHERE sid = %d", $edit['name'], $edit['status'], $edit['visibility'], $edit['template'], $edit['path'], $edit['weight'], $edit['sid']);
+      drupal_set_message(t('The sections configuration has been saved.'));
       cache_clear_all();
       menu_rebuild();
-      drupal_goto('admin/settings/sections/');
+      drupal_goto('admin/build/sections/');
+      break;
     case t('Add section'):
       $edit['sid'] = db_next_id('{sections_id}');
-      db_query("INSERT INTO {sections_data} SET sid = '%d', name = '%s', status = '%d', visibility = '%d', path = '%s', template = '%s', weight = %d", $edit['sid'], $edit['name'], $edit['status'], $edit['visibility'], $edit['path'], $edit['template'], $edit['weight']);
-      drupal_set_message('The sections configuration has been saved.');
+      db_query("INSERT INTO {sections_data} SET sid = %d, name = '%s', status = %d, visibility = %d, path = '%s', template = '%s', weight = %d", $edit['sid'], $edit['name'], $edit['status'], $edit['visibility'], $edit['path'], $edit['template'], $edit['weight']);
+      drupal_set_message(t('The sections configuration has been saved.'));
       cache_clear_all();
       menu_rebuild();
-      drupal_goto('admin/settings/sections/');
+      drupal_goto('admin/build/sections/');
       break;
   }
 }
@@ -153,94 +249,34 @@
 
   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' => '<em>'. $section->name .'</em>')));
+      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/settings/sections');
+      drupal_goto('admin/build/sections');
       break;
-
     default:
-      $output = confirm_form(
-                    'comment_confirm_delete',
-                    array(),
-                    t('Are you sure you want to delete the section %name?', array('%name' => '<em>'. $section->name .'</em>')),
-                    'admin/settings/sections/',
-                    '',
-                    t('Delete'),
-                    t('Cancel'));
+      $output = drupal_get_form('_sections_delete_confirm', $section);
       break;
   }
 
-  print theme('page', $output);
-}
-
-/**
- * Implementation of hook_perm().
- *
- * Since the access to our new custom pages will be granted based on
- * special permissions, we need to define what those permissions are here.
- * This ensures that they are available to enable on the user role
- * administration pages.
- */
-function sections_perm() {
-  return array('adminster sections');
+  return $output;
 }
 
-/**
- * Implementation of hook_menu().
- */
-function sections_menu($may_cache) {
-  global $custom_theme;
-  $items = array();
-
-  /*
-  * admin/settings/sections/ show the summary
-  * admin/settings/sections/list show the summary
-  * admin/settings/sections/add show an empty form
-  * admin/settings/sections/edit/XX show edit form for XX
-  */
-
-  if ($may_cache) {
-    $access = user_access('adminster sections');
-
-    // This is the minimum information you can provide for a menu item.
-    $items[] = array('path' => 'admin/settings/sections', 'title' => t('sections'),
-      'callback' => 'sections_list',
-      'access' => $access);
-
-    $items[] = array('path' => 'admin/settings/sections/list', 'title' => t('list'),
-      'callback' => 'sections_list',
-      'access' => $access,
-      'type' => MENU_DEFAULT_LOCAL_TASK);
-    $items[] = array('path' => 'admin/settings/sections/add', 'title' => t('add'),
-      'callback' => 'sections_settings_form',
-      'access' => $access,
-      'type' => MENU_LOCAL_TASK);
-
-    foreach (_sections_load() as $section) {
-       $items[] = array('path' => 'admin/settings/sections/edit/'.$section->sid, 'title' => t('edit %name', array('%name'=>$section->name)),
-        'callback' => 'sections_settings_form',
-        'callback arguments' => array(NULL,$section),
-        'access' => $access,
-        'type' => MENU_CALLBACK);
-       $items[] = array('path' => 'admin/settings/sections/delete/'.$section->sid, 'title' => t('edit %name', array('%name'=>$section->name)),
-        'callback' => '_sections_delete',
-        'callback arguments' => array($section),
-        'access' => $access,
-        'type' => MENU_CALLBACK);
-    }
-  }
-  else if ($section = sections_in_section()) {
-    $custom_theme = $section->template;
-  }
-
-  return $items;
+function _sections_delete_confirm($section) {
+  return confirm_form(
+    array(),
+    t('Delete section %name', array('%name' => $section->name)),
+    'admin/build/sections/',
+    '<p>'. t('Are you sure you want to delete the section %name?', array('%name' => $section->name)) .'</p>',
+    t('Delete'),
+    t('Cancel')
+  );
 }
 
 function _sections_load() {
   $sections = array();
 
-  $res = db_query('SELECT * FROM {sections_data}');
+  $res = db_query("SELECT * FROM {sections_data}");
 
   while ($row = db_fetch_object($res)) {
     $sections[] = $row;
@@ -251,9 +287,8 @@
 /**
  * Loads the section names
  */
-
 function _section_load($section_name) {
-  return db_fetch_object(db_query('SELECT * FROM {sections_data} WHERE n.name = %s ORDER BY weight', $section_name));
+  return db_fetch_object(db_query("SELECT * FROM {sections_data} WHERE name = '%s' ORDER BY weight", $section_name));
 }
 
 /**
@@ -285,33 +320,32 @@
  */
 function sections_in_section($section = NULL) {
 
+  $output = FALSE;
+
   if (is_string($section)) {
-    //caller wants to know if shes in the section she provided.
+    // caller wants to know if shes in the section she provided.
     if($section == sections_in_section()) {
-     return TRUE;
+      $output = TRUE;
     }
   }
   else {
-    //caller wants to know in which section she is.
-
+    // caller wants to know in which section she is.
     $res = db_query("SELECT path, status, visibility, template, 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)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($row->path, '/')) .')$/';
-        if(preg_match($regexp, $path) && !($path == 'admin/block')) {
-          return $row;
+        if (preg_match($regexp, $path) && !($path == 'admin/block')) {
+          $output = $row;
         }
       }
       else {
         if (drupal_eval($row->path)) {
-          return $row;
+          $output = $row;
         }
       }
     }
   }
-  //nothing found, return FALSE
-  return FALSE;
+  return $output;
 }
Index: modules/sections/sections.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sections/sections.install,v
retrieving revision 1.5
diff -u -r1.5 sections.install
--- modules/sections/sections.install	12 Jul 2006 17:41:36 -0000	1.5
+++ modules/sections/sections.install	21 Jul 2007 22:20:09 -0000
@@ -6,18 +6,17 @@
     case 'mysql':
     case 'mysqli':
       db_query("CREATE TABLE {sections_data} (
-                `sid` int(10) default NULL,
-                `name` text,
-                `status` smallint(1) default '0',
-                `path` text,
-                `template` text,
-                `visibility` smallint(1) default '0',
-                `weight` int(10) default NULL
-                ) ENGINE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
-      $id = db_next_id('sections_id');
-      db_query("INSERT INTO {sections_data} VALUES (%d,'Admin',1,'admin\nadmin/*','bluemarine',1,-10);", $id);
+                sid int(10) default NULL,
+                name text,
+                status smallint(1) default '0',
+                path text,
+                template text,
+                visibility smallint(1) default '0',
+                weight int(10) default NULL
+                ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
       break;
     case 'pgsql':
+      // TODO
       break;
   }
 }
@@ -26,12 +25,19 @@
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
-      db_query("ALTER TABLE {sections_data} ADD `visibility` smallint(1) default '0';");
-      db_query("ALTER TABLE {sections_data} ADD `weight` int(10) default '0';");
+      db_query("ALTER TABLE {sections_data} ADD visibility smallint(1) default '0';");
+      db_query("ALTER TABLE {sections_data} ADD weight int(10) default '0';");
       break;
   }
 }
 
 function sections_update_2() {
   return _system_update_utf8(array('sections_data'));
-}
\ No newline at end of file
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function sections_uninstall() {
+  db_query('DROP TABLE {sections_data}');
+}
Index: modules/sections/sections.info
===================================================================
RCS file: modules/sections/sections.info
diff -N modules/sections/sections.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/sections/sections.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,3 @@
+; $Id$
+name = Sections
+description = "Allows you to define sections of your site and apply themes to those sections."
