本文整理汇总了PHP中TimberURLHelper::get_rel_path方法的典型用法代码示例。如果您正苦于以下问题:PHP TimberURLHelper::get_rel_path方法的具体用法?PHP TimberURLHelper::get_rel_path怎么用?PHP TimberURLHelper::get_rel_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimberURLHelper
的用法示例。
在下文中一共展示了TimberURLHelper::get_rel_path方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sideload_image
/**
* downloads an external image to the server and stores it on the server
*
* @param string $file the URL to the original file
* @return string the URL to the downloaded file
*/
public static function sideload_image($file)
{
$loc = self::get_sideloaded_file_loc($file);
if (file_exists($loc)) {
return TimberURLHelper::preslashit(TimberURLHelper::get_rel_path($loc));
}
// Download file to temp location
if (!function_exists('download_url')) {
require_once ABSPATH . '/wp-admin/includes/file.php';
}
$tmp = download_url($file);
preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $file, $matches);
$file_array = array();
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
// If error storing temporarily, unlink
if (is_wp_error($tmp)) {
@unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
// do the validation and storage stuff
$locinfo = pathinfo($loc);
$file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name']));
return $file['url'];
}
示例2: testInitFromURL
function testInitFromURL()
{
$destination_path = self::copyTestImage();
$destination_path = TimberURLHelper::get_rel_path($destination_path);
$destination_url = 'http://' . $_SERVER['HTTP_HOST'] . $destination_path;
$image = new TimberImage($destination_url);
$this->assertEquals($destination_url, $image->get_src());
$this->assertEquals($destination_url, (string) $image);
}
示例3: testImageWidthWithFilter
function testImageWidthWithFilter()
{
$pid = $this->factory->post->create();
$photo = $this->copyTestImage();
$photo = TimberURLHelper::get_rel_path($photo);
update_post_meta($pid, 'custom_photo', '/' . $photo);
$str = '{{TimberImage(post.custom_photo).width}}';
$post = new TimberPost($pid);
$rendered = Timber::compile_string($str, array('post' => $post));
$this->assertEquals(1500, $rendered);
}
示例4: get_rel_path
/**
* @deprecated
*/
static function get_rel_path($src)
{
return TimberURLHelper::get_rel_path($src);
}
示例5: path
/**
* @api
* @example
* ```twig
* <img src="{{ image.path }}" />
* ```
* ```html
* <img src="/wp-content/uploads/2015/08/pic.jpg" />
* ```
* @return string the /relative/path/to/the/file
*/
public function path()
{
return TimberURLHelper::get_rel_path($this->src());
}