Пример #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;
 }
	public function action_form_publish( $form, $post, $context )
	{
		$old = $form->get_control( 'tags' );
		$tags = $old->value;
		$new = FormControlText::create('tags', null, array( 'style' => 'width:90%;', 'class' => 'check-change', 'id' => 'tags', 'tabindex' => $old->properties['tabindex'] ) );
		$new->set_value( $tags );
		$old->container->append( $new );
		$old->container->replace( $old, $new );
	}
Пример #3
0
 public function configure()
 {
     $form = new FormUI('lipsum');
     // $form->set_settings( array( 'use_session_errors' => true ) );
     $form->append(FormControlText::create('num_posts', 'option:lipsum__num_posts')->add_validator('validate_lipsum_numbers')->label(_t('Number of posts to have present:', __CLASS__)));
     $form->append(FormControlText::create('num_comments', 'option:lipsum__num_comments')->add_validator('validate_lipsum_numbers')->label(_t('Max number of comments for each post:', __CLASS__)));
     $form->append(FormControlText::create('num_tags', 'option:lipsum__num_tags')->add_validator('validate_lipsum_numbers')->label(_t('Max number of tags for each post:', __CLASS__)));
     $form->append(FormControlSubmit::create('save')->set_caption('Save'));
     $form->on_success(array($this, 'updated_config'));
     echo $form->get();
 }
Пример #4
0
 public function __construct()
 {
     $self = $this;
     FormUI::register('add_group', function (FormUI $form, $name) use($self) {
         $form->set_settings(array('use_session_errors' => true));
         $form->append(FormControlText::create('groupname')->add_validator('validate_required', _t('The group must have a name'))->add_validator('validate_groupname')->label(_t('Group Name'))->add_class('incontent')->set_template('control.label.outsideleft'));
         $form->append(FormControlSubmit::create('newgroup')->set_caption('Add Group'));
         $form->add_validator(array($self, 'validate_add_group'));
         $form->on_success(array($self, 'do_add_group'));
     });
     parent::__construct();
 }
Пример #5
0
 /**
  * Handle GET requests for /admin/tags to display the tags.
  */
 public function get_tags()
 {
     $this->theme->wsse = Utils::WSSE();
     $this->theme->tags = Tags::vocabulary()->get_tree('term_display asc');
     $this->theme->max = Tags::vocabulary()->max_count();
     $this->theme->min = Tags::vocabulary()->min_count();
     $form = new FormUI('tags');
     $form->append(FormControlFacet::create('search')->set_property('data-facet-config', array('onsearch' => 'deselect_all(); $("#tag_collection").manager("update", self.data("visualsearch").searchQuery.facets());', 'facetsURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'tags', 'component' => 'facets')), 'valuesURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'tags', 'component' => 'values')))));
     $aggregate = FormControlAggregate::create('selected_items')->set_selector("#tag_collection input")->label('0 Selected');
     $aggr_wrap = FormControlWrapper::create('tag_controls_aggregate')->add_class('aggregate_wrapper');
     $aggr_wrap->append($aggregate);
     $delete = FormControlDropbutton::create('delete_dropbutton');
     $delete->append(FormControlButton::create('action')->set_caption(_t('Delete selected'))->set_properties(array('title' => _t('Delete selected'), 'value' => 'delete')));
     $rename_text = FormControlText::create('rename_text');
     $rename = FormControlDropbutton::create('rename_dropbutton');
     $rename->append(FormControlButton::create('action')->set_caption(_t('Rename selected'))->set_properties(array('title' => _t('Rename selected'), 'value' => 'rename')));
     $tag_controls = $form->append(FormControlWrapper::create('tag_controls'))->add_class("container tag_controls");
     $tag_controls->append($aggr_wrap);
     $tag_controls->append($rename_text);
     $tag_controls->append($rename);
     $tag_controls->append($delete);
     $tag_controls->append(FormControlWrapper::create('selected_tags')->set_setting('wrap_element', 'ul')->set_property('id', 'selected_tags'));
     if (count($this->theme->tags) > 0) {
         $tag_collection = $form->append(FormControlWrapper::create('tag_collection')->add_class('container items')->set_setting('wrap_element', 'ul')->set_property('id', 'tag_collection'));
         $listitems = $this->get_tag_listitems();
         foreach ($listitems as $item) {
             $tag_collection->append($item);
         }
     } else {
         $tag_collection = $form->append(FormControlStatic::create('<p>' . _t('No tags could be found to match the query criteria.') . '</p>'));
     }
     $form->on_success(array($this, 'process_tags'));
     $this->theme->form = $form;
     Stack::add('admin_header_javascript', 'visualsearch');
     Stack::add('admin_header_javascript', 'manage-js');
     Stack::add('admin_stylesheet', 'visualsearch-css');
     Stack::add('admin_stylesheet', 'visualsearch-datauri-css');
     $this->display('tags');
 }
 /**
  * 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;
 }
Пример #7
0
	/**
	 * Magic function __get returns properties for this object, or passes it on to the parent class
	 * Potential valid properties:
	 * value: The value of the control, whether the default or submitted in the form
	 *
	 * @param string $name The paramter to retrieve
	 * @return mixed The value of the parameter
	 */
	public function __get( $name )
	{
		$default = $this->get_default();
		switch ( $name ) {
			case 'value':
				if ( isset( $_POST[$this->field] ) ) {
					if ( $_POST[$this->field] == substr( md5( $default ), 0, 8 ) ) {
						return $default;
					}
					else {
						return $_POST[$this->field];
					}
				}
				else {
					return $default;
				}
			default:
				return parent::__get( $name );
		}
	}
