Profile-View.php 78 KB

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