Ejemplo n.º 1
0
 /**
  * Construct a form for a comment.
  * @return FormUI The comment's form.
  */
 public function form_comment($comment, $actions)
 {
     $form = new FormUI('comment');
     // Create the top description
     $top = $form->append(FormControlWrapper::create('buttons_1', null, array('class' => array('container', 'buttons', 'comment', 'overview'))));
     $top->append(FormControlStatic::create('overview', null)->set_static($this->theme->fetch('comment.overview')));
     $buttons_1 = $top->append(FormControlWrapper::create('buttons_1', null, array('class' => array('item', 'buttons'))));
     foreach ($actions as $status => $action) {
         $id = $action . '_1';
         $buttons_1->append(FormControlSubmit::create($id, null, array('class' => array('status', 'button', $action)))->set_caption(MUltiByte::ucfirst(_t($action))));
         if (Comment::status_name($comment->status) == $status) {
             $buttons_1->{$id}->add_class('active');
             $buttons_1->{$id}->set_properties(array('disabled' => true));
         } else {
             $buttons_1->{$id}->set_properties(array('disabled' => false));
         }
     }
     // Content
     $form->append(FormControlWrapper::create('content_wrapper'));
     $form->content_wrapper->append(FormControlLabel::wrap(_t('Comment'), FormControlTextArea::create('content', null, array('class' => 'resizable'))->set_value($comment->content)));
     // Create the splitter
     $comment_controls = $form->append(FormControlTabs::create('comment_controls'));
     // Create the author info
     $author = $comment_controls->append(FormControlFieldset::create('authorinfo')->set_caption(_t('Author')));
     $author->append(FormControlLabel::wrap(_t('Author Name'), FormControlText::create('author_name')->set_value($comment->name)));
     $author->append(FormControlLabel::wrap(_t('Author Email'), FormControlText::create('author_email')->set_value($comment->email)));
     $author->append(FormControlLabel::wrap(_t('Author URL'), FormControlText::create('author_url')->set_value($comment->url)));
     $author->append(FormControlLabel::wrap(_t('IP Address:'), FormControlText::create('author_ip')->set_value($comment->ip)));
     // Create the advanced settings
     $settings = $comment_controls->append(FormControlFieldset::create('settings')->set_caption(_t('Settings')));
     $settings->append(FormControlLabel::wrap(_t('Date:'), FormControlText::create('comment_date')->set_value($comment->date->get('Y-m-d H:i:s'))));
     $settings->append(FormControlLabel::wrap(_t('Post ID:'), FormControlText::create('comment_post')->set_value($comment->post->id)));
     $statuses = Comment::list_comment_statuses(false);
     $statuses = Plugins::filter('admin_publish_list_comment_statuses', $statuses);
     $settings->append(FormControlLabel::wrap(_t('Status'), FormControlSelect::create('comment_status')->set_options($statuses)->set_value($comment->status)));
     // // Create the stats
     // $comment_controls->append('fieldset', 'stats_tab', _t('Stats'));
     // $stats = $form->stats_tab->append('wrapper', 'tags_buttons');
     // $stats->class = 'container';
     //
     // $stats->append('static', 'post_count', '<div class="container"><p class="pct25">'._t('Comments on this post:').'</p><p><strong>' . Comments::count_by_id($comment->post->id) . '</strong></p></div><hr />');
     // $stats->append('static', 'ip_count', '<div class="container"><p class="pct25">'._t('Comments from this IP:').'</p><p><strong>' . Comments::count_by_ip($comment->ip) . '</strong></p></div><hr />');
     // $stats->append('static', 'email_count', '<div class="container"><p class="pct25">'._t('Comments by this author:').'</p><p><strong>' . Comments::count_by_email($comment->email) . '</strong></p></div><hr />');
     // $stats->append('static', 'url_count', '<div class="container"><p class="pct25">'._t('Comments with this URL:').'</p><p><strong>' . Comments::count_by_url($comment->url) . '</strong></p></div><hr />');
     // Create the second set of action buttons
     $buttons_2 = $form->append(FormControlWrapper::create('buttons_2', null, array('class' => array('container', 'buttons', 'comment'))));
     foreach ($actions as $status => $action) {
         $id = $action . '_2';
         $buttons_2->append(FormControlSubmit::create($id, null, array('class' => array('status', 'button', $action)))->set_caption(MUltiByte::ucfirst(_t($action))));
         if (Comment::status_name($comment->status) == $status) {
             $buttons_2->{$id}->add_class('active');
             $buttons_2->{$id}->set_properties(array('disabled' => true));
         } else {
             $buttons_2->{$id}->set_properties(array('disabled' => false));
         }
     }
     // Allow plugins to alter form
     Plugins::act('form_comment_edit', $form, $comment);
     return $form;
 }
