当前位置: 首页>>代码示例>>PHP>>正文


PHP TimberURLHelper类代码示例

本文整理汇总了PHP中TimberURLHelper的典型用法代码示例。如果您正苦于以下问题:PHP TimberURLHelper类的具体用法?PHP TimberURLHelper怎么用?PHP TimberURLHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TimberURLHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_retina_file_path

 /**
  * @param string $src
  * @param int $w
  * @param int $h
  * @param string $crop
  * @return string
  */
 static function get_retina_file_path($src, $mult = 2)
 {
     $new_name = self::get_retina_file_name_relative_to_content($src, $mult);
     $new_server_path = WP_CONTENT_DIR . $new_name;
     $new_server_path = TimberURLHelper::remove_double_slashes($new_server_path);
     return $new_server_path;
 }
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:14,代码来源:timber-image-retina-helper.php

示例2: get_archives_link

 /**
  * @internal
  * @param string $url
  * @param string $text
  * @return mixed
  */
 protected function get_archives_link($url, $text)
 {
     $ret = array();
     $ret['text'] = $ret['title'] = $ret['name'] = wptexturize($text);
     $ret['url'] = $ret['link'] = esc_url(TimberURLHelper::prepend_to_url($url, $this->base));
     return $ret;
 }
开发者ID:sdunham,项目名称:sustainable,代码行数:13,代码来源:timber-archives.php

示例3: testGetParams

 function testGetParams()
 {
     $_SERVER['REQUEST_URI'] = 'http://example.org/blog/post/news/2014/whatever';
     $params = TimberURLHelper::get_params();
     $this->assertEquals(7, count($params));
     $whatever = TimberURLHelper::get_params(-1);
     $blog = TimberURLHelper::get_params(2);
     $this->assertEquals('whatever', $whatever);
     $this->assertEquals('blog', $blog);
 }
开发者ID:hamedb89,项目名称:wp-theme-boilerplate,代码行数:10,代码来源:test-timber-url-helper.php

示例4: 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);
 }
开发者ID:Butterwell,项目名称:timber,代码行数:13,代码来源:test-timber-image-multisite.php

示例5: get_rel_url

 /**
  * @param string $url
  * @param bool $force
  * @return string
  */
 public static function get_rel_url($url, $force = false)
 {
     $url_info = parse_url($url);
     if (isset($url_info['host']) && $url_info['host'] != $_SERVER['HTTP_HOST'] && !$force) {
         return $url;
     }
     $link = '';
     if (isset($url_info['path'])) {
         $link = $url_info['path'];
     }
     if (isset($url_info['query']) && strlen($url_info['query'])) {
         $link .= '?' . $url_info['query'];
     }
     if (isset($url_info['fragment']) && strlen($url_info['fragment'])) {
         $link .= '#' . $url_info['fragment'];
     }
     $link = TimberURLHelper::remove_double_slashes($link);
     return $link;
 }
开发者ID:Kilbourne,项目名称:restart,代码行数:24,代码来源:timber-url-helper.php

示例6: analyze_url

 /**
  * Takes in an URL and breaks it into components,
  * that will then be used in the different steps of image processing.
  * The image is expected to be either part of a theme, plugin, or an upload.
  *
  * @param  string $url an URL (absolute or relative) pointing to an image
  * @return array       an array (see keys in code below)
  */
 private static function analyze_url($url)
 {
     $result = array('url' => $url, 'absolute' => TimberURLHelper::is_absolute($url), 'base' => 0, 'subdir' => '', 'filename' => '', 'extension' => '', 'basename' => '');
     $upload_dir = wp_upload_dir();
     $tmp = $url;
     if (0 === strpos($tmp, ABSPATH)) {
         // we've been given a dir, not an url
         $result['absolute'] = true;
         if (0 === strpos($tmp, $upload_dir['basedir'])) {
             $result['base'] = self::BASE_UPLOADS;
             // upload based
             $tmp = str_replace($upload_dir['basedir'], '', $tmp);
         }
         if (0 === strpos($tmp, WP_CONTENT_DIR)) {
             $result['base'] = self::BASE_CONTENT;
             // content based
             $tmp = str_replace(WP_CONTENT_DIR, '', $tmp);
         }
     } else {
         if (!$result['absolute']) {
             $tmp = home_url() . $tmp;
         }
         if (0 === strpos($tmp, $upload_dir['baseurl'])) {
             $result['base'] = self::BASE_UPLOADS;
             // upload based
             $tmp = str_replace($upload_dir['baseurl'], '', $tmp);
         }
         if (0 === strpos($tmp, content_url())) {
             $result['base'] = self::BASE_CONTENT;
             // content-based
             $tmp = str_replace(content_url(), '', $tmp);
         }
     }
     $parts = pathinfo($tmp);
     $result['subdir'] = $parts['dirname'];
     $result['filename'] = $parts['filename'];
     $result['extension'] = $parts['extension'];
     $result['basename'] = $parts['basename'];
     // todo filename
     return $result;
 }
