示例#1
0
 /**
  * Seleciona qual render do mustache deverá ser chamado
  * E retorna o template para o arquivo solicitado
  * 
  * @param string $filename Nome do arquivo que deverá ser carregado. O arquivo deve existir em PATH_APP . '/view/' . $filename . '.mustache'
  * @return \Mustache_Template
  */
 protected function loadTemplate($filename)
 {
     if (file_exists(PATH_APP . '/view/' . $filename . '.mustache')) {
         return $this->mustacheapp->loadTemplate($filename);
     } else {
         return $this->mustache->loadTemplate($filename);
     }
 }
    public function testLambdasInsidePartialsAreIndentedProperly()
    {
        $src = <<<EOS
<fieldset>
  {{> input }}
</fieldset>

EOS;
        $partial = <<<EOS
<input placeholder="{{# _t }}Enter your name{{/ _t }}">

EOS;

        $expected = <<<EOS
<fieldset>
  <input placeholder="ENTER YOUR NAME">
</fieldset>

EOS;

        $m = new Mustache_Engine(array(
            'partials' => array('input' => $partial)
        ));

        $tpl = $m->loadTemplate($src);

        $data = new Mustache_Test_Functional_ClassWithLambda();
        $this->assertEquals($expected, $tpl->render($data));
    }
示例#3
0
 protected function renderHTML()
 {
     $dir = rtrim($this->viewDir);
     $mustache = new \Mustache_Engine(['loader' => new \Mustache_Loader_FilesystemLoader($dir)]);
     $template = $mustache->loadTemplate($this->view);
     return $template->render($this->data);
 }
示例#4
0
/**
 * render() takes a view name, and a model and renders a mustache template
 *
 * @param $view  string  The view name, which will be used to fetch the actual view
 * @param $model array   An array containing all of the fields that will be passed to mustache for render
 *
 * @return string
 */
function render($view, $model)
{
    $m = new Mustache_Engine(['loader' => new Mustache_Loader_FilesystemLoader(PREFIX . '/views')]);
    $tpl = $m->loadTemplate($view);
    header("Content-Type: text/html; charset=utf-8");
    echo minify_output($tpl->render($model));
}
示例#5
0
文件: RoboFile.php 项目: rarst/laps
 /**
  * Compiles plugin's mustache template
  */
 public function makeMustache()
 {
     $dir = __DIR__ . '/views/cache';
     $this->_cleanDir($dir);
     $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader(__DIR__ . '/views'), 'cache' => $dir));
     $mustache->loadTemplate('laps');
 }
示例#6
0
 /**
  * Action target that displays the popup to insert a form to a post/page.
  *
  * @access public
  * @return void
  */
 public function vimeography_add_mce_popup()
 {
     $mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader(VIMEOGRAPHY_PATH . 'lib/admin/templates')));
     require_once VIMEOGRAPHY_PATH . 'lib/admin/controllers/vimeography/mce.php';
     $view = new Vimeography_MCE();
     $template = $mustache->loadTemplate('vimeography/mce');
     echo $template->render($view);
 }
示例#7
0
 public function testCallEatsContext()
 {
     $m = new Mustache_Engine();
     $tpl = $m->loadTemplate('{{# foo }}{{ label }}: {{ name }}{{/ foo }}');
     $foo = new Mustache_Test_Functional_ClassWithCall();
     $foo->name = 'Bob';
     $data = array('label' => 'name', 'foo' => $foo);
     $this->assertEquals('name: Bob', $tpl->render($data));
 }
示例#8
0
文件: Html.php 项目: aoloe/php-senape
 public function getAddComment()
 {
     $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($this->path_template), 'helpers' => array('i18n' => \Aoloe\Senape\I18n::getInstance($this->settings))));
     $template = $mustache->loadTemplate('comment-form-add');
     // \Aoloe\debug('settings', $this->settings);
     // TODO: translating in the template or here in php before handing over to the template?
     // TODO: pass the current values once and if we have them
     return $template->render(array('has-labels' => false, 'site-current' => $this->settings['senape-site-current'], 'page-current' => $this->settings['senape-page-current'], 'comment-last-id' => null));
 }
示例#9
0
 public static function page($arr, $templ_short)
 {
     $mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader(dirname(__DIR__) . '/templ/')));
     // Add urls into Arr
     $arr['mainUrl'] = main_url;
     $arr['siteUrl'] = site_url;
     $_templ = $mustache->loadTemplate($templ_short);
     echo $_templ->render($arr);
 }
