/** * Initialize a consumer from API key * * @param string $api_key API Key * @return Consumer|void */ public static function factory($api_key) { if (!$api_key) { return; } $ia = elgg_set_ignore_access(true); $consumers = elgg_get_entities_from_private_settings(array('types' => 'object', 'subtypes' => self::SUBTYPE, 'private_setting_name_value_pairs' => array('name' => 'api_key', 'value' => $api_key), 'limit' => 1)); $consumer = !empty($consumers) ? $consumers[0] : null; elgg_set_ignore_access($ia); return $consumer; }
public function testElggApiGettersEntitiesFromPrivateSettings() { // create some test private settings $setting_name = 'test_setting_name_' . rand(); $setting_value = rand(1000, 9999); $setting_name2 = 'test_setting_name_' . rand(); $setting_value2 = rand(1000, 9999); $subtypes = $this->getRandomValidSubtypes(array('object'), 1); $subtype = $subtypes[0]; $guids = array(); // our targets $valid = new ElggObject(); $valid->subtype = $subtype; $valid->save(); $guids[] = $valid->getGUID(); set_private_setting($valid->getGUID(), $setting_name, $setting_value); set_private_setting($valid->getGUID(), $setting_name2, $setting_value2); $valid2 = new ElggObject(); $valid2->subtype = $subtype; $valid2->save(); $guids[] = $valid2->getGUID(); set_private_setting($valid2->getGUID(), $setting_name, $setting_value); set_private_setting($valid2->getGUID(), $setting_name2, $setting_value2); // simple test with name $options = array('private_setting_name' => $setting_name); $entities = elgg_get_entities_from_private_settings($options); foreach ($entities as $entity) { $this->assertTrue(in_array($entity->getGUID(), $guids)); $value = get_private_setting($entity->getGUID(), $setting_name); $this->assertEqual($value, $setting_value); } // simple test with value $options = array('private_setting_value' => $setting_value); $entities = elgg_get_entities_from_private_settings($options); foreach ($entities as $entity) { $this->assertTrue(in_array($entity->getGUID(), $guids)); $value = get_private_setting($entity->getGUID(), $setting_name); $this->assertEqual($value, $setting_value); } // test pairs $options = array('type' => 'object', 'subtype' => $subtype, 'private_setting_name_value_pairs' => array(array('name' => $setting_name, 'value' => $setting_value), array('name' => $setting_name2, 'value' => $setting_value2))); $entities = elgg_get_entities_from_private_settings($options); $this->assertEqual(2, count($entities)); foreach ($entities as $entity) { $this->assertTrue(in_array($entity->getGUID(), $guids)); } foreach ($guids as $guid) { if ($e = get_entity($guid)) { $e->delete(); } } }
public function getWidgets($context = 'framework') { $owner = $this->getOwnerEntity(); $options = array('type' => 'object', 'subtype' => 'widget', 'owner_guid' => $owner->guid, 'private_setting_name' => 'context', 'private_setting_value' => $context, 'limit' => 0); $widgets = elgg_get_entities_from_private_settings($options); foreach ($widgets as $widget) { if ($widget->container_guid == $this->guid) { $segment_widgets[] = $widget; } } if (!$segment_widgets) { return array(); } return $segment_widgets; }
function widget_favorites_has_widget($owner_guid = 0) { $result = false; if (empty($owner_guid)) { if ($user_guid = elgg_get_logged_in_user_guid()) { $owner_guid = $user_guid; } } if (!empty($owner_guid)) { $options = array("type" => "object", "subtype" => "widget", "private_setting_name_value_pairs" => array("handler" => "favorites"), "count" => true, "owner_guid" => $owner_guid); if (elgg_get_entities_from_private_settings($options)) { $result = true; } } return $result; }
function elgg_modifications_reportedcontent_hook($hook, $type, $return_value, $params) { if (!empty($params) && is_array($params)) { $report = elgg_extract("report", $params); $site = elgg_get_site_entity(); if (!subsite_manager_check_global_plugin_setting("reportedcontent", "use_global_usersettings")) { $setting = ELGG_PLUGIN_USER_SETTING_PREFIX . "reportedcontent:" . $site->getGUID() . ":notify"; } else { $setting = ELGG_PLUGIN_USER_SETTING_PREFIX . "reportedcontent:notify"; } // get users with setting $options = array("type" => "user", "limit" => false, "site_guids" => false, "private_setting_name" => $setting, "private_setting_value" => "yes"); if ($users = elgg_get_entities_from_private_settings($options)) { $filtered_users = array(); if (elgg_instanceof($site, "site", Subsite::SUBTYPE, "Subsite")) { foreach ($users as $user) { if ($user->getGUID() != $report->getOwner() && ($user->isAdmin() || $site->isAdmin($user->getGUID()))) { $filtered_users[] = $user; } } } else { foreach ($users as $user) { if ($user->getGUID() != $report->getOwner() && $user->isAdmin()) { $filtered_users[] = $user; } } } if (!empty($filtered_users)) { $subject = elgg_echo("elgg_modifications:usersettings:reportedcontent:notify:subject"); $message = elgg_echo("elgg_modifications:usersettings:reportedcontent:notify:message", array($report->getOwnerEntity()->name, $site->url . "admin/administer_utilities/reportedcontent")); foreach ($filtered_users as $user) { notify_user($user->getGUID(), $report->getOwner(), $subject, $message); } } } } }
/** * @see elgg_get_widgets * @access private * @since 1.9.0 */ public function getWidgets($owner_guid, $context) { $widget_cache_key = "{$context}-{$owner_guid}"; if (isset($this->widgetCache[$widget_cache_key])) { return $this->widgetCache[$widget_cache_key]; } $options = array('type' => 'object', 'subtype' => 'widget', 'owner_guid' => $owner_guid, 'private_setting_name' => 'context', 'private_setting_value' => $context, 'limit' => 0); $widgets = elgg_get_entities_from_private_settings($options); if (!$widgets) { return array(); } $sorted_widgets = array(); foreach ($widgets as $widget) { if (!isset($sorted_widgets[(int) $widget->column])) { $sorted_widgets[(int) $widget->column] = array(); } $sorted_widgets[(int) $widget->column][$widget->order] = $widget; } foreach ($sorted_widgets as $col => $widgets) { ksort($sorted_widgets[$col]); } $this->widgetCache[$widget_cache_key] = $sorted_widgets; return $sorted_widgets; }
<?php /** * Lists pending upgrades */ $upgrades = elgg_get_entities_from_private_settings(array('type' => 'object', 'subtype' => 'elgg_upgrade', 'private_setting_name' => 'is_completed', 'private_setting_value' => false)); if (!$upgrades) { echo elgg_echo('admin:upgrades:none'); } else { echo elgg_view_entity_list($upgrades); }
/** * Returns entities based upon plugin settings. * Takes all the options for {@see elgg_get_entities_from_private_settings()} * in addition to the ones below. * * @param array $options Array in the format: * * plugin_id => NULL|STR The plugin id. Defaults to calling plugin * * plugin_user_setting_names => NULL|ARR private setting names * * plugin_user_setting_values => NULL|ARR metadata values * * plugin_user_setting_name_value_pairs => NULL|ARR ( * name => 'name', * value => 'value', * 'operand' => '=', * ) * Currently if multiple values are sent via * an array (value => array('value1', 'value2') * the pair's operand will be forced to "IN". * * plugin_user_setting_name_value_pairs_operator => NULL|STR The operator to use for combining * (name = value) OPERATOR (name = value); default AND * * @return mixed int If count, int. If not count, array. false on errors. */ function elgg_get_entities_from_plugin_user_settings(array $options = array()) { // if they're passing it don't bother if (!isset($options['plugin_id'])) { $options['plugin_id'] = elgg_get_calling_plugin_id(); } $singulars = array('plugin_user_setting_name', 'plugin_user_setting_value', 'plugin_user_setting_name_value_pair'); $options = elgg_normalise_plural_options_array($options, $singulars); // rewrite plugin_user_setting_name_* to the right PS ones. $map = array('plugin_user_setting_names' => 'private_setting_names', 'plugin_user_setting_values' => 'private_setting_values', 'plugin_user_setting_name_value_pairs' => 'private_setting_name_value_pairs', 'plugin_user_setting_name_value_pairs_operator' => 'private_setting_name_value_pairs_operator'); foreach ($map as $plugin => $private) { if (!isset($options[$plugin])) { continue; } if (isset($options[$private])) { if (!is_array($options[$private])) { $options[$private] = array($options[$private]); } $options[$private] = array_merge($options[$private], $options[$plugin]); } else { $options[$private] = $options[$plugin]; } } $plugin_id = $options['plugin_id']; $prefix = elgg_namespace_plugin_private_setting('user_setting', '', $plugin_id); $options['private_setting_name_prefix'] = $prefix; return elgg_get_entities_from_private_settings($options); }
/** * Move the widget * * @param int $column The widget column * @param int $rank Zero-based rank from the top of the column * @return void * @since 1.8.0 */ public function move($column, $rank) { $options = array('type' => 'object', 'subtype' => 'widget', 'container_guid' => $this->container_guid, 'limit' => false, 'private_setting_name_value_pairs' => array(array('name' => 'context', 'value' => $this->getContext()), array('name' => 'column', 'value' => $column))); $widgets = elgg_get_entities_from_private_settings($options); if (!$widgets) { $this->column = (int) $column; $this->order = 0; return; } usort($widgets, create_function('$a,$b', 'return (int)$a->order > (int)$b->order;')); // remove widgets from inactive plugins $widget_types = elgg_get_widget_types($this->context); $inactive_widgets = array(); foreach ($widgets as $index => $widget) { if (!array_key_exists($widget->handler, $widget_types)) { $inactive_widgets[] = $widget; unset($widgets[$index]); } } if ($rank == 0) { // top of the column $this->order = reset($widgets)->order - 10; } elseif ($rank == count($widgets) - 1) { // bottom of the column of active widgets $this->order = end($widgets)->order + 10; } else { // reorder widgets // remove the widget that's being moved from the array foreach ($widgets as $index => $widget) { if ($widget->guid == $this->guid) { unset($widgets[$index]); } } // split the array in two and recombine with the moved widget in middle $before = array_slice($widgets, 0, $rank); array_push($before, $this); $after = array_slice($widgets, $rank); $widgets = array_merge($before, $after); ksort($widgets); $order = 0; foreach ($widgets as $widget) { $widget->order = $order; $order += 10; } } // put inactive widgets at the bottom if ($inactive_widgets) { $bottom = 0; foreach ($widgets as $widget) { if ($widget->order > $bottom) { $bottom = $widget->order; } } $bottom += 10; foreach ($inactive_widgets as $widget) { $widget->order = $bottom; $bottom += 10; } } $this->column = $column; }
/** * Returns entities based upon plugin user settings. * Takes all the options for {@link elgg_get_entities_from_private_settings()} * in addition to the ones below. * * @param array $options Array in the format: * * plugin_id => STR The plugin id. Required. * * plugin_user_setting_names => null|ARR private setting names * * plugin_user_setting_values => null|ARR metadata values * * plugin_user_setting_name_value_pairs => null|ARR ( * name => 'name', * value => 'value', * 'operand' => '=', * ) * Currently if multiple values are sent via * an array (value => array('value1', 'value2') * the pair's operand will be forced to "IN". * * plugin_user_setting_name_value_pairs_operator => null|STR The operator to use for combining * (name = value) OPERATOR (name = value); default AND * * @return mixed int If count, int. If not count, array. false on errors. */ function getEntitiesFromUserSettings(array $options = array()) { if (!isset($options['plugin_id'])) { elgg_deprecated_notice("'plugin_id' is now required for elgg_get_entities_from_plugin_user_settings()", 1.9); $options['plugin_id'] = elgg_get_calling_plugin_id(); } $singulars = array('plugin_user_setting_name', 'plugin_user_setting_value', 'plugin_user_setting_name_value_pair'); $options = _elgg_normalize_plural_options_array($options, $singulars); // rewrite plugin_user_setting_name_* to the right PS ones. $map = array('plugin_user_setting_names' => 'private_setting_names', 'plugin_user_setting_values' => 'private_setting_values', 'plugin_user_setting_name_value_pairs' => 'private_setting_name_value_pairs', 'plugin_user_setting_name_value_pairs_operator' => 'private_setting_name_value_pairs_operator'); foreach ($map as $plugin => $private) { if (!isset($options[$plugin])) { continue; } if (isset($options[$private])) { if (!is_array($options[$private])) { $options[$private] = array($options[$private]); } $options[$private] = array_merge($options[$private], $options[$plugin]); } else { $options[$private] = $options[$plugin]; } } $prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $options['plugin_id']); $options['private_setting_name_prefix'] = $prefix; return elgg_get_entities_from_private_settings($options); }
$list = "<table class='elgg-table'>"; $list .= "<tr>"; $list .= "<th>" . elgg_echo("widget") . "</th>"; foreach ($stats_context as $context) { $list .= "<th class='center'>" . elgg_echo($context) . "</th>"; } $list .= "<th class='center'>" . elgg_echo("total") . "</th>"; $list .= "</tr>"; $widgets = $CONFIG->widgets->handlers; widget_manager_sort_widgets($widgets); foreach ($widgets as $handler => $widget) { $widget_counts = array(); $widget_options = array("type" => "object", "subtype" => "widget", "count" => true, "private_setting_name_value_pairs" => array("handler" => $handler)); foreach ($stats_context as $context) { $widget_options["private_setting_name_value_pairs"]["context"] = $context; $widget_total = elgg_get_entities_from_private_settings($widget_options); $widget_counts[$context] = $widget_total; // keep track of context totals $context_totals[$context] += $widget_total; } $widget_counts["total"] = array_sum($widget_counts); $list .= "<tr>"; $list .= "<td><span title='[" . $handler . "] " . $widget->description . "'>" . $widget->name . "</span></td>"; foreach ($stats_context as $context) { $list .= "<td class='center'>"; if ($widget_counts[$context] === 0) { $list .= " "; } else { $list .= $widget_counts["total"]; } $list .= "</td>";
<?php if (subsite_manager_on_subsite()) { $site = elgg_get_site_entity(); if ($admins = $site->getAdminGuids()) { $options = array("type" => "user", "limit" => false, "site_guids" => false, "joins" => array("JOIN " . get_config("dbprefix") . "users_entity ue ON ue.guid = e.guid"), "wheres" => array("(e.guid IN (" . implode(",", $admins) . "))"), "order_by" => "ue.name", "full_view" => false, "pagination" => false, "view_type_toggle" => false); $body = elgg_list_entities($options); } } else { $options = array("type" => "user", "limit" => false, "private_setting_name_value_pairs" => array("name" => "superadmin", "value" => true), "joins" => array("JOIN " . get_config("dbprefix") . "users_entity ue ON ue.guid = e.guid"), "wheres" => array("ue.admin = 'yes'"), "order_by" => "ue.name", "full_view" => false, "pagination" => false, "view_type_toggle" => false); if ($users = elgg_get_entities_from_private_settings($options)) { $body = elgg_view_entity_list($users, $options); } } if (empty($body)) { $body = elgg_echo("notfound"); } echo elgg_view_module("inline", "", $body);
<?php /** * Shows the main admins and all Subsite admins per Subsite */ // get main admins $main_options = array("type" => "user", "limit" => false, "site_guids" => false, "private_setting_name_value_pairs" => array("name" => "superadmin", "value" => true), "joins" => array("JOIN " . get_config("dbprefix") . "users_entity ue ON ue.guid = e.guid"), "wheres" => array("ue.admin = 'yes'"), "order_by" => "ue.name", "full_view" => false, "pagination" => false, "view_type_toggle" => false); if ($main_admins = elgg_get_entities_from_private_settings($main_options)) { $main_list = elgg_view_entity_list($main_admins, $main_options); } else { $main_list = elgg_echo("notfound"); } // list main admins echo elgg_view_module("inline", elgg_echo("subsite_manager:subsites:admins:main_admins"), $main_list); // get all subsites $limit = (int) max(get_input('limit', 50), 0); $offset = (int) max(get_input('offset', 0), 0); $subsite_options = array("type" => "site", "subtype" => Subsite::SUBTYPE, "limit" => $limit, "offset" => $offset, "joins" => array("JOIN " . get_config("dbprefix") . "sites_entity se ON se.guid = e.guid"), "order_by" => "se.name ASC"); $export_button = ""; if ($subsites = elgg_get_entities($subsite_options)) { // create export button $export_button = elgg_view("output/url", array("text" => elgg_echo("export"), "href" => "action/subsites/export_admins", "is_action" => true, "class" => "elgg-button elgg-button-action float-alt")); // add pagination $subsite_options["count"] = true; $count = elgg_get_entities($subsite_options); $pagination = elgg_view("navigation/pagination", array("limit" => $limit, "offset" => $offset, "count" => $count)); $subsite_list = $pagination; foreach ($subsites as $subsite) { // some stats $temp_list = "<div class='elgg-subtext'>"; $temp_list .= elgg_echo("members") . ": " . $subsite->getMembers(array("count" => true)) . "<br />";
/** * Get all groups based on the email domain of the user from the group settings * * @param ElggUser $user The user used to base the search * @param int $site_guid (optional) the site guid to limit the search to, defaults to current site * * @return bool|ElggGroup[] false or an array of found groups */ function group_tools_get_domain_based_groups(ElggUser $user, $site_guid = 0) { $result = false; if (group_tools_domain_based_groups_enabled()) { if (empty($site_guid)) { $site_guid = elgg_get_site_entity()->getGUID(); } if (!empty($user) && elgg_instanceof($user, "user")) { list(, $domain) = explode("@", strtolower($user->email)); $options = array("type" => "group", "limit" => false, "site_guids" => $site_guid, "private_setting_name_value_pairs" => array("name" => "domain_based", "value" => "%|" . $domain . "|%", "operand" => "LIKE")); $groups = elgg_get_entities_from_private_settings($options); if (!empty($groups)) { $result = $groups; } } } return $result; }
/** * Creates default widgets * * This plugin hook handler is registered for events based on what kinds of * default widgets have been registered. See elgg_default_widgets_init() for * information on registering new default widget contexts. * * @param string $event The event * @param string $type The type of object * @param \ElggEntity $entity The entity being created * @return void * @access private */ function _elgg_create_default_widgets($event, $type, $entity) { $default_widget_info = elgg_get_config('default_widget_info'); if (!$default_widget_info || !$entity) { return; } $type = $entity->getType(); $subtype = $entity->getSubtype(); // event is already guaranteed by the hook registration. // need to check subtype and type. foreach ($default_widget_info as $info) { if ($info['entity_type'] == $type) { if ($info['entity_subtype'] == ELGG_ENTITIES_ANY_VALUE || $info['entity_subtype'] == $subtype) { // need to be able to access everything $old_ia = elgg_set_ignore_access(true); elgg_push_context('create_default_widgets'); // pull in by widget context with widget owners as the site // not using elgg_get_widgets() because it sorts by columns and we don't care right now. $options = array('type' => 'object', 'subtype' => 'widget', 'owner_guid' => elgg_get_site_entity()->guid, 'private_setting_name' => 'context', 'private_setting_value' => $info['widget_context'], 'limit' => 0); $widgets = elgg_get_entities_from_private_settings($options); /* @var \ElggWidget[] $widgets */ foreach ($widgets as $widget) { // change the container and owner $new_widget = clone $widget; $new_widget->container_guid = $entity->guid; $new_widget->owner_guid = $entity->guid; // pull in settings $settings = get_all_private_settings($widget->guid); foreach ($settings as $name => $value) { $new_widget->{$name} = $value; } $new_widget->save(); } elgg_set_ignore_access($old_ia); elgg_pop_context(); } } } }
<?php /** * add the ability to reset the access of all widgets in the group to a certain access level */ $group = elgg_extract('entity', $vars); if (empty($group) || !$group instanceof ElggGroup || !$group->canEdit()) { return; } $widgets_count = elgg_get_entities_from_private_settings(['type' => 'object', 'subtype' => 'widget', 'owner_guid' => $group->getGUID(), 'private_setting_name' => 'context', 'private_setting_value' => 'groups', 'count' => true]); if (!$widgets_count) { // no widgets = no need for this form return; } $title = elgg_echo('widget_manager:forms:groups_widget_access:title'); $form_body = '<div>' . elgg_echo('widget_manager:forms:groups_widget_access:description') . '</div>'; $form_body .= '<div>' . elgg_view('input/access', ['name' => 'widget_access_level']) . '</div>'; $form_body .= '<div class="elgg-footer">'; $form_body .= elgg_view('input/hidden', ['name' => 'group_guid', 'value' => $group->getGUID()]); $form_body .= elgg_view('input/submit', ['value' => elgg_echo('save')]); $form_body .= '</div>'; $content = elgg_view('input/form', ['action' => 'action/widget_manager/groups/update_widget_access', 'body' => $form_body]); echo elgg_view_module('info', $title, $content);
/** * Checks for plugins who have registered default widgets and * hooks into events to save. * * @param string $event The event * @param string $type The type of object * @param object $object The object * @return null */ function elgg_default_widgets_hook($event, $type, $object) { $default_widget_info = elgg_get_config('default_widget_info'); if (!$default_widget_info) { return null; } $subtype = $object->getSubtype(); // event is already guaranteed by the hook registration. // need to check subtype and type. foreach ($default_widget_info as $temp) { if ($temp['entity_type'] == $type && $temp['entity_subtype'] == $subtype) { $info = $temp; break; } } // need to be able to access everything $old_ia = elgg_get_ignore_access(true); elgg_push_context('create_default_widgets'); // pull in by widget context with widget owners as the site // not using elgg_get_widgets() because it sorts by columns and we don't care right now. $options = array('type' => 'object', 'subtype' => 'widget', 'owner_guid' => elgg_get_site_entity()->guid, 'private_setting_name' => 'context', 'private_setting_value' => $info['context'], 'limit' => 0); $widgets = elgg_get_entities_from_private_settings($options); foreach ($widgets as $widget) { // change the container and owner $new_widget = clone $widget; $new_widget->container_guid = $object->guid; $new_widget->owner_guid = $object->guid; // pull in settings $settings = get_all_private_settings($widget->guid); foreach ($settings as $name => $value) { $new_widget->{$name} = $value; } $new_widget->save(); } elgg_get_ignore_access($old_ia); elgg_pop_context(); // failure here shouldn't stop the event. return null; }
/** * Get all groups based on the email domain of the user from the group settings * * @param ElggUser $user The user used to base the search * @param int $site_guid (optional) the site guid to limit the search to, defaults to current site * * @return false|ElggGroup[] */ function group_tools_get_domain_based_groups(ElggUser $user, $site_guid = 0) { if (!group_tools_domain_based_groups_enabled()) { return false; } if (!$user instanceof ElggUser) { return false; } $site_guid = sanitize_int($site_guid, false); if (empty($site_guid)) { $site_guid = elgg_get_site_entity()->getGUID(); } list(, $domain) = explode('@', strtolower($user->email)); $options = ['type' => 'group', 'limit' => false, 'site_guids' => $site_guid, 'private_setting_name_value_pairs' => ['name' => 'domain_based', 'value' => "%|{$domain}|%", 'operand' => 'LIKE']]; $groups = elgg_get_entities_from_private_settings($options); if (!empty($groups)) { return $groups; } return false; }
/** * Move the widget * * @param int $column The widget column * @param int $rank Zero-based rank from the top of the column * @return void * @since 1.8.0 */ public function move($column, $rank) { $options = array('type' => 'object', 'subtype' => 'widget', 'private_setting_name_value_pairs' => array(array('name' => 'context', 'value' => $this->getContext()), array('name' => 'column', 'value' => $column))); $widgets = elgg_get_entities_from_private_settings($options); if (!$widgets) { $this->column = (int) $column; $this->order = 0; return; } usort($widgets, create_function('$a,$b', 'return (int)$a->order > (int)$b->order;')); if ($rank == 0) { // top of the column $this->order = $widgets[0]->order - 10; } elseif ($rank == count($widgets)) { // bottom of the column $this->order = end($widgets)->order + 10; } else { // reorder widgets that are below $this->order = $widgets[$rank]->order; for ($index = $rank; $index < count($widgets); $index++) { if ($widgets[$index]->guid != $this->guid) { $widgets[$index]->order += 10; } } } $this->column = $column; }
/** * Make sure the correct site administrators are notified for security tools updates, not all admins * * @param string $hook notify_admins * @param string $type security_tools * @param ElggUser[] $returnvalue default admins to be notified (this is too many) * @param array $params some more information to bas the result set on * * @return ElggUser[] */ function subsite_manager_notify_admins_security_tools_hook($hook, $type, $returnvalue, $params) { $result = array(); if (!empty($params) && is_array($params)) { $user = elgg_extract("user", $params); if (subsite_manager_on_subsite()) { // get subsite admins $site = elgg_get_site_entity(); $user_guids = $site->getAdminGuids(); if (!empty($user_guids)) { foreach ($user_guids as $user_guid) { if ($user_guid != $user->getGUID()) { $admin = get_user($user_guid); if (!empty($admin)) { $result[] = $admin; } } } } } else { // get main admins $options = array("type" => "user", "limit" => false, "private_setting_name_value_pairs" => array("name" => "superadmin", "value" => true), "joins" => array("JOIN " . get_config("dbprefix") . "users_entity ue ON ue.guid = e.guid"), "wheres" => array("(ue.admin = 'yes')", "(e.guid <> " . $user->getGUID() . ")")); $admins = elgg_get_entities_from_private_settings($options); if (!empty($admins)) { $result = $admins; } } } return $result; }
/** * Updates the fixed widgets for a given context and user * * @param string $context context of the widgets * @param int $user_guid owner of the new widgets * * @return void */ function widget_manager_update_fixed_widgets($context, $user_guid) { // need to be able to access everything $old_ia = elgg_set_ignore_access(true); elgg_push_context('create_default_widgets'); $options = ['type' => 'object', 'subtype' => 'widget', 'owner_guid' => elgg_get_site_entity()->guid, 'private_setting_name_value_pairs' => ['context' => $context, 'fixed' => 1.0], 'limit' => false]; // see if there are configured fixed widgets $configured_fixed_widgets = elgg_get_entities_from_private_settings($options); widget_manager_sort_widgets_guid($configured_fixed_widgets); // fetch all currently configured widgets fixed AND not fixed $options['private_setting_name_value_pairs'] = ['context' => $context]; $options['owner_guid'] = $user_guid; $user_widgets = elgg_get_entities_from_private_settings($options); widget_manager_sort_widgets_guid($user_widgets); $default_widget_guids = []; // update current widgets if ($user_widgets) { foreach ($user_widgets as $guid => $widget) { $widget_fixed = $widget->fixed; $default_widget_guid = $widget->fixed_parent_guid; $default_widget_guids[] = $default_widget_guid; if (empty($default_widget_guid)) { continue; } if ($widget_fixed && !array_key_exists($default_widget_guid, $configured_fixed_widgets)) { // remove fixed status $widget->fixed = false; } elseif (!$widget_fixed && array_key_exists($default_widget_guid, $configured_fixed_widgets)) { // add fixed status $widget->fixed = true; } // need to recheck the fixed status as it could have been changed if ($widget->fixed && array_key_exists($default_widget_guid, $configured_fixed_widgets)) { // update settings for currently configured widgets // pull in settings $settings = get_all_private_settings($configured_fixed_widgets[$default_widget_guid]->guid); foreach ($settings as $name => $value) { $widget->{$name} = $value; } // access is no setting, but could also be controlled from the default widget $widget->access = $configured_fixed_widgets[$default_widget_guid]->access; // save the widget (needed for access update) $widget->save(); } } } // add new fixed widgets if ($configured_fixed_widgets) { foreach ($configured_fixed_widgets as $guid => $widget) { if (in_array($guid, $default_widget_guids)) { continue; } // if no widget is found which is already linked to this default widget, clone the widget to the user $new_widget = clone $widget; $new_widget->container_guid = $user_guid; $new_widget->owner_guid = $user_guid; // pull in settings $settings = get_all_private_settings($guid); foreach ($settings as $name => $value) { $new_widget->{$name} = $value; } $new_widget->save(); } } // fixing order on all columns for this context, fixed widgets should always stay on top of other 'free' widgets foreach ([1, 2, 3] as $column) { // reuse previous declared options with a minor adjustment $options['private_setting_name_value_pairs'] = ['context' => $context, 'column' => $column]; $column_widgets = elgg_get_entities_from_private_settings($options); $free_widgets = []; $max_fixed_order = 0; if ($column_widgets) { foreach ($column_widgets as $widget) { if ($widget->fixed) { if ($widget->order > $max_fixed_order) { $max_fixed_order = $widget->order; } } else { $free_widgets[] = $widget; } } if (!empty($max_fixed_order) && !empty($free_widgets)) { foreach ($free_widgets as $widget) { $widget->order += $max_fixed_order; } } } } // revert access elgg_set_ignore_access($old_ia); elgg_pop_context(); // set the user timestamp elgg_set_plugin_user_setting($context . '_fixed_ts', time(), $user_guid, 'widget_manager'); }
function widget_manager_get_widgets($user_guid, $context) { global $CONFIG; $options = array('type' => 'object', 'subtype' => 'widget', 'owner_guid' => $user_guid, 'private_setting_name' => 'context', 'private_setting_value' => $context, 'wheres' => array("NOT EXISTS (\n\t\t\t\t\t\t\tSELECT 1 FROM {$CONFIG->dbprefix}entity_relationships r\n\t\t\t\t\t\t\tWHERE r.guid_one = e.guid\n\t\t\t\t\t\t\t\tAND r.relationship = '" . MultiDashboard::WIDGET_RELATIONSHIP . "')"), 'limit' => 0); $widgets = elgg_get_entities_from_private_settings($options); if (!$widgets) { return array(); } $sorted_widgets = array(); foreach ($widgets as $widget) { if (!isset($sorted_widgets[(int) $widget->column])) { $sorted_widgets[(int) $widget->column] = array(); } $sorted_widgets[(int) $widget->column][$widget->order] = $widget; } foreach ($sorted_widgets as $col => $widgets) { ksort($sorted_widgets[$col]); } return $sorted_widgets; }
/** * Get entities based on their private data by multiple keys. * * @param string $name The name of the setting * @param mixed $type Entity type * @param string $subtype Entity subtype * @param int $owner_guid The GUID of the owning user * @param string $order_by The field to order by; by default, time_created desc * @param int $limit The number of entities to return; 10 by default * @param int $offset The indexing offset, 0 by default * @param bool $count Count entities * @param int $site_guid Site GUID. 0 for current, -1 for any. * @param mixed $container_guid Container GUID * * @return array A list of entities. * @deprecated 1.8 Use elgg_get_entities_from_private_settings() */ function get_entities_from_private_setting_multi(array $name, $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null) { elgg_deprecated_notice('get_entities_from_private_setting_multi() was deprecated by elgg_get_entities_from_private_settings()!', 1.8); $options = array(); $pairs = array(); foreach ($name as $setting_name => $setting_value) { $pairs[] = array('name' => $setting_name, 'value' => $setting_value); } $options['private_setting_name_value_pairs'] = $pairs; // set container_guid to owner_guid to emulate old functionality if ($owner_guid != "") { if (is_null($container_guid)) { $container_guid = $owner_guid; } } if ($type) { $options['types'] = $type; } if ($subtype) { $options['subtypes'] = $subtype; } if ($owner_guid) { if (is_array($owner_guid)) { $options['owner_guids'] = $owner_guid; } else { $options['owner_guid'] = $owner_guid; } } if ($container_guid) { if (is_array($container_guid)) { $options['container_guids'] = $container_guid; } else { $options['container_guid'] = $container_guid; } } $options['limit'] = $limit; if ($offset) { $options['offset'] = $offset; } if ($order_by) { $options['order_by']; } if ($site_guid) { $options['site_guid']; } if ($count) { $options['count'] = $count; } return elgg_get_entities_from_private_settings($options); }
$content .= "<td>{$count}</td>"; $content .= '</tr>'; // content to update $options = elasticsearch_get_bulk_options('update'); $options['count'] = true; $count = elgg_get_entities_from_private_settings($options); $content .= '<tr>'; $content .= '<td>' . elgg_echo('elasticsearch:stats:elgg:update') . '</td>'; $content .= "<td>{$count}</td>"; $content .= '</tr>'; // content to reindex $options = elasticsearch_get_bulk_options('reindex'); $count = 0; if (!empty($options)) { $options['count'] = true; $count = elgg_get_entities_from_private_settings($options); } $content .= '<tr>'; $content .= '<td>' . elgg_echo('elasticsearch:stats:elgg:reindex'); $reindex_title = elgg_echo('elasticsearch:stats:elgg:reindex:action'); $last_ts = (int) elasticsearch_get_setting('reindex_ts'); if (!empty($last_ts)) { $reindex_title .= ' ' . elgg_echo('elasticsearch:stats:elgg:reindex:last_ts', [date('c', $last_ts)]); } $content .= elgg_view('output/url', ['confirm' => true, 'href' => 'action/elasticsearch/admin/reindex', 'text' => elgg_view_icon('refresh'), 'title' => $reindex_title, 'class' => 'mlm']); $content .= '</td>'; $content .= "<td>{$count}</td>"; $content .= '</tr>'; $count = count(elasticsearch_get_documents_for_deletion()); $content .= '<tr>'; $content .= '<td>' . elgg_echo('elasticsearch:stats:elgg:delete') . '</td>';