Ejemplo n.º 1
0
 protected function addFormatToParams(&$params)
 {
     if (!AK_AUTOMATICALLY_ACCEPT_KNOW_FORMATS || empty($params) || isset($params['format'])) {
         return;
     }
     $last_key = Ak::last(array_keys($params));
     if (!is_string($params[$last_key])) {
         return;
     }
     if ($format = strrchr($params[$last_key], '.')) {
         $trimmed_format = trim($format, '.');
         if (!AkMimeType::isFormatRegistered($trimmed_format)) {
             return;
         }
         $params[$last_key] = substr($params[$last_key], 0, strpos($params[$last_key], $format));
         $params['format'] = $trimmed_format;
     }
 }
Ejemplo n.º 2
0
 protected function _buildCacheId($path, $forcedLanguage = null, $normalize = true)
 {
     if ($path === null) {
         $path = @$_REQUEST['ak'];
     } else {
         if (is_array($path)) {
             unset($path['lang']);
             $path = $this->_pathFor($path, $normalize);
         } else {
             if (is_string($path)) {
             }
         }
     }
     $path = ltrim($path, '/');
     if (preg_match('@^([a-z]{2,2}|[a-z]{2,2}_[a-z]{2,2})/.*$@', $path)) {
         $parts = explode('/', $path);
         $forcedLanguage = array_shift($parts);
         $path = implode('/', $parts);
     }
     $cacheId = preg_replace('|' . DS . '+|', '/', $path);
     $cacheId = rtrim($cacheId, '/');
     $parts = explode('/', $cacheId);
     $hasExtension = preg_match('/.+\\..{2,4}/', $parts[count($parts) - 1]);
     if (!$hasExtension) {
         if (isset($this->_controller)) {
             $cacheId .= '.' . $this->_controller->Request->getFormat();
         } else {
             list($format, $requestPath) = AkMimeType::getFormat($path);
             $cacheId .= '.' . $format;
         }
     }
     $getParameters = $_GET;
     unset($getParameters['ak']);
     if (is_array($this->_include_get_parameters) && !empty($this->_include_get_parameters) && !empty($getParameters)) {
         $cacheableGetParameters = array();
         sort($this->_include_get_parameters);
         foreach ($this->_include_get_parameters as $include_get) {
             if (isset($getParameters[$include_get])) {
                 $cacheableGetParameters[] = $include_get . DS . $getParameters[$include_get];
             }
         }
         /**
          * writing cache fragment for the get_params that should be cached
          */
         $this->writeFragment('get_params' . DS . $cacheId, serialize($this->_include_get_parameters));
         $cacheIdGetPart = implode(DS, $cacheableGetParameters);
         $cacheId .= DS . $cacheIdGetPart;
     } else {
         if (!$this->_controller) {
             /**
              * reading cacheable get_parameters and adding them to the cacheId
              */
             if ($useCacheGetParams = $this->readFragment('get_params' . DS . $cacheId)) {
                 $useCacheGetParams = unserialize($useCacheGetParams);
                 $cacheableGetParameters = array();
                 foreach ($useCacheGetParams as $p) {
                     if (isset($getParameters[$p])) {
                         $cacheableGetParameters[] = $p . DS . $getParameters[$p];
                     }
                 }
                 if (!empty($cacheableGetParameters)) {
                     $cacheIdGetPart = implode(DS, $cacheableGetParameters);
                     $cacheId .= DS . $cacheIdGetPart;
                 }
             }
         }
     }
     $cacheId = strlen($cacheId) > $this->_max_url_length ? md5($cacheId) : $cacheId;
     $cacheId = ($forcedLanguage != null ? $forcedLanguage : $this->_getDefaultLanguageForUser()) . DS . $cacheId;
     $this->_lastCacheId = preg_replace('|' . DS . '+|', '/', $cacheId);
     return $this->_lastCacheId;
 }
Ejemplo n.º 3
0
 static function bestMimeType()
 {
     return AkMimeType::getMimeType(AkMimeType::getAccepts());
 }
Ejemplo n.º 4
0
 public function lookupMimeType($mime_type)
 {
     $mime_types = AkMimeType::getRegistered();
     if (!isset($mime_types[$mime_type])) {
         throw new NotAcceptableException('Invalid content type. Please register new content types in your config/ using AkMimeType::register("application/vnd.ms-excel", "xls")');
     }
     return $mime_types[$mime_type];
 }