public function __construct($attributes)
 {
     if (is_object($attributes)) {
         $attributes = (array) $attributes;
     }
     parent::__construct($attributes);
 }
 /**
  * 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;
 }
 public function testUniqueIdsGeneratedWithoutIndexes()
 {
     HTML_Common2::setOption('id_force_append_index', false);
     $this->testUniqueIdsGenerated();
 }
Beispiel #4
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 static function parseAttributes($attrString)
 {
     return parent::parseAttributes($attrString);
 }
 /**
  * Class constructor
  *
  * @param string       $name       Element name
  * @param string|array $attributes HTML attributes (either a string or an array)
  * @param array        $data       Element data (label, options used for element setup)
  */
 public function __construct($name = null, $attributes = null, array $data = array())
 {
     parent::__construct($attributes);
     $this->setName($name);
     // Autogenerating the id if not set on previous steps
     if ('' == $this->getId()) {
         $this->setId();
     }
     if (!empty($data)) {
         $this->data = array_merge($this->data, $data);
     }
 }
Beispiel #7
0
 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>";
 }
Beispiel #8
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));
 }
Beispiel #9
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>";
 }
Beispiel #10
0
 /**
  * Class constructor
  *
  * @param    string  Element name
  * @param    mixed   Attributes (either a string or an array)
  * @param    array   Element data (label, options and data used for element creation)
  */
 public function __construct($name = null, $attributes = null, $data = null)
 {
     parent::__construct($attributes);
     $this->setName($name);
     // Autogenerating the id if not set on previous steps
     if ('' == $this->getId()) {
         $this->setId();
     }
     if (!is_null($data)) {
         $this->data = $data;
     }
 }
 public function testAnyOptionAllowed()
 {
     HTML_Common2::setOption('foobar', 'baz');
     $this->assertEquals('baz', HTML_Common2::getOption('foobar'));
 }
Beispiel #12
0
<?php

/**
 * @package Am_Form
 */
if (!defined('INCLUDED_AMEMBER_CONFIG')) {
    die("Direct access to this location is not allowed");
}
HTML_Common2::setOption('charset', 'UTF-8');
/**
 * Adds the following functionality to QF2 forms:
 * - adds submit detecition
 * - adds init() method support
 * - adds JqueryValidation rendering
 */
class Am_Form extends HTML_QuickForm2
{
    protected $width;
    protected static $_usedIds = array();
    protected $prolog = null;
    protected $epilog = null;
    function __construct($id = null, $attributes = null, $method = 'post')
    {
        $this->addFilter(array(__CLASS__, '_trimArray'));
        if ($id === null) {
            $id = get_class($this);
        }
        $i = 0;
        $suggestId = $id;
        while (isset(self::$_usedIds[$suggestId])) {
            $suggestId = $id . '-' . ++$i;
Beispiel #13
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 . '>' : ' />');
     }
 }
