本文整理汇总了PHP中TimberURLHelper::is_external_content方法的典型用法代码示例。如果您正苦于以下问题:PHP TimberURLHelper::is_external_content方法的具体用法?PHP TimberURLHelper::is_external_content怎么用?PHP TimberURLHelper::is_external_content使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimberURLHelper
的用法示例。
在下文中一共展示了TimberURLHelper::is_external_content方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSubDirectoryImageLocaion
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);
}
示例2: testIsExternalContentMovingFolders
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;
}
示例3: _operate
/**
* 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;
}
}