コード例 #1
0
ファイル: group.php プロジェクト: QuezonMe/skelet
 public function output()
 {
     echo $this->element_before();
     $last_id = is_array($this->value) ? count($this->value) : 0;
     $acc_title = isset($this->field['accordion_title']) ? $this->field['accordion_title'] : __('Adding', SK_TEXTDOMAIN);
     $field_title = isset($this->field['fields'][0]['title']) ? $this->field['fields'][0]['title'] : $this->field['fields'][1]['title'];
     $field_id = isset($this->field['fields'][0]['id']) ? $this->field['fields'][0]['id'] : $this->field['fields'][1]['id'];
     $search_id = sk_array_search($this->field['fields'], 'id', $acc_title);
     if (!empty($search_id)) {
         $acc_title = isset($search_id[0]['title']) ? $search_id[0]['title'] : $acc_title;
         $field_id = isset($search_id[0]['id']) ? $search_id[0]['id'] : $field_id;
     }
     echo '<div class="sk-group hidden">';
     echo '<h4 class="sk-group-title">' . $acc_title . '</h4>';
     echo '<div class="sk-group-content">';
     foreach ($this->field['fields'] as $field_key => $field) {
         $field['sub'] = true;
         $unique = $this->unique . '[_nonce][' . $this->field['id'] . '][' . $last_id . ']';
         $field_default = isset($field['default']) ? $field['default'] : '';
         echo sk_add_element($field, $field_default, $unique);
     }
     echo '<div class="sk-element sk-text-right"><a href="#" class="button sk-warning-primary sk-remove-group">' . __('Remove', SK_TEXTDOMAIN) . '</a></div>';
     echo '</div>';
     echo '</div>';
     echo '<div class="sk-groups sk-accordion">';
     if (!empty($this->value)) {
         foreach ($this->value as $key => $value) {
             $title = isset($this->value[$key][$field_id]) ? $this->value[$key][$field_id] : '';
             if (is_array($title) && isset($this->multilang)) {
                 $lang = sk_language_defaults();
                 $title = $title[$lang['current']];
                 $title = is_array($title) ? $title[0] : $title;
             }
             $field_title = !empty($search_id) ? $acc_title : $field_title;
             echo '<div class="sk-group">';
             echo '<h4 class="sk-group-title">' . $field_title . ': ' . $title . '</h4>';
             echo '<div class="sk-group-content">';
             foreach ($this->field['fields'] as $field_key => $field) {
                 $field['sub'] = true;
                 $unique = $this->unique . '[' . $this->field['id'] . '][' . $key . ']';
                 $value = isset($field['id']) && isset($this->value[$key][$field['id']]) ? $this->value[$key][$field['id']] : '';
                 echo sk_add_element($field, $value, $unique);
             }
             echo '<div class="sk-element sk-text-right"><a href="#" class="button sk-warning-primary sk-remove-group">' . __('Remove', SK_TEXTDOMAIN) . '</a></div>';
             echo '</div>';
             echo '</div>';
         }
     }
     echo '</div>';
     echo '<a href="#" class="button button-primary sk-add-group">' . $this->field['button_title'] . '</a>';
     echo $this->element_after();
 }
コード例 #2
0
ファイル: helpers.php プロジェクト: QuezonMe/skelet
 function sk_add_element($field = array(), $value = '', $unique = '')
 {
     global $skelet_path;
     $output = '';
     $depend = '';
     $sub = isset($field['sub']) ? 'sub-' : '';
     $unique = isset($unique) ? $unique : '';
     $languages = sk_language_defaults();
     $class = isset($field['type']) ? 'SkeletFramework_Option_' . $field['type'] : '';
     $wrap_class = isset($field['wrap_class']) ? ' ' . $field['wrap_class'] : '';
     $hidden = isset($field['show_only_language']) && $field['show_only_language'] != $languages['current'] ? ' hidden' : '';
     $is_pseudo = isset($field['pseudo']) ? ' sk-pseudo-field' : '';
     if (isset($field['dependency'])) {
         $hidden = ' hidden';
         $depend .= ' data-' . $sub . 'controller="' . $field['dependency'][0] . '"';
         $depend .= ' data-' . $sub . 'condition="' . $field['dependency'][1] . '"';
         $depend .= " data-" . $sub . "value='" . $field['dependency'][2] . "'";
     }
     $output .= '<div class="sk-element sk-field-' . (isset($field['type']) ? $field['type'] : '') . $is_pseudo . $wrap_class . $hidden . '"' . $depend . '>';
     if (isset($field['title'])) {
         $field_desc = isset($field['desc']) ? '<p class="sk-text-desc">' . $field['desc'] . '</p>' : '';
         $output .= '<div class="sk-title"><h4>' . $field['title'] . '</h4>' . $field_desc . '</div>';
     }
     $output .= isset($field['title']) ? '<div class="sk-fieldset">' : '';
     $value = !isset($value) && isset($field['default']) ? $field['default'] : $value;
     $value = isset($field['value']) ? $field['value'] : $value;
     if (class_exists($class)) {
         ob_start();
         $element = new $class($field, $value, $unique);
         $element->output();
         $output .= ob_get_clean();
     } else {
         $output .= '<p>' . __('This field class is not available!', SK_TEXTDOMAIN) . '</p>';
     }
     $output .= isset($field['title']) ? '</div>' : '';
     $output .= '<div class="clear"></div>';
     $output .= '</div>';
     return $output;
 }
