Beispiel #1
0
 public static function instance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Beispiel #2
0
 public function can_output($hook_suffix = '')
 {
     // if not in option page, don't load
     $menu_page_slug = VP_Util_Config::instance()->load('option', 'menu_page_slug');
     if ($hook_suffix == 'appearance_page_' . $menu_page_slug) {
         return true;
     }
     return false;
 }
 function inner_build($fields, &$result)
 {
     $rules = VP_Util_Config::instance()->load('dependencies', 'rules');
     foreach ($fields as $field) {
         if ($field['type'] == 'group') {
             inner_build($field['fields'], $result);
         } else {
             if (array_key_exists($field['type'], $rules)) {
                 $result['scripts'] = array_merge($result['scripts'], $rules[$field['type']]['js']);
                 $result['styles'] = array_merge($result['styles'], $rules[$field['type']]['css']);
             }
             if ($field['type'] == 'upload') {
                 $result['use_upload'] = true;
             }
         }
     }
 }
Beispiel #4
0
 function _save($post_id)
 {
     // skip saving if dev mode is on
     $dev_mode = VP_Util_Config::instance()->load('metabox', 'dev_mode');
     if ($dev_mode) {
         return;
     }
     $real_post_id = isset($_POST['post_ID']) ? $_POST['post_ID'] : NULL;
     // check autosave
     if (defined('DOING_AUTOSAVE') and DOING_AUTOSAVE and !$this->autosave) {
         return $post_id;
     }
     // make sure data came from our meta box, verify nonce
     $nonce = isset($_POST[$this->id . '_nonce']) ? $_POST[$this->id . '_nonce'] : NULL;
     if (!wp_verify_nonce($nonce, $this->id)) {
         return $post_id;
     }
     // check user permissions
     if ($_POST['post_type'] == 'page') {
         if (!current_user_can('edit_page', $post_id)) {
             return $post_id;
         }
     } else {
         if (!current_user_can('edit_post', $post_id)) {
             return $post_id;
         }
     }
     // authentication passed, save data
     $new_data = isset($_POST[$this->id]) ? $_POST[$this->id] : NULL;
     // clean to copy and reset array indexes
     $this->_clean_tocopy($new_data);
     if (empty($new_data)) {
         $new_data = NULL;
     }
     // filter: save
     if ($this->has_filter('save')) {
         $new_data = $this->apply_filters('save', $new_data, $real_post_id);
         /**
          * halt saving
          * @since 1.3.4
          */
         if (FALSE === $new_data) {
             return $post_id;
         }
         $this->_clean_tocopy($new_data);
     }
     // get current fields, use $real_post_id (checked for in both modes)
     $current_fields = get_post_meta($real_post_id, $this->id . '_fields', TRUE);
     if ($this->mode == WPALCHEMY_MODE_EXTRACT) {
         $new_fields = array();
         if (is_array($new_data)) {
             foreach ($new_data as $k => $v) {
                 $field = $this->prefix . $k;
                 array_push($new_fields, $field);
                 $new_value = $new_data[$k];
                 if (is_null($new_value)) {
                     delete_post_meta($post_id, $field);
                 } else {
                     update_post_meta($post_id, $field, $new_value);
                 }
             }
         }
         $diff_fields = array_diff((array) $current_fields, $new_fields);
         if (is_array($diff_fields)) {
             foreach ($diff_fields as $field) {
                 delete_post_meta($post_id, $field);
             }
         }
         delete_post_meta($post_id, $this->id . '_fields');
         if (!empty($new_fields)) {
             add_post_meta($post_id, $this->id . '_fields', $new_fields, TRUE);
         }
         // keep data tidy, delete values if previously using WPALCHEMY_MODE_ARRAY
         delete_post_meta($post_id, $this->id);
     } else {
         if (is_null($new_data)) {
             delete_post_meta($post_id, $this->id);
         } else {
             update_post_meta($post_id, $this->id, $new_data);
         }
         // keep data tidy, delete values if previously using WPALCHEMY_MODE_EXTRACT
         if (is_array($current_fields)) {
             foreach ($current_fields as $field) {
                 delete_post_meta($post_id, $field);
             }
             delete_post_meta($post_id, $this->id . '_fields');
         }
     }
     // action: save
     if ($this->has_action('save')) {
         $this->do_action('save', $new_data, $real_post_id);
     }
     return $post_id;
 }
Beispiel #5
0
 function inner_build($fields, &$types)
 {
     $rules = VP_Util_Config::instance()->load('dependencies', 'rules');
     foreach ($fields as $field) {
         if ($field['type'] == 'group') {
             inner_build($field['fields'], $types);
         } else {
             if (!in_array($field['type'], $types)) {
                 $types[] = $field['type'];
             }
         }
     }
 }
Beispiel #6
0
 private function build_localize_data()
 {
     $messages = VP_Util_Config::instance()->load('messages');
     $localize = array('use_upload' => $this->_use_media_upload, 'use_new_media_upload' => $this->_use_wp_35_media_upload, 'public_url' => VP_PUBLIC_URL, 'wp_include_url' => includes_url(), 'nonce' => wp_create_nonce('vafpress'), 'val_msg' => $messages['validation'], 'util_msg' => $messages['util'], 'ctrl_msg' => $messages['control'], 'alphabet_validatable' => apply_filters('vp_alphabet_validatable', array('vp-textbox', 'vp-textarea')), 'alphanumeric_validatable' => apply_filters('vp_alphanumeric_validatable', array('vp-textbox', 'vp-textarea')), 'numeric_validatable' => apply_filters('vp_numeric_validatable', array('vp-textbox', 'vp-textarea')), 'email_validatable' => apply_filters('vp_email_validatable', array('vp-textbox', 'vp-textarea')), 'url_validatable' => apply_filters('vp_url_validatable', array('vp-textbox', 'vp-textarea')), 'maxlength_validatable' => apply_filters('vp_maxlength_validatable', array('vp-toggle', 'vp-radiobutton', 'vp-radioimage', 'vp-select')), 'minlength_validatable' => apply_filters('vp_minlength_validatable', array('vp-toggle', 'vp-radiobutton', 'vp-radioimage', 'vp-select')));
     $this->_localize = array_merge($this->_localize, $localize);
 }
Beispiel #7
0
 function inner_build($controls, &$types)
 {
     $rules = \VP_Util_Config::instance()->load('dependencies', 'rules');
     foreach ($controls as $control) {
         $field = $control->getSettings();
         if ($field['type'] == 'group') {
             inner_build($field['fields'], $types);
         } else {
             if (!in_array($field['type'], $types)) {
                 $types[] = $field['type'];
             }
         }
     }
 }