public function fenom() { if (is_null($this->fenomInstance)) { $this->fenomInstance = \Fenom::factory($this->getTemplatesDirectory(), $this->fenomCompileDir, $this->fenomConfig); } return $this->fenomInstance; }
/** * Loads template engine * * @return bool|Fenom */ public function getFenom() { if (!$this->fenom) { try { if (!class_exists('Fenom')) { require dirname(dirname(__FILE__)) . '/fenom/Fenom.php'; require dirname(dirname(__FILE__)) . '/fenom/Fenom/ProviderInterface.php'; require dirname(dirname(__FILE__)) . '/fenom/Providers/ModChunk.php'; require dirname(dirname(__FILE__)) . '/fenom/Providers/ModTemplate.php'; Fenom::registerAutoload(); } $cache = MODX_CORE_PATH . 'cache/'; if (!file_exists($cache)) { mkdir($cache); } $this->fenom = Fenom::factory(new modChunkProvider($this), $cache); $this->fenom->addProvider('template', new modTemplateProvider($this)); $default_options = array('force_compile' => true, 'disable_cache' => true, 'force_include' => true); if ($options = $this->modx->fromJSON($this->modx->getOption('pdotools_fenom_options'))) { $options = array_merge($options, $default_options); } else { $options = $default_options; } $this->fenom->setOptions($options); if (!$this->modx->getOption('pdotools_fenom_php', null, false)) { $this->fenom->removeAccessor('php'); } } catch (Exception $e) { $this->modx->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage()); return false; } } return $this->fenom; }
/** * Loads template engine * * @return bool|Fenom */ public function getFenom() { if (!$this->fenom) { try { if (!class_exists('Fenom')) { require dirname(dirname(__FILE__)) . '/fenom/Fenom.php'; Fenom::registerAutoload(); } $cache = MODX_CORE_PATH . 'cache/'; if (!file_exists($cache)) { mkdir($cache); } $this->fenom = Fenom::factory($cache, $cache); if (!$this->modx->getOption('pdotools_fenom_php', null, false)) { $this->fenom->removeAccessor('php'); } if ($options = $this->modx->getOption('pdotools_fenom_options')) { if (is_numeric($options) || ($options = $this->modx->fromJSON($options))) { $this->fenom->setOptions($options); } } } catch (Exception $e) { $this->modx->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage()); return false; } } return $this->fenom; }
/** * @param array $params */ public function getTemplater($params = []) { $templatePath = isset($params['templatePath']) ? $params['templatePath'] : ROOT_DIR . '/templates/' . Config::get('dle.skin') . '/'; $cachePath = isset($params['cachePath']) ? $params['cachePath'] : ENGINE_DIR . '/cache/'; unset($params['templatePath'], $params['cachePath']); $tplOptions = $params; $this->tpl = Fenom::factory($templatePath, $cachePath, $tplOptions); // Добавляем модификаторы $this->addModifiers(); // Тег постранички $this->tpl->addFunctionSmart('pages', 'bpModifiers::pages'); // Банеры $this->tpl->addFunctionSmart('banner', 'bpModifiers::banner'); /** * Добавляем в шаблонизатор функцию, которая будет отмечать текущий пункт в меню * Пример: * <a href="?mod=components&action=componentslist" class="{selected request="action" value="componentslist"}">Компоненты</a> */ $this->tpl->addFunction('selected', function ($params) { if (isset($params['request']) && $_REQUEST[$params['request']] == $params['value']) { return 'selected'; } return ''; }); }
function execute() { Load::file('Fenom.php', $this->source_dir); Fenom::registerAutoload(); $templatesDir = APP_DIR . DS . App::getAppName() . DS . APP_TEMPLATES_DIR; $fenom = Fenom::factory($templatesDir, TEMP_DIR . DS . $this->name . DS . 'templates_c'); $fenom->setOptions(array('auto_reload' => true)); return $fenom; }
/** * Генерация простой формы * * @param mixed $header Массив с даннымы шапки * @param mixed $detail Двумерный массив табличной части * @param mixed $summary Список полей по которым вычисляются итоговые данные табличной части */ public function generate(array $header, array $detail = array(), array $summary = array()) { $header['_detail'] = $detail; if (false == file_exists(_ROOT . 'templates/erp/printforms/' . $this->_template)) { return "Файл печатной формы " . $this->_template . " не найден"; } $fenom = \Fenom::factory(_ROOT . 'templates/erp/printforms'); $html = $fenom->fetch($this->_template, $header); $html = str_replace("\n", "", $html); $html = str_replace("\r", "", $html); return $html; }
protected function sendResponse() { global $system_s, $info_s; $this->addResponseData('dev_server', $system_s['dev_server']); $this->addResponseData('info_s', $info_s); $template = $this->getTemplate(); if (empty($template)) { $this->clearResponseMessages(); $template = $this->templateNotFound(); $this->responseNotFound(); } $this->templateEngine->display($template, $this->getResponseData()); }
public static function getThemes() { /* If there a list of YAML files $_themes = Spyc::YAMLLoad(file_get_contents('https://raw.githubusercontent.com/morfy-cms/morfy-themes-catalog/master/themes.yml')); foreach ($_themes as $theme) { $themes[] = Spyc::YAMLLoad(file_get_contents($theme)); } */ $themes = Spyc::YAMLLoad(file_get_contents('https://raw.githubusercontent.com/morfy-cms/morfy-themes-catalog/master/themes.yml')); $fenom = Fenom::factory(PLUGINS_PATH . '/extends/templates/', CACHE_PATH . '/fenom/', Morfy::$fenom); $fenom->display('themes.tpl', array('themes' => $themes)); }
/** * Loads template engine * * @return bool|Fenom */ public function getFenom() { if (!$this->fenom) { try { if (!class_exists('Fenom')) { require dirname(dirname(__FILE__)) . '/fenom/Fenom.php'; require dirname(dirname(__FILE__)) . '/fenom/Fenom/ProviderInterface.php'; require dirname(dirname(__FILE__)) . '/fenom/Providers/ModChunk.php'; require dirname(dirname(__FILE__)) . '/fenom/Providers/ModTemplate.php'; Fenom::registerAutoload(); } $cache = MODX_CORE_PATH . 'cache/'; if (!file_exists($cache)) { mkdir($cache); } $this->fenom = Fenom::factory(new modChunkProvider($this), $cache); $this->fenom->addProvider('template', new modTemplateProvider($this)); $default_options = array('force_compile' => true, 'disable_cache' => true, 'force_include' => true); if (!$this->modx->getOption('pdotools_fenom_php', null, false)) { $this->fenom->removeAccessor('php'); $default_options['disable_native_funcs'] = true; } if ($options = $this->modx->fromJSON($this->modx->getOption('pdotools_fenom_options'))) { $options = array_merge($options, $default_options); } else { $options = $default_options; } $this->fenom->setOptions($options); // Add modifiers if (!empty($this->config['fenomModifiers'])) { $modifiers = is_string($this->config['fenomModifiers']) ? explode(',', $this->config['fenomModifiers']) : $this->config['fenomModifiers']; $modx = $this->modx; foreach ($modifiers as $snippet) { $snippet = trim(strtolower($snippet)); if (!empty($snippet)) { $this->fenom->addModifier($snippet, function ($input, $options = '') use($snippet, $modx) { $result = $modx->runSnippet($snippet, array('input' => $input, 'options' => $options)); return !empty($result) ? $result : $input; }); } } } } catch (Exception $e) { $this->modx->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage()); return false; } } return $this->fenom; }
/** * Set compile directory * * @param string $dir directory to store compiled templates in * * @throws LogicException * @return Fenom */ public function setCompileDir($dir) { $dir = str_replace(MODX_CORE_PATH, '', $dir); $path = MODX_CORE_PATH; $tmp = explode('/', trim($dir, '/')); foreach ($tmp as $v) { if (!empty($v)) { $path .= $v . '/'; } if (!file_exists($path)) { mkdir($path); } } return parent::setCompileDir($path); }
public function __construct() { // $this->template_dir = APPPATH . "views"; $this->template_dir = FCPATH . "templates"; $this->compile_dir = FCPATH . "var/cache"; // $this->compile_dir = "../../var/cache"; $this->options = array('strip' => true, 'auto_trim' => true, 'auto_reload' => true); $this->fenom = Fenom::factory($this->template_dir, $this->compile_dir, $this->options); // Assign CodeIgniter object by reference to CI if (method_exists($this, 'assignByRef')) { $ci =& get_instance(); $this->assignByRef("ci", $ci); } log_message('debug', "Fenom Class Initialized"); }
/** * Template factory * * <code> * $template = Template::factory('templates_path'); * </code> * * @param string|Fenom\ProviderInterface $source path to templates or custom provider * @param string $compile_dir path to compiled files * @param int|array $options * @throws InvalidArgumentException * @return Fenom */ public static function factory($source, $compile_dir = '/tmp', $options = 0) { // Create fenom cache directory if its not exists !Dir::exists(CACHE_PATH . '/fenom/') and Dir::create(CACHE_PATH . '/fenom/'); // Create Unique Cache ID for Theme $theme_config_file = THEMES_PATH . '/' . Config::get('system.theme') . '/' . Config::get('system.theme') . '.yml'; $theme_cache_id = md5('theme' . ROOT_DIR . $theme_config_file . filemtime($theme_config_file)); // Set current them options if (Cache::driver()->contains($theme_cache_id)) { Config::set('theme', Cache::driver()->fetch($theme_cache_id)); } else { $theme_config = Yaml::parseFile($theme_config_file); Config::set('theme', $theme_config); Cache::driver()->save($theme_cache_id, $theme_config); } $compile_dir = CACHE_PATH . '/fenom/'; $options = Config::get('system.fenom'); $fenom = parent::factory($source, $compile_dir, $options); $fenom->assign('config', Config::getConfig()); return $fenom; }
/** * Loads template engine * * @return bool|Fenom */ public function getFenom() { if (!$this->fenom) { try { if (!class_exists('Fenom')) { require dirname(dirname(__FILE__)) . '/fenom/Fenom.php'; Fenom::registerAutoload(); } $cache = MODX_CORE_PATH . 'cache/'; if (!file_exists($cache)) { mkdir($cache); } $this->fenom = Fenom::factory($cache, $cache); if (!$this->modx->getOption('pdotools_fenom_php', null, false)) { $this->fenom->removeAccessor('php'); } if ($options = $this->modx->getOption('pdotools_fenom_options')) { if (is_numeric($options) || ($options = $this->modx->fromJSON($options))) { $this->fenom->setOptions($options); } } // Add line function for lexicons $this->fenom->addFunction('lexicon', function (array $params) { global $modx; $pdo = $modx->getService('pdoTools'); return $pdo->fenomFunction('lexicon', $params); }); // Add line function for making urls $this->fenom->addFunction('url', function (array $params) { global $modx; $pdo = $modx->getService('pdoTools'); return $pdo->fenomFunction('url', $params); }); } catch (Exception $e) { $this->modx->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage()); return false; } } return $this->fenom; }
<?php require_once 'vendor/autoload.php'; $TEMPLATES_DIR = 'templates'; $COMPILED_TEMPLATES_DIR = 'templates/compiled'; if (!file_exists($COMPILED_TEMPLATES_DIR)) { mkdir($COMPILED_TEMPLATES_DIR, 0777, true); } $fenom = Fenom::factory($TEMPLATES_DIR, $COMPILED_TEMPLATES_DIR, Fenom::FORCE_COMPILE | Fenom::AUTO_ESCAPE); function render($template, $vars) { global $fenom; $fenom->display($template . '.tpl.php', $vars); } function redirect($url) { $url = str_replace('\\n', '', $url); $url = str_replace('\\r', '', $url); header('Location: ' . $url); exit; } function is_form_submitted($options) { $all = true; foreach ($options as $option) { $all &= array_key_exists($option, $_POST); } if (!$all) { return false; } $result = [];
/** */ function _init() { require_php_lib('fenom'); $this->fenom = Fenom::factory('.', '/tmp', Fenom::AUTO_ESCAPE); // TODO: fenom configuration }
public function init() { $this->fenom = \Fenom::factory($this->templatePath, $this->compilePath, $this->options); }
#!/usr/bin/php <?php $config = ['git_urls' => ['https://github.com/bzick/fenom.git' => 'fenom/'], 'autoload_config' => ['fenom/src/Fenom/' => 'Fenom'], 'require_once' => ['fenom/src/Fenom.php'], 'example' => function () { $fenom = Fenom::factory('.', '/tmp', Fenom::AUTO_ESCAPE); $str = '<!DOCTYPE html> <html> <head><title>My Webpage</title></head> <body> <ul id="navigation"> {foreach $navigation as $item} <li><a href="{$item.href}">{$item.caption}</a></li> {/foreach} </ul> <h1>My Webpage</h1> {$a_variable} </body> </html>'; $tpl = $fenom->compileCode($str, $name); $replace = []; echo $tpl->fetch($replace); }]; if ($return_config) { return $config; } require_once __DIR__ . '/_yf_autoloader.php'; new yf_autoloader($config);
<?php require_once 'core.php'; use Fenom\Provider; $fenom = new Fenom(new Provider('../ucp/themes')); $fenom->setCompileDir('../cache'); if (defined('DEBUG')) { $fenom->setOptions(Fenom::AUTO_RELOAD); } if (isset($_GET['lang'])) { $currentLanguage = $_GET['lang']; setcookie('lang', $currentLanguage); } else { if (isset($_COOKIE['lang'])) { $currentLanguage = $_COOKIE['lang']; } else { $currentLanguage = configgetvalue('system', 'main', NULL, 'ucpLocale'); } } loadLocale('ucp', $currentLanguage); $ipRequest = " WHERE iplist LIKE '%\"" . $_SERVER['REMOTE_ADDR'] . "\"%'"; function formatCash($sum) { $currency = configgetvalue('system', 'main', NULL, 'currency'); return sprintf(_ngettext("%s {$currency}", "%s {$currency}", $sum), $sum); } class User { private $data = array(); private $valid = false; private $table = false;
<?php include_once 'inc/config.php'; //запрашиваем данные из базы и приводим их в удобный вид $query = "SELECT `tblinvoices`.`date`, CONCAT_WS(' ', `tblclients`.`firstname`, `tblclients`.`lastname`) AS client_fio, `tblinvoiceitems`.`description`, `tblinvoiceitems`.`amount` \n\tFROM `tblinvoices` INNER JOIN `tblinvoiceitems` ON `tblinvoices`.`id`=`tblinvoiceitems`.`invoiceid`\n\t\t\t\t\t\tINNER JOIN `tblclients` ON `tblinvoices`.`userid`=`tblclients`.`id` \n\tWHERE `tblinvoices`.`date` > DATE_ADD(CURRENT_DATE, INTERVAL -1 MONTH)"; $result = $pdo->query($query); foreach ($result as $key => $val) { $array_output[$key] = $val; } $header = array("date" => array("title" => "Дата", "column" => "A"), "client_fio" => array("title" => "Клиент", "column" => "B"), "description" => array("title" => "Продукт", "column" => "C"), "amount" => array("title" => "Сумма", "column" => "D")); //формируем и отправляем письмо \Fenom::registerAutoload(); $fenom = Fenom::factory(__DIR__ . '/template', __DIR__ . '/cache', Fenom::DISABLE_CACHE); $to = "*****@*****.**"; $patch_file = 'C:/WebServers/home/localhost/www/tasks/0_1_2/xls/'; $name_file = 'the report from ' . date("m.d.y H-i") . '.xls'; $text = $name_file; $crlf = "\r\n"; $hdrs = array('From' => '<*****@*****.**>', 'Subject' => $name_file); $mime = new Mail_mime($crlf); $mime->setTXTBody($text); if (!empty($array_output)) { //формируем файл для exel с данными create_file($patch_file, $name_file, $array_output, $header); $message = $fenom->fetch("index.tpl", array('title' => 'Отчет', 'array_output' => $array_output, 'header' => $header)); $file = $patch_file . $name_file; $mime->addAttachment($file); } else { $message = 'В БД нет данных за прошедший месяц!'; } $mime->setHTMLBody($message);
/** * Load Page template * * <code> * Morfy::loadPageTemplate($page); * </code> * * @access public * @param array $page Page array * @return string */ public static function loadPageTemplate($page) { $fenom = Fenom::factory(THEMES_PATH . '/' . static::$site['theme'] . '/', CACHE_PATH . '/fenom/', static::$fenom); if (file_exists($theme_config_path = THEMES_PATH . '/' . static::$site['theme'] . '/' . static::$site['theme'] . '.yml')) { static::$theme = Spyc::YAMLLoad(file_get_contents($theme_config_path)); // Do global tag {$.theme} for the template $fenom->addAccessorSmart('theme', 'theme_config', Fenom::ACCESSOR_PROPERTY); $fenom->theme_config = static::$theme; } // Do global tag {$.site} for the template $fenom->addAccessorSmart('site', 'site_config', Fenom::ACCESSOR_PROPERTY); $fenom->site_config = static::$site; // Display page try { $fenom->display((!empty($page['template']) ? $page['template'] : 'index') . '.tpl', $page); } catch (Exception $e) { echo $e->getMessage(); } }
<?php require_once __DIR__ . '/../src/Fenom.php'; require_once __DIR__ . '/../tests/tools.php'; \Fenom::registerAutoload(); $fenom = Fenom::factory(__DIR__ . '/templates', __DIR__ . '/compiled'); $fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_COMPILE); $fenom->addAccessorSmart('g', 'App::$q->get', Fenom::ACCESSOR_CALL); var_dump($fenom->compileCode('{$.g("env")}')->getBody()); //var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode()); //var_dump($fenom->display("bug158/main.tpl", [])); // $fenom->getTemplate("problem.tpl");
<?php /** * Morfy Feed Plugin * * (c) Romanenko Sergey / Awilum <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ if (Url::getUriSegment(0) == 'rss') { Morfy::factory()->addAction('before_render', function () { $fenom = Fenom::factory(PLUGINS_PATH . '/feed/templates/', CACHE_PATH . '/fenom/', Morfy::$fenom); $fenom->setOptions(array("strip" => false)); Response::status(200); Request::setHeaders('Content-Type: text/xml; charset=utf-8'); $fenom->display('rss.tpl', array('page' => Morfy::factory()->getPage(Morfy::$plugins['feed']['page']), 'pages' => Morfy::factory()->getPages(Morfy::$plugins['feed']['page'], 'date', 'DESC', array('404')))); Request::shutdown(); }); }
/** * @expectedException InvalidArgumentException * @expectedExceptionMessage Source must be a valid path or provider object */ public function testFactoryInvalid2() { Fenom::factory(new StdClass()); }
<?php require_once __DIR__ . '/../src/Fenom.php'; require_once __DIR__ . '/../tests/tools.php'; \Fenom::registerAutoload(); $fenom = Fenom::factory(__DIR__ . '/../tests/resources/provider', __DIR__ . '/../tests/resources/compile'); $fenom->setOptions(Fenom::AUTO_RELOAD); var_dump($fenom->fetch('extends/auto/parent.tpl')); //var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode()); //var_dump($fenom->display("bug158/main.tpl", [])); // $fenom->getTemplate("problem.tpl");
<?php /** * Registering Fenom Autoloader */ Fenom::registerAutoload();
<?php /** * Next & Previous Navigation for Morfy CMS * * @package Morfy * @subpackage Plugins * @author Taufik Nurrohman <http://latitudu.com> * @copyright 2015 Romanenko Sergey / Awilum * @version 2.0.0 * */ // Configuration data $nextprev_config = Spyc::YAMLLoad(file_get_contents(PLUGINS_PATH . '/' . basename(__DIR__) . '/nextprev.yml')); // Initialize Fenom $nextprev_template = Fenom::factory(PLUGINS_PATH . '/' . basename(__DIR__) . '/templates', CACHE_PATH . '/fenom', Morfy::$fenom); // Include `shell.css` in header // Uncomment the hook function below if you are not using Bootstrap. // Morfy::addAction('theme_header', function() { // echo '<link href="' . Morfy::$site['url'] . '/plugins/' . basename(__DIR__) . '/assets/css/shell.css" rel="stylesheet">' . "\n"; // }); // For posts listing page // Usage => Morfy::runAction('index_nextprev'); Morfy::addAction('index_nextprev', function () use($nextprev_config, $nextprev_template) { // Get current URI segments $path = trim(Url::getUriString(), '/'); // Number of posts to display per page request $per_page = isset($nextprev_config['limit']) ? $nextprev_config['limit'] : 5; // Get all posts $all_pages = Morfy::getPages($path, 'date', 'DESC', array('404', 'index')); // Calculate total pages