/** * 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; }
/** * 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(); }
/** * Produce the control for display * @param Theme $theme The theme that will be used to render the template * @return string The output of the template */ public function get(Theme $theme) { $this->vars['terms'] = $this->value; $this->settings['ignore_name'] = true; $this->settings['internal_value'] = true; $this->add_class('tree_control'); $this->get_id(); return parent::get($theme); }
/** * 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 get(Theme $theme) { $checkboxes = $this->options; $control = $this; if (!is_array($control->value)) { $control->value = array(); } array_walk($checkboxes, function (&$item, $key) use($control) { $item = array('label' => Utils::htmlspecialchars($item), 'id' => Utils::slugify($control->get_id() . '-' . $key), 'checked' => in_array($key, $control->value) ? 'checked="checked"' : ''); }); $this->vars['checkboxes'] = $checkboxes; $this->settings['ignore_name'] = true; return parent::get($theme); }
/** * Manipulate the controls on the publish page for Addons * * @todo fix tab indexes * @todo remove settings tab without breaking everything in it? * * @param FormUI $form The form that is used on the publish page * @param Post $post The post that's being edited */ private function form_publish_addon($form, $post) { // remove the settings pane from the publish controls for non-admin users, we don't want anyone editing that if (User::identify()->can('superuser') == false) { $form->publish_controls->remove($form->publish_controls->settings); } // add guid after title $guid = $form->append(FormControlText::create('guid', new ControlStorage(function ($name) use($post) { return $post->info->guid; }, function ($name, $value) use($post) { $post->info->guid = $value; }))->label(_t('GUID', 'addon_catalog'))); $form->move_after($guid, $form->label_for_title); // position it after the title // add the description after the guid $description = $form->append(FormControlTextArea::create('description', $post, array('rows' => 2))->label(_t('Description', 'addon_catalog'))); $form->move_after($description, $guid); // add the instructions after the content $instructions = $form->append(FormControlTextArea::create('instructions')->add_class('resizable')->set_properties(array('rows' => 4))->label(_t('Instructions', 'addon_catalog'))); $form->move_after($instructions, $form->label_for_content); // position it after the content box // create the addon details wrapper pane $addon_fields = $form->append(FormControlFieldset::create('addon_details')->set_caption(_t('Details', 'addon_catalog'))); $form->move_after($addon_fields, $form->label_for_tags); // add the type: plugin or theme $details_type = $addon_fields->append(FormControlSelect::create('type', $post)->set_options($this->_types)->add_validator('validate_required')->label(_t('Addon Type', 'addon_catalog'))); // add the url $details_url = $addon_fields->append(FormControlText::create('url', $post)->label(_t('URL', 'addon_catalog'))); // add the screenshot $details_screenshot = $addon_fields->append(FormControlText::create('screenshot_url', $post)->label(_t('Screenshot', 'addon_catalog'))); }
/** * Magic __get method for returning property values * Override the handling of the value property to properly return the setting of the checkbox. * * @param string $name The name of the property * @return mixed The value of the requested property */ public function __get( $name ) { static $posted = null; switch ( $name ) { case 'value': if ( isset( $_POST[$this->field . '_submitted'] ) ) { if(!isset($posted)) { $valuesj = $_POST->raw( $this->field . '_submitted'); $values = json_decode($valuesj); $terms = array(); foreach($this->get_default() as $term) { $terms[$term->id] = $term; } foreach($values as $value) { $terms[$value->id]->mptt_left = $value->left; $terms[$value->id]->mptt_right = $value->right; } $terms = new Terms($terms); $posted = $terms->tree_sort(); } return $posted; } else { return $this->get_default(); } } return parent::__get( $name ); }
/** * Magic __get method for returning property values * Override the handling of the value property to properly return the setting of the checkbox. * * @param string $name The name of the property * @return mixed The value of the requested property */ public function __get($name) { switch ($name) { case 'value': if (isset($_POST[$this->field . '_submitted'])) { if (isset($_POST[$this->field])) { return $_POST[$this->field]; } else { return array(); } } else { return $this->get_default(); } } return parent::__get($name); }
/** * 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; }
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(); }