Profile-View.php 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458
  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 int $start
  565. * @param int $items_per_page
  566. * @param string $sort
  567. * @param array $boardsAllowed
  568. * @param ing $memID
  569. * @return array
  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. // Any topics found?
  800. $topicsInfo = array();
  801. if (!empty($topics))
  802. {
  803. $request = $smcFunc['db_query']('', '
  804. 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
  805. FROM {db_prefix}topics AS t
  806. INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  807. INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
  808. LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
  809. LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)
  810. WHERE t.id_topic IN ({array_int:topics})',
  811. array(
  812. 'topics' => $topics,
  813. )
  814. );
  815. while ($row = $smcFunc['db_fetch_assoc']($request))
  816. $topicsInfo[] = $row;
  817. $smcFunc['db_free_result']($request);
  818. }
  819. return $topicsInfo;
  820. }
  821. /**
  822. * Count the number of topics in the disregarded list
  823. *
  824. * @param int $memID
  825. */
  826. function list_getNumDisregarded($memID)
  827. {
  828. global $smcFunc, $user_info;
  829. // Get the total number of attachments they have posted.
  830. $request = $smcFunc['db_query']('', '
  831. SELECT COUNT(*)
  832. FROM {db_prefix}log_topics as lt
  833. LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic)
  834. LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board)
  835. WHERE id_member = {int:current_member}
  836. AND disregarded = 1
  837. AND {query_see_board}',
  838. array(
  839. 'current_member' => $memID,
  840. )
  841. );
  842. list ($disregardedCount) = $smcFunc['db_fetch_row']($request);
  843. $smcFunc['db_free_result']($request);
  844. return $disregardedCount;
  845. }
  846. /**
  847. * Gets the user stats for display
  848. *
  849. * @param int $memID id_member
  850. */
  851. function statPanel($memID)
  852. {
  853. global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc;
  854. $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
  855. // Is the load average too high to allow searching just now?
  856. if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
  857. fatal_lang_error('loadavg_userstats_disabled', false);
  858. // General user statistics.
  859. $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
  860. $timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600);
  861. $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'];
  862. $context['num_posts'] = comma_format($user_profile[$memID]['posts']);
  863. // Number of topics started.
  864. $result = $smcFunc['db_query']('', '
  865. SELECT COUNT(*)
  866. FROM {db_prefix}topics
  867. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  868. AND id_board != {int:recycle_board}' : ''),
  869. array(
  870. 'current_member' => $memID,
  871. 'recycle_board' => $modSettings['recycle_board'],
  872. )
  873. );
  874. list ($context['num_topics']) = $smcFunc['db_fetch_row']($result);
  875. $smcFunc['db_free_result']($result);
  876. // Number polls started.
  877. $result = $smcFunc['db_query']('', '
  878. SELECT COUNT(*)
  879. FROM {db_prefix}topics
  880. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  881. AND id_board != {int:recycle_board}' : '') . '
  882. AND id_poll != {int:no_poll}',
  883. array(
  884. 'current_member' => $memID,
  885. 'recycle_board' => $modSettings['recycle_board'],
  886. 'no_poll' => 0,
  887. )
  888. );
  889. list ($context['num_polls']) = $smcFunc['db_fetch_row']($result);
  890. $smcFunc['db_free_result']($result);
  891. // Number polls voted in.
  892. $result = $smcFunc['db_query']('distinct_poll_votes', '
  893. SELECT COUNT(DISTINCT id_poll)
  894. FROM {db_prefix}log_polls
  895. WHERE id_member = {int:current_member}',
  896. array(
  897. 'current_member' => $memID,
  898. )
  899. );
  900. list ($context['num_votes']) = $smcFunc['db_fetch_row']($result);
  901. $smcFunc['db_free_result']($result);
  902. // Format the numbers...
  903. $context['num_topics'] = comma_format($context['num_topics']);
  904. $context['num_polls'] = comma_format($context['num_polls']);
  905. $context['num_votes'] = comma_format($context['num_votes']);
  906. // Grab the board this member posted in most often.
  907. $result = $smcFunc['db_query']('', '
  908. SELECT
  909. b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count
  910. FROM {db_prefix}messages AS m
  911. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  912. WHERE m.id_member = {int:current_member}
  913. AND b.count_posts = {int:count_enabled}
  914. AND {query_see_board}
  915. GROUP BY b.id_board
  916. ORDER BY message_count DESC
  917. LIMIT 10',
  918. array(
  919. 'current_member' => $memID,
  920. 'count_enabled' => 0,
  921. )
  922. );
  923. $context['popular_boards'] = array();
  924. while ($row = $smcFunc['db_fetch_assoc']($result))
  925. {
  926. $context['popular_boards'][$row['id_board']] = array(
  927. 'id' => $row['id_board'],
  928. 'posts' => $row['message_count'],
  929. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  930. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  931. 'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'],
  932. 'total_posts' => $row['num_posts'],
  933. 'total_posts_member' => $user_profile[$memID]['posts'],
  934. );
  935. }
  936. $smcFunc['db_free_result']($result);
  937. // Now get the 10 boards this user has most often participated in.
  938. $result = $smcFunc['db_query']('profile_board_stats', '
  939. SELECT
  940. b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count,
  941. CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage
  942. FROM {db_prefix}messages AS m
  943. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  944. WHERE m.id_member = {int:current_member}
  945. AND {query_see_board}
  946. GROUP BY b.id_board, b.num_posts
  947. ORDER BY percentage DESC
  948. LIMIT 10',
  949. array(
  950. 'current_member' => $memID,
  951. )
  952. );
  953. $context['board_activity'] = array();
  954. while ($row = $smcFunc['db_fetch_assoc']($result))
  955. {
  956. $context['board_activity'][$row['id_board']] = array(
  957. 'id' => $row['id_board'],
  958. 'posts' => $row['message_count'],
  959. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  960. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  961. 'percent' => comma_format((float) $row['percentage'], 2),
  962. 'posts_percent' => (float) $row['percentage'],
  963. 'total_posts' => $row['num_posts'],
  964. );
  965. }
  966. $smcFunc['db_free_result']($result);
  967. // Posting activity by time.
  968. $result = $smcFunc['db_query']('user_activity_by_time', '
  969. SELECT
  970. HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
  971. COUNT(*) AS post_count
  972. FROM {db_prefix}messages
  973. WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? '
  974. AND id_topic > {int:top_ten_thousand_topics}' : '') . '
  975. GROUP BY hour',
  976. array(
  977. 'current_member' => $memID,
  978. 'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
  979. 'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
  980. )
  981. );
  982. $maxPosts = $realPosts = 0;
  983. $context['posts_by_time'] = array();
  984. while ($row = $smcFunc['db_fetch_assoc']($result))
  985. {
  986. // Cast as an integer to remove the leading 0.
  987. $row['hour'] = (int) $row['hour'];
  988. $maxPosts = max($row['post_count'], $maxPosts);
  989. $realPosts += $row['post_count'];
  990. $context['posts_by_time'][$row['hour']] = array(
  991. 'hour' => $row['hour'],
  992. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])),
  993. 'posts' => $row['post_count'],
  994. 'posts_percent' => 0,
  995. 'is_last' => $row['hour'] == 23,
  996. );
  997. }
  998. $smcFunc['db_free_result']($result);
  999. if ($maxPosts > 0)
  1000. for ($hour = 0; $hour < 24; $hour++)
  1001. {
  1002. if (!isset($context['posts_by_time'][$hour]))
  1003. $context['posts_by_time'][$hour] = array(
  1004. 'hour' => $hour,
  1005. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
  1006. 'posts' => 0,
  1007. 'posts_percent' => 0,
  1008. 'relative_percent' => 0,
  1009. 'is_last' => $hour == 23,
  1010. );
  1011. else
  1012. {
  1013. $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
  1014. $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
  1015. }
  1016. }
  1017. // Put it in the right order.
  1018. ksort($context['posts_by_time']);
  1019. // Custom stats (just add a template_layer to add it to the template!)
  1020. call_integration_hook('integrate_profile_stats', array($memID));
  1021. }
  1022. /**
  1023. * @todo needs a description
  1024. *
  1025. * @param int $memID id_member
  1026. */
  1027. function tracking($memID)
  1028. {
  1029. global $sourcedir, $context, $txt, $scripturl, $modSettings, $user_profile;
  1030. $subActions = array(
  1031. 'activity' => array('trackActivity', $txt['trackActivity']),
  1032. 'ip' => array('TrackIP', $txt['trackIP']),
  1033. 'edits' => array('trackEdits', $txt['trackEdits']),
  1034. 'logins' => array('TrackLogins', $txt['trackLogins']),
  1035. );
  1036. $context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'activity';
  1037. // @todo what is $types? it is never set so this will never be true
  1038. if (isset($types[$context['tracking_area']][1]))
  1039. require_once($sourcedir . '/' . $types[$context['tracking_area']][1]);
  1040. // Create the tabs for the template.
  1041. $context[$context['profile_menu_name']]['tab_data'] = array(
  1042. 'title' => $txt['tracking'],
  1043. 'description' => $txt['tracking_description'],
  1044. 'icon' => 'profile_hd.png',
  1045. 'tabs' => array(
  1046. 'activity' => array(),
  1047. 'ip' => array(),
  1048. 'edits' => array(),
  1049. ),
  1050. );
  1051. // Moderation must be on to track edits.
  1052. if (empty($modSettings['modlog_enabled']))
  1053. unset($context[$context['profile_menu_name']]['tab_data']['edits']);
  1054. // Set a page title.
  1055. $context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name'];
  1056. // Pass on to the actual function.
  1057. $context['sub_template'] = $subActions[$context['tracking_area']][0];
  1058. $subActions[$context['tracking_area']][0]($memID);
  1059. }
  1060. /**
  1061. * @todo needs a description
  1062. *
  1063. * @param int $memID id_member
  1064. */
  1065. function trackActivity($memID)
  1066. {
  1067. global $scripturl, $txt, $modSettings, $sourcedir;
  1068. global $user_profile, $context, $smcFunc;
  1069. // Verify if the user has sufficient permissions.
  1070. isAllowedTo('moderate_forum');
  1071. $context['last_ip'] = $user_profile[$memID]['member_ip'];
  1072. if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
  1073. $context['last_ip2'] = $user_profile[$memID]['member_ip2'];
  1074. $context['member']['name'] = $user_profile[$memID]['real_name'];
  1075. // Set the options for the list component.
  1076. $listOptions = array(
  1077. 'id' => 'track_user_list',
  1078. 'title' => $txt['errors_by'] . ' ' . $context['member']['name'],
  1079. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1080. 'no_items_label' => $txt['no_errors_from_user'],
  1081. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
  1082. 'default_sort_col' => 'date',
  1083. 'get_items' => array(
  1084. 'function' => 'list_getUserErrors',
  1085. 'params' => array(
  1086. 'le.id_member = {int:current_member}',
  1087. array('current_member' => $memID),
  1088. ),
  1089. ),
  1090. 'get_count' => array(
  1091. 'function' => 'list_getUserErrorCount',
  1092. 'params' => array(
  1093. 'id_member = {int:current_member}',
  1094. array('current_member' => $memID),
  1095. ),
  1096. ),
  1097. 'columns' => array(
  1098. 'ip_address' => array(
  1099. 'header' => array(
  1100. 'value' => $txt['ip_address'],
  1101. ),
  1102. 'data' => array(
  1103. 'sprintf' => array(
  1104. 'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID. '">%1$s</a>',
  1105. 'params' => array(
  1106. 'ip' => false,
  1107. ),
  1108. ),
  1109. ),
  1110. 'sort' => array(
  1111. 'default' => 'le.ip',
  1112. 'reverse' => 'le.ip DESC',
  1113. ),
  1114. ),
  1115. 'message' => array(
  1116. 'header' => array(
  1117. 'value' => $txt['message'],
  1118. ),
  1119. 'data' => array(
  1120. 'sprintf' => array(
  1121. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  1122. 'params' => array(
  1123. 'message' => false,
  1124. 'url' => false,
  1125. ),
  1126. ),
  1127. ),
  1128. ),
  1129. 'date' => array(
  1130. 'header' => array(
  1131. 'value' => $txt['date'],
  1132. ),
  1133. 'data' => array(
  1134. 'db' => 'time',
  1135. ),
  1136. 'sort' => array(
  1137. 'default' => 'le.id_error DESC',
  1138. 'reverse' => 'le.id_error',
  1139. ),
  1140. ),
  1141. ),
  1142. 'additional_rows' => array(
  1143. array(
  1144. 'position' => 'after_title',
  1145. 'value' => $txt['errors_desc'],
  1146. 'class' => 'windowbg2',
  1147. 'style' => 'padding: 1ex 2ex;',
  1148. ),
  1149. ),
  1150. );
  1151. // Create the list for viewing.
  1152. require_once($sourcedir . '/Subs-List.php');
  1153. createList($listOptions);
  1154. // @todo cache this
  1155. // If this is a big forum, or a large posting user, let's limit the search.
  1156. if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500)
  1157. {
  1158. $request = $smcFunc['db_query']('', '
  1159. SELECT MAX(id_msg)
  1160. FROM {db_prefix}messages AS m
  1161. WHERE m.id_member = {int:current_member}',
  1162. array(
  1163. 'current_member' => $memID,
  1164. )
  1165. );
  1166. list ($max_msg_member) = $smcFunc['db_fetch_row']($request);
  1167. $smcFunc['db_free_result']($request);
  1168. // There's no point worrying ourselves with messages made yonks ago, just get recent ones!
  1169. $min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3);
  1170. }
  1171. // Default to at least the ones we know about.
  1172. $ips = array(
  1173. $user_profile[$memID]['member_ip'],
  1174. $user_profile[$memID]['member_ip2'],
  1175. );
  1176. // @todo cache this
  1177. // Get all IP addresses this user has used for his messages.
  1178. $request = $smcFunc['db_query']('', '
  1179. SELECT poster_ip
  1180. FROM {db_prefix}messages
  1181. WHERE id_member = {int:current_member}
  1182. ' . (isset($min_msg_member) ? '
  1183. AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
  1184. GROUP BY poster_ip',
  1185. array(
  1186. 'current_member' => $memID,
  1187. 'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
  1188. 'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
  1189. )
  1190. );
  1191. $context['ips'] = array();
  1192. while ($row = $smcFunc['db_fetch_assoc']($request))
  1193. {
  1194. $context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['poster_ip'] . ';u=' . $memID . '">' . $row['poster_ip'] . '</a>';
  1195. $ips[] = $row['poster_ip'];
  1196. }
  1197. $smcFunc['db_free_result']($request);
  1198. // Now also get the IP addresses from the error messages.
  1199. $request = $smcFunc['db_query']('', '
  1200. SELECT COUNT(*) AS error_count, ip
  1201. FROM {db_prefix}log_errors
  1202. WHERE id_member = {int:current_member}
  1203. GROUP BY ip',
  1204. array(
  1205. 'current_member' => $memID,
  1206. )
  1207. );
  1208. $context['error_ips'] = array();
  1209. while ($row = $smcFunc['db_fetch_assoc']($request))
  1210. {
  1211. $context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>';
  1212. $ips[] = $row['ip'];
  1213. }
  1214. $smcFunc['db_free_result']($request);
  1215. // Find other users that might use the same IP.
  1216. $ips = array_unique($ips);
  1217. $context['members_in_range'] = array();
  1218. if (!empty($ips))
  1219. {
  1220. // Get member ID's which are in messages...
  1221. $request = $smcFunc['db_query']('', '
  1222. SELECT mem.id_member
  1223. FROM {db_prefix}messages AS m
  1224. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1225. WHERE m.poster_ip IN ({array_string:ip_list})
  1226. GROUP BY mem.id_member
  1227. HAVING mem.id_member != {int:current_member}',
  1228. array(
  1229. 'current_member' => $memID,
  1230. 'ip_list' => $ips,
  1231. )
  1232. );
  1233. $message_members = array();
  1234. while ($row = $smcFunc['db_fetch_assoc']($request))
  1235. $message_members[] = $row['id_member'];
  1236. $smcFunc['db_free_result']($request);
  1237. // Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
  1238. if (!empty($message_members))
  1239. {
  1240. $request = $smcFunc['db_query']('', '
  1241. SELECT id_member, real_name
  1242. FROM {db_prefix}members
  1243. WHERE id_member IN ({array_int:message_members})',
  1244. array(
  1245. 'message_members' => $message_members,
  1246. 'ip_list' => $ips,
  1247. )
  1248. );
  1249. while ($row = $smcFunc['db_fetch_assoc']($request))
  1250. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  1251. $smcFunc['db_free_result']($request);
  1252. }
  1253. $request = $smcFunc['db_query']('', '
  1254. SELECT id_member, real_name
  1255. FROM {db_prefix}members
  1256. WHERE id_member != {int:current_member}
  1257. AND member_ip IN ({array_string:ip_list})',
  1258. array(
  1259. 'current_member' => $memID,
  1260. 'ip_list' => $ips,
  1261. )
  1262. );
  1263. while ($row = $smcFunc['db_fetch_assoc']($request))
  1264. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  1265. $smcFunc['db_free_result']($request);
  1266. }
  1267. }
  1268. /**
  1269. * Get the number of user errors
  1270. *
  1271. * @param string $where
  1272. * @param array $where_vars = array()
  1273. * @return string number of user errors
  1274. */
  1275. function list_getUserErrorCount($where, $where_vars = array())
  1276. {
  1277. global $smcFunc;
  1278. $request = $smcFunc['db_query']('', '
  1279. SELECT COUNT(*) AS error_count
  1280. FROM {db_prefix}log_errors
  1281. WHERE ' . $where,
  1282. $where_vars
  1283. );
  1284. list ($count) = $smcFunc['db_fetch_row']($request);
  1285. $smcFunc['db_free_result']($request);
  1286. // @todo cast this to an integer
  1287. return $count;
  1288. }
  1289. /**
  1290. * @todo needs a description
  1291. *
  1292. * @param int $start
  1293. * @param int $items_per_page
  1294. * @param string $sort
  1295. * @param string $where
  1296. * @param array $where_vars
  1297. * @return array error messages
  1298. */
  1299. function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array())
  1300. {
  1301. global $smcFunc, $txt, $scripturl;
  1302. // Get a list of error messages from this ip (range).
  1303. $request = $smcFunc['db_query']('', '
  1304. SELECT
  1305. le.log_time, le.ip, le.url, le.message, IFNULL(mem.id_member, 0) AS id_member,
  1306. IFNULL(mem.real_name, {string:guest_title}) AS display_name, mem.member_name
  1307. FROM {db_prefix}log_errors AS le
  1308. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member)
  1309. WHERE ' . $where . '
  1310. ORDER BY ' . $sort . '
  1311. LIMIT ' . $start . ', ' . $items_per_page,
  1312. array_merge($where_vars, array(
  1313. 'guest_title' => $txt['guest_title'],
  1314. ))
  1315. );
  1316. $error_messages = array();
  1317. while ($row = $smcFunc['db_fetch_assoc']($request))
  1318. $error_messages[] = array(
  1319. 'ip' => $row['ip'],
  1320. 'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
  1321. 'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
  1322. 'url' => $row['url'],
  1323. 'time' => timeformat($row['log_time']),
  1324. 'timestamp' => forum_time(true, $row['log_time']),
  1325. );
  1326. $smcFunc['db_free_result']($request);
  1327. return $error_messages;
  1328. }
  1329. /**
  1330. * @todo needs a description
  1331. *
  1332. * @param string $where
  1333. * @param array $where_vars
  1334. * @return string count of messages matching the IP
  1335. */
  1336. function list_getIPMessageCount($where, $where_vars = array())
  1337. {
  1338. global $smcFunc;
  1339. $request = $smcFunc['db_query']('', '
  1340. SELECT COUNT(*) AS message_count
  1341. FROM {db_prefix}messages AS m
  1342. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1343. WHERE {query_see_board} AND ' . $where,
  1344. $where_vars
  1345. );
  1346. list ($count) = $smcFunc['db_fetch_row']($request);
  1347. $smcFunc['db_free_result']($request);
  1348. // @todo cast to integer
  1349. return $count;
  1350. }
  1351. /**
  1352. * @todo needs a description
  1353. *
  1354. * @param int $start
  1355. * @param int $items_per_page
  1356. * @param string $sort
  1357. * @param string $where
  1358. * @param array $where_vars
  1359. * @return array an array of messages
  1360. */
  1361. function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array())
  1362. {
  1363. global $smcFunc, $txt, $scripturl;
  1364. // Get all the messages fitting this where clause.
  1365. // @todo SLOW This query is using a filesort.
  1366. $request = $smcFunc['db_query']('', '
  1367. SELECT
  1368. m.id_msg, m.poster_ip, IFNULL(mem.real_name, m.poster_name) AS display_name, mem.id_member,
  1369. m.subject, m.poster_time, m.id_topic, m.id_board
  1370. FROM {db_prefix}messages AS m
  1371. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1372. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1373. WHERE {query_see_board} AND ' . $where . '
  1374. ORDER BY ' . $sort . '
  1375. LIMIT ' . $start . ', ' . $items_per_page,
  1376. array_merge($where_vars, array(
  1377. ))
  1378. );
  1379. $messages = array();
  1380. while ($row = $smcFunc['db_fetch_assoc']($request))
  1381. $messages[] = array(
  1382. 'ip' => $row['poster_ip'],
  1383. 'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
  1384. 'board' => array(
  1385. 'id' => $row['id_board'],
  1386. 'href' => $scripturl . '?board=' . $row['id_board']
  1387. ),
  1388. 'topic' => $row['id_topic'],
  1389. 'id' => $row['id_msg'],
  1390. 'subject' => $row['subject'],
  1391. 'time' => timeformat($row['poster_time']),
  1392. 'timestamp' => forum_time(true, $row['poster_time'])
  1393. );
  1394. $smcFunc['db_free_result']($request);
  1395. return $messages;
  1396. }
  1397. /**
  1398. * @todo needs a description
  1399. *
  1400. * @param int $memID = 0 id_member
  1401. */
  1402. function TrackIP($memID = 0)
  1403. {
  1404. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1405. global $context, $smcFunc;
  1406. // Can the user do this?
  1407. isAllowedTo('moderate_forum');
  1408. if ($memID == 0)
  1409. {
  1410. $context['ip'] = $user_info['ip'];
  1411. loadTemplate('Profile');
  1412. loadLanguage('Profile');
  1413. $context['sub_template'] = 'trackIP';
  1414. $context['page_title'] = $txt['profile'];
  1415. $context['base_url'] = $scripturl . '?action=trackip';
  1416. }
  1417. else
  1418. {
  1419. $context['ip'] = $user_profile[$memID]['member_ip'];
  1420. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1421. }
  1422. // Searching?
  1423. if (isset($_REQUEST['searchip']))
  1424. $context['ip'] = trim($_REQUEST['searchip']);
  1425. if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false)
  1426. fatal_lang_error('invalid_tracking_ip', false);
  1427. $ip_var = str_replace('*', '%', $context['ip']);
  1428. $ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}';
  1429. if (empty($context['tracking_area']))
  1430. $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
  1431. $request = $smcFunc['db_query']('', '
  1432. SELECT id_member, real_name AS display_name, member_ip
  1433. FROM {db_prefix}members
  1434. WHERE member_ip ' . $ip_string,
  1435. array(
  1436. 'ip_address' => $ip_var,
  1437. )
  1438. );
  1439. $context['ips'] = array();
  1440. while ($row = $smcFunc['db_fetch_assoc']($request))
  1441. $context['ips'][$row['member_ip']][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
  1442. $smcFunc['db_free_result']($request);
  1443. ksort($context['ips']);
  1444. // Gonna want this for the list.
  1445. require_once($sourcedir . '/Subs-List.php');
  1446. // Start with the user messages.
  1447. $listOptions = array(
  1448. 'id' => 'track_message_list',
  1449. 'title' => $txt['messages_from_ip'] . ' ' . $context['ip'],
  1450. 'start_var_name' => 'messageStart',
  1451. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1452. 'no_items_label' => $txt['no_messages_from_ip'],
  1453. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1454. 'default_sort_col' => 'date',
  1455. 'get_items' => array(
  1456. 'function' => 'list_getIPMessages',
  1457. 'params' => array(
  1458. 'm.poster_ip ' . $ip_string,
  1459. array('ip_address' => $ip_var),
  1460. ),
  1461. ),
  1462. 'get_count' => array(
  1463. 'function' => 'list_getIPMessageCount',
  1464. 'params' => array(
  1465. 'm.poster_ip ' . $ip_string,
  1466. array('ip_address' => $ip_var),
  1467. ),
  1468. ),
  1469. 'columns' => array(
  1470. 'ip_address' => array(
  1471. 'header' => array(
  1472. 'value' => $txt['ip_address'],
  1473. ),
  1474. 'data' => array(
  1475. 'sprintf' => array(
  1476. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1477. 'params' => array(
  1478. 'ip' => false,
  1479. ),
  1480. ),
  1481. ),
  1482. 'sort' => array(
  1483. 'default' => 'INET_ATON(m.poster_ip)',
  1484. 'reverse' => 'INET_ATON(m.poster_ip) DESC',
  1485. ),
  1486. ),
  1487. 'poster' => array(
  1488. 'header' => array(
  1489. 'value' => $txt['poster'],
  1490. ),
  1491. 'data' => array(
  1492. 'db' => 'member_link',
  1493. ),
  1494. ),
  1495. 'subject' => array(
  1496. 'header' => array(
  1497. 'value' => $txt['subject'],
  1498. ),
  1499. 'data' => array(
  1500. 'sprintf' => array(
  1501. 'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>',
  1502. 'params' => array(
  1503. 'topic' => false,
  1504. 'id' => false,
  1505. 'subject' => false,
  1506. ),
  1507. ),
  1508. ),
  1509. ),
  1510. 'date' => array(
  1511. 'header' => array(
  1512. 'value' => $txt['date'],
  1513. ),
  1514. 'data' => array(
  1515. 'db' => 'time',
  1516. ),
  1517. 'sort' => array(
  1518. 'default' => 'm.id_msg DESC',
  1519. 'reverse' => 'm.id_msg',
  1520. ),
  1521. ),
  1522. ),
  1523. 'additional_rows' => array(
  1524. array(
  1525. 'position' => 'after_title',
  1526. 'value' => $txt['messages_from_ip_desc'],
  1527. 'class' => 'windowbg2',
  1528. 'style' => 'padding: 1ex 2ex;',
  1529. ),
  1530. ),
  1531. );
  1532. // Create the messages list.
  1533. createList($listOptions);
  1534. // Set the options for the error lists.
  1535. $listOptions = array(
  1536. 'id' => 'track_user_list',
  1537. 'title' => $txt['errors_from_ip'] . ' ' . $context['ip'],
  1538. 'start_var_name' => 'errorStart',
  1539. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1540. 'no_items_label' => $txt['no_errors_from_ip'],
  1541. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1542. 'default_sort_col' => 'date2',
  1543. 'get_items' => array(
  1544. 'function' => 'list_getUserErrors',
  1545. 'params' => array(
  1546. 'le.ip ' . $ip_string,
  1547. array('ip_address' => $ip_var),
  1548. ),
  1549. ),
  1550. 'get_count' => array(
  1551. 'function' => 'list_getUserErrorCount',
  1552. 'params' => array(
  1553. 'ip ' . $ip_string,
  1554. array('ip_address' => $ip_var),
  1555. ),
  1556. ),
  1557. 'columns' => array(
  1558. 'ip_address2' => array(
  1559. 'header' => array(
  1560. 'value' => $txt['ip_address'],
  1561. ),
  1562. 'data' => array(
  1563. 'sprintf' => array(
  1564. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1565. 'params' => array(
  1566. 'ip' => false,
  1567. ),
  1568. ),
  1569. ),
  1570. 'sort' => array(
  1571. 'default' => 'INET_ATON(le.ip)',
  1572. 'reverse' => 'INET_ATON(le.ip) DESC',
  1573. ),
  1574. ),
  1575. 'display_name' => array(
  1576. 'header' => array(
  1577. 'value' => $txt['display_name'],
  1578. ),
  1579. 'data' => array(
  1580. 'db' => 'member_link',
  1581. ),
  1582. ),
  1583. 'message' => array(
  1584. 'header' => array(
  1585. 'value' => $txt['message'],
  1586. ),
  1587. 'data' => array(
  1588. 'sprintf' => array(
  1589. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  1590. 'params' => array(
  1591. 'message' => false,
  1592. 'url' => false,
  1593. ),
  1594. ),
  1595. ),
  1596. ),
  1597. 'date2' => array(
  1598. 'header' => array(
  1599. 'value' => $txt['date'],
  1600. ),
  1601. 'data' => array(
  1602. 'db' => 'time',
  1603. ),
  1604. 'sort' => array(
  1605. 'default' => 'le.id_error DESC',
  1606. 'reverse' => 'le.id_error',
  1607. ),
  1608. ),
  1609. ),
  1610. 'additional_rows' => array(
  1611. array(
  1612. 'position' => 'after_title',
  1613. 'value' => $txt['errors_from_ip_desc'],
  1614. 'class' => 'windowbg2',
  1615. 'style' => 'padding: 1ex 2ex;',
  1616. ),
  1617. ),
  1618. );
  1619. // Create the error list.
  1620. createList($listOptions);
  1621. $context['single_ip'] = strpos($context['ip'], '*') === false;
  1622. if ($context['single_ip'])
  1623. {
  1624. $context['whois_servers'] = array(
  1625. 'afrinic' => array(
  1626. 'name' => $txt['whois_afrinic'],
  1627. 'url' => 'http://www.afrinic.net/cgi-bin/whois?searchtext=' . $context['ip'],
  1628. 'range' => array(41, 154, 196),
  1629. ),
  1630. 'apnic' => array(
  1631. 'name' => $txt['whois_apnic'],
  1632. 'url' => 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'],
  1633. 'range' => array(58, 59, 60, 61, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
  1634. 125, 126, 133, 150, 153, 163, 171, 202, 203, 210, 211, 218, 219, 220, 221, 222),
  1635. ),
  1636. 'arin' => array(
  1637. 'name' => $txt['whois_arin'],
  1638. 'url' => 'http://whois.arin.net/rest/ip/' . $context['ip'],
  1639. 'range' => array(7, 24, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 96, 97, 98, 99,
  1640. 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149,
  1641. 152, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 172, 173, 174,
  1642. 192, 198, 199, 204, 205, 206, 207, 208, 209, 216),
  1643. ),
  1644. 'lacnic' => array(
  1645. 'name' => $txt['whois_lacnic'],
  1646. 'url' => 'http://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'],
  1647. 'range' => array(186, 187, 189, 190, 191, 200, 201),
  1648. ),
  1649. 'ripe' => array(
  1650. 'name' => $txt['whois_ripe'],
  1651. 'url' => 'http://www.db.ripe.net/whois?searchtext=' . $context['ip'],
  1652. 'range' => array(62, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  1653. 141, 145, 151, 188, 193, 194, 195, 212, 213, 217),
  1654. ),
  1655. );
  1656. foreach ($context['whois_servers'] as $whois)
  1657. {
  1658. // Strip off the "decimal point" and anything following...
  1659. if (in_array((int) $context['ip'], $whois['range']))
  1660. $context['auto_whois_server'] = $whois;
  1661. }
  1662. }
  1663. }
  1664. /**
  1665. * Tracks a users logins.
  1666. *
  1667. * @param int $memID = 0 id_member
  1668. */
  1669. function TrackLogins($memID = 0)
  1670. {
  1671. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1672. global $context, $smcFunc;
  1673. // Gonna want this for the list.
  1674. require_once($sourcedir . '/Subs-List.php');
  1675. if ($memID == 0)
  1676. $context['base_url'] = $scripturl . '?action=trackip';
  1677. else
  1678. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1679. // Start with the user messages.
  1680. $listOptions = array(
  1681. 'id' => 'track_logins_list',
  1682. 'title' => $txt['trackLogins'],
  1683. 'no_items_label' => $txt['trackLogins_none_found'],
  1684. 'base_href' => $context['base_url'],
  1685. 'get_items' => array(
  1686. 'function' => 'list_getLogins',
  1687. 'params' => array(
  1688. 'id_member = {int:current_member}',
  1689. array('current_member' => $memID),
  1690. ),
  1691. ),
  1692. 'get_count' => array(
  1693. 'function' => 'list_getLoginCount',
  1694. 'params' => array(
  1695. 'id_member = {int:current_member}',
  1696. array('current_member' => $memID),
  1697. ),
  1698. ),
  1699. 'columns' => array(
  1700. 'time' => array(
  1701. 'header' => array(
  1702. 'value' => $txt['date'],
  1703. ),
  1704. 'data' => array(
  1705. 'db' => 'time',
  1706. ),
  1707. ),
  1708. 'ip' => array(
  1709. 'header' => array(
  1710. 'value' => $txt['ip_address'],
  1711. ),
  1712. 'data' => array(
  1713. 'sprintf' => array(
  1714. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ',
  1715. 'params' => array(
  1716. 'ip' => false,
  1717. 'ip2' => false
  1718. ),
  1719. ),
  1720. ),
  1721. ),
  1722. ),
  1723. 'additional_rows' => array(
  1724. array(
  1725. 'position' => 'after_title',
  1726. 'value' => $txt['trackLogins_desc'],
  1727. 'class' => 'windowbg2',
  1728. 'style' => 'padding: 1ex 2ex;',
  1729. ),
  1730. ),
  1731. );
  1732. // Create the messages list.
  1733. createList($listOptions);
  1734. $context['sub_template'] = 'show_list';
  1735. $context['default_list'] = 'track_logins_list';
  1736. }
  1737. /**
  1738. * Callback for trackLogins for counting history.
  1739. *
  1740. * @param string $where
  1741. * @param array $where_vars
  1742. * @return string count of messages matching the IP
  1743. */
  1744. function list_getLoginCount($where, $where_vars = array())
  1745. {
  1746. global $smcFunc;
  1747. $request = $smcFunc['db_query']('', '
  1748. SELECT COUNT(*) AS message_count
  1749. FROM {db_prefix}member_logins
  1750. WHERE id_member = {int:id_member}',
  1751. array(
  1752. 'id_member' => $where_vars['current_member'],
  1753. )
  1754. );
  1755. list ($count) = $smcFunc['db_fetch_row']($request);
  1756. $smcFunc['db_free_result']($request);
  1757. // @todo cast to integer
  1758. return $count;
  1759. }
  1760. /**
  1761. * Callback for trackLogins data.
  1762. *
  1763. * @param int $start
  1764. * @param int $items_per_page
  1765. * @param string $sort
  1766. * @param string $where
  1767. * @param array $where_vars
  1768. * @return array an array of messages
  1769. */
  1770. function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array())
  1771. {
  1772. global $smcFunc, $txt, $scripturl;
  1773. $request = $smcFunc['db_query']('', '
  1774. SELECT time, ip, ip2
  1775. FROM {db_prefix}member_logins
  1776. WHERE {int:id_member}
  1777. ORDER BY time DESC',
  1778. array(
  1779. 'id_member' => $where_vars['current_member'],
  1780. )
  1781. );
  1782. $logins = array();
  1783. while ($row = $smcFunc['db_fetch_assoc']($request))
  1784. $logins[] = array(
  1785. 'time' => timeformat($row['time']),
  1786. 'ip' => $row['ip'],
  1787. 'ip2' => $row['ip2'],
  1788. );
  1789. $smcFunc['db_free_result']($request);
  1790. return $logins;
  1791. }
  1792. /**
  1793. * @todo needs a description
  1794. *
  1795. * @param int $memID id_member
  1796. */
  1797. function trackEdits($memID)
  1798. {
  1799. global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc;
  1800. require_once($sourcedir . '/Subs-List.php');
  1801. // Get the names of any custom fields.
  1802. $request = $smcFunc['db_query']('', '
  1803. SELECT col_name, field_name, bbc
  1804. FROM {db_prefix}custom_fields',
  1805. array(
  1806. )
  1807. );
  1808. $context['custom_field_titles'] = array();
  1809. while ($row = $smcFunc['db_fetch_assoc']($request))
  1810. $context['custom_field_titles']['customfield_' . $row['col_name']] = array(
  1811. 'title' => $row['field_name'],
  1812. 'parse_bbc' => $row['bbc'],
  1813. );
  1814. $smcFunc['db_free_result']($request);
  1815. // Set the options for the error lists.
  1816. $listOptions = array(
  1817. 'id' => 'edit_list',
  1818. 'title' => $txt['trackEdits'],
  1819. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1820. 'no_items_label' => $txt['trackEdit_no_edits'],
  1821. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID,
  1822. 'default_sort_col' => 'time',
  1823. 'get_items' => array(
  1824. 'function' => 'list_getProfileEdits',
  1825. 'params' => array(
  1826. $memID,
  1827. ),
  1828. ),
  1829. 'get_count' => array(
  1830. 'function' => 'list_getProfileEditCount',
  1831. 'params' => array(
  1832. $memID,
  1833. ),
  1834. ),
  1835. 'columns' => array(
  1836. 'action' => array(
  1837. 'header' => array(
  1838. 'value' => $txt['trackEdit_action'],
  1839. ),
  1840. 'data' => array(
  1841. 'db' => 'action_text',
  1842. ),
  1843. ),
  1844. 'before' => array(
  1845. 'header' => array(
  1846. 'value' => $txt['trackEdit_before'],
  1847. ),
  1848. 'data' => array(
  1849. 'db' => 'before',
  1850. ),
  1851. ),
  1852. 'after' => array(
  1853. 'header' => array(
  1854. 'value' => $txt['trackEdit_after'],
  1855. ),
  1856. 'data' => array(
  1857. 'db' => 'after',
  1858. ),
  1859. ),
  1860. 'time' => array(
  1861. 'header' => array(
  1862. 'value' => $txt['date'],
  1863. ),
  1864. 'data' => array(
  1865. 'db' => 'time',
  1866. ),
  1867. 'sort' => array(
  1868. 'default' => 'id_action DESC',
  1869. 'reverse' => 'id_action',
  1870. ),
  1871. ),
  1872. 'applicator' => array(
  1873. 'header' => array(
  1874. 'value' => $txt['trackEdit_applicator'],
  1875. ),
  1876. 'data' => array(
  1877. 'db' => 'member_link',
  1878. ),
  1879. ),
  1880. ),
  1881. );
  1882. // Create the error list.
  1883. createList($listOptions);
  1884. $context['sub_template'] = 'show_list';
  1885. $context['default_list'] = 'edit_list';
  1886. }
  1887. /**
  1888. * How many edits?
  1889. *
  1890. * @param int $memID id_member
  1891. * @return string number of profile edits
  1892. */
  1893. function list_getProfileEditCount($memID)
  1894. {
  1895. global $smcFunc;
  1896. $request = $smcFunc['db_query']('', '
  1897. SELECT COUNT(*) AS edit_count
  1898. FROM {db_prefix}log_actions
  1899. WHERE id_log = {int:log_type}
  1900. AND id_member = {int:owner}',
  1901. array(
  1902. 'log_type' => 2,
  1903. 'owner' => $memID,
  1904. )
  1905. );
  1906. list ($edit_count) = $smcFunc['db_fetch_row']($request);
  1907. $smcFunc['db_free_result']($request);
  1908. // @todo cast to integer
  1909. return $edit_count;
  1910. }
  1911. /**
  1912. * @todo needs a description
  1913. *
  1914. * @param int $start
  1915. * @param int $items_per_page
  1916. * @param string $sort
  1917. * @param int $memID
  1918. * @return array
  1919. */
  1920. function list_getProfileEdits($start, $items_per_page, $sort, $memID)
  1921. {
  1922. global $smcFunc, $txt, $scripturl, $context;
  1923. // Get a list of error messages from this ip (range).
  1924. $request = $smcFunc['db_query']('', '
  1925. SELECT
  1926. id_action, id_member, ip, log_time, action, extra
  1927. FROM {db_prefix}log_actions
  1928. WHERE id_log = {int:log_type}
  1929. AND id_member = {int:owner}
  1930. ORDER BY ' . $sort . '
  1931. LIMIT ' . $start . ', ' . $items_per_page,
  1932. array(
  1933. 'log_type' => 2,
  1934. 'owner' => $memID,
  1935. )
  1936. );
  1937. $edits = array();
  1938. $members = array();
  1939. while ($row = $smcFunc['db_fetch_assoc']($request))
  1940. {
  1941. $extra = @unserialize($row['extra']);
  1942. if (!empty($extra['applicator']))
  1943. $members[] = $extra['applicator'];
  1944. // Work out what the name of the action is.
  1945. if (isset($txt['trackEdit_action_' . $row['action']]))
  1946. $action_text = $txt['trackEdit_action_' . $row['action']];
  1947. elseif (isset($txt[$row['action']]))
  1948. $action_text = $txt[$row['action']];
  1949. // Custom field?
  1950. elseif (isset($context['custom_field_titles'][$row['action']]))
  1951. $action_text = $context['custom_field_titles'][$row['action']]['title'];
  1952. else
  1953. $action_text = $row['action'];
  1954. // Parse BBC?
  1955. $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
  1956. $edits[] = array(
  1957. 'id' => $row['id_action'],
  1958. 'ip' => $row['ip'],
  1959. 'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0,
  1960. 'member_link' => $txt['trackEdit_deleted_member'],
  1961. 'action' => $row['action'],
  1962. 'action_text' => $action_text,
  1963. 'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '',
  1964. 'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '',
  1965. 'time' => timeformat($row['log_time']),
  1966. );
  1967. }
  1968. $smcFunc['db_free_result']($request);
  1969. // Get any member names.
  1970. if (!empty($members))
  1971. {
  1972. $request = $smcFunc['db_query']('', '
  1973. SELECT
  1974. id_member, real_name
  1975. FROM {db_prefix}members
  1976. WHERE id_member IN ({array_int:members})',
  1977. array(
  1978. 'members' => $members,
  1979. )
  1980. );
  1981. $members = array();
  1982. while ($row = $smcFunc['db_fetch_assoc']($request))
  1983. $members[$row['id_member']] = $row['real_name'];
  1984. $smcFunc['db_free_result']($request);
  1985. foreach ($edits as $key => $value)
  1986. if (isset($members[$value['id_member']]))
  1987. $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
  1988. }
  1989. return $edits;
  1990. }
  1991. /**
  1992. * @todo needs a description
  1993. *
  1994. * @param int $memID id_member
  1995. */
  1996. function showPermissions($memID)
  1997. {
  1998. global $scripturl, $txt, $board, $modSettings;
  1999. global $user_profile, $context, $user_info, $sourcedir, $smcFunc;
  2000. // Verify if the user has sufficient permissions.
  2001. isAllowedTo('manage_permissions');
  2002. loadLanguage('ManagePermissions');
  2003. loadLanguage('Admin');
  2004. loadTemplate('ManageMembers');
  2005. // Load all the permission profiles.
  2006. require_once($sourcedir . '/ManagePermissions.php');
  2007. loadPermissionProfiles();
  2008. $context['member']['id'] = $memID;
  2009. $context['member']['name'] = $user_profile[$memID]['real_name'];
  2010. $context['page_title'] = $txt['showPermissions'];
  2011. $board = empty($board) ? 0 : (int) $board;
  2012. $context['board'] = $board;
  2013. // Determine which groups this user is in.
  2014. if (empty($user_profile[$memID]['additional_groups']))
  2015. $curGroups = array();
  2016. else
  2017. $curGroups = explode(',', $user_profile[$memID]['additional_groups']);
  2018. $curGroups[] = $user_profile[$memID]['id_group'];
  2019. $curGroups[] = $user_profile[$memID]['id_post_group'];
  2020. // Load a list of boards for the jump box - except the defaults.
  2021. $request = $smcFunc['db_query']('order_by_board_order', '
  2022. SELECT b.id_board, b.name, b.id_profile, b.member_groups, IFNULL(mods.id_member, 0) AS is_mod
  2023. FROM {db_prefix}boards AS b
  2024. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
  2025. WHERE {query_see_board}',
  2026. array(
  2027. 'current_member' => $memID,
  2028. )
  2029. );
  2030. $context['boards'] = array();
  2031. $context['no_access_boards'] = array();
  2032. while ($row = $smcFunc['db_fetch_assoc']($request))
  2033. {
  2034. if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
  2035. $context['no_access_boards'][] = array(
  2036. 'id' => $row['id_board'],
  2037. 'name' => $row['name'],
  2038. 'is_last' => false,
  2039. );
  2040. elseif ($row['id_profile'] != 1 || $row['is_mod'])
  2041. $context['boards'][$row['id_board']] = array(
  2042. 'id' => $row['id_board'],
  2043. 'name' => $row['name'],
  2044. 'selected' => $board == $row['id_board'],
  2045. 'profile' => $row['id_profile'],
  2046. 'profile_name' => $context['profiles'][$row['id_profile']]['name'],
  2047. );
  2048. }
  2049. $smcFunc['db_free_result']($request);
  2050. if (!empty($context['no_access_boards']))
  2051. $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
  2052. $context['member']['permissions'] = array(
  2053. 'general' => array(),
  2054. 'board' => array()
  2055. );
  2056. // If you're an admin we know you can do everything, we might as well leave.
  2057. $context['member']['has_all_permissions'] = in_array(1, $curGroups);
  2058. if ($context['member']['has_all_permissions'])
  2059. return;
  2060. $denied = array();
  2061. // Get all general permissions.
  2062. $result = $smcFunc['db_query']('', '
  2063. SELECT p.permission, p.add_deny, mg.group_name, p.id_group
  2064. FROM {db_prefix}permissions AS p
  2065. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group)
  2066. WHERE p.id_group IN ({array_int:group_list})
  2067. 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',
  2068. array(
  2069. 'group_list' => $curGroups,
  2070. 'newbie_group' => 4,
  2071. )
  2072. );
  2073. while ($row = $smcFunc['db_fetch_assoc']($result))
  2074. {
  2075. // We don't know about this permission, it doesn't exist :P.
  2076. if (!isset($txt['permissionname_' . $row['permission']]))
  2077. continue;
  2078. if (empty($row['add_deny']))
  2079. $denied[] = $row['permission'];
  2080. // Permissions that end with _own or _any consist of two parts.
  2081. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  2082. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  2083. else
  2084. $name = $txt['permissionname_' . $row['permission']];
  2085. // Add this permission if it doesn't exist yet.
  2086. if (!isset($context['member']['permissions']['general'][$row['permission']]))
  2087. $context['member']['permissions']['general'][$row['permission']] = array(
  2088. 'id' => $row['permission'],
  2089. 'groups' => array(
  2090. 'allowed' => array(),
  2091. 'denied' => array()
  2092. ),
  2093. 'name' => $name,
  2094. 'is_denied' => false,
  2095. 'is_global' => true,
  2096. );
  2097. // Add the membergroup to either the denied or the allowed groups.
  2098. $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
  2099. // Once denied is always denied.
  2100. $context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  2101. }
  2102. $smcFunc['db_free_result']($result);
  2103. $request = $smcFunc['db_query']('', '
  2104. SELECT
  2105. bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ',
  2106. b.id_profile, CASE WHEN mods.id_member IS NULL THEN 0 ELSE 1 END AS is_moderator') . '
  2107. FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : '
  2108. INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board})
  2109. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})') . '
  2110. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group)
  2111. WHERE bp.id_profile = {raw:current_profile}
  2112. AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group})
  2113. AND (mods.id_member IS NOT NULL OR bp.id_group != {int:moderator_group})'),
  2114. array(
  2115. 'current_board' => $board,
  2116. 'group_list' => $curGroups,
  2117. 'current_member' => $memID,
  2118. 'current_profile' => empty($board) ? '1' : 'b.id_profile',
  2119. 'moderator_group' => 3,
  2120. )
  2121. );
  2122. while ($row = $smcFunc['db_fetch_assoc']($request))
  2123. {
  2124. // We don't know about this permission, it doesn't exist :P.
  2125. if (!isset($txt['permissionname_' . $row['permission']]))
  2126. continue;
  2127. // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
  2128. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  2129. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  2130. else
  2131. $name = $txt['permissionname_' . $row['permission']];
  2132. // Create the structure for this permission.
  2133. if (!isset($context['member']['permissions']['board'][$row['permission']]))
  2134. $context['member']['permissions']['board'][$row['permission']] = array(
  2135. 'id' => $row['permission'],
  2136. 'groups' => array(
  2137. 'allowed' => array(),
  2138. 'denied' => array()
  2139. ),
  2140. 'name' => $name,
  2141. 'is_denied' => false,
  2142. 'is_global' => empty($board),
  2143. );
  2144. $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'];
  2145. $context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  2146. }
  2147. $smcFunc['db_free_result']($request);
  2148. }
  2149. /**
  2150. * View a members warnings?
  2151. *
  2152. * @param int $memID id_member
  2153. */
  2154. function viewWarning($memID)
  2155. {
  2156. global $modSettings, $context, $sourcedir, $txt, $scripturl;
  2157. // Firstly, can we actually even be here?
  2158. if (!allowedTo('issue_warning') && (empty($modSettings['warning_show']) || ($modSettings['warning_show'] == 1 && !$context['user']['is_owner'])))
  2159. fatal_lang_error('no_access', false);
  2160. // Make sure things which are disabled stay disabled.
  2161. $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
  2162. $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
  2163. $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;
  2164. // Let's use a generic list to get all the current warnings, and use the issue warnings grab-a-granny thing.
  2165. require_once($sourcedir . '/Subs-List.php');
  2166. require_once($sourcedir . '/Profile-Actions.php');
  2167. $listOptions = array(
  2168. 'id' => 'view_warnings',
  2169. 'title' => $txt['profile_viewwarning_previous_warnings'],
  2170. 'items_per_page' => $modSettings['defaultMaxMessages'],
  2171. 'no_items_label' => $txt['profile_viewwarning_no_warnings'],
  2172. 'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID,
  2173. 'default_sort_col' => 'log_time',
  2174. 'get_items' => array(
  2175. 'function' => 'list_getUserWarnings',
  2176. 'params' => array(
  2177. $memID,
  2178. ),
  2179. ),
  2180. 'get_count' => array(
  2181. 'function' => 'list_getUserWarningCount',
  2182. 'params' => array(
  2183. $memID,
  2184. ),
  2185. ),
  2186. 'columns' => array(
  2187. 'log_time' => array(
  2188. 'header' => array(
  2189. 'value' => $txt['profile_warning_previous_time'],
  2190. ),
  2191. 'data' => array(
  2192. 'db' => 'time',
  2193. ),
  2194. 'sort' => array(
  2195. 'default' => 'lc.log_time DESC',
  2196. 'reverse' => 'lc.log_time',
  2197. ),
  2198. ),
  2199. 'reason' => array(
  2200. 'header' => array(
  2201. 'value' => $txt['profile_warning_previous_reason'],
  2202. 'style' => 'width: 50%;',
  2203. ),
  2204. 'data' => array(
  2205. 'db' => 'reason',
  2206. ),
  2207. ),
  2208. 'level' => array(
  2209. 'header' => array(
  2210. 'value' => $txt['profile_warning_previous_level'],
  2211. ),
  2212. 'data' => array(
  2213. 'db' => 'counter',
  2214. ),
  2215. 'sort' => array(
  2216. 'default' => 'lc.counter DESC',
  2217. 'reverse' => 'lc.counter',
  2218. ),
  2219. ),
  2220. ),
  2221. 'additional_rows' => array(
  2222. array(
  2223. 'position' => 'after_title',
  2224. 'value' => $txt['profile_viewwarning_desc'],
  2225. 'class' => 'smalltext',
  2226. 'style' => 'padding: 2ex;',
  2227. ),
  2228. ),
  2229. );
  2230. // Create the list for viewing.
  2231. require_once($sourcedir . '/Subs-List.php');
  2232. createList($listOptions);
  2233. // Create some common text bits for the template.
  2234. $context['level_effects'] = array(
  2235. 0 => '',
  2236. $modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'],
  2237. $modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'],
  2238. $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
  2239. );
  2240. $context['current_level'] = 0;
  2241. foreach ($context['level_effects'] as $limit => $dummy)
  2242. if ($context['member']['warning'] >= $limit)
  2243. $context['current_level'] = $limit;
  2244. }
  2245. ?>