/** * 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; }
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; }
/** * 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 __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");
/** * 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; $pdo = $this; foreach ($modifiers as $name) { $name = trim(strtolower($name)); if (!empty($name)) { $this->fenom->addModifier($name, function ($input, $options = '') use($name, $modx, $pdo) { /** @var modSnippet $snippet */ if (!($snippet = $pdo->getStore($name, 'snippet'))) { if ($snippet = $modx->getObject('modSnippet', array('name' => $name))) { $pdo->setStore($name, $snippet, 'snippet'); } else { return $input; } } $snippet->_cacheable = false; $snippet->_processed = false; $snippet->_content = ''; $result = $snippet->process(array('input' => $input, 'options' => $options, 'pdoTools' => $pdo)); return !empty($result) ? $result : $input; }); } } } } 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'; 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; }