Exemplo n.º 1
0
 /**
  * Sanitize the video duration post meta
  *
  * @static
  *
  * @param  mixed  $clean      Potentially pre-cleaned version of the new meta value
  * @param  mixed  $meta_value The new value
  * @param  string $field_def  The field definition for the current meta field
  *
  * @return string             Cleaned value
  */
 public static function sanitize_duration($clean, $meta_value, $field_def)
 {
     $field_def = WPSEO_Meta::get_meta_field_defs('video');
     $field_def = $field_def['videositemap-duration'];
     $clean = $field_def['default_value'];
     $int = WPSEO_Video_Wrappers::yoast_wpseo_video_validate_int($meta_value);
     if ($int !== false && $int > 0) {
         $clean = strval($int);
     }
     return $clean;
 }
 /**
  * Defines the meta box inputs
  *
  * @since      0.1
  * @deprecated 1.6.0
  * @deprecated use WPSEO_Meta::get_meta_field_defs()
  * @see        WPSEO_Meta::get_meta_field_defs()
  *
  * @param string $post_type The current post type
  *
  * @return array            Meta box inputs
  */
 public function get_meta_boxes($post_type = 'post')
 {
     _deprecated_function(__METHOD__, 'Video SEO 1.6.0', 'WPSEO_Meta::get_meta_field_defs()');
     return WPSEO_Meta::get_meta_field_defs('video', $post_type);
 }
