예제 #1
0
 /**
  * @see Walker::start_el()
  *
  * @param string $output            Passed by reference. Used to append additional content.
  * @param object $object            Item data object.
  * @param int    $depth             Depth of item.
  * @param int    $current_object_id Item ID.
  * @param array  $args
  */
 public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
 {
     $label = $this->db_fields['label'];
     $id = $this->db_fields['id'];
     $meta = $this->meta;
     $field = $this->field;
     $field_class = SWP_Meta_Box::get_class_name($field);
     $attributes = call_user_func(array($field_class, 'get_attributes'), $field, $object->{$id});
     $output .= sprintf('<li><label><input %s %s>%s</label>', SWPMB_Field::render_attributes($attributes), checked(in_array($object->{$id}, $meta), 1, false), $object->{$label});
 }
예제 #2
0
 /**
  * Walk options
  *
  * @param mixed $meta
  * @param array $field
  * @param mixed $options
  * @param mixed $db_fields
  *
  * @return string
  */
 public static function walk($options, $db_fields, $meta, $field)
 {
     $attributes = call_user_func(array(SWP_Meta_Box::get_class_name($field), 'get_attributes'), $field, $meta);
     $walker = new SWPMB_Select_Walker($db_fields, $field, $meta);
     $output = sprintf('<select %s>', self::render_attributes($attributes));
     $output .= '<option></option>';
     $output .= $walker->walk($options, $field['flatten'] ? -1 : 0);
     $output .= '</select>';
     $output .= self::get_select_all_html($field);
     return $output;
 }
예제 #3
0
파일: select.php 프로젝트: arobbins/sblog
 /**
  * Walk options
  *
  * @param mixed $meta
  * @param array $field
  * @param mixed $options
  * @param mixed $db_fields
  *
  * @return string
  */
 public static function walk($options, $db_fields, $meta, $field)
 {
     $attributes = call_user_func(array(SWP_Meta_Box::get_class_name($field), 'get_attributes'), $field, $meta);
     $walker = new SWPMB_Select_Walker($db_fields, $field, $meta);
     $output = sprintf('<select %s>', self::render_attributes($attributes));
     if (false === $field['multiple']) {
         if (isset($field['placeholder']) && $field['placeholder'] != '') {
             $output .= "<option value=''>{$field['placeholder']}</option>";
         }
     }
     $output .= $walker->walk($options, $field['flatten'] ? -1 : 0);
     $output .= '</select>';
     $output .= self::get_select_all_html($field);
     return $output;
 }
예제 #4
0
 function display_level($options, $parent_id = 0, $active = false)
 {
     $id = $this->db_fields['id'];
     $field = $this->field;
     $meta = $this->meta;
     $walker = new SWPMB_Select_Walker($this->db_fields, $this->field, $this->meta);
     $field_class = SWP_Meta_Box::get_class_name($field);
     $attributes = call_user_func(array($field_class, 'get_attributes'), $field, $meta);
     $children = $options[$parent_id];
     $output = sprintf('<div class="swpmb-select-tree %s" data-parent-id="%s"><select %s>', $active ? '' : 'hidden', $parent_id, SWPMB_Field::render_attributes($attributes));
     $output .= isset($field['placeholder']) ? "<option value=''>{$field['placeholder']}</option>" : '<option></option>';
     $output .= $walker->walk($children, -1);
     $output .= '</select>';
     foreach ($children as $c) {
         if (isset($options[$c->{$id}])) {
             $output .= $this->display_level($options, $c->{$id}, in_array($c->{$id}, $meta) && $active);
         }
     }
     $output .= '</div>';
     return $output;
 }
예제 #5
0
파일: helper.php 프로젝트: arobbins/sblog
 /**
  * Get post meta
  *
  * @param string   $key     Meta key. Required.
  * @param int|null $post_id Post ID. null for current post. Optional
  * @param array    $args    Array of arguments. Optional.
  *
  * @return mixed
  */
 public static function meta($key, $args = array(), $post_id = null)
 {
     $post_id = empty($post_id) ? get_the_ID() : $post_id;
     $args = wp_parse_args($args, array('type' => 'text', 'multiple' => false, 'clone' => false));
     // Always set 'multiple' true for following field types
     if (in_array($args['type'], array('checkbox_list', 'autocomplete', 'file', 'file_advanced', 'image', 'image_advanced', 'plupload_image', 'thickbox_image'))) {
         $args['multiple'] = true;
     }
     $field = array('id' => $key, 'type' => $args['type'], 'clone' => $args['clone'], 'multiple' => $args['multiple']);
     $class = SWP_Meta_Box::get_class_name($field);
     switch ($args['type']) {
         case 'taxonomy_advanced':
             if (empty($args['taxonomy'])) {
                 break;
             }
             $meta = get_post_meta($post_id, $key, !$args['multiple']);
             $term_ids = wp_parse_id_list($meta);
             // Allow to pass more arguments to "get_terms"
             $func_args = wp_parse_args(array('include' => $term_ids, 'hide_empty' => false), $args);
             unset($func_args['type'], $func_args['taxonomy'], $func_args['multiple']);
             $meta = get_terms($args['taxonomy'], $func_args);
             break;
         case 'taxonomy':
             $meta = empty($args['taxonomy']) ? array() : get_the_terms($post_id, $args['taxonomy']);
             break;
         case 'map':
             $field = array('id' => $key, 'multiple' => false, 'clone' => false);
             $meta = SWPMB_Map_Field::the_value($field, $args, $post_id);
             break;
         case 'oembed':
             $meta = SWPMB_OEmbed_Field::the_value($field, $args, $post_id);
             break;
         default:
             $meta = call_user_func(array($class, 'get_value'), $field, $args, $post_id);
             break;
     }
     return apply_filters('swpmb_meta', $meta, $key, $args, $post_id);
 }
