示例#1
0
 public function should_be_able_to_register_tag_using_alias()
 {
     h2o::addTag(array('sample' => 'Sample_Tag', 's' => 'Sample_Tag'));
     expects(h2o::$tags)->should_contain('Sample_Tag');
     expects(isset(h2o::$tags['s']))->should_be_true();
     unset(h2o::$tags['sample'], h2o::$tags['s']);
     h2o::addTag(array('sample', 's' => 'Sample_Tag'));
     expects(h2o::$tags)->should_contain('Sample_Tag');
     expects(isset(h2o::$tags['s']))->should_be_true();
     unset(h2o::$tags['sample'], h2o::$tags['s']);
 }
示例#2
0
<?php

class Site_Tag extends Tag
{
    function render($context, $stream)
    {
        $stream->write('This is my site');
    }
}
h2o::addTag('site');
示例#3
0
        }
        return $images;
    }
    function render($context, $stream)
    {
        $cache = h2o_cache($context->options);
        $term = $context->resolve(':term');
        $hack = $context->resolve(':hack');
        $url = $this->get_api_url($term, $hack);
        $feed = @$this->fetch($context, $url);
        $feed = @$this->filter($feed);
        $context->set("images", $feed);
        $context->set("is_single_image", $this->is_single_image());
    }
    function fix_json($j)
    {
        $j = trim($j);
        $j = ltrim($j, '(');
        $j = rtrim($j, ')');
        $a = preg_split('#(?<!\\\\)\\"#', $j);
        for ($i = 0; $i < count($a); $i += 2) {
            $s = $a[$i];
            $s = preg_replace('#([^\\s\\[\\]\\{\\}\\:\\,]+):#', '"\\1":', $s);
            $a[$i] = $s;
        }
        $j = implode('"', $a);
        return $j;
    }
}
h2o::addTag('image');
示例#4
0
        }
        return $filtered_feed;
    }
    function render($context, $stream)
    {
        $cache = h2o_cache($context->options);
        $term = $context->resolve(':term');
        $hack = $context->resolve(':hack');
        $url = $this->get_api_url($term, $hack);
        $feed = @$this->fetch($context, $url)->xpath('//channel/item');
        $feed = @$this->filter($feed);
        $context->set("api", $feed);
        $context->set("api_url", $url);
    }
}
h2o::addTag('api');
function filter_bad_words($content)
{
    global $spp_settings;
    $bad_words = explode(',', $spp_settings->bad_words);
    foreach ($bad_words as $word) {
        // mulai ubah konten
        $content = str_ireplace($word . ' ', '', $content);
        $content = str_ireplace(' ' . $word . ' ', '', $content);
        $content = str_ireplace(' ' . $word, '', $content);
        $content = str_ireplace($word, '.', $content);
        $content = str_ireplace($word, ',', $content);
        $content = str_ireplace($word, '-', $content);
    }
    return $content;
}
示例#5
0
    {
        if (!empty($argstring) && !preg_match($this->syntax, $argstring)) {
            throw TemplateSyntaxError('Please specify time to live value for this cache block');
        }
        $this->body = $parser->parse('endcache');
        $this->uid = md5($parser->filename . $pos);
        $this->ttl = (int) $argstring;
        $options = $parser->options;
        if ($this->ttl) {
            $options['cache_ttl'] = $this->ttl;
        }
        if (!$options['cache']) {
            $options['cache'] = 'file';
        }
        $this->cache = h2o_cache($options);
    }
    function render($context, $stream)
    {
        if ($output = $this->cache->read($this->uid)) {
            $stream->write($output);
            return;
        }
        $output = new StreamWriter();
        $this->body->render($context, $output);
        $output = $output->close();
        $this->cache->write($this->uid, $output);
        $stream->write($output);
    }
}
h2o::addTag('cache');
示例#6
0
                        if (method_exists($obj, $attribute)) {
                            $obj = call_user_func_array(array($obj, $attribute), array());
                        } else {
                            if (method_exists($obj, "get_" . $attribute)) {
                                $obj = call_user_func_array(array($obj, "get_" . $attribute), array());
                            } else {
                                if (method_exists($obj, "is_" . $attribute)) {
                                    $obj = call_user_func_array(array($obj, "is_" . $attribute), array());
                                } else {
                                    $obj = null;
                                }
                            }
                        }
                    }
                } else {
                    $obj = null;
                    break;
                }
            }
        }
    }
    return $obj;
}
h2o::addTag(array("sqlvalue"));
h2o::addTag(array("sparqlvalue"));
h2o::addTag(array("tplnotice"));
h2o::addFilter(array('pmb_StringFilters'));
h2o::addFilter(array('pmb_DateFilters'));
H2o::addLookup("messagesLookup");
H2o::addLookup("globalLookup");
H2o::addLookup("recursive_lookup");
示例#7
0
<?php

