PageRenderTime 30ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/php/Sources/Subs.php

https://github.com/dekoza/openshift-smf-2.0.7
PHP | 4392 lines | 3157 code | 535 blank | 700 comment | 791 complexity | d20ecd51f400ee6c2c73468919f456a9 MD5 | raw file
Possible License(s): BSD-3-Clause

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

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

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