예제 #6
0
 /**
  * Display the value of a field
  *
  * @param  string   $field_id Field ID. Required.
  * @param  array    $args     Additional arguments. Rarely used. See specific fields for details
  * @param  int|null $post_id  Post ID. null for current post. Optional.
  * @param  bool     $echo     Display field meta value? Default `true` which works in almost all cases. We use `false` for  the [swpmb_meta] shortcode
  *
  * @return string
  */
 function swpmb_the_value($field_id, $args = array(), $post_id = null, $echo = true)
 {
     // Find field
     $field = SWPMB_Helper::find_field($field_id, $post_id);
     if (!$field) {
         return '';
     }
     $output = call_user_func(array(SWP_Meta_Box::get_class_name($field), 'the_value'), $field, $args, $post_id);
     /**
      * Allow developers to change the returned value of field
      * For version < 4.8.2, the filter name was 'swpmb_get_field'
      *
      * @param mixed    $value   Field HTML output
      * @param array    $field   Field parameter
      * @param array    $args    Additional arguments. Rarely used. See specific fields for details
      * @param int|null $post_id Post ID. null for current post. Optional.
      */
     $output = apply_filters('swpmb_the_value', $output, $field, $args, $post_id);
     if ($echo) {
         echo $output;
     }
     return $output;
 }
예제 #7
0
파일: file.php 프로젝트: arobbins/sblog
 /**
  * Get the field value
  * The difference between this function and 'meta' function is 'meta' function always returns the escaped value
  * of the field saved in the database, while this function returns more meaningful value of the field
  *
  * @param  array    $field   Field parameters
  * @param  array    $args    Not used for this field
  * @param  int|null $post_id Post ID. null for current post. Optional.
  *
  * @return mixed Full info of uploaded files
  */
 static function get_value($field, $args = array(), $post_id = null)
 {
     if (!$post_id) {
         $post_id = get_the_ID();
     }
     /**
      * Get raw meta value in the database, no escape
      * Very similar to self::meta() function
      */
     $file_ids = get_post_meta($post_id, $field['id'], false);
     // For each file, get full file info
     $value = array();
     foreach ((array) $file_ids as $file_id) {
         if ($file_info = call_user_func(array(SWP_Meta_Box::get_class_name($field), 'file_info'), $file_id, $args)) {
             $value[$file_id] = $file_info;
         }
     }
     return $value;
 }
예제 #8
0
파일: choice.php 프로젝트: arobbins/sblog
 /**
  * Get option label
  *
  * @param string $value Option value
  * @param array  $field Field parameter
  *
  * @return string
  */
 public static function get_option_label($value, $field)
 {
     $options = call_user_func(array(SWP_Meta_Box::get_class_name($field), 'get_options'), $field);
     return $options[$value]->label;
 }
예제 #9
0
파일: input.php 프로젝트: arobbins/sblog
 /**
  * Get field HTML
  *
  * @param mixed $meta
  * @param array $field
  * @return string
  */
 static function html($meta, $field)
 {
     $attributes = call_user_func(array(SWP_Meta_Box::get_class_name($field), 'get_attributes'), $field, $meta);
     return sprintf('<input %s>%s', self::render_attributes($attributes), self::datalist_html($field));
 }
예제 #10
0
파일: field.php 프로젝트: arobbins/sblog
 /**
  * Output the field value
  * Depends on field value and field types, each field can extend this method to output its value in its own way
  * See specific field classes for details.
  *
  * Note: we don't echo the field value directly. We return the output HTML of field, which will be used in
  * swpmb_the_field function later.
  *
  * @use self::get_value()
  * @see swpmb_the_value()
  *
  * @param  array    $field   Field parameters
  * @param  array    $args    Additional arguments. Rarely used. See specific fields for details
  * @param  int|null $post_id Post ID. null for current post. Optional.
  *
  * @return string HTML output of the field
  */
 static function the_value($field, $args = array(), $post_id = null)
 {
     $value = call_user_func(array(SWP_Meta_Box::get_class_name($field), 'get_value'), $field, $args, $post_id);
     $output = $value;
     if (is_array($value)) {
         $output = '<ul>';
         foreach ($value as $subvalue) {
             $output .= '<li>' . $subvalue . '</li>';
         }
         $output .= '</ul>';
     }
     return $output;
 }
예제 #11
0
파일: datetime.php 프로젝트: arobbins/sblog
 /**
  * Get meta value
  *
  * @param int   $post_id
  * @param bool  $saved
  * @param array $field
  *
  * @return mixed
  */
 public static function meta($post_id, $saved, $field)
 {
     $meta = parent::meta($post_id, $saved, $field);
     if (!$field['timestamp']) {
         return $meta;
     }
     $method = array(SWP_Meta_Box::get_class_name($field), 'translate_format');
     if (is_array($meta)) {
         foreach ($meta as $key => $value) {
             $meta[$key] = array('timestamp' => $value, 'formatted' => date(call_user_func($method, $field), intval($value)));
         }
     } else {
         $meta = array('timestamp' => $meta, 'formatted' => date(call_user_func($method, $field), intval($meta)));
     }
     return $meta;
 }