/** * Clean up operations on calendar delete * * @param string $event "delete" * @param string $type "object" * @param ElggEntity $entity Entity being deleted */ function delete_event_handler($event, $type, $entity) { if ($entity instanceof Calendar) { // Do not allow users to delete publi calendars if ($entity->isPublicCalendar() && !elgg_is_admin_logged_in()) { register_error(elgg_echo('events:error:public_calendar_delete')); return false; } // Move all orphaned events to the public calendar $owner = $entity->getContainerEntity(); $public_calendar = Calendar::getPublicCalendar($owner); if (!$public_calendar) { register_error(elgg_echo('events:error:no_public_for_orphans')); return false; } $dbprefix = elgg_get_config('dbprefix'); $relationship_name = sanitize_string(Calendar::EVENT_CALENDAR_RELATIONSHIP); $calendar_subtype_id = (int) get_subtype_id('object', Calendar::SUBTYPE); // Get all events that do not appear on container's other calendars $events = new ElggBatch('elgg_get_entities_from_relationship', array('types' => 'object', 'subtypes' => Event::SUBTYPE, 'relationship' => Calendar::EVENT_CALENDAR_RELATIONSHIP, 'relationship_guid' => $entity->guid, 'inverse_relationship' => true, 'limit' => 0, 'wheres' => array("NOT EXISTS(SELECT * FROM {$dbprefix}entity_relationships er2\n\t\t\t\t\tJOIN {$dbprefix}entities e2 ON er2.guid_two = e2.guid\n\t\t\t\t\tWHERE er2.relationship = '{$relationship_name}'\n\t\t\t\t\t\tAND er2.guid_one = e.guid\n\t\t\t\t\t\tAND er2.guid_two != {$entity->guid}\n\t\t\t\t\t\tAND e2.container_guid = {$entity->container_guid}\n\t\t\t\t\t\tAND e2.type = 'object' AND e2.subtype = {$calendar_subtype_id})"))); foreach ($events as $event) { /* @var Event $event */ $public_calendar->addEvent($event); } } return true; }
function profile_manager_run_once() { global $CONFIG; // upgrade $profile_field_class_name = "ProfileManagerCustomProfileField"; $group_field_class_name = "ProfileManagerCustomGroupField"; $field_type_class_name = "ProfileManagerCustomProfileType"; $field_category_class_name = "ProfileManagerCustomFieldCategory"; if ($id = get_subtype_id('object', ProfileManagerCustomProfileField::SUBTYPE)) { update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes set class='{$profile_field_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomProfileField::SUBTYPE, $profile_field_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomGroupField::SUBTYPE)) { update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes set class='{$group_field_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomGroupField::SUBTYPE, $group_field_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomProfileType::SUBTYPE)) { update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes set class='{$field_type_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomProfileType::SUBTYPE, $field_type_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomFieldCategory::SUBTYPE)) { update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes set class='{$field_category_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomFieldCategory::SUBTYPE, $field_category_class_name); } }
/** * Push the blog post to the configured site */ function blog2groups_push_post($event, $object_type, $object) { // work around Elgg bug with subtype $id = get_subtype_id('object', 'blog'); if ($object->subtype !== 'blog' && $object->subtype !== $id) { return; } if ($object->access_id == ACCESS_PRIVATE) { return; } $url = get_plugin_setting('url', 'blog2groups'); if (!$url) { return; } // work around a Elgg bug with encoding parameters $url = str_replace('&', '&', $url); $body = $object->summary . "\n\n" . $object->description; $params = array('username' => $object->getOwnerEntity()->username, 'title' => $object->title, 'body' => $body); $post_data = http_build_query($params); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $json = curl_exec($ch); curl_close($ch); $result = json_decode($json); if ($result->status != 0) { error_log("Failed to send blog post: {$result->message}"); } }
public function search($string, $search_type, $type, $subtypes = array(), $limit = 10, $offset = 0, $sort = "", $order = "", $container_guid = 0, $profile_fields = array()) { if ($search_type == 'tags') { $search_type = SEARCH_TAGS; } else { $search_type = SEARCH_DEFAULT; } $query = new ESQuery($this->index, $search_type); $query->setOffset($offset); $query->setLimit($limit); if ($type) { $query->filterType($type); } if ($subtypes) { $search_subtypes = array(); if (is_array($subtypes)) { foreach ($subtypes as $subtype) { $search_subtypes[] = get_subtype_id('object', $subtype); } } else { $search_subtypes[] = get_subtype_id('object', $subtypes); } $query->filterSubtypes($search_subtypes); } if ($container_guid) { $query->filterContainer($container_guid); } if ($profile_fields && count($profile_fields) > 0) { $query->filterProfileFields($profile_fields); } try { $results = $this->client->search($query->search($string)); } catch (Exception $e) { elgg_log('Elasticsearch search exception ' . $e->getMessage(), 'ERROR'); return array('count' => 0, 'count_per_type' => array(), 'count_per_subtype' => array(), 'hits' => array()); } $hits = array(); foreach ($results['hits']['hits'] as $hit) { if ($hit['_type'] == 'annotation') { $object = elgg_get_annotation_from_id($hit['_id']); } else { $object = get_entity($hit['_id']); } if ($object) { $hits[] = $object; } } $count_per_type = array(); foreach ($results['facets']['type']['terms'] as $type) { $count_per_type[$type['term']] = $type['count']; } $count_per_subtype = array(); foreach ($results['facets']['subtype']['terms'] as $subtype) { if ($subtype['term']) { $key = get_subtype_from_id($subtype['term']); $count_per_subtype[$key] = $subtype['count']; } } return array('count' => $results['hits']['total'], 'count_per_type' => $count_per_type, 'count_per_subtype' => $count_per_subtype, 'hits' => $hits); }
/** * Set the correct class for the GroupMail subtype * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied object * * @return void */ public static function setGroupMailClassHandler($event, $type, $object) { if (get_subtype_id('object', \GroupMail::SUBTYPE)) { update_subtype('object', \GroupMail::SUBTYPE, 'GroupMail'); } else { add_subtype('object', \GroupMail::SUBTYPE, 'GroupMail'); } }
/** * Listen to the upgrade event to set the correct class handler * * @param string $event the name of the event * @param string $type the type of the event * @param null $object supplied param * * @return void */ public static function setClassHandler($event, $type, $object) { if (get_subtype_id('object', \CSVExport::SUBTYPE)) { update_subtype('object', \CSVExport::SUBTYPE, 'CSVExport'); } else { add_subtype('object', \CSVExport::SUBTYPE, 'CSVExport'); } }
/** * Update the class for publication subtype * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied params * * @return void */ public static function setClassHandler($event, $type, $object) { // set correct class handler for Publication if (get_subtype_id('object', \Publication::SUBTYPE)) { update_subtype('object', \Publication::SUBTYPE, 'Publication'); } else { add_subtype('object', \Publication::SUBTYPE, 'Publication'); } }
/** * Update subtype * * @param ElggObject $page */ function pages_2012061800($page) { $dbprefix = elgg_get_config('dbprefix'); $subtype_id = (int) get_subtype_id('object', 'page_top'); $page_guid = (int) $page->guid; update_data("UPDATE {$dbprefix}entities\n\t\tSET subtype = {$subtype_id} WHERE guid = {$page_guid}"); error_log("called"); return true; }
/** * Make sure the class handler for QuickLink is correct * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object misc params * * @return void */ public static function setClassHandler($event, $type, $object) { // set correct class handler for QuickLink if (get_subtype_id('object', \QuickLink::SUBTYPE)) { update_subtype('object', \QuickLink::SUBTYPE, 'QuickLink'); } else { add_subtype('object', \QuickLink::SUBTYPE, 'QuickLink'); } }
/** * Event handler for when an API key is deleted * * @param unknown_type $event * @param unknown_type $object_type * @param unknown_type $object */ function apiadmin_delete_key($event, $object_type, $object = null) { global $CONFIG; if ($object && $object->subtype === get_subtype_id('object', 'api_key')) { // Delete secret key return remove_api_user($CONFIG->site_id, $object->public); } return true; }
/** * {@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); }
/** * Get an array of tags with weights for use with the output/tagcloud view. * * @param int $threshold Get the threshold of minimum number of each tags to bother with (ie only show tags where there are more than $threshold occurances) * @param int $limit Number of tags to return * @param string $metadata_name Optionally, the name of the field you want to grab for * @param string $entity_type Optionally, the entity type ('object' etc) * @param string $entity_subtype The entity subtype, optionally * @param int $owner_guid The GUID of the tags owner, optionally * @param int $site_guid Optionally, the site to restrict to (default is the current site) * @return array|false Array of objects with ->tag and ->total values, or false on failure */ function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object", $entity_subtype = "", $owner_guid = "", $site_guid = -1) { global $CONFIG; $threshold = (int) $threshold; $limit = (int) $limit; if (!empty($metadata_name)) { $metadata_name = (int) get_metastring_id($metadata_name); } else { $metadata_name = 0; } $entity_subtype = get_subtype_id($entity_type, $entity_subtype); $entity_type = sanitise_string($entity_type); if ($owner_guid != "") { if (is_array($owner_guid)) { foreach ($owner_guid as $key => $val) { $owner_guid[$key] = (int) $val; } } else { $owner_guid = (int) $owner_guid; } } if ($site_guid < 0) { $site_guid = $CONFIG->site_id; } //$access = get_access_list(); $query = "SELECT msvalue.string as tag, count(msvalue.id) as total "; $query .= "FROM {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}metadata md on md.entity_guid = e.guid "; $query .= " join {$CONFIG->dbprefix}entity_subtypes subtype on subtype.id = e.subtype "; $query .= " join {$CONFIG->dbprefix}metastrings msvalue on msvalue.id = md.value_id "; $query .= " where msvalue.string != '' "; if ($metadata_name > 0) { $query .= " and md.name_id = {$metadata_name} "; } if ($site_guid > 0) { $query .= " and e.site_guid = {$site_guid} "; } if ($entity_subtype > 0) { $query .= " and e.subtype = {$entity_subtype} "; } if ($entity_type != "") { $query .= " and e.type = '{$entity_type}' "; } if (is_array($owner_guid)) { $query .= " and e.container_guid in (" . implode(",", $owner_guid) . ")"; } else { if (is_int($owner_guid)) { $query .= " and e.container_guid = {$owner_guid} "; } } //$userid = get_loggedin_userid(); //$query .= " and (e.access_id in {$access} or (e.access_id = " . ACCESS_PRIVATE . " and e.owner_guid = {$userid}))"; $query .= ' and ' . get_access_sql_suffix("e"); // Add access controls $query .= " group by msvalue.string having total > {$threshold} order by total desc limit {$limit} "; return get_data($query); }
function upgrade_1395096061() { $subtypes = array(HYPEGAMEMECHANICS_BADGE_SUBTYPE, HYPEGAMEMECHANICS_BADGERULE_SUBTYPE, HYPEGAMEMECHANICS_SCORE_SUBTYPE); foreach ($subtypes as $subtype) { if (get_subtype_id('object', $subtype)) { update_subtype('object', $subtype); } else { add_subtype('object', $subtype); } } }
/** * Listen to upgrade event * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied params * * @return void */ function wizard_upgrade_system_handler($event, $type, $object) { $id = get_subtype_id('object', Wizard::SUBTYPE); if (empty($id)) { // add subtype registration add_subtype('object', Wizard::SUBTYPE, 'Wizard'); } elseif (get_subtype_class_from_id($id) !== 'Wizard') { // update subtype registration update_subtype('object', Wizard::SUBTYPE, 'Wizard'); } }
public function testSubtypeAddRemove() { $test_subtype = 'test_1389988642'; $object = new \ElggObject(); $object->subtype = $test_subtype; $object->save(); $this->assertTrue(is_numeric(get_subtype_id('object', $test_subtype))); $object->delete(); remove_subtype('object', $test_subtype); $this->assertFalse(get_subtype_id('object', $test_subtype)); }
/** * Listen to the upgrade event * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied params */ function haarlem_tangram_upgrade($event, $type, $object) { // register correct class for future use if (get_subtype_id('object', TangramVacancy::SUBTYPE)) { update_subtype('object', TangramVacancy::SUBTYPE, 'TangramVacancy'); } else { add_subtype('object', TangramVacancy::SUBTYPE, 'TangramVacancy'); } // reset xml cache haarlem_tangram_clear_cached_xml(); }
/** * Listen for thewire and push messages accordingly. */ function twitterservice_wire_listener($event, $object_type, $object) { if ($object && $object->subtype == get_subtype_id('object', 'thewire')) { if (get_plugin_usersetting('sendtowire', $object->owner_guid, 'twitterservice') == 'yes') { $twittername = get_plugin_usersetting('twittername', $object->owner_guid, 'twitterservice'); $twitterpass = get_plugin_usersetting('twitterpass', $object->owner_guid, 'twitterservice'); if ($twittername && $twitterpass) { twitterservice_send($twittername, $twitterpass, $object->description); } } } }
/** * Check the class assosiation * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied params * * @return void */ public static function checkClasses($event, $type, $object) { if (get_subtype_id('object', \APIApplication::SUBTYPE)) { update_subtype('object', \APIApplication::SUBTYPE, 'APIApplication'); } else { add_subtype('object', \APIApplication::SUBTYPE, 'APIApplication'); } if (get_subtype_id('object', \APIApplicationUserSetting::SUBTYPE)) { update_subtype('object', \APIApplicationUserSetting::SUBTYPE, 'APIApplicationUserSetting'); } else { add_subtype('object', \APIApplicationUserSetting::SUBTYPE, 'APIApplicationUserSetting'); } }
/** * Loads the full ElggPodcast when given a guid. * * @param mixed $guid GUID of an ElggObject or the stdClass object from entities table * * @return bool * @throws InvalidClassException */ protected function load($guid) { $attr_loader = new ElggAttributeLoader(get_class(), 'object', $this->attributes); $attr_loader->requires_access_control = true; $attr_loader->secondary_loader = 'get_object_entity_as_row'; $attrs = $attr_loader->getRequiredAttributes($guid); if (!$attrs) { return false; } // Force subtype to podcast for this loaded entity $attrs['subtype'] = get_subtype_id('object', 'podcast'); $this->attributes = $attrs; $this->attributes['tables_loaded'] = 2; return true; }
/** * Setup a mock entity * * @param int $guid GUID of the mock entity * @param string $type Type of the mock entity * @param string $subtype Subtype of the mock entity * @param array $attributes Attributes of the mock entity * @return ElggEntity */ public function setup($guid, $type, $subtype, array $attributes = []) { while (!isset($guid)) { $this->iterator++; if (!isset($this->row[$this->iterator])) { $guid = $this->iterator; } } if ($subtype) { $subtype_id = get_subtype_id($type, $subtype); if (!$subtype_id) { $subtype_id = add_subtype($type, $subtype); } } else { if (isset($attributes['subtype_id'])) { $subtype_id = $attributes['subtype_id']; $subtype = get_subtype_from_id($subtype_id); } } $attributes['guid'] = $guid; $attributes['type'] = $type; $attributes['subtype'] = $subtype_id; $time = $this->getCurrentTime()->getTimestamp(); $primary_attributes = array('owner_guid' => 0, 'container_guid' => 0, 'access_id' => ACCESS_PUBLIC, 'time_created' => $time, 'time_updated' => $time, 'last_action' => $time, 'enabled' => 'yes'); switch ($type) { case 'object': $external_attributes = ['title' => null, 'description' => null]; break; case 'user': $external_attributes = ['name' => "John Doe {$guid}", 'username' => "john_doe_{$guid}", 'password_hash' => null, 'email' => "john_doe_{$guid}@example.com", 'language' => 'en', 'banned' => "no", 'admin' => 'no', 'prev_last_action' => null, 'last_login' => null, 'prev_last_login' => null]; break; case 'group': $external_attributes = ['name' => null, 'description' => null]; break; } $map = array_merge($primary_attributes, $external_attributes, $attributes); $attrs = (object) $map; $this->rows[$guid] = $attrs; $this->addQuerySpecs($attrs); $entity = $this->rowToElggStar($this->rows[$guid]); foreach ($attrs as $name => $value) { if (!isset($entity->{$name}) || $entity->{$name} != $value) { // not an attribute, so needs to be set again $entity->{$name} = $value; } } return $entity; }
/** * Listen to upgrade event * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied params * * @return void */ public static function fixClasses($event, $type, $object) { $id = get_subtype_id('object', \Wizard::SUBTYPE); if (empty($id)) { // add subtype registration add_subtype('object', \Wizard::SUBTYPE, 'Wizard'); } elseif (get_subtype_class_from_id($id) !== 'Wizard') { // update subtype registration update_subtype('object', \Wizard::SUBTYPE, 'Wizard'); } $id = get_subtype_id('object', \WizardStep::SUBTYPE); if (empty($id)) { // add subtype registration add_subtype('object', \WizardStep::SUBTYPE, 'WizardStep'); } elseif (get_subtype_class_from_id($id) !== 'WizardStep') { // update subtype registration update_subtype('object', \WizardStep::SUBTYPE, 'WizardStep'); } }
function rijkshuisstijl_get_popular_objects($subtype = 'question', ElggGroup $group = null) { global $CONFIG; $id = (int) get_subtype_id("object", $subtype); $sql = "SELECT guid FROM elgg_entity_views WHERE type = 'object' AND subtype = {$id} AND site_guid = {$CONFIG->site_guid}"; if ($group) { $container_guid = (int) $group->guid; $sql .= " AND container_guid = {$container_guid}"; } $sql .= " ORDER BY views DESC LIMIT 5"; $return = array(); foreach (get_data($sql) as $object) { $object = get_entity($object->guid); if ($object) { $return[] = $object; } } return $return; }
/** * Custom clauses for forum ordering */ function hj_forum_order_by_clauses($hook, $type, $options, $params) { $order_by = $params['order_by']; $direction = $params['direction']; list($prefix, $column) = explode('.', $order_by); if (!$prefix || !$column) { return $options; } if ($prefix !== 'forum') { return $options; } $prefix = sanitize_string($prefix); $column = sanitize_string($column); $direction = sanitize_string($direction); $dbprefix = elgg_get_config('dbprefix'); $order_by_prev = elgg_extract('order_by', $options, false); switch ($column) { case 'topics': $options = hj_framework_get_order_by_descendant_count_clauses(array('hjforum', 'hjforumtopic'), $direction, $options); break; case 'posts': $options = hj_framework_get_order_by_descendant_count_clauses(array('hjforumpost'), $direction, $options); break; case 'author': $options['joins'][] = "JOIN {$dbprefix}users_entity ue ON ue.guid = e.owner_guid"; $options['order_by'] = "ue.name {$direction}"; break; case 'sticky': $subtype_ids = implode(',', array(get_subtype_id('object', 'hjforum'), get_subtype_id('object', 'hjforumtopic'))); $options['selects'][] = "SUM(stickymsv.string) stickyval"; $options['joins'][] = "JOIN {$dbprefix}metadata stickymd ON e.guid = stickymd.entity_guid"; $options['joins'][] = "JOIN {$dbprefix}metastrings stickymsn ON (stickymsn.string = 'sticky')"; $options['joins'][] = "LEFT JOIN {$dbprefix}metastrings stickymsv ON (stickymd.name_id = stickymsn.id AND stickymd.value_id = stickymsv.id)"; $options['group_by'] = 'e.guid'; $options['order_by'] = "FIELD(e.subtype, {$subtype_ids}), ISNULL(SUM(stickymsv.string)), SUM(stickymsv.string) = 0, SUM(stickymsv.string) {$direction}, e.time_created DESC"; break; } if ($order_by_prev) { $options['order_by'] = "{$order_by_prev}, {$options['order_by']}"; } return $options; }
/** * Add sql clauses to order entities by descendants count * * @param array $subtypes Array of descendant subtypes * @param str $direction Order by direction * @param array $options Original options array */ function hj_framework_get_order_by_descendant_count_clauses($subtypes, $direction, $options) { foreach ($subtypes as $st) { if ($id = get_subtype_id('object', $st)) { $subtype_ids[] = $id; } } $subtype_ids_str = implode(',', $subtype_ids); if (empty($subtype_ids_str)) { return $options; } $dbprefix = elgg_get_config('dbprefix'); $options['selects'][] = "COUNT(r_descendant.guid_one)"; $options['joins'][] = "JOIN {$dbprefix}entities e_descendant ON (e_descendant.subtype IN ({$subtype_ids_str}))"; $options['joins'][] = "LEFT JOIN {$dbprefix}entity_relationships r_descendant ON (e.guid = r_descendant.guid_two AND r_descendant.relationship = 'descendant' AND r_descendant.guid_one = e_descendant.guid)"; $options['wheres'][] = get_access_sql_suffix('e_descendant'); $options['group_by'] = 'e.guid'; $options['order_by'] = "count(r_descendant.guid_one) {$direction}, e.time_created DESC"; return $options; }
/** * Run once function * * @return void */ function profiles_go_run_once() { $dbprefix = elgg_get_config("dbprefix"); // upgrade class names for subtypes $profile_field_class_name = "ProfileManagerCustomProfileField"; $trip_field_class_name = "ProfileManagerCustomTripField"; $field_type_class_name = "ProfileManagerCustomProfileType"; $field_category_class_name = "ProfileManagerCustomFieldCategory"; if ($id = get_subtype_id('object', ProfileManagerCustomProfileField::SUBTYPE)) { update_data("UPDATE {$dbprefix}entity_subtypes set class='{$profile_field_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomProfileField::SUBTYPE, $profile_field_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomTripField::SUBTYPE)) { update_data("UPDATE {$dbprefix}entity_subtypes set class='{$trip_field_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomTripField::SUBTYPE, $trip_field_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomProfileType::SUBTYPE)) { update_data("UPDATE {$dbprefix}entity_subtypes set class='{$field_type_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomProfileType::SUBTYPE, $field_type_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomFieldCategory::SUBTYPE)) { update_data("UPDATE {$dbprefix}entity_subtypes set class='{$field_category_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomFieldCategory::SUBTYPE, $field_category_class_name); } // update ownerships of profile manager field configuration // owner should be site instead of a user (prevents problems when upgrading) // Added in Profile Manager v5.6 $options = array("type" => "object", "subtypes" => array(ProfileManagerCustomProfileField::SUBTYPE, ProfileManagerCustomTripField::SUBTYPE, ProfileManagerCustomProfileType::SUBTYPE, ProfileManagerCustomFieldCategory::SUBTYPE), "limit" => false); $entities = elgg_get_entities($options); foreach ($entities as $entity) { $entity->owner_guid = $entity->site_guid; $entity->container_guid = $entity->site_guid; $entity->save(); } }
<?php /** * Register classes */ if (!get_subtype_id('object', Wizard::SUBTYPE)) { // new installation add_subtype('object', Wizard::SUBTYPE, 'Wizard'); } else { update_subtype('object', Wizard::SUBTYPE, 'Wizard'); }
function get_entities_from_metadata_by_value($meta_array, $entity_type = "", $entity_subtype = "", $count = false, $owner_guid = 0, $container_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0) { global $CONFIG; // ORDER BY if ($order_by == "") { $order_by = "e.time_created desc"; } $order_by = sanitise_string($order_by); $where = array(); // Filetr by metadata $mindex = 1; // Starting index of joined metadata/metastring tables $join_meta = ""; $query_access = ""; foreach ($meta_array as $meta) { $join_meta .= "JOIN {$CONFIG->dbprefix}metadata m{$mindex} on e.guid = m{$mindex}.entity_guid "; $join_meta .= "JOIN {$CONFIG->dbprefix}metastrings v{$mindex} on v{$mindex}.id = m{$mindex}.value_id "; $meta_n = get_metastring_id($meta['name']); $where[] = "m{$mindex}.name_id='{$meta_n}'"; if (strtolower($meta['operand']) == "like") { // "LIKE" search $where[] = "v{$mindex}.string LIKE ('" . $meta['value'] . "') "; } elseif (strtolower($meta['operand']) == "in") { // TO DO - "IN" search } elseif ($meta['operand'] != '') { // Simple operand search $where[] = "v{$mindex}.string" . $meta['operand'] . "'" . $meta['value'] . "'"; } $query_access .= ' and ' . get_access_sql_suffix("m{$mindex}"); // Add access controls $mindex++; } $limit = (int) $limit; $offset = (int) $offset; if (is_array($owner_guid) && count($owner_guid)) { foreach ($owner_guid as $key => $guid) { $owner_guid[$key] = (int) $guid; } } else { $owner_guid = (int) $owner_guid; } if (is_array($container_guid) && count($container_guid)) { foreach ($container_guid as $key => $guid) { $container_guid[$key] = (int) $guid; } } else { $container_guid = (int) $container_guid; } $site_guid = (int) $site_guid; if ($site_guid == 0) { $site_guid = $CONFIG->site_guid; } $entity_type = sanitise_string($entity_type); if ($entity_type != "") { $where[] = "e.type='{$entity_type}'"; } $entity_subtype = get_subtype_id($entity_type, $entity_subtype); if ($entity_subtype) { $where[] = "e.subtype={$entity_subtype}"; } if ($site_guid > 0) { $where[] = "e.site_guid = {$site_guid}"; } if (is_array($owner_guid)) { $where[] = "e.owner_guid in (" . implode(",", $owner_guid) . ")"; } else { if ($owner_guid > 0) { $where[] = "e.owner_guid = {$owner_guid}"; } } if (is_array($container_guid)) { $where[] = "e.container_guid in (" . implode(",", $container_guid) . ")"; } else { if ($container_guid > 0) { $where[] = "e.container_guid = {$container_guid}"; } } if (!$count) { $query = "SELECT distinct e.* "; } else { $query = "SELECT count(distinct e.guid) as total "; } $query .= "FROM {$CONFIG->dbprefix}entities e "; $query .= $join_meta; $query .= " WHERE "; foreach ($where as $w) { $query .= " {$w} and "; } $query .= get_access_sql_suffix("e"); // Add access controls $query .= $query_access; if (!$count) { $query .= " order by {$order_by} limit {$offset}, {$limit}"; // Add order and limit return get_data($query, "entity_row_to_elggstar"); } else { $row = get_data_row($query); //echo $query.mysql_error().__FILE__.__LINE__; if ($row) { return $row->total; } } return false; }
/** * As get_entities_from_metadata_groups() but with multiple entities. * * @param int $group_guid The ID of the group. * @param array $meta_array Array of 'name' => 'value' pairs * @param string $entity_type The type of entity to look for, eg 'site' or 'object' * @param string $entity_subtype The subtype of the entity. * @param int $owner_guid Owner GUID * @param int $limit Limit * @param int $offset Offset * @param string $order_by Optional ordering. * @param int $site_guid Site GUID. 0 for current, -1 for any * @param bool $count Return count of entities instead of entities * * @return int|array List of ElggEntities, or the total number if count is set to false * @deprecated 1.8 Use elgg_get_entities_from_metadata() */ function get_entities_from_metadata_groups_multi($group_guid, $meta_array, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) { elgg_deprecated_notice("get_entities_from_metadata_groups_multi was deprecated in 1.8.", 1.8); global $CONFIG; if (!is_array($meta_array) || sizeof($meta_array) == 0) { return false; } $where = array(); $mindex = 1; $join = ""; foreach ($meta_array as $meta_name => $meta_value) { $meta_n = get_metastring_id($meta_name); $meta_v = get_metastring_id($meta_value); $join .= " JOIN {$CONFIG->dbprefix}metadata m{$mindex} on e.guid = m{$mindex}.entity_guid" . " JOIN {$CONFIG->dbprefix}objects_entity o on e.guid = o.guid "; if ($meta_name != "") { $where[] = "m{$mindex}.name_id='{$meta_n}'"; } if ($meta_value != "") { $where[] = "m{$mindex}.value_id='{$meta_v}'"; } $mindex++; } $entity_type = sanitise_string($entity_type); $entity_subtype = get_subtype_id($entity_type, $entity_subtype); $limit = (int) $limit; $offset = (int) $offset; if ($order_by == "") { $order_by = "e.time_created desc"; } $order_by = sanitise_string($order_by); $owner_guid = (int) $owner_guid; $site_guid = (int) $site_guid; if ($site_guid == 0) { $site_guid = $CONFIG->site_guid; } //$access = get_access_list(); if ($entity_type != "") { $where[] = "e.type = '{$entity_type}'"; } if ($entity_subtype) { $where[] = "e.subtype = {$entity_subtype}"; } if ($site_guid > 0) { $where[] = "e.site_guid = {$site_guid}"; } if ($owner_guid > 0) { $where[] = "e.owner_guid = {$owner_guid}"; } if ($group_guid > 0) { $where[] = "e.container_guid = {$group_guid}"; } if ($count) { $query = "SELECT count(e.guid) as total "; } else { $query = "SELECT distinct e.* "; } $query .= " from {$CONFIG->dbprefix}entities e {$join} where"; foreach ($where as $w) { $query .= " {$w} and "; } $query .= get_access_sql_suffix("e"); // Add access controls if (!$count) { $query .= " order by {$order_by} limit {$offset}, {$limit}"; // Add order and limit return get_data($query, "entity_row_to_elggstar"); } else { if ($count = get_data_row($query)) { return $count->total; } } return false; }
<?php /** * Register the Wire class for the object/wire subtype */ if (get_subtype_id('object', 'wire')) { update_subtype('object', 'wire', 'Wire'); } else { add_subtype('object', 'wire', 'Wire'); }
<?php /** @todo: remove hjForm & hjField */ $subtypes = array('hjform' => 'hjForm', 'hjfield' => 'hjField', 'hjfile' => 'hjFile', 'hjfilefolder' => 'hjFileFolder', 'hjsegment' => 'hjSegment', 'hjannotation' => 'hjAnnotation', 'hjcategory' => 'hjCategory'); foreach ($subtypes as $subtype => $class) { if (get_subtype_id('object', $subtype)) { update_subtype('object', $subtype, $class); } else { add_subtype('object', $subtype, $class); } }