コード例 #1
0
ファイル: skype.php プロジェクト: SpencerNeitzke/types
/**
 * Returns 'skypename' if available.
 *
 * @global type $wpcf
 * @param type $null
 * @param type $object_id
 * @param type $meta_key
 * @param type $single
 * @return type
 */
function wpcf_fields_skype_conditional_filter_post_meta($null, $object_id, $meta_key, $single)
{
    global $wpcf;
    $field = wpcf_admin_fields_get_field($wpcf->field->__get_slug_no_prefix($meta_key));
    if (!empty($field) && $field['type'] == 'skype') {
        $_meta = maybe_unserialize(wpcf_get_post_meta($object_id, $meta_key, $single));
        if (is_array($_meta)) {
            $null = isset($_meta['skypename']) ? $_meta['skypename'] : '';
        }
        /**
         * be sure do not return string if array is expected!
         */
        if (!$single && !is_array($null)) {
            return array($null);
        }
    }
    return $null;
}
コード例 #2
0
ファイル: relationship.php プロジェクト: Kilbourne/restart
 /**
  * Gets post parent by post type.
  *
  * @param type $post_id
  * @param type $parent_post_type
  * @return type
  */
 public static function get_parent($post_id, $parent_post_type)
 {
     return wpcf_get_post_meta($post_id, '_wpcf_belongs_' . $parent_post_type . '_id', true);
 }
コード例 #3
0
ファイル: frontend.php プロジェクト: axeljohansson1988/oddcv
/**
 * Calls view function for specific field type.
 *
 * @param type $field
 * @param type $atts
 * @return type
 */
