SSI.php 71 KB

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