public function theme_route_change_sudo() { $form = $this->get_form(); $user_id = $form->userlist->value; $user = User::get_by_id($user_id); if ($_SESSION['user_id'] == $user->id) { unset($_SESSION['sudo']); } else { $_SESSION['sudo'] = $user->id; } $ar = new AjaxResponse(200, 'Ok.'); $ar->html('#sudo_handle', $user->displayname); $ar->out(); }
/** * Handles AJAX requests from the dashboard */ public function ajax_dashboard($handler_vars) { Utils::check_request_method(array('POST')); $theme_dir = Plugins::filter('admin_theme_dir', Site::get_dir('admin_theme', true)); $this->theme = Themes::create('admin', 'RawPHPEngine', $theme_dir); switch ($handler_vars['action']) { case 'updateModules': $modules = array(); foreach ($_POST as $key => $module) { // skip POST elements which are not module names if (preg_match('/^module\\d+$/', $key)) { list($module_id, $module_name) = explode(':', $module, 2); // remove non-sortable modules from the list if ($module_id != 'nosort') { $modules[$module_id] = $module_name; } } } Modules::set_active($modules); $ar = new AjaxResponse(200, _t('Modules updated.')); break; case 'addModule': $id = Modules::add($handler_vars['module_name']); $this->fetch_dashboard_modules(); $ar = new AjaxResponse(200, _t('Added module %s.', array($handler_vars['module_name']))); $ar->html('modules', $this->theme->fetch('dashboard_modules')); break; case 'removeModule': Modules::remove($handler_vars['moduleid']); $this->fetch_dashboard_modules(); $ar = new AjaxResponse(200, _t('Removed module.')); $ar->html('modules', $this->theme->fetch('dashboard_modules')); break; } $ar->out(); }
/** * Called from the themes page to save the blocks instances into areas * * @param mixed $handler_vars * @return */ public function ajax_save_areas($handler_vars) { Utils::check_request_method(array('POST')); $scope = $_POST['scope']; $msg = ''; $response = new AjaxResponse(); if (isset($_POST['area_blocks'])) { $area_blocks = $_POST['area_blocks']; DB::query('DELETE FROM {blocks_areas} WHERE scope_id = :scope_id', array('scope_id' => $scope)); foreach ((array) $area_blocks as $area => $blocks) { $display_order = 0; // if there are no blocks for a given area, skip it if (empty($blocks)) { continue; } foreach ($blocks as $block) { $display_order++; DB::query('INSERT INTO {blocks_areas} (block_id, area, scope_id, display_order) VALUES (:block_id, :area, :scope_id, :display_order)', array('block_id' => $block, 'area' => $area, 'scope_id' => $scope, 'display_order' => $display_order)); } } // $msg = json_encode( _t( 'Saved block areas settings.' ) ); // $msg = '<script type="text/javascript"> // human_msg.display_msg(' . $msg . '); // spinner.stop(); // </script>'; $response->message = _t('Saved block areas settings.'); } $this->setup_admin_theme(''); $blocks_areas_t = DB::get_results('SELECT b.*, ba.scope_id, ba.area, ba.display_order FROM {blocks} b INNER JOIN {blocks_areas} ba ON ba.block_id = b.id ORDER BY ba.scope_id ASC, ba.area ASC, ba.display_order ASC', array()); $blocks_areas = array(); foreach ($blocks_areas_t as $block) { if (!isset($blocks_areas[$block->scope_id])) { $blocks_areas[$block->scope_id] = array(); } $blocks_areas[$block->scope_id][$block->area][$block->display_order] = $block; } $this->theme->blocks_areas = $blocks_areas; $this->theme->scopeid = $scope; $this->theme->areas = $this->get_areas($scope); $scopes = DB::get_results('SELECT * FROM {scopes} ORDER BY name ASC;'); $scopes = Plugins::filter('get_scopes', $scopes); $this->theme->scopes = $scopes; $this->theme->active_theme = Themes::get_active_data(true); $output = $this->theme->fetch('block_areas'); $response->html('block_areas', $output); $response->out(); }
/** * Handles AJAX from /admin/tags * Used to search for, delete and rename tags */ public function ajax_tags() { Utils::check_request_method(array('POST', 'HEAD')); $this->create_theme(); $params = $_POST['query']; // Get a usable array with filter parameters from the odd syntax we received from the faceted search $fetch_params = array(); if (isset($params)) { foreach ($params as $param) { $key = key($param); // Revert translation if ($key != 'text') { $key = self::$facets[$key]; } $value = current($param); if (array_key_exists($key, $fetch_params)) { $fetch_params[$key] = Utils::single_array($fetch_params[$key]); $fetch_params[$key][] = $value; } else { $fetch_params[$key] = $value; } } } // Grab facets / params $search = array_key_exists('text', $fetch_params) ? $fetch_params['text'] : null; $min = array_key_exists('morethan', $fetch_params) ? $fetch_params['morethan'] + 1 : 0; $max = array_key_exists('lessthan', $fetch_params) ? $fetch_params['lessthan'] - 1 : null; $orderby_code = array_key_exists('orderby', $fetch_params) ? $fetch_params['orderby'] : null; $orderby = isset($orderby_code) ? explode('_', self::$facet_values['orderby'][$orderby_code]) : ['alphabetical', 'asc']; $this->theme->tags = Tags::get_by_frequency(null, null, $min, $max, $search, self::$orderby_translate[$orderby[0]], $orderby[1] == 'asc'); // Create FormUI elements (list items) from the filtered tag list $this->theme->max = Tags::vocabulary()->max_count(); $this->theme->min = Tags::vocabulary()->min_count(); $output = ''; if (count($this->theme->tags) > 0) { $listitems = $this->get_tag_listitems(); // Get HTML from FormUI foreach ($listitems as $listitem) { $output .= $listitem->get($this->theme); } } $ar = new AjaxResponse(); $ar->html('#tag_collection', $output); $ar->out(); }
/** * Handles AJAX requests from the dashboard */ public function ajax_dashboard($handler_vars) { Utils::check_request_method(array('POST')); $this->create_theme(); $this->get_additem_form(); $available_modules = Plugins::filter('dashboard_block_list', array()); $user_id = User::identify()->id; $dashboard_area = 'dashboard_' . $user_id; switch ($handler_vars['action']) { case 'updateModules': $modules = $_POST['moduleOrder']; $order = 0; foreach ($modules as $module) { $order++; DB::query('UPDATE {blocks_areas} SET display_order = :display_order WHERE block_id = :id AND area = :dashboardarea', array('display_order' => $order, 'id' => $module, 'dashboardarea' => $dashboard_area)); } $ar = new AjaxResponse(200, _t('Modules updated.')); break; case 'addModule': $type = $handler_vars['module_name']; $title = $available_modules[$type]; $block = new Block(array('title' => $title, 'type' => $type)); $block->insert(); $max_display_order = DB::get_value('SELECT max(display_order) FROM {blocks_areas} WHERE area = :dashboardarea and scope_id = 0;', array('dashboardarea' => $dashboard_area)); $max_display_order++; DB::query('INSERT INTO {blocks_areas} (block_id, area, scope_id, display_order) VALUES (:block_id, :dashboardarea, 0, :display_order)', array('block_id' => $block->id, 'display_order' => $max_display_order, 'dashboardarea' => $dashboard_area)); $ar = new AjaxResponse(200, _t('Added module %s.', array($title))); $ar->html('modules', $this->theme->fetch('dashboard_modules')); break; case 'removeModule': $block_id = $handler_vars['moduleid']; DB::delete('{blocks}', array('id' => $block_id)); DB::delete('{blocks_areas}', array('block_id' => $block_id)); $ar = new AjaxResponse(200, _t('Removed module.')); $ar->html('modules', $this->theme->fetch('dashboard_modules')); break; case 'configModule': $block_id = $handler_vars['moduleid']; $block = DB::get_row('SELECT * FROM {blocks} b WHERE b.id = :id', array('id' => $block_id), 'Block'); /** Block $block */ $form = $block->get_form(); $form->_ajax = true; $form->set_option('success_message', _t('Module Configuration Saved.') . '<script type="text/javascript">window.setTimeout(function(){$(".form_message").fadeOut();}, 2000);</script>'); $control_id = new FormControlHidden('moduleid', 'null:null'); $control_id->value = $block->id; $control_id->id = 'moduleid'; $form->append($control_id); $control_action = new FormControlHidden('action', 'null:null'); $control_action->value = 'configModule'; $control_action->id = 'action'; $form->append($control_action); $form->out(); $form_id = $form->name; exit; break; } $ar->out(); }
/** * Handles AJAX requests from the manage posts page. */ public function ajax_posts() { Utils::check_request_method(array('POST', 'HEAD')); $this->create_theme(); $params = $_POST['query']; $fetch_params = array(); if (isset($params) && !empty($params)) { foreach ($params as $param) { $key = key($param); $value = current($param); if (isset($fetch_params[$key])) { $fetch_params[$key] = Utils::single_array($fetch_params[$key]); $fetch_params[$key][] = $value; } else { $fetch_params[$key] = $value; } } } $this->fetch_posts($fetch_params); $items = $this->theme->fetch('posts_items'); $timeline = $this->theme->fetch('timeline_items'); $item_ids = array(); foreach ($this->theme->posts as $post) { if (ACL::access_check($post->get_access(), 'delete')) { $item_ids['p' . $post->id] = 1; } } $ar = new AjaxResponse(); $ar->html('.posts', $items); $ar->data = array('items' => $items, 'item_ids' => $item_ids, 'timeline' => $timeline); $ar->out(); }