Example #1
0
 public static function set_statics()
 {
     // Reset just in case this method is called more than once (like when we're testing)
     self::reset_statics();
     if (extension_loaded('dom') && class_exists('domxpath')) {
         self::$dom_enabled = true;
     }
     /**
      * Add WP core to 'active plugins' as the first (highest prio) item
      * Add this plugin as the second
      */
     self::$active_plugins['wp_core'] = new WPSEO_Video_Support_Core();
     self::$active_plugins['videoseo'] = new WPSEO_Video_Plugin_Yoast_Videoseo();
     //self::$active_plugins['premise']  = new WPSEO_Video_Plugin_Premise;
     //self::$active_plugins['weaver6']  = new WPSEO_Video_Plugin_Weaver;
     /* @todo It might be better if we can figure out if the plugin is installed rather than active
     			Also - this will give issues with plugins in the mu-plugins directory as is_plugin_active()
     			incorrectly returns false (should be fixed in WP4 ?) */
     if (!function_exists('is_plugin_active')) {
         require_once ABSPATH . 'wp-admin/includes/plugin.php';
     }
     foreach (self::$supported_plugins as $name => $plugin_basename) {
         if (is_plugin_active($plugin_basename)) {
             $classname = 'WPSEO_Video_Plugin_' . $name;
             self::$active_plugins[$name] = new $classname();
         }
     }
     unset($name, $plugin_basename, $classname);
     /* Add the plugin features for all active plugins */
     if (is_array(self::$active_plugins) && self::$active_plugins !== array()) {
         foreach (self::$active_plugins as $name => $instance) {
             // Add known shortcodes
             $shortcodes = $instance->get_shortcodes();
             if (is_array($shortcodes) && $shortcodes !== array()) {
                 foreach ($shortcodes as $sc) {
                     self::$shortcodes[$sc][] = array($instance, 'get_info_from_shortcode');
                 }
             }
             unset($shortcodes, $sc);
             // Add known additional post_types
             $post_types = $instance->get_post_types();
             if (is_array($post_types) && $post_types !== array()) {
                 foreach ($post_types as $pt) {
                     self::$post_types[$pt][] = array($instance, 'get_info_for_post_type');
                 }
             }
             unset($post_types, $pt);
             /*
             // Add known additional post_formats
             $post_formats = $instance->get_post_formats();
             if ( is_array( $post_formats ) && $post_formats !== array() ) {
             	foreach ( $post_formats as $format ) {
             		self::$post_formats[ $format ][] = array( $instance, 'get_info_for_post_format' );
             	}
             }
             unset( $post_formats, $format );
             */
             // Add known additional meta_keys
             $meta_keys = $instance->get_meta_keys();
             if (is_array($meta_keys) && $meta_keys !== array()) {
                 foreach ($meta_keys as $key) {
                     self::$meta_keys[$key][] = array($instance, 'get_info_from_post_meta');
                 }
             }
             unset($meta_keys, $key);
             // Add alternative protocols
             $alt_protocols = $instance->get_alt_protocols();
             if (is_array($alt_protocols) && $alt_protocols !== array()) {
                 self::$alt_protocols = array_unique(array_merge(self::$alt_protocols, $alt_protocols));
             }
             unset($alt_protocols);
             // Add autoembed information
             $video_autoembeds = $instance->get_video_autoembeds();
             if (is_array($video_autoembeds) && $video_autoembeds !== array()) {
                 /* @internal merge order reversed, if there is a handler name conflict between plugins,
                    defer to the the more popular plugin which will have been added first. */
                 self::$video_autoembeds = array_unique(array_merge($video_autoembeds, self::$video_autoembeds));
             }
             unset($video_autoembeds);
             // Add oembed information
             $video_oembeds = $instance->get_video_oembeds();
             if (is_array($video_oembeds) && $video_oembeds !== array()) {
                 /* @internal merge order reversed, if there is a handler name conflict between plugins,
                    defer to the the more popular plugin which will have been added first. */
                 self::$video_oembeds = array_unique(array_merge($video_oembeds, self::$video_oembeds));
             }
             unset($video_oembeds);
         }
         unset($name, $instance);
     }
 }
 /**
  * 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);
 }
Example #3
0
 /**
  * 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;
         }
     }
 }