/**
     *
     */
    public function testRender()
    {
        $headTpl = <<<'EOD'
Meta
{multi}
{title}
Text
<a href="{link}">{linkText}</a>
{content:plain}
{multi} More text
EOD;
        $footTpl = <<<'EOD'
Foot
{multi}
More text {multi}
EOD;
        $templates = array('head' => $headTpl, 'foot' => $footTpl);
        $expectedHead = <<<'EOD'
Meta
Multi
Test SimpleTemplate
Text
<a href="http://example.net/?foo=1&amp;bar=2">&lt;&gt;&amp;&quot;&#039; äöü</a>
<pre>äöü</pre>
Multi More text
EOD;
        $expectedFoot = <<<'EOD'
Foot
Multi
More text Multi
EOD;
        $tpl = new SimpleTemplate($templates);
        $tpl->title = 'Test SimpleTemplate';
        $tpl->content = '<pre>äöü</pre>';
        $tpl->link = 'http://example.net/?foo=1&bar=2';
        $tpl->linkText = '<>&"\' äöü';
        $tpl->multi = 'Multi';
        $this->assertEquals($expectedHead, $tpl->render('head'));
        $this->assertEquals($expectedFoot, $tpl->render('foot'));
        $tpl->clearValues();
        $this->assertEquals($headTpl, $tpl->render('head'));
    }
Ejemplo n.º 2
0
 function _before()
 {
     $this->smarty = SimpleTemplate::getInstance();
     $this->urlParam = array_merge($_GET, $_POST);
     //重置country
     $host = $_SERVER['HTTP_HOST'];
     $host = explode('.', $host);
     if (!preg_match('/\\d/', $host[0])) {
         $this->country = $host[0];
     }
     //cms数据merge
     $this->cmsData();
 }
Ejemplo n.º 3
0
 /**
  * Inject a KittenAuth into the user login form after a failed
  * password attempt as a speedbump for mass attacks.
  * @fixme if multiple thingies insert a header, could break
  * @param SimpleTemplate $template
  * @return bool true to keep running callbacks
  */
 function onUserLoginForm(&$template)
 {
     wfDebug("KittenAuth: onUserLoginForm hook activated  \n");
     if ($this->isBadLoginTriggered()) {
         global $wgOut;
         $this->addCSS(&$wgOut);
         $template->set('header', "<div class='kittens'>" . $wgOut->parse($this->getMessage('badlogin')) . $this->getForm() . "</div> \n");
     }
     return true;
 }
 /**
  * Inject a captcha into the user login form after a failed
  * password attempt as a speedbump for mass attacks.
  * @fixme if multiple thingies insert a header, could break
  * @param SimpleTemplate $template
  * @return bool true to keep running callbacks
  */
 function injectUserLogin(&$template)
 {
     if ($this->isBadLoginTriggered()) {
         global $wgOut;
         $template->set('header', "<div class='captcha'>" . $wgOut->parse($this->getMessage('badlogin')) . $this->getForm() . "</div>\n");
     }
     return true;
 }
Ejemplo n.º 5
0
        $this->output .= $data;
    }
    function escape(&$parser, $data)
    {
        $this->output .= "<!{$data}>";
    }
    function pi(&$parser, $target, $data)
    {
        $this->output .= "<?{$target} {$data}?>";
    }
    function jasp(&$parser, $data)
    {
        $this->output .= "<%{$data}%>";
    }
}
$tpl = new SimpleTemplate();
$tpl->setVar('title', 'HTMLSax as a Template Parser');
$para1 = <<<EOD

HTMLSax can be used as the basis for a template engine, 
as with <a href="http://wact.sf.net">WACT</a> and 
<a href="http://phpoot.sourceforge.jp/">PHPOOT</a>. For 
the most part is allows you to preserve the structure of
original template, preserving whitespace and so on with
one or two minor exceptions, such as whitespace between
attributes and the quotes used for attributes. Compare
the source template for this example with the output.

EOD;
$tpl->setVar('para1', $para1);
$para2 = <<<EOD
Ejemplo n.º 6
0
 public function test_Replacing_with_own_marks()
 {
     $variables = array('bar' => 'hello', 'foo' => 'world', 'user.name' => 'Jasir', 'font-size' => '12px');
     $this->assertEquals('...hello world, Jasir! {%this.is.not.replaced%}, font-size: 12px', SimpleTemplate::replaceVariables('...{%bar%} {%foo%}, {%user.name%}! {%this.is.not.replaced%}, font-size: {%font-size%}', $variables, '{%', '%}'));
 }
Ejemplo n.º 7
0
 /**
  * Used internally by Merge, or may be called directly.
  * If a placeholder is in the template but there is no matching value,
  * it will be replaced with empty string and will NOT appear in the output.
  * 
  * @param string $template string with placeholder variables
  * @param mixed (array or object) $values an associative array or object with key/value pairs
  * @param string the left (opening) delimiter for placeholders. default = {{
  * @param string the right (closing) delimiter for placeholders. default = }}
  * @return string merged template
  */
 static function MergeRegEx($template, $values, $ldelim = "{{", $rdelim = "}}")
 {
     self::$_MERGE_TEMPLATE_VALUES = $values;
     if ($ldelim != "{{" || $rdelim != "}}") {
         throw new Exception("Custom delimiters are not yet implemented. Sorry!");
     }
     $results = preg_replace_callback('!\\{\\{(\\w+)\\}\\}!', 'SimpleTemplate::_MergeRegExCallback', $template);
     self::$_MERGE_TEMPLATE_VALUES = null;
     return $results;
 }
