Example #1
0
 /**
  * Returns <option> tags.
  * 
  * @param array $options An array of (value => label)
  * @param string $current The value of the option that should be initially selected on the dropdown
  * 
  * @return string
  */
 static function option_tags($options, $current)
 {
     $html = '';
     foreach ($options as $value => $label) {
         if (is_array($label)) {
             $html .= "<optgroup label='{$value}'>\n" . suhtml::option_tags($label, $current) . "</optgroup>\n";
         } else {
             $html .= "\t<option value='{$value}'";
             if ((string) $value == (string) $current) {
                 $html .= " selected='selected'";
             }
             $html .= ">{$label}</option>\n";
         }
     }
     return $html;
 }
 /**
  * Generates the HTML for a single <select> post meta dropdown.
  * 
  * @since 2.5
  * @uses get_module_key()
  * @uses get_postmeta()
  * 
  * @param string $name The name of the <select> element.
  * @param array $options An array of options, where the array keys are the <option> values and the array values are the labels (<option> contents).
  * @param string $grouptext The text to display in a table cell to the left of the one containing the dropdown.
  * @return string $html
  */
 function get_postmeta_dropdown($name, $options, $grouptext)
 {
     register_setting('seo-ultimate', $name);
     $current = $this->get_postmeta($name);
     if ($current === '') {
         $current = reset($options);
     }
     $name = "_su_" . su_esc_attr($name);
     $html = "<div class='form-group su dropdown'>\n<label class='col-sm-4 col-md-4 control-label' for='{$name}'>{$grouptext}</label>\n<div class='col-sm-4 col-md-4'>\n";
     $html .= "<select name='{$name}' id='{$name}' onchange='javascript:su_toggle_select_children(this)'>\n";
     $html .= suhtml::option_tags($options, $current);
     $html .= "</select>\n";
     $html .= "</div>\n<div class='col-sm-4 col-md-4 help-text'></div>\n</div>\n";
     return $html;
 }
 /**
  * Generates the HTML for a single <select> post meta dropdown.
  * 
  * @since 2.5
  * @uses get_module_key()
  * @uses get_postmeta()
  * 
  * @param string $name The name of the <select> element.
  * @param array $options An array of options, where the array keys are the <option> values and the array values are the labels (<option> contents).
  * @param string $grouptext The text to display in a table cell to the left of the one containing the dropdown.
  * @return string $html
  */
 function get_postmeta_dropdown($name, $options, $grouptext)
 {
     register_setting('seo-ultimate', $name);
     $current = $this->get_postmeta($name);
     if ($current === '') {
         $current = array_shift(array_keys($options));
     }
     $name = "_su_" . su_esc_attr($name);
     $html = "<tr class='su dropdown' valign='middle'>\n<th scope='row' class='su'><label for='{$name}'>{$grouptext}</label></th>\n<td class='su'><fieldset><legend class='hidden'>{$grouptext}</legend>\n";
     $html .= "<select name='{$name}' id='{$name}' onchange='javascript:su_toggle_select_children(this)'>\n";
     $html .= suhtml::option_tags($options, $current);
     $html .= "</select>\n";
     $html .= "</fieldset></td>\n</tr>\n";
     return $html;
 }