/** * 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; }
/** * 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'; 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; }
/** * 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; }