Ejemplo n.º 8
0
//include object in session BEFORE initializing the session
set_include_path(get_include_path() . PATH_SEPARATOR . 'application/conf/' . PATH_SEPARATOR . 'application/class/' . PATH_SEPARATOR . 'application/library/' . PATH_SEPARATOR . 'application/mvc/models/autoLoadedClass/');
require_once 'AutoLoader.php';
session_start();
setlocale(LC_TIME, "fr_FR.utf8");
header('Content-type: text/html; charset=UTF-8');
//test d'admin
if ($_POST["password"] != null && $_POST["login"] != null) {
    $xml = simplexml_load_file("application/conf/admin.xml");
    if ($_POST["password"] == $xml->Password["value"] && $_POST["login"] == $xml->Login["value"]) {
        $_SESSION["user"]->setRole("admin");
    } else {
        $_SESSION["user"]->setRole("guest");
    }
}
$tplEngine = new SimpleTemplate();
//initialize ACL
$_SESSION["user"] = $_SESSION["user"] == null ? new User() : $_SESSION["user"];
$tplEngine->initACL("application/conf/ACL.xml", $_SESSION["user"]->getRole());
//get MVC map
$pages = PageLoader::loadFromXML("application/conf/MVCMap.xml");
if (isset($_REQUEST["displayPage"]) && $_REQUEST["displayPage"] != "") {
    $displayPage = !is_null($pages[strtolower($_REQUEST["displayPage"])]) ? $pages[strtolower($_REQUEST["displayPage"])] : $pages["404"];
    define("MODEL", $displayPage["Model"]);
    define("VIEW", $displayPage["View"]);
    $page = $tplEngine->getPage($displayPage["Model"], $displayPage["View"]);
} else {
    define("MODEL", $pages['home']["Model"]);
    define("VIEW", $pages['home']["View"]);
    $page = $tplEngine->getPage($pages['home']["Model"], $pages['home']["View"]);
}
Ejemplo n.º 9
0
function node_pick_step1($request)
{
    global $config;
    // Cacti config object
    $host_id = -1;
    $overlib = false;
    $aggregate = false;
    $SQL_picklist = "SELECT graph_templates_graph.id, graph_local.host_id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache as description, graph_templates.name, graph_local.host_id\tFROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id ";
    if (isset($request['host_id'])) {
        $host_id = intval($request['host_id']);
        if ($host_id >= 0) {
            $SQL_picklist .= " and graph_local.host_id={$host_id} ";
        }
    }
    $SQL_picklist .= " order by title_cache";
    cactiDatabaseConnect();
    $sources = db_fetch_assoc($SQL_picklist);
    uasort($sources, "usortNaturalDescriptions");
    $hosts = cactiHostList();
    $tpl = new SimpleTemplate();
    $tpl->set("title", "Pick a graph");
    $tpl->set("hosts", $hosts);
    $tpl->set("sources", $sources);
    $tpl->set("overlib", $overlib ? 1 : 0);
    $tpl->set("selected_host", $host_id);
    $tpl->set("aggregate", $aggregate ? 1 : 0);
    $tpl->set("base_url", isset($config['base_url']) ? $config['base_url'] : '');
    $tpl->set("rra_path", jsEscape($config['rra_path']));
    echo $tpl->fetch("editor-resources/templates/picker-graph.php");
}
 function showMainPage($editor)
 {
     global $WEATHERMAP_VERSION;
     /* add a random bit onto the URL so that the next request won't get the same URL/ETag combo
        even if the config file contents don't change, but the two requests for the same editor page WILL */
     $map_url = "?action=draw&mapname=" . $this->mapname . "&rand=" . rand(0, 100000);
     $tpl = new SimpleTemplate();
     $tpl->set("WEATHERMAP_VERSION", $WEATHERMAP_VERSION);
     $tpl->set("fromplug", $this->isEmbedded() ? 1 : 0);
     $tpl->set("imageurl", htmlspecialchars($map_url));
     if ($this->selected != "") {
         $tpl->set("imageurl", htmlspecialchars($map_url . "&selected=" . urlencode($this->selected)));
     }
     $tpl->set("mapname", htmlspecialchars($this->mapname));
     $tpl->set("newaction", htmlspecialchars($this->next_action));
     $tpl->set("param2", htmlspecialchars($this->param2));
     // draw a map to throw away, just to get the imagemap updated
     $editor->map->drawMapImage('null');
     $editor->map->htmlstyle = 'editor';
     $editor->map->calculateImageMap();
     $tpl->set("imagemap", $editor->map->generateSortedImagemap("weathermap_imap"));
     $tpl->set("map_json", $editor->map->asJS());
     $tpl->set("images_json", "");
     $tpl->set("map_width", $editor->map->width);
     $tpl->set("map_height", $editor->map->height);
     $tpl->set("log", $this->log_message);
     echo $tpl->fetch("editor-resources/templates/main.php");
 }