Add new directory structure. Tags will contain current and past releases, and stable will contain any bug fixes to the current stable release so users won't have to get the potentially broken trunk build to fix a screwup in stable.
Trunk updated to 0.9 git-svn-id: http://kusabax.cultnet.net/svn/repo/stable@176 73d99b7e-4f53-4972-b7b7-2ecd3c4d89ee
This commit is contained in:
commit
88bacfad9c
316 files changed
+79806
No files matched your search
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_assign_compile(Dwoo_Compiler $compiler, $value, $var)
|
||||
{
|
||||
return '$this->assignInScope('.$value.', '.$var.')';
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_capitalize(Dwoo $dwoo, $value, $numwords=false)
|
||||
{
|
||||
if ($numwords || preg_match('#^[^0-9]+$#',$value))
|
||||
{
|
||||
if ($dwoo->getCharset() === 'iso-8859-1') {
|
||||
return ucwords((string) $value);
|
||||
}
|
||||
return mb_convert_case((string) $value,MB_CASE_TITLE, $dwoo->getCharset());
|
||||
} else {
|
||||
$bits = explode(' ', (string) $value);
|
||||
$out = '';
|
||||
while (list(,$v) = each($bits)) {
|
||||
if (preg_match('#^[^0-9]+$#', $v)) {
|
||||
$out .= ' '.mb_convert_case($v, MB_CASE_TITLE, $dwoo->getCharset());
|
||||
} else {
|
||||
$out .= ' '.$v;
|
||||
}
|
||||
}
|
||||
|
||||
return substr($out, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_cat_compile(Dwoo_Compiler $compiler, $value, array $rest)
|
||||
{
|
||||
return '('.$value.').('.implode(').(', $rest).')';
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_count_characters_compile(Dwoo_Compiler $compiler, $value, $count_spaces=false)
|
||||
{
|
||||
if ($count_spaces==='false') {
|
||||
return 'preg_match_all(\'#[^\s\pZ]#u\', '.$value.', $tmp)';
|
||||
} else {
|
||||
return 'mb_strlen('.$value.', $this->charset)';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_count_paragraphs_compile(Dwoo_Compiler $compiler, $value)
|
||||
{
|
||||
return '(preg_match_all(\'#[\r\n]+#\', '.$value.', $tmp)+1)';
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_count_sentences_compile(Dwoo_Compiler $compiler, $value)
|
||||
{
|
||||
return "preg_match_all('#[\w\pL]\.(?![\w\pL])#u', $value, \$tmp)";
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_count_words_compile(Dwoo_Compiler $compiler, $value)
|
||||
{
|
||||
return 'preg_match_all(strcasecmp($this->charset, \'utf-8\')===0 ? \'#[\w\pL]+#u\' : \'#\w+#\', '.$value.', $tmp)';
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
class Dwoo_Plugin_counter extends Dwoo_Plugin
|
||||
{
|
||||
protected $counters = array();
|
||||
|
||||
public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null)
|
||||
{
|
||||
// init counter
|
||||
if (!isset($this->counters[$name])) {
|
||||
$this->counters[$name] = array
|
||||
(
|
||||
'count' => $start===null ? 1 : (int) $start,
|
||||
'skip' => $skip===null ? 1 : (int) $skip,
|
||||
'print' => $print===null ? true : (bool) $print,
|
||||
'assign' => $assign===null ? null : (string) $assign,
|
||||
'direction' => strtolower($direction)==='down' ? -1 : 1,
|
||||
);
|
||||
}
|
||||
// increment
|
||||
else
|
||||
{
|
||||
// override setting if present
|
||||
if ($skip !== null) {
|
||||
$this->counters[$name]['skip'] = (int) $skip;
|
||||
}
|
||||
|
||||
if ($direction !== null) {
|
||||
$this->counters[$name]['direction'] = strtolower($direction)==='down' ? -1 : 1;
|
||||
}
|
||||
|
||||
if ($print !== null) {
|
||||
$this->counters[$name]['print'] = (bool) $print;
|
||||
}
|
||||
|
||||
if ($assign !== null) {
|
||||
$this->counters[$name]['assign'] = (string) $assign;
|
||||
}
|
||||
|
||||
if ($start !== null) {
|
||||
$this->counters[$name]['count'] = (int) $start;
|
||||
} else {
|
||||
$this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']);
|
||||
}
|
||||
}
|
||||
|
||||
$out = $this->counters[$name]['count'];
|
||||
|
||||
if ($this->counters[$name]['assign'] !== null) {
|
||||
$this->dwoo->assignInScope($out, $this->counters[$name]['assign']);
|
||||
} elseif ($this->counters[$name]['print'] === true) {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.1
|
||||
* @date 2008-12-24
|
||||
* @package Dwoo
|
||||
*/
|
||||
class Dwoo_Plugin_cycle extends Dwoo_Plugin
|
||||
{
|
||||
protected $cycles = array();
|
||||
|
||||
public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false)
|
||||
{
|
||||
if ($values !== null) {
|
||||
if (is_string($values)) {
|
||||
$values = explode($delimiter, $values);
|
||||
}
|
||||
|
||||
if (!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values) {
|
||||
$this->cycles[$name]['index'] = 0;
|
||||
}
|
||||
|
||||
$this->cycles[$name]['values'] = array_values($values);
|
||||
} elseif (isset($this->cycles[$name])) {
|
||||
$values = $this->cycles[$name]['values'];
|
||||
}
|
||||
|
||||
if ($reset) {
|
||||
$this->cycles[$name]['index'] = 0;
|
||||
}
|
||||
|
||||
if ($print) {
|
||||
$out = $values[$this->cycles[$name]['index']];
|
||||
} else {
|
||||
$out = null;
|
||||
}
|
||||
|
||||
if ($advance) {
|
||||
if ($this->cycles[$name]['index'] >= count($values)-1) {
|
||||
$this->cycles[$name]['index'] = 0;
|
||||
} else {
|
||||
$this->cycles[$name]['index']++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($assign !== null) {
|
||||
$this->dwoo->assignInScope($out, $assign);
|
||||
} else {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.1
|
||||
* @date 2008-12-24
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_date_format(Dwoo $dwoo, $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);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_default_compile(Dwoo_Compiler $compiler, $value, $default='')
|
||||
{
|
||||
return '(($tmp = '.$value.')===null||$tmp===\'\' ? '.$default.' : $tmp)';
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
class Dwoo_Plugin_dump extends Dwoo_Plugin
|
||||
{
|
||||
protected $outputObjects;
|
||||
protected $outputMethods;
|
||||
|
||||
public function process($var = '$', $show_methods = false)
|
||||
{
|
||||
$this->outputMethods = $show_methods;
|
||||
if ($var === '$') {
|
||||
$var = $this->dwoo->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->dwoo->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>';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 />';
|
||||
}
|
||||
}
|
||||
|
||||
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>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_eol_compile(Dwoo_Compiler $compiler)
|
||||
{
|
||||
return 'PHP_EOL';
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_escape(Dwoo $dwoo, $value='', $format='html', $charset=null)
|
||||
{
|
||||
if ($charset === null) {
|
||||
$charset = $dwoo->getCharset();
|
||||
}
|
||||
|
||||
switch($format)
|
||||
{
|
||||
|
||||
case 'html':
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, $charset);
|
||||
case 'htmlall':
|
||||
return htmlentities((string) $value, ENT_QUOTES, $charset);
|
||||
case 'url':
|
||||
return rawurlencode((string) $value);
|
||||
case 'urlpathinfo':
|
||||
return str_replace('%2F', '/', rawurlencode((string) $value));
|
||||
case 'quotes':
|
||||
return preg_replace("#(?<!\\\\)'#", "\\'", (string) $value);
|
||||
case 'hex':
|
||||
$out = '';
|
||||
$cnt = strlen((string) $value);
|
||||
for ($i=0; $i < $cnt; $i++) {
|
||||
$out .= '%' . bin2hex((string) $value[$i]);
|
||||
}
|
||||
return $out;
|
||||
case 'hexentity':
|
||||
$out = '';
|
||||
$cnt = strlen((string) $value);
|
||||
for ($i=0; $i < $cnt; $i++)
|
||||
$out .= '&#x' . bin2hex((string) $value[$i]) . ';';
|
||||
return $out;
|
||||
case 'javascript':
|
||||
return strtr((string) $value, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
|
||||
case 'mail':
|
||||
return str_replace(array('@', '.'), array(' (AT) ', ' (DOT) '), (string) $value);
|
||||
default:
|
||||
return $dwoo->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript or mail, "'.$format.'" given.', E_USER_WARNING);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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_String 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_eval(Dwoo $dwoo, $var, $assign = null)
|
||||
{
|
||||
if ($var == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$tpl = new Dwoo_Template_String($var);
|
||||
$out = $dwoo->get($tpl, $dwoo->readVar('_parent'));
|
||||
|
||||
if ($assign !== null) {
|
||||
$dwoo->assignInScope($out, $assign);
|
||||
} else {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
class Dwoo_Plugin_extends extends Dwoo_Plugin implements Dwoo_ICompilable
|
||||
{
|
||||
protected static $childSource;
|
||||
protected static $l;
|
||||
protected static $r;
|
||||
protected static $lastReplacement;
|
||||
|
||||
public static function compile(Dwoo_Compiler $compiler, $file)
|
||||
{
|
||||
list($l, $r) = $compiler->getDelimiters();
|
||||
self::$l = preg_quote($l,'/');
|
||||
self::$r = preg_quote($r,'/');
|
||||
|
||||
if ($compiler->getLooseOpeningHandling()) {
|
||||
self::$l .= '\s*';
|
||||
self::$r = '\s*'.self::$r;
|
||||
}
|
||||
$inheritanceTree = array(array('source'=>$compiler->getTemplateSource()));
|
||||
$curPath = dirname($compiler->getDwoo()->getTemplate()->getResourceIdentifier()) . DIRECTORY_SEPARATOR;
|
||||
$curTpl = $compiler->getDwoo()->getTemplate();
|
||||
|
||||
while (!empty($file)) {
|
||||
if ($file === '""' || $file === "''" || (substr($file, 0, 1) !== '"' && substr($file, 0, 1) !== '\'')) {
|
||||
throw new Dwoo_Compilation_Exception($compiler, 'Extends : The file name must be a non-empty string');
|
||||
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 = $curTpl->getResourceName();
|
||||
$identifier = substr($file, 1, -1);
|
||||
}
|
||||
|
||||
try {
|
||||
$parent = $compiler->getDwoo()->templateFactory($resource, $identifier, null, null, null, $curTpl);
|
||||
} catch (Dwoo_Security_Exception $e) {
|
||||
throw new Dwoo_Compilation_Exception($compiler, 'Extends : Security restriction : '.$e->getMessage());
|
||||
} catch (Dwoo_Exception $e) {
|
||||
throw new Dwoo_Compilation_Exception($compiler, 'Extends : '.$e->getMessage());
|
||||
}
|
||||
|
||||
if ($parent === null) {
|
||||
throw new Dwoo_Compilation_Exception($compiler, 'Extends : Resource "'.$resource.':'.$identifier.'" not found.');
|
||||
} elseif ($parent === false) {
|
||||
throw new Dwoo_Compilation_Exception($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 Dwoo_Compilation_Exception($compiler, 'Extends : Recursive template inheritance detected');
|
||||
}
|
||||
|
||||
$inheritanceTree[] = $newParent;
|
||||
|
||||
if (preg_match('/^'.self::$l.'extends\s+(?:file=)?\s*(\S+?|(["\']).+?\2)'.self::$r.'/i', $parent->getSource(), $match)) {
|
||||
$curPath = dirname($identifier) . DIRECTORY_SEPARATOR;
|
||||
$file = (substr($match[1], 0, 1) !== '"' && substr($match[1], 0, 1) !== '"') ? '"'.str_replace('"', '\\"', $match[1]).'"' : $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::$l.'block (["\']?)(.+?)\1'.self::$r.'(?:\r?\n?)(.*?)(?:\r?\n?)'.self::$l.'\/block'.self::$r.'/is', array('Dwoo_Plugin_extends', 'replaceBlock'), $newSource);
|
||||
|
||||
$newSource = $l.'do extendsCheck("'.$parent['resource'].':'.$parent['identifier'].'" "'.str_replace('"', '\\"', $parent['uid']).'")'.$r.$newSource;
|
||||
|
||||
if (self::$lastReplacement) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$compiler->setTemplateSource($newSource);
|
||||
$compiler->setPointer(0);
|
||||
}
|
||||
|
||||
protected static function replaceBlock(array $matches)
|
||||
{
|
||||
if (preg_match('/'.self::$l.'block (["\']?)'.preg_quote($matches[2],'/').'\1'.self::$r.'(?:\r?\n?)(.*?)(?:\r?\n?)'.self::$l.'\/block'.self::$r.'/is', self::$childSource, $override)) {
|
||||
$l = stripslashes(self::$l);
|
||||
$r = stripslashes(self::$r);
|
||||
|
||||
if (self::$lastReplacement) {
|
||||
return preg_replace('/'.self::$l.'\$dwoo\.parent'.self::$r.'/is', $matches[3], $override[2]);
|
||||
} else {
|
||||
return $l.'block '.$matches[1].$matches[2].$matches[1].$r.preg_replace('/'.self::$l.'\$dwoo\.parent'.self::$r.'/is', $matches[3], $override[2]).$l.'/block'.$r;
|
||||
}
|
||||
} else {
|
||||
if (self::$lastReplacement) {
|
||||
return $matches[3];
|
||||
} else {
|
||||
return $matches[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_extendsCheck_compile(Dwoo_Compiler $compiler, $file, $uid)
|
||||
{
|
||||
preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m);
|
||||
$resource = $m[1];
|
||||
$identifier = $m[2];
|
||||
|
||||
return '// checking for modification in '.$resource.':'.$identifier.'
|
||||
try {
|
||||
$tpl = $this->templateFactory("'.$resource.'", "'.$identifier.'");
|
||||
} catch (Dwoo_Exception $e) {
|
||||
$this->triggerError(\'Extends : Resource <em>'.$resource.'</em> was not added to Dwoo, can not include <em>'.$identifier.'</em>\', E_USER_WARNING);
|
||||
}
|
||||
if ($tpl === null)
|
||||
$this->triggerError(\'Extends : Resource "'.$resource.':'.$identifier.'" was not found.\', E_USER_WARNING);
|
||||
elseif ($tpl === false)
|
||||
$this->triggerError(\'Extends : Resource "'.$resource.'" does not support extends.\', E_USER_WARNING);
|
||||
if ($tpl->getUid() != "'.substr($uid, 1, -1).'") { ob_end_clean(); return false; }';
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_fetch(Dwoo $dwoo, $file, $assign = null)
|
||||
{
|
||||
if ($file === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($policy = $dwoo->getSecurityPolicy()) {
|
||||
while (true) {
|
||||
if (preg_match('{^([a-z]+?)://}i', $file)) {
|
||||
return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
|
||||
}
|
||||
|
||||
$file = realpath($file);
|
||||
$dirs = $policy->getAllowedDirectories();
|
||||
foreach ($dirs as $dir=>$dummy) {
|
||||
if (strpos($file, $dir) === 0) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
return $dwoo->triggerError('The security policy prevents you to read <em>'.$file.'</em>', E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
$file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file);
|
||||
|
||||
$out = file_get_contents($file);
|
||||
|
||||
if ($assign !== null) {
|
||||
$dwoo->assignInScope($out, $assign);
|
||||
} else {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_include(Dwoo $dwoo, $file, $cache_time = null, $cache_id = null, $compile_id = null, $data = '_root', $assign = null, array $rest = array())
|
||||
{
|
||||
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 = $dwoo->getTemplate()->getResourceName();
|
||||
$identifier = $file;
|
||||
}
|
||||
|
||||
try {
|
||||
$include = $dwoo->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id);
|
||||
} catch (Dwoo_Security_Exception $e) {
|
||||
return $dwoo->triggerError('Include : Security restriction : '.$e->getMessage(), E_USER_WARNING);
|
||||
} catch (Dwoo_Exception $e) {
|
||||
return $dwoo->triggerError('Include : '.$e->getMessage(), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if ($include === null) {
|
||||
return $dwoo->triggerError('Include : Resource "'.$resource.':'.$identifier.'" not found.', E_USER_WARNING);
|
||||
} elseif ($include === false) {
|
||||
return $dwoo->triggerError('Include : Resource "'.$resource.'" does not support includes.', E_USER_WARNING);
|
||||
}
|
||||
|
||||
if ($dwoo->isArray($data)) {
|
||||
$vars = $data;
|
||||
} elseif ($dwoo->isArray($cache_time)) {
|
||||
$vars = $cache_time;
|
||||
} else {
|
||||
$vars = $dwoo->readVar($data);
|
||||
}
|
||||
|
||||
if (count($rest)) {
|
||||
$vars = $rest + $vars;
|
||||
}
|
||||
|
||||
$out = $dwoo->get($include, $vars);
|
||||
|
||||
if ($assign !== null) {
|
||||
$dwoo->assignInScope($out, $assign);
|
||||
} else {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_indent_compile(Dwoo_Compiler $compiler, $value, $by=4, $char=' ')
|
||||
{
|
||||
return "preg_replace('#^#m', '".str_repeat(substr($char, 1, -1), trim($by, '"\''))."', $value)";
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_isset_compile(Dwoo_Compiler $compiler, $var)
|
||||
{
|
||||
return '('.$var.' !== null)';
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_lower_compile(Dwoo_Compiler $compiler, $value)
|
||||
{
|
||||
return 'mb_strtolower((string) '.$value.', $this->charset)';
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_mailto(Dwoo $dwoo, $address, $text=null, $subject=null, $encode=null, $cc=null, $bcc=null, $newsgroups=null, $followupto=null, $extra=null)
|
||||
{
|
||||
if (empty($address)) {
|
||||
return '';
|
||||
}
|
||||
if (empty($text)) {
|
||||
$text = $address;
|
||||
}
|
||||
|
||||
// build address string
|
||||
$address .= '?';
|
||||
|
||||
if (!empty($subject)) {
|
||||
$address .= 'subject='.rawurlencode($subject).'&';
|
||||
}
|
||||
if (!empty($cc)) {
|
||||
$address .= 'cc='.rawurlencode($cc).'&';
|
||||
}
|
||||
if (!empty($bcc)) {
|
||||
$address .= 'bcc='.rawurlencode($bcc).'&';
|
||||
}
|
||||
if (!empty($newsgroup)) {
|
||||
$address .= 'newsgroups='.rawurlencode($newsgroups).'&';
|
||||
}
|
||||
if (!empty($followupto)) {
|
||||
$address .= 'followupto='.rawurlencode($followupto).'&';
|
||||
}
|
||||
|
||||
$address = rtrim($address, '?&');
|
||||
|
||||
// output
|
||||
switch($encode)
|
||||
{
|
||||
|
||||
case 'none':
|
||||
case null:
|
||||
return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
|
||||
|
||||
case 'js':
|
||||
case 'javascript':
|
||||
$str = 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');';
|
||||
$len = strlen($str);
|
||||
|
||||
$out = '';
|
||||
for ($i=0; $i<$len; $i++) {
|
||||
$out .= '%'.bin2hex($str[$i]);
|
||||
}
|
||||
return '<script type="text/javascript">eval(unescape(\''.$out.'\'));</script>';
|
||||
|
||||
break;
|
||||
case 'javascript_charcode':
|
||||
case 'js_charcode':
|
||||
case 'jscharcode':
|
||||
case 'jschar':
|
||||
$str = '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
|
||||
$len = strlen($str);
|
||||
|
||||
$out = '<script type="text/javascript">'."\n<!--\ndocument.write(String.fromCharCode(";
|
||||
for ($i=0; $i<$len; $i++) {
|
||||
$out .= ord($str[$i]).',';
|
||||
}
|
||||
return rtrim($out, ',') . "));\n-->\n</script>\n";
|
||||
|
||||
break;
|
||||
|
||||
case 'hex':
|
||||
if (strpos($address, '?') !== false) {
|
||||
return $dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.', E_USER_WARNING);
|
||||
}
|
||||
|
||||
$out = '<a href="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:
|
||||
return $dwoo->triggerError('Mailto: <em>encode</em> argument is invalid, it must be one of : <em>none (= no value), js, js_charcode or hex</em>', E_USER_WARNING);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_math_compile(Dwoo_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 Dwoo_Compilation_Exception($compiler, 'Math : Syntax error or variable undefined in equation '.$equationSrc.' at '.$substr);
|
||||
return;
|
||||
} else {
|
||||
// nothing special, advance
|
||||
$ptr++;
|
||||
}
|
||||
}
|
||||
if ($format !== '\'\'') {
|
||||
$out = 'sprintf('.$format.', '.$out.')';
|
||||
}
|
||||
if ($assign !== '\'\'') {
|
||||
return '($this->assignInScope('.$out.', '.$assign.'))';
|
||||
}
|
||||
return '('.$out.')';
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_nl2br_compile(Dwoo_Compiler $compiler, $value)
|
||||
{
|
||||
return 'nl2br((string) '.$value.')';
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_regex_replace(Dwoo $dwoo, $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);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_replace_compile(Dwoo_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.')';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_reverse(Dwoo $dwoo, $value, $preserve_keys=false)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return array_reverse($value, $preserve_keys);
|
||||
} elseif(($charset=$dwoo->getCharset()) === 'iso-8859-1') {
|
||||
return strrev((string) $value);
|
||||
} else {
|
||||
$strlen = mb_strlen($value);
|
||||
$out = '';
|
||||
while ($strlen--) {
|
||||
$out .= mb_substr($value, $strlen, 1, $charset);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_safe_compile(Dwoo_Compiler $compiler, $var)
|
||||
{
|
||||
return preg_replace('#\(is_string\(\$tmp=(.+?)\) \? htmlspecialchars\(\$tmp, ENT_QUOTES, \$this->charset\) : \$tmp\)#', '$1', $var);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_spacify_compile(Dwoo_Compiler $compiler, $value, $space_char=' ')
|
||||
{
|
||||
return 'implode('.$space_char.', str_split('.$value.', 1))';
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_string_format_compile(Dwoo_Compiler $compiler, $value, $format)
|
||||
{
|
||||
return 'sprintf('.$format.','.$value.')';
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Removes all html tags
|
||||
* <pre>
|
||||
* * value : the string to process
|
||||
* * addspace : if true, a space is added in place of every removed 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_strip_tags_compile(Dwoo_Compiler $compiler, $value, $addspace=true)
|
||||
{
|
||||
if ($addspace==='true') {
|
||||
return "preg_replace('#<[^>]*>#', ' ', $value)";
|
||||
} else {
|
||||
return "strip_tags($value)";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest)
|
||||
{
|
||||
// load if plugin
|
||||
if (!class_exists('Dwoo_Plugin_if', false)) {
|
||||
try {
|
||||
$compiler->getDwoo()->getLoader()->loadPlugin('if');
|
||||
} catch (Exception $e) {
|
||||
throw new Dwoo_Compilation_Exception($compiler, 'Tif: the if plugin is required to use Tif');
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// 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) || empty($trueResult) || empty($falseResult)) {
|
||||
throw new Dwoo_Compilation_Exception($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>');
|
||||
}
|
||||
|
||||
// parse condition
|
||||
$condition = Dwoo_Plugin_if::replaceKeywords($rest, $compiler);
|
||||
|
||||
return '(('.implode(' ', $condition).') ? '.($trueResult===true ? implode(' ', $condition) : $trueResult).' : '.$falseResult.')';
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_truncate(Dwoo $dwoo, $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));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_upper_compile(Dwoo_Compiler $compiler, $value)
|
||||
{
|
||||
return 'mb_strtoupper((string) '.$value.', $this->charset)';
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_whitespace_compile(Dwoo_Compiler $compiler, $value, $with=' ')
|
||||
{
|
||||
return "preg_replace('#\s+#'.(strcasecmp(\$this->charset, 'utf-8')===0?'u':''), $with, $value)";
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @copyright Copyright (c) 2008, Jordi Boggiano
|
||||
* @license http://dwoo.org/LICENSE Modified BSD License
|
||||
* @link http://dwoo.org/
|
||||
* @version 1.0.0
|
||||
* @date 2008-10-23
|
||||
* @package Dwoo
|
||||
*/
|
||||
function Dwoo_Plugin_wordwrap_compile(Dwoo_Compiler $compiler, $value, $length=80, $break="\n", $cut=false)
|
||||
{
|
||||
return 'wordwrap('.$value.','.$length.','.$break.','.$cut.')';
|
||||
}
|
||||
Reference in new issue
Block a user