CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * Text-to-HTML parser.
  5:  *
  6:  * Text-to-html parser, similar to {@link http://textism.com/tools/textile/ Textile} or {@link http://www.whytheluckystiff.net/ruby/redcloth/ RedCloth}.
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.libs
 20:  * @since         CakePHP(tm) v 0.2.9
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: /**
 27:  * Included libraries.
 28:  *
 29:  */
 30: if (!class_exists('Object')) {
 31:     uses('object');
 32: }
 33: /**
 34:  * Text-to-HTML parser.
 35:  *
 36:  * Text-to-html parser, similar to Textile or RedCloth, only with a little different syntax.
 37:  *
 38:  * @package       cake
 39:  * @subpackage    cake.cake.libs
 40:  */
 41: class Flay extends Object{
 42: /**
 43:  * Text to be parsed.
 44:  *
 45:  * @var string
 46:  * @access public
 47:  */
 48:     var $text = null;
 49: /**
 50:  * Set this to allow HTML in the markup.
 51:  *
 52:  * @var boolean
 53:  * @access public
 54:  */
 55:     var $allow_html = false;
 56: /**
 57:  * Constructor.
 58:  *
 59:  * @param string $text Text to transform
 60:  */
 61:     function __construct($text = null) {
 62:         $this->text = $text;
 63:         parent::__construct();
 64:     }
 65: /**
 66:  * Returns given text translated to HTML using the Flay syntax.
 67:  *
 68:  * @param string $text String to format
 69:  * @param boolean $bare Set this to only do <p> transforms and > to &gt;, no typography additions.
 70:  * @param boolean $allowHtml Set this to trim whitespace and disable all HTML
 71:  * @return string Formatted text
 72:  * @access public
 73:  */
 74:     function toHtml($text = null, $bare = false, $allowHtml = false) {
 75:         if (empty($text) && empty($this->text)) {
 76:             return false;
 77:         }
 78:         $text = $text ? $text : $this->text;
 79:         // trim whitespace and disable all HTML
 80:         if ($allowHtml) {
 81:             $text = trim($text);
 82:         } else {
 83:             $text = str_replace('<', '&lt;', str_replace('>', '&gt;', trim($text)));
 84:         }
 85: 
 86:         if (!$bare) {
 87:             // multi-paragraph functions
 88:             $text=preg_replace('#(?:[\n]{0,2})"""(.*)"""(?:[\n]{0,2})#s', "\n\n%BLOCKQUOTE%\n\n\\1\n\n%ENDBLOCKQUOTE%\n\n", $text);
 89:             $text=preg_replace('#(?:[\n]{0,2})===(.*)===(?:[\n]{0,2})#s', "\n\n%CENTER%\n\n\\1\n\n%ENDCENTER%\n\n", $text);
 90:         }
 91: 
 92:         // pre-parse newlines
 93:         $text=preg_replace("#\r\n#", "\n", $text);
 94:         $text=preg_replace("#[\n]{2,}#", "%PARAGRAPH%", $text);
 95:         $text=preg_replace('#[\n]{1}#', "%LINEBREAK%", $text);
 96:         $out ='';
 97: 
 98:         foreach (split('%PARAGRAPH%', $text)as $line) {
 99:             if ($line) {
100:                 if (!$bare) {
101:                     $links = array();
102:                     $regs = null;
103: 
104:                     if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) {
105:                         foreach ($regs[1] as $reg) {
106:                             $links[] = $reg;
107:                             $line = str_replace("[{$reg}]", '%LINK' . (count($links) - 1) . '%', $line);
108:                         }
109:                     }
110:                     // bold
111:                     $line = ereg_replace("\*([^\*]*)\*", "<strong>\\1</strong>", $line);
112:                     // italic
113:                     $line = ereg_replace("_([^_]*)_", "<em>\\1</em>", $line);
114:                 }
115:                 // entities
116:                 $line = str_replace(' - ', ' &ndash; ', $line);
117:                 $line = str_replace(' -- ', ' &mdash; ', $line);
118:                 $line = str_replace('(C)', '&copy;', $line);
119:                 $line = str_replace('(R)', '&reg;', $line);
120:                 $line = str_replace('(TM)', '&trade;', $line);
121:                 // guess e-mails
122:                 $emails = null;
123:                 if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) {
124:                     foreach ($emails[1] as $email) {
125:                         $line = str_replace($email, "<a href=\"mailto:{$email}\">{$email}</a>", $line);
126:                     }
127:                 }
128: 
129:                 if (!$bare) {
130:                     $urls = null;
131:                     if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) {
132:                         foreach ($urls[1] as $url) {
133:                             $line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
134:                         }
135:                     }
136: 
137:                     if (preg_match_all("#(www\.[^\n\%\ ]+[^\n\%\,\.\ ])#", $line, $urls)) {
138:                         foreach ($urls[1] as $url) {
139:                             $line = str_replace($url, "<a href=\"http://{$url}\">{$url}</a>", $line);
140:                         }
141:                     }
142: 
143:                     if ($count = count($links)) {
144:                         for ($ii = 0; $ii < $count; $ii++) {
145:                             if (preg_match("#^(http|https|ftp|nntp)://#", $links[$ii])) {
146:                                 $prefix = null;
147:                             } else {
148:                                 $prefix = 'http://';
149:                             }
150:                             if (preg_match('#^[^\ ]+\.(jpg|jpeg|gif|png)$#', $links[$ii])) {
151:                                 $with = "<img src=\"{$prefix}{$links[$ii]}\" alt=\"\" />";
152:                             } elseif (preg_match('#^([^\]\ ]+)(?:\ ([^\]]+))?$#', $links[$ii], $regs)) {
153:                                 if (isset($regs[2])) {
154:                                     if (preg_match('#\.(jpg|jpeg|gif|png)$#', $regs[2])) {
155:                                         $body = "<img src=\"{$prefix}{$regs[2]}\" alt=\"\" />";
156:                                     } else {
157:                                         $body = $regs[2];
158:                                     }
159:                                 } else {
160:                                     $body = $links[$ii];
161:                                 }
162:                                 $with = "<a href=\"{$prefix}{$regs[1]}\" target=\"_blank\">{$body}</a>";
163:                             } else {
164:                                 $with = $prefix . $links[$ii];
165:                             }
166:                             $line = str_replace("%LINK{$ii}%", $with, $line);
167:                         }
168:                     }
169:                 }
170:                 $out .= str_replace('%LINEBREAK%', "<br />\n", "<p>{$line}</p>\n");
171:             }
172:         }
173: 
174:         if (!$bare) {
175:             $out = str_replace('<p>%BLOCKQUOTE%</p>', "<blockquote>", $out);
176:             $out = str_replace('<p>%ENDBLOCKQUOTE%</p>', "</blockquote>", $out);
177:             $out = str_replace('<p>%CENTER%</p>', "<center>", $out);
178:             $out = str_replace('<p>%ENDCENTER%</p>', "</center>", $out);
179:         }
180:         return $out;
181:     }
182: /**
183:  * Return the words of the string as an array.
184:  *
185:  * @param string $string
186:  * @return array Array of words
187:  * @access public
188:  */
189:     function extractWords($string) {
190:         $split = preg_split('/[\s,\.:\/="!\(\)<>~\[\]]+/', $string);
191:         return $split;
192:      }
193: /**
194:  * Return given string with words in array colorMarked, up to a number of times (defaults to 5).
195:  *
196:  * @param array $words          Words to look for and markup
197:  * @param string $string        String to look in
198:  * @param integer $max_snippets Max number of snippets to extract
199:  * @return string String with words marked
200:  * @see colorMark
201:  * @access public
202:  */
203:     function markedSnippets($words, $string, $max_snippets = 5) {
204:         $string = strip_tags($string);
205:         $snips = array();
206:         $rest = $string;
207:         foreach ($words as $word) {
208:             if (preg_match_all("/[\s,]+.{0,40}{$word}.{0,40}[\s,]+/i", $rest, $r)) {
209:                 foreach ($r as $result) {
210:                     $rest = str_replace($result, '', $rest);
211:                 }
212:                 $snips = array_merge($snips, $r[0]);
213:             }
214:         }
215: 
216:         if (count($snips) > $max_snippets) {
217:             $snips = array_slice($snips, 0, $max_snippets);
218:         }
219:         $joined = implode(' <b>...</b> ', $snips);
220:         $snips = $joined ? "<b>...</b> {$joined} <b>...</b>" : substr($string, 0, 80) . '<b>...</b>';
221:         return $this->colorMark($words, $snips);
222:     }
223: /**
224:  * Returns string with EM elements with color classes added.
225:  *
226:  * @param array $words Array of words to be colorized
227:  * @param string $string Text in which the words might be found
228:  * @return string String with words colorized
229:  * @access public
230:  */
231:     function colorMark($words, $string) {
232:         $colors=array('yl', 'gr', 'rd', 'bl', 'fu', 'cy');
233:         $nextColorIndex = 0;
234:         foreach ($words as $word) {
235:             $string = preg_replace("/({$word})/i", '<em class="' . $colors[$nextColorIndex % count($colors)] . "\">\\1</em>", $string);
236:             $nextColorIndex++;
237:         }
238:         return $string;
239:     }
240: /**
241:  * Returns given text with tags stripped out.
242:  *
243:  * @param string $text Text to clean
244:  * @return string Cleaned text
245:  * @access public
246:  */
247:     function toClean($text) {
248:         $strip = strip_tags(html_entity_decode($text, ENT_QUOTES));
249:         return $strip;
250:     }
251: /**
252:  * Return parsed text with tags stripped out.
253:  *
254:  * @param string $text Text to parse and clean
255:  * @return string Cleaned text
256:  * @access public
257:  */
258:     function toParsedAndClean($text) {
259:         return $this->toClean(Flay::toHtml($text));
260:     }
261: /**
262:  * Return a fragment of a text, up to $length characters long, with an ellipsis after it.
263:  *
264:  * @param string $text      Text to be truncated.
265:  * @param integer $length   Max length of text.
266:  * @param string $ellipsis  Sign to print after truncated text.
267:  * @return string Fragment
268:  * @access public
269:  */
270:     function fragment($text, $length, $ellipsis = '...') {
271:         $soft = $length - 5;
272:         $hard = $length + 5;
273:         $rx = '/(.{' . $soft . ',' . $hard . '})[\s,\.:\/="!\(\)<>~\[\]]+.*/';
274: 
275:         if (preg_match($rx, $text, $r)) {
276:             $out = $r[1];
277:         } else {
278:             $out = substr($text, 0, $length);
279:         }
280:         $out = $out . (strlen($out) < strlen($text) ? $ellipsis : null);
281:         return $out;
282:     }
283: }
284: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs