123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- <?php
- function elgg_get_widgets($owner_guid, $context) {
- return _elgg_services()->widgets->getWidgets($owner_guid, $context);
- }
- function elgg_create_widget($owner_guid, $handler, $context, $access_id = null) {
- return _elgg_services()->widgets->createWidget($owner_guid, $handler, $context, $access_id);
- }
- function elgg_can_edit_widget_layout($context, $user_guid = 0) {
- return _elgg_services()->widgets->canEditLayout($context, $user_guid);
- }
- function elgg_register_widget_type($handler, $name, $description, $context = array('all'), $multiple = false) {
- if (is_string($context)) {
- elgg_deprecated_notice('context parameters for elgg_register_widget_type() should be passed as an array())', 1.9);
- $context = explode(",", $context);
- } elseif (empty($context)) {
- $context = array('all');
- }
- return _elgg_services()->widgets->registerType($handler, $name, $description, $context, $multiple);
- }
- function elgg_unregister_widget_type($handler) {
- return _elgg_services()->widgets->unregisterType($handler);
- }
- function elgg_is_widget_type($handler) {
- return _elgg_services()->widgets->validateType($handler);
- }
- function elgg_get_widget_types($context = "", $exact = false) {
- return _elgg_services()->widgets->getTypes($context, $exact);
- }
- function _elgg_widgets_set_ajax_title($hook, $type, $results, $params) {
- if ($params['action'] == 'widgets/save') {
-
- $widget = get_entity(get_input('guid'));
- if ($widget && $widget->title) {
- $results['title'] = $widget->title;
- return $results;
- }
- }
- }
- function _elgg_widgets_init() {
- elgg_register_action('widgets/save');
- elgg_register_action('widgets/add');
- elgg_register_action('widgets/move');
- elgg_register_action('widgets/delete');
- elgg_register_action('widgets/upgrade', '', 'admin');
- elgg_register_plugin_hook_handler('output', 'ajax', '_elgg_widgets_set_ajax_title');
- }
- function _elgg_default_widgets_init() {
- global $CONFIG;
- $default_widgets = elgg_trigger_plugin_hook('get_list', 'default_widgets', null, array());
- $CONFIG->default_widget_info = $default_widgets;
- if ($default_widgets) {
- elgg_register_admin_menu_item('configure', 'default_widgets', 'appearance');
-
- elgg_register_plugin_hook_handler('container_permissions_check', 'object', '_elgg_default_widgets_permissions_override');
-
- $events = array();
- foreach ($default_widgets as $info) {
- if (!is_array($info)) {
- continue;
- }
- $event = elgg_extract('event', $info);
- $entity_type = elgg_extract('entity_type', $info);
- if (!$event || !$entity_type) {
- continue;
- }
- if (!isset($events[$event][$entity_type])) {
- elgg_register_event_handler($event, $entity_type, '_elgg_create_default_widgets');
- $events[$event][$entity_type] = true;
- }
- }
- }
- }
- 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();
-
-
- foreach ($default_widget_info as $info) {
- if ($info['entity_type'] == $type) {
- if ($info['entity_subtype'] == ELGG_ENTITIES_ANY_VALUE || $info['entity_subtype'] == $subtype) {
-
- $old_ia = elgg_set_ignore_access(true);
- elgg_push_context('create_default_widgets');
-
-
- $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);
-
- foreach ($widgets as $widget) {
-
- $new_widget = clone $widget;
- $new_widget->container_guid = $entity->guid;
- $new_widget->owner_guid = $entity->guid;
-
- $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();
- }
- }
- }
- }
- function _elgg_default_widgets_permissions_override($hook, $type, $return, $params) {
- if ($type == 'object' && $params['subtype'] == 'widget') {
- return elgg_in_context('create_default_widgets') ? true : null;
- }
- return null;
- }
- return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
- $events->registerHandler('init', 'system', '_elgg_widgets_init');
- $events->registerHandler('ready', 'system', '_elgg_default_widgets_init');
- };
|