/**
  *	FilePath : retorna la ruta del xml o json para un contenido por ID
  *	@param $id del elemento
  *	@param $json : flag para retornar la extension json. xml por default
  *	@return $path
  */
 public static function FilePath($id, $module, $json = false)
 {
     $option = $json ? 'json' : 'xml';
     $options = array('module' => $module, 'folderoption' => $option);
     $path = PathManager::GetContentTargetPath($options);
     $folder = PathManager::GetDirectoryFromId($path, $id);
     return Util::DirectorySeparator($folder . '/' . $id . '.' . $option);
 }
Exemple #2
0
 /**
  *	Proccess Image
  *	Generate a image the first time is requested to be served by apache later
  *	To take advantage of this service, you should use Apache Header module width Header set Cache-Control
  *	@return void
  */
 public static function ProcessImage()
 {
     $id = Util::getvalue('id');
     $args = Util::getvalue('params');
     $ext = Util::getvalue('ext');
     $options = array('id' => $id, 'width' => false, 'height' => false, 'quality' => false, 'type' => 'resize');
     // Parametro Ancho
     if (preg_match('/w([0-9]+)/i', $args, $outputWidth)) {
         $options['width'] = $outputWidth[1];
     }
     // Parametro Alto
     if (preg_match('/h([0-9]+)/i', $args, $outputHeight)) {
         $options['height'] = $outputHeight[1];
     }
     // Parametro calidad
     if (preg_match('/q(100|\\d{1,2})/i', $args, $outputHeight)) {
         $options['quality'] = $outputHeight[1];
     }
     // Type Crop / Resize
     $arr = explode('.', $args);
     if (strpos($arr[0], 'c') !== false) {
         $options['type'] = 'crop';
     }
     // Extension del archivo solicitado
     $fileType = $ext ? strtolower($ext) : 'jpg';
     $fileType = substr($fileType, 0, 3);
     $fileType = $fileType == 'jpe' ? 'jpg' : $fileType;
     $fileType = '.' . $fileType;
     // Ruta del a imagen origina en disco
     $sourceOpt = array('module' => 'image', 'folderoption' => 'target');
     $sourceDir = PathManager::GetContentTargetPath($sourceOpt);
     $sourcePath = PathManager::GetDirectoryFromId($sourceDir, $id);
     $source = $sourcePath . '/' . $id . $fileType;
     $imageDir = PathManager::GetApplicationPath() . Configuration::Query('/configuration/images_bucket')->item(0)->nodeValue;
     if (!is_dir($imageDir)) {
         mkdir($imageDir, 0777);
     }
     $imagePath = PathManager::GetDirectoryFromId($imageDir, $id);
     $image = $imagePath . '/' . $id;
     // El nombre del archivo contendrá los parametros para ser servida de manera estatica
     if ($options['width']) {
         $image .= 'w' . $options['width'];
     }
     if ($options['height']) {
         $image .= 'h' . $options['height'];
     }
     if ($options['quality'] !== false) {
         $image .= 'q' . $options['quality'];
     }
     if ($options['type'] == 'crop') {
         $image .= 'c';
     }
     if (!file_exists($source)) {
         $source = PathManager::GetApplicationPath() . '/content/not-found' . $fileType;
     }
     list($sourceWidth, $sourceHeight) = getimagesize($source);
     /* 
     	Si no esta definido el ancho o el alto
     	debemos asignar limites por defecto para la generación de la imagen
     */
     $options['width'] = $options['width'] ? $options['width'] : $sourceWidth;
     $options['height'] = $options['height'] ? $options['height'] : $sourceHeight;
     // Generar la imagen
     $img = new Image();
     $img->load($source);
     $img->{$options}['type']($options['width'], $options['height']);
     /*
     	Guardar la imagen en disco
     	el próximo pedido será servido estáticamente por apache
     */
     $quality = $options['quality'] !== false ? $options['quality'] : '80';
     $img->save($image, $quality);
     /* Mostrar la imagen */
     $img->display();
 }