pluginspath . 'groupstagcloud/browsetags.php'); break; } } } // Displays tagcloud function groupstagcloud_display_tagcloud($view= "output/groupstagcloud" ,$threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object", $entity_subtype = "", $owner_guid = "", $site_guid = -1, $only_approved = false) { return elgg_view($view,array('value' => groupstagcloud_get_tags($threshold, $limit, $metadata_name, $entity_type, $entity_subtype, $owner_guid, $site_guid, $only_approved),'object' => $entity_type, 'subtype' => $entity_subtype, 'owner_entity' => $owner_guid)); } // Gets suitable tags for tagcloud function groupstagcloud_get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object", $entity_subtype = "", $owner_guid = "", $site_guid = -1, $only_approved = false) { global $CONFIG; $threshold = (int) $threshold; $limit = (int) $limit; if (!empty($metadata_name)) { $metadata_name = (int) get_metastring_id($metadata_name); } else { $metadata_name = 0; } $entity_type = sanitise_string($entity_type); // in case entity_subtype is array if (is_array($entity_subtype) && sizeof($entity_subtype) > 0) { $subtypes = array(); foreach ($entity_subtype as $subtype) { $subtype_id = get_subtype_id($entity_type, $subtype); if ($subtype_id) array_push($subtypes, $subtype_id); } } else { $entity_subtype = get_subtype_id($entity_type, $entity_subtype); } if ($owner_guid != "") if (is_array($owner_guid)) { foreach($owner_guid as $key => $val) $owner_guid[$key] = (int) $val; } else { $owner_guid = (int) $owner_guid; } if ($site_guid < 0) { $site_guid = $CONFIG->site_id; } //$access = get_access_list(); $query = "SELECT msvalue.string as tag, count(msvalue.id) as total "; $query .= "FROM {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}metadata md on md.entity_guid = e.guid "; if ($only_approved) { $query .= " join {$CONFIG->dbprefix}metadata md2 on md2.entity_guid = e.guid "; $query .= " join {$CONFIG->dbprefix}metadata md3 on md3.entity_guid = e.guid "; } $query .= " join {$CONFIG->dbprefix}entity_subtypes subtype on subtype.id = e.subtype "; $query .= " join {$CONFIG->dbprefix}metastrings msvalue on msvalue.id = md.value_id "; $query .= " where msvalue.string != '' "; if ($metadata_name > 0) { $query .= " and md.name_id = {$metadata_name} "; } if ($only_approved) { $meta_n = get_metastring_id("approved"); $meta_v = get_metastring_id("1"); $query .= " and md2.name_id = '{$meta_n}' and md2.value_id='{$meta_v}' "; // also find objects that are not archived already $archived_meta_n = get_metastring_id("archived"); $archived_meta_v = get_metastring_id("0"); $query .= " and md3.name_id='{$archived_meta_n}' and md3.value_id='{$archived_meta_v}' "; } if ($site_guid > 0) { $query .= " and e.site_guid = {$site_guid} "; } if (is_array($entity_subtype) && sizeof($entity_subtype) > 0) { if (sizeof($subtypes) > 0) $query .= " and e.subtype in (".implode(",", $subtypes).")"; } else if ($entity_subtype > 0) { $query .= " and e.subtype = {$entity_subtype} "; } if ($entity_type != "") { $query .= " and e.type = '{$entity_type}' "; } if (is_array($owner_guid)) { $query .= " and e.container_guid in (".implode(",",$owner_guid).")"; } else if (is_int($owner_guid)) { $query .= " and e.container_guid = {$owner_guid} "; } //$userid = get_loggedin_userid(); //$query .= " and (e.access_id in {$access} or (e.access_id = " . ACCESS_PRIVATE . " and e.owner_guid = {$userid}))"; $query .= ' and ' . get_access_sql_suffix("e"); // Add access controls // get most popular tags $query .= " group by msvalue.string having total > {$threshold} order by total desc limit {$limit} "; $data = get_data($query); // sort them alphabetically $tags = array(); foreach ($data as $tag) { $tags[$tag->tag] = $tag; } ksort($tags); return $tags; } // Initialize global $CONFIG; register_elgg_event_handler('init', 'system', 'groupstagcloud_init'); ?>