开发者ID:Kilbourne,项目名称:restart,代码行数:49,代码来源:timber-image-helper.php

示例7: get_context

 /**
  * Get context.
  *
  * @return array
  */
 public static function get_context()
 {
     $data = array();
     $data['http_host'] = 'http://' . TimberURLHelper::get_host();
     $data['wp_title'] = TimberHelper::get_wp_title();
     $data['wp_head'] = TimberHelper::function_wrapper('wp_head');
     $data['wp_footer'] = TimberHelper::function_wrapper('wp_footer');
     $data['body_class'] = implode(' ', get_body_class());
     $data['site'] = new TimberSite();
     $data['theme'] = $data['site']->theme;
     //deprecated, these should be fetched via TimberSite or TimberTheme
     $data['theme_dir'] = WP_CONTENT_SUBDIR . str_replace(WP_CONTENT_DIR, '', get_stylesheet_directory());
     $data['language_attributes'] = TimberHelper::function_wrapper('language_attributes');
     $data['stylesheet_uri'] = get_stylesheet_uri();
     $data['template_uri'] = get_template_directory_uri();
     $data['posts'] = Timber::query_posts();
     //deprecated, this should be fetched via TimberMenu
     if (function_exists('wp_nav_menu')) {
         $locations = get_nav_menu_locations();
         if (count($locations)) {
             $data['wp_nav_menu'] = wp_nav_menu(array('container_class' => 'menu-header', 'echo' => false, 'menu_class' => 'nav-menu'));
         }
     }
     $data = apply_filters('timber_context', $data);
     $data = apply_filters('timber/context', $data);
     return $data;
 }
开发者ID:Butterwell,项目名称:timber,代码行数:32,代码来源:timber.php

示例8: 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);
 }
开发者ID:aauroux,项目名称:timber,代码行数:9,代码来源:test-timber-image.php

示例9: path

 /**
  * @api
  * @return  string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`)
  */
 public function path()
 {
     return TimberURLHelper::get_rel_url($this->link());
 }
开发者ID:Butterwell,项目名称:timber,代码行数:8,代码来源:timber-theme.php

