start.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. elgg_register_event_handler('init', 'system', 'members_extended_init');
  3. function members_extended_init() {
  4. elgg_register_plugin_hook_handler('register', 'menu:entity', 'members_extended_users_setup_entity_menu');
  5. elgg_register_page_handler('member-locations', "members_extended_location_pagehandler");
  6. }
  7. function members_extended_location_pagehandler($page) {
  8. require_once elgg_get_plugins_path() . 'members_extended/pages/members_extended/member-locations.php';
  9. return true;
  10. }
  11. function members_extended_users_setup_entity_menu($hook, $type, $return, $params) {
  12. if (elgg_in_context('widgets')) {
  13. return $return;
  14. }
  15. $entity = $params['entity'];
  16. if (!elgg_instanceof($entity, 'user')) {
  17. return $return;
  18. }
  19. $to_remove = array('banned','location');
  20. foreach ($return as $index => $item) {
  21. $name = $item->getName();
  22. if (in_array($name, $to_remove)) {
  23. unset($return[$index]);
  24. }
  25. }
  26. if ($entity->isBanned()) {
  27. $banned = elgg_echo('banned');
  28. $options = array(
  29. 'name' => 'banned',
  30. 'text' => "<span>$banned</span>",
  31. 'href' => false,
  32. 'priority' => 0,
  33. );
  34. $return = array(ElggMenuItem::factory($options));
  35. } else {
  36. $return = array();
  37. $url_params = array();
  38. $menu = array();
  39. if (isset($entity->location)) {
  40. $page_owner = elgg_get_page_owner_entity();
  41. if (elgg_instanceof($page_owner, 'group')) {
  42. $url_params['group_guid'] = $page_owner->guid;
  43. }
  44. $user_location = htmlspecialchars($entity->location, ENT_QUOTES, 'UTF-8', false);
  45. $locations = explode(",", $user_location);
  46. foreach($locations as $location){
  47. $q = strtolower(trim($location));
  48. $url_params['q'] = $q;
  49. $url = elgg_http_add_url_query_elements(elgg_get_site_url()."member-locations/", $url_params);
  50. $menu[] = elgg_view('output/url', array('href' => $url, 'text' => $location, 'is_safe' => true));
  51. }
  52. $menu = implode(", ",$menu);
  53. $options = array(
  54. 'name' => 'location',
  55. 'text' => "<span>$menu</span>",
  56. 'href' => false,
  57. 'priority' => 150,
  58. );
  59. $return[] = ElggMenuItem::factory($options);
  60. }
  61. }
  62. return $return;
  63. }
  64. function members_extended_search($options = array()){
  65. $db_prefix = elgg_get_config('dbprefix');
  66. $query = sanitise_string($options['query']);
  67. $options['joins'] = array(
  68. "JOIN {$db_prefix}users_entity ue ON e.guid = ue.guid",
  69. "JOIN {$db_prefix}metadata md on e.guid = md.entity_guid",
  70. "JOIN {$db_prefix}metastrings msv ON n_table.value_id = msv.id",
  71. );
  72. $r_where = "";
  73. $group_guid = $options['group_guid'];
  74. if($group_guid){
  75. $group = get_entity($group_guid);
  76. if (elgg_instanceof($group, 'group')) {
  77. elgg_set_page_owner_guid($group_guid);
  78. $options['joins'][] = "JOIN {$db_prefix}entity_relationships r ON e.guid = r.guid_one";
  79. $r_where = "AND (r.relationship = 'member' AND r.guid_two = '$group_guid')";
  80. }
  81. }
  82. // username and display name
  83. $fields = array('username', 'name');
  84. $where = search_get_where_sql('ue', $fields, $options, FALSE);
  85. // get the where clauses for the md names
  86. // can't use egef_metadata() because the n_table join comes too late.
  87. $clauses = _elgg_entities_get_metastrings_options('metadata', array(
  88. 'metadata_names' => $options['metadata_names'],
  89. ));
  90. $options['joins'] = array_merge($clauses['joins'], $options['joins']);
  91. // no fulltext index, can't disable fulltext search in this function.
  92. // $md_where .= " AND " . search_get_where_sql('msv', array('string'), $options, FALSE);
  93. $md_where = "(({$clauses['wheres'][0]}) AND msv.string LIKE '%$query%')";
  94. $options['wheres'] = array("(($where) OR ($md_where) $r_where)");
  95. // override subtype -- All users should be returned regardless of subtype.
  96. $options['subtype'] = ELGG_ENTITIES_ANY_VALUE;
  97. $options['count'] = true;
  98. $count = elgg_get_entities($options);
  99. // no need to continue if nothing here.
  100. if (!$count) {
  101. return array('entities' => array(), 'count' => $count);
  102. }
  103. $options['count'] = FALSE;
  104. $options['order_by'] = search_get_order_by_sql('e', 'ue', $options['sort'], $options['order']);
  105. $entities = elgg_get_entities($options);
  106. return array(
  107. 'entities' => $entities,
  108. 'count' => $count,
  109. );
  110. }