/**
  * Generates inline javascript containing element's defaults and (available) options
  *
  * @return   string
  */
 private function _generateInlineScript()
 {
     // we store values and options with id of first select rather than with
     // the element's name since the former has more chances to be unique
     $selectId = reset($this->elements)->getId();
     $cr = HTML_Common2::getOption('linebreak');
     $js = "qf.elements.hierselect.defaults['{$selectId}'] = " . HTML_QuickForm2_JavascriptBuilder::encode($this->_values) . ";{$cr}";
     $jsParts = array();
     for ($i = 1; $i < count($this->options); $i++) {
         $jsParts[] = empty($this->options[$i]) ? '{}' : HTML_QuickForm2_JavascriptBuilder::encode($this->_prepareOptions($this->options[$i], $i));
     }
     $js .= "qf.elements.hierselect.options['{$selectId}'] = [{$cr}" . implode(",{$cr}", $jsParts) . "{$cr}];";
     return $js;
 }
 * @author   Bertrand Mansion <*****@*****.**>
 * @license  http://opensource.org/licenses/bsd-license.php New BSD License
 * @link     http://pear.php.net/package/HTML_QuickForm2
 */
/**
 * HTML_Common2 - base class for HTML elements
 */
require_once 'HTML/Common2.php';
// By default, we generate element IDs with numeric indexes appended even for
// elements with unique names. If you want IDs to be equal to the element
// names by default, set this configuration option to false.
if (null === HTML_Common2::getOption('id_force_append_index')) {
    HTML_Common2::setOption('id_force_append_index', true);
}
// set the default language for various elements' messages
if (null === HTML_Common2::getOption('language')) {
    HTML_Common2::setOption('language', 'en');
}
/**
 * Exception classes for HTML_QuickForm2
 */
require_once 'HTML/QuickForm2/Exception.php';
/**
 * Static factory class for QuickForm2 elements
 */
require_once 'HTML/QuickForm2/Factory.php';
/**
 * Base class for HTML_QuickForm2 rules
 */
require_once 'HTML/QuickForm2/Rule.php';
/**
Exemple #3
0
 public static function _renderFieldset(HTML_QuickForm2_Renderer $renderer, HTML_QuickForm2_Container_Fieldset $fieldset)
 {
     $break = HTML_Common2::getOption('linebreak');
     $html[] = '<fieldset' . $fieldset->getAttributes(true) . '>';
     $label = $fieldset->getLabel();
     if (!empty($label)) {
         $html[] = sprintf('<legend id="%s-legend">%s</legend>', $fieldset->getId(), $label);
     }
     $elements = array_pop($renderer->html);
     $html[] = implode($break, $elements);
     $html[] = '</fieldset>';
     return implode($break, $html) . $break;
 }
 public function __toString()
 {
     require_once 'HTML/QuickForm2/Renderer.php';
     $cr = HTML_Common2::getOption('linebreak');
     return $this->render(HTML_QuickForm2_Renderer::factory('default')->setTemplateForId($this->getId(), '{content}'))->__toString() . "<script type=\"text/javascript\">{$cr}//<![CDATA[{$cr}" . $this->_generateInitScript() . "{$cr}//]]>{$cr}</script>";
 }
Exemple #5
0
 /**
  * Finishes rendering a form, called after processing contained elements
  *
  * @param    HTML_QuickForm2_Node    Form being rendered
  */
 public function finishForm(HTML_QuickForm2_Node $form)
 {
     $formTpl = str_replace(array('{attributes}', '{hidden}', '{errors}'), array($form->getAttributes(true), $this->hiddenHtml, $this->outputGroupedErrors()), $this->findTemplate($form, '{content}'));
     $this->hiddenHtml = '';
     // required note
     if (!$this->hasRequired || $form->toggleFrozen() || empty($this->options['required_note'])) {
         $formTpl = preg_replace('!<qf:reqnote>.*</qf:reqnote>!isU', '', $formTpl);
     } else {
         $formTpl = str_replace(array('<qf:reqnote>', '</qf:reqnote>', '{reqnote}'), array('', '', $this->options['required_note']), $formTpl);
     }
     $break = HTML_Common2::getOption('linebreak');
     $script = $this->getJavascriptBuilder()->getFormJavascript($form->getId());
     $this->html[0] = array(str_replace('{content}', $break . implode($break, $this->html[0]), $formTpl) . (empty($script) ? '' : $break . $script));
 }
Exemple #6
0
 /**
  * Returns the element's content wrapped in <script></script> tags
  *
  * @return string
  */
 public function __toString()
 {
     $cr = HTML_Common2::getOption('linebreak');
     return "<script type=\"text/javascript\">{$cr}//<![CDATA[{$cr}" . $this->data['content'] . "{$cr}//]]>{$cr}</script>";
 }
 public function testAnyOptionAllowed()
 {
     HTML_Common2::setOption('foobar', 'baz');
     $this->assertEquals('baz', HTML_Common2::getOption('foobar'));
 }
Exemple #8
0
 * @category   HTML
 * @package    HTML_QuickForm2
 * @author     Alexey Borzov <*****@*****.**>
 * @author     Bertrand Mansion <*****@*****.**>
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
 * @version    SVN: $Id: Node.php 306085 2010-12-08 19:43:59Z avb $
 * @link       http://pear.php.net/package/HTML_QuickForm2
 */
/**
 * HTML_Common2 - base class for HTML elements
 */
require_once 'HTML/Common2.php';
// By default, we generate element IDs with numeric indexes appended even for
// elements with unique names. If you want IDs to be equal to the element
// names by default, set this configuration option to false.
if (null === HTML_Common2::getOption('id_force_append_index')) {
    HTML_Common2::setOption('id_force_append_index', true);
}
/**
 * Exception classes for HTML_QuickForm2
 */
require_once 'HTML/QuickForm2/Exception.php';
/**
 * Static factory class for QuickForm2 elements
 */
require_once 'HTML/QuickForm2/Factory.php';
/**
 * Base class for HTML_QuickForm2 rules
 */
require_once 'HTML/QuickForm2/Rule.php';
/**
Exemple #9
0
 public function __toString()
 {
     $prefix = $this->getIndent();
     if ($comment = $this->getComment()) {
         $prefix .= '<!-- ' . $comment . ' -->' . HTML_Common2::getOption('linebreak') . $this->getIndent();
     }
     if (!$this->tagName) {
         return $prefix . $this->getContent();
     } elseif ('' != $this->getContent()) {
         return $prefix . '<' . $this->tagName . $this->getAttributes(true) . '>' . $this->getContent() . '</' . $this->tagName . '>';
     } else {
         return $prefix . '<' . $this->tagName . $this->getAttributes(true) . ($this->forceClosingTag ? '></' . $this->tagName . '>' : ' />');
     }
 }
Exemple #10
0
 /**
  * Returns the default message(s) for the given ID and language
  *
  * If $langId is not given, language set via
  * <code>
  * HTML_Common2::setOption('language', '...');
  * </code>
  * will be used.
  *
  * @param    array   Message ID
  * @param    string  Language, will use the default if not given
  * @return   array|string|null
  */
 public function get(array $messageId, $langId = null)
 {
     if (empty($langId)) {
         $langId = HTML_Common2::getOption('language');
     }
     $key = array_shift($messageId);
     if (empty($this->messages[$key]) || empty($this->messages[$key][$langId])) {
         return null;
     }
     $message = $this->messages[$key][$langId];
     while (!empty($messageId)) {
         $key = array_shift($messageId);
         if (empty($message[$key])) {
             return null;
         }
         $message = $message[$key];
     }
     return $message;
 }