/** * Check if resharing of this entity is allowed * * @param \ElggEntity $entity the entity to check * * @return bool */ protected static function canReshareEntity(\ElggEntity $entity) { if (!$entity instanceof \ElggEntity) { return false; } // only allow objects and groups if (!$entity instanceof \ElggObject && !$entity instanceof \ElggGroup) { return false; } // comments and discussion replies are never allowed $blocked_subtypes = ['comment', 'discussion_reply']; if (in_array($entity->getSubtype(), $blocked_subtypes)) { return false; } // by default allow searchable entities $reshare_allowed = false; if ($entity instanceof \ElggGroup) { $reshare_allowed = true; } else { $searchable_entities = get_registered_entity_types($entity->getType()); if (!empty($searchable_entities)) { $reshare_allowed = in_array($entity->getSubtype(), $searchable_entities); } } // trigger hook to allow others to change $params = ['entity' => $entity, 'user' => elgg_get_logged_in_user_entity()]; return (bool) elgg_trigger_plugin_hook('reshare', $entity->getType(), $params, $reshare_allowed); }
/** * Performs a search of the elgg site * * @return array $results search result */ function site_search($query, $offset, $limit, $sort, $order, $search_type, $entity_type, $entity_subtype, $owner_guid, $container_guid) { $params = array('query' => $query, 'offset' => $offset, 'limit' => $limit, 'sort' => $sort, 'order' => $order, 'search_type' => $search_type, 'type' => $entity_type, 'subtype' => $entity_subtype, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid); $types = get_registered_entity_types(); foreach ($types as $type => $subtypes) { $results = elgg_trigger_plugin_hook('search', $type, $params, array()); if ($results === FALSE) { // someone is saying not to display these types in searches. continue; } if ($results['count']) { foreach ($results['entities'] as $single) { //search matched critera /* $result['search_matched_title'] = $single->getVolatileData('search_matched_title'); $result['search_matched_description'] = $single->getVolatileData('search_matched_description'); $result['search_matched_extra'] = $single->getVolatileData('search_matched_extra'); */ if ($type == 'group' || $type == 'user') { $result['title'] = $single->name; } else { $result['title'] = $single->title; } $result['guid'] = $single->guid; $result['type'] = $single->type; $result['subtype'] = get_subtype_from_id($single->subtype); $result['avatar_url'] = get_entity_icon_url($single, 'small'); $return[$type] = $result; } } } return $return; }
public function __construct() { $types = get_registered_entity_types(); $custom_types = elgg_trigger_plugin_hook('search_types', 'get_types', $params, array()); $types['object'] = array_merge($types['object'], $custom_types); $this->types = $types; }
/** * Get the type/subtypes for search in ElasticSearch * * @return false|array */ function elasticsearch_get_registered_entity_types_for_search() { $type_subtypes = get_registered_entity_types(); foreach ($type_subtypes as $type => $subtypes) { if (empty($subtypes)) { // repair so it can be used in elgg_get_entities* $type_subtypes[$type] = ELGG_ENTITIES_ANY_VALUE; } } return elgg_trigger_plugin_hook('search', 'type_subtype_pairs', $type_subtypes, $type_subtypes); }
<?php /** * Search form for internal content * * @uses $vars['container'] optional container */ $container = elgg_extract('container', $vars, elgg_get_logged_in_user_entity()); $content_options = []; $content_types = get_registered_entity_types(); if (!empty($content_types)) { $content_options = [ELGG_ENTITIES_ANY_VALUE => elgg_echo('all')]; foreach ($content_types as $type => $subtypes) { if (!empty($subtypes)) { foreach ($subtypes as $subtype) { $content_options["{$type}:{$subtype}"] = elgg_echo("item:{$type}:{$subtype}"); } } else { $content_options[$type] = elgg_echo("item:{$type}"); } } natcasesort($content_options); } $search = elgg_view('input/text', ['name' => 'q', 'placeholder' => elgg_echo('embed_extended:internal_content:placeholder')]); if (!empty($content_options)) { $search .= elgg_view('input/select', ['name' => 'type_subtype', 'options_values' => $content_options]); } $search .= elgg_view('input/submit', ['value' => elgg_echo('search')]); $result = elgg_format_element('div', [], $search); if (elgg_is_logged_in()) { $match_owner = elgg_view('input/checkbox', ['name' => 'match_owner', 'value' => 1, 'label' => elgg_echo('embed_extended:internal_content:match_owner')]);
/** * Returns a viewable list of entities based on the registered types. * * @see elgg_view_entity_list * * @param array $options Any elgg_get_entity() options plus: * * full_view => BOOL Display full view entities * * list_type_toggle => BOOL Display gallery / list switch * * allowed_types => true|ARRAY True to show all types or an array of valid types. * * pagination => BOOL Display pagination links * * @return string A viewable list of entities * @since 1.7.0 */ function elgg_list_registered_entities(array $options = array()) { elgg_register_rss_link(); $defaults = array('full_view' => false, 'allowed_types' => true, 'list_type_toggle' => false, 'pagination' => true, 'offset' => 0, 'types' => array(), 'type_subtype_pairs' => array()); $options = array_merge($defaults, $options); $types = get_registered_entity_types(); foreach ($types as $type => $subtype_array) { if (in_array($type, $options['allowed_types']) || $options['allowed_types'] === true) { // you must explicitly register types to show up in here and in search for objects if ($type == 'object') { if (is_array($subtype_array) && count($subtype_array)) { $options['type_subtype_pairs'][$type] = $subtype_array; } } else { if (is_array($subtype_array) && count($subtype_array)) { $options['type_subtype_pairs'][$type] = $subtype_array; } else { $options['type_subtype_pairs'][$type] = ELGG_ENTITIES_ANY_VALUE; } } } } if (!empty($options['type_subtype_pairs'])) { $count = elgg_get_entities(array_merge(array('count' => true), $options)); if ($count > 0) { $entities = elgg_get_entities($options); } else { $entities = array(); } } else { $count = 0; $entities = array(); } $options['count'] = $count; return elgg_view_entity_list($entities, $options); }
/** * Returns a number of indexable documents * @return int */ function elgg_solr_get_indexable_count() { $registered_types = get_registered_entity_types(); $solr_entities = elgg_get_config('solr_entities'); if (is_array($solr_entities)) { foreach ($solr_entities as $type => $subtypes) { foreach ($subtypes as $subtype => $callback) { if ($subtype == 'default') { continue; } $registered_types[$type][] = $subtype; } } } $ia = elgg_set_ignore_access(true); $count = 0; foreach ($registered_types as $type => $subtypes) { $options = array('type' => $type, 'count' => true); if ($subtypes) { $options['subtypes'] = $subtypes; } $count += elgg_get_entities($options); } elgg_set_ignore_access($ia); return $count; }
/** * Returns a viewable list of entities based on the registered types. * * @see elgg_view_entity_list * * @param array $options Any elgg_get_entity() options plus: * * full_view => BOOL Display full view entities * * list_type_toggle => BOOL Display gallery / list switch * * allowed_types => TRUE|ARRAY True to show all types or an array of valid types. * * pagination => BOOL Display pagination links * * @return string A viewable list of entities * @since 1.7.0 */ function elgg_list_registered_entities(array $options = array()) { global $autofeed; $autofeed = true; $defaults = array('full_view' => TRUE, 'allowed_types' => TRUE, 'list_type_toggle' => FALSE, 'pagination' => TRUE, 'offset' => 0, 'types' => array(), 'type_subtype_pairs' => array()); $options = array_merge($defaults, $options); //backwards compatibility if (isset($options['view_type_toggle'])) { $options['list_type_toggle'] = $options['view_type_toggle']; } $types = get_registered_entity_types(); foreach ($types as $type => $subtype_array) { if (in_array($type, $options['allowed_types']) || $options['allowed_types'] === TRUE) { // you must explicitly register types to show up in here and in search for objects if ($type == 'object') { if (is_array($subtype_array) && count($subtype_array)) { $options['type_subtype_pairs'][$type] = $subtype_array; } } else { if (is_array($subtype_array) && count($subtype_array)) { $options['type_subtype_pairs'][$type] = $subtype_array; } else { $options['type_subtype_pairs'][$type] = ELGG_ENTITIES_ANY_VALUE; } } } } $count = elgg_get_entities(array_merge(array('count' => TRUE), $options)); $entities = elgg_get_entities($options); return elgg_view_entity_list($entities, $count, $options['offset'], $options['limit'], $options['full_view'], $options['list_type_toggle'], $options['pagination']); }
} else { $owner_guid_array = $owner_guid; } $friends = (int) get_input('friends', 0); if ($friends > 0) { if ($friends = get_user_friends($friends, '', 9999)) { $owner_guid_array = array(); foreach ($friends as $friend) { $owner_guid_array[] = $friend->guid; } } else { $owner_guid = -1; } } // Set up submenus if ($object_types = get_registered_entity_types()) { foreach ($object_types as $object_type => $subtype_array) { if (is_array($subtype_array) && sizeof($subtype_array)) { foreach ($subtype_array as $object_subtype) { $label = 'item:' . $object_type; if (!empty($object_subtype)) { $label .= ':' . $object_subtype; } global $CONFIG; add_submenu_item(elgg_echo($label), $CONFIG->wwwroot . "search/?tag=" . urlencode($tag) . "&subtype=" . $object_subtype . "&object=" . urlencode($object_type) . "&tagtype=" . urlencode($md_type) . "&owner_guid=" . urlencode($owner_guid)); } } } add_submenu_item(elgg_echo('all'), $CONFIG->wwwroot . "search/?tag=" . urlencode($tag) . "&owner_guid=" . urlencode($owner_guid)); } if (empty($objecttype) && empty($subtype)) {
<?php $subtypes = get_registered_entity_types('group'); if (empty($subtypes)) { return; } $subtype_options = array('' => ''); foreach ($subtypes as $subtype) { $subtype_options[$subtype] = elgg_echo("group:{$subtype}"); } $dbprefix = elgg_get_config('dbprefix'); $options = array('selects' => array('ge.name AS name'), 'types' => 'group', 'limit' => 100, 'joins' => array("JOIN {$dbprefix}groups_entity ge ON ge.guid = e.guid"), 'wheres' => array("e.subtype = 0"), 'order_by' => 'ge.name ASC', 'callback' => false, 'count' => true); $count = elgg_get_entities($options); if (!$count) { return; } $options['count'] = false; $groups = new ElggBatch('elgg_get_entities', $options); $table = '<table class="elgg-table-alt">'; foreach ($groups as $group) { $table .= '<tr>'; $table .= '<td>' . $group->name . '</td>'; $table .= '<td>' . elgg_view('input/select', array('name' => "groups[{$group->guid}]", 'options_values' => $subtype_options)) . '</td>'; $table .= '</tr>'; } $table .= '</table>'; echo elgg_view_module('info', elgg_echo('admin:groups:subtypes:change_subtype'), $table, array('class' => 'groups-subtypes-config-module')); echo elgg_view('input/submit');
function elasticsearch_get_subtypes() { $types = get_registered_entity_types(); $types['object'] = array_merge($types['object'], elgg_trigger_plugin_hook('search_types', 'get_types', $params, array())); return $types; }
/** * Returns a list of subtype options * @return array */ public function getSubtypeOptions() { $types = get_registered_entity_types(); $types = elgg_trigger_plugin_hook('search_types', 'get_queries', [], $types); return elgg_extract($this->getEntityType(), $types); }
/** * Returns a viewable list of entities based on the registered types * * @see elgg_view_entity_list * * @param string $type The type of entity (eg "user", "object" etc) * @param string $subtype The arbitrary subtype of the entity * @param int $owner_guid The GUID of the owning user * @param int $limit The number of entities to display per page (default: 10) * @param true|false $fullview Whether or not to display the full view (default: true) * @param true|false $viewtypetoggle Whether or not to allow gallery view * @return string A viewable list of entities */ function list_registered_entities($owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $allowedtypes = true) { $typearray = array(); if ($object_types = get_registered_entity_types()) { foreach ($object_types as $object_type => $subtype_array) { if (is_array($subtype_array) && sizeof($subtype_array) && (in_array($object_type, $allowedtypes) || $allowedtypes === true)) { foreach ($subtype_array as $object_subtype) { $typearray[$object_type][] = $object_subtype; } } } } $offset = (int) get_input('offset'); $count = get_entities('', $typearray, $owner_guid, "", $limit, $offset, true); $entities = get_entities('', $typearray, $owner_guid, "", $limit, $offset); return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle); }
function index_search() { $entityTypes = array(); if ($_GET['check']) { foreach ($_GET['check'] as $entityType) { $entityTypes[] = $entityType; } } // $search_type == all || entities || trigger plugin hook $search_type = get_input('search_type', 'all'); // @todo there is a bug in get_input that makes variables have slashes sometimes. // @todo is there an example query to demonstrate ^ // XSS protection is more important that searching for HTML. $query = stripslashes(get_input('index-query', get_input('tag', ''))); if (function_exists('mb_convert_encoding')) { $display_query = mb_convert_encoding($query, 'HTML-ENTITIES', 'UTF-8'); } else { // if no mbstring extension, we just strip characters $display_query = preg_replace("/[^-]/", "", $query); } $display_query = htmlspecialchars($display_query, ENT_QUOTES, 'UTF-8', false); // check that we have an actual query if (!$query) { $title = sprintf(elgg_echo('search:results'), "\"{$display_query}\""); $body = elgg_view_title(elgg_echo('search:search_error')); $body .= elgg_echo('search:no_query'); $layout = elgg_view_layout('one_sidebar', array('content' => $body)); echo elgg_view_page($title, $layout); return; } // get limit and offset. override if on search dashboard, where only 2 // of each most recent entity types will be shown. $limit = $search_type == 'all' ? 2 : get_input('limit', 10); $offset = $search_type == 'all' ? 0 : get_input('offset', 0); $order = get_input('order', 'desc'); if ($order != 'asc' && $order != 'desc') { $order = 'desc'; } // set up search params $params = array('query' => $query, 'offset' => $offset, 'limit' => $limit, 'sort' => $sort, 'order' => $order, 'search_type' => $search_type, 'type' => $entity_type, 'subtype' => $entity_subtype, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'pagination' => $search_type == 'all' ? FALSE : TRUE); $types = get_registered_entity_types(); //$types['object'] foreach ($types as $type => $subtypes) { //only include subtypes the user wishes to search for foreach ($subtypes as $key => $subtype) { $flag = false; error_log($type . $key . $subtype); foreach ($entityTypes as $entityType) { if ($subtype == $entityType) { $flag = true; } } if ($flag !== true) { //var_dump($types[$type][$key]); unset($types[$type][$key]); //$types = array_values($types); } } //only include types user wishes to search for - this is only for groups and users as they are not sub types $flag = false; if ($type != 'object') { foreach ($entityTypes as $entityType) { if ($type == $entityType) { $flag = true; } } if ($flag !== true) { unset($types[$type]); } } } // add sidebar items for all and native types // @todo should these maintain any existing type / subtype filters or reset? $data = htmlspecialchars(http_build_query(array('q' => $query, 'entity_subtype' => $entity_subtype, 'entity_type' => $entity_type, 'owner_guid' => $owner_guid, 'search_type' => 'all'))); $url = elgg_get_site_url() . "search?{$data}"; $menu_item = new ElggMenuItem('all', elgg_echo('all'), $url); elgg_register_menu_item('page', $menu_item); foreach ($types as $type => $subtypes) { // @todo when using index table, can include result counts on each of these. if (is_array($subtypes) && count($subtypes)) { foreach ($subtypes as $subtype) { $label = "item:{$type}:{$subtype}"; $data = htmlspecialchars(http_build_query(array('q' => $query, 'entity_subtype' => $subtype, 'entity_type' => $type, 'owner_guid' => $owner_guid, 'search_type' => 'entities', 'friends' => $friends))); $url = elgg_get_site_url() . "search?{$data}"; $menu_item = new ElggMenuItem($label, elgg_echo($label), $url); elgg_register_menu_item('page', $menu_item); } } else { $label = "item:{$type}"; $data = htmlspecialchars(http_build_query(array('q' => $query, 'entity_type' => $type, 'owner_guid' => $owner_guid, 'search_type' => 'entities', 'friends' => $friends))); $url = elgg_get_site_url() . "search?{$data}"; $menu_item = new ElggMenuItem($label, elgg_echo($label), $url); elgg_register_menu_item('page', $menu_item); } } // start the actual search $results_html = ''; if ($search_type == 'all' || $search_type == 'entities') { // to pass the correct current search type to the views $current_params = $params; $current_params['search_type'] = 'entities'; // foreach through types. // if a plugin returns FALSE for subtype ignore it. // if a plugin returns NULL or '' for subtype, pass to generic type search function. // if still NULL or '' or empty(array()) no results found. (== don't show??) foreach ($types as $type => $subtypes) { if ($search_type != 'all' && $entity_type != $type) { continue; } if (is_array($subtypes) && count($subtypes)) { foreach ($subtypes as $subtype) { // no need to search if we're not interested in these results // @todo when using index table, allow search to get full count. if ($search_type != 'all' && $entity_subtype != $subtype) { continue; } $current_params['subtype'] = $subtype; $current_params['type'] = $type; $results = elgg_trigger_plugin_hook('search', "{$type}:{$subtype}", $current_params, NULL); if ($results === FALSE) { // someone is saying not to display these types in searches. continue; } elseif (is_array($results) && !count($results)) { // no results, but results searched in hook. } elseif (!$results) { // no results and not hooked. use default type search. // don't change the params here, since it's really a different subtype. // Will be passed to elgg_get_entities(). $results = elgg_trigger_plugin_hook('search', $type, $current_params, array()); } if (is_array($results['entities']) && $results['count']) { if ($view = search_get_search_view($current_params, 'list')) { $results_html .= elgg_view($view, array('results' => $results, 'params' => $current_params)); } } } } // pull in default type entities with no subtypes $current_params['type'] = $type; $current_params['subtype'] = ELGG_ENTITIES_NO_VALUE; $results = elgg_trigger_plugin_hook('search', $type, $current_params, array()); if ($results === FALSE) { // someone is saying not to display these types in searches. continue; } if (is_array($results['entities']) && $results['count']) { if ($view = search_get_search_view($current_params, 'list')) { $results_html .= elgg_view($view, array('results' => $results, 'params' => $current_params)); } } } } // highlight search terms if ($search_type == 'tags') { $searched_words = array($display_query); } else { $searched_words = search_remove_ignored_words($display_query, 'array'); } $highlighted_query = search_highlight_words($searched_words, $display_query); $body = elgg_view_title(elgg_echo('search:results', array("\"{$highlighted_query}\""))); if (!$results_html) { $body .= elgg_view('search/no_results'); } else { $body .= $results_html; } // this is passed the original params because we don't care what actually // matched (which is out of date now anyway). // we want to know what search type it is. $layout_view = search_get_search_view($params, 'layout'); $layout = elgg_view($layout_view, array('params' => $params, 'body' => $body)); $title = elgg_echo('search:results', array("\"{$display_query}\"")); echo elgg_view_page($title, $layout); }
/** * a static list of entity subtypes for views * @return string */ function get_entity_views() { $types = get_registered_entity_types('object'); sort($types); return $types; }
/** * Prepare entity SEF data * * @param \ElggEntity $entity Entity * @return array|false */ function seo_prepare_entity_data(\ElggEntity $entity) { $path = seo_get_path($entity->getURL()); if (!$path || $path == '/') { return false; } $type = $entity->getType(); switch ($type) { case 'user': if (elgg_is_active_plugin('profile')) { $sef_path = "/profile/{$entity->username}"; } break; case 'group': $subtype = $entity->getSubtype(); $registered = (array) get_registered_entity_types('group'); if (!$subtype || in_array($subtype, $registered)) { if ($subtype && elgg_language_key_exists("item:group:{$subtype}", 'en')) { $prefix = elgg_get_friendly_title(elgg_echo("item:group:{$subtype}", array(), 'en')); } else { $prefix = elgg_get_friendly_title(elgg_echo('item:group', array(), 'en')); } $friendly_title = elgg_get_friendly_title($entity->getDisplayName() ?: ''); $sef_path = "/{$prefix}/{$entity->guid}-{$friendly_title}"; } break; case 'object': $subtype = $entity->getSubtype(); $registered = (array) get_registered_entity_types('object'); if (in_array($subtype, $registered)) { if (elgg_language_key_exists("item:object:{$subtype}", 'en')) { $prefix = elgg_get_friendly_title(elgg_echo("item:object:{$subtype}", array(), 'en')); } else { $prefix = elgg_get_friendly_title($subtype); } $friendly_title = elgg_get_friendly_title($entity->getDisplayName() ?: ''); $sef_path = "/{$prefix}/{$entity->guid}-{$friendly_title}"; } break; } if (!$sef_path) { $sef_path = $path; } $sef_data = seo_get_data($entity->getURL()); if (!is_array($sef_data)) { $sef_data = array(); } $entity_sef_data = ['path' => $path, 'sef_path' => $sef_path, 'title' => $entity->getDisplayName(), 'description' => elgg_get_excerpt($entity->description), 'keywords' => is_array($entity->tags) ? implode(',', $entity->tags) : $entity->tags, 'guid' => $entity->guid]; if ($entity->guid != $entity->owner_guid) { $owner = $entity->getOwnerEntity(); if ($owner) { $entity_sef_data['owner'] = seo_prepare_entity_data($owner); } } if ($entity->guid != $entity->container_guid && $entity->owner_guid != $entity->container_guid) { $container = $entity->getContainerEntity(); if ($container) { $entity_sef_data['container'] = seo_prepare_entity_data($container); } } if (empty($sef_data['admin_defined'])) { $sef_data = array_merge($sef_data, $entity_sef_data); } else { foreach ($entity_sef_data as $key => $value) { if (empty($sef_data[$key])) { $sef_data[$key] = $value; } } } $entity_sef_metatags = elgg_trigger_plugin_hook('metatags', 'discovery', ['entity' => $entity, 'url' => elgg_normalize_url($sef_path)], []); if (!empty($entity_sef_metatags)) { foreach ($entity_sef_metatags as $key => $value) { if (empty($sef_data['admin_defined']) || empty($sef_data['metatags'][$key])) { $sef_data['metatags'][$key] = $value; } } } return $sef_data; }
} $container_guid = ELGG_ENTITIES_ANY_VALUE; if (!empty($match_container)) { $container_guid = $match_container; } $type = ELGG_ENTITIES_ANY_VALUE; $subtype = ELGG_ENTITIES_ANY_VALUE; if (!empty($type_subtype)) { list($type, $subtype) = explode(':', $type_subtype); } $entities = []; $dbprefix = elgg_get_config('dbprefix'); // search objects if ($type == ELGG_ENTITIES_ANY_VALUE || $type == 'object') { if ($subtype == ELGG_ENTITIES_ANY_VALUE) { $subtypes = get_registered_entity_types('object'); } else { $subtypes = [$subtype]; } $objects = elgg_get_entities(['type' => 'object', 'subtypes' => $subtypes, 'limit' => 10, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'joins' => ["JOIN {$dbprefix}objects_entity oe ON e.guid = oe.guid"], "wheres" => ["(oe.title LIKE '%{$q}%')"]]); if (!empty($objects)) { $entities = $objects; } } // search groups if (($type == ELGG_ENTITIES_ANY_VALUE || $type == 'group') && $container_guid == ELGG_ENTITIES_ANY_VALUE) { $groups = elgg_get_entities(['type' => 'group', 'limit' => 10, 'owner_guid' => $owner_guid, 'joins' => ["JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"], 'wheres' => ["(ge.name LIKE '%{$q}%')"]]); if (!empty($groups)) { $entities = array_merge($entities, $groups); } }
/** * Rendering an ECML embed * * @param string $hook Equals 'render:embed' * @param string $type Equals 'ecml; * @param string $content ECML string that needs to be converted * @param array $params ECML tokenizaton results * @uses string $params['keyword'] ECML keyword, i.e. embed in [embed guid="XXX"] * @uses array $params['attributes'] ECML attributes, i.e. array('guid' => XXX) in [embed guid="XXX"] * * @return string Rendered ECML replacement */ function render_embed($hook, $type, $content, $params) { if ($hook != 'render:embed' || $params['keyword'] != 'embed') { return $content; } $attributes = elgg_extract('attributes', $params); // Return empty strings for embeds within embeds if (elgg_in_context('embed')) { return ''; } elgg_push_context('embed'); if (isset($attributes['context'])) { $contexts = string_to_tag_array($attributes['context']); foreach ($contexts as $context) { elgg_push_context($context); } } if (isset($attributes['guid'])) { $guid = $attributes['guid']; unset($attributes['guid']); $entity = get_entity($guid); $attributes['entity'] = $entity; if (elgg_instanceof($entity)) { $type = $entity->getType(); $subtype = $entity->getSubtype(); if (elgg_view_exists("embed/ecml/{$type}/{$subtype}")) { $ecml = elgg_view("embed/ecml/{$type}/{$subtype}", $attributes); } else { if ($type == 'object' && in_array($subtype, get_registered_entity_types('object'))) { if (elgg_view_exists("embed/ecml/object")) { $ecml = elgg_view("embed/ecml/object", $attributes); } else { $ecml = elgg_view("embed/ecml/default", $attributes); } } } } if (empty($ecml)) { $content = elgg_view('embed/ecml/error'); } else { $content = $ecml; } } elseif (isset($attributes['src'])) { $content = elgg_view("embed/ecml/url", $attributes); } elgg_pop_context(); if (!empty($contexts)) { foreach ($contexts as $context) { elgg_pop_context(); } } return $content; }
<?php elgg_require_js('csv_exporter/admin'); // add tab menu echo elgg_view_menu('csv_exporter', ['class' => 'elgg-menu-hz elgg-tabs', 'sort_by' => 'priority']); // prepare type/subtype selector $type_subtypes = get_registered_entity_types(); $type_subtype_options = []; foreach ($type_subtypes as $type => $subtypes) { if (!empty($subtypes)) { foreach ($subtypes as $subtype) { $type_subtype_options["{$type}:{$subtype}"] = elgg_echo("item:{$type}:{$subtype}"); } } else { $type_subtype_options[$type] = elgg_echo("item:{$type}"); } } natcasesort($type_subtype_options); $type_subtype_options = array_merge(array_reverse($type_subtype_options), ['' => elgg_echo('csv_exporter:admin:type_subtype:choose')]); $type_subtype_options = array_reverse($type_subtype_options); $form_body = ''; $preview = ''; // type/subtype selector $type_subtype = elgg_get_sticky_value('csv_exporter', 'type_subtype', get_input('type_subtype')); $form_body .= '<div>'; $form_body .= elgg_format_element('label', ['for' => 'csv-exporter-type-subtype'], elgg_echo('csv_exporter:admin:type_subtype')); $form_body .= elgg_view('input/select', ['name' => 'type_subtype', 'value' => $type_subtype, 'options_values' => $type_subtype_options, 'id' => 'csv-exporter-type-subtype', 'class' => 'mls']); $form_body .= '</div>'; // additional fields if (!empty($type_subtype)) { // time options
/** * Returns a viewable list of entities based on the registered types. * * @see elgg_view_entity_list * * @param array $options Any elgg_get_entity() options plus: * * full_view => BOOL Display full view entities * * view_type_toggle => BOOL Display gallery / list switch * * allowed_types => TRUE|ARRAY True to show all types or an array of valid types. * * pagination => BOOL Display pagination links * * @return string A viewable list of entities */ function elgg_list_registered_entities($options) { $defaults = array('full_view' => TRUE, 'allowed_types' => TRUE, 'view_type_toggle' => FALSE, 'pagination' => TRUE, 'offset' => 0); $options = array_merge($defaults, $options); $typearray = array(); if ($object_types = get_registered_entity_types()) { foreach ($object_types as $object_type => $subtype_array) { if (in_array($object_type, $options['allowed_types']) || $options['allowed_types'] === TRUE) { $typearray[$object_type] = array(); if (is_array($subtype_array) && count($subtype_array)) { foreach ($subtype_array as $subtype) { $typearray[$object_type][] = $subtype; } } } } } $options['type_subtype_pairs'] = $typearray; $count = elgg_get_entities(array_merge(array('count' => TRUE), $options)); $entities = elgg_get_entities($options); return elgg_view_entity_list($entities, $count, $options['offset'], $options['limit'], $options['full_view'], $options['view_type_toggle'], $options['pagination']); }
function aga_handle_stats_page($group) { //only show if enabled or is admin if (!(($group->canEdit() || $group->aga_stats_enable == 'yes') && (elgg_get_plugin_setting('aga_stats', 'au_group_activity') != 'no' || elgg_is_admin_logged_in()))) { forward(REFERER); } $title = elgg_echo('aga:groupstats', array($group->name)); elgg_push_breadcrumb($group->name, $group->getURL()); elgg_push_breadcrumb(elgg_echo('aga:groupstats')); $content = ""; // Get entity statistics //first get array of possible objects $guid = $group->guid; $types = get_registered_entity_types('object'); $content .= elgg_view_module('info', elgg_echo('aga:note'), elgg_echo('aga:statscaution')); // generate a table of stats $even_odd = ""; $statscontent = "<table class=\"elgg-table-alt\">"; //member count $statscontent .= "<tr class=\"odd\"><td>" . elgg_echo('aga:nummembers') . "</td><td>" . aga_get_member_count($group) . "</td></tr>"; //post count $statscontent .= "<tr class=\"even\"><td>" . elgg_echo('aga:numposts') . "</td><td>" . aga_get_post_count($group) . "</td></tr>"; //count comments and discussion replies $statscontent .= "<tr><td>" . elgg_echo('aga:generic_comment') . "</td><td>" . aga_get_annotation_count($group, 'generic_comment') . "</td></tr>"; $statscontent .= "<tr><td>" . elgg_echo('aga:group_topic_post') . "</td><td>" . aga_get_annotation_count($group, 'group_topic_post') . "</td></tr>"; //get first and most recent posts $statscontent .= "<tr class=\"odd\"><td>" . elgg_echo('aga:first_post') . "</td><td>" . aga_get_firstlast_post($group, 'first') . "</td></tr>"; $statscontent .= "<tr class=\"even\"><td>" . elgg_echo('aga:last_post') . "</td><td>" . aga_get_firstlast_post($group, 'last') . "</td></tr>"; // show per-object stats $statscontent .= "<tr><td><h4>" . elgg_echo('aga:perobjecttype') . "</h4></td><td>" . elgg_echo('aga:perobjecttypehelp') . "</td></tr>"; foreach ($types as $k => $object) { //This function controls the alternating class $even_odd = 'odd' != $even_odd ? 'odd' : 'even'; $count = aga_get_post_count($group, $object); $objectNice = elgg_echo("item:object:{$object}"); $statscontent .= "<tr class=\"{$even_odd}\">\n\t\t\t\t\t<td>{$objectNice}</td>\n\t\t\t\t\t<td><a href=\"{$handler}ingroup?type=object&subtype={$object}\">{$count}</a></td>\n\t\t\t\t</tr> "; } /* trying to get things set with group acl but can't make it work yet $inacl=aga_get_acl_count($group,'in'); $outacl=aga_get_acl_count($group,'out'); $content.="<tr><td>".elgg_echo('aga:accesscount:in')."</td><td>".$inacl."</td></tr>"; $content.="<tr><td>".elgg_echo('aga:accesscount:out')."</td><td>".$outacl."</td></tr>"; */ //end table $statscontent .= "</table>"; $content .= elgg_view_module('aside', elgg_echo('aga:generalstats'), $statscontent); //show tags $content .= elgg_view_module('aside', elgg_echo('aga:populartags'), elgg_view_tagcloud(array('container_guid' => $guid, 'limit' => 500))); $params = array('filter_context' => 'aga', 'content' => $content, 'title' => $title); $body = elgg_view_layout('content', $params); echo elgg_view_page($title, $body); }
/** * Returns an array of group subtypes that can be added to the parent * * @param ElggEntity $parent Parent entity * @return array */ function group_subtypes_get_allowed_subtypes_for_parent($parent = null) { $allowed_subtypes = array(); $subtypes = get_registered_entity_types('group'); foreach ($subtypes as $subtype) { $params = array('parent' => $parent, 'type' => 'group', 'subtype' => $subtype); $can_parent = elgg_trigger_plugin_hook('permissions_check:parent', 'group', $params, true); if ($can_parent) { $allowed_subtypes[] = $subtype; } } return $allowed_subtypes; }
function advanced_statistics_get_content_data($chart_id) { $result = array("data" => array(), "options" => array()); $dbprefix = elgg_get_config("dbprefix"); $current_site_guid = elgg_get_site_entity()->getGUID(); switch ($chart_id) { case "totals": $data = array(); $subtype_ids = array(); $subtypes = get_registered_entity_types("object"); foreach ($subtypes as $subtype) { if ($subtype_id = get_subtype_id("object", $subtype)) { $subtype_ids[] = $subtype_id; } } $query = "SELECT e.subtype as subtype, count(*) as total"; $query .= " FROM " . $dbprefix . "entities e"; $query .= " WHERE e.type = 'object'"; $query .= " AND e.subtype IN (" . implode(",", $subtype_ids) . ")"; $query .= " AND e.site_guid = " . $current_site_guid; $query .= " GROUP BY e.subtype"; $query .= " ORDER BY total DESC"; if ($query_result = get_data($query)) { foreach ($query_result as $row) { $subtype = get_subtype_from_id($row->subtype); $subtype = elgg_echo("item:object:" . $subtype); $total = (int) $row->total; $data[] = array($subtype, $total); } } $result["data"] = array($data); $result["options"] = advanced_statistics_get_default_chart_options("bar"); $result["options"]["seriesDefaults"]["rendererOptions"] = array("varyBarColor" => true); $result["options"]["highlighter"] = array("show" => true, "sizeAdjust" => 7.5, "tooltipAxes" => "y"); $result["options"]["axes"]["xaxis"]["tickRenderer"] = "\$.jqplot.CanvasAxisTickRenderer"; $result["options"]["axes"]["xaxis"]["tickOptions"] = array("angle" => "-30", "fontSize" => "8pt"); break; case "distribution": $data = array(); $subtype_ids = array(); $subtypes = get_registered_entity_types("object"); foreach ($subtypes as $subtype) { if ($subtype_id = get_subtype_id("object", $subtype)) { $subtype_ids[] = $subtype_id; } } $query = "SELECT e2.type as type, count(*) as total"; $query .= " FROM " . $dbprefix . "entities e"; $query .= " JOIN " . $dbprefix . "entities e2 ON e.container_guid = e2.guid"; $query .= " WHERE e.type = 'object'"; $query .= " AND e.subtype IN (" . implode(",", $subtype_ids) . ")"; $query .= " AND e.site_guid = " . $current_site_guid; $query .= " GROUP BY e2.type"; $query .= " ORDER BY total DESC"; if ($query_result = get_data($query)) { foreach ($query_result as $row) { $total = (int) $row->total; $data[] = array($row->type, $total); } } $result["data"] = array($data); $result["options"] = advanced_statistics_get_default_chart_options("pie"); break; default: $params = array("chart_id" => $chart_id, "default_result" => $result); $result = elgg_trigger_plugin_hook("content", "advanced_statistics", $params, $result); break; } return json_encode($result); }
/** * Wall post export * * @param string $hook "to:object" * @param string $type "entity" * @param stdClass $return Export object * @param array $params Hook params * @return stdClass */ public function exportWall($hook, $type, $return, $params) { if (!elgg_in_context('graph')) { return $return; } $entity = elgg_extract('entity', $params); /* @var $entity \hypeJunction\Wall\Post */ if (!$entity instanceof ElggObject || $entity->getSubtype() !== \hypeJunction\Wall\Post::SUBTYPE) { return $return; } $allowed = $this->getFields($entity); $fields = get_input('fields') ?: $allowed; if (is_string($fields)) { $fields = string_to_tag_array($fields); } foreach ($fields as $key) { switch ($key) { case 'attachments': $return->attachments = array(); $attachments = new \ElggBatch('elgg_get_entities_from_relationship', array('types' => 'object', 'subtypes' => get_registered_entity_types('object'), 'relationship' => 'attached', 'relationship_guid' => $entity->guid, 'inverse_relationship' => true, 'limit' => 0)); foreach ($attachments as $attachment) { $return->attachments[] = $attachment->toObject(); } break; case 'location': $return->location = $entity->getLocation(); break; case 'address': $return->address = $entity->address; if (elgg_is_active_plugin('hypeScraper')) { $return->embed = hypeScraper()->resources->get($entity->address); } break; case 'tagged_users': $this->tagged_users = array(); $users = (array) $entity->getTaggedFriends(); foreach ($users as $user) { if ($user instanceof \ElggUser) { $this->tagged_users[] = $user->toObject(); } } break; } } return $return; }
/** * Returns a viewable list of entities based on the registered types. * * @see elgg_view_entity_list * * @param array $options Any elgg_get_entity() options plus: * * full_view => BOOL Display full view entities * * list_type_toggle => BOOL Display gallery / list switch * * allowed_types => true|ARRAY True to show all types or an array of valid types. * * pagination => BOOL Display pagination links * * @return string A viewable list of entities * @since 1.7.0 */ function elgg_list_registered_entities(array $options = array()) { global $autofeed; $autofeed = true; $defaults = array('full_view' => false, 'allowed_types' => true, 'list_type_toggle' => false, 'pagination' => true, 'offset' => 0, 'types' => array(), 'type_subtype_pairs' => array()); $options = array_merge($defaults, $options); // backward compatibility if (isset($options['view_type_toggle'])) { elgg_deprecated_notice("Option 'view_type_toggle' deprecated by 'list_type_toggle' in elgg_list* functions", 1.9); $options['list_type_toggle'] = $options['view_type_toggle']; } $types = get_registered_entity_types(); foreach ($types as $type => $subtype_array) { if (in_array($type, $options['allowed_types']) || $options['allowed_types'] === true) { // you must explicitly register types to show up in here and in search for objects if ($type == 'object') { if (is_array($subtype_array) && count($subtype_array)) { $options['type_subtype_pairs'][$type] = $subtype_array; } } else { if (is_array($subtype_array) && count($subtype_array)) { $options['type_subtype_pairs'][$type] = $subtype_array; } else { $options['type_subtype_pairs'][$type] = ELGG_ENTITIES_ANY_VALUE; } } } } if (!empty($options['type_subtype_pairs'])) { $count = elgg_get_entities(array_merge(array('count' => true), $options)); if ($count > 0) { $entities = elgg_get_entities($options); } else { $entities = array(); } } else { $count = 0; $entities = array(); } $options['count'] = $count; return elgg_view_entity_list($entities, $options); }
/** * Get the list of supported type/subtypes for quicklinks * * @return array */ function quicklinks_get_supported_types() { // default to registered entity types $supported_types = get_registered_entity_types(); // blacklist some type/subtypes $blacklist = ['object' => ['discussion_reply', 'comment', 'thewire']]; foreach ($blacklist as $black_type => $black_subtypes) { if (!isset($supported_types[$black_type])) { continue; } if (!is_array($black_subtypes)) { continue; } foreach ($black_subtypes as $black_subtype) { $index = array_search($black_subtype, $supported_types[$black_type]); if ($index === false) { continue; } unset($supported_types[$black_type][$index]); } } // allow others to change the list return elgg_trigger_plugin_hook('type_subtypes', 'quicklinks', $supported_types, $supported_types); }
<?php $show_hidden = access_get_show_hidden_status(); access_show_hidden_entities(true); $stats = array(); $registered_types = get_registered_entity_types(); $solr_entities = elgg_get_config('solr_entities'); if (is_array($solr_entities)) { foreach ($solr_entities as $type => $subtypes) { foreach ($subtypes as $subtype => $callback) { if ($subtype == 'default') { continue; } $registered_types[$type][] = $subtype; } } } foreach ($registered_types as $type => $subtypes) { $options = array('type' => $type, 'count' => true); if ($subtypes) { if (!is_array($subtypes)) { $subtypes = array($subtypes); } foreach ($subtypes as $s) { $options['subtype'] = $s; $count = elgg_get_entities($options); $indexed = elgg_solr_get_indexed_count("type:{$type}", array('subtype' => "subtype:{$s}")); $stats["{$type}:{$s}"] = array('count' => $count, 'indexed' => $indexed); } continue; }
/** * Returns title buttons to be registered on group pages * * @param ElggGroup $entity Group entity * @param string $identifier Page identifier * @return ElggMenuItem[] */ function group_list_get_title_buttons(ElggGroup $entity = null, $identifier = 'groups') { $buttons = array(); if ($entity) { $buttons = group_list_get_profile_buttons($entity); foreach ($buttons as &$button) { $button->addClass('elgg-button elgg-button-action'); } } else { $page_owner = elgg_get_page_owner_entity(); if (!$page_owner) { $page_owner = elgg_get_logged_in_user_entity(); } $register_buttons = elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in(); if ($page_owner instanceof ElggGroup && elgg_is_active_plugin('au_subgroups')) { // Do no register Add buttons for each allowed subtype if au_subgroups is enabled // au_subgroups adds a single Add Sub-Group button, which then handles the rest $register_buttons = false; } if ($page_owner && $register_buttons) { $subtypes = get_registered_entity_types('group'); if (empty($subtypes)) { $subtypes = array(ELGG_ENTITIES_ANY_VALUE); } foreach ($subtypes as $subtype) { if (!$page_owner->canWriteToContainer(0, 'group', $subtype)) { continue; } // can write to container ignores hierarchy logic $params = array('parent' => $page_owner, 'type' => 'group', 'subtype' => $subtype); $can_contain = elgg_trigger_plugin_hook('permissions_check:parent', 'group', $params, true); if (!$can_contain) { continue; } $buttons[] = ElggMenuItem::factory(array('name' => "{$subtype}:add", 'text' => elgg_echo("groups:add:{$subtype}"), 'href' => "{$identifier}/add/{$page_owner->guid}/{$subtype}", 'link_class' => 'elgg-button elgg-button-action')); } } } $params = array('entity' => $entity); return elgg_trigger_plugin_hook('title_buttons', $identifier, $params, $buttons); }
function elgg_solr_get_indexable_count() { $registered_types = get_registered_entity_types(); $ia = elgg_set_ignore_access(true); $count = 0; foreach ($registered_types as $type => $subtypes) { $options = array('type' => $type, 'count' => true); if ($subtypes) { $options['subtypes'] = $subtypes; } $count += elgg_get_entities($options); } // count comments $options = array('annotation_name' => 'generic_comment', 'count' => true); $count += elgg_get_annotations($options); elgg_set_ignore_access($ia); return $count; }
<?php $registered_subtypes = get_registered_entity_types('group'); if (empty($registered_subtypes)) { return; } $registered_subtypes = (array) get_registered_entity_types('group'); array_unshift($registered_subtypes, 'default'); $context = elgg_extract('filter_context', $vars, 'default'); foreach ($registered_subtypes as $subtype) { elgg_register_menu_item('filter', ['name' => $subtype, 'text' => $subtype === 'default' ? elgg_echo('groups:fields:default') : elgg_echo("item:group:{$subtype}"), 'href' => elgg_http_add_url_query_elements(current_page_url(), ['subtype' => $subtype]), 'selected' => $subtype == $context]); } echo elgg_view_menu('filter', ['sort_by' => 'priority', 'class' => 'elgg-tabs']);