Esempio n. 1
0
 /**
  * Creates the HTML for the datalist element.
  * 
  * @return string
  */
 public function __toString()
 {
     $html = sprintf('<datalist id="%s">', get::encodedAttribute($this->getId()));
     if (is::assoc_array($this->list)) {
         foreach ($this->list as $value => $lbl) {
             $html .= sprintf('<option label="%s" value="%s" />', get::encodedAttribute($lbl), get::encodedAttribute($value));
         }
     } else {
         foreach ($this->list as $value) {
             $html .= sprintf('<option value="%s" />', get::encodedAttribute($value));
         }
     }
     $html .= '</datalist>';
     return $html;
 }
Esempio n. 2
0
File: get.php Progetto: Borvik/Munla
 /**
  * Takes an array of HTML attributes, and formats them for the HTML tag.
  * 
  * @param array $attributes The array of attributes to format.
  * 
  * @return string The formatted attributes as a string, prepended with a space.
  */
 public static function formattedAttributes(array $attributes)
 {
     $attributes = array_filter($attributes);
     $return = array();
     foreach ($attributes as $name => $value) {
         $return[] = sprintf('%s="%s"', $name, get::encodedAttribute($value));
     }
     if (count($return) < 1) {
         return '';
     }
     return ' ' . implode(' ', $return);
 }
Esempio n. 3
0
 /**
  * Generates the HTML for the form element.
  * 
  * @return string
  */
 public function __toString()
 {
     $this->attributes['id'] = $this->getId();
     $this->attributes['name'] = $this->getName();
     $keyvalues = get::array_def($this->attributes, 'keyvalues', false, array(true, false));
     $placeholder = get::array_def($this->attributes, 'placeholder', '');
     $separator = get::array_def($this->attributes, 'separator', false);
     $value = get::array_def($this->attributes, 'value', array());
     $multiple = get::array_def($this->attributes, 'multiple', false) == 'multiple';
     if ($multiple && substr($this->attributes['name'], -2) != '[]') {
         $this->attributes['name'] .= '[]';
     }
     if (!is_array($value) && strlen(trim($value)) < 1) {
         $value = array();
     }
     if (!is_array($value)) {
         $value = array($value);
     }
     $html = sprintf('<select%s>', get::formattedAttributes($this->getAttributes()));
     if (!$multiple && isset($placeholder) && strlen(trim($placeholder)) > 0) {
         $html .= sprintf('<option value="%s" disabled%s>%s</option>', get::encodedAttribute($this->emptyValue), count($value) > 0 ? '' : ' selected', get::entities($placeholder));
         if (isset($separator) && $separator !== false) {
             $separator = $separator === true ? '---------------' : $separator;
             $html .= sprintf('<option value="%s" disabled>%s</option>', get::encodedAttribute($this->emptyValue), get::entities($separator));
         }
     }
     if (isset($this->list) && count($this->list) > 0) {
         $stack = $this->build_stack($this->list);
         while ($stack) {
             $current = array_shift($stack);
             if (!is_array($current)) {
                 $html .= $current;
                 continue;
             }
             if (is_array($current['value'])) {
                 if (!is_string($current['key'])) {
                     continue;
                 }
                 $substack = $this->build_stack($current['value']);
                 if ($substack) {
                     $html .= sprintf('<optgroup label="%s">', get::encodedAttribute($current['key']));
                     array_unshift($stack, '</optgroup>');
                     while ($substack) {
                         array_unshift($stack, array_pop($substack));
                     }
                 }
             } else {
                 $v = $keyvalues || is_string($current['key']) ? (string) $current['key'] : $current['value'];
                 $l = $current['value'];
                 $selected = '';
                 if ($l == '-') {
                     $l = !isset($separator) || is_bool($separator) ? '---------------' : $separator;
                     $v = $this->emptyValue;
                 } else {
                     $selected = in_array($v, $value) ? ' selected="selected"' : '';
                 }
                 $html .= sprintf('<option value="%s"%s>%s</option>', get::encodedAttribute($v), $selected, get::entities($l));
             }
         }
     }
     $html .= '</select>';
     if (is::existset($this->attributes, 'autofocus')) {
         $html .= $this->getAutoFocusScript($this->attributes['id']);
     }
     return $html;
 }