25 trait LegacyQueryOptionsAdapter {
34 public function normalizeOptions(array
$options = []): array {
62 protected function getDefaults(): array {
66 'type_subtype_pairs' => null,
68 'owner_guids' => null,
69 'container_guids' => null,
72 'created_after' => null,
73 'created_before' => null,
74 'updated_after' => null,
75 'updated_before' => null,
76 'last_action_after' => null,
77 'last_action_before' => null,
91 'metadata_name_value_pairs' => null,
92 'metadata_name_value_pairs_operator' =>
'AND',
93 'metadata_case_sensitive' => true,
94 'metadata_ids' => null,
95 'metadata_created_after' => null,
96 'metadata_created_before' => null,
97 'metadata_calculation' => null,
99 'search_name_value_pairs' => null,
101 'annotation_names' => null,
102 'annotation_values' => null,
103 'annotation_name_value_pairs' => null,
104 'annotation_name_value_pairs_operator' =>
'AND',
105 'annotation_case_sensitive' => true,
106 'annotation_ids' => null,
107 'annotation_created_after' => null,
108 'annotation_created_before' => null,
109 'annotation_owner_guids' => null,
110 'annotation_calculation' => null,
112 'relationship_pairs' => [],
114 'relationship' => null,
115 'relationship_guid' => null,
116 'inverse_relationship' => false,
117 'relationship_join_on' =>
'guid',
118 'relationship_created_after' => null,
119 'relationship_created_before' => null,
121 'preload_owners' => false,
122 'preload_containers' => false,
127 'batch_inc_offset' => true,
139 protected function normalizeAccessOptions(array
$options = []): array {
151 protected function normalizeTypeSubtypeOptions(array
$options = []): array {
157 if (isset(
$options[
'type_subtype_pair'])) {
158 elgg_deprecated_notice(
"Using the singular option 'type_subtype_pair' is deprecated. Update your code to use the plural 'type_subtype_pairs' instead.",
'6.3');
163 if (isset(
$options[
'type_subtype_pair']) && isset(
$options[
'type_subtype_pairs'])) {
164 $options[
'type_subtype_pairs'] = array_merge((array)
$options[
'type_subtype_pairs'], (array)
$options[
'type_subtype_pair']);
165 }
else if (isset(
$options[
'type_subtype_pair'])) {
167 }
else if (isset(
$options[
'type_subtype_pairs'])) {
169 }
else if (isset(
$options[
'types'])) {
170 $options[
'type_subtype_pairs'] = [];
176 }
else if (isset(
$options[
'subtypes'])) {
177 throw new InvalidArgumentException(
'If filtering for entity subtypes it is required to provide one or more entity types.');
180 if (isset(
$options[
'type_subtype_pairs']) && is_array(
$options[
'type_subtype_pairs'])) {
183 elgg_log(
"'$type' is not a valid entity type", \Psr\Log\LogLevel::WARNING);
192 unset(
$options[
'type_subtype_pair']);
206 protected function normalizeMetadataOptions(array
$options = []): array {
211 'metadata_name_value_pair',
218 'metadata_created_after',
219 'metadata_created_before',
222 foreach ($props as $prop) {
223 if (isset(
$options[$prop]) && empty(
$options[
'metadata_name_value_pairs'])) {
224 $options[
'metadata_name_value_pairs'][] = [
230 foreach (
$options[
'metadata_name_value_pairs'] as
$key => $pair) {
231 if ($pair instanceof Clause) {
235 foreach ($props as $prop) {
236 if (!isset($pair[$prop])) {
244 $options[
'metadata_name_value_pairs'] = $this->removeKeyPrefix(
'metadata_',
$options[
'metadata_name_value_pairs']);
246 foreach (
$options[
'metadata_name_value_pairs'] as
$key => $pair) {
247 if ($pair instanceof WhereClause) {
251 $class = MetadataWhereClause::class;
253 $class = AttributeWhereClause::class;
256 $pair = $this->normalizePluralOptions($pair, [
'name',
'value']);
258 $options[
'metadata_name_value_pairs'][
$key] = $class::factory($pair);
272 protected function normalizeMetadataSearchOptions(array
$options = []): array {
273 $options = $this->normalizePluralOptions(
$options, [
'search_name_value_pair']);
277 foreach (
$options[
'search_name_value_pairs'] as
$key => $pair) {
278 if ($pair instanceof Clause) {
285 $options[
'search_name_value_pairs'] = $this->removeKeyPrefix(
'metadata_',
$options[
'search_name_value_pairs']);
287 foreach (
$options[
'search_name_value_pairs'] as
$key => $pair) {
288 if ($pair instanceof WhereClause) {
292 $class = MetadataWhereClause::class;
294 $class = AttributeWhereClause::class;
297 $pair = $this->normalizePluralOptions($pair, [
'name',
'value']);
299 $options[
'search_name_value_pairs'][
$key] = $class::factory($pair);
312 protected function normalizeAnnotationOptions(array
$options = []): array {
317 'annotation_name_value_pair',
324 'annotation_owner_guids',
325 'annotation_created_after',
326 'annotation_created_before',
327 'annotation_sort_by_calculation',
330 foreach ($props as $prop) {
331 if (isset(
$options[$prop]) && empty(
$options[
'annotation_name_value_pairs'])) {
332 $options[
'annotation_name_value_pairs'][] = [
338 foreach (
$options[
'annotation_name_value_pairs'] as
$key => $pair) {
339 if ($pair instanceof WhereClause) {
343 foreach ($props as $prop) {
344 if (!isset($pair[$prop])) {
352 $options[
'annotation_name_value_pairs'] = $this->removeKeyPrefix(
'annotation_',
$options[
'annotation_name_value_pairs']);
354 foreach (
$options[
'annotation_name_value_pairs'] as
$key => $pair) {
355 if ($pair instanceof WhereClause) {
359 $pair = $this->normalizePluralOptions($pair, [
'name',
'value']);
361 if (!empty($pair[
'sort_by_calculation']) && empty(
$options[
'order_by'])) {
362 $pair[
'sort_by_direction'] =
'desc';
379 protected function normalizePairedOptions(
string $type =
'metadata', array
$options = []): array {
380 if (!is_array(
$options[
"{$type}_name_value_pairs"])) {
381 $options[
"{$type}_name_value_pairs"] = [];
394 if (isset(
$options[
"{$type}_name_value_pairs"][
'name'])) {
395 $options[
"{$type}_name_value_pairs"][] = [
396 'name' =>
$options[
"{$type}_name_value_pairs"][
'name'],
399 'case_sensitive' =>
elgg_extract(
'case_sensitive',
$options[
"{$type}_name_value_pairs"], $case_sensitive_default)
402 unset(
$options[
"{$type}_name_value_pairs"][
'name']);
403 unset(
$options[
"{$type}_name_value_pairs"][
'value']);
404 unset(
$options[
"{$type}_name_value_pairs"][
'operand']);
405 unset(
$options[
"{$type}_name_value_pairs"][
'case_sensitive']);
419 foreach (
$options[
"{$type}_name_value_pairs"] as
$index => $pair) {
420 if (is_array($pair)) {
421 $keys = array_keys($pair);
425 'value' => $pair[
$keys[0]],
439 foreach (
$options[
"{$type}_name_value_pairs"] as
$index => $values) {
440 if ($values instanceof Clause) {
444 if (is_array($values)) {
445 if (isset($values[
'name']) || isset($values[
'value'])) {
457 if (isset(
$options[
"{$type}_names"]) || isset(
$options[
"{$type}_values"])) {
458 $options[
"{$type}_name_value_pairs"][] = [
459 'name' => isset(
$options[
"{$type}_names"]) ? (array)
$options[
"{$type}_names"] :
null,
460 'value' => isset(
$options[
"{$type}_values"]) ? (array)
$options[
"{$type}_values"] :
null,
466 if (
$value instanceof Clause) {
470 if (!isset(
$value[
'case_sensitive'])) {
471 $value[
'case_sensitive'] = $case_sensitive_default;
474 if (isset(
$value[
'type'])) {
479 if (!isset(
$value[
'value_type'])) {
480 if (isset(
$value[
'value']) && is_bool(
$value[
'value'])) {
484 if (isset(
$value[
'value']) && is_int(
$value[
'value'])) {
491 if (!isset(
$value[
'comparison']) && isset(
$value[
'operand'])) {
501 unset(
$options[
"{$type}_case_sensitive"]);
513 protected function normalizeRelationshipOptions(array
$options = []): array {
515 'relationship_ids' => null,
516 'relationship' => null,
517 'relationship_guid' => null,
518 'inverse_relationship' => false,
519 'relationship_join_on' =>
'guid',
520 'relationship_created_after' => null,
521 'relationship_created_before' => null,
525 foreach (array_keys(
$defaults) as $prop) {
527 $simple_pair[$prop] =
$options[$prop];
534 $options[
'relationship_pairs'][] = $simple_pair;
536 foreach (
$options[
'relationship_pairs'] as
$index => $relationship_pair) {
537 if ($relationship_pair instanceof WhereClause) {
544 $options[
'relationship_pairs'] = $this->removeKeyPrefix(
'relationship_',
$options[
'relationship_pairs']);
546 foreach (
$options[
'relationship_pairs'] as
$key => $pair) {
547 if ($pair instanceof WhereClause) {
551 if (!$pair[
'relationship'] && !$pair[
'guid'] && !$pair[
'ids']) {
557 'ids' => $pair[
'ids'],
558 'names' => $pair[
'relationship'],
559 'join_on' => $pair[
'join_on'],
560 'inverse' => $pair[
'inverse_relationship'],
561 'created_after' => $pair[
'created_after'],
562 'created_before' => $pair[
'created_before'],
563 'guid_two' => $pair[
'inverse_relationship'] ? $pair[
'guid'] :
null,
564 'guid_one' => !$pair[
'inverse_relationship'] ? $pair[
'guid'] :
null,
578 protected function normalizeGuidOptions(array
$options = []): array {
583 'annotation_owner_guid',
590 'annotation_owner_guids',
594 foreach ($names as
$name) {
620 protected function normalizeTimeOptions(array
$options = []): array {
626 'annotation_created',
627 'relationship_created',
632 $bounds = [
'time_lower',
'time_upper',
'after',
'before'];
634 foreach ($props as $prop) {
635 foreach ($bounds as $bound) {
636 $prop_name =
"{$prop}_{$bound}";
643 $new_prop_name = $prop_name;
644 $new_prop_name = str_replace(
'modified',
'updated', $new_prop_name);
645 $new_prop_name = str_replace(
'posted',
'created', $new_prop_name);
646 $new_prop_name = str_replace(
'time_lower',
'after', $new_prop_name);
647 $new_prop_name = str_replace(
'time_upper',
'before', $new_prop_name);
649 if ($new_prop_name === $prop_name) {
654 if (!isset(
$options[$new_prop_name])) {
655 elgg_deprecated_notice(
"Using the option '{$prop_name}' is deprecated. Update your code to use '{$new_prop_name}' instead.",
'6.3');
675 protected function removeKeyPrefix(
string $prefix, array $array = []): array {
678 if (str_starts_with(
$key, $prefix)) {
679 $new_key = substr(
$key, strlen($prefix));
682 if (!isset($array[$new_key])) {
683 $array[$new_key] =
$value;
686 if ($new_key !==
$key) {
690 if (is_array($array[$new_key])) {
691 $array[$new_key] = $this->removeKeyPrefix($prefix, $array[$new_key]);
705 protected function normalizeJoinClauses(array
$options = []): array {
723 if ($join instanceof JoinClause) {
727 if (is_string($join)) {
728 preg_match(
'/((LEFT|INNER|RIGHT)\s+)?JOIN\s+(.*?)\s+((as\s+)?(.*?)\s+)ON\s+(.*)$/im', $join, $parts);
730 $type = !empty($parts[2]) ? strtolower($parts[2]) :
'inner';
733 $condition = preg_replace(
'/\r|\n/',
'', $parts[7]);
740 $clause =
new JoinClause(
$table, $alias, $condition,
$type);
755 protected function normalizeOrderByClauses(array
$options = []): array {
759 if (!empty($orders)) {
760 if (is_string($orders)) {
761 $orders = explode(
',', $orders);
762 }
elseif (!is_array($orders)) {
766 foreach ($orders as $order) {
767 if ($order instanceof OrderByClause) {
772 $order = trim($order);
774 if (preg_match(
'/(.*)(?=\s+(asc|desc))/i', $order, $parts)) {
776 $direction = $parts[2];
787 if (!is_array($sort_by)) {
791 if (isset($sort_by[
'property'])) {
796 foreach (
$options[
'sort_by'] as $sort_spec) {
797 $clause =
new EntitySortByClause();
798 $clause->property =
elgg_extract(
'property', $sort_spec);
799 $clause->property_type =
elgg_extract(
'property_type', $sort_spec);
800 $clause->join_type =
elgg_extract(
'join_type', $sort_spec,
'inner');
801 $clause->direction =
elgg_extract(
'direction', $sort_spec);
803 $clause->inverse_relationship =
elgg_extract(
'inverse_relationship', $sort_spec);
804 $clause->relationship_guid =
elgg_extract(
'relationship_guid', $sort_spec);
821 protected function normalizeQueryClauses(array
$options = []): array {
825 'group_by' => GroupByClause::class,
826 'having' => HavingClause::class,
827 'selects' => SelectClause::class,
828 'wheres' => WhereClause::class,
831 foreach ($clauses as $clause_key => $class_name) {
837 if (!is_array(
$options[$clause_key])) {
842 if ($expr instanceof $class_name) {
870 public static function normalizePluralOptions(array
$options, array $singulars): array {
871 foreach ($singulars as $singular) {
872 $plural = $singular .
's';
874 if (array_key_exists($singular,
$options)) {
879 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.
static factory(array $attributes)
Build a new AnnotationWhereClause.
Builds queries 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.
static factory(array $attributes)
Build a new RelationshipWhereClause.
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_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
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.