示例#1
0
 function nice_formbuilder($nice_options)
 {
     $interface = new stdClass();
     $interface->menu = '';
     $interface->content = '';
     foreach ($nice_options as $key => $option) {
         if ($option['type'] != 'heading') {
             $class = '';
             if (isset($option['class'])) {
                 $class = $option['class'];
             }
             $interface->content .= '<div class="section section-' . $option['type'] . ' ' . $class . '">' . "\n";
             if ($option['type'] != 'upload' && $option['type'] != 'color' && $option['type'] != 'heading') {
                 $interface->content .= '<h3 class="heading"><label for="' . esc_attr($option['id']) . '">' . esc_html($option['name']) . '</label></h3>' . "\n";
             } else {
                 $interface->content .= '<h3 class="heading">' . esc_html($option['name']) . '</h3>' . "\n";
             }
             if ($option['type'] != 'checkbox' && $option['type'] != 'info' && $option['desc'] != '') {
                 $interface->content .= '<a id="btn-help-' . $option['id'] . '" class="nice-help-button">' . __('Help', 'nicethemes') . '</a>' . "\n";
             }
             $interface->content .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
         }
         $select_value = '';
         switch ($option['type']) {
             case 'text':
                 $interface->content .= nice_option_get_text($option);
                 break;
             case 'password':
                 $interface->content .= nice_option_get_password($option);
                 break;
             case 'select':
                 $interface->content .= nice_option_get_select($option);
                 break;
             case 'textarea':
                 $interface->content .= nice_option_get_textarea($option);
                 break;
             case 'upload':
                 $interface->content .= nice_option_get_file($option);
                 break;
             case 'checkbox':
                 $interface->content .= nice_option_get_checkbox($option);
                 break;
             case 'radio':
                 $interface->content .= nice_option_get_radio($option);
                 break;
             case 'color':
                 $interface->content .= nice_option_get_color($option);
                 break;
             case 'date':
                 $interface->content .= nice_option_get_date($option);
                 break;
             case 'select_multiple':
                 $interface->content .= nice_option_get_select_multiple($option);
                 break;
             case 'info':
                 $interface->content .= nice_option_get_info($option);
                 break;
             case 'slider':
                 $interface->content .= nice_option_get_slider($option);
                 break;
             case 'heading':
                 if ($key >= 2) {
                     $interface->content .= '</div>' . "\n";
                 }
                 $jquery_click_hook = preg_replace('/[^a-zA-Z0-9\\s]/', '', strtolower($option['name']));
                 $jquery_click_hook = str_replace(' ', '-', $jquery_click_hook);
                 $jquery_click_hook = 'nice-option-' . $jquery_click_hook;
                 $interface->menu .= '<li><a title="' . esc_attr($option['name']) . '" href="#' . $jquery_click_hook . '">' . esc_html($option['name']) . '</a><div></div></li>' . "\n";
                 $interface->content .= '<div class="group" id="' . $jquery_click_hook . '"><h2>' . esc_html($option['name']) . '</h2>' . "\n";
                 break;
             case 'typography':
                 $interface->content .= nice_option_get_typography($option);
                 break;
         }
         $explain_class = 'explain';
         if ($option['type'] != 'heading') {
             if ($option['type'] != 'checkbox') {
                 $interface->content .= '<br />';
             } else {
                 $explain_class = 'explain-checkbox';
             }
             if (!isset($option['desc'])) {
                 $explain_value = '';
             } else {
                 $explain_value = $option['desc'];
             }
             $interface->content .= '</div><div id="nice-help-' . $option['id'] . '" class="' . $explain_class . '">';
             if ($option['type'] == 'checkbox') {
                 $interface->content .= '<label for="' . $option['id'] . '">' . $explain_value . '</label>';
             } else {
                 $interface->content .= $explain_value;
             }
             $interface->content .= '</div>' . "\n";
             $interface->content .= '<div class="clear"></div></div></div>' . "\n";
         }
     }
     $interface->content .= '</div>';
     return $interface;
 }
/**
 * nice_formbuilder()
 *
 * retrieve the options array, creating the html structure for the
 * options menu.
 *
 * @since 1.0.0
 *
 * @param array $nice_options. Theme Options.
 * @return object with menu and content.
 */
function nice_formbuilder($nice_options)
{
    $interface = new stdClass();
    $interface->menu = '';
    $interface->content = '';
    foreach ($nice_options as $key => $option) {
        if ($option['type'] != "heading") {
            $class = '';
            if (isset($option['class'])) {
                $class = $option['class'];
            }
            $interface->content .= '<div class="section section-' . $option['type'] . ' ' . $class . '">' . "\n";
            if ($option['type'] != "upload" && $option['type'] != "color" && $option['type'] != "heading") {
                $interface->content .= '<h3 class="heading"><label for="' . $option['id'] . '">' . $option['name'] . '</label></h3>' . "\n";
            } else {
                $interface->content .= '<h3 class="heading">' . $option['name'] . '</h3>' . "\n";
            }
            if ($option['type'] != "checkbox" && $option['desc'] != '') {
                $interface->content .= '<a id="btn-help-' . $option['id'] . '" class="nice-help-button">' . __('Help', 'nicethemes') . '</a>' . "\n";
            }
            $interface->content .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
        }
        $select_value = '';
        switch ($option['type']) {
            case 'text':
                $interface->content .= nice_option_get_text($option);
                break;
            case 'select':
                $interface->content .= nice_option_get_select($option);
                break;
            case 'textarea':
                $interface->content .= nice_option_get_textarea($option);
                break;
            case "upload":
                $interface->content .= nice_option_get_file($option);
                break;
            case "checkbox":
                $interface->content .= nice_option_get_checkbox($option);
                break;
            case "radio":
                $interface->content .= nice_option_get_radio($option);
                break;
            case "color":
                $interface->content .= nice_option_get_color($option);
                break;
            case "date":
                $interface->content .= nice_option_get_date($option);
                break;
            case "select_multiple":
                $interface->content .= nice_option_get_select_multiple($option);
                break;
            case "heading":
                if ($key >= 2) {
                    $interface->content .= '</div>' . "\n";
                }
                $jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($option['name']));
                $jquery_click_hook = "nice-option-" . $jquery_click_hook;
                $interface->menu .= '<li><a title="' . $option['name'] . '" href="#' . $jquery_click_hook . '">' . $option['name'] . '</a><div></div></li>' . "\n";
                $interface->content .= '<div class="group" id="' . $jquery_click_hook . '"><h2>' . $option['name'] . '</h2>' . "\n";
                break;
            case "typography":
                $interface->content .= nice_option_get_typography($option);
                break;
        }
        $explain_class = 'explain';
        if ($option['type'] != "heading") {
            if ($option['type'] != "checkbox") {
                $interface->content .= '<br />';
            } else {
                $explain_class = 'explain-checkbox';
            }
            if (!isset($option['desc'])) {
                $explain_value = '';
            } else {
                $explain_value = $option['desc'];
            }
            $interface->content .= '</div><div id="nice-help-' . $option['id'] . '" class="' . $explain_class . '">';
            if ($option['type'] == "checkbox") {
                $interface->content .= '<label for="' . $option['id'] . '">' . $explain_value . '</label>';
            } else {
                $interface->content .= $explain_value;
            }
            $interface->content .= '</div>' . "\n";
            $interface->content .= '<div class="clear"> </div></div></div>' . "\n";
        }
    }
    $interface->content .= '</div>';
    return $interface;
}