Exemple #1
0
 /**
  * @covers Xoops\Form\Hidden::render
  */
 public function testRender()
 {
     $value = $this->object->render();
     $this->assertTrue(is_string($value));
     $this->assertTrue(false !== strpos($value, '<input'));
     $this->assertTrue(false !== strpos($value, 'type="hidden"'));
 }
Exemple #2
0
 public function testCompile()
 {
     $field = new Hidden("test", "Test");
     $expected = "<input type=\"hidden\" name=\"test\"  value=\"\" />";
     $value = $field->compile();
     $this->assertEquals($expected, $value);
 }
Exemple #3
0
 /**
  * Constructor
  *
  * Instantiate the CSRF input form element
  *
  * @param  string $name
  * @param  string $value
  * @param  string $indent
  * @param  int    $expire
  * @return Csrf
  */
 public function __construct($name, $value = null, $indent = null, $expire = 300)
 {
     // Start a session.
     if (session_id() == '') {
         session_start();
     }
     // If token does not exist, create one
     if (!isset($_SESSION['pop_csrf'])) {
         $this->token = ['value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time()];
         $_SESSION['pop_csrf'] = serialize($this->token);
         // Else, retrieve existing token
     } else {
         $this->token = unserialize($_SESSION['pop_csrf']);
         // Check to see if the token has expired
         if ($this->token['expire'] > 0) {
             if ($this->token['expire'] + $this->token['start'] < time()) {
                 $this->token = ['value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time()];
                 $_SESSION['pop_csrf'] = serialize($this->token);
             }
         }
     }
     parent::__construct($name, $this->token['value'], $indent);
     $this->setRequired(true);
     $this->setValidator();
 }
 public function __construct()
 {
     parent::__construct();
     $this->isRequired();
     $this->setValidator('NotEmpty');
     $this->initCsrfValidator();
 }
Exemple #5
0
 /**
  * This renders a File Upload Form with an APC Progress Bar.
  *
  * It uses the APC RFC1867 File Upload Progress Hook check.
  * The APC PROGRESS BAR will only work if
  * a) APC is active
  * b) apc.rfc1867 = 1
  * Watch out: This value can not be set by .htaccess, it's a PHP_INI_SYSTEM value.
  * You have to set this in php.ini.
  *
  * @see http://php.net/manual/de/apc.configuration.php
  */
 public function render()
 {
     // APC RFC1867 File Upload Progress Hook check
     if (ini_get('apc.rfc1867') === false) {
         echo 'No Upload with APC possible.';
     }
     /*
      * This javascript handler for fetching the json results array from apc_fetch method.
      * @see get-progress.php
      */
     $javascript = "<script type=\"text/javascript\"> //<![CDATA[\n\n                            \$(document).ready(function () {\n                                \$(\"#progressbar\").progressbar({ value: 0 });\n                            });\n\n                            function getUploadProgress(uniqueID)\n                            {\n                                var req;\n                                try {\n                                    req = window.XMLHttpRequest?new XMLHttpRequest():\n                                        new ActiveXObject(\"Microsoft.XMLHTTP\");\n                                } catch (e) {\n                                    // No AJAX Support\n                                }\n\n                                req.onreadystatechange = function () {\n                                    if ((req.readyState == 4) && (req.status == 200)) {\n                                        // evaluate the incomming json array\n                                        var status = eval('(' + req.responseText + ')');\n                                        // call updateDisplay and assign array\n                                        updateDisplay(status);\n                                    }\n                                }\n                                req.open('GET', 'get-progress.php?uniqueID='+uniqueID);\n                                req.send(null);\n                            }\n\n                            function updateDisplay(status)\n                            {\n                                var rate = parseInt(status['rate']/1024);\n                                if (status['cancel_upload']) {\n                                    txt='Upload was cancelled after '+resp['current']+' bytes!';\n                                } else {\n                                    txt=status['total']+' bytes uploaded!';\n                                }\n                                txt += '<br>Upload rate was '+rate+' kbps.';\n\n                                document.getElementById('upload_status').style.display = '';\n\n                                var percent = parseInt(100*(status['current']/status['total']));\n                                document.getElementById('uploadFile').innerHTML = status['filename'];\n                                document.getElementById('uploadSize').innerHTML =\n                                (parseInt(status['current'])/1024) + 'KB of ' + (parseInt(status['total'])/1024) + 'KB';\n                                document.getElementById('progressBar').style.width = ''+percent+'%';\n\n                                // jquery progress bar\n                                \$('#progressbar').progressbar('option', 'value', percent);\n\n                                // todo: cancel button, status['done'], status['total'], status['canceled']\n\n                                //document.getElementById('upload_status').innerHTML =  txt;\n\n                            }\n                            //]]></script>";
     // add an iframe, so that the upload happens in there and is not blocking the website
     $html = '<!-- Hidden iframe for performing the Upload -->' . CR . '
                  <iframe style="display:none" name="hidden_upload" src="' . WWW_ROOT . 'upload-file.php"></iframe>';
     // add ajax status (upload_status, uploadFile, uploadSize, progressBar)
     $html .= '<!-- Ajax Upload Status -->
                   <div id="progressbar"></div>
                   <div id="upload_status" style="display:none;">
                     Currently uploading <strong id="uploadFile"></strong><br>
                     <span id="uploadSize"></span><br>
                     <div style="width:600px; background:#CCCCCC;">
                         <div id="progressBar" style="background-color:#00CC66; width:0%;">&nbsp;</div>
                     </div>
                   </div>
                 ';
     /*
      * APC needs a hidden element
      * a) with a certain name
      * b) with a unique tracking id for the file
      * c) placed before the input file element.
      */
     $uniqueID = md5(uniqid(mt_rand(), true));
     $hidden = new Hidden();
     $html .= $hidden->setName('APC_UPLOAD_PROGRESS')->setID('upload_status')->setValue($uniqueID);
     // add the input element
     $html .= '<input name="uploadfile" size="30" type="file">';
     // add a submit button
     $submit = new Submitbutton();
     $submit->setValue(_('Upload File'));
     $submit->setAdditionalAttributeAsText('onclick="this.disabled=true;' . "setInterval('getUploadProgress(\\''+this.form.APC_UPLOAD_PROGRESS.value+'\\')', 750); \" ");
     $html .= $submit;
     return $javascript . $html;
 }
Exemple #6
0
    /**
     * Add map canvas
     *
     * @param \WP_Post $post
     * @return string
     */
    protected function get_field(\WP_Post $post)
    {
        $field = parent::get_field($post);
        $automatic = $this->original_callback ? ' original' : '';
        $geocder = $this->show_geocoder ? $this->geocoder() : '';
        return <<<HTML
            {$field}
            <div id="{$this->name}-map" class="wpametu-map{$automatic}"></div>
            {$geocder}
HTML;
    }
Exemple #7
0
 private function renderWidgetList($value, $choices, $attributes)
 {
     $name = $this->getAttribute('name');
     $flags = $this->getAttribute('flags');
     $hiddenWidget = new Hidden($this->view);
     $hiddenWidget->setAttribute('flags', $flags)->setAttribute('value', '')->setAttribute('class', 'Hidden')->setAttribute('name', $name);
     $contentWidget = new Literal($this->view);
     $contentWidget->setAttribute('data', $this->generateSelectorContentWidgetList($name, $value, $choices, $flags));
     $panelWidget = new Panel($this->view);
     $panelWidget->setAttribute('class', $attributes['class'])->setAttribute('name', $name)->insert($hiddenWidget)->insert($contentWidget);
     if ($this->getAttribute('flags') & \Nethgui\Renderer\WidgetFactoryInterface::LABEL_NONE) {
         return $panelWidget->renderContent();
     }
     $fieldsetWidget = new Fieldset($this->view);
     $fieldsetWidget->setAttribute('template', $this->getAttribute('label', $this->getTranslateClosure($name . '_label')))->setAttribute('flags', $this->getAttribute('flags'));
     if ($this->hasAttribute('icon-before')) {
         $fieldsetWidget->setAttribute('icon-before', $this->getAttribute('icon-before'));
     }
     $fieldsetWidget->insert($panelWidget);
     return $fieldsetWidget->renderContent();
 }
Exemple #8
0
 /**
  * Constructor
  *
  * @param string|array $name    name attribute or array of all attributes
  * @param integer      $timeout timeout in seconds for generated token
  */
 public function __construct($name = 'XOOPS_TOKEN', $timeout = 0)
 {
     if (is_array($name)) {
         parent::__construct($name);
     } else {
         parent::__construct([]);
         $this->set('name', $name);
         $this->set(':timeout', $timeout);
     }
     $name = $this->get('name', 'XOOPS_TOKEN');
     if (substr($name, -8) !== '_REQUEST') {
         $this->set('name', $name . '_REQUEST');
     }
     $this->set('value', \Xoops::getInstance()->security()->createToken($this->get(':timeout', 0), $name));
 }
Exemple #9
0
    /**
     * Display field with video selector
     */
    protected function display_field()
    {
        parent::display_field();
        wp_enqueue_media();
        $media_ids = array_filter(explode(',', $this->get_data(false)), function ($id) {
            return is_numeric($id);
        });
        ?>
		<div class="tscf__placeholder" data-limit="<?php 
        echo esc_attr($this->field['limit']);
        ?>
">
			<?php 
        foreach ($media_ids as $media_id) {
            ?>
				<div class="tscf__video">
					<div class="tscf__video">
						<video data-video-id="<?php 
            echo $media_id;
            ?>
" class="tscf__video--object" src="<?php 
            echo wp_get_attachment_url($media_id);
            ?>
" />
					</div>
					<a class="button tscf__video--delete" href="#"><?php 
            $this->_e('Delete');
            ?>
</a>
				</div>
			<?php 
        }
        ?>
			<div class="tscf__placeholder--limit"><?php 
        $this->_e('You can select %d images.', $this->field['limit']);
        ?>
</div>
		</div>
		<a class="button tscf__video--add" href="#"><?php 
        $this->_e('Select or Upload');
        ?>
</a>
		<?php 
    }
Exemple #10
0
    private function getHiddenField()
    {
        $hidden = new Hidden($this->getName());
        $hidden->setValue($this->getForm()->getValue($this->getName()));
        $hidden->set("id", $this->getName());
        $script = <<<EOP
<script type="text/javascript">
updateSelectTimeFields("{$this->getName()}");
</script>
EOP;
        return $hidden . $script;
    }
Exemple #11
0
 /**
  * @param string $name
  * @param string $value
  */
 public function __construct(string $name, string $value = null)
 {
     parent::__construct($name, $value);
     $this->setRenderable(false);
 }
Exemple #12
0
 /**
  * Add a hidden input field to the form collection.
  *
  * Hidden fields can be used for example to inject custom values in your post data and still have
  * them validated using ValidForm Builder.
  *
  * @param string $name The hidden field's `name` attribute
  * @param string $type Define a validation type using one of the `ValidForm::VFORM_` constants. This does **not**
  * influence the fact that you're creating a hidden field. This is only used for validation of the hidden field's
  * content.
  * @param array $meta Optional meta array
  * @param boolean $blnJustRender If true, only create a {@link \ValidFormBuilder\Hidden} instance and return it.
  * When false, this {@link \ValidFormBuilder\Hidden} instance is added to the internal `elements` collection
  * and will be parsed when `toHtml()` is called.
  *
  * @return \ValidFormBuilder\Hidden
  */
 public function addHiddenField($name, $type, $meta = array(), $blnJustRender = false)
 {
     $objField = new Hidden($name, $type, $meta);
     if (!$blnJustRender) {
         // *** Fieldset already defined?
         $objFieldset = $this->__elements->getLast("ValidFormBuilder\\Fieldset");
         if ($this->__elements->count() == 0 || !is_object($objFieldset)) {
             $objFieldset = $this->addFieldset();
         }
         $objField->setMeta("parent", $objFieldset, true);
         // *** Add field to the fieldset.
         $objFieldset->addField($objField);
     }
     return $objField;
 }
 public function testInput()
 {
     $hidden = new Hidden(['name' => "name", 'value' => "Valor"]);
     $this->assertEquals($hidden->render(), '<div><input value="Valor" name="name" type="hidden" /></div>');
 }
Exemple #14
0
 /**
  * Create instance
  *
  * @param string $name The name of the field
  * @param array  $data The data to construct the field
  */
 public function __construct($name, array $data)
 {
     parent::__construct($name, $data);
 }
Exemple #15
0
 /**
  * @covers Xoops\Form\Hidden::__construct
  * @covers Xoops\Form\Hidden::render
  */
 public function test__construct()
 {
     $oldWay = new Hidden('myname', 'myvalue');
     $newWay = new Hidden(['name' => 'myname', 'value' => 'myvalue']);
     $this->assertEquals($oldWay->render(), $newWay->render());
 }
 private function addDraggableTranslationEditor($label_name, $label_value)
 {
     $label_input = new TextArea($this->form);
     $label_input->setAutoHeight();
     $label_input->setValue(str_replace("\\'", "'", $label_value));
     $label_input->setName("TextArea_" . $label_name)->setWidth(320);
     // Saved position of the label when dragged
     $hdn_label = new Hidden($this->form, "Hdn_Position_" . $label_name);
     $hdn_label->setValue(sizeof($this->array_translation_position) + 1);
     $this->array_translation_position[$label_name] = $hdn_label;
     // Create draggable label object
     $translate_obj = new Object();
     $translate_obj->setWidth(588)->setId("Draggable_" . $label_name);
     $pic_drag = new Picture("wsp/img/drag_arrow_16x16.png", 16, 16, 0, Picture::ALIGN_ABSMIDDLE);
     $pic_drag->setStyle("cursor:pointer;");
     $label_obj = new Object($pic_drag, $label_name . ":&nbsp;");
     $label_obj->setWidth(250)->setStyle("float: left;");
     $translate_obj->add($label_obj, $hdn_label, $label_input);
     if (!$this->btn_save->isClicked() && !$this->sort_label_event->isSorted() && !$this->btn_add_label->isClicked()) {
         $this->translate_area->add($translate_obj);
     }
     $this->array_translation_input[$label_name] = $label_input;
 }
Exemple #17
0
 public function getCheckboxesHidden()
 {
     $val = "";
     foreach ($this->checkboxes as $checkbox) {
         $val .= $checkbox->getName() . ";";
     }
     $hidden = new Hidden("_checkboxes");
     $hidden->setValue($val);
     return $hidden;
 }
Exemple #18
0
 public static function hidden($text, $value, array $attributes = array())
 {
     $control = new Hidden($text, $value, $attributes);
     $control->setEscaper(self::$escaper);
     echo $control->render();
 }
 protected function renderElement()
 {
     $html = array();
     if (empty($this->uploaded_file)) {
         $attr = array('name' => $this->name, 'id' => $this->getDOMId(), 'class' => 'form-control');
         $html[] = '	<input type="file" ' . $this->serialiseAttributes($attr) . '/>';
     } else {
         $hidden = new Hidden($this->name, $this->label);
         $hidden->setValue($this->uploaded_file . '||' . $this->filename);
         $html[] = $hidden->render();
         $html[] = '	<label>' . $this->label . '</label>';
         $html[] = '	<p class="form-control-static">';
         $html[] = '		' . System::getLanguage()->_('MessageFileAlreadySelected');
         $html[] = '	</p>';
     }
     return implode("\n", $html);
 }
 /**
  * @covers Hidden::toString
  */
 public function testToString()
 {
     $hidden = new \Hidden("sensors");
     $this->assertEmpty($hidden->toString());
 }
 /**
  * Method render
  * @access public
  * @return mixed
  * @since 1.2.10
  */
 public function render()
 {
     $paypal_obj = new Object();
     $this->form->setAction($this->is_sandbox ? PaypalBuyButton::PAYPAL_SANDBOX_URL : PaypalBuyButton::PAYPAL_PROD_URL);
     $this->form->onSubmitJs("");
     $amount = new Hidden($this->form);
     $amount->setNotWspObjectName("amount")->setValue($this->amount);
     // HT amount
     $currency_code = new Hidden($this->form);
     $currency_code->setNotWspObjectName("currency_code")->setValue($this->currency_code);
     // Currency
     $shipping = new Hidden($this->form);
     $shipping->setNotWspObjectName("shipping")->setValue($this->shipping);
     // frais de transport
     $tax = new Hidden($this->form);
     if ($this->vat_amount > 0) {
         $tax->setNotWspObjectName("tax")->setValue($this->vat_amount);
     }
     $return = new Hidden($this->form);
     $return->setNotWspObjectName("return")->setValue($this->return_url);
     $cancel_return = new Hidden($this->form);
     $cancel_return->setNotWspObjectName("cancel_return")->setValue($this->cancel_url);
     $notify_url = new Hidden($this->form);
     $notify_url->setNotWspObjectName("notify_url")->setValue($this->notify_url);
     $cmd = new Hidden($this->form);
     $cmd->setNotWspObjectName("cmd")->setValue("_xclick");
     $business = new Hidden($this->form);
     $business->setNotWspObjectName("business")->setValue($this->business_paypal_account);
     $item_name = new Hidden($this->form);
     $item_name->setNotWspObjectName("item_name")->setValue($this->item_name);
     $no_note = new Hidden($this->form);
     $no_note->setNotWspObjectName("no_note")->setValue(1);
     $lc = new Hidden($this->form);
     $lc->setNotWspObjectName("lc")->setValue($this->getPage()->getLanguage());
     $bn = new Hidden($this->form);
     $bn->setNotWspObjectName("bn")->setValue("PP-BuyNowBF");
     $charset = new Hidden($this->form);
     $charset->setNotWspObjectName("charset")->setValue("utf-8");
     $custom = new Hidden($this->form);
     $custom->setNotWspObjectName("custom")->setValue($this->command_number);
     $paypal_obj->add($this->buy_btn);
     $paypal_obj->add($amount, $currency_code, $shipping, $tax, $return, $cancel_return, $notify_url, $cmd, $business, $item_name, $no_note, $lc, $bn, $charset, $custom);
     $this->form->setContent($paypal_obj);
     return $this->form->render();
 }
Exemple #22
0
 /** @test */
 public function it_passses_the_label_as_value()
 {
     $field = new Hidden('test', 'test');
     $field->render();
     $this->assertSame('test', $field->getValue());
 }
Exemple #23
0
 /**
  * Constructor
  *
  * @param string  $name    name
  * @param integer $timeout timeout in seconds for generated token
  */
 public function __construct($name = 'XOOPS_TOKEN', $timeout = 0)
 {
     $xoops = \Xoops::getInstance();
     parent::__construct($name . '_REQUEST', $xoops->security()->createToken($timeout, $name));
 }