/** * Updates the answer given by a user * * @param Event $event the event entity used for setting the access of the annotation correctly * @param string $new_answer the new answer * @param string $user_guid guid of the entity giving the answer * * @return void */ public function updateAnswerFromUser($event, $new_answer, $user_guid = null) { if (empty($user_guid)) { $user_guid = elgg_get_logged_in_user_guid(); } $old_answer = $this->getAnswerFromUser($user_guid); if ($old_answer && get_user($user_guid)) { if (!empty($new_answer)) { update_annotation($old_answer->id, "answer_to_event_registration", $new_answer, "", $user_guid, $event->access_id); } else { elgg_delete_annotation_by_id($old_answer->id); } } else { $this->annotate("answer_to_event_registration", $new_answer, $event->access_id, $user_guid); } }
/** * Create a new annotation. * * @param int $entity_guid GUID of entity to be annotated * @param string $name Name of annotation * @param string $value Value of annotation * @param string $value_type Type of value (default is auto detection) * @param int $owner_guid Owner of annotation (default is logged in user) * @param int $access_id Access level of annotation * * @return int|bool id on success or false on failure */ function create_annotation($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE) { global $CONFIG; $result = false; $entity_guid = (int) $entity_guid; $name = trim($name); $value_type = detect_extender_valuetype($value, $value_type); $owner_guid = (int) $owner_guid; if ($owner_guid == 0) { $owner_guid = elgg_get_logged_in_user_guid(); } $access_id = (int) $access_id; $time = time(); $value_id = elgg_get_metastring_id($value); if (!$value_id) { return false; } $name_id = elgg_get_metastring_id($name); if (!$name_id) { return false; } // @todo we don't check that the entity is loaded which means the user may // not have access to the entity $entity = get_entity($entity_guid); if (elgg_trigger_event('annotate', $entity->type, $entity)) { $result = insert_data("INSERT INTO {$CONFIG->dbprefix}annotations\n\t\t\t(entity_guid, name_id, value_id, value_type, owner_guid, time_created, access_id) VALUES\n\t\t\t({$entity_guid}, {$name_id}, {$value_id}, '{$value_type}', {$owner_guid}, {$time}, {$access_id})"); if ($result !== false) { $obj = elgg_get_annotation_from_id($result); if (elgg_trigger_event('create', 'annotation', $obj)) { return $result; } else { // plugin returned false to reject annotation elgg_delete_annotation_by_id($result); return false; } } } return $result; }
/** * Create a new annotation. * * @param int $entity_guid GUID of entity to be annotated * @param string $name Name of annotation * @param string $value Value of annotation * @param string $value_type Type of value (default is auto detection) * @param int $owner_guid Owner of annotation (default is logged in user) * @param int $access_id Access level of annotation * * @return int|bool id on success or false on failure */ function create($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE) { $result = false; $entity_guid = (int) $entity_guid; $value_type = detect_extender_valuetype($value, $value_type); $owner_guid = (int) $owner_guid; if ($owner_guid == 0) { $owner_guid = $this->session->getLoggedInUserGuid(); } $access_id = (int) $access_id; // @todo we don't check that the entity is loaded which means the user may // not have access to the entity $entity = get_entity($entity_guid); if ($this->events->trigger('annotate', $entity->type, $entity)) { $sql = "INSERT INTO {$this->db->prefix}annotations\n\t\t\t\t(entity_guid, name, value, value_type, owner_guid, time_created, access_id)\n\t\t\t\tVALUES\n\t\t\t\t(:entity_guid, :name, :value, :value_type, :owner_guid, :time_created, :access_id)"; $result = $this->db->insertData($sql, [':entity_guid' => $entity_guid, ':name' => $name, ':value' => $value, ':value_type' => $value_type, ':owner_guid' => $owner_guid, ':time_created' => $this->getCurrentTime()->getTimestamp(), ':access_id' => $access_id]); if ($result !== false) { $obj = elgg_get_annotation_from_id($result); if ($this->events->trigger('create', 'annotation', $obj)) { return $result; } else { // plugin returned false to reject annotation elgg_delete_annotation_by_id($result); return false; } } } return $result; }
/** * Update an annotation. * * @param int $annotation_id Annotation ID * @param string $name Name of annotation * @param string $value Value of annotation * @param string $value_type Type of value * @param int $owner_guid Owner of annotation * @param int $access_id Access level of annotation * * @return bool */ function update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id) { global $CONFIG; $annotation_id = (int) $annotation_id; $name = trim($name); $value = trim($value); $value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type))); $owner_guid = (int) $owner_guid; if ($owner_guid == 0) { $owner_guid = elgg_get_logged_in_user_guid(); } $access_id = (int) $access_id; $access = get_access_sql_suffix(); // Add the metastring $value = add_metastring($value); if (!$value) { return false; } $name = add_metastring($name); if (!$name) { return false; } // If ok then add it $result = update_data("UPDATE {$CONFIG->dbprefix}annotations\n\t\tset name_id='{$name}', value_id='{$value}', value_type='{$value_type}', access_id={$access_id}, owner_guid={$owner_guid}\n\t\twhere id={$annotation_id} and {$access}"); if ($result !== false) { $obj = elgg_get_annotation_from_id($annotation_id); if (elgg_trigger_event('update', 'annotation', $obj)) { return true; } else { // @todo add plugin hook that sends old and new annotation information before db access elgg_delete_annotation_by_id($annotation_id); } } return $result; }
$tidypics_batch = get_entity($like_entry->entity_guid); // Get images related to this batch $images = elgg_get_entities_from_relationship(array('relationship' => 'belongs_to_batch', 'relationship_guid' => $tidypics_batch->getGUID(), 'inverse_relationship' => true, 'type' => 'object', 'subtype' => 'image', 'limit' => false)); // move the like to the album if more than a single image was uploaded in this batch if (count($images) > 1) { $album = get_entity($tidypics_batch->container_guid); // in case the same user who liked the Tidypics batch entry on the activity already // liked the album delete the annotation to prevent double likes if (elgg_annotation_exists($album->guid, 'likes', $like_entry->owner_guid)) { elgg_delete_annotation_by_id($like_entry->id); } else { // fix annotation $query = "\n\t\t\t\t\tUPDATE {$db_prefix}annotations\n\t\t\t\t\tSET entity_guid = {$album->guid},\n\t\t\t\t\t\taccess_id = {$album->access_id}\n\t\t\t\t\tWHERE id = {$like_entry->id}\n\t\t\t"; update_data($query); } // move the like to the image if only a single image was uploaded in the batch } else { // in case the same user who liked the Tidypics batch entry on the activity already // liked the image delete the annotation to prevent double likes if (elgg_annotation_exists($images[0]->guid, 'likes', $like_entry->owner_guid)) { elgg_delete_annotation_by_id($like_entry->id); } else { // fix annotation $query = "\n\t\t\t\t\tUPDATE {$db_prefix}annotations\n\t\t\t\t\tSET entity_guid = {$images[0]->guid},\n\t\t\t\t\t\taccess_id = {$images[0]->access_id}\n\t\t\t\t\tWHERE id = {$like_entry->id}\n\t\t\t"; update_data($query); } } } // End of Update Part 4/4 elgg_set_ignore_access($ia); access_show_hidden_entities($access_status);
/** * Create a new annotation. * * @param int $entity_guid Entity Guid * @param string $name Name of annotation * @param string $value Value of annotation * @param string $value_type Type of value (default is auto detection) * @param int $owner_guid Owner of annotation (default is logged in user) * @param int $access_id Access level of annotation * * @return int|bool id on success or false on failure */ function create_annotation($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE) { global $CONFIG; $result = false; $entity_guid = (int) $entity_guid; //$name = sanitise_string(trim($name)); //$value = sanitise_string(trim($value)); $value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type))); $owner_guid = (int) $owner_guid; if ($owner_guid == 0) { $owner_guid = elgg_get_logged_in_user_guid(); } $access_id = (int) $access_id; $time = time(); // Add the metastring $value = add_metastring($value); if (!$value) { return false; } $name = add_metastring($name); if (!$name) { return false; } $entity = get_entity($entity_guid); if (elgg_trigger_event('annotate', $entity->type, $entity)) { system_log($entity, 'annotate'); // If ok then add it $result = insert_data("INSERT into {$CONFIG->dbprefix}annotations\n\t\t\t(entity_guid, name_id, value_id, value_type, owner_guid, time_created, access_id) VALUES\n\t\t\t({$entity_guid},'{$name}',{$value},'{$value_type}', {$owner_guid}, {$time}, {$access_id})"); if ($result !== false) { $obj = elgg_get_annotation_from_id($result); if (elgg_trigger_event('create', 'annotation', $obj)) { return $result; } else { // plugin returned false to reject annotation elgg_delete_annotation_by_id($result); return FALSE; } } } return $result; }
function pleio_api_unlike_entity($guid) { $user = elgg_get_logged_in_user_entity(); $user_id = $user !== false ? $user->guid : 0; $guid = (int) $guid; $entity = get_entity($guid); if (!$entity) { return new ErrorResult(elgg_echo("likes:notdeleted")); } // limit likes through a plugin hook (to prevent liking your own content for example) if (!$entity->canAnnotate($user_id, 'likes')) { return new ErrorResult(elgg_echo("likes:notdeleted")); } $options = array('guid' => $guid, 'annotation_name' => "likes", 'annotation_owner_guid' => $user_id); $annotations = elgg_get_annotations($options); // see if the user has liked the item if (!sizeof($annotations)) { return new ErrorResult("sizeof " . elgg_echo("likes:notdeleted")); } //delete like(s) foreach ($annotations as $annotation) { elgg_delete_annotation_by_id($annotation->id); } return new SuccessResult(elgg_echo("likes:deleted")); }
<?php $spam_login_filter_ip_list = get_input('spam_login_filter_ip_list'); $error = false; if (!$spam_login_filter_ip_list) { register_error(elgg_echo('spam_login_filter:errors:unknown_ips')); forward('admin/administer_utilities/manageip'); } foreach ($spam_login_filter_ip_list as $id) { if (!elgg_delete_annotation_by_id($id)) { $error = true; continue; } } if (count($spam_login_filter_ip_list) == 1) { $message_txt = elgg_echo('spam_login_filter:messages:deleted_ip'); $error_txt = elgg_echo('spam_login_filter:errors:could_not_delete_ip'); } else { $message_txt = elgg_echo('spam_login_filter:messages:deleted_ips'); $error_txt = elgg_echo('spam_login_filter:errors:could_not_delete_ips'); } if ($error) { register_error($error_txt); } else { system_message($message_txt); } forward('admin/administer_utilities/manageip');
<?php /** * Elgg delete like action * */ $likeid = (int) get_input('likeid'); $like = elgg_get_annotation_from_id($likeid); if (!$like) { returnAjaxResult(false, elgg_echo("likes:notdeleted")); exit; } $entity_guid = $like->entity_guid; $entity = get_entity($like->entity_guid); if (!$entity) { returnAjaxResult(false, elgg_echo("likes:notdeleted"), $entity); exit; } if (elgg_delete_annotation_by_id($likeid)) { returnAjaxResult(true, elgg_echo("likes:deleted"), $entity); } else { returnAjaxResult(false, elgg_echo("likes:notdeleted"), $entity); } exit;
/** * handles the extended garbage collection * * @param string $hook hookname * @param string $type hooktype * @param mixed $returnvalue current return value * @param mixed $params original parameters * * @return void */ public static function collect($hook, $type, $returnvalue, $params) { if (elgg_get_plugin_setting('enable_gc', 'garbagecollector_extended') !== 'yes') { return; } elgg_register_plugin_hook_handler('permissions_check', 'all', '\\Elgg\\Values::getTrue'); $dbprefix = elgg_get_config('dbprefix'); // overrule access settigns $ia = elgg_get_ignore_access(); elgg_set_ignore_access(true); // cleanup entities if ($entity_guids = garbagecollector_extended_get_orphaned_entities()) { echo elgg_echo('garbagecollector_extended:cleanup', ['entities']); foreach ($entity_guids as $guid) { $entity = get_entity($guid); if ($entity) { $entity->delete(); } } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup access collections if ($acl_ids = garbagecollector_extended_get_orphaned_access_collections()) { echo elgg_echo('garbagecollector_extended:cleanup', ['access collections']); foreach ($acl_ids as $id) { delete_access_collection($id); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup annotations if ($anno_ids = garbagecollector_extended_get_orphaned_annotations()) { echo elgg_echo('garbagecollector_extended:cleanup', ['annotations']); foreach ($anno_ids as $id) { elgg_delete_annotation_by_id($id); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup metadata if ($meta_ids = garbagecollector_extended_get_orphaned_metadata()) { echo elgg_echo('garbagecollector_extended:cleanup', ['metadata']); foreach ($meta_ids as $id) { // We need to manualy delete metadata as the Elgg functions don't work because this is orphaned metadata // also we need to delete this one by one because of potential long query strings $sql = 'DELETE FROM ' . $dbprefix . 'metadata'; $sql .= ' WHERE id = ' . $id; delete_data($sql); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup private settings if ($private_ids = garbagecollector_extended_get_orphaned_private_settings()) { echo elgg_echo('garbagecollector_extended:cleanup', ['private settings']); foreach ($private_ids as $id) { // We need to manualy delete private settings as Elgg doesn't have a function fot this // also we need to delete this one by one because of potential long query strings $sql = 'DELETE FROM ' . $dbprefix . 'private_settings'; $sql .= ' WHERE id = ' . $id; delete_data($sql); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup relationships if ($rel_ids = garbagecollector_extended_get_orphaned_relationships()) { echo elgg_echo('garbagecollector_extended:cleanup', ['relationships']); foreach ($rel_ids as $id) { delete_relationship($id); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup river if ($river_ids = garbagecollector_extended_get_orphaned_river()) { echo elgg_echo('garbagecollector_extended:cleanup', ['river items']); elgg_delete_river(['ids' => $river_ids]); echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // because we cleaned up a lot, do metastrings again garbagecollector_orphaned_metastrings(); // restore access settings elgg_set_ignore_access($ia); elgg_unregister_plugin_hook_handler('permissions_check', 'all', '\\Elgg\\Values::getTrue'); }
<?php /** * Tasks remove comment action * * @package ElggTasks */ group_gatekeeper(); elgg_load_library('elgg:tasks'); if (elgg_annotation_exists($annotation->guid)) { elgg_delete_annotation_by_id($annotation_id->id); } // Forward to the page the action occurred on forward(REFERER);
/** * {@inheritdoc} */ public function handle(\ElggEntity $entity) { $shortname = $this->getShortname(); $current_annotations = elgg_get_annotations(array('guids' => (int) $entity->guid, 'annotation_names' => $shortname)); if (is_array($current_annotations) && count($current_annotations)) { foreach ($current_annotations as $ann) { $current_annotations_ids[] = $ann->id; } } if (!is_array($current_annotations_ids)) { $current_annotations_ids = array(); } $future_annotations = get_input($this->getShortname(), array()); $params = array('field' => $this, 'entity' => $entity, 'annotation_name' => $shortname, 'value' => $current_annotations, 'future_value' => $future_annotations); // Allow plugins to prevent annotation from being changed if (!elgg_trigger_plugin_hook('handle:annotation:before', 'prototyper', $params, true)) { return $entity; } $future_annotations_ids = elgg_extract('id', $future_annotations, array()); $to_delete = array_diff($current_annotations_ids, $future_annotations_ids); foreach ($to_delete as $id) { elgg_delete_annotation_by_id($id); } $keys = array_keys(elgg_extract('name', $future_annotations, array())); $ids = array(); foreach ($keys as $i) { $id = $future_annotations['id'][$i]; $name = $future_annotations['name'][$i]; $value = $future_annotations['value'][$i]; if ($this->getValueType() == 'tags') { $value = string_to_tag_array($value); } $access_id = $future_annotations['access_id'][$i]; $owner_guid = $future_annotations['owner_guid'][$i]; if (!is_array($value)) { if ($id) { update_annotation($id, $name, $value, '', $owner_guid, $access_id); } else { $id = create_annotation($entity->guid, $name, $value, '', $owner_guid, $access_id); } $ids[] = $id; } else { if ($id) { elgg_delete_annotation_by_id($id); } foreach ($value as $val) { $ids[] = create_annotation($entity->guid, $name, $val, '', $owner_guid, $access_id); } } } $params = array('field' => $this, 'entity' => $entity, 'annotation_name' => $shortname, 'value' => count($ids) ? elgg_get_annotations(array('annotation_ids' => $ids)) : array(), 'previous_value' => $current_annotations); elgg_trigger_plugin_hook('handle:annotation:after', 'prototyper', $params, true); return $entity; }