Overview
Comment: | Progress on the rendering side of files |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
049b3cf40d8cd1f5764f90f0a6cda77e |
User & Date: | bohwaz on 2020-12-13 00:58:53 |
Other Links: | branch diff | manifest | tags |
Context
2020-12-13
| ||
15:34 | New file storage is working check-in: 0e27827269 user: bohwaz tags: dev | |
00:58 | Progress on the rendering side of files check-in: 049b3cf40d user: bohwaz tags: dev | |
00:32 | Use Session::getInstance instead of constructor check-in: d3afacb8be user: bohwaz tags: dev | |
Changes
Modified src/include/lib/Garradin/Entities/Files/File.php from [aca14b6fd1] to [e4f0a7a0d2].
︙ | ︙ | |||
459 460 461 462 463 464 465 466 467 468 469 470 471 472 | if (null !== $path) { readfile($path); } else { echo $content; } } public function isPublic(): bool { if (null === $this->_public) { throw new \RuntimeException('_public is unset'); } | > > > > > > > > > > > > > > > > > > > > > > > | 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | if (null !== $path) { readfile($path); } else { echo $content; } } public function render(): string { static $render_types = ['text/html', 'text/vnd.skriv', 'text/vnd.skriv.encrypted']; if (!in_array($this->type, $render_types)) { throw new \LogicException('Render can not be called on files of type: ' . $this->type); } $content = Files::callStorage('fetch', $this); if ($this->type == 'text/html') { return \Garradin\Files\Render\HTML::render($this, $content); } elseif ($this->type == 'text/vnd.skriv') { return \Garradin\Files\Render\Skriv::render($this, $content); } elseif ($this->type == 'text/vnd.skriv.encrypted') { return \Garradin\Files\Render\EncryptedSkriv::render($this, $content); } throw new \LogicException('Unknown render type'); } public function isPublic(): bool { if (null === $this->_public) { throw new \RuntimeException('_public is unset'); } |
︙ | ︙ |
Modified src/include/lib/Garradin/Fichiers.php from [b460df65f5] to [a47061b5a4].
︙ | ︙ | |||
97 98 99 100 101 102 103 | { preg_match_all('/<<?(?:fichier|image)\s*(?:\|\s*)?(\d+)/', $text, $match, PREG_PATTERN_ORDER); preg_match_all('/(?:fichier|image):\/\/(\d+)/', $text, $match2, PREG_PATTERN_ORDER); return array_merge($match[1], $match2[1]); } | < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 97 98 99 100 101 102 103 104 | { preg_match_all('/<<?(?:fichier|image)\s*(?:\|\s*)?(\d+)/', $text, $match, PREG_PATTERN_ORDER); preg_match_all('/(?:fichier|image):\/\/(\d+)/', $text, $match2, PREG_PATTERN_ORDER); return array_merge($match[1], $match2[1]); } } |
Added src/include/lib/Garradin/Files/Render/EncryptedSkriv.php version [085541e42b].
> > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php namespace Garradin\Files\Render; class EncryptedSkriv { static public function render(File $file, string $content): string { $tpl = Template::getInstance(); $tpl->assign(compact('file', 'content')); return $tpl->fetch('common/_file_render_encrypted.tpl'); } } |
Added src/include/lib/Garradin/Files/Render/HTML.php version [38e9516154].
> > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?php namespace Garradin\Files\Render; use KD2\Garbage2xhtml; class HTML { static protected $g2x; static public function render(File $file, string $content): string { if (null === self::$g2x) { $g2x = self::$g2x = new Garbage2xhtml; $g2x->auto_br = false; } return self::$g2x->process($content); } } |
Added src/include/lib/Garradin/Files/Render/Skriv.php version [048c543789].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | <?php namespace Garradin\Files\Render; use Garradin\Web\Squelette_Filtres; use KD2\SkrivLite; class Skriv { static protected $skriv; static public function render(File $file, string $str): string { if (!self::$skriv) { self::$skriv = new \KD2\SkrivLite; self::$skriv->registerExtension('fichier', [self::class, 'SkrivFichier']); self::$skriv->registerExtension('image', [self::class, 'SkrivImage']); // Enregistrer d'autres extensions éventuellement Plugin::fireSignal('skriv.init', ['skriv' => self::$skriv]); } $skriv =& self::$skriv; $str = preg_replace_callback('/(fichier|image):\/\/(\d+)/', function ($match) use ($skriv) { $file = Files::get((int)$match[2]); if (!$file) { return $skriv->parseError('/!\ Lien fichier invalide'); } return $file->url(); }, $str); $str = self::$skriv->render($str); $str = Squelette_Filtres::typo_fr($str); $str = preg_replace_callback('!<a href="([^/.:@]+)">!i', function ($matches) use ($prefix) { return '<a href="' . $prefix . self::transformTitleToURI($matches[1]) . '">'; }, $str); return $str; } static public function transformTitleToURI($str) { $str = Utils::transliterateToAscii($str); $str = preg_replace('![^\w\d_-]!i', '-', $str); $str = preg_replace('!-{2,}!', '-', $str); $str = trim($str, '-'); return $str; } /** * Callback utilisé pour l'extension <<fichier>> dans le wiki-texte * @param array $args Arguments passés à l'extension * @param string $content Contenu éventuel (en mode bloc) * @param object $skriv Objet SkrivLite */ static public function SkrivFichier($args, $content, $skriv) { $id = $caption = null; foreach ($args as $value) { if (preg_match('/^\d+$/', $value) && !$id) { $id = (int)$value; break; } else { $caption = trim($value); } } if (empty($id)) { return $skriv->parseError('/!\ Tag fichier : aucun numéro de fichier indiqué.'); } $file = Files::get((int)$match[2]); if (!$file) { return $skriv->parseError('/!\ Tag fichier invalide'); } if (empty($caption)) { $caption = $file->name; } $out = '<aside class="fichier" data-type="'.$skriv->escape($file->type).'">'; $out.= '<a href="'.$file->getURL().'" class="internal-file">'.$skriv->escape($caption).'</a> '; $out.= '<small>('.$skriv->escape(($file->type ? $file->type . ', ' : '') . Utils::format_bytes($file->size)).')</small>'; $out.= '</aside>'; return $out; } /** * Callback utilisé pour l'extension <<image>> dans le wiki-texte * @param array $args Arguments passés à l'extension * @param string $content Contenu éventuel (en mode bloc) * @param object $skriv Objet SkrivLite */ static public function SkrivImage($args, $content, $skriv) { static $align_values = ['droite', 'gauche', 'centre']; $align = ''; $id = $caption = null; foreach ($args as $value) { if (preg_match('/^\d+$/', $value) && !$id) { $id = (int)$value; } else if (in_array($value, $align_values) && !$align) { $align = $value; } else { $caption = $value; } } if (!$id) { return $skriv->parseError('/!\ Tag image : aucun numéro de fichier indiqué.'); } $file = Files::get((int)$match[2]); if (!$file) { return $skriv->parseError('/!\ Tag image invalide'); } if (!$file->image) { return $skriv->parseError('/!\ Tag image : ce fichier n\'est pas une image.'); } $out = '<a href="'.$file->url().'" class="internal-image">'; $out .= '<img src="'.$file->url($align == 'centre' ? 500 : 200).'" alt="'; if ($caption) { $out .= htmlspecialchars($caption); } $out .= '" /></a>'; if (!empty($align)) { $out = '<figure class="image ' . $align . '">' . $out; if ($caption) { $out .= '<figcaption>' . htmlspecialchars($caption) . '</figcaption>'; } $out .= '</figure>'; } return $out; } } |
Modified src/include/lib/Garradin/Utils.php from [c164f7f4a8] to [f7c395e1cb].
︙ | ︙ | |||
10 11 12 13 14 15 16 | class Utils { const EMAIL_CONTEXT_BULK = 'bulk'; const EMAIL_CONTEXT_PRIVATE = 'private'; const EMAIL_CONTEXT_SYSTEM = 'system'; | < < | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | class Utils { const EMAIL_CONTEXT_BULK = 'bulk'; const EMAIL_CONTEXT_PRIVATE = 'private'; const EMAIL_CONTEXT_SYSTEM = 'system'; const FRENCH_DATE_NAMES = [ 'January'=>'Janvier', 'February'=>'Février', 'March'=>'Mars', 'April'=>'Avril', 'May'=>'Mai', 'June'=>'Juin', 'July'=>'Juillet', 'August'=>'Août', 'September'=>'Septembre', 'October'=>'Octobre', 'November'=>'Novembre', 'December'=>'Décembre', 'Monday'=>'Lundi', 'Tuesday'=>'Mardi', 'Wednesday'=>'Mercredi', 'Thursday'=>'Jeudi','Friday'=>'Vendredi','Saturday'=>'Samedi','Sunday'=>'Dimanche', 'Feb'=>'Fév','Apr'=>'Avr','Jun'=>'Juin', 'Jul'=>'Juil','Aug'=>'Aout','Dec'=>'Déc', 'Mon'=>'Lun','Tue'=>'Mar','Wed'=>'Mer','Thu'=>'Jeu','Fri'=>'Ven','Sat'=>'Sam','Sun'=>'Dim']; |
︙ | ︙ | |||
338 339 340 341 342 343 344 | $str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères $str = preg_replace('![^[:ascii:]]+!', '', $str); return $str; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | $str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères $str = preg_replace('![^[:ascii:]]+!', '', $str); return $str; } /** * Transforme les tags HTML basiques en tags SkrivML * @param string $str Texte d'entrée * @return string Texte transformé */ static public function HTMLToSkriv($str) { |
︙ | ︙ |
Modified src/include/lib/Garradin/Wiki.php from [ebb7e50c24] to [a3cb964340].
︙ | ︙ | |||
12 13 14 15 16 17 18 | const ECRITURE_CATEGORIE = 1; const ITEMS_PER_PAGE = 25; protected $restriction_categorie = null; protected $restriction_droit = null; | < < < < < < < < < < < | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | const ECRITURE_CATEGORIE = 1; const ITEMS_PER_PAGE = 25; protected $restriction_categorie = null; protected $restriction_droit = null; // Gestion des données /////////////////////////////////////////////////////// public function _checkFields(&$data) { $db = DB::getInstance(); if (array_key_exists('titre', $data) && !trim($data['titre'])) |
︙ | ︙ |
Added src/templates/common/files/_file_render_encrypted.tpl version [fc5e705fb9].
> > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <noscript> <div class="error"> Vous dever activer javascript pour pouvoir déchiffrer cette page. </div> </noscript> <script type="text/javascript" src="{$admin_url}static/scripts/wiki-encryption.js"></script> <div id="wikiEncryptedMessage"> <p class="block alert">Cette page est chiffrée. <input type="button" onclick="return wikiDecrypt(false);" value="Entrer le mot de passe" /> </p> </div> <div class="wikiContent" style="display: none;" id="wikiEncryptedContent"> {$page.contenu.contenu} </div> |