public function testGetSetSecurityPolicy() { $dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); $policy = new Dwoo_Security_Policy(); $policy->setConstantHandling(Dwoo_Security_Policy::CONST_ALLOW); $dwoo->setSecurityPolicy($policy); $this->assertEquals($policy, $dwoo->getSecurityPolicy()); $this->assertEquals($policy->getConstantHandling(), $dwoo->getSecurityPolicy()->getConstantHandling()); }
function __construct() { $this->ci =& get_instance(); $this->ci->config->load('parser', TRUE); $config = $this->ci->config->item('parser'); // Main Dwoo object $this->dwoo = new Dwoo(); // The directory where compiled templates are located $this->dwoo->setCompileDir($config['parser_compile_dir']); $this->dwoo->setCacheDir($config['parser_cache_dir']); $this->dwoo->setCacheTime($config['parser_cache_time']); // Security $security = new Dwoo_Security_Policy(); $security->setPhpHandling($config['parser_allow_php_tags']); $security->allowPhpFunction($config['parser_allowed_php_functions']); $this->dwoo->setSecurityPolicy($security); }
/** * 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 * @return int type as a multi bit flag composed of the Dwoo plugin types constants */ protected function getPluginType($name) { $pluginType = -1; if ($this->securityPolicy === null && (function_exists($name) || strtolower($name) === 'isset' || strtolower($name) === 'empty') || $this->securityPolicy !== null && in_array(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) !== false) { $phpFunc = true; } while ($pluginType <= 0) { if (isset($this->customPlugins[$name])) { $pluginType = $this->customPlugins[$name]['type'] | Dwoo::CUSTOM_PLUGIN; } elseif (class_exists('Dwoo_Plugin_' . $name, false) !== false) { if (is_subclass_of('Dwoo_Plugin_' . $name, 'Dwoo_Block_Plugin')) { $pluginType = Dwoo::BLOCK_PLUGIN; } else { $pluginType = Dwoo::CLASS_PLUGIN; } $interfaces = class_implements('Dwoo_Plugin_' . $name, false); if (in_array('Dwoo_ICompilable', $interfaces) !== false || in_array('Dwoo_ICompilable_Block', $interfaces) !== false) { $pluginType |= Dwoo::COMPILABLE_PLUGIN; } } elseif (function_exists('Dwoo_Plugin_' . $name) !== false) { $pluginType = Dwoo::FUNC_PLUGIN; } elseif (function_exists('Dwoo_Plugin_' . $name . '_compile')) { $pluginType = Dwoo::FUNC_PLUGIN | Dwoo::COMPILABLE_PLUGIN; } elseif (function_exists('smarty_modifier_' . $name) !== false) { $pluginType = Dwoo::SMARTY_MODIFIER; } elseif (function_exists('smarty_function_' . $name) !== false) { $pluginType = Dwoo::SMARTY_FUNCTION; } elseif (function_exists('smarty_block_' . $name) !== false) { $pluginType = Dwoo::SMARTY_BLOCK; } else { if ($pluginType === -1) { try { $this->dwoo->getLoader()->loadPlugin($name, isset($phpFunc) === false); } catch (Exception $e) { if (isset($phpFunc)) { $pluginType = Dwoo::NATIVE_PLUGIN; } elseif (is_object($this->dwoo->getPluginProxy()) && $this->dwoo->getPluginProxy()->handles($name)) { $pluginType = Dwoo::PROXY_PLUGIN; break; } else { throw $e; } } } else { throw new Dwoo_Exception('Plugin "' . $name . '" could not be found'); } $pluginType++; } } if (($pluginType & Dwoo::COMPILABLE_PLUGIN) === 0 && ($pluginType & Dwoo::NATIVE_PLUGIN) === 0 && ($pluginType & Dwoo::PROXY_PLUGIN) === 0) { $this->usedPlugins[$name] = $pluginType; } return $pluginType; }