SSI.php 73 KB

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