ReadmeType.class.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class ReadmeType {
  3. public static function manifest(){
  4. return array(
  5. 'uid' => 'readme',
  6. 'label' => 'README',
  7. 'icon' => 'fas fa-book-reader',
  8. 'color' => '#ffffff',
  9. 'background' => '#000000',
  10. 'description' => 'Fichier texte de type "lisez moi", utilise du markdown pour la mise en forme',
  11. 'fromExtension' => array('md'),
  12. 'toExtension' => 'md',
  13. 'default' => '# Sommaire'.PHP_EOL.'Votre contenu ici...',
  14. );
  15. }
  16. /* EDITION */
  17. public static function toHtml($resource,$sketch=null){
  18. $infos = self::manifest();
  19. return array(
  20. 'html'=>'<textarea id="content" onblur="hackpoint_resource_save_content()" class="markdown-text">'.$resource->content.'</textarea>',
  21. 'javascript' => "
  22. hackpoint_resource_mirrorify('.markdown-text',{
  23. mode : 'markdown',
  24. lineNumbers : false,
  25. theme : 'monokai',
  26. readOnly : false
  27. });
  28. "
  29. );
  30. }
  31. /* IMPORT / EXPORT */
  32. //Import depuis un glisser déposé du fichier
  33. public static function fromFile($resource,$sketch=null){
  34. $enc = mb_detect_encoding($resource->content,"UTF-8, ISO-8859-1, GBK");
  35. if($enc!='UTF-8')
  36. $resource->content = iconv($enc,"utf-8",$resource->content);
  37. return $resource;
  38. }
  39. //Export vers un fichier brut
  40. public static function toFile($resource){
  41. $infos = self::manifest();
  42. return array(
  43. 'name'=> slugify($resource->label).'.'.$infos['toExtension'],
  44. 'content' => html_entity_decode($resource->content)
  45. );
  46. }
  47. //Import depuis un flux json compressé de la ressource
  48. public static function fromJson($resource){
  49. return $resource;
  50. }
  51. //export en fichier JSON compressé de la ressource
  52. public static function toJson($resource){
  53. $resource = $resource->toArray();
  54. $resource['content'] = htmlspecialchars($resource['content']);
  55. return $resource;
  56. }
  57. }
  58. ?>