Profile-View.php 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  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. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. /**
  15. * View a summary.
  16. * @param int $memID id_member
  17. */
  18. function summary($memID)
  19. {
  20. global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $sourcedir, $scripturl, $smcFunc;
  21. // Attempt to load the member's profile data.
  22. if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
  23. fatal_lang_error('not_a_user', false);
  24. // Set up the stuff and load the user.
  25. $context += array(
  26. 'page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']),
  27. 'can_send_pm' => allowedTo('pm_send'),
  28. 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']),
  29. 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1,
  30. );
  31. $context['member'] = &$memberContext[$memID];
  32. $context['can_view_warning'] = in_array('w', $context['admin_features']) && (allowedTo('issue_warning') && !$context['user']['is_owner']) || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $context['user']['is_owner']));
  33. // Set a canonical URL for this page.
  34. $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID;
  35. // Are there things we don't show?
  36. $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
  37. // See if they have broken any warning levels...
  38. list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
  39. if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
  40. $context['warning_status'] = $txt['profile_warning_is_muted'];
  41. elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
  42. $context['warning_status'] = $txt['profile_warning_is_moderation'];
  43. elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
  44. $context['warning_status'] = $txt['profile_warning_is_watch'];
  45. // They haven't even been registered for a full day!?
  46. $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
  47. if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
  48. $context['member']['posts_per_day'] = $txt['not_applicable'];
  49. else
  50. $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
  51. // Set the age...
  52. if (empty($context['member']['birth_date']))
  53. {
  54. $context['member'] += array(
  55. 'age' => $txt['not_applicable'],
  56. 'today_is_birthday' => false
  57. );
  58. }
  59. else
  60. {
  61. list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
  62. $datearray = getdate(forum_time());
  63. $context['member'] += array(
  64. 'age' => $birth_year <= 4 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
  65. 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day
  66. );
  67. }
  68. if (allowedTo('moderate_forum'))
  69. {
  70. // Make sure it's a valid ip address; otherwise, don't bother...
  71. if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
  72. $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
  73. else
  74. $context['member']['hostname'] = '';
  75. $context['can_see_ip'] = true;
  76. }
  77. else
  78. $context['can_see_ip'] = false;
  79. if (!empty($modSettings['who_enabled']))
  80. {
  81. include_once($sourcedir . '/Who.php');
  82. $action = determineActions($user_profile[$memID]['url']);
  83. if ($action !== false)
  84. $context['member']['action'] = $action;
  85. }
  86. // If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
  87. if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum'))
  88. {
  89. $context['activate_type'] = $context['member']['is_activated'];
  90. // What should the link text be?
  91. $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
  92. // Should we show a custom message?
  93. $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];
  94. }
  95. // Is the signature even enabled on this forum?
  96. $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
  97. // How about, are they banned?
  98. $context['member']['bans'] = array();
  99. if (allowedTo('moderate_forum'))
  100. {
  101. // Can they edit the ban?
  102. $context['can_edit_ban'] = allowedTo('manage_bans');
  103. $ban_query = array();
  104. $ban_query_vars = array(
  105. 'time' => time(),
  106. );
  107. $ban_query[] = 'id_member = ' . $context['member']['id'];
  108. // Valid IP?
  109. if (preg_match('/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $memberContext[$memID]['ip'], $ip_parts) == 1)
  110. {
  111. $ban_query[] = '((' . $ip_parts[1] . ' BETWEEN bi.ip_low1 AND bi.ip_high1)
  112. AND (' . $ip_parts[2] . ' BETWEEN bi.ip_low2 AND bi.ip_high2)
  113. AND (' . $ip_parts[3] . ' BETWEEN bi.ip_low3 AND bi.ip_high3)
  114. AND (' . $ip_parts[4] . ' BETWEEN bi.ip_low4 AND bi.ip_high4))';
  115. // Do we have a hostname already?
  116. if (!empty($context['member']['hostname']))
  117. {
  118. $ban_query[] = '({string:hostname} LIKE hostname)';
  119. $ban_query_vars['hostname'] = $context['member']['hostname'];
  120. }
  121. }
  122. // Use '255.255.255.255' for 'unknown' - it's not valid anyway.
  123. elseif ($memberContext[$memID]['ip'] == 'unknown')
  124. $ban_query[] = '(bi.ip_low1 = 255 AND bi.ip_high1 = 255
  125. AND bi.ip_low2 = 255 AND bi.ip_high2 = 255
  126. AND bi.ip_low3 = 255 AND bi.ip_high3 = 255
  127. AND bi.ip_low4 = 255 AND bi.ip_high4 = 255)';
  128. // Check their email as well...
  129. if (strlen($context['member']['email']) != 0)
  130. {
  131. $ban_query[] = '({string:email} LIKE bi.email_address)';
  132. $ban_query_vars['email'] = $context['member']['email'];
  133. }
  134. // So... are they banned? Dying to know!
  135. $request = $smcFunc['db_query']('', '
  136. SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register,
  137. bg.cannot_login, bg.reason
  138. FROM {db_prefix}ban_items AS bi
  139. INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time}))
  140. WHERE (' . implode(' OR ', $ban_query) . ')',
  141. $ban_query_vars
  142. );
  143. while ($row = $smcFunc['db_fetch_assoc']($request))
  144. {
  145. // Work out what restrictions we actually have.
  146. $ban_restrictions = array();
  147. foreach (array('access', 'register', 'login', 'post') as $type)
  148. if ($row['cannot_' . $type])
  149. $ban_restrictions[] = $txt['ban_type_' . $type];
  150. // No actual ban in place?
  151. if (empty($ban_restrictions))
  152. continue;
  153. // Prepare the link for context.
  154. $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
  155. $context['member']['bans'][$row['id_ban_group']] = array(
  156. 'reason' => empty($row['reason']) ? '' : '<br /><br /><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'],
  157. 'cannot' => array(
  158. 'access' => !empty($row['cannot_access']),
  159. 'register' => !empty($row['cannot_register']),
  160. 'post' => !empty($row['cannot_post']),
  161. 'login' => !empty($row['cannot_login']),
  162. ),
  163. 'explanation' => $ban_explanation,
  164. );
  165. }
  166. $smcFunc['db_free_result']($request);
  167. }
  168. loadCustomFields($memID);
  169. }
  170. /**
  171. * Show all posts by the current user
  172. * @todo This function needs to be split up properly.
  173. *
  174. * @param int $memID id_member
  175. */
  176. function showPosts($memID)
  177. {
  178. global $txt, $user_info, $scripturl, $modSettings;
  179. global $context, $user_profile, $sourcedir, $smcFunc, $board;
  180. // Some initial context.
  181. $context['start'] = (int) $_REQUEST['start'];
  182. $context['current_member'] = $memID;
  183. // Create the tabs for the template.
  184. $context[$context['profile_menu_name']]['tab_data'] = array(
  185. 'title' => $txt['showPosts'],
  186. 'description' => $txt['showPosts_help'],
  187. 'icon' => 'profile_sm.gif',
  188. 'tabs' => array(
  189. 'messages' => array(
  190. ),
  191. 'topics' => array(
  192. ),
  193. 'attach' => array(
  194. ),
  195. ),
  196. );
  197. // Set the page title
  198. $context['page_title'] = $txt['showPosts'] . ' - ' . $user_profile[$memID]['real_name'];
  199. // Is the load average too high to allow searching just now?
  200. if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
  201. fatal_lang_error('loadavg_show_posts_disabled', false);
  202. // If we're specifically dealing with attachments use that function!
  203. if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
  204. return showAttachments($memID);
  205. // Are we just viewing topics?
  206. $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
  207. // If just deleting a message, do it and then redirect back.
  208. if (isset($_GET['delete']) && !$context['is_topics'])
  209. {
  210. checkSession('get');
  211. // We need msg info for logging.
  212. $request = $smcFunc['db_query']('', '
  213. SELECT subject, id_member, id_topic, id_board
  214. FROM {db_prefix}messages
  215. WHERE id_msg = {int:id_msg}',
  216. array(
  217. 'id_msg' => (int) $_GET['delete'],
  218. )
  219. );
  220. $info = $smcFunc['db_fetch_row']($request);
  221. $smcFunc['db_free_result']($request);
  222. // Trying to remove a message that doesn't exist.
  223. if (empty($info))
  224. redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
  225. // We can be lazy, since removeMessage() will check the permissions for us.
  226. require_once($sourcedir . '/RemoveTopic.php');
  227. removeMessage((int) $_GET['delete']);
  228. // Add it to the mod log.
  229. if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
  230. logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
  231. // Back to... where we are now ;).
  232. redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
  233. }
  234. // Default to 10.
  235. if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
  236. $_REQUEST['viewscount'] = '10';
  237. if ($context['is_topics'])
  238. $request = $smcFunc['db_query']('', '
  239. SELECT COUNT(*)
  240. FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
  241. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
  242. WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
  243. AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  244. AND t.approved = {int:is_approved}'),
  245. array(
  246. 'current_member' => $memID,
  247. 'is_approved' => 1,
  248. 'board' => $board,
  249. )
  250. );
  251. else
  252. $request = $smcFunc['db_query']('', '
  253. SELECT COUNT(*)
  254. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  255. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  256. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  257. AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  258. AND m.approved = {int:is_approved}'),
  259. array(
  260. 'current_member' => $memID,
  261. 'is_approved' => 1,
  262. 'board' => $board,
  263. )
  264. );
  265. list ($msgCount) = $smcFunc['db_fetch_row']($request);
  266. $smcFunc['db_free_result']($request);
  267. $request = $smcFunc['db_query']('', '
  268. SELECT MIN(id_msg), MAX(id_msg)
  269. FROM {db_prefix}messages AS m
  270. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  271. AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  272. AND m.approved = {int:is_approved}'),
  273. array(
  274. 'current_member' => $memID,
  275. 'is_approved' => 1,
  276. 'board' => $board,
  277. )
  278. );
  279. list ($min_msg_member, $max_msg_member) = $smcFunc['db_fetch_row']($request);
  280. $smcFunc['db_free_result']($request);
  281. $reverse = false;
  282. $range_limit = '';
  283. $maxIndex = (int) $modSettings['defaultMaxMessages'];
  284. // Make sure the starting place makes sense and construct our friend the page index.
  285. $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex);
  286. $context['current_page'] = $context['start'] / $maxIndex;
  287. // Reverse the query if we're past 50% of the pages for better performance.
  288. $start = $context['start'];
  289. $reverse = $_REQUEST['start'] > $msgCount / 2;
  290. if ($reverse)
  291. {
  292. $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages'];
  293. $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages'];
  294. }
  295. // Guess the range of messages to be shown.
  296. if ($msgCount > 1000)
  297. {
  298. $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + .1 * ($max_msg_member - $min_msg_member));
  299. // Make a bigger margin for topics only.
  300. if ($context['is_topics'])
  301. {
  302. $margin *= 5;
  303. $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
  304. }
  305. else
  306. $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
  307. }
  308. // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks.
  309. $looped = false;
  310. while (true)
  311. {
  312. if ($context['is_topics'])
  313. {
  314. $request = $smcFunc['db_query']('', '
  315. SELECT
  316. b.id_board, b.name AS bname, c.id_cat, c.name AS cname, t.id_member_started, t.id_first_msg, t.id_last_msg,
  317. t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg
  318. FROM {db_prefix}topics AS t
  319. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  320. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  321. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  322. WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
  323. AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
  324. AND ' . $range_limit) . '
  325. AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  326. AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
  327. ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . '
  328. LIMIT ' . $start . ', ' . $maxIndex,
  329. array(
  330. 'current_member' => $memID,
  331. 'is_approved' => 1,
  332. 'board' => $board,
  333. )
  334. );
  335. }
  336. else
  337. {
  338. $request = $smcFunc['db_query']('', '
  339. SELECT
  340. b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg,
  341. t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled,
  342. m.subject, m.poster_time, m.approved
  343. FROM {db_prefix}messages AS m
  344. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
  345. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  346. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  347. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  348. AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
  349. AND ' . $range_limit) . '
  350. AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  351. AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
  352. ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . '
  353. LIMIT ' . $start . ', ' . $maxIndex,
  354. array(
  355. 'current_member' => $memID,
  356. 'is_approved' => 1,
  357. 'board' => $board,
  358. )
  359. );
  360. }
  361. // Make sure we quit this loop.
  362. if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
  363. break;
  364. $looped = true;
  365. $range_limit = '';
  366. }
  367. // Start counting at the number of the first message displayed.
  368. $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
  369. $context['posts'] = array();
  370. $board_ids = array('own' => array(), 'any' => array());
  371. while ($row = $smcFunc['db_fetch_assoc']($request))
  372. {
  373. // Censor....
  374. censorText($row['body']);
  375. censorText($row['subject']);
  376. // Do the code.
  377. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
  378. // And the array...
  379. $context['posts'][$counter += $reverse ? -1 : 1] = array(
  380. 'body' => $row['body'],
  381. 'counter' => $counter,
  382. 'alternate' => $counter % 2,
  383. 'category' => array(
  384. 'name' => $row['cname'],
  385. 'id' => $row['id_cat']
  386. ),
  387. 'board' => array(
  388. 'name' => $row['bname'],
  389. 'id' => $row['id_board']
  390. ),
  391. 'topic' => $row['id_topic'],
  392. 'subject' => $row['subject'],
  393. 'start' => 'msg' . $row['id_msg'],
  394. 'time' => timeformat($row['poster_time']),
  395. 'timestamp' => forum_time(true, $row['poster_time']),
  396. 'id' => $row['id_msg'],
  397. 'can_reply' => false,
  398. 'can_mark_notify' => false,
  399. 'can_delete' => false,
  400. 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()),
  401. 'approved' => $row['approved'],
  402. );
  403. if ($user_info['id'] == $row['id_member_started'])
  404. $board_ids['own'][$row['id_board']][] = $counter;
  405. $board_ids['any'][$row['id_board']][] = $counter;
  406. }
  407. $smcFunc['db_free_result']($request);
  408. // All posts were retrieved in reverse order, get them right again.
  409. if ($reverse)
  410. $context['posts'] = array_reverse($context['posts'], true);
  411. // These are all the permissions that are different from board to board..
  412. if ($context['is_topics'])
  413. $permissions = array(
  414. 'own' => array(
  415. 'post_reply_own' => 'can_reply',
  416. ),
  417. 'any' => array(
  418. 'post_reply_any' => 'can_reply',
  419. 'mark_any_notify' => 'can_mark_notify',
  420. )
  421. );
  422. else
  423. $permissions = array(
  424. 'own' => array(
  425. 'post_reply_own' => 'can_reply',
  426. 'delete_own' => 'can_delete',
  427. ),
  428. 'any' => array(
  429. 'post_reply_any' => 'can_reply',
  430. 'mark_any_notify' => 'can_mark_notify',
  431. 'delete_any' => 'can_delete',
  432. )
  433. );
  434. // For every permission in the own/any lists...
  435. foreach ($permissions as $type => $list)
  436. {
  437. foreach ($list as $permission => $allowed)
  438. {
  439. // Get the boards they can do this on...
  440. $boards = boardsAllowedTo($permission);
  441. // Hmm, they can do it on all boards, can they?
  442. if (!empty($boards) && $boards[0] == 0)
  443. $boards = array_keys($board_ids[$type]);
  444. // Now go through each board they can do the permission on.
  445. foreach ($boards as $board_id)
  446. {
  447. // There aren't any posts displayed from this board.
  448. if (!isset($board_ids[$type][$board_id]))
  449. continue;
  450. // Set the permission to true ;).
  451. foreach ($board_ids[$type][$board_id] as $counter)
  452. $context['posts'][$counter][$allowed] = true;
  453. }
  454. }
  455. }
  456. // Clean up after posts that cannot be deleted and quoted.
  457. $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
  458. foreach ($context['posts'] as $counter => $dummy)
  459. {
  460. $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];
  461. $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
  462. }
  463. }
  464. /**
  465. * Show all the attachments of a user.
  466. *
  467. * @param int $memID id_member
  468. */
  469. function showAttachments($memID)
  470. {
  471. global $txt, $user_info, $scripturl, $modSettings, $board;
  472. global $context, $user_profile, $sourcedir, $smcFunc;
  473. // OBEY permissions!
  474. $boardsAllowed = boardsAllowedTo('view_attachments');
  475. // Make sure we can't actually see anything...
  476. if (empty($boardsAllowed))
  477. $boardsAllowed = array(-1);
  478. // Get the total number of attachments they have posted.
  479. $request = $smcFunc['db_query']('', '
  480. SELECT COUNT(*)
  481. FROM {db_prefix}attachments AS a
  482. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
  483. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  484. WHERE a.attachment_type = {int:attachment_type}
  485. AND a.id_msg != {int:no_message}
  486. AND m.id_member = {int:current_member}' . (!empty($board) ? '
  487. AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
  488. AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  489. AND m.approved = {int:is_approved}'),
  490. array(
  491. 'boards_list' => $boardsAllowed,
  492. 'attachment_type' => 0,
  493. 'no_message' => 0,
  494. 'current_member' => $memID,
  495. 'is_approved' => 1,
  496. 'board' => $board,
  497. )
  498. );
  499. list ($attachCount) = $smcFunc['db_fetch_row']($request);
  500. $smcFunc['db_free_result']($request);
  501. $maxIndex = (int) $modSettings['defaultMaxMessages'];
  502. // What about ordering?
  503. $sortTypes = array(
  504. 'filename' => 'a.filename',
  505. 'downloads' => 'a.downloads',
  506. 'subject' => 'm.subject',
  507. 'posted' => 'm.poster_time',
  508. );
  509. $context['sort_order'] = isset($_GET['sort']) && isset($sortTypes[$_GET['sort']]) ? $_GET['sort'] : 'posted';
  510. $context['sort_direction'] = isset($_GET['asc']) ? 'up' : 'down';
  511. $sort = $sortTypes[$context['sort_order']];
  512. // Let's get ourselves a lovely page index.
  513. $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts;sa=attach;sort=' . $context['sort_order'] . ($context['sort_direction'] == 'up' ? ';asc' : ''), $context['start'], $attachCount, $maxIndex);
  514. // Retrieve some attachments.
  515. $request = $smcFunc['db_query']('', '
  516. SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, m.id_msg, m.id_topic,
  517. m.id_board, m.poster_time, m.subject, b.name
  518. FROM {db_prefix}attachments AS a
  519. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
  520. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  521. WHERE a.attachment_type = {int:attachment_type}
  522. AND a.id_msg != {int:no_message}
  523. AND m.id_member = {int:current_member}' . (!empty($board) ? '
  524. AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
  525. AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  526. AND m.approved = {int:is_approved}') . '
  527. ORDER BY {raw:sort}
  528. LIMIT {int:offset}, {int:limit}',
  529. array(
  530. 'boards_list' => $boardsAllowed,
  531. 'attachment_type' => 0,
  532. 'no_message' => 0,
  533. 'current_member' => $memID,
  534. 'is_approved' => 1,
  535. 'board' => $board,
  536. 'sort' => $sort . ' ' . ($context['sort_direction'] == 'down' ? 'DESC' : 'ASC'),
  537. 'offset' => $context['start'],
  538. 'limit' => $maxIndex,
  539. )
  540. );
  541. $context['attachments'] = array();
  542. while ($row = $smcFunc['db_fetch_assoc']($request))
  543. {
  544. $row['subject'] = censorText($row['subject']);
  545. $context['attachments'][] = array(
  546. 'id' => $row['id_attach'],
  547. 'filename' => $row['filename'],
  548. 'downloads' => $row['downloads'],
  549. 'subject' => $row['subject'],
  550. 'posted' => timeformat($row['poster_time']),
  551. 'msg' => $row['id_msg'],
  552. 'topic' => $row['id_topic'],
  553. 'board' => $row['id_board'],
  554. 'board_name' => $row['name'],
  555. 'approved' => $row['approved'],
  556. );
  557. }
  558. $smcFunc['db_free_result']($request);
  559. }
  560. /**
  561. * @todo needs a description
  562. *
  563. * @param int $memID id_member
  564. */
  565. function statPanel($memID)
  566. {
  567. global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc;
  568. $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
  569. // General user statistics.
  570. $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
  571. $timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600);
  572. $context['time_logged_in'] = ($timeDays > 0 ? $timeDays . $txt['totalTimeLogged2'] : '') . ($timeHours > 0 ? $timeHours . $txt['totalTimeLogged3'] : '') . floor(($user_profile[$memID]['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged4'];
  573. $context['num_posts'] = comma_format($user_profile[$memID]['posts']);
  574. // Number of topics started.
  575. $result = $smcFunc['db_query']('', '
  576. SELECT COUNT(*)
  577. FROM {db_prefix}topics
  578. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  579. AND id_board != {int:recycle_board}' : ''),
  580. array(
  581. 'current_member' => $memID,
  582. 'recycle_board' => $modSettings['recycle_board'],
  583. )
  584. );
  585. list ($context['num_topics']) = $smcFunc['db_fetch_row']($result);
  586. $smcFunc['db_free_result']($result);
  587. // Number polls started.
  588. $result = $smcFunc['db_query']('', '
  589. SELECT COUNT(*)
  590. FROM {db_prefix}topics
  591. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  592. AND id_board != {int:recycle_board}' : '') . '
  593. AND id_poll != {int:no_poll}',
  594. array(
  595. 'current_member' => $memID,
  596. 'recycle_board' => $modSettings['recycle_board'],
  597. 'no_poll' => 0,
  598. )
  599. );
  600. list ($context['num_polls']) = $smcFunc['db_fetch_row']($result);
  601. $smcFunc['db_free_result']($result);
  602. // Number polls voted in.
  603. $result = $smcFunc['db_query']('distinct_poll_votes', '
  604. SELECT COUNT(DISTINCT id_poll)
  605. FROM {db_prefix}log_polls
  606. WHERE id_member = {int:current_member}',
  607. array(
  608. 'current_member' => $memID,
  609. )
  610. );
  611. list ($context['num_votes']) = $smcFunc['db_fetch_row']($result);
  612. $smcFunc['db_free_result']($result);
  613. // Format the numbers...
  614. $context['num_topics'] = comma_format($context['num_topics']);
  615. $context['num_polls'] = comma_format($context['num_polls']);
  616. $context['num_votes'] = comma_format($context['num_votes']);
  617. // Grab the board this member posted in most often.
  618. $result = $smcFunc['db_query']('', '
  619. SELECT
  620. b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count
  621. FROM {db_prefix}messages AS m
  622. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  623. WHERE m.id_member = {int:current_member}
  624. AND b.count_posts = {int:count_enabled}
  625. AND {query_see_board}
  626. GROUP BY b.id_board
  627. ORDER BY message_count DESC
  628. LIMIT 10',
  629. array(
  630. 'current_member' => $memID,
  631. 'count_enabled' => 0,
  632. )
  633. );
  634. $context['popular_boards'] = array();
  635. while ($row = $smcFunc['db_fetch_assoc']($result))
  636. {
  637. $context['popular_boards'][$row['id_board']] = array(
  638. 'id' => $row['id_board'],
  639. 'posts' => $row['message_count'],
  640. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  641. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  642. 'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'],
  643. 'total_posts' => $row['num_posts'],
  644. 'total_posts_member' => $user_profile[$memID]['posts'],
  645. );
  646. }
  647. $smcFunc['db_free_result']($result);
  648. // Now get the 10 boards this user has most often participated in.
  649. $result = $smcFunc['db_query']('profile_board_stats', '
  650. SELECT
  651. b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count,
  652. CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage
  653. FROM {db_prefix}messages AS m
  654. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  655. WHERE m.id_member = {int:current_member}
  656. AND {query_see_board}
  657. GROUP BY b.id_board, b.num_posts
  658. ORDER BY percentage DESC
  659. LIMIT 10',
  660. array(
  661. 'current_member' => $memID,
  662. )
  663. );
  664. $context['board_activity'] = array();
  665. while ($row = $smcFunc['db_fetch_assoc']($result))
  666. {
  667. $context['board_activity'][$row['id_board']] = array(
  668. 'id' => $row['id_board'],
  669. 'posts' => $row['message_count'],
  670. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  671. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  672. 'percent' => comma_format((float) $row['percentage'], 2),
  673. 'posts_percent' => (float) $row['percentage'],
  674. 'total_posts' => $row['num_posts'],
  675. );
  676. }
  677. $smcFunc['db_free_result']($result);
  678. // Posting activity by time.
  679. $result = $smcFunc['db_query']('user_activity_by_time', '
  680. SELECT
  681. HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
  682. COUNT(*) AS post_count
  683. FROM {db_prefix}messages
  684. WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? '
  685. AND id_topic > {int:top_ten_thousand_topics}' : '') . '
  686. GROUP BY hour',
  687. array(
  688. 'current_member' => $memID,
  689. 'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
  690. 'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
  691. )
  692. );
  693. $maxPosts = $realPosts = 0;
  694. $context['posts_by_time'] = array();
  695. while ($row = $smcFunc['db_fetch_assoc']($result))
  696. {
  697. // Cast as an integer to remove the leading 0.
  698. $row['hour'] = (int) $row['hour'];
  699. $maxPosts = max($row['post_count'], $maxPosts);
  700. $realPosts += $row['post_count'];
  701. $context['posts_by_time'][$row['hour']] = array(
  702. 'hour' => $row['hour'],
  703. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])),
  704. 'posts' => $row['post_count'],
  705. 'posts_percent' => 0,
  706. 'is_last' => $row['hour'] == 23,
  707. );
  708. }
  709. $smcFunc['db_free_result']($result);
  710. if ($maxPosts > 0)
  711. for ($hour = 0; $hour < 24; $hour++)
  712. {
  713. if (!isset($context['posts_by_time'][$hour]))
  714. $context['posts_by_time'][$hour] = array(
  715. 'hour' => $hour,
  716. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
  717. 'posts' => 0,
  718. 'posts_percent' => 0,
  719. 'relative_percent' => 0,
  720. 'is_last' => $hour == 23,
  721. );
  722. else
  723. {
  724. $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
  725. $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
  726. }
  727. }
  728. // Put it in the right order.
  729. ksort($context['posts_by_time']);
  730. }
  731. /**
  732. * @todo needs a description
  733. *
  734. * @param int $memID id_member
  735. */
  736. function tracking($memID)
  737. {
  738. global $sourcedir, $context, $txt, $scripturl, $modSettings, $user_profile;
  739. $subActions = array(
  740. 'activity' => array('trackActivity', $txt['trackActivity']),
  741. 'ip' => array('TrackIP', $txt['trackIP']),
  742. 'edits' => array('trackEdits', $txt['trackEdits']),
  743. 'logins' => array('TrackLogins', $txt['trackLogins']),
  744. );
  745. $context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'activity';
  746. if (isset($types[$context['tracking_area']][1]))
  747. require_once($sourcedir . '/' . $types[$context['tracking_area']][1]);
  748. // Create the tabs for the template.
  749. $context[$context['profile_menu_name']]['tab_data'] = array(
  750. 'title' => $txt['tracking'],
  751. 'description' => $txt['tracking_description'],
  752. 'icon' => 'profile_sm.gif',
  753. 'tabs' => array(
  754. 'activity' => array(),
  755. 'ip' => array(),
  756. 'edits' => array(),
  757. ),
  758. );
  759. // Moderation must be on to track edits.
  760. if (empty($modSettings['modlog_enabled']))
  761. unset($context[$context['profile_menu_name']]['tab_data']['edits']);
  762. // Set a page title.
  763. $context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name'];
  764. // Pass on to the actual function.
  765. $context['sub_template'] = $subActions[$context['tracking_area']][0];
  766. $subActions[$context['tracking_area']][0]($memID);
  767. }
  768. /**
  769. * @todo needs a description
  770. *
  771. * @param int $memID id_member
  772. */
  773. function trackActivity($memID)
  774. {
  775. global $scripturl, $txt, $modSettings, $sourcedir;
  776. global $user_profile, $context, $smcFunc;
  777. // Verify if the user has sufficient permissions.
  778. isAllowedTo('moderate_forum');
  779. $context['last_ip'] = $user_profile[$memID]['member_ip'];
  780. if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
  781. $context['last_ip2'] = $user_profile[$memID]['member_ip2'];
  782. $context['member']['name'] = $user_profile[$memID]['real_name'];
  783. // Set the options for the list component.
  784. $listOptions = array(
  785. 'id' => 'track_user_list',
  786. 'title' => $txt['errors_by'] . ' ' . $context['member']['name'],
  787. 'items_per_page' => $modSettings['defaultMaxMessages'],
  788. 'no_items_label' => $txt['no_errors_from_user'],
  789. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
  790. 'default_sort_col' => 'date',
  791. 'get_items' => array(
  792. 'function' => 'list_getUserErrors',
  793. 'params' => array(
  794. 'le.id_member = {int:current_member}',
  795. array('current_member' => $memID),
  796. ),
  797. ),
  798. 'get_count' => array(
  799. 'function' => 'list_getUserErrorCount',
  800. 'params' => array(
  801. 'id_member = {int:current_member}',
  802. array('current_member' => $memID),
  803. ),
  804. ),
  805. 'columns' => array(
  806. 'ip_address' => array(
  807. 'header' => array(
  808. 'value' => $txt['ip_address'],
  809. ),
  810. 'data' => array(
  811. 'sprintf' => array(
  812. 'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID. '">%1$s</a>',
  813. 'params' => array(
  814. 'ip' => false,
  815. ),
  816. ),
  817. ),
  818. 'sort' => array(
  819. 'default' => 'le.ip',
  820. 'reverse' => 'le.ip DESC',
  821. ),
  822. ),
  823. 'message' => array(
  824. 'header' => array(
  825. 'value' => $txt['message'],
  826. ),
  827. 'data' => array(
  828. 'sprintf' => array(
  829. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  830. 'params' => array(
  831. 'message' => false,
  832. 'url' => false,
  833. ),
  834. ),
  835. ),
  836. ),
  837. 'date' => array(
  838. 'header' => array(
  839. 'value' => $txt['date'],
  840. ),
  841. 'data' => array(
  842. 'db' => 'time',
  843. ),
  844. 'sort' => array(
  845. 'default' => 'le.id_error DESC',
  846. 'reverse' => 'le.id_error',
  847. ),
  848. ),
  849. ),
  850. 'additional_rows' => array(
  851. array(
  852. 'position' => 'after_title',
  853. 'value' => $txt['errors_desc'],
  854. 'class' => 'smalltext',
  855. 'style' => 'padding: 2ex;',
  856. ),
  857. ),
  858. );
  859. // Create the list for viewing.
  860. require_once($sourcedir . '/Subs-List.php');
  861. createList($listOptions);
  862. // If this is a big forum, or a large posting user, let's limit the search.
  863. if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500)
  864. {
  865. $request = $smcFunc['db_query']('', '
  866. SELECT MAX(id_msg)
  867. FROM {db_prefix}messages AS m
  868. WHERE m.id_member = {int:current_member}',
  869. array(
  870. 'current_member' => $memID,
  871. )
  872. );
  873. list ($max_msg_member) = $smcFunc['db_fetch_row']($request);
  874. $smcFunc['db_free_result']($request);
  875. // There's no point worrying ourselves with messages made yonks ago, just get recent ones!
  876. $min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3);
  877. }
  878. // Default to at least the ones we know about.
  879. $ips = array(
  880. $user_profile[$memID]['member_ip'],
  881. $user_profile[$memID]['member_ip2'],
  882. );
  883. // Get all IP addresses this user has used for his messages.
  884. $request = $smcFunc['db_query']('', '
  885. SELECT poster_ip
  886. FROM {db_prefix}messages
  887. WHERE id_member = {int:current_member}
  888. ' . (isset($min_msg_member) ? '
  889. AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
  890. GROUP BY poster_ip',
  891. array(
  892. 'current_member' => $memID,
  893. 'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
  894. 'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
  895. )
  896. );
  897. $context['ips'] = array();
  898. while ($row = $smcFunc['db_fetch_assoc']($request))
  899. {
  900. $context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['poster_ip'] . ';u=' . $memID . '">' . $row['poster_ip'] . '</a>';
  901. $ips[] = $row['poster_ip'];
  902. }
  903. $smcFunc['db_free_result']($request);
  904. // Now also get the IP addresses from the error messages.
  905. $request = $smcFunc['db_query']('', '
  906. SELECT COUNT(*) AS error_count, ip
  907. FROM {db_prefix}log_errors
  908. WHERE id_member = {int:current_member}
  909. GROUP BY ip',
  910. array(
  911. 'current_member' => $memID,
  912. )
  913. );
  914. $context['error_ips'] = array();
  915. while ($row = $smcFunc['db_fetch_assoc']($request))
  916. {
  917. $context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>';
  918. $ips[] = $row['ip'];
  919. }
  920. $smcFunc['db_free_result']($request);
  921. // Find other users that might use the same IP.
  922. $ips = array_unique($ips);
  923. $context['members_in_range'] = array();
  924. if (!empty($ips))
  925. {
  926. // Get member ID's which are in messages...
  927. $request = $smcFunc['db_query']('', '
  928. SELECT mem.id_member
  929. FROM {db_prefix}messages AS m
  930. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  931. WHERE m.poster_ip IN ({array_string:ip_list})
  932. GROUP BY mem.id_member
  933. HAVING mem.id_member != {int:current_member}',
  934. array(
  935. 'current_member' => $memID,
  936. 'ip_list' => $ips,
  937. )
  938. );
  939. $message_members = array();
  940. while ($row = $smcFunc['db_fetch_assoc']($request))
  941. $message_members[] = $row['id_member'];
  942. $smcFunc['db_free_result']($request);
  943. // Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
  944. if (!empty($message_members))
  945. {
  946. $request = $smcFunc['db_query']('', '
  947. SELECT id_member, real_name
  948. FROM {db_prefix}members
  949. WHERE id_member IN ({array_int:message_members})',
  950. array(
  951. 'message_members' => $message_members,
  952. 'ip_list' => $ips,
  953. )
  954. );
  955. while ($row = $smcFunc['db_fetch_assoc']($request))
  956. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  957. $smcFunc['db_free_result']($request);
  958. }
  959. $request = $smcFunc['db_query']('', '
  960. SELECT id_member, real_name
  961. FROM {db_prefix}members
  962. WHERE id_member != {int:current_member}
  963. AND member_ip IN ({array_string:ip_list})',
  964. array(
  965. 'current_member' => $memID,
  966. 'ip_list' => $ips,
  967. )
  968. );
  969. while ($row = $smcFunc['db_fetch_assoc']($request))
  970. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  971. $smcFunc['db_free_result']($request);
  972. }
  973. }
  974. /**
  975. * Get the number of user errors
  976. *
  977. * @param string $where
  978. * @param array $where_vars = array()
  979. * @return string number of user errors
  980. */
  981. function list_getUserErrorCount($where, $where_vars = array())
  982. {
  983. global $smcFunc;
  984. $request = $smcFunc['db_query']('', '
  985. SELECT COUNT(*) AS error_count
  986. FROM {db_prefix}log_errors
  987. WHERE ' . $where,
  988. $where_vars
  989. );
  990. list ($count) = $smcFunc['db_fetch_row']($request);
  991. $smcFunc['db_free_result']($request);
  992. // @todo cast this to an integer
  993. return $count;
  994. }
  995. /**
  996. * @todo needs a description
  997. *
  998. * @param int $start
  999. * @param int $items_per_page
  1000. * @param string $sort
  1001. * @param string $where
  1002. * @param array $where_vars
  1003. * @return array error messages
  1004. */
  1005. function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array())
  1006. {
  1007. global $smcFunc, $txt, $scripturl;
  1008. // Get a list of error messages from this ip (range).
  1009. $request = $smcFunc['db_query']('', '
  1010. SELECT
  1011. le.log_time, le.ip, le.url, le.message, IFNULL(mem.id_member, 0) AS id_member,
  1012. IFNULL(mem.real_name, {string:guest_title}) AS display_name, mem.member_name
  1013. FROM {db_prefix}log_errors AS le
  1014. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member)
  1015. WHERE ' . $where . '
  1016. ORDER BY ' . $sort . '
  1017. LIMIT ' . $start . ', ' . $items_per_page,
  1018. array_merge($where_vars, array(
  1019. 'guest_title' => $txt['guest_title'],
  1020. ))
  1021. );
  1022. $error_messages = array();
  1023. while ($row = $smcFunc['db_fetch_assoc']($request))
  1024. $error_messages[] = array(
  1025. 'ip' => $row['ip'],
  1026. 'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
  1027. 'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
  1028. 'url' => $row['url'],
  1029. 'time' => timeformat($row['log_time']),
  1030. 'timestamp' => forum_time(true, $row['log_time']),
  1031. );
  1032. $smcFunc['db_free_result']($request);
  1033. return $error_messages;
  1034. }
  1035. /**
  1036. * @todo needs a description
  1037. *
  1038. * @param string $where
  1039. * @param array $where_vars
  1040. * @return string count of messages matching the IP
  1041. */
  1042. function list_getIPMessageCount($where, $where_vars = array())
  1043. {
  1044. global $smcFunc;
  1045. $request = $smcFunc['db_query']('', '
  1046. SELECT COUNT(*) AS message_count
  1047. FROM {db_prefix}messages AS m
  1048. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1049. WHERE {query_see_board} AND ' . $where,
  1050. $where_vars
  1051. );
  1052. list ($count) = $smcFunc['db_fetch_row']($request);
  1053. $smcFunc['db_free_result']($request);
  1054. // @todo cast to integer
  1055. return $count;
  1056. }
  1057. /**
  1058. * @todo needs a description
  1059. *
  1060. * @param int $start
  1061. * @param int $items_per_page
  1062. * @param string $sort
  1063. * @param string $where
  1064. * @param array $where_vars
  1065. * @return array an array of messages
  1066. */
  1067. function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array())
  1068. {
  1069. global $smcFunc, $txt, $scripturl;
  1070. // Get all the messages fitting this where clause.
  1071. // @todo SLOW This query is using a filesort.
  1072. $request = $smcFunc['db_query']('', '
  1073. SELECT
  1074. m.id_msg, m.poster_ip, IFNULL(mem.real_name, m.poster_name) AS display_name, mem.id_member,
  1075. m.subject, m.poster_time, m.id_topic, m.id_board
  1076. FROM {db_prefix}messages AS m
  1077. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1078. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1079. WHERE {query_see_board} AND ' . $where . '
  1080. ORDER BY ' . $sort . '
  1081. LIMIT ' . $start . ', ' . $items_per_page,
  1082. array_merge($where_vars, array(
  1083. ))
  1084. );
  1085. $messages = array();
  1086. while ($row = $smcFunc['db_fetch_assoc']($request))
  1087. $messages[] = array(
  1088. 'ip' => $row['poster_ip'],
  1089. 'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
  1090. 'board' => array(
  1091. 'id' => $row['id_board'],
  1092. 'href' => $scripturl . '?board=' . $row['id_board']
  1093. ),
  1094. 'topic' => $row['id_topic'],
  1095. 'id' => $row['id_msg'],
  1096. 'subject' => $row['subject'],
  1097. 'time' => timeformat($row['poster_time']),
  1098. 'timestamp' => forum_time(true, $row['poster_time'])
  1099. );
  1100. $smcFunc['db_free_result']($request);
  1101. return $messages;
  1102. }
  1103. /**
  1104. * @todo needs a description
  1105. *
  1106. * @param int $memID = 0 id_member
  1107. */
  1108. function TrackIP($memID = 0)
  1109. {
  1110. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1111. global $context, $smcFunc;
  1112. // Can the user do this?
  1113. isAllowedTo('moderate_forum');
  1114. if ($memID == 0)
  1115. {
  1116. $context['ip'] = $user_info['ip'];
  1117. loadTemplate('Profile');
  1118. loadLanguage('Profile');
  1119. $context['sub_template'] = 'trackIP';
  1120. $context['page_title'] = $txt['profile'];
  1121. $context['base_url'] = $scripturl . '?action=trackip';
  1122. }
  1123. else
  1124. {
  1125. $context['ip'] = $user_profile[$memID]['member_ip'];
  1126. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1127. }
  1128. // Searching?
  1129. if (isset($_REQUEST['searchip']))
  1130. $context['ip'] = trim($_REQUEST['searchip']);
  1131. if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false)
  1132. fatal_lang_error('invalid_tracking_ip', false);
  1133. $ip_var = str_replace('*', '%', $context['ip']);
  1134. $ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}';
  1135. if (empty($context['tracking_area']))
  1136. $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
  1137. $request = $smcFunc['db_query']('', '
  1138. SELECT id_member, real_name AS display_name, member_ip
  1139. FROM {db_prefix}members
  1140. WHERE member_ip ' . $ip_string,
  1141. array(
  1142. 'ip_address' => $ip_var,
  1143. )
  1144. );
  1145. $context['ips'] = array();
  1146. while ($row = $smcFunc['db_fetch_assoc']($request))
  1147. $context['ips'][$row['member_ip']][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
  1148. $smcFunc['db_free_result']($request);
  1149. ksort($context['ips']);
  1150. // Gonna want this for the list.
  1151. require_once($sourcedir . '/Subs-List.php');
  1152. // Start with the user messages.
  1153. $listOptions = array(
  1154. 'id' => 'track_message_list',
  1155. 'title' => $txt['messages_from_ip'] . ' ' . $context['ip'],
  1156. 'start_var_name' => 'messageStart',
  1157. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1158. 'no_items_label' => $txt['no_messages_from_ip'],
  1159. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1160. 'default_sort_col' => 'date',
  1161. 'get_items' => array(
  1162. 'function' => 'list_getIPMessages',
  1163. 'params' => array(
  1164. 'm.poster_ip ' . $ip_string,
  1165. array('ip_address' => $ip_var),
  1166. ),
  1167. ),
  1168. 'get_count' => array(
  1169. 'function' => 'list_getIPMessageCount',
  1170. 'params' => array(
  1171. 'm.poster_ip ' . $ip_string,
  1172. array('ip_address' => $ip_var),
  1173. ),
  1174. ),
  1175. 'columns' => array(
  1176. 'ip_address' => array(
  1177. 'header' => array(
  1178. 'value' => $txt['ip_address'],
  1179. ),
  1180. 'data' => array(
  1181. 'sprintf' => array(
  1182. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1183. 'params' => array(
  1184. 'ip' => false,
  1185. ),
  1186. ),
  1187. ),
  1188. 'sort' => array(
  1189. 'default' => 'INET_ATON(m.poster_ip)',
  1190. 'reverse' => 'INET_ATON(m.poster_ip) DESC',
  1191. ),
  1192. ),
  1193. 'poster' => array(
  1194. 'header' => array(
  1195. 'value' => $txt['poster'],
  1196. ),
  1197. 'data' => array(
  1198. 'db' => 'member_link',
  1199. ),
  1200. ),
  1201. 'subject' => array(
  1202. 'header' => array(
  1203. 'value' => $txt['subject'],
  1204. ),
  1205. 'data' => array(
  1206. 'sprintf' => array(
  1207. 'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>',
  1208. 'params' => array(
  1209. 'topic' => false,
  1210. 'id' => false,
  1211. 'subject' => false,
  1212. ),
  1213. ),
  1214. ),
  1215. ),
  1216. 'date' => array(
  1217. 'header' => array(
  1218. 'value' => $txt['date'],
  1219. ),
  1220. 'data' => array(
  1221. 'db' => 'time',
  1222. ),
  1223. 'sort' => array(
  1224. 'default' => 'm.id_msg DESC',
  1225. 'reverse' => 'm.id_msg',
  1226. ),
  1227. ),
  1228. ),
  1229. 'additional_rows' => array(
  1230. array(
  1231. 'position' => 'after_title',
  1232. 'value' => $txt['messages_from_ip_desc'],
  1233. 'class' => 'smalltext',
  1234. 'style' => 'padding: 2ex;',
  1235. ),
  1236. ),
  1237. );
  1238. // Create the messages list.
  1239. createList($listOptions);
  1240. // Set the options for the error lists.
  1241. $listOptions = array(
  1242. 'id' => 'track_user_list',
  1243. 'title' => $txt['errors_from_ip'] . ' ' . $context['ip'],
  1244. 'start_var_name' => 'errorStart',
  1245. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1246. 'no_items_label' => $txt['no_errors_from_ip'],
  1247. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1248. 'default_sort_col' => 'date2',
  1249. 'get_items' => array(
  1250. 'function' => 'list_getUserErrors',
  1251. 'params' => array(
  1252. 'le.ip ' . $ip_string,
  1253. array('ip_address' => $ip_var),
  1254. ),
  1255. ),
  1256. 'get_count' => array(
  1257. 'function' => 'list_getUserErrorCount',
  1258. 'params' => array(
  1259. 'ip ' . $ip_string,
  1260. array('ip_address' => $ip_var),
  1261. ),
  1262. ),
  1263. 'columns' => array(
  1264. 'ip_address2' => array(
  1265. 'header' => array(
  1266. 'value' => $txt['ip_address'],
  1267. ),
  1268. 'data' => array(
  1269. 'sprintf' => array(
  1270. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1271. 'params' => array(
  1272. 'ip' => false,
  1273. ),
  1274. ),
  1275. ),
  1276. 'sort' => array(
  1277. 'default' => 'INET_ATON(le.ip)',
  1278. 'reverse' => 'INET_ATON(le.ip) DESC',
  1279. ),
  1280. ),
  1281. 'display_name' => array(
  1282. 'header' => array(
  1283. 'value' => $txt['display_name'],
  1284. ),
  1285. 'data' => array(
  1286. 'db' => 'member_link',
  1287. ),
  1288. ),
  1289. 'message' => array(
  1290. 'header' => array(
  1291. 'value' => $txt['message'],
  1292. ),
  1293. 'data' => array(
  1294. 'sprintf' => array(
  1295. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  1296. 'params' => array(
  1297. 'message' => false,
  1298. 'url' => false,
  1299. ),
  1300. ),
  1301. ),
  1302. ),
  1303. 'date2' => array(
  1304. 'header' => array(
  1305. 'value' => $txt['date'],
  1306. ),
  1307. 'data' => array(
  1308. 'db' => 'time',
  1309. ),
  1310. 'sort' => array(
  1311. 'default' => 'le.id_error DESC',
  1312. 'reverse' => 'le.id_error',
  1313. ),
  1314. ),
  1315. ),
  1316. 'additional_rows' => array(
  1317. array(
  1318. 'position' => 'after_title',
  1319. 'value' => $txt['errors_from_ip_desc'],
  1320. 'class' => 'smalltext',
  1321. 'style' => 'padding: 2ex;',
  1322. ),
  1323. ),
  1324. );
  1325. // Create the error list.
  1326. createList($listOptions);
  1327. $context['single_ip'] = strpos($context['ip'], '*') === false;
  1328. if ($context['single_ip'])
  1329. {
  1330. $context['whois_servers'] = array(
  1331. 'afrinic' => array(
  1332. 'name' => $txt['whois_afrinic'],
  1333. 'url' => 'http://www.afrinic.net/cgi-bin/whois?searchtext=' . $context['ip'],
  1334. 'range' => array(41, 154, 196),
  1335. ),
  1336. 'apnic' => array(
  1337. 'name' => $txt['whois_apnic'],
  1338. 'url' => 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'],
  1339. 'range' => array(58, 59, 60, 61, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
  1340. 125, 126, 133, 150, 153, 163, 171, 202, 203, 210, 211, 218, 219, 220, 221, 222),
  1341. ),
  1342. 'arin' => array(
  1343. 'name' => $txt['whois_arin'],
  1344. 'url' => 'http://whois.arin.net/rest/ip/' . $context['ip'],
  1345. 'range' => array(7, 24, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 96, 97, 98, 99,
  1346. 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149,
  1347. 152, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 172, 173, 174,
  1348. 192, 198, 199, 204, 205, 206, 207, 208, 209, 216),
  1349. ),
  1350. 'lacnic' => array(
  1351. 'name' => $txt['whois_lacnic'],
  1352. 'url' => 'http://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'],
  1353. 'range' => array(186, 187, 189, 190, 191, 200, 201),
  1354. ),
  1355. 'ripe' => array(
  1356. 'name' => $txt['whois_ripe'],
  1357. 'url' => 'http://www.db.ripe.net/whois?searchtext=' . $context['ip'],
  1358. 'range' => array(62, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  1359. 141, 145, 151, 188, 193, 194, 195, 212, 213, 217),
  1360. ),
  1361. );
  1362. foreach ($context['whois_servers'] as $whois)
  1363. {
  1364. // Strip off the "decimal point" and anything following...
  1365. if (in_array((int) $context['ip'], $whois['range']))
  1366. $context['auto_whois_server'] = $whois;
  1367. }
  1368. }
  1369. }
  1370. /**
  1371. * Tracks a users logins.
  1372. *
  1373. * @param int $memID = 0 id_member
  1374. */
  1375. function TrackLogins($memID = 0)
  1376. {
  1377. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1378. global $context, $smcFunc;
  1379. // Gonna want this for the list.
  1380. require_once($sourcedir . '/Subs-List.php');
  1381. if ($memID == 0)
  1382. $context['base_url'] = $scripturl . '?action=trackip';
  1383. else
  1384. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1385. // Start with the user messages.
  1386. $listOptions = array(
  1387. 'id' => 'track_logins_list',
  1388. 'title' => $txt['trackLogins'],
  1389. 'no_items_label' => $txt['trackLogins_none_found'],
  1390. 'base_href' => $context['base_url'],
  1391. 'get_items' => array(
  1392. 'function' => 'list_getLogins',
  1393. 'params' => array(
  1394. 'id_member = {int:current_member}',
  1395. array('current_member' => $memID),
  1396. ),
  1397. ),
  1398. 'get_count' => array(
  1399. 'function' => 'list_getLoginCount',
  1400. 'params' => array(
  1401. 'id_member = {int:current_member}',
  1402. array('current_member' => $memID),
  1403. ),
  1404. ),
  1405. 'columns' => array(
  1406. 'time' => array(
  1407. 'header' => array(
  1408. 'value' => $txt['date'],
  1409. ),
  1410. 'data' => array(
  1411. 'db' => 'time',
  1412. ),
  1413. ),
  1414. 'ip' => array(
  1415. 'header' => array(
  1416. 'value' => $txt['ip_address'],
  1417. ),
  1418. 'data' => array(
  1419. 'sprintf' => array(
  1420. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ',
  1421. 'params' => array(
  1422. 'ip' => false,
  1423. 'ip2' => false
  1424. ),
  1425. ),
  1426. ),
  1427. ),
  1428. ),
  1429. 'additional_rows' => array(
  1430. array(
  1431. 'position' => 'after_title',
  1432. 'value' => $txt['trackLogins_desc'],
  1433. 'class' => 'smalltext',
  1434. 'style' => 'padding: 2ex;',
  1435. ),
  1436. ),
  1437. );
  1438. // Create the messages list.
  1439. createList($listOptions);
  1440. $context['sub_template'] = 'show_list';
  1441. $context['default_list'] = 'track_logins_list';
  1442. }
  1443. /**
  1444. * Callback for trackLogins for counting history.
  1445. *
  1446. * @param string $where
  1447. * @param array $where_vars
  1448. * @return string count of messages matching the IP
  1449. */
  1450. function list_getLoginCount($where, $where_vars = array())
  1451. {
  1452. global $smcFunc;
  1453. $request = $smcFunc['db_query']('', '
  1454. SELECT COUNT(*) AS message_count
  1455. FROM {db_prefix}member_logins
  1456. WHERE id_member = {int:id_member}',
  1457. array(
  1458. 'id_member' => $where_vars['current_member'],
  1459. )
  1460. );
  1461. list ($count) = $smcFunc['db_fetch_row']($request);
  1462. $smcFunc['db_free_result']($request);
  1463. // @todo cast to integer
  1464. return $count;
  1465. }
  1466. /**
  1467. * Callback for trackLogins data.
  1468. *
  1469. * @param int $start
  1470. * @param int $items_per_page
  1471. * @param string $sort
  1472. * @param string $where
  1473. * @param array $where_vars
  1474. * @return array an array of messages
  1475. */
  1476. function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array())
  1477. {
  1478. global $smcFunc, $txt, $scripturl;
  1479. $request = $smcFunc['db_query']('', '
  1480. SELECT time, ip, ip2
  1481. FROM {db_prefix}member_logins
  1482. WHERE {int:id_member}
  1483. ORDER BY time DESC',
  1484. array(
  1485. 'id_member' => $where_vars['current_member'],
  1486. )
  1487. );
  1488. $logins = array();
  1489. while ($row = $smcFunc['db_fetch_assoc']($request))
  1490. $logins[] = array(
  1491. 'time' => timeformat($row['time']),
  1492. 'ip' => $row['ip'],
  1493. 'ip2' => $row['ip2'],
  1494. );
  1495. $smcFunc['db_free_result']($request);
  1496. return $logins;
  1497. }
  1498. /**
  1499. * @todo needs a description
  1500. *
  1501. * @param int $memID id_member
  1502. */
  1503. function trackEdits($memID)
  1504. {
  1505. global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc;
  1506. require_once($sourcedir . '/Subs-List.php');
  1507. // Get the names of any custom fields.
  1508. $request = $smcFunc['db_query']('', '
  1509. SELECT col_name, field_name, bbc
  1510. FROM {db_prefix}custom_fields',
  1511. array(
  1512. )
  1513. );
  1514. $context['custom_field_titles'] = array();
  1515. while ($row = $smcFunc['db_fetch_assoc']($request))
  1516. $context['custom_field_titles']['customfield_' . $row['col_name']] = array(
  1517. 'title' => $row['field_name'],
  1518. 'parse_bbc' => $row['bbc'],
  1519. );
  1520. $smcFunc['db_free_result']($request);
  1521. // Set the options for the error lists.
  1522. $listOptions = array(
  1523. 'id' => 'edit_list',
  1524. 'title' => $txt['trackEdits'],
  1525. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1526. 'no_items_label' => $txt['trackEdit_no_edits'],
  1527. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID,
  1528. 'default_sort_col' => 'time',
  1529. 'get_items' => array(
  1530. 'function' => 'list_getProfileEdits',
  1531. 'params' => array(
  1532. $memID,
  1533. ),
  1534. ),
  1535. 'get_count' => array(
  1536. 'function' => 'list_getProfileEditCount',
  1537. 'params' => array(
  1538. $memID,
  1539. ),
  1540. ),
  1541. 'columns' => array(
  1542. 'action' => array(
  1543. 'header' => array(
  1544. 'value' => $txt['trackEdit_action'],
  1545. ),
  1546. 'data' => array(
  1547. 'db' => 'action_text',
  1548. ),
  1549. ),
  1550. 'before' => array(
  1551. 'header' => array(
  1552. 'value' => $txt['trackEdit_before'],
  1553. ),
  1554. 'data' => array(
  1555. 'db' => 'before',
  1556. ),
  1557. ),
  1558. 'after' => array(
  1559. 'header' => array(
  1560. 'value' => $txt['trackEdit_after'],
  1561. ),
  1562. 'data' => array(
  1563. 'db' => 'after',
  1564. ),
  1565. ),
  1566. 'time' => array(
  1567. 'header' => array(
  1568. 'value' => $txt['date'],
  1569. ),
  1570. 'data' => array(
  1571. 'db' => 'time',
  1572. ),
  1573. 'sort' => array(
  1574. 'default' => 'id_action DESC',
  1575. 'reverse' => 'id_action',
  1576. ),
  1577. ),
  1578. 'applicator' => array(
  1579. 'header' => array(
  1580. 'value' => $txt['trackEdit_applicator'],
  1581. ),
  1582. 'data' => array(
  1583. 'db' => 'member_link',
  1584. ),
  1585. ),
  1586. ),
  1587. );
  1588. // Create the error list.
  1589. createList($listOptions);
  1590. $context['sub_template'] = 'show_list';
  1591. $context['default_list'] = 'edit_list';
  1592. }
  1593. /**
  1594. * How many edits?
  1595. *
  1596. * @param int $memID id_member
  1597. * @return string number of profile edits
  1598. */
  1599. function list_getProfileEditCount($memID)
  1600. {
  1601. global $smcFunc;
  1602. $request = $smcFunc['db_query']('', '
  1603. SELECT COUNT(*) AS edit_count
  1604. FROM {db_prefix}log_actions
  1605. WHERE id_log = {int:log_type}
  1606. AND id_member = {int:owner}',
  1607. array(
  1608. 'log_type' => 2,
  1609. 'owner' => $memID,
  1610. )
  1611. );
  1612. list ($edit_count) = $smcFunc['db_fetch_row']($request);
  1613. $smcFunc['db_free_result']($request);
  1614. // @todo cast to integer
  1615. return $edit_count;
  1616. }
  1617. /**
  1618. * @todo needs a description
  1619. *
  1620. * @param int $start
  1621. * @param int $items_per_page
  1622. * @param string $sort
  1623. * @param int $memID
  1624. * @return array
  1625. */
  1626. function list_getProfileEdits($start, $items_per_page, $sort, $memID)
  1627. {
  1628. global $smcFunc, $txt, $scripturl, $context;
  1629. // Get a list of error messages from this ip (range).
  1630. $request = $smcFunc['db_query']('', '
  1631. SELECT
  1632. id_action, id_member, ip, log_time, action, extra
  1633. FROM {db_prefix}log_actions
  1634. WHERE id_log = {int:log_type}
  1635. AND id_member = {int:owner}
  1636. ORDER BY ' . $sort . '
  1637. LIMIT ' . $start . ', ' . $items_per_page,
  1638. array(
  1639. 'log_type' => 2,
  1640. 'owner' => $memID,
  1641. )
  1642. );
  1643. $edits = array();
  1644. $members = array();
  1645. while ($row = $smcFunc['db_fetch_assoc']($request))
  1646. {
  1647. $extra = @unserialize($row['extra']);
  1648. if (!empty($extra['applicator']))
  1649. $members[] = $extra['applicator'];
  1650. // Work out what the name of the action is.
  1651. if (isset($txt['trackEdit_action_' . $row['action']]))
  1652. $action_text = $txt['trackEdit_action_' . $row['action']];
  1653. elseif (isset($txt[$row['action']]))
  1654. $action_text = $txt[$row['action']];
  1655. // Custom field?
  1656. elseif (isset($context['custom_field_titles'][$row['action']]))
  1657. $action_text = $context['custom_field_titles'][$row['action']]['title'];
  1658. else
  1659. $action_text = $row['action'];
  1660. // Parse BBC?
  1661. $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
  1662. $edits[] = array(
  1663. 'id' => $row['id_action'],
  1664. 'ip' => $row['ip'],
  1665. 'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0,
  1666. 'member_link' => $txt['trackEdit_deleted_member'],
  1667. 'action' => $row['action'],
  1668. 'action_text' => $action_text,
  1669. 'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '',
  1670. 'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '',
  1671. 'time' => timeformat($row['log_time']),
  1672. );
  1673. }
  1674. $smcFunc['db_free_result']($request);
  1675. // Get any member names.
  1676. if (!empty($members))
  1677. {
  1678. $request = $smcFunc['db_query']('', '
  1679. SELECT
  1680. id_member, real_name
  1681. FROM {db_prefix}members
  1682. WHERE id_member IN ({array_int:members})',
  1683. array(
  1684. 'members' => $members,
  1685. )
  1686. );
  1687. $members = array();
  1688. while ($row = $smcFunc['db_fetch_assoc']($request))
  1689. $members[$row['id_member']] = $row['real_name'];
  1690. $smcFunc['db_free_result']($request);
  1691. foreach ($edits as $key => $value)
  1692. if (isset($members[$value['id_member']]))
  1693. $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
  1694. }
  1695. return $edits;
  1696. }
  1697. /**
  1698. * @todo needs a description
  1699. *
  1700. * @param int $memID id_member
  1701. */
  1702. function showPermissions($memID)
  1703. {
  1704. global $scripturl, $txt, $board, $modSettings;
  1705. global $user_profile, $context, $user_info, $sourcedir, $smcFunc;
  1706. // Verify if the user has sufficient permissions.
  1707. isAllowedTo('manage_permissions');
  1708. loadLanguage('ManagePermissions');
  1709. loadLanguage('Admin');
  1710. loadTemplate('ManageMembers');
  1711. // Load all the permission profiles.
  1712. require_once($sourcedir . '/ManagePermissions.php');
  1713. loadPermissionProfiles();
  1714. $context['member']['id'] = $memID;
  1715. $context['member']['name'] = $user_profile[$memID]['real_name'];
  1716. $context['page_title'] = $txt['showPermissions'];
  1717. $board = empty($board) ? 0 : (int) $board;
  1718. $context['board'] = $board;
  1719. // Determine which groups this user is in.
  1720. if (empty($user_profile[$memID]['additional_groups']))
  1721. $curGroups = array();
  1722. else
  1723. $curGroups = explode(',', $user_profile[$memID]['additional_groups']);
  1724. $curGroups[] = $user_profile[$memID]['id_group'];
  1725. $curGroups[] = $user_profile[$memID]['id_post_group'];
  1726. // Load a list of boards for the jump box - except the defaults.
  1727. $request = $smcFunc['db_query']('order_by_board_order', '
  1728. SELECT b.id_board, b.name, b.id_profile, b.member_groups, IFNULL(mods.id_member, 0) AS is_mod
  1729. FROM {db_prefix}boards AS b
  1730. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
  1731. WHERE {query_see_board}',
  1732. array(
  1733. 'current_member' => $memID,
  1734. )
  1735. );
  1736. $context['boards'] = array();
  1737. $context['no_access_boards'] = array();
  1738. while ($row = $smcFunc['db_fetch_assoc']($request))
  1739. {
  1740. if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
  1741. $context['no_access_boards'][] = array(
  1742. 'id' => $row['id_board'],
  1743. 'name' => $row['name'],
  1744. 'is_last' => false,
  1745. );
  1746. elseif ($row['id_profile'] != 1 || $row['is_mod'])
  1747. $context['boards'][$row['id_board']] = array(
  1748. 'id' => $row['id_board'],
  1749. 'name' => $row['name'],
  1750. 'selected' => $board == $row['id_board'],
  1751. 'profile' => $row['id_profile'],
  1752. 'profile_name' => $context['profiles'][$row['id_profile']]['name'],
  1753. );
  1754. }
  1755. $smcFunc['db_free_result']($request);
  1756. if (!empty($context['no_access_boards']))
  1757. $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
  1758. $context['member']['permissions'] = array(
  1759. 'general' => array(),
  1760. 'board' => array()
  1761. );
  1762. // If you're an admin we know you can do everything, we might as well leave.
  1763. $context['member']['has_all_permissions'] = in_array(1, $curGroups);
  1764. if ($context['member']['has_all_permissions'])
  1765. return;
  1766. $denied = array();
  1767. // Get all general permissions.
  1768. $result = $smcFunc['db_query']('', '
  1769. SELECT p.permission, p.add_deny, mg.group_name, p.id_group
  1770. FROM {db_prefix}permissions AS p
  1771. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group)
  1772. WHERE p.id_group IN ({array_int:group_list})
  1773. ORDER BY p.add_deny DESC, p.permission, mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name',
  1774. array(
  1775. 'group_list' => $curGroups,
  1776. 'newbie_group' => 4,
  1777. )
  1778. );
  1779. while ($row = $smcFunc['db_fetch_assoc']($result))
  1780. {
  1781. // We don't know about this permission, it doesn't exist :P.
  1782. if (!isset($txt['permissionname_' . $row['permission']]))
  1783. continue;
  1784. if (empty($row['add_deny']))
  1785. $denied[] = $row['permission'];
  1786. // Permissions that end with _own or _any consist of two parts.
  1787. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  1788. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  1789. else
  1790. $name = $txt['permissionname_' . $row['permission']];
  1791. // Add this permission if it doesn't exist yet.
  1792. if (!isset($context['member']['permissions']['general'][$row['permission']]))
  1793. $context['member']['permissions']['general'][$row['permission']] = array(
  1794. 'id' => $row['permission'],
  1795. 'groups' => array(
  1796. 'allowed' => array(),
  1797. 'denied' => array()
  1798. ),
  1799. 'name' => $name,
  1800. 'is_denied' => false,
  1801. 'is_global' => true,
  1802. );
  1803. // Add the membergroup to either the denied or the allowed groups.
  1804. $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
  1805. // Once denied is always denied.
  1806. $context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  1807. }
  1808. $smcFunc['db_free_result']($result);
  1809. $request = $smcFunc['db_query']('', '
  1810. SELECT
  1811. bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ',
  1812. b.id_profile, CASE WHEN mods.id_member IS NULL THEN 0 ELSE 1 END AS is_moderator') . '
  1813. FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : '
  1814. INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board})
  1815. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})') . '
  1816. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group)
  1817. WHERE bp.id_profile = {raw:current_profile}
  1818. AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group})
  1819. AND (mods.id_member IS NOT NULL OR bp.id_group != {int:moderator_group})'),
  1820. array(
  1821. 'current_board' => $board,
  1822. 'group_list' => $curGroups,
  1823. 'current_member' => $memID,
  1824. 'current_profile' => empty($board) ? '1' : 'b.id_profile',
  1825. 'moderator_group' => 3,
  1826. )
  1827. );
  1828. while ($row = $smcFunc['db_fetch_assoc']($request))
  1829. {
  1830. // We don't know about this permission, it doesn't exist :P.
  1831. if (!isset($txt['permissionname_' . $row['permission']]))
  1832. continue;
  1833. // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
  1834. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  1835. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  1836. else
  1837. $name = $txt['permissionname_' . $row['permission']];
  1838. // Create the structure for this permission.
  1839. if (!isset($context['member']['permissions']['board'][$row['permission']]))
  1840. $context['member']['permissions']['board'][$row['permission']] = array(
  1841. 'id' => $row['permission'],
  1842. 'groups' => array(
  1843. 'allowed' => array(),
  1844. 'denied' => array()
  1845. ),
  1846. 'name' => $name,
  1847. 'is_denied' => false,
  1848. 'is_global' => empty($board),
  1849. );
  1850. $context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
  1851. $context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  1852. }
  1853. $smcFunc['db_free_result']($request);
  1854. }
  1855. /**
  1856. * View a members warnings?
  1857. *
  1858. * @param int $memID id_member
  1859. */
  1860. function viewWarning($memID)
  1861. {
  1862. global $modSettings, $context, $sourcedir, $txt, $scripturl;
  1863. // Firstly, can we actually even be here?
  1864. if (!allowedTo('issue_warning') && (empty($modSettings['warning_show']) || ($modSettings['warning_show'] == 1 && !$context['user']['is_owner'])))
  1865. fatal_lang_error('no_access', false);
  1866. // Make sure things which are disabled stay disabled.
  1867. $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
  1868. $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
  1869. $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;
  1870. // Let's use a generic list to get all the current warnings, and use the issue warnings grab-a-granny thing.
  1871. require_once($sourcedir . '/Subs-List.php');
  1872. require_once($sourcedir . '/Profile-Actions.php');
  1873. $listOptions = array(
  1874. 'id' => 'view_warnings',
  1875. 'title' => $txt['profile_viewwarning_previous_warnings'],
  1876. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1877. 'no_items_label' => $txt['profile_viewwarning_no_warnings'],
  1878. 'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID,
  1879. 'default_sort_col' => 'log_time',
  1880. 'get_items' => array(
  1881. 'function' => 'list_getUserWarnings',
  1882. 'params' => array(
  1883. $memID,
  1884. ),
  1885. ),
  1886. 'get_count' => array(
  1887. 'function' => 'list_getUserWarningCount',
  1888. 'params' => array(
  1889. $memID,
  1890. ),
  1891. ),
  1892. 'columns' => array(
  1893. 'log_time' => array(
  1894. 'header' => array(
  1895. 'value' => $txt['profile_warning_previous_time'],
  1896. ),
  1897. 'data' => array(
  1898. 'db' => 'time',
  1899. ),
  1900. 'sort' => array(
  1901. 'default' => 'lc.log_time DESC',
  1902. 'reverse' => 'lc.log_time',
  1903. ),
  1904. ),
  1905. 'reason' => array(
  1906. 'header' => array(
  1907. 'value' => $txt['profile_warning_previous_reason'],
  1908. 'style' => 'width: 50%',
  1909. ),
  1910. 'data' => array(
  1911. 'db' => 'reason',
  1912. ),
  1913. ),
  1914. 'level' => array(
  1915. 'header' => array(
  1916. 'value' => $txt['profile_warning_previous_level'],
  1917. ),
  1918. 'data' => array(
  1919. 'db' => 'counter',
  1920. ),
  1921. 'sort' => array(
  1922. 'default' => 'lc.counter DESC',
  1923. 'reverse' => 'lc.counter',
  1924. ),
  1925. ),
  1926. ),
  1927. 'additional_rows' => array(
  1928. array(
  1929. 'position' => 'after_title',
  1930. 'value' => $txt['profile_viewwarning_desc'],
  1931. 'class' => 'smalltext',
  1932. 'style' => 'padding: 2ex;',
  1933. ),
  1934. ),
  1935. );
  1936. // Create the list for viewing.
  1937. require_once($sourcedir . '/Subs-List.php');
  1938. createList($listOptions);
  1939. // Create some common text bits for the template.
  1940. $context['level_effects'] = array(
  1941. 0 => '',
  1942. $modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'],
  1943. $modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'],
  1944. $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
  1945. );
  1946. $context['current_level'] = 0;
  1947. foreach ($context['level_effects'] as $limit => $dummy)
  1948. if ($context['member']['warning'] >= $limit)
  1949. $context['current_level'] = $limit;
  1950. }
  1951. ?>