h2o::addTag('lorem');
class Lorem_Tag extends H2o_Node
{
    private $common = true;
    private $syntax = '/^(\\d+)?(?:\\s+(p|w))?(?:\\s?(random))?$/i';
    var $hint = "{% lorem [count] [format] [random]%}";
    function __construct($argstring, $parser, $position = 0)
    {
        if (!preg_match($this->syntax, trim($argstring), $match)) {
            throw new TemplateSyntaxError($this->hint);
        }
        @(list(, $count, $mode, $random) = $match);
        $this->count = $count ? $count : 1;
        $this->mode = $mode ? $mode : 'p';
        $this->common = !$random;
    }
    function render($context, $stream)
    {
        $output = '';
        switch ($this->mode) {
            case 'w':
                $output = lorem_words($this->count);
                break;
            case 'p':
                $output = "<p>" . join("</p>\n<p>", lorem_paragraphs($this->count, $this->common)) . '</p>';
                break;
        }
        $stream->write($output);
    }
示例#8
0
<?php

# For compatibility with Django.
class Admin_media_prefix_Tag extends H2o_Node
{
    function render($context, $stream)
    {
        $stream->write("/media/");
    }
}
h2o::addTag('admin_media_prefix');
示例#9
0
文件: i18n.php 项目: hbasria/pjango
<?php

h2o::addTag('trans');
h2o::addTag('blocktrans');
h2o::addLookup(array('H2o_I18n', 'gettext'));
class Trans_Tag extends H2o_Node
{
    var $text = null;
    function __construct($argstring, $parser, $position = 0)
    {
        $this->args = H2o_Parser::parseArguments($argstring);
        $this->text = stripcslashes(substr($argstring, 1, -1));
    }
    function render($context, $stream)
    {
        $argPrefix = substr($this->args[0], 0, 1);
        if ($argPrefix == ':') {
            $message = $context->resolve($this->args[0]);
        } else {
            $message = $this->text;
            $message = str_replace("'", '', $message);
            $message = str_replace('"', '', $message);
        }
        if ($message) {
            $stream->write(pjango_gettext($message));
        }
    }
}
class Blocktrans_Tag extends H2o_Node
{
    private $singular, $plural;
示例#10
0
文件: video.php 项目: gigikir/adebe
    }
    function __construct($argstring, $parser, $pos = 0)
    {
        list($this->term, $this->hack) = explode(' ', $argstring);
    }
    function get_api_url($term = 'hello world', $hack = "")
    {
        $term .= " " . $hack;
        $term = urlencode($term);
        return "http://www.bing.com/search?q={$term}&format=rss";
    }
    function fetch($context, $url)
    {
        $this->url = $url;
        $feed = @file_get_contents($this->url);
        $feed = @simplexml_load_string($feed);
        return $feed;
    }
    function render($context, $stream)
    {
        $cache = h2o_cache($context->options);
        $term = $context->resolve(':term');
        $hack = 'site:youtube.com';
        $url = $this->get_api_url($term, $hack);
        $feed = @$this->fetch($context, $url)->xpath('//channel/item');
        $context->set("videos", $feed);
        $context->set("is_single_video", $this->is_single_video());
    }
}
h2o::addTag('video');
示例#11
0
<?php

h2o::addTag('gravatar');
class Gravatar_Tag extends H2o_Node
{
    private $email;
    private $img_size;
    function __construct($argstring, $parser, $pos = 0)
    {
        if (!empty($argstring)) {
            $args = explode(" ", trim($argstring));
            $this->email = strtolower($args[0]);
            $this->img_size = $args[1] ? $args[1] : 80;
            if (is_numeric($this->email)) {
                $this->img_size = $this->email;
                $this->email = '';
            }
            /*
             * TODO Fix to manage custom default image
             */
        } else {
            $this->img_size = 80;
        }
    }
    function render($context, $stream)
    {
        $context->push();
        if (substr($this->email, 0, 1) == ":") {
            $this->email = $context->resolve($this->email);
        }
        $output = '<img src="http://www.gravatar.com/avatar/' . (!empty($this->email) ? md5($this->email) . '.jpg' : '') . '?s=' . $this->img_size . '" alt="gravatar-image"/>';
示例#12
0
            $context->set($this->struct_name, 0);
        }
    }
}
class Sparqlvalue_Tag extends H2o_Node
{
    private $struct_name;
    private $endpoint;
    function __construct($argstring, $parser, $position)
    {
        $params = explode(" ", $argstring);
        $this->struct_name = $params[0];
        $this->endpoint = $params[1];
        $this->sparql_query = $parser->parse('endsparqlvalue');
    }
    function render($context, $stream)
    {
        global $dbh;
        global $class_path;
        $query_stream = new StreamWriter();
        $this->sparql_query->render($context, $query_stream);
        $query = $query_stream->close();
        require_once "{$class_path}/rdf/arc2/ARC2.php";
        $config = array('remote_store_endpoint' => $this->endpoint, 'remote_store_timeout' => 10);
        $store = ARC2::getRemoteStore($config);
        $context->set($this->struct_name, $store->query($query, 'rows'));
    }
}
h2o::addTag(array("sqlvalue"));
h2o::addTag(array("sparqlvalue"));
h2o::addFilter(array('pmb_StringFilters'));