示例#10
0
 /**
  * @group wip
  * @dataProvider strictCallables
  */
 public function testStrictCallablesEnabled($name, $section, $expected)
 {
     $mustache = new Mustache_Engine(array('strict_callables' => true));
     $tpl = $mustache->loadTemplate('{{# section }}{{ name }}{{/ section }}');
     $data = new StdClass();
     $data->name = $name;
     $data->section = $section;
     $this->assertEquals($expected, $tpl->render($data));
 }
 /**
  * @dataProvider cacheLambdaTemplatesData
  */
 public function testCacheLambdaTemplatesOptionWorks($dirName, $tplPrefix, $enable, $expect)
 {
     $cacheDir = $this->setUpCacheDir($dirName);
     $mustache = new Mustache_Engine(array('template_class_prefix' => $tplPrefix, 'cache' => $cacheDir, 'cache_lambda_templates' => $enable));
     $tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
     $foo = new Mustache_Test_Functional_Foo();
     $foo->wrap = array($foo, 'wrapWithEm');
     $this->assertEquals('<em>' . $foo->name . '</em>', $tpl->render($foo));
     $this->assertCount($expect, glob($cacheDir . '/*.php'));
 }
示例#12
0
 public function render($view)
 {
     if (!is_subclass_of($this, 'Layout')) {
         return;
     }
     $name = $this->name;
     $base = VIEWS_DIR . DIRECTORY_SEPARATOR . 'layout' . DIRECTORY_SEPARATOR . 'mustache';
     $partials = VIEWS_DIR . DIRECTORY_SEPARATOR . 'mustache' . DIRECTORY_SEPARATOR . 'partials';
     $mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader($base), 'partials_loader' => new Mustache_Loader_FilesystemLoader($partials)));
     $template = $mustache->loadTemplate($this->name);
     return $template->render($view);
 }
示例#13
0
 public function generateBlog()
 {
     set_time_limit(0);
     global $app;
     $this->parser = new \Parsedown();
     $data = $this->getData();
     $layout = $data['settings']['layout'] ?: 'default';
     $layoutDir = $app->view->getData('layoutsDir') . $layout . '/';
     // first copy all contents of template to public folder
     copy_directory($layoutDir, $this->publicDir);
     // now create actual html pages
     $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($layoutDir), 'partials_loader' => new \Mustache_Loader_FilesystemLoader($layoutDir . '/partials')));
     $mustacheFiles = glob($layoutDir . '/*.mustache');
     $excludedFiles = array('category', 'post', 'page', 'archive', 'tag');
     foreach ($mustacheFiles as $mustacheFile) {
         $fileName = basename($mustacheFile);
         $fileName = str_replace('.mustache', '', $fileName);
         // we will generate these later
         if (true === in_array($fileName, $excludedFiles)) {
             continue;
         }
         $template = $mustache->loadTemplate($fileName);
         $html = $template->render($data);
         file_put_contents($this->publicDir . $fileName . '.html', $html);
     }
     // delete mustache particals folders from public folder
     rrmdir($this->publicDir . 'partials/');
     // delete *.mustache from public dir
     $mustacheFiles = glob($this->publicDir . '/*.mustache');
     foreach ($mustacheFiles as $mustacheFile) {
         @unlink($mustacheFile);
     }
     // generate post files
     $this->generatePostPageFiles($mustache, $data, 'post');
     // generate page files
     $this->generatePostPageFiles($mustache, $data, 'page');
     // generate category and tag files
     $this->generateCategoryTagFiles($mustache, $data, 'category');
     $this->generateCategoryTagFiles($mustache, $data, 'tag');
     // generate archive files
     $this->generateArchiveFiles($mustache, $data);
     // generate RSS file
     $this->generateRSS($data);
     // generate sitemap.xml
     $this->generateSitemap($data);
     // copy blog data file
     copy('data/blog.json', 'public/data/blog.json');
     $message = '';
     $message .= 'Blog has been generated in <strong>public</strong> folder :)<br><br>';
     $message .= '<a id="viewGenLog" class="btn btn-primary">View Log</a><br><br>';
     $message .= '<div id="genlog">' . $this->getGenerateLog($this->generateLog) . '</div>';
     echo $message;
 }
