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