Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -4,22 +4,22 @@
*
* Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.View.Helper
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('AppHelper', 'View/Helper');
App::uses('Hash', 'Utility');
/**
* Text helper library.
@ -49,7 +49,9 @@ class TextHelper extends AppHelper {
protected $_placeholders = array();
/**
* String utility instance
* CakeText utility instance
*
* @var stdClass
*/
protected $_engine;
@ -58,7 +60,7 @@ class TextHelper extends AppHelper {
*
* ### Settings:
*
* - `engine` Class name to use to replace String functionality.
* - `engine` Class name to use to replace CakeText functionality.
* The class needs to be placed in the `Utility` directory.
*
* @param View $View the view object the helper is attached to.
@ -66,7 +68,7 @@ class TextHelper extends AppHelper {
* @throws CakeException when the engine class could not be found.
*/
public function __construct(View $View, $settings = array()) {
$settings = Hash::merge(array('engine' => 'String'), $settings);
$settings = Hash::merge(array('engine' => 'CakeText'), $settings);
parent::__construct($View, $settings);
list($plugin, $engineClass) = pluginSplit($settings['engine'], true);
App::uses($engineClass, $plugin . 'Utility');
@ -78,7 +80,11 @@ class TextHelper extends AppHelper {
}
/**
* Call methods from String utility class
* Call methods from CakeText utility class
*
* @param string $method Method to call.
* @param array $params Parameters to pass to method.
* @return mixed Whatever is returned by called method, or false on failure
*/
public function __call($method, $params) {
return call_user_func_array(array($this->_engine, $method), $params);
@ -101,14 +107,14 @@ class TextHelper extends AppHelper {
$this->_placeholders = array();
$options += array('escape' => true);
$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:/[^\s]*)?)#i';
$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[\p{L}0-9.\-_:]+(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#i';
$text = preg_replace_callback(
$pattern,
array(&$this, '_insertPlaceHolder'),
$text
);
$text = preg_replace_callback(
'#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://)www.[^\n\%\ <]+[^<\n\%\,\.\ <](?<!\))#i',
'#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://|//)www\.[^\n\%\ <]+[^<\n\%\,\.\ <](?<!\))#i',
array(&$this, '_insertPlaceHolder'),
$text
);
@ -119,7 +125,7 @@ class TextHelper extends AppHelper {
}
/**
* Saves the placeholder for a string, for later use. This gets around double
* Saves the placeholder for a string, for later use. This gets around double
* escaping content in URL's.
*
* @param array $matches An array of regexp matches.
@ -182,9 +188,9 @@ class TextHelper extends AppHelper {
$options += array('escape' => true);
$this->_placeholders = array();
$atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]';
$atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]';
$text = preg_replace_callback(
'/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)+)/i',
'/(?<=\s|^|\(|\>|\;)(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
array(&$this, '_insertPlaceholder'),
$text
);
@ -212,12 +218,14 @@ class TextHelper extends AppHelper {
}
/**
* @see String::highlight()
* Highlights a given phrase in a text. You can specify any expression in highlighter that
* may include the \1 expression to include the $phrase found.
*
* @param string $text Text to search the phrase in
* @param string $phrase The phrase that will be searched
* @param array $options An array of html attributes and options.
* @return string The highlighted text
* @see CakeText::highlight()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::highlight
*/
public function highlight($text, $phrase, $options = array()) {
@ -225,10 +233,34 @@ class TextHelper extends AppHelper {
}
/**
* @see String::stripLinks()
* Formats paragraphs around given text for all line breaks
* <br /> added for single line return
* <p> added for double line return
*
* @param string $text Text
* @return string The text with proper <p> and <br /> tags
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoParagraph
*/
public function autoParagraph($text) {
if (trim($text) !== '') {
$text = preg_replace('|<br[^>]*>\s*<br[^>]*>|i', "\n\n", $text . "\n");
$text = preg_replace("/\n\n+/", "\n\n", str_replace(array("\r\n", "\r"), "\n", $text));
$texts = preg_split('/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
$text = '';
foreach ($texts as $txt) {
$text .= '<p>' . nl2br(trim($txt, "\n")) . "</p>\n";
}
$text = preg_replace('|<p>\s*</p>|', '', $text);
}
return $text;
}
/**
* Strips given text of all links (<a href=....)
*
* @param string $text Text
* @return string The text without links
* @see CakeText::stripLinks()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::stripLinks
*/
public function stripLinks($text) {
@ -236,12 +268,22 @@ class TextHelper extends AppHelper {
}
/**
* @see String::truncate()
* Truncates text.
*
* Cuts a string to the length of $length and replaces the last characters
* with the ellipsis if the text is longer than length.
*
* ### Options:
*
* - `ellipsis` Will be used as Ending and appended to the trimmed string (`ending` is deprecated)
* - `exact` If false, $text will not be cut mid-word
* - `html` If true, HTML tags would be handled correctly
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param int $length Length of returned string, including ellipsis.
* @param array $options An array of html attributes and options.
* @return string Trimmed string.
* @see CakeText::truncate()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate
*/
public function truncate($text, $length = 100, $options = array()) {
@ -249,13 +291,37 @@ class TextHelper extends AppHelper {
}
/**
* @see String::excerpt()
* Truncates text starting from the end.
*
* Cuts a string to the length of $length and replaces the first characters
* with the ellipsis if the text is longer than length.
*
* ### Options:
*
* - `ellipsis` Will be used as Beginning and prepended to the trimmed string
* - `exact` If false, $text will not be cut mid-word
*
* @param string $text String to truncate.
* @param int $length Length of returned string, including ellipsis.
* @param array $options An array of html attributes and options.
* @return string Trimmed string.
* @see CakeText::tail()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::tail
*/
public function tail($text, $length = 100, $options = array()) {
return $this->_engine->tail($text, $length, $options);
}
/**
* Extracts an excerpt from the text surrounding the phrase with a number of characters on each side
* determined by radius.
*
* @param string $text String to search the phrase in
* @param string $phrase Phrase that will be searched for
* @param integer $radius The amount of characters that will be returned on each side of the founded phrase
* @param int $radius The amount of characters that will be returned on each side of the founded phrase
* @param string $ending Ending that will be appended
* @return string Modified string
* @see CakeText::excerpt()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::excerpt
*/
public function excerpt($text, $phrase, $radius = 100, $ending = '...') {
@ -263,15 +329,16 @@ class TextHelper extends AppHelper {
}
/**
* @see String::toList()
* Creates a comma separated list where the last two items are joined with 'and', forming natural language.
*
* @param array $list The list to be joined
* @param string $and The word used to join the last and second last items together with. Defaults to 'and'
* @param string $separator The separator used to join all the other items together. Defaults to ', '
* @param array $list The list to be joined.
* @param string $and The word used to join the last and second last items together with. Defaults to 'and'.
* @param string $separator The separator used to join all the other items together. Defaults to ', '.
* @return string The glued together string.
* @see CakeText::toList()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::toList
*/
public function toList($list, $and = 'and', $separator = ', ') {
public function toList($list, $and = null, $separator = ', ') {
return $this->_engine->toList($list, $and, $separator);
}