REFACTORING: framework cleanup, preparing for php7.4 and loading dependencies from composer
This commit is contained in:
0
core/l/.gitkeep
Normal file
0
core/l/.gitkeep
Normal file
@@ -1,119 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Block
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Block;
|
||||
|
||||
use Dwoo\Plugin as DwooPlugin;
|
||||
use Dwoo\Compiler as DwooCompiler;
|
||||
|
||||
/**
|
||||
* Base class for block plugins.
|
||||
* you have to implement the <em>init()</em> method, it will receive the parameters that
|
||||
* are in the template code and is called when the block starts
|
||||
* 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.
|
||||
*/
|
||||
abstract class Plugin extends DwooPlugin
|
||||
{
|
||||
/**
|
||||
* Stores the contents of the block while it runs.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $buffer = '';
|
||||
|
||||
/**
|
||||
* Buffers input, override only if necessary.
|
||||
*
|
||||
* @var string the content that must be buffered
|
||||
*/
|
||||
public function buffer($input)
|
||||
{
|
||||
$this->buffer .= $input;
|
||||
}
|
||||
|
||||
// initialization code, receives the parameters from {block param1 param2}
|
||||
// public function init($arg, $arg, ...);
|
||||
|
||||
/**
|
||||
* Called when the block ends, this is most of the time followed right away by a call
|
||||
* of <em>process()</em> but not always, so this should be used to do any shutdown operations on the
|
||||
* block object, if required.
|
||||
*/
|
||||
public function end()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the block output is required by a parent block.
|
||||
* this must read $this->buffer and return it processed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
return $this->buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at compile time to define what the block should output in the compiled template code, happens when the
|
||||
* block is declared basically this will replace the {block arg arg arg} tag in the template.
|
||||
*
|
||||
* @param DwooCompiler $compiler the compiler instance that calls this function
|
||||
* @param array $params an array containing original and compiled parameters
|
||||
* @param string $prepend that is just meant to allow a child class to call
|
||||
* parent::postProcessing($compiler, $params, "foo();") to add a command before the
|
||||
* default commands are executed parent::postProcessing($compiler, $params, "foo();")
|
||||
* to add a command before the default commands are executed
|
||||
* @param string $append that is just meant to allow a child class to call
|
||||
* parent::postProcessing($compiler, $params, null, "foo();") to add a command after
|
||||
* the default commands are executed parent::postProcessing($compiler, $params, null,
|
||||
* "foo();") to add a command after the default commands are executed
|
||||
* @param string $type the type is the plugin class name used
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
return DwooCompiler::PHP_OPEN . $prepend . '$this->addStack("' . $type . '", array(' . DwooCompiler::implode_r($compiler->getCompiledParams($params)) . '));' . $append . DwooCompiler::PHP_CLOSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at compile time to define what the block should output in the compiled template code, happens when the
|
||||
* block is ended basically this will replace the {/block} tag in the template.
|
||||
*
|
||||
* @see preProcessing
|
||||
*
|
||||
* @param DwooCompiler $compiler the compiler instance that calls this function
|
||||
* @param array $params an array containing original and compiled parameters, see preProcessing() for more
|
||||
* details more details
|
||||
* @param string $prepend that is just meant to allow a child class to call
|
||||
* parent::postProcessing($compiler, $params, "foo();") to add a command before the
|
||||
* default commands are executed parent::postProcessing($compiler, $params, "foo();")
|
||||
* to add a command before the default commands are executed
|
||||
* @param string $append that is just meant to allow a child class to call
|
||||
* parent::postProcessing($compiler, $params, null, "foo();") to add a command after
|
||||
* the default commands are executed parent::postProcessing($compiler, $params, null,
|
||||
* "foo();") to add a command after the default commands are executed
|
||||
* @param string $content the entire content of the block being closed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
return $content . DwooCompiler::PHP_OPEN . $prepend . '$this->delStack();' . $append . DwooCompiler::PHP_CLOSE;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Compilation
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.3.6
|
||||
* @date 2017-03-21
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Compilation;
|
||||
|
||||
use Dwoo\Exception as DwooException;
|
||||
use Dwoo\Compiler as DwooCompiler;
|
||||
|
||||
/**
|
||||
* Dwoo compilation exception class.
|
||||
* 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.
|
||||
*/
|
||||
class Exception extends DwooException
|
||||
{
|
||||
protected $compiler;
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* Exception constructor.
|
||||
*
|
||||
* @param DwooCompiler $compiler
|
||||
* @param int $message
|
||||
*/
|
||||
public function __construct(DwooCompiler $compiler, $message)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->template = $compiler->getCore()->getTemplate();
|
||||
parent::__construct('Compilation error at line ' . $compiler->getLine() . ' in "' . $this->template->getResourceName() . ':' . $this->template->getResourceIdentifier() . '" : ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DwooCompiler
|
||||
*/
|
||||
public function getCompiler()
|
||||
{
|
||||
return $this->compiler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Dwoo\ITemplate|null
|
||||
*/
|
||||
public function getTemplate()
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
1792
core/l/Dwoo/Core.php
1792
core/l/Dwoo/Core.php
File diff suppressed because it is too large
Load Diff
@@ -1,264 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.4
|
||||
* @date 2017-03-01
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class Data implements IDataProvider
|
||||
{
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function mergeData(array $data)
|
||||
{
|
||||
$args = func_get_args();
|
||||
foreach ($args as $key => $v) {
|
||||
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);
|
||||
foreach ($name as $k => $v){
|
||||
$this->data[$k] = $v;
|
||||
}
|
||||
} else {
|
||||
$this->data[$name] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to assign variables using the object syntax.
|
||||
*
|
||||
* @param string $name the variable name
|
||||
* @param string $value the value to assign to it
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->assign($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
} elseif (!isset($this->data[$name])) {
|
||||
$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 => &$value) {
|
||||
$this->data[$name][$key] = &$value;
|
||||
}
|
||||
} else {
|
||||
$this->data[$name][] = &$val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the variable has been assigned already, false otherwise.
|
||||
*
|
||||
* @param string $name the variable name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAssigned($name)
|
||||
{
|
||||
return isset($this->data[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports calls to isset($dwoo->var).
|
||||
*
|
||||
* @param string $name the variable name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name)
|
||||
{
|
||||
return isset($this->data[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassigns/removes a variable.
|
||||
*
|
||||
* @param string $name the variable name
|
||||
*/
|
||||
public function unassign($name)
|
||||
{
|
||||
unset($this->data[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports unsetting variables using the object syntax.
|
||||
*
|
||||
* @param string $name the variable name
|
||||
*/
|
||||
public function __unset($name)
|
||||
{
|
||||
unset($this->data[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a variable if it was assigned.
|
||||
*
|
||||
* @param string $name the variable name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
return $this->__get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to read variables using the object syntax.
|
||||
*
|
||||
* @param string $name the variable name
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if (isset($this->data[$name])) {
|
||||
return $this->data[$name];
|
||||
} else {
|
||||
throw new Exception('Tried to read a value that was not assigned yet : "' . $name . '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Main dwoo exception class.
|
||||
* 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.
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Base class for filters.
|
||||
* 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.
|
||||
*/
|
||||
abstract class Filter
|
||||
{
|
||||
/**
|
||||
* The dwoo instance that runs this filter.
|
||||
*
|
||||
* @var Core
|
||||
*/
|
||||
protected $dwoo;
|
||||
|
||||
/**
|
||||
* Constructor, if you override it, call parent::__construct($dwoo); or assign
|
||||
* the dwoo instance yourself if you need it.
|
||||
*
|
||||
* @param Core $dwoo the dwoo instance that runs this plugin
|
||||
*/
|
||||
public function __construct(Core $dwoo)
|
||||
{
|
||||
$this->dwoo = $dwoo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the input and returns it filtered.
|
||||
*
|
||||
* @param string $input the template to process
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function process($input);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Interface that represents a compilable plugin.
|
||||
* implement this to notify the compiler that this plugin does not need to be loaded at runtime.
|
||||
* to implement it right, you must implement <em>public static function compile(Compiler $compiler, $arg, $arg,
|
||||
* ...)</em>, which replaces the <em>process()</em> method (that means <em>compile()</em> should have all arguments it
|
||||
* requires). 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.
|
||||
*/
|
||||
interface ICompilable
|
||||
{
|
||||
// this replaces the process function
|
||||
//public static function compile(Compiler $compiler, $arg, $arg, ...);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\ICompilable
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\ICompilable;
|
||||
|
||||
/**
|
||||
* Interface that represents a compilable block plugin.
|
||||
* implement this to notify the compiler that this plugin does not need to be loaded at runtime.
|
||||
* 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.
|
||||
*/
|
||||
interface Block
|
||||
{
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.3.6
|
||||
* @date 2017-03-21
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
use Dwoo\Security\Policy as SecurityPolicy;
|
||||
|
||||
/**
|
||||
* Interface that represents a dwoo compiler.
|
||||
* while implementing this is enough to interact with Dwoo/Templates, it is not
|
||||
* sufficient to interact with Dwoo/Plugins, however the main purpose of creating a
|
||||
* new compiler would be to interact with other/different plugins, that is why this
|
||||
* interface has been left with the minimum requirements.
|
||||
* 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.
|
||||
*/
|
||||
interface ICompiler
|
||||
{
|
||||
/**
|
||||
* Compiles the provided string down to php code.
|
||||
*
|
||||
* @param Core $core
|
||||
* @param ITemplate $template the template to compile
|
||||
*
|
||||
* @return string a compiled php code string
|
||||
*/
|
||||
public function compile(Core $core, ITemplate $template);
|
||||
|
||||
/**
|
||||
* Adds the custom plugins loaded into Dwoo to the compiler so it can load them.
|
||||
*
|
||||
* @see Core::addPlugin
|
||||
*
|
||||
* @param array $customPlugins an array of custom plugins
|
||||
*/
|
||||
public function setCustomPlugins(array $customPlugins);
|
||||
|
||||
/**
|
||||
* Sets the security policy object to enforce some php security settings.
|
||||
* use this if untrusted persons can modify templates,
|
||||
* set it on the Dwoo object as it will be passed onto the compiler automatically
|
||||
*
|
||||
* @param SecurityPolicy $policy the security policy object
|
||||
*/
|
||||
public function setSecurityPolicy(SecurityPolicy $policy = null);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Interface that represents a dwoo data object.
|
||||
* 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.
|
||||
*/
|
||||
interface IDataProvider
|
||||
{
|
||||
/**
|
||||
* Returns the data as an associative array that will be used in the template.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData();
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Interface that represents a block plugin that supports the else functionality.
|
||||
* the else block will enter an "hasElse" parameter inside the parameters array
|
||||
* of the closest parent implementing this interface, the hasElse parameter contains
|
||||
* the else output that should be appended to the block's content (see foreach or other
|
||||
* block for examples)
|
||||
* 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.
|
||||
*/
|
||||
interface IElseable
|
||||
{
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Interface for dwoo plugin loaders.
|
||||
* 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.
|
||||
*/
|
||||
interface ILoader
|
||||
{
|
||||
/**
|
||||
* Loads a plugin file.
|
||||
* the second parameter is used to avoid permanent rehashing when using php functions,
|
||||
* however this means that if you have add a plugin that overrides a php function you have
|
||||
* to delete the classpath.cache file(s) by hand to force a rehash of the plugins
|
||||
*
|
||||
* @param string $class the plugin name, without the `Plugin` prefix
|
||||
* @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it
|
||||
* has just been added, defaults to true
|
||||
*/
|
||||
public function loadPlugin($class, $forceRehash = true);
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Interface that represents a dwoo plugin proxy.
|
||||
* 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.
|
||||
*/
|
||||
interface IPluginProxy
|
||||
{
|
||||
/**
|
||||
* Returns true or false to say whether the given plugin is handled by this proxy or not.
|
||||
*
|
||||
* @param string $name the plugin name
|
||||
*
|
||||
* @return bool true if the plugin is known and usable, otherwise false
|
||||
*/
|
||||
public function handles($name);
|
||||
|
||||
/**
|
||||
* Returns the code (as a string) to call the plugin
|
||||
* (this will be executed at runtime inside the Dwoo class).
|
||||
*
|
||||
* @param string $name the plugin name
|
||||
* @param array $params a parameter array, array key "*" is the rest array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCode($name, $params);
|
||||
|
||||
/**
|
||||
* Returns a callback to the plugin, this is used with the reflection API to
|
||||
* find out about the plugin's parameter names etc.
|
||||
* should you need a rest array without the possibility to edit the
|
||||
* plugin's code, you can provide a callback to some
|
||||
* other function with the correct parameter signature, i.e. :
|
||||
* <code>
|
||||
* return array($this, "callbackHelper");
|
||||
* // and callbackHelper would be as such:
|
||||
* public function callbackHelper(array $rest=array()){}
|
||||
* </code>
|
||||
*
|
||||
* @param string $name the plugin name
|
||||
*
|
||||
* @return callback
|
||||
*/
|
||||
public function getCallback($name);
|
||||
|
||||
/**
|
||||
* Returns some code that will check if the plugin is loaded and if not load it
|
||||
* this is optional, if your plugins are autoloaded or whatever, just return an
|
||||
* empty string.
|
||||
*
|
||||
* @param string $name the plugin name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLoader($name);
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.4
|
||||
* @date 2017-03-07
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Interface that represents a dwoo template.
|
||||
* 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.
|
||||
*/
|
||||
interface ITemplate
|
||||
{
|
||||
/**
|
||||
* Returns the cache duration for this template.
|
||||
* defaults to null if it was not provided
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCacheTime();
|
||||
|
||||
/**
|
||||
* Sets the cache duration for this template.
|
||||
* can be used to set it after the object is created if you did not provide
|
||||
* it in the constructor
|
||||
*
|
||||
* @param int $seconds duration of the cache validity for this template, if
|
||||
* null it defaults to the Dwoo instance's cache time. 0 = disable and
|
||||
* -1 = infinite cache
|
||||
*/
|
||||
public function setCacheTime($seconds = null);
|
||||
|
||||
/**
|
||||
* Returns the cached template output file name, true if it's cache-able but not cached
|
||||
* or false if it's not cached.
|
||||
*
|
||||
* @param Core $core the dwoo instance that requests it
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getCachedTemplate(Core $core);
|
||||
|
||||
/**
|
||||
* Caches the provided output into the cache file.
|
||||
*
|
||||
* @param Core $core the dwoo instance that requests it
|
||||
* @param string $output the template output
|
||||
*
|
||||
* @return mixed full path of the cached file or false upon failure
|
||||
*/
|
||||
public function cache(Core $core, $output);
|
||||
|
||||
/**
|
||||
* Clears the cached template if it's older than the given time.
|
||||
*
|
||||
* @param Core $core the dwoo instance that was used to cache that template
|
||||
* @param int $olderThan minimum time (in seconds) required for the cache to be cleared
|
||||
*
|
||||
* @return bool true if the cache was not present or if it was deleted, false if it remains there
|
||||
*/
|
||||
public function clearCache(Core $core, $olderThan = - 1);
|
||||
|
||||
/**
|
||||
* Returns the compiled template file name.
|
||||
*
|
||||
* @param Core $core the dwoo instance that requests it
|
||||
* @param ICompiler $compiler the compiler that must be used
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCompiledTemplate(Core $core, ICompiler $compiler = null);
|
||||
|
||||
/**
|
||||
* Returns the template name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Returns the resource name for this template class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceName();
|
||||
|
||||
/**
|
||||
* Returns the resource identifier for this template or false if it has no identifier.
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function getResourceIdentifier();
|
||||
|
||||
/**
|
||||
* Returns the template source of this template.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSource();
|
||||
|
||||
/**
|
||||
* Returns an unique string identifying the current version of this template,
|
||||
* for example a timestamp of the last modified date or a hash of the template source.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUid();
|
||||
|
||||
/**
|
||||
* Returns the compiler used by this template, if it was just compiled, or null.
|
||||
*
|
||||
* @return ICompiler
|
||||
*/
|
||||
public function getCompiler();
|
||||
|
||||
/**
|
||||
* Returns some php code that will check if this template has been modified or not.
|
||||
* if the function returns null, the template will be instanciated and then the Uid checked
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIsModifiedCode();
|
||||
|
||||
/**
|
||||
* Returns a new template object from the given resource identifier, null if no include is
|
||||
* possible (resource not found), or false if include is not permitted by this resource type.
|
||||
* this method should also check if $dwoo->getSecurityPolicy() is null or not and do the
|
||||
* necessary permission checks if required, if the security policy prevents the template
|
||||
* generation it should throw a new Security\Exception with a relevant message
|
||||
*
|
||||
* @param Core $core
|
||||
* @param mixed $resourceId the resource identifier
|
||||
* @param int $cacheTime duration of the cache validity for this template, if null it defaults to the
|
||||
* Dwoo instance that will render this template if null it defaults to the Dwoo
|
||||
* instance that will render this template
|
||||
* @param string $cacheId the unique cache identifier of this page or anything else that makes this
|
||||
* template's content unique, if null it defaults to the current url makes this
|
||||
* template's content unique, if null it defaults to the current url
|
||||
* @param string $compileId the unique compiled identifier, which is used to distinguish this template from
|
||||
* others, if null it defaults to the filename+bits of the path template from
|
||||
* others, if null it defaults to the filename+bits of the path
|
||||
* @param ITemplate $parentTemplate the template that is requesting a new template object (through an include,
|
||||
* extends or any other plugin) an include, extends or any other plugin)
|
||||
*
|
||||
* @return ITemplate|false|null
|
||||
*/
|
||||
public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null,
|
||||
$compileId = null, ITemplate $parentTemplate = null);
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.4.0
|
||||
* @date 2017-03-16
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Handles plugin loading and caching of plugins names/paths relationships.
|
||||
* 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.
|
||||
*/
|
||||
class Loader implements ILoader
|
||||
{
|
||||
/**
|
||||
* Stores the plugin directories.
|
||||
*
|
||||
* @see addDirectory
|
||||
* @var array
|
||||
*/
|
||||
protected $paths = array();
|
||||
|
||||
/**
|
||||
* Stores the plugins names/paths relationships
|
||||
* don't edit this on your own, use addDirectory.
|
||||
*
|
||||
* @see addDirectory
|
||||
* @var array
|
||||
*/
|
||||
protected $classPath = array();
|
||||
|
||||
/**
|
||||
* Path where class paths cache files are written.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $cacheDir;
|
||||
|
||||
/**
|
||||
* Path where builtin plugins are stored.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $corePluginDir;
|
||||
|
||||
/**
|
||||
* Loader constructor.
|
||||
*
|
||||
* @param $cacheDir
|
||||
*/
|
||||
public function __construct($cacheDir)
|
||||
{
|
||||
$this->corePluginDir = __DIR__ . DIRECTORY_SEPARATOR;
|
||||
$this->cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
|
||||
// include class paths or rebuild paths if the cache file isn't there
|
||||
$cacheFile = $this->cacheDir . 'classpath.cache.d' . Core::RELEASE_TAG . '.php';
|
||||
if (file_exists($cacheFile)) {
|
||||
$classpath = file_get_contents($cacheFile);
|
||||
$this->classPath = unserialize($classpath) + $this->classPath;
|
||||
} else {
|
||||
$this->rebuildClassPathCache($this->corePluginDir, $cacheFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuilds class paths, scans the given directory recursively and saves all paths in the given file.
|
||||
*
|
||||
* @param string $path the plugin path to scan
|
||||
* @param string|boolean $cacheFile the file where to store the plugin paths cache, it will be overwritten
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function rebuildClassPathCache($path, $cacheFile)
|
||||
{
|
||||
$tmp = array();
|
||||
if ($cacheFile !== false) {
|
||||
$tmp = $this->classPath;
|
||||
$this->classPath = array();
|
||||
}
|
||||
|
||||
// iterates over all files/folders
|
||||
foreach (new \DirectoryIterator($path) as $fileInfo) {
|
||||
if (!$fileInfo->isDot()) {
|
||||
if ($fileInfo->isDir()) {
|
||||
$this->rebuildClassPathCache($fileInfo->getPathname(), false);
|
||||
} else {
|
||||
$this->classPath[$fileInfo->getBasename('.php')] = $fileInfo->getPathname();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// save in file if it's the first call (not recursed)
|
||||
if ($cacheFile !== false) {
|
||||
if (!file_put_contents($cacheFile, serialize($this->classPath))) {
|
||||
throw new Exception('Could not write into ' . $cacheFile . ', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()');
|
||||
}
|
||||
$this->classPath += $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a plugin file.
|
||||
*
|
||||
* @param string $class the plugin name, without the `Plugin` prefix
|
||||
* @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it
|
||||
* has just been added, defaults to true
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function loadPlugin($class, $forceRehash = true)
|
||||
{
|
||||
/**
|
||||
* An unknown class was requested (maybe newly added) or the
|
||||
* include failed so we rebuild the cache. include() will fail
|
||||
* with an uncatchable error if the file doesn't exist, which
|
||||
* usually means that the cache is stale and must be rebuilt,
|
||||
* so we check for that before trying to include() the plugin.
|
||||
*/
|
||||
if ((!isset($this->classPath[$class]) || !is_readable($this->classPath[$class])) || (!isset
|
||||
($this->classPath[$class . 'Compile']) || !is_readable($this->classPath[$class . 'Compile']))) {
|
||||
if ($forceRehash) {
|
||||
$this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d' .
|
||||
Core::RELEASE_TAG . '.php');
|
||||
foreach ($this->paths as $path => $file) {
|
||||
$this->rebuildClassPathCache($path, $file);
|
||||
}
|
||||
if (isset($this->classPath[$class])) {
|
||||
include_once $this->classPath[$class];
|
||||
} elseif (isset($this->classPath[$class . 'Compile'])) {
|
||||
include_once $this->classPath[$class . 'Compile'];
|
||||
} else {
|
||||
throw new Exception('Plugin "' . $class . '" can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
|
||||
}
|
||||
} else {
|
||||
throw new Exception('Plugin "' . $class . '" can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a plugin directory, the plugins found in the new plugin directory
|
||||
* will take precedence over the other directories (including the default
|
||||
* dwoo plugin directory), you can use this for example to override plugins
|
||||
* in a specific directory for a specific application while keeping all your
|
||||
* usual plugins in the same place for all applications.
|
||||
* TOCOM don't forget that php functions overrides are not rehashed so you
|
||||
* need to clear the classpath caches by hand when adding those.
|
||||
*
|
||||
* @param string $pluginDirectory the plugin path to scan
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addDirectory($pluginDirectory)
|
||||
{
|
||||
$pluginDir = realpath($pluginDirectory);
|
||||
if (!$pluginDir) {
|
||||
throw new Exception('Plugin directory does not exist or can not be read : ' . $pluginDirectory);
|
||||
}
|
||||
$cacheFile = $this->cacheDir . 'classpath-' . substr(strtr($pluginDir, '/\\:' . PATH_SEPARATOR, '----'),
|
||||
strlen($pluginDir) > 80 ? - 80 : 0) . '.d' . Core::RELEASE_TAG . '.php';
|
||||
$this->paths[$pluginDir] = $cacheFile;
|
||||
if (file_exists($cacheFile)) {
|
||||
$classpath = file_get_contents($cacheFile);
|
||||
$this->classPath = unserialize($classpath) + $this->classPath;
|
||||
} else {
|
||||
$this->rebuildClassPathCache($pluginDir, $cacheFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Base plugin class.
|
||||
* you have to implement the <em>process()</em> method, it will receive the parameters that
|
||||
* are in the template code
|
||||
* 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.
|
||||
*/
|
||||
abstract class Plugin
|
||||
{
|
||||
/**
|
||||
* The dwoo instance that runs this plugin.
|
||||
*
|
||||
* @var Core
|
||||
*/
|
||||
protected $core;
|
||||
|
||||
/**
|
||||
* Constructor, if you override it, call parent::__construct($core); or assign
|
||||
* the dwoo instance yourself if you need it.
|
||||
*
|
||||
* @param Core $core the dwoo instance that runs this plugin
|
||||
*/
|
||||
public function __construct(Core $core)
|
||||
{
|
||||
$this->core = $core;
|
||||
}
|
||||
|
||||
// plugins should always implement :
|
||||
// public function process($arg, $arg, ...)
|
||||
// or for block plugins :
|
||||
// public function init($arg, $arg, ...)
|
||||
|
||||
// this could be enforced with :
|
||||
// abstract public function process(...);
|
||||
// if my feature request gets enough interest one day
|
||||
// see => http://bugs.php.net/bug.php?id=44043
|
||||
|
||||
/**
|
||||
* Utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag
|
||||
* attributes. this is to be used in preProcessing or postProcessing functions, example :
|
||||
* $p = $compiler->getCompiledParams($params);
|
||||
* // get only the rest array as attributes
|
||||
* $attributes = Plugin::paramsToAttributes($p['*']);
|
||||
* // get all the parameters as attributes (if there is a rest array, it will be included)
|
||||
* $attributes = Plugin::paramsToAttributes($p);
|
||||
*
|
||||
* @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string
|
||||
* inclusion in a php string
|
||||
* @param string $delim the string delimiter you want to use (defaults to ')
|
||||
* @param Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior)
|
||||
* escaping behavior)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function paramsToAttributes(array $params, $delim = '\'', Compiler $compiler = null)
|
||||
{
|
||||
if (isset($params['*'])) {
|
||||
$params = array_merge($params, $params['*']);
|
||||
unset($params['*']);
|
||||
}
|
||||
|
||||
$out = '';
|
||||
foreach ($params as $attr => $val) {
|
||||
$out .= ' ' . $attr . '=';
|
||||
if (trim($val, '"\'') == '' || $val == 'null') {
|
||||
$out .= str_replace($delim, '\\' . $delim, '""');
|
||||
} elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) {
|
||||
$out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"');
|
||||
} else {
|
||||
if (!$compiler) {
|
||||
// disable double encoding since it can not be determined if it was encoded
|
||||
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).';
|
||||
} elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) {
|
||||
// escape if auto escaping is disabled, or there was no variable in the string
|
||||
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).';
|
||||
} else {
|
||||
// print as is
|
||||
$escapedVal = '.' . $val . '.';
|
||||
}
|
||||
|
||||
$out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"');
|
||||
}
|
||||
}
|
||||
|
||||
return ltrim($out);
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Outputs a html <a> tag
|
||||
* <pre>
|
||||
* * href : the target URI where the link must point
|
||||
* * rest : any other attributes you want to add to the tag can be added as named parameters
|
||||
* </pre>.
|
||||
* Example :
|
||||
* <code>
|
||||
* {* Create a simple link out of an url variable and add a special class attribute: *}
|
||||
* {a $url class="external" /}
|
||||
* {* Mark a link as active depending on some other variable : *}
|
||||
* {a $link.url class=tif($link.active "active"); $link.title /}
|
||||
* {* This is similar to: <a href="{$link.url}" class="{if $link.active}active{/if}">{$link.title}</a> *}
|
||||
* </code>
|
||||
* 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.
|
||||
*/
|
||||
class PluginA extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
/**
|
||||
* @param $href
|
||||
* @param array $rest
|
||||
*/
|
||||
public function init($href, array $rest = array())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
$p = $compiler->getCompiledParams($params);
|
||||
|
||||
$out = Compiler::PHP_OPEN . 'echo \'<a ' . self::paramsToAttributes($p, "'", $compiler);
|
||||
|
||||
return $out . '>\';' . Compiler::PHP_CLOSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$p = $compiler->getCompiledParams($params);
|
||||
|
||||
// no content was provided so use the url as display text
|
||||
if ($content == '') {
|
||||
// merge </a> into the href if href is a string
|
||||
if (substr($p['href'], - 1) === '"' || substr($p['href'], - 1) === '\'') {
|
||||
return Compiler::PHP_OPEN . 'echo ' . substr($p['href'], 0, - 1) . '</a>' . substr($p['href'], - 1) . ';' . Compiler::PHP_CLOSE;
|
||||
}
|
||||
|
||||
// otherwise append
|
||||
return Compiler::PHP_OPEN . 'echo ' . $p['href'] . '.\'</a>\';' . Compiler::PHP_CLOSE;
|
||||
}
|
||||
|
||||
// return content
|
||||
return $content . '</a>';
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
|
||||
/**
|
||||
* Overrides the compiler auto-escape setting within the block
|
||||
* <pre>
|
||||
* * enabled : if set to "on", "enable", true or 1 then the compiler autoescaping is enabled inside this block. set to
|
||||
* "off", "disable", false or 0 to disable it
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginAutoEscape extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
protected static $stack = array();
|
||||
|
||||
/**
|
||||
* @param $enabled
|
||||
*/
|
||||
public function init($enabled)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
switch (strtolower(trim((string)$params['enabled'], '"\''))) {
|
||||
|
||||
case 'on':
|
||||
case 'true':
|
||||
case 'enabled':
|
||||
case 'enable':
|
||||
case '1':
|
||||
$enable = true;
|
||||
break;
|
||||
case 'off':
|
||||
case 'false':
|
||||
case 'disabled':
|
||||
case 'disable':
|
||||
case '0':
|
||||
$enable = false;
|
||||
break;
|
||||
default:
|
||||
throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false');
|
||||
}
|
||||
|
||||
self::$stack[] = $compiler->getAutoEscape();
|
||||
$compiler->setAutoEscape($enable);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$compiler->setAutoEscape(array_pop(self::$stack));
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* This is used only when rendering a template that has blocks but is not extending anything,
|
||||
* it doesn't do anything by itself and should not be used outside of template inheritance context,
|
||||
* see {@link http://wiki.dwoo.org/index.php/TemplateInheritance} to read more about it.
|
||||
* 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.
|
||||
*/
|
||||
class PluginBlock extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function init($name = '')
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Captures all the output within this block and saves it into {$.capture.default} by default,
|
||||
* or {$.capture.name} if you provide another name.
|
||||
* <pre>
|
||||
* * name : capture name, used to read the value afterwards
|
||||
* * assign : if set, the value is also saved in the given variable
|
||||
* * cat : if true, the value is appended to the previous one (if any) instead of overwriting it
|
||||
* </pre>
|
||||
* If the cat parameter is true, the content
|
||||
* will be appended to the existing content.
|
||||
* Example :
|
||||
* <code>
|
||||
* {capture "foo"}
|
||||
* Anything in here won't show, it will be saved for later use..
|
||||
* {/capture}
|
||||
* Output was : {$.capture.foo}
|
||||
* </code>
|
||||
* 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.
|
||||
*/
|
||||
class PluginCapture extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
* @param null $assign
|
||||
* @param bool $cat
|
||||
* @param bool $trim
|
||||
*/
|
||||
public function init($name = 'default', $assign = null, $cat = false, $trim = false)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
return Compiler::PHP_OPEN . $prepend . 'ob_start();' . $append . Compiler::PHP_CLOSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
|
||||
$out = $content . Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();';
|
||||
if ($params['trim'] !== 'false' && $params['trim'] !== 0) {
|
||||
$out .= "\n" . '$tmp = trim($tmp);';
|
||||
}
|
||||
if ($params['cat'] === 'true' || $params['cat'] === 1) {
|
||||
$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 . Compiler::PHP_CLOSE;
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
|
||||
/**
|
||||
* Marks the contents of the block as dynamic. Which means that it will not be cached.
|
||||
* 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.
|
||||
*/
|
||||
class PluginDynamic extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
try {
|
||||
$compiler->findBlock('dynamic');
|
||||
|
||||
return $content;
|
||||
}
|
||||
catch (CompilationException $e) {
|
||||
}
|
||||
$output = Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t";
|
||||
if (substr($content, 0, strlen(Compiler::PHP_OPEN)) == Compiler::PHP_OPEN) {
|
||||
$output .= substr($content, strlen(Compiler::PHP_OPEN));
|
||||
} else {
|
||||
$output .= Compiler::PHP_CLOSE . $content;
|
||||
}
|
||||
if (substr($output, - strlen(Compiler::PHP_CLOSE)) == Compiler::PHP_CLOSE) {
|
||||
$output = substr($output, 0, - strlen(Compiler::PHP_CLOSE));
|
||||
} else {
|
||||
$output .= Compiler::PHP_OPEN;
|
||||
}
|
||||
$output .= "\n}" . Compiler::PHP_CLOSE;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $output
|
||||
* @param $dynamicId
|
||||
* @param $compiledFile
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function unescape($output, $dynamicId, $compiledFile)
|
||||
{
|
||||
$output = preg_replace_callback('/<dwoo:dynamic_(' . $dynamicId . ')>(.+?)<\/dwoo:dynamic_' . $dynamicId . '>/s', array(
|
||||
'self',
|
||||
'unescapePhp'
|
||||
), $output, - 1, $count);
|
||||
// re-add the includes on top of the file
|
||||
if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) {
|
||||
$output = '<?php ' . $m[1] . ' ?>' . $output;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $match
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function unescapePhp($match)
|
||||
{
|
||||
return preg_replace('{<\?php /\*' . $match[1] . '\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
|
||||
/**
|
||||
* Generic else block, it supports all builtin optional-display blocks which are if/for/foreach/loop/with.
|
||||
* If any of those block contains an else statement, the content between {else} and {/block} (you do not
|
||||
* need to close the else block) will be shown if the block's condition has no been met
|
||||
* Example :
|
||||
* <code>
|
||||
* {foreach $array val}
|
||||
* $array is not empty so we display it's values : {$val}
|
||||
* {else}
|
||||
* if this shows, it means that $array is empty or doesn't exist.
|
||||
* {/foreach}
|
||||
* </code>
|
||||
* 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.
|
||||
*/
|
||||
class PluginElse extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
$preContent = '';
|
||||
while (true) {
|
||||
$preContent .= $compiler->removeTopBlock();
|
||||
$block = &$compiler->getCurrentBlock();
|
||||
if (!$block) {
|
||||
throw new CompilationException($compiler, 'An else block was found but it was not preceded by an if or other else-able construct');
|
||||
}
|
||||
$interfaces = class_implements($block['class']);
|
||||
if (in_array('Dwoo\IElseable', $interfaces) !== false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$params['initialized'] = true;
|
||||
$compiler->injectBlock($type, $params);
|
||||
|
||||
return $preContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
if (!isset($params['initialized'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$block = &$compiler->getCurrentBlock();
|
||||
$block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\IElseable;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Acts as a php elseif block, allowing you to add one more condition
|
||||
* if the previous one(s) didn't match. See the {if} plugin for syntax details.
|
||||
* 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.
|
||||
*/
|
||||
class PluginElseif extends PluginIf implements ICompilableBlock, IElseable
|
||||
{
|
||||
/**
|
||||
* @param array $rest
|
||||
*/
|
||||
public function init(array $rest)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
$preContent = '';
|
||||
while (true) {
|
||||
$preContent .= $compiler->removeTopBlock();
|
||||
$block = &$compiler->getCurrentBlock();
|
||||
$interfaces = class_implements($block['class']);
|
||||
if (in_array('Dwoo\IElseable', $interfaces) !== false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$params['initialized'] = true;
|
||||
$compiler->injectBlock($type, $params);
|
||||
|
||||
return $preContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
if (!isset($params['initialized'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$tokens = $compiler->getParamTokens($params);
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
|
||||
$pre = Compiler::PHP_OPEN . 'elseif (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE;
|
||||
$post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
|
||||
|
||||
if (isset($params['hasElse'])) {
|
||||
$post .= $params['hasElse'];
|
||||
}
|
||||
|
||||
$block = &$compiler->getCurrentBlock();
|
||||
$block['params']['hasElse'] = $pre . $content . $post;
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\IElseable;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Similar to the php for block
|
||||
* <pre>
|
||||
* * name : for name to access it's iterator variables through {$.for.name.var} see {@link
|
||||
* http://wiki.dwoo.org/index.php/IteratorVariables} for details
|
||||
* * from : array to iterate from (which equals 0) or a number as a start value
|
||||
* * to : value to stop iterating at (equals count($array) by default if you set an array in from)
|
||||
* * step : defines the incrementation of the pointer at each iteration
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginFor extends BlockPlugin implements ICompilableBlock, IElseable
|
||||
{
|
||||
public static $cnt = 0;
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $from
|
||||
* @param null $to
|
||||
* @param int $step
|
||||
* @param int $skip
|
||||
*/
|
||||
public function init($name, $from, $to = null, $step = 1, $skip = 0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
// get block params and save the current template pointer to use it in the postProcessing method
|
||||
$currentBlock = &$compiler->getCurrentBlock();
|
||||
$currentBlock['params']['tplPointer'] = $compiler->getPointer();
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
$tpl = $compiler->getTemplateSource($params['tplPointer']);
|
||||
|
||||
// assigns params
|
||||
$from = $params['from'];
|
||||
$name = $params['name'];
|
||||
$step = $params['step'];
|
||||
$to = $params['to'];
|
||||
|
||||
// evaluates which global variables have to be computed
|
||||
$varName = '$dwoo.for.' . trim($name, '"\'') . '.';
|
||||
$shortVarName = '$.for.' . 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 = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
|
||||
$usesIteration = $usesFirst || $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;
|
||||
|
||||
if (strpos($name, '$this->scope[') !== false) {
|
||||
$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
|
||||
}
|
||||
|
||||
// gets foreach id
|
||||
$cnt = self::$cnt ++;
|
||||
|
||||
// builds pre processing output for
|
||||
$out = Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\n" . 'if (is_numeric($_for' . $cnt . '_from) && !is_numeric($_for' . $cnt . '_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }' . "\n" . '$tmp_shows = $this->isArray($_for' . $cnt . '_from, true) || (is_numeric($_for' . $cnt . '_from) && (abs(($_for' . $cnt . '_from - $_for' . $cnt . '_to)/$_for' . $cnt . '_step) !== 0 || $_for' . $cnt . '_from == $_for' . $cnt . '_to));';
|
||||
// adds for properties
|
||||
if ($usesAny) {
|
||||
$out .= "\n" . '$this->globals["for"][' . $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" => $tmp_shows,';
|
||||
}
|
||||
if ($usesTotal) {
|
||||
$out .= "\n\t" . '"total" => $this->isArray($_for' . $cnt . '_from) ? floor($this->count($_for' . $cnt . '_from) / $_for' . $cnt . '_step) : (is_numeric($_for' . $cnt . '_from) ? abs(($_for' . $cnt . '_to + 1 - $_for' . $cnt . '_from)/$_for' . $cnt . '_step) : 0),';
|
||||
}
|
||||
$out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];';
|
||||
}
|
||||
// checks if for must be looped
|
||||
$out .= "\n" . 'if ($tmp_shows)' . "\n{";
|
||||
// set from/to to correct values if an array was given
|
||||
$out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from' . (isset($params['hasElse']) ? ', true' : '') . ') == true) {
|
||||
$_for' . $cnt . '_to = is_numeric($_for' . $cnt . '_to) ? $_for' . $cnt . '_to - $_for' . $cnt . '_step : $this->count($_for' . $cnt . '_from) - 1;
|
||||
$_for' . $cnt . '_from = 0;
|
||||
}';
|
||||
|
||||
// if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used
|
||||
$reverse = false;
|
||||
$condition = '<=';
|
||||
$incrementer = '+';
|
||||
|
||||
if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) {
|
||||
$from = (int)$mN1[2];
|
||||
$to = (int)$mN2[2];
|
||||
if ($from > $to) {
|
||||
$reverse = true;
|
||||
$condition = '>=';
|
||||
$incrementer = '-';
|
||||
}
|
||||
}
|
||||
|
||||
// reverse from and to if needed
|
||||
if (!$reverse) {
|
||||
$out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) {
|
||||
$tmp = $_for' . $cnt . '_from;
|
||||
$_for' . $cnt . '_from = $_for' . $cnt . '_to;
|
||||
$_for' . $cnt . '_to = $tmp;
|
||||
}';
|
||||
}
|
||||
|
||||
$out .= "\n\t" . 'for ($this->scope[' . $name . '] = $_for' . $cnt . '_from; $this->scope[' . $name . '] ' . $condition . ' $_for' . $cnt . '_to; $this->scope[' . $name . '] ' . $incrementer . '= $_for' . $cnt . '_step)' . "\n\t{";
|
||||
// updates properties
|
||||
if ($usesIndex) {
|
||||
$out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];';
|
||||
}
|
||||
if ($usesFirst) {
|
||||
$out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);';
|
||||
}
|
||||
if ($usesLast) {
|
||||
$out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);';
|
||||
}
|
||||
$out .= "\n/* -- for start output */\n" . Compiler::PHP_CLOSE;
|
||||
|
||||
// build post processing output and cache it
|
||||
$postOut = Compiler::PHP_OPEN . '/* -- for end output */';
|
||||
// update properties
|
||||
if ($usesIteration) {
|
||||
$postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;';
|
||||
}
|
||||
// end loop
|
||||
$postOut .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
|
||||
|
||||
if (isset($params['hasElse'])) {
|
||||
$postOut .= $params['hasElse'];
|
||||
}
|
||||
|
||||
return $out . $content . $postOut;
|
||||
}
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\IElseable;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
|
||||
/**
|
||||
* Similar to the php foreach block, loops over an array.
|
||||
* Note that if you don't provide the item parameter, the key will act as item
|
||||
* <pre>
|
||||
* * from : the array that you want to iterate over
|
||||
* * key : variable name for the key (or for the item if item is not defined)
|
||||
* * item : variable name for each item
|
||||
* * name : foreach name to access it's iterator variables through {$.foreach.name.var} see {@link
|
||||
* http://wiki.dwoo.org/index.php/IteratorVariables} for details
|
||||
* </pre>
|
||||
* Example :
|
||||
* <code>
|
||||
* {foreach $array val}
|
||||
* {$val.something}
|
||||
* {/foreach}
|
||||
* </code>
|
||||
* 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.
|
||||
*/
|
||||
class PluginForeach extends BlockPlugin implements ICompilableBlock, IElseable
|
||||
{
|
||||
public static $cnt = 0;
|
||||
|
||||
/**
|
||||
* @param $from
|
||||
* @param null $key
|
||||
* @param null $item
|
||||
* @param string $name
|
||||
* @param null $implode
|
||||
*/
|
||||
public function init($from, $key = null, $item = null, $name = 'default', $implode = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
// get block params and save the current template pointer to use it in the postProcessing method
|
||||
$currentBlock = &$compiler->getCurrentBlock();
|
||||
$currentBlock['params']['tplPointer'] = $compiler->getPointer();
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
$tpl = $compiler->getTemplateSource($params['tplPointer']);
|
||||
|
||||
// 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 {
|
||||
throw new CompilationException($compiler, 'Foreach <em>item</em> parameter missing');
|
||||
}
|
||||
$name = $params['name'];
|
||||
|
||||
if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
|
||||
throw new CompilationException($compiler, 'Foreach <em>item</em> parameter must be of type string');
|
||||
}
|
||||
if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
|
||||
throw new CompilationException($compiler, 'Foreach <em>key</em> parameter must be of type string');
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
if (strpos($name, '$this->scope[') !== false) {
|
||||
$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
|
||||
}
|
||||
|
||||
// override globals vars if implode is used
|
||||
if ($params['implode'] !== 'null') {
|
||||
$implode = $params['implode'];
|
||||
$usesAny = true;
|
||||
$usesLast = true;
|
||||
$usesIteration = true;
|
||||
$usesTotal = true;
|
||||
}
|
||||
|
||||
// gets foreach id
|
||||
$cnt = self::$cnt ++;
|
||||
|
||||
// build pre content output
|
||||
$pre = Compiler::PHP_OPEN . "\n" . '$_fh' . $cnt . '_data = ' . $src . ';';
|
||||
// adds foreach properties
|
||||
if ($usesAny) {
|
||||
$pre .= "\n" . '$this->globals["foreach"][' . $name . '] = array' . "\n(";
|
||||
if ($usesIndex) {
|
||||
$pre .= "\n\t" . '"index" => 0,';
|
||||
}
|
||||
if ($usesIteration) {
|
||||
$pre .= "\n\t" . '"iteration" => 1,';
|
||||
}
|
||||
if ($usesFirst) {
|
||||
$pre .= "\n\t" . '"first" => null,';
|
||||
}
|
||||
if ($usesLast) {
|
||||
$pre .= "\n\t" . '"last" => null,';
|
||||
}
|
||||
if ($usesShow) {
|
||||
$pre .= "\n\t" . '"show" => $this->isArray($_fh' . $cnt . '_data, true),';
|
||||
}
|
||||
if ($usesTotal) {
|
||||
$pre .= "\n\t" . '"total" => $this->count($_fh' . $cnt . '_data),';
|
||||
}
|
||||
$pre .= "\n);\n" . '$_fh' . $cnt . '_glob =& $this->globals["foreach"][' . $name . '];';
|
||||
}
|
||||
// checks if foreach must be looped
|
||||
$pre .= "\n" . 'if ($this->isTraversable($_fh' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{";
|
||||
// iterates over keys
|
||||
$pre .= "\n\t" . 'foreach ($_fh' . $cnt . '_data as ' . (isset($key) ? '$this->scope[' . $key . ']=>' : '') . '$this->scope[' . $val . '])' . "\n\t{";
|
||||
// updates properties
|
||||
if ($usesFirst) {
|
||||
$pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["first"] = (string) ($_fh' . $cnt . '_glob["index"] === 0);';
|
||||
}
|
||||
if ($usesLast) {
|
||||
$pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["last"] = (string) ($_fh' . $cnt . '_glob["iteration"] === $_fh' . $cnt . '_glob["total"]);';
|
||||
}
|
||||
$pre .= "\n/* -- foreach start output */\n" . Compiler::PHP_CLOSE;
|
||||
|
||||
// build post content output
|
||||
$post = Compiler::PHP_OPEN . "\n";
|
||||
|
||||
if (isset($implode)) {
|
||||
$post .= '/* -- implode */' . "\n" . 'if (!$_fh' . $cnt . '_glob["last"]) {' . "\n\t" . 'echo ' . $implode . ";\n}\n";
|
||||
}
|
||||
$post .= '/* -- foreach end output */';
|
||||
// update properties
|
||||
if ($usesIndex) {
|
||||
$post .= "\n\t\t" . '$_fh' . $cnt . '_glob["index"]+=1;';
|
||||
}
|
||||
if ($usesIteration) {
|
||||
$post .= "\n\t\t" . '$_fh' . $cnt . '_glob["iteration"]+=1;';
|
||||
}
|
||||
// end loop
|
||||
$post .= "\n\t}\n}" . Compiler::PHP_CLOSE;
|
||||
if (isset($params['hasElse'])) {
|
||||
$post .= $params['hasElse'];
|
||||
}
|
||||
|
||||
return $pre . $content . $post;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* This plugin serves as a {else} block specifically for the {foreach} plugin.
|
||||
* 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.
|
||||
*/
|
||||
class PluginForeachelse extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
$with = &$compiler->findBlock('foreach', true);
|
||||
|
||||
$params['initialized'] = true;
|
||||
$compiler->injectBlock($type, $params);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
if (!isset($params['initialized'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$block = &$compiler->getCurrentBlock();
|
||||
$block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* This plugin serves as a {else} block specifically for the {for} plugin.
|
||||
* 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.
|
||||
*/
|
||||
class PluginForelse extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
$with = &$compiler->findBlock('for', true);
|
||||
|
||||
$params['initialized'] = true;
|
||||
$compiler->injectBlock($type, $params);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
if (!isset($params['initialized'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$block = &$compiler->getCurrentBlock();
|
||||
$block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -1,274 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\IElseable;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
|
||||
/**
|
||||
* Conditional block, the syntax is very similar to the php one, allowing () || && and
|
||||
* other php operators. Additional operators and their equivalent php syntax are as follow :.
|
||||
* eq -> ==
|
||||
* neq or ne -> !=
|
||||
* gte or ge -> >=
|
||||
* lte or le -> <=
|
||||
* gt -> >
|
||||
* lt -> <
|
||||
* mod -> %
|
||||
* not -> !
|
||||
* X is [not] div by Y -> (X % Y) == 0
|
||||
* X is [not] even [by Y] -> (X % 2) == 0 or ((X/Y) % 2) == 0
|
||||
* X is [not] odd [by Y] -> (X % 2) != 0 or ((X/Y) % 2) != 0
|
||||
* 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.
|
||||
*/
|
||||
class PluginIf extends BlockPlugin implements ICompilableBlock, IElseable
|
||||
{
|
||||
/**
|
||||
* @param array $rest
|
||||
*/
|
||||
public function init(array $rest)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @param array $tokens
|
||||
* @param Compiler $compiler
|
||||
*
|
||||
* @return array
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function replaceKeywords(array $params, array $tokens, Compiler $compiler)
|
||||
{
|
||||
$p = array();
|
||||
|
||||
reset($params);
|
||||
while (list($k, $v) = each($params)) {
|
||||
$v = (string)$v;
|
||||
if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') {
|
||||
$vmod = strtolower(substr($v, 1, - 1));
|
||||
} else {
|
||||
$vmod = strtolower($v);
|
||||
}
|
||||
switch ($vmod) {
|
||||
|
||||
case 'and':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '&&';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'or':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '||';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'xor':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '^';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'eq':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '==';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'ne':
|
||||
case 'neq':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '!=';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'gte':
|
||||
case 'ge':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '>=';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'lte':
|
||||
case 'le':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '<=';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'gt':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '>';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'lt':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '<';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'mod':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '%';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case 'not':
|
||||
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = '!';
|
||||
} else {
|
||||
$p[] = $v;
|
||||
}
|
||||
break;
|
||||
case '<>':
|
||||
$p[] = '!=';
|
||||
break;
|
||||
case '==':
|
||||
case '!=':
|
||||
case '>=':
|
||||
case '<=':
|
||||
case '>':
|
||||
case '<':
|
||||
case '===':
|
||||
case '!==':
|
||||
case '%':
|
||||
case '!':
|
||||
case '^':
|
||||
$p[] = $vmod;
|
||||
break;
|
||||
case 'is':
|
||||
if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) {
|
||||
$p[] = $v;
|
||||
break;
|
||||
}
|
||||
if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) {
|
||||
$negate = true;
|
||||
next($params);
|
||||
} else {
|
||||
$negate = false;
|
||||
}
|
||||
$ptr = 1 + (int)$negate;
|
||||
if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) {
|
||||
break;
|
||||
}
|
||||
if (!isset($params[$k + $ptr])) {
|
||||
$params[$k + $ptr] = '';
|
||||
} else {
|
||||
$params[$k + $ptr] = trim($params[$k + $ptr], '"\'');
|
||||
}
|
||||
switch ($params[$k + $ptr]) {
|
||||
|
||||
case 'div':
|
||||
if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') {
|
||||
$p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0';
|
||||
next($params);
|
||||
next($params);
|
||||
next($params);
|
||||
} else {
|
||||
throw new CompilationException($compiler, '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]);
|
||||
}
|
||||
break;
|
||||
case 'even':
|
||||
$a = array_pop($p);
|
||||
if (isset($params[$k + $ptr + 1]) && strtolower(trim($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]) && strtolower(trim($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:
|
||||
throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$p[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$tokens = $compiler->getParamTokens($params);
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
$pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE;
|
||||
|
||||
$post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
|
||||
|
||||
if (isset($params['hasElse'])) {
|
||||
$post .= $params['hasElse'];
|
||||
}
|
||||
|
||||
return $pre . $content . $post;
|
||||
}
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\IElseable;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Loops over an array and moves the scope into each value, allowing for shorter loop constructs.
|
||||
* Note that to access the array key within a loop block, you have to use the {$_key} variable,
|
||||
* you can not specify it yourself.
|
||||
* <pre>
|
||||
* * from : the array that you want to iterate over
|
||||
* * name : loop name to access it's iterator variables through {$.loop.name.var} see {@link
|
||||
* http://wiki.dwoo.org/index.php/IteratorVariables} for details
|
||||
* </pre>
|
||||
* Example :
|
||||
* instead of a foreach block such as :
|
||||
* <code>
|
||||
* {foreach $variable value}
|
||||
* {$value.foo} {$value.bar}
|
||||
* {/foreach}
|
||||
* </code>
|
||||
* you can do :
|
||||
* <code>
|
||||
* {loop $variable}
|
||||
* {$foo} {$bar}
|
||||
* {/loop}
|
||||
* </code>
|
||||
* 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.
|
||||
*/
|
||||
class PluginLoop extends BlockPlugin implements ICompilableBlock, IElseable
|
||||
{
|
||||
public static $cnt = 0;
|
||||
|
||||
/**
|
||||
* @param $from
|
||||
* @param string $name
|
||||
*/
|
||||
public function init($from, $name = 'default')
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
// get block params and save the current template pointer to use it in the postProcessing method
|
||||
$currentBlock = &$compiler->getCurrentBlock();
|
||||
$currentBlock['params']['tplPointer'] = $compiler->getPointer();
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
$tpl = $compiler->getTemplateSource($params['tplPointer']);
|
||||
|
||||
// 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;
|
||||
|
||||
if (strpos($name, '$this->scope[') !== false) {
|
||||
$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
|
||||
}
|
||||
|
||||
// gets foreach id
|
||||
$cnt = self::$cnt ++;
|
||||
|
||||
// builds pre processing output
|
||||
$pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';';
|
||||
// adds foreach properties
|
||||
if ($usesAny) {
|
||||
$pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n(";
|
||||
if ($usesIndex) {
|
||||
$pre .= "\n\t" . '"index" => 0,';
|
||||
}
|
||||
if ($usesIteration) {
|
||||
$pre .= "\n\t" . '"iteration" => 1,';
|
||||
}
|
||||
if ($usesFirst) {
|
||||
$pre .= "\n\t" . '"first" => null,';
|
||||
}
|
||||
if ($usesLast) {
|
||||
$pre .= "\n\t" . '"last" => null,';
|
||||
}
|
||||
if ($usesShow) {
|
||||
$pre .= "\n\t" . '"show" => $this->isTraversable($_loop' . $cnt . '_data, true),';
|
||||
}
|
||||
if ($usesTotal) {
|
||||
$pre .= "\n\t" . '"total" => $this->count($_loop' . $cnt . '_data),';
|
||||
}
|
||||
$pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];';
|
||||
}
|
||||
// checks if the loop must be looped
|
||||
$pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{";
|
||||
// iterates over keys
|
||||
$pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{";
|
||||
// updates properties
|
||||
if ($usesFirst) {
|
||||
$pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);';
|
||||
}
|
||||
if ($usesLast) {
|
||||
$pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);';
|
||||
}
|
||||
$pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE;
|
||||
|
||||
// build post processing output and cache it
|
||||
$post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);';
|
||||
// update properties
|
||||
if ($usesIndex) {
|
||||
$post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;';
|
||||
}
|
||||
if ($usesIteration) {
|
||||
$post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;';
|
||||
}
|
||||
// end loop
|
||||
$post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
|
||||
if (isset($params['hasElse'])) {
|
||||
$post .= $params['hasElse'];
|
||||
}
|
||||
|
||||
return $pre . $content . $post;
|
||||
}
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\IElseable;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Compatibility plugin for smarty templates, do not use otherwise, this is deprecated.
|
||||
* 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.
|
||||
*/
|
||||
class PluginSection extends BlockPlugin implements ICompilableBlock, IElseable
|
||||
{
|
||||
public static $cnt = 0;
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $loop
|
||||
* @param null $start
|
||||
* @param null $step
|
||||
* @param null $max
|
||||
* @param bool $show
|
||||
*/
|
||||
public function init($name, $loop, $start = null, $step = null, $max = null, $show = true)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$output = Compiler::PHP_OPEN;
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
|
||||
// assigns params
|
||||
$loop = $params['loop'];
|
||||
$start = $params['start'];
|
||||
$max = $params['max'];
|
||||
$name = $params['name'];
|
||||
$step = $params['step'];
|
||||
$show = $params['show'];
|
||||
|
||||
// gets unique id
|
||||
$cnt = self::$cnt ++;
|
||||
|
||||
$output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n";
|
||||
|
||||
if ($loop !== 'null') {
|
||||
$output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n";
|
||||
} else {
|
||||
$output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n";
|
||||
}
|
||||
|
||||
if ($show !== 'null') {
|
||||
$output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n";
|
||||
} else {
|
||||
$output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n";
|
||||
}
|
||||
|
||||
if ($name !== 'null') {
|
||||
$output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n";
|
||||
} else {
|
||||
$output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n";
|
||||
}
|
||||
|
||||
if ($max !== 'null') {
|
||||
$output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n";
|
||||
} else {
|
||||
$output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
|
||||
}
|
||||
|
||||
if ($step !== 'null') {
|
||||
$output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n";
|
||||
} else {
|
||||
$output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n";
|
||||
}
|
||||
|
||||
if ($start !== 'null') {
|
||||
$output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n";
|
||||
} else {
|
||||
$output .= '$_section' . $cnt . '[\'start\'] = $_section' . $cnt . '[\'step\'] > 0 ? 0 : $_section' . $cnt . '[\'loop\'] - 1;' . "\n" . 'if ($_section' . $cnt . '[\'start\'] < 0) { $_section' . $cnt . '[\'start\'] = max($_section' . $cnt . '[\'step\'] > 0 ? 0 : -1, $_section' . $cnt . '[\'loop\'] + $_section' . $cnt . '[\'start\']); } ' . "\n" . 'else { $_section' . $cnt . '[\'start\'] = min($_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] : $_section' . $cnt . '[\'loop\'] -1); }' . "\n";
|
||||
}
|
||||
|
||||
/* if ($usesAny) {
|
||||
$output .= "\n".'$this->globals["section"]['.$name.'] = array'."\n(";
|
||||
if ($usesIndex) $output .="\n\t".'"index" => 0,';
|
||||
if ($usesIteration) $output .="\n\t".'"iteration" => 1,';
|
||||
if ($usesFirst) $output .="\n\t".'"first" => null,';
|
||||
if ($usesLast) $output .="\n\t".'"last" => null,';
|
||||
if ($usesShow) $output .="\n\t".'"show" => ($this->isArray($_for'.$cnt.'_from, true)) || (is_numeric($_for'.$cnt.'_from) && $_for'.$cnt.'_from != $_for'.$cnt.'_to),';
|
||||
if ($usesTotal) $output .="\n\t".'"total" => $this->isArray($_for'.$cnt.'_from) ? $this->count($_for'.$cnt.'_from) - $_for'.$cnt.'_skip : (is_numeric($_for'.$cnt.'_from) ? abs(($_for'.$cnt.'_to + 1 - $_for'.$cnt.'_from)/$_for'.$cnt.'_step) : 0),';
|
||||
$out.="\n);\n".'$_section'.$cnt.'[\'glob\'] =& $this->globals["section"]['.$name.'];'."\n\n";
|
||||
}
|
||||
*/
|
||||
|
||||
$output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
|
||||
if ($start === 'null' && $step === 'null' && $max === 'null') {
|
||||
$output .= ' $_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
|
||||
} else {
|
||||
$output .= ' $_section' . $cnt . '[\'total\'] = min(ceil(($_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] - $_section' . $cnt . '[\'start\'] : $_section' . $cnt . '[\'start\'] + 1) / abs($_section' . $cnt . '[\'step\'])), $_section' . $cnt . '[\'max\']);' . "\n";
|
||||
}
|
||||
$output .= ' if ($_section' . $cnt . '[\'total\'] == 0) {' . "\n" . ' $_section' . $cnt . '[\'show\'] = false;' . "\n" . ' }' . "\n" . '} else {' . "\n" . ' $_section' . $cnt . '[\'total\'] = 0;' . "\n}\n";
|
||||
$output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
|
||||
$output .= "\t" . 'for ($this->scope[' . $name . '] = $_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'iteration\'] = 1; ' . '$_section' . $cnt . '[\'iteration\'] <= $_section' . $cnt . '[\'total\']; ' . '$this->scope[' . $name . '] += $_section' . $cnt . '[\'step\'], $_section' . $cnt . '[\'iteration\']++) {' . "\n";
|
||||
$output .= "\t\t" . '$_section' . $cnt . '[\'rownum\'] = $_section' . $cnt . '[\'iteration\'];' . "\n";
|
||||
$output .= "\t\t" . '$_section' . $cnt . '[\'index_prev\'] = $this->scope[' . $name . '] - $_section' . $cnt . '[\'step\'];' . "\n";
|
||||
$output .= "\t\t" . '$_section' . $cnt . '[\'index_next\'] = $this->scope[' . $name . '] + $_section' . $cnt . '[\'step\'];' . "\n";
|
||||
$output .= "\t\t" . '$_section' . $cnt . '[\'first\'] = ($_section' . $cnt . '[\'iteration\'] == 1);' . "\n";
|
||||
$output .= "\t\t" . '$_section' . $cnt . '[\'last\'] = ($_section' . $cnt . '[\'iteration\'] == $_section' . $cnt . '[\'total\']);' . "\n";
|
||||
|
||||
$output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN;
|
||||
|
||||
$output .= "\n\t}\n} " . Compiler::PHP_CLOSE;
|
||||
|
||||
if (isset($params['hasElse'])) {
|
||||
$output .= $params['hasElse'];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.3.6
|
||||
* @date 2017-03-21
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Core;
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Smarty compatibility layer for block plugins, this is used internally and you should not call it.
|
||||
* 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.
|
||||
*/
|
||||
class PluginSmartyinterface extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
/**
|
||||
* @param $__funcname
|
||||
* @param $__functype
|
||||
* @param array $rest
|
||||
*/
|
||||
public function init($__funcname, $__functype, array $rest = array())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
$func = $params['__funcname'];
|
||||
$pluginType = $params['__functype'];
|
||||
$params = $params['*'];
|
||||
|
||||
if ($pluginType & Core::CUSTOM_PLUGIN) {
|
||||
$customPlugins = $compiler->getCore()->getCustomPlugins();
|
||||
$callback = $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 . '(';
|
||||
}
|
||||
|
||||
$paramsOut = '';
|
||||
foreach ($params as $i => $p) {
|
||||
$paramsOut .= var_export($i, true) . ' => ' . $p . ',';
|
||||
}
|
||||
|
||||
$curBlock = &$compiler->getCurrentBlock();
|
||||
$curBlock['params']['postOut'] = Compiler::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);' . Compiler::PHP_CLOSE;
|
||||
|
||||
return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
return $content . $params['postOut'];
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Strips the spaces at the beginning and end of each line and also the line breaks
|
||||
* <pre>
|
||||
* * mode : sets the content being stripped, available mode are 'default' or 'js'
|
||||
* for javascript, which strips the comments to prevent syntax errors
|
||||
* </pre>.
|
||||
* 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.
|
||||
*/
|
||||
class PluginStrip extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
/**
|
||||
* @param string $mode
|
||||
*/
|
||||
public function init($mode = 'default')
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
|
||||
$mode = trim($params['mode'], '"\'');
|
||||
switch ($mode) {
|
||||
case 'js':
|
||||
case 'javascript':
|
||||
$content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content);
|
||||
|
||||
case 'default':
|
||||
default:
|
||||
}
|
||||
$content = preg_replace(array(
|
||||
"/\n/",
|
||||
"/\r/",
|
||||
'/(<\?(?:php)?|<%)\s*/'
|
||||
), array(
|
||||
'',
|
||||
'',
|
||||
'$1 '
|
||||
), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-20
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Core;
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
|
||||
/**
|
||||
* Defines a sub-template that can then be called (even recursively) with the defined arguments
|
||||
* <pre>
|
||||
* * name : template name
|
||||
* * rest : list of arguments and optional default values
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginTemplate extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
$params = $compiler->getCompiledParams($params);
|
||||
$parsedParams = array();
|
||||
if (!isset($params['*'])) {
|
||||
$params['*'] = array();
|
||||
}
|
||||
foreach ($params['*'] as $param => $defValue) {
|
||||
if (is_numeric($param)) {
|
||||
$param = $defValue;
|
||||
$defValue = null;
|
||||
}
|
||||
$param = trim($param, '\'"');
|
||||
if (!preg_match('#^[a-z0-9_]+$#i', $param)) {
|
||||
throw new CompilationException($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _');
|
||||
}
|
||||
$parsedParams[$param] = $defValue;
|
||||
}
|
||||
$params['name'] = substr($params['name'], 1, - 1);
|
||||
$params['*'] = $parsedParams;
|
||||
$params['uuid'] = uniqid();
|
||||
$compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']);
|
||||
$currentBlock = &$compiler->getCurrentBlock();
|
||||
$currentBlock['params'] = $params;
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$paramstr = 'Dwoo\Core $dwoo';
|
||||
$init = 'static $_callCnt = 0;' . "\n" . '$dwoo->scope[\' ' . $params['uuid'] . '\'.$_callCnt] = array();' . "\n" . '$_scope = $dwoo->setScope(array(\' ' . $params['uuid'] . '\'.($_callCnt++)));' . "\n";
|
||||
$cleanup = '/* -- template end output */ $dwoo->setScope($_scope, true);';
|
||||
foreach ($params['*'] as $param => $defValue) {
|
||||
if ($defValue === null) {
|
||||
$paramstr .= ', $' . $param;
|
||||
} else {
|
||||
$paramstr .= ', $' . $param . ' = ' . $defValue;
|
||||
}
|
||||
$init .= '$dwoo->scope[\'' . $param . '\'] = $' . $param . ";\n";
|
||||
}
|
||||
$init .= '/* -- template start output */';
|
||||
|
||||
$funcName = 'Plugin' . Core::toCamelCase($params['name']) . Core::toCamelCase($params['uuid']);
|
||||
|
||||
$search = array('$this->charset', '$this->', '$this,',);
|
||||
$replacement = array('$dwoo->getCharset()', '$dwoo->', '$dwoo,',);
|
||||
$content = str_replace($search, $replacement, $content);
|
||||
|
||||
$body = 'if (!function_exists(\'' . $funcName . "')) {\nfunction " . $funcName . '(' . $paramstr . ') {' . "\n$init" . Compiler::PHP_CLOSE . $prepend . $content . $append . Compiler::PHP_OPEN . $cleanup . "\n}\n}";
|
||||
$compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param array $rest
|
||||
*/
|
||||
public function init($name, array $rest = array())
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
|
||||
/**
|
||||
* Formats a string to the given format, you can wrap lines at a certain
|
||||
* length and indent them
|
||||
* <pre>
|
||||
* * wrap : maximum line length
|
||||
* * wrap_char : the character(s) to use to break the line
|
||||
* * wrap_cut : if true, the words that are longer than $wrap are cut instead of overflowing
|
||||
* * indent : amount of $indent_char to insert before every line
|
||||
* * indent_char : character(s) to insert before every line
|
||||
* * indent_first : amount of additional $indent_char to insert before the first line of each paragraphs
|
||||
* * style : some predefined formatting styles that set up every required variables, can be "email" or "html"
|
||||
* * assign : if set, the formatted text is assigned to that variable instead of being output
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginTextformat extends BlockPlugin
|
||||
{
|
||||
protected $wrap;
|
||||
protected $wrapChar;
|
||||
protected $wrapCut;
|
||||
protected $indent;
|
||||
protected $indChar;
|
||||
protected $indFirst;
|
||||
protected $assign;
|
||||
|
||||
/**
|
||||
* @param int $wrap
|
||||
* @param string $wrap_char
|
||||
* @param bool $wrap_cut
|
||||
* @param int $indent
|
||||
* @param string $indent_char
|
||||
* @param int $indent_first
|
||||
* @param string $style
|
||||
* @param string $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" ? ' ' : ' ';
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
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->core->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign);
|
||||
} else {
|
||||
return implode($this->wrapChar . $this->wrapChar, $pgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Internal plugin used to wrap the template output, do not use in your templates as it will break them.
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
*/
|
||||
final class PluginTopLevelBlock extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();';
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\IElseable;
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* Moves the scope down into the provided variable, allowing you to use shorter
|
||||
* variable names if you repeatedly access values into a single array.
|
||||
* The with block won't display anything at all if the provided scope is empty,
|
||||
* so in effect it acts as {if $var}*content*{/if}
|
||||
* <pre>
|
||||
* * var : the variable name to move into
|
||||
* </pre>
|
||||
* Example :
|
||||
* instead of the following :
|
||||
* <code>
|
||||
* {if $long.boring.prefix}
|
||||
* {$long.boring.prefix.val} - {$long.boring.prefix.secondVal} - {$long.boring.prefix.thirdVal}
|
||||
* {/if}
|
||||
* </code>
|
||||
* you can use :
|
||||
* <code>
|
||||
* {with $long.boring.prefix}
|
||||
* {$val} - {$secondVal} - {$thirdVal}
|
||||
* {/with}
|
||||
* </code>
|
||||
* 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.
|
||||
*/
|
||||
class PluginWith extends BlockPlugin implements ICompilableBlock, IElseable
|
||||
{
|
||||
protected static $cnt = 0;
|
||||
|
||||
/**
|
||||
* @param $var
|
||||
*/
|
||||
public function init($var)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
$rparams = $compiler->getRealParams($params);
|
||||
$cparams = $compiler->getCompiledParams($params);
|
||||
|
||||
$compiler->setScope($rparams['var']);
|
||||
|
||||
$pre = Compiler::PHP_OPEN . 'if (' . $cparams['var'] . ')' . "\n{\n" . '$_with' . (self::$cnt) . ' = $this->setScope("' . $rparams['var'] . '");' . "\n/* -- start with output */\n" . Compiler::PHP_CLOSE;
|
||||
|
||||
$post = Compiler::PHP_OPEN . "\n/* -- end with output */\n" . '$this->setScope($_with' . (self::$cnt ++) . ', true);' . "\n}\n" . Compiler::PHP_CLOSE;
|
||||
|
||||
if (isset($params['hasElse'])) {
|
||||
$post .= $params['hasElse'];
|
||||
}
|
||||
|
||||
return $pre . $content . $post;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Blocks
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Blocks;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Block\Plugin as BlockPlugin;
|
||||
use Dwoo\ICompilable\Block as ICompilableBlock;
|
||||
|
||||
/**
|
||||
* This plugin serves as a {else} block specifically for the {with} plugin.
|
||||
* 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.
|
||||
*/
|
||||
class PluginWithelse extends BlockPlugin implements ICompilableBlock
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
|
||||
{
|
||||
$with = &$compiler->findBlock('with', true);
|
||||
|
||||
$params['initialized'] = true;
|
||||
$compiler->injectBlock($type, $params);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $params
|
||||
* @param string $prepend
|
||||
* @param string $append
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
|
||||
{
|
||||
if (!isset($params['initialized'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$block = &$compiler->getCurrentBlock();
|
||||
$block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Filters
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-18
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Filters;
|
||||
|
||||
use Dwoo\Filter;
|
||||
|
||||
/**
|
||||
* Formats any html output (must be valid xml where every tag opened is closed)
|
||||
* using a single tab for indenting. 'pre' and other whitespace sensitive
|
||||
* tags should not be affected.
|
||||
* It is not recommended to use this on every template if you render multiple
|
||||
* templates per page, you should only use it once on the main page template so that
|
||||
* everything is formatted in one pass.
|
||||
* 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.
|
||||
*/
|
||||
class PluginHtmlFormat extends Filter
|
||||
{
|
||||
/**
|
||||
* tab count to auto-indent the source.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected static $tabCount = - 1;
|
||||
|
||||
/**
|
||||
* stores the additional data (following a tag) of the last call to open/close/singleTag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $lastCallAdd = '';
|
||||
|
||||
/**
|
||||
* formats the input using the singleTag/closeTag/openTag functions.
|
||||
* It is auto indenting the whole code, excluding <textarea>, <code> and <pre> tags that must be kept intact.
|
||||
* Those tags must however contain only htmlentities-escaped text for everything to work properly.
|
||||
* Inline tags are presented on a single line with their content
|
||||
*
|
||||
* @param string $input the xhtml to format
|
||||
*
|
||||
* @return string formatted xhtml
|
||||
*/
|
||||
public function process($input)
|
||||
{
|
||||
self::$tabCount = - 1;
|
||||
|
||||
// auto indent all but textareas & pre (or we have weird tabs inside)
|
||||
$input = preg_replace_callback("#(<[^>]+>)(\s*)([^<]*)#", array(
|
||||
'self',
|
||||
'tagDispatcher'
|
||||
), $input);
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* helper function for format()'s preg_replace call.
|
||||
*
|
||||
* @param array $input array of matches (1=>tag, 2=>whitespace(optional), 3=>additional non-html content)
|
||||
*
|
||||
* @return string the indented tag
|
||||
*/
|
||||
protected static function tagDispatcher($input)
|
||||
{
|
||||
// textarea, pre, code tags and comments are to be left alone to avoid any non-wanted whitespace inside them so it just outputs them as they were
|
||||
if (substr($input[1], 0, 9) == '<textarea' || substr($input[1], 0, 4) == '<pre' || substr($input[1], 0, 5) == '<code' || substr($input[1], 0, 4) == '<!--' || substr($input[1], 0, 9) == '<![CDATA[') {
|
||||
return $input[1] . $input[3];
|
||||
}
|
||||
// closing textarea, code and pre tags and self-closed tags (i.e. <br />) are printed as singleTags because we didn't use openTag for the formers and the latter is a single tag
|
||||
if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], - 2) == '/>') {
|
||||
return self::singleTag($input[1], $input[3], $input[2]);
|
||||
}
|
||||
// it's the closing tag
|
||||
if ($input[0][1] == '/') {
|
||||
return self::closeTag($input[1], $input[3], $input[2]);
|
||||
}
|
||||
|
||||
// opening tag
|
||||
return self::openTag($input[1], $input[3], $input[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an open tag and adds a tab into the auto indenting.
|
||||
*
|
||||
* @param string $tag content of the tag
|
||||
* @param string $add additional data (anything before the following tag)
|
||||
* @param string $whitespace white space between the tag and the additional data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function openTag($tag, $add, $whitespace)
|
||||
{
|
||||
$tabs = str_pad('', self::$tabCount ++, "\t");
|
||||
|
||||
if (preg_match('#^<(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)(?: [^>]*|)>#', $tag)) {
|
||||
// if it's one of those tag it's inline so it does not require a leading line break
|
||||
$result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
|
||||
} elseif (substr($tag, 0, 9) == '<!DOCTYPE') {
|
||||
// it's the doctype declaration so no line break here either
|
||||
$result = $tabs . $tag;
|
||||
} else {
|
||||
// normal block tag
|
||||
$result = "\n" . $tabs . $tag;
|
||||
|
||||
if (!empty($add)) {
|
||||
$result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
|
||||
}
|
||||
}
|
||||
|
||||
self::$lastCallAdd = $add;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a closing tag and removes a tab from the auto indenting.
|
||||
*
|
||||
* @param string $tag content of the tag
|
||||
* @param string $add additional data (anything before the following tag)
|
||||
* @param string $whitespace white space between the tag and the additional data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function closeTag($tag, $add, $whitespace)
|
||||
{
|
||||
$tabs = str_pad('', -- self::$tabCount, "\t");
|
||||
|
||||
// if it's one of those tag it's inline so it does not require a leading line break
|
||||
if (preg_match('#^</(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)>#', $tag)) {
|
||||
$result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
|
||||
} else {
|
||||
$result = "\n" . $tabs . $tag;
|
||||
|
||||
if (!empty($add)) {
|
||||
$result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
|
||||
}
|
||||
}
|
||||
|
||||
self::$lastCallAdd = $add;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a single tag with auto indenting.
|
||||
*
|
||||
* @param string $tag content of the tag
|
||||
* @param string $add additional data (anything before the following tag)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function singleTag($tag, $add, $whitespace)
|
||||
{
|
||||
$tabs = str_pad('', self::$tabCount, "\t");
|
||||
|
||||
// if it's img, br it's inline so it does not require a leading line break
|
||||
// if it's a closing textarea, code or pre tag, it does not require a leading line break either or it creates whitespace at the end of those blocks
|
||||
if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) {
|
||||
$result = $tag . $whitespace;
|
||||
|
||||
if (!empty($add)) {
|
||||
$result .= str_replace("\n", "\n" . $tabs, $add);
|
||||
}
|
||||
} else {
|
||||
$result = "\n" . $tabs . $tag;
|
||||
|
||||
if (!empty($add)) {
|
||||
$result .= "\n" . $tabs . str_replace("\n", "\n" . $tabs, $add);
|
||||
}
|
||||
}
|
||||
|
||||
self::$lastCallAdd = $add;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Assigns a value to a variable
|
||||
* <pre>
|
||||
* * value : the value that you want to save
|
||||
* * var : the variable name (without the leading $)
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginAssign extends Plugin implements ICompilable
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param mixed $value
|
||||
* @param mixed $var
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $var)
|
||||
{
|
||||
return '$this->assignInScope(' . $value . ', ' . $var . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.4
|
||||
* @date 2017-03-01
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Capitalizes the first letter of each word
|
||||
* <pre>
|
||||
* * value : the string to capitalize
|
||||
* * numwords : if true, the words containing numbers are capitalized as well
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginCapitalize extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param bool $numwords
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process($value, $numwords = false)
|
||||
{
|
||||
if ($numwords || preg_match('#^[^0-9]+$#', $value)) {
|
||||
return mb_convert_case((string)$value, MB_CASE_TITLE, $this->core->getCharset());
|
||||
} else {
|
||||
$bits = explode(' ', (string)$value);
|
||||
$out = '';
|
||||
foreach ($bits as $k => $v){
|
||||
if (preg_match('#^[^0-9]+$#', $v)) {
|
||||
$out .= ' ' . mb_convert_case($v, MB_CASE_TITLE, $this->core->getCharset());
|
||||
} else {
|
||||
$out .= ' ' . $v;
|
||||
}
|
||||
}
|
||||
|
||||
return substr($out, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Concatenates any number of variables or strings fed into it
|
||||
* <pre>
|
||||
* * rest : two or more strings that will be merged into one
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginCat extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
* @param array $rest
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, array $rest)
|
||||
{
|
||||
return '(' . $value . ').(' . implode(').(', $rest) . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Counts the characters in a string
|
||||
* <pre>
|
||||
* * value : the string to process
|
||||
* * count_spaces : if true, the white-space characters are counted as well
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginCountCharacters extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
* @param bool $count_spaces
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $count_spaces = false)
|
||||
{
|
||||
if ($count_spaces === 'false') {
|
||||
return 'preg_match_all(\'#[^\s\pZ]#u\', ' . $value . ', $tmp)';
|
||||
}
|
||||
|
||||
return 'mb_strlen(' . $value . ', $this->charset)';
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Counts the paragraphs in a string
|
||||
* <pre>
|
||||
* * value : the string to process
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginCountParagraphs extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value)
|
||||
{
|
||||
return '(preg_match_all(\'#[\r\n]+#\', ' . $value . ', $tmp)+1)';
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Counts the sentences in a string
|
||||
* <pre>
|
||||
* * value : the string to process
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginCountSentences extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value)
|
||||
{
|
||||
return "preg_match_all('#[\\w\\pL]\\.(?![\\w\\pL])#u', $value, \$tmp)";
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Counts the words in a string
|
||||
* <pre>
|
||||
* * value : the string to process
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginCountWords extends Plugin implements ICompilable
|
||||
{
|
||||
public static function compile(Compiler $compiler, $value)
|
||||
{
|
||||
return 'preg_match_all(strcasecmp($this->charset, \'utf-8\')===0 ? \'#[\w\pL]+#u\' : \'#\w+#\', ' . $value . ', $tmp)';
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Initiates a counter that is incremented every time you call it
|
||||
* <pre>
|
||||
* * name : the counter name, define it if you want to have multiple concurrent counters
|
||||
* * start : the start value, if it's set, it will reset the counter to this value, defaults to 1
|
||||
* * skip : the value to add to the counter at each call, defaults to 1
|
||||
* * direction : "up" (default) or "down" to define whether the counter increments or decrements
|
||||
* * print : if false, the counter will not output the current count, defaults to true
|
||||
* * assign : if set, the counter is saved into the given variable and does not output anything, overriding the print
|
||||
* parameter
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginCounter extends Plugin
|
||||
{
|
||||
protected $counters = array();
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param null $start
|
||||
* @param null $skip
|
||||
* @param null $direction
|
||||
* @param null $print
|
||||
* @param null $assign
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
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->core->assignInScope($out, $this->counters[$name]['assign']);
|
||||
} elseif ($this->counters[$name]['print'] === true) {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Cycles between several values and returns one of them on each call
|
||||
* <pre>
|
||||
* * name : the cycler name, specify if you need to have multiple concurrent cycles running
|
||||
* * values : an array of values or a string of values delimited by $delimiter
|
||||
* * print : if false, the pointer will go to the next one but not print anything
|
||||
* * advance : if false, the pointer will not advance to the next value
|
||||
* * delimiter : the delimiter used to split values if they are provided as a string
|
||||
* * assign : if set, the value is saved in that variable instead of being output
|
||||
* * reset : if true, the pointer is reset to the first value
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginCycle extends Plugin
|
||||
{
|
||||
protected $cycles = array();
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param null $values
|
||||
* @param bool $print
|
||||
* @param bool $advance
|
||||
* @param string $delimiter
|
||||
* @param null $assign
|
||||
* @param bool $reset
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
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) {
|
||||
return $out;
|
||||
}
|
||||
$this->core->assignInScope($out, $assign);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Core;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Formats a date
|
||||
* <pre>
|
||||
* * value : the date, as a unix timestamp, mysql datetime or whatever strtotime() can parse
|
||||
* * format : output format, see {@link http://php.net/strftime} for details
|
||||
* * default : a default timestamp value, if the first one is empty
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginDateFormat extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param string $format
|
||||
* @param null $default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process($value, $format = '%b %e, %Y', $default = null)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
// convert if it's not a valid unix timestamp
|
||||
if (preg_match('#^-?\d{1,10}$#', $value) === 0) {
|
||||
$value = strtotime($value);
|
||||
}
|
||||
} elseif (!empty($default)) {
|
||||
// convert if it's not a valid unix timestamp
|
||||
if (preg_match('#^-?\d{1,10}$#', $default) === 0) {
|
||||
$value = strtotime($default);
|
||||
} else {
|
||||
$value = $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);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Returns a variable or a default value if it's empty
|
||||
* <pre>
|
||||
* * value : the variable to check
|
||||
* * default : fallback value if the first one is empty
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginDefault extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param mixed $value
|
||||
* @param string $default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $default = '')
|
||||
{
|
||||
return '(($tmp = ' . $value . ')===null||$tmp===\'\' ? ' . $default . ' : $tmp)';
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
use Iterator;
|
||||
use ReflectionObject;
|
||||
|
||||
/**
|
||||
* Dumps values of the given variable, or the entire data if nothing provided
|
||||
* <pre>
|
||||
* * var : the variable to display
|
||||
* * show_methods : if set to true, the public methods of any object encountered are also displayed
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginDump extends Plugin
|
||||
{
|
||||
protected $outputObjects;
|
||||
protected $outputMethods;
|
||||
|
||||
/**
|
||||
* @param string $var
|
||||
* @param bool $show_methods
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process($var = '$', $show_methods = false)
|
||||
{
|
||||
$this->outputMethods = $show_methods;
|
||||
if ($var === '$') {
|
||||
$var = $this->core->getData();
|
||||
$out = '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">data';
|
||||
} else {
|
||||
$out = '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">dump';
|
||||
}
|
||||
|
||||
$this->outputObjects = array();
|
||||
|
||||
if (!is_array($var)) {
|
||||
if (is_object($var)) {
|
||||
return $this->exportObj('', $var);
|
||||
} else {
|
||||
return $this->exportVar('', $var);
|
||||
}
|
||||
}
|
||||
|
||||
$scope = $this->core->getScope();
|
||||
|
||||
if ($var === $scope) {
|
||||
$out .= ' (current scope): <div style="background:#ccc;">';
|
||||
} else {
|
||||
$out .= ':<div style="padding-left:20px;">';
|
||||
}
|
||||
|
||||
$out .= $this->export($var, $scope);
|
||||
|
||||
return $out . '</div></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $var
|
||||
* @param $scope
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function export($var, $scope)
|
||||
{
|
||||
$out = '';
|
||||
foreach ($var as $i => $v) {
|
||||
if (is_array($v) || (is_object($v) && $v instanceof Iterator)) {
|
||||
$out .= $i . ' (' . (is_array($v) ? 'array' : 'object: ' . get_class($v)) . ')';
|
||||
if ($v === $scope) {
|
||||
$out .= ' (current scope):<div style="background:#ccc;padding-left:20px;">' . $this->export($v, $scope) . '</div>';
|
||||
} else {
|
||||
$out .= ':<div style="padding-left:20px;">' . $this->export($v, $scope) . '</div>';
|
||||
}
|
||||
} elseif (is_object($v)) {
|
||||
$out .= $this->exportObj($i . ' (object: ' . get_class($v) . '):', $v);
|
||||
} else {
|
||||
$out .= $this->exportVar($i . ' = ', $v);
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $i
|
||||
* @param $v
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function exportVar($i, $v)
|
||||
{
|
||||
if (is_string($v) || is_bool($v) || is_numeric($v)) {
|
||||
return $i . htmlentities(var_export($v, true)) . '<br />';
|
||||
} elseif (is_null($v)) {
|
||||
return $i . 'null<br />';
|
||||
} elseif (is_resource($v)) {
|
||||
return $i . 'resource(' . get_resource_type($v) . ')<br />';
|
||||
} else {
|
||||
return $i . htmlentities(var_export($v, true)) . '<br />';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $i
|
||||
* @param $obj
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function exportObj($i, $obj)
|
||||
{
|
||||
if (array_search($obj, $this->outputObjects, true) !== false) {
|
||||
return $i . ' [recursion, skipped]<br />';
|
||||
}
|
||||
|
||||
$this->outputObjects[] = $obj;
|
||||
|
||||
$list = (array)$obj;
|
||||
|
||||
$protectedLength = strlen(get_class($obj)) + 2;
|
||||
|
||||
$out = array();
|
||||
|
||||
if ($this->outputMethods) {
|
||||
$ref = new ReflectionObject($obj);
|
||||
|
||||
foreach ($ref->getMethods() as $method) {
|
||||
if (!$method->isPublic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($out['method'])) {
|
||||
$out['method'] = '';
|
||||
}
|
||||
|
||||
$params = array();
|
||||
foreach ($method->getParameters() as $param) {
|
||||
$params[] = ($param->isPassedByReference() ? '&' : '') . '$' . $param->getName() . ($param->isOptional() ? ' = ' . var_export($param->getDefaultValue(), true) : '');
|
||||
}
|
||||
|
||||
$out['method'] .= '(method) ' . $method->getName() . '(' . implode(', ', $params) . ')<br />';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($list as $attributeName => $attributeValue) {
|
||||
if (property_exists($obj, $attributeName)) {
|
||||
$key = 'public';
|
||||
} elseif (substr($attributeName, 0, 3) === "\0*\0") {
|
||||
$key = 'protected';
|
||||
$attributeName = substr($attributeName, 3);
|
||||
} else {
|
||||
$key = 'private';
|
||||
$attributeName = substr($attributeName, $protectedLength);
|
||||
}
|
||||
|
||||
if (empty($out[$key])) {
|
||||
$out[$key] = '';
|
||||
}
|
||||
|
||||
$out[$key] .= '(' . $key . ') ';
|
||||
|
||||
if (is_array($attributeValue)) {
|
||||
$out[$key] .= $attributeName . ' (array):<br />
|
||||
<div style="padding-left:20px;">' . $this->export($attributeValue, false) . '</div>';
|
||||
} elseif (is_object($attributeValue)) {
|
||||
$out[$key] .= $this->exportObj($attributeName . ' (object: ' . get_class($attributeValue) . '):', $attributeValue);
|
||||
} else {
|
||||
$out[$key] .= $this->exportVar($attributeName . ' = ', $attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
$return = $i . '<br /><div style="padding-left:20px;">';
|
||||
|
||||
if (!empty($out['method'])) {
|
||||
$return .= $out['method'];
|
||||
}
|
||||
|
||||
if (!empty($out['public'])) {
|
||||
$return .= $out['public'];
|
||||
}
|
||||
|
||||
if (!empty($out['protected'])) {
|
||||
$return .= $out['protected'];
|
||||
}
|
||||
|
||||
if (!empty($out['private'])) {
|
||||
$return .= $out['private'];
|
||||
}
|
||||
|
||||
return $return . '</div>';
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Returns the correct end of line character(s) for the current operating system.
|
||||
* 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.
|
||||
*/
|
||||
class PluginEol extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler)
|
||||
{
|
||||
return 'PHP_EOL';
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Applies various escaping schemes on the given string
|
||||
* <pre>
|
||||
* * value : the string to process
|
||||
* * format : escaping format to use, valid formats are : html, htmlall, url, urlpathinfo, quotes, hex, hexentity,
|
||||
* javascript and mail
|
||||
* * charset : character set to use for the conversion (applies to some formats only), defaults to the current Dwoo
|
||||
* charset
|
||||
* </pre>
|
||||
* 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.
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
class PluginEscape extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param string $format
|
||||
* @param null $charset
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function process($value = '', $format = 'html', $charset = null)
|
||||
{
|
||||
if ($charset === null) {
|
||||
$charset = $this->core->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':
|
||||
case 'js':
|
||||
return strtr((string)$value,
|
||||
array(
|
||||
'\\' => '\\\\',
|
||||
"'" => "\\'",
|
||||
'"' => '\\"',
|
||||
"\r" => '\\r',
|
||||
"\n" => '\\n',
|
||||
'</' => '<\/'
|
||||
));
|
||||
case 'mail':
|
||||
return str_replace(array(
|
||||
'@',
|
||||
'.'
|
||||
),
|
||||
array(
|
||||
' (AT) ',
|
||||
' (DOT) '
|
||||
),
|
||||
(string)$value);
|
||||
default:
|
||||
$this->core->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript, js or mail, "' . $format . '" given.',
|
||||
E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Core;
|
||||
use Dwoo\Plugin;
|
||||
use Dwoo\Template\Str as TemplateString;
|
||||
|
||||
/**
|
||||
* Evaluates the given string as if it was a template.
|
||||
* Although this plugin is kind of optimized and will
|
||||
* not recompile your string each time, it is still not
|
||||
* a good practice to use it. If you want to have templates
|
||||
* stored in a database or something you should probably use
|
||||
* the Dwoo\Template\Str class or make another class that
|
||||
* extends it
|
||||
* <pre>
|
||||
* * var : the string to use as a template
|
||||
* * assign : if set, the output of the template will be saved in this variable instead of being output
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginEval extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param string $var
|
||||
* @param null $assign
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process($var, $assign = null)
|
||||
{
|
||||
if ($var == '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$tpl = new TemplateString($var);
|
||||
$clone = clone $this->core;
|
||||
$out = $clone->get($tpl, $this->core->readVar('_parent'));
|
||||
|
||||
if ($assign !== null) {
|
||||
$this->core->assignInScope($out, $assign);
|
||||
} else {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.3.6
|
||||
* @date 2017-03-21
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
use Dwoo\Exception as Exception;
|
||||
use Dwoo\Security\Exception as SecurityException;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
|
||||
/**
|
||||
* Extends another template, read more about template inheritance at {@link
|
||||
* http://wiki.dwoo.org/index.php/TemplateInheritance}
|
||||
* <pre>
|
||||
* * file : the template to extend
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginExtends extends Plugin implements ICompilable
|
||||
{
|
||||
protected static $childSource;
|
||||
protected static $regex;
|
||||
protected static $l;
|
||||
protected static $r;
|
||||
protected static $lastReplacement;
|
||||
|
||||
public function process()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param $file
|
||||
*
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $file)
|
||||
{
|
||||
list($l, $r) = $compiler->getDelimiters();
|
||||
self::$l = preg_quote($l, '/');
|
||||
self::$r = preg_quote($r, '/');
|
||||
self::$regex = '/
|
||||
' . self::$l . 'block\s(["\']?)(.+?)\1' . self::$r . '(?:\r?\n?)
|
||||
((?:
|
||||
(?R)
|
||||
|
|
||||
[^' . self::$l . ']*
|
||||
(?:
|
||||
(?! ' . self::$l . '\/?block\b )
|
||||
' . self::$l . '
|
||||
[^' . self::$l . ']*+
|
||||
)*
|
||||
)*)
|
||||
' . self::$l . '\/block' . self::$r . '
|
||||
/six';
|
||||
|
||||
if ($compiler->getLooseOpeningHandling()) {
|
||||
self::$l .= '\s*';
|
||||
self::$r = '\s*' . self::$r;
|
||||
}
|
||||
$inheritanceTree = array(array('source' => $compiler->getTemplateSource()));
|
||||
$curPath = dirname($compiler->getCore()->getTemplate()->getResourceIdentifier()) . DIRECTORY_SEPARATOR;
|
||||
$curTpl = $compiler->getCore()->getTemplate();
|
||||
|
||||
while (!empty($file)) {
|
||||
if ($file === '""' || $file === "''" || (substr($file, 0, 1) !== '"' && substr($file, 0, 1) !== '\'')) {
|
||||
throw new CompilationException($compiler, 'Extends : The file name must be a non-empty string');
|
||||
}
|
||||
|
||||
if (preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m)) {
|
||||
// resource:identifier given, extract them
|
||||
$resource = $m[1];
|
||||
$identifier = $m[2];
|
||||
} else {
|
||||
// get the current template's resource
|
||||
$resource = $curTpl->getResourceName();
|
||||
$identifier = substr($file, 1, - 1);
|
||||
}
|
||||
|
||||
try {
|
||||
$parent = $compiler->getCore()->templateFactory($resource, $identifier, null, null, null, $curTpl);
|
||||
}
|
||||
catch (SecurityException $e) {
|
||||
throw new CompilationException($compiler, 'Extends : Security restriction : ' . $e->getMessage());
|
||||
}
|
||||
catch (Exception $e) {
|
||||
throw new CompilationException($compiler, 'Extends : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($parent === null) {
|
||||
throw new CompilationException($compiler, 'Extends : Resource "' . $resource . ':' . $identifier . '" not found.');
|
||||
} elseif ($parent === false) {
|
||||
throw new CompilationException($compiler, 'Extends : Resource "' . $resource . '" does not support extends.');
|
||||
}
|
||||
|
||||
$curTpl = $parent;
|
||||
$newParent = array(
|
||||
'source' => $parent->getSource(),
|
||||
'resource' => $resource,
|
||||
'identifier' => $parent->getResourceIdentifier(),
|
||||
'uid' => $parent->getUid()
|
||||
);
|
||||
if (array_search($newParent, $inheritanceTree, true) !== false) {
|
||||
throw new CompilationException($compiler, 'Extends : Recursive template inheritance detected');
|
||||
}
|
||||
$inheritanceTree[] = $newParent;
|
||||
|
||||
if (preg_match('/^' . self::$l . 'extends(?:\(?\s*|\s+)(?:file=)?\s*((["\']).+?\2|\S+?)\s*\)?\s*?' . self::$r . '/i', $parent->getSource(), $match)) {
|
||||
$curPath = dirname($identifier) . DIRECTORY_SEPARATOR;
|
||||
if (isset($match[2]) && $match[2] == '"') {
|
||||
$file = '"' . str_replace('"', '\\"', substr($match[1], 1, - 1)) . '"';
|
||||
} elseif (isset($match[2]) && $match[2] == "'") {
|
||||
$file = '"' . substr($match[1], 1, - 1) . '"';
|
||||
} else {
|
||||
$file = '"' . $match[1] . '"';
|
||||
}
|
||||
} else {
|
||||
$file = false;
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
$parent = array_pop($inheritanceTree);
|
||||
$child = end($inheritanceTree);
|
||||
self::$childSource = $child['source'];
|
||||
self::$lastReplacement = count($inheritanceTree) === 1;
|
||||
if (!isset($newSource)) {
|
||||
$newSource = $parent['source'];
|
||||
}
|
||||
$newSource = preg_replace_callback(self::$regex, array(
|
||||
'Dwoo\Plugins\Functions\PluginExtends',
|
||||
'replaceBlock'
|
||||
), $newSource);
|
||||
$newSource = $l . 'do extendsCheck(' . var_export($parent['resource'] . ':' . $parent['identifier'], true) . ')' . $r . $newSource;
|
||||
|
||||
if (self::$lastReplacement) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$compiler->setTemplateSource($newSource);
|
||||
$compiler->recompile();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $matches
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
protected static function replaceBlock(array $matches)
|
||||
{
|
||||
$matches[3] = self::removeTrailingNewline($matches[3]);
|
||||
|
||||
if (preg_match_all(self::$regex, self::$childSource, $override) && in_array($matches[2], $override[2])) {
|
||||
$key = array_search($matches[2], $override[2]);
|
||||
$override = self::removeTrailingNewline($override[3][$key]);
|
||||
|
||||
$l = stripslashes(self::$l);
|
||||
$r = stripslashes(self::$r);
|
||||
|
||||
if (self::$lastReplacement) {
|
||||
return preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override);
|
||||
}
|
||||
|
||||
return $l . 'block ' . $matches[1] . $matches[2] . $matches[1] . $r . preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override) . $l . '/block' . $r;
|
||||
}
|
||||
|
||||
if (preg_match(self::$regex, $matches[3])) {
|
||||
return preg_replace_callback(self::$regex, array(
|
||||
'Dwoo\Plugins\Functions\PluginExtends',
|
||||
'replaceBlock'
|
||||
), $matches[3]);
|
||||
}
|
||||
|
||||
if (self::$lastReplacement) {
|
||||
return $matches[3];
|
||||
}
|
||||
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function removeTrailingNewline($text)
|
||||
{
|
||||
return substr($text, - 1) === "\n" ? substr($text, - 2, 1) === "\r" ? substr($text, 0, - 2) : substr($text, 0, - 1) : $text;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.3.6
|
||||
* @date 2017-03-21
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Checks whether an extended file has been modified, and if so recompiles the current template. This is for internal
|
||||
* use only, do not use. 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.
|
||||
*/
|
||||
class PluginExtendsCheck extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param $file
|
||||
*
|
||||
* @return string
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $file)
|
||||
{
|
||||
preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m);
|
||||
$resource = $m[1];
|
||||
$identifier = $m[2];
|
||||
|
||||
$tpl = $compiler->getCore()->templateFactory($resource, $identifier);
|
||||
|
||||
if ($tpl === null) {
|
||||
throw new CompilationException($compiler,
|
||||
'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
|
||||
} elseif ($tpl === false) {
|
||||
throw new CompilationException($compiler,
|
||||
'Load Templates : Resource "' . $resource . '" does not support includes.');
|
||||
}
|
||||
|
||||
$out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
|
||||
|
||||
$modCheck = $tpl->getIsModifiedCode();
|
||||
|
||||
if ($modCheck) {
|
||||
$out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
|
||||
} else {
|
||||
$out .= 'try {
|
||||
$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
|
||||
} catch (Dwoo\Exception $e) {
|
||||
$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
|
||||
}
|
||||
if ($tpl === null)
|
||||
$this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING);
|
||||
elseif ($tpl === false)
|
||||
$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
|
||||
if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Reads a file
|
||||
* <pre>
|
||||
* * file : path or URI of the file to read (however reading from another website is not recommended for performance
|
||||
* reasons)
|
||||
* * assign : if set, the file will be saved in this variable instead of being output
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginFetch extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param string $file
|
||||
* @param null $assign
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process($file, $assign = null)
|
||||
{
|
||||
if ($file === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($policy = $this->core->getSecurityPolicy()) {
|
||||
while (true) {
|
||||
if (preg_match('{^([a-z]+?)://}i', $file)) {
|
||||
$this->core->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;
|
||||
}
|
||||
}
|
||||
$this->core->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) {
|
||||
return $out;
|
||||
}
|
||||
$this->core->assignInScope($out, $assign);
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Exception as Exception;
|
||||
use Dwoo\Plugin;
|
||||
use Dwoo\Security\Exception as SecurityException;
|
||||
|
||||
/**
|
||||
* Inserts another template into the current one
|
||||
* <pre>
|
||||
* * file : the resource name of the template
|
||||
* * cache_time : cache length in seconds
|
||||
* * cache_id : cache identifier for the included template
|
||||
* * compile_id : compilation identifier for the included template
|
||||
* * data : data to feed into the included template, it can be any array and will default to $_root (the current data)
|
||||
* * assign : if set, the output of the included template will be saved in this variable instead of being output
|
||||
* * rest : any additional parameter/value provided will be added to the data array
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginInclude extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param $file
|
||||
* @param null $cache_time
|
||||
* @param null $cache_id
|
||||
* @param null $compile_id
|
||||
* @param string $data
|
||||
* @param null $assign
|
||||
* @param array $rest
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process($file, $cache_time = null, $cache_id = null, $compile_id = null, $data = '_root', $assign = null, array $rest = array())
|
||||
{
|
||||
$include = null;
|
||||
if ($file === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
|
||||
// resource:identifier given, extract them
|
||||
$resource = $m[1];
|
||||
$identifier = $m[2];
|
||||
} else {
|
||||
// get the current template's resource
|
||||
$resource = $this->core->getTemplate()->getResourceName();
|
||||
$identifier = $file;
|
||||
}
|
||||
|
||||
try {
|
||||
$include = $this->core->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id);
|
||||
}
|
||||
catch (SecurityException $e) {
|
||||
$this->core->triggerError('Include : Security restriction : ' . $e->getMessage(), E_USER_WARNING);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->core->triggerError('Include : ' . $e->getMessage(), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if ($include === null) {
|
||||
$this->core->triggerError('Include : Resource "' . $resource . ':' . $identifier . '" not found.',
|
||||
E_USER_WARNING);
|
||||
} elseif ($include === false) {
|
||||
$this->core->triggerError('Include : Resource "' . $resource . '" does not support includes.',
|
||||
E_USER_WARNING);
|
||||
}
|
||||
|
||||
if (is_string($data)) {
|
||||
$vars = $this->core->readVar($data);
|
||||
} else {
|
||||
$vars = $data;
|
||||
}
|
||||
|
||||
if (count($rest)) {
|
||||
$vars = $rest + $vars;
|
||||
}
|
||||
|
||||
$clone = clone $this->core;
|
||||
$out = $clone->get($include, $vars);
|
||||
|
||||
if ($assign !== null) {
|
||||
$this->core->assignInScope($out, $assign);
|
||||
}
|
||||
|
||||
foreach ($clone->getReturnValues() as $name => $value) {
|
||||
$this->core->assignInScope($value, $name);
|
||||
}
|
||||
|
||||
if ($assign === null) {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Indents every line of a text by the given amount of characters
|
||||
* <pre>
|
||||
* * value : the string to indent
|
||||
* * by : how many characters should be inserted before each line
|
||||
* * char : the character(s) to insert
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginIndent extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
* @param int $by
|
||||
* @param string $char
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $by = 4, $char = ' ')
|
||||
{
|
||||
return "preg_replace('#^#m', '" . str_repeat(substr($char, 1, - 1), trim($by, '"\'')) . "', $value)";
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Checks whether a variable is not null
|
||||
* <pre>
|
||||
* * var : variable to check
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginIsset extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param mixed $var
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $var)
|
||||
{
|
||||
return '(' . $var . ' !== null)';
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.3.6
|
||||
* @date 2017-03-21
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Loads sub-templates contained in an external file
|
||||
* <pre>
|
||||
* * file : the resource name of the file to load
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginLoadTemplates extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $file
|
||||
*
|
||||
* @return string
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $file)
|
||||
{
|
||||
$file = substr($file, 1, - 1);
|
||||
|
||||
if ($file === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
|
||||
// resource:identifier given, extract them
|
||||
$resource = $m[1];
|
||||
$identifier = $m[2];
|
||||
} else {
|
||||
// get the current template's resource
|
||||
$resource = $compiler->getCore()->getTemplate()->getResourceName();
|
||||
$identifier = $file;
|
||||
}
|
||||
|
||||
$tpl = $compiler->getCore()->templateFactory($resource, $identifier);
|
||||
|
||||
if ($tpl === null) {
|
||||
throw new CompilationException($compiler,
|
||||
'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
|
||||
} elseif ($tpl === false) {
|
||||
throw new CompilationException($compiler,
|
||||
'Load Templates : Resource "' . $resource . '" does not support includes.');
|
||||
}
|
||||
|
||||
$cmp = clone $compiler;
|
||||
$cmp->compile($compiler->getCore(), $tpl);
|
||||
foreach ($cmp->getTemplatePlugins() as $template => $args) {
|
||||
$compiler->addTemplatePlugin($template, $args['params'], $args['uuid'], $args['body']);
|
||||
}
|
||||
foreach ($cmp->getUsedPlugins() as $plugin => $type) {
|
||||
$compiler->addUsedPlugin($plugin, $type);
|
||||
}
|
||||
|
||||
$out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
|
||||
|
||||
$modCheck = $tpl->getIsModifiedCode();
|
||||
|
||||
if ($modCheck) {
|
||||
$out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
|
||||
} else {
|
||||
$out .= 'try {
|
||||
$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
|
||||
} catch (Dwoo\Exception $e) {
|
||||
$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
|
||||
}
|
||||
if ($tpl === null)
|
||||
$this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING);
|
||||
elseif ($tpl === false)
|
||||
$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
|
||||
if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Makes the input string lower cased
|
||||
* <pre>
|
||||
* * value : the string to process
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginLower extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value)
|
||||
{
|
||||
return 'mb_strtolower((string) ' . $value . ', $this->charset)';
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Outputs a mailto link with optional spam-proof (okay probably not) encoding
|
||||
* <pre>
|
||||
* * address : target email address
|
||||
* * text : display text to show for the link, defaults to the address if not provided
|
||||
* * subject : the email subject
|
||||
* * encode : one of the available encoding (none, js, jscharcode or hex)
|
||||
* * cc : address(es) to carbon copy, comma separated
|
||||
* * bcc : address(es) to blind carbon copy, comma separated
|
||||
* * newsgroups : newsgroup(s) to post to, comma separated
|
||||
* * followupto : address(es) to follow up, comma separated
|
||||
* * extra : additional attributes to add to the <a> tag
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginMailto extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param $address
|
||||
* @param null $text
|
||||
* @param null $subject
|
||||
* @param null $encode
|
||||
* @param null $cc
|
||||
* @param null $bcc
|
||||
* @param null $newsgroups
|
||||
* @param null $followupto
|
||||
* @param null $extra
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process($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($newsgroups)) {
|
||||
$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(Str.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) {
|
||||
$this->core->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="mailto:';
|
||||
$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:
|
||||
$this->core->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Computes a mathematical equation
|
||||
* <pre>
|
||||
* * equation : the equation to compute, it can include normal variables with $foo or special math variables without
|
||||
* the dollar sign
|
||||
* * format : output format, see {@link http://php.net/sprintf} for details
|
||||
* * assign : if set, the output is assigned into the given variable name instead of being output
|
||||
* * rest : all math specific variables that you use must be defined, see the example
|
||||
* </pre>
|
||||
* Example :.
|
||||
* <code>
|
||||
* {$c=2}
|
||||
* {math "(a+b)*$c/4" a=3 b=5}
|
||||
* output is : 4 ( = (3+5)*2/4)
|
||||
* </code>
|
||||
* 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.
|
||||
*/
|
||||
class PluginMath extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $equation
|
||||
* @param string $format
|
||||
* @param string $assign
|
||||
* @param array $rest
|
||||
*
|
||||
* @return string
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function compile(Compiler $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);
|
||||
if (array_search($substr, $allowed) !== false) {
|
||||
// allowed string
|
||||
$out .= $substr;
|
||||
$equation = substr($equation, $ptr);
|
||||
$ptr = 0;
|
||||
} elseif (array_search($substr, $funcs) !== false) {
|
||||
// allowed func
|
||||
$out .= $substr;
|
||||
$equation = substr($equation, $ptr);
|
||||
$ptr = 0;
|
||||
++ $allowcomma;
|
||||
if ($allowcomma === 1) {
|
||||
$allowed[] = ',';
|
||||
}
|
||||
} elseif (isset($rest[$substr])) {
|
||||
// variable
|
||||
$out .= $rest[$substr];
|
||||
$equation = substr($equation, $ptr);
|
||||
$ptr = 0;
|
||||
} elseif ($substr === $open) {
|
||||
// pre-replaced variable
|
||||
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;
|
||||
} elseif ($substr === '(') {
|
||||
// opening parenthesis
|
||||
if ($allowcomma > 0) {
|
||||
++ $allowcomma;
|
||||
}
|
||||
|
||||
$out .= $substr;
|
||||
$equation = substr($equation, $ptr);
|
||||
$ptr = 0;
|
||||
} elseif ($substr === ')') {
|
||||
// closing parenthesis
|
||||
if ($allowcomma > 0) {
|
||||
-- $allowcomma;
|
||||
if ($allowcomma === 0) {
|
||||
array_pop($allowed);
|
||||
}
|
||||
}
|
||||
|
||||
$out .= $substr;
|
||||
$equation = substr($equation, $ptr);
|
||||
$ptr = 0;
|
||||
} elseif ($ptr >= strlen($equation)) {
|
||||
// parse error if we've consumed the entire equation without finding anything valid
|
||||
throw new CompilationException($compiler,
|
||||
'Math : Syntax error or variable undefined in equation ' . $equationSrc . ' at ' . $substr);
|
||||
} else {
|
||||
// nothing special, advance
|
||||
++ $ptr;
|
||||
}
|
||||
}
|
||||
if ($format !== '\'\'') {
|
||||
$out = 'sprintf(' . $format . ', ' . $out . ')';
|
||||
}
|
||||
if ($assign !== '\'\'') {
|
||||
return '($this->assignInScope(' . $out . ', ' . $assign . '))';
|
||||
}
|
||||
|
||||
return '(' . $out . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Converts line breaks into <br /> tags
|
||||
* <pre>
|
||||
* * value : the string to process
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginNl2br extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value)
|
||||
{
|
||||
return 'nl2br((string) ' . $value . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Prints out a variable without any notice if it doesn't exist.
|
||||
* <pre>
|
||||
* * value : the variable to print
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginOptional extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Replaces the search string by the replace string using regular expressions
|
||||
* <pre>
|
||||
* * value : the string to search into
|
||||
* * search : the string to search for, must be a complete regular expression including delimiters
|
||||
* * replace : the string to use as a replacement, must be a complete regular expression including delimiters
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginRegexReplace extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param string $search
|
||||
* @param string $replace
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function process($value, $search, $replace)
|
||||
{
|
||||
$search = (array)$search;
|
||||
$cnt = count($search);
|
||||
|
||||
for ($i = 0; $i < $cnt; ++ $i) {
|
||||
// Credits for this to Monte Ohrt who made smarty's regex_replace modifier
|
||||
if (($pos = strpos($search[$i], "\0")) !== false) {
|
||||
$search[$i] = substr($search[$i], 0, $pos);
|
||||
}
|
||||
|
||||
if (preg_match('#[a-z\s]+$#is', $search[$i], $m) && (strpos($m[0], 'e') !== false)) {
|
||||
$search[$i] = substr($search[$i], 0, - strlen($m[0])) . str_replace(array(
|
||||
'e',
|
||||
' '
|
||||
),
|
||||
'',
|
||||
$m[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return preg_replace($search, $replace, $value);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Replaces the search string by the replace string
|
||||
* <pre>
|
||||
* * value : the string to search into
|
||||
* * search : the string to search for
|
||||
* * replace : the string to use as a replacement
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginReplace extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
* @param string $search
|
||||
* @param string $replace
|
||||
* @param bool $case_sensitive
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $search, $replace, $case_sensitive = true)
|
||||
{
|
||||
if ($case_sensitive == 'false' || (bool)$case_sensitive === false) {
|
||||
return 'str_ireplace(' . $search . ', ' . $replace . ', ' . $value . ')';
|
||||
} else {
|
||||
return 'str_replace(' . $search . ', ' . $replace . ', ' . $value . ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Inserts another template into the current one
|
||||
* <pre>
|
||||
* * file : the resource name of the template
|
||||
* * cache_time : cache length in seconds
|
||||
* * cache_id : cache identifier for the included template
|
||||
* * compile_id : compilation identifier for the included template
|
||||
* * data : data to feed into the included template, it can be any array and will default to $_root (the current data)
|
||||
* * assign : if set, the output of the included template will be saved in this variable instead of being output
|
||||
* * rest : any additional parameter/value provided will be added to the data array
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginReturn extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $rest
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, array $rest = array())
|
||||
{
|
||||
$out = array();
|
||||
foreach ($rest as $var => $val) {
|
||||
$out[] = '$this->setReturnValue(' . var_export($var, true) . ', ' . $val . ')';
|
||||
}
|
||||
|
||||
return '(' . implode('.', $out) . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Reverses a string or an array
|
||||
* <pre>
|
||||
* * value : the string or array to reverse
|
||||
* * preserve_keys : if value is an array and this is true, then the array keys are left intact
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginReverse extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param bool $preserve_keys
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
public function process($value, $preserve_keys = false)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return array_reverse($value, $preserve_keys);
|
||||
} elseif (($charset = $this->core->getCharset()) === 'iso-8859-1') {
|
||||
return strrev((string)$value);
|
||||
}
|
||||
|
||||
$strlen = mb_strlen($value);
|
||||
$out = '';
|
||||
while ($strlen --) {
|
||||
$out .= mb_substr($value, $strlen, 1, $charset);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Marks the variable as safe and removes the auto-escape function, only useful if you turned auto-escaping on
|
||||
* <pre>
|
||||
* * var : the variable to pass through untouched
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginSafe extends Plugin implements ICompilable
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param mixed $var
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $var)
|
||||
{
|
||||
return preg_replace('#\(is_string\(\$tmp=(.+)\) \? htmlspecialchars\(\$tmp, ENT_QUOTES, \$this->charset\) : \$tmp\)#',
|
||||
'$1',
|
||||
$var);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Adds spaces (or the given character(s)) between every character of a string
|
||||
* <pre>
|
||||
* * value : the string to process
|
||||
* * space_char : the character(s) to insert between each character
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginSpacify extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
* @param string $space_char
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $space_char = ' ')
|
||||
{
|
||||
return 'implode(' . $space_char . ', str_split(' . $value . ', 1))';
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Formats a string using the sprintf function
|
||||
* <pre>
|
||||
* * value : the string to format
|
||||
* * format : the format to use, see {@link http://php.net/sprintf} for details
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginStringFormat extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $format)
|
||||
{
|
||||
return 'sprintf(' . $format . ',' . $value . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.3
|
||||
* @date 2017-01-07
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Removes all html tags
|
||||
* <pre>
|
||||
* * value: the string to process
|
||||
* * addspace: if true, a space is added in place of every removed tag
|
||||
* * allowable_tags: specify tags which should not be stripped
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginStripTags extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
* @param bool $addspace
|
||||
* @param null|string $allowable_tags
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $addspace = true, $allowable_tags = null)
|
||||
{
|
||||
if ($addspace === 'true') {
|
||||
if ("null" == $allowable_tags) {
|
||||
return "preg_replace('#<[^>]*>#', ' ', $value)";
|
||||
}
|
||||
|
||||
return "preg_replace('#<\\s*\\/?(" . $allowable_tags . ")\\s*[^>]*?>#im', ' ', $value)";
|
||||
}
|
||||
|
||||
return "strip_tags($value, $allowable_tags)";
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.3.6
|
||||
* @date 2017-03-21
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Core;
|
||||
use Dwoo\Exception;
|
||||
use Dwoo\Compilation\Exception as CompilationException;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
use Dwoo\Plugins\Blocks\PluginIf;
|
||||
|
||||
/**
|
||||
* Ternary if operation.
|
||||
* It evaluates the first argument and returns the second if it's true, or the third if it's false
|
||||
* <pre>
|
||||
* * rest : you can not use named parameters to call this, use it either with three arguments in the correct order
|
||||
* (expression, true result, false result) or write it as in php (expression ? true result : false result)
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginTif extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $rest
|
||||
* @param array $tokens
|
||||
*
|
||||
* @return mixed|string
|
||||
* @throws CompilationException
|
||||
*/
|
||||
public static function compile(Compiler $compiler, array $rest, array $tokens)
|
||||
{
|
||||
// load if plugin
|
||||
if (!class_exists(Core::NAMESPACE_PLUGINS_BLOCKS . 'PluginIf')) {
|
||||
try {
|
||||
$compiler->getCore()->getLoader()->loadPlugin('if');
|
||||
}
|
||||
catch (Exception $e) {
|
||||
throw new CompilationException($compiler, 'Tif: the if plugin is required to use Tif');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($rest) == 1) {
|
||||
return $rest[0];
|
||||
}
|
||||
|
||||
// fetch false result and remove the ":" if it was present
|
||||
$falseResult = array_pop($rest);
|
||||
|
||||
if (trim(end($rest), '"\'') === ':') {
|
||||
// remove the ':' if present
|
||||
array_pop($rest);
|
||||
} elseif (trim(end($rest), '"\'') === '?' || count($rest) === 1) {
|
||||
if ($falseResult === '?' || $falseResult === ':') {
|
||||
throw new CompilationException($compiler,
|
||||
'Tif: incomplete tif statement, value missing after ' . $falseResult);
|
||||
}
|
||||
// there was in fact no false result provided, so we move it to be the true result instead
|
||||
$trueResult = $falseResult;
|
||||
$falseResult = "''";
|
||||
}
|
||||
|
||||
// fetch true result if needed
|
||||
if (!isset($trueResult)) {
|
||||
$trueResult = array_pop($rest);
|
||||
// no true result provided so we use the expression arg
|
||||
if ($trueResult === '?') {
|
||||
$trueResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
// remove the '?' if present
|
||||
if (trim(end($rest), '"\'') === '?') {
|
||||
array_pop($rest);
|
||||
}
|
||||
|
||||
// check params were correctly provided
|
||||
if (empty($rest) || $trueResult === null || $falseResult === null) {
|
||||
throw new CompilationException($compiler,
|
||||
'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>');
|
||||
}
|
||||
|
||||
// parse condition
|
||||
$condition = PluginIf::replaceKeywords($rest, $tokens, $compiler);
|
||||
|
||||
return '((' . implode(' ', $condition) . ') ? ' . ($trueResult === true ? implode(' ',
|
||||
$condition) : $trueResult) . ' : ' . $falseResult . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Truncates a string at the given length
|
||||
* <pre>
|
||||
* * value : text to truncate
|
||||
* * length : the maximum length for the string
|
||||
* * etc : the characters that are added to show that the string was cut off
|
||||
* * break : if true, the string will be cut off at the exact length, instead of cutting at the nearest space
|
||||
* * middle : if true, the string will contain the beginning and the end, and the extra characters will be removed
|
||||
* from the middle
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginTruncate extends Plugin
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param int $length
|
||||
* @param string $etc
|
||||
* @param bool $break
|
||||
* @param bool $middle
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function process($value, $length = 80, $etc = '...', $break = false, $middle = false)
|
||||
{
|
||||
if ($length == 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$value = (string)$value;
|
||||
$etc = (string)$etc;
|
||||
$length = (int)$length;
|
||||
|
||||
if (strlen($value) < $length) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$length = max($length - strlen($etc), 0);
|
||||
if ($break === false && $middle === false) {
|
||||
$value = preg_replace('#\s+(\S*)?$#', '', substr($value, 0, $length + 1));
|
||||
}
|
||||
if ($middle === false) {
|
||||
return substr($value, 0, $length) . $etc;
|
||||
}
|
||||
|
||||
return substr($value, 0, ceil($length / 2)) . $etc . substr($value, - floor($length / 2));
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Makes a string uppercased
|
||||
* <pre>
|
||||
* * value : the text to uppercase
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginUpper extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value)
|
||||
{
|
||||
return 'mb_strtoupper((string) ' . $value . ', $this->charset)';
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Block\Plugin;
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
|
||||
/**
|
||||
* Replaces all white-space characters with the given string
|
||||
* <pre>
|
||||
* * value : the text to process
|
||||
* * with : the replacement string, note that any number of consecutive white-space characters will be replaced by a
|
||||
* single replacement string
|
||||
* </pre>
|
||||
* Example :.
|
||||
* <code>
|
||||
* {"a b c d
|
||||
*
|
||||
* e"|whitespace}
|
||||
* results in : a b c d e
|
||||
* </code>
|
||||
* 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.
|
||||
*/
|
||||
class PluginWhitespace extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
* @param string $with
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $with = ' ')
|
||||
{
|
||||
return "preg_replace('#\s+#'.(strcasecmp(\$this->charset, 'utf-8')===0?'u':''), $with, $value)";
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Functions
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Functions;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Wraps a text at the given line length
|
||||
* <pre>
|
||||
* * value : the text to wrap
|
||||
* * length : maximum line length
|
||||
* * break : the character(s) to use to break the line
|
||||
* * cut : if true, the line is cut at the exact length instead of breaking at the nearest space
|
||||
* </pre>
|
||||
* 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.
|
||||
*/
|
||||
class PluginWordwrap extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param string $value
|
||||
* @param int $length
|
||||
* @param string $break
|
||||
* @param bool $cut
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, $value, $length = 80, $break = "\n", $cut = false)
|
||||
{
|
||||
return 'wordwrap(' . $value . ',' . $length . ',' . $break . ',' . $cut . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Helpers
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.2
|
||||
* @date 2017-01-06
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Helpers;
|
||||
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ICompilable;
|
||||
use Dwoo\Plugin;
|
||||
|
||||
/**
|
||||
* Builds an array with all the provided variables, use named parameters to make an associative array
|
||||
* <pre>
|
||||
* * rest : any number of variables, strings or anything that you want to store in the array
|
||||
* </pre>
|
||||
* Example :
|
||||
* <code>
|
||||
* {array(a, b, c)} results in array(0=>'a', 1=>'b', 2=>'c')
|
||||
* {array(a=foo, b=5, c=array(4,5))} results in array('a'=>'foo', 'b'=>5, 'c'=>array(0=>4, 1=>5))
|
||||
* </code>
|
||||
* 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.
|
||||
*/
|
||||
class PluginArray extends Plugin implements ICompilable
|
||||
{
|
||||
/**
|
||||
* @param Compiler $compiler
|
||||
* @param array $rest
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function compile(Compiler $compiler, array $rest = array())
|
||||
{
|
||||
$out = array();
|
||||
foreach ($rest as $key => $value) {
|
||||
if (!is_numeric($key) && !strstr($key, '$this->scope')) {
|
||||
$key = "'" . $key . "'";
|
||||
}
|
||||
$out[] = $key . '=>' . $value;
|
||||
}
|
||||
|
||||
return 'array(' . implode(', ', $out) . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Plugins\Processors
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-18
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Plugins\Processors;
|
||||
|
||||
use Dwoo\Processor;
|
||||
|
||||
/**
|
||||
* Performs some template conversions to allow smarty templates to be used by
|
||||
* the Dwoo compiler.
|
||||
* 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.
|
||||
*/
|
||||
class PluginSmartyCompatible extends Processor
|
||||
{
|
||||
/**
|
||||
* @param string $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function process($input)
|
||||
{
|
||||
list($l, $r) = $this->compiler->getDelimiters();
|
||||
|
||||
$rl = preg_quote($l, '/');
|
||||
$rr = preg_quote($r, '/');
|
||||
$sectionParam = '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*';
|
||||
$input = preg_replace_callback('/' . $rl . '\s*section ' . str_repeat($sectionParam, 6) . '\s*' . $rr . '(.+?)(?:' . $rl . '\s*sectionelse\s*' . $rr . '(.+?))?' . $rl . '\s*\/section\s*' . $rr . '/is', array(
|
||||
$this,
|
||||
'convertSection'
|
||||
), $input);
|
||||
$input = str_replace('$smarty.section.', '$smarty.for.', $input);
|
||||
|
||||
$smarty = array(
|
||||
'/' . $rl . '\s*ldelim\s*' . $rr . '/',
|
||||
'/' . $rl . '\s*rdelim\s*' . $rr . '/',
|
||||
'/' . $rl . '\s*\$smarty\.ldelim\s*' . $rr . '/',
|
||||
'/' . $rl . '\s*\$smarty\.rdelim\s*' . $rr . '/',
|
||||
'/\$smarty\./',
|
||||
'/' . $rl . '\s*php\s*' . $rr . '/',
|
||||
'/' . $rl . '\s*\/php\s*' . $rr . '/',
|
||||
'/\|(@?)strip(\||' . $rr . ')/',
|
||||
'/' . $rl . '\s*sectionelse\s*' . $rr . '/',
|
||||
);
|
||||
|
||||
$dwoo = array(
|
||||
'\\' . $l,
|
||||
$r,
|
||||
'\\' . $l,
|
||||
$r,
|
||||
'$dwoo.',
|
||||
'<?php ',
|
||||
' ?>',
|
||||
'|$1whitespace$2',
|
||||
$l . 'else' . $r,
|
||||
);
|
||||
|
||||
if (preg_match('{\|@([a-z][a-z0-9_]*)}i', $input, $matches)) {
|
||||
trigger_error('The Smarty Compatibility Module has detected that you use |@' . $matches[1] . ' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator', E_USER_NOTICE);
|
||||
}
|
||||
|
||||
return preg_replace($smarty, $dwoo, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $matches
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function convertSection(array $matches)
|
||||
{
|
||||
$params = array();
|
||||
$index = 1;
|
||||
while (!empty($matches[$index]) && $index < 13) {
|
||||
$params[$matches[$index]] = $matches[$index + 1];
|
||||
$index += 2;
|
||||
}
|
||||
|
||||
return str_replace('[' . trim($params['name'], '"\'') . ']', '[$' . trim($params['name'], '"\'') . ']', $matches[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo;
|
||||
|
||||
/**
|
||||
* Base class for processors.
|
||||
* 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.
|
||||
*/
|
||||
abstract class Processor
|
||||
{
|
||||
/**
|
||||
* The compiler instance that runs this processor.
|
||||
*
|
||||
* @var Core
|
||||
*/
|
||||
protected $compiler;
|
||||
|
||||
/**
|
||||
* Constructor, if you override it, call parent::__construct($compiler); or assign
|
||||
* the dwoo instance yourself if you need it.
|
||||
*
|
||||
* @param Compiler $compiler the compiler class
|
||||
*/
|
||||
public function __construct(Compiler $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the input and returns it filtered.
|
||||
*
|
||||
* @param string $input the template to process
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function process($input);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Security
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-19
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Security;
|
||||
|
||||
use Dwoo\Exception as DwooException;
|
||||
|
||||
/**
|
||||
* Dwoo security exception class.
|
||||
* 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.
|
||||
*/
|
||||
class Exception extends DwooException
|
||||
{
|
||||
}
|
||||
@@ -1,322 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Security
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Security;
|
||||
|
||||
use Dwoo\Core;
|
||||
|
||||
/**
|
||||
* Represents the security settings of a dwoo instance, it can be passed around to different dwoo instances.
|
||||
* 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.
|
||||
*/
|
||||
class Policy
|
||||
{
|
||||
/**
|
||||
* Php handling constants, defaults to PHP_REMOVE
|
||||
* PHP_ENCODE : run htmlentities over them
|
||||
* PHP_REMOVE : remove all <?php ?> (+ short tags if your short tags option is on) from the input template
|
||||
* PHP_ALLOW : leave them as they are
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const PHP_ENCODE = 1;
|
||||
const PHP_REMOVE = 2;
|
||||
const PHP_ALLOW = 3;
|
||||
|
||||
/**
|
||||
* Constant handling constants, defaults to CONST_DISALLOW
|
||||
* CONST_DISALLOW : throw an error if {$dwoo.const.*} is used in the template
|
||||
* CONST_ALLOW : allow {$dwoo.const.*} calls
|
||||
*/
|
||||
const CONST_DISALLOW = false;
|
||||
const CONST_ALLOW = true;
|
||||
|
||||
/**
|
||||
* Php functions that are allowed to be used within the template.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedPhpFunctions = array(
|
||||
'str_repeat' => true,
|
||||
'number_format' => true,
|
||||
'htmlentities' => true,
|
||||
'htmlspecialchars' => true,
|
||||
'long2ip' => true,
|
||||
'strlen' => true,
|
||||
'list' => true,
|
||||
'empty' => true,
|
||||
'count' => true,
|
||||
'sizeof' => true,
|
||||
'in_array' => true,
|
||||
'is_array' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* Methods that are allowed to be used within the template.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedMethods = array();
|
||||
|
||||
/**
|
||||
* Paths that are safe to use with include or other file-access plugins.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedDirectories = array();
|
||||
|
||||
/**
|
||||
* Stores the php handling level.
|
||||
* defaults to self::PHP_REMOVE
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $phpHandling = self::PHP_REMOVE;
|
||||
|
||||
/**
|
||||
* Stores the constant handling level.
|
||||
* defaults to self::CONST_DISALLOW
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $constHandling = self::CONST_DISALLOW;
|
||||
|
||||
/**
|
||||
* Adds a php function to the allowed list.
|
||||
*
|
||||
* @param mixed $func function name or array of function names
|
||||
*/
|
||||
public function allowPhpFunction($func)
|
||||
{
|
||||
if (is_array($func)) {
|
||||
foreach ($func as $fname) {
|
||||
$this->allowedPhpFunctions[strtolower($fname)] = true;
|
||||
}
|
||||
} else {
|
||||
$this->allowedPhpFunctions[strtolower($func)] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a php function from the allowed list.
|
||||
*
|
||||
* @param mixed $func function name or array of function names
|
||||
*/
|
||||
public function disallowPhpFunction($func)
|
||||
{
|
||||
if (is_array($func)) {
|
||||
foreach ($func as $fname) {
|
||||
unset($this->allowedPhpFunctions[strtolower($fname)]);
|
||||
}
|
||||
} else {
|
||||
unset($this->allowedPhpFunctions[strtolower($func)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of php functions allowed to run, note that the function names
|
||||
* are stored in the array keys and not values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllowedPhpFunctions()
|
||||
{
|
||||
return $this->allowedPhpFunctions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a class method to the allowed list, this must be used for
|
||||
* both static and non static method by providing the class name
|
||||
* and method name to use.
|
||||
*
|
||||
* @param mixed $class class name or array of array('class', 'method') couples
|
||||
* @param string $method method name
|
||||
*/
|
||||
public function allowMethod($class, $method = null)
|
||||
{
|
||||
if (is_array($class)) {
|
||||
foreach ($class as $elem) {
|
||||
$this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])] = true;
|
||||
}
|
||||
} else {
|
||||
$this->allowedMethods[strtolower($class)][strtolower($method)] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a class method from the allowed list.
|
||||
*
|
||||
* @param mixed $class class name or array of array('class', 'method') couples
|
||||
* @param string $method method name
|
||||
*/
|
||||
public function disallowMethod($class, $method = null)
|
||||
{
|
||||
if (is_array($class)) {
|
||||
foreach ($class as $elem) {
|
||||
unset($this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])]);
|
||||
}
|
||||
} else {
|
||||
unset($this->allowedMethods[strtolower($class)][strtolower($method)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of class methods allowed to run, note that the class names
|
||||
* and method names are stored in the array keys and not values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllowedMethods()
|
||||
{
|
||||
return $this->allowedMethods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a directory to the safelist for includes and other file-access plugins.
|
||||
* note that all the includePath directories you provide to the Dwoo_Template_File class
|
||||
* are automatically marked as safe
|
||||
*
|
||||
* @param mixed $path a path name or an array of paths
|
||||
*/
|
||||
public function allowDirectory($path)
|
||||
{
|
||||
if (is_array($path)) {
|
||||
foreach ($path as $dir) {
|
||||
$this->allowedDirectories[realpath($dir)] = true;
|
||||
}
|
||||
} else {
|
||||
$this->allowedDirectories[realpath($path)] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a directory from the safe list.
|
||||
*
|
||||
* @param mixed $path a path name or an array of paths
|
||||
*/
|
||||
public function disallowDirectory($path)
|
||||
{
|
||||
if (is_array($path)) {
|
||||
foreach ($path as $dir) {
|
||||
unset($this->allowedDirectories[realpath($dir)]);
|
||||
}
|
||||
} else {
|
||||
unset($this->allowedDirectories[realpath($path)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of safe paths, note that the paths are stored in the array
|
||||
* keys and not values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllowedDirectories()
|
||||
{
|
||||
return $this->allowedDirectories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the php handling level, defaults to REMOVE.
|
||||
*
|
||||
* @param int $level one of the Dwoo_Security_Policy::PHP_* constants
|
||||
*/
|
||||
public function setPhpHandling($level = self::PHP_REMOVE)
|
||||
{
|
||||
$this->phpHandling = $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the php handling level.
|
||||
*
|
||||
* @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants
|
||||
*/
|
||||
public function getPhpHandling()
|
||||
{
|
||||
return $this->phpHandling;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the constant handling level, defaults to CONST_DISALLOW.
|
||||
*
|
||||
* @param bool $level one of the Dwoo_Security_Policy::CONST_* constants
|
||||
*/
|
||||
public function setConstantHandling($level = self::CONST_DISALLOW)
|
||||
{
|
||||
$this->constHandling = $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constant handling level.
|
||||
*
|
||||
* @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants
|
||||
*/
|
||||
public function getConstantHandling()
|
||||
{
|
||||
return $this->constHandling;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used at run time to check whether method calls are allowed or not.
|
||||
*
|
||||
* @param Core $dwoo dwoo instance that calls this
|
||||
* @param object $obj any object on which the method must be called
|
||||
* @param string $method lowercased method name
|
||||
* @param array $args arguments array
|
||||
*
|
||||
* @return mixed result of method call or unll + E_USER_NOTICE if not allowed
|
||||
*/
|
||||
public function callMethod(Core $dwoo, $obj, $method, $args)
|
||||
{
|
||||
foreach ($this->allowedMethods as $class => $methods) {
|
||||
if (!isset($methods[$method])) {
|
||||
continue;
|
||||
}
|
||||
if ($obj instanceof $class) {
|
||||
return call_user_func_array(array($obj, $method), $args);
|
||||
}
|
||||
}
|
||||
$dwoo->triggerError('The current security policy prevents you from calling ' . get_class($obj) . '::' . $method . '()');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used at compile time to check whether static method calls are allowed or not.
|
||||
*
|
||||
* @param mixed $class lowercased class name or array('class', 'method') couple
|
||||
* @param string $method lowercased method name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMethodAllowed($class, $method = null)
|
||||
{
|
||||
if (is_array($class)) {
|
||||
list($class, $method) = $class;
|
||||
}
|
||||
foreach ($this->allowedMethods as $allowedClass => $methods) {
|
||||
if (!isset($methods[$method])) {
|
||||
continue;
|
||||
}
|
||||
if ($class === $allowedClass || is_subclass_of($class, $allowedClass)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,698 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Smarty
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Smarty;
|
||||
|
||||
use Dwoo\Core;
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\Data;
|
||||
use Dwoo\Security\Policy as SecurityPolicy;
|
||||
use Dwoo\Exception as Exception;
|
||||
use Dwoo\Template\File as TemplateFile;
|
||||
use Dwoo\Smarty\Filter\Adapter as FilterAdapter;
|
||||
use Dwoo\Smarty\Processor\Adapter as ProcessorAdapter;
|
||||
|
||||
if (!defined('DIR_SEP')) {
|
||||
define('DIR_SEP', DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
if (!defined('SMARTY_PHP_PASSTHRU')) {
|
||||
define('SMARTY_PHP_PASSTHRU', 0);
|
||||
define('SMARTY_PHP_QUOTE', 1);
|
||||
define('SMARTY_PHP_REMOVE', 2);
|
||||
define('SMARTY_PHP_ALLOW', 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Smarty compatibility layer for Dwoo.
|
||||
* 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.
|
||||
*/
|
||||
class Adapter extends Core
|
||||
{
|
||||
/**
|
||||
* Magic get/set/call functions that handle unsupported features
|
||||
*
|
||||
* @param string $p
|
||||
* @param string $v
|
||||
*/
|
||||
public function __set($p, $v)
|
||||
{
|
||||
if ($p === 'scope') {
|
||||
$this->scope = $v;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($p === 'data') {
|
||||
$this->data = $v;
|
||||
|
||||
return;
|
||||
}
|
||||
if (array_key_exists($p, $this->compat['properties']) !== false) {
|
||||
if ($this->show_compat_errors) {
|
||||
$this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
|
||||
}
|
||||
$this->compat['properties'][$p] = $v;
|
||||
} else {
|
||||
if ($this->show_compat_errors) {
|
||||
$this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at j.boggiano@seld.be', E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $p
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($p)
|
||||
{
|
||||
if (array_key_exists($p, $this->compat['properties']) !== false) {
|
||||
if ($this->show_compat_errors) {
|
||||
$this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
|
||||
}
|
||||
|
||||
return $this->compat['properties'][$p];
|
||||
} else {
|
||||
if ($this->show_compat_errors) {
|
||||
$this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at j.boggiano@seld.be', E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $m
|
||||
* @param array $a
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function __call($m, $a)
|
||||
{
|
||||
if (method_exists($this->dataProvider, $m)) {
|
||||
call_user_func_array(
|
||||
array(
|
||||
$this->dataProvider,
|
||||
$m
|
||||
), $a
|
||||
);
|
||||
} elseif ($this->show_compat_errors) {
|
||||
if (array_search($m, $this->compat['methods']) !== false) {
|
||||
$this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
|
||||
} else {
|
||||
$this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at j.boggiano@seld.be', E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List of unsupported properties and methods
|
||||
*/
|
||||
protected $compat = array(
|
||||
'methods' => array(
|
||||
'register_resource',
|
||||
'unregister_resource',
|
||||
'load_filter',
|
||||
'clear_compiled_tpl',
|
||||
'clear_config',
|
||||
'get_config_vars',
|
||||
'config_load',
|
||||
),
|
||||
'properties' => array(
|
||||
'cache_handler_func' => null,
|
||||
'debugging' => false,
|
||||
'error_reporting' => null,
|
||||
'debugging_ctrl' => 'NONE',
|
||||
'request_vars_order' => 'EGPCS',
|
||||
'request_use_auto_globals' => true,
|
||||
'use_sub_dirs' => false,
|
||||
'autoload_filters' => array(),
|
||||
'default_template_handler_func' => '',
|
||||
'debug_tpl' => '',
|
||||
'cache_modified_check' => false,
|
||||
'default_modifiers' => array(),
|
||||
'default_resource_type' => 'file',
|
||||
'config_overwrite' => true,
|
||||
'config_booleanize' => true,
|
||||
'config_read_hidden' => false,
|
||||
'config_fix_newlines' => true,
|
||||
'config_class' => 'Config_File',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Security vars
|
||||
*/
|
||||
public $security = false;
|
||||
public $trusted_dir = array();
|
||||
public $secure_dir = array();
|
||||
public $php_handling = SMARTY_PHP_PASSTHRU;
|
||||
public $security_settings = array(
|
||||
'PHP_HANDLING' => false,
|
||||
'IF_FUNCS' => array(
|
||||
'list',
|
||||
'empty',
|
||||
'count',
|
||||
'sizeof',
|
||||
'in_array',
|
||||
'is_array',
|
||||
),
|
||||
'INCLUDE_ANY' => false,
|
||||
'PHP_TAGS' => false,
|
||||
'MODIFIER_FUNCS' => array(),
|
||||
'ALLOW_CONSTANTS' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Paths
|
||||
*/
|
||||
public $template_dir = 'templates';
|
||||
public $compile_dir = 'templates_c';
|
||||
public $config_dir = 'configs';
|
||||
public $cache_dir = 'cache';
|
||||
public $plugins_dir = array();
|
||||
|
||||
/**
|
||||
* Misc options
|
||||
*/
|
||||
public $left_delimiter = '{';
|
||||
public $right_delimiter = '}';
|
||||
public $compile_check = true;
|
||||
public $force_compile = false;
|
||||
public $caching = 0;
|
||||
public $cache_lifetime = 3600;
|
||||
public $compile_id = null;
|
||||
public $compiler_file = null;
|
||||
public $compiler_class = null;
|
||||
|
||||
/**
|
||||
* Dwoo/Smarty compat layer
|
||||
*/
|
||||
public $show_compat_errors = false;
|
||||
protected $dataProvider;
|
||||
protected $_filters = array(
|
||||
'pre' => array(),
|
||||
'post' => array(),
|
||||
'output' => array()
|
||||
);
|
||||
protected static $tplCache = array();
|
||||
protected $compiler = null;
|
||||
|
||||
/**
|
||||
* Adapter constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->charset = 'iso-8859-1';
|
||||
$this->dataProvider = new Data();
|
||||
$this->compiler = new Compiler();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @param null $cacheId
|
||||
* @param null $compileId
|
||||
*/
|
||||
public function display($filename, $cacheId = null, $compileId = null)
|
||||
{
|
||||
$this->fetch($filename, $cacheId, $compileId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @param null $cacheId
|
||||
* @param null $compileId
|
||||
* @param bool $display
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function fetch($filename, $cacheId = null, $compileId = null, $display = false)
|
||||
{
|
||||
$this->setCacheDir($this->cache_dir);
|
||||
$this->setCompileDir($this->compile_dir);
|
||||
|
||||
if ($this->security) {
|
||||
$policy = new SecurityPolicy();
|
||||
$policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS']));
|
||||
|
||||
$phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling;
|
||||
if ($this->security_settings['PHP_TAGS']) {
|
||||
$phpTags = SMARTY_PHP_ALLOW;
|
||||
}
|
||||
switch ($phpTags) {
|
||||
case SMARTY_PHP_ALLOW:
|
||||
case SMARTY_PHP_PASSTHRU:
|
||||
$phpTags = SecurityPolicy::PHP_ALLOW;
|
||||
break;
|
||||
case SMARTY_PHP_QUOTE:
|
||||
$phpTags = SecurityPolicy::PHP_ENCODE;
|
||||
break;
|
||||
case SMARTY_PHP_REMOVE:
|
||||
default:
|
||||
$phpTags = SecurityPolicy::PHP_REMOVE;
|
||||
break;
|
||||
}
|
||||
$policy->setPhpHandling($phpTags);
|
||||
|
||||
$policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']);
|
||||
|
||||
if ($this->security_settings['INCLUDE_ANY']) {
|
||||
$policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__));
|
||||
} else {
|
||||
$policy->allowDirectory($this->secure_dir);
|
||||
}
|
||||
|
||||
$this->setSecurityPolicy($policy);
|
||||
}
|
||||
|
||||
if (!empty($this->plugins_dir)) {
|
||||
foreach ($this->plugins_dir as $dir) {
|
||||
$this->getLoader()->addDirectory(rtrim($dir, '\\/'));
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = $this->makeTemplate($filename, $cacheId, $compileId);
|
||||
if ($this->force_compile) {
|
||||
$tpl->forceCompilation();
|
||||
}
|
||||
|
||||
if ($this->caching > 0) {
|
||||
$this->cacheTime = $this->cache_lifetime;
|
||||
} else {
|
||||
$this->cacheTime = 0;
|
||||
}
|
||||
|
||||
if ($this->compiler_class !== null) {
|
||||
if ($this->compiler_file !== null && !class_exists($this->compiler_class)) {
|
||||
include $this->compiler_file;
|
||||
}
|
||||
$this->compiler = new $this->compiler_class();
|
||||
} else {
|
||||
$this->compiler->addPreProcessor('PluginSmartyCompatible', true);
|
||||
$this->compiler->setLooseOpeningHandling(true);
|
||||
}
|
||||
|
||||
$this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter);
|
||||
|
||||
return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $_tpl
|
||||
* @param array $data
|
||||
* @param null $_compiler
|
||||
* @param bool $_output
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function get($_tpl, $data = array(), $_compiler = null, $_output = false)
|
||||
{
|
||||
if ($_compiler === null) {
|
||||
$_compiler = $this->compiler;
|
||||
}
|
||||
|
||||
return parent::get($_tpl, $data, $_compiler, $_output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $callback
|
||||
* @param bool $cacheable
|
||||
* @param null $cache_attrs
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function register_function($name, $callback, $cacheable = true, $cache_attrs = null)
|
||||
{
|
||||
if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_FUNCTION) {
|
||||
throw new Exception('Multiple plugins of different types can not share the same name');
|
||||
}
|
||||
$this->plugins[$name] = array(
|
||||
'type' => self::SMARTY_FUNCTION,
|
||||
'callback' => $callback
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*/
|
||||
public function unregister_function($name)
|
||||
{
|
||||
unset($this->plugins[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $callback
|
||||
* @param bool $cacheable
|
||||
* @param null $cache_attrs
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function register_block($name, $callback, $cacheable = true, $cache_attrs = null)
|
||||
{
|
||||
if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) {
|
||||
throw new Exception('Multiple plugins of different types can not share the same name');
|
||||
}
|
||||
$this->plugins[$name] = array(
|
||||
'type' => self::SMARTY_BLOCK,
|
||||
'callback' => $callback
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*/
|
||||
public function unregister_block($name)
|
||||
{
|
||||
unset($this->plugins[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $callback
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function register_modifier($name, $callback)
|
||||
{
|
||||
if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_MODIFIER) {
|
||||
throw new Exception('Multiple plugins of different types can not share the same name');
|
||||
}
|
||||
$this->plugins[$name] = array(
|
||||
'type' => self::SMARTY_MODIFIER,
|
||||
'callback' => $callback
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*/
|
||||
public function unregister_modifier($name)
|
||||
{
|
||||
unset($this->plugins[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
*/
|
||||
public function register_prefilter($callback)
|
||||
{
|
||||
$processor = new ProcessorAdapter($this->compiler);
|
||||
$processor->registerCallback($callback);
|
||||
$this->_filters['pre'][] = $processor;
|
||||
$this->compiler->addPreProcessor($processor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
*/
|
||||
public function unregister_prefilter($callback)
|
||||
{
|
||||
foreach ($this->_filters['pre'] as $index => $processor) {
|
||||
if ($processor->callback === $callback) {
|
||||
$this->compiler->removePostProcessor($processor);
|
||||
unset($this->_filters['pre'][$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
*/
|
||||
public function register_postfilter($callback)
|
||||
{
|
||||
$processor = new ProcessorAdapter($this->compiler);
|
||||
$processor->registerCallback($callback);
|
||||
$this->_filters['post'][] = $processor;
|
||||
$this->compiler->addPostProcessor($processor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
*/
|
||||
public function unregister_postfilter($callback)
|
||||
{
|
||||
foreach ($this->_filters['post'] as $index => $processor) {
|
||||
if ($processor->callback === $callback) {
|
||||
$this->compiler->removePostProcessor($processor);
|
||||
unset($this->_filters['post'][$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
*/
|
||||
public function register_outputfilter($callback)
|
||||
{
|
||||
$filter = new FilterAdapter($this);
|
||||
$filter->registerCallback($callback);
|
||||
$this->_filters['output'][] = $filter;
|
||||
$this->addFilter($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
*/
|
||||
public function unregister_outputfilter($callback)
|
||||
{
|
||||
foreach ($this->_filters['output'] as $index => $filter) {
|
||||
if ($filter->callback === $callback) {
|
||||
$this->removeOutputFilter($filter);
|
||||
unset($this->_filters['output'][$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @param $object_impl
|
||||
* @param array $allowed
|
||||
* @param bool $smarty_args
|
||||
* @param array $block_methods
|
||||
*/
|
||||
public function register_object($object, $object_impl, $allowed = array(), $smarty_args = false, $block_methods = array())
|
||||
{
|
||||
settype($allowed, 'array');
|
||||
settype($block_methods, 'array');
|
||||
settype($smarty_args, 'boolean');
|
||||
|
||||
if (!empty($allowed) && $this->show_compat_errors) {
|
||||
$this->triggerError('You can register objects but can not restrict the method/properties used, this is PHP5, you have proper OOP access restrictions so use them.', E_USER_NOTICE);
|
||||
}
|
||||
|
||||
if ($smarty_args) {
|
||||
$this->triggerError('You can register objects but methods will be called using method($arg1, $arg2, $arg3), not as an argument array like smarty did.', E_USER_NOTICE);
|
||||
}
|
||||
|
||||
if (!empty($block_methods)) {
|
||||
$this->triggerError('You can register objects but can not use methods as being block methods, you have to build a plugin for that.', E_USER_NOTICE);
|
||||
}
|
||||
|
||||
$this->dataProvider->assign($object, $object_impl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
*/
|
||||
public function unregister_object($object)
|
||||
{
|
||||
$this->dataProvider->clear($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_registered_object($name)
|
||||
{
|
||||
$data = $this->dataProvider->getData();
|
||||
if (isset($data[$name]) && is_object($data[$name])) {
|
||||
return $data[$name];
|
||||
} else {
|
||||
trigger_error('Dwoo_Compiler: object "' . $name . '" was not registered or is not an object', E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function template_exists($filename)
|
||||
{
|
||||
if (!is_array($this->template_dir)) {
|
||||
return file_exists($this->template_dir . DIRECTORY_SEPARATOR . $filename);
|
||||
} else {
|
||||
foreach ($this->template_dir as $tpl_dir) {
|
||||
if (file_exists($tpl_dir . DIRECTORY_SEPARATOR . $filename)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tpl
|
||||
* @param null $cacheId
|
||||
* @param null $compileId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_cached($tpl, $cacheId = null, $compileId = null)
|
||||
{
|
||||
return $this->isCached($this->makeTemplate($tpl, $cacheId, $compileId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $var
|
||||
* @param $value
|
||||
* @param bool $merge
|
||||
*/
|
||||
public function append_by_ref($var, &$value, $merge = false)
|
||||
{
|
||||
$this->dataProvider->appendByRef($var, $value, $merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $val
|
||||
*/
|
||||
public function assign_by_ref($name, &$val)
|
||||
{
|
||||
$this->dataProvider->assignByRef($name, $val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $var
|
||||
*/
|
||||
public function clear_assign($var)
|
||||
{
|
||||
$this->dataProvider->clear($var);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function clear_all_assign()
|
||||
{
|
||||
$this->dataProvider->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $name
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function get_template_vars($name = null)
|
||||
{
|
||||
if ($this->show_compat_errors) {
|
||||
trigger_error('get_template_vars does not return values by reference, if you try to modify the data that way you should modify your code.', E_USER_NOTICE);
|
||||
}
|
||||
|
||||
$data = $this->dataProvider->getData();
|
||||
if ($name === null) {
|
||||
return $data;
|
||||
} elseif (isset($data[$name])) {
|
||||
return $data[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $olderThan
|
||||
*/
|
||||
public function clear_all_cache($olderThan = 0)
|
||||
{
|
||||
$this->clearCache($olderThan);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $template
|
||||
* @param null $cacheId
|
||||
* @param null $compileId
|
||||
* @param int $olderThan
|
||||
*/
|
||||
public function clear_cache($template, $cacheId = null, $compileId = null, $olderThan = 0)
|
||||
{
|
||||
$this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $error_msg
|
||||
* @param int $error_type
|
||||
*/
|
||||
public function trigger_error($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
$this->triggerError($error_msg, $error_type);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function initGlobals()
|
||||
{
|
||||
parent::initGlobals();
|
||||
$this->globals['ldelim'] = '{';
|
||||
$this->globals['rdelim'] = '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $file
|
||||
* @param $cacheId
|
||||
* @param $compileId
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function makeTemplate($file, $cacheId, $compileId)
|
||||
{
|
||||
if ($compileId === null) {
|
||||
$compileId = $this->compile_id;
|
||||
}
|
||||
|
||||
$hash = bin2hex(md5($file . $cacheId . $compileId, true));
|
||||
if (!isset(self::$tplCache[$hash])) {
|
||||
// abs path
|
||||
if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') {
|
||||
self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId);
|
||||
} elseif (is_string($this->template_dir) || is_array($this->template_dir)) {
|
||||
self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId, $this->template_dir);
|
||||
} else {
|
||||
throw new Exception('Unable to load "' . $file . '", check the template_dir');
|
||||
}
|
||||
}
|
||||
|
||||
return self::$tplCache[$hash];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param int $level
|
||||
*/
|
||||
public function triggerError($message, $level = E_USER_NOTICE)
|
||||
{
|
||||
if (is_object($this->template)) {
|
||||
parent::triggerError($message, $level);
|
||||
}
|
||||
trigger_error('Dwoo error : ' . $message, $level);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Smarty\Filter
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Smarty\Filter;
|
||||
|
||||
use Dwoo\Filter;
|
||||
|
||||
/**
|
||||
* Class Adapter
|
||||
*/
|
||||
class Adapter extends Filter
|
||||
{
|
||||
public $callback;
|
||||
|
||||
/**
|
||||
* @param string $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function process($input)
|
||||
{
|
||||
return call_user_func($this->callback, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
*/
|
||||
public function registerCallback($callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2016
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Smarty\Processor
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2016 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @version 1.3.0
|
||||
* @date 2016-09-23
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Smarty\Processor;
|
||||
|
||||
use Dwoo\Processor;
|
||||
|
||||
/**
|
||||
* Class Adapter
|
||||
*/
|
||||
class Adapter extends Processor
|
||||
{
|
||||
public $callback;
|
||||
|
||||
/**
|
||||
* @param string $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function process($input)
|
||||
{
|
||||
return call_user_func($this->callback, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
*/
|
||||
public function registerCallback($callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
}
|
||||
@@ -1,276 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Template
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.4.0
|
||||
* @date 2017-03-16
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Template;
|
||||
|
||||
use Dwoo\Exception as DwooException;
|
||||
use Dwoo\Core as Core;
|
||||
use Dwoo\ICompiler;
|
||||
use Dwoo\ITemplate as ITemplate;
|
||||
use Dwoo\Security\Exception as SecurityException;
|
||||
use Dwoo\Template\File as TemplateFile;
|
||||
|
||||
/**
|
||||
* Represents a Dwoo template contained in a file.
|
||||
* 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.
|
||||
*/
|
||||
class File extends Str
|
||||
{
|
||||
/**
|
||||
* Template filename.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* Include path(s) to look into to find this template.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $includePath = array();
|
||||
|
||||
/**
|
||||
* Resolved path cache when looking for a file in multiple include paths.
|
||||
* this is reset when the include path is changed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $resolvedPath = null;
|
||||
|
||||
/**
|
||||
* Creates a template from a file.
|
||||
*
|
||||
* @param string $file the path to the template file, make sure it exists
|
||||
* @param int $cacheTime duration of the cache validity for this template,
|
||||
* if null it defaults to the Dwoo instance that will
|
||||
* render this template
|
||||
* @param string $cacheId the unique cache identifier of this page or anything else that
|
||||
* makes this template's content unique, if null it defaults
|
||||
* to the current url
|
||||
* @param string $compileId the unique compiled identifier, which is used to distinguish this
|
||||
* template from others, if null it defaults to the filename+bits of the path
|
||||
* @param mixed $includePath a string for a single path to look into for the given file, or an array of paths
|
||||
*/
|
||||
public function __construct($file, $cacheTime = null, $cacheId = null, $compileId = null, $includePath = array())
|
||||
{
|
||||
parent::__construct($file, $cacheTime, $cacheId, $compileId);
|
||||
$this->template = null;
|
||||
$this->file = $file;
|
||||
$this->name = basename($file);
|
||||
$this->setIncludePath($includePath);
|
||||
$this->compileId = $this->getResourceIdentifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the include path(s) to where the given template filename must be looked up.
|
||||
*
|
||||
* @param mixed $paths the path to look into, can be string for a single path or an array of paths
|
||||
*/
|
||||
public function setIncludePath($paths)
|
||||
{
|
||||
if (is_array($paths) === false) {
|
||||
$paths = array($paths);
|
||||
}
|
||||
|
||||
$this->includePath = $paths;
|
||||
$this->resolvedPath = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current include path(s).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIncludePath()
|
||||
{
|
||||
return $this->includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if compiled file is valid (exists and it's the modification is greater or
|
||||
* equal to the modification time of the template file).
|
||||
*
|
||||
* @param string file
|
||||
*
|
||||
* @return bool True cache file existance and it's modification time
|
||||
*/
|
||||
protected function isValidCompiledFile($file)
|
||||
{
|
||||
return parent::isValidCompiledFile($file) && (int)$this->getUid() <= filemtime($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the template source of this template.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return file_get_contents($this->getResourceIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resource name for this template class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceName()
|
||||
{
|
||||
return 'file';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this template's source filename.
|
||||
*
|
||||
* @return string
|
||||
* @throws DwooException
|
||||
*/
|
||||
public function getResourceIdentifier()
|
||||
{
|
||||
if ($this->resolvedPath !== null) {
|
||||
return $this->resolvedPath;
|
||||
} elseif (array_filter($this->getIncludePath()) == array()) {
|
||||
return $this->file;
|
||||
} else {
|
||||
foreach ($this->getIncludePath() as $path) {
|
||||
$path = rtrim($path, DIRECTORY_SEPARATOR);
|
||||
if (file_exists($path . DIRECTORY_SEPARATOR . $this->file) === true) {
|
||||
return $this->resolvedPath = $path . DIRECTORY_SEPARATOR . $this->file;
|
||||
}
|
||||
}
|
||||
|
||||
throw new DwooException('Template "' . $this->file . '" could not be found in any of your include path(s)');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unique value identifying the current version of this template,
|
||||
* in this case it's the unix timestamp of the last modification.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUid()
|
||||
{
|
||||
return (string)filemtime($this->getResourceIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new template object from the given include name, null if no include is
|
||||
* possible (resource not found), or false if include is not permitted by this resource type.
|
||||
*
|
||||
* @param Core $core the dwoo instance requiring it
|
||||
* @param mixed $resourceId the filename (relative to this template's dir) of the template to
|
||||
* include
|
||||
* @param int $cacheTime duration of the cache validity for this template, if null it defaults
|
||||
* to the Dwoo instance that will render this template if null it
|
||||
* defaults to the Dwoo instance that will render this template if null
|
||||
* it defaults to the Dwoo instance that will render this template
|
||||
* @param string $cacheId the unique cache identifier of this page or anything else that makes
|
||||
* this template's content unique, if null it defaults to the current
|
||||
* url makes this template's content unique, if null it defaults to the
|
||||
* current url makes this template's content unique, if null it defaults
|
||||
* to the current url
|
||||
* @param string $compileId the unique compiled identifier, which is used to distinguish this
|
||||
* template from others, if null it defaults to the filename+bits of the
|
||||
* path template from others, if null it defaults to the filename+bits
|
||||
* of the path template from others, if null it defaults to the
|
||||
* filename+bits of the path
|
||||
* @param ITemplate $parentTemplate the template that is requesting a new template object (through an
|
||||
* include, extends or any other plugin) an include, extends or any
|
||||
* other plugin) an include, extends or any other plugin)
|
||||
*
|
||||
* @return TemplateFile|null
|
||||
* @throws DwooException
|
||||
* @throws SecurityException
|
||||
*/
|
||||
public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null,
|
||||
$compileId = null, ITemplate $parentTemplate = null)
|
||||
{
|
||||
if (DIRECTORY_SEPARATOR === '\\') {
|
||||
$resourceId = str_replace(array("\t", "\n", "\r", "\f", "\v"), array(
|
||||
'\\t',
|
||||
'\\n',
|
||||
'\\r',
|
||||
'\\f',
|
||||
'\\v'
|
||||
), $resourceId);
|
||||
}
|
||||
$resourceId = strtr($resourceId, '\\', '/');
|
||||
|
||||
$includePath = null;
|
||||
|
||||
if (file_exists($resourceId) === false) {
|
||||
if ($parentTemplate === null) {
|
||||
$parentTemplate = $core->getTemplate();
|
||||
}
|
||||
if ($parentTemplate instanceof self) {
|
||||
if ($includePath = $parentTemplate->getIncludePath()) {
|
||||
if (strstr($resourceId, '../')) {
|
||||
throw new DwooException('When using an include path you can not reference a template into a parent directory (using ../)');
|
||||
}
|
||||
} else {
|
||||
$resourceId = dirname($parentTemplate->getResourceIdentifier()) . DIRECTORY_SEPARATOR . $resourceId;
|
||||
if (file_exists($resourceId) === false) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($policy = $core->getSecurityPolicy()) {
|
||||
while (true) {
|
||||
if (preg_match('{^([a-z]+?)://}i', $resourceId)) {
|
||||
throw new SecurityException('The security policy prevents you to read files from external sources : <em>' . $resourceId . '</em>.');
|
||||
}
|
||||
|
||||
if ($includePath) {
|
||||
break;
|
||||
}
|
||||
|
||||
$resourceId = realpath($resourceId);
|
||||
$dirs = $policy->getAllowedDirectories();
|
||||
foreach ($dirs as $dir => $dummy) {
|
||||
if (strpos($resourceId, $dir) === 0) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
throw new SecurityException('The security policy prevents you to read <em>' . $resourceId . '</em>');
|
||||
}
|
||||
}
|
||||
|
||||
$class = 'Dwoo\Template\File';
|
||||
if ($parentTemplate) {
|
||||
$class = get_class($parentTemplate);
|
||||
}
|
||||
|
||||
return new $class($resourceId, $cacheTime, $cacheId, $compileId, $includePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns some php code that will check if this template has been modified or not.
|
||||
* if the function returns null, the template will be instanciated and then the Uid checked
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIsModifiedCode()
|
||||
{
|
||||
return '"' . $this->getUid() . '" == filemtime(' . var_export($this->getResourceIdentifier(), true) . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,535 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013-2017
|
||||
*
|
||||
* @category Library
|
||||
* @package Dwoo\Template
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author David Sanchez <david38sanchez@gmail.com>
|
||||
* @copyright 2008-2013 Jordi Boggiano
|
||||
* @copyright 2013-2017 David Sanchez
|
||||
* @license http://dwoo.org/LICENSE LGPLv3
|
||||
* @version 1.4.0
|
||||
* @date 2017-03-16
|
||||
* @link http://dwoo.org/
|
||||
*/
|
||||
|
||||
namespace Dwoo\Template;
|
||||
|
||||
use Dwoo\Core;
|
||||
use Dwoo\Compiler;
|
||||
use Dwoo\ITemplate;
|
||||
use Dwoo\ICompiler;
|
||||
use Dwoo\Exception;
|
||||
|
||||
/**
|
||||
* Represents a Dwoo template contained in a string.
|
||||
* 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.
|
||||
*/
|
||||
class Str implements ITemplate
|
||||
{
|
||||
/**
|
||||
* Template name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Template compilation id.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $compileId;
|
||||
|
||||
/**
|
||||
* Template cache id, if not provided in the constructor, it is set to
|
||||
* the md4 hash of the request_uri. it is however highly recommended to
|
||||
* provide one that will fit your needs.
|
||||
* in all cases, the compilation id is prepended to the cache id to separate
|
||||
* templates with similar cache ids from one another
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $cacheId;
|
||||
|
||||
/**
|
||||
* Validity duration of the generated cache file (in seconds).
|
||||
* set to -1 for infinite cache, 0 to disable and null to inherit the Dwoo instance's cache time
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $cacheTime;
|
||||
|
||||
/**
|
||||
* Boolean flag that defines whether the compilation should be enforced (once) or
|
||||
* not use this if you have issues with the compiled templates not being updated
|
||||
* but if you do need this it's most likely that you should file a bug report.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $compilationEnforced;
|
||||
|
||||
/**
|
||||
* Caches the results of the file checks to save some time when the same
|
||||
* templates is rendered several times.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $cache = array(
|
||||
'cached' => array(),
|
||||
'compiled' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Holds the compiler that built this template.
|
||||
*
|
||||
* @var ICompiler
|
||||
*/
|
||||
protected $compiler;
|
||||
|
||||
/**
|
||||
* Chmod value for all files written (cached or compiled ones).
|
||||
* set to null if you don't want any chmod operation to happen
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $chmod = 0777;
|
||||
|
||||
/**
|
||||
* Containing template string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* Creates a template from a string.
|
||||
*
|
||||
* @param string $templateString the template to use
|
||||
* @param int $cacheTime duration of the cache validity for this template,
|
||||
* if null it defaults to the Dwoo instance that will
|
||||
* render this template, set to -1 for infinite cache or 0 to disable
|
||||
* @param string $cacheId the unique cache identifier of this page or anything else that
|
||||
* makes this template's content unique, if null it defaults
|
||||
* to the current url
|
||||
* @param string $compileId the unique compiled identifier, which is used to distinguish this
|
||||
* template from others, if null it defaults to the md4 hash of the template
|
||||
*/
|
||||
public function __construct($templateString, $cacheTime = null, $cacheId = null, $compileId = null)
|
||||
{
|
||||
$this->template = $templateString;
|
||||
$this->name = hash('md4', $templateString);
|
||||
$this->cacheTime = $cacheTime;
|
||||
|
||||
if ($compileId !== null) {
|
||||
$this->compileId = str_replace('../', '__', strtr($compileId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
|
||||
} else {
|
||||
$this->compileId = $templateString;
|
||||
}
|
||||
|
||||
if ($cacheId !== null) {
|
||||
$this->cacheId = str_replace('../', '__', strtr($cacheId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cache duration for this template.
|
||||
* defaults to null if it was not provided
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCacheTime()
|
||||
{
|
||||
return $this->cacheTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cache duration for this template.
|
||||
* can be used to set it after the object is created if you did not provide
|
||||
* it in the constructor
|
||||
*
|
||||
* @param int $seconds duration of the cache validity for this template, if
|
||||
* null it defaults to the Dwoo instance's cache time. 0 = disable and
|
||||
* -1 = infinite cache
|
||||
*/
|
||||
public function setCacheTime($seconds = null)
|
||||
{
|
||||
$this->cacheTime = $seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the chmod value for all files written (cached or compiled ones).
|
||||
* defaults to 0777
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getChmod()
|
||||
{
|
||||
return $this->chmod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the chmod value for all files written (cached or compiled ones).
|
||||
* set to null if you don't want to do any chmod() operation
|
||||
*
|
||||
* @param int $mask new bitmask to use for all files
|
||||
*/
|
||||
public function setChmod($mask = null)
|
||||
{
|
||||
$this->chmod = $mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the template name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resource name for this template class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceName()
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resource identifier for this template, false here as strings don't have identifiers.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public function getResourceIdentifier()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the template source of this template.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unique value identifying the current version of this template,
|
||||
* in this case it's the md4 hash of the content.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUid()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the compiler used by this template, if it was just compiled, or null.
|
||||
*
|
||||
* @return ICompiler
|
||||
*/
|
||||
public function getCompiler()
|
||||
{
|
||||
return $this->compiler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks this template as compile-forced, which means it will be recompiled even if it
|
||||
* was already saved and wasn't modified since the last compilation. do not use this in production,
|
||||
* it's only meant to be used in development (and the development of dwoo particularly).
|
||||
*/
|
||||
public function forceCompilation()
|
||||
{
|
||||
$this->compilationEnforced = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached template output file name, true if it's cache-able but not cached
|
||||
* or false if it's not cached.
|
||||
*
|
||||
* @param Core $core the dwoo instance that requests it
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getCachedTemplate(Core $core)
|
||||
{
|
||||
$cacheLength = $core->getCacheTime();
|
||||
if ($this->cacheTime !== null) {
|
||||
$cacheLength = $this->cacheTime;
|
||||
}
|
||||
|
||||
// file is not cacheable
|
||||
if ($cacheLength == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cachedFile = $this->getCacheFilename($core);
|
||||
|
||||
if (isset(self::$cache['cached'][$this->cacheId]) === true && file_exists($cachedFile)) {
|
||||
// already checked, return cache file
|
||||
return $cachedFile;
|
||||
} elseif ($this->compilationEnforced !== true && file_exists($cachedFile) && ($cacheLength === - 1 || filemtime($cachedFile) > ($_SERVER['REQUEST_TIME'] - $cacheLength)) && $this->isValidCompiledFile($this->getCompiledFilename($core))) {
|
||||
// cache is still valid and can be loaded
|
||||
self::$cache['cached'][$this->cacheId] = true;
|
||||
|
||||
return $cachedFile;
|
||||
}
|
||||
|
||||
// file is cacheable
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches the provided output into the cache file.
|
||||
*
|
||||
* @param Core $core the dwoo instance that requests it
|
||||
* @param string $output the template output
|
||||
*
|
||||
* @return mixed full path of the cached file or false upon failure
|
||||
*/
|
||||
public function cache(Core $core, $output)
|
||||
{
|
||||
$cacheDir = $core->getCacheDir();
|
||||
$cachedFile = $this->getCacheFilename($core);
|
||||
|
||||
// the code below is courtesy of Rasmus Schultz,
|
||||
// thanks for his help on avoiding concurency issues
|
||||
$temp = tempnam($cacheDir, 'temp');
|
||||
if (!($file = @fopen($temp, 'wb'))) {
|
||||
$temp = $cacheDir . uniqid('temp');
|
||||
if (!($file = @fopen($temp, 'wb'))) {
|
||||
trigger_error('Error writing temporary file \'' . $temp . '\'', E_USER_WARNING);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
fwrite($file, $output);
|
||||
fclose($file);
|
||||
|
||||
$this->makeDirectory(dirname($cachedFile), $cacheDir);
|
||||
if (!@rename($temp, $cachedFile)) {
|
||||
@unlink($cachedFile);
|
||||
@rename($temp, $cachedFile);
|
||||
}
|
||||
|
||||
if ($this->chmod !== null) {
|
||||
chmod($cachedFile, $this->chmod);
|
||||
}
|
||||
|
||||
self::$cache['cached'][$this->cacheId] = true;
|
||||
|
||||
return $cachedFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the cached template if it's older than the given time.
|
||||
*
|
||||
* @param Core $core the dwoo instance that was used to cache that template
|
||||
* @param int $olderThan minimum time (in seconds) required for the cache to be cleared
|
||||
*
|
||||
* @return bool true if the cache was not present or if it was deleted, false if it remains there
|
||||
*/
|
||||
public function clearCache(Core $core, $olderThan = - 1)
|
||||
{
|
||||
$cachedFile = $this->getCacheFilename($core);
|
||||
|
||||
return !file_exists($cachedFile) || (filectime($cachedFile) < (time() - $olderThan) && unlink($cachedFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the compiled template file name.
|
||||
*
|
||||
* @param Core $core the dwoo instance that requests it
|
||||
* @param ICompiler $compiler the compiler that must be used
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCompiledTemplate(Core $core, ICompiler $compiler = null)
|
||||
{
|
||||
$compiledFile = $this->getCompiledFilename($core);
|
||||
|
||||
if ($this->compilationEnforced !== true && isset(self::$cache['compiled'][$this->compileId]) === true) {
|
||||
// already checked, return compiled file
|
||||
} elseif ($this->compilationEnforced !== true && $this->isValidCompiledFile($compiledFile)) {
|
||||
// template is compiled
|
||||
self::$cache['compiled'][$this->compileId] = true;
|
||||
} else {
|
||||
// compiles the template
|
||||
$this->compilationEnforced = false;
|
||||
|
||||
if ($compiler === null) {
|
||||
$compiler = $core->getDefaultCompilerFactory($this->getResourceName());
|
||||
|
||||
if ($compiler === null || $compiler === array('Dwoo\Compiler', 'compilerFactory')) {
|
||||
$compiler = Compiler::compilerFactory();
|
||||
} else {
|
||||
$compiler = call_user_func($compiler);
|
||||
}
|
||||
}
|
||||
|
||||
$this->compiler = $compiler;
|
||||
|
||||
$compiler->setCustomPlugins($core->getCustomPlugins());
|
||||
$compiler->setSecurityPolicy($core->getSecurityPolicy());
|
||||
$this->makeDirectory(dirname($compiledFile), $core->getCompileDir());
|
||||
file_put_contents($compiledFile, $compiler->compile($core, $this));
|
||||
if ($this->chmod !== null) {
|
||||
chmod($compiledFile, $this->chmod);
|
||||
}
|
||||
|
||||
if (extension_loaded('Zend OPcache')) {
|
||||
opcache_invalidate($compiledFile);
|
||||
} elseif (extension_loaded('apc') && ini_get('apc.enabled')) {
|
||||
apc_delete_file($compiledFile);
|
||||
}
|
||||
|
||||
self::$cache['compiled'][$this->compileId] = true;
|
||||
}
|
||||
|
||||
return $compiledFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if compiled file is valid (it exists).
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool True cache file existence
|
||||
*/
|
||||
protected function isValidCompiledFile($file)
|
||||
{
|
||||
return file_exists($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new template string object with the resource id being the template source code.
|
||||
*
|
||||
* @param Core $core the dwoo instance requiring it
|
||||
* @param mixed $resourceId the filename (relative to this template's dir) of the template to include
|
||||
* @param int $cacheTime duration of the cache validity for this template, if null it defaults to the
|
||||
* Dwoo instance that will render this template if null it defaults to the Dwoo
|
||||
* instance that will render this template
|
||||
* @param string $cacheId the unique cache identifier of this page or anything else that makes this
|
||||
* template's content unique, if null it defaults to the current url makes this
|
||||
* template's content unique, if null it defaults to the current url
|
||||
* @param string $compileId the unique compiled identifier, which is used to distinguish this template from
|
||||
* others, if null it defaults to the filename+bits of the path template from
|
||||
* others, if null it defaults to the filename+bits of the path
|
||||
* @param ITemplate $parentTemplate the template that is requesting a new template object (through an include,
|
||||
* extends or any other plugin) an include, extends or any other plugin)
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null,
|
||||
$compileId = null, ITemplate $parentTemplate = null)
|
||||
{
|
||||
return new self($resourceId, $cacheTime, $cacheId, $compileId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full compiled file name and assigns a default value to it if
|
||||
* required.
|
||||
*
|
||||
* @param Core $core the Core instance that requests the file name
|
||||
*
|
||||
* @return string the full path to the compiled file
|
||||
*/
|
||||
protected function getCompiledFilename(Core $core)
|
||||
{
|
||||
return $core->getCompileDir() . hash('md4', $this->compileId) . '.d' . Core::RELEASE_TAG . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full cached file name and assigns a default value to it if
|
||||
* required.
|
||||
*
|
||||
* @param Core $core the dwoo instance that requests the file name
|
||||
*
|
||||
* @return string the full path to the cached file
|
||||
*/
|
||||
protected function getCacheFilename(Core $core)
|
||||
{
|
||||
// no cache id provided, use request_uri as default
|
||||
if ($this->cacheId === null) {
|
||||
if (isset($_SERVER['REQUEST_URI']) === true) {
|
||||
$cacheId = $_SERVER['REQUEST_URI'];
|
||||
} elseif (isset($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['argv'])) {
|
||||
$cacheId = $_SERVER['SCRIPT_FILENAME'] . '-' . implode('-', $_SERVER['argv']);
|
||||
} else {
|
||||
$cacheId = '';
|
||||
}
|
||||
// force compiled id generation
|
||||
$this->getCompiledFilename($core);
|
||||
|
||||
$this->cacheId = str_replace('../', '__',
|
||||
$this->compileId . strtr($cacheId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
|
||||
}
|
||||
|
||||
return $core->getCacheDir() . $this->cacheId . '.html';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns some php code that will check if this template has been modified or not.
|
||||
* if the function returns null, the template will be instanciated and then the Uid checked
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIsModifiedCode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the given path exists.
|
||||
*
|
||||
* @param string $path any path
|
||||
* @param string $baseDir the base directory where the directory is created
|
||||
* ($path must still contain the full path, $baseDir
|
||||
* is only used for unix permissions)
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function makeDirectory($path, $baseDir = null)
|
||||
{
|
||||
if (is_dir($path) === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->chmod === null) {
|
||||
$chmod = 0777;
|
||||
} else {
|
||||
$chmod = $this->chmod;
|
||||
}
|
||||
|
||||
$retries = 3;
|
||||
while ($retries --) {
|
||||
@mkdir($path, $chmod, true);
|
||||
if (is_dir($path)) {
|
||||
break;
|
||||
}
|
||||
usleep(20);
|
||||
}
|
||||
|
||||
// enforce the correct mode for all directories created
|
||||
if (strpos(PHP_OS, 'WIN') !== 0 && $baseDir !== null) {
|
||||
$path = strtr(str_replace($baseDir, '', $path), '\\', '/');
|
||||
$folders = explode('/', trim($path, '/'));
|
||||
foreach ($folders as $folder) {
|
||||
$baseDir .= $folder . DIRECTORY_SEPARATOR;
|
||||
if (!chmod($baseDir, $chmod)) {
|
||||
throw new Exception('Unable to chmod ' . "$baseDir to $chmod: " . print_r(error_get_last(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
core/l/PHPMailer/.gitattributes
vendored
17
core/l/PHPMailer/.gitattributes
vendored
@@ -1,17 +0,0 @@
|
||||
* text=auto
|
||||
|
||||
/.gitattributes export-ignore
|
||||
/.github export-ignore
|
||||
/.gitignore export-ignore
|
||||
/.phan export-ignore
|
||||
/.php_cs export-ignore
|
||||
/.scrutinizer.yml export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/changelog.md export-ignore
|
||||
/composer.json export-ignore
|
||||
/docs export-ignore
|
||||
/examples export-ignore
|
||||
/phpdoc.dist.xml export-ignore
|
||||
/test export-ignore
|
||||
/travis.phpunit.xml.dist export-ignore
|
||||
/UPGRADING.md export-ignore
|
||||
13
core/l/PHPMailer/.github/ISSUE_TEMPLATE.md
vendored
13
core/l/PHPMailer/.github/ISSUE_TEMPLATE.md
vendored
@@ -1,13 +0,0 @@
|
||||
Please check these things before submitting your issue:
|
||||
|
||||
- [ ] Make sure you're using the latest version of PHPMailer
|
||||
- [ ] Check that your problem is not dealt with in [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting), especially if you're having problems connecting to Gmail or GoDaddy
|
||||
- [ ] Include sufficient code to reproduce your problem
|
||||
- [ ] If you're having an SMTP issue, include the debug output generated with `SMTPDebug = 2` set
|
||||
- [ ] If you have a question about how to use PHPMailer (rather than reporting a bug in it), tag a question on Stack Overflow with `phpmailer`, but [**search first**](http://stackoverflow.com/questions/tagged/phpmailer)!
|
||||
|
||||
# Problem description
|
||||
|
||||
# Code to reproduce
|
||||
|
||||
# Debug output
|
||||
@@ -1,6 +0,0 @@
|
||||
Before submitting your pull request, check whether your code adheres to PHPMailer
|
||||
coding standards by running the following command:
|
||||
|
||||
`./vendor/bin/php-cs-fixer --diff --dry-run --verbose fix `
|
||||
|
||||
And committing eventual changes. It's important that this command uses the specific version of php-cs-fixer configured for PHPMailer, so run `composer install` within the PHPMailer folder to use the exact version it needs.
|
||||
9
core/l/PHPMailer/.gitignore
vendored
9
core/l/PHPMailer/.gitignore
vendored
@@ -1,9 +0,0 @@
|
||||
docs/*
|
||||
!docs/README.md
|
||||
test/message.txt
|
||||
test/testbootstrap.php
|
||||
build/
|
||||
vendor/
|
||||
*.pem
|
||||
composer.lock
|
||||
.php_cs.cache
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This configuration will be read and overlaid on top of the
|
||||
* default configuration. Command line arguments will be applied
|
||||
* after this file is read.
|
||||
*/
|
||||
return [
|
||||
|
||||
// A list of directories that should be parsed for class and
|
||||
// method information. After excluding the directories
|
||||
// defined in exclude_analysis_directory_list, the remaining
|
||||
// files will be statically analyzed for errors.
|
||||
//
|
||||
// Thus, both first-party and third-party code being used by
|
||||
// your application should be included in this list.
|
||||
'directory_list' => [
|
||||
'src',
|
||||
'vendor',
|
||||
'examples'
|
||||
],
|
||||
|
||||
// A directory list that defines files that will be excluded
|
||||
// from static analysis, but whose class and method
|
||||
// information should be included.
|
||||
//
|
||||
// Generally, you'll want to include the directories for
|
||||
// third-party code (such as "vendor/") in this list.
|
||||
//
|
||||
// n.b.: If you'd like to parse but not analyze 3rd
|
||||
// party code, directories containing that code
|
||||
// should be added to the `directory_list` as
|
||||
// to `exclude_analysis_directory_list`.
|
||||
"exclude_analysis_directory_list" => [
|
||||
'vendor/'
|
||||
],
|
||||
|
||||
'skip_slow_php_options_warning' => true,
|
||||
|
||||
'exclude_file_regex' => '@^vendor/.*/(tests|Tests)/@',
|
||||
];
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
return PhpCsFixer\Config::create()
|
||||
->setRiskyAllowed(true)
|
||||
->setRules([
|
||||
'@Symfony' => true,
|
||||
'@Symfony:risky' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'binary_operator_spaces' => false,
|
||||
'concat_space' => ['spacing' => 'one'],
|
||||
'heredoc_to_nowdoc' => true,
|
||||
'method_argument_space' => true,
|
||||
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
|
||||
'no_php4_constructor' => true,
|
||||
'no_short_echo_tag' => true,
|
||||
'no_unreachable_default_argument_value' => true,
|
||||
'no_useless_else' => true,
|
||||
'no_useless_return' => true,
|
||||
'ordered_imports' => true,
|
||||
'php_unit_fqcn_annotation' => false,
|
||||
'phpdoc_add_missing_param_annotation' => true,
|
||||
'phpdoc_order' => true,
|
||||
'phpdoc_summary' => false,
|
||||
'semicolon_after_instruction' => true,
|
||||
'simplified_null_return' => true
|
||||
])
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
->in(__DIR__ . '/src')
|
||||
->in(__DIR__ . '/test')
|
||||
)
|
||||
;
|
||||
@@ -1,128 +0,0 @@
|
||||
build:
|
||||
environment:
|
||||
php: '5.6.0'
|
||||
|
||||
before_commands:
|
||||
- "composer install --prefer-source"
|
||||
|
||||
tools:
|
||||
external_code_coverage:
|
||||
enabled: true
|
||||
timeout: 300
|
||||
filter:
|
||||
excluded_paths:
|
||||
- 'docs/*'
|
||||
- 'examples/*'
|
||||
- 'extras/*'
|
||||
- 'test/*'
|
||||
- 'vendor/*'
|
||||
|
||||
php_code_coverage:
|
||||
enabled: false
|
||||
filter:
|
||||
excluded_paths:
|
||||
- 'docs/*'
|
||||
- 'examples/*'
|
||||
- 'extras/*'
|
||||
- 'test/*'
|
||||
- 'vendor/*'
|
||||
|
||||
php_code_sniffer:
|
||||
enabled: true
|
||||
config:
|
||||
standard: PSR2
|
||||
filter:
|
||||
excluded_paths:
|
||||
- 'docs/*'
|
||||
- 'examples/*'
|
||||
- 'extras/*'
|
||||
- 'test/*'
|
||||
- 'vendor/*'
|
||||
|
||||
# Copy/Paste Detector
|
||||
php_cpd:
|
||||
enabled: true
|
||||
excluded_dirs:
|
||||
- docs
|
||||
- examples
|
||||
- extras
|
||||
- test
|
||||
- vendor
|
||||
|
||||
# PHP CS Fixer (http://http://cs.sensiolabs.org/).
|
||||
php_cs_fixer:
|
||||
enabled: true
|
||||
config:
|
||||
level: psr2
|
||||
filter:
|
||||
excluded_paths:
|
||||
- 'docs/*'
|
||||
- 'examples/*'
|
||||
- 'extras/*'
|
||||
- 'test/*'
|
||||
- 'vendor/*'
|
||||
|
||||
# Analyzes the size and structure of a PHP project.
|
||||
php_loc:
|
||||
enabled: true
|
||||
excluded_dirs:
|
||||
- docs
|
||||
- examples
|
||||
- extras
|
||||
- test
|
||||
- vendor
|
||||
|
||||
# PHP Mess Detector (http://phpmd.org).
|
||||
php_mess_detector:
|
||||
enabled: true
|
||||
config:
|
||||
rulesets:
|
||||
- codesize
|
||||
- unusedcode
|
||||
- naming
|
||||
- design
|
||||
naming_rules:
|
||||
short_variable: { minimum: 2 }
|
||||
filter:
|
||||
excluded_paths:
|
||||
- 'docs/*'
|
||||
- 'examples/*'
|
||||
- 'extras/*'
|
||||
- 'test/*'
|
||||
- 'vendor/*'
|
||||
|
||||
# Analyzes the size and structure of a PHP project.
|
||||
php_pdepend:
|
||||
enabled: true
|
||||
excluded_dirs:
|
||||
- docs
|
||||
- examples
|
||||
- extras
|
||||
- test
|
||||
- vendor
|
||||
|
||||
# Runs Scrutinizer's PHP Analyzer Tool
|
||||
# https://scrutinizer-ci.com/docs/tools/php/php-analyzer/config_reference
|
||||
php_analyzer:
|
||||
enabled: true
|
||||
config:
|
||||
checkstyle:
|
||||
enabled: true
|
||||
naming:
|
||||
enabled: true
|
||||
property_name: ^[_a-zA-Z][a-zA-Z0-9_]*$ #Allow underscores & caps
|
||||
method_name: ^(?:[_a-zA-Z]|__)[a-zA-Z0-9_]*$ #Allow underscores & caps
|
||||
parameter_name: ^[a-z][a-zA-Z0-9_]*$ # Allow underscores
|
||||
local_variable: ^[a-zA-Z][a-zA-Z0-9_]*$ #Allow underscores & caps
|
||||
exception_name: ^[a-zA-Z][a-zA-Z0-9]*Exception$
|
||||
isser_method_name: ^(?:[_a-zA-Z]|__)[a-zA-Z0-9]*$ #Allow underscores & caps
|
||||
filter:
|
||||
excluded_paths:
|
||||
- 'docs/*'
|
||||
- 'examples/*'
|
||||
- 'extras/*'
|
||||
- 'test/*'
|
||||
- 'vendor/*'
|
||||
|
||||
# Security Advisory Checker
|
||||
sensiolabs_security_checker: true
|
||||
@@ -1,60 +0,0 @@
|
||||
language: php
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y -qq postfix
|
||||
|
||||
install:
|
||||
- REMOVE_PACKAGE="friendsofphp/php-cs-fixer"; if [ "$CS_CHECK" = 1 ]; then REMOVE_PACKAGE="phpunit/phpunit"; fi; composer remove --no-update --no-scripts --dev $REMOVE_PACKAGE
|
||||
- composer remove --no-update --no-scripts --dev phpdocumentor/phpdocumentor
|
||||
- composer install
|
||||
- if [ "$CODE_COVERAGE" != 1 ]; then phpenv config-rm xdebug.ini || true; fi
|
||||
|
||||
before_script:
|
||||
- sudo service postfix stop
|
||||
- smtp-sink -d "%d.%H.%M.%S" localhost:2500 1000 &
|
||||
- mkdir -p build/logs
|
||||
- cp test/testbootstrap-dist.php test/testbootstrap.php
|
||||
- chmod +x test/fakesendmail.sh
|
||||
- sudo mkdir -p /var/qmail/bin
|
||||
- sudo cp test/fakesendmail.sh /var/qmail/bin/sendmail
|
||||
- sudo cp test/fakesendmail.sh /usr/sbin/sendmail
|
||||
- |
|
||||
if [[ $TRAVIS_PHP_VERSION = "hhv"* ]]; then
|
||||
echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' >> /etc/hhvm/php.ini
|
||||
else
|
||||
echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > $(php --ini|grep -m 1 "ini files in:"|cut -d ":" -f 2)/sendmail.ini
|
||||
fi
|
||||
|
||||
script: ./vendor/bin/phpunit --configuration ./travis.phpunit.xml.dist
|
||||
|
||||
after_script:
|
||||
- if [ "$CODE_COVERAGE" = 1 ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
|
||||
- if [ "$CODE_COVERAGE" = 1 ]; then php ocular.phar code-coverage:upload --format=php-clover ../build/logs/clover.xml; fi
|
||||
|
||||
stages:
|
||||
- coding-standard
|
||||
- test
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: coding-standard
|
||||
before_install:
|
||||
before_script:
|
||||
script: ./vendor/bin/php-cs-fixer --diff --dry-run --verbose fix
|
||||
after_script:
|
||||
php: 5.5
|
||||
env: CS_CHECK=1
|
||||
- stage: test
|
||||
php: 5.5
|
||||
- php: 5.6
|
||||
- php: 7.0
|
||||
- php: 7.1
|
||||
env: CODE_COVERAGE=1
|
||||
- php: 7.2
|
||||
- php: hhvm
|
||||
dist: trusty
|
||||
@@ -1,502 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
@@ -1,217 +0,0 @@
|
||||

|
||||
|
||||
# PHPMailer - A full-featured email creation and transfer class for PHP
|
||||
|
||||
Build status: [](https://travis-ci.org/PHPMailer/PHPMailer)
|
||||
[](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/)
|
||||
[](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/)
|
||||
|
||||
[](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist.org/packages/phpmailer/phpmailer)
|
||||
|
||||
## Class Features
|
||||
- Probably the world's most popular code for sending email from PHP!
|
||||
- Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla! and many more
|
||||
- Integrated SMTP support - send without a local mail server
|
||||
- Send emails with multiple To, CC, BCC and Reply-to addresses
|
||||
- Multipart/alternative emails for mail clients that do not read HTML email
|
||||
- Add attachments, including inline
|
||||
- Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings
|
||||
- SMTP authentication with LOGIN, PLAIN, CRAM-MD5 and XOAUTH2 mechanisms over SSL and SMTP+STARTTLS transports
|
||||
- Validates email addresses automatically
|
||||
- Protect against header injection attacks
|
||||
- Error messages in 47 languages!
|
||||
- DKIM and S/MIME signing support
|
||||
- Compatible with PHP 5.5 and later
|
||||
- Namespaced to prevent name clashes
|
||||
- Much more!
|
||||
|
||||
## Why you might need it
|
||||
Many PHP developers utilize email in their code. The only PHP function that supports this is the `mail()` function. However, it does not provide any assistance for making use of popular features such as HTML-based emails and attachments.
|
||||
|
||||
Formatting email correctly is surprisingly difficult. There are myriad overlapping RFCs, requiring tight adherence to horribly complicated formatting and encoding rules - the vast majority of code that you'll find online that uses the `mail()` function directly is just plain wrong!
|
||||
*Please* don't be tempted to do it yourself - if you don't use PHPMailer, there are many other excellent libraries that you should look at before rolling your own - try [SwiftMailer](https://swiftmailer.symfony.com/), [Zend/Mail](https://zendframework.github.io/zend-mail/), [eZcomponents](https://github.com/zetacomponents/Mail) etc.
|
||||
|
||||
The PHP `mail()` function usually sends via a local mail server, typically fronted by a `sendmail` binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server.
|
||||
|
||||
## License
|
||||
This software is distributed under the [LGPL 2.1](http://www.gnu.org/licenses/lgpl-2.1.html) license. Please read LICENSE for information on the
|
||||
software availability and distribution.
|
||||
|
||||
## Installation & loading
|
||||
PHPMailer is available on [Packagist](https://packagist.org/packages/phpmailer/phpmailer) (using semantic versioning), and installation via composer is the recommended way to install PHPMailer. Just add this line to your `composer.json` file:
|
||||
|
||||
```json
|
||||
"phpmailer/phpmailer": "~6.0"
|
||||
```
|
||||
|
||||
or run
|
||||
|
||||
```sh
|
||||
composer require phpmailer/phpmailer
|
||||
```
|
||||
|
||||
Note that the `vendor` folder and the `vendor/autoload.php` script are generated by composer; they are not part of PHPMailer.
|
||||
|
||||
If you want to use the Gmail XOAUTH2 authentication class, you will also need to add a dependency on the `league/oauth2-client` package in your `composer.json`.
|
||||
|
||||
Alternatively, if you're not using composer, copy the contents of the PHPMailer folder into one of the `include_path` directories specified in your PHP configuration and load each class file manually:
|
||||
|
||||
```php
|
||||
<?php
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
require 'path/to/PHPMailer/src/Exception.php';
|
||||
require 'path/to/PHPMailer/src/PHPMailer.php';
|
||||
require 'path/to/PHPMailer/src/SMTP.php';
|
||||
```
|
||||
|
||||
If you're not using the `SMTP` class explicitly (you're probably not), you don't need a `use` line for the SMTP class.
|
||||
|
||||
If you don't speak git or just want a tarball, click the 'zip' button on the right of the project page in GitHub, though note that docs and examples are not included in the tarball.
|
||||
|
||||
## Legacy versions
|
||||
PHPMailer 5.2 (which is compatible with PHP 5.0 - 7.0) is no longer being supported for feature updates, and will only be receiving security updates from now on. You will find the latest version of 5.2 in the [5.2-stable branch](https://github.com/PHPMailer/PHPMailer/tree/5.2-stable), and future versions of 5.2 will be tagged with 5.2.x version numbers, so existing composer configs should remain working. If you're using PHP 5.5 or later, we recommend you make the necessary changes to switch to the 6.0 release.
|
||||
|
||||
## Upgrading from 5.2
|
||||
The biggest changes are that source files are now in the `src/` folder, and PHPMailer now declares the namespace `PHPMailer\PHPMailer`. This has several important effects – [read the upgrade guide](https://github.com/PHPMailer/PHPMailer/tree/master/UPGRADING.md) for more details.
|
||||
|
||||
### Minimal installation
|
||||
While installing the entire package manually or with composer is simple, convenient and reliable, you may want to include only vital files in your project. At the very least you will need [src/PHPMailer.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/PHPMailer.php). If you're using SMTP, you'll need [src/SMTP.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/SMTP.php), and if you're using POP-before SMTP, you'll need [src/POP3.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/POP3.php). You can skip the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder if you're not showing errors to users and can make do with English-only errors. If you're using XOAUTH2 you will need [src/OAuth.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/OAuth.php) as well as the composer dependencies for the services you wish to authenticate with. Really, it's much easier to use composer!
|
||||
|
||||
## A Simple Example
|
||||
|
||||
```php
|
||||
<?php
|
||||
// Import PHPMailer classes into the global namespace
|
||||
// These must be at the top of your script, not inside a function
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
//Load composer's autoloader
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$mail = new PHPMailer(true); // Passing `true` enables exceptions
|
||||
try {
|
||||
//Server settings
|
||||
$mail->SMTPDebug = 2; // Enable verbose debug output
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = 'user@example.com'; // SMTP username
|
||||
$mail->Password = 'secret'; // SMTP password
|
||||
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
|
||||
$mail->Port = 587; // TCP port to connect to
|
||||
|
||||
//Recipients
|
||||
$mail->setFrom('from@example.com', 'Mailer');
|
||||
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
|
||||
$mail->addAddress('ellen@example.com'); // Name is optional
|
||||
$mail->addReplyTo('info@example.com', 'Information');
|
||||
$mail->addCC('cc@example.com');
|
||||
$mail->addBCC('bcc@example.com');
|
||||
|
||||
//Attachments
|
||||
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
|
||||
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
|
||||
|
||||
//Content
|
||||
$mail->isHTML(true); // Set email format to HTML
|
||||
$mail->Subject = 'Here is the subject';
|
||||
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
|
||||
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||
|
||||
$mail->send();
|
||||
echo 'Message has been sent';
|
||||
} catch (Exception $e) {
|
||||
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
|
||||
}
|
||||
```
|
||||
|
||||
You'll find plenty more to play with in the [examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) folder.
|
||||
|
||||
That's it. You should now be ready to use PHPMailer!
|
||||
|
||||
## Localization
|
||||
PHPMailer defaults to English, but in the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder you'll find numerous (47 at the time of writing!) translations for PHPMailer error messages that you may encounter. Their filenames contain [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) language code for the translations, for example `fr` for French. To specify a language, you need to tell PHPMailer which one to use, like this:
|
||||
|
||||
```php
|
||||
// To load the French version
|
||||
$mail->setLanguage('fr', '/optional/path/to/language/directory/');
|
||||
```
|
||||
|
||||
We welcome corrections and new languages - if you're looking for corrections to do, run the [PHPMailerLangTest.php](https://github.com/PHPMailer/PHPMailer/tree/master/test/PHPMailerLangTest.php) script in the tests folder and it will show any missing translations.
|
||||
|
||||
## Documentation
|
||||
Start reading at the [GitHub wiki](https://github.com/PHPMailer/PHPMailer/wiki). If you're having trouble, this should be the first place you look as it's the most frequently updated.
|
||||
|
||||
Examples of how to use PHPMailer for common scenarios can be found in the [examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) folder. If you're looking for a good starting point, we recommend you start with [the Gmail example](https://github.com/PHPMailer/PHPMailer/tree/master/examples/gmail.phps).
|
||||
|
||||
Note that in order to reduce PHPMailer's deployed code footprint, the examples are no longer included if you load PHPMailer via composer or via [GitHub's zip file download](https://github.com/PHPMailer/PHPMailer/archive/master.zip), so you'll need to either clone the git repository or use the above links to get to the examples directly.
|
||||
|
||||
Complete generated API documentation is [available online](http://phpmailer.github.io/PHPMailer/).
|
||||
|
||||
You can generate complete API-level documentation by running `phpdoc` in the top-level folder, and documentation will appear in teh `docs` folder, though you'll need to have [PHPDocumentor](http://www.phpdoc.org) installed. You may find [the unit tests](https://github.com/PHPMailer/PHPMailer/tree/master/test/phpmailerTest.php) a good source of how to do various operations such as encryption.
|
||||
|
||||
If the documentation doesn't cover what you need, search the [many questions on Stack Overflow](http://stackoverflow.com/questions/tagged/phpmailer), and before you ask a question about "SMTP Error: Could not connect to SMTP host.", [read the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting).
|
||||
|
||||
## Tests
|
||||
There is a PHPUnit test script in the [test](https://github.com/PHPMailer/PHPMailer/tree/master/test/) folder. PHPMailer uses PHPUnit 4.8 - we would use 5.x but we need to run on PHP 5.5.
|
||||
|
||||
Build status: [](https://travis-ci.org/PHPMailer/PHPMailer)
|
||||
|
||||
If this isn't passing, is there something you can do to help?
|
||||
|
||||
## Security
|
||||
Please disclose any vulnerabilities found responsibly - report any security problems found to the maintainers privately.
|
||||
|
||||
PHPMailer versions prior to 5.2.22 (released January 9th 2017) have a local file disclosure vulnerability, [CVE-2017-5223](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2017-5223). If content passed into `msgHTML()` is sourced from unfiltered user input, relative paths can map to absolute local file paths and added as attachments. Also note that `addAttachment` (just like `file_get_contents`, `passthru`, `unlink`, etc) should not be passed user-sourced params either! Reported by Yongxiang Li of Asiasecurity.
|
||||
|
||||
PHPMailer versions prior to 5.2.20 (released December 28th 2016) are vulnerable to [CVE-2016-10045](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2016-10045) a remote code execution vulnerability, responsibly reported by [Dawid Golunski](https://legalhackers.com/advisories/PHPMailer-Exploit-Remote-Code-Exec-CVE-2016-10045-Vuln-Patch-Bypass.html), and patched by Paul Buonopane (@Zenexer).
|
||||
|
||||
PHPMailer versions prior to 5.2.18 (released December 2016) are vulnerable to [CVE-2016-10033](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2016-10033) a critical remote code execution vulnerability, responsibly reported by [Dawid Golunski](http://legalhackers.com/advisories/PHPMailer-Exploit-Remote-Code-Exec-CVE-2016-10033-Vuln.html).
|
||||
|
||||
See [SECURITY](https://github.com/PHPMailer/PHPMailer/tree/master/SECURITY.md) for more detail on security issues.
|
||||
|
||||
## Contributing
|
||||
Please submit bug reports, suggestions and pull requests to the [GitHub issue tracker](https://github.com/PHPMailer/PHPMailer/issues).
|
||||
|
||||
We're particularly interested in fixing edge-cases, expanding test coverage and updating translations.
|
||||
|
||||
If you found a mistake in the docs, or want to add something, go ahead and amend the wiki - anyone can edit it.
|
||||
|
||||
If you have git clones from prior to the move to the PHPMailer GitHub organisation, you'll need to update any remote URLs referencing the old GitHub location with a command like this from within your clone:
|
||||
|
||||
```sh
|
||||
git remote set-url upstream https://github.com/PHPMailer/PHPMailer.git
|
||||
```
|
||||
|
||||
Please *don't* use the SourceForge or Google Code projects any more; they are obsolete and no longer maintained.
|
||||
|
||||
## Sponsorship
|
||||
Development time and resources for PHPMailer are provided by [Smartmessages.net](https://info.smartmessages.net/), a powerful email marketing system.
|
||||
|
||||
<a href="https://info.smartmessages.net/"><img src="https://www.smartmessages.net/img/smartmessages-logo.svg" width="250" height="28" alt="Smartmessages email marketing"></a>
|
||||
|
||||
Other contributions are gladly received, whether in beer 🍺, T-shirts 👕, Amazon wishlist raids, or cold, hard cash 💰. If you'd like to donate to say "thank you" to maintainers or contributors, please contact them through individual profile pages via [the contributors page](https://github.com/PHPMailer/PHPMailer/graphs/contributors).
|
||||
|
||||
## Changelog
|
||||
See [changelog](changelog.md).
|
||||
|
||||
## History
|
||||
- PHPMailer was originally written in 2001 by Brent R. Matzelle as a [SourceForge project](http://sourceforge.net/projects/phpmailer/).
|
||||
- Marcus Bointon (coolbru on SF) and Andy Prevost (codeworxtech) took over the project in 2004.
|
||||
- Became an Apache incubator project on Google Code in 2010, managed by Jim Jagielski.
|
||||
- Marcus created his fork on [GitHub](https://github.com/Synchro/PHPMailer) in 2008.
|
||||
- Jim and Marcus decide to join forces and use GitHub as the canonical and official repo for PHPMailer in 2013.
|
||||
- PHPMailer moves to the [PHPMailer organisation](https://github.com/PHPMailer) on GitHub in 2013.
|
||||
|
||||
### What's changed since moving from SourceForge?
|
||||
- Official successor to the SourceForge and Google Code projects.
|
||||
- Test suite.
|
||||
- Continuous integration with Travis-CI.
|
||||
- Composer support.
|
||||
- Public development.
|
||||
- Additional languages and language strings.
|
||||
- CRAM-MD5 authentication support.
|
||||
- Preserves full repo history of authors, commits and branches from the original SourceForge project.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user