Ejemplo n.º 2
0
 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);
     });
 }
Ejemplo n.º 3
0
 /**
  * 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');
 }
Ejemplo n.º 4
0
    /**
     * Take an array of parameters, use the first as the FormControl class/type, and run the constructor with the rest
     * @param array $arglist The array of arguments
     * @throws \Exception When the requested type is invalid
     * @return FormControl The created control.
     */
    public static function from_args($arglist)
    {
        $arglist = array_pad($arglist, 6, null);
        list($type, $name, $storage, $properties, $settings) = $arglist;
        if (class_exists('\\Habari\\FormControl' . ucwords($type))) {
            $type = '\\Habari\\FormControl' . ucwords($type);
        }
        if (!class_exists($type)) {
            throw new \Exception(_t('The FormControl type "%s" is invalid.', array($type)));
        }
        if (is_null($properties)) {
            $properties = array();
        }
        if (is_null($settings)) {
            $settings = array();
        }
        if (is_string($properties)) {
            $bt = debug_backtrace(false, 4);
            $x = reset($bt);
            while ($x['function'] != 'append' && count($bt) > 0) {
                array_shift($bt);
                $x = reset($bt);
            }
            $params = implode("\n\t", $arglist);
            $err = <<<ERR
<div class="error">Fixup for {$x['file']}[{$x['line']}]:<br/><code style="font-family:monospace;color:#c00;">{$type}::create('{$name}', '{$storage}')->label('{$properties}');</code></div>
\t<!-- {$params} -->
ERR;
            return FormControlStatic::create(uniqid('fc', true))->set_static($err);
        }
        return new $type($name, $storage, $properties, $settings);
    }
