/** * @TODO - is there a way we can target them directly instead of iterating through all? * * @param type $h * @param type $t * @param type $r * @param type $p * @return type */ function weekly_cron($h, $t, $r, $p) { $ia = elgg_set_ignore_access(true); // check for abandoned acls $dbprefix = elgg_get_config('dbprefix'); // try to make this as light as possible $options = array('type' => 'object', 'subtype' => 'granular_access', 'limit' => false); $batch = new ElggBatch('elgg_get_entities', $options); foreach ($batch as $b) { $sql = "SELECT COUNT(guid) as total FROM {$dbprefix}entities WHERE access_id = {$b->acl_id}"; $result = get_data($sql); if ($result[0]->total) { continue; } $sql = "SELECT COUNT(id) as total FROM {$dbprefix}metadata WHERE access_id = {$b->acl_id}"; $result = get_data($sql); if ($result[0]->total) { continue; } $sql = "SELECT COUNT(id) as total FROM {$dbprefix}annotations WHERE access_id = {$b->acl_id}"; $result = get_data($sql); if ($result[0]->total) { continue; } // this appears to be orphaned delete_access_collection($b->acl_id); $b->delete(); } elgg_set_ignore_access($ia); return $r; }
/** * Change the default notification message for comments * * @param string $hook the name of the hook * @param stirng $type the type of the hook * @param Elgg_Notifications_Notification $return_value the current return value * @param array $params supplied values * * @return Elgg_Notifications_Notification */ function content_subscriptions_prepare_comment_notification($hook, $type, $return_value, $params) { if (empty($return_value) || !$return_value instanceof \Elgg\Notifications\Notification) { return $return_value; } if (empty($params) || !is_array($params)) { return $return_value; } $event = elgg_extract("event", $params); if (empty($event) || !$event instanceof \Elgg\Notifications\Event) { return $return_value; } // ignore access for now $ia = elgg_set_ignore_access(true); $comment = $event->getObject(); $actor = $event->getActor(); $object = $comment->getContainerEntity(); $language = elgg_extract("language", $params, get_current_language()); $recipient = elgg_extract("recipient", $params); $return_value->subject = elgg_echo("content_subscriptions:create:comment:subject", array($object->title), $language); $return_value->body = elgg_echo("content_subscriptions:create:comment:message", array($recipient->name, $actor->name, $object->title, $comment->description, $object->getURL()), $language); $return_value->summary = elgg_echo("content_subscriptions:create:comment:summary", array($object->title), $language); // restore access elgg_set_ignore_access($ia); return $return_value; }
/** * https://github.com/Elgg/Elgg/pull/6393 * Hook handlers for 'access:collections:write','all' hook should respect * group's content access mode and container write permissions */ public function testWriteAccessArray() { $membersonly = ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY; $unrestricted = ElggGroup::CONTENT_ACCESS_MODE_UNRESTRICTED; $original_page_owner = elgg_get_page_owner_entity(); elgg_set_page_owner_guid($this->group->guid); $ia = elgg_set_ignore_access(false); // User is not a member of the group // Member-only group $this->group->setContentAccessMode($membersonly); $write_access = get_write_access_array($this->user->guid, true); $this->assertFalse(array_key_exists($this->group->group_acl, $write_access)); // Unrestricted group $this->group->setContentAccessMode($unrestricted); $write_access = get_write_access_array($this->user->guid, true); $this->assertFalse(array_key_exists($this->group->group_acl, $write_access)); // User is a member (can write to container) $this->group->join($this->user); // Member-only group $this->group->setContentAccessMode($membersonly); $write_access = get_write_access_array($this->user->guid, true); $this->assertTrue(array_key_exists($this->group->group_acl, $write_access)); // Unrestricted group $this->group->setContentAccessMode($unrestricted); $write_access = get_write_access_array($this->user->guid, true); $this->assertTrue(array_key_exists($this->group->group_acl, $write_access)); elgg_set_ignore_access($ia); $this->group->leave($this->user); $original_page_owner_guid = elgg_instanceof($original_page_owner) ? $original_page_owner->guid : 0; elgg_set_page_owner_guid($original_page_owner_guid); }
function group_tools_join_site_handler($event, $type, $relationship) { if (!empty($relationship) && $relationship instanceof ElggRelationship) { $user_guid = $relationship->guid_one; $site_guid = $relationship->guid_two; if ($user = get_user($user_guid)) { // ignore access $ia = elgg_set_ignore_access(true); // add user to the auto join groups if ($auto_joins = elgg_get_plugin_setting("auto_join", "group_tools")) { $auto_joins = string_to_tag_array($auto_joins); foreach ($auto_joins as $group_guid) { if (($group = get_entity($group_guid)) && $group instanceof ElggGroup) { if ($group->site_guid == $site_guid) { // join the group $group->join($user); } } } } // auto detect email invited groups if ($groups = group_tools_get_invited_groups_by_email($user->email, $site_guid)) { foreach ($groups as $group) { // join the group $group->join($user); } } // restore access settings elgg_set_ignore_access($ia); } } }
function river_activity_3C_bday_mailer($hook, $entity_type, $returnvalue, $params) { $bday = elgg_get_plugin_setting('birth_day', 'river_activity_3C'); elgg_set_ignore_access(true); $siteurl = elgg_get_site_entity()->url; $sitename = elgg_get_site_entity()->name; $siteemail = elgg_get_site_entity()->email; $from = $sitename . ' <' . $siteemail . '>'; $month = date('m', strtotime("now")); $options = array('metadata_names' => 'BD_month', 'metadata_values' => $month, 'types' => 'user', 'limit' => false, 'full_view' => false, 'pagination' => false); $bd_users = new ElggBatch('elgg_get_entities_from_metadata', $options); $bd_today = date('j, F', strtotime('now')); foreach ($bd_users as $bd_user) { $bd_name = $bd_user->name; $bd_email = $bd_user->email; $bd_day = date('j, F', strtotime($bd_user->{$bday})); if ($bd_day == $bd_today) { if ($bd_email) { $message = elgg_echo('river_activity_3C:bday_message', array($bd_name, $bd_day, $sitename, $siteurl)); elgg_send_email($from, $bd_email, elgg_echo('river_activity_3C:bday_message:subject'), $message); $result = elgg_echo("river_activity_3C:bday_mailer_cron_true"); } else { $result = elgg_echo("river_activity_3C:bday_mailer_cron_false"); } } } elgg_set_ignore_access(false); return $returnvalue . $result; }
/** * Checks if additional select columns are readable as volatile data even if we hit the cache while fetching entity. * * https://github.com/Elgg/Elgg/issues/5544 */ public function testSqlAdditionalSelectsAsVolatileDataWithCache() { // remove ignore access as it disables entity cache $access = elgg_set_ignore_access(false); // may not have groups in DB - let's create one $group = new ElggGroup(); $group->name = 'test_group'; $group->access_id = ACCESS_PUBLIC; $this->assertTrue($group->save() !== false); foreach (array('site', 'user', 'group', 'object') as $type) { $entities = elgg_get_entities(array('type' => $type, 'selects' => array('42 as added_col3'), 'limit' => 1)); $entity = array_shift($entities); $this->assertTrue($entity instanceof ElggEntity); $this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity)); $this->assertEqual($entity->getVolatileData('select:added_col3'), 42); // make sure we have cached the entity $this->assertNotEqual(false, _elgg_retrieve_cached_entity($entity->guid)); } // run these again but with different value to make sure cache does not interfere foreach (array('site', 'user', 'group', 'object') as $type) { $entities = elgg_get_entities(array('type' => $type, 'selects' => array('64 as added_col3'), 'limit' => 1)); $entity = array_shift($entities); $this->assertTrue($entity instanceof ElggEntity); $this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity)); $this->assertEqual($entity->getVolatileData('select:added_col3'), 64, "Failed to overwrite volatile data in cached entity"); } elgg_set_ignore_access($access); $group->delete(); }
function current_dokuwiki_entity($create = true) { $page_owner = elgg_get_page_owner_guid(); $user = elgg_get_logged_in_user_entity(); //error_log($page_owner->guid); //error_log($user->guid); if (!$page_owner) { $page_owner = 0; } $entities = elgg_get_entities(array('types' => 'object', 'subtypes' => 'dokuwiki', 'limit' => 1, 'owner_guid' => $page_owner)); if ($entities) { $doku = $entities[0]; return $doku; } elseif ($user && $create) { elgg_set_ignore_access(true); $newdoku = new ElggObject(); $newdoku->access_id = ACCESS_PUBLIC; $newdoku->owner_guid = $page_owner; $newdoku->subtype = 'dokuwiki'; $newdoku->container_guid = $page_owner; $newdoku->save(); $acl = array(); $acl[] = "# acl.auth.php"; $acl[] = '# <?php exit()?\\>'; $acl[] = "* @ALL 0"; $acl[] = "* @user 1"; $acl[] = "* @member 8"; $acl[] = "* @admin 16"; $acl[] = "* @root 255"; $newdoku->wiki_acl = implode("\n", $acl) . "\n"; elgg_set_ignore_access(false); return $newdoku; } }
/** * The cron hook will take care of sending all the scheduled newsletters * * @param string $hook name of the hook * @param string $type type of the hook * @param string $returnvalue returnvalue of the hook * @param array $params params of the hook * * @return void */ function newsletter_cron_handler($hook, $type, $returnvalue, $params) { if (!empty($params) && is_array($params)) { $cron_ts = elgg_extract("time", $params, time()); // check for time drift if (date("i", $cron_ts) >= 30) { // example of the time: 14:59:56 // which should be the hourly cron for 15:00:00 $cron_ts = $cron_ts + 30 * 60; } // make the timestamp to an hour $newsletter_ts = mktime(date("H", $cron_ts), 0, 0, date("n", $cron_ts), date("j", $cron_ts), date("Y", $cron_ts)); $options = array("type" => "object", "subtype'" => Newsletter::SUBTYPE, "limit" => false, "metadata_name_value_pairs" => array("name" => "scheduled", "value" => $newsletter_ts)); // ignore access $ia = elgg_set_ignore_access(true); $newsletters = elgg_get_entities_from_metadata($options); // retore access elgg_set_ignore_access($ia); if (!empty($newsletters)) { foreach ($newsletters as $newsletter) { newsletter_start_commandline_sending($newsletter); } } } }
/** * Add menu items to the filter menu * * @param string $hook 'cron' * @param string $type 'daily' * @param string $return_value optional output * @param array $params supplied params * * @return void */ public static function daily($hook, $type, $return_value, $params) { if (!static_out_of_date_enabled()) { return; } $time = elgg_extract('time', $params, time()); $days = (int) elgg_get_plugin_setting('out_of_date_days', 'static'); $site = elgg_get_site_entity(); $options = ['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'limit' => false, 'modified_time_upper' => $time - $days * 24 * 60 * 60, 'modified_time_lower' => $time - ($days + 1) * 24 * 60 * 60, 'order_by' => 'e.time_updated DESC']; // ignore access $ia = elgg_set_ignore_access(true); $batch = new \ElggBatch('elgg_get_entities', $options); $users = []; foreach ($batch as $entity) { $last_editors = $entity->getAnnotations(['annotation_name' => 'static_revision', 'limit' => 1, 'order_by' => 'n_table.time_created DESC']); if (empty($last_editors)) { continue; } $users[$last_editors[0]->getOwnerGUID()] = $last_editors[0]->getOwnerEntity(); } // restore access elgg_set_ignore_access($ia); if (empty($users)) { return; } foreach ($users as $user) { $subject = elgg_echo('static:out_of_date:notification:subject'); $message = elgg_echo('static:out_of_date:notification:message', [$user->name, elgg_normalize_url('static/out_of_date/' . $user->username)]); notify_user($user->getGUID(), $site->getGUID(), $subject, $message, [], 'email'); } }
/** * After the question is updated in the databse make sure the answers have the same access_id * * @param string $event the name of the event * @param string $type the type of the event * @param \ElggObject $entity the affected object * * @return void */ public static function updateQuestion($event, $type, $entity) { if (!$entity instanceof \ElggQuestion) { return; } $org_attributes = $entity->getOriginalAttributes(); if (elgg_extract('access_id', $org_attributes) === null) { // access wasn't updated return; } // ignore access for this part $ia = elgg_set_ignore_access(true); // get all the answers for this question $answers = $entity->getAnswers(['limit' => false]); if (empty($answers)) { // restore access elgg_set_ignore_access($ia); return; } /* @var $answer \ElggAnswer */ foreach ($answers as $answer) { // update the access_id with the questions access_id $answer->access_id = $entity->access_id; $answer->save(); } // restore access elgg_set_ignore_access($ia); }
function westorElggMan_cron_handler($hook, $entity_type, $returnvalue, $params) { global $CONFIG; // old elgg bevore 1.7.0 global $is_admin; $is_admin = true; if (function_exists("elgg_set_ignore_access")) { // new function for access overwrite elgg_set_ignore_access(true); } $context = westorElggMan_get_context(); westorElggMan_set_context('westorElggMan'); $prefix = $CONFIG->dbprefix; $sql = "SELECT {$prefix}metadata.entity_guid\nFROM (({$prefix}metadata AS {$prefix}metadata_1 INNER JOIN {$prefix}metastrings AS {$prefix}metastrings_3\nON {$prefix}metadata_1.name_id = {$prefix}metastrings_3.id) INNER JOIN {$prefix}metastrings\nAS {$prefix}metastrings_2 ON {$prefix}metadata_1.value_id = {$prefix}metastrings_2.id) INNER JOIN (({$prefix}metadata INNER JOIN {$prefix}metastrings ON {$prefix}metadata.name_id = {$prefix}metastrings.id) INNER JOIN {$prefix}metastrings AS {$prefix}metastrings_1 ON {$prefix}metadata.value_id = {$prefix}metastrings_1.id) ON {$prefix}metadata_1.entity_guid = {$prefix}metadata.entity_guid\nWHERE ((({$prefix}metastrings.string)='waitForSend') AND (({$prefix}metastrings_1.string)='1')\nAND (({$prefix}metastrings_3.string)='hiddenTo') AND (({$prefix}metastrings_2.string)<>'1'))"; // and (scheduled is null || scheduled <= now()); try { $result = get_data($sql); } catch (Exception $e) { westorElggMan_set_context($context); throw new Exception($e); } if (is_array($result)) { $elggMan = new class_elggMan(); $now = date("Y-m-d H:i:s"); foreach ($result as $row) { $message = westorElggMan_get_entity($row->entity_guid); if (is_object($message) && $message->getSubtype() == "messages" && ($message->scheduled == null || $message->scheduled <= $now)) { $elggMan->sendMsgNow($message); } } } westorElggMan_set_context($context); }
/** * Retrieve ancestry relationships / update if they have changed * * @param int $guid * @param mixed $subtypes * @return boolean|array */ function hj_framework_set_ancestry($guid) { $entity = get_entity($guid); if (!$entity) { return false; } $ia = elgg_set_ignore_access(true); // Build an hierarchy from [0]highest to [X]lowest $ancestry = array(); $ancestry_guids = array(); $container = $entity->getContainerEntity(); while (elgg_instanceof($container)) { array_unshift($ancestry, $container); array_unshift($ancestry_guids, $container->guid); $container = $container->getContainerEntity(); } // Store as a hash so we don't unnecessarily update the hierarchy every time save() is calleed if (!isset($entity->hierarchy_hash) || $entity->hierarchy_hash != sha1(serialize($ancestry_guids))) { remove_entity_relationships($entity->guid, 'descendant', false); foreach ($ancestry as $ancestor) { if (elgg_instanceof($ancestor, 'object')) { update_entity_last_action($ancestor->guid, $entity->time_created); } if (!check_entity_relationship($entity->guid, 'descendant', $ancestor->guid)) { add_entity_relationship($entity->guid, 'descendant', $ancestor->guid); } } $entity->hierarchy_hash = sha1(serialize($ancestry_guids)); } elgg_set_ignore_access($ia); return $ancestry; }
function event_shutdown() { State::$handle_updates = false; if (State::$users_leaving_probation) { set_time_limit(0); } $ia = elgg_set_ignore_access(true); $force_private = elgg_get_plugin_setting(QUARANTINE_PRIVATE, PLUGIN_ID); foreach (State::$entities_quarantined as $entity) { if ($entity->{ORIGINAL_ACCESS_ID} === null || $entity->access_id != ACCESS_PRIVATE) { $entity->{ORIGINAL_ACCESS_ID} = $entity->access_id; } if ($force_private) { $entity->access_id = ACCESS_PRIVATE; } elseif ($entity->access_id == ACCESS_PUBLIC) { $entity->access_id = ACCESS_LOGGED_IN; } $entity->save(); } foreach (State::$users_leaving_probation as $user) { $options = ['owner_guid' => $user->guid, 'metadata_name' => QUARANTINED, 'metadata_value' => '1', 'limit' => 0]; $batch = new \ElggBatch('elgg_get_entities_from_metadata', $options, null, 25, false); foreach ($batch as $object) { /* @var \ElggObject $object */ approve_content($object); } } elgg_set_ignore_access($ia); }
/** * Make sure the last editor of a static page gets notified about a comment * * @param string $event 'create' * @param string $type 'object' * @param \ElggObject $object the object that was just created * * @return void */ public static function notifyLastEditor($event, $type, \ElggObject $object) { // check of this is a comment if (empty($object) || !elgg_instanceof($object, 'object', 'comment')) { return; } // is it a comment on a static page $container = $object->getContainerEntity(); if (empty($container) || !elgg_instanceof($container, 'object', 'static')) { return; } $comment_owner = $object->getOwnerEntity(); // get last revisor $ia = elgg_set_ignore_access(true); $revisions = $container->getAnnotations(['annotation_name' => 'static_revision', 'limit' => 1, 'reverse_order_by' => true]); $static_owner = $revisions[0]->getOwnerEntity(); elgg_set_ignore_access($ia); // don't notify yourself if ($static_owner->getGUID() == $comment_owner->getGUID()) { return; } // @see actions/comment/save $subject = elgg_echo('generic_comment:email:subject'); $message = elgg_echo('generic_comment:email:body', [$container->title, $comment_owner->name, $object->description, $container->getURL(), $comment_owner->name, $comment_owner->getURL()]); $params = ['object' => $object, 'action' => 'create']; notify_user($static_owner->getGUID(), $comment_owner->getGUID(), $subject, $message, $params); }
/** * Check if requested page is a static page * * @param string $hook name of the hook * @param string $type type of the hook * @param array $return_value return value * @param array $params hook parameters * * @return array */ public static function routeAll($hook, $type, $return_value, $params) { if (!is_array($return_value)) { // someone else already routed this page return; } /** * $return_value contains: * $return_value['identifier'] => requested handler * $return_value['segments'] => url parts ($page) */ $identifier = elgg_extract('identifier', $return_value); if (empty($identifier)) { return; } $handlers = _elgg_services()->router->getPageHandlers(); if (elgg_extract($identifier, $handlers)) { return; } $ia = elgg_set_ignore_access(true); $entities = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'limit' => 1, 'metadata_name_value_pairs' => ['friendly_title' => $identifier], 'metadata_case_sensitive' => false]); elgg_set_ignore_access($ia); if (empty($entities)) { return; } $entity = $entities[0]; if (!has_access_to_entity($entity) && !$entity->canEdit()) { return; } $return_value['segments'] = ['view', $entity->getGUID()]; $return_value['identifier'] = 'static'; return $return_value; }
/** * Clean unvalidated users cron hook */ function clean_unvalidate($vars) { $days_till_first_reminder = elgg_get_plugin_setting("validation_reminder_first_message") * 1; $days_till_second_reminder = elgg_get_plugin_setting("validation_reminder_second_message") * 1; $days_till_removal = elgg_get_plugin_setting("validation_reminder_remove") * 1; $proviousAccessShowHiddenEntities = access_show_hidden_entities(true); $proviousIgnoreAccess = elgg_set_ignore_access(true); $dbprefix = elgg_get_config('dbprefix'); // @var $users ElggUser[] $users = elgg_get_entities_from_metadata(['type' => 'user', 'limit' => false, 'metadata_name_value_pair' => array(array('name' => 'validated', 'value' => false))]); foreach ($users as $user) { $validate_reminder_start_date = $user->time_created; if (time() - $validate_reminder_start_date >= $days_till_removal * 24 * 60 * 60) { $user->delete(); echo 'Account deleted'; } else { if (time() - $validate_reminder_start_date >= $days_till_second_reminder * 24 * 60 * 60 && time() - $validate_reminder_start_date <= ($days_till_second_reminder + 1) * 24 * 60 * 60) { send_validation_reminder_mail($user, $days_till_removal, $days_till_second_reminder); echo 'Send second reminder send'; } else { if (time() - $validate_reminder_start_date >= $days_till_first_reminder * 24 * 60 * 60 && time() - $validate_reminder_start_date <= ($days_till_first_reminder + 1) * 24 * 60 * 60) { send_validation_reminder_mail($user, $days_till_removal, $days_till_first_reminder); echo 'Send first reminder send'; } else { echo 'Waiting for validation'; } } } echo ' for user: '******'<br>'; } elgg_set_ignore_access($proviousIgnoreAccess); access_show_hidden_entities($proviousAccessShowHiddenEntities); }
public function countAttendees($count = true) { $old_ia = elgg_set_ignore_access(true); $entities = elgg_get_entities_from_relationship(array('relationship' => ZHAOHU_MANAGER_RELATION_ATTENDING, 'relationship_guid' => $this->getGUID(), 'inverse_relationship' => FALSE, 'count' => $count)); elgg_set_ignore_access($old_ia); return $entities; }
/** * Migrates old (pre MenuBuilder 2.0) menu entities to json * * @return void */ public static function migrateEntitiesToJSON() { $ia = elgg_set_ignore_access(true); $menu = new \ColdTrick\MenuBuilder\Menu('site'); $menu->save(); $options = ['type' => 'object', 'subtype' => 'menu_builder_menu_item', 'limit' => false]; $entities = elgg_get_entities($options); if (empty($entities)) { elgg_set_ignore_access($ia); return; } foreach ($entities as $menu_item) { $parent_name = null; $parent_guid = $menu_item->parent_guid; if ($parent_guid) { $parent = get_entity($parent_guid); if ($parent) { $parent_name = "menu_name_{$parent_guid}"; } } $menu->addMenuItem(['name' => "menu_name_{$menu_item->guid}", 'text' => $menu_item->title, 'href' => $menu_item->url, 'target' => $menu_item->target, 'is_action' => $menu_item->is_action, 'access_id' => $menu_item->access_id, 'priority' => $menu_item->order, 'parent_name' => $parent_name]); } // delete entities need to do it afterwards as parents are not always available otherwise foreach ($entities as $menu_item) { $menu_item->delete(); } elgg_set_ignore_access($ia); }
/** * Called after each test object. */ public function __destruct() { $this->user->delete(); $this->user2->delete(); $this->apikey->delete(); elgg_set_ignore_access($this->ia); // all __destruct() code should go above here parent::__destruct(); }
/** * Save the subscription to the database * * @return bool * * @see ElggObject::save() */ public function save() { // ignore access restrictions $ia = elgg_set_ignore_access(true); $result = parent::save(); // restore access elgg_set_ignore_access($ia); return $result; }
/** * Listen to the creation of metadata * * @param string $event the name of the event * @param string $type the type of the event * @param ElggMetadata $metadata supplied metadata * * @return void */ function tag_tools_create_metadata_event_handler($event, $type, $metadata) { if (empty($metadata) || !$metadata instanceof ElggMetadata) { return; } // is it a tag if ($metadata->name != 'tags') { return; } // get the entity for further use $ia = elgg_set_ignore_access(true); $entity_guid = $metadata->entity_guid; // can't use elgg get entity because cache is not correctly updated $entity_row = get_entity_as_row($entity_guid); elgg_set_ignore_access($ia); // shortcut for private entities if ($entity_row->access_id == ACCESS_PRIVATE) { return; } // only send notifications on creation of the entity $time_created_treshold = 5; if ($entity_row->time_created < time() - $time_created_treshold) { // assume it is an update return; } // check of the entity is allowed for notifications if (!tag_tools_is_notification_entity($entity_row->guid)) { return; } $tag = $metadata->value; $options = ['type' => 'user', 'annotation_name_value_pairs' => ['name' => 'follow_tag', 'value' => $tag], 'limit' => false]; $ia = elgg_set_ignore_access(true); $dbprefix = elgg_get_config('dbprefix'); $entities = new ElggBatch('elgg_get_entities_from_annotations', $options); foreach ($entities as $user) { // check if not trying to notify the owner if ($user->getGUID() == $entity_row->owner_guid) { continue; } // force a correct access bit elgg_set_ignore_access(false); // check access for the user, can't use has_access_to_entity // because that requires a full entity $access_bit = _elgg_get_access_where_sql(['user_guid' => $user->getGUID()]); // ignore access to get the correct next user elgg_set_ignore_access(true); // build correct query to check access $query = "SELECT guid FROM {$dbprefix}entities e\n\t\t\t WHERE e.guid = {$entity_guid}\n\t\t\t AND {$access_bit}"; if (get_data($query)) { // regsiter shutdown function because we need the full entity // this is a workaround and should be reviewed in the near future register_shutdown_function('tag_tools_notify_user', $user->getGUID(), $entity_row->guid, $tag); } } elgg_set_ignore_access($ia); }
/** * Flush menu tree cache for root page * * @param string $event the name of the event * @param string $type the type of the event * @param ElggObject $object the object affected * * @return void */ function pages_tools_cache_handler($event, $type, ElggObject $object) { if (!pages_tools_is_valid_page($object)) { return; } $ia = elgg_set_ignore_access(true); $root_page = pages_tools_get_root_page($object); pages_tools_flush_tree_html_cache($root_page); elgg_set_ignore_access($ia); }
/** * Listen to the cache flush event to invalidate cache of widgets content * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied param * * @return void */ public static function resetWidgetsCache($event, $type, $object) { $ia = elgg_set_ignore_access(true); $batch = new \ElggBatch('elgg_get_entities_from_private_settings', ['type' => 'object', 'subtype' => 'widget', 'limit' => false, 'private_setting_name' => 'widget_manager_cached_data']); $batch->setIncrementOffset(false); foreach ($batch as $entity) { $entity->removePrivateSetting('widget_manager_cached_data'); } elgg_set_ignore_access($ia); }
/** * fix the global count due to messages structure differences * * @param type $hook * @param type $type * @param type $return * @param type $params */ function messages_count_correction($hook, $type, $return, $params) { if (!isset($params['subtypes']) || $params['subtypes'][0] != 'messages') { return $return; } $from_guid = elgg_get_logged_in_user_guid(); $ia = elgg_set_ignore_access(true); $right_messages = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'messages', 'metadata_name_value_pairs' => array('name' => 'fromId', 'value' => $from_guid), 'wheres' => array("e.owner_guid != {$from_guid}"), 'created_time_lower' => $params['created_time_lower'], 'count' => true)); elgg_set_ignore_access($ia); return $right_messages; }
/** * Set the current rating for an entity * * @param object $entity The entity to set the rating on * @return array Includes the current rating and number of votes */ function elggx_fivestar_set_rating(ElggEntity $entity) { $result = false; if (!empty($entity) && elgg_instanceof($entity)) { $access = elgg_set_ignore_access(true); $rating = elggx_fivestar_get_rating($entity->getGUID()); $entity->elggx_fivestar_rating = (double) elgg_extract("rating", $rating, 0); elgg_set_ignore_access($access); } return $result; }
function pleio_rest_created_river_async($river_id) { $ia = elgg_set_ignore_access(true); $river = elgg_get_river(array('id' => $river_id, 'site_guid' => null)); if (count($river) === 1) { $river = $river[0]; $notHandler = new \PleioRest\Services\PushNotificationHandler(); $notHandler->fanOutNotifications($river); } elgg_set_ignore_access($ia); }
/** * Returns the users waiting for this slot * * @param boolean $count if a count should be returned, or the entity * * @return boolean|int|array */ public function getWaitingUsers($count = false) { $old_ia = elgg_set_ignore_access(true); if ($count) { $result = $this->countEntitiesFromRelationship(EVENT_MANAGER_RELATION_SLOT_REGISTRATION_WAITINGLIST, true); } else { $result = $this->getEntitiesFromRelationship(['relationship' => EVENT_MANAGER_RELATION_SLOT_REGISTRATION_WAITINGLIST, 'inverse_relationship' => true]); } elgg_set_ignore_access($old_ia); return $result; }
/** * (non-PHPdoc) * @see ElggEntity::getURL() */ public function getURL() { // make sure we can get the container $ia = elgg_set_ignore_access(true); // get the container/question $container_entity = $this->getContainerEntity(); $url = $container_entity->getURL() . "#elgg-object-{$this->getGUID()}"; // restore access elgg_set_ignore_access($ia); return $url; }
function elasticsearch_console_sync_all() { global $CONFIG; $CONFIG->memcache = false; ini_set('memory_limit', '1024M'); set_time_limit(0); $ia = elgg_set_ignore_access(true); $interface = ESInterface::get(); $bulksync = new ESBulkSync($interface); $bulksync->sync(); elgg_set_ignore_access($ia); }
/** * Determine visibility of items within a container for the current user * * @param int $container_guid GUID of a container (may/may not be a group) * @param bool $use_cache Use the cached result of * * @return \Elgg\GroupItemVisibility * * @todo Make this faster, considering it must run for every river item. */ public static function factory($container_guid, $use_cache = true) { // cache because this may be called repeatedly during river display, and // due to need to check group visibility, cache will be disabled for some // get_entity() calls static $cache = array(); if (!$container_guid) { return new \Elgg\GroupItemVisibility(); } $user = elgg_get_logged_in_user_entity(); $user_guid = $user ? $user->guid : 0; $container_guid = (int) $container_guid; $cache_key = "{$container_guid}|{$user_guid}"; if (empty($cache[$cache_key]) || !$use_cache) { // compute $container = get_entity($container_guid); $is_visible = (bool) $container; if (!$is_visible) { // see if it *really* exists... $prev_access = elgg_set_ignore_access(); $container = get_entity($container_guid); elgg_set_ignore_access($prev_access); } $ret = new \Elgg\GroupItemVisibility(); if ($container && $container instanceof \ElggGroup) { /* @var \ElggGroup $container */ if ($is_visible) { if ($container->getContentAccessMode() === \ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY) { if ($user) { if (!$container->isMember($user) && !$user->isAdmin()) { $ret->shouldHideItems = true; $ret->reasonHidden = self::REASON_NON_MEMBER; } } else { $ret->shouldHideItems = true; $ret->reasonHidden = self::REASON_LOGGED_OUT; } } } else { $ret->shouldHideItems = true; $ret->reasonHidden = self::REASON_NO_ACCESS; } } $cache[$cache_key] = $ret; } $return = $cache[$cache_key]; // don't exhaust memory in extreme uses if (count($cache) > 500) { reset($cache); unset($cache[key($cache)]); } return $return; }