SSI.php 72 KB

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