Example #1
0
 /**
  * Generate url for given asset file. Depending on options passed provides full url with domain name.
  * Also calls Helper::assetTimestamp() to add timestamp to local files
  *
  * @param string|array Path string or url array
  * @param array $options Options array. Possible keys:
  *   `fullBase` Return full url with domain name
  *   `pathPrefix` Path prefix for relative urls
  *   `ext` Asset extension to append
  *   `plugin` False value will prevent parsing path as a plugin
  * @return string Generated url
  */
 public function assetUrl($path, $options = array())
 {
     if (is_array($path)) {
         $path = $this->url($path, !empty($options['fullBase']));
     } elseif (strpos($path, '://') === false) {
         if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
             list($plugin, $path) = $this->_View->pluginSplit($path, false);
         }
         if (!empty($options['pathPrefix']) && $path[0] !== '/') {
             $path = $options['pathPrefix'] . $path;
         }
         if (!empty($options['ext']) && strpos($path, '?') === false && substr($path, -strlen($options['ext'])) !== $options['ext']) {
             $path .= $options['ext'];
         }
         if (isset($plugin)) {
             $path = Inflector::underscore($plugin) . '/' . $path;
         }
         $path = h($this->assetTimestamp($this->webroot($path)));
         if (!empty($options['fullBase'])) {
             $base = $this->url('/', true);
             $len = strlen($this->request->webroot);
             if ($len) {
                 $base = substr($base, 0, -$len);
             }
             $path = $base . $path;
         }
     }
     return $path;
 }
Example #2
0
 /**
  * Generate url for given asset file. Depending on options passed provides full url with domain name.
  * Also calls Helper::assetTimestamp() to add timestamp to local files
  *
  * @param string|array Path string or url array
  * @param array $options Options array. Possible keys:
  *   `fullBase` Return full url with domain name
  *   `pathPrefix` Path prefix for relative URLs
  *   `ext` Asset extension to append
  *   `plugin` False value will prevent parsing path as a plugin
  * @return string Generated url
  */
 public function assetUrl($path, $options = array())
 {
     if (is_array($path)) {
         return $this->url($path, !empty($options['fullBase']));
     }
     if (strpos($path, '://') !== false) {
         return $path;
     }
     if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
         list($plugin, $path) = $this->_View->pluginSplit($path, false);
     }
     if (!empty($options['pathPrefix']) && $path[0] !== '/') {
         $path = $options['pathPrefix'] . $path;
     }
     if (!empty($options['ext']) && strpos($path, '?') === false && substr($path, -strlen($options['ext'])) !== $options['ext']) {
         $path .= $options['ext'];
     }
     if (isset($plugin)) {
         $path = Inflector::underscore($plugin) . '/' . $path;
     }
     $path = $this->_encodeUrl($this->assetTimestamp($this->webroot($path)));
     if (!empty($options['fullBase'])) {
         $path = rtrim(FULL_BASE_URL, '/') . '/' . ltrim($path, '/');
     }
     return $path;
 }
Example #3
0
 /**
  * Generate URL for given asset file. Depending on options passed provides full URL with domain name.
  * Also calls Helper::assetTimestamp() to add timestamp to local files
  *
  * @param string|array $path    Path string or URL array
  * @param array        $options Options array. Possible keys:
  *                              `fullBase` Return full URL with domain name
  *                              `pathPrefix` Path prefix for relative URLs
  *                              `ext` Asset extension to append
  *                              `plugin` False value will prevent parsing path as a plugin
  *
  * @return string Generated URL
  */
 public function assetUrl($path, $options = array())
 {
     if (is_array($path)) {
         return $this->url($path, !empty($options['fullBase']));
     }
     if (strpos($path, '://') !== FALSE) {
         return $path;
     }
     if (!array_key_exists('plugin', $options) || $options['plugin'] !== FALSE) {
         list($plugin, $path) = $this->_View->pluginSplit($path, FALSE);
     }
     if (!empty($options['pathPrefix']) && $path[0] !== '/') {
         $path = $options['pathPrefix'] . $path;
     }
     if (!empty($options['ext']) && strpos($path, '?') === FALSE && substr($path, -strlen($options['ext'])) !== $options['ext']) {
         $path .= $options['ext'];
     }
     if (preg_match('|^([a-z0-9]+:)?//|', $path)) {
         return $path;
     }
     if (isset($plugin)) {
         $path = Inflector::underscore($plugin) . '/' . $path;
     }
     $path = $this->_encodeUrl($this->assetTimestamp($this->webroot($path)));
     if (!empty($options['fullBase'])) {
         $path = rtrim(Router::fullBaseUrl(), '/') . '/' . ltrim($path, '/');
     }
     return $path;
 }