Gdn_Upload::parse PHP 메소드

parse() 공개 정적인 메소드

There are various formats supported for the name, mostly due to legacy concerns. - http(s)://domain/path.ext: A fully qualified url. - /path/from/uploads.ext: This is a locally uploaded file. - /path/to/uploads/path.ext: A full path starting from the uploads directory (deprecated). - ~type/path.ext: A specific type of upload provided by a plugin (deprecated). - type://domain/path.ext: A specific type of upload provied by a plugin with additional domain information.
public static parse ( string $Name ) : array | boolean
$Name string The virtual name of the file.
리턴 array | boolean Returns an array of parsed information or false if the parse failed.
    public static function parse($Name)
    {
        $Result = false;
        $Name = str_replace('\\', '/', $Name);
        $PathUploads = str_replace('\\', '/', PATH_UPLOADS);
        if (preg_match('`^https?://`', $Name)) {
            $Result = array('Name' => $Name, 'Type' => 'external', 'SaveName' => $Name, 'SaveFormat' => '%s', 'Url' => $Name);
            return $Result;
        } elseif (stringBeginsWith($Name, $PathUploads)) {
            $Name = ltrim(substr($Name, strlen($PathUploads)), '/');
            // This is an upload.
            $Result = array('Name' => $Name, 'Type' => '', 'SaveName' => $Name, 'SaveFormat' => '%s');
        } elseif (preg_match('`^~([^/]*)/(.*)$`', $Name, $Matches)) {
            // The first part of the name tells us the type.
            $Type = $Matches[1];
            $Name = $Matches[2];
            $Result = array('Name' => $Name, 'Type' => $Type, 'SaveName' => "~{$Type}/{$Name}", 'SaveFormat' => "~{$Type}/%s");
        } else {
            $Parts = parse_url($Name);
            if (empty($Parts['scheme'])) {
                $Name = ltrim($Name, '/');
                // This is an upload in the uploads folder.
                $Result = array('Name' => $Name, 'Type' => '', 'SaveName' => $Name, 'SaveFormat' => '%s');
            } else {
                // This is a url in the format type:://domain/path.
                $Result = array('Name' => ltrim(val('path', $Parts), '/'), 'Type' => $Parts['scheme'], 'Domain' => val('host', $Parts));
                $SaveFormat = "{$Result['Type']}://{$Result['Domain']}/%s";
                $Result['SaveName'] = sprintf($SaveFormat, $Result['Name']);
                $Result['SaveFormat'] = $SaveFormat;
            }
        }
        if (!empty($Result['Domain'])) {
            $UrlPrefix = self::urls("{$Result['Type']}://{$Result['Domain']}");
        } else {
            $UrlPrefix = self::urls($Result['Type']);
        }
        if ($UrlPrefix === false) {
            $Result['Url'] = false;
        } else {
            $Result['Url'] = $UrlPrefix . '/' . $Result['Name'];
        }
        return $Result;
    }

Usage Example

예제 #1
0
파일: default.php 프로젝트: vanilla/vanilla
 /**
  * Generate a Gravatar image URL based on the provided email address.
  *
  * @link http://en.gravatar.com/site/implement/images/ Gravatar Image Requests
  * @param string $email Email address for the user, used to generate the avatar ID.
  * @param int $size Target image size.
  * @return string A formatted Gravatar image URL.
  */
 public static function generateUrl($email, $size = 80)
 {
     $avatarID = md5(strtolower($email));
     // Figure out our base URLs.  Gravatar doesn't support SVGs, so we're stuck with using Vanillicon v1.
     if (Gdn::request()->scheme() === 'https') {
         $baseUrl = 'https://secure.gravatar.com/avatar';
         $vanilliconBaseUrl = 'https://vanillicon.com';
     } else {
         $baseUrl = 'http://www.gravatar.com/avatar';
         $vanilliconBaseUrl = 'http://vanillicon.com';
     }
     if (c('Plugins.Gravatar.UseVanillicon', true)) {
         // Version 1 of Vanillicon only supports three sizes.  Figure out which one is best for this image.
         if ($size <= 50) {
             $vanilliconSize = 50;
         } elseif ($size <= 100) {
             $vanilliconSize = 100;
         } else {
             $vanilliconSize = 200;
         }
         $default = "{$vanilliconBaseUrl}/{$avatarID}_{$vanilliconSize}.png";
     } else {
         $configuredDefaultAvatar = c('Plugins.Gravatar.DefaultAvatar', c('Garden.DefaultAvatar'));
         if ($configuredDefaultAvatar) {
             $defaultParsed = Gdn_Upload::parse($configuredDefaultAvatar);
             $default = val('Url', $defaultParsed);
         }
     }
     if (empty($default)) {
         $default = asset($size <= 50 ? 'plugins/Gravatar/default.png' : 'plugins/Gravatar/default_250.png', true);
     }
     $query = ['default' => $default, 'rating' => c('Plugins.Gravatar.Rating', 'g'), 'size' => $size];
     return $baseUrl . "/{$avatarID}/?" . http_build_query($query);
 }
All Usage Examples Of Gdn_Upload::parse