Example #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;
 }
 /**
  * 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')));
 }
Example #3
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;
 }
Example #4
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');
    }