/** * 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'); }
/** * Find the plugin settings for a user. * * @param string $plugin_name Plugin name. * @param int $user_guid The guid who's settings to retrieve. * @return array of settings in an associative array minus prefix. */ function find_plugin_usersettings($plugin_name = "", $user_guid = 0) { $plugin_name = sanitise_string($plugin_name); $user_guid = (int) $user_guid; if (!$plugin_name) { $plugin_name = get_plugin_name(); } if ($user_guid == 0) { $user_guid = get_loggedin_userid(); } // Get metadata for user $all_metadata = get_all_private_settings($user_guid); //get_metadata_for_entity($user_guid); if ($all_metadata) { $prefix = "plugin:settings:{$plugin_name}:"; $return = new stdClass(); foreach ($all_metadata as $key => $meta) { $name = substr($key, strlen($prefix)); $value = $meta; if (strpos($key, $prefix) === 0) { $return->{$name} = $value; } } return $return; } return false; }
/** * 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(); } } } }
/** * 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; }
/** * Gets a private setting for an entity. * * Plugin authors can set private data on entities. By default * private data will not be searched or exported. * * @internal Private data is used to store settings for plugins * and user settings. * * @param int $entity_guid The entity GUID * @param string $name The name of the setting * * @return mixed The setting value, or false on failure * @see set_private_setting() * @see get_all_private_settings() * @see remove_private_setting() * @see remove_all_private_settings() * @link http://docs.elgg.org/DataModel/Entities/PrivateSettings */ function get_private_setting($entity_guid, $name) { $entity_guid = (int) $entity_guid; $name = sanitise_string($name); // check if you have access to the entity if (!elgg_get_ignore_access() && !get_entity_as_row($entity_guid)) { return false; } if ($settings = get_all_private_settings($entity_guid)) { return elgg_extract($name, $settings, false); } return false; }
<?php $entity = elgg_extract('entity', $vars); $private_settings = get_all_private_settings($entity->guid); if (empty($private_settings)) { $private_settings_info = elgg_echo('notfound'); } else { $private_settings_info = '<table class="elgg-table">'; $private_settings_info .= '<tr>'; $private_settings_info .= '<th>key</th><th>value</th><th> </th>'; $private_settings_info .= '</tr>'; foreach ($private_settings as $key => $value) { $key_val = elgg_view('output/text', ['value' => $key]); $value = elgg_view('output/text', ['value' => $value]); $private_settings_info .= '<tr>'; $private_settings_info .= "<td>{$key_val}</td><td>{$value}</td>"; $private_settings_info .= '<td>' . elgg_view('output/url', ['text' => elgg_view_icon('remove'), 'href' => elgg_http_add_url_query_elements('action/developers/entity_explorer_delete', ['guid' => $entity->guid, 'type' => 'private_setting', 'key' => $key]), 'confirm' => true]) . '</td>'; $private_settings_info .= '</tr>'; } $private_settings_info .= '</table>'; } echo elgg_view_module('inline', elgg_echo('developers:entity_explorer:info:private_settings'), $private_settings_info);
} // get default widgets and add them $widgets = elgg_get_widgets($site_guid, $context); $num_columns = count($widgets); for ($column_index = 1; $column_index <= $num_columns; $column_index++) { if (isset($widgets[$column_index])) { $column_widgets = $widgets[$column_index]; } else { $column_widgets = array(); } if (sizeof($column_widgets) > 0) { $line = 0; foreach ($column_widgets as $widget) { if ($widget) { // change the container and owner $new_widget = clone $widget; $new_widget->container_guid = $owner_guid; $new_widget->owner_guid = $owner_guid; // pull in settings $settings = get_all_private_settings($widget->guid); foreach ($settings as $name => $value) { $new_widget->{$name} = $value; } $new_widget->move($column_index, $line); $new_widget->save(); $line++; } } } } }
function pleio_api_get_site_colors($site_guid = 1) { $settings = get_all_private_settings($site_guid); $colorset = array_key_exists("colorset", $settings) ? $settings["colorset"] : false; $colors = array("01689B", "CCE0F1", "E5F0F9", "154273", "0162CD"); //default color set switch ($colorset) { case "custom": for ($i = 0; $i < count($colors); $i++) { $custom_color = "custom_color_" . ($i + 1); if (array_key_exists($custom_color, $settings)) { $colors[$i] = $settings[$custom_color]; } } break; case "mint": $colors[0] = "6ED9AD"; $colors[1] = "CBE6DB"; $colors[2] = "E5F2ED"; break; case "magenta": $colors[0] = "900079"; $colors[1] = "E3B2DA"; $colors[2] = "F1D9ED"; break; case "yellow": $colors[0] = "F9E11E"; $colors[1] = "FDF6BB"; $colors[2] = "FEFBDD"; break; case "purple": $colors[0] = "42145F"; $colors[1] = "C6B8CF"; $colors[2] = "E3DCE7"; break; case "violet": $colors[0] = "A90061"; $colors[1] = "E5B2CF"; $colors[2] = "F2D9E7"; break; case "pink": $colors[0] = "F092CD"; $colors[1] = "FADEF0"; $colors[2] = "FDEFF8"; break; case "navy": $colors[0] = "01689B"; $colors[1] = "CCE0F1"; $colors[2] = "E5F0F9"; $colors[3] = "154273"; $colors[4] = "0162CD"; break; case "orange": $colors[0] = "E17000"; $colors[1] = "F6D4B2"; $colors[2] = "FBEAD9"; break; case "blue": $colors[0] = "007BC7"; $colors[1] = "B2D7EE"; $colors[2] = "D9EBF7"; break; case "sand": $colors[0] = "F9B249"; $colors[1] = "FDE4BE"; $colors[2] = "FEF2DF"; break; case "green": $colors[0] = "4E9625"; $colors[1] = "CBE1BD"; $colors[2] = "E1FECF"; break; default: break; } return $colors; }