SSI.php 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973
  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 ($output_method != 'echo')
  1258. return $scripturl . '?action=search';
  1259. echo '
  1260. <form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
  1261. <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" />
  1262. </form>';
  1263. }
  1264. // Show what would be the forum news.
  1265. function ssi_news($output_method = 'echo')
  1266. {
  1267. global $context;
  1268. if ($output_method != 'echo')
  1269. return $context['random_news_line'];
  1270. echo $context['random_news_line'];
  1271. }
  1272. // Show today's birthdays.
  1273. function ssi_todaysBirthdays($output_method = 'echo')
  1274. {
  1275. global $scripturl, $modSettings, $user_info;
  1276. $eventOptions = array(
  1277. 'include_birthdays' => true,
  1278. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  1279. );
  1280. $return = cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  1281. if ($output_method != 'echo')
  1282. return $return['calendar_birthdays'];
  1283. foreach ($return['calendar_birthdays'] as $member)
  1284. echo '
  1285. <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'] ? ', ' : '');
  1286. }
  1287. // Show today's holidays.
  1288. function ssi_todaysHolidays($output_method = 'echo')
  1289. {
  1290. global $modSettings, $user_info;
  1291. $eventOptions = array(
  1292. 'include_holidays' => true,
  1293. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  1294. );
  1295. $return = cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  1296. if ($output_method != 'echo')
  1297. return $return['calendar_holidays'];
  1298. echo '
  1299. ', implode(', ', $return['calendar_holidays']);
  1300. }
  1301. // Show today's events.
  1302. function ssi_todaysEvents($output_method = 'echo')
  1303. {
  1304. global $modSettings, $user_info;
  1305. $eventOptions = array(
  1306. 'include_events' => true,
  1307. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  1308. );
  1309. $return = cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  1310. if ($output_method != 'echo')
  1311. return $return['calendar_events'];
  1312. foreach ($return['calendar_events'] as $event)
  1313. {
  1314. if ($event['can_edit'])
  1315. echo '
  1316. <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
  1317. echo '
  1318. ' . $event['link'] . (!$event['is_last'] ? ', ' : '');
  1319. }
  1320. }
  1321. // Show all calendar entires for today. (birthdays, holodays, and events.)
  1322. function ssi_todaysCalendar($output_method = 'echo')
  1323. {
  1324. global $modSettings, $txt, $scripturl, $user_info;
  1325. $eventOptions = array(
  1326. 'include_birthdays' => true,
  1327. 'include_holidays' => true,
  1328. 'include_events' => true,
  1329. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  1330. );
  1331. $return = cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  1332. if ($output_method != 'echo')
  1333. return $return;
  1334. if (!empty($return['calendar_holidays']))
  1335. echo '
  1336. <span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br /></span>';
  1337. if (!empty($return['calendar_birthdays']))
  1338. {
  1339. echo '
  1340. <span class="birthday">' . $txt['birthdays_upcoming'] . '</span> ';
  1341. foreach ($return['calendar_birthdays'] as $member)
  1342. echo '
  1343. <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'] ? ', ' : '';
  1344. echo '
  1345. <br />';
  1346. }
  1347. if (!empty($return['calendar_events']))
  1348. {
  1349. echo '
  1350. <span class="event">' . $txt['events_upcoming'] . '</span> ';
  1351. foreach ($return['calendar_events'] as $event)
  1352. {
  1353. if ($event['can_edit'])
  1354. echo '
  1355. <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
  1356. echo '
  1357. ' . $event['link'] . (!$event['is_last'] ? ', ' : '');
  1358. }
  1359. }
  1360. }
  1361. // Show the latest news, with a template... by board.
  1362. function ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
  1363. {
  1364. global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
  1365. global $smcFunc;
  1366. loadLanguage('Stats');
  1367. // Must be integers....
  1368. if ($limit === null)
  1369. $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
  1370. else
  1371. $limit = (int) $limit;
  1372. if ($start === null)
  1373. $start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
  1374. else
  1375. $start = (int) $start;
  1376. if ($board !== null)
  1377. $board = (int) $board;
  1378. elseif (isset($_GET['board']))
  1379. $board = (int) $_GET['board'];
  1380. if ($length === null)
  1381. $length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
  1382. else
  1383. $length = (int) $length;
  1384. $limit = max(0, $limit);
  1385. $start = max(0, $start);
  1386. // Make sure guests can see this board.
  1387. $request = $smcFunc['db_query']('', '
  1388. SELECT id_board
  1389. FROM {db_prefix}boards
  1390. WHERE ' . ($board === null ? '' : 'id_board = {int:current_board}
  1391. AND ') . 'FIND_IN_SET(-1, member_groups)
  1392. LIMIT 1',
  1393. array(
  1394. 'current_board' => $board,
  1395. )
  1396. );
  1397. if ($smcFunc['db_num_rows']($request) == 0)
  1398. {
  1399. if ($output_method == 'echo')
  1400. die($txt['ssi_no_guests']);
  1401. else
  1402. return array();
  1403. }
  1404. list ($board) = $smcFunc['db_fetch_row']($request);
  1405. $smcFunc['db_free_result']($request);
  1406. // Load the message icons - the usual suspects.
  1407. $stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'poll', 'moved', 'recycled', 'wireless');
  1408. $icon_sources = array();
  1409. foreach ($stable_icons as $icon)
  1410. $icon_sources[$icon] = 'images_url';
  1411. // Find the post ids.
  1412. $request = $smcFunc['db_query']('', '
  1413. SELECT id_first_msg
  1414. FROM {db_prefix}topics
  1415. WHERE id_board = {int:current_board}' . ($modSettings['postmod_active'] ? '
  1416. AND approved = {int:is_approved}' : '') . '
  1417. ORDER BY id_first_msg DESC
  1418. LIMIT ' . $start . ', ' . $limit,
  1419. array(
  1420. 'current_board' => $board,
  1421. 'is_approved' => 1,
  1422. )
  1423. );
  1424. $posts = array();
  1425. while ($row = $smcFunc['db_fetch_assoc']($request))
  1426. $posts[] = $row['id_first_msg'];
  1427. $smcFunc['db_free_result']($request);
  1428. if (empty($posts))
  1429. return array();
  1430. // Find the posts.
  1431. $request = $smcFunc['db_query']('', '
  1432. SELECT
  1433. m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
  1434. t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, t.id_last_msg
  1435. FROM {db_prefix}topics AS t
  1436. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  1437. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1438. WHERE t.id_first_msg IN ({array_int:post_list})
  1439. ORDER BY t.id_first_msg DESC
  1440. LIMIT ' . count($posts),
  1441. array(
  1442. 'post_list' => $posts,
  1443. )
  1444. );
  1445. $return = array();
  1446. while ($row = $smcFunc['db_fetch_assoc']($request))
  1447. {
  1448. // If we want to limit the length of the post.
  1449. if (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
  1450. {
  1451. $row['body'] = $smcFunc['substr']($row['body'], 0, $length);
  1452. // The first space or line break. (<br />, etc.)
  1453. $cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));
  1454. if ($cutoff !== false)
  1455. $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
  1456. $row['body'] .= '...';
  1457. }
  1458. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
  1459. // Check that this message icon is there...
  1460. if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
  1461. $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
  1462. censorText($row['subject']);
  1463. censorText($row['body']);
  1464. $return[] = array(
  1465. 'id' => $row['id_topic'],
  1466. 'message_id' => $row['id_msg'],
  1467. 'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.png" alt="' . $row['icon'] . '" />',
  1468. 'subject' => $row['subject'],
  1469. 'time' => timeformat($row['poster_time']),
  1470. 'timestamp' => forum_time(true, $row['poster_time']),
  1471. 'body' => $row['body'],
  1472. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
  1473. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>',
  1474. 'replies' => $row['num_replies'],
  1475. 'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';last_msg=' . $row['id_last_msg'],
  1476. '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>',
  1477. 'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
  1478. 'poster' => array(
  1479. 'id' => $row['id_member'],
  1480. 'name' => $row['poster_name'],
  1481. 'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
  1482. 'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
  1483. ),
  1484. 'locked' => !empty($row['locked']),
  1485. 'is_last' => false
  1486. );
  1487. }
  1488. $smcFunc['db_free_result']($request);
  1489. if (empty($return))
  1490. return $return;
  1491. $return[count($return) - 1]['is_last'] = true;
  1492. if ($output_method != 'echo')
  1493. return $return;
  1494. foreach ($return as $news)
  1495. {
  1496. echo '
  1497. <div class="news_item">
  1498. <h3 class="news_header">
  1499. ', $news['icon'], '
  1500. <a href="', $news['href'], '">', $news['subject'], '</a>
  1501. </h3>
  1502. <div class="news_timestamp">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '</div>
  1503. <div class="news_body" style="padding: 2ex 0;">', $news['body'], '</div>
  1504. ', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
  1505. </div>';
  1506. if (!$news['is_last'])
  1507. echo '
  1508. <hr />';
  1509. }
  1510. }
  1511. // Show the most recent events.
  1512. function ssi_recentEvents($max_events = 7, $output_method = 'echo')
  1513. {
  1514. global $db_prefix, $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc;
  1515. // Find all events which are happening in the near future that the member can see.
  1516. $request = $smcFunc['db_query']('', '
  1517. SELECT
  1518. cal.id_event, cal.start_date, cal.end_date, cal.title, cal.id_member, cal.id_topic,
  1519. cal.id_board, t.id_first_msg, t.approved
  1520. FROM {db_prefix}calendar AS cal
  1521. LEFT JOIN {db_prefix}boards AS b ON (b.id_board = cal.id_board)
  1522. LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = cal.id_topic)
  1523. WHERE cal.start_date <= {date:current_date}
  1524. AND cal.end_date >= {date:current_date}
  1525. AND (cal.id_board = {int:no_board} OR {query_wanna_see_board})
  1526. ORDER BY cal.start_date DESC
  1527. LIMIT ' . $max_events,
  1528. array(
  1529. 'current_date' => strftime('%Y-%m-%d', forum_time(false)),
  1530. 'no_board' => 0,
  1531. )
  1532. );
  1533. $return = array();
  1534. $duplicates = array();
  1535. while ($row = $smcFunc['db_fetch_assoc']($request))
  1536. {
  1537. // 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.
  1538. if (!empty($duplicates[$row['title'] . $row['id_topic']]))
  1539. continue;
  1540. // Censor the title.
  1541. censorText($row['title']);
  1542. if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false)))
  1543. $date = strftime('%Y-%m-%d', forum_time(false));
  1544. else
  1545. $date = $row['start_date'];
  1546. // If the topic it is attached to is not approved then don't link it.
  1547. if (!empty($row['id_first_msg']) && !$row['approved'])
  1548. $row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
  1549. $return[$date][] = array(
  1550. 'id' => $row['id_event'],
  1551. 'title' => $row['title'],
  1552. 'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
  1553. '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'],
  1554. 'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
  1555. 'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
  1556. 'start_date' => $row['start_date'],
  1557. 'end_date' => $row['end_date'],
  1558. 'is_last' => false
  1559. );
  1560. // Let's not show this one again, huh?
  1561. $duplicates[$row['title'] . $row['id_topic']] = true;
  1562. }
  1563. $smcFunc['db_free_result']($request);
  1564. foreach ($return as $mday => $array)
  1565. $return[$mday][count($array) - 1]['is_last'] = true;
  1566. if ($output_method != 'echo' || empty($return))
  1567. return $return;
  1568. // Well the output method is echo.
  1569. echo '
  1570. <span class="event">' . $txt['events'] . '</span> ';
  1571. foreach ($return as $mday => $array)
  1572. foreach ($array as $event)
  1573. {
  1574. if ($event['can_edit'])
  1575. echo '
  1576. <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
  1577. echo '
  1578. ' . $event['link'] . (!$event['is_last'] ? ', ' : '');
  1579. }
  1580. }
  1581. // Check the passed id_member/password. If $is_username is true, treats $id as a username.
  1582. function ssi_checkPassword($id = null, $password = null, $is_username = false)
  1583. {
  1584. global $db_prefix, $sourcedir, $smcFunc;
  1585. // If $id is null, this was most likely called from a query string and should do nothing.
  1586. if ($id === null)
  1587. return;
  1588. $request = $smcFunc['db_query']('', '
  1589. SELECT passwd, member_name, is_activated
  1590. FROM {db_prefix}members
  1591. WHERE ' . ($is_username ? 'member_name' : 'id_member') . ' = {string:id}
  1592. LIMIT 1',
  1593. array(
  1594. 'id' => $id,
  1595. )
  1596. );
  1597. list ($pass, $user, $active) = $smcFunc['db_fetch_row']($request);
  1598. $smcFunc['db_free_result']($request);
  1599. return sha1(strtolower($user) . $password) == $pass && $active == 1;
  1600. }
  1601. // We want to show the recent attachments outside of the forum.
  1602. function ssi_recentAttachments($num_attachments = 10, $attachment_ext = array(), $output_method = 'echo')
  1603. {
  1604. global $smcFunc, $context, $modSettings, $scripturl, $txt, $settings;
  1605. // We want to make sure that we only get attachments for boards that we can see *if* any.
  1606. $attachments_boards = boardsAllowedTo('view_attachments');
  1607. // No boards? Adios amigo.
  1608. if (empty($attachments_boards))
  1609. return array();
  1610. // Is it an array?
  1611. if (!is_array($attachment_ext))
  1612. $attachment_ext = array($attachment_ext);
  1613. // Lets build the query.
  1614. $request = $smcFunc['db_query']('', '
  1615. SELECT
  1616. att.id_attach, att.id_msg, att.filename, IFNULL(att.size, 0) AS filesize, att.downloads, mem.id_member,
  1617. IFNULL(mem.real_name, m.poster_name) AS poster_name, m.id_topic, m.subject, t.id_board, m.poster_time,
  1618. 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') . '
  1619. FROM {db_prefix}attachments AS att
  1620. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = att.id_msg)
  1621. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
  1622. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : '
  1623. LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = att.id_thumb)') . '
  1624. WHERE att.attachment_type = 0' . ($attachments_boards === array(0) ? '' : '
  1625. AND m.id_board IN ({array_int:boards_can_see})') . (!empty($attachment_ext) ? '
  1626. AND att.fileext IN ({array_string:attachment_ext})' : '') .
  1627. (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  1628. AND t.approved = {int:is_approved}
  1629. AND m.approved = {int:is_approved}
  1630. AND att.approved = {int:is_approved}') . '
  1631. ORDER BY att.id_attach DESC
  1632. LIMIT {int:num_attachments}',
  1633. array(
  1634. 'boards_can_see' => $attachments_boards,
  1635. 'attachment_ext' => $attachment_ext,
  1636. 'num_attachments' => $num_attachments,
  1637. 'is_approved' => 1,
  1638. )
  1639. );
  1640. // We have something.
  1641. $attachments = array();
  1642. while ($row = $smcFunc['db_fetch_assoc']($request))
  1643. {
  1644. $filename = preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($row['filename']));
  1645. // Is it an image?
  1646. $attachments[$row['id_attach']] = array(
  1647. 'member' => array(
  1648. 'id' => $row['id_member'],
  1649. 'name' => $row['poster_name'],
  1650. 'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>',
  1651. ),
  1652. 'file' => array(
  1653. 'filename' => $filename,
  1654. 'filesize' => round($row['filesize'] /1024, 2) . $txt['kilobyte'],
  1655. 'downloads' => $row['downloads'],
  1656. 'href' => $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'],
  1657. '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>',
  1658. 'is_image' => !empty($row['width']) && !empty($row['height']) && !empty($modSettings['attachmentShowImages']),
  1659. ),
  1660. 'topic' => array(
  1661. 'id' => $row['id_topic'],
  1662. 'subject' => $row['subject'],
  1663. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
  1664. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>',
  1665. 'time' => timeformat($row['poster_time']),
  1666. ),
  1667. );
  1668. // Images.
  1669. if ($attachments[$row['id_attach']]['file']['is_image'])
  1670. {
  1671. $id_thumb = empty($row['id_thumb']) ? $row['id_attach'] : $row['id_thumb'];
  1672. $attachments[$row['id_attach']]['file']['image'] = array(
  1673. 'id' => $id_thumb,
  1674. 'width' => $row['width'],
  1675. 'height' => $row['height'],
  1676. 'img' => '<img src="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'] . ';image" alt="' . $filename . '" />',
  1677. 'thumb' => '<img src="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $id_thumb . ';image" alt="' . $filename . '" />',
  1678. 'href' => $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $id_thumb . ';image',
  1679. '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>',
  1680. );
  1681. }
  1682. }
  1683. $smcFunc['db_free_result']($request);
  1684. // So you just want an array? Here you can have it.
  1685. if ($output_method == 'array' || empty($attachments))
  1686. return $attachments;
  1687. // Give them the default.
  1688. echo '
  1689. <table class="ssi_downloads" cellpadding="2">
  1690. <tr>
  1691. <th align="left">', $txt['file'], '</th>
  1692. <th align="left">', $txt['posted_by'], '</th>
  1693. <th align="left">', $txt['downloads'], '</th>
  1694. <th align="left">', $txt['filesize'], '</th>
  1695. </tr>';
  1696. foreach ($attachments as $attach)
  1697. echo '
  1698. <tr>
  1699. <td>', $attach['file']['link'], '</td>
  1700. <td>', $attach['member']['link'], '</td>
  1701. <td align="center">', $attach['file']['downloads'], '</td>
  1702. <td>', $attach['file']['filesize'], '</td>
  1703. </tr>';
  1704. echo '
  1705. </table>';
  1706. }
  1707. ?>