示例#14
0
 protected static function capture($kohana_view_filename, array $kohana_view_data)
 {
     $extension = func_get_args()[2];
     // is mustache ?
     // If it's not a mustache file, do the default:
     if ($extension == 'php') {
         return Kohana_View::capture($kohana_view_filename, $kohana_view_data);
     }
     // continue
     $vars = Arr::merge(self::kohanaVariables(), View::$_global_data);
     $vars = Arr::merge($vars, $kohana_view_data);
     $conf = Kohana::$config->load('mustache')->as_array();
     $mustache = new Mustache_Engine($conf);
     $tpl = $mustache->loadTemplate($kohana_view_filename);
     return $tpl->render($vars);
 }
示例#15
0
function mustache($viewPath, $values = [])
{
    global $controller;
    global $renderArgs;
    global $strings;
    $mustache = new Mustache_Engine(['loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views'), 'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views/partials'), 'strict_callables' => true]);
    $tpl = $mustache->loadTemplate($viewPath);
    $values["controller:{$controller}?"] = true;
    $values["controller"] = $controller;
    foreach (["firstName", "lastName", "roles", "id", "email"] as $i) {
        if (isset($_SESSION[$i])) {
            $values["currentUser:{$i}"] = $_SESSION[$i];
        }
    }
    if (isset($_SESSION["id"])) {
        $reports = reports("SELECT SUM(hours) FROM logs WHERE created_by = :created_by AND date >= :start AND date <= :end", $_SESSION["id"], ":created_by", ":start", ":end");
        foreach (["weekly", "monthly", "quarterly", "annually"] as $j) {
            $values["currentUser:{$j}"] = $reports[$j];
        }
        $thisWeek = query("SELECT SUM(hours) FROM logs WHERE created_by = :created_by AND date >= :start AND date <= :end", [":created_by" => $_SESSION["id"], ":start" => date("Y-m-d", strtotime("last Sunday")), ":end" => date("Y-m-d", strtotime("this Saturday"))])[0][0];
        if ($thisWeek === null) {
            $thisWeek = 0;
        }
        $values["currentUser:thisWeek"] = $thisWeek;
    }
    # Roles identifier for template
    foreach (roles() as $role) {
        $values["currentUser:{$role}?"] = true;
    }
    foreach ($renderArgs as $key => $value) {
        if (isset($strings[$value])) {
            $value = $strings[$value];
        }
        $values["args:{$key}"] = $value;
    }
    return $tpl->render($values);
}
示例#16
0
 /**
  * View rendering, called once Controller has done its work
  */
 public function render()
 {
     $this->loadGlobals();
     $layout = $this->layout;
     if (is_string($layout) && class_exists($layout . 'Layout')) {
         $layoutClass = $layout . 'Layout';
         $layout = $this->layout = new $layoutClass();
     } elseif (is_null($layout) && class_exists('NewWorklistLayout')) {
         /* In case no layout were specified, NewWorklist will be used. 19-MAY-2014 <kordero> */
         $layout = $this->layout = new NewWorklistLayout();
     }
     $base = VIEWS_DIR . DIRECTORY_SEPARATOR . 'mustache';
     $partials = VIEWS_DIR . DIRECTORY_SEPARATOR . 'mustache' . DIRECTORY_SEPARATOR . 'partials';
     $mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader($base), 'partials_loader' => new Mustache_Loader_FilesystemLoader($partials)));
     $template = $mustache->loadTemplate($this->name);
     $content = $this->content = $template->render($this);
     /**
      * Layout could still not be present here because whether it's
      * missing or an empty/false value were specified, so in that
      * case, rendered content will not be wraped into any other
      * markup or layout behavior. 19-MAY-2014 <kordero>
      */
     return is_null($layout) ? $content : $layout->render($this);
 }
#!/usr/bin/env php
<?php 
/*
 * Small script that generates wp-base.php mostly because we do not want to update multiple files.
 *
 * Script runns after composer-update
 */
