'files', 'label' => 'Set de fichiers', 'description' => 'Ensemble de fichiers attachés', 'fromExtension' => array('zip','7z'), 'toExtension' => 'zip', 'upload' => array( 'url'=>'action.php?action=upload_resource_file', 'element' => '#dropZoneFiles', 'callback' => "search_file();", ) ); } //Import depuis un glisser déposé du fichier public static function fromFile($resource){ $resource->save(); $path = SKETCH_PATH.'/'.$resource->id; if(!file_exists($path)) mkdir($path); $filepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.$resource->label.'-'.time(); if(file_exists($filepath))unlink($filepath); file_put_contents($filepath, $resource->content); $zip = new ZipArchive; $res = $zip->open($filepath); if ($res === TRUE) { $zip->extractTo($path); $zip->close(); } $resource->content = ''; return $resource; } //Import depuis un flux json compressé de la ressource public static function fromJson($resource){ $files = $resource->content; $resource->content = ''; $resource->save(); $folder = SKETCH_PATH.'/'.$resource->id; if(!file_exists($folder)) mkdir($folder); foreach($files as $file): $stream = base64_decode($file['stream']); file_put_contents($folder.'/'.$file['label'],$stream); endforeach; return $resource; } //export en fichier JSON compressé de la ressource public static function toJson($resource){ $resource = $resource->toArray(); $resource->content = array(); $folder = SKETCH_PATH.'/'.$resource->id; foreach(glob($folder.'/*') as $file): $resource->content[] = array('label'=>basename($file),'stream'=>base64_encode(file_get_contents($file))); endforeach; return $resource; } public static function toFile($resource){ global $myUser; $infos = self::manifest(); $path = SKETCH_PATH.'/'.$resource->id; $filename = $resource->label.'-'.time().'.'.$infos['toExtension']; $filepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.$filename; $zip = new ZipArchive; if(file_exists($filepath))unlink($filepath); $res = $zip->open($filepath, ZipArchive::CREATE); if ($res === TRUE) { foreach(glob($path.'/*') as $f) $zip->addFile($f,basename($f)); $zip->close(); } return array( 'name'=> slugify($resource->label).'.'.$infos['toExtension'], 'content' => file_get_contents($filepath) ); } public static function toHtml($resource,$sketch){ global $myUser; $infos = self::manifest(); if($myUser->id == $sketch->owner){ $response['upload'] = $infos['upload']; $response['content'] = '
Fichiers disponibles Télécharger | '; $response['content'] .= ''; $response['content'] .= ' |
---|