/** * Analyse a video shortcode from the plugin for usable video information * * @param string $full_shortcode Full shortcode as found in the post content * @param string $sc Shortcode found * @param array $atts Shortcode attributes - already decoded if needed * @param string $content The shortcode content, i.e. the bit between [sc]content[/sc] * * @return array An array with the usable information found or else an empty array */ public function get_info_from_shortcode($full_shortcode, $sc, $atts = array(), $content = '') { $vid = array(); $validated_int = WPSEO_Video_Wrappers::yoast_wpseo_video_validate_int($atts['id']); if (isset($atts['id']) && !empty($atts['id']) && $validated_int !== false) { $vid = $this->get_info_for_post_type((int) $atts['id'], 'flowplayer5', null, true); } else { // Old flowplayer shortcode format if (isset($atts['webm']) && (is_string($atts['webm']) && $atts['webm'] !== '')) { $vid['url'] = $atts['webm']; } elseif (isset($atts['mp4']) && (is_string($atts['mp4']) && $atts['mp4'] !== '')) { $vid['url'] = $atts['mp4']; } elseif (isset($atts['ogg']) && (is_string($atts['ogg']) && $atts['ogg'] !== '')) { $vid['url'] = $atts['ogg']; } if (isset($vid['url'])) { $vid['content_loc'] = $vid['url']; $vid['maybe_local'] = true; if (isset($atts['splash']) && (is_string($atts['splash']) && $atts['splash'] !== '')) { $vid['thumbnail_loc'] = $atts['splash']; } $vid['type'] = 'flowplayer'; $vid = $this->maybe_get_dimensions($vid, $atts, true); } } return $vid; }
/** * Analyse a video shortcode from the plugin for usable video information * * @param string $full_shortcode Full shortcode as found in the post content * @param string $sc Shortcode found * @param array $atts Shortcode attributes - already decoded if needed * @param string $content The shortcode content, i.e. the bit between [sc]content[/sc] * * @return array An array with the usable information found or else an empty array */ public function get_info_from_shortcode($full_shortcode, $sc, $atts = array(), $content = '') { $vid = array(); if (isset($atts['mediaid'])) { $mediaid = WPSEO_Video_Wrappers::yoast_wpseo_video_validate_int($atts['mediaid']); if ($mediaid !== false && $mediaid > 0) { $content_loc = wp_get_attachment_url($mediaid); // @todo should we maybe use JWP6_Plugin::url_from_post( $mediaid ) to stay in line ? if ($content_loc !== false) { $vid['content_loc'] = $content_loc; } $duration = get_post_meta($mediaid, 'jwplayermodule_duration', true); if ($duration !== '') { $vid['duration'] = $duration; } $thumbnail_loc = get_post_meta($mediaid, 'jwplayermodule_thumbnail_url', true); if ($thumbnail_loc !== '') { $vid['thumbnail_loc'] = $thumbnail_loc; } } unset($mediaid, $content_loc, $duration, $thumbnail_loc); } // @todo [JRF] Does this really belong with this plugin ? can't find documentation for this plugin on the html5_file or file attributes if (!isset($vid['content_loc'])) { if (isset($atts['html5_file']) && (is_string($atts['html5_file']) && $atts['html5_file'] !== '')) { $vid['content_loc'] = $atts['html5_file']; } elseif (isset($atts['file']) && (is_string($atts['file']) && $atts['file'] !== '')) { $vid['content_loc'] = $atts['file']; } if (isset($vid['content_loc'], $atts['image']) && (is_string($atts['image']) && $atts['image'] !== '')) { $vid['thumbnail_loc'] = $atts['image']; } } if ($vid !== array()) { $vid['type'] = 'jwplayer'; // @todo - should this be added ? or should we believe the jwplayer plugin info to be good enough (though incomplete) ? //$vid['url'] = $vid['content_loc']; //$vid['maybe_local'] = true; $vid = $this->maybe_get_dimensions($vid, $atts); } return $vid; }
/** * Validate the option * * @param array $dirty New value for the option * @param array $clean Clean value for the option, normally the defaults * @param array $old Old value of the option * * @return array Validated clean value for the option to be saved to the database */ protected function validate_option($dirty, $clean, $old) { foreach ($clean as $key => $value) { switch ($key) { case 'dbversion': $clean[$key] = WPSEO_VIDEO_VERSION; break; case 'videositemap_posttypes': $clean[$key] = array(); $valid_post_types = get_post_types(array('public' => true)); if (isset($dirty[$key]) && (is_array($dirty[$key]) && $dirty[$key] !== array())) { foreach ($dirty[$key] as $k => $v) { if (in_array($k, $valid_post_types, true)) { $clean[$key][$k] = $v; } elseif (sanitize_title_with_dashes($k) === $k) { // Allow post types which may not be registered yet $clean[$key][$k] = $v; } } } break; case 'videositemap_taxonomies': $clean[$key] = array(); $valid_taxonomies = get_taxonomies(array('public' => true)); if (isset($dirty[$key]) && (is_array($dirty[$key]) && $dirty[$key] !== array())) { foreach ($dirty[$key] as $k => $v) { if (in_array($k, $valid_taxonomies, true)) { $clean[$key][$k] = $v; } elseif (sanitize_title_with_dashes($k) === $k) { // Allow taxonomies which may not be registered yet $clean[$key][$k] = $v; } } } break; /* text field - may not be in form */ /* @todo - validate custom fields against meta table ? */ /* text field - may not be in form */ /* @todo - validate custom fields against meta table ? */ case 'custom_fields': if (isset($dirty[$key]) && $dirty[$key] !== '') { $clean[$key] = sanitize_text_field($dirty[$key]); } break; /* @todo - validate domains in some way ? */ /* @todo - validate domains in some way ? */ case 'vzaar_domain': case 'wistia_domain': if (isset($dirty[$key]) && $dirty[$key] !== '') { $clean[$key] = sanitize_text_field(urldecode($dirty[$key])); $clean[$key] = preg_replace(array('`^http[s]?://`', '`^//`', '`/$`'), '', $clean[$key]); } break; case 'embedly_api_key': if (isset($dirty[$key]) && $dirty[$key] !== '' && preg_match('`^[a-f0-9]{32}$`', $dirty[$key])) { $clean[$key] = sanitize_text_field($dirty[$key]); } break; /* numeric text field - may not be in form */ /* numeric text field - may not be in form */ case 'content_width': if (isset($dirty[$key]) && $dirty[$key] !== '') { $int = WPSEO_Video_Wrappers::yoast_wpseo_video_validate_int($dirty[$key]); if ($int !== false && $int > 0) { $clean[$key] = $int; } } break; /* boolean (checkbox) field - may not be in form */ /* boolean (checkbox) field - may not be in form */ case 'cloak_sitemap': case 'disable_rss': case 'facebook_embed': case 'fitvids': if (isset($dirty[$key])) { $clean[$key] = WPSEO_Video_Wrappers::validate_bool($dirty[$key]); } else { $clean[$key] = false; } break; } } return $clean; }
/** * 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; }