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


PHP TimberURLHelper::preslashit方法代码示例

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


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

示例1: preslashit

 /**
  * @deprecated
  */
 static function preslashit($path)
 {
     return TimberURLHelper::preslashit($path);
 }
开发者ID:aauroux,项目名称:timber,代码行数:7,代码来源:timber-helper.php

示例2: 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'];
 }
开发者ID:Butterwell,项目名称:timber,代码行数:31,代码来源:timber-image-helper.php

示例3: 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


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