/** * 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; }
/** * 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; }