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