Elgg  Version 1.9
entities.php
Go to the documentation of this file.
1 <?php
16 $ENTITY_CACHE = array();
17 
26 
34 $SUBTYPE_CACHE = null;
35 
46 
48  $ENTITY_CACHE_DISABLED_GUIDS[$guid] = true;
49 }
50 
60 
61  unset($ENTITY_CACHE_DISABLED_GUIDS[$guid]);
62 }
63 
74 
75  $guid = (int)$guid;
76 
77  if (isset($ENTITY_CACHE[$guid])) {
78  unset($ENTITY_CACHE[$guid]);
79 
80  // Purge separate metadata cache. Original idea was to do in entity destructor, but that would
81  // have caused a bunch of unnecessary purges at every shutdown. Doing it this way we have no way
82  // to know that the expunged entity will be GCed (might be another reference living), but that's
83  // OK; the metadata will reload if necessary.
84  _elgg_get_metadata_cache()->clear($guid);
85  }
86 }
87 
103 
104  // Don't cache non-plugin entities while access control is off, otherwise they could be
105  // exposed to users who shouldn't see them when control is re-enabled.
106  if (!($entity instanceof ElggPlugin) && elgg_get_ignore_access()) {
107  return;
108  }
109 
110  $guid = $entity->getGUID();
111  if (isset($ENTITY_CACHE_DISABLED_GUIDS[$guid])) {
112  return;
113  }
114 
115  // Don't store too many or we'll have memory problems
116  // @todo Pick a less arbitrary limit
117  if (count($ENTITY_CACHE) > 256) {
118  _elgg_invalidate_cache_for_entity(array_rand($ENTITY_CACHE));
119  }
120 
121  $ENTITY_CACHE[$guid] = $entity;
122 }
123 
136 
137  if (isset($ENTITY_CACHE[$guid])) {
138  if ($ENTITY_CACHE[$guid]->isFullyLoaded()) {
139  return $ENTITY_CACHE[$guid];
140  }
141  }
142 
143  return false;
144 }
145 
168 
169  if (!$subtype) {
170  return false;
171  }
172 
173  if ($SUBTYPE_CACHE === null) {
175  }
176 
177  // use the cache before hitting database
179  if ($result !== null) {
180  return $result->id;
181  }
182 
183  return false;
184 }
185 
194 function get_subtype_from_id($subtype_id) {
196 
197  if (!$subtype_id) {
198  return '';
199  }
200 
201  if ($SUBTYPE_CACHE === null) {
203  }
204 
205  if (isset($SUBTYPE_CACHE[$subtype_id])) {
206  return $SUBTYPE_CACHE[$subtype_id]->subtype;
207  }
208 
209  return false;
210 }
211 
223 
224  if ($SUBTYPE_CACHE === null) {
226  }
227 
228  foreach ($SUBTYPE_CACHE as $obj) {
229  if ($obj->type === $type && $obj->subtype === $subtype) {
230  return $obj;
231  }
232  }
233  return null;
234 }
235 
243 
244  $results = get_data("SELECT * FROM {$CONFIG->dbprefix}entity_subtypes");
245 
246  $SUBTYPE_CACHE = array();
247  foreach ($results as $row) {
248  $SUBTYPE_CACHE[$row->id] = $row;
249  }
250 }
251 
269 
270  if ($SUBTYPE_CACHE === null) {
272  }
273 
274  // use the cache before going to the database
276  if ($obj) {
277  return $obj->class;
278  }
279 
280  return null;
281 }
282 
293 function get_subtype_class_from_id($subtype_id) {
295 
296  if (!$subtype_id) {
297  return null;
298  }
299 
300  if ($SUBTYPE_CACHE === null) {
302  }
303 
304  if (isset($SUBTYPE_CACHE[$subtype_id])) {
305  return $SUBTYPE_CACHE[$subtype_id]->class;
306  }
307 
308  return null;
309 }
310 
331 function add_subtype($type, $subtype, $class = "") {
333 
334  if (!$subtype) {
335  return 0;
336  }
337 
339 
340  if (!$id) {
341  // In cache we store non-SQL-escaped strings because that's what's returned by query
342  $cache_obj = (object) array(
343  'type' => $type,
344  'subtype' => $subtype,
345  'class' => $class,
346  );
347 
351 
352  $id = insert_data("INSERT INTO {$CONFIG->dbprefix}entity_subtypes"
353  . " (type, subtype, class) VALUES ('$type', '$subtype', '$class')");
354 
355  // add entry to cache
356  $cache_obj->id = $id;
357  $SUBTYPE_CACHE[$id] = $cache_obj;
358  }
359 
360  return $id;
361 }
362 
379 
382 
383  $success = delete_data("DELETE FROM {$CONFIG->dbprefix}entity_subtypes"
384  . " WHERE type = '$type' AND subtype = '$subtype'");
385 
386  if ($success) {
387  // invalidate the cache
388  $SUBTYPE_CACHE = null;
389  }
390 
391  return (bool) $success;
392 }
393 
405 
407  if (!$id) {
408  return false;
409  }
410 
411  if ($SUBTYPE_CACHE === null) {
413  }
414 
415  $unescaped_class = $class;
416 
420 
421  $success = update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes
422  SET type = '$type', subtype = '$subtype', class = '$class'
423  WHERE id = $id
424  ");
425 
426  if ($success && isset($SUBTYPE_CACHE[$id])) {
427  $SUBTYPE_CACHE[$id]->class = $unescaped_class;
428  }
429 
430  return $success;
431 }
432 
449 function can_write_to_container($user_guid = 0, $container_guid = 0, $type = 'all', $subtype = 'all') {
450  $container_guid = (int)$container_guid;
451  if (!$container_guid) {
452  $container_guid = elgg_get_page_owner_guid();
453  }
454 
455  $container = get_entity($container_guid);
456 
457  $user_guid = (int)$user_guid;
458  if ($user_guid == 0) {
461  } else {
463  if (!$user) {
464  return false;
465  }
466  }
467 
468  $return = false;
469  if ($container) {
470  // If the user can edit the container, they can also write to it
471  if ($container->canEdit($user_guid)) {
472  $return = true;
473  }
474  }
475 
476  // See if anyone else has anything to say
478  'container_permissions_check',
479  $type,
480  array(
481  'container' => $container,
482  'user' => $user,
483  'subtype' => $subtype
484  ),
485  $return);
486 }
487 
503  global $CONFIG;
504 
505  if (!$guid) {
506  return false;
507  }
508 
509  $guid = (int) $guid;
510  $access = _elgg_get_access_where_sql(array('table_alias' => ''));
511 
512  return get_data_row("SELECT * from {$CONFIG->dbprefix}entities where guid=$guid and $access");
513 }
514 
531  if (!($row instanceof stdClass)) {
532  return $row;
533  }
534 
535  if ((!isset($row->guid)) || (!isset($row->subtype))) {
536  return $row;
537  }
538 
539  $new_entity = false;
540 
541  // Create a memcache cache if we can
542  static $newentity_cache;
543  if ((!$newentity_cache) && (is_memcache_available())) {
544  $newentity_cache = new ElggMemcache('new_entity_cache');
545  }
546  if ($newentity_cache) {
547  $new_entity = $newentity_cache->load($row->guid);
548  }
549  if ($new_entity) {
550  return $new_entity;
551  }
552 
553  // load class for entity if one is registered
554  $classname = get_subtype_class_from_id($row->subtype);
555  if ($classname != "") {
556  if (class_exists($classname)) {
557  $new_entity = new $classname($row);
558 
559  if (!($new_entity instanceof ElggEntity)) {
560  $msg = $classname . " is not a " . 'ElggEntity' . ".";
561  throw new ClassException($msg);
562  }
563  } else {
564  error_log("Class '" . $classname . "' was not found, missing plugin?");
565  }
566  }
567 
568  if (!$new_entity) {
569  //@todo Make this into a function
570  switch ($row->type) {
571  case 'object' :
572  $new_entity = new ElggObject($row);
573  break;
574  case 'user' :
575  $new_entity = new ElggUser($row);
576  break;
577  case 'group' :
578  $new_entity = new ElggGroup($row);
579  break;
580  case 'site' :
581  $new_entity = new ElggSite($row);
582  break;
583  default:
584  $msg = "Entity type " . $row->type . " is not supported.";
585  throw new InstallationException($msg);
586  }
587  }
588 
589  // Cache entity if we have a cache available
590  if (($newentity_cache) && ($new_entity)) {
591  $newentity_cache->save($new_entity->guid, $new_entity);
592  }
593 
594  return $new_entity;
595 }
596 
604 function get_entity($guid) {
605  // This should not be a static local var. Notice that cache writing occurs in a completely
606  // different instance outside this function.
607  // @todo We need a single Memcache instance with a shared pool of namespace wrappers. This function would pull an instance from the pool.
608  static $shared_cache;
609 
610  // We could also use: if (!(int) $guid) { return false },
611  // but that evaluates to a false positive for $guid = true.
612  // This is a bit slower, but more thorough.
613  if (!is_numeric($guid) || $guid === 0 || $guid === '0') {
614  return false;
615  }
616 
617  // Check local cache first
618  $new_entity = _elgg_retrieve_cached_entity($guid);
619  if ($new_entity) {
620  return $new_entity;
621  }
622 
623  // Check shared memory cache, if available
624  if (null === $shared_cache) {
625  if (is_memcache_available()) {
626  $shared_cache = new ElggMemcache('new_entity_cache');
627  } else {
628  $shared_cache = false;
629  }
630  }
631 
632  // until ACLs in memcache, DB query is required to determine access
633  $entity_row = get_entity_as_row($guid);
634  if (!$entity_row) {
635  return false;
636  }
637 
638  if ($shared_cache) {
639  $cached_entity = $shared_cache->load($guid);
640  // @todo store ACLs in memcache https://github.com/elgg/elgg/issues/3018#issuecomment-13662617
641  if ($cached_entity) {
642  // @todo use ACL and cached entity access_id to determine if user can see it
643  return $cached_entity;
644  }
645  }
646 
647  // don't let incomplete entities cause fatal exceptions
648  try {
649  $new_entity = entity_row_to_elggstar($entity_row);
650  } catch (IncompleteEntityException $e) {
651  return false;
652  }
653 
654  if ($new_entity) {
655  _elgg_cache_entity($new_entity);
656  }
657  return $new_entity;
658 }
659 
674  global $CONFIG;
675 
677 
678  $query = "SELECT count(*) as total FROM {$CONFIG->dbprefix}entities WHERE guid = $guid";
679  $result = get_data_row($query);
680  if ($result->total == 0) {
681  return false;
682  } else {
683  return true;
684  }
685 }
686 
696 function elgg_enable_entity($guid, $recursive = true) {
697 
698  // Override access only visible entities
699  $old_access_status = access_get_show_hidden_status();
701 
702  $result = false;
704  if ($entity) {
705  $result = $entity->enable($recursive);
706  }
707 
708  access_show_hidden_entities($old_access_status);
709  return $result;
710 }
711 
777 function elgg_get_entities(array $options = array()) {
778  global $CONFIG;
779 
780  $defaults = array(
781  'types' => ELGG_ENTITIES_ANY_VALUE,
782  'subtypes' => ELGG_ENTITIES_ANY_VALUE,
783  'type_subtype_pairs' => ELGG_ENTITIES_ANY_VALUE,
784 
785  'guids' => ELGG_ENTITIES_ANY_VALUE,
786  'owner_guids' => ELGG_ENTITIES_ANY_VALUE,
787  'container_guids' => ELGG_ENTITIES_ANY_VALUE,
788  'site_guids' => $CONFIG->site_guid,
789 
790  'modified_time_lower' => ELGG_ENTITIES_ANY_VALUE,
791  'modified_time_upper' => ELGG_ENTITIES_ANY_VALUE,
792  'created_time_lower' => ELGG_ENTITIES_ANY_VALUE,
793  'created_time_upper' => ELGG_ENTITIES_ANY_VALUE,
794 
795  'reverse_order_by' => false,
796  'order_by' => 'e.time_created desc',
797  'group_by' => ELGG_ENTITIES_ANY_VALUE,
798  'limit' => 10,
799  'offset' => 0,
800  'count' => false,
801  'selects' => array(),
802  'wheres' => array(),
803  'joins' => array(),
804 
805  'callback' => 'entity_row_to_elggstar',
806 
807  '__ElggBatch' => null,
808  );
809 
810  $options = array_merge($defaults, $options);
811 
812  // can't use helper function with type_subtype_pair because
813  // it's already an array...just need to merge it
814  if (isset($options['type_subtype_pair'])) {
815  if (isset($options['type_subtype_pairs'])) {
816  $options['type_subtype_pairs'] = array_merge($options['type_subtype_pairs'],
817  $options['type_subtype_pair']);
818  } else {
819  $options['type_subtype_pairs'] = $options['type_subtype_pair'];
820  }
821  }
822 
823  $singulars = array('type', 'subtype', 'guid', 'owner_guid', 'container_guid', 'site_guid');
825 
826  // evaluate where clauses
827  if (!is_array($options['wheres'])) {
828  $options['wheres'] = array($options['wheres']);
829  }
830 
831  $wheres = $options['wheres'];
832 
833  $wheres[] = _elgg_get_entity_type_subtype_where_sql('e', $options['types'],
834  $options['subtypes'], $options['type_subtype_pairs']);
835 
836  $wheres[] = _elgg_get_guid_based_where_sql('e.guid', $options['guids']);
837  $wheres[] = _elgg_get_guid_based_where_sql('e.owner_guid', $options['owner_guids']);
838  $wheres[] = _elgg_get_guid_based_where_sql('e.container_guid', $options['container_guids']);
839  $wheres[] = _elgg_get_guid_based_where_sql('e.site_guid', $options['site_guids']);
840 
841  $wheres[] = _elgg_get_entity_time_where_sql('e', $options['created_time_upper'],
842  $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']);
843 
844  // see if any functions failed
845  // remove empty strings on successful functions
846  foreach ($wheres as $i => $where) {
847  if ($where === false) {
848  return false;
849  } elseif (empty($where)) {
850  unset($wheres[$i]);
851  }
852  }
853 
854  // remove identical where clauses
855  $wheres = array_unique($wheres);
856 
857  // evaluate join clauses
858  if (!is_array($options['joins'])) {
859  $options['joins'] = array($options['joins']);
860  }
861 
862  // remove identical join clauses
863  $joins = array_unique($options['joins']);
864 
865  foreach ($joins as $i => $join) {
866  if ($join === false) {
867  return false;
868  } elseif (empty($join)) {
869  unset($joins[$i]);
870  }
871  }
872 
873  // evalutate selects
874  if ($options['selects']) {
875  $selects = '';
876  foreach ($options['selects'] as $select) {
877  $selects .= ", $select";
878  }
879  } else {
880  $selects = '';
881  }
882 
883  if (!$options['count']) {
884  $query = "SELECT DISTINCT e.*{$selects} FROM {$CONFIG->dbprefix}entities e ";
885  } else {
886  $query = "SELECT count(DISTINCT e.guid) as total FROM {$CONFIG->dbprefix}entities e ";
887  }
888 
889  // add joins
890  foreach ($joins as $j) {
891  $query .= " $j ";
892  }
893 
894  // add wheres
895  $query .= ' WHERE ';
896 
897  foreach ($wheres as $w) {
898  $query .= " $w AND ";
899  }
900 
901  // Add access controls
902  $query .= _elgg_get_access_where_sql();
903 
904  // reverse order by
905  if ($options['reverse_order_by']) {
906  $options['order_by'] = _elgg_sql_reverse_order_by_clause($options['order_by']);
907  }
908 
909  if (!$options['count']) {
910  if ($options['group_by']) {
911  $query .= " GROUP BY {$options['group_by']}";
912  }
913 
914  if ($options['order_by']) {
915  $query .= " ORDER BY {$options['order_by']}";
916  }
917 
918  if ($options['limit']) {
919  $limit = sanitise_int($options['limit'], false);
920  $offset = sanitise_int($options['offset'], false);
921  $query .= " LIMIT $offset, $limit";
922  }
923 
924  if ($options['callback'] === 'entity_row_to_elggstar') {
925  $dt = _elgg_fetch_entities_from_sql($query, $options['__ElggBatch']);
926  } else {
927  $dt = get_data($query, $options['callback']);
928  }
929 
930  if ($dt) {
931  // populate entity and metadata caches
932  $guids = array();
933  foreach ($dt as $item) {
934  // A custom callback could result in items that aren't ElggEntity's, so check for them
935  if ($item instanceof ElggEntity) {
936  _elgg_cache_entity($item);
937  // plugins usually have only settings
938  if (!$item instanceof ElggPlugin) {
939  $guids[] = $item->guid;
940  }
941  }
942  }
943  // @todo Without this, recursive delete fails. See #4568
944  reset($dt);
945 
946  if ($guids) {
947  _elgg_get_metadata_cache()->populateFromEntities($guids);
948  }
949  }
950  return $dt;
951  } else {
952  $total = get_data_row($query);
953  return (int)$total->total;
954  }
955 }
956 
967 function _elgg_fetch_entities_from_sql($sql, ElggBatch $batch = null) {
968  static $plugin_subtype;
969  if (null === $plugin_subtype) {
970  $plugin_subtype = get_subtype_id('object', 'plugin');
971  }
972 
973  // Keys are types, values are columns that, if present, suggest that the secondary
974  // table is already JOINed
975  $types_to_optimize = array(
976  'object' => 'title',
977  'user' => 'password',
978  'group' => 'name',
979  );
980 
981  $rows = get_data($sql);
982 
983  // guids to look up in each type
984  $lookup_types = array();
985  // maps GUIDs to the $rows key
986  $guid_to_key = array();
987 
988  if (isset($rows[0]->type, $rows[0]->subtype)
989  && $rows[0]->type === 'object'
990  && $rows[0]->subtype == $plugin_subtype) {
991  // Likely the entire resultset is plugins, which have already been optimized
992  // to JOIN the secondary table. In this case we allow retrieving from cache,
993  // but abandon the extra queries.
994  $types_to_optimize = array();
995  }
996 
997  // First pass: use cache where possible, gather GUIDs that we're optimizing
998  foreach ($rows as $i => $row) {
999  if (empty($row->guid) || empty($row->type)) {
1000  throw new LogicException('Entity row missing guid or type');
1001  }
1003  if ($entity) {
1004  $entity->refresh($row);
1005  $rows[$i] = $entity;
1006  continue;
1007  }
1008  if (isset($types_to_optimize[$row->type])) {
1009  // check if row already looks JOINed.
1010  if (isset($row->{$types_to_optimize[$row->type]})) {
1011  // Row probably already contains JOINed secondary table. Don't make another query just
1012  // to pull data that's already there
1013  continue;
1014  }
1015  $lookup_types[$row->type][] = $row->guid;
1016  $guid_to_key[$row->guid] = $i;
1017  }
1018  }
1019  // Do secondary queries and merge rows
1020  if ($lookup_types) {
1021  $dbprefix = elgg_get_config('dbprefix');
1022 
1023  foreach ($lookup_types as $type => $guids) {
1024  $set = "(" . implode(',', $guids) . ")";
1025  $sql = "SELECT * FROM {$dbprefix}{$type}s_entity WHERE guid IN $set";
1026  $secondary_rows = get_data($sql);
1027  if ($secondary_rows) {
1028  foreach ($secondary_rows as $secondary_row) {
1029  $key = $guid_to_key[$secondary_row->guid];
1030  // cast to arrays to merge then cast back
1031  $rows[$key] = (object)array_merge((array)$rows[$key], (array)$secondary_row);
1032  }
1033  }
1034  }
1035  }
1036  // Second pass to finish conversion
1037  foreach ($rows as $i => $row) {
1038  if ($row instanceof ElggEntity) {
1039  continue;
1040  } else {
1041  try {
1043  } catch (IncompleteEntityException $e) {
1044  // don't let incomplete entities throw fatal errors
1045  unset($rows[$i]);
1046 
1047  // report incompletes to the batch process that spawned this query
1048  if ($batch) {
1049  $batch->reportIncompleteEntity($row);
1050  }
1051  }
1052  }
1053  }
1054  return $rows;
1055 }
1056 
1070  // subtype depends upon type.
1071  if ($subtypes && !$types) {
1072  elgg_log("Cannot set subtypes without type.", 'WARNING');
1073  return false;
1074  }
1075 
1076  // short circuit if nothing is requested
1077  if (!$types && !$subtypes && !$pairs) {
1078  return '';
1079  }
1080 
1081  // these are the only valid types for entities in elgg
1082  $valid_types = elgg_get_config('entity_types');
1083 
1084  // pairs override
1085  $wheres = array();
1086  if (!is_array($pairs)) {
1087  if (!is_array($types)) {
1088  $types = array($types);
1089  }
1090 
1091  if ($subtypes && !is_array($subtypes)) {
1092  $subtypes = array($subtypes);
1093  }
1094 
1095  // decrementer for valid types. Return false if no valid types
1096  $valid_types_count = count($types);
1097  $valid_subtypes_count = 0;
1098  // remove invalid types to get an accurate count of
1099  // valid types for the invalid subtype detection to use
1100  // below.
1101  // also grab the count of ALL subtypes on valid types to decrement later on
1102  // and check against.
1103  //
1104  // yes this is duplicating a foreach on $types.
1105  foreach ($types as $type) {
1106  if (!in_array($type, $valid_types)) {
1107  $valid_types_count--;
1108  unset($types[array_search($type, $types)]);
1109  } else {
1110  // do the checking (and decrementing) in the subtype section.
1111  $valid_subtypes_count += count($subtypes);
1112  }
1113  }
1114 
1115  // return false if nothing is valid.
1116  if (!$valid_types_count) {
1117  return false;
1118  }
1119 
1120  // subtypes are based upon types, so we need to look at each
1121  // type individually to get the right subtype id.
1122  foreach ($types as $type) {
1123  $subtype_ids = array();
1124  if ($subtypes) {
1125  foreach ($subtypes as $subtype) {
1126  // check that the subtype is valid
1127  if (!$subtype && ELGG_ENTITIES_NO_VALUE === $subtype) {
1128  // subtype value is 0
1129  $subtype_ids[] = ELGG_ENTITIES_NO_VALUE;
1130  } elseif (!$subtype) {
1131  // subtype is ignored.
1132  // this handles ELGG_ENTITIES_ANY_VALUE, '', and anything falsy that isn't 0
1133  continue;
1134  } else {
1135  $subtype_id = get_subtype_id($type, $subtype);
1136 
1137  if ($subtype_id) {
1138  $subtype_ids[] = $subtype_id;
1139  } else {
1140  $valid_subtypes_count--;
1141  elgg_log("Type-subtype '$type:$subtype' does not exist!", 'NOTICE');
1142  continue;
1143  }
1144  }
1145  }
1146 
1147  // return false if we're all invalid subtypes in the only valid type
1148  if ($valid_subtypes_count <= 0) {
1149  return false;
1150  }
1151  }
1152 
1153  if (is_array($subtype_ids) && count($subtype_ids)) {
1154  $subtype_ids_str = implode(',', $subtype_ids);
1155  $wheres[] = "({$table}.type = '$type' AND {$table}.subtype IN ($subtype_ids_str))";
1156  } else {
1157  $wheres[] = "({$table}.type = '$type')";
1158  }
1159  }
1160  } else {
1161  // using type/subtype pairs
1162  $valid_pairs_count = count($pairs);
1163  $valid_pairs_subtypes_count = 0;
1164 
1165  // same deal as above--we need to know how many valid types
1166  // and subtypes we have before hitting the subtype section.
1167  // also normalize the subtypes into arrays here.
1168  foreach ($pairs as $paired_type => $paired_subtypes) {
1169  if (!in_array($paired_type, $valid_types)) {
1170  $valid_pairs_count--;
1171  unset($pairs[array_search($paired_type, $pairs)]);
1172  } else {
1173  if ($paired_subtypes && !is_array($paired_subtypes)) {
1174  $pairs[$paired_type] = array($paired_subtypes);
1175  }
1176  $valid_pairs_subtypes_count += count($paired_subtypes);
1177  }
1178  }
1179 
1180  if ($valid_pairs_count <= 0) {
1181  return false;
1182  }
1183  foreach ($pairs as $paired_type => $paired_subtypes) {
1184  // this will always be an array because of line 2027, right?
1185  // no...some overly clever person can say pair => array('object' => null)
1186  if (is_array($paired_subtypes)) {
1187  $paired_subtype_ids = array();
1188  foreach ($paired_subtypes as $paired_subtype) {
1189  if (ELGG_ENTITIES_NO_VALUE === $paired_subtype
1190  || ($paired_subtype_id = get_subtype_id($paired_type, $paired_subtype))) {
1191 
1192  $paired_subtype_ids[] = (ELGG_ENTITIES_NO_VALUE === $paired_subtype) ?
1193  ELGG_ENTITIES_NO_VALUE : $paired_subtype_id;
1194  } else {
1195  $valid_pairs_subtypes_count--;
1196  elgg_log("Type-subtype '$paired_type:$paired_subtype' does not exist!", 'NOTICE');
1197  // return false if we're all invalid subtypes in the only valid type
1198  continue;
1199  }
1200  }
1201 
1202  // return false if there are no valid subtypes.
1203  if ($valid_pairs_subtypes_count <= 0) {
1204  return false;
1205  }
1206 
1207 
1208  if ($paired_subtype_ids_str = implode(',', $paired_subtype_ids)) {
1209  $wheres[] = "({$table}.type = '$paired_type'"
1210  . " AND {$table}.subtype IN ($paired_subtype_ids_str))";
1211  }
1212  } else {
1213  $wheres[] = "({$table}.type = '$paired_type')";
1214  }
1215  }
1216  }
1217 
1218  // pairs override the above. return false if they don't exist.
1219  if (is_array($wheres) && count($wheres)) {
1220  $where = implode(' OR ', $wheres);
1221  return "($where)";
1222  }
1223 
1224  return '';
1225 }
1226 
1239  // short circuit if nothing requested
1240  // 0 is a valid guid
1241  if (!$guids && $guids !== 0) {
1242  return '';
1243  }
1244 
1245  // normalize and sanitise owners
1246  if (!is_array($guids)) {
1247  $guids = array($guids);
1248  }
1249 
1250  $guids_sanitized = array();
1251  foreach ($guids as $guid) {
1252  if ($guid !== ELGG_ENTITIES_NO_VALUE) {
1253  $guid = sanitise_int($guid);
1254 
1255  if (!$guid) {
1256  return false;
1257  }
1258  }
1259  $guids_sanitized[] = $guid;
1260  }
1261 
1262  $where = '';
1263  $guid_str = implode(',', $guids_sanitized);
1264 
1265  // implode(',', 0) returns 0.
1266  if ($guid_str !== false && $guid_str !== '') {
1267  $where = "($column IN ($guid_str))";
1268  }
1269 
1270  return $where;
1271 }
1272 
1287 function _elgg_get_entity_time_where_sql($table, $time_created_upper = null,
1288 $time_created_lower = null, $time_updated_upper = null, $time_updated_lower = null) {
1289 
1290  $wheres = array();
1291 
1292  // exploit PHP's loose typing (quack) to check that they are INTs and not str cast to 0
1293  if ($time_created_upper && $time_created_upper == sanitise_int($time_created_upper)) {
1294  $wheres[] = "{$table}.time_created <= $time_created_upper";
1295  }
1296 
1297  if ($time_created_lower && $time_created_lower == sanitise_int($time_created_lower)) {
1298  $wheres[] = "{$table}.time_created >= $time_created_lower";
1299  }
1300 
1301  if ($time_updated_upper && $time_updated_upper == sanitise_int($time_updated_upper)) {
1302  $wheres[] = "{$table}.time_updated <= $time_updated_upper";
1303  }
1304 
1305  if ($time_updated_lower && $time_updated_lower == sanitise_int($time_updated_lower)) {
1306  $wheres[] = "{$table}.time_updated >= $time_updated_lower";
1307  }
1308 
1309  if (is_array($wheres) && count($wheres) > 0) {
1310  $where_str = implode(' AND ', $wheres);
1311  return "($where_str)";
1312  }
1313 
1314  return '';
1315 }
1316 
1343 function elgg_list_entities(array $options = array(), $getter = 'elgg_get_entities',
1344  $viewer = 'elgg_view_entity_list') {
1345 
1346  global $autofeed;
1347  $autofeed = true;
1348 
1349  $offset_key = isset($options['offset_key']) ? $options['offset_key'] : 'offset';
1350 
1351  $defaults = array(
1352  'offset' => (int) max(get_input($offset_key, 0), 0),
1353  'limit' => (int) max(get_input('limit', 10), 0),
1354  'full_view' => false,
1355  'list_type_toggle' => false,
1356  'pagination' => true,
1357  'no_results' => '',
1358  );
1359 
1360  $options = array_merge($defaults, $options);
1361 
1362  // backward compatibility
1363  if (isset($options['view_type_toggle'])) {
1364  elgg_deprecated_notice("Option 'view_type_toggle' deprecated by 'list_type_toggle' in elgg_list* functions", 1.9);
1365  $options['list_type_toggle'] = $options['view_type_toggle'];
1366  }
1367 
1368  $options['count'] = true;
1369  $count = call_user_func($getter, $options);
1370 
1371  if ($count > 0) {
1372  $options['count'] = false;
1373  $entities = call_user_func($getter, $options);
1374  } else {
1375  $entities = array();
1376  }
1377 
1378  $options['count'] = $count;
1379 
1380  return call_user_func($viewer, $entities, $options);
1381 }
1382 
1415 function elgg_get_entities_from_attributes(array $options = array()) {
1416  $defaults = array(
1417  'attribute_name_value_pairs' => ELGG_ENTITIES_ANY_VALUE,
1418  'attribute_name_value_pairs_operator' => 'AND',
1419  );
1420 
1421  $options = array_merge($defaults, $options);
1422 
1423  $singulars = array('type', 'attribute_name_value_pair');
1425 
1427 
1428  if ($clauses) {
1429  // merge wheres to pass to elgg_get_entities()
1430  if (isset($options['wheres']) && !is_array($options['wheres'])) {
1431  $options['wheres'] = array($options['wheres']);
1432  } elseif (!isset($options['wheres'])) {
1433  $options['wheres'] = array();
1434  }
1435 
1436  $options['wheres'] = array_merge($options['wheres'], $clauses['wheres']);
1437 
1438  // merge joins to pass to elgg_get_entities()
1439  if (isset($options['joins']) && !is_array($options['joins'])) {
1440  $options['joins'] = array($options['joins']);
1441  } elseif (!isset($options['joins'])) {
1442  $options['joins'] = array();
1443  }
1444 
1445  $options['joins'] = array_merge($options['joins'], $clauses['joins']);
1446  }
1447 
1449 }
1450 
1460 
1461  if (!isset($options['types'])) {
1462  throw new InvalidArgumentException("The entity type must be defined for elgg_get_entities_from_attributes()");
1463  }
1464 
1465  if (is_array($options['types']) && count($options['types']) !== 1) {
1466  throw new InvalidArgumentException("Only one type can be passed to elgg_get_entities_from_attributes()");
1467  }
1468 
1469  // type can be passed as string or array
1470  $type = $options['types'];
1471  if (is_array($type)) {
1472  $type = $type[0];
1473  }
1474 
1475  // @todo the types should be defined somewhere (as constant on ElggEntity?)
1476  if (!in_array($type, array('group', 'object', 'site', 'user'))) {
1477  throw new InvalidArgumentException("Invalid type '$type' passed to elgg_get_entities_from_attributes()");
1478  }
1479 
1480  global $CONFIG;
1481  $type_table = "{$CONFIG->dbprefix}{$type}s_entity";
1482 
1483  $return = array(
1484  'joins' => array(),
1485  'wheres' => array(),
1486  );
1487 
1488  // short circuit if nothing requested
1489  if ($options['attribute_name_value_pairs'] == ELGG_ENTITIES_ANY_VALUE) {
1490  return $return;
1491  }
1492 
1493  if (!is_array($options['attribute_name_value_pairs'])) {
1494  throw new InvalidArgumentException("attribute_name_value_pairs must be an array for elgg_get_entities_from_attributes()");
1495  }
1496 
1497  $wheres = array();
1498 
1499  // check if this is an array of pairs or just a single pair.
1500  $pairs = $options['attribute_name_value_pairs'];
1501  if (isset($pairs['name']) || isset($pairs['value'])) {
1502  $pairs = array($pairs);
1503  }
1504 
1505  $pair_wheres = array();
1506  foreach ($pairs as $index => $pair) {
1507  // must have at least a name and value
1508  if (!isset($pair['name']) || !isset($pair['value'])) {
1509  continue;
1510  }
1511 
1512  if (isset($pair['operand'])) {
1513  $operand = sanitize_string($pair['operand']);
1514  } else {
1515  $operand = '=';
1516  }
1517 
1518  if (is_numeric($pair['value'])) {
1519  $value = sanitize_string($pair['value']);
1520  } else if (is_array($pair['value'])) {
1521  $values_array = array();
1522  foreach ($pair['value'] as $pair_value) {
1523  if (is_numeric($pair_value)) {
1524  $values_array[] = sanitize_string($pair_value);
1525  } else {
1526  $values_array[] = "'" . sanitize_string($pair_value) . "'";
1527  }
1528  }
1529 
1530  $operand = 'IN';
1531  if ($values_array) {
1532  $value = '(' . implode(', ', $values_array) . ')';
1533  }
1534 
1535  } else {
1536  $value = "'" . sanitize_string($pair['value']) . "'";
1537  }
1538 
1539  $name = sanitize_string($pair['name']);
1540 
1541  // case sensitivity can be specified per pair
1542  $pair_binary = '';
1543  if (isset($pair['case_sensitive'])) {
1544  $pair_binary = ($pair['case_sensitive']) ? 'BINARY ' : '';
1545  }
1546 
1547  $pair_wheres[] = "({$pair_binary}type_table.$name $operand $value)";
1548  }
1549 
1550  if ($where = implode(" {$options['attribute_name_value_pairs_operator']} ", $pair_wheres)) {
1551  $return['wheres'][] = "($where)";
1552 
1553  $return['joins'][] = "JOIN $type_table type_table ON e.guid = type_table.guid";
1554  }
1555 
1556  return $return;
1557 }
1558 
1576 function get_entity_dates($type = '', $subtype = '', $container_guid = 0, $site_guid = 0,
1577 $order_by = 'time_created') {
1578 
1579  global $CONFIG;
1580 
1581  $site_guid = (int) $site_guid;
1582  if ($site_guid == 0) {
1583  $site_guid = $CONFIG->site_guid;
1584  }
1585  $where = array();
1586 
1587  if ($type != "") {
1589  $where[] = "type='$type'";
1590  }
1591 
1592  if (is_array($subtype)) {
1593  $tempwhere = "";
1594  if (sizeof($subtype)) {
1595  foreach ($subtype as $typekey => $subtypearray) {
1596  foreach ($subtypearray as $subtypeval) {
1597  $typekey = sanitise_string($typekey);
1598  if (!empty($subtypeval)) {
1599  if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval)) {
1600  return false;
1601  }
1602  } else {
1603  $subtypeval = 0;
1604  }
1605  if (!empty($tempwhere)) {
1606  $tempwhere .= " or ";
1607  }
1608  $tempwhere .= "(type = '{$typekey}' and subtype = {$subtypeval})";
1609  }
1610  }
1611  }
1612  if (!empty($tempwhere)) {
1613  $where[] = "({$tempwhere})";
1614  }
1615  } else {
1616  if ($subtype) {
1617  if (!$subtype_id = get_subtype_id($type, $subtype)) {
1618  return false;
1619  } else {
1620  $where[] = "subtype=$subtype_id";
1621  }
1622  }
1623  }
1624 
1625  if ($container_guid !== 0) {
1626  if (is_array($container_guid)) {
1627  foreach ($container_guid as $key => $val) {
1628  $container_guid[$key] = (int) $val;
1629  }
1630  $where[] = "container_guid in (" . implode(",", $container_guid) . ")";
1631  } else {
1632  $container_guid = (int) $container_guid;
1633  $where[] = "container_guid = {$container_guid}";
1634  }
1635  }
1636 
1637  if ($site_guid > 0) {
1638  $where[] = "site_guid = {$site_guid}";
1639  }
1640 
1641  $where[] = _elgg_get_access_where_sql(array('table_alias' => ''));
1642 
1643  $sql = "SELECT DISTINCT EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(time_created)) AS yearmonth
1644  FROM {$CONFIG->dbprefix}entities where ";
1645 
1646  foreach ($where as $w) {
1647  $sql .= " $w and ";
1648  }
1649 
1650  $sql .= "1=1 ORDER BY $order_by";
1651  if ($result = get_data($sql)) {
1652  $endresult = array();
1653  foreach ($result as $res) {
1654  $endresult[] = $res->yearmonth;
1655  }
1656  return $endresult;
1657  }
1658  return false;
1659 }
1660 
1676  global $CONFIG;
1677 
1678  $type = strtolower($type);
1679  if (!in_array($type, $CONFIG->entity_types)) {
1680  return false;
1681  }
1682 
1683  if (!isset($CONFIG->registered_entities)) {
1684  $CONFIG->registered_entities = array();
1685  }
1686 
1687  if (!isset($CONFIG->registered_entities[$type])) {
1688  $CONFIG->registered_entities[$type] = array();
1689  }
1690 
1691  if ($subtype) {
1692  $CONFIG->registered_entities[$type][] = $subtype;
1693  }
1694 
1695  return true;
1696 }
1697 
1711  global $CONFIG;
1712 
1713  $type = strtolower($type);
1714  if (!in_array($type, $CONFIG->entity_types)) {
1715  return false;
1716  }
1717 
1718  if (!isset($CONFIG->registered_entities)) {
1719  return false;
1720  }
1721 
1722  if (!isset($CONFIG->registered_entities[$type])) {
1723  return false;
1724  }
1725 
1726  if ($subtype) {
1727  if (in_array($subtype, $CONFIG->registered_entities[$type])) {
1728  $key = array_search($subtype, $CONFIG->registered_entities[$type]);
1729  unset($CONFIG->registered_entities[$type][$key]);
1730  } else {
1731  return false;
1732  }
1733  } else {
1734  unset($CONFIG->registered_entities[$type]);
1735  }
1736 
1737  return true;
1738 }
1739 
1749  global $CONFIG;
1750 
1751  if (!isset($CONFIG->registered_entities)) {
1752  return false;
1753  }
1754  if ($type) {
1755  $type = strtolower($type);
1756  }
1757  if (!empty($type) && empty($CONFIG->registered_entities[$type])) {
1758  return false;
1759  }
1760 
1761  if (empty($type)) {
1762  return $CONFIG->registered_entities;
1763  }
1764 
1765  return $CONFIG->registered_entities[$type];
1766 }
1767 
1777  global $CONFIG;
1778 
1779  if (!isset($CONFIG->registered_entities)) {
1780  return false;
1781  }
1782 
1783  $type = strtolower($type);
1784 
1785  // @todo registering a subtype implicitly registers the type.
1786  // see #2684
1787  if (!isset($CONFIG->registered_entities[$type])) {
1788  return false;
1789  }
1790 
1791  if ($subtype && !in_array($subtype, $CONFIG->registered_entities[$type])) {
1792  return false;
1793  }
1794  return true;
1795 }
1796 
1815 function elgg_list_registered_entities(array $options = array()) {
1816  global $autofeed;
1817  $autofeed = true;
1818 
1819  $defaults = array(
1820  'full_view' => false,
1821  'allowed_types' => true,
1822  'list_type_toggle' => false,
1823  'pagination' => true,
1824  'offset' => 0,
1825  'types' => array(),
1826  'type_subtype_pairs' => array(),
1827  );
1828 
1829  $options = array_merge($defaults, $options);
1830 
1831  // backward compatibility
1832  if (isset($options['view_type_toggle'])) {
1833  elgg_deprecated_notice("Option 'view_type_toggle' deprecated by 'list_type_toggle' in elgg_list* functions", 1.9);
1834  $options['list_type_toggle'] = $options['view_type_toggle'];
1835  }
1836 
1837  $types = get_registered_entity_types();
1838 
1839  foreach ($types as $type => $subtype_array) {
1840  if (in_array($type, $options['allowed_types']) || $options['allowed_types'] === true) {
1841  // you must explicitly register types to show up in here and in search for objects
1842  if ($type == 'object') {
1843  if (is_array($subtype_array) && count($subtype_array)) {
1844  $options['type_subtype_pairs'][$type] = $subtype_array;
1845  }
1846  } else {
1847  if (is_array($subtype_array) && count($subtype_array)) {
1848  $options['type_subtype_pairs'][$type] = $subtype_array;
1849  } else {
1850  $options['type_subtype_pairs'][$type] = ELGG_ENTITIES_ANY_VALUE;
1851  }
1852  }
1853  }
1854  }
1855 
1856  if (!empty($options['type_subtype_pairs'])) {
1857  $count = elgg_get_entities(array_merge(array('count' => true), $options));
1858  if ($count > 0) {
1859  $entities = elgg_get_entities($options);
1860  } else {
1861  $entities = array();
1862  }
1863  } else {
1864  $count = 0;
1865  $entities = array();
1866  }
1867 
1868  $options['count'] = $count;
1869  return elgg_view_entity_list($entities, $options);
1870 }
1871 
1886 function elgg_instanceof($entity, $type = null, $subtype = null, $class = null) {
1887  $return = ($entity instanceof ElggEntity);
1888 
1889  if ($type) {
1890  /* @var ElggEntity $entity */
1891  $return = $return && ($entity->getType() == $type);
1892  }
1893 
1894  if ($subtype) {
1895  $return = $return && ($entity->getSubtype() == $subtype);
1896  }
1897 
1898  if ($class) {
1899  $return = $return && ($entity instanceof $class);
1900  }
1901 
1902  return $return;
1903 }
1904 
1918  global $CONFIG;
1919  $guid = (int)$guid;
1920  $posted = (int)$posted;
1921 
1922  if (!$posted) {
1923  $posted = time();
1924  }
1925 
1926  if ($guid) {
1927  //now add to the river updated table
1928  $query = "UPDATE {$CONFIG->dbprefix}entities SET last_action = {$posted} WHERE guid = {$guid}";
1929  $result = update_data($query);
1930  if ($result) {
1931  return true;
1932  } else {
1933  return false;
1934  }
1935  } else {
1936  return false;
1937  }
1938 }
1939 
1947 function _elgg_entities_gc() {
1948  global $CONFIG;
1949 
1950  $tables = array(
1951  'site' => 'sites_entity',
1952  'object' => 'objects_entity',
1953  'group' => 'groups_entity',
1954  'user' => 'users_entity',
1955  );
1956 
1957  foreach ($tables as $type => $table) {
1958  delete_data("DELETE FROM {$CONFIG->dbprefix}{$table}
1959  WHERE guid NOT IN (SELECT guid FROM {$CONFIG->dbprefix}entities)");
1960  delete_data("DELETE FROM {$CONFIG->dbprefix}entities
1961  WHERE type = '$type' AND guid NOT IN (SELECT guid FROM {$CONFIG->dbprefix}{$table})");
1962  }
1963 }
1964 
1975 function _elgg_entities_test($hook, $type, $value) {
1976  global $CONFIG;
1977  $value[] = $CONFIG->path . 'engine/tests/ElggEntityTest.php';
1978  $value[] = $CONFIG->path . 'engine/tests/ElggCoreAttributeLoaderTest.php';
1979  $value[] = $CONFIG->path . 'engine/tests/ElggCoreGetEntitiesTest.php';
1980  $value[] = $CONFIG->path . 'engine/tests/ElggCoreGetEntitiesFromAnnotationsTest.php';
1981  $value[] = $CONFIG->path . 'engine/tests/ElggCoreGetEntitiesFromMetadataTest.php';
1982  $value[] = $CONFIG->path . 'engine/tests/ElggCoreGetEntitiesFromPrivateSettingsTest.php';
1983  $value[] = $CONFIG->path . 'engine/tests/ElggCoreGetEntitiesFromRelationshipTest.php';
1984  $value[] = $CONFIG->path . 'engine/tests/ElggCoreGetEntitiesFromAttributesTest.php';
1985  return $value;
1986 }
1987 
1996  elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_entities_test');
1997  elgg_register_plugin_hook_handler('gc', 'system', '_elgg_entities_gc');
1998 }
1999 
2000 elgg_register_event_handler('init', 'system', '_elgg_entities_init');
_elgg_disable_caching_for_entity($guid)
Remove this entity from the entity cache and make sure it is not re-added.
Definition: entities.php:44
$success
Definition: view.php:29
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$dbprefix
Definition: index.php:13
_elgg_populate_subtype_cache()
Fetch all suptypes from DB to local cache.
Definition: entities.php:241
_elgg_retrieve_cached_subtype($type, $subtype)
Retrieve subtype from the cache.
Definition: entities.php:221
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
get_data_row($query, $callback="")
Retrieve a single row from the database.
Definition: database.php:66
_elgg_invalidate_cache_for_entity($guid)
Invalidate this class&#39;s entry in the cache.
Definition: entities.php:72
elgg_get_entities_from_attributes(array $options=array())
Gets entities based upon attributes in secondary tables.
Definition: entities.php:1415
$table
Definition: cron.php:28
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
_elgg_retrieve_cached_entity($guid)
Retrieve a entity from the cache.
Definition: entities.php:134
$e
Definition: metadata.php:12
get_subtype_id($type, $subtype)
Return the id for a given subtype.
Definition: entities.php:166
elgg_enable_entity($guid, $recursive=true)
Enable an entity.
Definition: entities.php:696
const ELGG_ENTITIES_NO_VALUE
Definition: elgglib.php:2143
_elgg_get_guid_based_where_sql($column, $guids)
Returns SQL where clause for owner and containers.
Definition: entities.php:1238
update_entity_last_action($guid, $posted=null)
Update the last_action column in the entities table for $guid.
Definition: entities.php:1917
elgg_view_entity_list($entities, $vars=array(), $offset=0, $limit=10, $full_view=true, $list_type_toggle=true, $pagination=true)
Returns a rendered list of entities with pagination.
Definition: views.php:969
if(elgg_in_context('widget')) $offset
Definition: pagination.php:20
_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.
Definition: entities.php:1287
get_subtype_from_id($subtype_id)
Gets the denormalized string for a given subtype ID.
Definition: entities.php:194
_elgg_get_metadata_cache()
Get the global metadata cache instance.
Definition: metadata.php:849
$value
Definition: longtext.php:29
get_entity_dates($type= '', $subtype= '', $container_guid=0, $site_guid=0, $order_by= 'time_created')
Returns a list of months in which entities were updated or created.
Definition: entities.php:1576
$column
Definition: add.php:13
elgg_unregister_entity_type($type, $subtype=null)
Unregisters an entity type and subtype as a public-facing type.
Definition: entities.php:1710
$return
Definition: opendd.php:15
getGUID()
Returns the guid.
elgg_entity_exists($guid)
Does an entity exist?
Definition: entities.php:673
$guid
Removes an admin notice.
_elgg_enable_caching_for_entity($guid)
Allow this entity to be stored in the entity cache.
Definition: entities.php:58
global $SUBTYPE_CACHE
Cache subtypes and related class names.
Definition: entities.php:33
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
Definition: elgglib.php:853
delete_data($query)
Remove a row from the database.
Definition: database.php:106
if(isset($vars['id'])) $class
Definition: ajax_loader.php:19
_elgg_sql_reverse_order_by_clause($order_by)
Reverses the ordering in an ORDER BY clause.
Definition: elgglib.php:1809
update_data($query)
Update a row in the database.
Definition: database.php:93
sanitize_string($string)
Sanitize a string for database use.
Definition: database.php:140
get_subtype_class_from_id($subtype_id)
Returns the class name for a subtype id.
Definition: entities.php:293
insert_data($query)
Insert a row into the database.
Definition: database.php:80
elgg_get_ignore_access()
Get current ignore access setting.
Definition: access.php:57
entity_row_to_elggstar($row)
Create an Elgg* object from a given entity row.
Definition: entities.php:530
$options
Definition: index.php:14
get_subtype_class($type, $subtype)
Return the class name for a registered type and subtype.
Definition: entities.php:267
is_registered_entity_type($type, $subtype=null)
Returns if the entity type and subtype have been registered with elgg_register_entity_type().
Definition: entities.php:1776
get_registered_entity_types($type=null)
Returns registered entity types and subtypes.
Definition: entities.php:1748
global $ENTITY_CACHE_DISABLED_GUIDS
GUIDs of entities banned from the entity cache (during this request)
Definition: entities.php:24
_elgg_entities_gc()
Garbage collect stub and fragments from any broken delete/create calls.
Definition: entities.php:1947
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an ElggEntity and optionally for type and subtype.
Definition: entities.php:1886
$limit
Definition: userpicker.php:33
add_subtype($type, $subtype, $class="")
Register ElggEntities with a certain type and subtype to be loaded as a specific class.
Definition: entities.php:331
$key
Definition: summary.php:34
get_user($guid)
Get a user object from a GUID.
Definition: users.php:222
$item
Definition: item.php:12
global $CONFIG
can_write_to_container($user_guid=0, $container_guid=0, $type= 'all', $subtype= 'all')
Determine if a given user can write to an entity container.
Definition: entities.php:449
sanitise_string($string)
Wrapper function for alternate English spelling (.
Definition: database.php:150
$user
Definition: ban.php:13
const ELGG_ENTITIES_ANY_VALUE
Definition: elgglib.php:2134
elgg ElggUser
Definition: ElggUser.js:12
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:777
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
Definition: elgglib.php:925
_elgg_entities_test($hook, $type, $value)
Runs unit tests for the entity objects.
Definition: entities.php:1975
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
elgg global
Pointer to the global context.
Definition: elgglib.js:12
$offset_key
Definition: pagination.php:27
$type
Definition: add.php:8
access_get_show_hidden_status()
Return current status of showing disabled entities.
Definition: access.php:299
get_entity_as_row($guid)
Returns a database row from the entities table.
Definition: entities.php:502
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:669
elgg_log($message, $level= 'NOTICE')
Display or log a message.
Definition: elgglib.php:1083
update_subtype($type, $subtype, $class= '')
Update a registered ElggEntity type, subtype, and class name.
Definition: entities.php:403
$posted
Definition: comment.php:61
$guids
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:1343
get_data($query, $callback="")
Retrieve rows from the database.
Definition: database.php:50
$count
Definition: tools.php:19
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
Definition: access.php:286
elgg_list_registered_entities(array $options=array())
Returns a viewable list of entities based on the registered types.
Definition: entities.php:1815
_elgg_fetch_entities_from_sql($sql, ElggBatch $batch=null)
Return entities from an SQL query generated by elgg_get_entities.
Definition: entities.php:967
remove_subtype($type, $subtype)
Removes a registered ElggEntity type, subtype, and classname.
Definition: entities.php:377
$subtypes
_elgg_get_entity_type_subtype_where_sql($table, $types, $subtypes, $pairs)
Returns SQL where clause for type and subtype on main entity table.
Definition: entities.php:1069
$row
sanitise_int($int, $signed=true)
Sanitizes an integer for database use.
Definition: database.php:173
_elgg_get_entity_attribute_where_sql(array $options=array())
Get the join and where clauses for working with entity attributes.
Definition: entities.php:1459
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:32
is_memcache_available()
Return true if memcache is available and configured.
Definition: memcache.php:16
$rows
elgg_get_entities_from_relationship($options)
Return entities matching a given query joining against a relationship.
_elgg_normalize_plural_options_array($options, $singulars)
Normalise the singular keys in an options array to plural keys.
Definition: elgglib.php:1594
elgg_register_entity_type($type, $subtype=null)
Registers an entity type and subtype as a public-facing entity that should be shown in search and by ...
Definition: entities.php:1675
sanitize_int($int, $signed=true)
Sanitizes an integer for database use.
Definition: database.php:161
$user_guid
Avatar remove action.
Definition: remove.php:6
$defaults
Definition: access.php:19
$entity
Definition: delete.php:10
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
Definition: access.php:343
$subtype
Definition: river.php:10
global $ENTITY_CACHE
Cache entities in memory once loaded.
Definition: entities.php:15
if(!$collection_name) $id
Definition: add.php:17
list style type
Definition: admin.php:724
$container
Definition: access.php:30
elgg ElggEntity
Definition: ElggEntity.js:16
A Site entity.
Definition: ElggSite.php:28
elgg_get_page_owner_guid($guid=0)
Gets the guid of the entity that owns the current page.
Definition: pageowner.php:18
_elgg_cache_entity(ElggEntity $entity)
Cache an entity.
Definition: entities.php:101
_elgg_entities_init()
Entities init function; establishes the default entity page handler.
Definition: entities.php:1995
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:42
Elgg Object.
Definition: ElggObject.php:22
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604
$access
Definition: save.php:15