SSI.php 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  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
  11. */
  12. // Don't do anything if SMF is already loaded.
  13. if (defined('SMF'))
  14. return true;
  15. define('SMF', 'SSI');
  16. // We're going to want a few globals... these are all set later.
  17. global $time_start, $maintenance, $msubject, $mmessage, $mbname, $language;
  18. global $boardurl, $boarddir, $sourcedir, $webmaster_email, $cookiename;
  19. global $db_server, $db_name, $db_user, $db_prefix, $db_persist, $db_error_send, $db_last_error;
  20. global $db_connection, $modSettings, $context, $sc, $user_info, $topic, $board, $txt;
  21. global $smcFunc, $ssi_db_user, $scripturl, $ssi_db_passwd, $db_passwd, $cachedir;
  22. // Remember the current configuration so it can be set back.
  23. $ssi_magic_quotes_runtime = function_exists('get_magic_quotes_gpc') && get_magic_quotes_runtime();
  24. if (function_exists('set_magic_quotes_runtime'))
  25. @set_magic_quotes_runtime(0);
  26. $time_start = microtime();
  27. // Just being safe...
  28. foreach (array('db_character_set', 'cachedir') as $variable)
  29. if (isset($GLOBALS[$variable]))
  30. unset($GLOBALS[$variable]);
  31. // Get the forum's settings for database and file paths.
  32. require_once(dirname(__FILE__) . '/Settings.php');
  33. // Make absolutely sure the cache directory is defined.
  34. if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
  35. $cachedir = $boarddir . '/cache';
  36. $ssi_error_reporting = error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
  37. /* Set this to one of three values depending on what you want to happen in the case of a fatal error.
  38. false: Default, will just load the error sub template and die - not putting any theme layers around it.
  39. true: Will load the error sub template AND put the SMF layers around it (Not useful if on total custom pages).
  40. string: Name of a callback function to call in the event of an error to allow you to define your own methods. Will die after function returns.
  41. */
  42. $ssi_on_error_method = false;
  43. // Don't do john didley if the forum's been shut down competely.
  44. if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true))
  45. die($mmessage);
  46. // Fix for using the current directory as a path.
  47. if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
  48. $sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
  49. // Load the important includes.
  50. require_once($sourcedir . '/QueryString.php');
  51. require_once($sourcedir . '/Session.php');
  52. require_once($sourcedir . '/Subs.php');
  53. require_once($sourcedir . '/Errors.php');
  54. require_once($sourcedir . '/Load.php');
  55. require_once($sourcedir . '/Security.php');
  56. // Using an pre-PHP 5.1 version?
  57. if (@version_compare(PHP_VERSION, '5.1') == -1)
  58. require_once($sourcedir . '/Subs-Compat.php');
  59. // Create a variable to store some SMF specific functions in.
  60. $smcFunc = array();
  61. // Initate the database connection and define some database functions to use.
  62. loadDatabase();
  63. // Load installed 'Mods' settings.
  64. reloadSettings();
  65. // Clean the request variables.
  66. cleanRequest();
  67. // Seed the random generator?
  68. if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
  69. smf_seed_generator();
  70. // Check on any hacking attempts.
  71. if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
  72. die('Hacking attempt...');
  73. elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme)
  74. die('Hacking attempt...');
  75. elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme)
  76. die('Hacking attempt...');
  77. elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers)
  78. die('Hacking attempt...');
  79. if (isset($_REQUEST['context']))
  80. die('Hacking attempt...');
  81. // Make sure wireless is always off.
  82. define('WIRELESS', false);
  83. // Gzip output? (because it must be boolean and true, this can't be hacked.)
  84. if (isset($ssi_gzip) && $ssi_gzip === true && @ini_get('zlib.output_compression') != '1' && @ini_get('output_handler') != 'ob_gzhandler' && @version_compare(PHP_VERSION, '4.2.0') != -1)
  85. ob_start('ob_gzhandler');
  86. else
  87. $modSettings['enableCompressedOutput'] = '0';
  88. // Primarily, this is to fix the URLs...
  89. ob_start('ob_sessrewrite');
  90. // Start the session... known to scramble SSI includes in cases...
  91. if (!headers_sent())
  92. loadSession();
  93. else
  94. {
  95. if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()]))
  96. {
  97. // Make a stab at it, but ignore the E_WARNINGs generated because we can't send headers.
  98. $temp = error_reporting(error_reporting() & !E_WARNING);
  99. loadSession();
  100. error_reporting($temp);
  101. }
  102. if (!isset($_SESSION['session_value']))
  103. {
  104. $_SESSION['session_var'] = substr(md5(mt_rand() . session_id() . mt_rand()), 0, rand(7, 12));
  105. $_SESSION['session_value'] = md5(session_id() . mt_rand());
  106. }
  107. $sc = $_SESSION['session_value'];
  108. }
  109. // Get rid of $board and $topic... do stuff loadBoard would do.
  110. unset($board, $topic);
  111. $user_info['is_mod'] = false;
  112. $context['user']['is_mod'] = &$user_info['is_mod'];
  113. $context['linktree'] = array();
  114. // Load the user and their cookie, as well as their settings.
  115. loadUserSettings();
  116. // Load the current user's permissions....
  117. loadPermissions();
  118. // Load the current or SSI theme. (just use $ssi_theme = id_theme;)
  119. loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0);
  120. // Take care of any banning that needs to be done.
  121. if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true))
  122. is_not_banned();
  123. // Do we allow guests in here?
  124. if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php')
  125. {
  126. require_once($sourcedir . '/Subs-Auth.php');
  127. KickGuest();
  128. obExit(null, true);
  129. }
  130. // Load the stuff like the menu bar, etc.
  131. if (isset($ssi_layers))
  132. {
  133. $context['template_layers'] = $ssi_layers;
  134. template_header();
  135. }
  136. else
  137. setupThemeContext();
  138. // Make sure they didn't muss around with the settings... but only if it's not cli.
  139. if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
  140. trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);
  141. // Without visiting the forum this session variable might not be set on submit.
  142. if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote'))
  143. $_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
  144. // Call a function passed by GET.
  145. if (isset($_GET['ssi_function']) && function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest']))
  146. {
  147. call_user_func('ssi_' . $_GET['ssi_function']);
  148. exit;
  149. }
  150. if (isset($_GET['ssi_function']))
  151. exit;
  152. // You shouldn't just access SSI.php directly by URL!!
  153. elseif (basename($_SERVER['PHP_SELF']) == 'SSI.php')
  154. die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
  155. error_reporting($ssi_error_reporting);
  156. if (function_exists('set_magic_quotes_runtime'))
  157. @set_magic_quotes_runtime($ssi_magic_quotes_runtime);
  158. return true;
  159. // This shuts down the SSI and shows the footer.
  160. function ssi_shutdown()
  161. {
  162. if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown')
  163. template_footer();
  164. }
  165. // Display a welcome message, like: Hey, User, you have 0 messages, 0 are new.
  166. function ssi_welcome($output_method = 'echo')
  167. {
  168. global $context, $txt, $scripturl;
  169. if ($output_method == 'echo')
  170. {
  171. if ($context['user']['is_guest'])
  172. echo sprintf($txt['welcome_guest'], $txt['guest_title']);
  173. else
  174. echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . $txt['msg_alert_you_have'] . ' <a href="' . $scripturl . '?action=pm">' . $context['user']['messages'] . ' ' . ($context['user']['messages'] == '1' ? $txt['message_lowercase'] : $txt['msg_alert_messages']) . '</a>' . $txt['newmessages4'] . ' ' . $context['user']['unread_messages'] . ' ' . ($context['user']['unread_messages'] == '1' ? $txt['newmessages0'] : $txt['newmessages1']) : '', '.';
  175. }
  176. // Don't echo... then do what?!
  177. else
  178. return $context['user'];
  179. }
  180. // Display a menu bar, like is displayed at the top of the forum.
  181. function ssi_menubar($output_method = 'echo')
  182. {
  183. global $context;
  184. if ($output_method == 'echo')
  185. template_menu();
  186. // What else could this do?
  187. else
  188. return $context['menu_buttons'];
  189. }
  190. // Show a logout link.
  191. function ssi_logout($redirect_to = '', $output_method = 'echo')
  192. {
  193. global $context, $txt, $scripturl;
  194. if ($redirect_to != '')
  195. $_SESSION['logout_url'] = $redirect_to;
  196. // Guests can't log out.
  197. if ($context['user']['is_guest'])
  198. return false;
  199. $link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>';
  200. if ($output_method == 'echo')
  201. echo $link;
  202. else
  203. return $link;
  204. }
  205. // Recent post list: [board] Subject by Poster Date
  206. function ssi_recentPosts($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo', $limit_body = true)
  207. {
  208. global $context, $settings, $scripturl, $txt, $db_prefix, $user_info;
  209. global $modSettings, $smcFunc;
  210. // Excluding certain boards...
  211. if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
  212. $exclude_boards = array($modSettings['recycle_board']);
  213. else
  214. $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
  215. // What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter.
  216. if (is_array($include_boards) || (int) $include_boards === $include_boards)
  217. {
  218. $include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
  219. }
  220. elseif ($include_boards != null)
  221. {
  222. $include_boards = array();
  223. }
  224. // Let's restrict the query boys (and girls)
  225. $query_where = '
  226. m.id_msg >= {int:min_message_id}
  227. ' . (empty($exclude_boards) ? '' : '
  228. AND b.id_board NOT IN ({array_int:exclude_boards})') . '
  229. ' . ($include_boards === null ? '' : '
  230. AND b.id_board IN ({array_int:include_boards})') . '
  231. AND {query_wanna_see_board}' . ($modSettings['postmod_active'] ? '
  232. AND m.approved = {int:is_approved}' : '');
  233. $query_where_params = array(
  234. 'is_approved' => 1,
  235. 'include_boards' => $include_boards === null ? '' : $include_boards,
  236. 'exclude_boards' => empty($exclude_boards) ? '' : $exclude_boards,
  237. 'min_message_id' => $modSettings['maxMsgID'] - 25 * min($num_recent, 5),
  238. );
  239. // Past to this simpleton of a function...
  240. return ssi_queryPosts($query_where, $query_where_params, $num_recent, 'm.id_msg DESC', $output_method, $limit_body);
  241. }
  242. // Fetch a post with a particular ID. By default will only show if you have permission to the see the board in question - this can be overriden.
  243. function ssi_fetchPosts($post_ids, $override_permissions = false, $output_method = 'echo')
  244. {
  245. global $user_info, $modSettings;
  246. // Allow the user to request more than one - why not?
  247. $post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
  248. // Restrict the posts required...
  249. $query_where = '
  250. m.id_msg IN ({array_int:message_list})' . ($override_permissions ? '' : '
  251. AND {query_wanna_see_board}') . ($modSettings['postmod_active'] ? '
  252. AND m.approved = {int:is_approved}' : '');
  253. $query_where_params = array(
  254. 'message_list' => $post_ids,
  255. 'is_approved' => 1,
  256. );
  257. // Then make the query and dump the data.
  258. return ssi_queryPosts($query_where, $query_where_params, '', 'm.id_msg DESC', $output_method);
  259. }
  260. // This removes code duplication in other queries - don't call it direct unless you really know what you're up to.
  261. function ssi_queryPosts($query_where = '', $query_where_params = array(), $query_limit = '', $query_order = 'm.id_msg DESC', $output_method = 'echo', $limit_body = false)
  262. {
  263. global $context, $settings, $scripturl, $txt, $db_prefix, $user_info;
  264. global $modSettings, $smcFunc;
  265. // Find all the posts. Newer ones will have higher IDs.
  266. $request = $smcFunc['db_query']('substring', '
  267. SELECT
  268. m.poster_time, m.subject, m.id_topic, m.id_member, m.id_msg, m.id_board, b.name AS board_name,
  269. IFNULL(mem.real_name, m.poster_name) AS poster_name, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
  270. IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
  271. IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . ', ' . ($limit_body ? 'SUBSTRING(m.body, 1, 384) AS body' : 'm.body') . ', m.smileys_enabled
  272. FROM {db_prefix}messages AS m
  273. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  274. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!$user_info['is_guest'] ? '
  275. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = {int:current_member})
  276. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = m.id_board AND lmr.id_member = {int:current_member})' : '') . '
  277. ' . (empty($query_where) ? '' : 'WHERE ' . $query_where) . '
  278. ORDER BY ' . $query_order . '
  279. ' . ($query_limit == '' ? '' : 'LIMIT ' . $query_limit),
  280. array_merge($query_where_params, array(
  281. 'current_member' => $user_info['id'],
  282. ))
  283. );
  284. $posts = array();
  285. while ($row = $smcFunc['db_fetch_assoc']($request))
  286. {
  287. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
  288. // Censor it!
  289. censorText($row['subject']);
  290. censorText($row['body']);
  291. $preview = strip_tags(strtr($row['body'], array('<br />' => '&#10;')));
  292. // Build the array.
  293. $posts[] = array(
  294. 'id' => $row['id_msg'],
  295. 'board' => array(
  296. 'id' => $row['id_board'],
  297. 'name' => $row['board_name'],
  298. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  299. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
  300. ),
  301. 'topic' => $row['id_topic'],
  302. 'poster' => array(
  303. 'id' => $row['id_member'],
  304. 'name' => $row['poster_name'],
  305. 'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
  306. 'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
  307. ),
  308. 'subject' => $row['subject'],
  309. 'short_subject' => shorten_subject($row['subject'], 25),
  310. 'preview' => $smcFunc['strlen']($preview) > 128 ? $smcFunc['substr']($preview, 0, 128) . '...' : $preview,
  311. 'body' => $row['body'],
  312. 'time' => timeformat($row['poster_time']),
  313. 'timestamp' => forum_time(true, $row['poster_time']),
  314. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
  315. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $row['subject'] . '</a>',
  316. 'new' => !empty($row['is_read']),
  317. 'is_new' => empty($row['is_read']),
  318. 'new_from' => $row['new_from'],
  319. );
  320. }
  321. $smcFunc['db_free_result']($request);
  322. // Just return it.
  323. if ($output_method != 'echo' || empty($posts))
  324. return $posts;
  325. echo '
  326. <table border="0" class="ssi_table">';
  327. foreach ($posts as $post)
  328. echo '
  329. <tr>
  330. <td align="right" valign="top" nowrap="nowrap">
  331. [', $post['board']['link'], ']
  332. </td>
  333. <td valign="top">
  334. <a href="', $post['href'], '">', $post['subject'], '</a>
  335. ', $txt['by'], ' ', $post['poster']['link'], '
  336. ', $post['is_new'] ? '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>' : '', '
  337. </td>
  338. <td align="right" nowrap="nowrap">
  339. ', $post['time'], '
  340. </td>
  341. </tr>';
  342. echo '
  343. </table>';
  344. }
  345. // Recent topic list: [board] Subject by Poster Date
  346. function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo')
  347. {
  348. global $context, $settings, $scripturl, $txt, $db_prefix, $user_info;
  349. global $modSettings, $smcFunc;
  350. if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
  351. $exclude_boards = array($modSettings['recycle_board']);
  352. else
  353. $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
  354. // Only some boards?.
  355. if (is_array($include_boards) || (int) $include_boards === $include_boards)
  356. {
  357. $include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
  358. }
  359. elseif ($include_boards != null)
  360. {
  361. $output_method = $include_boards;
  362. $include_boards = array();
  363. }
  364. $stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
  365. $icon_sources = array();
  366. foreach ($stable_icons as $icon)
  367. $icon_sources[$icon] = 'images_url';
  368. // Find all the posts in distinct topics. Newer ones will have higher IDs.
  369. $request = $smcFunc['db_query']('substring', '
  370. SELECT
  371. m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
  372. IFNULL(mem.real_name, m.poster_name) AS poster_name, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
  373. IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
  374. IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . ', SUBSTRING(m.body, 1, 384) AS body, m.smileys_enabled, m.icon
  375. FROM {db_prefix}topics AS t
  376. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
  377. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  378. INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
  379. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!$user_info['is_guest'] ? '
  380. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
  381. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})' : '') . '
  382. WHERE t.id_last_msg >= {int:min_message_id}
  383. ' . (empty($exclude_boards) ? '' : '
  384. AND b.id_board NOT IN ({array_int:exclude_boards})') . '
  385. ' . (empty($include_boards) ? '' : '
  386. AND b.id_board IN ({array_int:include_boards})') . '
  387. AND {query_wanna_see_board}' . ($modSettings['postmod_active'] ? '
  388. AND t.approved = {int:is_approved}
  389. AND m.approved = {int:is_approved}' : '') . '
  390. ORDER BY t.id_last_msg DESC
  391. LIMIT ' . $num_recent,
  392. array(
  393. 'current_member' => $user_info['id'],
  394. 'include_boards' => empty($include_boards) ? '' : $include_boards,
  395. 'exclude_boards' => empty($exclude_boards) ? '' : $exclude_boards,
  396. 'min_message_id' => $modSettings['maxMsgID'] - 35 * min($num_recent, 5),
  397. 'is_approved' => 1,
  398. )
  399. );
  400. $posts = array();
  401. while ($row = $smcFunc['db_fetch_assoc']($request))
  402. {
  403. $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br />' => '&#10;')));
  404. if ($smcFunc['strlen']($row['body']) > 128)
  405. $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
  406. // Censor the subject.
  407. censorText($row['subject']);
  408. censorText($row['body']);
  409. if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
  410. $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
  411. // Build the array.
  412. $posts[] = array(
  413. 'board' => array(
  414. 'id' => $row['id_board'],
  415. 'name' => $row['board_name'],
  416. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  417. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
  418. ),
  419. 'topic' => $row['id_topic'],
  420. 'poster' => array(
  421. 'id' => $row['id_member'],
  422. 'name' => $row['poster_name'],
  423. 'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
  424. 'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
  425. ),
  426. 'subject' => $row['subject'],
  427. 'replies' => $row['num_replies'],
  428. 'views' => $row['num_views'],
  429. 'short_subject' => shorten_subject($row['subject'], 25),
  430. 'preview' => $row['body'],
  431. 'time' => timeformat($row['poster_time']),
  432. 'timestamp' => forum_time(true, $row['poster_time']),
  433. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
  434. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#new" rel="nofollow">' . $row['subject'] . '</a>',
  435. // Retained for compatibility - is technically incorrect!
  436. 'new' => !empty($row['is_read']),
  437. 'is_new' => empty($row['is_read']),
  438. 'new_from' => $row['new_from'],
  439. 'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" />',
  440. );
  441. }
  442. $smcFunc['db_free_result']($request);
  443. // Just return it.
  444. if ($output_method != 'echo' || empty($posts))
  445. return $posts;
  446. echo '
  447. <table border="0" class="ssi_table">';
  448. foreach ($posts as $post)
  449. echo '
  450. <tr>
  451. <td align="right" valign="top" nowrap="nowrap">
  452. [', $post['board']['link'], ']
  453. </td>
  454. <td valign="top">
  455. <a href="', $post['href'], '">', $post['subject'], '</a>
  456. ', $txt['by'], ' ', $post['poster']['link'], '
  457. ', !$post['is_new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>', '
  458. </td>
  459. <td align="right" nowrap="nowrap">
  460. ', $post['time'], '
  461. </td>
  462. </tr>';
  463. echo '
  464. </table>';
  465. }
  466. // Show the top poster's name and profile link.
  467. function ssi_topPoster($topNumber = 1, $output_method = 'echo')
  468. {
  469. global $db_prefix, $scripturl, $smcFunc;
  470. // Find the latest poster.
  471. $request = $smcFunc['db_query']('', '
  472. SELECT id_member, real_name, posts
  473. FROM {db_prefix}members
  474. ORDER BY posts DESC
  475. LIMIT ' . $topNumber,
  476. array(
  477. )
  478. );
  479. $return = array();
  480. while ($row = $smcFunc['db_fetch_assoc']($request))
  481. $return[] = array(
  482. 'id' => $row['id_member'],
  483. 'name' => $row['real_name'],
  484. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  485. 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  486. 'posts' => $row['posts']
  487. );
  488. $smcFunc['db_free_result']($request);
  489. // Just return all the top posters.
  490. if ($output_method != 'echo')
  491. return $return;
  492. // Make a quick array to list the links in.
  493. $temp_array = array();
  494. foreach ($return as $member)
  495. $temp_array[] = $member['link'];
  496. echo implode(', ', $temp_array);
  497. }
  498. // Show boards by activity.
  499. function ssi_topBoards($num_top = 10, $output_method = 'echo')
  500. {
  501. global $context, $settings, $db_prefix, $txt, $scripturl, $user_info, $modSettings, $smcFunc;
  502. // Find boards with lots of posts.
  503. $request = $smcFunc['db_query']('', '
  504. SELECT
  505. b.name, b.num_topics, b.num_posts, b.id_board,' . (!$user_info['is_guest'] ? ' 1 AS is_read' : '
  506. (IFNULL(lb.id_msg, 0) >= b.id_last_msg) AS is_read') . '
  507. FROM {db_prefix}boards AS b
  508. LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
  509. WHERE {query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  510. AND b.id_board != {int:recycle_board}' : '') . '
  511. ORDER BY b.num_posts DESC
  512. LIMIT ' . $num_top,
  513. array(
  514. 'current_member' => $user_info['id'],
  515. 'recycle_board' => (int) $modSettings['recycle_board'],
  516. )
  517. );
  518. $boards = array();
  519. while ($row = $smcFunc['db_fetch_assoc']($request))
  520. $boards[] = array(
  521. 'id' => $row['id_board'],
  522. 'num_posts' => $row['num_posts'],
  523. 'num_topics' => $row['num_topics'],
  524. 'name' => $row['name'],
  525. 'new' => empty($row['is_read']),
  526. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  527. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'
  528. );
  529. $smcFunc['db_free_result']($request);
  530. // If we shouldn't output or have nothing to output, just jump out.
  531. if ($output_method != 'echo' || empty($boards))
  532. return $boards;
  533. echo '
  534. <table class="ssi_table">
  535. <tr>
  536. <th align="left">', $txt['board'], '</th>
  537. <th align="left">', $txt['board_topics'], '</th>
  538. <th align="left">', $txt['posts'], '</th>
  539. </tr>';
  540. foreach ($boards as $board)
  541. echo '
  542. <tr>
  543. <td>', $board['link'], $board['new'] ? ' <a href="' . $board['href'] . '"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>' : '', '</td>
  544. <td align="right">', comma_format($board['num_topics']), '</td>
  545. <td align="right">', comma_format($board['num_posts']), '</td>
  546. </tr>';
  547. echo '
  548. </table>';
  549. }
  550. // Shows the top topics.
  551. function ssi_topTopics($type = 'replies', $num_topics = 10, $output_method = 'echo')
  552. {
  553. global $db_prefix, $txt, $scripturl, $user_info, $modSettings, $smcFunc, $context;
  554. if ($modSettings['totalMessages'] > 100000)
  555. {
  556. // !!! Why don't we use {query(_wanna)_see_board}?
  557. $request = $smcFunc['db_query']('', '
  558. SELECT id_topic
  559. FROM {db_prefix}topics
  560. WHERE num_' . ($type != 'replies' ? 'views' : 'replies') . ' != 0' . ($modSettings['postmod_active'] ? '
  561. AND approved = {int:is_approved}' : '') . '
  562. ORDER BY num_' . ($type != 'replies' ? 'views' : 'replies') . ' DESC
  563. LIMIT {int:limit}',
  564. array(
  565. 'is_approved' => 1,
  566. 'limit' => $num_topics > 100 ? ($num_topics + ($num_topics / 2)) : 100,
  567. )
  568. );
  569. $topic_ids = array();
  570. while ($row = $smcFunc['db_fetch_assoc']($request))
  571. $topic_ids[] = $row['id_topic'];
  572. $smcFunc['db_free_result']($request);
  573. }
  574. else
  575. $topic_ids = array();
  576. $request = $smcFunc['db_query']('', '
  577. SELECT m.subject, m.id_topic, t.num_views, t.num_replies
  578. FROM {db_prefix}topics AS t
  579. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  580. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  581. WHERE {query_wanna_see_board}' . ($modSettings['postmod_active'] ? '
  582. AND t.approved = {int:is_approved}' : '') . (!empty($topic_ids) ? '
  583. AND t.id_topic IN ({array_int:topic_list})' : '') . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  584. AND b.id_board != {int:recycle_enable}' : '') . '
  585. ORDER BY t.num_' . ($type != 'replies' ? 'views' : 'replies') . ' DESC
  586. LIMIT {int:limit}',
  587. array(
  588. 'topic_list' => $topic_ids,
  589. 'is_approved' => 1,
  590. 'recycle_enable' => $modSettings['recycle_board'],
  591. 'limit' => $num_topics,
  592. )
  593. );
  594. $topics = array();
  595. while ($row = $smcFunc['db_fetch_assoc']($request))
  596. {
  597. censorText($row['subject']);
  598. $topics[] = array(
  599. 'id' => $row['id_topic'],
  600. 'subject' => $row['subject'],
  601. 'num_replies' => $row['num_replies'],
  602. 'num_views' => $row['num_views'],
  603. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
  604. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>',
  605. );
  606. }
  607. $smcFunc['db_free_result']($request);
  608. if ($output_method != 'echo' || empty($topics))
  609. return $topics;
  610. echo '
  611. <table class="ssi_table">
  612. <tr>
  613. <th align="left"></th>
  614. <th align="left">', $txt['views'], '</th>
  615. <th align="left">', $txt['replies'], '</th>
  616. </tr>';
  617. foreach ($topics as $topic)
  618. echo '
  619. <tr>
  620. <td align="left">
  621. ', $topic['link'], '
  622. </td>
  623. <td align="right">', comma_format($topic['num_views']), '</td>
  624. <td align="right">', comma_format($topic['num_replies']), '</td>
  625. </tr>';
  626. echo '
  627. </table>';
  628. }
  629. // Shows the top topics, by replies.
  630. function ssi_topTopicsReplies($num_topics = 10, $output_method = 'echo')
  631. {
  632. return ssi_topTopics('replies', $num_topics, $output_method);
  633. }
  634. // Shows the top topics, by views.
  635. function ssi_topTopicsViews($num_topics = 10, $output_method = 'echo')
  636. {
  637. return ssi_topTopics('views', $num_topics, $output_method);
  638. }
  639. // Show a link to the latest member: Please welcome, Someone, out latest member.
  640. function ssi_latestMember($output_method = 'echo')
  641. {
  642. global $db_prefix, $txt, $scripturl, $context;
  643. if ($output_method == 'echo')
  644. echo '
  645. ', $txt['welcome_member'], ' ', $context['common_stats']['latest_member']['link'], '', $txt['newest_member'], '<br />';
  646. else
  647. return $context['common_stats']['latest_member'];
  648. }
  649. // Fetch a random member - if type set to 'day' will only change once a day!
  650. function ssi_randomMember($random_type = '', $output_method = 'echo')
  651. {
  652. global $modSettings;
  653. // If we're looking for something to stay the same each day then seed the generator.
  654. if ($random_type == 'day')
  655. {
  656. // Set the seed to change only once per day.
  657. mt_srand(floor(time() / 86400));
  658. }
  659. // Get the lowest ID we're interested in.
  660. $member_id = mt_rand(1, $modSettings['latestMember']);
  661. $where_query = '
  662. id_member >= {int:selected_member}
  663. AND is_activated = {int:is_activated}';
  664. $query_where_params = array(
  665. 'selected_member' => $member_id,
  666. 'is_activated' => 1,
  667. );
  668. $result = ssi_queryMembers($where_query, $query_where_params, 1, 'id_member ASC', $output_method);
  669. // If we got nothing do the reverse - in case of unactivated members.
  670. if (empty($result))
  671. {
  672. $where_query = '
  673. id_member <= {int:selected_member}
  674. AND is_activated = {int:is_activated}';
  675. $query_where_params = array(
  676. 'selected_member' => $member_id,
  677. 'is_activated' => 1,
  678. );
  679. $result = ssi_queryMembers($where_query, $query_where_params, 1, 'id_member DESC', $output_method);
  680. }
  681. // Just to be sure put the random generator back to something... random.
  682. if ($random_type != '')
  683. mt_srand(time());
  684. return $result;
  685. }
  686. // Fetch a specific member.
  687. function ssi_fetchMember($member_ids, $output_method = 'echo')
  688. {
  689. // Can have more than one member if you really want...
  690. $member_ids = is_array($member_ids) ? $member_ids : array($member_ids);
  691. // Restrict it right!
  692. $query_where = '
  693. id_member IN ({array_int:member_list})';
  694. $query_where_params = array(
  695. 'member_list' => $member_ids,
  696. );
  697. // Then make the query and dump the data.
  698. return ssi_queryMembers($query_where, $query_where_params, '', 'id_member', $output_method);
  699. }
  700. // Get all members of a group.
  701. function ssi_fetchGroupMembers($group_id, $output_method = 'echo')
  702. {
  703. $query_where = '
  704. id_group = {int:id_group}
  705. OR id_post_group = {int:id_group}
  706. OR FIND_IN_SET({int:id_group}, additional_groups)';
  707. $query_where_params = array(
  708. 'id_group' => $group_id,
  709. );
  710. return ssi_queryMembers($query_where, $query_where_params, '', 'real_name', $output_method);
  711. }
  712. // Fetch some member data!
  713. function ssi_queryMembers($query_where, $query_where_params = array(), $query_limit = '', $query_order = 'id_member DESC', $output_method = 'echo')
  714. {
  715. global $context, $settings, $scripturl, $txt, $db_prefix, $user_info;
  716. global $modSettings, $smcFunc, $memberContext;
  717. // Fetch the members in question.
  718. $request = $smcFunc['db_query']('', '
  719. SELECT id_member
  720. FROM {db_prefix}members
  721. WHERE ' . $query_where . '
  722. ORDER BY ' . $query_order . '
  723. ' . ($query_limit == '' ? '' : 'LIMIT ' . $query_limit),
  724. array_merge($query_where_params, array(
  725. ))
  726. );
  727. $members = array();
  728. while ($row = $smcFunc['db_fetch_assoc']($request))
  729. $members[] = $row['id_member'];
  730. $smcFunc['db_free_result']($request);
  731. if (empty($members))
  732. return array();
  733. // Load the members.
  734. loadMemberData($members);
  735. // Draw the table!
  736. if ($output_method == 'echo')
  737. echo '
  738. <table border="0" class="ssi_table">';
  739. $query_members = array();
  740. foreach ($members as $member)
  741. {
  742. // Load their context data.
  743. if (!loadMemberContext($member))
  744. continue;
  745. // Store this member's information.
  746. $query_members[$member] = $memberContext[$member];
  747. // Only do something if we're echo'ing.
  748. if ($output_method == 'echo')
  749. echo '
  750. <tr>
  751. <td align="right" valign="top" nowrap="nowrap">
  752. ', $query_members[$member]['link'], '
  753. <br />', $query_members[$member]['blurb'], '
  754. <br />', $query_members[$member]['avatar']['image'], '
  755. </td>
  756. </tr>';
  757. }
  758. // End the table if appropriate.
  759. if ($output_method == 'echo')
  760. echo '
  761. </table>';
  762. // Send back the data.
  763. return $query_members;
  764. }
  765. // Show some basic stats: Total This: XXXX, etc.
  766. function ssi_boardStats($output_method = 'echo')
  767. {
  768. global $db_prefix, $txt, $scripturl, $modSettings, $smcFunc;
  769. $totals = array(
  770. 'members' => $modSettings['totalMembers'],
  771. 'posts' => $modSettings['totalMessages'],
  772. 'topics' => $modSettings['totalTopics']
  773. );
  774. $result = $smcFunc['db_query']('', '
  775. SELECT COUNT(*)
  776. FROM {db_prefix}boards',
  777. array(
  778. )
  779. );
  780. list ($totals['boards']) = $smcFunc['db_fetch_row']($result);
  781. $smcFunc['db_free_result']($result);
  782. $result = $smcFunc['db_query']('', '
  783. SELECT COUNT(*)
  784. FROM {db_prefix}categories',
  785. array(
  786. )
  787. );
  788. list ($totals['categories']) = $smcFunc['db_fetch_row']($result);
  789. $smcFunc['db_free_result']($result);
  790. if ($output_method != 'echo')
  791. return $totals;
  792. echo '
  793. ', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br />
  794. ', $txt['total_posts'], ': ', comma_format($totals['posts']), '<br />
  795. ', $txt['total_topics'], ': ', comma_format($totals['topics']), ' <br />
  796. ', $txt['total_cats'], ': ', comma_format($totals['categories']), '<br />
  797. ', $txt['total_boards'], ': ', comma_format($totals['boards']);
  798. }
  799. // Shows a list of online users: YY Guests, ZZ Users and then a list...
  800. function ssi_whosOnline($output_method = 'echo')
  801. {
  802. global $user_info, $txt, $sourcedir, $settings, $modSettings;
  803. require_once($sourcedir . '/Subs-MembersOnline.php');
  804. $membersOnlineOptions = array(
  805. 'show_hidden' => allowedTo('moderate_forum'),
  806. );
  807. $return = getMembersOnlineStats($membersOnlineOptions);
  808. // Add some redundancy for backwards compatibility reasons.
  809. if ($output_method != 'echo')
  810. return $return + array(
  811. 'users' => $return['users_online'],
  812. 'guests' => $return['num_guests'],
  813. 'hidden' => $return['num_users_hidden'],
  814. 'buddies' => $return['num_buddies'],
  815. 'num_users' => $return['num_users_online'],
  816. 'total_users' => $return['num_users_online'] + $return['num_guests'] + $return['num_spiders'],
  817. );
  818. echo '
  819. ', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
  820. $bracketList = array();
  821. if (!empty($user_info['buddies']))
  822. $bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
  823. if (!empty($return['num_spiders']))
  824. $bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
  825. if (!empty($return['num_users_hidden']))
  826. $bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
  827. if (!empty($bracketList))
  828. echo ' (' . implode(', ', $bracketList) . ')';
  829. echo '<br />
  830. ', implode(', ', $return['list_users_online']);
  831. // Showing membergroups?
  832. if (!empty($settings['show_group_key']) && !empty($return['membergroups']))
  833. echo '<br />
  834. [' . implode(']&nbsp;&nbsp;[', $return['membergroups']) . ']';
  835. }
  836. // Just like whosOnline except it also logs the online presence.
  837. function ssi_logOnline($output_method = 'echo')
  838. {
  839. writeLog();
  840. if ($output_method != 'echo')
  841. return ssi_whosOnline($output_method);
  842. else
  843. ssi_whosOnline($output_method);
  844. }
  845. // Shows a login box.
  846. function ssi_login($redirect_to = '', $output_method = 'echo')
  847. {
  848. global $scripturl, $txt, $user_info, $context, $modSettings;
  849. if ($redirect_to != '')
  850. $_SESSION['login_url'] = $redirect_to;
  851. if ($output_method != 'echo' || !$user_info['is_guest'])
  852. return $user_info['is_guest'];
  853. echo '
  854. <form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '">
  855. <table border="0" cellspacing="1" cellpadding="0" class="ssi_table">
  856. <tr>
  857. <td align="right"><label for="user">', $txt['username'], ':</label>&nbsp;</td>
  858. <td><input type="text" id="user" name="user" size="9" value="', $user_info['username'], '" class="input_text" /></td>
  859. </tr><tr>
  860. <td align="right"><label for="passwrd">', $txt['password'], ':</label>&nbsp;</td>
  861. <td><input type="password" name="passwrd" id="passwrd" size="9" class="input_password" /></td>
  862. </tr>';
  863. // Open ID?
  864. if (!empty($modSettings['enableOpenID']))
  865. echo '<tr>
  866. <td colspan="2" align="center"><strong>&mdash;', $txt['or'], '&mdash;</strong></td>
  867. </tr><tr>
  868. <td align="right"><label for="openid_url">', $txt['openid'], ':</label>&nbsp;</td>
  869. <td><input type="text" name="openid_identifier" id="openid_url" class="input_text openid_login" size="17" /></td>
  870. </tr>';
  871. echo '<tr>
  872. <td><input type="hidden" name="cookielength" value="-1" /></td>
  873. <td><input type="submit" value="', $txt['login'], '" class="button_submit" /></td>
  874. </tr>
  875. </table>
  876. </form>';
  877. }
  878. // Show the most-voted-in poll.
  879. function ssi_topPoll($output_method = 'echo')
  880. {
  881. // Just use recentPoll, no need to duplicate code...
  882. return ssi_recentPoll(true, $output_method);
  883. }
  884. // Show the most recently posted poll.
  885. function ssi_recentPoll($topPollInstead = false, $output_method = 'echo')
  886. {
  887. global $db_prefix, $txt, $settings, $boardurl, $user_info, $context, $smcFunc, $modSettings;
  888. $boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote'));
  889. if (empty($boardsAllowed))
  890. return array();
  891. $request = $smcFunc['db_query']('', '
  892. SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time
  893. FROM {db_prefix}polls AS p
  894. INNER JOIN {db_prefix}topics AS t ON (t.id_poll = p.id_poll' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ')
  895. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)' . ($topPollInstead ? '
  896. INNER JOIN {db_prefix}poll_choices AS pc ON (pc.id_poll = p.id_poll)' : '') . '
  897. LEFT JOIN {db_prefix}log_polls AS lp ON (lp.id_poll = p.id_poll AND lp.id_member > {int:no_member} AND lp.id_member = {int:current_member})
  898. WHERE p.voting_locked = {int:voting_opened}
  899. AND (p.expire_time = {int:no_expiration} OR {int:current_time} < p.expire_time)
  900. AND ' . ($user_info['is_guest'] ? 'p.guest_vote = {int:guest_vote_allowed}' : 'lp.id_choice IS NULL') . '
  901. AND {query_wanna_see_board}' . (!in_array(0, $boardsAllowed) ? '
  902. AND b.id_board IN ({array_int:boards_allowed_list})' : '') . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  903. AND b.id_board != {int:recycle_enable}' : '') . '
  904. ORDER BY ' . ($topPollInstead ? 'pc.votes' : 'p.id_poll') . ' DESC
  905. LIMIT 1',
  906. array(
  907. 'current_member' => $user_info['id'],
  908. 'boards_allowed_list' => $boardsAllowed,
  909. 'is_approved' => 1,
  910. 'guest_vote_allowed' => 1,
  911. 'no_member' => 0,
  912. 'voting_opened' => 0,
  913. 'no_expiration' => 0,
  914. 'current_time' => time(),
  915. 'recycle_enable' => $modSettings['recycle_board'],
  916. )
  917. );
  918. $row = $smcFunc['db_fetch_assoc']($request);
  919. $smcFunc['db_free_result']($request);
  920. // This user has voted on all the polls.
  921. if ($row === false)
  922. return array();
  923. // If this is a guest who's voted we'll through ourselves to show poll to show the results.
  924. if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))))
  925. return ssi_showPoll($row['id_topic'], $output_method);
  926. $request = $smcFunc['db_query']('', '
  927. SELECT COUNT(DISTINCT id_member)
  928. FROM {db_prefix}log_polls
  929. WHERE id_poll = {int:current_poll}',
  930. array(
  931. 'current_poll' => $row['id_poll'],
  932. )
  933. );
  934. list ($total) = $smcFunc['db_fetch_row']($request);
  935. $smcFunc['db_free_result']($request);
  936. $request = $smcFunc['db_query']('', '
  937. SELECT id_choice, label, votes
  938. FROM {db_prefix}poll_choices
  939. WHERE id_poll = {int:current_poll}',
  940. array(
  941. 'current_poll' => $row['id_poll'],
  942. )
  943. );
  944. $options = array();
  945. while ($rowChoice = $smcFunc['db_fetch_assoc']($request))
  946. {
  947. censorText($rowChoice['label']);
  948. $options[$rowChoice['id_choice']] = array($rowChoice['label'], $rowChoice['votes']);
  949. }
  950. $smcFunc['db_free_result']($request);
  951. // Can they view it?
  952. $is_expired = !empty($row['expire_time']) && $row['expire_time'] < time();
  953. $allow_view_results = allowedTo('moderate_board') || $row['hide_results'] == 0 || $is_expired;
  954. $return = array(
  955. 'id' => $row['id_poll'],
  956. 'image' => 'poll',
  957. 'question' => $row['question'],
  958. 'total_votes' => $total,
  959. 'is_locked' => false,
  960. 'topic' => $row['id_topic'],
  961. 'allow_view_results' => $allow_view_results,
  962. 'options' => array()
  963. );
  964. // Calculate the percentages and bar lengths...
  965. $divisor = $return['total_votes'] == 0 ? 1 : $return['total_votes'];
  966. foreach ($options as $i => $option)
  967. {
  968. $bar = floor(($option[1] * 100) / $divisor);
  969. $barWide = $bar == 0 ? 1 : floor(($bar * 5) / 3);
  970. $return['options'][$i] = array(
  971. 'id' => 'options-' . ($topPollInstead ? 'top-' : 'recent-') . $i,
  972. 'percent' => $bar,
  973. 'votes' => $option[1],
  974. 'bar' => '<span style="white-space: nowrap;"><img src="' . $settings['images_url'] . '/poll_' . ($context['right_to_left'] ? 'right' : 'left') . '.gif" alt="" /><img src="' . $settings['images_url'] . '/poll_middle.gif" width="' . $barWide . '" height="12" alt="-" /><img src="' . $settings['images_url'] . '/poll_' . ($context['right_to_left'] ? 'left' : 'right') . '.gif" alt="" /></span>',
  975. 'option' => parse_bbc($option[0]),
  976. 'vote_button' => '<input type="' . ($row['max_votes'] > 1 ? 'checkbox' : 'radio') . '" name="options[]" id="options-' . ($topPollInstead ? 'top-' : 'recent-') . $i . '" value="' . $i . '" class="input_' . ($row['max_votes'] > 1 ? 'check' : 'radio') . '" />'
  977. );
  978. }
  979. $return['allowed_warning'] = $row['max_votes'] > 1 ? sprintf($txt['poll_options6'], min(count($options), $row['max_votes'])) : '';
  980. if ($output_method != 'echo')
  981. return $return;
  982. if ($allow_view_results)
  983. {
  984. echo '
  985. <form class="ssi_poll" action="', $boardurl, '/SSI.php?ssi_function=pollVote" method="post" accept-charset="', $context['character_set'], '">
  986. <strong>', $return['question'], '</strong><br />
  987. ', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br />' : '';
  988. foreach ($return['options'] as $option)
  989. echo '
  990. <label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br />';
  991. echo '
  992. <input type="submit" value="', $txt['poll_vote'], '" class="button_submit" />
  993. <input type="hidden" name="poll" value="', $return['id'], '" />
  994. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
  995. </form>';
  996. }
  997. else
  998. echo $txt['poll_cannot_see'];
  999. }
  1000. function ssi_showPoll($topic = null, $output_method = 'echo')
  1001. {
  1002. global $db_prefix, $txt, $settings, $boardurl, $user_info, $context, $smcFunc, $modSettings;
  1003. $boardsAllowed = boardsAllowedTo('poll_view');
  1004. if (empty($boardsAllowed))
  1005. return array();
  1006. if ($topic === null && isset($_REQUEST['ssi_topic']))
  1007. $topic = (int) $_REQUEST['ssi_topic'];
  1008. else
  1009. $topic = (int) $topic;
  1010. $request = $smcFunc['db_query']('', '
  1011. SELECT
  1012. p.id_poll, p.question, p.voting_locked, p.hide_results, p.expire_time, p.max_votes, p.guest_vote, b.id_board
  1013. FROM {db_prefix}topics AS t
  1014. INNER JOIN {db_prefix}polls AS p ON (p.id_poll = t.id_poll)
  1015. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  1016. WHERE t.id_topic = {int:current_topic}
  1017. AND {query_see_board}' . (!in_array(0, $boardsAllowed) ? '
  1018. AND b.id_board IN ({array_int:boards_allowed_see})' : '') . ($modSettings['postmod_active'] ? '
  1019. AND t.approved = {int:is_approved}' : '') . '
  1020. LIMIT 1',
  1021. array(
  1022. 'current_topic' => $topic,
  1023. 'boards_allowed_see' => $boardsAllowed,
  1024. 'is_approved' => 1,
  1025. )
  1026. );
  1027. // Either this topic has no poll, or the user cannot view it.
  1028. if ($smcFunc['db_num_rows']($request) == 0)
  1029. return array();
  1030. $row = $smcFunc['db_fetch_assoc']($request);
  1031. $smcFunc['db_free_result']($request);
  1032. // Check if they can vote.
  1033. if (!empty($row['expire_time']) && $row['expire_time'] < time())
  1034. $allow_vote = false;
  1035. elseif ($user_info['is_guest'] && $row['guest_vote'] && (!isset($_COOKIE['guest_poll_vote']) || !in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))
  1036. $allow_vote = true;
  1037. elseif ($user_info['is_guest'])
  1038. $allow_vote = false;
  1039. elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board']))
  1040. $allow_vote = false;
  1041. else
  1042. {
  1043. $request = $smcFunc['db_query']('', '
  1044. SELECT id_member
  1045. FROM {db_prefix}log_polls
  1046. WHERE id_poll = {int:current_poll}
  1047. AND id_member = {int:current_member}
  1048. LIMIT 1',
  1049. array(
  1050. 'current_member' => $user_info['id'],
  1051. 'current_poll' => $row['id_poll'],
  1052. )
  1053. );
  1054. $allow_vote = $smcFunc['db_num_rows']($request) == 0;
  1055. $smcFunc['db_free_result']($request);
  1056. }
  1057. // Can they view?
  1058. $is_expired = !empty($row['expire_time']) && $row['expire_time'] < time();
  1059. $allow_view_results = allowedTo('moderate_board') || $row['hide_results'] == 0 || ($row['hide_results'] == 1 && !$allow_vote) || $is_expired;
  1060. $request = $smcFunc['db_query']('', '
  1061. SELECT COUNT(DISTINCT id_member)
  1062. FROM {db_prefix}log_polls
  1063. WHERE id_poll = {int:current_poll}',
  1064. array(
  1065. 'current_poll' => $row['id_poll'],
  1066. )
  1067. );
  1068. list ($total) = $smcFunc['db_fetch_row']($request);
  1069. $smcFunc['db_free_result']($request);
  1070. $request = $smcFunc['db_query']('', '
  1071. SELECT id_choice, label, votes
  1072. FROM {db_prefix}poll_choices
  1073. WHERE id_poll = {int:current_poll}',
  1074. array(
  1075. 'current_poll' => $row['id_poll'],
  1076. )
  1077. );
  1078. $options = array();
  1079. $total_votes = 0;
  1080. while ($rowChoice = $smcFunc['db_fetch_assoc']($request))
  1081. {
  1082. censorText($rowChoice['label']);
  1083. $options[$rowChoice['id_choice']] = array($rowChoice['label'], $rowChoice['votes']);
  1084. $total_votes += $rowChoice['votes'];
  1085. }
  1086. $smcFunc['db_free_result']($request);
  1087. $return = array(
  1088. 'id' => $row['id_poll'],
  1089. 'image' => empty($pollinfo['voting_locked']) ? 'poll' : 'locked_poll',
  1090. 'question' => $row['question'],
  1091. 'total_votes' => $total,
  1092. 'is_locked' => !empty($pollinfo['voting_locked']),
  1093. 'allow_vote' => $allow_vote,
  1094. 'allow_view_results' => $allow_view_results,
  1095. 'topic' => $topic
  1096. );
  1097. // Calculate the percentages and bar lengths...
  1098. $divisor = $total_votes == 0 ? 1 : $total_votes;
  1099. foreach ($options as $i => $option)
  1100. {
  1101. $bar = floor(($option[1] * 100) / $divisor);
  1102. $barWide = $bar == 0 ? 1 : floor(($bar * 5) / 3);
  1103. $return['options'][$i] = array(
  1104. 'id' => 'options-' . $i,
  1105. 'percent' => $bar,
  1106. 'votes' => $option[1],
  1107. 'bar' => '<span style="white-space: nowrap;"><img src="' . $settings['images_url'] . '/poll_' . ($context['right_to_left'] ? 'right' : 'left') . '.gif" alt="" /><img src="' . $settings['images_url'] . '/poll_middle.gif" width="' . $barWide . '" height="12" alt="-" /><img src="' . $settings['images_url'] . '/poll_' . ($context['right_to_left'] ? 'left' : 'right') . '.gif" alt="" /></span>',
  1108. 'option' => parse_bbc($option[0]),
  1109. 'vote_button' => '<input type="' . ($row['max_votes'] > 1 ? 'checkbox' : 'radio') . '" name="options[]" id="options-' . $i . '" value="' . $i . '" class="input_' . ($row['max_votes'] > 1 ? 'check' : 'radio') . '" />'
  1110. );
  1111. }
  1112. $return['allowed_warning'] = $row['max_votes'] > 1 ? sprintf($txt['poll_options6'], min(count($options), $row['max_votes'])) : '';
  1113. if ($output_method != 'echo')
  1114. return $return;
  1115. if ($return['allow_vote'])
  1116. {
  1117. echo '
  1118. <form class="ssi_poll" action="', $boardurl, '/SSI.php?ssi_function=pollVote" method="post" accept-charset="', $context['character_set'], '">
  1119. <strong>', $return['question'], '</strong><br />
  1120. ', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br />' : '';
  1121. foreach ($return['options'] as $option)
  1122. echo '
  1123. <label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br />';
  1124. echo '
  1125. <input type="submit" value="', $txt['poll_vote'], '" class="button_submit" />
  1126. <input type="hidden" name="poll" value="', $return['id'], '" />
  1127. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
  1128. </form>';
  1129. }
  1130. elseif ($return['allow_view_results'])
  1131. {
  1132. echo '
  1133. <div class="ssi_poll">
  1134. <strong>', $return['question'], '</strong>
  1135. <dl>';
  1136. foreach ($return['options'] as $option)
  1137. echo '
  1138. <dt>', $option['option'], '</dt>
  1139. <dd>
  1140. <div class="ssi_poll_bar" style="border: 1px solid #666; height: 1em">
  1141. <div class="ssi_poll_bar_fill" style="background: #ccf; height: 1em; width: ', $option['percent'], '%;">
  1142. </div>
  1143. </div>
  1144. ', $option['votes'], ' (', $option['percent'], '%)
  1145. </dd>';
  1146. echo '
  1147. </dl>
  1148. <strong>', $txt['poll_total_voters'], ': ', $return['total_votes'], '</strong>
  1149. </div>';
  1150. }
  1151. // Cannot see it I'm afraid!
  1152. else
  1153. echo $txt['poll_cannot_see'];
  1154. }
  1155. // Takes care of voting - don't worry, this is done automatically.
  1156. function ssi_pollVote()
  1157. {
  1158. global $context, $db_prefix, $user_info, $sc, $smcFunc, $sourcedir, $modSettings;
  1159. if (!isset($_POST[$context['session_var']]) || $_POST[$context['session_var']] != $sc || empty($_POST['options']) || !isset($_POST['poll']))
  1160. {
  1161. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1162. <html>
  1163. <head>
  1164. <script type="text/javascript"><!-- // --><![CDATA[
  1165. history.go(-1);
  1166. // ]]></script>
  1167. </head>
  1168. <body>&laquo;</body>
  1169. </html>';
  1170. return;
  1171. }
  1172. // This can cause weird errors! (ie. copyright missing.)
  1173. checkSession();
  1174. $_POST['poll'] = (int) $_POST['poll'];
  1175. // Check if they have already voted, or voting is locked.
  1176. $request = $smcFunc['db_query']('', '
  1177. SELECT
  1178. p.id_poll, p.voting_locked, p.expire_time, p.max_votes, p.guest_vote,
  1179. t.id_topic,
  1180. IFNULL(lp.id_choice, -1) AS selected
  1181. FROM {db_prefix}polls AS p
  1182. INNER JOIN {db_prefix}topics AS t ON (t.id_poll = {int:current_poll})
  1183. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  1184. LEFT JOIN {db_prefix}log_polls AS lp ON (lp.id_poll = p.id_poll AND lp.id_member = {int:current_member})
  1185. WHERE p.id_poll = {int:current_poll}
  1186. AND {query_see_board}' . ($modSettings['postmod_active'] ? '
  1187. AND t.approved = {int:is_approved}' : '') . '
  1188. LIMIT 1',
  1189. array(
  1190. 'current_member' => $user_info['id'],
  1191. 'current_poll' => $_POST['poll'],
  1192. 'is_approved' => 1,
  1193. )
  1194. );
  1195. if ($smcFunc['db_num_rows']($request) == 0)
  1196. die;
  1197. $row = $smcFunc['db_fetch_assoc']($request);
  1198. $smcFunc['db_free_result']($request);
  1199. if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time']))
  1200. redirectexit('topic=' . $row['id_topic'] . '.0');
  1201. // Too many options checked?
  1202. if (count($_REQUEST['options']) > $row['max_votes'])
  1203. redirectexit('topic=' . $row['id_topic'] . '.0');
  1204. // It's a guest who has already voted?
  1205. if ($user_info['is_guest'])
  1206. {
  1207. // Guest voting disabled?
  1208. if (!$row['guest_vote'])
  1209. redirectexit('topic=' . $row['id_topic'] . '.0');
  1210. // Already voted?
  1211. elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))
  1212. redirectexit('topic=' . $row['id_topic'] . '.0');
  1213. }
  1214. $options = array();
  1215. $inserts = array();
  1216. foreach ($_REQUEST['options'] as $id)
  1217. {
  1218. $id = (int) $id;
  1219. $options[] = $id;
  1220. $inserts[] = array($_POST['poll'], $user_info['id'], $id);
  1221. }
  1222. // Add their vote in to the tally.
  1223. $smcFunc['db_insert']('insert',
  1224. $db_prefix . 'log_polls',
  1225. array('id_poll' => 'int', 'id_member' => 'int', 'id_choice' => 'int'),
  1226. $inserts,
  1227. array('id_poll', 'id_member', 'id_choice')
  1228. );
  1229. $smcFunc['db_query']('', '
  1230. UPDATE {db_prefix}poll_choices
  1231. SET votes = votes + 1
  1232. WHERE id_poll = {int:current_poll}
  1233. AND id_choice IN ({array_int:option_list})',
  1234. array(
  1235. 'option_list' => $options,
  1236. 'current_poll' => $_POST['poll'],
  1237. )
  1238. );
  1239. // Track the vote if a guest.
  1240. if ($user_info['is_guest'])
  1241. {
  1242. $_COOKIE['guest_poll_vote'] = !empty($_COOKIE['guest_poll_vote']) ? ($_COOKIE['guest_poll_vote'] . ',' . $row['id_poll']) : $row['id_poll'];
  1243. require_once($sourcedir . '/Subs-Auth.php');
  1244. $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
  1245. setcookie('guest_poll_vote', $_COOKIE['guest_poll_vote'], time() + 2500000, $cookie_url[1], $cookie_url[0], 0);
  1246. }
  1247. redirectexit('topic=' . $row['id_topic'] . '.0');
  1248. }
  1249. // Show a search box.
  1250. function ssi_quickSearch($output_method = 'echo')
  1251. {
  1252. global $scripturl, $txt, $context;
  1253. if ($output_method != 'echo')
  1254. return $scripturl . '?action=search';
  1255. echo '
  1256. <form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
  1257. <input type="hidden" name="advanced" value="0" /><input type="text" name="search" size="30" class="input_text" /> <input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
  1258. </form>';
  1259. }
  1260. // Show what would be the forum news.
  1261. function ssi_news($output_method = 'echo')
  1262. {
  1263. global $context;
  1264. if ($output_method != 'echo')
  1265. return $context['random_news_line'];
  1266. echo $context['random_news_line'];
  1267. }
  1268. // Show today's birthdays.
  1269. function ssi_todaysBirthdays($output_method = 'echo')
  1270. {
  1271. global $scripturl, $modSettings, $user_info;
  1272. $eventOptions = array(
  1273. 'include_birthdays' => true,
  1274. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  1275. );
  1276. $return = cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  1277. if ($output_method != 'echo')
  1278. return $return['calendar_birthdays'];
  1279. foreach ($return['calendar_birthdays'] as $member)
  1280. echo '
  1281. <a href="', $scripturl, '?action=profile;u=', $member['id'], '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>' . (!$member['is_last'] ? ', ' : '');
  1282. }
  1283. // Show today's holidays.
  1284. function ssi_todaysHolidays($output_method = 'echo')
  1285. {
  1286. global $modSettings, $user_info;
  1287. $eventOptions = array(
  1288. 'include_holidays' => true,
  1289. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  1290. );
  1291. $return = cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  1292. if ($output_method != 'echo')
  1293. return $return['calendar_holidays'];
  1294. echo '
  1295. ', implode(', ', $return['calendar_holidays']);
  1296. }
  1297. // Show today's events.
  1298. function ssi_todaysEvents($output_method = 'echo')
  1299. {
  1300. global $modSettings, $user_info;
  1301. $eventOptions = array(
  1302. 'include_events' => true,
  1303. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  1304. );
  1305. $return = cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  1306. if ($output_method != 'echo')
  1307. return $return['calendar_events'];
  1308. foreach ($return['calendar_events'] as $event)
  1309. {
  1310. if ($event['can_edit'])
  1311. echo '
  1312. <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
  1313. echo '
  1314. ' . $event['link'] . (!$event['is_last'] ? ', ' : '');
  1315. }
  1316. }
  1317. // Show all calendar entires for today. (birthdays, holodays, and events.)
  1318. function ssi_todaysCalendar($output_method = 'echo')
  1319. {
  1320. global $modSettings, $txt, $scripturl, $user_info;
  1321. $eventOptions = array(
  1322. 'include_birthdays' => true,
  1323. 'include_holidays' => true,
  1324. 'include_events' => true,
  1325. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  1326. );
  1327. $return = cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  1328. if ($output_method != 'echo')
  1329. return $return;
  1330. if (!empty($return['calendar_holidays']))
  1331. echo '
  1332. <span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br /></span>';
  1333. if (!empty($return['calendar_birthdays']))
  1334. {
  1335. echo '
  1336. <span class="birthday">' . $txt['birthdays_upcoming'] . '</span> ';
  1337. foreach ($return['calendar_birthdays'] as $member)
  1338. echo '
  1339. <a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', !$member['is_last'] ? ', ' : '';
  1340. echo '
  1341. <br />';
  1342. }
  1343. if (!empty($return['calendar_events']))
  1344. {
  1345. echo '
  1346. <span class="event">' . $txt['events_upcoming'] . '</span> ';
  1347. foreach ($return['calendar_events'] as $event)
  1348. {
  1349. if ($event['can_edit'])
  1350. echo '
  1351. <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
  1352. echo '
  1353. ' . $event['link'] . (!$event['is_last'] ? ', ' : '');
  1354. }
  1355. }
  1356. }
  1357. // Show the latest news, with a template... by board.
  1358. function ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
  1359. {
  1360. global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
  1361. global $smcFunc;
  1362. loadLanguage('Stats');
  1363. // Must be integers....
  1364. if ($limit === null)
  1365. $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
  1366. else
  1367. $limit = (int) $limit;
  1368. if ($start === null)
  1369. $start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
  1370. else
  1371. $start = (int) $start;
  1372. if ($board !== null)
  1373. $board = (int) $board;
  1374. elseif (isset($_GET['board']))
  1375. $board = (int) $_GET['board'];
  1376. if ($length === null)
  1377. $length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
  1378. else
  1379. $length = (int) $length;
  1380. $limit = max(0, $limit);
  1381. $start = max(0, $start);
  1382. // Make sure guests can see this board.
  1383. $request = $smcFunc['db_query']('', '
  1384. SELECT id_board
  1385. FROM {db_prefix}boards
  1386. WHERE ' . ($board === null ? '' : 'id_board = {int:current_board}
  1387. AND ') . 'FIND_IN_SET(-1, member_groups)
  1388. LIMIT 1',
  1389. array(
  1390. 'current_board' => $board,
  1391. )
  1392. );
  1393. if ($smcFunc['db_num_rows']($request) == 0)
  1394. {
  1395. if ($output_method == 'echo')
  1396. die($txt['ssi_no_guests']);
  1397. else
  1398. return array();
  1399. }
  1400. list ($board) = $smcFunc['db_fetch_row']($request);
  1401. $smcFunc['db_free_result']($request);
  1402. // Load the message icons - the usual suspects.
  1403. $stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
  1404. $icon_sources = array();
  1405. foreach ($stable_icons as $icon)
  1406. $icon_sources[$icon] = 'images_url';
  1407. // Find the post ids.
  1408. $request = $smcFunc['db_query']('', '
  1409. SELECT id_first_msg
  1410. FROM {db_prefix}topics
  1411. WHERE id_board = {int:current_board}' . ($modSettings['postmod_active'] ? '
  1412. AND approved = {int:is_approved}' : '') . '
  1413. ORDER BY id_first_msg DESC
  1414. LIMIT ' . $start . ', ' . $limit,
  1415. array(
  1416. 'current_board' => $board,
  1417. 'is_approved' => 1,
  1418. )
  1419. );
  1420. $posts = array();
  1421. while ($row = $smcFunc['db_fetch_assoc']($request))
  1422. $posts[] = $row['id_first_msg'];
  1423. $smcFunc['db_free_result']($request);
  1424. if (empty($posts))
  1425. return array();
  1426. // Find the posts.
  1427. $request = $smcFunc['db_query']('', '
  1428. SELECT
  1429. m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
  1430. t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, t.id_last_msg
  1431. FROM {db_prefix}topics AS t
  1432. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  1433. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1434. WHERE t.id_first_msg IN ({array_int:post_list})
  1435. ORDER BY t.id_first_msg DESC
  1436. LIMIT ' . count($posts),
  1437. array(
  1438. 'post_list' => $posts,
  1439. )
  1440. );
  1441. $return = array();
  1442. while ($row = $smcFunc['db_fetch_assoc']($request))
  1443. {
  1444. // If we want to limit the length of the post.
  1445. if (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
  1446. {
  1447. $row['body'] = $smcFunc['substr']($row['body'], 0, $length);
  1448. // The first space or line break. (<br />, etc.)
  1449. $cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));
  1450. if ($cutoff !== false)
  1451. $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
  1452. $row['body'] .= '...';
  1453. }
  1454. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
  1455. // Check that this message icon is there...
  1456. if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
  1457. $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
  1458. censorText($row['subject']);
  1459. censorText($row['body']);
  1460. $return[] = array(
  1461. 'id' => $row['id_topic'],
  1462. 'message_id' => $row['id_msg'],
  1463. 'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" alt="' . $row['icon'] . '" />',
  1464. 'subject' => $row['subject'],
  1465. 'time' => timeformat($row['poster_time']),
  1466. 'timestamp' => forum_time(true, $row['poster_time']),
  1467. 'body' => $row['body'],
  1468. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
  1469. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>',
  1470. 'replies' => $row['num_replies'],
  1471. 'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';last_msg=' . $row['id_last_msg'],
  1472. 'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';last_msg=' . $row['id_last_msg'] . '">' . $txt['ssi_write_comment'] . '</a>',
  1473. 'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
  1474. 'poster' => array(
  1475. 'id' => $row['id_member'],
  1476. 'name' => $row['poster_name'],
  1477. 'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
  1478. 'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
  1479. ),
  1480. 'locked' => !empty($row['locked']),
  1481. 'is_last' => false
  1482. );
  1483. }
  1484. $smcFunc['db_free_result']($request);
  1485. if (empty($return))
  1486. return $return;
  1487. $return[count($return) - 1]['is_last'] = true;
  1488. if ($output_method != 'echo')
  1489. return $return;
  1490. foreach ($return as $news)
  1491. {
  1492. echo '
  1493. <div class="news_item">
  1494. <h3 class="news_header">
  1495. ', $news['icon'], '
  1496. <a href="', $news['href'], '">', $news['subject'], '</a>
  1497. </h3>
  1498. <div class="news_timestamp">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '</div>
  1499. <div class="news_body" style="padding: 2ex 0;">', $news['body'], '</div>
  1500. ', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
  1501. </div>';
  1502. if (!$news['is_last'])
  1503. echo '
  1504. <hr />';
  1505. }
  1506. }
  1507. // Show the most recent events.
  1508. function ssi_recentEvents($max_events = 7, $output_method = 'echo')
  1509. {
  1510. global $db_prefix, $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc;
  1511. // Find all events which are happening in the near future that the member can see.
  1512. $request = $smcFunc['db_query']('', '
  1513. SELECT
  1514. cal.id_event, cal.start_date, cal.end_date, cal.title, cal.id_member, cal.id_topic,
  1515. cal.id_board, t.id_first_msg, t.approved
  1516. FROM {db_prefix}calendar AS cal
  1517. LEFT JOIN {db_prefix}boards AS b ON (b.id_board = cal.id_board)
  1518. LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = cal.id_topic)
  1519. WHERE cal.start_date <= {date:current_date}
  1520. AND cal.end_date >= {date:current_date}
  1521. AND (cal.id_board = {int:no_board} OR {query_wanna_see_board})
  1522. ORDER BY cal.start_date DESC
  1523. LIMIT ' . $max_events,
  1524. array(
  1525. 'current_date' => strftime('%Y-%m-%d', forum_time(false)),
  1526. 'no_board' => 0,
  1527. )
  1528. );
  1529. $return = array();
  1530. $duplicates = array();
  1531. while ($row = $smcFunc['db_fetch_assoc']($request))
  1532. {
  1533. // Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
  1534. if (!empty($duplicates[$row['title'] . $row['id_topic']]))
  1535. continue;
  1536. // Censor the title.
  1537. censorText($row['title']);
  1538. if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false)))
  1539. $date = strftime('%Y-%m-%d', forum_time(false));
  1540. else
  1541. $date = $row['start_date'];
  1542. // If the topic it is attached to is not approved then don't link it.
  1543. if (!empty($row['id_first_msg']) && !$row['approved'])
  1544. $row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
  1545. $return[$date][] = array(
  1546. 'id' => $row['id_event'],
  1547. 'title' => $row['title'],
  1548. 'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
  1549. 'modify_href' => $scripturl . '?action=' . ($row['id_board'] == 0 ? 'calendar;sa=post;' : 'post;msg=' . $row['id_first_msg'] . ';topic=' . $row['id_topic'] . '.0;calendar;') . 'eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  1550. 'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
  1551. 'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
  1552. 'start_date' => $row['start_date'],
  1553. 'end_date' => $row['end_date'],
  1554. 'is_last' => false
  1555. );
  1556. // Let's not show this one again, huh?
  1557. $duplicates[$row['title'] . $row['id_topic']] = true;
  1558. }
  1559. $smcFunc['db_free_result']($request);
  1560. foreach ($return as $mday => $array)
  1561. $return[$mday][count($array) - 1]['is_last'] = true;
  1562. if ($output_method != 'echo' || empty($return))
  1563. return $return;
  1564. // Well the output method is echo.
  1565. echo '
  1566. <span class="event">' . $txt['events'] . '</span> ';
  1567. foreach ($return as $mday => $array)
  1568. foreach ($array as $event)
  1569. {
  1570. if ($event['can_edit'])
  1571. echo '
  1572. <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
  1573. echo '
  1574. ' . $event['link'] . (!$event['is_last'] ? ', ' : '');
  1575. }
  1576. }
  1577. // Check the passed id_member/password. If $is_username is true, treats $id as a username.
  1578. function ssi_checkPassword($id = null, $password = null, $is_username = false)
  1579. {
  1580. global $db_prefix, $sourcedir, $smcFunc;
  1581. // If $id is null, this was most likely called from a query string and should do nothing.
  1582. if ($id === null)
  1583. return;
  1584. $request = $smcFunc['db_query']('', '
  1585. SELECT passwd, member_name, is_activated
  1586. FROM {db_prefix}members
  1587. WHERE ' . ($is_username ? 'member_name' : 'id_member') . ' = {string:id}
  1588. LIMIT 1',
  1589. array(
  1590. 'id' => $id,
  1591. )
  1592. );
  1593. list ($pass, $user, $active) = $smcFunc['db_fetch_row']($request);
  1594. $smcFunc['db_free_result']($request);
  1595. return sha1(strtolower($user) . $password) == $pass && $active == 1;
  1596. }
  1597. // We want to show the recent attachments outside of the forum.
  1598. function ssi_recentAttachments($num_attachments = 10, $attachment_ext = array(), $output_method = 'echo')
  1599. {
  1600. global $smcFunc, $context, $modSettings, $scripturl, $txt, $settings;
  1601. // We want to make sure that we only get attachments for boards that we can see *if* any.
  1602. $attachments_boards = boardsAllowedTo('view_attachments');
  1603. // No boards? Adios amigo.
  1604. if (empty($attachments_boards))
  1605. return array();
  1606. // Is it an array?
  1607. if (!is_array($attachment_ext))
  1608. $attachment_ext = array($attachment_ext);
  1609. // Lets build the query.
  1610. $request = $smcFunc['db_query']('', '
  1611. SELECT
  1612. att.id_attach, att.id_msg, att.filename, IFNULL(att.size, 0) AS filesize, att.downloads, mem.id_member,
  1613. IFNULL(mem.real_name, m.poster_name) AS poster_name, m.id_topic, m.subject, t.id_board, m.poster_time,
  1614. att.width, att.height' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ', IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height') . '
  1615. FROM {db_prefix}attachments AS att
  1616. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = att.id_msg)
  1617. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
  1618. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : '
  1619. LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = att.id_thumb)') . '
  1620. WHERE att.attachment_type = 0' . ($attachments_boards === array(0) ? '' : '
  1621. AND m.id_board IN ({array_int:boards_can_see})') . (!empty($attachment_ext) ? '
  1622. AND att.fileext IN ({array_string:attachment_ext})' : '') .
  1623. (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  1624. AND t.approved = {int:is_approved}
  1625. AND m.approved = {int:is_approved}
  1626. AND att.approved = {int:is_approved}') . '
  1627. ORDER BY att.id_attach DESC
  1628. LIMIT {int:num_attachments}',
  1629. array(
  1630. 'boards_can_see' => $attachments_boards,
  1631. 'attachment_ext' => $attachment_ext,
  1632. 'num_attachments' => $num_attachments,
  1633. 'is_approved' => 1,
  1634. )
  1635. );
  1636. // We have something.
  1637. $attachments = array();
  1638. while ($row = $smcFunc['db_fetch_assoc']($request))
  1639. {
  1640. $filename = preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($row['filename']));
  1641. // Is it an image?
  1642. $attachments[$row['id_attach']] = array(
  1643. 'member' => array(
  1644. 'id' => $row['id_member'],
  1645. 'name' => $row['poster_name'],
  1646. 'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>',
  1647. ),
  1648. 'file' => array(
  1649. 'filename' => $filename,
  1650. 'filesize' => round($row['filesize'] /1024, 2) . $txt['kilobyte'],
  1651. 'downloads' => $row['downloads'],
  1652. 'href' => $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'],
  1653. 'link' => '<img src="' . $settings['images_url'] . '/icons/clip.gif" alt="" /> <a href="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'] . '">' . $filename . '</a>',
  1654. 'is_image' => !empty($row['width']) && !empty($row['height']) && !empty($modSettings['attachmentShowImages']),
  1655. ),
  1656. 'topic' => array(
  1657. 'id' => $row['id_topic'],
  1658. 'subject' => $row['subject'],
  1659. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
  1660. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>',
  1661. 'time' => timeformat($row['poster_time']),
  1662. ),
  1663. );
  1664. // Images.
  1665. if ($attachments[$row['id_attach']]['file']['is_image'])
  1666. {
  1667. $id_thumb = empty($row['id_thumb']) ? $row['id_attach'] : $row['id_thumb'];
  1668. $attachments[$row['id_attach']]['file']['image'] = array(
  1669. 'id' => $id_thumb,
  1670. 'width' => $row['width'],
  1671. 'height' => $row['height'],
  1672. 'img' => '<img src="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'] . ';image" alt="' . $filename . '" />',
  1673. 'thumb' => '<img src="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $id_thumb . ';image" alt="' . $filename . '" />',
  1674. 'href' => $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $id_thumb . ';image',
  1675. 'link' => '<a href="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'] . ';image"><img src="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $id_thumb . ';image" alt="' . $filename . '" /></a>',
  1676. );
  1677. }
  1678. }
  1679. $smcFunc['db_free_result']($request);
  1680. // So you just want an array? Here you can have it.
  1681. if ($output_method == 'array' || empty($attachments))
  1682. return $attachments;
  1683. // Give them the default.
  1684. echo '
  1685. <table class="ssi_downloads" cellpadding="2">
  1686. <tr>
  1687. <th align="left">', $txt['file'], '</th>
  1688. <th align="left">', $txt['posted_by'], '</th>
  1689. <th align="left">', $txt['downloads'], '</th>
  1690. <th align="left">', $txt['filesize'], '</th>
  1691. </tr>';
  1692. foreach ($attachments as $attach)
  1693. echo '
  1694. <tr>
  1695. <td>', $attach['file']['link'], '</td>
  1696. <td>', $attach['member']['link'], '</td>
  1697. <td align="center">', $attach['file']['downloads'], '</td>
  1698. <td>', $attach['file']['filesize'], '</td>
  1699. </tr>';
  1700. echo '
  1701. </table>';
  1702. }
  1703. ?>