/** * Add the Add Item form to the theme for display */ public function get_additem_form() { /** @var FormUI $additem_form */ $additem_form = FormUI::create('dash_additem')->set_properties(array('onsubmit' => 'dashboard.add(); return false;')); $additem_form->append(FormControlSelect::create('module')->set_options(Plugins::filter('dashboard_block_list', array()))); $additem_form->append(FormControlSubmit::create('submit')->set_caption(_t('+'))); $this->theme->additem_form = $additem_form->get(); }
public function configure() { $form = new FormUI('lipsum'); // $form->set_settings( array( 'use_session_errors' => true ) ); $form->append(FormControlText::create('num_posts', 'option:lipsum__num_posts')->add_validator('validate_lipsum_numbers')->label(_t('Number of posts to have present:', __CLASS__))); $form->append(FormControlText::create('num_comments', 'option:lipsum__num_comments')->add_validator('validate_lipsum_numbers')->label(_t('Max number of comments for each post:', __CLASS__))); $form->append(FormControlText::create('num_tags', 'option:lipsum__num_tags')->add_validator('validate_lipsum_numbers')->label(_t('Max number of tags for each post:', __CLASS__))); $form->append(FormControlSubmit::create('save')->set_caption('Save')); $form->on_success(array($this, 'updated_config')); echo $form->get(); }
public function __construct() { $self = $this; FormUI::register('add_group', function (FormUI $form, $name) use($self) { $form->set_settings(array('use_session_errors' => true)); $form->append(FormControlText::create('groupname')->add_validator('validate_required', _t('The group must have a name'))->add_validator('validate_groupname')->label(_t('Group Name'))->add_class('incontent')->set_template('control.label.outsideleft')); $form->append(FormControlSubmit::create('newgroup')->set_caption('Add Group')); $form->add_validator(array($self, 'validate_add_group')); $form->on_success(array($self, 'do_add_group')); }); parent::__construct(); }
/** * Builds and returns the form for the first stage of the importer * @param array The list of importers the plugin contains * @param string The name of the current importer * * @return FormUI The FormUI element used to chose the importer */ public function get_form($importers, $importer) { $form = new FormUI('import'); if (count($importers) == 0) { $form->append(FormControlStatic(' <p>' . _t('You do not currently have any import plugins installed.') . '</p>')); $form->append(FormControlStatic(' <p>' . _t('Please <a href="%1$s">activate an import plugin</a> to enable importing.', array(URL::get('display_plugins'))) . '</p>')); } else { $form->append(FormControlLabel::wrap(_t('Please choose the type of import to perform:'), FormControlSelect::create('importer')->set_options(array_combine($importers, $importers)))); $form->append(FormControlSubmit::create('import')->set_caption(_t('Select'))); } return $form->get(); }
public function __construct() { parent::__construct(); // Let's register the options page form so we can use it with ajax $self = $this; FormUI::register('admin_options', function ($form, $name, $extra_data) use($self) { $option_items = array(); $timezones = \DateTimeZone::listIdentifiers(); $timezones = array_merge(array('' => ''), array_combine(array_values($timezones), array_values($timezones))); $option_items[_t('Name & Tagline')] = array('title' => array('label' => _t('Site Name'), 'type' => 'text', 'helptext' => ''), 'tagline' => array('label' => _t('Site Tagline'), 'type' => 'text', 'helptext' => ''), 'about' => array('label' => _t('About'), 'type' => 'textarea', 'helptext' => '')); $option_items[_t('Publishing')] = array('pagination' => array('label' => _t('Items per Page'), 'type' => 'text', 'helptext' => ''), 'atom_entries' => array('label' => _t('Entries to show in Atom feed'), 'type' => 'text', 'helptext' => ''), 'comments_require_id' => array('label' => _t('Require Comment Author Email'), 'type' => 'checkbox', 'helptext' => ''), 'spam_percentage' => array('label' => _t('Comment SPAM Threshold'), 'type' => 'text', 'helptext' => _t('The likelihood a comment is considered SPAM, in percent.'))); $option_items[_t('Time & Date')] = array('timezone' => array('label' => _t('Time Zone'), 'type' => 'select', 'selectarray' => $timezones, 'helptext' => _t('Current Date Time: %s', array(DateTime::create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(DateTime::create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(DateTime::create()->time)))); $option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(Locale::list_all(), Locale::list_all())), 'helptext' => Config::exists('locale') ? _t('International language code : This value is set in your config.php file, and cannot be changed here.') : _t('International language code'), 'disabled' => Config::exists('locale'), 'value' => Config::get('locale', Options::get('locale', 'en-us'))), 'system_locale' => array('label' => _t('System Locale'), 'type' => 'text', 'helptext' => _t('The appropriate locale code for your server'))); $option_items[_t('Troubleshooting')] = array('log_min_severity' => array('label' => _t('Minimum Severity'), 'type' => 'select', 'selectarray' => LogEntry::list_severities(), 'helptext' => _t('Only log entries with a this or higher severity.')), 'log_backtraces' => array('label' => _t('Log Backtraces'), 'type' => 'checkbox', 'helptext' => _t('Logs error backtraces to the log table\'s data column. Can drastically increase log size!'))); $option_items = Plugins::filter('admin_option_items', $option_items); $tab_index = 3; foreach ($option_items as $name => $option_fields) { /** @var FormControlFieldset $fieldset */ $fieldset = $form->append(FormControlWrapper::create(Utils::slugify(_u($name)))->set_properties(array('class' => 'container main settings'))); $fieldset->append(FormControlStatic::create($name)->set_static('<h2 class="lead">' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>')); $fieldset->set_wrap_each('<div>%s</div>'); foreach ($option_fields as $option_name => $option) { /** @var FormControlLabel $label */ $label = $fieldset->append(FormControlLabel::create('label_for_' . $option_name, null)->set_label($option['label'])); /** @var FormControl $field */ $field = $label->append($option['type'], $option_name, $option_name); $label->set_for($field); if (isset($option['value'])) { $field->set_value($option['value']); } if (isset($option['disabled']) && $option['disabled'] == true) { $field->set_properties(array('disabled' => 'disabled')); } if ($option['type'] == 'select' && isset($option['selectarray'])) { $field->set_options($option['selectarray']); } $field->tabindex = $tab_index; $tab_index++; if (isset($option['helptext'])) { $field->set_helptext($option['helptext']); } } } $buttons = $form->append(new FormControlWrapper('buttons', null, array('class' => 'container'))); $buttons->append(FormControlSubmit::create('apply', null, array('tabindex' => $tab_index))->set_caption(_t('Apply'))); $form->on_success(array($self, 'form_options_success')); $form = Plugins::filter('admin_options_form', $form); }); }
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 }
<h4><a href="<?php echo URL::get('display_group', 'id=' . $group->id); ?> " title="<?php _e('Edit group'); ?> "><?php echo $group->name; ?> </a></h4> <?php $group_actions = FormControlDropbutton::create('group_actions'); $group_actions->append(FormControlSubmit::create('edit')->set_caption(_t('Edit'))->set_url(URL::get('display_group', 'id=' . $group->id))->set_property('title', _t('Edit \'%s\'', array($group->title)))->set_enable(function ($control) { return User::identify()->can('manage_groups'); })); $group_actions->append(FormControlSubmit::create('delete')->set_caption(_t('Delete'))->set_url('javascript:itemManage.remove(' . $group->id . ', \'group\');')->set_property('title', _t('Delete \'%s\'', array($group->name)))->set_enable(function ($control) { return User::identify()->can('manage_groups'); })); echo $group_actions->pre_out(); echo $group_actions->get($theme); // @todo Add back in filtering of group actions // $actions = Plugins::filter('group_actions', $actions); ?> </div> <?php if (count($users) > 0) { ?> <p class="users"><?php echo _t('Members: ') . Format::and_list($users); ?> </p>
} elseif (isset($inactive_theme['req_parent'])) { ?> <p class="legacy"><?php _e('This theme requires the parent theme named "%s".', array($inactive_theme['req_parent'])); ?> </p> <?php } else { ?> <?php $dbtn = FormControlDropbutton::create('actions'); $dbtn->append(FormControlSubmit::create('activate')->set_url(URL::get('activate_theme', 'theme_dir=' . $inactive_theme['dir'] . '&theme_name=' . $inactive_theme['info']->name))->set_caption(_t('Activate'))); if ($previewed == $inactive_theme['dir']) { $dbtn->append(FormControlSubmit::create('end_preview')->set_url(URL::get('preview_theme', 'theme_dir=' . $inactive_theme['dir'] . '&theme_name=' . $inactive_theme['info']->name))->set_caption(_t('End Preview'))); } else { $dbtn->append(FormControlSubmit::create('preview')->set_url(URL::get('preview_theme', 'theme_dir=' . $inactive_theme['dir'] . '&theme_name=' . $inactive_theme['info']->name))->set_caption(_t('Preview'))); } echo $dbtn->pre_out(); echo $dbtn->get($theme); ?> <?php } ?> </div> <div class="clearfix"> <div class="thumb columns four"> <img class="themethumb columns four" src="<?php echo $inactive_theme['screenshot']; ?> "> </div>
} ?> </div> <p class="description"><?php echo $plugin['info']->description; ?> </p> </div> <?php /** @var FormControlDropbutton $dbtn */ if (count($plugin['actions']) > 0) { $dbtn = FormControlDropbutton::create('actions'); foreach ($plugin['actions'] as $key => $data) { $dbtn->append(FormControlSubmit::create($key)->set_url($data['href'])->set_caption($data['caption'])); } echo $dbtn->pre_out(); echo $dbtn->get($theme); } ?> </div> <div class="requirements"> <?php if (isset($plugin['missing'])) { ?> <ul> <?php foreach ($plugin['missing'] as $feature => $url) { ?>
function test_inline_control_template() { $myform = new FormUI('my_identifier'); $myform->get_theme()->add_template('control.text.custom', dirname(__FILE__) . '/../data/formcontrol_custom2.php'); $firstname = FormControlText::Create('firstname', 'user:username')->set_template('control.text.custom'); $myform->append(FormControlLabel::wrap('Firstname:', $firstname)); $myform->append(FormControlSubmit::create('save')->set_caption('Save')); $html = $myform->get(); $this->output($html); $this->assert_true(strpos($html, 'custom:formcontrol_custom2.php') !== false, 'Could not find content of custom template in form output'); }
/** * Manage this post's comment form * * @param string $context The context in which the form is used, used to facilitate plugin alteration of the comment form in different circumstances * @return FormUI The comment form for this post */ public function comment_form($context = 'public') { // Handle comment submissions and default commenter id values $cookie = 'comment_' . Options::get('public-GUID'); $commenter_name = ''; $commenter_email = ''; $commenter_url = ''; $commenter_content = ''; $user = User::identify(); if ($user->loggedin) { $commenter_name = $user->displayname; $commenter_email = $user->email; $commenter_url = Site::get_url('habari'); } elseif (isset($_COOKIE[$cookie])) { // limit to 3 elements so a # in the URL stays appended $commenter = explode('#', $_COOKIE[$cookie], 3); // make sure there are always at least 3 elements $commenter = array_pad($commenter, 3, null); list($commenter_name, $commenter_email, $commenter_url) = $commenter; } // Now start the form. $form = new FormUI('comment-' . $context, 'comment'); $form->add_class($context); $form->add_class('commentform'); $form->set_wrap_each('<div>%s</div>'); $form->set_setting('use_session_errors', true); // Enforce commenting rules if (Options::get('comments_disabled')) { $form->append(new FormControlStatic('message', _t('Comments are disabled site-wide.'))); $form->class[] = 'comments_disabled'; $form->set_properties(array('action' => '/')); } elseif ($this->info->comments_disabled) { $form->append(new FormControlStatic('message', _t('Comments for this post are disabled.'))); $form->class[] = 'comments_disabled'; $form->set_properties(array('action' => '/')); } elseif (Options::get('comments_require_logon') && !$user->loggedin) { $form->append(new FormControlStatic('message', _t('Commenting on this site requires authentication.'))); $form->class[] = 'comments_require_logon'; $form->set_properties(array('action' => '/')); } elseif (!$user->can('comment')) { $form->append(new FormControlStatic('message', _t('You do not have permission to comment on this site.'))); $form->class[] = 'comments_require_permission'; $form->set_properties(array('action' => '/')); } else { $form->set_properties(array('action' => URL::get('submit_feedback', array('id' => $this->id)))); // Create the Name field $form->append(FormControlLabel::wrap(_t('Name <span class="required">*Required</span>'), FormControlText::create('cf_commenter', 'null:null', array('id' => 'comment_name', 'required' => 'required'))->add_validator('validate_required', _t('The Name field value is required')))); // Create the Email field $form->append($cf_email = FormControlText::create('cf_email', 'null:null', array('id' => 'comment_email', 'type' => 'email'))->add_validator('validate_email', _t('The Email field value must be a valid email address'))); if (Options::get('comments_require_id') == 1) { $cf_email->add_validator('validate_required', _t('The Email field value must be a valid email address')); $cf_email->label(_t('Email <span class="required">*Required</span>')); $cf_email->set_property("required", "required"); } else { $cf_email->label(_t('Email')); } $cf_email->set_value($commenter_email); // Create the URL field $form->append(FormControlLabel::wrap(_t('Website'), FormControlText::create('cf_url', 'null:null', array('id' => 'comment_url', 'type' => 'url')))->add_validator('validate_url', _t('The Website field value must be a valid URL'))); $form->cf_url->value = $commenter_url; // Create the Comment field $form->append(FormControlTextArea::create('cf_content', 'null:null', array('id' => 'comment_content', 'required' => 'required'))->add_validator('validate_required', _t('The Comment field value is required'))->label(_t('Content'))); $form->cf_content->value = $commenter_content; // Create the Submit button $form->append(FormControlSubmit::create('cf_submit')->set_properties(array('value' => _t('Submit')))); // Let plugins alter this form Plugins::act('form_comment', $form, $this, $context); } // Return the form object return $form; }
/** * Display the login form * * @param string $name Pre-fill the name field with this name */ protected function login_form() { // Build theme and login page template $this->setup_theme(); if (!$this->theme->template_exists('login')) { $this->theme = Themes::create('admin', 'RawPHPEngine', Site::get_dir('admin_theme', true)); $this->theme->assign('admin_page', 'login'); } // Build the login form $form = new FormUI('habari_login'); //$form->on_success( array( $this, 'loginform_success' ) ); $login_form_title = _t('<h1><a href="%1$s" title="%2$s"><img alt="%2$s" src="%3$s" style="height:1em;margin-right:10px;vertical-align:top;">%4$s</a></h1>', array(Site::get_url('site'), _t('Go to Site'), Site::get_url('habari', '/system/admin/images/habari.logo.png'), Options::get('title'))); $form->append(FormControlStatic::create('title')->set_static($login_form_title)); $form->append(FormControlStatic::create('reset_message')->set_static('<p id="reset_message" class="on_reset">' . _t('Please enter the username you wish to reset the password for. A unique password reset link will be emailed to that user.') . '</p>')); $form->append(FormControlLabel::wrap(_t('Name'), FormControlText::create('habari_username')->set_property('autofocus', 'autofocus'))->set_template('control.label.outsideleft')); $form->append(FormControlLabel::wrap(_t('Password'), FormControlPassword::create('habari_password', null, array('class' => 'off_reset')))->set_template('control.label.outsideleft')->set_properties(array('class' => 'off_reset'))); $form->append($drop_button = FormControlDropbutton::create('submit_button')->add_template_class('ul', 'off_reset')); $drop_button->append(FormControlSubmit::create('login')->on_success(array($this, 'loginform_do_login'))->set_caption(_t('Login'))); $form->append(FormControlStatic::create('reset_link')->set_static('<a href="#" class="off_reset reset_link">' . _t('Reset password') . '</a>')); $form->append(FormControlStatic::create('login_link')->set_static('<a href="#" class="on_reset reset_link">' . _t('Login') . '</a>')); $form->append(FormControlSubmit::create('reset_button')->set_caption(_t('Reset password'))->set_properties(array('class' => 'on_reset'))->on_success(array($this, 'loginform_do_reset'))); // Use the dropbutton's visualizer to select the primary action for form submission upon pressing enter $form->set_settings(array('prefix_html' => '<script>$(function(){$("body").on("keypress", "form[name=' . $form->input_name() . ']", function(e){if(e.which==13){$(this).find("#' . $form->submit_button->get_visualizer() . ' .primary").click();return e.preventDefault()&&false;}});})</script>')); // Let plugins alter this form Plugins::act('form_login', $form); // Assign login form and display the page $this->theme->form = $form; $this->display('login'); return true; }
/** * Get the block configuration form to show in a modal iframe on the themes page * */ public function get_configure_block() { Utils::check_request_method(array('GET', 'POST')); $block = DB::get_row('SELECT b.* FROM {blocks} b WHERE id = :id ORDER BY b.title ASC', array('id' => $_GET['blockid']), 'Block'); /** @var FormUI $block_form */ $block_form = $block->get_form(); // @todo This. Is dumb. Fix it. $block_form->set_properties(array('success_message' => '</div><div class="humanMsg" id="humanMsg" style="display: block;top: auto;bottom:-50px;"><div class="imsgs"><div id="msgid_2" class="msg" style="display: block; opacity: 0.8;"><p>' . _t('Saved block configuration.') . '</p></div></div></div> <script type="text/javascript"> $("#humanMsg").animate({bottom: "5px"}, 500, function(){ window.setTimeout(function(){$("#humanMsg").animate({bottom: "-50px"}, 500)},3000) }) parent.refresh_block_forms(); </script> <div style="display:none;"> ')); $first_control = reset($block_form->controls); $block_admin = FormControlFieldset::create('block_admin')->set_caption(_t('Block Display Settings')); if ($first_control) { $block_form->insert($first_control, $block_admin); } else { $block_form->append($block_admin); } $block_title_storage = new ControlStorage(function () use($block) { return $block->title; }, function ($name, $value) use($block) { $block->title = $value; }); $block_admin->append(FormControlLabel::wrap(_t('Block Title:'), FormControlText::create('_title', $block_title_storage)->add_validator('validate_required'))); $block_admin->append(FormControlLabel::wrap(_t('Display Block Title:'), FormControlCheckbox::create('_show_title', $block))); $block_form->append(FormControlSubmit::create('save')->set_caption(_t('Save'))); $this->theme->content = $block_form->get(); $this->display('block_configure'); }
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(); }
/** * Retrieve comments. */ public function fetch_comments($params = array()) { // Make certain handler_vars local with defaults, and add them to the theme output $locals = array('do_delete' => false, 'do_spam' => false, 'do_approve' => false, 'do_unapprove' => false, 'comment_ids' => null, 'nonce' => '', 'timestamp' => '', 'password_digest' => '', 'mass_spam_delete' => null, 'mass_delete' => null, 'type' => 'All', 'limit' => 20, 'offset' => 0, 'search' => '', 'status' => 'All', 'orderby' => 'date DESC'); foreach ($locals as $varname => $default) { ${$varname} = isset($this->handler_vars[$varname]) ? $this->handler_vars[$varname] : (isset($params[$varname]) ? $params[$varname] : $default); $this->theme->{$varname} = ${$varname}; } // Setting these mass_delete options prevents any other processing. Desired? if (isset($mass_spam_delete) && $status == 'spam') { // Delete all comments that have the spam status. Comments::delete_by_status('spam'); // let's optimize the table $result = DB::query('OPTIMIZE TABLE {comments}'); Session::notice(_t('Deleted all spam comments')); EventLog::log(_t('Deleted all spam comments'), 'info'); Utils::redirect(); } elseif (isset($mass_delete) && $status == 'unapproved') { // Delete all comments that are unapproved. Comments::delete_by_status('unapproved'); Session::notice(_t('Deleted all unapproved comments')); EventLog::log(_t('Deleted all unapproved comments'), 'info'); Utils::redirect(); } elseif (($do_delete || $do_spam || $do_approve || $do_unapprove) && isset($comment_ids)) { $okay = true; if (empty($nonce) || empty($timestamp) || empty($password_digest)) { $okay = false; } $wsse = Utils::WSSE($nonce, $timestamp); if ($password_digest != $wsse['digest']) { $okay = false; } if ($okay) { if ($do_delete) { $action = 'delete'; } elseif ($do_spam) { $action = 'spam'; } elseif ($do_approve) { $action = 'approve'; } elseif ($do_unapprove) { $action = 'unapprove'; } $ids = array(); foreach ($comment_ids as $id => $id_value) { if (!isset(${'$comment_ids[' . $id . ']'})) { // Skip unmoderated submitted comment_ids $ids[] = $id; } } $to_update = Comments::get(array('id' => $ids)); $modstatus = array(_t('Deleted %d comments') => 0, _t('Marked %d comments as spam') => 0, _t('Approved %d comments') => 0, _t('Unapproved %d comments') => 0, _t('Edited %d comments') => 0); Plugins::act('admin_moderate_comments', $action, $to_update, $this); switch ($action) { case 'delete': // This comment was marked for deletion $to_update = $this->comment_access_filter($to_update, 'delete'); Comments::delete_these($to_update); $modstatus[_t('Deleted %d comments')] = count($to_update); break; case 'spam': // This comment was marked as spam $to_update = $this->comment_access_filter($to_update, 'edit'); Comments::moderate_these($to_update, 'spam'); $modstatus[_t('Marked %d comments as spam')] = count($to_update); break; case 'approve': case 'approved': // Comments marked for approval $to_update = $this->comment_access_filter($to_update, 'edit'); Comments::moderate_these($to_update, 'approved'); $modstatus[_t('Approved %d comments')] = count($to_update); foreach ($to_update as $comment) { $modstatus[_t('Approved comments on these posts: %s')] = (isset($modstatus[_t('Approved comments on these posts: %s')]) ? $modstatus[_t('Approved comments on these posts: %s')] . ' · ' : '') . '<a href="' . $comment->post->permalink . '">' . $comment->post->title . '</a> '; } break; case 'unapprove': case 'unapproved': // This comment was marked for unapproval $to_update = $this->comment_access_filter($to_update, 'edit'); Comments::moderate_these($to_update, 'unapproved'); $modstatus[_t('Unapproved %d comments')] = count($to_update); break; case 'edit': $to_update = $this->comment_access_filter($to_update, 'edit'); foreach ($to_update as $comment) { // This comment was edited if ($_POST['name_' . $comment->id] != null) { $comment->name = $_POST['name_' . $comment->id]; } if ($_POST['email_' . $comment->id] != null) { $comment->email = $_POST['email_' . $comment->id]; } if ($_POST['url_' . $comment->id] != null) { $comment->url = $_POST['url_' . $comment->id]; } if ($_POST['content_' . $comment->id] != null) { $comment->content = $_POST['content_' . $comment->id]; } $comment->update(); } $modstatus[_t('Edited %d comments')] = count($to_update); break; } foreach ($modstatus as $key => $value) { if ($value) { Session::notice(sprintf($key, $value)); } } } Utils::redirect(); } // we load the WSSE tokens // for use in the delete button $this->theme->wsse = Utils::WSSE(); $arguments = array('type' => $type, 'status' => $status, 'limit' => $limit, 'offset' => $offset, 'orderby' => $orderby); // only get comments the user is allowed to manage if (!User::identify()->can('manage_all_comments')) { $arguments['post_author'] = User::identify()->id; } // there is no explicit 'all' type/status for comments, so we need to unset these arguments // if that's what we want. At the same time we can set up the search field $this->theme->search_args = ''; if ($type == 'All') { unset($arguments['type']); } else { $this->theme->search_args = 'type:' . Comment::type_name($type) . ' '; } if ($status == 'All') { unset($arguments['status']); } else { $this->theme->search_args .= 'status:' . Comment::status_name($status); } if ('' != $search) { $arguments = array_merge($arguments, Comments::search_to_get($search)); } $this->theme->comments = Comments::get($arguments); $monthcts = Comments::get(array_merge($arguments, array('month_cts' => 1))); $years = array(); foreach ($monthcts as $month) { if (isset($years[$month->year])) { $years[$month->year][] = $month; } else { $years[$month->year] = array($month); } } $this->theme->years = $years; $baseactions = array(); $statuses = Comment::list_comment_statuses(); foreach ($statuses as $statusid => $statusname) { $baseactions[$statusname] = array('url' => 'javascript:itemManage.update(\'' . $statusname . '\',__commentid__);', 'title' => _t('Change this comment\'s status to %s', array($statusname)), 'label' => Comment::status_action($statusid), 'access' => 'edit'); } /* Standard actions */ $baseactions['delete'] = array('url' => 'javascript:itemManage.update(\'delete\',__commentid__);', 'title' => _t('Delete this comment'), 'label' => _t('Delete'), 'access' => 'delete'); $baseactions['edit'] = array('url' => URL::get('edit_comment', 'id=__commentid__'), 'title' => _t('Edit this comment'), 'label' => _t('Edit'), 'access' => 'edit'); /* Allow plugins to apply actions */ $actions = Plugins::filter('comments_actions', $baseactions, $this->theme->comments); foreach ($this->theme->comments as $comment) { // filter the actions based on the user's permissions $comment_access = $comment->get_access(); $menu = FormControlDropbutton::create('comment' . $comment->id . '_commentactions'); foreach ($actions as $name => $action) { if ($name == Comment::status_name($comment->status)) { // skip current status continue; } if (!isset($action['label']) || empty($action['label'])) { // just grab something so the thing is labeled $action['label'] = _t($name); } // replace constants/placeholders $action['url'] = str_replace('__commentid__', $comment->id, $action['url']); $entry = FormControlSubmit::create($name)->set_caption($action['label'])->set_url($action['url'])->set_property('title', $action['title']); if (!isset($action['access']) || ACL::access_check($comment_access, $action['access'])) { $menu->append($entry); } } $comment->menu = Plugins::filter('comment_actions', $menu, $comment); } }
</a></span> <span class="time"><?php _e('at'); ?> <?php $post->pubdate->out(DateTime::get_default_time_format()); ?> </span> <div class="actions"> <?php $post_actions = FormControlDropbutton::create('post' . $post->id . '_postactions'); $post_actions->append(FormControlSubmit::create('edit')->set_caption(_t('Edit'))->set_url(URL::get('display_publish', $post, false))->set_property('title', _t('Edit \'%s\'', array($post->title)))->set_enable(function ($control) use($post) { return ACL::access_check($post->get_access(), 'edit'); })); $post_actions->append(FormControlSubmit::create('view')->set_caption(_t('View'))->set_url($post->permalink . '?preview=1')->set_property('title', _t('View \'%s\'', array($post->title)))); $post_actions->append(FormControlSubmit::create('delete')->set_caption(_t('Delete'))->set_url('javascript:itemManage.remove(' . $post->id . ', \'post\');')->set_property('title', _t('Delete \'%s\'', array($post->title)))->set_enable(function ($control) use($post) { return ACL::access_check($post->get_access(), 'delete'); })); Plugins::act('post_actions', $post_actions, $post); echo $post_actions->pre_out(); echo $post_actions->get($theme); ?> </div> </div> </div> <div class="content"> <span class="excerpt" ><?php echo MultiByte::substr(strip_tags($post->content), 0, 250); ?> …</span> </div>
/** * Add target site and checkout forms to cart block */ public function action_block_content_addoncart($block) { $data = Session::get_set('cart_target', false); $target_site = isset($data['target_site']) ? $data['target_site'] : false; $block->cart_target_site = $target_site; // Build form for setting the target site // @todo Later: If user is logged in, offer saving locations for re-use $target_form = new FormUI(__CLASS__ . "_target"); $target_form->append(FormControlLabel::wrap(_t("Install addons on this website"), FormControlText::create('target_site', 'session:cart_target'))); $target_form->target_site->add_validator('validate_required'); $target_form->target_site->add_validator('validate_url'); $target_form->append(FormControlSubmit::create('save')->set_caption('Save')->add_class('save_button')); $target_form->on_success(array($this, "cart_callback")); // Build checkout form if ($target_site) { $target_site .= substr($target_site, -1) == '/' ? '' : '/'; $checkout = new FormUI(__CLASS__ . "_checkout"); $checkout->append(FormControlLabel::wrap(_t("Install addons to <span>%s</span>", array($target_site)), FormControlSubmit::create('checkout')->set_caption('Install')->add_class('proceed_button'))); // Include JSON payload for the target site $cart = Session::get_set("addon_cart", false); $checkout->append(FormControlHidden::create('payload')->set_value(json_encode($cart))); // Point form to target site $checkout->set_properties(array('action' => $target_site . 'install_addons')); $block->checkout_form = $checkout; } $block->target_form = $target_form; }
/** * 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'); }