/** * Settings of View Type = Scrollable * * @return array */ static function view_type_settings_scrollable() { $prefix = 'scrollable-'; $result = array(PT_CV_Settings::setting_no_option()); $result = apply_filters(PT_CV_PREFIX_ . 'view_type_settings_scrollable', $result); return $result; }
/** * Print HTML code of field type: input, select, textarea... * * @param array $param Array of parameters of a setting option * @param array $data Array of stored data * * @return string */ public static function field_type($param, $data, $value_ = NULL) { if (!$param || !isset($param['type'])) { return ''; } $html = $extend = ''; $class = 'form-control ' . (isset($param['class']) ? ' ' . PT_CV_PREFIX . $param['class'] : ''); $type = esc_attr($param['type']); $name = !empty($param['name']) ? PT_CV_PREFIX . esc_attr($param['name']) : ''; $id = !empty($param['id']) ? "id='" . PT_CV_PREFIX . esc_attr($param['id']) . "'" : ''; $value = isset($value_) ? $value_ : self::field_value($data, $param, $name); $description = isset($param['desc']) ? $param['desc'] : ''; $placeholder = isset($param['placeholder']) ? $param['placeholder'] : ''; // Add extra information of option type switch ($type) { case 'number': $min = !empty($param['min']) ? intval($param['min']) : 0; $extend = 'min="' . $min . '"'; break; case 'color': $class .= ' ' . PT_CV_PREFIX . 'color'; break; case 'checkbox': case 'radio': // Remove form-control class in checkbox, radio $class = str_replace('form-control', '', $class); break; } $class = esc_attr($class); // Show HTML of option type switch ($type) { case 'group': $html .= self::do_settings($param['params'], $data); break; case 'text': case 'email': case 'password': case 'number': case 'url': $prepend_text = !empty($param['prepend_text']) ? $param['prepend_text'] : ''; $append_text = !empty($param['append_text']) ? $param['append_text'] : ''; $input = "<input type='{$type}' name='{$name}' value='{$value}' class='{$class}' {$id} {$extend} placeholder='{$placeholder}'>"; if (!empty($prepend_text) || !empty($append_text)) { $input = "<div class='input-group'>{$prepend_text}{$input}<span class='input-group-addon'>{$append_text}</span></div>"; } $html .= $input; break; case 'color': $html .= "<input type='text' name='{$name}' value='{$value}' class='{$class}' {$id} {$extend} style='background-color:{$value};'>"; $html .= "<div class='" . PT_CV_PREFIX . "colorpicker' style='z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;'></div><br>"; break; case 'textarea': $html .= "<textarea name='{$name}' class='{$class}' {$id} {$extend} placeholder='{$placeholder}' rows=4>{$value}</textarea>"; break; case 'checkbox': case 'radio': if (!isset($param['options'])) { break; } $settings = isset($param['settings']) ? $param['settings'] : array(); foreach ($param['options'] as $key => $text) { // Append Html to $text, such as image... if ($settings) { $append = isset($settings['text-append']) ? $settings['text-append'] : ''; if ($append == 'image') { $path = isset($settings['path']) ? $settings['path'] : ''; if ($path) { $text .= "<br> <img src='" . plugins_url($path . "/{$key}.png", PT_CV_FILE) . "' />"; } } } $checked = in_array($key, (array) $value) || $value == 'all' ? 'checked' : ''; $html .= "<div class='{$type}'><label><input type='{$type}' name='{$name}' value='{$key}' class='{$class}' {$checked} {$id} {$extend}>{$text}</label></div>"; } break; case 'select': if (!isset($param['options'])) { break; } if (is_string($value) && strpos($value, ',') !== false) { $value = explode(',', $value); } $options = ''; foreach ($param['options'] as $key => $text) { $selected = in_array(str_replace('&', '&', $key), (array) $value) || $value == 'all' ? 'selected' : ''; $option_class = isset($param['option_class_prefix']) ? sprintf("class='%s'", $param['option_class_prefix'] . esc_attr(sanitize_title($key))) : ''; $options .= "<option value='{$key}' {$selected} {$option_class}>{$text}</option>"; } if (empty($options)) { $html .= PT_CV_Settings::setting_no_option(true); } else { $multiple = ''; if (isset($param['multiple']) && $param['multiple'] == '1' || $value == 'all') { $multiple = 'multiple'; // Auto add [] to name of select $name .= substr($name, -2) == '[]' ? '' : '[]'; } $html .= "<select name='{$name}' class='{$class}' {$multiple} {$id} {$extend}>{$options}</select>"; } break; case 'color_picker': $html .= self::field_type($param['options'], $data); break; case 'html': if (isset($param['content'])) { $html .= $param['content']; } break; case 'panel_group': // In format: key => array of params $parent_id = PT_CV_Functions::string_random(true); $settings = isset($param['settings']) ? $param['settings'] : array(); foreach ($param['params'] as $key => $param_group) { $html .= self::sub_panel_group($key, $param_group, $data, $parent_id, $settings); } break; } $description = apply_filters(PT_CV_PREFIX_ . 'options_description', $description, $param); if (!empty($description)) { // Append dot to end of description if (trim(strip_tags($description)) != '' && substr($description, -1) != '?') { $description .= '.'; } $html .= "<p class='text-muted'>{$description}</p>"; } return $html; }