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() { global $CONFIG; $validated_id = get_metastring_id('validated'); if ($validated_id === false) { $validated_id = add_metastring('validated'); } $one_id = get_metastring_id('1'); if ($one_id === false) { $one_id = add_metastring('1'); } // thanks to daveb@freenode for the SQL tips! $wheres = array(); $wheres[] = "e.enabled='no'"; $wheres[] = "NOT EXISTS (\n\t\t\tSELECT 1 FROM {$CONFIG->dbprefix}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; }
/** * Make sure users follow the wizard * * @return void */ function wizard_check_wizards() { $user = elgg_get_logged_in_user_entity(); if (empty($user)) { // only logged in users return; } if (elgg_in_context('wizard') || elgg_in_context('admin')) { // deadloop prevention and /admin is allowed return; } if (!empty($_SESSION['wizards'])) { if ($_SESSION['wizards'] === true) { return; } else { foreach ($_SESSION['wizards'] as $index => $guid) { $wizard = get_entity($guid); if (empty($wizard) || !elgg_instanceof($wizard, 'object', Wizard::SUBTYPE)) { unset($_SESSION['wizards'][$index]); continue; } forward($wizard->getURL()); } if (empty($_SESSION['wizards'])) { $_SESSION['wizards'] = true; } } } $dbprefix = elgg_get_config('dbprefix'); $endtime_id = add_metastring('endtime'); $options = array('type' => 'object', 'subtype' => Wizard::SUBTYPE, 'limit' => false, 'metadata_name_value_pairs' => array(array('name' => 'starttime', 'value' => time(), 'operand' => '<=')), 'joins' => array("JOIN {$dbprefix}metadata mde ON e.guid = mde.entity_guid", "JOIN {$dbprefix}metastrings mse ON mde.value_id = mse.id"), 'wheres' => array("(e.guid NOT IN (SELECT guid_one\n\t\t\t\tFROM {$dbprefix}entity_relationships\n\t\t\t\tWHERE relationship = 'done'\n\t\t\t\tAND guid_two = {$user->getGUID()}\n\t\t\t))", "(mde.name_id = {$endtime_id} AND mse.string = 0 OR mse.string > " . time() . ")")); $entities = elgg_get_entities_from_metadata($options); if (empty($entities)) { $_SESSION['wizards'] = true; return; } $_SESSION['wizards'] = array(); foreach ($entities as $e) { $_SESSION['wizards'][] = $e->getGUID(); } forward($entities[0]->getURL()); }
<?php // this is a perfect action for the vroom plugin... elgg_load_library('simplekaltura'); elgg_load_library('KalturaClient'); set_time_limit(0); $dbprefix = elgg_get_config('dbprefix'); $name_metastring_id = add_metastring('simplekaltura_cannot_import'); $value_metastring_id = add_metastring('1'); $options = array('type' => 'object', 'subtype' => 'kaltura_video', 'wheres' => array("NOT EXISTS ( SELECT 1 FROM {$dbprefix}metadata md WHERE md.entity_guid = e.guid AND md.name_id = {$name_metastring_id} AND md.value_id = {$value_metastring_id})"), 'limit' => false); // inc_offset = false because we take them out of the query results $videos = new ElggBatch('elgg_get_entities', $options, '', 25, false); $new = get_subtype_id('object', 'simplekaltura_video'); if (!$new) { $new = add_subtype('object', 'simplekaltura_video'); } $old = get_subtype_id('object', 'kaltura_video'); foreach ($videos as $v) { if ($v->simplekaltura_cannot_import) { // we can't import this for some reason... continue; } // note the old plugin made mixes which are deprecated and don't play properly // we can get the associated source video id instead which works correctly $entry_id = false; // check if it's a mix (most of them are) try { $client = simplekaltura_create_client(true); $entry = $client->mixing->get($v->kaltura_video_id); $xml = new SimpleXMLElement($entry->dataContent); $assets = $xml->VideoAssets->vidAsset[0];
/** * analog of Calendar::getAllEvents but doesn't limit to a specific calendar * * @param type $starttime * @param type $endtime */ public static function getAllEvents($starttime, $endtime) { $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); $dbprefix = elgg_get_config('dbprefix'); $mds_name = add_metastring('start_timestamp'); $mdre_name = add_metastring('repeat_end_timestamp'); $options = array('type' => 'object', 'subtype' => Event::SUBTYPE, 'joins' => array("JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", "JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid", "JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id"), 'wheres' => array("mds.name_id = {$mds_name}", "mdre.name_id = {$mdre_name}", "((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))"), 'limit' => false); return new ElggBatch('elgg_get_entities', $options); }
/** * Get all the groups this email address is invited for * * @param string $email the email address * @param int $site_guid (optional) site_guid * * @return boolean|ElggGroup[] array of groups or false on failure */ function group_tools_get_invited_groups_by_email($email, $site_guid = 0) { $result = false; if (!empty($email)) { $dbprefix = elgg_get_config("dbprefix"); $site_secret = get_site_secret(); $email = sanitise_string(strtolower($email)); $email_invitation_id = add_metastring("email_invitation"); if ($site_guid === 0) { $site_guid = elgg_get_site_entity()->getGUID(); } $options = array("type" => "group", "limit" => false, "site_guids" => $site_guid, "joins" => array("JOIN " . $dbprefix . "annotations a ON a.owner_guid = e.guid", "JOIN " . $dbprefix . "metastrings msv ON a.value_id = msv.id"), "wheres" => array("(a.name_id = " . $email_invitation_id . " AND\n\t\t\t\t\t(msv.string = md5(CONCAT('" . $site_secret . $email . "', e.guid))\n\t\t\t\t\tOR msv.string LIKE CONCAT(md5(CONCAT('" . $site_secret . $email . "', e.guid)), '|%')\n\t\t\t\t\t)\n\t\t\t\t)")); // make sure we can see all groups $ia = elgg_set_ignore_access(true); $groups = elgg_get_entities($options); if (!empty($groups)) { $result = $groups; } // restore access elgg_set_ignore_access($ia); } return $result; }
<?php $limit = get_input('limit', 20); $offset = get_input('offset', 0); $user = elgg_get_page_owner_entity(); $message_type = elgg_extract('message_type', $vars, 'all'); $read = elgg_extract('read', $vars, 'all'); if (!in_array($read, array(0, 1))) { $read = 'all'; } $strings = array('toId', $user->guid, 'readYet', $read, 'msgType', $message_type, 'msgHash'); $map = array(); foreach ($strings as $string) { $id = get_metastring_id($string); if (!$id) { $id = add_metastring($string); } $map[$string] = $id; } $dbprefix = elgg_get_config('dbprefix'); $access = get_access_sql_suffix('e', $user->guid); $subtype_id = get_subtype_id('object', 'messages'); if (!$subtype_id) { $subtype_id = add_subtype('object', 'messages'); } $query = "SELECT COUNT(DISTINCT md.value_id) AS count\n\t\t\tFROM {$dbprefix}metadata md\n\t\t\tJOIN {$dbprefix}entities e ON e.guid = md.entity_guid\n\t\t\tJOIN {$dbprefix}metadata md2 ON md2.entity_guid = md.entity_guid AND md2.name_id = {$map['msgType']}\n\t\t\tWHERE e.type = 'object' AND e.subtype = {$subtype_id}\n\t\t\t\tAND md.name_id = {$map['msgHash']}\n\t\t\t\tAND md2.value_id = {$map[$message_type]}\n\t\t\t\tAND e.owner_guid = {$user->guid}\n\t\t\t\tAND {$access}"; $count = get_data($query); $count = $count[0]->count; if (!$count) { echo elgg_autop(elgg_echo('hj:inbox:nomessages')); return;
$featured_options = array("type" => "group", "limit" => $num_display, "full_view" => false, "pagination" => false, "metadata_name_value_pairs" => array("featured_group" => "yes"), "order_by" => "RAND()"); if ($widget->show_members == "yes") { $show_members = true; } else { $show_members = false; } if ($show_members) { elgg_push_context("widgets_groups_show_members"); } $featured = elgg_list_entities_from_metadata($featured_options); if ($show_members) { elgg_pop_context(); } $random = ""; if ($show_random == "yes") { $dbprefix = elgg_get_config("dbprefix"); $featured_id = add_metastring("featured_group"); $yes_id = add_metastring("yes"); $random_options = array("type" => "group", "limit" => 1, "order_by" => "RAND()", "wheres" => array("NOT EXISTS (\n\t\t\t\tSELECT 1 FROM {$dbprefix}metadata md\n\t\t\t\tWHERE md.entity_guid = e.guid\n\t\t\t\t\tAND md.name_id = {$featured_id}\n\t\t\t\t\tAND md.value_id = {$yes_id})")); if ($random_groups = elgg_get_entities($random_options)) { $group = $random_groups[0]; $title = elgg_view("output/url", array("text" => $group->name, "href" => $group->getURL())); $icon = elgg_view_entity_icon($group, "large"); $random = elgg_view_module("main", $title, $icon, array("class" => "center")); } } $list = $featured . $random; if (empty($list)) { $list = elgg_echo("notfound"); } echo $list;
$action = current_page_url(); $action = elgg_http_remove_url_query_element($action, 'query'); $action = elgg_http_remove_url_query_element($action, 'simpletype'); $action = elgg_http_remove_url_query_element($action, 'limit'); $action = elgg_http_remove_url_query_element($action, 'offset'); echo elgg_view_form('embed/search_files', array('method' => 'get', 'disable_security' => true, 'action' => $action, 'class' => 'elgg-form-embed-search'), array('query' => $display_query, 'simpletype' => $simpletype)); $container_guids = array(elgg_get_logged_in_user_guid()); $page_owner = elgg_get_page_owner_entity(); if (elgg_instanceof($page_owner) && $page_owner->canWriteToContainer('object', 'file')) { $container_guids[] = $page_owner->guid; } $dbprefix = elgg_get_config('dbprefix'); $options = array('types' => 'object', 'subtypes' => 'file', 'limit' => $limit, 'offset' => $offset, 'container_guids' => $container_guids, 'joins' => array(), 'wheres' => array(), 'count' => true); if ($query) { $string = sanitize_string($display_query); $options['joins'][] = "JOIN {$dbprefix}objects_entity oe ON e.guid = oe.guid"; $options['wheres'][] = "oe.title LIKE '%{$string}%'"; } if ($simpletype) { $simpletype_id = add_metastring($simpletype); $md_name_id = add_metastring('simpletype'); $options['joins'][] = "JOIN {$dbprefix}metadata md ON e.guid = md.entity_guid AND md.name_id = {$md_name_id} AND md.value_id = {$simpletype_id}"; } $count = elgg_get_entities($options); if (!$count) { echo elgg_autop(elgg_echo('embed:tab:file:empty')); return; } $options['count'] = false; $files = elgg_get_entities($options); echo elgg_view('embed/list', array('items' => $files, 'count' => $count, 'limit' => $limit, 'offset' => $offset));
/** * Update an item of metadata. * * @param int $id * @param string $name * @param string $value * @param string $value_type * @param int $owner_guid * @param int $access_id */ function update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id) { global $CONFIG; $id = (int) $id; if (!($md = get_metadata($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) { $metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}"); } //$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 = get_loggedin_userid(); } $access_id = (int) $access_id; $access = get_access_sql_suffix(); // Support boolean types (as integers) if (is_bool($value)) { if ($value) { $value = 1; } else { $value = 0; } } // 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}metadata set value_id='{$value}', value_type='{$value_type}', access_id={$access_id}, owner_guid={$owner_guid} where id={$id} and name_id='{$name}'"); if ($result !== false) { $obj = get_metadata($id); if (trigger_elgg_event('update', 'metadata', $obj)) { return true; } else { delete_metadata($id); } } return $result; }
function advanced_statistics_get_groups_data($chart_id) { $result = array("data" => array(), "options" => array()); $dbprefix = elgg_get_config("dbprefix"); $current_site_guid = elgg_get_site_entity()->getGUID(); switch ($chart_id) { case "popular": $data = array(); $query = "SELECT ge.name, count(*) AS total"; $query .= " FROM " . $dbprefix . "groups_entity ge"; $query .= " JOIN " . $dbprefix . "entity_relationships r ON ge.guid = r.guid_two"; $query .= " JOIN " . $dbprefix . "entities e ON ge.guid = e.guid"; $query .= " JOIN " . $dbprefix . "entities eu ON r.guid_one = eu.guid"; $query .= " JOIN " . $dbprefix . "users_entity ue ON eu.guid = ue.guid"; $query .= " WHERE r.relationship = 'member' AND eu.type = 'user'"; $query .= " AND eu.enabled = 'yes' AND ue.banned = 'no'"; $query .= " AND e.site_guid = " . $current_site_guid . " AND e.enabled = 'yes'"; $query .= " GROUP BY ge.name"; $query .= " ORDER BY total DESC"; $query .= " LIMIT 0, 10"; if ($query_result = get_data($query)) { foreach ($query_result as $row) { $total = (int) $row->total; $data[] = array(elgg_get_excerpt($row->name, 25), $total); } } $result["data"] = array($data); $options = advanced_statistics_get_default_chart_options("bar"); $options["axes"]["xaxis"]["tickRenderer"] = "\$.jqplot.CanvasAxisTickRenderer"; $options["axes"]["xaxis"]["tickOptions"] = array("angle" => "-30", "fontSize" => "8pt"); $result["options"] = $options; break; case "popular-tools": if ($group_tools = elgg_get_config("group_tool_options")) { $yes_id = add_metastring("yes"); $data = array(); $order = array(); foreach ($group_tools as $key => $tool) { $tool_id = add_metastring($tool->name . "_enable"); $query = "SELECT md.name_id, count(*) AS total"; $query .= " FROM " . $dbprefix . "metadata md"; $query .= " JOIN " . $dbprefix . "entities e ON md.entity_guid = e.guid"; $query .= " WHERE md.name_id = " . $tool_id; $query .= " AND e.type = 'group' AND e.enabled = 'yes'"; $query .= " AND md.value_id = " . $yes_id; if ($query_result = get_data_row($query)) { $total = (int) $query_result->total; $order[$key] = $total; $data[$key] = array($tool->name . " [" . $total . "]", $total); } } array_multisort($order, $data); $result["data"] = array($data); $result["options"] = advanced_statistics_get_default_chart_options("pie"); } break; case "most-active": $data = array(); $week_ago = time() - 7 * 24 * 60 * 60; $query = "SELECT ge.name, count(*) AS total"; $query .= " FROM " . $dbprefix . "river r"; $query .= " JOIN " . $dbprefix . "entities e ON r.object_guid = e.guid"; $query .= " JOIN " . $dbprefix . "entities eg ON e.container_guid = eg.guid"; $query .= " JOIN " . $dbprefix . "groups_entity ge ON eg.guid = ge.guid"; $query .= " WHERE e.enabled = 'yes' AND e.site_guid = " . $current_site_guid; $query .= " AND eg.type = 'group' AND eg.enabled = 'yes' AND eg.site_guid = " . $current_site_guid; $query .= " AND r.posted > " . $week_ago; $query .= " GROUP BY ge.name"; $query .= " ORDER BY total DESC"; $query .= " LIMIT 0, 10"; if ($query_result = get_data($query)) { foreach ($query_result as $row) { $total = (int) $row->total; $data[] = array(elgg_get_excerpt($row->name, 25), $total); } $result["data"] = array($data); $options = advanced_statistics_get_default_chart_options("bar"); $options["axes"]["xaxis"]["tickRenderer"] = "\$.jqplot.CanvasAxisTickRenderer"; $options["axes"]["xaxis"]["tickOptions"] = array("angle" => "-30", "fontSize" => "8pt"); $result["options"] = $options; } break; case "least-active": $data = array(); $week_ago = time() - 7 * 24 * 60 * 60; $query = "SELECT ge.name, count(*) AS total"; $query .= " FROM " . $dbprefix . "river r"; $query .= " JOIN " . $dbprefix . "entities e ON r.object_guid = e.guid"; $query .= " JOIN " . $dbprefix . "entities eg ON e.container_guid = eg.guid"; $query .= " JOIN " . $dbprefix . "groups_entity ge ON eg.guid = ge.guid"; $query .= " WHERE e.enabled = 'yes' AND e.site_guid = " . $current_site_guid; $query .= " AND eg.type = 'group' AND eg.enabled = 'yes' AND eg.site_guid = " . $current_site_guid; $query .= " GROUP BY ge.name"; $query .= " ORDER BY total ASC"; $query .= " LIMIT 0, 10"; if ($query_result = get_data($query)) { foreach ($query_result as $row) { $total = (int) $row->total; $data[] = array(elgg_get_excerpt($row->name, 25), $total); } $result["data"] = array($data); $options = advanced_statistics_get_default_chart_options("bar"); $options["axes"]["xaxis"]["tickRenderer"] = "\$.jqplot.CanvasAxisTickRenderer"; $options["axes"]["xaxis"]["tickOptions"] = array("angle" => "-30", "fontSize" => "8pt"); $result["options"] = $options; } break; case "dead-vs-alive": $data = array(); $guids = array(); $month = time() - 30 * 24 * 60 * 60; $base_query = "SELECT DISTINCT eg.guid"; $base_query .= " FROM " . $dbprefix . "river r"; $base_query .= " JOIN " . $dbprefix . "entities e ON r.object_guid = e.guid"; $base_query .= " JOIN " . $dbprefix . "entities eg ON e.container_guid = eg.guid"; $base_query .= " WHERE e.enabled = 'yes' AND e.site_guid = " . $current_site_guid; $base_query .= " AND eg.enabled = 'yes' AND eg.site_guid = " . $current_site_guid; $base_query .= " AND eg.type = 'group'"; // activity in last month $month_query = $base_query . " AND r.posted >= " . $month; if ($query_result = get_data($month_query)) { $total = count($query_result); $data[] = array(elgg_echo("advanced_statistics:groups:dead_vs_alive:last_month", array($total)), $total); } // activity in last 3 months $threemonth = time() - 90 * 24 * 60 * 60; $threemonth_query_base = $base_query . " AND r.posted >= " . $threemonth; $query = $threemonth_query_base . " AND eg.guid NOT IN (" . $month_query . ")"; if ($query_result = get_data($query)) { $total = count($query_result); $data[] = array(elgg_echo("advanced_statistics:groups:dead_vs_alive:3_months", array($total)), $total); } // activity in last 6 months $sixmonth = time() - 180 * 24 * 60 * 60; $sixmonth_query_base = $base_query . " AND r.posted >= " . $sixmonth; $query = $sixmonth_query_base . " AND eg.guid NOT IN (" . $threemonth_query_base . ")"; if ($query_result = get_data($query)) { $total = count($query_result); $data[] = array(elgg_echo("advanced_statistics:groups:dead_vs_alive:6_months", array($total)), $total); } // activity in last year $year = time() - 365 * 24 * 60 * 60; $year_query_base = $base_query . " AND r.posted >= " . $year; $query = $year_query_base . " AND eg.guid NOT IN (" . $sixmonth_query_base . ")"; if ($query_result = get_data($query)) { $total = count($query_result); $data[] = array(elgg_echo("advanced_statistics:groups:dead_vs_alive:year", array($total)), $total); } // activity < last year $query = $base_query . " AND r.posted < " . $year; $query .= " AND eg.guid NOT IN (" . $year_query_base . ")"; if ($query_result = get_data($query)) { $total = count($query_result); $data[] = array(elgg_echo("advanced_statistics:groups:dead_vs_alive:more_year", array($total)), $total); } $result["data"] = array($data); $result["options"] = advanced_statistics_get_default_chart_options("pie"); break; default: $params = array("chart_id" => $chart_id, "default_result" => $result); $result = elgg_trigger_plugin_hook("groups", "advanced_statistics", $params, $result); break; } return json_encode($result); }
switch ($widget->context) { case "profile": $options["owner_guid"] = $widget->getOwnerGUID(); break; case "dashboard": $type = $widget->content_type; if ($type == "todo" && !questions_is_expert()) { $type = "mine"; } // user shows owned switch ($type) { case "todo": $getter = "elgg_get_entities_from_metadata"; // prepare options $dbprefix = elgg_get_config("dbprefix"); $correct_answer_id = add_metastring("correct_answer"); $site = elgg_get_site_entity(); $user = elgg_get_logged_in_user_entity(); $container_where = array(); $options["wheres"] = array("NOT EXISTS (\n\t\t\t\t\t\t\tSELECT 1\n\t\t\t\t\t\t\tFROM " . $dbprefix . "entities e2\n\t\t\t\t\t\t\tJOIN " . $dbprefix . "metadata md ON e2.guid = md.entity_guid\n\t\t\t\t\t\t\tWHERE e2.container_guid = e.guid\n\t\t\t\t\t\t\tAND md.name_id = " . $correct_answer_id . ")"); $options["order_by_metadata"] = array("name" => "solution_time"); if (check_entity_relationship($user->getGUID(), QUESTIONS_EXPERT_ROLE, $site->getGUID())) { $container_where[] = "(e.container_guid NOT IN (\n\t\t\t\t\t\tSELECT ge.guid\n\t\t\t\t\t\tFROM " . $dbprefix . "entities ge\n\t\t\t\t\t\tWHERE ge.type = 'group'\n\t\t\t\t\t\tAND ge.site_guid = " . $site->getGUID() . "\n\t\t\t\t\t\tAND ge.enabled = 'yes'\n\t\t\t\t\t))"; } $group_options = array("type" => "group", "limit" => false, "relationship" => QUESTIONS_EXPERT_ROLE, "relationship_guid" => $user->getGUID(), "callback" => "questions_row_to_guid"); $groups = elgg_get_entities_from_relationship($group_options); if (!empty($groups)) { $container_where[] = "(e.container_guid IN (" . implode(",", $groups) . "))"; } $container_where = "(" . implode(" OR ", $container_where) . ")"; $options["wheres"][] = $container_where;
/** * Get total score that was collected on an object by a given user with a given rule in given time frame * * @param object $object * @param ElggUser $user * @param string $rule * @param int $time_lower * @param int $time_upper * @return int */ function get_object_total($object, $user = null, $rule = null, $time_lower = null, $time_upper = null) { if (!is_object($object)) { return 0; } $object_id = isset($object->guid) ? $object->guid : $object->id; $object_type = $object->getType(); $dbprefix = elgg_get_config('dbprefix'); $msn_id = add_metastring('object_ref'); $msv_id = add_metastring("{$object_type}:{$object_id}"); $options = array('type' => 'object', 'subtype' => HYPEGAMEMECHANICS_SCORE_SUBTYPE, 'container_guid' => $user->guid, 'metadata_names' => 'annotation_value', 'metadata_calculation' => 'sum', 'metadata_created_time_lower' => $time_lower, 'metadata_created_time_upper' => $time_upper, 'joins' => array("JOIN {$dbprefix}metadata objmd ON n_table.entity_guid = objmd.entity_guid"), 'wheres' => array("(objmd.name_id = {$msn_id} AND objmd.value_id = {$msv_id})")); if (!empty($rule)) { $msn_id = add_metastring('rule'); $msv_id = add_metastring($rule); $options['joins'][] = "JOIN {$dbprefix}metadata rulemd ON n_table.entity_guid = rulemd.entity_guid"; $options['wheres'][] = "(rulemd.name_id = {$msn_id} AND rulemd.value_id = {$msv_id})"; } return (int) elgg_get_metadata($options); }
<?php // Get search-specific settings $serialized_settings = elgg_get_plugin_setting('search-settings', 'community_plugins'); $settings = unserialize($serialized_settings); if (!is_array($settings)) { $settings = array(); } $offset = get_input('offset', 0); $limit = get_input('limit', 10); $options = array('type' => 'object', 'subtype' => 'plugin_project', 'preload_owners' => true); $list_type = get_input('type'); $dbprefix = elgg_get_config('dbprefix'); switch ($list_type) { case 'recommended': $digg_id = add_metastring('plugin_digg', true); $options['selects'] = array("count(a.entity_guid) as recommendations"); $options['joins'][] = "LEFT JOIN {$dbprefix}annotations a on (e.guid = a.entity_guid AND a.name_id = {$digg_id})"; $group_bys = array('e.guid', 'a.entity_guid'); $options['group_by'] = implode(',', $group_bys); $options['order_by'] = "recommendations DESC"; break; case 'popular': $options['selects'] = array("a.downloads"); $options['joins'][] = "LEFT JOIN {$dbprefix}plugin_downloads a on (e.guid = a.guid)"; $group_bys = array('e.guid', 'a.guid'); $options['group_by'] = implode(',', $group_bys); $options['order_by'] = "a.downloads DESC"; break; case 'newest': default:
if (!empty($profile_fields)) { $params["joins"] = array("JOIN {$db_prefix}groups_entity ge ON e.guid = ge.guid", "JOIN {$db_prefix}metadata md on e.guid = md.entity_guid", "JOIN {$db_prefix}metastrings msv ON md.value_id = msv.id"); } else { $params["joins"] = array("JOIN {$db_prefix}groups_entity ge ON e.guid = ge.guid"); } $where = "ge.name LIKE '%{$query}%' OR ge.description LIKE '%{$query}%'"; if (!empty($profile_fields)) { // get the where clauses for the md names // can't use egef_metadata() because the n_table join comes too late. // $clauses = elgg_entities_get_metastrings_options("metadata", array( // "metadata_names" => $profile_fields, // )); // $params["joins"] = array_merge($clauses["joins"], $params["joins"]); $tag_name_ids = array(); foreach ($profile_fields as $field) { $tag_name_ids[] = add_metastring($field); } $md_where = "((md.name_id IN (" . implode(",", $tag_name_ids) . ")) AND (msv.string LIKE '%{$query}%'))"; $params["wheres"] = array("(({$where}) OR ({$md_where}))"); } else { $params["wheres"] = array($where); } $content = elgg_list_entities($params); } if (empty($content)) { $content = elgg_echo("groups:search:none"); } $sidebar = elgg_view("groups/sidebar/find"); $sidebar .= elgg_view("groups/sidebar/featured"); $params = array("content" => $content, "sidebar" => $sidebar, "filter" => false, "title" => $title); $body = elgg_view_layout("content", $params);
function pages_tools_daily_cron_hook($hook, $type, $return_value, $params) { if (pages_tools_use_advanced_publication_options()) { $publication_id = add_metastring("publication_date"); $expiration_id = add_metastring("expiration_date"); $dbprefix = elgg_get_config("dbprefix"); $time = elgg_extract("time", $params, time()); $publish_options = array("type" => "object", "subtype" => array("page_top"), "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("name" => "unpublished", "value" => true), "wheres" => array("((mdtime.name_id = " . $publication_id . ") AND (DATE(mstime.string) = DATE(NOW())))")); $expire_options = array("type" => "object", "subtypes" => array("page_top", "page"), "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "wheres" => pages_tools_get_publication_wheres()); $expire_options["wheres"][] = "((mdtime.name_id = " . $expiration_id . ") AND (DATE(mstime.string) = DATE(NOW())))"; // ignore access $ia = elgg_set_ignore_access(true); // get unpublished pages that need to be published if ($entities = elgg_get_entities_from_metadata($publish_options)) { foreach ($entities as $entity) { // add river event add_to_river("river/object/page/create", "create", $entity->getOwner(), $entity->getGUID()); // set time created $entity->time_created = $time; // make sure the page is listed unset($entity->unpublished); // notify the user notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("pages_tools:notify:publish:subject"), elgg_echo("pages_tools:notify:publish:message", array($entity->title, $entity->getURL()))); // save everything $entity->save(); } } // get pages that have expired if ($entities = elgg_get_entities_from_metadata($expire_options)) { foreach ($entities as $entity) { // remove river event elgg_delete_river(array("object_guid" => $entity->getGUID(), "action_type" => "create")); // make sure the page is no longer listed $entity->unpublished = true; // notify the user notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("pages_tools:notify:expire:subject"), elgg_echo("pages_tools:notify:expire:message", array($entity->title, $entity->getURL()))); // save everything $entity->save(); } } // reset access elgg_set_ignore_access($ia); } }
} } } // determine menu counters $db_prefix = elgg_get_config('dbprefix'); $count_query = "SELECT es.subtype, count(distinct e.guid) as total"; $count_query .= " FROM {$db_prefix}entities e"; $count_query .= " JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid"; $count_query .= " JOIN {$db_prefix}entity_subtypes es ON e.subtype = es.id"; $fields = array('title', 'description'); $where = search_advanced_get_where_sql('oe', $fields, $params); // add tags search if ($valid_tag_names = elgg_get_registered_tag_metadata_names()) { $tag_name_ids = array(); foreach ($valid_tag_names as $tag_name) { $tag_name_ids[] = add_metastring($tag_name); } $count_query .= " JOIN {$db_prefix}metadata md on e.guid = md.entity_guid"; $count_query .= " JOIN {$db_prefix}metastrings msv ON md.value_id = msv.id"; $md_where = "((md.name_id IN (" . implode(",", $tag_name_ids) . ")) AND msv.string = '" . sanitise_string($params["query"]) . "')"; } // add wheres $count_query .= " WHERE e.type = 'object' AND es.subtype IN ('" . implode("', '", $current_params['subtype']) . "') AND "; if ($container_guid) { $count_query .= "e.container_guid = " . $container_guid . " AND "; } if ($md_where) { $count_query .= "((" . $where . ") OR (" . $md_where . "))"; } else { $count_query .= $where; }
<?php $ha = access_get_show_hidden_status(); access_show_hidden_entities(true); $name_id = get_metastring_id('msgHash'); if (!$name_id) { $name_id = add_metastring('msgHash'); } $dbprefix = elgg_get_config('dbprefix'); $messages = elgg_get_entities(array('types' => 'object', 'subtypes' => array('messages'), 'wheres' => array("NOT EXISTS (SELECT 1 FROM {$dbprefix}metadata md WHERE md.entity_guid = e.guid\n AND md.name_id = {$name_id})"), 'order_by' => 'e.guid ASC', 'count' => true)); access_show_hidden_entities($ha); if ($messages) { echo elgg_view('framework/inbox/admin/import', array('count' => $messages)); }
/** * 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; }
function pages_tools_get_publication_wheres() { static $result; if (!isset($result)) { $result = array(); if (pages_tools_use_advanced_publication_options()) { $unpublished_id = add_metastring("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; }
* 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 = add_metastring("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":
/** * 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) { $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; $access = get_access_sql_suffix(); // Support boolean types (as integers) if (is_bool($value)) { if ($value) { $value = 1; } else { $value = 0; } } // Add the metastring $value = add_metastring($value); if (!$value) { return false; } $name = add_metastring($name); if (!$name) { return false; } // If ok then add it $query = "UPDATE {$CONFIG->dbprefix}metadata" . " set name_id='{$name}', value_id='{$value}', value_type='{$value_type}', access_id={$access_id}," . " owner_guid={$owner_guid} where id={$id}"; $result = update_data($query); if ($result !== false) { // @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; }
/** * Runonce to convert the pre Elgg 1.8 wire tools conversations to the new wire_threads * * @return void */ function thewire_tools_runonce() { $conversation_id = add_metastring("conversation"); $wire_thread_id = add_metastring("wire_thread"); $subtype_id = get_subtype_id("object", "thewire"); $query = "UPDATE " . elgg_get_config("dbprefix") . "metadata SET name_id = " . $wire_thread_id; $query .= " WHERE name_id = " . $conversation_id . " AND entity_guid IN"; $query .= " (SELECT guid FROM " . elgg_get_config("dbprefix") . "entities WHERE type = 'object' AND subtype = " . $subtype_id . ")"; update_data($query); }
continue; } $lan_key = "profile:" . $profile_field; $name = $profile_field; if (elgg_echo($lan_key) !== $lan_key) { $name = elgg_echo($lan_key); } $input_options = array("name" => "search_advanced_profile_fields[" . $profile_field . "]", "value" => elgg_extract($profile_field, $submit_values)); $is_autocomplete = (bool) array_search($profile_field, $profile_field_autocomplete_values); $row = new stdClass(); $row->label = $name; if ($is_autocomplete) { $input_options['class'] = 'elgg-input-text'; $input_options['rel'] = $profile_field; $input_options['options'] = array(''); $name_id = add_metastring($profile_field); $dbprefix = elgg_get_config('dbprefix'); $query = "SELECT msv.string\n\t\tFROM {$dbprefix}metadata md\n\t\tJOIN {$dbprefix}metastrings msv ON md.value_id = msv.id\n\t\tJOIN {$dbprefix}entities e ON md.entity_guid = e.guid\n\t\tWHERE md.name_id = {$name_id}\n\t\tAND e.type = 'user'\n\t\tGROUP BY msv.string\n\t\tORDER BY msv.string ASC"; $metadata = get_data($query); if ($metadata) { foreach ($metadata as $md) { $input_options['options'][] = html_entity_decode($md->string); } } $row->input = elgg_view("input/dropdown", $input_options); } else { $row->input = elgg_view("input/text", $input_options); } $output[] = $row; } if (!empty($output)) {
/** * Update an annotation. * * @param int $annotation_id * @param string $name * @param string $value * @param string $value_type * @param int $owner_guid * @param int $access_id */ 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 = get_loggedin_userid(); } $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 set value_id='{$value}', value_type='{$value_type}', access_id={$access_id}, owner_guid={$owner_guid} where id={$annotation_id} and name_id='{$name}' and {$access}"); if ($result !== false) { $obj = get_annotation($annotation_id); if (trigger_elgg_event('update', 'annotation', $obj)) { return true; } else { delete_annotation($annotation_id); } } return $result; }
/** * Returns one-time events * * @param int $starttime Time range start, default: now * @param int $endtime Time range end, default: 1 year from start time * @return ElggBatch */ public function getOneTimeEvents($starttime = null, $endtime = null) { if (is_null($starttime)) { $starttime = time(); } if (is_null($endtime)) { $endtime = strtotime('+1 year', $starttime); } $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); $relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP); $dbprefix = elgg_get_config('dbprefix'); // for performance we'll denormalize metastrings first $mdr_name = add_metastring('repeat'); $mdr_val = add_metastring(0); $mds_name = add_metastring('start_timestamp'); $mde_name = add_metastring('end_timestamp'); $options = array('type' => 'object', 'subtype' => Event::SUBTYPE, 'joins' => array("JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", "JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid", "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", "JOIN {$dbprefix}metadata mde ON mde.entity_guid = e.guid", "JOIN {$dbprefix}metastrings mse ON mse.id = mde.value_id"), 'wheres' => array("er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'", "mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}", "mds.name_id = {$mds_name}", "mde.name_id = {$mde_name}", "((CAST(mss.string AS SIGNED) BETWEEN {$starttime} AND {$endtime})\n\t\t\t\t\tOR (CAST(mse.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}))"), 'limit' => false); return new ElggBatch('elgg_get_entities', $options); }
<?php /** * Shows the latests blogs in the Digest * */ $ts_lower = (int) elgg_extract("ts_lower", $vars); $ts_upper = (int) elgg_extract("ts_upper", $vars); // only show blogs that are published $dbprefix = elgg_get_config("dbprefix"); $blog_status_name_id = add_metastring("status"); $blog_published_value_id = add_metastring("published"); $blog_options = array("type" => "object", "subtype" => "blog", "limit" => 5, "created_time_lower" => $ts_lower, "created_time_upper" => $ts_upper, "joins" => array("JOIN " . $dbprefix . "metadata bm ON e.guid = bm.entity_guid"), "wheres" => array("bm.name_id = " . $blog_status_name_id, "bm.value_id = " . $blog_published_value_id)); if ($blogs = elgg_get_entities($blog_options)) { if ($vars['email']) { $title = "<h2 class='email'>" . elgg_echo("blog:blogs") . "</h2>"; $title .= "<h5 class='email'>To view all site blogs visit " . elgg_get_site_url() . "blog/all?filter=newest </h5>"; $latest_blogs = "<div class='email-section'>"; foreach ($blogs as $blog) { $latest_blogs .= "<div class='blog'>"; $latest_blogs .= "<h4 class='email'>" . $blog->title . "</h4>"; $latest_blogs .= "<p>" . elgg_get_excerpt($blog->description) . "</p>"; $latest_blogs .= "</div>"; } $latest_blogs .= "</div>"; echo $title . $latest_blogs; } else { $title = elgg_echo("blog:blogs"); $title .= "<h5>To view all site blogs visit " . elgg_get_site_url() . "blog/all?filter=newest </h5>"; $latest_blogs = ""; foreach ($blogs as $blog) {
<?php /** * This upgrade will fix all folders which have themselfs as parent_guid. * All theres parent_guids will be reset to 0 (main level) * */ // prepare some variables $dbprefix = elgg_get_config("dbprefix"); $folder_subtype_id = get_subtype_id("object", FILE_TOOLS_SUBTYPE); $parent_guid_id = add_metastring("parent_guid"); $zero_metadata_id = add_metastring(0); // check if the folder subtype exists in your database if (!empty($folder_subtype_id)) { // create a (temp) table with metadata id's that need fixing $query = "CREATE TABLE file_tools_fix"; $query .= " AS (SELECT md.id"; $query .= " FROM " . $dbprefix . "metadata md"; $query .= " JOIN " . $dbprefix . "entities e ON md.entity_guid = e.guid"; $query .= " JOIN " . $dbprefix . "metastrings msv ON md.value_id = msv.id"; $query .= " WHERE e.type = 'object' AND e.subtype = " . $folder_subtype_id; $query .= " AND md.name_id = " . $parent_guid_id . " AND msv.string = md.entity_guid)"; update_data($query); // the update query $query = " UPDATE " . $dbprefix . "metadata"; $query .= " SET value_id = " . $zero_metadata_id; $query .= " WHERE id IN (SELECT id FROM file_tools_fix)"; // execute the update query update_data($query); // cleanup the temp table $query = "DROP TABLE file_tools_fix";
function hj_forum_1372438394() { add_metastring('priority'); add_metastring('sticky'); }
<?php namespace Arck\Stormpath; echo elgg_view('stormpath/admin/navigation'); $vroom = elgg_is_active_plugin('vroom'); $dbprefix = elgg_get_config('dbprefix'); 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); } $count = elgg_get_entities(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'), 'count' => true)); $title = elgg_echo('stormpath:import:title', array('<b>' . $count . '<b>')); if ($count) { $description = elgg_view('output/longtext', array('value' => elgg_echo('stormpath:import:description'))); if ($vroom) { $description .= elgg_view('output/longtext', array('value' => elgg_echo('stormpath:import:directory:instructions'))); $description .= elgg_view_form('stormpath/import'); } else { $description .= elgg_view('output/longtext', array('value' => elgg_echo('stormpath:import:required:vroom'))); } } else { $description = elgg_echo('stormpath:import:description:unnecessary'); } echo elgg_view_module('main', $title, $description);