Exemplo n.º 3
0
    function map_to_dropdown()
    {
        global $wpdb;
        $dont_allow = array('_wp_attachment_image_alt', '_wp_attachment_metadata', '_wp_attached_file', '_edit_lock', '_edit_last', '_wp_page_template');
        $html = '
			<li data-post-type="all" class="live_filter">
				<input type="text" class="live_filter" placeholder="' . esc_attr($this->__('Search... ')) . '" />
			</li>';
        $field_groups = array();
        $supports_custom = array();
        $yoast_field_type_array = array('text', 'textarea', 'select', 'upload', 'radio', 'multiselect');
        $yoast = false;
        if (function_exists('wpseo_admin_init')) {
            $this->_initialize_yoast();
            $yoast = true;
        }
        $yoast_prefix = '_yoast_wpseo_';
        $yoast_fields = array();
        foreach ($this->post_types as $name => $title) {
            $supports = get_all_post_type_supports($name);
            if (isset($supports['custom-fields'])) {
                $supports_custom[] = $name;
            }
            if ($name == 'attachment') {
                $html .= '
			<li data-post-type="|attachment|" data-search="' . esc_attr($this->__('Title')) . '">
				<a href="#" data-value="post_title">' . $this->__('Title') . '</a>
			</li>
			<li data-post-type="|attachment|" data-search="' . esc_attr($this->__('Caption')) . '">
				<a href="#" data-value="post_excerpt">' . $this->__('Caption') . '</a>
			</li>
			<li data-post-type="|attachment|" data-search="' . esc_attr($this->__('Description')) . '">
				<a href="#" data-value="post_content">' . $this->__('Description') . '</a>
			</li>
			<li data-post-type="|attachment|" data-search="' . esc_attr($this->__('Alt Text')) . '">
				<a href="#" data-value="_wp_attachment_image_alt">' . $this->__('Alt Text') . '</a>
			</li>';
            } else {
                $labels = array('title' => sprintf($this->__('%s Title'), $title), 'editor' => sprintf($this->__('%s Content'), $title), 'excerpt' => sprintf($this->__('%s Excerpt'), $title), 'thumbnail' => $this->__('Featured Image'), 'tags' => $this->__('Tags'), 'cats' => $this->__('Category'), 'author' => $this->__('Author'));
                $fields = array('editor' => 'post_content', 'title' => 'post_title', 'excerpt' => 'post_excerpt', 'thumbnail' => 'gc_featured_image_', 'author' => 'post_author');
                foreach ($fields as $type => $fieldname) {
                    if (isset($supports[$type])) {
                        $html .= '
			<li data-post-type="|' . $name . '|" data-search="' . esc_attr($labels[$type]) . '">
				<a href="#" data-value="' . $fieldname . '">' . esc_html($labels[$type]) . '</a>
			</li>';
                    }
                }
                if (count($this->taxonomies[$name]) > 0) {
                    $html .= '
			<li data-post-type="|' . $name . '|" data-search="' . esc_attr($labels['cats']) . '">
				<a href="#" data-value="gc_post_cat_">' . esc_html($labels['cats']) . '</a>
			</li>';
                }
                if (isset($this->allows_tags[$name])) {
                    $html .= '
			<li data-post-type="|' . $name . '|" data-search="' . esc_attr($labels['tags']) . '">
				<a href="#" data-value="gc_post_tags_">' . esc_html($labels['tags']) . '</a>
			</li>';
                }
            }
            if ($this->has_acf) {
                $acf = $this->_acf_get_field_groups(array('post_type' => $name));
                foreach ($acf as $post_id) {
                    if (!isset($field_groups[$post_id])) {
                        $field_groups[$post_id] = array('types' => array(), 'posts' => array());
                    }
                    $field_groups[$post_id]['types'][] = $name;
                    $field_groups[$post_id]['posts'][] = 0;
                }
                foreach ($this->page_ids[$name] as $page_id) {
                    $acf = $this->_acf_get_field_groups(array('post_id' => $page_id));
                    foreach ($acf as $post_id) {
                        if (!isset($field_groups[$post_id])) {
                            $field_groups[$post_id] = array('posts' => array());
                        } elseif (!isset($field_groups[$post_id]['posts'])) {
                            $field_groups[$post_id]['posts'] = array();
                        }
                        $field_groups[$post_id]['posts'][] = $page_id;
                    }
                }
            }
            if ($yoast) {
                $meta_boxes = array_merge(WPSEO_Meta::get_meta_field_defs('general', $name), WPSEO_Meta::get_meta_field_defs('advanced'), apply_filters('wpseo_save_metaboxes', array()));
                foreach ($meta_boxes as $field_name => $meta_box) {
                    if (in_array($meta_box['type'], $yoast_field_type_array)) {
                        $yoast_fields[$yoast_prefix . $field_name] = true;
                        $html .= '
			<li data-post-type="|' . $name . '|" data-search="' . esc_attr($meta_box['title']) . '">
				<a href="#" data-value="' . $yoast_prefix . esc_attr($field_name) . '">' . esc_html($meta_box['title']) . '</a>
			</li>';
                    }
                }
            }
        }
        foreach ($field_groups as $id => $options) {
            $options['posts'] = array_unique($options['posts']);
            if ($this->acf_pro) {
                $fields = acf_get_fields($id);
            } else {
                $fields = apply_filters('acf/field_group/get_fields', array(), $id);
            }
            foreach ($fields as $field) {
                $dont_allow[] = $field['key'];
                $text = $field['label'];
                if (strlen($text) > 30) {
                    $text = substr($text, 0, 30) . '...';
                }
                $ext = '';
                if (isset($options['types']) && count($options['types']) > 0) {
                    $ext .= ' data-acf-post-types="|' . implode('|', $options['types']) . '|"';
                }
                if (isset($options['posts']) && count($options['posts']) > 0) {
                    $ext .= ' data-acf-post-ids="|' . implode('|', $options['posts']) . '|"';
                }
                $html .= '
			<li data-post-type="all" class="acf-row" data-search="' . esc_attr($field['label']) . '"' . $ext . '>
				<a href="#" data-value="' . esc_attr($field['name']) . '" data-acf-post="' . esc_attr($id) . '" data-acf-field="' . esc_attr($field['key']) . '" title="' . esc_attr($field['label']) . '" class="acf-field">' . esc_html($text) . '</a>
			</li>';
            }
        }
        if ($yoast) {
            $yoast_fields[$yoast_prefix . 'linkdex'] = true;
            $dont_allow = array_merge($dont_allow, array_keys($yoast_fields));
        }
        $dont_allow = "'" . implode("','", $dont_allow) . "'";
        $keys = $wpdb->get_col("SELECT meta_key FROM {$wpdb->postmeta} WHERE meta_key NOT IN({$dont_allow}) GROUP BY meta_key ORDER BY meta_key");
        $supports_custom = '|' . implode('|', $supports_custom) . '|';
        if ($keys) {
            natcasesort($keys);
            foreach ($keys as $key) {
                $text = $key;
                if (strlen($key) > 30) {
                    $text = substr($key, 0, 30) . '...';
                }
                $html .= '
			<li data-post-type="' . $supports_custom . '" class="custom-field" data-search="' . esc_attr($key) . '">
				<a href="#" data-value="' . esc_attr($key) . '" title="' . esc_attr($key) . '">' . esc_html($text) . '</a>
			</li>';
            }
        }
        $html .= '
			<li data-post-type="' . $supports_custom . '" data-search="' . $this->__('New Custom Field') . '">
				<a href="#" data-value="_new_custom_field_">' . $this->__('New Custom Field') . '</a>
			</li>
			<li class="divider" data-post-type="all"></li>
			<li data-post-type="all" data-search="' . $this->__('Do Not Import') . '">
				<a href="#" data-value="_dont_import_">' . $this->__('Do Not Import') . '</a>
			</li>';
        $this->data['map_to_select'] = $html;
    }