/** * Parse a URL and find the host name and more. * * @since 1.1 * @deprecated 1.8.0 * @deprecated use WPSEO_Video_Analyse_Post::parse_url() * @see WPSEO_Video_Analyse_Post::parse_url * * @link http://php.net/manual/en/function.parse-url.php#83875 * * @param string $url The URL to parse * * @return array */ public function parse_url($url) { _deprecated_function(__METHOD__, 'Video SEO 1.8.0', 'WPSEO_Video_Analyse_Post::parse_url()'); return WPSEO_Video_Analyse_Post::parse_url($url); }
/** * Try and determine if a url refers to a local file. * * For relative urls, this method recurses onto itself while trying to find the file with a variety * of absolute versions of the relative url. * * @todo This one could do with some refactoring, but at least got it working ;-) * * @param string $url The url to test * * @return bool */ private function is_attachment_or_local_file($url) { static $uploads; static $site_url; static $network_url; static $search; static $extensions; // Set statics if (!isset($uploads)) { $uploads = wp_upload_dir(); } if (!isset($site_url)) { $site_url = preg_replace('`^http[s]?:`', '', site_url()); } if (!isset($network_url)) { if (is_multisite()) { $network_url = preg_replace('`^http[s]?:`', '', network_site_url()); } else { $network_url = false; } } if (!isset($search)) { $search = array($site_url . '/'); if (!empty($network_url)) { $search[] = $network_url . '/'; } } if (!isset($extensions)) { $extensions = explode('|', WPSEO_Video_Sitemap::$video_ext_pattern); } /** * Absolute url */ if (strpos($url, 'http') === 0 || strpos($url, '//') === 0) { $is_local = false; // Make it protocol relative so we don't have to worry about that $url = preg_replace('`^http[s]?:`', '', $url); $url = rtrim($url, '\\/'); // Is this a url on our site/network ? if (strpos($url, $site_url) === 0 || !empty($network_url) && strpos($url, $network_url) === 0) { $parsed_url = WPSEO_Video_Analyse_Post::parse_url($url); if ($parsed_url['file'] !== '') { $ext = strrchr($parsed_url['file'], '.'); if ($ext !== false && in_array(substr($ext, 1), $extensions, true)) { $base_url = preg_replace('`^http[s]?:`', '', $uploads['baseurl']); if (strpos($url, $base_url) === 0) { $this->file_path = str_replace($base_url, $uploads['basedir'], $url); } else { $this->file_path = str_replace($search, ABSPATH, $url); } if (file_exists($this->file_path)) { $this->file_url = 'http:' . $url; $is_local = true; } } elseif ($ext === false) { /* @internal At some point in the future we may want to switch this over to the attachment_url_to_postid( $url ) function which is introduced in WP 4.0 */ $path_parts = explode('/', trim($parsed_url['path'], '\\/')); $last_bit = array_pop($path_parts); $query_arg = array('post_status' => 'any', 'post_type' => 'attachment', 'name' => $last_bit); $query = new WP_Query($query_arg); if ($query->post_count === 1) { // ok, this is an id we can work with $this->attachment_id = $query->post->ID; $is_local = true; } else { // last ditch effort - can we find the file if we add an extension ? $base_url = preg_replace('`^http[s]?:`', '', $uploads['baseurl']); if (strpos($url, $base_url) === 0) { $file_path = str_replace($base_url, $uploads['basedir'], $url); } else { $file_path = str_replace($search, ABSPATH, $url); } foreach ($extensions as $extension) { if (file_exists($file_path . '.' . $extension)) { $this->file_path = $file_path . '.' . $extension; $this->file_url = 'http:' . $url . '.' . $extension; $is_local = true; break; } } } } } elseif ($parsed_url['query'] !== '') { parse_str($parsed_url['query'], $query); if (!empty($query['attachment_id'])) { $post_id = $query['attachment_id']; } elseif (!empty($query['p'])) { $post_id = $query['p']; } if (isset($post_id) && get_post_type($post_id) === 'attachment') { $this->attachment_id = $post_id; $is_local = true; } } } return $is_local; } else { if ($this->is_attachment_or_local_file(site_url($url)) === true) { return true; } elseif (is_multisite() && $this->is_attachment_or_local_file(network_site_url($url)) === true) { return true; } elseif ($this->is_attachment_or_local_file($uploads['baseurl'] . '/' . ltrim($url, '\\/')) === true) { return true; } elseif ($this->is_attachment_or_local_file($uploads['url'] . '/' . ltrim($url, '\\/')) === true) { return true; } elseif ($this->is_attachment_or_local_file(content_url($url)) === true) { return true; } elseif ($this->is_attachment_or_local_file(get_stylesheet_directory_uri() . '/' . ltrim($url, '\\/')) === true) { return true; } elseif ($this->is_attachment_or_local_file(get_template_directory_uri() . '/' . ltrim($url, '\\/')) === true) { return true; } elseif ($this->is_attachment_or_local_file(plugins_url($url)) === true) { return true; } else { return false; } } }