Commit dc33f417 by Seldaek

! Intermediate commit, unstable state

* Changed all line endings (unix) and uniformized tabs/spaces to full tabs (tabspace 4) * Changed Dwoo::getCurrentTemplate() to Dwoo::getTemplate() and Dwoo::getTemplate() to Dwoo::templateFactory() * Small changes in the compiler git-svn-id: svn://dwoo.org/dwoo/trunk@30 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 2f0eff5f
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
/**
* dwoo data object, use it for complex data assignments or if you want to easily pass it
* around multiple functions to avoid passing an array by reference
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooData implements DwooIDataProvider
{
/**
* data array
*
* @var array
*/
protected $data = array();
/**
* returns the data array
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* clears a the entire data or only the given key
*
<?php
/**
* dwoo data object, use it for complex data assignments or if you want to easily pass it
* around multiple functions to avoid passing an array by reference
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooData implements DwooIDataProvider
{
/**
* data array
*
* @var array
*/
protected $data = array();
/**
* returns the data array
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* clears a the entire data or only the given key
*
* @param array|string $name clears only one value if you give a name, multiple values if
* you give an array of names, or the entire data if left null
*/
public function clear($name = null)
{
if($name === null)
{
$this->data = array();
}
elseif(is_array($name))
{
foreach($name as $index)
unset($this->data[$index]);
}
else
unset($this->data[$name]);
}
/**
* overwrites the entire data with the given array
*
* @param array $data the new data array to use
*/
public function setData(array $data)
{
$this->data = $data;
}
/**
* merges the given array(s) with the current data with array_merge
*
* @param array $data the array to merge
* @param array $data2 $data3 ... other arrays to merge, optional, etc.
*/
public function mergeData(array $data)
{
$args = func_get_args();
while(list(,$v) = each($args))
if(is_array($v))
$this->data = array_merge($this->data, $v);
}
/**
* assigns a value or an array of values to the data object
*
* @param array|string $name an associative array of multiple (index=>value) or a string
* that is the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign, or null if $name was an array
*/
public function assign($name, $val = null)
{
if(is_array($name))
{
reset($name);
while(list($k,$v) = each($name))
$this->data[$k] = $v;
}
else
$this->data[$name] = $val;
}
/**
* assigns a value by reference to the data object
*
* @param string $name the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign by reference
*/
public function assignByRef($name, &$val)
{
$this->data[$name] =& $val;
}
/**
* appends values or an array of values to the data object
*
* @param array|string $name an associative array of multiple (index=>value) or a string
* that is the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign, or null if $name was an array
* @param bool $merge true to merge data or false to append, defaults to false
*/
public function append($name, $val = null, $merge = false)
{
if(is_array($name))
{
foreach($name as $key=>$val)
{
if(isset($this->data[$key]) && !is_array($this->data[$key]))
settype($this->data[$key], 'array');
if($merge === true && is_array($val))
$this->data[$key] = $val + $this->data[$key];
else
$this->data[$key][] = $val;
}
}
elseif($val !== null)
{
if(isset($this->data[$name]) && !is_array($this->data[$name]))
settype($this->data[$name], 'array');
if($merge === true && is_array($val))
$this->data[$name] = $val + $this->data[$name];
else
$this->data[$name][] = $val;
}
}
/**
* appends a value by reference to the data object
*
* @param string $name the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to append by reference
* @param bool $merge true to merge data or false to append, defaults to false
*/
public function appendByRef($name, &$val, $merge = false)
{
if(isset($this->data[$name]) && !is_array($this->data[$name]))
settype($this->data[$name], 'array');
if($merge === true && is_array($val))
{
foreach($val as $key => &$val)
$this->data[$name][$key] =& $val;
}
else
$this->data[$name][] =& $val;
}
}
* you give an array of names, or the entire data if left null
*/
public function clear($name = null)
{
if($name === null)
{
$this->data = array();
}
elseif(is_array($name))
{
foreach($name as $index)
unset($this->data[$index]);
}
else
unset($this->data[$name]);
}
/**
* overwrites the entire data with the given array
*
* @param array $data the new data array to use
*/
public function setData(array $data)
{
$this->data = $data;
}
/**
* merges the given array(s) with the current data with array_merge
*
* @param array $data the array to merge
* @param array $data2 $data3 ... other arrays to merge, optional, etc.
*/
public function mergeData(array $data)
{
$args = func_get_args();
while(list(,$v) = each($args))
if(is_array($v))
$this->data = array_merge($this->data, $v);
}
/**
* assigns a value or an array of values to the data object
*
* @param array|string $name an associative array of multiple (index=>value) or a string
* that is the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign, or null if $name was an array
*/
public function assign($name, $val = null)
{
if(is_array($name))
{
reset($name);
while(list($k,$v) = each($name))
$this->data[$k] = $v;
}
else
$this->data[$name] = $val;
}
/**
* assigns a value by reference to the data object
*
* @param string $name the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign by reference
*/
public function assignByRef($name, &$val)
{
$this->data[$name] =& $val;
}
/**
* appends values or an array of values to the data object
*
* @param array|string $name an associative array of multiple (index=>value) or a string
* that is the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign, or null if $name was an array
* @param bool $merge true to merge data or false to append, defaults to false
*/
public function append($name, $val = null, $merge = false)
{
if(is_array($name))
{
foreach($name as $key=>$val)
{
if(isset($this->data[$key]) && !is_array($this->data[$key]))
settype($this->data[$key], 'array');
if($merge === true && is_array($val))
$this->data[$key] = $val + $this->data[$key];
else
$this->data[$key][] = $val;
}
}
elseif($val !== null)
{
if(isset($this->data[$name]) && !is_array($this->data[$name]))
settype($this->data[$name], 'array');
if($merge === true && is_array($val))
$this->data[$name] = $val + $this->data[$name];
else
$this->data[$name][] = $val;
}
}
/**
* appends a value by reference to the data object
*
* @param string $name the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to append by reference
* @param bool $merge true to merge data or false to append, defaults to false
*/
public function appendByRef($name, &$val, $merge = false)
{
if(isset($this->data[$name]) && !is_array($this->data[$name]))
settype($this->data[$name], 'array');
if($merge === true && is_array($val))
{
foreach($val as $key => &$val)
$this->data[$name][$key] =& $val;
}
else
$this->data[$name][] =& $val;
}
}
?>
\ No newline at end of file
-----------------------------------------------------------------------------
-- WHAT IS DWOO? readme - version 0.3.2
-----------------------------------------------------------------------------
Dwoo is a PHP5 Template Engine that was started in early 2008. The idea came
from the fact that Smarty, a well known template engine, is getting older and
older. It carries the weight of it's age, having old features that are
inconsistent compared to newer ones, being written for PHP4 its Object
Oriented aspect doesn't take advantage of PHP5's more advanced features in
the area, etc. Hence Dwoo was born, hoping to provide a more up to date and
stronger engine.
So far it has proven to be faster than Smarty in many areas, and it provides
a compatibility layer to allow developers that have been using Smarty for
years to switch their application over to Dwoo progressively.
-----------------------------------------------------------------------------
-- DOCUMENTATION
-----------------------------------------------------------------------------
Dwoo's website to get the latest version is at http://dwoo.org/
The wiki/documentation pages are available at http://wiki.dwoo.org/
-----------------------------------------------------------------------------
-- LICENSE
-----------------------------------------------------------------------------
Dwoo is released under the GNU Lesser General Public License version 3.0.
See the LICENSE file included in the archive or go to the URL below to obtain
a copy.
http://www.gnu.org/licenses/lgpl.html
-----------------------------------------------------------------------------
-- QUICK START - RUNNING DWOO
-----------------------------------------------------------------------------
/***************************** Basic Example *******************************/
// Include the main class (it should handle the rest on its own)
include 'path/to/Dwoo.php';
// Create the controller, this is reusable
$dwoo = new Dwoo();
// Load a template file (name it as you please), this is reusable
// if you want to render multiple times the same template with different data
$tpl = new DwooTemplateFile('path/to/index.tpl');
// Create a data set, if you don't like this you can directly input an
// associative array in $dwoo->output()
$data = new DwooData();
// Fill it with some data
$data->assign('foo', 'BAR');
$data->assign('bar', 'BAZ');
// Outputs the result ...
$dwoo->output($tpl, $data);
// ... or get it to use it somewhere else
$dwoo->get($tpl, $data);
/***************************** Loop Example *******************************/
// To loop over multiple articles of a blog for instance, if you have a
// template file representing an article, you could do the following :
include 'path/to/Dwoo.php';
$dwoo = new Dwoo();
$tpl = new DwooTemplateFile('path/to/article.tpl');
$pageContent = '';
// Loop over articles that have been retrieved from the DB
foreach($articles as $article) {
// Either associate variables one by one
$data = new DwooData();
$data->assign('title', $article['title'];
$data->assign('content', $article['content']);
$pageContent .= $dwoo->get($tpl, $data);
// Or use the article directly (which is a lot easier in this case)
$pageContent .= $dwoo->get($tpl, $article);
-----------------------------------------------------------------------------
-- WHAT IS DWOO? readme - version 0.3.2
-----------------------------------------------------------------------------
Dwoo is a PHP5 Template Engine that was started in early 2008. The idea came
from the fact that Smarty, a well known template engine, is getting older and
older. It carries the weight of it's age, having old features that are
inconsistent compared to newer ones, being written for PHP4 its Object
Oriented aspect doesn't take advantage of PHP5's more advanced features in
the area, etc. Hence Dwoo was born, hoping to provide a more up to date and
stronger engine.
So far it has proven to be faster than Smarty in many areas, and it provides
a compatibility layer to allow developers that have been using Smarty for
years to switch their application over to Dwoo progressively.
-----------------------------------------------------------------------------
-- DOCUMENTATION
-----------------------------------------------------------------------------
Dwoo's website to get the latest version is at http://dwoo.org/
The wiki/documentation pages are available at http://wiki.dwoo.org/
-----------------------------------------------------------------------------
-- LICENSE
-----------------------------------------------------------------------------
Dwoo is released under the GNU Lesser General Public License version 3.0.
See the LICENSE file included in the archive or go to the URL below to obtain
a copy.
http://www.gnu.org/licenses/lgpl.html
-----------------------------------------------------------------------------
-- QUICK START - RUNNING DWOO
-----------------------------------------------------------------------------
/***************************** Basic Example *******************************/
// Include the main class (it should handle the rest on its own)
include 'path/to/Dwoo.php';
// Create the controller, this is reusable
$dwoo = new Dwoo();
// Load a template file (name it as you please), this is reusable
// if you want to render multiple times the same template with different data
$tpl = new DwooTemplateFile('path/to/index.tpl');
// Create a data set, if you don't like this you can directly input an
// associative array in $dwoo->output()
$data = new DwooData();
// Fill it with some data
$data->assign('foo', 'BAR');
$data->assign('bar', 'BAZ');
// Outputs the result ...
$dwoo->output($tpl, $data);
// ... or get it to use it somewhere else
$dwoo->get($tpl, $data);
/***************************** Loop Example *******************************/
// To loop over multiple articles of a blog for instance, if you have a
// template file representing an article, you could do the following :
include 'path/to/Dwoo.php';
$dwoo = new Dwoo();
$tpl = new DwooTemplateFile('path/to/article.tpl');
$pageContent = '';
// Loop over articles that have been retrieved from the DB
foreach($articles as $article) {
// Either associate variables one by one
$data = new DwooData();
$data->assign('title', $article['title'];
$data->assign('content', $article['content']);
$pageContent .= $dwoo->get($tpl, $data);
// Or use the article directly (which is a lot easier in this case)
$pageContent .= $dwoo->get($tpl, $article);
}
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_block extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init($name='')
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
return '';
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return '';
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_block extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init($name='')
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
return '';
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return '';
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_capture extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init($name = 'default', $assign = null, $cat = false)
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
return DwooCompiler::PHP_OPEN.$prepend.'ob_start();'.$append.DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
$params = $compiler->getCompiledParams($params);
$out = DwooCompiler::PHP_OPEN.$prepend."\n".'$tmp = ob_get_clean();';
if($params['cat'] === 'true') {
$out .= "\n".'$tmp = $this->readVar(\'dwoo.capture.\'.'.$params['name'].') . $tmp;';
}
if($params['assign'] !== "null") {
$out .= "\n".'$this->scope['.$params['assign'].'] = $tmp;';
}
return $out . "\n".'$this->globals[\'capture\']['.$params['name'].'] = $tmp;'.$append.DwooCompiler::PHP_CLOSE;
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_capture extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init($name = 'default', $assign = null, $cat = false)
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
return DwooCompiler::PHP_OPEN.$prepend.'ob_start();'.$append.DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
$params = $compiler->getCompiledParams($params);
$out = DwooCompiler::PHP_OPEN.$prepend."\n".'$tmp = ob_get_clean();';
if($params['cat'] === 'true') {
$out .= "\n".'$tmp = $this->readVar(\'dwoo.capture.\'.'.$params['name'].') . $tmp;';
}
if($params['assign'] !== "null") {
$out .= "\n".'$this->scope['.$params['assign'].'] = $tmp;';
}
return $out . "\n".'$this->globals[\'capture\']['.$params['name'].'] = $tmp;'.$append.DwooCompiler::PHP_CLOSE;
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_else extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$block =& $compiler->getCurrentBlock();
$out = '';
while($block['type'] !== 'if' && $block['type'] !== 'foreach' && $block['type'] !== 'for' && $block['type'] !== 'with' && $block['type'] !== 'loop')
{
$out .= $compiler->removeTopBlock();
$block =& $compiler->getCurrentBlock();
}
$out .= $block['params']['postOutput'];
$block['params']['postOutput'] = '';
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = DwooCompiler::PHP_OPEN."\n}".DwooCompiler::PHP_CLOSE;
return $out . "else {\n".DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
if(isset($params['postOutput']))
return $params['postOutput'];
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_else extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$block =& $compiler->getCurrentBlock();
$out = '';
while($block['type'] !== 'if' && $block['type'] !== 'foreach' && $block['type'] !== 'for' && $block['type'] !== 'with' && $block['type'] !== 'loop')
{
$out .= $compiler->removeTopBlock();
$block =& $compiler->getCurrentBlock();
}
$out .= $block['params']['postOutput'];
$block['params']['postOutput'] = '';
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = DwooCompiler::PHP_OPEN."\n}".DwooCompiler::PHP_CLOSE;
return $out . "else {\n".DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
if(isset($params['postOutput']))
return $params['postOutput'];
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_elseif extends DwooPlugin_if implements DwooICompilableBlock
{
public function init(array $rest)
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$if =& $compiler->findBlock('if', true);
$out = $if['params']['postOutput'];
$if['params']['postOutput'] = '';
$compiler->injectBlock($type, $params, 1);
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = DwooCompiler::PHP_OPEN."\n}".DwooCompiler::PHP_CLOSE;
if($out === '')
$out = DwooCompiler::PHP_OPEN."\n}";
else
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
return $out . " elseif(".implode(' ', self::replaceKeywords($params, $compiler)).") {\n" . DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
if(isset($params['postOutput']))
return $params['postOutput'];
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_elseif extends DwooPlugin_if implements DwooICompilableBlock
{
public function init(array $rest)
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$if =& $compiler->findBlock('if', true);
$out = $if['params']['postOutput'];
$if['params']['postOutput'] = '';
$compiler->injectBlock($type, $params, 1);
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = DwooCompiler::PHP_OPEN."\n}".DwooCompiler::PHP_CLOSE;
if($out === '')
$out = DwooCompiler::PHP_OPEN."\n}";
else
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
return $out . " elseif(".implode(' ', self::replaceKeywords($params, $compiler)).") {\n" . DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
if(isset($params['postOutput']))
return $params['postOutput'];
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_foreach extends DwooBlockPlugin implements DwooICompilableBlock
{
public static $cnt=0;
public function init($from, $key=null, $item=null, $name='default')
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$params = $compiler->getCompiledParams($params);
$tpl = $compiler->getTemplateSource(true);
// assigns params
$src = $params['from'];
if($params['item'] !== 'null')
{
if($params['key'] !== 'null')
$key = $params['key'];
$val = $params['item'];
}
elseif($params['key'] !== 'null')
{
$val = $params['key'];
}
else
$compiler->triggerError('Foreach <em>item</em> parameter missing', E_USER_ERROR);
$name = $params['name'];
if(substr($val,0,1) !== '"' && substr($val,0,1) !== '\'')
$compiler->triggerError('Foreach <em>item</em> parameter must be of type string', E_USER_ERROR);
if(isset($key) && substr($val,0,1) !== '"' && substr($val,0,1) !== '\'')
$compiler->triggerError('Foreach <em>key</em> parameter must be of type string', E_USER_ERROR);
// evaluates which global variables have to be computed
$varName = '$dwoo.foreach.'.trim($name, '"\'').'.';
$shortVarName = '$.foreach.'.trim($name, '"\'').'.';
$usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
$usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
$usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
$usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
$usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
$usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
$usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
// gets foreach id
$cnt = self::$cnt++;
// builds pre processing output
$out = DwooCompiler::PHP_OPEN . "\n".'$_fh'.$cnt.'_data = '.$src.';';
// adds foreach properties
if($usesAny)
{
$out .= "\n".'$this->globals["foreach"]['.$name.'] = array'."\n(";
if($usesIndex) $out .="\n\t".'"index" => 0,';
if($usesIteration) $out .="\n\t".'"iteration" => 1,';
if($usesFirst) $out .="\n\t".'"first" => null,';
if($usesLast) $out .="\n\t".'"last" => null,';
if($usesShow) $out .="\n\t".'"show" => $this->isArray($_fh'.$cnt.'_data, true, true),';
if($usesTotal) $out .="\n\t".'"total" => $this->isArray($_fh'.$cnt.'_data) ? count($_fh'.$cnt.'_data) : 0,';
$out.="\n);\n".'$_fh'.$cnt.'_glob =& $this->globals["foreach"]['.$name.'];';
}
// checks if foreach must be looped
$out .= "\n".'if($this->isArray($_fh'.$cnt.'_data, true, true) === true)'."\n{";
// iterates over keys
$out .= "\n\t".'foreach($_fh'.$cnt.'_data as '.(isset($key)?'$this->scope['.$key.']=>':'').'$this->scope['.$val.'])'."\n\t{";
// updates properties
if($usesFirst)
$out .= "\n\t\t".'$_fh'.$cnt.'_glob["first"] = (string) ($_fh'.$cnt.'_glob["index"] === 0);';
if($usesLast)
$out .= "\n\t\t".'$_fh'.$cnt.'_glob["last"] = (string) ($_fh'.$cnt.'_glob["iteration"] === $_fh'.$cnt.'_glob["total"]);';
$out .= "\n// -- foreach start output\n".DwooCompiler::PHP_CLOSE;
// build post processing output and cache it
$postOut = DwooCompiler::PHP_OPEN . "\n".'// -- foreach end output';
// update properties
if($usesIndex)
$postOut.="\n\t\t".'$_fh'.$cnt.'_glob["index"]+=1;';
if($usesIteration)
$postOut.="\n\t\t".'$_fh'.$cnt.'_glob["iteration"]+=1;';
// end loop
$postOut .= "\n\t}\n}\n";
// get block params and save the post-processing output already
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = $postOut . DwooCompiler::PHP_CLOSE;
return $out;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOutput'];
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_foreach extends DwooBlockPlugin implements DwooICompilableBlock
{
public static $cnt=0;
public function init($from, $key=null, $item=null, $name='default')
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$params = $compiler->getCompiledParams($params);
$tpl = $compiler->getTemplateSource(true);
// assigns params
$src = $params['from'];
if($params['item'] !== 'null')
{
if($params['key'] !== 'null')
$key = $params['key'];
$val = $params['item'];
}
elseif($params['key'] !== 'null')
{
$val = $params['key'];
}
else
$compiler->triggerError('Foreach <em>item</em> parameter missing', E_USER_ERROR);
$name = $params['name'];
if(substr($val,0,1) !== '"' && substr($val,0,1) !== '\'')
$compiler->triggerError('Foreach <em>item</em> parameter must be of type string', E_USER_ERROR);
if(isset($key) && substr($val,0,1) !== '"' && substr($val,0,1) !== '\'')
$compiler->triggerError('Foreach <em>key</em> parameter must be of type string', E_USER_ERROR);
// evaluates which global variables have to be computed
$varName = '$dwoo.foreach.'.trim($name, '"\'').'.';
$shortVarName = '$.foreach.'.trim($name, '"\'').'.';
$usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
$usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
$usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
$usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
$usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
$usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
$usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
// gets foreach id
$cnt = self::$cnt++;
// builds pre processing output
$out = DwooCompiler::PHP_OPEN . "\n".'$_fh'.$cnt.'_data = '.$src.';';
// adds foreach properties
if($usesAny)
{
$out .= "\n".'$this->globals["foreach"]['.$name.'] = array'."\n(";
if($usesIndex) $out .="\n\t".'"index" => 0,';
if($usesIteration) $out .="\n\t".'"iteration" => 1,';
if($usesFirst) $out .="\n\t".'"first" => null,';
if($usesLast) $out .="\n\t".'"last" => null,';
if($usesShow) $out .="\n\t".'"show" => $this->isArray($_fh'.$cnt.'_data, true, true),';
if($usesTotal) $out .="\n\t".'"total" => $this->isArray($_fh'.$cnt.'_data) ? count($_fh'.$cnt.'_data) : 0,';
$out.="\n);\n".'$_fh'.$cnt.'_glob =& $this->globals["foreach"]['.$name.'];';
}
// checks if foreach must be looped
$out .= "\n".'if($this->isArray($_fh'.$cnt.'_data, true, true) === true)'."\n{";
// iterates over keys
$out .= "\n\t".'foreach($_fh'.$cnt.'_data as '.(isset($key)?'$this->scope['.$key.']=>':'').'$this->scope['.$val.'])'."\n\t{";
// updates properties
if($usesFirst)
$out .= "\n\t\t".'$_fh'.$cnt.'_glob["first"] = (string) ($_fh'.$cnt.'_glob["index"] === 0);';
if($usesLast)
$out .= "\n\t\t".'$_fh'.$cnt.'_glob["last"] = (string) ($_fh'.$cnt.'_glob["iteration"] === $_fh'.$cnt.'_glob["total"]);';
$out .= "\n// -- foreach start output\n".DwooCompiler::PHP_CLOSE;
// build post processing output and cache it
$postOut = DwooCompiler::PHP_OPEN . "\n".'// -- foreach end output';
// update properties
if($usesIndex)
$postOut.="\n\t\t".'$_fh'.$cnt.'_glob["index"]+=1;';
if($usesIteration)
$postOut.="\n\t\t".'$_fh'.$cnt.'_glob["iteration"]+=1;';
// end loop
$postOut .= "\n\t}\n}\n";
// get block params and save the post-processing output already
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = $postOut . DwooCompiler::PHP_CLOSE;
return $out;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOutput'];
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_foreachelse extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$foreach =& $compiler->findBlock('foreach', true);
$out = $foreach['params']['postOutput'];
$foreach['params']['postOutput'] = '';
$compiler->injectBlock($type, $params, 1);
if(substr($out, -strlen(DwooCompiler::PHP_CLOSE)) === DwooCompiler::PHP_CLOSE)
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
else
$out .= DwooCompiler::PHP_OPEN;
return $out . "else\n{" . DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return DwooCompiler::PHP_OPEN.'}'.DwooCompiler::PHP_CLOSE;
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_foreachelse extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$foreach =& $compiler->findBlock('foreach', true);
$out = $foreach['params']['postOutput'];
$foreach['params']['postOutput'] = '';
$compiler->injectBlock($type, $params, 1);
if(substr($out, -strlen(DwooCompiler::PHP_CLOSE)) === DwooCompiler::PHP_CLOSE)
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
else
$out .= DwooCompiler::PHP_OPEN;
return $out . "else\n{" . DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return DwooCompiler::PHP_OPEN.'}'.DwooCompiler::PHP_CLOSE;
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_forelse extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$foreach =& $compiler->findBlock('for', true);
$out = $foreach['params']['postOutput'];
$foreach['params']['postOutput'] = '';
$compiler->injectBlock($type, $params, 1);
if(substr($out, -strlen(DwooCompiler::PHP_CLOSE)) === DwooCompiler::PHP_CLOSE)
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
else
$out .= DwooCompiler::PHP_OPEN;
return $out . "else\n{" . DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return DwooCompiler::PHP_OPEN.'}'.DwooCompiler::PHP_CLOSE;
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_forelse extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$foreach =& $compiler->findBlock('for', true);
$out = $foreach['params']['postOutput'];
$foreach['params']['postOutput'] = '';
$compiler->injectBlock($type, $params, 1);
if(substr($out, -strlen(DwooCompiler::PHP_CLOSE)) === DwooCompiler::PHP_CLOSE)
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
else
$out .= DwooCompiler::PHP_OPEN;
return $out . "else\n{" . DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return DwooCompiler::PHP_OPEN.'}'.DwooCompiler::PHP_CLOSE;
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_if extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init(array $rest) {}
public static function replaceKeywords($params, DwooCompiler $compiler)
{
$params = $compiler->getCompiledParams($params);
$p = array();
$params = $params['*'];
while(list($k,$v) = each($params))
{
switch($v)
{
case '"<<"':
case '">>"':
case '"&&"':
case '"||"':
case '"|"':
case '"^"':
case '"&"':
case '"~"':
case '"("':
case '")"':
case '","':
case '"+"':
case '"-"':
case '"*"':
case '"/"':
$p[] = trim($v, '"');
break;
case '"=="':
case '"eq"':
$p[] = '==';
break;
case '"<>"':
case '"!="':
case '"ne"':
case '"neq"':
$p[] = '!=';
break;
case '">="':
case '"gte"':
case '"ge"':
$p[] = '>=';
break;
case '"<="':
case '"lte"':
case '"le"':
$p[] = '<=';
break;
case '">"':
case '"gt"':
$p[] = '>';
break;
case '"<"':
case '"lt"':
$p[] = '<';
break;
case '"==="':
$p[] = '===';
break;
case '"!=="':
$p[] = '!==';
break;
case '"is"':
if($params[$k+1] === '"not"')
{
$negate = true;
next($params);
}
else
$negate = false;
$ptr = 1+(int)$negate;
switch($params[$k+$ptr])
{
case '"div"':
if(isset($params[$k+$ptr+1]) && $params[$k+$ptr+1] === '"by"')
{
$p[] = ' % '.$params[$k+$ptr+2].' '.($negate?'!':'=').'== 0';
next($params);
next($params);
next($params);
}
else
$compiler->triggerError('If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate?'not ':'').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2], E_USER_ERROR);
break;
case '"even"':
$a = array_pop($p);
if(isset($params[$k+$ptr+1]) && $params[$k+$ptr+1] === '"by"')
{
$b = $params[$k+$ptr+2];
$p[] = '('.$a .' / '.$b.') % 2 '.($negate?'!':'=').'== 0';
next($params);
next($params);
}
else
{
$p[] = $a.' % 2 '.($negate?'!':'=').'== 0';
}
next($params);
break;
case '"odd"':
$a = array_pop($p);
if(isset($params[$k+$ptr+1]) && $params[$k+$ptr+1] === '"by"')
{
$b = $params[$k+$ptr+2];
$p[] = '('.$a .' / '.$b.') % 2 '.($negate?'=':'!').'== 0';
next($params);
next($params);
}
else
{
$p[] = $a.' % 2 '.($negate?'=':'!').'== 0';
}
next($params);
break;
default:
$compiler->triggerError('If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1], E_USER_ERROR);
}
break;
case '"%"':
case '"mod"':
$p[] = '%';
break;
case '"!"':
case '"not"':
$p[] = '!';
break;
default:
$p[] = $v;
}
}
return $p;
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = DwooCompiler::PHP_OPEN."\n}".DwooCompiler::PHP_CLOSE;
return DwooCompiler::PHP_OPEN.'if('.implode(' ', self::replaceKeywords($params, $compiler)).") {\n".DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOutput'];
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_if extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init(array $rest) {}
public static function replaceKeywords($params, DwooCompiler $compiler)
{
$params = $compiler->getCompiledParams($params);
$p = array();
$params = $params['*'];
while(list($k,$v) = each($params))
{
switch($v)
{
case '"<<"':
case '">>"':
case '"&&"':
case '"||"':
case '"|"':
case '"^"':
case '"&"':
case '"~"':
case '"("':
case '")"':
case '","':
case '"+"':
case '"-"':
case '"*"':
case '"/"':
$p[] = trim($v, '"');
break;
case '"=="':
case '"eq"':
$p[] = '==';
break;
case '"<>"':
case '"!="':
case '"ne"':
case '"neq"':
$p[] = '!=';
break;
case '">="':
case '"gte"':
case '"ge"':
$p[] = '>=';
break;
case '"<="':
case '"lte"':
case '"le"':
$p[] = '<=';
break;
case '">"':
case '"gt"':
$p[] = '>';
break;
case '"<"':
case '"lt"':
$p[] = '<';
break;
case '"==="':
$p[] = '===';
break;
case '"!=="':
$p[] = '!==';
break;
case '"is"':
if($params[$k+1] === '"not"')
{
$negate = true;
next($params);
}
else
$negate = false;
$ptr = 1+(int)$negate;
switch($params[$k+$ptr])
{
case '"div"':
if(isset($params[$k+$ptr+1]) && $params[$k+$ptr+1] === '"by"')
{
$p[] = ' % '.$params[$k+$ptr+2].' '.($negate?'!':'=').'== 0';
next($params);
next($params);
next($params);
}
else
$compiler->triggerError('If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate?'not ':'').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2], E_USER_ERROR);
break;
case '"even"':
$a = array_pop($p);
if(isset($params[$k+$ptr+1]) && $params[$k+$ptr+1] === '"by"')
{
$b = $params[$k+$ptr+2];
$p[] = '('.$a .' / '.$b.') % 2 '.($negate?'!':'=').'== 0';
next($params);
next($params);
}
else
{
$p[] = $a.' % 2 '.($negate?'!':'=').'== 0';
}
next($params);
break;
case '"odd"':
$a = array_pop($p);
if(isset($params[$k+$ptr+1]) && $params[$k+$ptr+1] === '"by"')
{
$b = $params[$k+$ptr+2];
$p[] = '('.$a .' / '.$b.') % 2 '.($negate?'=':'!').'== 0';
next($params);
next($params);
}
else
{
$p[] = $a.' % 2 '.($negate?'=':'!').'== 0';
}
next($params);
break;
default:
$compiler->triggerError('If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1], E_USER_ERROR);
}
break;
case '"%"':
case '"mod"':
$p[] = '%';
break;
case '"!"':
case '"not"':
$p[] = '!';
break;
default:
$p[] = $v;
}
}
return $p;
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = DwooCompiler::PHP_OPEN."\n}".DwooCompiler::PHP_CLOSE;
return DwooCompiler::PHP_OPEN.'if('.implode(' ', self::replaceKeywords($params, $compiler)).") {\n".DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOutput'];
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_loop extends DwooBlockPlugin implements DwooICompilableBlock
{
public static $cnt=0;
public function init($from, $name='default')
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$params = $compiler->getCompiledParams($params);
$tpl = $compiler->getTemplateSource(true);
// assigns params
$src = $params['from'];
$name = $params['name'];
// evaluates which global variables have to be computed
$varName = '$dwoo.loop.'.trim($name, '"\'').'.';
$shortVarName = '$.loop.'.trim($name, '"\'').'.';
$usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
$usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
$usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
$usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
$usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
$usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
$usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
// gets foreach id
$cnt = self::$cnt++;
// builds pre processing output
$out = DwooCompiler::PHP_OPEN . "\n".'$_loop'.$cnt.'_data = '.$src.';';
// adds foreach properties
if($usesAny)
{
$out .= "\n".'$this->globals["loop"]['.$name.'] = array'."\n(";
if($usesIndex) $out .="\n\t".'"index" => 0,';
if($usesIteration) $out .="\n\t".'"iteration" => 1,';
if($usesFirst) $out .="\n\t".'"first" => null,';
if($usesLast) $out .="\n\t".'"last" => null,';
if($usesShow) $out .="\n\t".'"show" => $this->isArray($_loop'.$cnt.'_data, true, true),';
if($usesTotal) $out .="\n\t".'"total" => $this->isArray($_loop'.$cnt.'_data) ? count($_loop'.$cnt.'_data) : 0,';
$out.="\n);\n".'$_loop'.$cnt.'_glob =& $this->globals["loop"]['.$name.'];';
}
// checks if foreach must be looped
$out .= "\n".'if($this->isArray($_loop'.$cnt.'_data, true, true) === true)'."\n{";
// iterates over keys
$out .= "\n\t".'foreach($_loop'.$cnt.'_data as $this->scope["-loop-"])'."\n\t{";
// updates properties
if($usesFirst)
$out .= "\n\t\t".'$_loop'.$cnt.'_glob["first"] = (string) ($_loop'.$cnt.'_glob["index"] === 0);';
if($usesLast)
$out .= "\n\t\t".'$_loop'.$cnt.'_glob["last"] = (string) ($_loop'.$cnt.'_glob["iteration"] === $_loop'.$cnt.'_glob["total"]);';
$out .= "\n\t\t".'$_loop'.$cnt.'_scope = $this->setScope("-loop-");'."\n// -- loop start output\n".DwooCompiler::PHP_CLOSE;
// build post processing output and cache it
$postOut = DwooCompiler::PHP_OPEN . "\n".'// -- loop end output'."\n\t\t".'$this->forceScope($_loop'.$cnt.'_scope);';
// update properties
if($usesIndex)
$postOut.="\n\t\t".'$_loop'.$cnt.'_glob["index"]+=1;';
if($usesIteration)
$postOut.="\n\t\t".'$_loop'.$cnt.'_glob["iteration"]+=1;';
// end loop
$postOut .= "\n\t}\n}\n";
// get block params and save the post-processing output already
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = $postOut . DwooCompiler::PHP_CLOSE;
return $out;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOutput'];
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_loop extends DwooBlockPlugin implements DwooICompilableBlock
{
public static $cnt=0;
public function init($from, $name='default')
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$params = $compiler->getCompiledParams($params);
$tpl = $compiler->getTemplateSource(true);
// assigns params
$src = $params['from'];
$name = $params['name'];
// evaluates which global variables have to be computed
$varName = '$dwoo.loop.'.trim($name, '"\'').'.';
$shortVarName = '$.loop.'.trim($name, '"\'').'.';
$usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
$usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
$usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
$usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
$usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
$usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
$usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
// gets foreach id
$cnt = self::$cnt++;
// builds pre processing output
$out = DwooCompiler::PHP_OPEN . "\n".'$_loop'.$cnt.'_data = '.$src.';';
// adds foreach properties
if($usesAny)
{
$out .= "\n".'$this->globals["loop"]['.$name.'] = array'."\n(";
if($usesIndex) $out .="\n\t".'"index" => 0,';
if($usesIteration) $out .="\n\t".'"iteration" => 1,';
if($usesFirst) $out .="\n\t".'"first" => null,';
if($usesLast) $out .="\n\t".'"last" => null,';
if($usesShow) $out .="\n\t".'"show" => $this->isArray($_loop'.$cnt.'_data, true, true),';
if($usesTotal) $out .="\n\t".'"total" => $this->isArray($_loop'.$cnt.'_data) ? count($_loop'.$cnt.'_data) : 0,';
$out.="\n);\n".'$_loop'.$cnt.'_glob =& $this->globals["loop"]['.$name.'];';
}
// checks if foreach must be looped
$out .= "\n".'if($this->isArray($_loop'.$cnt.'_data, true, true) === true)'."\n{";
// iterates over keys
$out .= "\n\t".'foreach($_loop'.$cnt.'_data as $this->scope["-loop-"])'."\n\t{";
// updates properties
if($usesFirst)
$out .= "\n\t\t".'$_loop'.$cnt.'_glob["first"] = (string) ($_loop'.$cnt.'_glob["index"] === 0);';
if($usesLast)
$out .= "\n\t\t".'$_loop'.$cnt.'_glob["last"] = (string) ($_loop'.$cnt.'_glob["iteration"] === $_loop'.$cnt.'_glob["total"]);';
$out .= "\n\t\t".'$_loop'.$cnt.'_scope = $this->setScope("-loop-");'."\n// -- loop start output\n".DwooCompiler::PHP_CLOSE;
// build post processing output and cache it
$postOut = DwooCompiler::PHP_OPEN . "\n".'// -- loop end output'."\n\t\t".'$this->forceScope($_loop'.$cnt.'_scope);';
// update properties
if($usesIndex)
$postOut.="\n\t\t".'$_loop'.$cnt.'_glob["index"]+=1;';
if($usesIteration)
$postOut.="\n\t\t".'$_loop'.$cnt.'_glob["iteration"]+=1;';
// end loop
$postOut .= "\n\t}\n}\n";
// get block params and save the post-processing output already
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params']['postOutput'] = $postOut . DwooCompiler::PHP_CLOSE;
return $out;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOutput'];
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_smartyinterface extends DwooPlugin
{
public function init($__funcname, $__functype, array $rest=array()) {}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$params = $compiler->getCompiledParams($params);
$func = $params['__funcname'];
$pluginType = $params['__functype'];
$params = $params['*'];
if($pluginType & Dwoo::CUSTOM_PLUGIN)
{
$callback = $compiler->customPlugins[$func]['callback'];
if(is_array($callback))
{
if(is_object($callback[0]))
$callback = '$this->customPlugins[\''.$func.'\'][0]->'.$callback[1].'(';
else
$callback = ''.$callback[0].'::'.$callback[1].'(';
}
else
$callback = $callback.'(';
}
else
$callback = 'smarty_block_'.$func.'(';
$compiler->curBlock['params']['postOut'] = DwooCompiler::PHP_OPEN.' $_block_content = ob_get_clean(); $_block_repeat=false; echo '.$callback.'$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);'.DwooCompiler::PHP_CLOSE;
return DwooCompiler::PHP_OPEN.$prepend.' if(!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = '.var_export($params,true).'; $_block_repeat=true; '.$callback.'$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();'.DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOut'];
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_smartyinterface extends DwooPlugin
{
public function init($__funcname, $__functype, array $rest=array()) {}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$params = $compiler->getCompiledParams($params);
$func = $params['__funcname'];
$pluginType = $params['__functype'];
$params = $params['*'];
if($pluginType & Dwoo::CUSTOM_PLUGIN)
{
$callback = $compiler->customPlugins[$func]['callback'];
if(is_array($callback))
{
if(is_object($callback[0]))
$callback = '$this->customPlugins[\''.$func.'\'][0]->'.$callback[1].'(';
else
$callback = ''.$callback[0].'::'.$callback[1].'(';
}
else
$callback = $callback.'(';
}
else
$callback = 'smarty_block_'.$func.'(';
$compiler->curBlock['params']['postOut'] = DwooCompiler::PHP_OPEN.' $_block_content = ob_get_clean(); $_block_repeat=false; echo '.$callback.'$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);'.DwooCompiler::PHP_CLOSE;
return DwooCompiler::PHP_OPEN.$prepend.' if(!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = '.var_export($params,true).'; $_block_repeat=true; '.$callback.'$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();'.DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOut'];
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_textformat extends DwooBlockPlugin
{
protected $wrap;
protected $wrapChar;
protected $wrapCut;
protected $indent;
protected $indChar;
protected $indFirst;
protected $assign;
public function init($wrap=80, $wrap_char="\r\n", $wrap_cut=false, $indent=0, $indent_char=" ", $indent_first=0, $style="", $assign="")
{
if($indent_char === 'tab')
$indent_char = "\t";
switch($style)
{
case 'email':
$wrap = 72;
$indent_first = 0;
break;
case 'html':
$wrap_char = '<br />';
$indent_char = $indent_char == "\t" ? '&nbsp;&nbsp;&nbsp;&nbsp;':'&nbsp;';
break;
}
$this->wrap = (int) $wrap;
$this->wrapChar = (string) $wrap_char;
$this->wrapCut = (bool) $wrap_cut;
$this->indent = (int) $indent;
$this->indChar = (string) $indent_char;
$this->indFirst = (int) $indent_first + $this->indent;
$this->assign = (string) $assign;
}
public function process()
{
// gets paragraphs
$pgs = explode("\n", str_replace(array("\r\n", "\r"), "\n", $this->buffer));
while(list($i,) = each($pgs))
{
if(empty($pgs[$i]))
continue;
// removes line breaks and extensive white space
$pgs[$i] = preg_replace(array('#\s+#', '#^\s*(.+?)\s*$#m'), array(' ', '$1'), str_replace("\n", '', $pgs[$i]));
// wordwraps + indents lines
$pgs[$i] = str_repeat($this->indChar, $this->indFirst) .
wordwrap(
$pgs[$i],
max($this->wrap - $this->indent, 1),
$this->wrapChar . str_repeat($this->indChar, $this->indent),
$this->wrapCut
);
}
if($this->assign !== '')
$this->dwoo->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign);
else
return implode($this->wrapChar . $this->wrapChar, $pgs);
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_textformat extends DwooBlockPlugin
{
protected $wrap;
protected $wrapChar;
protected $wrapCut;
protected $indent;
protected $indChar;
protected $indFirst;
protected $assign;
public function init($wrap=80, $wrap_char="\r\n", $wrap_cut=false, $indent=0, $indent_char=" ", $indent_first=0, $style="", $assign="")
{
if($indent_char === 'tab')
$indent_char = "\t";
switch($style)
{
case 'email':
$wrap = 72;
$indent_first = 0;
break;
case 'html':
$wrap_char = '<br />';
$indent_char = $indent_char == "\t" ? '&nbsp;&nbsp;&nbsp;&nbsp;':'&nbsp;';
break;
}
$this->wrap = (int) $wrap;
$this->wrapChar = (string) $wrap_char;
$this->wrapCut = (bool) $wrap_cut;
$this->indent = (int) $indent;
$this->indChar = (string) $indent_char;
$this->indFirst = (int) $indent_first + $this->indent;
$this->assign = (string) $assign;
}
public function process()
{
// gets paragraphs
$pgs = explode("\n", str_replace(array("\r\n", "\r"), "\n", $this->buffer));
while(list($i,) = each($pgs))
{
if(empty($pgs[$i]))
continue;
// removes line breaks and extensive white space
$pgs[$i] = preg_replace(array('#\s+#', '#^\s*(.+?)\s*$#m'), array(' ', '$1'), str_replace("\n", '', $pgs[$i]));
// wordwraps + indents lines
$pgs[$i] = str_repeat($this->indChar, $this->indFirst) .
wordwrap(
$pgs[$i],
max($this->wrap - $this->indent, 1),
$this->wrapChar . str_repeat($this->indChar, $this->indent),
$this->wrapCut
);
}
if($this->assign !== '')
$this->dwoo->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign);
else
return implode($this->wrapChar . $this->wrapChar, $pgs);
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
final class DwooPlugin_topLevelBlock extends DwooBlockPlugin
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
return 'ob_start(); '.DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return DwooCompiler::PHP_OPEN.'return $this->buffer . ob_get_clean();';
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
final class DwooPlugin_topLevelBlock extends DwooBlockPlugin
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
return 'ob_start(); '.DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return DwooCompiler::PHP_OPEN.'return $this->buffer . ob_get_clean();';
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_with extends DwooBlockPlugin implements DwooICompilableBlock
{
protected static $cnt=0;
public function init($var)
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$rparams = $compiler->getRealParams($params);
$cparams = $compiler->getCompiledParams($params);
$compiler->setScope($rparams['var']);
$params =& $compiler->getCurrentBlock();
$params['params']['postOutput'] = DwooCompiler::PHP_OPEN."\n// -- end with output\n".'$this->forceScope($_with'.(self::$cnt).');'."\n}\n".DwooCompiler::PHP_CLOSE;
return DwooCompiler::PHP_OPEN.'if('.$cparams['var'].')'."\n{\n".'$_with'.(self::$cnt++).' = $this->setScope("'.$rparams['var'].'");'."\n// -- start with output\n".DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOutput'];
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_with extends DwooBlockPlugin implements DwooICompilableBlock
{
protected static $cnt=0;
public function init($var)
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$rparams = $compiler->getRealParams($params);
$cparams = $compiler->getCompiledParams($params);
$compiler->setScope($rparams['var']);
$params =& $compiler->getCurrentBlock();
$params['params']['postOutput'] = DwooCompiler::PHP_OPEN."\n// -- end with output\n".'$this->forceScope($_with'.(self::$cnt).');'."\n}\n".DwooCompiler::PHP_CLOSE;
return DwooCompiler::PHP_OPEN.'if('.$cparams['var'].')'."\n{\n".'$_with'.(self::$cnt++).' = $this->setScope("'.$rparams['var'].'");'."\n// -- start with output\n".DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return $params['postOutput'];
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_withelse extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$foreach =& $compiler->findBlock('with', true);
$out = $foreach['params']['postOutput'];
$foreach['params']['postOutput'] = '';
$compiler->injectBlock($type, $params, 1);
if(substr($out, -strlen(DwooCompiler::PHP_CLOSE)) === DwooCompiler::PHP_CLOSE)
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
else
$out .= DwooCompiler::PHP_OPEN;
return $out . "else\n{" . DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return DwooCompiler::PHP_OPEN.'}'.DwooCompiler::PHP_CLOSE;
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_withelse extends DwooBlockPlugin implements DwooICompilableBlock
{
public function init()
{
}
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='', $type)
{
$foreach =& $compiler->findBlock('with', true);
$out = $foreach['params']['postOutput'];
$foreach['params']['postOutput'] = '';
$compiler->injectBlock($type, $params, 1);
if(substr($out, -strlen(DwooCompiler::PHP_CLOSE)) === DwooCompiler::PHP_CLOSE)
$out = substr($out, 0, -strlen(DwooCompiler::PHP_CLOSE));
else
$out .= DwooCompiler::PHP_OPEN;
return $out . "else\n{" . DwooCompiler::PHP_CLOSE;
}
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend='', $append='')
{
return DwooCompiler::PHP_OPEN.'}'.DwooCompiler::PHP_CLOSE;
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_assign_compile(DwooCompiler $compiler, $value, $var)
{
return '$this->assignInScope('.$value.', '.$var.')';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_assign_compile(DwooCompiler $compiler, $value, $var)
{
return '$this->assignInScope('.$value.', '.$var.')';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_capitalize(Dwoo $dwoo, $value, $numwords=false)
{
if($numwords || preg_match('#^[^0-9]+$#',$value))
{
if($dwoo->getCharset() === 'iso-8859-1')
return ucwords((string) $value);
return mb_convert_case((string) $value,MB_CASE_TITLE, $dwoo->getCharset());
}
else
{
$bits = explode(' ', (string) $value);
$out = '';
while(list(,$v) = each($bits))
if(preg_match('#^[^0-9]+$#', $v))
$out .= ' '.mb_convert_case($v, MB_CASE_TITLE, $dwoo->getCharset());
else
$out .= ' '.$v;
return substr($out, 1);
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_capitalize(Dwoo $dwoo, $value, $numwords=false)
{
if($numwords || preg_match('#^[^0-9]+$#',$value))
{
if($dwoo->getCharset() === 'iso-8859-1')
return ucwords((string) $value);
return mb_convert_case((string) $value,MB_CASE_TITLE, $dwoo->getCharset());
}
else
{
$bits = explode(' ', (string) $value);
$out = '';
while(list(,$v) = each($bits))
if(preg_match('#^[^0-9]+$#', $v))
$out .= ' '.mb_convert_case($v, MB_CASE_TITLE, $dwoo->getCharset());
else
$out .= ' '.$v;
return substr($out, 1);
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_cat_compile(DwooCompiler $compiler, $value, array $rest)
{
return '('.$value.').('.implode(').(', $rest).')';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_cat_compile(DwooCompiler $compiler, $value, array $rest)
{
return '('.$value.').('.implode(').(', $rest).')';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_count_characters_compile(DwooCompiler $compiler, $value, $count_spaces=false)
{
if($count_spaces==='false')
return 'preg_match_all(\'#[^\s\pZ]#u\', '.$value.', $tmp)';
else
return 'mb_strlen('.$value.', $this->charset)';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_count_characters_compile(DwooCompiler $compiler, $value, $count_spaces=false)
{
if($count_spaces==='false')
return 'preg_match_all(\'#[^\s\pZ]#u\', '.$value.', $tmp)';
else
return 'mb_strlen('.$value.', $this->charset)';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_count_paragraphs_compile(DwooCompiler $compiler, $value)
{
return '(preg_match_all(\'#[\r\n]+#\', '.$value.', $tmp)+1)';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_count_paragraphs_compile(DwooCompiler $compiler, $value)
{
return '(preg_match_all(\'#[\r\n]+#\', '.$value.', $tmp)+1)';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_count_sentences_compile(DwooCompiler $compiler, $value)
{
return "preg_match_all('#[\w\pL]\.(?![\w\pL])#u', $value, \$tmp)";
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_count_sentences_compile(DwooCompiler $compiler, $value)
{
return "preg_match_all('#[\w\pL]\.(?![\w\pL])#u', $value, \$tmp)";
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_count_words_compile(DwooCompiler $compiler, $value)
{
return 'preg_match_all(strcasecmp($this->charset, \'utf-8\')===0 ? \'#[\w\pL]+#u\' : \'#\w+#\', '.$value.', $tmp)';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_count_words_compile(DwooCompiler $compiler, $value)
{
return 'preg_match_all(strcasecmp($this->charset, \'utf-8\')===0 ? \'#[\w\pL]+#u\' : \'#\w+#\', '.$value.', $tmp)';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_counter extends DwooPlugin
{
protected $counters = array();
public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null)
{
// init counter
if(!isset($this->counters[$name]))
{
$this->counters[$name] = array
(
'count' => $start===null ? 1 : (int) $start,
'skip' => $skip===null ? 1 : (int) $skip,
'print' => $print===null ? true : (bool) $print,
'assign' => $assign===null ? null : (string) $assign,
'direction' => strtolower($direction)==='down' ? -1 : 1,
);
}
// increment
else
{
// override setting if present
if($skip !== null)
$this->counters[$name]['skip'] = (int) $skip;
if($direction !== null)
$this->counters[$name]['direction'] = strtolower($direction)==='down' ? -1 : 1;
if($print !== null)
$this->counters[$name]['print'] = (bool) $print;
if($assign !== null)
$this->counters[$name]['assign'] = (string) $assign;
if($start !== null)
$this->counters[$name]['count'] = (int) $start;
else
$this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']);
}
$out = $this->counters[$name]['count'];
if($this->counters[$name]['assign'] !== null)
$this->dwoo->assignInScope($out, $this->counters[$name]['assign']);
elseif($this->counters[$name]['print'] === true)
return $out;
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_counter extends DwooPlugin
{
protected $counters = array();
public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null)
{
// init counter
if(!isset($this->counters[$name]))
{
$this->counters[$name] = array
(
'count' => $start===null ? 1 : (int) $start,
'skip' => $skip===null ? 1 : (int) $skip,
'print' => $print===null ? true : (bool) $print,
'assign' => $assign===null ? null : (string) $assign,
'direction' => strtolower($direction)==='down' ? -1 : 1,
);
}
// increment
else
{
// override setting if present
if($skip !== null)
$this->counters[$name]['skip'] = (int) $skip;
if($direction !== null)
$this->counters[$name]['direction'] = strtolower($direction)==='down' ? -1 : 1;
if($print !== null)
$this->counters[$name]['print'] = (bool) $print;
if($assign !== null)
$this->counters[$name]['assign'] = (string) $assign;
if($start !== null)
$this->counters[$name]['count'] = (int) $start;
else
$this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']);
}
$out = $this->counters[$name]['count'];
if($this->counters[$name]['assign'] !== null)
$this->dwoo->assignInScope($out, $this->counters[$name]['assign']);
elseif($this->counters[$name]['print'] === true)
return $out;
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_cycle extends DwooPlugin
{
protected $cycles = array();
public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false)
{
if($values !== null)
{
if(is_string($values))
$values = explode($delimiter, $values);
if(!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values)
$this->cycles[$name]['index'] = 0;
$this->cycles[$name]['values'] = array_values($values);
}
elseif(isset($this->cycles[$name]))
{
$values = $this->cycles[$name]['values'];
}
if($reset)
$this->cycles[$name]['index'] = 0;
if($print)
$out = $values[$this->cycles[$name]['index']];
else
$out = null;
if($advance)
{
if($this->cycles[$name]['index'] >= count($values)-1)
$this->cycles[$name]['index'] = 0;
else
$this->cycles[$name]['index']++;
}
if($assign !== null)
$this->dwoo->assignInScope($assign, $out);
else
return $out;
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class DwooPlugin_cycle extends DwooPlugin
{
protected $cycles = array();
public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false)
{
if($values !== null)
{
if(is_string($values))
$values = explode($delimiter, $values);
if(!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values)
$this->cycles[$name]['index'] = 0;
$this->cycles[$name]['values'] = array_values($values);
}
elseif(isset($this->cycles[$name]))
{
$values = $this->cycles[$name]['values'];
}
if($reset)
$this->cycles[$name]['index'] = 0;
if($print)
$out = $values[$this->cycles[$name]['index']];
else
$out = null;
if($advance)
{
if($this->cycles[$name]['index'] >= count($values)-1)
$this->cycles[$name]['index'] = 0;
else
$this->cycles[$name]['index']++;
}
if($assign !== null)
$this->dwoo->assignInScope($assign, $out);
else
return $out;
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_date_format(Dwoo $dwoo, $value, $format='%b %e, %Y', $default=null)
{
if(!empty($value))
{
// don't convert if it's a valid unix timestamp
if(preg_match('#^\d{10}$#', $value)===false)
$value = strtotime($value);
}
elseif(!empty($default))
{
// don't convert if it's a valid unix timestamp
if(preg_match('#^\d{10}$#', $default)===false)
$value = strtotime($default);
}
else
return '';
// Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin
if(DIRECTORY_SEPARATOR == '\\')
{
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
if(strpos($format, '%e') !== false)
{
$_win_from[] = '%e';
$_win_to[] = sprintf('%\' 2d', date('j', $value));
}
if(strpos($format, '%l') !== false)
{
$_win_from[] = '%l';
$_win_to[] = sprintf('%\' 2d', date('h', $value));
}
$format = str_replace($_win_from, $_win_to, $format);
}
return strftime($format, $value);
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_date_format(Dwoo $dwoo, $value, $format='%b %e, %Y', $default=null)
{
if(!empty($value))
{
// don't convert if it's a valid unix timestamp
if(preg_match('#^\d{10}$#', $value)===false)
$value = strtotime($value);
}
elseif(!empty($default))
{
// don't convert if it's a valid unix timestamp
if(preg_match('#^\d{10}$#', $default)===false)
$value = strtotime($default);
}
else
return '';
// Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin
if(DIRECTORY_SEPARATOR == '\\')
{
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
if(strpos($format, '%e') !== false)
{
$_win_from[] = '%e';
$_win_to[] = sprintf('%\' 2d', date('j', $value));
}
if(strpos($format, '%l') !== false)
{
$_win_from[] = '%l';
$_win_to[] = sprintf('%\' 2d', date('h', $value));
}
$format = str_replace($_win_from, $_win_to, $format);
}
return strftime($format, $value);
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_default_compile(DwooCompiler $compiler, $value, $default='')
{
return '(($tmp = '.$value.')===null||$tmp===\'\' ? '.$default.' : $tmp)';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_default_compile(DwooCompiler $compiler, $value, $default='')
{
return '(($tmp = '.$value.')===null||$tmp===\'\' ? '.$default.' : $tmp)';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_escape(Dwoo $dwoo, $value='', $format='html', $charset=null)
{
if($charset === null)
$charset = $dwoo->getCharset();
switch($format)
{
case 'html':
return htmlspecialchars((string) $value, ENT_QUOTES, $charset);
case 'htmlall':
return htmlentities((string) $value, ENT_QUOTES, $charset);
case 'url':
return rawurlencode((string) $value);
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode((string) $value));
case 'quotes':
return preg_replace("#(?<!\\\\)'#", "\\'", (string) $value);
case 'hex':
$out = '';
$cnt = strlen((string) $value);
for ($i=0; $i < $cnt; $i++) {
$out .= '%' . bin2hex((string) $value[$i]);
}
return $out;
case 'hexentity':
$out = '';
$cnt = strlen((string) $value);
for($i=0; $i < $cnt; $i++)
$out .= '&#x' . bin2hex((string) $value[$i]) . ';';
return $out;
case 'javascript':
return strtr((string) $value, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
case 'mail':
return str_replace(array('@', '.'), array('&nbsp;(AT)&nbsp;', '&nbsp;(DOT)&nbsp;'), (string) $value);
default:
$dwoo->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript or mail, "'.$format.'" given.', E_USER_WARNING);
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_escape(Dwoo $dwoo, $value='', $format='html', $charset=null)
{
if($charset === null)
$charset = $dwoo->getCharset();
switch($format)
{
case 'html':
return htmlspecialchars((string) $value, ENT_QUOTES, $charset);
case 'htmlall':
return htmlentities((string) $value, ENT_QUOTES, $charset);
case 'url':
return rawurlencode((string) $value);
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode((string) $value));
case 'quotes':
return preg_replace("#(?<!\\\\)'#", "\\'", (string) $value);
case 'hex':
$out = '';
$cnt = strlen((string) $value);
for ($i=0; $i < $cnt; $i++) {
$out .= '%' . bin2hex((string) $value[$i]);
}
return $out;
case 'hexentity':
$out = '';
$cnt = strlen((string) $value);
for($i=0; $i < $cnt; $i++)
$out .= '&#x' . bin2hex((string) $value[$i]) . ';';
return $out;
case 'javascript':
return strtr((string) $value, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
case 'mail':
return str_replace(array('@', '.'), array('&nbsp;(AT)&nbsp;', '&nbsp;(DOT)&nbsp;'), (string) $value);
default:
$dwoo->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript or mail, "'.$format.'" given.', E_USER_WARNING);
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_eval(Dwoo $dwoo, $var, $assign = null)
{
// TOCOM eval is bad, warn people that they should not use it as a full template for DB-templates, they better extend DwooITemplate for that
if($var == '')
return;
$tpl = new DwooTemplateString($var);
$out = $dwoo->get($var, $dwoo->readVar('_parent'));
if($assign !== null)
$dwoo->assignInScope($out, $assign);
else
return $out;
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_eval(Dwoo $dwoo, $var, $assign = null)
{
// TOCOM eval is bad, warn people that they should not use it as a full template for DB-templates, they better extend DwooITemplate for that
if($var == '')
return;
$tpl = new DwooTemplateString($var);
$out = $dwoo->get($var, $dwoo->readVar('_parent'));
if($assign !== null)
$dwoo->assignInScope($out, $assign);
else
return $out;
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_extendsCheck_compile(DwooCompiler $compiler, $file, $uid)
{
preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m);
$resource = $m[1];
$identifier = $m[2];
return '// check for modification in '.$resource.':'.$identifier.'
try {
$tpl = $this->getTemplate("'.$resource.'", "'.$identifier.'");
} catch (DwooException $e) {
$this->triggerError(\'Extends : Resource <em>'.$resource.'</em> was not added to Dwoo, can not include <em>'.$identifier.'</em>\', E_USER_WARNING);
}
if($tpl === null)
$this->triggerError(\'Extends : Resource "'.$resource.':'.$identifier.'" was not found.\', E_USER_WARNING);
elseif($tpl === false)
$this->triggerError(\'Include : Extending "'.$resource.':'.$identifier.'" was not allowed for an unknown reason.\', E_USER_WARNING);
if($tpl->getUid() !== "'.substr($uid, 1, -1).'") { ob_end_clean(); return false; }';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_extendsCheck_compile(DwooCompiler $compiler, $file, $uid)
{
preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m);
$resource = $m[1];
$identifier = $m[2];
return '// check for modification in '.$resource.':'.$identifier.'
try {
$tpl = $this->templateFactory("'.$resource.'", "'.$identifier.'");
} catch (DwooException $e) {
$this->triggerError(\'Extends : Resource <em>'.$resource.'</em> was not added to Dwoo, can not include <em>'.$identifier.'</em>\', E_USER_WARNING);
}
if($tpl === null)
$this->triggerError(\'Extends : Resource "'.$resource.':'.$identifier.'" was not found.\', E_USER_WARNING);
elseif($tpl === false)
$this->triggerError(\'Include : Extending "'.$resource.':'.$identifier.'" was not allowed for an unknown reason.\', E_USER_WARNING);
if($tpl->getUid() !== "'.substr($uid, 1, -1).'") { ob_end_clean(); return false; }';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_fetch(Dwoo $dwoo, $file, $assign = null)
{
if($file === '')
return;
if($policy = $dwoo->getSecurityPolicy())
{
while(true)
{
if(preg_match('{^([a-z]+?)://}i', $file))
return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
$file = realpath($file);
$dirs = $policy->getAllowedDirectories();
foreach($dirs as $dir=>$dummy)
{
if(strpos($file, $dir) === 0)
break 2;
}
return $dwoo->triggerError('The security policy prevents you to read <em>'.$file.'</em>', E_USER_WARNING);
}
}
$file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file);
$out = file_get_contents($file);
if($assign !== null)
$dwoo->assignInScope($out, $assign);
else
return $out;
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_fetch(Dwoo $dwoo, $file, $assign = null)
{
if($file === '')
return;
if($policy = $dwoo->getSecurityPolicy())
{
while(true)
{
if(preg_match('{^([a-z]+?)://}i', $file))
return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
$file = realpath($file);
$dirs = $policy->getAllowedDirectories();
foreach($dirs as $dir=>$dummy)
{
if(strpos($file, $dir) === 0)
break 2;
}
return $dwoo->triggerError('The security policy prevents you to read <em>'.$file.'</em>', E_USER_WARNING);
}
}
$file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file);
$out = file_get_contents($file);
if($assign !== null)
$dwoo->assignInScope($out, $assign);
else
return $out;
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_include(Dwoo $dwoo, $file, $cache_time = null, $cache_id = null, $compile_id = null, $assign = null, array $rest = array())
{
if($file === '')
return;
if(preg_match('#^([a-z]{2,}):(.*)#i', $file, $m))
{
$resource = $m[1];
$identifier = $m[2];
}
else
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_include(Dwoo $dwoo, $file, $cache_time = null, $cache_id = null, $compile_id = null, $assign = null, array $rest = array())
{
if($file === '')
return;
if(preg_match('#^([a-z]{2,}):(.*)#i', $file, $m))
{
// get the current template's resource
$resource = $dwoo->getCurrentTemplate()->getResourceName();
$identifier = $file;
}
if($resource === 'file' && $policy = $dwoo->getSecurityPolicy())
{
while(true)
{
if(preg_match('{^([a-z]+?)://}i', $identifier))
return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
$identifier = realpath($identifier);
$dirs = $policy->getAllowedDirectories();
foreach($dirs as $dir=>$dummy)
{
if(strpos($identifier, $dir) === 0)
break 2;
}
return $dwoo->triggerError('The security policy prevents you to read <em>'.$identifier.'</em>', E_USER_WARNING);
}
}
try {
$include = $dwoo->getTemplate($resource, $identifier, $cache_time, $cache_id, $compile_id);
} catch (DwooException $e) {
$dwoo->triggerError('Include : Resource <em>'.$resource.'</em> was not added to Dwoo, can not include <em>'.$identifier.'</em>', E_USER_WARNING);
}
if($include === null)
return;
elseif($include === false)
$dwoo->triggerError('Include : Including "'.$resource.':'.$identifier.'" was not allowed for an unknown reason.', E_USER_WARNING);
if(count($rest))
{
$vars = $rest;
}
else
{
$vars = $dwoo->readVar('_parent');
}
$resource = $m[1];
$identifier = $m[2];
}
else
{
// get the current template's resource
$resource = $dwoo->getTemplate()->getResourceName();
$identifier = $file;
}
if($resource === 'file' && $policy = $dwoo->getSecurityPolicy())
{
while(true)
{
if(preg_match('{^([a-z]+?)://}i', $identifier))
return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
$identifier = realpath($identifier);
$dirs = $policy->getAllowedDirectories();
foreach($dirs as $dir=>$dummy)
{
if(strpos($identifier, $dir) === 0)
break 2;
}
return $dwoo->triggerError('The security policy prevents you to read <em>'.$identifier.'</em>', E_USER_WARNING);
}
}
try {
$include = $dwoo->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id);
} catch (DwooException $e) {
$dwoo->triggerError('Include : Resource <em>'.$resource.'</em> was not added to Dwoo, can not include <em>'.$identifier.'</em>', E_USER_WARNING);
}
if($include === null)
return;
elseif($include === false)
$dwoo->triggerError('Include : Including "'.$resource.':'.$identifier.'" was not allowed for an unknown reason.', E_USER_WARNING);
if(count($rest))
{
$vars = $rest;
}
else
{
$vars = $dwoo->readVar('_parent');
}
$out = $dwoo->get($include, $vars);
if($assign !== null)
$dwoo->assignInScope($out, $assign);
else
return $out;
}
$out = $dwoo->get($include, $vars);
if($assign !== null)
$dwoo->assignInScope($out, $assign);
else
return $out;
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_indent_compile(DwooCompiler $compiler, $value, $by=4, $char=' ')
{
return "preg_replace('#^#m', '".str_repeat(substr($char, 1, -1), trim($by, '"\''))."', $value)";
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_indent_compile(DwooCompiler $compiler, $value, $by=4, $char=' ')
{
return "preg_replace('#^#m', '".str_repeat(substr($char, 1, -1), trim($by, '"\''))."', $value)";
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_isset_compile(DwooCompiler $compiler, $var)
{
return '('.$var.' !== null)';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_isset_compile(DwooCompiler $compiler, $var)
{
return '('.$var.' !== null)';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_lower_compile(DwooCompiler $compiler, $value)
{
return 'mb_strtolower((string) '.$value.', $this->charset)';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_lower_compile(DwooCompiler $compiler, $value)
{
return 'mb_strtolower((string) '.$value.', $this->charset)';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_mailto(Dwoo $dwoo, $address, $text=null, $subject=null, $encode=null, $cc=null, $bcc=null, $newsgroups=null, $followupto=null, $extra=null)
{
if(empty($address))
return '';
if(empty($text))
$text = $address;
// build address string
$address .= '?';
if(!empty($subject))
$address .= 'subject='.rawurlencode($subject).'&';
if(!empty($cc))
$address .= 'cc='.rawurlencode($cc).'&';
if(!empty($bcc))
$address .= 'bcc='.rawurlencode($bcc).'&';
if(!empty($newsgroup))
$address .= 'newsgroups='.rawurlencode($newsgroups).'&';
if(!empty($followupto))
$address .= 'followupto='.rawurlencode($followupto).'&';
$address = rtrim($address, '?&');
// output
switch($encode)
{
case 'none':
case null:
return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
case 'js':
case 'javascript':
$str = 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');';
$len = strlen($str);
$out = '';
for ($i=0; $i<$len; $i++)
$out .= '%'.bin2hex($str[$i]);
return '<script type="text/javascript">eval(unescape(\''.$out.'\'));</script>';
break;
case 'javascript_charcode':
case 'js_charcode':
case 'jscharcode':
case 'jschar':
$str = '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
$len = strlen($str);
$out = '<script type="text/javascript">'."\n<!--\ndocument.write(String.fromCharCode(";
for ($i=0; $i<$len; $i++)
$out .= ord($str[$i]).',';
return rtrim($out, ',') . "));\n-->\n</script>\n";
break;
case 'hex':
if(strpos($address, '?') !== false)
$dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.', E_USER_WARNING);
$out = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;';
$len = strlen($address);
for ($i=0; $i<$len; $i++)
{
if(preg_match('#\w#', $address[$i]))
$out .= '%'.bin2hex($address[$i]);
else
$out .= $address[$i];
}
$out .= '" '.$extra.'>';
$len = strlen($text);
for ($i=0; $i<$len; $i++)
$out .= '&#x'.bin2hex($text[$i]);
return $out.'</a>';
default:
$dwoo->triggerError('Mailto: <em>encode</em> argument is invalid, it must be one of : <em>none (= no value), js, js_charcode or hex</em>', E_USER_WARNING);
}
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_mailto(Dwoo $dwoo, $address, $text=null, $subject=null, $encode=null, $cc=null, $bcc=null, $newsgroups=null, $followupto=null, $extra=null)
{
if(empty($address))
return '';
if(empty($text))
$text = $address;
// build address string
$address .= '?';
if(!empty($subject))
$address .= 'subject='.rawurlencode($subject).'&';
if(!empty($cc))
$address .= 'cc='.rawurlencode($cc).'&';
if(!empty($bcc))
$address .= 'bcc='.rawurlencode($bcc).'&';
if(!empty($newsgroup))
$address .= 'newsgroups='.rawurlencode($newsgroups).'&';
if(!empty($followupto))
$address .= 'followupto='.rawurlencode($followupto).'&';
$address = rtrim($address, '?&');
// output
switch($encode)
{
case 'none':
case null:
return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
case 'js':
case 'javascript':
$str = 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');';
$len = strlen($str);
$out = '';
for ($i=0; $i<$len; $i++)
$out .= '%'.bin2hex($str[$i]);
return '<script type="text/javascript">eval(unescape(\''.$out.'\'));</script>';
break;
case 'javascript_charcode':
case 'js_charcode':
case 'jscharcode':
case 'jschar':
$str = '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
$len = strlen($str);
$out = '<script type="text/javascript">'."\n<!--\ndocument.write(String.fromCharCode(";
for ($i=0; $i<$len; $i++)
$out .= ord($str[$i]).',';
return rtrim($out, ',') . "));\n-->\n</script>\n";
break;
case 'hex':
if(strpos($address, '?') !== false)
$dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.', E_USER_WARNING);
$out = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;';
$len = strlen($address);
for ($i=0; $i<$len; $i++)
{
if(preg_match('#\w#', $address[$i]))
$out .= '%'.bin2hex($address[$i]);
else
$out .= $address[$i];
}
$out .= '" '.$extra.'>';
$len = strlen($text);
for ($i=0; $i<$len; $i++)
$out .= '&#x'.bin2hex($text[$i]);
return $out.'</a>';
default:
$dwoo->triggerError('Mailto: <em>encode</em> argument is invalid, it must be one of : <em>none (= no value), js, js_charcode or hex</em>', E_USER_WARNING);
}
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_math_compile(DwooCompiler $compiler, $equation, $format='', $assign='', array $rest=array())
{
/**
* Holds the allowed function, characters, operators and constants
*/
$allowed = array
(
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'+', '-', '/', '*', '.', ' ', '<<', '>>', '%', '&', '^', '|', '~',
'abs(', 'ceil(', 'floor(', 'exp(', 'log10(',
'cos(', 'sin(', 'sqrt(', 'tan(',
'M_PI', 'INF', 'M_E',
);
/**
* Holds the functions that can accept multiple arguments
*/
$funcs = array
(
'round(', 'log(', 'pow(',
'max(', 'min(', 'rand(',
);
$equation = $equationSrc = str_ireplace(array('pi', 'M_PI()', 'inf', ' e '), array('M_PI', 'M_PI', 'INF', ' M_E '), $equation);
$delim = $equation[0];
$open = $delim.'.';
$close = '.'.$delim;
$equation = substr($equation, 1, -1);
$out = '';
$ptr = 1;
$allowcomma = 0;
while(strlen($equation) > 0)
{
$substr = substr($equation, 0, $ptr);
// allowed string
if (array_search($substr, $allowed) !== false) {
$out.=$substr;
$equation = substr($equation, $ptr);
$ptr = 0;
}
// allowed func
elseif (array_search($substr, $funcs) !== false) {
$out.=$substr;
$equation = substr($equation, $ptr);
$ptr = 0;
$allowcomma++;
if($allowcomma === 1) {
$allowed[] = ',';
}
}
// variable
elseif(isset($rest[$substr]))
{
$out.=$rest[$substr];
$equation = substr($equation, $ptr);
$ptr = 0;
}
// pre-replaced variable
elseif($substr === $open)
{
preg_match('#.*\((?:[^()]*?|(?R))\)'.str_replace('.', '\\.', $close).'#', substr($equation, 2), $m);
if(empty($m))
preg_match('#.*?'.str_replace('.', '\\.', $close).'#', substr($equation, 2), $m);
$out.=substr($m[0], 0, -2);
$equation = substr($equation, strlen($m[0])+2);
$ptr = 0;
}
// opening parenthesis
elseif ($substr==='(') {
if($allowcomma>0)
$allowcomma++;
$out.=$substr;
$equation = substr($equation, $ptr);
$ptr = 0;
}
// closing parenthesis
elseif ($substr===')') {
if($allowcomma>0) {
$allowcomma--;
if($allowcomma===0) {
array_pop($allowed);
}
}
$out.=$substr;
$equation = substr($equation, $ptr);
$ptr = 0;
}
// parse error if we've consumed the entire equation without finding anything valid
elseif ($ptr >= strlen($equation)) {
$compiler->triggerError('Math : Syntax error or variable undefined in equation '.$equationSrc.' at '.$substr, E_USER_ERROR);
return;
}
else
{
$ptr++;
}
}
if($format !== '\'\'')
$out = 'sprintf('.$format.', '.$out.')';
if($assign !== '\'\'')
return '($this->assignInScope('.$out.', '.$assign.'))';
return '('.$out.')';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_math_compile(DwooCompiler $compiler, $equation, $format='', $assign='', array $rest=array())
{
/**
* Holds the allowed function, characters, operators and constants
*/
$allowed = array
(
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'+', '-', '/', '*', '.', ' ', '<<', '>>', '%', '&', '^', '|', '~',
'abs(', 'ceil(', 'floor(', 'exp(', 'log10(',
'cos(', 'sin(', 'sqrt(', 'tan(',
'M_PI', 'INF', 'M_E',
);
/**
* Holds the functions that can accept multiple arguments
*/
$funcs = array
(
'round(', 'log(', 'pow(',
'max(', 'min(', 'rand(',
);
$equation = $equationSrc = str_ireplace(array('pi', 'M_PI()', 'inf', ' e '), array('M_PI', 'M_PI', 'INF', ' M_E '), $equation);
$delim = $equation[0];
$open = $delim.'.';
$close = '.'.$delim;
$equation = substr($equation, 1, -1);
$out = '';
$ptr = 1;
$allowcomma = 0;
while(strlen($equation) > 0)
{
$substr = substr($equation, 0, $ptr);
// allowed string
if (array_search($substr, $allowed) !== false) {
$out.=$substr;
$equation = substr($equation, $ptr);
$ptr = 0;
}
// allowed func
elseif (array_search($substr, $funcs) !== false) {
$out.=$substr;
$equation = substr($equation, $ptr);
$ptr = 0;
$allowcomma++;
if($allowcomma === 1) {
$allowed[] = ',';
}
}
// variable
elseif(isset($rest[$substr]))
{
$out.=$rest[$substr];
$equation = substr($equation, $ptr);
$ptr = 0;
}
// pre-replaced variable
elseif($substr === $open)
{
preg_match('#.*\((?:[^()]*?|(?R))\)'.str_replace('.', '\\.', $close).'#', substr($equation, 2), $m);
if(empty($m))
preg_match('#.*?'.str_replace('.', '\\.', $close).'#', substr($equation, 2), $m);
$out.=substr($m[0], 0, -2);
$equation = substr($equation, strlen($m[0])+2);
$ptr = 0;
}
// opening parenthesis
elseif ($substr==='(') {
if($allowcomma>0)
$allowcomma++;
$out.=$substr;
$equation = substr($equation, $ptr);
$ptr = 0;
}
// closing parenthesis
elseif ($substr===')') {
if($allowcomma>0) {
$allowcomma--;
if($allowcomma===0) {
array_pop($allowed);
}
}
$out.=$substr;
$equation = substr($equation, $ptr);
$ptr = 0;
}
// parse error if we've consumed the entire equation without finding anything valid
elseif ($ptr >= strlen($equation)) {
$compiler->triggerError('Math : Syntax error or variable undefined in equation '.$equationSrc.' at '.$substr, E_USER_ERROR);
return;
}
else
{
$ptr++;
}
}
if($format !== '\'\'')
$out = 'sprintf('.$format.', '.$out.')';
if($assign !== '\'\'')
return '($this->assignInScope('.$out.', '.$assign.'))';
return '('.$out.')';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_nl2br_compile(DwooCompiler $compiler, $value)
{
return 'nl2br((string) '.$value.')';
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_nl2br_compile(DwooCompiler $compiler, $value)
{
return 'nl2br((string) '.$value.')';
}
?>
\ No newline at end of file
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_regex_replace(Dwoo $dwoo, $value, $search, $replace)
{
// Credits for this to Monte Ohrt who made smarty's regex_replace modifier
if(($pos = strpos($search,"\0")) !== false)
$search = substr($search,0,$pos);
if(preg_match('#([a-z\s]+)$#i', $search, $m) && strpos($m[0], 'e') !== false) {
$search = substr($search, 0, -strlen($m[0])) . str_replace('e', '', $m[0]);
}
return preg_replace($search, $replace, $value);
}
<?php
/**
* TOCOM
*
* 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 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 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
function DwooPlugin_regex_replace(Dwoo $dwoo, $value, $search, $replace)
{
// Credits for this to Monte Ohrt who made smarty's regex_replace modifier
if(($pos = strpos($search,"\0")) !== false)
$search = substr($search,0,$pos);
if(preg_match('#([a-z\s]+)$#i', $search, $m) && strpos($m[0], 'e') !== false) {
$search = substr($search, 0, -strlen($m[0])) . str_replace('e', '', $m[0]);
}
return preg_replace($search, $replace, $value);
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment