SSI.php 73 KB

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