'String'), $settings); parent::__construct($View, $settings); list($plugin, $engineClass) = pluginSplit($settings['engine'], true); App::uses($engineClass, $plugin . 'Utility'); if (class_exists($engineClass)) { $this->_engine = new $engineClass($settings); } else { throw new CakeException(__d('cake_dev', '%s could not be found', $engineClass)); } } /** * Call methods from String utility class * @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); } /** * Adds links (_placeholders = array(); $options += array('escape' => true); $pattern = '#(?)((?:https?|ftp|nntp)://[\p{L}0-9.\-:]+(?:[/?][^\s<]*)?)#ui'; $text = preg_replace_callback( $pattern, array(&$this, '_insertPlaceHolder'), $text ); $text = preg_replace_callback( '#(?)(?_linkUrls($text, $options); } /** * 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. * @return string Replaced values. */ protected function _insertPlaceHolder($matches) { $key = md5($matches[0]); $this->_placeholders[$key] = $matches[0]; return $key; } /** * Replace placeholders with links. * * @param string $text The text to operate on. * @param array $htmlOptions The options for the generated links. * @return string The text with links inserted. */ protected function _linkUrls($text, $htmlOptions) { $replace = array(); foreach ($this->_placeholders as $hash => $url) { $link = $url; if (!preg_match('#^[a-z]+\://#', $url)) { $url = 'http://' . $url; } $replace[$hash] = $this->Html->link($link, $url, $htmlOptions); } return strtr($text, $replace); } /** * Links email addresses * * @param string $text The text to operate on * @param array $options An array of options to use for the HTML. * @return string * @see TextHelper::autoLinkEmails() */ protected function _linkEmails($text, $options) { $replace = array(); foreach ($this->_placeholders as $hash => $url) { $replace[$hash] = $this->Html->link($url, 'mailto:' . $url, $options); } return strtr($text, $replace); } /** * Adds email links (\n"; } $text = preg_replace('|

\s*

|', '', $text); } return $text; } /** * Strips given text of all links (
_engine->stripLinks($text); } /** * 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 * * @see String::truncate() * * @param string $text String to truncate. * @param integer $length Length of returned string, including ellipsis. * @param array $options An array of html attributes and options. * @return string Trimmed string. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate */ public function truncate($text, $length = 100, $options = array()) { return $this->_engine->truncate($text, $length, $options); } /** * Extracts an excerpt from the text surrounding the phrase with a number of characters on each side * determined by radius. * * @see String::excerpt() * * @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 string $ending Ending that will be appended * @return string Modified string * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::excerpt */ public function excerpt($text, $phrase, $radius = 100, $ending = '...') { return $this->_engine->excerpt($text, $phrase, $radius, $ending); } /** * Creates a comma separated list where the last two items are joined with 'and', forming natural English * * @see String::toList() * * @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. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::toList */ public function toList($list, $and = 'and', $separator = ', ') { return $this->_engine->toList($list, $and, $separator); } }