예제 #1
0
파일: www.php 프로젝트: nyan-cat/easyweb
 static function create($options)
 {
     if (isset($options->cache)) {
         $cache = $options->cache . 'cache.tmp';
         if ($www = fs::read($cache)) {
             $www = unserialize($www);
             $www->locale->setup($options->language, $options->country);
             return $www;
         } else {
             $www = new www($options);
             fs::write($cache, serialize($www));
             return $www;
         }
     } else {
         return new www($options);
     }
 }
예제 #2
0
파일: www.php 프로젝트: nyan-cat/easyweb
 static function create($options)
 {
     if (isset($options->cache)) {
         $cache = $options->cache . 'cache.tmp';
         if ($www = fs::read($cache)) {
             $www = unserialize($www);
             $www->bind();
             return $www;
         } else {
             $www = new www($options);
             fs::write($cache, serialize($www));
             $www->bind();
             return $www;
         }
     } else {
         $www = new www($options);
         $www->bind();
         return $www;
     }
 }
예제 #3
0
파일: www.php 프로젝트: nyan-cat/easyweb
 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);
     }
 }