function testSubDirectoryImageLocaion()
 {
     if (!is_multisite()) {
         $this->markTestSkipped('Test is only for Multisite');
         return;
     }
     $blog_id = TestTimberMultisite::createSubDirectorySite();
     $this->assertGreaterThan(1, $blog_id);
     $blog_details = get_blog_details($blog_id);
     $pretend_image = 'http://example.org/wp-content/2015/08/fake-pic.jpg';
     $is_external = TimberURLHelper::is_external_content($pretend_image);
     $this->assertFalse($is_external);
 }
Esempio n. 2
0
 function testIsExternalContentMovingFolders()
 {
     $internal = 'http://example.org/wp-content/uploads/my-image.png';
     $internal_in_abspath = 'http://example.org/wp/uploads/my-image.png';
     $internal_in_uploads = 'http://example.org/uploads/my-image.png';
     $external = 'http://upstatement.com/my-image.png';
     add_filter('upload_dir', array(&$this, 'mockUploadDir'));
     add_filter('content_url', array(&$this, 'mockContentUrl'));
     $this->mockUploadDir = true;
     $this->assertFalse(TimberURLHelper::is_external_content($internal));
     $this->assertFalse(TimberURLHelper::is_external_content($internal_in_uploads));
     $this->assertFalse(TimberURLHelper::is_external_content($internal_in_abspath));
     $this->assertTrue(TimberURLHelper::is_external_content($external));
     $this->mockUploadDir = false;
 }
Esempio n. 3
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 '';
     }
     // if external image, load it first
     if (TimberURLHelper::is_external_content($src)) {
         $src = self::sideload_image($src);
     }
     // 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']);
     // 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)) {
         return $new_url;
     } else {
         // in case of error, we return source file itself
         return $src;
     }
 }