Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.641
diff -u -r1.641 common.inc
--- includes/common.inc	15 May 2007 20:19:47 -0000	1.641
+++ includes/common.inc	21 May 2007 02:01:18 -0000
@@ -24,6 +24,10 @@
  */
 define('SAVED_DELETED', 3);
 
+define('PAGE_MATCH_ALL_BUT_LISTED', 0);
+define('PAGE_MATCH_ONLY_LISTED', 1);
+define('PAGE_MATCH_PHP', 2);
+
 /**
  * Set content for a specified region.
  *
@@ -1382,31 +1386,6 @@
 }
 
 /**
- * Evaluate a string of PHP code.
- *
- * This is a wrapper around PHP's eval(). It uses output buffering to capture both
- * returned and printed text. Unlike eval(), we require code to be surrounded by
- * <?php ?> tags; in other words, we evaluate the code as if it were a stand-alone
- * PHP file.
- *
- * Using this wrapper also ensures that the PHP code which is evaluated can not
- * overwrite any variables in the calling code, unlike a regular eval() call.
- *
- * @param $code
- *   The code to evaluate.
- * @return
- *   A string containing the printed output of the code, followed by the returned
- *   output of the code.
- */
-function drupal_eval($code) {
-  ob_start();
-  print eval('?>'. $code);
-  $output = ob_get_contents();
-  ob_end_clean();
-  return $output;
-}
-
-/**
  * Returns the path to a system item (module, theme, etc.).
  *
  * @param $type
@@ -2209,6 +2188,44 @@
 
 
 /**
+ * Determine if an item should display on the current page.
+ *
+ * @param $visibility
+ *   Method to be used to determine visibility; one of the three constant:
+ *   - PAGE_MATCH_ALL_BUT_LISTED: Show on all pages except those listed.
+ *   - PAGE_MATCH_ONLY_LISTED: Show only on listed pages.
+ *   - PAGE_MATCH_PHP: show if a PHP expression evaluates to TRUE.
+ * @param $pages
+ *   The pages on which the item should or should not display, or a PHP
+ *   code block.
+ *
+ * @return
+ *   Boolean indicating if the item should display.
+ */
+function drupal_page_match($visibility, $pages) {
+  if ($visibility < PAGE_MATCH_PHP) {
+    $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($pages, '/')) .')$/';
+    // Compare with the internal and path alias (if any).
+    $page_match = preg_match($regexp, $path);
+    if ($path != $_GET['q']) {
+      $page_match = $page_match || preg_match($regexp, $_GET['q']);
+    }
+    // When $visibility has a value of 0, the item is displayed on
+    // all pages except those listed in $pages. When set to 1, it
+    // is displayed only on those pages listed in $pages.
+    $page_match = !($visibility xor $page_match);
+  }
+  elseif (module_exists('php')) {
+    $page_match = drupal_eval($pages);
+  }
+  else {
+    $page_match = FALSE;
+  }
+  return $page_match;
+}
+
+/**
  * Renders HTML given a structured array tree. Recursively iterates over each
  * of the array elements, generating HTML code. This function is usually
  * called from within a another function, like drupal_get_form() or node_view().
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.261
diff -u -r1.261 block.module
--- modules/block/block.module	20 May 2007 16:40:20 -0000	1.261
+++ modules/block/block.module	21 May 2007 02:22:39 -0000
@@ -63,7 +63,7 @@
  * Implementation of hook_perm().
  */
 function block_perm() {
-  return array('administer blocks', 'use PHP for block visibility');
+  return array('administer blocks');
 }
 
 /**
@@ -456,38 +456,8 @@
     '#description' =>  t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
   );
 
-  $form['page_vis_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Page specific visibility settings'),
-    '#collapsible' => TRUE,
-  );
-  $access = user_access('use PHP for block visibility');
-
-  if ($edit['visibility'] == 2 && !$access) {
-    $form['page_vis_settings'] = array();
-    $form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => 2);
-    $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $edit['pages']);
-  }
-  else {
-    $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' => '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' => '<?php ?>'));
-    }
-    $form['page_vis_settings']['visibility'] = array(
-      '#type' => 'radios',
-      '#title' => t('Show block on specific pages'),
-      '#options' => $options,
-      '#default_value' => $edit['visibility'],
-    );
-    $form['page_vis_settings']['pages'] = array(
-      '#type' => 'textarea',
-      '#title' => t('Pages'),
-      '#default_value' => $edit['pages'],
-      '#description' => $description,
-    );
+  if (module_exists('php')) {
+    $form += php_page_match_form($edit['visibility'], $edit['pages']);
   }
 
   $form['submit'] = array(
@@ -703,27 +673,7 @@
       }
 
       // Match path if necessary
-      if ($block->pages) {
-        if ($block->visibility < 2) {
-          $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($block->pages, '/')) .')$/';
-          // Compare with the internal and path alias (if any).
-          $page_match = preg_match($regexp, $path);
-          if ($path != $_GET['q']) {
-            $page_match = $page_match || preg_match($regexp, $_GET['q']);
-          }
-          // When $block->visibility has a value of 0, the block is displayed on
-          // all pages except those listed in $block->pages. When set to 1, it
-          // is displayed only on those pages listed in $block->pages.
-          $page_match = !($block->visibility xor $page_match);
-        }
-        else {
-          $page_match = drupal_eval($block->pages);
-        }
-      }
-      else {
-        $page_match = TRUE;
-      }
+      $page_match = $block->pages ? drupal_page_match($block->visibility, $block->pages) : TRUE;
 
       if ($enabled && $page_match) {
         // Check the current throttle status and see if block should be displayed
Index: modules/php/php.info
===================================================================
RCS file: /cvs/drupal/drupal/modules/php/php.info,v
retrieving revision 1.1
diff -u -r1.1 php.info
--- modules/php/php.info	24 Apr 2007 10:54:34 -0000	1.1
+++ modules/php/php.info	21 May 2007 02:11:18 -0000
@@ -1,5 +1,5 @@
 ; $Id: php.info,v 1.1 2007/04/24 10:54:34 dries Exp $
-name = PHP filter
-description = Allows embedded PHP code/snippets to be evaluated.
+name = PHP
+description = Allows embedded PHP code/snippets to be evaluated and PHP to be used for settings.
 package = Core - optional
 version = VERSION
Index: modules/php/php.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/php/php.install,v
retrieving revision 1.1
diff -u -r1.1 php.install
--- modules/php/php.install	24 Apr 2007 10:54:34 -0000	1.1
+++ modules/php/php.install	21 May 2007 02:36:59 -0000
@@ -19,6 +19,17 @@
 
     drupal_set_message(t('A !php-code input format has been created.', array('!php-code' => l('PHP code', 'admin/settings/filters/'. $format))));
   }
+  // Old installs may not have this module and so may need the update.
+  php_update_1();
+}
+
+/**
+ * Update existing installs to change old block-specific permission to new PHP one.
+ */
+function php_update_1() {
+  $ret = array();
+  $ret[] = update_sql("UPDATE {permission} set perm = replace(perm,'use PHP for block visibility','use PHP for settings')");
+  return $ret;
 }
 
 /**
Index: modules/php/php.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/php/php.module,v
retrieving revision 1.1
diff -u -r1.1 php.module
--- modules/php/php.module	24 Apr 2007 10:54:34 -0000	1.1
+++ modules/php/php.module	21 May 2007 01:54:24 -0000
@@ -53,6 +53,13 @@
 }
 
 /**
+ * Implementation of hook_perm().
+ */
+function php_perm() {
+  return array('use PHP for settings');
+}
+
+/**
  * Implementation of hook_filter(). Contains a basic PHP evaluator.
  *
  * Executes PHP code. Use with care.
@@ -72,3 +79,84 @@
       return $text;
   }
 }
+
+/**
+ * Output a page match form.
+ *
+ * This function returns a form fragment for matching pages.
+ *
+ * @param $visibility
+ *   Method to be used to determine visibility; one of the three constant:
+ *   - PAGE_MATCH_ALL_BUT_LISTED: Show on all pages except those listed.
+ *   - PAGE_MATCH_ONLY_LISTED: Show only on listed pages.
+ *   - PAGE_MATCH_PHP: show if a PHP expression evaluates to TRUE.
+ * @param $pages
+ *   The pages on which the item should or should not display, or a PHP
+ *   code block.
+ *
+ * @return
+ *   The form.
+ */
+function php_page_match_form($visibility, $pages) {
+  $access = user_access('use PHP for settings');
+  $form = array();
+
+  $form['page_vis_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Page specific visibility settings'),
+    '#collapsible' => TRUE,
+  );
+
+  if ($visibility == PAGE_MATCH_PHP && !$access) {
+    $form['page_vis_settings'] = array();
+    $form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => PAGE_MATCH_PHP);
+    $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $pages);
+  }
+  else {
+    $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' => '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' => '<?php ?>'));
+    }
+    $form['page_vis_settings']['visibility'] = array(
+      '#type' => 'radios',
+      '#title' => t('Show block on specific pages'),
+      '#options' => $options,
+      '#default_value' => $visibility,
+    );
+    $form['page_vis_settings']['pages'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Pages'),
+      '#default_value' => $pages,
+      '#description' => $description,
+    );
+  }
+  return $form;
+}
+
+/**
+ * Evaluate a string of PHP code.
+ *
+ * This is a wrapper around PHP's eval(). It uses output buffering to capture both
+ * returned and printed text. Unlike eval(), we require code to be surrounded by
+ * <?php ?> tags; in other words, we evaluate the code as if it were a stand-alone
+ * PHP file.
+ *
+ * Using this wrapper also ensures that the PHP code which is evaluated can not
+ * overwrite any variables in the calling code, unlike a regular eval() call.
+ *
+ * @param $code
+ *   The code to evaluate.
+ * @return
+ *   A string containing the printed output of the code, followed by the returned
+ *   output of the code.
+ */
+function drupal_eval($code) {
+  ob_start();
+  print eval('?>'. $code);
+  $output = ob_get_contents();
+  ob_end_clean();
+  return $output;
+}
\ No newline at end of file
