PageRenderTime 64ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/shared/codes.php

https://github.com/altatof/yacs
PHP | 4235 lines | 2154 code | 753 blank | 1328 comment | 384 complexity | 16fac73c75f329bb4e89037c5b60a86a MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Transform some text containing UBB-like code sequences.
  4. *
  5. * @todo CDATA for proxy http://javascript.about.com/library/blxhtml.htm
  6. * @todo &#91;files] - most recent files, in a compact list
  7. * @todo &#91;files=section:&lt;id>] - files attached in the given section
  8. * @todo &#91;links] - most recent links, in a compact list
  9. * @todo &#91;links=section:&lt;id>] - links attached in the given section
  10. * @todo for [read, add hits aside
  11. * @todo add a code to link images with clickable maps
  12. * @todo replace marquee with our own customizable scroller
  13. * @todo WiKi rendering for lists
  14. *
  15. * This module uses the Skin class for the actual rendering.
  16. *
  17. * Basic codes, demonstrated into [link]codes/basic.php[/link]:
  18. * - **...** - wiki bold text
  19. * - &#91;b]...[/b] - bold text
  20. * - //...// - italics
  21. * - &#91;i]...[/i] - italics
  22. * - __...__ - underlined
  23. * - &#91;u]...[/u] - underlined
  24. * - ##...## - monospace
  25. * - &#91;code]...[/code] - a short sample of fixed-size text (e.g. a file name)
  26. * - &#91;color]...[/color] - change font color
  27. * - &#91;tiny]...[/tiny] - tiny size
  28. * - &#91;small]...[/small] - small size
  29. * - &#91;big]...[/big] - big size
  30. * - &#91;huge]...[/huge] - huge size
  31. * - &#91;subscript]...[/subscript] - subscript
  32. * - &#91;superscript]...[/superscript] - superscript
  33. * - ++...++ - inserted
  34. * - &#91;inserted]...[/inserted] - inserted
  35. * - --...-- - deleted
  36. * - &#91;deleted]...[/deleted] - deleted
  37. * - &#91;flag]...[/flag] - draw attention
  38. * - &#91;lang=xy]...[/lang] - show some text only on matching language
  39. * - &#91;style=sans-serif]...[/style] - use a sans-serif font
  40. * - &#91;style=serif]...[/style] - use a serif font
  41. * - &#91;style=cursive]...[/style] - mimic hand writing
  42. * - &#91;style=comic]...[/style] - make it funny
  43. * - &#91;style=fantasy]...[/style] - guess what will appear
  44. * - &#91;style=my_style]...[/style] - translated to &lt;span class="my_style"&gt;...&lt;/span&gt;
  45. *
  46. * @see codes/basic.php
  47. *
  48. * Block codes, demonstrated in [link]codes/blocks.php[/link]:
  49. * - &#91;indent]...[/indent] - shift text to the right
  50. * - &#91;center]...[/center] - some centered text
  51. * - &#91;right]...[/right] - some right-aligned text
  52. * - &#91;decorated]...[/decorated] - some pretty paragraphs
  53. * - &#91;caution]...[/caution] - a warning paragraph
  54. * - &#91;note]...[/note] - a noticeable paragraph
  55. * - &#91;php]...[/php] - a snippet of php
  56. * - &#91;snippet]...[/snippet] - a snippet of fixed font data
  57. * - &#91;quote]...[/quote] - a block of quoted text
  58. * - &#91;folded]...[/folded] - click to view its content, or to fold it away
  59. * - &#91;folded=foo bar]...[/folded] - with title 'foo bar'
  60. * - &#91;unfolded]...[/unfolded] - click to fold
  61. * - &#91;unfolded=foo bar]...[/unfolded] - with title 'foo bar'
  62. * - &#91;sidebar]...[/sidebar] - a nice box aside
  63. * - &#91;sidebar=foo bar]...[/sidebar] - with title 'foo bar'
  64. * - &#91;scroller]...[/scroller] - some scrolling text
  65. *
  66. * @see codes/blocks.php
  67. *
  68. * List codes, demonstrated in [link]codes/lists.php[/link]:
  69. * - &#91;*] - for simple lists
  70. * - &#91;list]...[/list] - bulleted list
  71. * - &#91;list=1]...[/list] - numbered list, use numbers
  72. * - &#91;list=a]...[/list] - numbered list, use letters
  73. * - &#91;list=A]...[/list] - numbered list, use capital letters
  74. * - &#91;list=i]...[/list] - numbered list, use roman numbers
  75. * - &#91;list=I]...[/list] - numbered list, use upper case roman numbers
  76. *
  77. * @see codes/lists.php
  78. *
  79. * Codes for links, demonstrated in [link]codes/links.php[/link]:
  80. * - &lt;url&gt; - &lt;a href="url">url&lt;/a> or &lt;a href="url" class="external">url&lt;/a>
  81. * - &#91;link]&lt;url&gt;[/link] - &lt;a href="url">url&lt;/a> or &lt;a href="url" class="external">url&lt;/a>
  82. * - &#91;&lt;label&gt;|&lt;url&gt;] - &lt;a href="url">label&lt;/a> or &lt;a href="url" class="external">label&lt;/a>
  83. * - &#91;link=&lt;label&gt;]&lt;url&gt;[/link] - &lt;a href="url">label&lt;/a> or &lt;a href="url" class="external">label&lt;/a>
  84. * - &#91;url]&lt;url&gt;[/url] - deprecated by &#91;link]
  85. * - &#91;url=&lt;url&gt;]&lt;label&gt;[/url] - deprecated by &#91;link]
  86. * - &#91;button=&lt;label&gt;|&lt;url&gt;] - build simple buttons with css
  87. * - &#91;click=&lt;label&gt;|&lt;url&gt;] - a button that counts clicks
  88. * - &#91;clicks=&lt;url&gt;] - lists people who have clicked
  89. * - &lt;address&gt; - &lt;a href="mailto:address" class="email">address&lt;/a>
  90. * - &#91;email]&lt;address&gt;[/email] - &lt;a href="mailto:address" class="email">address&lt;/a>
  91. * - &#91;email=&lt;name&gt;]&lt;address&gt;[/email] - &lt;a href="mailto:address" class="email">name&lt;/a>
  92. * - &#91;go=&lt;name&gt;, &lt;label&gt;] - trigger the selector on 'name'
  93. * - &#91;&#91;&lt;name&gt;, &lt;label&gt;]] - Wiki selector
  94. * - &#91;article=&lt;id>] - use article title as link label
  95. * - &#91;article=&lt;id>, foo bar] - with label 'foo bar'
  96. * - &#91;article.description=&lt;id>] - insert article description
  97. * - &#91;next=&lt;id>] - shortcut to next article
  98. * - &#91;next=&lt;id>, foo bar] - with label 'foo bar'
  99. * - &#91;previous=&lt;id>] - shortcut to previous article
  100. * - &#91;previous=&lt;id>, foo bar] - with label 'foo bar'
  101. * - &#91;random] - pick up one page randomly
  102. * - &#91;random=&lt;section:id>] - one page in this section
  103. * - &#91;section=&lt;id>] - use section title as link label
  104. * - &#91;section=&lt;id>, foo bar] - with label 'foo bar'
  105. * - &#91;category=&lt;id>] - use category title as link label
  106. * - &#91;category=&lt;id>, foo bar] - with label 'foo bar'
  107. * - &#91;category.description=&lt;id>] - insert category description
  108. * - &#91;user=&lt;id>] - use nick name as link label
  109. * - &#91;user=&lt;id>, foo bar] - with label 'foo bar'
  110. * - &#91;server=&lt;id>] - use server title as link label
  111. * - &#91;server=&lt;id>, foo bar] - with label 'foo bar'
  112. * - &#91;file=&lt;id>] - use file title as link label
  113. * - &#91;file=&lt;id>, foo bar] - with label 'foo bar'
  114. * - &#91;download=&lt;id>] - a link to download a file
  115. * - &#91;download=&lt;id>, foo bar] - with label 'foo bar'
  116. * - &#91;comment=&lt;id>] - use comment id in link label
  117. * - &#91;comment=&lt;id>, foo bar] - with label 'foo bar'
  118. * - &#91;script]&lt;path/script.php&gt;[/script] - to the phpDoc page for script 'path/script.php'
  119. * - &#91;search] - a search form
  120. * - &#91;search=&lt;word&gt;] - hit Enter to search for 'word'
  121. * - &#91;wikipedia=&lt;keyword] - search Wikipedia
  122. * - &#91;wikipedia=&lt;keyword, foo bar] - search Wikipedia, with label 'foo bar'
  123. * - &#91;proxy]&lt;url&gt;[/proxy] - proxy a remote address
  124. *
  125. * @see codes/links.php
  126. *
  127. * Titles and questions, demonstrated in [link]codes/titles.php[/link]:
  128. * - &#91;toc] - table of contents
  129. * - ==...== - a level 1 headline
  130. * - &#91;title]...[/title] - a level 1 headline, put in the table of contents
  131. * - ===...=== - a level 2 headline
  132. * - &#91;subtitle]...[/subtitle] - a level 2 headline
  133. * - &#91;header1]...[/header1] - a level 1 headline
  134. * - &#91;header2]...[/header2] - a level 2 headline
  135. * - &#91;header3]...[/header3] - a level 3 headline
  136. * - &#91;header4]...[/header4] - a level 4 headline
  137. * - &#91;header5]...[/header5] - a level 5 headline
  138. * - &#91;toq] - the table of questions for this page
  139. * - &#91;question]...[/question] - a question-title
  140. * - &#91;question] - a simple question
  141. * - &#91;answer] - some answer in a FAQ
  142. *
  143. * @see codes/titles.php
  144. *
  145. * Tables, demonstrated in [link]codes/tables.php[/link]:
  146. * - &#91;table]...[/table] - one simple table
  147. * - &#91;table=grid]...[/table] - add a grid
  148. * - &#91;table].[body].[/table] - a table with headers
  149. * - &#91;csv]...[/csv] - import some data from a spreadsheet
  150. * - &#91;csv=;]...[/csv] - import some data from a spreadsheet
  151. * - &#91;table.json] - format a table as json
  152. *
  153. * @see codes/tables.php
  154. *
  155. * Live codes, demonstrated in [link]codes/live.php[/link]:
  156. * - &#91;sections] - site map
  157. * - &#91;sections=section:&lt;id>] - sub-sections
  158. * - &#91;sections=self] - sections assigned to current surfer
  159. * - &#91;sections=user:&lt;id>] - sections assigned to given user
  160. * - &#91;categories] - category tree
  161. * - &#91;categories=category:&lt;id>] - sub-categories
  162. * - &#91;categories=self] - categories assigned to current surfer
  163. * - &#91;categories=user:&lt;id>] - categories assigned to given user
  164. * - &#91;published] - most recent published pages, in a compact list
  165. * - &#91;published=section:&lt;id>] - articles published most recently in the given section
  166. * - &#91;published=category:&lt;id>] - articles published most recently in the given category
  167. * - &#91;published=user:&lt;id>] - articles published most recently created by given user
  168. * - &#91;published.decorated=self, 20] - 20 most recent pages from current surfer, as a decorated list
  169. * - &#91;updated] - most recent updated pages, in a compact list
  170. * - &#91;updated=section:&lt;id>] - articles updated most recently in the given section
  171. * - &#91;updated=category:&lt;id>] - articles updated most recently in the given category
  172. * - &#91;updated=user:&lt;id>] - articles updated most recently created by given user
  173. * - &#91;updated.simple=self, 12] - articles updated most recently created by current surfer, as a simple list
  174. * - &#91;read] - most read articles, in a compact list
  175. * - &#91;read=section:&lt;id>] - articles of fame in the given section
  176. * - &#91;read=self] - personal hits
  177. * - &#91;read=user:&lt;id>] - personal hits
  178. * - &#91;voted] - most voted articles, in a compact list
  179. * - &#91;voted=section:&lt;id>] - articles of fame in the given section
  180. * - &#91;voted=self] - personal hits
  181. * - &#91;voted=user:&lt;id>] - personal hits
  182. * - &#91;users=present] - list of users present on site
  183. *
  184. * @see codes/live.php
  185. *
  186. * Widgets, demonstrated in [link]codes/widgets.php[/link]:
  187. * - &#91;newsfeed=url] - integrate a newsfeed dynamically
  188. * - &#91;newsfeed.embed=url] - integrate a newsfeed dynamically
  189. * - &#91;twitter=id] - twitter updates of one person
  190. * - &#91;tsearch=token] - twitter search on a given topic
  191. * - &#91;iframe=&lt;width&gt;, &lt;height&gt;]&lt;url&gt;[/iframe] - include some external page
  192. * - &#91;cloud] - the tags used at this site
  193. * - &#91;cloud=12] - maximum count of tags used at this site
  194. * - &#91;calendar] - events for this month
  195. * - &#91;calendar=section:&lt;id>] - dates in one section
  196. * - &#91;locations=all] - newest locations
  197. * - &#91;locations=users] - map user locations on Google maps
  198. * - &#91;location=latitude, longitude, label] - to build a dynamic map
  199. *
  200. * @see codes/widgets.php
  201. *
  202. * Miscellaneous codes, demonstrated in [link]codes/misc.php[/link]:
  203. * - &#91;hint=&lt;help popup]...[/hint] - &lt;acronym tite="help popup">...&lt;/acronym>
  204. * - &#91;nl] - new line
  205. * - ----... - line break
  206. * - &#91;---] or &#91;___] - horizontal rule
  207. * - &#91;new] - something new
  208. * - &#91;popular] - people love it
  209. * - &#91;be] - country flag
  210. * - &#91;ca] - country flag
  211. * - &#91;ch] - country flag
  212. * - &#91;de] - country flag
  213. * - &#91;en] - country flag
  214. * - &#91;es] - country flag
  215. * - &#91;fr] - country flag
  216. * - &#91;gb] - country flag
  217. * - &#91;gr] - country flag
  218. * - &#91;it] - country flag
  219. * - &#91;pt] - country flag
  220. * - &#91;us] - country flag
  221. * - &#91;chart]...[/chart] - draw a dynamic chart
  222. * - &#91;execute=script] - include another local script
  223. * - &#91;redirect=link] - jump to another local page
  224. * - &#91;parameter=name] - value of one attribute of the global context
  225. * - &#91;escape]...[/escape]
  226. * - &#91;anonymous]...[/anonymous] - for non-logged people only
  227. * - &#91;authenticated]...[/authenticated] - for logged members only
  228. * - &#91;associate]...[/associate] - for associates only
  229. *
  230. * @see codes/misc.php
  231. *
  232. * In-line elements:
  233. * - &#91;embed=&lt;id>, &lt;width>, &lt;height>, &lt;flashparams>] - embed a multimedia file
  234. * - &#91;embed=&lt;id>, window] - render a multimedia file in a separate window
  235. * - &#91;sound=&lt;id>] - play a sound
  236. * - &#91;image=&lt;id>] - an inline image
  237. * - &#91;image=&lt;id>,left] - a left-aligned image
  238. * - &#91;image=&lt;id>,center] - a centered image
  239. * - &#91;image=&lt;id>,right] - a right-aligned image
  240. * - &#91;image]src[/image]
  241. * - &#91;image=&lt;alt>]src[/image]
  242. * - &#91;images=&lt;id1>, &lt;id2>, ...] - a stack of images
  243. * - &#91;img]src[/img] (deprecated)
  244. * - &#91;img=&lt;alt>]src[/img] (deprecated)
  245. * - &#91;table=&lt;id>] - an inline table
  246. * - &#91;location=&lt;id>] - embed a map
  247. * - &#91;location=&lt;id>, foo bar] - with label 'foo bar'
  248. * - &#91;clear] - to introduce breaks after floating elements
  249. *
  250. * @link http://www.estvideo.com/dew/index/2005/02/16/370-player-flash-mp3-leger-comme-une-plume the dewplayer page
  251. *
  252. * Other codes:
  253. * - &#91;menu=label]url[/menu] - one of the main menu command
  254. * - &#91;submenu=label]url[/submenu] - one of the second-level menu commands
  255. *
  256. * This script attempts to fight bbCode code injections by filtering strings to be used
  257. * as [code]src[/code] or as [code]href[/code] attributes (Thank you Mordread).
  258. *
  259. * @author Bernard Paques
  260. * @author Mordread Wallas
  261. * @author GnapZ
  262. * @author Alain Lesage (Lasares)
  263. * @tester Viviane Zaniroli
  264. * @tester Agnes
  265. * @tester Pat
  266. * @tester Guillaume Perez
  267. * @tester Fw_crocodile
  268. * @tester Christian Piercot
  269. * @tester Christian Loubechine
  270. * @tester Daniel Dupuis
  271. * @reference
  272. * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  273. */
  274. Class Codes {
  275. /**
  276. * beautify some text for final rendering
  277. *
  278. * This function is used to transform some text before sending it back to the browser.
  279. * It actually performs following analysis:
  280. * - implicit formatting
  281. * - formatting codes
  282. * - smileys
  283. *
  284. * If the keyword [escape][formatted][/escape] appears at the first line of text,
  285. * or if options have the keyword ##formatted##, no implicit formatting is performed.
  286. *
  287. * If the keyword [escape][hardcoded][/escape] appears at the first line of text,
  288. * or if options have the keyword ##hardcoded##, the only transformation is new lines to breaks.
  289. *
  290. * If options feature the keyword ##compact##, then YACS codes that may
  291. * generate big objects are removed, such as [escape][table]...[/table][/escape]
  292. * and [escape][location][/escape].
  293. *
  294. * @param string the text to beautify
  295. * @param string the set of options that apply to this text
  296. * @return the beautified text
  297. *
  298. * @see articles/view.php
  299. */
  300. public static function &beautify($text, $options='') {
  301. global $context;
  302. // save CPU cycles
  303. $text = trim($text);
  304. if(!$text)
  305. return $text;
  306. //
  307. // looking for compact content
  308. //
  309. if(preg_match('/\bcompact\b/i', $options))
  310. $text = preg_replace(array('/\[table.+?\/table\]/', '/\[location.+?\]/'), '', $text);
  311. //
  312. // implicit formatting
  313. //
  314. // new lines will have to be checked
  315. $new_lines = 'proceed';
  316. // text is already formatted
  317. if(!strncmp($text, '[formatted]', 11)) {
  318. $new_lines = 'none';
  319. $text = substr($text, 11);
  320. // text is already formatted (through options)
  321. } elseif(preg_match('/\bformatted\b/i', $options))
  322. $new_lines = 'none';
  323. // newlines are hard coded
  324. elseif(!strncmp($text, '[hardcoded]', 11)) {
  325. $new_lines = 'hardcoded';
  326. $text = substr($text, 11);
  327. // newlines are hard coded (through options)
  328. } elseif(preg_match('/\bhardcoded\b/i', $options))
  329. $new_lines = 'hardcoded';
  330. // implicit formatting
  331. else
  332. $text =& Codes::beautify_implied($text, 'text');
  333. //
  334. // translate codes
  335. //
  336. // render codes
  337. $text =& Codes::render($text);
  338. // render smileys after codes, else it will break escaped strings
  339. if(is_callable(array('Smileys', 'render_smileys')))
  340. $text = Smileys::render_smileys($text);
  341. // relocate images
  342. $text = str_replace('"skins/', '"'.$context['path_to_root'].'skins/', $text);
  343. //
  344. // adjust end of lines
  345. //
  346. // newlines are hard coded
  347. if($new_lines == 'hardcoded')
  348. $text = nl2br($text);
  349. // implicit formatting
  350. elseif($new_lines == 'proceed')
  351. $text =& Codes::beautify_implied($text, 'newlines');
  352. return $text;
  353. }
  354. /**
  355. * beautify some text in the extra panel
  356. *
  357. * @param string the text to beautify
  358. * @return the beautified text
  359. *
  360. * @see articles/view.php
  361. */
  362. public static function &beautify_extra($text) {
  363. global $context;
  364. $search = array();
  365. $replace = array();
  366. // [box.extra=title]...[/box]
  367. $search[] = '/\[box\.(extra)=([^\]]+?)\](.*?)\[\/box\]/ise';
  368. $replace[] = "Skin::build_box(stripslashes('$2'), stripslashes('$3'), '$1')";
  369. // [box.navigation=title]...[/box]
  370. $search[] = '/\[box\.(navigation)=([^\]]+?)\](.*?)\[\/box\]/ise';
  371. $replace[] = "Skin::build_box(stripslashes('$2'), stripslashes('$3'), '$1')";
  372. // process all codes
  373. $text = preg_replace($search, $replace, $text);
  374. // regular rendering
  375. $text =& Codes::beautify($text);
  376. return $text;
  377. }
  378. /**
  379. * render some basic formatting
  380. *
  381. * - suppress multiple newlines
  382. * - render empty lines
  383. * - render simple bulleted lines
  384. * - make URL clickable (http://..., www.foo.bar, foo.bar@foo.com)
  385. *
  386. * Now this function looks for the keyword &#91;escape] in order
  387. * to avoid for formatting pre-formatted areas.
  388. *
  389. * For example, if you type:
  390. * [snippet]
  391. * hello
  392. * world
  393. *
  394. * how are
  395. * you doing?
  396. *
  397. * - my first item
  398. * - my second item
  399. *
  400. * > quoted from
  401. * > a previous message
  402. * [/snippet]
  403. *
  404. * This will be rendered visually in the browser as:
  405. * [snippet]
  406. * hello world
  407. *
  408. * how are you doing?
  409. *
  410. * - my first item
  411. * - my second item
  412. *
  413. * > quoted from
  414. * > a previous message
  415. * [/snippet]
  416. *
  417. * @param string the text to transform
  418. * @param sring either 'text' or 'newlines'
  419. * @return the modified string
  420. */
  421. public static function &beautify_implied($text, $variant='text') {
  422. // streamline newlines, even if this has been done elsewhere
  423. $text = str_replace(array("\r\n", "\r"), "\n", $text);
  424. // only change end of lines
  425. if($variant == 'newlines') {
  426. // formatting patterns
  427. $search = array(
  428. "|<br\s*/>\n+|i", /* don't insert additional \n after <br /> */
  429. "|\n\n+|i" /* force an html space between paragraphs */
  430. );
  431. $replace = array(
  432. BR,
  433. BR.BR
  434. );
  435. // change everything, except new lines
  436. } else {
  437. // formatting patterns
  438. $search = array(
  439. "|</h1>\n+|i", /* strip \n after title */
  440. "|</h2>\n+|i",
  441. "|</h3>\n+|i",
  442. "|</h4>\n+|i",
  443. '/http:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_\-]+)[a-zA-Z0-9_\-&=]*/i', // YouTube link
  444. '/http:\/\/youtu\.be\/([a-zA-Z0-9_\-]+)/i', // YouTube link too
  445. "#([\n\t \(])([a-z]+?)://([a-z0-9_\-\.\~\/@&;:=%$\?]+)#ie", /* make URL clickable */
  446. "#([\n\t \(])www\.([a-z0-9\-]+)\.([a-z0-9_\-\.\~]+)((?:/[^,< \r\n\)]*)?)#ie", /* web server */
  447. "/\n[ \t]*(From|To|cc|bcc|Subject|Date):(\s*)/i", /* common message headers */
  448. "|\n[ \t]*-(\s+)|i", /* - list item > */
  449. "|\n[ \t]*>(\s*)|i", /* quoted by > */
  450. "|\n[ \t]*\|(\s*)|i", /* quoted by | */
  451. "#([\n\t ])(mailto:|)([a-z0-9_\-\.\~]+?)@([a-z0-9_\-\.\~]+\.[a-z0-9_\-\.\~]+)([\n\t ]*)#ie" /* mail address*/
  452. );
  453. $replace = array(
  454. "</h1>",
  455. "</h2>",
  456. "</h3>",
  457. "</h4>",
  458. '<iframe class="youtube-player" type="text/html" width="445" height="364" src="http://www.youtube.com/embed/$1" frameborder="0"></iframe>', // YouTube link
  459. '<iframe class="youtube-player" type="text/html" width="445" height="364" src="http://www.youtube.com/embed/$1" frameborder="0"></iframe>', // YouTube link too
  460. "'$1'.Skin::build_link('$2://$3', '$2://$3')",
  461. "'$1'.Skin::build_link('http://www.$2.$3$4', 'www.$2.$3$4')",
  462. BR."$1:$2",
  463. BR."-$1",
  464. BR.">$1",
  465. BR."|$1",
  466. "'$1'.Skin::build_link('mailto:$3@$4', '$3@$4', 'email').'$5'"
  467. );
  468. }
  469. // preserve escaped areas
  470. $text = str_replace(array('[escape]', '[/escape]', '[list]', '[/list]', '[php]', '[/php]', '[snippet]', '[/snippet]'),
  471. array('<escape>', '</escape>', '<list>', '</list>', '<php>', '</php>', '<snippet>', '</snippet>'), $text);
  472. // locate pre-formatted areas
  473. $areas = preg_split('#<(code|escape|list|php|snippet|pre)>(.*?)</\1>#is', trim($text), -1, PREG_SPLIT_DELIM_CAPTURE);
  474. // format only adequate areas
  475. $index = 0;
  476. $formatted = '';
  477. $inside = FALSE;
  478. $target = '';
  479. foreach($areas as $area) {
  480. switch($index%3) {
  481. case 0: // area to be formatted
  482. // do not rewrite tags
  483. $items = preg_split('/<(.+?)>/is', $area, -1, PREG_SPLIT_DELIM_CAPTURE);
  484. $where = 0;
  485. foreach($items as $item) {
  486. switch($where%2) {
  487. case 0: // outside a tag
  488. if($inside)
  489. $target .= $item;
  490. else
  491. $formatted .= preg_replace($search, $replace, $item);
  492. break;
  493. case 1: // inside a tag
  494. // inside or outside a link
  495. if($inside && !strncmp($item, '/a', 2)) {
  496. $formatted .= preg_replace($search, $replace, $target).'<'.$item.'>';
  497. $target = '';
  498. $inside = FALSE;
  499. } elseif($inside)
  500. $target .= '<'.$item.'>';
  501. elseif(!strncmp($item, 'a ', 2)) {
  502. $formatted .= '<'.$item.'>';
  503. $inside = TRUE;
  504. } else
  505. $formatted .= '<'.$item.'>';
  506. break;
  507. }
  508. $where++;
  509. }
  510. break;
  511. case 1: // area boundary
  512. $tag = $area;
  513. break;
  514. case 2: // pre-formatted area - left unmodified
  515. // inside a link, or regular text
  516. if($inside)
  517. $target .= '<'.$tag.'>'.$area.'</'.$tag.'>';
  518. else
  519. $formatted .= '<'.$tag.'>'.$area.'</'.$tag.'>';
  520. break;
  521. }
  522. $index++;
  523. }
  524. // post-optimization
  525. if($variant == 'text')
  526. $formatted = preg_replace('#</ul>\n{0,1}<ul>#', '', $formatted);
  527. $formatted = preg_replace('#\n\n+<ul#', "\n<ul", $formatted);
  528. // restore escaped areas
  529. $formatted = str_replace(array('<escape>', '</escape>', '<list>', '</list>', '<php>', '</php>', '<snippet>', '</snippet>'),
  530. array('[escape]', '[/escape]', '[list]', '[/list]', '[php]', '[/php]', '[snippet]', '[/snippet]'), $formatted);
  531. return $formatted;
  532. }
  533. /**
  534. * format an introduction
  535. *
  536. * @param string raw introduction
  537. * @return string finalized title
  538. */
  539. public static function &beautify_introduction($text) {
  540. // render codes
  541. $output =& Codes::render($text);
  542. // render smileys after codes, else it will break escaped strings
  543. if(is_callable(array('Smileys', 'render_smileys')))
  544. $output = Smileys::render_smileys($output);
  545. // return by reference
  546. return $output;
  547. }
  548. /**
  549. * format a title
  550. *
  551. * New lines and images are the only things accepted in titles.
  552. * The goal is to provide a faster service than beautify()
  553. *
  554. * @param string raw title
  555. * @return string finalized title
  556. */
  557. public static function &beautify_title($text) {
  558. // suppress pairing codes
  559. $output =& Codes::strip($text, FALSE);
  560. // the only code transformed in titles
  561. $output = str_replace(array('[nl]', '[NL]'), '<br />', $output);
  562. // remove everything, except links, breaks and images, and selected tags
  563. $output = strip_tags($output, '<a><abbr><acronym><b><big><br><code><del><div><dfn><em><i><img><ins><p><q><small><span><strong><sub><sup><tt><u>');
  564. // return by reference
  565. return $output;
  566. }
  567. /**
  568. * determine if a code is already in some text
  569. *
  570. * @param string the text to check
  571. * @param string code to check (e.g., 'embed')
  572. * @param int the id of the object
  573. * @return boolean TRUE if the code is present, false otherwise
  574. */
  575. public static function check_embedded($text, $code, $id) {
  576. // we check the string of digits
  577. $id = strval($id);
  578. // parse the full string
  579. $count = strlen($text);
  580. $position = 0;
  581. // look for '[embed' or similar
  582. while(($position = strpos($text, '['.$code, $position)) !== FALSE) {
  583. $position += 1+strlen($code);
  584. // parse remaining chars
  585. while($position < $count) {
  586. // digits just follow the '=' sign
  587. if($text[$position] == '=') {
  588. $position++;
  589. // exact match
  590. if(($position + 2 + strlen($id) < $count) && !strcmp(substr($text, $position, strlen($id)), $id))
  591. return TRUE;
  592. // not in this code, look at next one
  593. break;
  594. // malformed code
  595. } elseif($text[$position] == ']') {
  596. $position++;
  597. break;
  598. }
  599. // next char
  600. $position++;
  601. }
  602. }
  603. // not found
  604. return FALSE;
  605. }
  606. /**
  607. * delete a code if it is present in some text
  608. *
  609. * @param string the text to check
  610. * @param string code to check (e.g., 'embed')
  611. * @param int the id of the object
  612. * @return string the resulting string
  613. */
  614. public static function delete_embedded($text, $code, $id) {
  615. // we check the string of digits
  616. $id = strval($id);
  617. // parse the full string
  618. $count = strlen($text);
  619. $position = 0;
  620. // look for '[embed' or similar
  621. while(($position = strpos($text, '['.$code, $position)) !== FALSE) {
  622. // we have to take everything before that point
  623. $prefix = $position;
  624. // next char
  625. $position += 1+strlen($code);
  626. // parse remaining chars
  627. while($position < $count) {
  628. // digits just follow the '=' sign
  629. if($text[$position] == '=') {
  630. $position++;
  631. // exact match
  632. if(($position + strlen($id) <= $count) && !strcmp(substr($text, $position, strlen($id)), $id)) {
  633. $position += strlen($id);
  634. // look for ']'
  635. while($position < $count) {
  636. if($text[$position] == ']') {
  637. $position++;
  638. break;
  639. }
  640. $position++;
  641. }
  642. // do the deletion
  643. $modified = '';
  644. if($prefix > 0)
  645. $modified .= substr($text, 0, $prefix);
  646. if($position < $count)
  647. $modified .= substr($text, $position, $count-$position);
  648. return $modified;
  649. }
  650. // not in this code, look at next one
  651. break;
  652. // malformed code
  653. } elseif($text[$position] == ']') {
  654. $position++;
  655. break;
  656. }
  657. // next char
  658. $position++;
  659. }
  660. }
  661. // not found
  662. return $text;
  663. }
  664. /**
  665. * fix line breaks
  666. *
  667. * This function moves unclosed tags to the beginning of content.
  668. *
  669. * @param string input
  670. * @return string original or modified content
  671. */
  672. public static function &fix_tags($text) {
  673. // look for opening tag at content end
  674. $last_open = strrpos($text, '<p>');
  675. $last_close = strrpos($text, '</p');
  676. if($last_open && (($last_close === FALSE) || ($last_open > $last_close))) {
  677. // trail
  678. $trail = '';
  679. if(strlen($text) > $last_open + 3)
  680. $trail = substr($text, $last_open + 3);
  681. // move it to content start to restore pairing tags
  682. $text = '<p>'.substr($text, 0, $last_open).$trail;
  683. }
  684. // also fix broken img tags, if any
  685. $text = preg_replace('#<(img[^</]+)>#i', '<$1 />', $text);
  686. // remove slashes added by preg_replace -- only for double quotes
  687. $text = str_replace('\"', '"', $text);
  688. // done
  689. return $text;
  690. }
  691. /**
  692. * reset global variables used for rendering
  693. *
  694. * This function should be called between the processing of different articles in a loop
  695. *
  696. * @param string the target URL for this rendering (e.g., 'articles/view.php/123')
  697. */
  698. public static function initialize($main_target=NULL) {
  699. global $context;
  700. if($main_target)
  701. $context['self_url'] = $context['url_to_root'].$main_target;
  702. }
  703. /**
  704. * list all ids matching some code
  705. *
  706. * @param string the text to check
  707. * @param string code to check (e.g., 'embed')
  708. * @return array the list of matching ids
  709. */
  710. public static function list_embedded($text, $code='embed') {
  711. // all ids we have found
  712. $ids = array();
  713. // parse the full string
  714. $count = strlen($text);
  715. $position = 0;
  716. // look for '[embed' or similar
  717. while(($position = strpos($text, '['.$code, $position)) !== FALSE) {
  718. $position += 1+strlen($code);
  719. // parse remaining chars
  720. while($position < $count) {
  721. // digits just follow the '=' sign
  722. if($text[$position] == '=') {
  723. $position++;
  724. // capture all digits
  725. $id = '';
  726. while($position < $count) {
  727. if(($text[$position] >= '0') && ($text[$position] <= '9')) {
  728. $id .= $text[$position];
  729. $position++;
  730. } else
  731. break;
  732. }
  733. // save this id
  734. if(strlen($id))
  735. $ids[] = $id;
  736. // look at next code
  737. break;
  738. // malformed code
  739. } elseif($text[$position] == ']') {
  740. $position++;
  741. break;
  742. }
  743. // next char
  744. $position++;
  745. }
  746. }
  747. // job done
  748. return $ids;
  749. }
  750. /**
  751. * transform codes to html
  752. *
  753. * [php]
  754. * // build the page
  755. * $context['text'] .= ...
  756. *
  757. * // transform codes
  758. * $context['text'] = Codes::render($context['text']);
  759. *
  760. * // final rendering
  761. * render_skin();
  762. * [/php]
  763. *
  764. * @link http://pureform.wordpress.com/2008/01/04/matching-a-word-characters-outside-of-html-tags/
  765. *
  766. * @param string the input string
  767. * @return string the transformed string
  768. */
  769. public static function &render($text) {
  770. global $context;
  771. // streamline newlines, even if this has been done elsewhere
  772. $text = str_replace(array("\r\n", "\r"), "\n", $text);
  773. // prevent wysiwyg editors to bracket our own tags
  774. $text = preg_replace('#^<p>(\[.+\])</p>$#m', '$1', $text);
  775. // initialize only once
  776. static $pattern;
  777. if(!isset($pattern)) {
  778. // $pattern[] = ;
  779. // $replace[] = ;
  780. //
  781. // $pattern[] = ;
  782. // $replace[] = ;
  783. //
  784. // $pattern[] = ;
  785. // $replace[] = ;
  786. //
  787. // $pattern[] = ;
  788. // $replace[] = ;
  789. //
  790. // $pattern[] = ;
  791. // $replace[] = ;
  792. $pattern = array(
  793. "|<!-- .* -->|i", // remove HTML comments
  794. '/\[escape\](.*?)\[\/escape\]/ise', // [escape]...[/escape] (before everything)
  795. '/\[php\](.*?)\[\/php\]/ise', // [php]...[/php]
  796. '/\[snippet\](.*?)\[\/snippet\]/ise', // [snippet]...[/snippet]
  797. '/(\[page\].*)$/is', // [page] (provide only the first one)
  798. '/\[associate\](.*?)\[\/associate\]/ise', // [associate]...[/associate] (save some cycles if at the beginning)
  799. '/\[hidden\](.*?)\[\/hidden\]/ise', // [hidden]...[/hidden] obsolete, replaced by [associate]...[/associate]
  800. '/\[authenticated\](.*?)\[\/authenticated\]/ise', // [authenticated]...[/authenticated] (save some cycles if at the beginning)
  801. '/\[restricted\](.*?)\[\/restricted\]/ise', // [restricted]...[/restricted] obsolete, replaced by [authenticated]...[/authenticated]
  802. '/\[anonymous\](.*?)\[\/anonymous\]/ise', // [anonymous]...[/anonymous] (save some cycles if at the beginning)
  803. '/\[redirect=([^\]]+?)\]/ise', // [redirect=<link>]
  804. '/\[execute=([^\]]+?)\]/ise', // [execute=<name>]
  805. '/\[parameter=([^\]]+?)\]/ise', // [parameter=<name>]
  806. '/\[lang=([^\]]+?)\](.*?)\[\/lang\]/ise', // [lang=xy]...[/lang]
  807. '/\[csv=(.)\](.*?)\[\/csv\]/ise', // [csv=;]...[/csv] (before [table])
  808. '/\[csv\](.*?)\[\/csv\]/ise', // [csv]...[/csv] (before [table])
  809. '/\[table=([^\]]+?)\](.*?)\[\/table\]/ise', // [table=variant]...[/table]
  810. '/\[table\](.*?)\[\/table\]/ise', // [table]...[/table]
  811. '/\[images=([^\]]+?)\]/ie', // [images=<ids>] (before other links)
  812. '/\[image\](.*?)\[\/image\]/ise', // [image]src[/image]
  813. '/\[image=([^\]]+?)\](.*?)\[\/image\]/ise', // [image=alt]src[/image]
  814. '/\[img\](.*?)\[\/img\]/ise', // [img]src[/img]
  815. '/\[img=([^\]]+?)\](.*?)\[\/img\]/ise', // [img=alt]src[/img]
  816. '/\[image=([^\]]+?)\]/ie', // [image=<id>]
  817. '/##(\S.*?\S)##/is', // ##...##
  818. '/\[code\](.*?)\[\/code\]/is', // [code]...[/code]
  819. '/\[indent\](.*?)\[\/indent\]/ise', // [indent]...[/indent]
  820. '/\[quote\](.*?)\[\/quote\]/ise', // [quote]...[/quote]
  821. '/\[folded=([^\]]+?)\](.*?)\[\/folded\]\s*/ise', // [folded=...]...[/folded]
  822. '/\[folded\](.*?)\[\/folded\]\s*/ise', // [folded]...[/folded]
  823. '/\[folder=([^\]]+?)\](.*?)\[\/folder\]\s*/ise', // [folder=...]...[/folder]
  824. '/\[folder\](.*?)\[\/folder\]\s*/ise', // [folder]...[/folder]
  825. '/\[unfolded=([^\]]+?)\](.*?)\[\/unfolded\]\s*/ise', // [unfolded=...]...[/unfolded]
  826. '/\[unfolded\](.*?)\[\/unfolded\]\s*/ise', // [unfolded]...[/unfolded]
  827. '/\[sidebar=([^\]]+?)\](.*?)\[\/sidebar\]\s*/ise', // [sidebar=...]...[/sidebar]
  828. '/\[sidebar\](.*?)\[\/sidebar\]\s*/ise', // [sidebar]...[/sidebar]
  829. '/\[note\](.*?)\[\/note\]\s*/ise', // [note]...[/note]
  830. '/\[caution\](.*?)\[\/caution\]\s*/ise', // [caution]...[/caution]
  831. '/\[search=([^\]]+?)\]/ise', // [search=words]
  832. '/\[search\]/ise', // [search]
  833. '/\[cloud=(\d+?)\]/ise', // [cloud=12]
  834. '/\[cloud\]/ise', // [cloud]
  835. '/\[login=([^\]]+?)\]/is', // [login=words] --obsoleted
  836. '/\[login\]/is', // [login] --obsoleted
  837. '/\[center\](.*?)\[\/center\]/ise', // [center]...[/center]
  838. '/\[right\](.*?)\[\/right\]/ise', // [right]...[/right]
  839. '/\[decorated\](.*?)\[\/decorated\]/ise',// [decorated]...[/decorated]
  840. '/\[style=([^\]]+?)\](.*?)\[\/style\]/ise', // [style=variant]...[/style]
  841. '/\[hint=([^\]]+?)\](.*?)\[\/hint\]/is', // [hint=help]...[/hint]
  842. '/\[tiny\](.*?)\[\/tiny\]/ise', // [tiny]...[/tiny]
  843. '/\[small\](.*?)\[\/small\]/ise', // [small]...[/small]
  844. '/\[big\](.*?)\[\/big\]/ise', // [big]...[/big]
  845. '/\[huge\](.*?)\[\/huge\]/ise', // [huge]...[/huge]
  846. '/\[subscript\](.*?)\[\/subscript\]/is',// [subscript]...[/subscript]
  847. '/\[superscript\](.*?)\[\/superscript\]/is',// [superscript]...[/superscript]
  848. '/\+\+(\S.*?\S)\+\+(?!([^<]+)?>)/is', // ++...++
  849. '/\[(---+|___+)\]\s*/ise', // [---], [___] --- before inserted
  850. '/^-----*/me', // ----
  851. '/\[inserted\](.*?)\[\/inserted\]/is', // [inserted]...[/inserted]
  852. '/ --(\S.*?\S)--(?!([^<]+)?>)/is', // --...--
  853. '/\[deleted\](.*?)\[\/deleted\]/is', // [deleted]...[/deleted]
  854. '/\*\*(\S.*?\S)\*\*/is', // **...**
  855. '/\[b\](.*?)\[\/b\]/is', // [b]...[/b]
  856. '/ \/\/(\S.*?\w)\/\/(?!([^<]+)?>)/is', // //...//
  857. '/\[i\](.*?)\[\/i\]/is', // [i]...[/i]
  858. '/__(\S.*?\S)__(?!([^<]+)?>)/is', // __...__
  859. '/\[u\](.*?)\[\/u\]/is', // [u]...[/u]
  860. '/\[color=([^\]]+?)\](.*?)\[\/color\]/is', // [color=<color>]...[/color]
  861. '/\[new\]/ie', // [new]
  862. '/\[popular\]/ie', // [popular]
  863. '/\[flag=([^\]]+?)\]/ie', // [flag=<flag>]
  864. '/\[flag\](.*?)\[\/flag\]/ise', // [flag]...[/flag]
  865. '/\[list\](.*?)\[\/list\]/ise', // [list]...[/list]
  866. '/\[list=([^\]]+?)\](.*?)\[\/list\]/ise', // [list=1]...[/list]
  867. '/\n\n+[ \t]*\[\*\][ \t]*/ie', // [*] (outside [list]...[/list])
  868. '/\n?[ \t]*\[\*\][ \t]*/ie',
  869. '/\[li\](.*?)\[\/li\]/is', // [li]...[/li] (outside [list]...[/list])
  870. '/\[chart=([^\]]+?)\](.*?)\[\/chart\]/ise', // [chart=<width>, <height>, <params>]...[/chart]
  871. '/\[embed=([^\]]+?)\]/ie', // [embed=<id>, <width>, <height>, <params>] or [embed=<id>, window]
  872. '/\[flash=([^\]]+?)\]/ie', // [flash=<id>, <width>, <height>, <params>] or [flash=<id>, window]
  873. '/\[sound=([^\]]+?)\]/ie', // [sound=<id>]
  874. '/\[go=([^\]]+?)\]/ie', // [go=<name>]
  875. '/\[\[([^\]]+?)\]\]/ie', // [[<name>]]
  876. '/\[article\.description=([^\]]+?)\]/ie', // [article.description=<id>]
  877. '/\[article=([^\]]+?)\]/ie', // [article=<id>] or [article=<id>, title]
  878. '/\[next=([^\]]+?)\]/ie', // [next=<id>]
  879. '/\[previous=([^\]]+?)\]/ie', // [previous=<id>]
  880. '/\[random\]/ie', // [random]
  881. '/\[random\.description=([^\]]+?)\]/ie', // [random.description=section:<id>]
  882. '/\[random=([^\]]+?)\]/ie', // [random=section:<id>] or [random=category:<id>]
  883. '/\[form=([^\]]+?)\]/ie', // [form=<id>] or [form=<id>, title]
  884. '/\[section=([^\]]+?)\]/ie', // [section=<id>] or [section=<id>, title]
  885. '/\[category\.description=([^\]]+?)\]\n*/ise', // [category.description=<id>]
  886. '/\[category=([^\]]+?)\]/ie', // [category=<id>] or [category=<id>, title]
  887. '/\[user=([^\]]+?)\]/ie', // [user=<id>] or [user=<id>, title]
  888. '/\[server=([^\]]+?)\]/ie', // [server=<id>]
  889. '/\[file=([^\]]+?)\]/ie', // [file=<id>] or [file=<id>, title]
  890. '/\[download=([^\]]+?)\]/ie', // [download=<id>] or [download=<id>, title]
  891. '/\[comment=([^\]]+?)\]/ie', // [comment=<id>] or [comment=<id>, title]
  892. '/\[url=([^\]]+?)\](.*?)\[\/url\]/ise', // [url=url]label[/url] (deprecated by [link])
  893. '/\[url\](.*?)\[\/url\]/ise', // [url]url[/url] (deprecated by [link])
  894. '/\[link=([^\]]+?)\](.*?)\[\/link\]/ise', // [link=label]url[/link]
  895. '/\[link\](.*?)\[\/link\]/ise', // [link]url[/link]
  896. '/\[proxy\](.*?)\[\/proxy\]/ise', // [proxy]url[/proxy]
  897. '/\[button=([^\]]+?)\](.*?)\[\/button\]/ise', // [button=label]url[/button]
  898. '/\[button=([^\|]+?)\|([^\]]+?)]/ise', // [button=label|url]
  899. '/\[click=([^\|]+?)\|([^\]]+?)]/ise', // [click=label|url]
  900. '/\[clicks=([^\]]+?)]/ise', // [clicks=url]
  901. '/\[script\](.*?)\[\/script\]/ise', // [script]url[/script]
  902. '/\[menu\](.*?)\[\/menu\]\n*/ise', // [menu]url[/menu]
  903. '/\[menu=([^\]]+?)\](.*?)\[\/menu\]\n{0,1}/ise', // [menu=label]url[/menu]
  904. '/\[submenu\](.*?)\[\/submenu\]\n{0,1}/ise', // [submenu]url[/submenu]
  905. '/\[submenu=([^\]]+?)\](.*?)\[\/submenu\]\n*/ise', // [submenu=label]url[/submenu]
  906. '/\[email=([^\]]+?)\](.*?)\[\/email\]/ise', // [email=label]url[/email]
  907. '/\[email\](.*?)\[\/email\]/ise', // [email]url[/email]
  908. '/\[([^ ][^\]\|]+?[^ ])\|([^ ][^\]]+?[^ ])\]/ise', // [label|url]
  909. '/\[question\](.*?)\[\/question\]\n*/ise', // [question]...[/question]
  910. '/\[question\]/ise', // [question]
  911. '/\[answer\]/ise', // [answer]
  912. '/\[newsfeed=([^\]]+?)\]/ise', // [newsfeed=url]
  913. '/\[newsfeed\.([^=\]]+?)=([^\]]+?)\]/ise', // [newsfeed.variant=url]
  914. '/\[twitter=([^\]]+?)\]/ise', // [twitter=id]
  915. '/\[tsearch=([^\]]+?)\]/ise', // [tsearch=id]
  916. '/\[retweet\]/ise', // [retweet]
  917. '/\[iframe\](.*?)\[\/iframe\]/ise', // [iframe]<url>[/iframe]
  918. '/\[iframe=([^\]]+?)\](.*?)\[\/iframe\]/ise', // [iframe=<width>, <height>]<url>[/iframe]
  919. '/\[scroller\](.*?)\[\/scroller\]/ise', // [scroller]...[/scroller]
  920. '/\[toq\]\n*/ise', // [toq] (table of questions)
  921. '/\[title\](.*?)\[\/title\]\n*/is', // [title]...[/title]
  922. '/\[subtitle\](.*?)\[\/subtitle\]\n*/is', // [subtitle]...[/subtitle]
  923. '#\[(header[1-5])\](.*?)\[/\1\]\n*#ise', // [header1]...[/header1] ... [header5]...[/header5]
  924. '/^======(\S.*?\S)======/me', // ======...====== level 5 headline
  925. '/<(br \/|p)>======(\S.*?\S)======<(br \/|\/p)>/me', // ======...====== level 5 headline
  926. '/^=====(\S.*?\S)=====/me', // =====...===== level 4 headline
  927. '/<(br \/|p)>=====(\S.*?\S)=====<(br \/|\/p)>/me', // =====...===== level 4 headline
  928. '/^====(\S.*?\S)====/me', // ====...==== level 3 headline
  929. '/<(br \/|p)>====(\S.*?\S)====<(br \/|\/p)>/me', // ====...==== level 3 headline
  930. '/^===(\S.*?\S)===/me', // ===...=== level 2 headline
  931. '/<(br \/|p)>===(\S.*?\S)===<(br \/|\/p)>/me', // ===...=== level 2 headline
  932. '/^==(\S.*?\S)==/me', // ==...== level 1 headline
  933. '/<(br \/|p)>==(\S.*?\S)==<(br \/|\/p)>/me', // ==...== level 1 headline
  934. '/\[toc\]\n*/ise', // [toc] (table of content)
  935. '/\[published\.([^\]=]+?)=([^\]]+?)\]\n*/ise', // [published.decorated=section:4029]
  936. '/\[published\.([^\]]+?)\]\n*/ise', // [published.decorated]
  937. '/\[published=([^\]]+?)\]\n*/ise', // [published=section:4029]
  938. '/\[published\]\n*/ise', // [published]
  939. '/\[read\.([^\]=]+?)=([^\]]+?)\]\n*/ise', // [read.decorated=section:4029]
  940. '/\[read\.([^\]]+?)\]\n*/ise', // [read.decorated]
  941. '/\[read=([^\]]+?)\]\n*/ise', // [read=section:4029]
  942. '/\[read\]\n*/ise', // [read]
  943. '/\[updated\.([^\]=]+?)=([^\]]+?)\]\n*/ise', // [updated.simple=section:4029] (a list of recent updates)
  944. '/\[updated\.([^\]]+?)\]\n*/ise', // [updated.simple] (a list of recent updates)
  945. '/\[updated=([^\]]+?)\]\n*/ise', // [updated=section:4029] (a compact list of recent updates)
  946. '/\[updated\]\n*/ise', // [updated] (a compact list of recent updates)
  947. '/\[voted\.([^\]=]+?)=([^\]]+?)\]\n*/ise', // [voted.decorated=section:4029]
  948. '/\[voted\.([^\]]+?)\]\n*/ise', // [voted.decorated]
  949. '/\[voted=([^\]]+?)\]\n*/ise', // [voted=section:4029]
  950. '/\[voted\]\n*/ise', // [voted]
  951. '/\[sections\]\n*/ise', // [sections] (site map)
  952. '/\[sections\.([^\]=]+?)\]\n*/ise', // [sections.folded] (site map)
  953. '/\[sections=([^\]]+?)\]\n*/ise', // [sections=section:4029] (sub-sections)
  954. '/\[sections\.([^\]=]+?)=([^\]]+?)\]\n*/ise', // [sections.simple=self] (assigned)
  955. '/\[categories\]\n*/ise', // [categories] (category tree)
  956. '/\[categories\.([^\]=]+?)\]\n*/ise', // [categories.folded] (category tree)
  957. '/\[categories=([^\]]+?)\]\n*/ise', // [categories=section:4029] (sub-categories)
  958. '/\[categories\.([^\]=]+?)=([^\]]+?)\]\n*/ise', // [categories.simple=self] (assigned)
  959. '/\[calendar\]\n*/ise', // [calendar]
  960. '/\[calendar=([^\]]+?)\]\n*/ise', // [calendar=section:4029]
  961. '/\[users=([^\]]+?)\]/ie', // [users=present]
  962. '/\[news=([^\]]+?)\]/ise', // [news=flash]
  963. '/\[table=([^\]]+?)\]/ise', // [table=<id>]
  964. '/\[table\.([^=\]]+?)=([^\]]+?)\]/ise', // [table.json=<id>] [table.timeplot=<id>]
  965. '/\[locations=([^\]]+?)\]/ise', // [locations=<id>]
  966. '/\[location=([^\]]+?)\]/ise', // [location=<id>]
  967. '/\[wikipedia=([^\]]+?)\]/ise', // [wikipedia=keyword] or [wikipedia=keyword, title]
  968. '/\[digraph\](.*?)\[\/digraph\]/ise', // [digraph]url[/digraph]
  969. '/\[be\]/i', // [be] belgian flag
  970. '/\[ca\]/i', // [ca] canadian flag
  971. '/\[ch\]/i', // [ch] swiss flag
  972. '/\[de\]/i', // [de] german flag
  973. '/\[en\]/i', // [en] english flag
  974. '/\[es\]/i', // [es] spanish flag
  975. '/\[fr\]/i', // [fr] french flag
  976. '/\[gb\]/i', // [gb] gb flag
  977. '/\[gr\]/i', // [gr] greek flag
  978. '/\[it\]/i', // [it] italian flag
  979. '/\[pt\]/i', // [pt] portuguese flag
  980. '/\[us\]/i', // [pt] us flag
  981. '/\[clear\]\n*/i', // [clear]
  982. '/\[nl\]\n*/si', // [nl] (after tables)
  983. '/\[br\]/i' // [br] (deprecated by [nl])
  984. );
  985. }
  986. // initialize only once
  987. static $replace;
  988. if(!isset($replace)) {
  989. $replace = array(
  990. '', // delete HTML comments
  991. "Codes::render_escaped(Codes::fix_tags('$1'))", // [escape]...[/escape]
  992. "Codes::render_pre(Codes::fix_tags('$1'), 'php')", // [php]...[/php]
  993. "Codes::render_pre(Codes::fix_tags('$1'), 'snippet')", // [snippet]...[/snippet]
  994. '', // [page]
  995. "Codes::render_hidden(Codes::fix_tags('$1'), 'associate')", // [associate]...[/associate]
  996. "Codes::render_hidden(Codes::fix_tags('$1'), 'associate')", // [hidden]...[/hidden]
  997. "Codes::render_hidden(Codes::fix_tags('$1'), 'authenticated')", // [authenticated]...[/authenticated]
  998. "Codes::render_hidden(Codes::fix_tags('$1'), 'authenticated')", // [restricted]...[/restricted]
  999. "Codes::render_hidden(Codes::fix_tags('$1'), 'anonymous')", // [anonymous]...[/anonymous]
  1000. "Codes::render_redirect('$1')", // [redirect=<link>]
  1001. "Codes::render_execute('$1')", // [execute=<name>]
  1002. "Codes::render_parameter('$1')", // [parameter=<name>]
  1003. "i18n::filter(Codes::fix_tags('$2'), '$1')", // [lang=xy]...[/lang]
  1004. "utf8::encode(str_replace('$1', '|', utf8::from_unicode(Codes::fix_tags('$2'))))", // [csv=;]...[/csv]
  1005. "str_replace(',', '|', Codes::fix_tags('$1'))", // [csv]...[/csv]
  1006. "Codes::render_static_table(Codes::fix_tags('$2'), '$1')", // [table=variant]...[/table]
  1007. "Codes::render_static_table(Codes::fix_tags('$1'), '')", // [table]...[/table]
  1008. "Codes::render_object('images', '$1')", // [images=<ids>]
  1009. "'<div class=\"external_image\"><img src=\"'.encode_link('$1').'\" alt=\"\" /></div>'", // [image]src[/image]
  1010. "'<div class=\"external_image\"><img src=\"'.encode_link('$2').'\" alt=\"'.encode_link('$1').'\" /></div>'", // [image=alt]src[/image]
  1011. "'<div class=\"external_image\"><img src=\"'.encode_link('$1').'\" alt=\"\" /></div>'", // [img]src[/img]
  1012. "'<div class=\"external_image\"><img src=\"'.encode_link('$2').'\" alt=\"'.encode_link('$1').'\" /></div>'", // [img=alt]src[/img]
  1013. "Codes::render_object('image', Codes::fix_tags('$1'))", // [image=<id>]
  1014. '<code>$1</code>', // ##...##
  1015. '<code>$1</code>', // [code]...[/code]
  1016. "Skin::build_block(Codes::fix_tags('$1'), 'indent')", // [indent]...[indent]
  1017. "Skin::build_block(Codes::fix_tags('$1'), 'quote')", // [quote]...[/quote]
  1018. "Skin::build_box('$1', Codes::fix_tags('$2'), 'folded')", // [folded=title]...[/folded]
  1019. "Skin::build_box(NULL, Codes::fix_tags('$1'), 'folded')", // [folded]...[/folded]
  1020. "Skin::build_box('$1', Codes::fix_tags('$2'), 'folded')", // [folder=title]...[/folder]
  1021. "Skin::build_box(NULL, Codes::fix_tags('$1'), 'folded')", // [folder]...[/folder]
  1022. "Skin::build_box('$1', Codes::fix_tags('$2'), 'unfolded')", // [unfolded=title]...[/unfolded]
  1023. "Skin::build_box(NULL, Codes::fix_tags('$1'), 'unfolded')", // [unfolded]...[/unfolded]
  1024. "Skin::build_box('$1', Codes::fix_tags('$2'), 'sidebar')", // [sidebar=title]...[/sidebar]
  1025. "Skin::build_box(NULL, Codes::fix_tags('$1'), 'sidebar')", // [sidebar]...[/sidebar]
  1026. "Skin::build_block(Codes::fix_tags('$1'), 'note')", // [note]...[/note]
  1027. "Skin::build_block(Codes::fix_tags('$1'), 'caution')", // [caution]...[/caution]
  1028. "Skin::build_block('$1', 'search')", // [search=<words>]
  1029. "Skin::build_block(NULL, 'search')", // [search]
  1030. "Codes::render_cloud('$1')", // [cloud=12]
  1031. "Codes::render_cloud(20)", // [cloud]
  1032. '', // [login=<words>] --obsoleted
  1033. '', // [login] --obsoleted
  1034. "Skin::build_block(Codes::fix_tags('$1'), 'center')", // [center]...[/center]
  1035. "Skin::build_block(Codes::fix_tags('$1'), 'right')", // [right]...[/right]
  1036. "Skin::build_block(Codes::fix_tags('$1'), 'decorated')", // [decorated]...[/decorated]
  1037. "Skin::build_block(Codes::fix_tags('$2'), '$1')", // [style=variant]...[/style]
  1038. '<acronym title="$1">$2</acronym>', // [hint=help]...[/hint]
  1039. "Skin::build_block(Codes::fix_tags('$1'), 'tiny')", // [tiny]...[/tiny]
  1040. "Skin::build_block(Codes::fix_tags('$1'), 'small')", // [small]...[/small]
  1041. "Skin::build_block(Codes::fix_tags('$1'), 'big')", // [big]...[/big]
  1042. "Skin::build_block(Codes::fix_tags('$1'), 'huge')", // [huge]...[/huge]
  1043. '<sub>$1</sub>', // [subscript]...[/subscript]
  1044. '<sup>$1</sup>', // [superscript]...[/superscript]
  1045. '<ins>$1</ins>', // ++...++
  1046. "HORIZONTAL_RULER", // [---], [___]
  1047. "HORIZONTAL_RULER", // ----
  1048. '<ins>$1</ins>', // [inserted]...[/inserted]
  1049. ' <del>$1</del>', // --...--
  1050. '<del>$1</del>', // [deleted]...[/deleted]
  1051. '<b>$1</b>', // **...**
  1052. '<b>$1</b>', // [b]...[/b]
  1053. ' <i>$1</i>', // //...//
  1054. '<i>$1</i>', // [i]...[/i]
  1055. '<span style="text-decoration: underline">$1</span>', // __...__
  1056. '<span style="text-decoration: underline">$1</span>', // [u]...[/u]
  1057. '<span style="color: $1">$2</span>', // [color]...[/color]
  1058. "NEW_FLAG", // [new]
  1059. "POPULAR_FLAG", // [popular]
  1060. "Skin::build_flag('$1')", // [flag=....]
  1061. "Skin::build_flag('$1')", // [flag]...[/flag]
  1062. "Codes::render_list(Codes::fix_tags('$1'), NULL)", // [list]...[/list]
  1063. "Codes::render_list(Codes::fix_tags('$2'), '$1')", // [list=?]...[/list]
  1064. "BR.BR.BULLET_IMG.'&nbsp;'", // standalone [*]
  1065. "BR.BULLET_IMG.'&nbsp;'",
  1066. '<li>$1</li>', // [li]...[/li]
  1067. "Codes::render_chart(Codes::fix_tags('$2'), '$1')", // [chart=<width>, <height>, <params>]...[/chart]
  1068. "Codes::render_embed(Codes::fix_tags('$1'))", // [embed=<id>, <width>, <height>, <params>]
  1069. "Codes::render_embed(Codes::fix_tags('$1'))", // [flash=<id>, <width>, <height>, <params>] -- obsoleted by 'embed'
  1070. "Codes::render_object('sound', Codes::fix_tags('$1'))", // [sound=<id>]
  1071. "Codes::render_object('go', Codes::fix_tags('$1'))", // [go=<name>]
  1072. "Codes::render_object('go', Codes::fix_tags('$1'))", // [[<name>]]
  1073. "Codes::render_object('article.description', Codes::fix_tags('$1'))",// [article.description=<id>]
  1074. "Codes::render_object('article', Codes::fix_tags('$1'))", // [article=<id>]
  1075. "Codes::render_object('next', Codes::fix_tags('$1'))", // [next=<id>]
  1076. "Codes::render_object('previous', Codes::fix_tags('$1'))", // [previous=<id>]
  1077. "Codes::render_random()", // [random]
  1078. "Codes::render_random('$1', 'description')", // [random.description=section:<id>]
  1079. "Codes::render_random('$1')", // [random=section:<id>]
  1080. "Codes::render_object('form', Codes::fix_tags('$1'))", // [form=<id>]
  1081. "Codes::render_object('section', Codes::fix_tags('$1'))", // [section=<id>]
  1082. "Codes::render_object('category.description', '$1')", // [category.description=<id>]
  1083. "Codes::render_object('category', Codes::fix_tags('$1'))", // [category=<id>]
  1084. "Codes::render_object('user', Codes::fix_tags('$1'))", // [user=<id>]
  1085. "Codes::render_object('server', Codes::fix_tags('$1'))", // [server=<id>]
  1086. "Codes::render_object('file', Codes::fix_tags('$1'))", // [file=<id>] or [file=<id>, title]
  1087. "Codes::render_object('download', Codes::fix_tags('$1'))", // [download=<id>] or [download=<id>, title]
  1088. "Codes::render_object('comment', Codes::fix_tags('$1'))", // [comment=<id>] or [comment=<id>, title]
  1089. "Skin::build_link(encode_link('$1'), Codes::fix_tags('$2'))", // [url=url]label[/link] (deprecated by [link])
  1090. "Skin::build_link(encode_link('$1'), NULL)", // [url]url[/url] (deprecated by [link])
  1091. "Skin::build_link(encode_link('$2'), Codes::fix_tags('$1'))", // [link=label]url[/link]
  1092. "Skin::build_link(enco…

Large files files are truncated, but you can click here to view the full file