private function replace_group($name, $args) { $args = stripslashes($args); $args = args::decode($args); $expression = $this->group($name, $args)->get($args); $expression = $this->vars->apply($expression, true); return preg_replace('/(([\\w:]+\\w)\\(([^\\)]*)\\))/e', "\$this->replace_query('\\1', '\\2')", $expression); }
function parse_query($expression, $document) { if (preg_match('/\\A([\\w:]+)\\(([^\\)]*)\\)\\Z/', $expression, $match)) { return $this->query($match[1], args::decode($match[2]), $document); } else { if (!isset($this->cache[$expression])) { $this->cache[$expression] = xml::load($expression); } return $this->cache[$expression]; } }
function load_template($config, $node) { if ($node) { $template = new template($node['@src'], args::decode($node->attribute('args', '')), $node->attribute('xml')); foreach ($config->query('template', $node) as $child) { $template->insert($child['@name'], load_template($config, $child)); } return $template; } else { return null; } }
private function replace_www($template, $document, $args = array()) { foreach ($document->query('//www:*') as $node) { $nested = null; switch ($node->name()) { case 'www:template': $nested = $this->render_template($template->get($node['@name'])); break; case 'www:xslt': $args = $node->attribute('args'); if ($node->attribute('cache') !== 'true') { $nested = $this->render_xslt($template, $node['@xsl'], $node['@xml'], $args ? args::decode($args) : array()); } else { $cache_args = $node->attribute('cache-args') ? $node->attribute('cache-args') : array(); $cache_lifetime = $node->attribute('cache-lifetime'); is_null($cache_lifetime) or is_numeric($cache_lifetime) or runtime_error('Cache lifetime should be numeric: ' . $cache_lifetime); $cache_args = args::decode($cache_args); $filename = cache_location . md5($node['@xsl'] . $node['@xml'] . ($args ? $args : '')) . '.xml'; if (!fs::exists($filename) || $cache_lifetime && $cache_lifetime > time() - fs::modification($filename)) { fs::write($filename, $this->render_xslt($template, $node['@xsl'], $node['@xml'], $args ? args::decode($args) : array())->render(false)); } $fragment = fs::checked_read($filename); if (!empty($cache_args)) { $fragment = vars::apply_assoc($fragment, $cache_args); } $nested = $document->fragment($fragment); } break; case 'www:xquery': require_once www_root . 'thirdparty/xquerylite/class_xquery_lite.php'; $xq = new XqueryLite(); $fragment = $xq->evaluate_xqueryl(fs::checked_read($node['@src'])); $nested = $document->fragment($fragment); break; case 'www:style': $src = $node['@src']; $nested = $document->element('link'); $nested['@rel'] = 'stylesheet'; $nested['@href'] = $src . '?' . fs::crc32($src); break; case 'www:script': $src = $node['@src']; $nested = $document->element('script', ''); $nested['@type'] = 'text/javascript'; $nested['@src'] = $src . '?' . fs::crc32($src); break; case 'www:img': $src = $node['@src']; $nested = $document->element('img'); $nested['@src'] = $src . '?' . crc32(fs::modification($src)); foreach ($node->attributes() as $name => $value) { if ($name != 'src') { $nested['@' . $name] = $value; } } break; case 'www:bbcode': $allow = $node->attribute('allow'); $deny = $node->attribute('deny'); $nested = bbcode::parse($node, $allow ? preg_split('/, */', $allow) : null, $deny ? preg_split('/, */', $deny) : null); break; default: runtime_error('Unknown extension element: ' . $node->name()); } self::replace_node($document, $node, $nested); } }
function wwwquery($name, $args) { return xslt::top()->query($name, args::decode($args))->get(); }