require __DIR__ . '/../vendor/autoload.php';
use DigitalUnited\WPBase\Configuration;
Configuration::load_configuration('cli');
$mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader(Configuration::get('templates_dir'))));
$json = json_decode(file_get_contents(__DIR__ . '/../composer.json'));
$data = $mustache->loadTemplate('wp_bootstrap')->render(array('plugin_name' => 'WP Base', 'plugin_uri' => $json->homepage, 'description' => $json->description, 'author' => 'Digital United', 'version' => $json->version, 'author_uri' => 'http://digitalunited.io'));
file_put_contents(__DIR__ . '/../wp-base.php', $data);
echo "bin/generate_wp_boostrap.php: wp-base.php updated";
示例#18
0
 public function testLoadPartialCascading()
 {
     $loader = new Mustache_Loader_ArrayLoader(array('foo' => 'FOO'));
     $mustache = new Mustache_Engine(array('loader' => $loader));
     $tpl = $mustache->loadTemplate('foo');
     $this->assertSame($tpl, $mustache->loadPartial('foo'));
     $mustache->setPartials(array('foo' => 'f00'));
     // setting partials overrides the default template loading fallback.
     $this->assertNotSame($tpl, $mustache->loadPartial('foo'));
     // but it didn't overwrite the original template loader templates.
     $this->assertSame($tpl, $mustache->loadTemplate('foo'));
 }
示例#19
0
 public function testHelpers()
 {
     $foo = array($this, 'getFoo');
     $bar = 'BAR';
     $mustache = new Mustache_Engine(array('helpers' => array('foo' => $foo, 'bar' => $bar)));
     $helpers = $mustache->getHelpers();
     $this->assertTrue($mustache->hasHelper('foo'));
     $this->assertTrue($mustache->hasHelper('bar'));
     $this->assertTrue($helpers->has('foo'));
     $this->assertTrue($helpers->has('bar'));
     $this->assertSame($foo, $mustache->getHelper('foo'));
     $this->assertSame($bar, $mustache->getHelper('bar'));
     $mustache->removeHelper('bar');
     $this->assertFalse($mustache->hasHelper('bar'));
     $mustache->addHelper('bar', $bar);
     $this->assertSame($bar, $mustache->getHelper('bar'));
     $baz = array($this, 'wrapWithUnderscores');
     $this->assertFalse($mustache->hasHelper('baz'));
     $this->assertFalse($helpers->has('baz'));
     $mustache->addHelper('baz', $baz);
     $this->assertTrue($mustache->hasHelper('baz'));
     $this->assertTrue($helpers->has('baz'));
     // ... and a functional test
     $tpl = $mustache->loadTemplate('{{foo}} - {{bar}} - {{#baz}}qux{{/baz}}');
     $this->assertEquals('foo - BAR - __qux__', $tpl->render());
     $this->assertEquals('foo - BAR - __qux__', $tpl->render(array('qux' => "won't mess things up")));
 }
示例#20
0
 /**
  * @param ReportComposerInterface $report
  * @return string
  */
 public function serialize(ReportComposerInterface $report)
 {
     $rows = $this->getRows($report->getReportHeader()->getRows());
     $html = $this->engine->loadTemplate(file_get_contents(__DIR__ . '/../../../../../assets/templates/report.mustache'))->render(['rows' => $rows]);
     return $html;
 }
<?php