Пример #8
0
 /**
  * Implementation of menu_type_data filter, created by this plugin
  * @param array $menu_type_data Existing menu type data
  * @return array Updated menu type data
  */
 public function filter_menu_type_data($menu_type_data)
 {
     $menu_type_data['menu_link'] = array('label' => _t('Link', 'termmenus'), 'form' => function ($form, $term) {
         $link_name = new FormControlText('link_name', 'null:null', _t('Link Title', 'termmenus'));
         $link_name->add_validator('validate_required', _t('A name is required.', 'termmenus'));
         $link_url = new FormControlText('link_url', 'null:null', _t('Link URL', 'termmenus'));
         $link_url->add_validator('validate_required')->add_validator('validate_url', _t('You must supply a valid URL.', 'termmenus'));
         if ($term) {
             $link_name->value = $term->term_display;
             $link_url->value = $term->info->url;
             $form->append('hidden', 'term')->value = $term->id;
         }
         $form->append($link_name);
         $form->append($link_url);
     }, 'save' => function ($menu, $form) {
         if (!$form->term->value) {
             $term = new Term(array('term_display' => $form->link_name->value, 'term' => Utils::slugify($form->link_name->value)));
             $term->info->type = "link";
             $term->info->url = $form->link_url->value;
             $term->info->menu = $menu->id;
             $menu->add_term($term);
             $term->associate('menu_link', 0);
             Session::notice(_t('Link added.', 'termmenus'));
         } else {
             $term = Term::get(intval($form->term->value));
             $updated = false;
             if ($term->info->url !== $form->link_url->value) {
                 $term->info->url = $form->link_url->value;
                 $updated = true;
             }
             if ($form->link_name->value !== $term->term_display) {
                 $term->term_display = $form->link_name->value;
                 $term->term = Utils::slugify($form->link_name->value);
                 $updated = true;
             }
             $term->info->url = $form->link_url->value;
             if ($updated) {
                 $term->update();
                 Session::notice(_t('Link updated.', 'termmenus'));
             }
         }
     }, 'render' => function ($term, $object_id, $config) {
         $result = array('link' => $term->info->url);
         return $result;
     });
     $menu_type_data['menu_spacer'] = array('label' => _t('Spacer', 'termmenus'), 'form' => function ($form, $term) {
         $spacer = new FormControlText('spacer_text', 'null:null', _t('Item text', 'termmenus'), 'optionscontrol_text');
         $spacer->helptext = _t('Leave blank for blank space', 'termmenus');
         if ($term) {
             $spacer->value = $term->term_display;
             $form->append('hidden', 'term')->value = $term->id;
         }
         $form->append($spacer);
     }, 'save' => function ($menu, $form) {
         if (!$form->term->value) {
             $term = new Term(array('term_display' => $form->spacer_text->value !== '' ? $form->spacer_text->value : '&nbsp;', 'term' => Utils::slugify($form->spacer_text->value !== '' ? $form->spacer_text->value : 'menu_spacer')));
             $term->info->type = "spacer";
             $term->info->menu = $menu->id;
             $menu->add_term($term);
             $term->associate('menu_spacer', 0);
             Session::notice(_t('Spacer added.', 'termmenus'));
         } else {
             $term = Term::get(intval($form->term->value));
             if ($form->spacer_text->value !== $term->term_display) {
                 $term->term_display = $form->spacer_text->value;
                 $term->update();
                 Session::notice(_t('Spacer updated.', 'termmenus'));
             }
         }
     });
     $menu_type_data['post'] = array('label' => _t('Links to Posts', 'termmenus'), 'form' => function ($form, $term) {
         if ($term) {
             $object_types = $term->object_types();
             $term_object = reset($object_types);
             $post_display = $form->append('text', 'term_display', 'null:null', _t('Title to display', 'termmenus'));
             $post_display->value = $term->term_display;
             $post_display->disabled = 'disabled';
             $post = Post::get($term_object->object_id);
             $post_term = $form->append('static', 'post_link', _t("Links to <a target='_blank' href='{$post->permalink}'>{$post->title}</a>", 'termmenus'));
             $form->append('hidden', 'term')->value = $term->id;
         } else {
             $post_ids = $form->append('text', 'post_ids', 'null:null', _t('Posts', 'termmenus'));
             $post_ids->template = 'text_tokens';
             $post_ids->ready_function = "\$('#{$post_ids->field}').tokenInput( habari.url.ajaxPostTokens )";
         }
     }, 'save' => function ($menu, $form) {
         if (!$form->term->value) {
             $post_ids = explode(',', $form->post_ids->value);
             foreach ($post_ids as $post_id) {
                 $post = Post::get(array('id' => $post_id));
                 $term_title = $post->title;
                 $terms = $menu->get_object_terms('post', $post->id);
                 if (count($terms) == 0) {
                     $term = new Term(array('term_display' => $post->title, 'term' => $post->slug));
                     $term->info->menu = $menu->id;
                     $menu->add_term($term);
                     $menu->set_object_terms('post', $post->id, array($term->term));
                 }
             }
             Session::notice(_t('Link(s) added.', 'termmenus'));
         } else {
             $term = Term::get(intval($form->term->value));
             if ($form->term_display->value !== $term->term_display) {
                 $term->term_display = $form->term_display->value;
                 $term->update();
                 Session::notice(_t('Link updated.', 'termmenus'));
             }
         }
     }, 'render' => function ($term, $object_id, $config) {
         $result = array();
         if ($post = Post::get($object_id)) {
             $result['link'] = $post->permalink;
         }
         return $result;
     });
     return $menu_type_data;
 }
Пример #9
0
 /**
  * Produce HTML output for this password control.
  *
  * @param Theme $theme The theme to use to render this control
  * @return string HTML for this control in the form
  */
 public function get(Theme $theme)
 {
     $this->vars['value'] = $this->value == '' ? '' : substr(md5($this->value), 0, 8);
     return parent::get($theme);
 }
Пример #10
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;
 }
Пример #11
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;
 }
Пример #12
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');
    }
Пример #13
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();
 }
Пример #14
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');
 }