function types_render_field($field_id = null, $params = array(), $content = null, $code = '')
{
    if (empty($field_id)) {
        return '';
    }
    global $wpcf;
    // HTML var holds actual output
    $html = '';
    // Set post ID to global
    $post_id = get_the_ID();
    // Check if other post required
    if (isset($params['post_id'])) {
        // If numeric value
        if (is_numeric($params['post_id'])) {
            $post_id = intval($params['post_id']);
            // WP parent
        } else {
            if ($params['post_id'] == '$parent') {
                $current_post = get_post($post_id);
                if (empty($current_post->post_parent)) {
                    return '';
                }
                $post_id = $current_post->post_parent;
                // Types parent
            } else {
                if (strpos($params['post_id'], '$') === 0) {
                    $post_id = intval(WPCF_Relationship::get_parent($post_id, trim($params['post_id'], '$')));
                }
            }
        }
    }
    if (empty($post_id)) {
        return '';
    }
    // Set post
    $post = get_post($post_id);
    if (empty($post)) {
        return '';
    }
    // Get field
    $field = types_get_field($field_id);
    // If field not found return empty string
    if (empty($field)) {
        // Log
        if (!function_exists('wplogger')) {
            require_once WPCF_EMBEDDED_TOOLSET_ABSPATH . '/toolset-common/wplogger.php';
        }
        global $wplogger;
        $wplogger->log('types_render_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG);
        return '';
    }
    // Set field
    $wpcf->field->set($post, $field);
    // See if repetitive
    if (types_is_repetitive($field)) {
        $wpcf->repeater->set($post_id, $field);
        $_meta = $wpcf->repeater->_get_meta();
        $meta = $_meta['custom_order'];
        // Sometimes if meta is empty - array(0 => '') is returned
        if (count($meta) == 1 && reset($meta) == '') {
            return '';
        }
        if (!empty($meta)) {
            $output = '';
            if (isset($params['index'])) {
                $index = $params['index'];
            } else {
                $index = '';
            }
            // Allow wpv-for-each shortcode to set the index
            $index = apply_filters('wpv-for-each-index', $index);
            if ($index === '') {
                $output = array();
                foreach ($meta as $temp_key => $temp_value) {
                    $params['field_value'] = $temp_value;
                    $temp_output = types_render_field_single($field, $params, $content, $code, $temp_key);
                    if (!empty($temp_output)) {
                        $output[] = $temp_output;
                    }
                }
                if (!empty($output) && isset($params['separator']) && $params['separator'] !== '') {
                    $output = implode(html_entity_decode($params['separator']), $output);
                } else {
                    if (!empty($output)) {
                        $output = implode(' ', $output);
                    } else {
                        return '';
                    }
                }
            } else {
                // Make sure indexed right
                $_index = 0;
                foreach ($meta as $temp_key => $temp_value) {
                    if ($_index == $index) {
                        $params['field_value'] = $temp_value;
                        return types_render_field_single($field, $params, $content, $code, $temp_key);
                    }
                    $_index++;
                }
                // If missed index
                return '';
            }
            $html = $output;
        } else {
            return '';
        }
    } else {
        // Non-repetitive field
        $params['field_value'] = wpcf_get_post_meta($post_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
        if ($params['field_value'] == '' && $field['type'] != 'checkbox') {
            return '';
        }
        $html = types_render_field_single($field, $params, $content, $code, $wpcf->field->meta_object->meta_id);
    }
    return $wpcf->field->html($html, $params);
}
コード例 #4
0
ファイル: api.php プロジェクト: lytranuit/wordpress
/**
 * Gets posts that belongs to current post.
 * 
 * @global type $post
 * @param type $post_type
 * @param type $args
 * @return type 
 */
function types_child_posts($post_type, $args = array())
{
    static $cache = array();
    if (isset($args['post_id'])) {
        $post = $args['post_id'] != '0' ? get_post($args['post_id']) : null;
    } else {
        global $post;
    }
    if (empty($post->ID)) {
        return array();
    }
    $cache_key = md5($post->ID . serialize(func_get_args()));
    if (isset($cache[$cache_key])) {
        return $cache[$cache_key];
    }
    global $wp_post_types;
    // WP allows querying inactive post types
    if (!isset($wp_post_types[$post_type]) || !$wp_post_types[$post_type]->publicly_queryable) {
        return array();
    }
    $defaults = array('post_status' => array('publish'));
    $args = wp_parse_args($args, $defaults);
    WPCF_Loader::loadModel('relationship');
    WPCF_Loader::loadInclude('fields-post');
    $child_posts = WPCF_Relationship_Model::getChildrenByPostType($post, $post_type, array(), array(), $args);
    foreach ($child_posts as $child_post_key => $child_post) {
        $child_posts[$child_post_key]->fields = array();
        $groups = wpcf_admin_post_get_post_groups_fields($child_post);
        foreach ($groups as $group) {
            if (!empty($group['fields'])) {
                // Process fields
                foreach ($group['fields'] as $k => $field) {
                    $data = null;
                    if (types_is_repetitive($field)) {
                        $data = wpcf_get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], false);
                        // get all field instances
                    } else {
                        $data = wpcf_get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                        // get single field instance
                        // handle checkboxes which are one value serialized
                        if ($field['type'] == 'checkboxes' && !empty($data)) {
                            $data = maybe_unserialize($data);
                        }
                    }
                    if (!is_null($data)) {
                        $child_posts[$child_post_key]->fields[$k] = $data;
                    }
                }
            }
        }
    }
    $cache[$cache_key] = $child_posts;
    return $child_posts;
}
コード例 #5
0
ファイル: functions.php プロジェクト: nhainam/wordpress4
/**
 * Fix due to a bug saving date as array.
 * 
 * BUGS
 * 'timestamp' is saved without Hour and Minute appended.
 * 
 * @param type $value
 * @param type $field
 */
