Profile-View.php 76 KB

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