Ejemplo n.º 5
0
 /**
  * Returns a form for editing this post
  * @param string $context The context the form is being created in, most often 'admin'
  * @return FormUI A form appropriate for creating and updating this post.
  */
 public function get_form($context)
 {
     /** @var FormUI $form  */
     $form = new FormUI('create-content', null, array('class' => array('create')));
     $form->set_wrap_each('<div class="container">%s</div>');
     $newpost = 0 === $this->id;
     // If the post has already been saved, add a link to its permalink
     if (!$newpost) {
         /** @var FormControlWrapper $post_links  */
         $post_links = $form->append(FormControlWrapper::create('post_links', null, array('class' => 'container')));
         $permalink = $this->status != Post::status('published') ? $this->permalink . '?preview=1' : $this->permalink;
         $post_links->append(FormControlStatic::create('post_permalink')->set_static('<a href="' . $permalink . '" class="viewpost" >' . ($this->status != Post::status('published') ? _t('Preview Post') : _t('View Post')) . '</a>'));
     }
     // Store this post instance into a hidden field for later use when saving data
     $form->append(FormControlData::create('post')->set_value($this));
     // Create the Title field
     $form->append(FormControlLabel::wrap(_t('Title'), FormControlText::create('title', null, array('class' => array('check-change full-width')))->set_value($this->title_internal)));
     // Create the silos
     if (count(Plugins::get_by_interface('MediaSilo'))) {
         $silos = FormControlSilos::create('silos')->set_setting('wrap', '<div class="container silos">%s</div>');
         $form->append($silos);
     }
     // Create the Content field
     $form->append(FormControlLabel::wrap(_t('Content'), FormControlTextArea::create('content', null, array('class' => array('resizable', 'check-change full-width rte')))->set_value($this->content_internal)));
     $form->content->raw = true;
     // @todo What does this do?
     // Create the tags field
     /** @var FormControlAutocomplete $tags_control */
     $form->append(FormControlLabel::wrap(_t('Tags, separated by, commas'), $tags_control = FormControlAutocomplete::create('tags', null, array('style' => 'width:100%;margin:0px 0px 20px;', 'class' => 'check-change full-width'), array('allow_new' => true, 'init_selection' => true)))->set_properties(array('style' => 'width:100%;margin:0px 0px 20px;')));
     $tags = (array) $this->get_tags();
     array_walk($tags, function (&$element, $key) {
         $element->term_display = MultiByte::strpos($element->term_display, ',') === false ? $element->term_display : $element->tag_text_searchable;
     });
     $tags_control->set_value(implode(',', $tags));
     $tags_control->set_ajax(URL::auth_ajax('tag_list'));
     // Create the splitter
     /** @var FormControlTabs $publish_controls  */
     $publish_controls = $form->append(FormControlTabs::create('publish_controls')->set_setting('wrap', '%s')->set_setting('class_each', 'container'));
     // Create the publishing controls
     // pass "false" to list_post_statuses() so that we don't include internal post statuses
     $statuses = Post::list_post_statuses($this);
     unset($statuses[array_search('any', $statuses)]);
     $statuses = Plugins::filter('admin_publish_list_post_statuses', $statuses);
     /** @var FormControlFieldset $settings */
     $settings = $publish_controls->append(FormControlFieldset::create('post_settings')->set_caption(_t('Settings')));
     $settings->append(FormControlLabel::wrap(_t('Content State'), FormControlSelect::create('status')->set_options(array_flip($statuses))->set_value($this->status)));
     // hide the minor edit checkbox if the post is new
     if ($newpost) {
         $settings->append(FormControlData::create('minor_edit')->set_value(false));
     } else {
         $settings->append(FormControlLabel::wrap(_t('Minor Edit'), FormControlCheckbox::create('minor_edit')->set_value(true)));
         $form->append(FormControlData::create('modified')->set_value($this->modified));
     }
     $settings->append(FormControlLabel::wrap(_t('Comments Allowed'), FormControlCheckbox::create('comments_enabled')->set_value($this->info->comments_disabled ? false : true)));
     $settings->append(FormControlLabel::wrap(_t('Publication Time'), FormControlText::create('pubdate')->set_value($this->pubdate->format('Y-m-d H:i:s'))));
     $settings->pubdate->set_helptext(_t('YYYY-MM-DD HH:MM:SS'));
     $settings->append(FormControlData::create('updated')->set_value($this->updated->int));
     $settings->append(FormControlLabel::wrap(_t('Content Address'), FormControlText::create('newslug')->set_value($this->slug)));
     // Create the button area
     $buttons = $form->append(FormControlFieldset::create('buttons', null, array('class' => array('container', 'buttons', 'publish'))));
     // What buttons should we have?
     $require_any = array('own_posts' => 'create', 'post_any' => 'create', 'post_' . Post::type_name($this->content_type) => 'create');
     $show_buttons = array();
     if ($newpost) {
         if (User::identify()->can_any($require_any)) {
             $show_buttons['save'] = true;
             $show_buttons['publish'] = true;
         }
     } else {
         if (ACL::access_check($this->get_access(), 'edit')) {
             if ($this->status == Post::status('draft')) {
                 $show_buttons['publish'] = true;
             }
             $show_buttons['save'] = true;
         }
         if (ACL::access_check($this->get_access(), 'delete')) {
             $show_buttons['delete'] = true;
         }
     }
     $show_buttons = Plugins::filter('publish_form_buttons', $show_buttons, $this);
     if (isset($show_buttons['delete'])) {
         // Create the Delete button
         $buttons->append(FormControlSubmit::create('delete', null, array('class' => 'three columns'))->set_caption(_t('Delete'))->on_success(array($this, 'form_publish_delete')));
     }
     if (isset($show_buttons['save'])) {
         // Create the Save button
         $buttons->append(FormControlSubmit::create('save', null, array('class' => 'three columns'))->set_caption(_t('Save')));
     }
     if (isset($show_buttons['publish'])) {
         // Create the Publish button
         $buttons->append(FormControlSubmit::create('publish', null, array('class' => 'three columns'))->set_caption(_t('Publish'))->add_validator(function ($value, FormControlSubmit $control, FormUI $form) {
             $form->status->set_value(Post::status('published'));
             $allow = Plugins::filter('post_publish_allow', true, $this);
             if (!$allow) {
                 return array('Publishing has been denied');
             }
             return array();
         }));
     }
     // Add required hidden controls
     $form->append(FormControlData::create('content_type', null, array('id' => 'content_type'))->set_value($this->content_type));
     $form->append(FormControlData::create('post_id', null, array('id' => 'id'))->set_value($this->id));
     $form->append(FormControlData::create('slug', null, array('id' => 'originalslug'))->set_value($this->slug));
     $form->on_success(array($this, 'form_publish_success'));
     // Let plugins alter this form
     Plugins::act('form_publish', $form, $this, $context);
     $content_types = array_flip(Post::list_active_post_types());
     Plugins::act('form_publish_' . Utils::slugify($content_types[$this->content_type], '_'), $form, $this, $context);
     // Return the form object
     return $form;
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }
Ejemplo n.º 7
0
 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();
 }
Ejemplo n.º 8
0
 /**
  * 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');
 }