예제 #1
0
파일: Tales.php 프로젝트: jeko/pksworld
        return call_user_func($callback, $expression, $nothrow);
    }
    // class method
    if (strpos($typePrefix, '.')) {
        $classCallback = explode('.', $typePrefix, 2);
        $callbackName = NULL;
        if (!is_callable($classCallback, FALSE, $callbackName)) {
            throw new PHPTAL_ParserException(sprintf('Unknown phptal modifier %s. Function %s does not exists or is not statically callable.', $typePrefix, $callbackName));
        }
        $ref = new ReflectionClass($classCallback[0]);
        if (!$ref->implementsInterface('PHPTAL_Tales')) {
            throw new PHPTAL_ParserException(sprintf('Unable to use phptal modifier %s as the class %s does not implement the PHPTAL_Tales interface.', $typePrefix, $callbackName));
        }
        return call_user_func($classCallback, $expression, $nothrow);
    }
    // check if it is implemented via code-generating function
    $func = 'phptal_tales_' . str_replace('-', '_', $typePrefix);
    if (function_exists($func)) {
        return $func($expression, $nothrow);
    }
    // check if it is implemented via runtime function
    $runfunc = 'phptal_runtime_tales_' . str_replace('-', '_', $typePrefix);
    if (function_exists($runfunc)) {
        return "{$runfunc}(" . phptal_tale($expression, $nothrow) . ")";
    }
    throw new PHPTAL_ParserException("Unknown phptal modifier '{$typePrefix}'. Function '{$func}' does not exist");
}
// Register internal Tales expression modifiers
require_once PHPTAL_DIR . 'PHPTAL/Php/TalesInternal.php';
PHPTAL_TalesInternal::registerInternalTales();
예제 #2
0
/**
 * This modifier will return a formatted date string
 * usage:
 *      midcomdate_short: path/to/my/timestamp
 *
 * Formarts date with config var ['date_formats']['long']
 */
function phptal_tales_midcomDateRfc($src, $nothrow)
{
    $src = trim($src);
    return 'date(DATE_RFC3339, strtotime(' . PHPTAL_TalesInternal::path($src, $nothrow) . '))';
}
예제 #3
0
파일: State.php 프로젝트: jeko/pksworld
 public function interpolateTalesVarsInHtml($src)
 {
     if ($this->_talesMode == 'tales') {
         $result = preg_replace_callback('/(?<!\\$)\\$\\{structure (.*?)\\}/ism', array($this, '_interpolateTalesVarsStructure'), $src);
         $result = preg_replace_callback('/(?<!\\$)\\$\\{(.*?)\\}/ism', array($this, '_interpolateTalesVarsEscaped'), $result);
         $result = str_replace('$${', '${', $result);
         return $result;
     }
     while (preg_match('/(?<!\\$)\\${(structure )?([^\\}]+)\\}/ism', $src, $m)) {
         list($ori, $struct, $exp) = $m;
         $php = PHPTAL_TalesInternal::php($exp);
         // when structure keyword is specified the output is not html
         // escaped
         if ($struct) {
             $repl = '<?php echo ' . $php . '; ?>';
         } else {
             $repl = '<?php echo ' . $this->htmlchars($php) . '; ?>';
         }
         $src = str_replace($ori, $repl, $src);
     }
     return str_replace('$${', '${', $src);
 }