/**
  * 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;
 }
Exemple #2
0
 /**
  * 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);
     });
 }
Exemple #4
0
 /**
  * Shortcut to wrap this control in a label
  * @param string $label The caption of the label
  * @return FormControlLabel The label control is returned.  FYI, THIS BREAKS THE FLUENT INTERFACE.
  */
 public function label($label)
 {
     return FormControlLabel::wrap($label, $this);
 }
 /**
  * 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;
 }
 /**
  * Shortcut to wrap this control in a label
  * This version for this control defaults to use the control.label.outsideright template
  * @param string $label The caption of the label
  * @return FormControlLabel The label control is returned.  FYI, THIS BREAKS THE FLUENT INTERFACE.
  */
 public function label($label)
 {
     return FormControlLabel::wrap($label, $this)->set_template('control.label.outsideright');
 }
Exemple #7
0
 /**
  * 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;
 }
Exemple #8
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;
 }
Exemple #9
0
    /**
     * 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');
    }
Exemple #10
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();
 }
Exemple #11
0
 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');
 }