PageRenderTime 37ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/forum/Sources/Subs.php

https://github.com/leftnode/nooges.com
PHP | 4074 lines | 2930 code | 493 blank | 651 comment | 741 complexity | a076807073e5e67fc3b8858b1e43911d MD5 | raw file

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

  1. <?php
  2. /**********************************************************************************
  3. * Subs.php *
  4. ***********************************************************************************
  5. * SMF: Simple Machines Forum *
  6. * Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com) *
  7. * =============================================================================== *
  8. * Software Version: SMF 2.0 RC2 *
  9. * Software by: Simple Machines (http://www.simplemachines.org) *
  10. * Copyright 2006-2009 by: Simple Machines LLC (http://www.simplemachines.org) *
  11. * 2001-2006 by: Lewis Media (http://www.lewismedia.com) *
  12. * Support, News, Updates at: http://www.simplemachines.org *
  13. ***********************************************************************************
  14. * This program is free software; you may redistribute it and/or modify it under *
  15. * the terms of the provided license as published by Simple Machines LLC. *
  16. * *
  17. * This program is distributed in the hope that it is and will be useful, but *
  18. * WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY *
  19. * or FITNESS FOR A PARTICULAR PURPOSE. *
  20. * *
  21. * See the "license.txt" file for details of the Simple Machines license. *
  22. * The latest version can always be found at http://www.simplemachines.org. *
  23. **********************************************************************************/
  24. if (!defined('SMF'))
  25. die('Hacking attempt...');
  26. /* This file has all the main functions in it that relate to, well,
  27. everything. It provides all of the following functions:
  28. void updateStats(string statistic, string condition = '1')
  29. - statistic can be 'member', 'message', 'topic', or 'postgroups'.
  30. - parameter1 and parameter2 are optional, and are used to update only
  31. those stats that need updating.
  32. - the 'member' statistic updates the latest member, the total member
  33. count, and the number of unapproved members.
  34. - 'member' also only counts approved members when approval is on, but
  35. is much more efficient with it off.
  36. - updating 'message' changes the total number of messages, and the
  37. highest message id by id_msg - which can be parameters 1 and 2,
  38. respectively.
  39. - 'topic' updates the total number of topics, or if parameter1 is true
  40. simply increments them.
  41. - the 'postgroups' case updates those members who match condition's
  42. post-based membergroups in the database (restricted by parameter1).
  43. void updateMemberData(int id_member, array data)
  44. - updates the columns in the members table.
  45. - id_member is either an int or an array of ints to be updated.
  46. - data is an associative array of the columns to be updated and their
  47. respective values.
  48. - any string values updated should be quoted and slashed.
  49. - the value of any column can be '+' or '-', which mean 'increment'
  50. and decrement, respectively.
  51. - if the member's post number is updated, updates their post groups.
  52. - this function should be used whenever member data needs to be
  53. updated in place of an UPDATE query.
  54. void updateSettings(array changeArray, use_update = false)
  55. - updates both the settings table and $modSettings array.
  56. - all of changeArray's indexes and values are assumed to have escaped
  57. apostrophes (')!
  58. - if a variable is already set to what you want to change it to, that
  59. variable will be skipped over; it would be unnecessary to reset.
  60. - if use_update is true, UPDATEs will be used instead of REPLACE.
  61. - when use_update is true, the value can be true or false to increment
  62. or decrement it, respectively.
  63. string constructPageIndex(string base_url, int &start, int max_value,
  64. int num_per_page, bool compact_start = false)
  65. - builds the page list, e.g. 1 ... 6 7 [8] 9 10 ... 15.
  66. - compact_start caused it to use "url.page" instead of
  67. "url;start=page".
  68. - handles any wireless settings (adding special things to URLs.)
  69. - very importantly, cleans up the start value passed, and forces it to
  70. be a multiple of num_per_page.
  71. - also checks that start is not more than max_value.
  72. - base_url should be the URL without any start parameter on it.
  73. - uses the compactTopicPagesEnable and compactTopicPagesContiguous
  74. settings to decide how to display the menu.
  75. - an example is available near the function definition.
  76. string comma_format(float number)
  77. - formats a number to display in the style of the admins' choosing.
  78. - uses the format of number_format to decide how to format the number.
  79. - for example, it might display "1 234,50".
  80. - caches the formatting data from the setting for optimization.
  81. string timeformat(int time, bool show_today = true, string offset_type = false)
  82. - returns a pretty formated version of time based on the user's format
  83. in $user_info['time_format'].
  84. - applies all necessary time offsets to the timestamp, unless offset_type
  85. is set.
  86. - if todayMod is set and show_today was not not specified or true, an
  87. alternate format string is used to show the date with something to
  88. show it is "today" or "yesterday".
  89. - performs localization (more than just strftime would do alone.)
  90. string un_htmlspecialchars(string text)
  91. - removes the base entities (&lt;, &quot;, etc.) from text.
  92. - should be used instead of html_entity_decode for PHP version
  93. compatibility reasons.
  94. - additionally converts &nbsp; and &#039;.
  95. - returns the string without entities.
  96. string shorten_subject(string regular_subject, int length)
  97. - shortens a subject so that it is either shorter than length, or that
  98. length plus an ellipsis.
  99. - respects internationalization characters and entities as one character.
  100. - avoids trailing entities.
  101. - returns the shortened string.
  102. int forum_time(bool use_user_offset = true)
  103. - returns the current time with offsets.
  104. - always applies the offset in the time_offset setting.
  105. - if use_user_offset is true, applies the user's offset as well.
  106. - returns seconds since the unix epoch.
  107. array permute(array input)
  108. - calculates all the possible permutations (orders) of array.
  109. - should not be called on huge arrays (bigger than like 10 elements.)
  110. - returns an array containing each permutation.
  111. string parse_bbc(string message, bool smileys = true, string cache_id = '', array parse_tags = null)
  112. - this very hefty function parses bbc in message.
  113. - only parses bbc tags which are not disabled in disabledBBC.
  114. - also handles basic HTML, if enablePostHTML is on.
  115. - caches the from/to replace regular expressions so as not to reload
  116. them every time a string is parsed.
  117. - only parses smileys if smileys is true.
  118. - does nothing if the enableBBC setting is off.
  119. - applies the fixLongWords magic if the setting is set to on.
  120. - uses the cache_id as a unique identifier to facilitate any caching
  121. it may do.
  122. - returns the modified message.
  123. void parsesmileys(string &message)
  124. - the smiley parsing function which makes pretty faces appear :).
  125. - if custom smiley sets are turned off by smiley_enable, the default
  126. set of smileys will be used.
  127. - these are specifically not parsed in code tags [url=mailto:Dad@blah.com]
  128. - caches the smileys from the database or array in memory.
  129. - doesn't return anything, but rather modifies message directly.
  130. string highlight_php_code(string code)
  131. - Uses PHP's highlight_string() to highlight PHP syntax
  132. - does special handling to keep the tabs in the code available.
  133. - used to parse PHP code from inside [code] and [php] tags.
  134. - returns the code with highlighted HTML.
  135. void writeLog(bool force = false)
  136. // !!!
  137. void redirectexit(string setLocation = '', bool use_refresh = false)
  138. // !!!
  139. void obExit(bool do_header = true, bool do_footer = do_header)
  140. // !!!
  141. int logAction($action, $extra = array())
  142. // !!!
  143. void trackStats($stats = array())
  144. - caches statistics changes, and flushes them if you pass nothing.
  145. - if '+' is used as a value, it will be incremented.
  146. - does not actually commit the changes until the end of the page view.
  147. - depends on the trackStats setting.
  148. void spamProtection(string error_type)
  149. - attempts to protect from spammed messages and the like.
  150. - takes a $txt index. (not an actual string.)
  151. - time taken depends on error_type - generally uses the modSetting.
  152. array url_image_size(string url)
  153. - uses getimagesize() to determine the size of a file.
  154. - attempts to connect to the server first so it won't time out.
  155. - returns false on failure, otherwise the output of getimagesize().
  156. void determineTopicClass(array &topic_context)
  157. // !!!
  158. void setupThemeContext(bool force_reload = false)
  159. // !!!
  160. void template_rawdata()
  161. // !!!
  162. void template_header()
  163. // !!!
  164. void theme_copyright(bool get_it = false)
  165. // !!!
  166. void template_footer()
  167. // !!!
  168. void db_debug_junk()
  169. // !!!
  170. void getAttachmentFilename(string filename, int id_attach, bool new = true)
  171. // !!!
  172. string host_from_ip(string ip_address)
  173. // !!!
  174. string create_button(string filename, string alt, string label, bool custom = '')
  175. // !!!
  176. void clean_cache(type = '')
  177. // !!!
  178. */
  179. // Update some basic statistics...
  180. function updateStats($type, $parameter1 = null, $parameter2 = null)
  181. {
  182. global $sourcedir, $modSettings, $smcFunc;
  183. switch ($type)
  184. {
  185. case 'member':
  186. $changes = array(
  187. 'memberlist_updated' => time(),
  188. );
  189. // #1 latest member ID, #2 the real name for a new registration.
  190. if (is_numeric($parameter1))
  191. {
  192. $changes['latestMember'] = $parameter1;
  193. $changes['latestRealName'] = $parameter2;
  194. updateSettings(array('totalMembers' => true), true);
  195. }
  196. // We need to calculate the totals.
  197. else
  198. {
  199. // Update the latest activated member (highest id_member) and count.
  200. $result = $smcFunc['db_query']('', '
  201. SELECT COUNT(*), MAX(id_member)
  202. FROM {db_prefix}members
  203. WHERE is_activated = {int:is_activated}',
  204. array(
  205. 'is_activated' => 1,
  206. )
  207. );
  208. list ($changes['totalMembers'], $changes['latestMember']) = $smcFunc['db_fetch_row']($result);
  209. $smcFunc['db_free_result']($result);
  210. // Get the latest activated member's display name.
  211. $result = $smcFunc['db_query']('', '
  212. SELECT real_name
  213. FROM {db_prefix}members
  214. WHERE id_member = {int:id_member}
  215. LIMIT 1',
  216. array(
  217. 'id_member' => (int) $changes['latestMember'],
  218. )
  219. );
  220. list ($changes['latestRealName']) = $smcFunc['db_fetch_row']($result);
  221. $smcFunc['db_free_result']($result);
  222. // Are we using registration approval?
  223. if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 2)
  224. {
  225. // Update the amount of members awaiting approval - ignoring COPPA accounts, as you can't approve them until you get permission.
  226. $result = $smcFunc['db_query']('', '
  227. SELECT COUNT(*)
  228. FROM {db_prefix}members
  229. WHERE is_activated IN ({array_int:activation_status})',
  230. array(
  231. 'activation_status' => array(3, 4),
  232. )
  233. );
  234. list ($changes['unapprovedMembers']) = $smcFunc['db_fetch_row']($result);
  235. $smcFunc['db_free_result']($result);
  236. }
  237. }
  238. updateSettings($changes);
  239. break;
  240. case 'message':
  241. if ($parameter1 === true && $parameter2 !== null)
  242. updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
  243. else
  244. {
  245. // SUM and MAX on a smaller table is better for InnoDB tables.
  246. $result = $smcFunc['db_query']('', '
  247. SELECT SUM(num_posts + unapproved_posts) AS total_messages, MAX(id_last_msg) AS max_msg_id
  248. FROM {db_prefix}boards
  249. WHERE redirect = {string:blank_redirect}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  250. AND id_board != {int:recycle_board}' : ''),
  251. array(
  252. 'recycle_board' => isset($modSettings['recycle_board']) ? $modSettings['recycle_board'] : 0,
  253. 'blank_redirect' => '',
  254. )
  255. );
  256. $row = $smcFunc['db_fetch_assoc']($result);
  257. $smcFunc['db_free_result']($result);
  258. updateSettings(array(
  259. 'totalMessages' => $row['total_messages'] === null ? 0 : $row['total_messages'],
  260. 'maxMsgID' => $row['max_msg_id'] === null ? 0 : $row['max_msg_id']
  261. ));
  262. }
  263. break;
  264. case 'subject':
  265. // Remove the previous subject (if any).
  266. $smcFunc['db_query']('', '
  267. DELETE FROM {db_prefix}log_search_subjects
  268. WHERE id_topic = {int:id_topic}',
  269. array(
  270. 'id_topic' => (int) $parameter1,
  271. )
  272. );
  273. // Insert the new subject.
  274. if ($parameter2 !== null)
  275. {
  276. $parameter1 = (int) $parameter1;
  277. $parameter2 = text2words($parameter2);
  278. $inserts = array();
  279. foreach ($parameter2 as $word)
  280. $inserts[] = array($word, $parameter1);
  281. if (!empty($inserts))
  282. $smcFunc['db_insert']('ignore',
  283. '{db_prefix}log_search_subjects',
  284. array('word' => 'string', 'id_topic' => 'int'),
  285. $inserts,
  286. array('word', 'id_topic')
  287. );
  288. }
  289. break;
  290. case 'topic':
  291. if ($parameter1 === true)
  292. updateSettings(array('totalTopics' => true), true);
  293. else
  294. {
  295. // Get the number of topics - a SUM is better for InnoDB tables.
  296. // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
  297. $result = $smcFunc['db_query']('', '
  298. SELECT SUM(num_topics + unapproved_topics) AS total_topics
  299. FROM {db_prefix}boards' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  300. WHERE id_board != {int:recycle_board}' : ''),
  301. array(
  302. 'recycle_board' => !empty($modSettings['recycle_board']) ? $modSettings['recycle_board'] : 0,
  303. )
  304. );
  305. $row = $smcFunc['db_fetch_assoc']($result);
  306. $smcFunc['db_free_result']($result);
  307. updateSettings(array('totalTopics' => $row['total_topics'] === null ? 0 : $row['total_topics']));
  308. }
  309. break;
  310. case 'postgroups':
  311. // Parameter two is the updated columns: we should check to see if we base groups off any of these.
  312. if ($parameter2 !== null && !in_array('posts', $parameter2))
  313. return;
  314. if (($postgroups = cache_get_data('updateStats:postgroups', 360)) == null)
  315. {
  316. // Fetch the postgroups!
  317. $request = $smcFunc['db_query']('', '
  318. SELECT id_group, min_posts
  319. FROM {db_prefix}membergroups
  320. WHERE min_posts != {int:min_posts}',
  321. array(
  322. 'min_posts' => -1,
  323. )
  324. );
  325. $postgroups = array();
  326. while ($row = $smcFunc['db_fetch_assoc']($request))
  327. $postgroups[$row['id_group']] = $row['min_posts'];
  328. $smcFunc['db_free_result']($request);
  329. // Sort them this way because if it's done with MySQL it causes a filesort :(.
  330. arsort($postgroups);
  331. cache_put_data('updateStats:postgroups', $postgroups, 360);
  332. }
  333. // Oh great, they've screwed their post groups.
  334. if (empty($postgroups))
  335. return;
  336. // Set all membergroups from most posts to least posts.
  337. $conditions = '';
  338. foreach ($postgroups as $id => $min_posts)
  339. {
  340. $conditions .= '
  341. WHEN posts >= ' . $min_posts . (!empty($lastMin) ? ' AND posts <= ' . $lastMin : '') . ' THEN ' . $id;
  342. $lastMin = $min_posts;
  343. }
  344. // A big fat CASE WHEN... END is faster than a zillion UPDATE's ;).
  345. $smcFunc['db_query']('', '
  346. UPDATE {db_prefix}members
  347. SET id_post_group = CASE ' . $conditions . '
  348. ELSE 0
  349. END' . ($parameter1 != null ? '
  350. WHERE ' . (is_array($parameter1) ? 'id_member IN ({array_int:members})' : 'id_member = {int:members}') : ''),
  351. array(
  352. 'members' => $parameter1,
  353. )
  354. );
  355. break;
  356. default:
  357. trigger_error('updateStats(): Invalid statistic type \'' . $type . '\'', E_USER_NOTICE);
  358. }
  359. }
  360. // Assumes the data has been htmlspecialchar'd.
  361. function updateMemberData($members, $data)
  362. {
  363. global $modSettings, $user_info, $smcFunc;
  364. $parameters = array();
  365. if (is_array($members))
  366. {
  367. $condition = 'id_member IN ({array_int:members})';
  368. $parameters['members'] = $members;
  369. }
  370. elseif ($members === null)
  371. $condition = '1=1';
  372. else
  373. {
  374. $condition = 'id_member = {int:member}';
  375. $parameters['member'] = $members;
  376. }
  377. if (isset($modSettings['integrate_change_member_data']) && function_exists($modSettings['integrate_change_member_data']))
  378. {
  379. // Only a few member variables are really interesting for integration.
  380. $integration_vars = array(
  381. 'member_name',
  382. 'real_name',
  383. 'email_address',
  384. 'id_group',
  385. 'gender',
  386. 'birthdate',
  387. 'website_title',
  388. 'website_url',
  389. 'location',
  390. 'hide_email',
  391. 'time_format',
  392. 'time_offset',
  393. 'avatar',
  394. 'lngfile',
  395. );
  396. $vars_to_integrate = array_intersect($integration_vars, array_keys($data));
  397. // Only proceed if there are any variables left to call the integration function.
  398. if (count($vars_to_integrate) != 0)
  399. {
  400. // Fetch a list of member_names if necessary
  401. if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
  402. $member_names = array($user_info['username']);
  403. else
  404. {
  405. $member_names = array();
  406. $request = $smcFunc['db_query']('', '
  407. SELECT member_name
  408. FROM {db_prefix}members
  409. WHERE ' . $condition,
  410. $parameters
  411. );
  412. while ($row = $smcFunc['db_fetch_assoc']($request))
  413. $member_names[] = $row['member_name'];
  414. $smcFunc['db_free_result']($request);
  415. }
  416. if (!empty($member_names))
  417. foreach ($vars_to_integrate as $var)
  418. call_user_func($modSettings['integrate_change_member_data'], $member_names, $var, $data[$var]);
  419. }
  420. }
  421. // Everything is assumed to be a string unless it's in the below.
  422. $knownInts = array(
  423. 'date_registered', 'posts', 'id_group', 'last_login', 'instant_messages', 'unread_messages',
  424. 'new_pm', 'pm_prefs', 'gender', 'hide_email', 'show_online', 'pm_email_notify', 'pm_receive_from', 'karma_good', 'karma_bad',
  425. 'notify_announcements', 'notify_send_body', 'notify_regularity', 'notify_types',
  426. 'id_theme', 'is_activated', 'id_msg_last_visit', 'id_post_group', 'total_time_logged_in', 'warning',
  427. );
  428. $knownFloats = array(
  429. 'time_offset',
  430. );
  431. $setString = '';
  432. foreach ($data as $var => $val)
  433. {
  434. $type = 'string';
  435. if (in_array($var, $knownInts))
  436. $type = 'int';
  437. elseif (in_array($var, $knownFloats))
  438. $type = 'float';
  439. elseif ($var == 'birthdate')
  440. $type = 'date';
  441. // Doing an increment?
  442. if ($type == 'int' && ($val === '+' || $val === '-'))
  443. {
  444. $val = $var . ' ' . $val . ' 1';
  445. $type = 'raw';
  446. }
  447. // Ensure posts, instant_messages, and unread_messages don't overflow or underflow.
  448. if (in_array($var, array('posts', 'instant_messages', 'unread_messages')))
  449. {
  450. if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
  451. {
  452. if ($match[1] != '+ ')
  453. $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
  454. $type = 'raw';
  455. }
  456. }
  457. $setString .= ' ' . $var . ' = {' . $type . ':p_' . $var . '},';
  458. $parameters['p_' . $var] = $val;
  459. }
  460. $smcFunc['db_query']('', '
  461. UPDATE {db_prefix}members
  462. SET' . substr($setString, 0, -1) . '
  463. WHERE ' . $condition,
  464. $parameters
  465. );
  466. updateStats('postgroups', $members, array_keys($data));
  467. // Clear any caching?
  468. if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
  469. {
  470. if (!is_array($members))
  471. $members = array($members);
  472. foreach ($members as $member)
  473. {
  474. if ($modSettings['cache_enable'] >= 3)
  475. {
  476. cache_put_data('member_data-profile-' . $member, null, 120);
  477. cache_put_data('member_data-normal-' . $member, null, 120);
  478. cache_put_data('member_data-minimal-' . $member, null, 120);
  479. }
  480. cache_put_data('user_settings-' . $member, null, 60);
  481. }
  482. }
  483. }
  484. // Updates the settings table as well as $modSettings... only does one at a time if $update is true.
  485. function updateSettings($changeArray, $update = false, $debug = false)
  486. {
  487. global $modSettings, $smcFunc;
  488. if (empty($changeArray) || !is_array($changeArray))
  489. return;
  490. // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
  491. if ($update)
  492. {
  493. foreach ($changeArray as $variable => $value)
  494. {
  495. $smcFunc['db_query']('', '
  496. UPDATE {db_prefix}settings
  497. SET value = {' . ($value === false || $value === true ? 'raw' : 'string') . ':value}
  498. WHERE variable = {string:variable}',
  499. array(
  500. 'value' => $value === true ? 'value + 1' : ($value === false ? 'value - 1' : $value),
  501. 'variable' => $variable,
  502. )
  503. );
  504. $modSettings[$variable] = $value === true ? $modSettings[$variable] + 1 : ($value === false ? $modSettings[$variable] - 1 : $value);
  505. }
  506. // Clean out the cache and make sure the cobwebs are gone too.
  507. cache_put_data('modSettings', null, 90);
  508. return;
  509. }
  510. $replaceArray = array();
  511. foreach ($changeArray as $variable => $value)
  512. {
  513. // Don't bother if it's already like that ;).
  514. if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
  515. continue;
  516. // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
  517. elseif (!isset($modSettings[$variable]) && empty($value))
  518. continue;
  519. $replaceArray[] = array($variable, $value);
  520. $modSettings[$variable] = $value;
  521. }
  522. if (empty($replaceArray))
  523. return;
  524. $smcFunc['db_insert']('replace',
  525. '{db_prefix}settings',
  526. array('variable' => 'string-255', 'value' => 'string-65534'),
  527. $replaceArray,
  528. array('variable')
  529. );
  530. // Kill the cache - it needs redoing now, but we won't bother ourselves with that here.
  531. cache_put_data('modSettings', null, 90);
  532. }
  533. // Constructs a page list.
  534. // $pageindex = constructPageIndex($scripturl . '?board=' . $board, $_REQUEST['start'], $num_messages, $maxindex, true);
  535. function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false)
  536. {
  537. global $modSettings;
  538. // Save whether $start was less than 0 or not.
  539. $start_invalid = $start < 0;
  540. // Make sure $start is a proper variable - not less than 0.
  541. if ($start_invalid)
  542. $start = 0;
  543. // Not greater than the upper bound.
  544. elseif ($start >= $max_value)
  545. $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
  546. // And it has to be a multiple of $num_per_page!
  547. else
  548. $start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
  549. // Wireless will need the protocol on the URL somewhere.
  550. if (WIRELESS)
  551. $base_url .= ';' . WIRELESS_PROTOCOL;
  552. $base_link = '<a class="navPages" href="' . ($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d') . '">%2$s</a> ';
  553. // Compact pages is off or on?
  554. if (empty($modSettings['compactTopicPagesEnable']))
  555. {
  556. // Show the left arrow.
  557. $pageindex = $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, '&#171;');
  558. // Show all the pages.
  559. $display_page = 1;
  560. for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
  561. $pageindex .= $start == $counter && !$start_invalid ? '<strong>' . $display_page++ . '</strong> ' : sprintf($base_link, $counter, $display_page++);
  562. // Show the right arrow.
  563. $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
  564. if ($start != $counter - $max_value && !$start_invalid)
  565. $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, '&#187;');
  566. }
  567. else
  568. {
  569. // If they didn't enter an odd value, pretend they did.
  570. $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
  571. // Show the first page. (>1< ... 6 7 [8] 9 10 ... 15)
  572. if ($start > $num_per_page * $PageContiguous)
  573. $pageindex = sprintf($base_link, 0, '1');
  574. else
  575. $pageindex = '';
  576. // Show the ... after the first page. (1 >...< 6 7 [8] 9 10 ... 15)
  577. if ($start > $num_per_page * ($PageContiguous + 1))
  578. $pageindex .= '<span style="font-weight: bold;" onclick="expandPages(this, \'' . ($flexible_start ? strtr($base_url, array('\'' => '\\\'')) : strtr($base_url, array('%' => '%%', '\'' => '\\\'')) . ';start=%1$d') . '\', ' . $num_per_page . ', ' . ($start - $num_per_page * $PageContiguous) . ', ' . $num_per_page . ');" onmouseover="this.style.cursor=\'pointer\';"> ... </span>';
  579. // Show the pages before the current one. (1 ... >6 7< [8] 9 10 ... 15)
  580. for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
  581. if ($start >= $num_per_page * $nCont)
  582. {
  583. $tmpStart = $start - $num_per_page * $nCont;
  584. $pageindex.= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
  585. }
  586. // Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)
  587. if (!$start_invalid)
  588. $pageindex .= '[<strong>' . ($start / $num_per_page + 1) . '</strong>] ';
  589. else
  590. $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
  591. // Show the pages after the current one... (1 ... 6 7 [8] >9 10< ... 15)
  592. $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
  593. for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
  594. if ($start + $num_per_page * $nCont <= $tmpMaxPages)
  595. {
  596. $tmpStart = $start + $num_per_page * $nCont;
  597. $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
  598. }
  599. // Show the '...' part near the end. (1 ... 6 7 [8] 9 10 >...< 15)
  600. if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
  601. $pageindex .= '<span style="font-weight: bold;" onclick="expandPages(this, \'' . ($flexible_start ? strtr($base_url, array('\'' => '\\\'')) : strtr($base_url, array('%' => '%%', '\'' => '\\\'')) . ';start=%1$d') . '\', ' . ($start + $num_per_page * ($PageContiguous + 1)) . ', ' . $tmpMaxPages . ', ' . $num_per_page . ');" onmouseover="this.style.cursor=\'pointer\';"> ... </span>';
  602. // Show the last number in the list. (1 ... 6 7 [8] 9 10 ... >15<)
  603. if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
  604. $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
  605. }
  606. return $pageindex;
  607. }
  608. // Formats a number to display in the style of the admin's choosing.
  609. function comma_format($number, $override_decimal_count = false)
  610. {
  611. global $txt;
  612. static $thousands_separator = null, $decimal_separator = null, $decimal_count = null;
  613. // !!! Should, perhaps, this just be handled in the language files, and not a mod setting?
  614. // (French uses 1 234,00 for example... what about a multilingual forum?)
  615. // Cache these values...
  616. if ($decimal_separator === null)
  617. {
  618. // Not set for whatever reason?
  619. if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
  620. return $number;
  621. // Cache these each load...
  622. $thousands_separator = $matches[1];
  623. $decimal_separator = $matches[2];
  624. $decimal_count = strlen($matches[3]);
  625. }
  626. // Format the string with our friend, number_format.
  627. return number_format($number, is_float($number) ? ($override_decimal_count === false ? $decimal_count : $override_decimal_count) : 0, $decimal_separator, $thousands_separator);
  628. }
  629. // Format a time to make it look purdy.
  630. function timeformat($log_time, $show_today = true, $offset_type = false)
  631. {
  632. global $user_info, $txt, $modSettings, $smcFunc;
  633. // Offset the time.
  634. if (!$offset_type)
  635. $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
  636. // Just the forum offset?
  637. elseif ($offset_type == 'forum')
  638. $time = $log_time + $modSettings['time_offset'] * 3600;
  639. else
  640. $time = $log_time;
  641. // We can't have a negative date (on Windows, at least.)
  642. if ($log_time < 0)
  643. $log_time = 0;
  644. // Today and Yesterday?
  645. if ($modSettings['todayMod'] >= 1 && $show_today === true)
  646. {
  647. // Get the current time.
  648. $nowtime = forum_time();
  649. $then = @getdate($time);
  650. $now = @getdate($nowtime);
  651. // Try to make something of a time format string...
  652. $s = strpos($user_info['time_format'], '%S') === false ? '' : ':%S';
  653. if (strpos($user_info['time_format'], '%H') === false && strpos($user_info['time_format'], '%T') === false)
  654. {
  655. $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
  656. $today_fmt = $h . ':%M' . $s . ' %p';
  657. }
  658. else
  659. $today_fmt = '%H:%M' . $s;
  660. // Same day of the year, same year.... Today!
  661. if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
  662. return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
  663. // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
  664. if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
  665. return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
  666. }
  667. $str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
  668. if (setlocale(LC_TIME, $txt['lang_locale']))
  669. {
  670. foreach (array('%a', '%A', '%b', '%B') as $token)
  671. if (strpos($str, $token) !== false)
  672. $str = str_replace($token, !empty($txt['lang_capitalize_dates']) ? $smcFunc['ucwords'](strftime($token, $time)) : strftime($token, $time), $str);
  673. }
  674. else
  675. {
  676. // Do-it-yourself time localization. Fun.
  677. foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
  678. if (strpos($str, $token) !== false)
  679. $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
  680. if (strpos($str, '%p'))
  681. $str = str_replace('%p', (strftime('%H', $time) < 12 ? 'am' : 'pm'), $str);
  682. }
  683. // Format any other characters..
  684. return strftime($str, $time);
  685. }
  686. // Removes special entities from strings. Compatibility...
  687. function un_htmlspecialchars($string)
  688. {
  689. static $translation;
  690. if (!isset($translation))
  691. $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array('&#039;' => '\'', '&nbsp;' => ' ');
  692. return strtr($string, $translation);
  693. }
  694. // Shorten a subject + internationalization concerns.
  695. function shorten_subject($subject, $len)
  696. {
  697. global $smcFunc;
  698. // It was already short enough!
  699. if ($smcFunc['strlen']($subject) <= $len)
  700. return $subject;
  701. // Shorten it by the length it was too long, and strip off junk from the end.
  702. return $smcFunc['substr']($subject, 0, $len) . '...';
  703. }
  704. // The current time with offset.
  705. function forum_time($use_user_offset = true, $timestamp = null)
  706. {
  707. global $user_info, $modSettings;
  708. if ($timestamp === null)
  709. $timestamp = time();
  710. elseif ($timestamp == 0)
  711. return 0;
  712. return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
  713. }
  714. // This gets all possible permutations of an array.
  715. function permute($array)
  716. {
  717. $orders = array($array);
  718. $n = count($array);
  719. $p = range(0, $n);
  720. for ($i = 1; $i < $n; null)
  721. {
  722. $p[$i]--;
  723. $j = $i % 2 != 0 ? $p[$i] : 0;
  724. $temp = $array[$i];
  725. $array[$i] = $array[$j];
  726. $array[$j] = $temp;
  727. for ($i = 1; $p[$i] == 0; $i++)
  728. $p[$i] = 1;
  729. $orders[] = $array;
  730. }
  731. return $orders;
  732. }
  733. // Parse bulletin board code in a string, as well as smileys optionally.
  734. function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = array())
  735. {
  736. global $txt, $scripturl, $context, $modSettings, $user_info, $smcFunc;
  737. static $bbc_codes = array(), $itemcodes = array(), $no_autolink_tags = array();
  738. static $disabled;
  739. // Never show smileys for wireless clients. More bytes, can't see it anyway :P.
  740. if (WIRELESS)
  741. $smileys = false;
  742. elseif ($smileys !== null && ($smileys == '1' || $smileys == '0'))
  743. $smileys = (bool) $smileys;
  744. if (empty($modSettings['enableBBC']) && $message !== false)
  745. {
  746. if ($smileys === true)
  747. parsesmileys($message);
  748. return $message;
  749. }
  750. // Just in case it wasn't determined yet whether UTF-8 is enabled.
  751. if (!isset($context['utf8']))
  752. $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
  753. // If we are not doing every tag then we don't cache this run.
  754. if (!empty($parse_tags) && !empty($bbc_codes))
  755. {
  756. $temp_bbc = $bbc_codes;
  757. $bbc_codes = array();
  758. }
  759. // Sift out the bbc for a performance improvement.
  760. if (empty($bbc_codes) || $message === false || !empty($parse_tags))
  761. {
  762. if (!empty($modSettings['disabledBBC']))
  763. {
  764. $temp = explode(',', strtolower($modSettings['disabledBBC']));
  765. foreach ($temp as $tag)
  766. $disabled[trim($tag)] = true;
  767. }
  768. if (empty($modSettings['enableEmbeddedFlash']))
  769. $disabled['flash'] = true;
  770. /* The following bbc are formatted as an array, with keys as follows:
  771. tag: the tag's name - should be lowercase!
  772. type: one of...
  773. - (missing): [tag]parsed content[/tag]
  774. - unparsed_equals: [tag=xyz]parsed content[/tag]
  775. - parsed_equals: [tag=parsed data]parsed content[/tag]
  776. - unparsed_content: [tag]unparsed content[/tag]
  777. - closed: [tag], [tag/], [tag /]
  778. - unparsed_commas: [tag=1,2,3]parsed content[/tag]
  779. - unparsed_commas_content: [tag=1,2,3]unparsed content[/tag]
  780. - unparsed_equals_content: [tag=...]unparsed content[/tag]
  781. parameters: an optional array of parameters, for the form
  782. [tag abc=123]content[/tag]. The array is an associative array
  783. where the keys are the parameter names, and the values are an
  784. array which may contain the following:
  785. - match: a regular expression to validate and match the value.
  786. - quoted: true if the value should be quoted.
  787. - validate: callback to evaluate on the data, which is $data.
  788. - value: a string in which to replace $1 with the data.
  789. either it or validate may be used, not both.
  790. - optional: true if the parameter is optional.
  791. test: a regular expression to test immediately after the tag's
  792. '=', ' ' or ']'. Typically, should have a \] at the end.
  793. Optional.
  794. content: only available for unparsed_content, closed,
  795. unparsed_commas_content, and unparsed_equals_content.
  796. $1 is replaced with the content of the tag. Parameters
  797. are replaced in the form {param}. For unparsed_commas_content,
  798. $2, $3, ..., $n are replaced.
  799. before: only when content is not used, to go before any
  800. content. For unparsed_equals, $1 is replaced with the value.
  801. For unparsed_commas, $1, $2, ..., $n are replaced.
  802. after: similar to before in every way, except that it is used
  803. when the tag is closed.
  804. disabled_content: used in place of content when the tag is
  805. disabled. For closed, default is '', otherwise it is '$1' if
  806. block_level is false, '<div>$1</div>' elsewise.
  807. disabled_before: used in place of before when disabled. Defaults
  808. to '<div>' if block_level, '' if not.
  809. disabled_after: used in place of after when disabled. Defaults
  810. to '</div>' if block_level, '' if not.
  811. block_level: set to true the tag is a "block level" tag, similar
  812. to HTML. Block level tags cannot be nested inside tags that are
  813. not block level, and will not be implicitly closed as easily.
  814. One break following a block level tag may also be removed.
  815. trim: if set, and 'inside' whitespace after the begin tag will be
  816. removed. If set to 'outside', whitespace after the end tag will
  817. meet the same fate.
  818. validate: except when type is missing or 'closed', a callback to
  819. validate the data as $data. Depending on the tag's type, $data
  820. may be a string or an array of strings (corresponding to the
  821. replacement.)
  822. quoted: when type is 'unparsed_equals' or 'parsed_equals' only,
  823. may be not set, 'optional', or 'required' corresponding to if
  824. the content may be quoted. This allows the parser to read
  825. [tag="abc]def[esdf]"] properly.
  826. require_parents: an array of tag names, or not set. If set, the
  827. enclosing tag *must* be one of the listed tags, or parsing won't
  828. occur.
  829. require_children: similar to require_parents, if set children
  830. won't be parsed if they are not in the list.
  831. disallow_children: similar to, but very different from,
  832. require_children, if it is set the listed tags will not be
  833. parsed inside the tag.
  834. parsed_tags_allowed: an array restricting what BBC can be in the
  835. parsed_equals parameter, if desired.
  836. */
  837. $codes = array(
  838. array(
  839. 'tag' => 'abbr',
  840. 'type' => 'unparsed_equals',
  841. 'before' => '<abbr title="$1">',
  842. 'after' => '</abbr>',
  843. 'quoted' => 'optional',
  844. 'disabled_after' => ' ($1)',
  845. ),
  846. array(
  847. 'tag' => 'acronym',
  848. 'type' => 'unparsed_equals',
  849. 'before' => '<acronym title="$1">',
  850. 'after' => '</acronym>',
  851. 'quoted' => 'optional',
  852. 'disabled_after' => ' ($1)',
  853. ),
  854. array(
  855. 'tag' => 'anchor',
  856. 'type' => 'unparsed_equals',
  857. 'test' => '[#]?([A-Za-z][A-Za-z0-9_\-]*)\]',
  858. 'before' => '<span id="post_$1">',
  859. 'after' => '</span>',
  860. ),
  861. array(
  862. 'tag' => 'b',
  863. 'before' => '<strong>',
  864. 'after' => '</strong>',
  865. ),
  866. array(
  867. 'tag' => 'bdo',
  868. 'type' => 'unparsed_equals',
  869. 'before' => '<bdo dir="$1">',
  870. 'after' => '</bdo>',
  871. 'test' => '(rtl|ltr)\]',
  872. 'block_level' => true,
  873. ),
  874. array(
  875. 'tag' => 'black',
  876. 'before' => '<span style="color: black;" class="bbc_color">',
  877. 'after' => '</span>',
  878. ),
  879. array(
  880. 'tag' => 'blue',
  881. 'before' => '<span style="color: blue;" class="bbc_color">',
  882. 'after' => '</span>',
  883. ),
  884. array(
  885. 'tag' => 'br',
  886. 'type' => 'closed',
  887. 'content' => '<br />',
  888. ),
  889. array(
  890. 'tag' => 'code',
  891. 'type' => 'unparsed_content',
  892. 'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><code>$1</code>',
  893. // !!! Maybe this can be simplified?
  894. 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
  895. global $context;
  896. if (!isset($disabled[\'code\']))
  897. {
  898. $php_parts = preg_split(\'~(&lt;\?php|\?&gt;)~\', $data, -1, PREG_SPLIT_DELIM_CAPTURE);
  899. for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
  900. {
  901. // Do PHP code coloring?
  902. if ($php_parts[$php_i] != \'&lt;?php\')
  903. continue;
  904. $php_string = \'\';
  905. while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != \'?&gt;\')
  906. {
  907. $php_string .= $php_parts[$php_i];
  908. $php_parts[$php_i++] = \'\';
  909. }
  910. $php_parts[$php_i] = highlight_php_code($php_string . $php_parts[$php_i]);
  911. }
  912. // Fix the PHP code stuff...
  913. $data = str_replace("<pre style=\"display: inline;\">\t</pre>", "\t", implode(\'\', $php_parts));
  914. // Older browsers are annoying, aren\'t they?
  915. if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
  916. $data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
  917. elseif (!$context[\'browser\'][\'is_gecko\'])
  918. $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
  919. else
  920. $data = str_replace("\t", "&nbsp;&nbsp;&nbsp;", $data);
  921. // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
  922. if ($context[\'browser\'][\'is_opera\'])
  923. $data .= \'&nbsp;\';
  924. }'),
  925. 'block_level' => true,
  926. ),
  927. array(
  928. 'tag' => 'code',
  929. 'type' => 'unparsed_equals_content',
  930. 'content' => '<div class="codeheader">' . $txt['code'] . ': ($2) <a href="#" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><code>$1</code>',
  931. // !!! Maybe this can be simplified?
  932. 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
  933. global $context;
  934. if (!isset($disabled[\'code\']))
  935. {
  936. $php_parts = preg_split(\'~(&lt;\?php|\?&gt;)~\', $data[0], -1, PREG_SPLIT_DELIM_CAPTURE);
  937. for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
  938. {
  939. // Do PHP code coloring?
  940. if ($php_parts[$php_i] != \'&lt;?php\')
  941. continue;
  942. $php_string = \'\';
  943. while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != \'?&gt;\')
  944. {
  945. $php_string .= $php_parts[$php_i];
  946. $php_parts[$php_i++] = \'\';
  947. }
  948. $php_parts[$php_i] = highlight_php_code($php_string . $php_parts[$php_i]);
  949. }
  950. // Fix the PHP code stuff...
  951. $data[0] = str_replace("<pre style=\"display: inline;\">\t</pre>", "\t", implode(\'\', $php_parts));
  952. // Older browsers are annoying, aren\'t they?
  953. if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
  954. $data[0] = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data[0]);
  955. elseif (!$context[\'browser\'][\'is_gecko\'])
  956. $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
  957. else
  958. $data[0] = str_replace("\t", "&nbsp;&nbsp;&nbsp;", $data[0]);
  959. // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
  960. if ($context[\'browser\'][\'is_opera\'])
  961. $data[0] .= \'&nbsp;\';
  962. }'),
  963. 'block_level' => true,
  964. ),
  965. array(
  966. 'tag' => 'center',
  967. 'before' => '<div align="center">',
  968. 'after' => '</div>',
  969. 'block_level' => true,
  970. ),
  971. array(
  972. 'tag' => 'color',
  973. 'type' => 'unparsed_equals',
  974. 'test' => '(#[\da-fA-F]{3}|#[\da-fA-F]{6}|[A-Za-z]{1,20}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\))\]',
  975. 'before' => '<span style="color: $1;" class="bbc_color">',
  976. 'after' => '</span>',
  977. ),
  978. array(
  979. 'tag' => 'email',
  980. 'type' => 'unparsed_content',
  981. 'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
  982. // !!! Should this respect guest_hideContacts?
  983. 'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
  984. ),
  985. array(
  986. 'tag' => 'email',
  987. 'type' => 'unparsed_equals',
  988. 'before' => '<a href="mailto:$1" class="bbc_email">',
  989. 'after' => '</a>',
  990. // !!! Should this respect guest_hideContacts?
  991. 'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
  992. 'disabled_after' => ' ($1)',
  993. ),
  994. array(
  995. 'tag' => 'ftp',
  996. 'type' => 'unparsed_content',
  997. 'content' => '<a href="$1" class="bbc_ftp new_win" target="_blank">$1</a>',
  998. 'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
  999. ),
  1000. array(
  1001. 'tag' => 'ftp',
  1002. 'type' => 'unparsed_equals',
  1003. 'before' => '<a href="$1" class="bbc_ftp new_win" target="_blank">',
  1004. 'after' => '</a>',
  1005. 'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
  1006. 'disabled_after' => ' ($1)',
  1007. ),
  1008. array(
  1009. 'tag' => 'font',
  1010. 'type' => 'unparsed_equals',
  1011. 'test' => '[A-Za-z0-9_,\-\s]+?\]',
  1012. 'before' => '<span style="font-family: $1;" class="bbc_font">',
  1013. 'after' => '</span>',
  1014. ),
  1015. array(
  1016. 'tag' => 'flash',
  1017. 'type' => 'unparsed_commas_content',
  1018. 'test' => '\d+,\d+\]',
  1019. 'content' => ($context['browser']['is_ie'] && !$context['browser']['is_mac_ie'] ? '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="$2" height="$3"><param name="movie" value="$1" /><param name="play" value="true" /><param name="loop" value="true" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never" /><noembed><a href="$1" target="_blank" class="new_win">$1</a></noembed></object>' : '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never" /><noembed><a href="$1" target="_blank" class="new_win">$1</a></noembed>'),
  1020. 'validate' => create_function('&$tag, &$data, $disabled', '
  1021. if (isset($disabled[\'url\']))
  1022. $tag[\'content\'] = \'$1\';'),
  1023. 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
  1024. ),
  1025. array(
  1026. 'tag' => 'green',
  1027. 'before' => '<span style="color: green;" class="bbc_color">',
  1028. 'after' => '</span>',
  1029. ),
  1030. array(
  1031. 'tag' => 'glow',
  1032. 'type' => 'unparsed_commas',
  1033. 'test' => '[#0-9a-zA-Z\-]{3,12},([012]\d{1,2}|\d{1,2})(,[^]]+)?\]',
  1034. 'before' => $context['browser']['is_ie'] ? '<table border="0" cellpadding="0" cellspacing="0" style="display: inline; vertical-align: middle; font: inherit;"><tr><td style="filter: Glow(color=$1, strength=$2); font: inherit;">' : '<span style="text-shadow: $1 1px 1px 1px">',
  1035. 'after' => $context['browser']['is_ie'] ? '</td></tr></table> ' : '</span>',
  1036. ),
  1037. array(
  1038. 'tag' => 'hr',
  1039. 'type' => 'closed',
  1040. 'content' => '<hr />',
  1041. 'block_level' => true,
  1042. ),
  1043. array(
  1044. 'tag' => 'html',
  1045. 'type' => 'unparsed_content',
  1046. 'content' => '$1',
  1047. 'block_level' => true,
  1048. 'disabled_content' => '$1',
  1049. ),
  1050. array(
  1051. 'tag' => 'img',
  1052. 'type' => 'unparsed_content',
  1053. 'parameters' => array(
  1054. 'alt' => array('optional' => true),
  1055. 'width' => array('optional' => true, 'value' => ' width="$1"', 'match' => '(\d+)'),
  1056. 'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
  1057. ),
  1058. 'content' => '<img src="$1" alt="{alt}"{width}{height} class="bbc_img" />',
  1059. 'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
  1060. 'disabled_content' => '($1)',
  1061. ),
  1062. array(
  1063. 'tag' => 'img',
  1064. 'type' => 'unparsed_content',
  1065. 'content' => '<img src="$1" alt="" class="bbc_img" />',
  1066. 'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
  1067. 'disabled_content' => '($1)',
  1068. ),
  1069. array(
  1070. 'tag' => 'i',
  1071. 'before' => '<em>',
  1072. 'after' => '</em>',
  1073. ),
  1074. array(
  1075. 'tag' => 'iurl',
  1076. 'type' => 'unparsed_content',
  1077. 'content' => '<a href="$1" class="bbc_link">$1</a>',
  1078. 'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
  1079. ),
  1080. array(
  1081. 'tag' => 'iurl',
  1082. 'type' => 'unparsed_equals',
  1083. 'before' => '<a href="$1" class="bbc_link">',
  1084. 'after' => '</a>',
  1085. 'validate' => create_function('&$tag, &$data, $disabled', '
  1086. if (substr($data, 0, 1) == \'#\')
  1087. $data = \'#post_\' . substr($data, 1);'),
  1088. 'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
  1089. 'disabled_after' => ' ($1)',
  1090. ),
  1091. array(
  1092. 'tag' => 'li',
  1093. 'before' => '<li>',
  1094. 'after' => '</li>',
  1095. 'trim' => 'outside',
  1096. 'require_parents' => array('list'),
  1097. 'block_level' => true,
  1098. 'disabled_before' => '',
  1099. 'disabled_after' => '<br />',
  1100. ),
  1101. array(
  1102. 'tag' => 'list',
  1103. 'before' => '<ul class="bbc_list">',
  1104. 'after' => '</ul>',
  1105. 'trim' => 'inside',
  1106. 'require_children' => array('li', 'list'),
  1107. 'block_level' => true,
  1108. ),
  1109. array(
  1110. 'tag' => 'list',
  1111. 'parameters' => array(
  1112. 'type' => array('match' => '(none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha)'),
  1113. ),
  1114. 'before' => '<ul class="bbc_list" style="list-style-type: {type};">',
  1115. 'after' => '</ul>',
  1116. 'trim' => 'inside',
  1117. 'require_children' => array('li'),
  1118. 'block_level' => true,
  1119. ),
  1120. array(
  1121. 'tag' => 'left',
  1122. 'before' => '<div style="text-align: left;">',
  1123. 'after' => '</div>',
  1124. 'block_level' => true,
  1125. ),
  1126. array(
  1127. 'tag' => 'ltr',
  1128. 'before' => '<div dir="ltr">',
  1129. 'after' => '</div>',
  1130. 'block_level' => true,
  1131. ),
  1132. array(
  1133. 'tag' => 'me',
  1134. 'type' => 'unparsed_equals',
  1135. 'before' => '<div class="meaction">* $1 ',
  1136. 'after' => '</div>',
  1137. 'quoted' => 'optional',
  1138. 'block_level' => true,
  1139. 'disabled_before' => '/me ',
  1140. 'disabled_after' => '<br />',
  1141. ),
  1142. array(
  1143. 'tag' => 'move',
  1144. 'before' => '<marquee>',
  1145. 'after' => '</marquee>',
  1146. 'block_level' => true,
  1147. ),
  1148. array(
  1149. 'tag' => 'nobbc',
  1150. 'type' => 'unparsed_content',
  1151. 'content' => '$1',
  1152. ),
  1153. array(
  1154. 'tag' => 'pre',
  1155. 'before' => '<pre>',
  1156. 'after' => '</pre>',
  1157. ),
  1158. array(
  1159. 'tag' => 'php',
  1160. 'type' => 'unparsed_content',
  1161. 'content' => '<span class="phpcode">$1</span>',
  1162. 'validate' => isset($disabled['php']) ? null : create_function('&$tag, &$data, $disabled', '
  1163. if (!isset($disabled[\'php\']))
  1164. {
  1165. $add_begin = substr(trim($data), 0, 5) != \'&lt;?\';
  1166. $data = highlight_php_code($add_begin ? \'&lt;?php \' . $data . \'?&gt;\' : $data);
  1167. if ($add_begin)
  1168. $data = preg_replace(array(\'~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~\', \'~\?&gt;((?:</(font|span)>)*)$~\'), \'$1\', $data, 2);
  1169. }'),
  1170. 'block_level' => false,
  1171. 'disabled_content' => '$1',
  1172. ),
  1173. array(
  1174. 'tag' => 'quote',
  1175. 'before' => '<div class="quoteheader"><div class="topslice_quote">' . $txt['quote'] . '</div></div><blockquote>',
  1176. 'after' => '</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div><br />',
  1177. 'block_level' => true,
  1178. ),
  1179. array(
  1180. 'tag' => 'quote',
  1181. 'parameters' => array(
  1182. 'author' => array('match' => '(.{1,192}?)', 'quoted' => true),
  1183. ),
  1184. 'before' => '<div class="quoteheader"><div class="topslice_quote">' . $txt['quote_from'] . ': {author}</div></div><blockquote>',
  1185. 'after' => '</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div><br />',
  1186. 'block_level' => true,
  1187. ),
  1188. array(
  1189. 'tag' => 'quote',
  1190. 'type' => 'parsed_equals',
  1191. 'before' => '<div class="quoteheader"><div class="topslice_quote">' . $txt['quote_from'] . ': $1</div></div><blockquote>',
  1192. 'after'

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