public function resolve(OOTemplate_Context $context) { $resolved = $this->_variable->resolve($context); foreach (explode('|', $this->_filters) as $filter) { $filter = trim($filter); if (!empty($filter)) { @(list($filter_name, $str_args) = explode(':', $filter, 2)); try { $args = array(); foreach (explode(',', $str_args) as $arg) { switch (strpos($arg, "'") || strpos($arg, '"')) { case true: $args[] = trim($arg, '\'" '); break; case false: $args[] = new OOTemplate_Variable($arg); break; } } $resolved = OOTemplate_Libs::filter($filter_name, $resolved, $args)->resolve($context); } catch (OOTemplate_Exception $e) { OOTemplate_Debug::show($e->getMessage()); } } } return $resolved; }
*/ require_once 'OOTemplate_Exception.php'; require_once 'OOTemplate_Setting.php'; require_once 'OOTemplate_Context.php'; class OOTemplate_Libs { protected static $_filters = array(); public static function setFilter($name, $path) { self::$_filters[$name] = $path; } public static function filter($name, $var, $args) { if (!array_key_exists($name, self::$_filters)) { throw new OOTemplate_Exception(sprintf("Invalid filter: '%s'", $name)); } require_once self::$_filters[$name]; return new $name($var, $args); } public static function buildFilters($path) { $path = rtrim($path, '\\/ '); if (file_exists($path)) { foreach (scandir($path) as $file) { self::setFilter(substr($file, 0, -4), $path . '/' . $file); } } } } OOTemplate_Libs::buildFilters(dirname(__FILE__) . '/filters');