PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/sources/controllers/Members.controller.php

https://github.com/Arantor/Elkarte
PHP | 164 lines | 90 code | 30 blank | 44 comment | 12 complexity | a0998e4465b658bdc9703daceccf69b6 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * This software is a derived product, based on:
  8. *
  9. * Simple Machines Forum (SMF)
  10. * copyright: 2011 Simple Machines (http://www.simplemachines.org)
  11. * license: BSD, See included LICENSE.TXT for terms and conditions.
  12. *
  13. * @version 1.0 Alpha
  14. *
  15. * This file processes actions on members.
  16. *
  17. */
  18. if (!defined('ELKARTE'))
  19. die('No access...');
  20. /**
  21. * This simple function adds/removes the passed user from the current users buddy list.
  22. * Requires profile_identity_own permission.
  23. * Called by ?action=buddy;u=x;session_id=y.
  24. * Subactions: sa=add and sa=remove. (@todo refactor subactions)
  25. * Redirects to ?action=profile;u=x.
  26. */
  27. function action_buddy()
  28. {
  29. global $user_info;
  30. checkSession('get');
  31. isAllowedTo('profile_identity_own');
  32. is_not_guest();
  33. if (empty($_REQUEST['u']))
  34. fatal_lang_error('no_access', false);
  35. $_REQUEST['u'] = (int) $_REQUEST['u'];
  36. // Remove if it's already there...
  37. if (in_array($_REQUEST['u'], $user_info['buddies']))
  38. $user_info['buddies'] = array_diff($user_info['buddies'], array($_REQUEST['u']));
  39. // ...or add if it's not and if it's not you.
  40. elseif ($user_info['id'] != $_REQUEST['u'])
  41. $user_info['buddies'][] = (int) $_REQUEST['u'];
  42. // Update the settings.
  43. updateMemberData($user_info['id'], array('buddy_list' => implode(',', $user_info['buddies'])));
  44. // Redirect back to the profile
  45. redirectexit('action=profile;u=' . $_REQUEST['u']);
  46. }
  47. /**
  48. * Outputs each member name on its own line.
  49. * This function is used by javascript to find members matching the request.
  50. * Accessed by action=requestmembers.
  51. */
  52. function action_requestmembers()
  53. {
  54. global $user_info, $txt, $smcFunc;
  55. checkSession('get');
  56. $_REQUEST['search'] = $smcFunc['htmlspecialchars']($_REQUEST['search']) . '*';
  57. $_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
  58. $_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
  59. if (function_exists('iconv'))
  60. header('Content-Type: text/plain; charset=UTF-8');
  61. $request = $smcFunc['db_query']('', '
  62. SELECT real_name
  63. FROM {db_prefix}members
  64. WHERE real_name LIKE {string:search}' . (isset($_REQUEST['buddies']) ? '
  65. AND id_member IN ({array_int:buddy_list})' : '') . '
  66. AND is_activated IN (1, 11)
  67. LIMIT ' . ($smcFunc['strlen']($_REQUEST['search']) <= 2 ? '100' : '800'),
  68. array(
  69. 'buddy_list' => $user_info['buddies'],
  70. 'search' => $_REQUEST['search'],
  71. )
  72. );
  73. while ($row = $smcFunc['db_fetch_assoc']($request))
  74. {
  75. $row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
  76. if (preg_match('~&#\d+;~', $row['real_name']) != 0)
  77. $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
  78. echo $row['real_name'], "\n";
  79. }
  80. $smcFunc['db_free_result']($request);
  81. obExit(false);
  82. }
  83. /**
  84. * Called by index.php?action=findmember.
  85. * This function result is used as a popup for searching members.
  86. * @uses sub template find_members of the Help template.
  87. */
  88. function action_findmember()
  89. {
  90. global $context, $scripturl, $user_info, $smcFunc;
  91. checkSession('get');
  92. // Why is this in the Help template, you ask? Well, erm... it helps you. Does that work?
  93. loadTemplate('Help');
  94. $context['template_layers'] = array();
  95. $context['sub_template'] = 'find_members';
  96. if (isset($_REQUEST['search']))
  97. $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
  98. else
  99. $_REQUEST['start'] = 0;
  100. // Allow the user to pass the input to be added to to the box.
  101. $context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
  102. // Take the delimiter over GET in case it's \n or something.
  103. $context['delimiter'] = isset($_REQUEST['delim']) ? ($_REQUEST['delim'] == 'LB' ? "\n" : $_REQUEST['delim']) : ', ';
  104. $context['quote_results'] = !empty($_REQUEST['quote']);
  105. // List all the results.
  106. $context['results'] = array();
  107. // Some buddy related settings ;)
  108. $context['show_buddies'] = !empty($user_info['buddies']);
  109. $context['buddy_search'] = isset($_REQUEST['buddies']);
  110. // If the user has done a search, well - search.
  111. if (isset($_REQUEST['search']))
  112. {
  113. $_REQUEST['search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
  114. $context['results'] = findMembers(array($_REQUEST['search']), true, $context['buddy_search']);
  115. $total_results = count($context['results']);
  116. $context['page_index'] = constructPageIndex($scripturl . '?action=findmember;search=' . $context['last_search'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';input=' . $context['input_box_name'] . ($context['quote_results'] ? ';quote=1' : '') . ($context['buddy_search'] ? ';buddies' : ''), $_REQUEST['start'], $total_results, 7);
  117. // Determine the navigation context (especially useful for the wireless template).
  118. $base_url = $scripturl . '?action=findmember;search=' . urlencode($context['last_search']) . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']) . ';' . $context['session_var'] . '=' . $context['session_id'];
  119. $context['links'] = array(
  120. 'first' => $_REQUEST['start'] >= 7 ? $base_url . ';start=0' : '',
  121. 'prev' => $_REQUEST['start'] >= 7 ? $base_url . ';start=' . ($_REQUEST['start'] - 7) : '',
  122. 'next' => $_REQUEST['start'] + 7 < $total_results ? $base_url . ';start=' . ($_REQUEST['start'] + 7) : '',
  123. 'last' => $_REQUEST['start'] + 7 < $total_results ? $base_url . ';start=' . (floor(($total_results - 1) / 7) * 7) : '',
  124. 'up' => $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']),
  125. );
  126. $context['page_info'] = array(
  127. 'current_page' => $_REQUEST['start'] / 7 + 1,
  128. 'num_pages' => floor(($total_results - 1) / 7) + 1
  129. );
  130. $context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
  131. }
  132. else
  133. $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
  134. }