Fritzing.class.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. class Fritzing {
  3. public static function manifest(){
  4. return array(
  5. 'uid' => 'fritzing',
  6. 'label' => 'Schéma fritzing',
  7. 'description' => 'Fichier pour le logiciel fritzing',
  8. 'fromExtension' => array('fzz'),
  9. 'toExtension' => 'fzz',
  10. 'upload' => array(
  11. 'url' => 'action.php?action=upload_resource_file',
  12. 'element' => '#dropZoneFiles',
  13. 'callback' => "refresh_fritzing();",
  14. )
  15. );
  16. }
  17. //Import depuis un glisser déposé du fichier
  18. public static function fromFile($resource){
  19. $resource->save();
  20. $ext = getExt($resource->label);
  21. $name = $resource->id.'.'.$ext;
  22. file_put_contents(SKETCH_PATH.$name,$resource->content);
  23. $resource->content = $name;
  24. return $resource;
  25. }
  26. //Import depuis un flux json compressé de la ressource
  27. public static function fromJson($resource){
  28. $resource->save();
  29. $stream = base64_decode($resource->content);
  30. $resource->content = $resource->id.'.png';
  31. file_put_contents(SKETCH_PATH.$resource->content,$stream);
  32. return $resource;
  33. }
  34. //export en fichier JSON compressé de la ressource
  35. public static function toJson($resource){
  36. $resource = $resource->toArray();
  37. $resource['content'] = base64_encode(file_get_contents(SKETCH_PATH.$resource['content']));
  38. return $resource;
  39. }
  40. public static function toFile($resource){
  41. $ext = getExt($resource->content);
  42. $infos = self::manifest();
  43. return array(
  44. 'name'=> slugify($resource->label).'.'.$ext,
  45. 'content' => file_exists(SKETCH_PATH.$resource->content) ? file_get_contents(SKETCH_PATH.$resource->content) : ''
  46. );
  47. }
  48. public static function toHtml($resource,$sketch){
  49. global $myUser;
  50. $infos = self::manifest();
  51. $content = $resource->content ==''?'Envoyer un fichier':'<a href="action.php?action=get_resource&id='.$resource->id.'">Télécharger</a>';
  52. $response['content'] = '<div id="dropZoneFiles" style="width:100%;height:auto;" class="dropzone">'.$content.'</div>';
  53. if($myUser->id == $sketch->owner)
  54. $response['upload'] = $infos['upload'];
  55. return $response;
  56. }
  57. }
  58. ?>