include 'configs/global.php';
require 'app/libraries/Mustache/Autoloader.php';
Mustache_Autoloader::register();
$obj = new stdClass();
$obj->app = new stdClass();
$obj->app->culture = CULTURE;
if ($obj->app->culture === "fr") {
    $obj->app->cultureOff = "en";
} else {
    $obj->app->cultureOff = "fr";
}
$isSafari = false;
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') && !strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome')) {
    $isSafari = true;
}
$obj->app->browser = new stdClass();
$obj->app->browser->isSafari = $isSafari;
$obj->path = new stdClass();
$obj->path->root = URL;
$obj->path->styles = URL . 'public/styles/';
$obj->path->scripts = URL . 'public/scripts/';
$obj->path->images = URL . 'public/images/';
$obj->path->data = URL . 'public/data/';
$obj->path->templates = URL . 'public/templates/';
$text = file_get_contents($obj->path->data . $culture . "/text.json");
$obj->text = json_decode($text, true);
$mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader('public/templates'), 'partials_loader' => new Mustache_Loader_FilesystemLoader('public/templates/_partials/')));
$tpl = $mustache->loadTemplate('site');
echo $tpl->render($obj);
示例#22
0
 /**
  * Renders the applicable theme settings controls for the
  * current theme
  *
  * @since  1.3
  * @return mixed
  */
 private function _render_theme_settings_controls()
 {
     if ($this->theme_supports_settings === TRUE) {
         // Make sure the theme_settings_controls array is empty
         $this->theme_settings_controls = array();
         foreach ($this->_theme_settings as $index => $setting) {
             try {
                 // If the setting type isn't set, throw an error.
                 if (!isset($setting['type'])) {
                     throw new Vimeography_Exception(__('One of your active theme settings does not specify the type of setting it is.', 'vimeography'));
                 }
                 // Setting doesn't apply or show if it requires Pro and it isn't installed
                 if ($setting['pro'] === TRUE and $this->has_pro() === FALSE) {
                     continue;
                 }
                 if (file_exists(VIMEOGRAPHY_PATH . 'lib/admin/controllers/theme/settings/' . $setting['type'] . '.php')) {
                     require_once VIMEOGRAPHY_PATH . 'lib/admin/controllers/theme/settings/' . $setting['type'] . '.php';
                     $template_dir = VIMEOGRAPHY_PATH;
                 } elseif (defined('VIMEOGRAPHY_PRO_PATH')) {
                     if (file_exists(VIMEOGRAPHY_PRO_PATH . 'lib/admin/controllers/theme/settings/' . $setting['type'] . '.php')) {
                         require_once VIMEOGRAPHY_PRO_PATH . 'lib/admin/controllers/theme/settings/' . $setting['type'] . '.php';
                         $template_dir = VIMEOGRAPHY_PRO_PATH;
                         // backwards compatibility
                     } elseif (file_exists(VIMEOGRAPHY_PRO_PATH . 'lib/admin/view/theme/settings/' . $setting['type'] . '.php')) {
                         require_once VIMEOGRAPHY_PRO_PATH . 'lib/admin/view/theme/settings/' . $setting['type'] . '.php';
                         $template_dir = VIMEOGRAPHY_PRO_PATH;
                     } else {
                         continue;
                     }
                 } else {
                     continue;
                 }
                 // Otherwise, include the setting if there are no errors with the class.
                 $class = 'Vimeography_Theme_Settings_' . ucfirst($setting['type']);
                 if (!class_exists($class)) {
                     throw new Vimeography_Exception(sprintf(__('The "%s" setting type does not exist or is improperly structured.', 'vimeography'), $setting['type']));
                 }
                 // Load the template file for the current theme setting.
                 $mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader($template_dir . 'lib/admin/templates/theme/settings')));
                 // Populate the setting type class
                 $controller = new $class($setting);
                 $view = $mustache->loadTemplate($setting['type']);
                 //and render the results from the template.
                 $this->theme_settings_controls[]['setting'] = $view->render($controller);
             } catch (Exception $e) {
                 wp_die(__('Theme settings file error: ' . $e->getMessage(), 'vimeography'));
             }
         }
     } else {
         return FALSE;
     }
 }
 /**
  * @dataProvider partialsAndStuff
  */
 public function testNestedPartialsAreIndentedProperly($src, array $partials, $expected)
 {
     $m = new Mustache_Engine(array('partials' => $partials));
     $tpl = $m->loadTemplate($src);
     $this->assertEquals($expected, $tpl->render());
 }
示例#24
0
<?php

