/** * Handle GET requests for /admin/tags to display the tags. */ public function get_tags() { $this->theme->wsse = Utils::WSSE(); $this->theme->tags = Tags::vocabulary()->get_tree('term_display asc'); $this->theme->max = Tags::vocabulary()->max_count(); $this->theme->min = Tags::vocabulary()->min_count(); $form = new FormUI('tags'); $form->append(FormControlFacet::create('search')->set_property('data-facet-config', array('onsearch' => 'deselect_all(); $("#tag_collection").manager("update", self.data("visualsearch").searchQuery.facets());', 'facetsURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'tags', 'component' => 'facets')), 'valuesURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'tags', 'component' => 'values'))))); $aggregate = FormControlAggregate::create('selected_items')->set_selector("#tag_collection input")->label('0 Selected'); $aggr_wrap = FormControlWrapper::create('tag_controls_aggregate')->add_class('aggregate_wrapper'); $aggr_wrap->append($aggregate); $delete = FormControlDropbutton::create('delete_dropbutton'); $delete->append(FormControlButton::create('action')->set_caption(_t('Delete selected'))->set_properties(array('title' => _t('Delete selected'), 'value' => 'delete'))); $rename_text = FormControlText::create('rename_text'); $rename = FormControlDropbutton::create('rename_dropbutton'); $rename->append(FormControlButton::create('action')->set_caption(_t('Rename selected'))->set_properties(array('title' => _t('Rename selected'), 'value' => 'rename'))); $tag_controls = $form->append(FormControlWrapper::create('tag_controls'))->add_class("container tag_controls"); $tag_controls->append($aggr_wrap); $tag_controls->append($rename_text); $tag_controls->append($rename); $tag_controls->append($delete); $tag_controls->append(FormControlWrapper::create('selected_tags')->set_setting('wrap_element', 'ul')->set_property('id', 'selected_tags')); if (count($this->theme->tags) > 0) { $tag_collection = $form->append(FormControlWrapper::create('tag_collection')->add_class('container items')->set_setting('wrap_element', 'ul')->set_property('id', 'tag_collection')); $listitems = $this->get_tag_listitems(); foreach ($listitems as $item) { $tag_collection->append($item); } } else { $tag_collection = $form->append(FormControlStatic::create('<p>' . _t('No tags could be found to match the query criteria.') . '</p>')); } $form->on_success(array($this, 'process_tags')); $this->theme->form = $form; Stack::add('admin_header_javascript', 'visualsearch'); Stack::add('admin_header_javascript', 'manage-js'); Stack::add('admin_stylesheet', 'visualsearch-css'); Stack::add('admin_stylesheet', 'visualsearch-datauri-css'); $this->display('tags'); }
private function fetch_logs() { // load all the values for our filter drop-downs $dates = $this->fetch_log_dates(); $users = $this->fetch_log_users(); $ips = $this->fetch_log_ips(); extract($this->fetch_log_modules_types()); // $modules and $types $severities = LogEntry::list_severities(); // parse out the arguments we'll fetch logs for // the initial arguments $arguments = array('limit' => Controller::get_var('limit', 20), 'offset' => Controller::get_var('offset', 0)); // filter for the search field $search = Controller::get_var('search', ''); if ($search != '') { $arguments['criteria'] = $search; } // filter by date $date = Controller::get_var('date', 'any'); if ($date != 'any') { $d = DateTime::create($date); // ! means fill any non-specified pieces with default Unix Epoch ones $arguments['year'] = $d->format('Y'); $arguments['month'] = $d->format('m'); } // filter by user $user = Controller::get_var('user', 'any'); if ($user != 'any') { $arguments['user_id'] = $user; } // filter by ip $ip = Controller::get_var('address', 'any'); if ($ip != 'any') { $arguments['ip'] = $ip; } // filter modules and types // @todo get events of a specific type in a specific module, instead of either of the two // the interface doesn't currently make any link between module and type, so we won't worry about it for now $module = Controller::get_var('module', 'any'); $type = Controller::get_var('type', 'any'); if ($module != 'any') { // we get a slugified key back, get the actual module name $arguments['module'] = $modules[$module]; } if ($type != 'any') { // we get a slugified key back, get the actual type name $arguments['type'] = $types[$type]; } // filter by severity $severity = Controller::get_var('severity', 0); if ($severity != 0) { $arguments['severity'] = $severity; } // get the logs! $logs = EventLog::get($arguments); // last, but not least, generate the list of years used for the timeline $months = EventLog::get(array_merge($arguments, array('month_cts' => true))); $years = array(); foreach ($months as $m) { $years[$m->year][] = $m; } // assign all our theme values in one spot // first the filter options $this->theme->dates = $dates; $this->theme->users = $users; $this->theme->addresses = $ips; $this->theme->modules = $modules; $this->theme->types = $types; $this->theme->severities = $severities; // next the filter criteria we used $this->theme->search_args = $search; $this->theme->date = $date; $this->theme->user = $user; $this->theme->address = $ip; $this->theme->module = $module; $this->theme->type = $type; $this->theme->severity = $severity; $this->theme->logs = $logs; $this->theme->years = $years; $form = new FormUI('logs_batch', 'logs_batch'); $form->append(FormControlAggregate::create('entries')->set_selector('.log_entry')->set_value(array())->label('None Selected')); $form->append($actions = FormControlDropbutton::create('actions')); $actions->append(FormControlSubmit::create('delete_selected')->on_success(function (FormUI $form) { $ids = $form->entries->value; $count = 0; /** @var LogEntry $log */ foreach ($ids as $id) { $logs = EventLog::get(array('id' => $id)); foreach ($logs as $log) { $log->delete(); $count++; } } Session::notice(_t('Deleted %d logs.', array($count))); $form->bounce(false); })->set_caption(_t('Delete Selected'))); $actions->append(FormControlSubmit::create('purge_logs')->on_success(function (FormUI $form) { if (EventLog::purge()) { Session::notice(_t('Logs purged.')); } else { Session::notice(_t('There was a problem purging the event logs.')); } $form->bounce(false); })->set_caption(_t('Purge Logs'))); $this->theme->form = $form; $this->theme->wsse = Utils::WSSE(); // prepare a WSSE token for any ajax calls }
/** * Handles the submission of the comment moderation form. * @todo Separate delete from "delete until purge" */ public function post_comments() { // Get special search statuses $statuses = Comment::list_comment_statuses(); $labels = array_map(function ($a) { return MultiByte::ucfirst(Plugins::filter("comment_status_display", $a)); }, $statuses); $terms = array_map(function ($a) { return "status:{$a}"; }, $statuses); $statuses = array_combine($terms, $labels); // Get special search types $types = Comment::list_comment_types(); $labels = array_map(function ($a) { return MultiByte::ucfirst(Plugins::filter("comment_type_display", $a, "singular")); }, $types); $terms = array_map(function ($a) { return "type:{$a}"; }, $types); $types = array_combine($terms, $labels); $this->theme->special_searches = array_merge($statuses, $types); $this->fetch_comments(); // Create the form for the search and manage dropbutton. I bet we can save some code when combining this with the other manage pages. $form = new FormUI('manage'); //$search = FormControlFacet::create('search'); //$form->append($search); $aggregate = FormControlAggregate::create('selected_items')->set_selector('.comment_checkbox')->label('None Selected'); $form->append($aggregate); $page_actions = FormControlDropbutton::create('page_actions'); $page_actions->append(FormControlSubmit::create('delete')->set_caption(_t('Delete Selected'))->set_properties(array('onclick' => 'itemManage.update(\'delete\');return false;', 'title' => _t('Delete Selected')))); Plugins::act('comments_manage_actions', $page_actions); $form->append($page_actions); Stack::add('admin_header_javascript', 'manage-js'); $this->theme->form = $form; $this->display('comments'); }
public function __construct() { $self = $this; FormUI::register('add_user', function (FormUI $form, $name) use($self) { $form->set_settings(array('use_session_errors' => true)); $form->append(FormControlText::create('username')->set_properties(array('class' => 'columns three', 'placeholder' => _t('Username')))->add_validator('validate_username')->add_validator('validate_required')); $form->append(FormControlText::create('email')->set_properties(array('class' => 'columns four', 'placeholder' => _t('E-Mail')))->add_validator('validate_email')->add_validator('validate_required')); $password = FormControlPassword::create('password')->set_properties(array('class' => 'columns three', 'placeholder' => _t('Password')))->add_validator('validate_required'); $form->append($password); $form->append(FormControlPassword::create('password_again')->set_properties(array('class' => 'columns three', 'placeholder' => _t('Password Again')))->add_validator('validate_same', $password)); $form->append(FormControlSubmit::create('newuser')->set_caption('Add User')); $form->add_validator(array($self, 'validate_add_user')); $form->on_success(array($self, 'do_add_user')); }); FormUI::register('delete_users', function (FormUI $form, $name) use($self) { $form->set_settings(array('use_session_errors' => true)); $form->append(FormControlAggregate::create('deletion_queue')->set_selector('.select_user')->label('Select All')); $author_list = Users::get_all(); $authors[0] = _t('nobody'); foreach ($author_list as $author) { $authors[$author->id] = $author->displayname; } $form->append(FormControlSelect::create('reassign')->set_options($authors)); $form->append(FormControlSubmit::create('delete_selected')->set_caption(_t('Delete Selected'))); $form->add_validator(array($self, 'validate_delete_users')); $form->on_success(array($self, 'do_delete_users')); }); FormUI::register('edit_user', function (FormUI $form, $name, $form_type, $data) use($self) { $form->set_settings(array('use_session_errors' => true)); $edit_user = $data['edit_user']; $field_sections = array('user_info' => _t('User Information'), 'change_password' => _t('Change Password'), 'regional_settings' => _t('Regional Settings'), 'dashboard' => _t('Dashboard')); // Create a tracker for who we are dealing with $form->append(FormControlData::create('edit_user')->set_value($edit_user->id)); // Generate sections foreach ($field_sections as $key => $name) { $fieldset = $form->append('wrapper', $key, $name); $fieldset->add_class('container main settings'); $fieldset->append(FormControlStatic::create($key)->set_static('<h2 class="lead">' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>')); } // User Info $displayname = FormControlText::create('displayname')->set_value($edit_user->displayname); $form->user_info->append(FormControlLabel::wrap(_t('Display Name'), $displayname)); $username = FormControlText::create('username')->add_validator('validate_username', $edit_user->username)->set_value($edit_user->username); $form->user_info->append(FormControlLabel::wrap(_t('User Name'), $username)); $email = FormControlText::create('email')->add_validator('validate_email')->set_value($edit_user->email); $form->user_info->append(FormControlLabel::wrap(_t('Email'), $email)); $imageurl = FormControlText::create('imageurl')->set_value($edit_user->info->imageurl); $form->user_info->append(FormControlLabel::wrap(_t('Portrait URL'), $imageurl)); // Change Password $password1 = FormControlPassword::create('password1', null, array('autocomplete' => 'off'))->set_value(''); $form->change_password->append(FormControlLabel::wrap(_t('New Password'), $password1)); $password2 = FormControlPassword::create('password2', null, array('autocomplete' => 'off'))->set_value(''); $form->change_password->append(FormControlLabel::wrap(_t('New Password Again'), $password2)); $delete = $self->handler_vars->filter_keys('delete'); // don't validate password match if action is delete if (!isset($delete['delete'])) { $password2->add_validator('validate_same', $password1, _t('Passwords must match.')); } // Regional settings $timezones = \DateTimeZone::listIdentifiers(); $timezones = array_merge(array_combine(array_values($timezones), array_values($timezones))); $locale_tz = FormControlSelect::create('locale_tz', null, array('multiple' => false))->set_options($timezones)->set_value($edit_user->info->locale_tz); $form->regional_settings->append(FormControlLabel::wrap(_t('Timezone'), $locale_tz)); $locale_date_format = FormControlText::create('locale_date_format')->set_value($edit_user->info->locale_date_format); $form->regional_settings->append(FormControlLabel::wrap(_t('Date Format'), $locale_date_format)); $edit_user_info = $edit_user->info; if (isset($edit_user_info->locale_date_format) && $edit_user_info->locale_date_format != '') { $current = DateTime::create()->get($edit_user_info->locale_date_format); } else { $current = DateTime::create()->date; } $locale_date_format->set_helptext(_t('See <a href="%s">php.net/date</a> for details. Current format: %s', array('http://php.net/date', $current))); $locale_time_format = FormControlText::create('locale_time_format')->set_value($edit_user_info->locale_time_format); $form->regional_settings->append(FormControlLabel::wrap(_t('Time Format'), $locale_time_format)); if (isset($edit_user_info->locale_time_format) && $edit_user_info->locale_time_format != '') { $current = DateTime::create()->get($edit_user_info->locale_time_format); } else { $current = DateTime::create()->time; } $locale_time_format->set_helptext(_t('See <a href="%s">php.net/date</a> for details. Current format: %s', array('http://php.net/date', $current))); $locales = array_merge(array('' => _t('System default') . ' (' . Options::get('locale', 'en-us') . ')'), array_combine(Locale::list_all(), Locale::list_all())); $locale_lang = FormcontrolSelect::create('locale_lang', null, array('multiple' => false))->set_options($locales)->set_value($edit_user_info->locale_lang); $form->regional_settings->append(FormControlLabel::wrap(_t(' Language'), $locale_lang)); $spam_count = FormControlCheckbox::create('dashboard_hide_spam_count')->set_helptext(_t('Hide the number of SPAM comments on your dashboard.'))->set_value($edit_user_info->dashboard_hide_spam_count); $form->dashboard->append(FormControlLabel::wrap(_t('Hide Spam Count'), $spam_count)); // Groups if (User::identify()->can('manage_groups')) { $fieldset = $form->append(FormControlWrapper::create('groups')); $fieldset->add_class('container main settings'); $fieldset->append(FormControlStatic::create('groups_title')->set_static('<h2 class="lead">' . htmlentities(_t('Groups'), ENT_COMPAT, 'UTF-8') . '</h2>')); $fieldset->append(FormControlCheckboxes::create('user_group_membership')->set_options(Utils::array_map_field(UserGroups::get_all(), 'name', 'id'))->set_value($edit_user->groups)); } // Controls $controls = $form->append(FormControlWrapper::create('page_controls')->add_class('container controls transparent')); $apply = $controls->append(FormControlSubmit::create('apply')->set_caption(_t('Apply'))); // Get author list $author_list = Users::get_all(); $authors[0] = _t('nobody'); foreach ($author_list as $author) { $authors[$author->id] = $author->displayname; } unset($authors[$edit_user->id]); // We can't reassign this user's posts to themselves if we're deleting them $reassign = FormControlSelect::create('reassign')->set_options($authors); $reassign_label = FormControlLabel::wrap(_t('Reassign posts to:'), $reassign)->set_settings(array('wrap' => '<span class="reassigntext">%s</span>')); $controls->append($reassign_label); $controls->append(FormControlStatic::create('conjunction')->set_static(_t('and'))->set_settings(array('wrap' => '<span class="conjunction">%s</span>'))); $delete = $controls->append(FormControlSubmit::create('delete')->set_caption(_t('Delete'))->set_settings(array('wrap' => '<span>%s</span>'))->add_class('button')); $delete->on_success(array($self, 'edit_user_delete')); $delete->add_validator(array($self, 'validate_delete_user')); $apply->on_success(array($self, 'edit_user_apply')); $apply->add_validator(array($self, 'validate_edit_user')); }); parent::__construct(); }
/** * Handles POST values from /manage/posts. * Used to control what content to show / manage. */ public function post_posts() { // Simply pass $_GET to the function, it's save as only values we understand will be read $this->fetch_posts($_GET); // Check which values have been passed and translate them for the faceted seach $search_values = array(); foreach ($this->locals as $varname => $default) { if (isset($_GET[$varname])) { switch ($varname) { case 'type': $search_values[] = 'type: ' . Post::type_name($_GET['type']); break; case 'status': $search_values[] = 'status: ' . Post::status_name($_GET['status']); break; case 'tag': $tags = explode(',', $_GET['tag']); foreach ($tags as $tag) { $search_values[] = 'tag: ' . $tag; } break; case 'author': $search_values[] = 'author: ' . User::get($_GET['author'])->username; break; default: $search_values[] = $varname . ': ' . $_GET[$varname]; } } } if (count($search_values) > 0) { $search_value = implode(' ', $search_values); } else { $search_value = ''; } // Create search controls and global buttons for the manage page $search = FormControlFacet::create('search'); $search->set_value($search_value)->set_property('data-facet-config', array('onsearch' => '$(".posts").manager("update", self.data("visualsearch").searchQuery.facets());', 'facetsURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'manage', 'component' => 'facets')), 'valuesURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'manage', 'component' => 'values')))); $navigation = FormControlStatic::create('navigation')->set_static('<a href="" id="nav_prev" class="navigation">' . _t('Previous page') . '</a>' . '<a href="" id="nav_next" class="navigation">' . _t('Next page') . '</a>'); $aggregate = FormControlAggregate::create('selected_items')->set_selector('.post_item')->label('None Selected'); $page_actions = FormControlDropbutton::create('page_actions'); $page_actions->append(FormControlSubmit::create('delete')->set_caption(_t('Delete Selected'))->set_properties(array('onclick' => 'itemManage.update(\'delete\');return false;', 'title' => _t('Delete Selected')))); Plugins::act('posts_manage_actions', $page_actions); $form = new FormUI('manage'); $form->append($search); $form->append($navigation); $form->append($aggregate); $form->append($page_actions); $this->theme->form = $form; $this->theme->admin_page = _t('Manage Posts'); $this->theme->admin_title = _t('Manage Posts'); Stack::add('admin_header_javascript', 'visualsearch'); Stack::add('admin_header_javascript', 'manage-js'); Stack::add('admin_stylesheet', 'visualsearch-css'); Stack::add('admin_stylesheet', 'visualsearch-datauri-css'); $this->display('posts'); }