123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- class ReadmeType {
- public static function manifest(){
- return array(
- 'uid' => 'readme',
- 'label' => 'README',
- 'icon' => 'fas fa-book-reader',
- 'color' => '#ffffff',
- 'background' => '#000000',
- 'description' => 'Fichier texte de type "lisez moi", utilise du markdown pour la mise en forme',
- 'fromExtension' => array('md'),
- 'toExtension' => 'md',
- 'default' => '# Sommaire'.PHP_EOL.'Votre contenu ici...',
- );
- }
- /* EDITION */
- public static function toHtml($resource,$sketch=null){
- $infos = self::manifest();
- return array(
- 'html'=>'<textarea id="content" onblur="hackpoint_resource_save_content()" class="markdown-text">'.$resource->content.'</textarea><div id="htmlcontent"></div>',
- 'javascript' => "
- hackpoint_resource_mirrorify('.markdown-text',{
- mode : 'markdown',
- lineNumbers : false,
- theme : 'monokai',
- readOnly : false,
- change : function (){ hackpoint_resource_markdown_parse(); },
- complete : function(){hackpoint_resource_markdown_parse();}
- });
- "
- );
- }
- /* IMPORT / EXPORT */
- //Import depuis un glisser déposé du fichier
- public static function fromFile($resource,$sketch=null){
- $enc = mb_detect_encoding($resource->content,"UTF-8, ISO-8859-1, GBK");
- if($enc!='UTF-8')
- $resource->content = iconv($enc,"utf-8",$resource->content);
-
- return $resource;
- }
- //Export vers un fichier brut
- public static function toFile($resource){
- $infos = self::manifest();
- return array(
- 'name'=> slugify($resource->label).'.'.$infos['toExtension'],
- 'content' => html_entity_decode($resource->content)
- );
- }
- //Import depuis un flux json compressé de la ressource
- public static function fromJson($resource){
- return $resource;
- }
-
- //export en fichier JSON compressé de la ressource
- public static function toJson($resource){
- $resource = $resource->toArray();
- $resource['content'] = htmlspecialchars($resource['content']);
- return $resource;
- }
-
- }
- ?>
|