Commit 05171acd authored by Yuliya Bozhko's avatar Yuliya Bozhko Committed by Gerrit Code Review
Browse files

Update Dwoo to version 1.2.0 (Bug #966001)



Change-Id: I56747b80bf6fac21d968d0f7ecf214dcf2ce5e6c
Signed-off-by: default avatarYuliya Bozhko <yuliya.bozhko@totaralms.com>
parent efdfa623
......@@ -2,10 +2,10 @@ Dwoo in Mahara
======================
Website: http://www.dwoo.org/
Version: 1.1.1
Version: 1.2.0
This library is used for all the templating.
Changes:
* None
\ No newline at end of file
* None
[2011--] 1.2.0
! BC Break: Dwoo_Core::isArray had to be fixed and it has been split up
in 3 methods, isArray (for array access), isTraversable (for foreach)
and count (just a helper that counts anything). It won't affect you
unless you built some plugin depending on isArray, in which case you
should check all works fine still
! BC Break: The fix for objects implemented __get but not __isset that was
applied in 1.1.1 was causing problems for people implementing it
correctly, therefore it had to be reverted. If you are affected you must
implement __isset() properly
! BC Break: Dwoo_Core::get now returns a new Dwoo_Core instance if it's
evaluating a template already, this only affects you if you built your
own include-like plugin, see the changes to include plugin in revision
346 [http://bugs.dwoo.org/dwoo/browse_code/revision/345] for more infos
+ Added support for nested blocks for template inheritance, block names
must be unique, overriding of any block is done at the top level, thanks
to Ian Carpenter for the patch
+ Added {return} plugin that allows any included template to return
variables into the one that included it, or to the main controller
code via $dwoo->getReturnValues()
+ Added support for static vars and methods access on namespaced classes
+ Moved Dwoo code to Dwoo_Core that is extended by Dwoo, so you can use
the Dwoo directory as an svn:externals without problems now and just
use Dwoo_Core in place of Dwoo in your code
+ Improved parsing of array() to support real php array syntax as well
as variables as array keys, thanks to acecream for the help
+ Improved parsing of named parameters that can now be quoted
+ Added support for instance and static method calls white-listing in
Dwoo_Security_Policy (see allowMethod()), this is hardly efficient
though for instance calls since it has to do runtime checks so use
it with caution
* Fixed PHP parse errors being generated in compiled templates when
{dynamic} was nested
* Fixed extends bug when calling {extends} with parenthesis
* Fixed a double escaping bug when a variable was assigned to another one
* Added $this->viewParam support to ZendFramework adapter through a
Dwoo_Adapters_ZendFramework_Dwoo class that extends Dwoo, you should use
this if you called setEngine() on the ZF view
* Fixed parsing of blocks with a huge (25K+) content
* Fixed parsing of quoted keywords in if statements, like 'not' was
parsed as ! because using {if not $foo} is valid, but it was impossible
to use them even as string.
* Fixed parsing bug with method calls used as arguments with a comma
following.
* Fixed parsing of function/constants that start with an underscore,
thanks to Dominik del Bondio for the patch
* Adapters: Agavi: Added support for multiple plugin directories in the
config, thanks to Mike Seth for the patch
* Fixed endless loop when parsing an invalid else block
* Fixed custom compilable plugins not being recognized as such
[2010-02-07] 1.1.1
+ Added {optional} plugin that just prints an optional var without any
notice if it doesn't exist
......@@ -505,4 +556,4 @@
although the API to register them is already in.
[2008-02-08] 0.1.0
Initial release
\ No newline at end of file
Initial release
This diff is collapsed.
This diff is collapsed.
......@@ -16,7 +16,10 @@
* <parameter name="request_data">rd</parameter>
* </parameter>
* <parameter name="extract_vars">true</parameter>
* <parameter name="plugin_dir">%core.lib_dir%/dwoo_plugins</parameter>
* <parameters name="plugin_dir">
* <parameter>%core.lib_dir%/dwoo_plugins</parameter>
* <parameter>%core.lib_dir%/other_dwoo_plugins</parameter>
* </parameters>
* </renderer>
*
* - add dwoo's directory to your include path or include dwooAutoload.php yourself
......@@ -27,6 +30,8 @@
* lib directory, or change the plugin_dir parameter in the output_types.xml file.
* these plugins are agavi-specific helpers that shortens the syntax to call common
* agavi helpers (i18n, routing, ..)
* - in the previous versions of this adapter, only a single value could be passed to
* plugin_dir parameter; now you can pass several plugin directories (see example)
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the
......@@ -36,8 +41,8 @@
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.1.0
* @date 2009-07-18
* @version 1.1.1
* @date 2010-04-06
* @package Dwoo
*/
class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer
......@@ -72,7 +77,7 @@ class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer
protected $defaultExtension = '.html';
/**
* stores the (optional) plugin directory to add to the Dwoo_Loader
* stores the (optional) plugin directories to add to the Dwoo_Loader
*/
protected $plugin_dir = null;
......@@ -128,6 +133,7 @@ class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer
return $this->dwoo;
}
// this triggers Agavi autoload
if(!class_exists('Dwoo')) {
if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) {
// file was dropped with the entire dwoo package
......@@ -146,10 +152,12 @@ class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer
$cacheDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_DIR;
AgaviToolkit::mkdir($cacheDir, $parentMode, true);
$this->dwoo = new Dwoo($compileDir, $cacheDir);
$this->dwoo = new Dwoo_Core($compileDir, $cacheDir);
if (!empty($this->plugin_dir)) {
$this->dwoo->getLoader()->addDirectory($this->plugin_dir);
foreach ((array) $this->plugin_dir as $dir) {
$this->dwoo->getLoader()->addDirectory($dir);
}
}
$this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
......@@ -181,7 +189,7 @@ class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer
$data[$this->slotsVarName] =& $slots;
foreach($this->assigns as $key => $getter) {
$data[$key] = $this->context->$getter();
$data[$key] = $this->getContext()->$getter();
}
foreach($moreAssigns as $key => &$value) {
......
// CakePHP Dwoo bridge - v0.2
// CakePHP Dwoo bridge - v0.2
// ------------------------
// Installation :
// ------------------------
......@@ -8,8 +8,8 @@
// line in dwoo.php to include the dwoo library properly.
//
// 2. Place this file in the app/views directory, or on cake/libs/view.
//
// 3. Create the app/tmp/dwoo/cache and app/tmp/dwoo/compile directories
//
// 3. Create the app/tmp/dwoo/cache and app/tmp/dwoo/compile directories
// and make sure they are writable.
// ------------------------
// Usage example :
......
<?php
App::import('vendor', 'dwoo', array("file" => 'dwoo/dwooAutoload.php'));
/**
* Dwoo adapter for CakePHP
*
* Based on SmartyView by Mark John S. Buenconsejo <mjwork@simpleteq.com>
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*
* This file is released under the LGPL
* "GNU Lesser General Public License"
* More information can be found here:
* {@link http://www.gnu.org/copyleft/lesser.html}
*
* @author Mark John S. Buenconsejo <mjwork@simpleteq.com>
* @author Giangi <giangi@qwerg.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @link http://dwoo.org/
<?php
App::import('vendor', 'dwoo', array("file" => 'dwoo/dwooAutoload.php'));
/**
* Dwoo adapter for CakePHP
*
* Based on SmartyView by Mark John S. Buenconsejo <mjwork@simpleteq.com>
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*
* This file is released under the LGPL
* "GNU Lesser General Public License"
* More information can be found here:
* {@link http://www.gnu.org/copyleft/lesser.html}
*
* @author Mark John S. Buenconsejo <mjwork@simpleteq.com>
* @author Giangi <giangi@qwerg.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @link http://dwoo.org/
* @version 1.1.0
* @date 2009-07-18
* @package Dwoo
*/
class DwooView extends View
{
protected $_sv_template_dir;
protected $_sv_layout_dir;
protected $_sv_compile_dir;
protected $_sv_cache_dir;
protected $_sv_compile_id;
protected $_dwoo;
public $sv_processedTpl;
public function __construct(&$controller)
{
parent::__construct($controller);
$this->ext = '.tpl';
$this->_sv_template_dir = array
(
VIEWS . $this->viewPath . DS . $this->subDir,
VIEWS . $this->viewPath,
VIEWS
);
$this->_sv_layout_dir = array
(
LAYOUTS . $this->subDir,
VIEWS
);
$this->_sv_compile_dir = TMP . 'dwoo' . DS . 'compile';
$this->_sv_cache_dir = TMP . 'dwoo' . DS . 'cache';
$this->_dwoo = new Dwoo($this->_sv_compile_dir, $this->_sv_cache_dir);
$this->_sv_compile_id = $controller->name;
$this->_dwoo->sv_this = $this;
* @package Dwoo
*/
class DwooView extends View
{
protected $_sv_template_dir;
protected $_sv_layout_dir;
protected $_sv_compile_dir;
protected $_sv_cache_dir;
protected $_sv_compile_id;
protected $_dwoo;
public $sv_processedTpl;
public function __construct(&$controller)
{
parent::__construct($controller);
$this->ext = '.tpl';
$this->_sv_template_dir = array
(
VIEWS . $this->viewPath . DS . $this->subDir,
VIEWS . $this->viewPath,
VIEWS
);
$this->_sv_layout_dir = array
(
LAYOUTS . $this->subDir,
VIEWS
);
$this->_sv_compile_dir = TMP . 'dwoo' . DS . 'compile';
$this->_sv_cache_dir = TMP . 'dwoo' . DS . 'cache';
$this->_dwoo = new Dwoo_Core($this->_sv_compile_dir, $this->_sv_cache_dir);
$this->_sv_compile_id = $controller->name;
$this->_dwoo->sv_this = $this;
$this->_dwoo->setSecurityPolicy();
return;
}
/**
* changes the template directory
*/
public function setTemplateDir($path = VIEW) {
$old = $this->_sv_template_dir;
$this->_sv_template_dir = $path;
return $old;
}
public function getTemplateDir() {
return $this->_sv_template_dir ;
}
public function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true)
{
// let's determine if this is a layout call or a template call
// and change the template dir accordingly
$layout = false;
if(isset($___data_for_view['content_for_layout'])) {
$this->_sv_template_dir = $this->_sv_layout_dir;
$layout = true;
}
$tpl = new Dwoo_Template_File($___viewFn);
$data = $___data_for_view;
$data['view'] = $this;
if ($this->helpers != false && $loadHelpers === true) {
$loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach (array_keys($loadedHelpers) as $helper) {
$camelBackedHelper = strtolower(substr($helper, 0, 1)) . substr($helper, 1);
${$camelBackedHelper} = $loadedHelpers[$helper];
if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) {
$subHelpers = ${$camelBackedHelper}->helpers;
foreach ($subHelpers as $subHelper) {
${$camelBackedHelper}->{$subHelper} = $loadedHelpers[$subHelper];
}
}
if(isset($this->passedArgs)) {
${$camelBackedHelper}->passedArgs = $this->passedArgs;
}
$this->loaded[$camelBackedHelper] = ${$camelBackedHelper};
$data[$camelBackedHelper] = ${$camelBackedHelper};
}
}
if ($this->helpers != false && $loadHelpers === true) {
foreach ($loadedHelpers as $helper) {
if (is_object($helper)) {
if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) {
$helper->beforeRender();
}
}
}
}
return $this->_dwoo->get($tpl, $data);
}
public function get(){
return $this->_dwoo;
}
}
return;
}
/**
* changes the template directory
*/
public function setTemplateDir($path = VIEW) {
$old = $this->_sv_template_dir;
$this->_sv_template_dir = $path;
return $old;
}
public function getTemplateDir() {
return $this->_sv_template_dir ;
}
public function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true)
{
// let's determine if this is a layout call or a template call
// and change the template dir accordingly
$layout = false;
if(isset($___data_for_view['content_for_layout'])) {
$this->_sv_template_dir = $this->_sv_layout_dir;
$layout = true;
}
$tpl = new Dwoo_Template_File($___viewFn);
$data = $___data_for_view;
$data['view'] = $this;
if ($this->helpers != false && $loadHelpers === true) {
$loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach (array_keys($loadedHelpers) as $helper) {
$camelBackedHelper = strtolower(substr($helper, 0, 1)) . substr($helper, 1);
${$camelBackedHelper} = $loadedHelpers[$helper];
if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) {
$subHelpers = ${$camelBackedHelper}->helpers;
foreach ($subHelpers as $subHelper) {
${$camelBackedHelper}->{$subHelper} = $loadedHelpers[$subHelper];
}
}
if(isset($this->passedArgs)) {
${$camelBackedHelper}->passedArgs = $this->passedArgs;
}
$this->loaded[$camelBackedHelper] = ${$camelBackedHelper};
$data[$camelBackedHelper] = ${$camelBackedHelper};
}
}
if ($this->helpers != false && $loadHelpers === true) {
foreach ($loadedHelpers as $helper) {
if (is_object($helper)) {
if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) {
$helper->beforeRender();
}
}
}
}
return $this->_dwoo->get($tpl, $data);
}
public function get(){
return $this->_dwoo;
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ Dwoo - http://dwoo.org
CodeIgniter - http://codeigniter.com
Installation:
1) Extract package into your application directory (i.e. $webroot/application or
1) Extract package into your application directory (i.e. $webroot/application or
$webroot/system/application)
2) Change the parameters in config/dwootemplate.php
3) Create the compile and cache directory you set in your config file in step 2
......
......@@ -9,8 +9,8 @@ class Dwoowelcome extends Controller {
function index()
{
$this->load->library('Dwootemplate');
$this->dwootemplate->assign('itshowlate', date('H:i:s'));
$this->dwootemplate->display('dwoowelcome.tpl');
$this->load->library('Dwootemplate');
$this->dwootemplate->assign('itshowlate', date('H:i:s'));
$this->dwootemplate->display('dwoowelcome.tpl');
}
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ require "dwoo/dwooAutoload.php";
*
* @uses the dwoo package from http://dwoo.org
*/
class Dwootemplate extends Dwoo {
class Dwootemplate extends Dwoo_Core {
protected $dwoo_data = array();
/**
......
<?php
/**
* Dwoo base class for ZendFramework
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the
* use of this software.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Marc Hodgins <mjh@hodginsmedia.com>
* @copyright Copyright (c) 2010, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.2.0
* @date 2010-02-28
* @package Dwoo
*/
class Dwoo_Adapters_ZendFramework_Dwoo extends Dwoo_Core
{
/**
* Redirects all unknown properties to plugin proxy
* to support $this->viewVariable from within templates
*
* @param string $name Property name
* @return mixed
*/
public function __get($name)
{
if (isset($this->getPluginProxy()->view->$name)) {
return $this->getPluginProxy()->view->$name;
}
$trace = debug_backtrace();
trigger_error('Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'], E_USER_NOTICE);
return null;
}
}
\ No newline at end of file
......@@ -2,7 +2,8 @@
// Usage example :
// ------------------------
// Note that you might need to manually include 'lib/Dwoo.php',
// 'lib/Dwoo/Adapters/ZendFramework/View.php' and
// 'lib/Dwoo/Adapters/ZendFramework/View.php',
// 'lib/Dwoo/Adapters/ZendFramework/Dwoo.php', and
// 'lib/Dwoo/Adapters/ZendFramework/PluginProxy.php' for this to
// work as expected, depending on your ZF setup
//
......@@ -15,6 +16,7 @@ $view = new Dwoo_Adapters_ZendFramework_View(array(
));
// This allows you to use ZF's helpers as if they were Dwoo plugins (i.e. {doctype} will call the doctype helper)
// This also allows you to use $this->variable to access view variables from within templates
$view->setPluginProxy(new Dwoo_Adapters_ZendFramework_PluginProxy(new Zend_View()));
......
......@@ -92,17 +92,6 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
*/
public function setOptions(array $opt = array())
{
// BC checks
// TODO remove in 1.1
if (isset($opt['compileDir']) || isset($opt['compile_dir'])) {
trigger_error('Dwoo ZF Adapter: the compile dir should be set in the $options[\'engine\'][\'compileDir\'] value the adapter settings', E_USER_WARNING);
}
if (isset($opt['cacheDir']) || isset($opt['cache_dir'])) {
trigger_error('Dwoo ZF Adapter: the cache dir should be set in the $options[\'engine\'][\'cacheDir\'] value the adapter settings', E_USER_WARNING);
}
// end BC
// Making sure that everything is loaded.
$classes = array('engine', 'dataProvider', 'compiler');
......@@ -138,12 +127,12 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
}
}
/**
* Set object state from Zend_Config object
*
* @param Zend_Config $config
* @return Dwoo_Adapters_ZendFramework_View
*/
/**
* Set object state from Zend_Config object
*
* @param Zend_Config $config
* @return Dwoo_Adapters_ZendFramework_View
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
......@@ -155,7 +144,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
* Binds plugin proxy to the Dwoo.
*
* @see Dwoo_Adapters_ZendFramework_View::getPluginProxy();
* @see Dwoo::setPluginProxy();
* @see Dwoo_Core::setPluginProxy();
*/
protected function preRender()
{
......@@ -273,7 +262,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
public function getEngine()
{
if (null === $this->_engine) {
$this->_engine = new Dwoo();
$this->_engine = new Dwoo_Adapters_ZendFramework_Dwoo();
}
return $this->_engine;
......@@ -402,7 +391,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract