/** * Registers page menu items for file type filtering and returns a view * * @param int $container_guid The GUID of the container of the files * @param bool $friends Whether we're looking at the container or the container's friends * * @return string The typecloud */ function file_get_type_cloud($container_guid = "", $friends = false) { $container_guids = $container_guid; $container = get_entity($container_guid); if ($friends && $container) { // tags interface does not support pulling tags on friends' content so // we need to grab all friends $friend_entities = $container->getFriends(array('limit' => 0)); if ($friend_entities) { $friend_guids = array(); foreach ($friend_entities as $friend) { $friend_guids[] = $friend->getGUID(); } } $container_guids = $friend_guids; } elgg_register_tag_metadata_name('simpletype'); $options = array('type' => 'object', 'subtype' => 'file', 'container_guids' => $container_guids, 'threshold' => 0, 'limit' => 10, 'tag_names' => array('simpletype')); $types = elgg_get_tags($options); if ($types) { $all = new stdClass(); $all->tag = 'all'; elgg_register_menu_item('page', array('name' => 'file:all', 'text' => elgg_echo('all'), 'href' => file_type_cloud_get_url($all, $friends))); foreach ($types as $type) { elgg_register_menu_item('page', array('name' => "file:{$type->tag}", 'text' => elgg_echo("file:type:{$type->tag}"), 'href' => file_type_cloud_get_url($type, $friends))); } } // returning the view is needed for BC $params = array('friends' => $friends, 'types' => $types); return elgg_view('file/typecloud', $params); }
/** * Type cloud */ function file_type_cloud_get_url($type, $friends) { $url = elgg_get_site_url() . 'file/search?subtype=file'; if ($type->tag != "all") { $url .= "&md_type=simpletype&tag=" . urlencode($type->tag); } if ($friends) { $url .= "&friends={$friends}"; } if ($type->tag == "image") { $url .= "&listtype=gallery"; } if (elgg_get_page_owner_guid()) { $url .= "&page_owner=" . elgg_get_page_owner_guid(); } return $url; } $types = elgg_extract('types', $vars, array()); if (!$types) { return true; } $friends = elgg_extract('friends', $vars, false); $all = new stdClass(); $all->tag = "all"; elgg_register_menu_item('page', array('name' => 'file:all', 'text' => elgg_echo('all'), 'href' => file_type_cloud_get_url($all, $friends))); foreach ($types as $type) { elgg_register_menu_item('page', array('name' => "file:{$type->tag}", 'text' => elgg_echo("file:type:{$type->tag}"), 'href' => file_type_cloud_get_url($type, $friends))); }