function __wpcf_fields_date_check_leftover($value, $field, $use_cache = true)
{
    if (empty($value)) {
        return $value;
    }
    if (!is_object($field)) {
        $post_id = wpcf_get_post_id();
        $field_id = isset($field['id']) ? $field['id'] : false;
        $meta_id = isset($field['__meta_id']) ? $field['__meta_id'] : false;
    } else {
        $post_id = isset($field->meta_object->post_id) ? $field->meta_object->post_id : false;
        $field_id = isset($field->cf['id']) ? $field->cf['id'] : false;
        $meta_id = isset($field->meta_object->meta_id) ? $field->meta_object->meta_id : false;
    }
    if (empty($post_id) || empty($meta_id) || empty($field_id)) {
        return $value;
    }
    $field_slug = wpcf_types_get_meta_prefix() . $field_id;
    // Check if cached
    static $cache = array();
    $cache_key = $meta_id;
    if (isset($cache[$cache_key]) && $use_cache) {
        return $cache[$cache_key];
    }
    $_meta = wpcf_get_post_meta($post_id, '_wpcf_' . $field_id . '_hour_and_minute', true);
    /*
     * If meta exists - it's outdated value
     * and Hour and Minute should be appended and removed.
     */
    if (!empty($_meta) && is_array($_meta) && isset($_meta[$meta_id])) {
        $meta = $_meta[$meta_id];
        // Return empty date if can not be calculated
        if (!empty($meta['timestamp']) || !empty($meta['datepicker'])) {
            $meta['timestamp'] = wpcf_fields_date_value_get_filter($meta, $field, 'timestamp', 'check_leftover');
            // Check if calculation needed
            if (isset($meta['hour']) && $meta['hour'] != adodb_date('H', $meta['timestamp']) || isset($meta['minute']) && $meta['minute'] != adodb_date('i', $meta['timestamp'])) {
                $value = wpcf_fields_date_calculate_time($meta);
            }
        }
    }
    // Cache it
    if ($use_cache) {
        $cache[$cache_key] = $value;
    }
    return $value;
}
コード例 #6
0
 /**
  * Fetch children by post type.
  *
  * @global object $wpdb
  *
  * @param type $post
  * @param type $post_type
  * @param string $data
  * @param array $params
  * @param array $user_query - Override default query
  * @return type
  */
 public static function getChildrenByPostType($post, $post_type, $data, $params = array(), $user_query = array())
 {
     if (empty($post->ID)) {
         return array();
     }
     global $wpdb;
     $items = array();
     // Merge with user query
     $query = wp_parse_args($user_query, array('post_type' => $post_type, 'numberposts' => -1, 'post_status' => array('publish', 'pending', 'draft', 'future', 'private'), 'meta_key' => '_wpcf_belongs_' . $post->post_type . '_id', 'meta_value' => $post->ID, 'suppress_filters' => 0));
     // Cleanup data
     if (empty($data['fields_setting'])) {
         $data['fields_setting'] = 'all_cf';
     }
     // List items
     if (isset($params['sort']) && isset($params['field'])) {
         // Set sorting
         $query['order'] = esc_attr(strtoupper(strval($params['sort'])));
         if (!preg_match('/^(A|DE)SC$/', $query['order'])) {
             $query['order'] = 'ASC';
         }
         /*
          *
          * Order by title
          */
         if ($params['field'] == '_wp_title') {
             $query['orderby'] = 'title';
             $query = apply_filters('wpcf_relationship_get_children_query', $query, $post, $post_type, $data, esc_attr($params['field']));
             $items = get_posts($query);
             /*
              *
              * Order by parents
              */
         } else {
             if ($params['field'] == '_wpcf_pr_parent') {
                 $query = apply_filters('wpcf_relationship_get_children_query', $query, $post, $post_type, $data, esc_attr($params['field']));
                 $items = get_posts($query);
                 if (!empty($items)) {
                     $include = array();
                     $additional = array();
                     foreach ($items as $item) {
                         $meta = wpcf_get_post_meta($item->ID, '_wpcf_belongs_' . esc_attr($params['post_type_sort_parent']) . '_id', true);
                         if (empty($meta)) {
                             $additional[] = $item;
                             continue;
                         }
                         $include[intval($meta)][] = $item;
                     }
                     if (!empty($include)) {
                         ksort($include, SORT_NUMERIC);
                         if ($query['order'] == 'DESC') {
                             $include = array_reverse($include);
                         }
                         $sorted = array();
                         foreach ($include as $meta_value => $posts) {
                             foreach ($posts as $post) {
                                 $sorted[] = $post;
                             }
                         }
                         $items = array_merge($sorted, $additional);
                     }
                 }
                 /*
                  *
                  * Order by body
                  */
             } else {
                 if ($params['field'] == '_wp_body') {
                     $_query = "\r\r\n                    SELECT p.ID\r\r\n                    FROM {$wpdb->posts} p\r\r\n                    WHERE p.post_type = %s\r\r\n                    AND p.post_status NOT IN ('auto-draft', 'trash', 'inherit')\r\r\n                    ORDER BY p.post_content " . ('ASC' == $query['order'] ? 'ASC' : 'DESC');
                     $sorted = $wpdb->get_results($wpdb->prepare($_query, $post_type));
                     if (!empty($sorted)) {
                         $query['orderby'] = 'post__in';
                         foreach ($sorted as $key => $value) {
                             $query['post__in'][] = $value->ID;
                         }
                     }
                     $query = apply_filters('wpcf_relationship_get_children_query', $query, $post, $post_type, $data, esc_attr($params['field']));
                     $items = get_posts($query);
                     /*
                      *
                      *
                      * Order by custom field
                      */
                 } else {
                     $field = wpcf_admin_fields_get_field(str_replace('wpcf-', '', $params['field']));
                     if (!empty($field)) {
                         $query['orderby'] = isset($field['type']) && in_array($field['type'], array('numeric', 'date')) ? 'meta_value_num' : 'meta_value';
                     }
                     $query = apply_filters('wpcf_relationship_get_children_query', $query, $post, $post_type, $data, esc_attr($params['field']));
                     $items = get_posts($query);
                     if (!empty($items)) {
                         $include = array();
                         $additional = array();
                         foreach ($items as $item) {
                             $meta = wpcf_get_post_meta($item->ID, 'wpcf-' . $field['slug'], true);
                             if (empty($meta)) {
                                 $additional[] = $item;
                                 continue;
                             }
                             $check = wpcf_cd_post_edit_field_filter(array(), $field, $item, 'post-relationship-sort');
                             if (isset($check['__wpcf_cd_status']) && $check['__wpcf_cd_status'] == 'failed') {
                                 $additional[] = $item;
                                 continue;
                             }
                             $key = $query['orderby'] == 'meta_value_num' ? intval($meta) : strval($meta);
                             $include[$key][] = $item;
                         }
                         if (!empty($include)) {
                             if ($query['orderby'] == 'meta_value_num') {
                                 ksort($include, SORT_NUMERIC);
                             } else {
                                 ksort($include, SORT_STRING);
                             }
                             if ($query['order'] == 'DESC') {
                                 $include = array_reverse($include);
                             }
                             $sorted = array();
                             foreach ($include as $meta_value => $posts) {
                                 foreach ($posts as $post) {
                                     $sorted[] = $post;
                                 }
                             }
                             $items = array_merge($sorted, $additional);
                         }
                     }
                 }
             }
         }
         /**
          *
          * Regular
          *
          */
     } else {
         $query = apply_filters('wpcf_relationship_get_children_query', $query, $post, $post_type, $data);
         $items = get_posts($query);
     }
     return $items;
 }
