Example #1
0
 /**
  * Sets the available option in the facet, from the settings that are
  * passed to the constructor.  Uses either a 'values' key or a number
  * of keys of the name format 'value 1', 'value 2', etc.
  *
  * @param array hash
  */
 function setOptions($options)
 {
     if (isset($options['values'])) {
         loader_import('saf.Misc.Shorthand');
         $sh = new PHPShorthand();
         $o = eval(CLOSE_TAG . OPEN_TAG . ' return (' . $sh->transform($options['values']) . ');' . CLOSE_TAG);
         foreach ($o as $k => $v) {
             $o[$v] = strtoupper($v);
             unset($o[$k]);
         }
         $this->options = $o;
         unset($options['values']);
     } else {
         $o = array();
         foreach ($options as $k => $v) {
             if (strpos($k, 'value ') === 0) {
                 $o[$v] = ucfirst($v);
                 unset($options[$k]);
             }
         }
         $this->options = $o;
     }
     foreach ($options as $k => $v) {
         if ($k == 'fields') {
             continue;
         }
         $this->{$k} = $v;
     }
 }
Example #2
0
 function evaluate($string, $node, $default_type = 'path', $carry = true)
 {
     $this->register['attrs'] = $node['attributes'];
     $this->register['paths'] = isset($node['paths']) ? $node['paths'] : array();
     if (!$carry) {
         $this->register['loop'] = false;
         $this->register['repeat'] =& $this->register['loop'];
     }
     $this->node = $node;
     $this->defaultMode = $default_type;
     $this->out = '';
     $this->buffer = array(array());
     $this->bcount = 0;
     $this->ccount = -1;
     $this->escape = false;
     $str = $this->parse($default_type . ':' . $string);
     $out = '';
     foreach ($this->buffer as $condition) {
         foreach ($condition as $element) {
             // element has [0] => type, [1] => contents
             if ($element[0] == 'string') {
                 $out .= $element[1];
             } elseif ($element[0] == 'php') {
                 //echo 'PHP: ' . htmlentities ($element[1]) . '<br />';
                 //ob_start ();
                 global $loader;
                 $loader->import('saf.Misc.Shorthand');
                 $sh = new PHPShorthand();
                 $sh->replaceGlobals('this->register');
                 $_original = $element[1];
                 $element[1] = $sh->transform($element[1]);
                 ob_start();
                 $res = eval(CLOSE_TAG . OPEN_TAG . ' $_return = (' . $element[1] . '); ' . CLOSE_TAG);
                 $err = ob_get_contents();
                 ob_end_clean();
                 if ($res === false) {
                     echo '<h2>Invalid Shorthand Expression:</h2><pre> ' . htmlentities($_original) . '</pre><h2>Evaluates To:</h2><pre>' . htmlentities($element[1]) . '</pre><h2>Error Message</h2>' . $err . '';
                     exit;
                 }
                 if ($_return === false || is_object($_return) || is_array($_return)) {
                     $out = $_return;
                     continue;
                 } else {
                     $out .= $_return;
                 }
             } elseif ($element[0] == 'path') {
                 $res =& $this->getPath(rtrim($element[1]));
                 if (is_string($res) || is_numeric($res)) {
                     $out .= $res;
                 } elseif ($res === false) {
                     $out = $res;
                     continue;
                 } else {
                     $out =& $res;
                     break;
                 }
             }
         }
         if ($out !== false) {
             return $out;
         }
     }
     return '';
 }
