/** * 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 <*****@*****.**> * @copyright Copyright (c) 2008, Jordi Boggiano * @license http://dwoo.org/LICENSE Modified BSD License * @link http://dwoo.org/ * @version 1.1.0 * @date 2009-07-18 * @package Dwoo */ function Dwoo_Plugin_capitalize(Dwoo $dwoo, $value, $numwords = false) { if ($numwords || preg_match('#^[^0-9]+$#', $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); } }
/** * 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 <*****@*****.**> * @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; } }
/** * 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 <*****@*****.**> * @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); } }