24 $ar = array_map(
'trim', $ar);
25 $ar = array_filter($ar,
'is_not_null');
26 $ar = array_map(
'strip_tags', $ar);
77 'tag_names' => array(),
86 'site_guids' => $CONFIG->site_guid,
100 $singulars = array(
'type',
'subtype',
'owner_guid',
'container_guid',
'site_guid',
'tag_name');
105 if (!is_array(
$options[
'tag_names'])) {
110 if (count(
$options[
'tag_names']) == 0) {
111 $options[
'tag_names'] = $registered_tags;
114 $diff = array_diff(
$options[
'tag_names'], $registered_tags);
115 if (count($diff) > 0) {
116 elgg_deprecated_notice(
'Tag metadata names must be registered by elgg_register_tag_metadata_name()', 1.7);
124 $wheres[] =
"msv.string != ''";
126 $sanitised_tags = array();
127 foreach (
$options[
'tag_names'] as $tag) {
130 $tags_in = implode(
',', $sanitised_tags);
131 $wheres[] =
"(msn.string IN ($tags_in))";
143 foreach ($wheres as $i => $where) {
144 if ($where ===
false) {
146 } elseif (empty($where)) {
152 $wheres = array_unique($wheres);
156 $joins[] =
"JOIN {$CONFIG->dbprefix}metadata md on md.entity_guid = e.guid";
157 $joins[] =
"JOIN {$CONFIG->dbprefix}metastrings msv on msv.id = md.value_id";
158 $joins[] =
"JOIN {$CONFIG->dbprefix}metastrings msn on md.name_id = msn.id";
161 $joins = array_unique($joins);
163 foreach ($joins as $i => $join) {
164 if ($join ===
false) {
166 } elseif (empty($join)) {
172 $query =
"SELECT msv.string as tag, count(msv.id) as total ";
173 $query .=
"FROM {$CONFIG->dbprefix}entities e ";
176 foreach ($joins as $j) {
183 foreach ($wheres as $w) {
184 $query .=
" $w AND ";
191 $query .=
" GROUP BY msv.string HAVING total >= {$threshold} ";
192 $query .=
" ORDER BY total DESC ";
195 $query .=
" LIMIT {$limit} ";
213 if (!isset($CONFIG->registered_tag_metadata_names)) {
214 $CONFIG->registered_tag_metadata_names = array();
217 if (!in_array(
$name, $CONFIG->registered_tag_metadata_names)) {
218 $CONFIG->registered_tag_metadata_names[] =
$name;
233 $names = (isset($CONFIG->registered_tag_metadata_names)) ? $CONFIG->registered_tag_metadata_names : array();
247 $events->registerHandler(
'init',
'system',
'_elgg_tags_init');
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
if($guid==elgg_get_logged_in_user_guid()) $name
_elgg_get_guid_based_where_sql($column, $guids)
Returns SQL where clause for owner and containers.
_elgg_get_entity_time_where_sql($table, $time_created_upper=null, $time_created_lower=null, $time_updated_upper=null, $time_updated_lower=null)
Returns SQL where clause for entity time limits.
sanitise_string($string)
Wrapper function for alternate English spelling (.
const ELGG_ENTITIES_ANY_VALUE
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
elgg global
Pointer to the global context.
get_data($query, $callback="")
Retrieve rows from the database.
_elgg_get_entity_type_subtype_where_sql($table, $types, $subtypes, $pairs)
Returns SQL where clause for type and subtype on main entity table.
sanitise_int($int, $signed=true)
Sanitizes an integer for database use.
_elgg_normalize_plural_options_array($options, $singulars)
Normalise the singular keys in an options array to plural keys.
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.