コード例 #7
0
ファイル: functions.php プロジェクト: CrankMaster336/FFW-TR
/**
 * Fix due to a bug saving date as array.
 * 
 * BUGS
 * 'timestamp' is saved without Hour and Minute appended.
 * 
 * @param type $value
 * @param type $field
 */
function __wpcf_fields_date_check_leftover($value, $field, $use_cache = true)
{
    if (empty($value)) {
        return $value;
    }
    if (!is_object($field)) {
        $post_id = wpcf_get_post_id();
        $field_id = isset($field['id']) ? $field['id'] : false;
        $meta_id = isset($field['__meta_id']) ? $field['__meta_id'] : false;
    } else {
        $post_id = isset($field->meta_object->post_id) ? $field->meta_object->post_id : false;
        $field_id = isset($field->cf['id']) ? $field->cf['id'] : false;
        $meta_id = isset($field->meta_object->meta_id) ? $field->meta_object->meta_id : false;
    }
    if (empty($post_id) || empty($meta_id) || empty($field_id)) {
        return $value;
    }
    $field_slug = wpcf_types_get_meta_prefix() . $field_id;
    // Check if cached
    static $cache = array();
    $cache_key = $meta_id;
    if (isset($cache[$cache_key]) && $use_cache) {
        return $cache[$cache_key];
    }
    $_meta = wpcf_get_post_meta($post_id, '_wpcf_' . $field_id . '_hour_and_minute', true);
    /*
     * If meta exists - it's outdated value
     * and Hour and Minute should be appended and removed.
     */
    if (!empty($_meta) && is_array($_meta) && isset($_meta[$meta_id])) {
        $meta = $_meta[$meta_id];
        // Return empty date if can not be calculated
        if (!empty($meta['timestamp']) || !empty($meta['datepicker'])) {
            $meta['timestamp'] = wpcf_fields_date_value_get_filter($meta, $field, 'timestamp', 'check_leftover');
            // Check if calculation needed
            if (isset($meta['hour']) && $meta['hour'] != adodb_date('H', $meta['timestamp']) || isset($meta['minute']) && $meta['minute'] != adodb_date('i', $meta['timestamp'])) {
                $value = wpcf_fields_date_calculate_time($meta);
                /*
                 * 
                 * If enabling clearing old values here,
                 * pay attention if field is repetitive.
                 * 
                 * For now - old data is cleared on date save.
                 * wpcf_fields_date_value_save_filter()
                 */
                // Update meta
                //                    $success = update_post_meta( $post_id, $field_slug, $value );
                // Remove additional meta
                //                    if ( $success ) {
                //                        delete_post_meta( $post_id,
                //                                '_wpcf_' . $field_id . '_hour_and_minute' );
                //                    }
            }
        }
    }
    // Cache it
    if ($use_cache) {
        $cache[$cache_key] = $value;
    }
    return $value;
}