is_external_content() public static method

This function is slightly different from the one below in the case of: an image hosted on the same domain BUT on a different site than the Wordpress install will be reported as external content.
public static is_external_content ( string $url ) : boolean
$url string a URL to evaluate against
return boolean if $url points to an external location returns true
Ejemplo n.º 1
0
 /**
  * Main method that applies operation to src image:
  * 1. break down supplied URL into components
  * 2. use components to determine result file and URL
  * 3. check if a result file already exists
  * 4. otherwise, delegate to supplied TimberImageOperation
  *
  * @param  string  $src   an URL (absolute or relative) to an image
  * @param  object  $op    object of class TimberImageOperation
  * @param  boolean $force if true, remove any already existing result file and forces file generation
  * @return string         URL to the new image - or the source one if error
  *
  */
 private static function _operate($src, $op, $force = false)
 {
     if (empty($src)) {
         return '';
     }
     $external = false;
     // if external image, load it first
     if (URLHelper::is_external_content($src)) {
         $src = self::sideload_image($src);
         $external = true;
     }
     // break down URL into components
     $au = self::analyze_url($src);
     // build URL and filenames
     $new_url = self::_get_file_url($au['base'], $au['subdir'], $op->filename($au['filename'], $au['extension']), $au['absolute']);
     $new_server_path = self::_get_file_path($au['base'], $au['subdir'], $op->filename($au['filename'], $au['extension']));
     $old_server_path = self::_get_file_path($au['base'], $au['subdir'], $au['basename']);
     $new_url = apply_filters('timber/image/new_url', $new_url);
     $new_server_path = apply_filters('timber/image/new_path', $new_server_path);
     // if already exists...
     if (file_exists($new_server_path)) {
         if ($force) {
             // Force operation - warning: will regenerate the image on every pageload, use for testing purposes only!
             unlink($new_server_path);
         } else {
             // return existing file (caching)
             return $new_url;
         }
     }
     // otherwise generate result file
     if ($op->run($old_server_path, $new_server_path)) {
         if (get_class($op) === 'Timber\\Image\\Operation\\Resize' && $external) {
             $new_url = strtolower($new_url);
         }
         return $new_url;
     } else {
         // in case of error, we return source file itself
         return $src;
     }
 }