function bulk_user_admin_get_sql_where_not_enqueued() { $db_prefix = get_config('dbprefix'); $name_id = elgg_get_metastring_id(\BulkUserAdmin\DeleteService::PENDING_DELETE_MD); $value_id = elgg_get_metastring_id(true); return "NOT EXISTS (\n\t\t\tSELECT 1 FROM {$db_prefix}metadata md\n\t\t\tWHERE md.entity_guid = e.guid\n\t\t\t\tAND md.name_id = {$name_id}\n\t\t\t\tAND md.value_id = {$value_id})"; }
protected function getOptions() { $options = parent::getOptions(); if ($this->banned === true) { $options['wheres'][] = "u.banned = 'yes'"; } elseif ($this->banned === false) { $options['wheres'][] = "u.banned = 'no'"; } if ($this->admin === true) { $options['wheres'][] = "u.admin = 'yes'"; } elseif ($this->admin === false) { $options['wheres'][] = "u.admin = 'no'"; } if ($this->search) { $q = sanitize_string($this->search); $where = "u.name LIKE \"%{$q}%\" OR u.username LIKE \"%{$q}%\""; if (\elgg_is_admin_logged_in()) { $where .= " u.email LIKE \"%{$q}%\""; } $options['wheres'][] = "({$where})"; } /* * "Unvalidated" means metadata of validated is not set or not truthy. * We can't use elgg_get_entities_from_metadata() because you can't say * "where the entity has metadata set OR it's not equal to 1". */ if ($this->validated === false) { $validated_id = \elgg_get_metastring_id('validated'); $one_id = \elgg_get_metastring_id('1'); $options['wheres'][] = "NOT EXISTS (\n\t\t\t\tSELECT 1 FROM {$this->getDB()->getPrefix()}metadata validated_md\n\t\t\t\tWHERE validated_md.entity_guid = e.guid\n\t\t\t\t\tAND validated_md.name_id = {$validated_id}\n\t\t\t\t\tAND validated_md.value_id = {$one_id})"; } return $options; }
/** * Prepares ege* options for querying subcategories * * @param mixed $containers Containers (guids or entities) * @param array $options ege* options * @return ElggBatch */ public function getSubcategoriesQueryOptions($containers, array $options = array()) { $dbprefix = elgg_get_config('dbprefix'); $nid = elgg_get_metastring_id('priority'); $defaults = array('selects' => array('CAST(msv.string AS SIGNED) AS priority'), 'types' => 'object', 'subtypes' => $this->config->getCategorySubtypes(), 'joins' => array("JOIN {$dbprefix}metadata md ON md.entity_guid = e.guid AND md.name_id = {$nid}", "JOIN {$dbprefix}metastrings msv ON msv.id = md.value_id"), 'order_by' => 'priority = 0, priority ASC'); $options = array_merge($defaults, $options); $options['container_guids'] = ItemCollection::create($containers)->guids(); return $options; }
/** * {@inheritdoc} */ public static function addSortQuery(array $options = [], $field = 'time_created', $direction = 'DESC') { $dbprefix = elgg_get_config('dbprefix'); $order_by = explode(',', elgg_extract('order_by', $options, '')); array_walk($order_by, 'trim'); $options['joins']['objects_entity'] = "\n\t\t\tJOIN {$dbprefix}objects_entity AS objects_entity\n\t\t\t\tON objects_entity.guid = e.guid\n\t\t\t"; switch ($field) { case 'type': case 'subtype': case 'guid': case 'owner_guid': case 'container_guid': case 'site_guid': case 'enabled': case 'time_created': case 'time_updated': case 'access_id': array_unshift($order_by, "e.{$field} {$direction}"); break; case 'title': case 'description': array_unshift($order_by, "objects_entity.{$field} {$direction}"); break; case 'last_action': $options['selects']['last_action'] = "\n\t\t\t\t\tGREATEST (e.time_created, e.last_action, e.time_updated) AS last_action\n\t\t\t\t\t"; array_unshift($order_by, "last_action {$direction}"); break; case 'likes_count': $name_id = elgg_get_metastring_id('likes'); $options['joins']['likes_count'] = "\n\t\t\t\t\tLEFT JOIN {$dbprefix}annotations AS likes\n\t\t\t\t\t\tON likes.entity_guid = e.guid AND likes.name_id = {$name_id}\n\t\t\t\t\t"; $options['selects']['likes_count'] = "COUNT(likes.id) as likes_count"; $options['group_by'] = 'e.guid'; array_unshift($order_by, "likes_count {$direction}"); $order_by[] = 'e.time_created DESC'; // show newest first if count is the same break; case 'responses_count': $ids = array(); $ids[] = (int) get_subtype_id('object', 'comment'); $ids[] = (int) get_subtype_id('object', 'discussion_reply'); $ids_in = implode(',', $ids); $options['joins']['responses_count'] = "\n\t\t\t\t\tLEFT JOIN {$dbprefix}entities AS responses\n\t\t\t\t\t\tON responses.container_guid = e.guid\n\t\t\t\t\t\tAND responses.type = 'object'\n\t\t\t\t\t\tAND responses.subtype IN ({$ids_in})\n\t\t\t\t\t"; $options['selects']['responses_count'] = "COUNT(responses.guid) as responses_count"; $options['group_by'] = 'e.guid'; array_unshift($order_by, "responses_count {$direction}"); $order_by[] = 'e.time_created DESC'; // show newest first if count is the same break; } if ($field == 'alpha') { array_unshift($order_by, "objects_entity.title {$direction}"); } $options['order_by'] = implode(', ', array_unique(array_filter($order_by))); $params = array('field' => $field, 'direction' => $direction); return elgg_trigger_plugin_hook('sort_options', 'object', $params, $options); }
function import_to_stormpath() { $dbprefix = elgg_get_config('dbprefix'); $subject = elgg_get_plugin_setting('import_subject', PLUGIN_ID); $message = elgg_get_plugin_setting('import_message', PLUGIN_ID); $site = elgg_get_site_entity(); $site_url = elgg_get_site_url(); if (!$subject || !$message) { error_log('no subject/message'); return true; } if (is_elgg18()) { $name_id = add_metastring('__stormpath_user'); $value_id = add_metastring(1); } else { $name_id = elgg_get_metastring_id('__stormpath_user'); $value_id = elgg_get_metastring_id(1); } $options = array('type' => 'user', 'joins' => array("LEFT JOIN {$dbprefix}metadata md ON md.entity_guid = e.guid AND md.name_id = {$name_id}"), 'wheres' => array('md.name_id IS NULL'), 'limit' => false); $batch = new \ElggBatch('elgg_get_entities', $options); $batch->setIncrementOffset(false); foreach ($batch as $user) { // search stormpath for a matching account $application = get_application(); $accts = $application->getAccounts(array('email' => $user->email)); $already_exists = false; foreach ($accts as $a) { $user->__stormpath_user = $a->href; error_log('set user ' . $user->username . ': ' . $a->href); $already_exists = true; break; } if ($already_exists) { continue; } // change it locally $password = generate_random_cleartext_password(); $user->salt = _elgg_generate_password_salt(); $user->password = generate_user_password($user, $password); $user->save(); error_log('adding to stormpath ' . $user->email); $result = add_to_stormpath($user, $password); if ($result) { // notify them of the change // replace tokens in the message $message_m = str_replace('{{password}}', $password, $message); $message_m = str_replace('{{name}}', $user->name, $message_m); $message_m = str_replace('{{username}}', $user->username, $message_m); $message_m = str_replace('{{email}}', $user->email, $message_m); $message_m = str_replace('{{forgot_password}}', $site_url . 'forgotpassword', $message_m); $message_m = str_replace('{{site_email}}', $site->email, $message_m); $message_m = str_replace('{{site_url}}', $site_url, $message_m); notify_user($user->guid, $site->guid, $subject, $message_m, null, 'email'); } } }
/** * Return a where clause to get entities * * "Unvalidated" means metadata of validated is not set or not truthy. * We can't use elgg_get_entities_from_metadata() because you can't say * "where the entity has metadata set OR it's not equal to 1". * * @return array */ function uservalidationbyemail_get_unvalidated_users_sql_where() { $db_prefix = elgg_get_config('dbprefix'); $validated_id = elgg_get_metastring_id('validated'); $one_id = elgg_get_metastring_id('1'); // thanks to daveb@freenode for the SQL tips! $wheres = array(); $wheres[] = "e.enabled='no'"; $wheres[] = "NOT EXISTS (\n\t\t\tSELECT 1 FROM {$db_prefix}metadata md\n\t\t\tWHERE md.entity_guid = e.guid\n\t\t\t\tAND md.name_id = {$validated_id}\n\t\t\t\tAND md.value_id = {$one_id})"; return $wheres; }
/** * Publish blogs based on advanced publication options * * @param string $hook 'cron' * @param string $type 'daily' * @param string $return_value optional stdout text * @param array $params supplied params * * @return void */ public static function daily($hook, $type, $return_value, $params) { // only do if this is configured if (!blog_tools_use_advanced_publication_options()) { return $return_value; } $dbprefix = elgg_get_config("dbprefix"); $publication_id = elgg_get_metastring_id("publication_date"); $expiration_id = elgg_get_metastring_id("expiration_date"); $time = elgg_extract("time", $params, time()); $publish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_value_pairs" => array(array("name" => "status", "value" => "draft")), "wheres" => array("((mdtime.name_id = " . $publication_id . ") AND (DATE(mstime.string) = DATE(NOW())))")); $unpublish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_values_pairs" => array(array("name" => "status", "value" => "published")), "wheres" => array("((mdtime.name_id = " . $expiration_id . ") AND (DATE(mstime.string) = DATE(NOW())))")); // ignore access $ia = elgg_set_ignore_access(true); // get unpublished blogs that need to be published $entities = new \ElggBatch("elgg_get_entities_from_metadata", $publish_options); foreach ($entities as $entity) { // add river item elgg_create_river_item(array("view" => "river/object/blog/create", "action_type" => "create", "subject_guid" => $entity->getOwnerGUID(), "object_guid" => $entity->getGUID())); // set correct time created $entity->time_created = $time; // publish blog $entity->status = "published"; // revert access $entity->access_id = $entity->future_access; unset($entity->future_access); // send notifications when post published elgg_trigger_event('publish', 'object', $entity); // notify owner notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:publish:subject"), elgg_echo("blog_tools:notify:publish:message", array($entity->title, $entity->getURL()))); // save everything $entity->save(); } // get published blogs that need to be unpublished $entities = new \ElggBatch("elgg_get_entities_from_metadata", $unpublish_options); foreach ($entities as $entity) { // remove river item elgg_delete_river(array("object_guid" => $entity->getGUID(), "action_type" => "create")); // unpublish blog $entity->status = "draft"; // notify owner notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:expire:subject"), elgg_echo("blog_tools:notify:expire:message", array($entity->title, $entity->getURL()))); // save everything $entity->save(); } // reset access elgg_set_ignore_access($ia); }
/** * Unpublish blogs based on advanced publication settings * * @return void */ protected static function unpublishBlogs() { $dbprefix = elgg_get_config('dbprefix'); $expiration_id = elgg_get_metastring_id('expiration_date'); $unpublish_options = ['type' => 'object', 'subtype' => 'blog', 'limit' => false, 'joins' => ["JOIN {$dbprefix}metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN {$dbprefix}metastrings mstime ON mdtime.value_id = mstime.id"], 'metadata_name_values_pairs' => [['name' => 'status', 'value' => 'published']], 'wheres' => ["((mdtime.name_id = {$expiration_id}) AND (DATE(mstime.string) = DATE(NOW())))"]]; // get published blogs that need to be unpublished $entities = new \ElggBatch('elgg_get_entities_from_metadata', $unpublish_options); foreach ($entities as $entity) { // remove river item elgg_delete_river(['object_guid' => $entity->getGUID(), 'action_type' => 'create']); // unpublish blog $entity->status = 'draft'; // notify owner notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo('blog_tools:notify:expire:subject'), elgg_echo('blog_tools:notify:expire:message', [$entity->title, $entity->getURL()])); // save everything $entity->save(); } }
public function testGetMetastringById() { foreach (array('metaUnitTest', 'metaunittest', 'METAUNITTEST') as $string) { // since there is no guarantee that metastrings are garbage collected // between unit test runs, we delete before testing $this->delete_metastrings($string); $this->create_metastring($string); } // lookup metastring id $cs_ids = elgg_get_metastring_id('metaUnitTest', true); $this->assertEqual($cs_ids, $this->metastrings['metaUnitTest']); // lookup all metastrings, ignoring case $cs_ids = elgg_get_metastring_id('metaUnitTest', false); $this->assertEqual(count($cs_ids), 3); $this->assertEqual(count($cs_ids), count($this->metastrings)); foreach ($cs_ids as $string) { $this->assertTrue(in_array($string, $this->metastrings)); } }
/** * Get the where selector for advanced publications * * @return array */ function pages_tools_get_publication_wheres() { static $result; if (!isset($result)) { $result = array(); if (pages_tools_use_advanced_publication_options()) { $unpublished_id = elgg_get_metastring_id("unpublished"); $dbprefix = elgg_get_config("dbprefix"); $query = "(e.guid NOT IN ("; $query .= "SELECT entity_guid"; $query .= " FROM {$dbprefix}metadata"; $query .= " WHERE name_id = {$unpublished_id}"; $query .= "))"; $result[] = $query; } } return $result; }
// all groups doesn't get link to self elgg_pop_breadcrumb(); elgg_push_breadcrumb(elgg_echo('groups')); // only register title button if allowed if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) { elgg_register_title_button(); } $selected_tab = get_input('filter'); //system_message("selected tab " . $selected_tab); // default group options $group_options = ['type' => 'group', 'full_view' => false]; $dbprefix = elgg_get_config('dbprefix'); //system_message("teranga selected tab es ... " . $selected_tab); switch ($selected_tab) { case 'ordered': $order_id = elgg_get_metastring_id('order'); $group_options['limit'] = false; $group_options['pagination'] = false; $group_options['selects'] = ["IFNULL((SELECT order_ms.string as order_val\n\t\t\tFROM {$dbprefix}metadata mo\n\t\t\tJOIN {$dbprefix}metastrings order_ms ON mo.value_id = order_ms.id\n\t\t\tWHERE e.guid = mo.entity_guid\n\t\t\tAND mo.name_id = {$order_id}), 99999) AS order_val"]; $group_options['order_by'] = 'CAST(order_val AS SIGNED) ASC, e.time_created DESC'; if (elgg_is_admin_logged_in()) { elgg_require_js('fuzzy_filter/ordered_list'); $group_options['list_class'] = 'fuzzy-filter-list-ordered'; } break; case 'yours': elgg_gatekeeper(); $group_options['relationship'] = 'member'; $group_options['relationship_guid'] = elgg_get_logged_in_user_guid(); $group_options['inverse_relationship'] = false; break;
$oldCat = get_input("oldCat"); $newCat = get_input("newCat"); $access = (int) get_input("access"); if (!empty($question) && !empty($answer) && !empty($access) && (!empty($oldCat) || !empty($newCat))) { $cat = ""; if ($oldCat == "newCat" && !empty($newCat)) { $cat = ucfirst(strtolower($newCat)); } else { $cat = ucfirst(strtolower($oldCat)); } if (!empty($cat)) { $faq = new FAQObject(); $faq->container_guid = elgg_get_config('site_guid'); $faq->owner_guid = elgg_get_config('site_guid'); $faq->category = $cat; $faq->question = $question; $faq->answer = $answer; $faq->access_id = $access; if ($faq->save()) { system_message(elgg_echo("faq:add:success")); } else { register_error(elgg_echo("faq:add:error:save")); } } else { register_error(elgg_echo("faq:add:error:invalid_input")); } } else { register_error(elgg_echo("faq:add:error:invalid_input")); } forward(elgg_get_site_url() . "faq/list?categoryId=" . elgg_get_metastring_id($faq->category));
$answers = ''; // add the answer marked as the correct answer first $marked_answer = $question->getMarkedAnswer(); if (!empty($marked_answer)) { $answers .= elgg_view_entity($marked_answer); } // add the rest of the answers $options = ['type' => 'object', 'subtype' => 'answer', 'container_guid' => $question->getGUID(), 'count' => true, 'limit' => false]; if (!empty($marked_answer)) { // do not include the marked answer as it already added to the output before $options['wheres'] = ["e.guid <> {$marked_answer->getGUID()}"]; } if (elgg_is_active_plugin('likes')) { // order answers based on likes $dbprefix = elgg_get_config('dbprefix'); $likes_id = elgg_get_metastring_id('likes'); $options['selects'] = ["(SELECT count(a.name_id) AS likes_count\n\t\tFROM {$dbprefix}annotations a\n\t\tWHERE a.entity_guid = e.guid\n\t\tAND a.name_id = {$likes_id}) AS likes_count"]; $options['order_by'] = 'likes_count desc, e.time_created asc'; } $answers .= elgg_list_entities($options); $count = elgg_get_entities($options); if (!empty($marked_answer)) { $count++; } if (!empty($answers)) { $content .= elgg_view_module('info', "{$count} " . elgg_echo('answers'), $answers, ['class' => 'mtm', 'id' => 'question-answers']); } // add answer form if ($question->getStatus() === 'open' && $question->canWriteToContainer(0, 'object', 'answer')) { $add_form = elgg_view_form('object/answer/add', [], ['container_guid' => $question->getGUID()]); $content .= elgg_view_module('info', elgg_echo('answers:addyours'), $add_form);
/** * Check if the given user has full access. * * @todo: Will always return full access if the user is an admin. * * @param int $user_guid The user to check * * @return bool * @since 1.7.1 */ function elgg_is_admin_user($user_guid) { global $CONFIG; $user_guid = (int) $user_guid; // cannot use magic metadata here because of recursion // must support the old way of getting admin from metadata // in order to run the upgrade to move it into the users table. $version = (int) datalist_get('version'); if ($version < 2010040201) { $admin = elgg_get_metastring_id('admin'); $yes = elgg_get_metastring_id('yes'); $one = elgg_get_metastring_id('1'); $query = "SELECT * FROM {$CONFIG->dbprefix}users_entity as e,\n\t\t\t{$CONFIG->dbprefix}metadata as md\n\t\t\tWHERE (\n\t\t\t\tmd.name_id = '{$admin}'\n\t\t\t\tAND md.value_id IN ('{$yes}', '{$one}')\n\t\t\t\tAND e.guid = md.entity_guid\n\t\t\t\tAND e.guid = {$user_guid}\n\t\t\t\tAND e.banned = 'no'\n\t\t\t)"; } else { $query = "SELECT * FROM {$CONFIG->dbprefix}users_entity as e\n\t\t\tWHERE (\n\t\t\t\te.guid = {$user_guid}\n\t\t\t\tAND e.admin = 'yes'\n\t\t\t)"; } // normalizing the results from get_data() // See #1242 $info = get_data($query); if (!(is_array($info) && count($info) < 1 || $info === false)) { return true; } return false; }
<?php // Get all received messages fromId != owner_guid $dbprefix = elgg_get_config('dbprefix'); $fromId = elgg_get_metastring_id('fromId'); echo elgg_view('admin/inbox/search'); $query = get_input('query'); $options = array('types' => 'object', 'subtypes' => 'messages', 'joins' => array("JOIN {$dbprefix}metadata md ON md.entity_guid = e.guid AND md.name_id = {$fromId}", "JOIN {$dbprefix}metastrings fromId ON fromId.id = md.value_id"), 'wheres' => array('fromId.string != e.owner_guid'), 'preload_owners' => true, 'no_results' => elgg_echo('inbox:monitor:no_results'), 'item_view' => 'object/messages/admin'); if ($query) { $query = sanitize_string($query); $options['query'] = $query; $options['joins'][] = "JOIN {$dbprefix}objects_entity oe ON e.guid = oe.guid"; $fields = array('title', 'description'); $where = search_get_where_sql('oe', $fields, $options); $options['wheres'][] = $where; } $module = elgg_view('object/messages/controls'); $module .= elgg_list_entities($options); echo elgg_format_element('div', array('class' => 'inbox-monitor-module'), $module);
/** * Get messages that have not been assigned a hash * * @param array $options Getter options * @return ElggBatch */ public function getUnhashedMessages(array $options = array()) { $name_id = elgg_get_metastring_id('msgHash'); $dbprefix = elgg_get_config('dbprefix'); $defaults = array('types' => 'object', 'subtypes' => Message::SUBTYPE, 'wheres' => array("NOT EXISTS (SELECT 1 FROM {$dbprefix}metadata md WHERE md.entity_guid = e.guid\n\t\t\tAND md.name_id = {$name_id})"), 'order_by' => 'e.guid ASC'); $options = array_merge($defaults, $options); return $this->getEntities($options); }
/** * 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; $annotation = elgg_get_annotation_from_id($annotation_id); if (!$annotation) { return false; } if (!$annotation->canEdit()) { return false; } $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; $value_id = elgg_get_metastring_id($value); if (!$value_id) { return false; } $name_id = elgg_get_metastring_id($name); if (!$name_id) { return false; } $result = update_data("UPDATE {$CONFIG->dbprefix}annotations\n\t\tSET name_id = {$name_id}, value_id = {$value_id}, value_type = '{$value_type}',\n\t\taccess_id = {$access_id}, owner_guid = {$owner_guid}\n\t\tWHERE id = {$annotation_id}"); if ($result !== false) { // @todo add plugin hook that sends old and new annotation information before db access $obj = elgg_get_annotation_from_id($annotation_id); elgg_trigger_event('update', 'annotation', $obj); } return $result; }
* Extra tabs for the all groups page */ // all groups doesn"t get link to self elgg_pop_breadcrumb(); elgg_push_breadcrumb(elgg_echo("groups")); // only register title button if allowed if (elgg_get_plugin_setting("limited_groups", "groups") != "yes" || elgg_is_admin_logged_in()) { elgg_register_title_button(); } $selected_tab = get_input("filter"); // default group options $group_options = array("type" => "group", "full_view" => false); $dbprefix = elgg_get_config("dbprefix"); switch ($selected_tab) { case "ordered": $order_id = elgg_get_metastring_id("order"); $group_options["limit"] = false; $group_options["pagination"] = false; $group_options["selects"] = array("IFNULL((SELECT order_ms.string as order_val FROM " . $dbprefix . "metadata mo JOIN " . $dbprefix . "metastrings order_ms ON mo.value_id = order_ms.id WHERE e.guid = mo.entity_guid AND mo.name_id = " . $order_id . "), 99999) AS order_val"); $group_options["order_by"] = "CAST(order_val AS SIGNED) ASC, e.time_created DESC"; if (elgg_is_admin_logged_in()) { $group_options["list_class"] = "group-tools-list-ordered"; } break; case "yours": elgg_gatekeeper(); $group_options["relationship"] = "member"; $group_options["relationship_guid"] = elgg_get_logged_in_user_guid(); $group_options["inverse_relationship"] = false; break; case "open":
<?php elgg_require_js('faq/faq_entity'); $faq = $vars["entity"]; $selected = $vars["selected"]; $hitcount = $vars["hitcount"]; echo "<div>"; echo "<table><tr>"; if (elgg_is_admin_logged_in()) { echo "<td><div id='faqSelect" . $faq->guid . "' class='faqSelect'>"; echo elgg_view('input/checkbox', array("name" => "selectQuestion", "id" => "selectQuestion" . $faq->guid, "value" => $faq->guid)); echo "</div></td>"; } echo "<td width='100%'>"; if (!empty($hitcount)) { echo "<a href='" . elgg_get_site_url() . "faq/list?categoryId=" . elgg_get_metastring_id($faq->category) . "'>" . $faq->category . "</a> > "; } echo "<a href='javascript:void(0);' class='qID' id='qID" . $faq->guid . "' data-faqguid='" . $faq->guid . "'>" . $faq->question . "</a>"; echo "</td>"; if (!empty($hitcount)) { echo "<td class='hitcount'>" . elgg_echo("faq:search:hitcount") . " " . $hitcount . "</td>"; } if (elgg_is_admin_logged_in()) { echo "<td>"; echo "<div class='faqedit' data-faqguid='" . $faq->guid . "'>" . elgg_view_icon('faqedit') . "</div>"; echo "</td>"; echo "<td>"; echo "<div class='delForm' data-faqguid='" . $faq->guid . "'>" . elgg_view_icon('delete') . "</div>"; echo "</td>"; } echo "</tr></table>";
/** * Returns the unread messages in a user's inbox * * @param int $user_guid GUID of user whose inbox we're counting (0 for logged in user) * @param int $limit Number of unread messages to return (default from settings) * @param int $offset Start at a defined offset (for listings) * @param bool $count Switch between entities array or count mode * * @return array, int (if $count = true) * @since 1.9 */ function messages_get_unread($user_guid = 0, $limit = null, $offset = 0, $count = false) { if (!$user_guid) { $user_guid = elgg_get_logged_in_user_guid(); } $db_prefix = elgg_get_config('dbprefix'); // denormalize the md to speed things up. // seriously, 10 joins if you don't. $strings = array('toId', $user_guid, 'readYet', 0); $map = array(); foreach ($strings as $string) { $id = elgg_get_metastring_id($string); $map[$string] = $id; } if ($limit === null) { $limit = elgg_get_config('default_limit'); } $options = array('joins' => array("JOIN {$db_prefix}metadata msg_toId on e.guid = msg_toId.entity_guid", "JOIN {$db_prefix}metadata msg_readYet on e.guid = msg_readYet.entity_guid"), 'wheres' => array("msg_toId.name_id='{$map['toId']}' AND msg_toId.value_id='{$map[$user_guid]}'", "msg_readYet.name_id='{$map['readYet']}' AND msg_readYet.value_id='{$map[0]}'"), 'owner_guid' => $user_guid, 'limit' => $limit, 'offset' => $offset, 'count' => $count, 'distinct' => false); return elgg_get_entities_from_metadata($options); }
/** *function to return array of visitors */ function izapVisitorList() { $ProfileEntity = elgg_get_page_owner_entity(); if (!$ProfileEntity) { $ProfileEntity = elgg_get_logged_in_user_entity(); } $ProfileName = $ProfileEntity->name; $ProfileGuid = $ProfileEntity->guid; $ProfileOwner = $ProfileEntity->owner_guid; $ProfileAccess = $ProfileEntity->access_id; $meta_name = elgg_get_metastring_id('izapProfileVisitor'); $db_prefix = elgg_get_config('dbprefix'); $Metadata = get_data("SELECT m.*, n.string as name, v.string as value from {$db_prefix}metadata m JOIN {$db_prefix}entities e ON e.guid = m.entity_guid JOIN {$db_prefix}metastrings v on m.value_id = v.id JOIN {$db_prefix}metastrings n on m.name_id = n.id where m.entity_guid={$ProfileGuid} and m.name_id={$meta_name}", "row_to_elggmetadata"); if ($Metadata) { return unserialize($Metadata[0]->value); } }
/** * Metastring ID mapping * * @param array $metastrings An array of metastrings * @return array */ private static function getMetaMap($metastrings = array()) { $map = array(); foreach ($metastrings as $metastring) { if (isset(self::$matamap) && in_array(self::$metamap[$metastring])) { $map[$metastring] = self::$metamap[$metastring]; } else { $id = elgg_get_metastring_id($metastring); self::$metamap[$metastring] = $map[$metastring] = $id; } } return $map; }
<?php elgg_gatekeeper(); if (!static_out_of_date_enabled()) { forward(REFERER); } $page_owner = elgg_get_page_owner_entity(); if (!$page_owner instanceof ElggUser) { register_error(elgg_echo('pageownerunavailable', [elgg_get_page_owner_guid()])); forward(REFERER); } if (!$page_owner->canEdit()) { register_error(elgg_echo('limited_access')); forward(REFERER); } $dbprefix = elgg_get_config('dbprefix'); $static_revision_id = elgg_get_metastring_id('static_revision'); $days = (int) elgg_get_plugin_setting('out_of_date_days', 'static'); $options = ['type' => 'object', 'subtype' => StaticPage::SUBTYPE, 'modified_time_upper' => time() - $days * 24 * 60 * 60, 'wheres' => ["e.guid IN (\n\t\t\tSELECT entity_guid\n\t\t\tFROM (\n\t\t\t\tSELECT *\n\t\t\t\tFROM (\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM {$dbprefix}annotations\n\t\t\t\t\tWHERE name_id = {$static_revision_id}\n\t\t\t\t\tORDER BY entity_guid, time_created DESC) a1\n\t\t\t\tGROUP BY a1.entity_guid) a2\n\t\t\tWHERE a2.owner_guid = {$page_owner->getGUID()})\n\t\t"], 'order_by' => 'e.time_updated DESC', 'no_results' => elgg_echo('static:out_of_date:none'), 'item_view' => 'object/static/simple']; $title_text = elgg_echo('static:out_of_date:owner:title', [$page_owner->name]); $filter = elgg_view('page/layouts/elements/filter'); $body = elgg_list_entities($options); // build page $page_data = elgg_view_layout('one_column', ['title' => $title_text, 'content' => $filter . $body]); // draw page echo elgg_view_page($title_text, $page_data);
/** * Get Last Conversation * * @param int $user_guid User GUID * @param int $limit Limit of Conversations * @param int $offset Offset * @param int $count Count * * @return SuccessResult|ErrorResult */ function ws_pack_get_last_conversations($user_guid, $limit = 100, $offset = 0, $count = false) { $result = false; $user = elgg_get_logged_in_user_entity(); $api_application = ws_pack_get_current_api_application(); if (!empty($user) && !empty($api_application)) { if (!$user_guid) { $user_guid = elgg_get_logged_in_user_guid(); } $db_prefix = elgg_get_config('dbprefix'); $strings = array('toId', $user_guid, 'msg', 1, 'fromId', $fromto_guid); $map = array(); foreach ($strings as $string) { $id = elgg_get_metastring_id($string); $map[$string] = $id; } $options = array('selects' => array("MAX(e.guid) as guid", "MAX(e.time_created) as time_created"), 'joins' => array("JOIN {$db_prefix}metadata msg_toId on e.guid = msg_toId.entity_guid", "JOIN {$db_prefix}metadata msg_msg on e.guid = msg_msg.entity_guid", "JOIN {$db_prefix}metadata msg_fromId on e.guid = msg_fromId.entity_guid"), 'owner_guid' => $user_guid, 'limit' => $limit, 'offset' => $offset, 'count' => $count); $options["wheres"] = array("msg_msg.name_id='{$map['msg']}' AND msg_msg.value_id='{$map[1]}'"); $options["group_by"] = "msg_fromId.value_id, msg_toId.value_id"; $messages = elgg_get_entities_from_metadata($options); if ($messages === false) { $result = new ErrorResult(elgg_echo("ws_pack:error:notfound")); } else { $messages["entities"] = ws_pack_export_entities($messages); $guids = array(); foreach ($messages["entities"] as $key => $message) { $message_guid = $message["guid"]; if (!in_array($message_guid, $guids)) { $guids[] = $message_guid; $message_entity = get_entity($message_guid); $recipient_id = $message_entity->toId; if ($recipient_id === $user_guid) { $recipient_id = $message_entity->fromId; } $recipient = get_entity($recipient_id); $message["recipient"] = ws_pack_export_entity($recipient); $messages["entities"][$key] = $message; } else { unset($messages["entities"][$key]); } } $result = new SuccessResult($messages); } } if ($result === false) { $result = new ErrorResult(elgg_echo("ws_pack:error:notfound")); } 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_id, $name, $value, $value_type, $owner_guid, $access_id) { $annotation_id = (int) $annotation_id; $annotation = $this->get($annotation_id); if (!$annotation) { return false; } if (!$annotation->canEdit()) { return false; } $name = trim($name); $value_type = detect_extender_valuetype($value, $value_type); $owner_guid = (int) $owner_guid; if ($owner_guid == 0) { $owner_guid = _elgg_services()->session->getLoggedInUserGuid(); } $access_id = (int) $access_id; $value_id = elgg_get_metastring_id($value); if (!$value_id) { return false; } $name_id = elgg_get_metastring_id($name); if (!$name_id) { return false; } $result = _elgg_services()->db->updateData("UPDATE {$this->CONFIG->dbprefix}annotations\n\t\t\tSET name_id = {$name_id}, value_id = {$value_id}, value_type = '{$value_type}',\n\t\t\taccess_id = {$access_id}, owner_guid = {$owner_guid}\n\t\t\tWHERE id = {$annotation_id}"); if ($result !== false) { // @todo add plugin hook that sends old and new annotation information before db access $obj = $this->get($annotation_id); _elgg_services()->events->trigger('update', 'annotation', $obj); } return $result; }
/** * Return an array of entities ordered by the number of views * * @param $options */ function get_entities_by_views_counter($options) { $dbprefix = elgg_get_config('dbprefix'); // Select the sum of the views counter returned by the JOIN $select = 'sum(ms.string) as views_counter'; if (is_array($options['selects'])) { $options['selects'][] = $select; } else { if ($options['selects']) { $options['selects'] = array($options['selects'], $select); } else { $options['selects'] = array($select); } } // Get the annotations "views_counter" for each entity $metastring_id = elgg_get_metastring_id('views_counter'); $join = 'LEFT JOIN ' . $dbprefix . 'annotations a ON a.entity_guid = e.guid AND a.name_id = ' . $metastring_id; if (is_array($options['joins'])) { $options['joins'][] = $join; } else { if ($options['joins']) { $options['joins'] = array($options['joins'], $join); } else { $options['joins'] = array($join); } } // JOIN the value of the annotations. The value of each views counter... $options['joins'][] = 'LEFT JOIN ' . $dbprefix . 'metastrings ms ON a.entity_guid = e.guid AND a.name_id = ' . $metastring_id . ' AND a.value_id = ms.id'; // Check if the user does not want to list by best average any value different of: 'desc' if ($options['order_by'] != 'asc') { $options['order_by'] = ' views_counter desc, e.time_created desc'; } else { $options['order_by'] = ' views_counter asc, e.time_created desc'; } // Group the result of JOIN annotations by entity because each entity may have infinite annotations "generic_rate" $options['group_by'] .= ' e.guid '; // Let the elgg_get_entities() function make do work for us :) $entities = elgg_get_entities($options); return $entities; }
/** * Update a specific piece of metadata. * * @param int $id ID of the metadata to update * @param string $name Metadata name * @param string $value Metadata value * @param string $value_type Value type * @param int $owner_guid Owner guid * @param int $access_id Access ID * * @return bool */ function update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id) { global $CONFIG; $id = (int) $id; if (!($md = elgg_get_metadata_from_id($id))) { return false; } if (!$md->canEdit()) { return false; } // If memcached then we invalidate the cache for this entry static $metabyname_memcache; if (!$metabyname_memcache && is_memcache_available()) { $metabyname_memcache = new ElggMemcache('metabyname_memcache'); } if ($metabyname_memcache) { // @todo fix memcache (name_id is not a property of ElggMetadata) $metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}"); } $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; // Support boolean types (as integers) if (is_bool($value)) { $value = (int) $value; } $value_id = elgg_get_metastring_id($value); if (!$value_id) { return false; } $name_id = elgg_get_metastring_id($name); if (!$name_id) { return false; } // If ok then add it $query = "UPDATE {$CONFIG->dbprefix}metadata" . " set name_id='{$name_id}', value_id='{$value_id}', value_type='{$value_type}', access_id={$access_id}," . " owner_guid={$owner_guid} where id={$id}"; $result = update_data($query); if ($result !== false) { _elgg_get_metadata_cache()->save($md->entity_guid, $name, $value); // @todo this event tells you the metadata has been updated, but does not // let you do anything about it. What is needed is a plugin hook before // the update that passes old and new values. $obj = elgg_get_metadata_from_id($id); elgg_trigger_event('update', 'metadata', $obj); } return $result; }
$options["relationship_guid"] = $group->getGUID(); $options["inverse_relationship"] = true; } else { $options["relationship"] = "member_of_site"; $options["relationship_guid"] = $site->getGUID(); $options["inverse_relationship"] = true; } $users = elgg_get_entities_from_relationship($options); if (!empty($users)) { foreach ($users as $user) { $result[] = array("type" => "user", "username" => $user->username, "name" => $user->name, "icon" => $user->getIconURL("tiny")); } } } elseif (substr($q, 0, 1) == "#") { $tag = substr($q, 1); $tags_id = elgg_get_metastring_id("tags"); $thewire_id = get_subtype_id("object", "thewire"); $query = "SELECT DISTINCT *"; $query .= " FROM (SELECT ms1.string as value"; $query .= " FROM " . elgg_get_config("dbprefix") . "entities e"; $query .= " JOIN " . elgg_get_config("dbprefix") . "metadata m ON e.guid = m.entity_guid"; $query .= " JOIN " . elgg_get_config("dbprefix") . "metastrings ms1 ON m.value_id = ms1.id"; $query .= " WHERE (e.type = 'object' AND e.subtype = " . $thewire_id . ")"; $query .= " AND (e.owner_guid = " . elgg_get_logged_in_user_guid() . ")"; $query .= " AND (m.name_id = " . $tags_id . ")"; $query .= " AND (ms1.string LIKE '%" . sanitise_string($tag) . "%')"; $query .= " AND " . get_access_sql_suffix("e"); $query .= " AND " . get_access_sql_suffix("m"); $query .= " ORDER BY m.time_created DESC) a"; $query .= " LIMIT 0, " . $limit; $rows = get_data($query);
} else { $values_where .= " OR (n_table.value_id IN ({$value_id}))"; } } else { $values_where .= "(n_table.value_id IN ({$value_id}))"; } } $values_where .= ")"; } // excluded tags $excluded_values = string_to_tag_array($widget->excluded_tags); if ($excluded_values) { // and value_id not in $value_ids = array(); foreach ($excluded_values as $excluded_value) { $value_ids += elgg_get_metastring_id($excluded_value, false); } if (!empty($values_where)) { $values_where .= " AND "; } $values_where .= "e.guid NOT IN (SELECT DISTINCT entity_guid FROM " . $dbprefix . "metadata WHERE name_id IN (" . implode(",", $name_ids) . ") AND value_id IN (" . implode(",", $value_ids) . "))"; } $access = _elgg_get_access_where_sql(array("table_alias" => 'n_table')); if ($names_where && $values_where) { $wheres[] = "({$names_where} AND {$values_where} AND {$access})"; } elseif ($names_where) { $wheres[] = "({$names_where} AND {$access})"; } elseif ($values_where) { $wheres[] = "({$values_where} AND {$access})"; } $options = array("type" => "object", "subtypes" => $content_type, "limit" => $count, "full_view" => false, "pagination" => false, "joins" => $joins, "wheres" => $wheres);
<?php /** * Set validation metadata on unvalidated users to false rather than * not existing. This is needed because of the change in how validation is * being handled. */ // turn off system log because of all the metadata this can create elgg_unregister_event_handler('all', 'all', 'system_log_listener'); elgg_unregister_event_handler('log', 'systemlog', 'system_log_default_logger'); $ia = elgg_set_ignore_access(TRUE); $hidden_entities = access_get_show_hidden_status(); access_show_hidden_entities(TRUE); $validated_id = elgg_get_metastring_id('validated'); $one_id = elgg_get_metastring_id(1); $query = "SELECT guid FROM {$CONFIG->dbprefix}entities e\n\t\t\tWHERE e.type = 'user' AND e.enabled = 'no' AND\n\t\t\tNOT EXISTS (\n\t\t\t\tSELECT 1 FROM {$CONFIG->dbprefix}metadata md\n\t\t\t\tWHERE md.entity_guid = e.guid\n\t\t\t\tAND md.name_id = {$validated_id}\n\t\t\t\tAND md.value_id = {$one_id})"; $user_guids = mysql_query($query); while ($user_guid = mysql_fetch_object($user_guids)) { create_metadata($user_guid->guid, 'validated', false, '', 0, ACCESS_PUBLIC, false); } access_show_hidden_entities($hidden_entities); elgg_set_ignore_access($ia);