Example #1
0
 /**
  * Set Dwoo template use in email.
  * @param string $file
  * @param array $data
  */
 public function setTemplate($file, $data = array())
 {
     \Dwoo\Autoloader::register();
     $emailTemplatesDir = 'email_templates/';
     /** @var \Dwoo\Core $dwoo */
     $dwoo = new \Dwoo\Core($emailTemplatesDir . 'compiled', $emailTemplatesDir . 'cache');
     $dwoo->setTemplateDir($emailTemplatesDir);
     $output = $dwoo->get($file, $data);
     $this->msgHTML($output);
 }
Example #2
0
 /**
  * returns the plugin type of a plugin and adds it to the used plugins array if required
  *
  * @param string $name plugin name, as found in the template
  *
  * @throws Exception
  *
  * @return int $pluginType as a multi bit flag composed of the \Dwoo\plugin types constants
  */
 protected function getPluginType($name)
 {
     $pluginType = -1;
     $tmpName = $name;
     if ($this->securityPolicy === null && (function_exists($name) || strtolower($name) === 'isset' || strtolower($name) === 'empty') || $this->securityPolicy !== null && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) !== false) {
         $phpFunc = true;
     } else {
         if ($this->securityPolicy !== null && function_exists($name) && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) === false) {
             throw new Exception\SecurityException('Call to a disallowed php function : ' . $name);
         }
     }
     if (isset($this->templatePlugins[$name])) {
         $pluginType = Core::TEMPLATE_PLUGIN | Core::COMPILABLE_PLUGIN;
     } else {
         if (isset($this->customPlugins[$name])) {
             $pluginType = $this->customPlugins[$name]['type'] | Core::CUSTOM_PLUGIN;
         } else {
             // It's a Block/Function class
             $classPrefixArray = array(Core::PLUGIN_BLOCK_CLASS_PREFIX_NAME, Core::PLUGIN_FUNC_CLASS_PREFIX_NAME);
             foreach ($classPrefixArray as $value) {
                 if (class_exists($value . Core::underscoreToCamel($name))) {
                     try {
                         $reflectionClass = new \ReflectionClass($value . Core::underscoreToCamel($name));
                         if ($reflectionClass->isSubclassOf('\\Dwoo\\Block\\Plugin')) {
                             $pluginType = Core::BLOCK_PLUGIN;
                         } else {
                             $pluginType = Core::CLASS_PLUGIN;
                         }
                         if ($reflectionClass->implementsInterface('\\Dwoo\\ICompilable') || $reflectionClass->implementsInterface('\\Dwoo\\ICompilable\\Block')) {
                             $pluginType |= Core::COMPILABLE_PLUGIN;
                         }
                     } catch (\ReflectionException $Exception) {
                     }
                 }
             }
             // It's a block/function/smarty function
             if ($pluginType === -1) {
                 $functionNameArray = array(Core::PLUGIN_BLOCK_FUNCTION_PREFIX_NAME . Core::underscoreToCamel($name) => Core::FUNC_PLUGIN, Core::PLUGIN_FUNC_FUNCTION_PREFIX_NAME . Core::underscoreToCamel($name) => Core::FUNC_PLUGIN, Core::PLUGIN_BLOCK_FUNCTION_PREFIX_NAME . Core::underscoreToCamel($name) . 'Compile' => Core::FUNC_PLUGIN | Core::COMPILABLE_PLUGIN, Core::PLUGIN_FUNC_FUNCTION_PREFIX_NAME . Core::underscoreToCamel($name) . 'Compile' => Core::FUNC_PLUGIN | Core::COMPILABLE_PLUGIN, 'smartyModifier' => Core::SMARTY_MODIFIER, 'smartyFunction' => Core::SMARTY_FUNCTION, 'smartyBlock' => Core::SMARTY_BLOCK);
                 foreach ($functionNameArray as $key => $value) {
                     Autoloader::loadFunction($key);
                     if (function_exists($key) !== false) {
                         $pluginType = $value;
                     }
                 }
             }
             // Otherwise, it's not a class/function, we try to load plugin
             if ($pluginType === -1) {
                 try {
                     $this->dwoo->getLoader()->loadPlugin($tmpName, isset($phpFunc) === false);
                 } catch (Exception $e) {
                     if (isset($phpFunc)) {
                         $pluginType = Core::NATIVE_PLUGIN;
                     } elseif (is_object($this->dwoo->getPluginProxy()) && $this->dwoo->getPluginProxy()->handles($tmpName)) {
                         $pluginType = Core::PROXY_PLUGIN;
                     } else {
                         throw new PluginException(sprintf(PluginException::NOT_FOUND, Core::underscoreToCamel($name)));
                     }
                 }
             }
         }
     }
     if (($pluginType & Core::COMPILABLE_PLUGIN) === 0 && ($pluginType & Core::NATIVE_PLUGIN) === 0 && ($pluginType & Core::PROXY_PLUGIN) === 0) {
         $this->addUsedPlugin($name, $pluginType);
     }
     return $pluginType;
 }