Example #3
0
 /**
  * Determines the value to return based on the
  * specified $obj and $var.
  * 
  * @access	public
  * @param	string	$var
  * @param	object	$obj
  * @return	mixed
  * 
  */
 function determine($var, $obj)
 {
     global $simple_template_register;
     if (strpos($var, 'loop ') === 0) {
         // start of loop
         // 1. parse
         $simple_template_register['obj'] = $obj;
         $v = str_replace('loop ', '', $var);
         if (isset($simple_template_register[$v])) {
             $res = $simple_template_register[$v];
         } else {
             loader_import('saf.Misc.Shorthand');
             $sh = new PHPShorthand();
             $sh->replaceGlobals('simple_template_register');
             $php = $sh->transform($v);
             $res = eval(CLOSE_TAG . OPEN_TAG . ' return (' . $php . '); ' . CLOSE_TAG);
         }
         if (!$res) {
             //$this->_loopList = array ();
             $this->_ignoreUntilEndLoop = true;
         } elseif (!is_array($res)) {
             $this->_loopList = array($res);
         } else {
             $this->_loopList = $res;
         }
         $this->_bufferUntilEndLoop = true;
         $this->_loopBuffer = '';
         $this->_structCount = 0;
     } elseif (strpos($var, 'if ') === 0) {
         // start of if
         if (str_replace('if ', '', $var) == 'else') {
             if (!isset($simple_template_register['else'])) {
                 $simple_template_register['else'] = 'true';
             }
             $php = '! (' . $simple_template_register['else'] . ')';
             unset($simple_template_register['else']);
         } else {
             loader_import('saf.Misc.Shorthand');
             $sh = new PHPShorthand();
             $sh->replaceGlobals('simple_template_register');
             $php = $sh->transform(str_replace('if ', '', $var));
             $simple_template_register['obj'] = $obj;
             $simple_template_register['else'] = $php;
         }
         $res = eval(CLOSE_TAG . OPEN_TAG . ' return (' . $php . '); ' . CLOSE_TAG);
         if (!$res) {
             $this->_ignoreUntilEndIf = true;
             $this->_structCount = 0;
         }
     } elseif (strpos($var, 'intl ') === 0) {
         return intl_get(str_replace('intl ', '', $var));
     } elseif (strpos($var, 'php ') === 0) {
         loader_import('saf.Misc.Shorthand');
         $sh = new PHPShorthand();
         $sh->replaceGlobals('simple_template_register');
         $php = $sh->transform(substr($var, 4));
         //str_replace ('php ', '', $var));
         $simple_template_register['obj'] = $obj;
         return eval(CLOSE_TAG . OPEN_TAG . ' return (' . $php . '); ' . CLOSE_TAG);
     } elseif (strpos($var, 'exec ') === 0) {
         // {php} but returns no output
         loader_import('saf.Misc.Shorthand');
         $sh = new PHPShorthand();
         $sh->replaceGlobals('simple_template_register');
         $php = $sh->transform(substr($var, 5));
         //str_replace ('exec ', '', $var));
         $simple_template_register['obj'] = $obj;
         @eval(CLOSE_TAG . OPEN_TAG . ' return (' . $php . '); ' . CLOSE_TAG);
     } elseif (strpos($var, 'alt ') === 0) {
         loader_import('saf.Misc.Alt');
         $simple_template_register['alt'] = new Alt(preg_split('/ +/', str_replace('alt ', '', $var)));
         return '';
     } elseif (strpos($var, 'filter ') === 0) {
         $this->filter = str_replace('filter ', '', $var);
     } elseif (strpos($var, '-- ') === 0 && strrpos($var, ' --') === strlen($var) - 3) {
         return '';
     }
     // end special cases
     /* order of precedence after special tags:
      * - check $obj before anything else
      * - check the register second
      * - check the global namespace third
      * - properties before methods
      * - objects/arrays before variables
      * - is it a function?
      * - is it a constant?
      * - if all else fails, return nothing
      */
     if (is_object($obj)) {
         if (isset($obj->{$var})) {
             return $obj->{$var};
         } elseif (method_exists($obj, $var)) {
             return $obj->{$var}();
         }
     } elseif (is_array($obj) && isset($obj[$var])) {
         return $obj[$var];
     }
     if ($var == 'obj') {
         return $obj;
     } elseif (count($simple_template_register) && in_array($var, array_keys($simple_template_register))) {
         return $simple_template_register[$var];
     }
     $original = $obj;
     list($obj, $var) = preg_split('/(\\.|:|\\/)/', $var);
     if (!empty($var)) {
         if (is_object($simple_template_register[$obj])) {
             if (isset($simple_template_register[$obj]->{$var})) {
                 return $simple_template_register[$obj]->{$var};
             } elseif (method_exists($simple_template_register[$obj], $var)) {
                 return $simple_template_register[$obj]->{$var}();
             } else {
                 return '';
             }
         } elseif (is_array($simple_template_register[$obj]) && isset($simple_template_register[$obj][$var])) {
             return $simple_template_register[$obj][$var];
         } elseif (is_object($GLOBALS[$obj])) {
             if (isset($GLOBALS[$obj]->{$var})) {
                 return $GLOBALS[$obj]->{$var};
             } elseif (method_exists($GLOBALS[$obj], $var)) {
                 return $GLOBALS[$obj]->{$var}();
             } else {
                 return '';
             }
         } elseif (is_array($GLOBALS[$obj]) && isset($GLOBALS[$obj][$var])) {
             return $GLOBALS[$obj][$var];
         } elseif (function_exists($obj)) {
             if (is_object($original) && isset($original->{$var})) {
                 return $obj($original->{$var});
             } elseif (is_array($original) && isset($original[$var])) {
                 return $obj($original[$var]);
             } else {
                 return $obj($var);
             }
         }
     } elseif (defined($obj)) {
         return constant($obj);
     }
     return '';
 }