00001 <?php
00002
00003
00004
00005
00006 class context_condition_path extends context_condition {
00007
00008
00009
00010 function condition_values() {
00011 return array();
00012 }
00013
00014
00015
00016
00017 function condition_form($context) {
00018 $form = parent::condition_form($context);
00019 unset($form['#options']);
00020
00021 $form['#type'] = 'textarea';
00022 $form['#default_value'] = implode("\n", $this->fetch_from_context($context, 'values'));
00023 return $form;
00024 }
00025
00026
00027
00028
00029 function condition_form_submit($values) {
00030 $parsed = array();
00031 $items = explode("\n", $values);
00032 if (!empty($items)) {
00033 foreach ($items as $v) {
00034 $v = trim($v);
00035 if (!empty($v)) {
00036 $parsed[$v] = $v;
00037 }
00038 }
00039 }
00040 return $parsed;
00041 }
00042
00043
00044
00045
00046 function execute() {
00047 if ($this->condition_used()) {
00048
00049 $current_path = array(drupal_get_path_alias($_GET['q']));
00050 if ($current_path[0] != $_GET['q']) {
00051 $current_path[] = $_GET['q'];
00052 }
00053 foreach ($this->get_contexts() as $context) {
00054 $paths = $this->fetch_from_context($context, 'values');
00055 if ($this->match($current_path, $paths, TRUE)) {
00056 $this->condition_met($context);
00057 }
00058 }
00059 }
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 protected function match($subject, $patterns, $path = FALSE) {
00078 static $regexps;
00079 $match = FALSE;
00080 $positives = $negatives = 0;
00081 $subject = !is_array($subject) ? array($subject) : $subject;
00082 foreach ($patterns as $pattern) {
00083 if (strpos($pattern, '~') === 0) {
00084 $negate = TRUE;
00085 $negatives++;
00086 }
00087 else {
00088 $negate = FALSE;
00089 $positives++;
00090 }
00091 $pattern = ltrim($pattern, '~');
00092 if (!isset($regexps[$pattern])) {
00093 if ($path) {
00094 $regexps[$pattern] = '/^(' . preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\2'), preg_quote($pattern, '/')) . ')$/';
00095 }
00096 else {
00097 $regexps[$pattern] = '/^(' . preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/'), array('|', '.*'), preg_quote($pattern, '/')) . ')$/';
00098 }
00099 }
00100 foreach ($subject as $value) {
00101 if (preg_match($regexps[$pattern], $value)) {
00102 if ($negate) {
00103 return FALSE;
00104 }
00105 $match = TRUE;
00106 }
00107 }
00108 }
00109
00110
00111 if ($positives === 0 && $negatives) {
00112 return TRUE;
00113 }
00114 return $match;
00115 }
00116 }