SSI.php 72 KB

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