require "settings.php";
require "include/rb.php";
require "vendor/autoload.php";
session_start();
/* This is to temporarily work around QueerID not yet existing. */
// nothing here yet.
/* End of temporary workaround. */
/* Temporarily work around DB */
$bigimage[] = array("url" => "http://lorempixel.com/g/1900/1080/people", "text" => "Image 1", "is_first" => true);
$bigimage[] = array("url" => "http://lorempixel.com/g/1900/1080/abstract", "text" => "Image 2");
$bigimage[] = array("url" => "http://lorempixel.com/g/1900/1080/nature", "text" => "Image 3");
$item[] = array("service" => "deed-poll", "icon" => "check", "header" => "Deed Poll for Change of Name", "text" => "We went to the store to buy some ice cream but it all had dairy. Wah");
$item[] = array("service" => "stat-dec", "icon" => "gift", "header" => "Statutory Declaration for Change of Name", "text" => "Chico tried to eat the cat's food, but the cat said no and threw her waterbowl at him. He was not happy.");
$item[] = array("service" => "gender-letter", "icon" => "compass", "header" => "Doctor's Letter confirming change of gender", "text" => "The piano is a cool intrument, but it's got nothing on the trombone because actually the trombone means it's walk time.");
/* End of temporary workaround. */
R::setup('mysql:host=' . $settings['database']['server'] . '; dbname=' . $settings['database']['database'], $settings['database']['username'], $settings['database']['password']);
$url = preg_replace("/^\\//", '', $_SERVER['REQUEST_URI']);
if (!$url) {
    $url = "home";
}
$m = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/mustache_templates')));
$bodyModel = array("site_title" => $settings['site']['title'], "header_images" => $bigimage, "page_items" => $item);
if ($url == "home") {
    $body = $m->loadTemplate("home");
    echo $body->render($bodyModel);
}
示例#25
0
function wp_fuel_pagebuilder_save($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!isset($_POST['wp_fuel_pagebuilder_nonce']) || !wp_verify_nonce($_POST['wp_fuel_pagebuilder_nonce'], '_wp_fuel_pagebuilder_nonce')) {
        return;
    }
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }
    if (isset($_POST['wp_fuel_pagebuilder_page_data'])) {
        update_post_meta($post_id, 'wp_fuel_pagebuilder_page_data', esc_attr($_POST['wp_fuel_pagebuilder_page_data']));
        $page_contents_blocks = array();
        $used_vars_names = [];
        $page_json = [];
        $wp_fuel_pagebuilder_page_data = stripslashes($_POST['wp_fuel_pagebuilder_page_data']);
        $is_page_data = true;
        $rendered_content = '';
        $str = file_get_contents(ABSPATH . 'wp-content/plugins/wp-fuel-page-builder/views/components.json');
        $all_pb_components = json_decode($str, true);
        //Render the page
        $mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader(ABSPATH . 'wp-content/plugins/wp-fuel-page-builder/views')));
        if (trim($wp_fuel_pagebuilder_page_data) == '') {
            $is_page_data = false;
        } else {
            $page_json = json_decode($wp_fuel_pagebuilder_page_data, true);
        }
        if ($is_page_data) {
            $components_pool = [];
            foreach ($all_pb_components as $key => $_component) {
                $components_pool[$_component['id']]['name'] = $_component['name'];
                $components_pool[$_component['id']]['vars'] = $_component['vars'];
            }
            foreach ($page_json as $index => $el) {
                // This loop does 2 things
                // 1. Generate a list of used variable names
                $used_vars_names = array_merge($used_vars_names, $el['vars']);
                // 2. Also creates rendered content
                $model = [];
                $_i = 0;
                foreach ($el['vars'] as $index => $var_name) {
                    $_key = $components_pool[$el['id']]['vars'][$_i]['id'];
                    // $_val = wp_kses_decode_entities($_POST[$var_name]);
                    $_val = $_POST[$var_name];
                    $model = array_merge($model, array($_key => $_val));
                    $_i++;
                }
                $rendered_content .= $mustache->loadTemplate($el['id'])->render($model);
                $rendered_content = htmlspecialchars_decode($rendered_content);
            }
        }
        foreach ($used_vars_names as $index => $var_name) {
            if (isset($_POST[$var_name])) {
                $page_contents_blocks[$var_name] = $_POST[$var_name];
            }
        }
        update_post_meta($post_id, 'page_contents_blocks', $page_contents_blocks);
    }
    // Update to the rendered content
    $my_post = array('ID' => $post_id, 'post_content' => $rendered_content);
    //If calling wp_update_post, unhook this function so it doesn't loop infinitely
    remove_action('save_post', 'wp_fuel_pagebuilder_save');
    // call wp_update_post update, which calls save_post again. E.g:
    wp_update_post($my_post);
    // re-hook this function
    add_action('save_post', 'wp_fuel_pagebuilder_save');
}
示例#26
0
文件: header.php 项目: CFERepo/cfe
        <p></p>
      </div>

      <div class="static">

        <div class="content">

          <a class="back" href="#">
            <span>
              <img src="/wp-content/uploads/2015/07/arrow-blue.png" />Back
            </span>
          </a>

          <?php 
