25 trait LegacyQueryOptionsAdapter {
34 public function normalizeOptions(array
$options = []): array {
61 protected function getDefaults(): array {
65 'type_subtype_pairs' => null,
67 'owner_guids' => null,
68 'container_guids' => null,
71 'created_after' => null,
72 'created_before' => null,
73 'updated_after' => null,
74 'updated_before' => null,
75 'last_action_after' => null,
76 'last_action_before' => null,
90 'metadata_name_value_pairs' => null,
91 'metadata_name_value_pairs_operator' =>
'AND',
92 'metadata_case_sensitive' => true,
93 'metadata_ids' => null,
94 'metadata_created_after' => null,
95 'metadata_created_before' => null,
96 'metadata_calculation' => null,
98 'search_name_value_pairs' => null,
100 'annotation_names' => null,
101 'annotation_values' => null,
102 'annotation_name_value_pairs' => null,
103 'annotation_name_value_pairs_operator' =>
'AND',
104 'annotation_case_sensitive' => true,
105 'annotation_ids' => null,
106 'annotation_created_after' => null,
107 'annotation_created_before' => null,
108 'annotation_owner_guids' => null,
109 'annotation_calculation' => null,
111 'relationship_pairs' => [],
113 'relationship' => null,
114 'relationship_guid' => null,
115 'inverse_relationship' => false,
116 'relationship_join_on' =>
'guid',
117 'relationship_created_after' => null,
118 'relationship_created_before' => null,
120 'preload_owners' => false,
121 'preload_containers' => false,
126 'batch_inc_offset' => true,
138 protected function normalizeAccessOptions(array
$options = []): array {
150 protected function normalizeTypeSubtypeOptions(array
$options = []): array {
156 if (isset(
$options[
'type_subtype_pairs'])) {
158 }
else if (isset(
$options[
'types'])) {
159 $options[
'type_subtype_pairs'] = [];
165 }
else if (isset(
$options[
'subtypes'])) {
166 throw new InvalidArgumentException(
'If filtering for entity subtypes it is required to provide one or more entity types.');
169 if (isset(
$options[
'type_subtype_pairs']) && is_array(
$options[
'type_subtype_pairs'])) {
172 elgg_log(
"'$type' is not a valid entity type", \Psr\Log\LogLevel::WARNING);
194 protected function normalizeMetadataOptions(array
$options = []): array {
199 'metadata_name_value_pair',
206 'metadata_created_after',
207 'metadata_created_before',
210 foreach ($props as $prop) {
211 if (isset(
$options[$prop]) && empty(
$options[
'metadata_name_value_pairs'])) {
212 $options[
'metadata_name_value_pairs'][] = [
218 foreach (
$options[
'metadata_name_value_pairs'] as
$key => $pair) {
219 if ($pair instanceof Clause) {
223 foreach ($props as $prop) {
224 if (!isset($pair[$prop])) {
232 $options[
'metadata_name_value_pairs'] = $this->removeKeyPrefix(
'metadata_',
$options[
'metadata_name_value_pairs']);
234 foreach (
$options[
'metadata_name_value_pairs'] as
$key => $pair) {
235 if ($pair instanceof WhereClause) {
239 $class = MetadataWhereClause::class;
241 $class = AttributeWhereClause::class;
244 $pair = $this->normalizePluralOptions($pair, [
'name',
'value']);
246 $options[
'metadata_name_value_pairs'][
$key] = $class::factory($pair);
260 protected function normalizeMetadataSearchOptions(array
$options = []): array {
261 $options = $this->normalizePluralOptions(
$options, [
'search_name_value_pair']);
265 foreach (
$options[
'search_name_value_pairs'] as
$key => $pair) {
266 if ($pair instanceof Clause) {
273 $options[
'search_name_value_pairs'] = $this->removeKeyPrefix(
'metadata_',
$options[
'search_name_value_pairs']);
275 foreach (
$options[
'search_name_value_pairs'] as
$key => $pair) {
276 if ($pair instanceof WhereClause) {
280 $class = MetadataWhereClause::class;
282 $class = AttributeWhereClause::class;
285 $pair = $this->normalizePluralOptions($pair, [
'name',
'value']);
287 $options[
'search_name_value_pairs'][
$key] = $class::factory($pair);
300 protected function normalizeAnnotationOptions(array
$options = []): array {
305 'annotation_name_value_pair',
312 'annotation_owner_guids',
313 'annotation_created_after',
314 'annotation_created_before',
315 'annotation_sort_by_calculation',
318 foreach ($props as $prop) {
319 if (isset(
$options[$prop]) && empty(
$options[
'annotation_name_value_pairs'])) {
320 $options[
'annotation_name_value_pairs'][] = [
326 foreach (
$options[
'annotation_name_value_pairs'] as
$key => $pair) {
327 if ($pair instanceof WhereClause) {
331 foreach ($props as $prop) {
332 if (!isset($pair[$prop])) {
340 $options[
'annotation_name_value_pairs'] = $this->removeKeyPrefix(
'annotation_',
$options[
'annotation_name_value_pairs']);
342 foreach (
$options[
'annotation_name_value_pairs'] as
$key => $pair) {
343 if ($pair instanceof WhereClause) {
347 $pair = $this->normalizePluralOptions($pair, [
'name',
'value']);
349 if (!empty($pair[
'sort_by_calculation']) && empty(
$options[
'order_by'])) {
350 $pair[
'sort_by_direction'] =
'desc';
367 protected function normalizePairedOptions(
string $type =
'metadata', array
$options = []): array {
368 if (!is_array(
$options[
"{$type}_name_value_pairs"])) {
369 $options[
"{$type}_name_value_pairs"] = [];
382 if (isset(
$options[
"{$type}_name_value_pairs"][
'name'])) {
383 $options[
"{$type}_name_value_pairs"][] = [
384 'name' =>
$options[
"{$type}_name_value_pairs"][
'name'],
387 'case_sensitive' =>
elgg_extract(
'case_sensitive',
$options[
"{$type}_name_value_pairs"], $case_sensitive_default)
390 unset(
$options[
"{$type}_name_value_pairs"][
'name']);
391 unset(
$options[
"{$type}_name_value_pairs"][
'value']);
392 unset(
$options[
"{$type}_name_value_pairs"][
'operand']);
393 unset(
$options[
"{$type}_name_value_pairs"][
'case_sensitive']);
407 foreach (
$options[
"{$type}_name_value_pairs"] as
$index => $pair) {
408 if (is_array($pair)) {
409 $keys = array_keys($pair);
413 'value' => $pair[
$keys[0]],
427 foreach (
$options[
"{$type}_name_value_pairs"] as
$index => $values) {
428 if ($values instanceof Clause) {
432 if (is_array($values)) {
433 if (isset($values[
'name']) || isset($values[
'value'])) {
445 if (isset(
$options[
"{$type}_names"]) || isset(
$options[
"{$type}_values"])) {
446 $options[
"{$type}_name_value_pairs"][] = [
447 'name' => isset(
$options[
"{$type}_names"]) ? (array)
$options[
"{$type}_names"] :
null,
448 'value' => isset(
$options[
"{$type}_values"]) ? (array)
$options[
"{$type}_values"] :
null,
454 if (
$value instanceof Clause) {
458 if (!isset(
$value[
'case_sensitive'])) {
459 $value[
'case_sensitive'] = $case_sensitive_default;
462 if (isset(
$value[
'type'])) {
467 if (!isset(
$value[
'value_type'])) {
468 if (isset(
$value[
'value']) && is_bool(
$value[
'value'])) {
472 if (isset(
$value[
'value']) && is_int(
$value[
'value'])) {
479 if (!isset(
$value[
'comparison']) && isset(
$value[
'operand'])) {
489 unset(
$options[
"{$type}_case_sensitive"]);
501 protected function normalizeRelationshipOptions(array
$options = []): array {
503 'relationship_ids' => null,
504 'relationship' => null,
505 'relationship_guid' => null,
506 'inverse_relationship' => false,
507 'relationship_join_on' =>
'guid',
508 'relationship_created_after' => null,
509 'relationship_created_before' => null,
513 foreach (array_keys(
$defaults) as $prop) {
515 $simple_pair[$prop] =
$options[$prop];
522 $options[
'relationship_pairs'][] = $simple_pair;
524 foreach (
$options[
'relationship_pairs'] as
$index => $relationship_pair) {
525 if ($relationship_pair instanceof WhereClause) {
532 $options[
'relationship_pairs'] = $this->removeKeyPrefix(
'relationship_',
$options[
'relationship_pairs']);
534 foreach (
$options[
'relationship_pairs'] as
$key => $pair) {
535 if ($pair instanceof WhereClause) {
539 if (!$pair[
'relationship'] && !$pair[
'guid'] && !$pair[
'ids']) {
545 'ids' => $pair[
'ids'],
546 'names' => $pair[
'relationship'],
547 'join_on' => $pair[
'join_on'],
548 'inverse' => $pair[
'inverse_relationship'],
549 'created_after' => $pair[
'created_after'],
550 'created_before' => $pair[
'created_before'],
551 'guid_two' => $pair[
'inverse_relationship'] ? $pair[
'guid'] :
null,
552 'guid_one' => !$pair[
'inverse_relationship'] ? $pair[
'guid'] :
null,
566 protected function normalizeGuidOptions(array
$options = []): array {
571 'annotation_owner_guid',
578 'annotation_owner_guids',
582 foreach ($names as
$name) {
609 protected function removeKeyPrefix(
string $prefix, array $array = []): array {
612 if (str_starts_with(
$key, $prefix)) {
613 $new_key = substr(
$key, strlen($prefix));
616 if (!isset($array[$new_key])) {
617 $array[$new_key] =
$value;
620 if ($new_key !==
$key) {
624 if (is_array($array[$new_key])) {
625 $array[$new_key] = $this->removeKeyPrefix($prefix, $array[$new_key]);
639 protected function normalizeJoinClauses(array
$options = []): array {
657 if ($join instanceof JoinClause) {
661 if (is_string($join)) {
662 preg_match(
'/((LEFT|INNER|RIGHT)\s+)?JOIN\s+(.*?)\s+((as\s+)?(.*?)\s+)ON\s+(.*)$/im', $join, $parts);
664 $type = !empty($parts[2]) ? strtolower($parts[2]) :
'inner';
667 $condition = preg_replace(
'/\r|\n/',
'', $parts[7]);
674 $clause =
new JoinClause(
$table, $alias, $condition,
$type);
689 protected function normalizeOrderByClauses(array
$options = []): array {
693 if (!empty($orders)) {
694 if (is_string($orders)) {
695 $orders = explode(
',', $orders);
696 }
elseif (!is_array($orders)) {
700 foreach ($orders as $order) {
701 if ($order instanceof OrderByClause) {
706 $order = trim($order);
708 if (preg_match(
'/(.*)(?=\s+(asc|desc))/i', $order, $parts)) {
710 $direction = $parts[2];
721 if (!is_array($sort_by)) {
725 if (isset($sort_by[
'property'])) {
730 foreach (
$options[
'sort_by'] as $sort_spec) {
731 $clause =
new EntitySortByClause();
732 $clause->property =
elgg_extract(
'property', $sort_spec);
733 $clause->property_type =
elgg_extract(
'property_type', $sort_spec);
734 $clause->join_type =
elgg_extract(
'join_type', $sort_spec,
'inner');
735 $clause->direction =
elgg_extract(
'direction', $sort_spec);
737 $clause->inverse_relationship =
elgg_extract(
'inverse_relationship', $sort_spec);
738 $clause->relationship_guid =
elgg_extract(
'relationship_guid', $sort_spec);
755 protected function normalizeQueryClauses(array
$options = []): array {
759 'group_by' => GroupByClause::class,
760 'having' => HavingClause::class,
761 'selects' => SelectClause::class,
762 'wheres' => WhereClause::class,
765 foreach ($clauses as $clause_key => $class_name) {
771 if (!is_array(
$options[$clause_key])) {
776 if ($expr instanceof $class_name) {
804 public static function normalizePluralOptions(array
$options, array $singulars): array {
805 foreach ($singulars as $singular) {
806 $plural = $singular .
's';
808 if (array_key_exists($singular,
$options)) {
813 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_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.