--- nodeteaser.module	Thu Jan  4 06:34:24 2007
+++ nodeteaser-phpcode_for_visibility.module	Thu Jan  4 06:36:38 2007
@@ -183,31 +183,43 @@ function nodeteaser_settings() {
   if (!user_access("administer nodeteaser")) {
     return message_access();
   }
- 	$form['nodeteaser_readmore'] = array('#type' => 'checkbox',
-		'#title' => t('"continue reading" link'), 
-		'#default_value' => variable_get("nodeteaser_readmore", FALSE), 
-		'#description' => t('Display a "continue reading" link below teasers'), 
-		'#required' => FALSE,
-		'#weight' => 0
-	);
-	
-	$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>')));
-
-	$form['nodeteaser_access'] = array(
-		'#type' => 'radios', 
-		'#title' => t('Show Teaser on specific pages'), 
-		'#default_value' => variable_get('nodeteaser_access', 1), 
-		'#options' => $options
-	);
-	$form['nodeteaser_access_pages'] = array(
-		'#type' => 'textarea', 
-		'#title' => t('Pages'), 
-		'#default_value' => variable_get('nodeteaser_access_pages', ''), 
-		'#description' => $description
-	);
-	
-	return $form;
+  
+  $form['nodeteaser_readmore'] = array('#type' => 'checkbox',
+    '#title' => t('"continue reading" link'), 
+    '#default_value' => variable_get("nodeteaser_readmore", FALSE), 
+    '#description' => t('Display a "continue reading" link below teasers'), 
+    '#required' => FALSE,
+    '#weight' => 0,
+  );
+
+  // Check if user has permission to 'use PHP for block visibility' 
+  // in Administer > access control > block
+  $access = user_access('use PHP for block visibility');
+
+  $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>')));
+
+  // If user does not have access to PHP code for visibility in Administer > access control > block,
+  // radio button option for 'PHP for visibility' and description won't appear
+  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 ?>')));
+  }
+
+  $form['nodeteaser_access'] = array(
+    '#type' => 'radios', 
+    '#title' => t('Show Teaser on specific pages'), 
+    '#default_value' => variable_get('nodeteaser_access', 1), 
+    '#options' => $options,
+  );
+  $form['nodeteaser_access_pages'] = array(
+    '#type' => 'textarea', 
+    '#title' => t('Pages'), 
+    '#default_value' => variable_get('nodeteaser_access_pages', ''), 
+    '#description' => $description,
+  );
+
+  return $form;
 }
 
 /**
@@ -219,15 +231,25 @@ function nodeteaser_settings() {
 function _nodeteaser_page_match() {
   $page_match = "FALSE";
 
+  // If one of the options to control nodeteaser visibility was selected
   if (variable_get('nodeteaser_access_pages', '')) {
-		$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(variable_get('nodeteaser_access_pages', ''), '/')) .')$/';
-		$page_match = !(variable_get('nodeteaser_access', 1) xor preg_match($regexp, $path));
+    // If the PHP option wasn't selected
+    if (variable_get('nodeteaser_access', 1)< 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(variable_get('nodeteaser_access_pages', ''), '/')) .')$/';
+      $page_match = !(variable_get('nodeteaser_access', 1) xor preg_match($regexp, $path));
+    }
+    // If the PHP option was selected 
+    else {
+      $page_match = drupal_eval(variable_get('nodeteaser_access_pages', ''));
+    }
   }
-  // No pages were specified to block so show on all
+  // If no options to control nodeteaser visibility are selected,
+  // visibility defaults to show nodeteaser on every page
   else {
     $page_match = "TRUE";
   }
-  return $page_match;
+    return $page_match;
 }
+
 ?>