Beispiel #14
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;
 }
 /**
  * Class constructor
  *
  * Sets the $config data from the primary config.php file as a class variable.
  *
  * @return    void
  */
 public function __construct()
 {
     $this->config =& get_config();
     // Added by Ivan Tcholakov, 20-JAN-2014.
     // Load additional configuration data for languages.
     $c = array();
     $config = array();
     if (file_exists(COMMONPATH . 'config/lang.php')) {
         require COMMONPATH . 'config/lang.php';
         $c = array_replace_recursive($c, $config);
         $config = array();
     }
     if (file_exists(COMMONPATH . 'config/' . ENVIRONMENT . '/lang.php')) {
         require COMMONPATH . 'config/' . ENVIRONMENT . '/lang.php';
         $c = array_replace_recursive($c, $config);
         $config = array();
     }
     if (file_exists(APPPATH . 'config/lang.php')) {
         require APPPATH . 'config/lang.php';
         $c = array_replace_recursive($c, $config);
         $config = array();
     }
     if (file_exists(APPPATH . 'config/' . ENVIRONMENT . '/lang.php')) {
         require APPPATH . 'config/' . ENVIRONMENT . '/lang.php';
         $c = array_replace_recursive($c, $config);
         $config = array();
     }
     $c['hide_default_uri_segment'] = !empty($c['hide_default_uri_segment']);
     $languages = isset($c['languages']) && is_array($c['languages']) ? $c['languages'] : array();
     foreach ($languages as $key => $value) {
         if (!isset($value['direction'])) {
             $languages[$key]['direction'] = 'ltr';
         }
         if (!isset($value['uri_segment'])) {
             $languages[$key]['uri_segment'] = $value['code'];
         }
     }
     $c['languages'] = $languages;
     $c['default_language'] = $this->config['language'];
     if (!isset($c['enabled_languages']) && !is_array($c['enabled_languages'])) {
         $c['enabled_languages'] = array($c['default_language']);
     }
     if (!in_array($c['default_language'], $c['enabled_languages'])) {
         $c['enabled_languages'][] = $c['default_language'];
     }
     $this->config = array_replace_recursive($this->config, $c);
     //
     global $DETECT_URL;
     // Set the base_url automatically if none was provided
     if (empty($this->config['base_url'])) {
         $this->set_item('base_url', $DETECT_URL['base_url']);
     } else {
         $this->set_item('base_url', http_build_url($this->config['base_url'], array('scheme' => $DETECT_URL['server_protocol'], 'port' => $DETECT_URL['port'])));
     }
     if (!defined('BASE_URL')) {
         define('BASE_URL', $this->add_slash($this->base_url()));
     }
     if (!defined('BASE_URI')) {
         define('BASE_URI', $DETECT_URL['base_uri']);
     }
     if (!defined('SERVER_URL')) {
         define('SERVER_URL', $this->add_slash(substr(BASE_URL, 0, strlen(BASE_URL) - strlen(BASE_URI))));
     }
     if (!defined('SITE_URL')) {
         define('SITE_URL', $this->add_slash($this->site_url()));
     }
     if (!defined('SITE_URI')) {
         define('SITE_URI', '/' . str_replace(SERVER_URL, '', SITE_URL));
     }
     if (!defined('CURRENT_URI')) {
         define('CURRENT_URI', $DETECT_URL['current_uri']);
     }
     if (!defined('CURRENT_URL')) {
         define('CURRENT_URL', rtrim(SERVER_URL, '/') . CURRENT_URI);
     }
     if (!defined('CURRENT_URL_IS_HTTPS')) {
         define('CURRENT_URL_IS_HTTPS', $DETECT_URL['is_https']);
     }
     if (!defined('CURRENT_URL_PROTOCOL')) {
         define('CURRENT_URL_PROTOCOL', $DETECT_URL['server_protocol']);
     }
     if (!defined('CURRENT_URL_HOST')) {
         define('CURRENT_URL_HOST', $DETECT_URL['server_name']);
     }
     if (!defined('CURRENT_URL_PORT')) {
         define('CURRENT_URL_PORT', $DETECT_URL['port']);
     }
     if (!defined('CURRENT_URI_STRING')) {
         define('CURRENT_URI_STRING', $DETECT_URL['current_uri_string']);
     }
     if (!defined('CURRENT_QUERY_STRING')) {
         define('CURRENT_QUERY_STRING', $DETECT_URL['current_query_string']);
     }
     // Added by Ivan Tcholakov, 13-JAN-2014.
     if (!defined('DEFAULT_BASE_URL')) {
         if (APPSEGMENT != '') {
             define('DEFAULT_BASE_URL', preg_replace('/' . preg_quote($this->add_slash(APPSEGMENT), '/') . '$/', '', BASE_URL));
         } else {
             define('DEFAULT_BASE_URL', BASE_URL);
         }
     }
     //
     // Added by Ivan Tcholakov, 13-JAN-2014.
     if (!defined('DEFAULT_BASE_URI')) {
         if (APPSEGMENT != '') {
             define('DEFAULT_BASE_URI', preg_replace('/' . preg_quote($this->add_slash(APPSEGMENT), '/') . '$/', '', BASE_URI));
         } else {
             define('DEFAULT_BASE_URI', BASE_URI);
         }
     }
     //
     // Added by Ivan Tcholakov, 26-DEC-2013.
     // See https://github.com/EllisLab/CodeIgniter/issues/2792
     if (!defined('IS_UTF8_CHARSET')) {
         define('IS_UTF8_CHARSET', strtolower($this->config['charset']) === 'utf-8');
     }
     //
     // Added by Ivan Tcholakov, 02-JAN-2016.
     HTML_Common2::setOption('charset', $this->config['charset']);
     //
     // Common Purpose File System Repositories
     $public_upload_path = $this->add_slash(isset($this->config['public_upload_path']) && $this->config['public_upload_path'] != '' ? $this->config['public_upload_path'] : DEFAULTFCPATH . 'upload/');
     $this->set_item('public_upload_path', $public_upload_path);
     if (!defined('PUBLIC_UPLOAD_PATH')) {
         define('PUBLIC_UPLOAD_PATH', $public_upload_path);
     }
     $public_upload_url = $this->add_slash(isset($this->config['public_upload_url']) && $this->config['public_upload_url'] != '' ? str_replace(array('{default_base_url}', '{base_url}'), array(DEFAULT_BASE_URL, BASE_URL), $this->config['public_upload_url']) : DEFAULT_BASE_URL . 'upload/');
     $this->set_item('public_upload_url', $public_upload_url);
     if (!defined('PUBLIC_UPLOAD_URL')) {
         define('PUBLIC_UPLOAD_URL', $public_upload_url);
     }
     $platform_upload_path = $this->add_slash(isset($this->config['platform_upload_path']) && $this->config['platform_upload_path'] != '' ? $this->config['platform_upload_path'] : PLATFORMPATH . 'upload/');
     $this->set_item('platform_upload_path', $platform_upload_path);
     if (!defined('PLATFORM_UPLOAD_PATH')) {
         define('PLATFORM_UPLOAD_PATH', $platform_upload_path);
     }
     // Assets
     $c = array();
     $config = array();
     if (file_exists(COMMONPATH . 'config/asset.php')) {
         require COMMONPATH . 'config/asset.php';
         $c = array_replace_recursive($c, $config);
         $config = array();
     }
     if (file_exists(COMMONPATH . 'config/' . ENVIRONMENT . '/asset.php')) {
         require COMMONPATH . 'config/' . ENVIRONMENT . '/asset.php';
         $c = array_replace_recursive($c, $config);
         $config = array();
     }
     if (file_exists(APPPATH . 'config/asset.php')) {
         require APPPATH . 'config/asset.php';
         $c = array_replace_recursive($c, $config);
         $config = array();
     }
     if (file_exists(APPPATH . 'config/' . ENVIRONMENT . '/asset.php')) {
         require APPPATH . 'config/' . ENVIRONMENT . '/asset.php';
         $c = array_replace_recursive($c, $config);
         $config = array();
     }
     if (!defined('ASSET_URL')) {
         define('ASSET_URL', $this->add_slash($c['asset_url']));
     }
     if (!defined('ASSET_URI')) {
         define('ASSET_URI', $this->add_slash($c['asset_dir']));
     }
     if (!defined('THEME_ASSET_URL')) {
         define('THEME_ASSET_URL', $this->add_slash($c['theme_asset_url']));
     }
     if (!defined('THEME_ASSET_URI')) {
         define('THEME_ASSET_URI', $this->add_slash($c['theme_asset_dir']));
     }
     if (!defined('ASSET_IMG_URL')) {
         define('ASSET_IMG_URL', ASSET_URL . $this->add_slash($c['asset_img_dir']));
     }
     if (!defined('ASSET_IMG_URI')) {
         define('ASSET_IMG_URI', ASSET_URI . $this->add_slash($c['asset_img_dir']));
     }
     if (!defined('ASSET_JS_URL')) {
         define('ASSET_JS_URL', ASSET_URL . $this->add_slash($c['asset_js_dir']));
     }
     if (!defined('ASSET_JS_URI')) {
         define('ASSET_JS_URI', ASSET_URI . $this->add_slash($c['asset_js_dir']));
     }
     if (!defined('ASSET_CSS_URL')) {
         define('ASSET_CSS_URL', ASSET_URL . $this->add_slash($c['asset_css_dir']));
     }
     if (!defined('ASSET_CSS_URI')) {
         define('ASSET_CSS_URI', ASSET_URI . $this->add_slash($c['asset_css_dir']));
     }
     if (!defined('THEME_IMG_URL')) {
         define('THEME_IMG_URL', THEME_ASSET_URL . $this->add_slash($c['asset_img_dir']));
     }
     if (!defined('THEME_IMG_URI')) {
         define('THEME_IMG_URI', THEME_ASSET_URI . $this->add_slash($c['asset_img_dir']));
     }
     if (!defined('THEME_JS_URL')) {
         define('THEME_JS_URL', THEME_ASSET_URL . $this->add_slash($c['asset_js_dir']));
     }
     if (!defined('THEME_JS_URI')) {
         define('THEME_JS_URI', THEME_ASSET_URI . $this->add_slash($c['asset_js_dir']));
     }
     if (!defined('THEME_CSS_URL')) {
         define('THEME_CSS_URL', THEME_ASSET_URL . $this->add_slash($c['asset_css_dir']));
     }
     if (!defined('THEME_CSS_URI')) {
         define('THEME_CSS_URI', THEME_ASSET_URI . $this->add_slash($c['asset_css_dir']));
     }
     log_message('info', 'Config Class Initialized');
 }