if (is_single() && isset($article) && $article) {
    $tpl = $mustache->loadTemplate('post');
    echo $tpl->render((array) $article);
}
?>
        </div>
      </div>

      <div data-controls="feed-ctl" class="feed featured">

        <div class="swiper-featured">
          <div class="feed-ctl controls">
            <a href="#" class="content-forward"><img src="/wp-content/uploads/2015/09/arrow-content-navigation-right.png" /></a>
            <a href="#" class="content-back"><img src="/wp-content/uploads/2015/07/arrow-content-navigation.png" /></a>
          </div>
          <div class="content swiper-wrapper">
          </div>
示例#27
0
require_once "../vendor/autoload.php";
$template = __DIR__ . "/../templates/index.html";
$inputOrdem = filter_input(INPUT_GET, 'ordem', FILTER_SANITIZE_STRING);
$ordem = ['next' => '?ordem=asc'];
if (strtolower($inputOrdem) == 'asc') {
    $ordem = ['next' => '?ordem=desc', 'icon' => 'fa fa-caret-up'];
}
if (strtolower($inputOrdem) == 'desc') {
    $ordem = ['icon' => 'fa fa-caret-down'];
}
$dadosClientes = (include '../data/clientes.data.php');
if ($inputOrdem != '') {
    $valorOrdem = 1;
    if ($inputOrdem == 'desc') {
        $valorOrdem = -1;
    }
    usort($dadosClientes, function ($a, $b) use($valorOrdem) {
        return $valorOrdem * ($a['id'] <=> $b['id']);
    });
}
$clientes = [];
foreach ($dadosClientes as $cliente) {
    $clientes[] = new Poo\Cliente($cliente);
}
$m = new Mustache_Engine();
$m->addHelper("dateBR", function (DateTime $date) {
    return $date->format('d/m/Y');
});
$tpl = $m->loadTemplate(file_get_contents($template));
echo $tpl->render(['clientes' => $clientes, 'ordem' => $ordem]);
示例#28
0
<?php

require __DIR__ . '/../src/boot.php';
$router = new AltoRouter();
$mustache = new Mustache_Engine(['loader' => new Mustache_Loader_FilesystemLoader(__DIR__ . '/../src/views')]);
// map homepage
$router->map('GET', '/', function () use($mustache) {
    $yuleparty = new \Lutzen\Models\YuleDate(\Carbon\Carbon::now());
    if ($yuleparty->isYulePartyStarted()) {
        $tpl = $mustache->loadTemplate('yuleparty');
    } else {
        $tpl = $mustache->loadTemplate('no-yuleparty');
    }
    $yulepartyDate = $yuleparty->getYulePartyDate();
    echo $tpl->render(array('countdownDate' => $yulepartyDate->format("Y/m/d H:i:s"), 'date' => $yulepartyDate->formatLocalized("%d. %B %Y kl. %H:%M")));
});
// map users details page
$router->map('GET', '/[i:year]/?', function ($year) use($mustache) {
    $date = \Carbon\Carbon::create((int) $year);
    $yuleparty = new \Lutzen\Models\YuleDate($date);
    $tpl = $mustache->loadTemplate('historic-yuleparty');
    $yulepartyDate = $yuleparty->getYulePartyDate();
    echo $tpl->render(array('future' => $year > date('Y') ? 'er' : 'var', 'year' => (int) $year, 'date' => $yulepartyDate->formatLocalized("%d. %B kl. %H:%M")));
});
// match current request url
$match = $router->match();
// call closure or throw 404 status
if ($match && is_callable($match['target'])) {
    call_user_func_array($match['target'], $match['params']);
} else {
    // no route was matched
 /**
  * Test everything in the `examples` directory.
  *
  * @dataProvider getExamples
  *
  * @param string $context
  * @param string $source
  * @param array  $partials
  * @param string $expected
  */
 public function testExamples($context, $source, $partials, $expected)
 {
     $mustache = new Mustache_Engine(array('partials' => $partials));
     $this->assertEquals($expected, $mustache->loadTemplate($source)->render($context));
 }
示例#30
0
 /**
  * Write markdown file
  */
 public function write()
 {
     $m = new \Mustache_Engine(['loader' => new \Mustache_Loader_FilesystemLoader(__DIR__ . '/../views')]);
     $template = $m->loadTemplate('Page');
     $generatedMd = $template->render($this);
     $this->writeSubPages();
     /// Write page
     @mkdir($this->page_rd, 0777, true);
     file_put_contents($this->page_rd . DIRECTORY_SEPARATOR . $this->page_bfe, $generatedMd);
 }