ReadmeType.class.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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><div id="htmlcontent"></div>',
  21. 'javascript' => "
  22. hackpoint_resource_mirrorify('.markdown-text',{
  23. mode : 'markdown',
  24. lineNumbers : false,
  25. theme : 'monokai',
  26. readOnly : false,
  27. change : function (){ hackpoint_resource_markdown_parse(); },
  28. complete : function(){hackpoint_resource_markdown_parse();}
  29. });
  30. "
  31. );
  32. }
  33. /* IMPORT / EXPORT */
  34. //Import depuis un glisser déposé du fichier
  35. public static function fromFile($resource,$sketch=null){
  36. $enc = mb_detect_encoding($resource->content,"UTF-8, ISO-8859-1, GBK");
  37. if($enc!='UTF-8')
  38. $resource->content = iconv($enc,"utf-8",$resource->content);
  39. return $resource;
  40. }
  41. //Export vers un fichier brut
  42. public static function toFile($resource){
  43. $infos = self::manifest();
  44. return array(
  45. 'name'=> slugify($resource->label).'.'.$infos['toExtension'],
  46. 'content' => html_entity_decode($resource->content)
  47. );
  48. }
  49. //Import depuis un flux json compressé de la ressource
  50. public static function fromJson($resource){
  51. return $resource;
  52. }
  53. //export en fichier JSON compressé de la ressource
  54. public static function toJson($resource){
  55. $resource = $resource->toArray();
  56. $resource['content'] = htmlspecialchars($resource['content']);
  57. return $resource;
  58. }
  59. }
  60. ?>