示例10: add_timber_filters

 /**
  *
  *
  * @param Twig_Environment $twig
  * @return Twig_Environment
  */
 function add_timber_filters($twig)
 {
     /* image filters */
     $twig->addFilter(new Twig_SimpleFilter('resize', array('TimberImageHelper', 'resize')));
     $twig->addFilter(new Twig_SimpleFilter('retina', array('TimberImageHelper', 'retina_resize')));
     $twig->addFilter(new Twig_SimpleFilter('letterbox', array('TimberImageHelper', 'letterbox')));
     $twig->addFilter(new Twig_SimpleFilter('tojpg', array('TimberImageHelper', 'img_to_jpg')));
     /* debugging filters */
     $twig->addFilter(new Twig_SimpleFilter('docs', 'twig_object_docs'));
     $twig->addFilter(new Twig_SimpleFilter('get_class', 'get_class'));
     $twig->addFilter(new Twig_SimpleFilter('get_type', 'get_type'));
     $twig->addFilter(new Twig_SimpleFilter('print_r', function ($arr) {
         return print_r($arr, true);
     }));
     $twig->addFilter(new Twig_SimpleFilter('print_a', function ($arr) {
         return '<pre>' . self::object_docs($arr, true) . '</pre>';
     }));
     /* other filters */
     $twig->addFilter(new Twig_SimpleFilter('stripshortcodes', 'strip_shortcodes'));
     $twig->addFilter(new Twig_SimpleFilter('array', array($this, 'to_array')));
     $twig->addFilter(new Twig_SimpleFilter('excerpt', 'wp_trim_words'));
     $twig->addFilter(new Twig_SimpleFilter('function', array($this, 'exec_function')));
     $twig->addFilter(new Twig_SimpleFilter('pretags', array($this, 'twig_pretags')));
     $twig->addFilter(new Twig_SimpleFilter('sanitize', 'sanitize_title'));
     $twig->addFilter(new Twig_SimpleFilter('shortcodes', 'do_shortcode'));
     $twig->addFilter(new Twig_SimpleFilter('time_ago', array($this, 'time_ago')));
     $twig->addFilter(new Twig_SimpleFilter('wpautop', 'wpautop'));
     $twig->addFilter(new Twig_SimpleFilter('relative', function ($link) {
         return TimberURLHelper::get_rel_url($link, true);
     }));
     $twig->addFilter(new Twig_SimpleFilter('date', array($this, 'intl_date')));
     $twig->addFilter(new Twig_SimpleFilter('truncate', function ($text, $len) {
         return TimberHelper::trim_words($text, $len);
     }));
     /* actions and filters */
     $twig->addFunction(new Twig_SimpleFunction('action', function ($context) {
         $args = func_get_args();
         array_shift($args);
         $args[] = $context;
         call_user_func_array('do_action', $args);
     }, array('needs_context' => true)));
     $twig->addFilter(new Twig_SimpleFilter('apply_filters', function () {
         $args = func_get_args();
         $tag = current(array_splice($args, 1, 1));
         return apply_filters_ref_array($tag, $args);
     }));
     $twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function')));
     $twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function')));
     $twig->addFunction(new Twig_SimpleFunction('shortcode', 'do_shortcode'));
     /* TimberObjects */
     $twig->addFunction(new Twig_SimpleFunction('TimberPost', function ($pid, $PostClass = 'TimberPost') {
         if (is_array($pid) && !TimberHelper::is_array_assoc($pid)) {
             foreach ($pid as &$p) {
                 $p = new $PostClass($p);
             }
             return $pid;
         }
         return new $PostClass($pid);
     }));
     $twig->addFunction(new Twig_SimpleFunction('TimberImage', function ($pid, $ImageClass = 'TimberImage') {
         if (is_array($pid) && !TimberHelper::is_array_assoc($pid)) {
             foreach ($pid as &$p) {
                 $p = new $ImageClass($p);
             }
             return $pid;
         }
         return new $ImageClass($pid);
     }));
     $twig->addFunction(new Twig_SimpleFunction('TimberTerm', function ($pid, $TermClass = 'TimberTerm') {
         if (is_array($pid) && !TimberHelper::is_array_assoc($pid)) {
             foreach ($pid as &$p) {
                 $p = new $TermClass($p);
             }
             return $pid;
         }
         return new $TermClass($pid);
     }));
     $twig->addFunction(new Twig_SimpleFunction('TimberUser', function ($pid, $UserClass = 'TimberUser') {
         if (is_array($pid) && !TimberHelper::is_array_assoc($pid)) {
             foreach ($pid as &$p) {
                 $p = new $UserClass($p);
             }
             return $pid;
         }
         return new $UserClass($pid);
     }));
     /* TimberObjects Alias */
     $twig->addFunction(new Twig_SimpleFunction('Post', function ($pid, $PostClass = 'TimberPost') {
         if (is_array($pid) && !TimberHelper::is_array_assoc($pid)) {
             foreach ($pid as &$p) {
                 $p = new $PostClass($p);
             }
             return $pid;
         }
//.........这里部分代码省略.........
开发者ID:adrianjonmiller,项目名称:hearts-being-healed,代码行数:101,代码来源:timber-twig.php

示例11: testResizeGif

 function testResizeGif()
 {
     $filename = self::copyTestImage('loading.gif');
     $gif_url = str_replace(ABSPATH, 'http://' . $_SERVER['HTTP_HOST'] . '/', $filename);
     $str = '<img src="{{' . "'{$gif_url}'" . '|resize(200)}}" />';
     $result = Timber::compile_string($str);
     $resized_url = str_replace('loading.gif', 'loading-200x0-c-default.gif', $gif_url);
     $resized_path = str_replace('http://example.org', ABSPATH, $resized_url);
     $resized_path = TimberURLHelper::remove_double_slashes($resized_path);
     $this->assertFileExists($resized_path);
 }
开发者ID:rpkoller,项目名称:timber,代码行数:11,代码来源:test-timber-image.php

示例12: get_path

 /**
  * @return string
  */
 public function get_path()
 {
     $link = $this->get_link();
     $rel = TimberURLHelper::get_rel_url($link, true);
     return apply_filters('timber_term_path', $rel, $this);
 }
开发者ID:wpmu,项目名称:maera,代码行数:9,代码来源:timber-term.php

示例13: resize

 /**
  *
  *
  * @param string  $src
  * @param int     $w
  * @param int     $h
  * @param string  $crop
  * @param bool    $force_resize
  * @return string
  */
 public static function resize($src, $w, $h = 0, $crop = 'default', $force_resize = false)
 {
     if (empty($src)) {
         return '';
     }
     if (strstr($src, 'http') && !strstr($src, home_url())) {
         $src = self::sideload_image($src);
     }
     $abs = false;
     if (strstr($src, 'http')) {
         $abs = true;
     }
     // Sanitize crop position
     $allowed_crop_positions = array('default', 'center', 'top', 'bottom', 'left', 'right');
     if ($crop !== false && !in_array($crop, $allowed_crop_positions)) {
         $crop = $allowed_crop_positions[0];
     }
     //oh good, it's a relative image in the uploads folder!
     $new_path = self::get_resize_file_rel($src, $w, $h, $crop);
     $new_server_path = self::get_resize_file_path($src, $w, $h, $crop);
     $old_server_path = self::get_server_location($src);
     $old_server_path = TimberURLHelper::remove_double_slashes($old_server_path);
     $new_server_path = TimberURLHelper::remove_double_slashes($new_server_path);
     if (file_exists($new_server_path)) {
         if ($force_resize) {
             // Force resize - warning: will regenerate the image on every pageload, use for testing purposes only!
             unlink($new_server_path);
         } else {
             if (!$abs) {
                 return TimberURLHelper::preslashit($new_path);
             }
             return untrailingslashit(home_url()) . $new_path;
         }
     }
     $image = wp_get_image_editor($old_server_path);
     if (!is_wp_error($image)) {
         $current_size = $image->get_size();
         $src_w = $current_size['width'];
         $src_h = $current_size['height'];
         $src_ratio = $src_w / $src_h;
         if (!$h) {
             $h = round($w / $src_ratio);
         }
         // Get ratios
         $dest_ratio = $w / $h;
         $src_wt = $src_h * $dest_ratio;
         $src_ht = $src_w / $dest_ratio;
         if (!$crop) {
             // Always crop, to allow resizing upwards
             $image->crop(0, 0, $src_w, $src_h, $w, $h);
         } else {
             //start with defaults:
             $src_x = $src_w / 2 - $src_wt / 2;
             $src_y = ($src_h - $src_ht) / 6;
             //now specific overrides based on options:
             if ($crop == 'center') {
                 // Get source x and y
                 $src_x = round(($src_w - $src_wt) / 2);
                 $src_y = round(($src_h - $src_ht) / 2);
             } else {
                 if ($crop == 'top') {
                     $src_y = 0;
                 } else {
                     if ($crop == 'bottom') {
                         $src_y = $src_h - $src_ht;
                     } else {
                         if ($crop == 'left') {
                             $src_x = 0;
                         } else {
                             if ($crop == 'right') {
                                 $src_x = $src_w - $src_wt;
                             }
                         }
                     }
                 }
             }
             // Crop the image
             if ($dest_ratio > $src_ratio) {
                 $image->crop(0, $src_y, $src_w, $src_ht, $w, $h);
             } else {
                 $image->crop($src_x, 0, $src_wt, $src_h, $w, $h);
             }
         }
         $result = $image->save($new_server_path);
         if (is_wp_error($result)) {
             error_log('Error resizing image');
             error_log(print_r($result, true));
         }
         if ($abs) {
             return untrailingslashit(home_url()) . $new_path;
//.........这里部分代码省略.........
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:101,代码来源:timber-image-helper.php

示例14: 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());
 }
开发者ID:o2themar,项目名称:wordpress_site,代码行数:15,代码来源:timber-image.php

示例15: get_context

 /**
  * Get context.
  *
  * @return array
  */
 public static function get_context()
 {
     $data = array();
     $data['http_host'] = 'http://' . TimberURLHelper::get_host();
     $data['wp_title'] = TimberHelper::get_wp_title();
     $data['wp_head'] = TimberHelper::function_wrapper('wp_head');
     $data['wp_footer'] = TimberHelper::function_wrapper('wp_footer');
     $data['body_class'] = implode(' ', get_body_class());
     $data['site'] = new TimberSite();
     $data['theme'] = $data['site']->theme;
     $data['posts'] = Timber::query_posts();
     $data = apply_filters('timber_context', $data);
     $data = apply_filters('timber/context', $data);
     return $data;
 }
开发者ID:ruscon,项目名称:timber,代码行数:20,代码来源:timber.php


注:本文中的TimberURLHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。