コード例 #3
0
ファイル: path.php プロジェクト: QuezonMe/skelet
 function sk_get_multilang_option($option_name = '', $default = '')
 {
     $value = sk_get_option($option_name, $default);
     $languages = sk_language_defaults();
     $default = $languages['default'];
     $current = $languages['current'];
     if (is_array($value) && is_array($languages) && isset($value[$current])) {
         return $value[$current];
     } else {
         if ($default != $current) {
             return '';
         }
     }
     return $value;
 }
コード例 #4
0
ファイル: framework.class.php プロジェクト: QuezonMe/skelet
 public function validate_save($request)
 {
     $add_errors = array();
     $section_id = isset($_POST['sk_section_id']) ? $_POST['sk_section_id'] : '';
     // ignore nonce requests
     if (isset($request['_nonce'])) {
         unset($request['_nonce']);
     }
     // import
     if (isset($request['import']) && !empty($request['import'])) {
         $decode_string = sk_decode_string($request['import']);
         if (is_array($decode_string)) {
             return $decode_string;
         }
         $add_errors[] = $this->add_settings_error(__('Success. Imported backup options.', SK_TEXTDOMAIN), 'updated');
     }
     // reset all options
     if (isset($request['resetall'])) {
         $add_errors[] = $this->add_settings_error(__('Default options restored.', SK_TEXTDOMAIN), 'updated');
         return;
     }
     // reset only section
     if (isset($request['reset']) && !empty($section_id)) {
         foreach ($this->sections as $value) {
             if ($value['name'] == $section_id) {
                 foreach ($value['fields'] as $field) {
                     if (isset($field['id'])) {
                         if (isset($field['default'])) {
                             $request[$field['id']] = $field['default'];
                         } else {
                             unset($request[$field['id']]);
                         }
                     }
                 }
             }
         }
         $add_errors[] = $this->add_settings_error(__('Default options restored for only this section.', SK_TEXTDOMAIN), 'updated');
     }
     // option sanitize and validate
     foreach ($this->sections as $section) {
         if (isset($section['fields'])) {
             foreach ($section['fields'] as $field) {
                 // ignore santize and validate if element multilangual
                 if (isset($field['type']) && !isset($field['multilang']) && isset($field['id'])) {
                     // sanitize options
                     $request_value = isset($request[$field['id']]) ? $request[$field['id']] : '';
                     $sanitize_type = $field['type'];
                     if (isset($field['sanitize'])) {
                         $sanitize_type = $field['sanitize'] !== false ? $field['sanitize'] : false;
                     }
                     if ($sanitize_type !== false && has_filter('sk_sanitize_' . $sanitize_type)) {
                         $request[$field['id']] = apply_filters('sk_sanitize_' . $sanitize_type, $request_value, $field, $section['fields']);
                     }
                     // validate options
                     if (isset($field['validate']) && has_filter('sk_validate_' . $field['validate'])) {
                         $validate = apply_filters('sk_validate_' . $field['validate'], $request_value, $field, $section['fields']);
                         if (!empty($validate)) {
                             $add_errors[] = $this->add_settings_error($validate, 'error', $field['id']);
                             $request[$field['id']] = isset($this->get_option[$field['id']]) ? $this->get_option[$field['id']] : '';
                         }
                     }
                 }
                 if (!isset($field['id']) || empty($request[$field['id']])) {
                     continue;
                 }
             }
         }
     }
     $request = apply_filters('sk_validate_save', $request);
     // set transient
     $transient_time = sk_language_defaults() !== false ? 30 : 10;
     set_transient('sk-framework-transient', array('errors' => $add_errors, 'section_id' => $section_id), $transient_time);
     return $request;
 }
コード例 #5
0
ファイル: options.class.php プロジェクト: QuezonMe/skelet
 public function element_multilang()
 {
     return isset($this->field['multilang']) ? sk_language_defaults() : false;
 }