SSI.php 73 KB

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