25 trait LegacyQueryOptionsAdapter {
34 public function normalizeOptions(array
$options = []): array {
65 protected function getDefaults(): array {
69 'type_subtype_pairs' => null,
71 'owner_guids' => null,
72 'container_guids' => null,
75 'created_after' => null,
76 'created_before' => null,
77 'updated_after' => null,
78 'updated_before' => null,
79 'last_action_after' => null,
80 'last_action_before' => null,
94 'metadata_name_value_pairs' => null,
95 'metadata_name_value_pairs_operator' =>
'AND',
96 'metadata_case_sensitive' => true,
97 'metadata_ids' => null,
98 'metadata_created_time_lower' => null,
99 'metadata_created_time_upper' => null,
100 'metadata_calculation' => null,
102 'search_name_value_pairs' => null,
104 'annotation_names' => null,
105 'annotation_values' => null,
106 'annotation_name_value_pairs' => null,
107 'annotation_name_value_pairs_operator' =>
'AND',
108 'annotation_case_sensitive' => true,
109 'annotation_ids' => null,
110 'annotation_created_time_lower' => null,
111 'annotation_created_time_upper' => null,
112 'annotation_owner_guids' => null,
113 'annotation_calculation' => null,
115 'relationship_pairs' => [],
117 'relationship' => null,
118 'relationship_guid' => null,
119 'inverse_relationship' => false,
120 'relationship_join_on' =>
'guid',
121 'relationship_created_time_lower' => null,
122 'relationship_created_time_upper' => null,
124 'preload_owners' => false,
125 'preload_containers' => false,
130 'batch_inc_offset' => true,
133 '__ElggBatch' => null,
144 protected function normalizeAccessOptions(array
$options = []): array {
156 protected function normalizeTypeSubtypeOptions(array
$options = []): array {
164 if (isset(
$options[
'type_subtype_pair']) && isset(
$options[
'type_subtype_pairs'])) {
165 $options[
'type_subtype_pairs'] = array_merge((array)
$options[
'type_subtype_pairs'], (array)
$options[
'type_subtype_pair']);
166 }
else if (isset(
$options[
'type_subtype_pair'])) {
168 }
else if (isset(
$options[
'type_subtype_pairs'])) {
170 }
else if (isset(
$options[
'types'])) {
171 $options[
'type_subtype_pairs'] = [];
177 }
else if (isset(
$options[
'subtypes'])) {
178 throw new InvalidArgumentException(
'If filtering for entity subtypes it is required to provide one or more entity types.');
181 if (isset(
$options[
'type_subtype_pairs']) && is_array(
$options[
'type_subtype_pairs'])) {
184 elgg_log(
"'$type' is not a valid entity type", \Psr\Log\LogLevel::WARNING);
193 unset(
$options[
'type_subtype_pair']);
207 protected function normalizeMetadataOptions(array
$options = []): array {
212 'metadata_name_value_pair',
219 'metadata_created_after',
220 'metadata_created_before',
223 foreach ($props as $prop) {
224 if (isset(
$options[$prop]) && empty(
$options[
'metadata_name_value_pairs'])) {
225 $options[
'metadata_name_value_pairs'][] = [
231 foreach (
$options[
'metadata_name_value_pairs'] as
$key => $pair) {
232 if ($pair instanceof Clause) {
236 foreach ($props as $prop) {
237 if (!isset($pair[$prop])) {
245 $options[
'metadata_name_value_pairs'] = $this->removeKeyPrefix(
'metadata_',
$options[
'metadata_name_value_pairs']);
252 'case_sensitive' =>
true,
253 'entity_guids' =>
null,
255 'created_after' =>
null,
256 'created_before' =>
null,
259 foreach (
$options[
'metadata_name_value_pairs'] as
$key => $pair) {
260 if ($pair instanceof WhereClause) {
267 $clause =
new AttributeWhereClause();
269 $clause =
new MetadataWhereClause();
270 $clause->ids = (array) $pair[
'ids'];
271 $clause->entity_guids = (array) $pair[
'entity_guids'];
272 $clause->created_after = $pair[
'created_after'];
273 $clause->created_before = $pair[
'created_before'];
276 $clause->names = (array) $pair[
'name'];
277 $clause->values = (array) $pair[
'value'];
278 $clause->comparison = $pair[
'comparison'];
279 $clause->value_type = $pair[
'type'];
280 $clause->case_sensitive = $pair[
'case_sensitive'];
296 protected function normalizeMetadataSearchOptions(array
$options = []): array {
297 $options = $this->normalizePluralOptions(
$options, [
'search_name_value_pair']);
301 foreach (
$options[
'search_name_value_pairs'] as
$key => $pair) {
302 if ($pair instanceof Clause) {
309 $options[
'search_name_value_pairs'] = $this->removeKeyPrefix(
'metadata_',
$options[
'search_name_value_pairs']);
316 'case_sensitive' =>
true,
317 'entity_guids' =>
null,
319 'created_after' =>
null,
320 'created_before' =>
null,
323 foreach (
$options[
'search_name_value_pairs'] as
$key => $pair) {
324 if ($pair instanceof WhereClause) {
331 $clause =
new AttributeWhereClause();
333 $clause =
new MetadataWhereClause();
334 $clause->ids = (array) $pair[
'ids'];
335 $clause->entity_guids = (array) $pair[
'entity_guids'];
336 $clause->created_after = $pair[
'created_after'];
337 $clause->created_before = $pair[
'created_before'];
340 $clause->names = (array) $pair[
'name'];
341 $clause->values = (array) $pair[
'value'];
342 $clause->comparison = $pair[
'comparison'];
343 $clause->value_type = $pair[
'type'];
344 $clause->case_sensitive = $pair[
'case_sensitive'];
359 protected function normalizeAnnotationOptions(array
$options = []): array {
364 'annotation_name_value_pair',
371 'annotation_owner_guids',
372 'annotation_created_after',
373 'annotation_created_before',
374 'annotation_sort_by_calculation',
377 foreach ($props as $prop) {
378 if (isset(
$options[$prop]) && empty(
$options[
'annotation_name_value_pairs'])) {
379 $options[
'annotation_name_value_pairs'][] = [
385 foreach (
$options[
'annotation_name_value_pairs'] as
$key => $pair) {
386 if ($pair instanceof WhereClause) {
390 foreach ($props as $prop) {
391 if (!isset($pair[$prop])) {
399 $options[
'annotation_name_value_pairs'] = $this->removeKeyPrefix(
'annotation_',
$options[
'annotation_name_value_pairs']);
406 'case_sensitive' =>
true,
407 'entity_guids' =>
null,
408 'owner_guids' =>
null,
411 'access_ids' =>
null,
412 'created_after' =>
null,
413 'created_before' =>
null,
414 'sort_by_calculation' =>
null,
417 foreach (
$options[
'annotation_name_value_pairs'] as
$key => $pair) {
418 if ($pair instanceof WhereClause) {
424 $clause =
new AnnotationWhereClause();
425 $clause->ids = (array) $pair[
'ids'];
426 $clause->entity_guids = (array) $pair[
'entity_guids'];
427 $clause->owner_guids = (array) $pair[
'owner_guids'];
428 $clause->created_after = $pair[
'created_after'];
429 $clause->created_before = $pair[
'created_before'];
430 $clause->names = (array) $pair[
'name'];
431 $clause->values = (array) $pair[
'value'];
432 $clause->comparison = $pair[
'comparison'];
433 $clause->value_type = $pair[
'type'];
434 $clause->case_sensitive = $pair[
'case_sensitive'];
435 $clause->access_ids = (array) $pair[
'access_ids'];
436 $clause->sort_by_calculation = $pair[
'sort_by_calculation'];
438 if ($clause->sort_by_calculation && empty(
$options[
'order_by'])) {
439 $clause->sort_by_direction =
'desc';
442 $options[
'annotation_name_value_pairs'][
$key] = $clause;
456 protected function normalizePairedOptions(
$type =
'metadata', array
$options = []): array {
457 if (!is_array(
$options[
"{$type}_name_value_pairs"])) {
458 $options[
"{$type}_name_value_pairs"] = [];
471 if (isset(
$options[
"{$type}_name_value_pairs"][
'name'])) {
472 $options[
"{$type}_name_value_pairs"][] = [
473 'name' =>
$options[
"{$type}_name_value_pairs"][
'name'],
476 'case_sensitive' =>
elgg_extract(
'case_sensitive',
$options[
"{$type}_name_value_pairs"], $case_sensitive_default)
479 unset(
$options[
"{$type}_name_value_pairs"][
'name']);
480 unset(
$options[
"{$type}_name_value_pairs"][
'value']);
481 unset(
$options[
"{$type}_name_value_pairs"][
'operand']);
482 unset(
$options[
"{$type}_name_value_pairs"][
'case_sensitive']);
496 foreach (
$options[
"{$type}_name_value_pairs"] as
$index => $pair) {
497 if (is_array($pair)) {
498 $keys = array_keys($pair);
502 'value' => $pair[
$keys[0]],
516 foreach (
$options[
"{$type}_name_value_pairs"] as
$index => $values) {
517 if ($values instanceof Clause) {
521 if (is_array($values)) {
522 if (isset($values[
'name']) || isset($values[
'value'])) {
534 if (isset(
$options[
"{$type}_names"]) || isset(
$options[
"{$type}_values"])) {
535 $options[
"{$type}_name_value_pairs"][] = [
536 'name' => isset(
$options[
"{$type}_names"]) ? (array)
$options[
"{$type}_names"] :
null,
537 'value' => isset(
$options[
"{$type}_values"]) ? (array)
$options[
"{$type}_values"] :
null,
543 if (
$value instanceof Clause) {
547 if (!isset(
$value[
'case_sensitive'])) {
548 $value[
'case_sensitive'] = $case_sensitive_default;
551 if (!isset(
$value[
'type'])) {
552 if (isset(
$value[
'value']) && is_bool(
$value[
'value'])) {
556 if (isset(
$value[
'value']) && is_int(
$value[
'value'])) {
563 if (!isset(
$value[
'comparison']) && isset(
$value[
'operand'])) {
573 unset(
$options[
"{$type}_case_sensitive"]);
585 protected function normalizeRelationshipOptions(array
$options = []): array {
587 'relationship_ids' => null,
588 'relationship' => null,
589 'relationship_guid' => null,
590 'inverse_relationship' => false,
591 'relationship_join_on' =>
'guid',
592 'relationship_created_after' => null,
593 'relationship_created_before' => null,
597 foreach (array_keys(
$defaults) as $prop) {
599 $simple_pair[$prop] =
$options[$prop];
606 $options[
'relationship_pairs'][] = $simple_pair;
608 foreach (
$options[
'relationship_pairs'] as
$index => $relationship_pair) {
609 if ($relationship_pair instanceof WhereClause) {
616 $options[
'relationship_pairs'] = $this->removeKeyPrefix(
'relationship_',
$options[
'relationship_pairs']);
618 foreach (
$options[
'relationship_pairs'] as
$key => $pair) {
619 if ($pair instanceof WhereClause) {
623 if (!$pair[
'relationship'] && !$pair[
'guid'] && !$pair[
'ids']) {
628 $clause =
new RelationshipWhereClause();
629 $clause->ids = (array) $pair[
'ids'];
630 $clause->names = (array) $pair[
'relationship'];
632 $clause->join_on = $pair[
'join_on'];
633 $clause->inverse = $pair[
'inverse_relationship'];
634 if ($clause->inverse) {
635 $clause->object_guids = (array) $pair[
'guid'];
637 $clause->subject_guids = (array) $pair[
'guid'];
640 $clause->created_after = $pair[
'created_after'];
641 $clause->created_before = $pair[
'created_before'];
657 protected function normalizeGuidOptions(array
$options = []): array {
662 'annotation_owner_guid',
669 'annotation_owner_guids',
673 foreach ($names as
$name) {
699 protected function normalizeTimeOptions(array
$options = []): array {
705 'annotation_created',
706 'relationship_created',
711 $bounds = [
'time_lower',
'time_upper',
'after',
'before'];
713 foreach ($props as $prop) {
714 foreach ($bounds as $bound) {
715 $prop_name =
"{$prop}_{$bound}";
717 $new_prop_name = $prop_name;
718 $new_prop_name = str_replace(
'modified',
'updated', $new_prop_name);
719 $new_prop_name = str_replace(
'posted',
'created', $new_prop_name);
720 $new_prop_name = str_replace(
'time_lower',
'after', $new_prop_name);
721 $new_prop_name = str_replace(
'time_upper',
'before', $new_prop_name);
723 if (!isset(
$options[$new_prop_name])) {
740 protected function removeKeyPrefix(
string $prefix, array $array = []): array {
743 if (str_starts_with(
$key, $prefix)) {
744 $new_key = substr(
$key, strlen($prefix));
747 if (!isset($array[$new_key])) {
748 $array[$new_key] =
$value;
751 if ($new_key !==
$key) {
755 if (is_array($array[$new_key])) {
756 $array[$new_key] = $this->removeKeyPrefix($prefix, $array[$new_key]);
770 protected function normalizeSelectClauses(array
$options = []): array {
779 if (!is_array(
$options[
'selects'])) {
784 if (empty($clause)) {
789 if ($clause instanceof SelectClause) {
806 protected function normalizeWhereClauses(array
$options = []): array {
815 if (!is_array(
$options[
'wheres'])) {
820 if (empty($clause)) {
825 if ($clause instanceof WhereClause) {
842 protected function normalizeJoinClauses(array
$options = []): array {
861 if ($join instanceof JoinClause) {
865 if (is_string($join)) {
866 preg_match(
'/((LEFT|INNER|RIGHT)\s+)?JOIN\s+(.*?)\s+((as\s+)?(.*?)\s+)ON\s+(.*)$/im', $join, $parts);
868 $type = !empty($parts[2]) ? strtolower($parts[2]) :
'inner';
871 $condition = preg_replace(
'/\r|\n/',
'', $parts[7]);
878 $clause =
new JoinClause(
$table, $alias, $condition,
$type);
893 protected function normalizeOrderByClauses(array
$options = []): array {
897 if (!empty($orders)) {
898 if (is_string($orders)) {
899 $orders = explode(
',', $orders);
900 }
elseif (!is_array($orders)) {
904 foreach ($orders as $order) {
905 if ($order instanceof OrderByClause) {
910 $order = trim($order);
912 if (preg_match(
'/(.*)(?=\s+(asc|desc))/i', $order, $parts)) {
914 $direction = $parts[2];
925 if (!is_array($sort_by)) {
929 if (isset($sort_by[
'property'])) {
934 foreach (
$options[
'sort_by'] as $sort_spec) {
935 $clause =
new EntitySortByClause();
936 $clause->property =
elgg_extract(
'property', $sort_spec);
937 $clause->property_type =
elgg_extract(
'property_type', $sort_spec);
938 $clause->join_type =
elgg_extract(
'join_type', $sort_spec,
'inner');
939 $clause->direction =
elgg_extract(
'direction', $sort_spec);
941 $clause->inverse_relationship =
elgg_extract(
'inverse_relationship', $sort_spec);
942 $clause->relationship_guid =
elgg_extract(
'relationship_guid', $sort_spec);
957 protected function normalizeHavingClauses(array
$options = []): array {
964 if (!is_array(
$options[
'having'])) {
969 if ($expr instanceof HavingClause) {
986 protected function normalizeGroupByClauses(array
$options = []): array {
993 if (!is_array(
$options[
'group_by'])) {
998 if ($expr instanceof GroupByClause) {
1016 public static function normalizeMetastringOptions(array
$options = []): array {
1026 $prefixes = [
'metadata_',
'annotation_',
'annotations_'];
1030 'names' =>
'metastring_names',
1031 'values' =>
'metastring_values',
1032 'case_sensitive' =>
'metastring_case_sensitive',
1033 'owner_guids' =>
'metastring_owner_guids',
1034 'created_time_lower' =>
'metastring_created_time_lower',
1035 'created_time_upper' =>
'metastring_created_time_upper',
1036 'calculation' =>
'metastring_calculation',
1037 'ids' =>
'metastring_ids',
1040 foreach ($prefixes as $prefix) {
1041 $singulars = [
"{$prefix}name",
"{$prefix}value",
"{$prefix}owner_guid",
"{$prefix}id"];
1044 foreach ($map as $specific => $normalized) {
1045 $key = $prefix . $specific;
1067 public static function normalizePluralOptions(array
$options, array $singulars): array {
1068 foreach ($singulars as $singular) {
1069 $plural = $singular .
's';
1071 if (array_key_exists($singular,
$options)) {
1076 if (!is_array(
$options[$singular])) {
if(! $user||! $user->canDelete()) $name
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
foreach( $paths as $path)
Builds queries for matching annotations against their properties.
Builds quereis for matching entities by their attributes.
Interface that allows resolving statements and/or extending query builder.
Extends QueryBuilder with clauses necessary to sort entity lists by entity properties.
Extends QueryBuilder with GROUP BY statements.
Extends QueryBuilder with HAVING clauses.
Extends QueryBuilder with JOIN clauses.
Extends QueryBuilder with ORDER BY clauses.
Builds clauses for filtering entities by their properties in entity_relationships table.
Extends QueryBuilder with SELECT clauses.
Builds a clause from closure or composite expression.
Exception thrown if an argument is not of the expected type.
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
const ELGG_ENTITIES_ANY_VALUE
Constant to request the value of a parameter be ignored in elgg_get_*() functions.
const ELGG_VALUE_INTEGER
Value types.
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.