PageRenderTime 66ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/Sources/Subs.php

https://github.com/smf-portal/SMF2.1
PHP | 4371 lines | 3006 code | 523 blank | 842 comment | 765 complexity | 30c6b5986a820cd189f7a600cc02f6ac MD5 | raw file

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

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

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