Comment: | Affichage des images et fichiers dans le wiki + insertion d'image avec choix légende et alignement |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
152296c65397463340c1721b1296e934 |
User & Date: | bohwaz on 2015-04-01 02:54:01 |
Other Links: | manifest | tags |
2015-04-01
| ||
04:12 | Liste des fichiers et images liés à une page wiki check-in: c5be620e4b user: bohwaz tags: trunk | |
02:54 | Affichage des images et fichiers dans le wiki + insertion d'image avec choix légende et alignement check-in: 152296c653 user: bohwaz tags: trunk | |
2015-03-31
| ||
20:16 | Servir les fichiers stockés check-in: e86b32517d user: bohwaz tags: trunk | |
Modified src/include/lib/Garradin/Fichiers.php from [a66301146d] to [b8a1959299].
︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 18 19 | public $type; public $image; public $datetime; public $hash; public $taille; public $id_contenu; const LIEN_COMPTA = 'compta_journal'; const LIEN_WIKI = 'wiki_pages'; const LIEN_MEMBRES = 'membres'; | > > > > > > > | | > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | 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 | public $type; public $image; public $datetime; public $hash; public $taille; public $id_contenu; /** * Tailles de miniatures autorisées, pour ne pas avoir 500 fichiers générés avec 500 tailles différentes * @var array */ protected $allowed_thumb_sizes = [200, 500]; const LIEN_COMPTA = 'compta_journal'; const LIEN_WIKI = 'wiki_pages'; const LIEN_MEMBRES = 'membres'; /** * Constructeur de l'objet pour un fichier * @param integer $id Numéro unique du fichier */ public function __construct($id) { $data = DB::getInstance()->simpleQuerySingle('SELECT fichiers.*, fc.hash, fc.taille, strftime(\'%s\', datetime) AS datetime FROM fichiers INNER JOIN fichiers_contenu AS fc ON fc.id = fichiers.id_contenu WHERE fichiers.id = ?;', true, (int)$id); if (!$data) { throw new \InvalidArgumentException('Ce fichier n\'existe pas.'); } foreach ($data as $key=>$value) { $this->$key = $value; } } /** * Renvoie la taille de miniature la plus proche de la taille demandée * @param integer $size Taille demandée * @return integer Taille possible */ protected function _findThumbSize($size) { $size = (int) $size; if (in_array($size, $this->allowed_thumb_sizes)) { return $size; } foreach ($this->allowed_thumb_sizes as $s) { if ($s >= $size) return $size; } return max($this->allowed_thumb_sizes); } /** * Renvoie l'adresse d'accès au fichier * @param boolean $size Taille éventuelle de la miniature demandée * @return string URL d'accès au fichier */ public function getURL($size = false) { $url = WWW_URL . 'f/' . base_convert((int)$this->id, 10, 36) . '/' . $this->nom; if ($size) { $url .= '?' . $this->_findThumbSize($size) . 'px'; } return $url; } /** * Lier un fichier à un contenu * @param string $type Type de contenu (constantes LIEN_*) * @param integer $foreign_id ID du contenu lié * @return boolean TRUE en cas de succès |
︙ | ︙ | |||
196 197 198 199 200 201 202 | /** * Envoie le fichier au client HTTP * @return void */ public function serve() { | | | > > | | | 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | /** * Envoie le fichier au client HTTP * @return void */ public function serve() { return $this->_serve($this->getFilePathFromCache(), $this->type, ($this->image ? false : $this->nom), $this->taille); } /** * Envoie une miniature à la taille indiquée au client HTTP * @return void */ public function serveThumbnail($width = self::TAILLE_MINIATURE) { if (!$this->image) { throw new \LogicException('Il n\'est pas possible de fournir une miniature pour un fichier qui n\'est pas une image.'); } $width = $this->_findThumbSize($width); $cache_id = 'fichiers.' . $this->id_contenu . '.thumb.' . (int)$width; $path = Static_Cache::getPath($cache_id); // La miniature n'existe pas dans le cache statique, on la crée if (!Static_Cache::exists($cache_id)) { $source = $this->getFilePathFromCache(); \KD2\Image::resize($source, $path, $width); } return $this->_serve($path, $this->type); } /** * Servir un fichier local en HTTP |
︙ | ︙ | |||
439 440 441 442 443 444 445 | 'type' => $file['type'], 'image' => (int)$file['image'], ]); return new Fichiers($db->lastInsertRowID()); } | | > | > > > | | | > | < < | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > | > > > > | | > > > > | > | > | > > > | > | > > | > | > | > | 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | 'type' => $file['type'], 'image' => (int)$file['image'], ]); return new Fichiers($db->lastInsertRowID()); } static public function SkrivFichier($args, $content, $skriv) { $_args = []; foreach ($args as $value) { if (preg_match('/^\d+$/', $value)) { $_args['id'] = (int)$value; } } if (empty($_args['id'])) { return $skriv->parseError('/!\ Tag fichier : aucun numéro de fichier indiqué.'); } try { $file = new Fichiers($_args['id']); } catch (\InvalidArgumentException $e) { return $skriv->parseError('/!\ Tag fichier : ' . $e->getMessage()); } $out = '<aside class="fichier" data-type="'.$skriv->escape($file->type).'">'; $out.= '<a href="'.$file->getURL().'" class="internal-file">'.$skriv->escape($file->nom).'</a> '; $out.= '<small>('.$skriv->escape($file->type . ', ' . Utils::format_bytes($file->taille)).')</small>'; $out.= '</aside>'; return $out; } static public function SkrivImage($args, $content, $skriv) { $_args = []; $_align_values = ['droite', 'gauche', 'centre']; foreach ($args as $value) { if (preg_match('/^\d+$/', $value)) { $_args['id'] = (int)$value; } else if (in_array($value, $_align_values)) { $_args['align'] = $value; } else { $_args['caption'] = $value; } } if (empty($_args['id'])) { return $skriv->parseError('/!\ Tag image : aucun numéro de fichier indiqué.'); } try { $file = new Fichiers($_args['id']); } catch (\InvalidArgumentException $e) { return $skriv->parseError('/!\ Tag image : ' . $e->getMessage()); } if (!$file->image) { return $skriv->parseError('/!\ Tag image : ce fichier n\'est pas une image.'); } if (empty($_args['caption'])) { $_args['caption'] = false; } $out = '<a href="'.$file->getURL().'" class="internal-image">'; $out .= '<img src="'.$file->getURL($_args['align'] == 'centre' ? 500 : 200).'" alt="'; if ($_args['caption']) { $out .= htmlspecialchars($_args['caption'], ENT_QUOTES, 'UTF-8'); } $out .= '" /></a>'; if (!empty($_args['align'])) { $out = '<figure class="image ' . $_args['align'] . '">' . $out; if ($_args['caption']) { $out .= '<figcaption>' . htmlspecialchars($_args['caption'], ENT_QUOTES, 'UTF-8') . '</figcaption>'; } $out .= '</figure>'; } return $out; } } |
Modified src/include/lib/Garradin/Template.php from [3428aae4cb] to [d428ff4e65].
︙ | ︙ | |||
597 598 599 600 601 602 603 | $tpl->register_modifier('html_money', 'Garradin\tpl_html_money'); $tpl->register_modifier('abs', 'abs'); $tpl->register_modifier('display_champ_membre', 'Garradin\tpl_display_champ_membre'); $tpl->register_modifier('format_sqlite_date_to_french', ['Garradin\Utils', 'sqliteDateToFrench']); | | < < < < < < < | 597 598 599 600 601 602 603 604 605 606 607 608 609 | $tpl->register_modifier('html_money', 'Garradin\tpl_html_money'); $tpl->register_modifier('abs', 'abs'); $tpl->register_modifier('display_champ_membre', 'Garradin\tpl_display_champ_membre'); $tpl->register_modifier('format_sqlite_date_to_french', ['Garradin\Utils', 'sqliteDateToFrench']); $tpl->register_modifier('format_bytes', ['Garradin\Utils', 'format_bytes']); $tpl->register_modifier('strftime_fr', 'Garradin\tpl_strftime_fr'); $tpl->register_modifier('date_fr', 'Garradin\tpl_date_fr'); ?> |
Modified src/include/lib/Garradin/Utils.php from [b300101854] to [8abbfb6919].
︙ | ︙ | |||
386 387 388 389 390 391 392 | * @return string Texte HTML */ static public function SkrivToHTML($str) { if (!self::$skriv) { self::$skriv = new \KD2\SkrivLite; | | > | 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | * @return string Texte HTML */ static public function SkrivToHTML($str) { if (!self::$skriv) { self::$skriv = new \KD2\SkrivLite; self::$skriv->registerExtension('fichier', ['\\Garradin\\Fichiers', 'SkrivFichier']); self::$skriv->registerExtension('image', ['\\Garradin\\Fichiers', 'SkrivImage']); } $str = self::$skriv->render($str); return $str; } |
︙ | ︙ | |||
588 589 590 591 592 593 594 595 596 597 598 599 600 601 | { case 'G': case 'g': return (int)$size_str * pow(1024, 3); case 'M': case 'm': return (int)$size_str * pow(1024, 2); case 'K': case 'k': return (int)$size_str * 1024; default: return $size_str; } } static public function deleteRecursive($path, $delete_target = false) { if (!file_exists($path)) return false; $dir = dir($path); | > > > > > > > > > | 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | { case 'G': case 'g': return (int)$size_str * pow(1024, 3); case 'M': case 'm': return (int)$size_str * pow(1024, 2); case 'K': case 'k': return (int)$size_str * 1024; default: return $size_str; } } static public function format_bytes($size) { if ($size > (1024 * 1024)) return round($size / 1024 / 1024, 2) . ' Mo'; elseif ($size > 1024) return round($size / 1024, 2) . ' Ko'; else return $size . ' o'; } static public function deleteRecursive($path, $delete_target = false) { if (!file_exists($path)) return false; $dir = dir($path); |
︙ | ︙ |
Modified src/templates/admin/wiki/_fichiers.tpl from [89bace7a8d] to [e94dce0bbd].
1 2 | {include file="admin/_head.tpl" title="Inclure un fichier" current="wiki" body_id="transparent" is_popup=true js=1} | | > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > | 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 | {include file="admin/_head.tpl" title="Inclure un fichier" current="wiki" body_id="transparent" is_popup=true js=1} <form method="post" enctype="multipart/form-data" action="{$self_url|escape}" id="f_upload"> <fieldset> <legend>Téléverser un fichier</legend> <input type="hidden" name="MAX_FILE_SIZE" value="{$max_size|escape}" id="f_maxsize" /> <dl> <dd class="help">Taille maximale : {$max_size|format_bytes}</dd> <dd class="fileUpload"><input type="file" name="fichier" id="f_fichier" data-hash-check /></dd> </dl> <p class="submit"> {csrf_field key="wiki_upload_`$page.id`"} <input type="submit" id="f_submit" value="Envoyer le fichier" /> </p> </fieldset> </form> <form method="get" action="#" style="display: none;" id="insertImage"> <fieldset> <legend>Insérer une image</legend> <dl> <dd class="image"></dd> <dt>Légende <i>(facultatif)</i></dt> <dd class="caption"> <input type="text" name="f_caption" size="50" /> </dd> <dt>Alignement :</dt> <dd class="align"> <input type="button" name="gauche" value="À gauche" /> <input type="button" name="centre" value="Au centre" /> <input type="button" name="droite" value="À droite" /> </dd> </dl> </fieldset> </form> <script type="text/javascript"> {literal} uploadHelper($('#f_fichier'), { width: 1920, height: null, resize: true, bytes: 'o', size_error_msg: 'Le fichier %file fait %size, soit plus que la taille maximale autorisée de %max_size.' }); function insertImageHelper(file) { if (!document.querySelectorAll) { window.parent.te_insertImage(file.id, 'centre'); return true; } var f = document.getElementById('insertImage'); f.style.display = 'block'; var inputs = f.querySelectorAll('input[type=button]'); for (var i = 0; i < inputs.length; i++) { inputs[i].onclick = function(e) { window.parent.te_insertImage(file.id, e.target.name, f.f_caption.value); }; } var img = document.createElement('img'); img.src = file.thumb; img.alt = ''; f.querySelector('dd.image').appendChild(img); } function insertHelper(data) { var file = (data.file || data); if (file.image) { insertImageHelper(file); } else { window.parent.te_insertFile(data.file.id); } return true; } //insertImageHelper({}) {/literal} </script> {include file="admin/_foot.tpl"} |
Modified src/www/.htaccess from [6bda533d32] to [c992fe3d1c].
1 2 3 | <IfModule mod_rewrite.c> RewriteEngine on RewriteRule admin/plugin/(.*?)/(.*) /admin/plugin.php?_p=$1&_u=$2 [QSA,L] | | | 1 2 3 4 5 6 7 8 9 10 11 12 | <IfModule mod_rewrite.c> RewriteEngine on RewriteRule admin/plugin/(.*?)/(.*) /admin/plugin.php?_p=$1&_u=$2 [QSA,L] RewriteRule f/([\d\w]+)/(.*) /file.php?id=$1&file=$2 [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* /index.php [QSA,L] </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule> |
Modified src/www/_route.php from [7717833717] to [63daf0cfc2].
︙ | ︙ | |||
20 21 22 23 24 25 26 | } elseif (preg_match('!/admin/plugin/(.+)/(.*)!', $uri, $match)) { $_GET['_p'] = $match[1]; $_GET['_u'] = $match[2]; require __DIR__ . '/admin/plugin.php'; } | | < | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | } elseif (preg_match('!/admin/plugin/(.+)/(.*)!', $uri, $match)) { $_GET['_p'] = $match[1]; $_GET['_u'] = $match[2]; require __DIR__ . '/admin/plugin.php'; } elseif (preg_match('!/f/([\d\w]+)/(.+)!', $uri, $match)) { $_GET['id'] = $match[1]; $_GET['file'] = $match[2]; require __DIR__ . '/file.php'; } else { require __DIR__ . '/index.php'; } |
Modified src/www/admin/static/admin.css from [01a0c5d7e1] to [a582528eb9].
︙ | ︙ | |||
105 106 107 108 109 110 111 112 113 114 115 116 117 118 | .page img { max-width: 100%; } body#popup .page { margin: 1em 1em 1em 2.5em; } span.error, b.error { color: #900; } span.confirm, b.confirm { color: #090; | > > > > > | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | .page img { max-width: 100%; } body#popup .page { margin: 1em 1em 1em 2.5em; } body#transparent .page { margin: 0; padding: 0; } span.error, b.error { color: #900; } span.confirm, b.confirm { color: #090; |
︙ | ︙ | |||
790 791 792 793 794 795 796 797 798 799 800 801 802 803 | .wikiContent ul { list-style-type: disc; } .wikiContent ol { list-style-type: decimal; } .wikiFooter { font-size: 0.8em; color: #666; border-top: 0.1em solid #ccc; clear: both; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 | .wikiContent ul { list-style-type: disc; } .wikiContent ol { list-style-type: decimal; } .wikiContent aside.fichier { margin: 1em; } .wikiContent aside.fichier small { opacity: 0.7; } .wikiContent aside.fichier a { display: inline-block; margin-right: 1em; padding: .5em; padding-left: 1.8em; border: 1px solid #ccc; border-radius: .5em; background-repeat: no-repeat; background-position: .5em center; background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAQCAYAAADAvYV+AAAAd0lEQVQoz2NgQAVNQDwDCTcw4AF3gPg/Er4xSBWnAXEHFL9HU/wWSS4FpFgZiJ+jKULHT4BYAWa6LhC/w6HwNRBrojvHEoi/oCn8BMQmuDzoBsQ/oQq/A7E9AwEQDMQ/gNiHgUggx0AN8IVI/AGkeA+ReCdJTgAAgMhKhf6mzTIAAAAASUVORK5CYII="); transition: background-color .2s, color .2s; } .wikiContent aside.fichier a:hover { background-color: #eee; color: darkred; } .wikiContent figure.image { text-align: center; } .wikiContent figure.image figcaption { font-style: italic; color: #666; margin-top: 2pt; } .wikiContent figure.image.centre { max-width: 500px; margin: 0 auto 8pt auto; } .wikiContent figure.image.gauche { max-width: 200px; float: left; margin: 0 8pt 4pt 0; } .wikiContent figure.image.droite { max-width: 200px; float: right; margin: 0 0 4pt 8pt; } .wikiContent figure.image.gauche figcaption, .wikiContent figure.image.droite figcaption { font-size: .8em; } .wikiFooter { font-size: 0.8em; color: #666; border-top: 0.1em solid #ccc; clear: both; } |
︙ | ︙ | |||
1178 1179 1180 1181 1182 1183 1184 | box-shadow: 0px 0px 5px #999; border-radius: .5em; } form .fileUpload progress { width: 50%; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 | box-shadow: 0px 0px 5px #999; border-radius: .5em; } form .fileUpload progress { width: 50%; } form#insertImage { position: absolute; top: 10px; left: 10px; right: 10px; box-shadow: 5px 5px 10px #999; padding: 1em; background: #ddd; border-radius: .5em; text-align: center; } form#insertImage .align input { font-size: 1.2em; line-height: 32px; background: #fff; background-position: 5px center; background-repeat: no-repeat; padding: 5px; padding-left: 42px; border: 1px solid #999; border-radius: 5px; margin: .5em; } form#insertImage .align input[name=""] { background-image: url("pics/img_flow.png"); } form#insertImage .align input[name="gauche"] { background-image: url("pics/img_left.png"); } form#insertImage .align input[name="droite"] { background-image: url("pics/img_right.png"); } form#insertImage .align input[name="centre"] { background-image: url("pics/img_center.png"); } form#insertImage .align input:hover { background-color: #eee; color: darkred; } |
Modified src/www/admin/static/scripts/upload_helper.min.js from [9401f4e562] to [ce426371a6].
|
| | | 1 | (function(){if(!FileReader||!File||!document.querySelector||!FormData||!XMLHttpRequest||!JSON)return false;function getByteSize(size,bytes){if(size<1024)return size+' '+bytes;else if(size<1024*1024)return Math.round(size/1024)+' K'+bytes;else return(Math.round(size/1024/1024*100)/100)+' M'+bytes}window.uploadHelper=function(element,options){var rusha=new Rusha();var form=element.form;var hash_check=element.hasAttribute('data-hash-check');var upload_queue=false;var hash_queue=false;var progress_status=false;var progress_bar=false;var options=options||{};options.width=options.width||false;options.height=options.height||null;options.resize=(options.width&&options.resize)?true:false;options.bytes=options.bytes||'B';options.size_error_msg=options.size_error_msg||'The file %file has a size of %size, more than the allowed %max_size allowed.';var max_size=null;if(i=form.querySelector('input[name=MAX_FILE_SIZE]')){var max_size=i.value}element.addEventListener('change',function(){var files=this.files;hash_queue=[];if(files.length<1){return false}if(!this.multiple&&files.length>1){this.value='';return false}var l=files.length;for(var i=0;i<l;i++){var file=files[i];if(file.size>max_size&&(!options.resize||!file.type.match(/^image\//))){this.value='';var args={name:file.name,size:getByteSize(file.size,options.bytes),max_size:getByteSize(max_size,options.bytes)};var msg=options.size_error_msg.replace(/%([a-z_]+)/g,function(match,name){return args[name]});return!alert(msg)}hash_queue.push(file)}runHashQueue()},false);form.addEventListener('submit',function(e){if(!element.files||element.files.length==0){return true}e.preventDefault();if(upload_queue!==false){return false}if(upload_queue.length==0){return true}upload_queue=Object.keys(element.files).map(function(key){return element.files[key]});element.disabled=true;var list=form.elements;for(var i=0;i<list.length;i++){if(list[i].type!='hidden'){list[i].readOnly=true}}var progress_container=document.createElement('div');progress_container.className='uploadHelper_progress';progress_bar=document.createElement('progress');progress_container.appendChild(progress_bar);element.parentNode.insertBefore(progress_container,element.nextSibling);if(hash_check){var http=new XMLHttpRequest();var data=new FormData();var count=0;for(var i=0;i<upload_queue.length;i++){if(upload_queue[i].hash){data.append('uploadHelper_hashCheck[]',upload_queue[i].hash);count++}}if(count>0){http.onreadystatechange=function(){if(http.readyState!=4)return;if(http.status==200){var result=http.responseText;result=window.JSON.parse(result);upload_queue=upload_queue.filter(function(file){if(!file.hash)return true;if(file.hash in result)file.noUpload=true;return true})}runUploadQueue()};http.open('POST',form.action,true);http.send(data);return false}}runUploadQueue();return false},false);function runHashQueue(){if(hash_queue.length==0)return false;var file=hash_queue.shift();var fr=new FileReader;fr.file=file;fr.onloadend=function(){if(this.error)return false;fr.file.hash=rusha.digestFromArrayBuffer(fr.result);delete fr;runHashQueue()};fr.readAsArrayBuffer(file)}function runUploadQueue(){if(upload_queue.length==0){return false}var file=upload_queue.shift();progress_status=upload_queue.length;if(options.resize&&file.type.match(/^image\/jpe?g/)&&!file.noUpload){progress_bar.removeAttribute('max');progress_bar.removeAttribute('value');resize(file,options.width,options.height,function(resizedBlob){if(resizedBlob.size>max_size){this.value='';var args={name:file.name,size:getByteSize(resizedBlob.size,options.bytes),max_size:getByteSize(max_size,options.bytes)};var msg=options.size_error_msg.replace(/%([a-z_]+)/g,function(match,name){return args[name]});abortUpload();return!alert(msg)}uploadFile(file,resizedBlob)})}else{uploadFile(file,false)}}function uploadFile(file,resizedBlob){var http=new XMLHttpRequest();var data=new FormData(form);if(file.noUpload){data.append(element.getAttribute('name'),file.name)}else if(resizedBlob){data.append(element.getAttribute('name'),resizedBlob,file.name)}else{data.append(element.getAttribute('name'),file)}if(file.hash){data.append('uploadHelper_fileHash',file.hash)}data.append('uploadHelper_status',progress_status);http.onprogress=function(e){progress_bar.max=e.total;if(e.lengthComputable){progress_bar.value=e.loaded;progress_bar.innerHTML=Math.round(e.loaded/e.total)+'%'}else{progress_bar.innerHTML=e.loaded}};http.onreadystatechange=function(){if(http.readyState!=4)return;if(http.status==200){try{var result=window.JSON.parse(http.responseText)}catch(e){var result={error:'Server replied with invalid JSON ('+e.message+'): '+http.responseText}}try{if(result.callback&&window[result.callback](result)){return false}else if(result.redirect){location.href=result.redirect;return false}else if(result.next){runUploadQueue();return false}}catch(e){var result={error:'Server error: '+e.message}}}else{var result={error:'Server response error. HTTP code: '+http.status}}alert(result.error);abortUpload();delete http};http.open('POST',form.action,true);http.send(data);delete data;if(upload_queue.length+1==element.files.length){var list=form.elements;for(var i=0;i<list.length;i++){if(list[i].type!='hidden'){list[i].disabled=true}}}}function abortUpload(){var list=form.elements;for(var i=0;i<list.length;i++){if(list[i].type!='hidden'){list[i].disabled=false;list[i].readOnly=false}}progress_status='error';progress_bar.parentNode.parentNode.removeChild(progress_bar.parentNode);upload_queue=false}function resize(file,max_width,max_height,callback){var img=new Image;img.src=(window.URL||window.webkitURL).createObjectURL(file);img.onload=function(){var width=max_width,height=max_height;if(max_height==null&&max_width<0){var max_mp=Math.abs(max_width)*Math.abs(max_width);var img_mp=img.width*img.height;if(img_mp>max_mp){var ratio=Math.sqrt(img_mp)/Math.abs(max_width);height=Math.round(img.height/ratio);width=Math.round(img.width/ratio)}else{width=img.width;height=img.height}if(width>Math.abs(max_width)*10){width=Math.abs(max_width)*10;height=Math.round(img.height*width/img.width)}else if(height>Math.abs(max_width)*10){height=Math.abs(max_width)*10;width=Math.round(img.width*height/img.height)}}else if(max_height==null){if(img.width>img.height){height=Math.round(img.height*max_width/img.width)}else if(img.width==img.height){height=max_width}else{height=max_width;width=Math.round(img.width*height/img.height)}if(img.width<width&&img.height<height){width=img.width,height=img.height}}width=Math.abs(width);height=Math.abs(height);var canvas2=false,ctx=false;if(width<img.width||height<img.height){canvas2=document.createElement("canvas");canvas2.width=width*2;canvas2.height=height*2;canvas2.getContext("2d").drawImage(img,0,0,img.width,img.height,0,0,width*2,height*2)}var canvas=document.createElement("canvas");canvas.width=width;canvas.height=height;canvas.getContext("2d").drawImage((canvas2||img),0,0,(canvas2||img).width,(canvas2||img).height,0,0,width,height);delete canvas2;canvas.toBlob(callback,'image/jpeg',0.85);(window.URL||window.webkitURL).revokeObjectURL(img.src);delete img;delete canvas}}};!function(){function a(a){"use strict";var d={fill:0},f=function(a){for(a+=9;a%64>0;a+=1);return a},g=function(a,b){for(var c=b>>2;c<a.length;c++)a[c]=0},h=function(a,b,c){a[b>>2]|=128<<24-(b%4<<3),a[((b>>2)+2&-16)+15]=c<<3},i=function(a,b,c,d,e){var f,g=this,h=e%4,i=d%4,j=d-i;if(j>0)switch(h){case 0:a[e+3|0]=g.charCodeAt(c);case 1:a[e+2|0]=g.charCodeAt(c+1);case 2:a[e+1|0]=g.charCodeAt(c+2);case 3:a[0|e]=g.charCodeAt(c+3)}for(f=h;j>f;f=f+4|0)b[e+f>>2]=g.charCodeAt(c+f)<<24|g.charCodeAt(c+f+1)<<16|g.charCodeAt(c+f+2)<<8|g.charCodeAt(c+f+3);switch(i){case 3:a[e+j+1|0]=g.charCodeAt(c+j+2);case 2:a[e+j+2|0]=g.charCodeAt(c+j+1);case 1:a[e+j+3|0]=g.charCodeAt(c+j)}},j=function(a,b,c,d,e){var f,g=this,h=e%4,i=d%4,j=d-i;if(j>0)switch(h){case 0:a[e+3|0]=g[c];case 1:a[e+2|0]=g[c+1];case 2:a[e+1|0]=g[c+2];case 3:a[0|e]=g[c+3]}for(f=4-h;j>f;f=f+=4)b[e+f>>2]=g[c+f]<<24|g[c+f+1]<<16|g[c+f+2]<<8|g[c+f+3];switch(i){case 3:a[e+j+1|0]=g[c+j+2];case 2:a[e+j+2|0]=g[c+j+1];case 1:a[e+j+3|0]=g[c+j]}},k=function(a,b,d,e,f){var g,h=this,i=f%4,j=e%4,k=e-j,l=new Uint8Array(c.readAsArrayBuffer(h.slice(d,d+e)));if(k>0)switch(i){case 0:a[f+3|0]=l[0];case 1:a[f+2|0]=l[1];case 2:a[f+1|0]=l[2];case 3:a[0|f]=l[3]}for(g=4-i;k>g;g=g+=4)b[f+g>>2]=l[g]<<24|l[g+1]<<16|l[g+2]<<8|l[g+3];switch(j){case 3:a[f+k+1|0]=l[k+2];case 2:a[f+k+2|0]=l[k+1];case 1:a[f+k+3|0]=l[k]}},l=function(a){switch(e.getDataType(a)){case"string":return i.bind(a);case"array":return j.bind(a);case"buffer":return j.bind(a);case"arraybuffer":return j.bind(new Uint8Array(a));case"view":return j.bind(new Uint8Array(a.buffer,a.byteOffset,a.byteLength));case"blob":return k.bind(a)}},m=function(a){var b,c,d="0123456789abcdef",e=[],f=new Uint8Array(a);for(b=0;b<f.length;b++)c=f[b],e[b]=d.charAt(c>>4&15)+d.charAt(c>>0&15);return e.join("")},n=function(a){var b;if(65536>=a)return 65536;if(16777216>a)for(b=1;a>b;b<<=1);else for(b=16777216;a>b;b+=16777216);return b},o=function(a){if(a%64>0)throw new Error("Chunk size must be a multiple of 128 bit");d.maxChunkLen=a,d.padMaxChunkLen=f(a),d.heap=new ArrayBuffer(n(d.padMaxChunkLen+320+20)),d.h32=new Int32Array(d.heap),d.h8=new Int8Array(d.heap),d.core=b({Int32Array:Int32Array,DataView:DataView},{},d.heap),d.buffer=null};o(a||65536);var p=function(a,b){var c=new Int32Array(a,b+320,5);c[0]=1732584193,c[1]=-271733879,c[2]=-1732584194,c[3]=271733878,c[4]=-1009589776},q=function(a,b){var c=f(a),e=new Int32Array(d.heap,0,c>>2);return g(e,a),h(e,a,b),c},r=function(a,b,c){l(a)(d.h8,d.h32,b,c,0)},s=function(a,b,c,e,f){var g=c;f&&(g=q(c,e)),r(a,b,c),d.core.hash(g,d.padMaxChunkLen)},t=function(a,b){var c=new Int32Array(a,b+320,5),d=new Int32Array(5),e=new DataView(d.buffer);return e.setInt32(0,c[0],!1),e.setInt32(4,c[1],!1),e.setInt32(8,c[2],!1),e.setInt32(12,c[3],!1),e.setInt32(16,c[4],!1),d},u=this.rawDigest=function(a){var b=a.byteLength||a.length||a.size;p(d.heap,d.padMaxChunkLen);var c=0,e=d.maxChunkLen;for(c=0;b>c+e;c+=e)s(a,c,e,b,!1);return s(a,c,b-c,b,!0),t(d.heap,d.padMaxChunkLen)};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(a){return m(u(a).buffer)}}function b(a,b,c){"use asm";function d(a,b){a|=0,b|=0;var c=0,d=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;for(f=e[b+320>>2]|0,h=e[b+324>>2]|0,j=e[b+328>>2]|0,l=e[b+332>>2]|0,n=e[b+336>>2]|0,c=0;(c|0)<(a|0);c=c+64|0){for(g=f,i=h,k=j,m=l,o=n,d=0;(d|0)<64;d=d+4|0)q=e[c+d>>2]|0,p=((f<<5|f>>>27)+(h&j|~h&l)|0)+((q+n|0)+1518500249|0)|0,n=l,l=j,j=h<<30|h>>>2,h=f,f=p,e[a+d>>2]=q;for(d=a+64|0;(d|0)<(a+80|0);d=d+4|0)q=(e[d-12>>2]^e[d-32>>2]^e[d-56>>2]^e[d-64>>2])<<1|(e[d-12>>2]^e[d-32>>2]^e[d-56>>2]^e[d-64>>2])>>>31,p=((f<<5|f>>>27)+(h&j|~h&l)|0)+((q+n|0)+1518500249|0)|0,n=l,l=j,j=h<<30|h>>>2,h=f,f=p,e[d>>2]=q;for(d=a+80|0;(d|0)<(a+160|0);d=d+4|0)q=(e[d-12>>2]^e[d-32>>2]^e[d-56>>2]^e[d-64>>2])<<1|(e[d-12>>2]^e[d-32>>2]^e[d-56>>2]^e[d-64>>2])>>>31,p=((f<<5|f>>>27)+(h^j^l)|0)+((q+n|0)+1859775393|0)|0,n=l,l=j,j=h<<30|h>>>2,h=f,f=p,e[d>>2]=q;for(d=a+160|0;(d|0)<(a+240|0);d=d+4|0)q=(e[d-12>>2]^e[d-32>>2]^e[d-56>>2]^e[d-64>>2])<<1|(e[d-12>>2]^e[d-32>>2]^e[d-56>>2]^e[d-64>>2])>>>31,p=((f<<5|f>>>27)+(h&j|h&l|j&l)|0)+((q+n|0)-1894007588|0)|0,n=l,l=j,j=h<<30|h>>>2,h=f,f=p,e[d>>2]=q;for(d=a+240|0;(d|0)<(a+320|0);d=d+4|0)q=(e[d-12>>2]^e[d-32>>2]^e[d-56>>2]^e[d-64>>2])<<1|(e[d-12>>2]^e[d-32>>2]^e[d-56>>2]^e[d-64>>2])>>>31,p=((f<<5|f>>>27)+(h^j^l)|0)+((q+n|0)-899497514|0)|0,n=l,l=j,j=h<<30|h>>>2,h=f,f=p,e[d>>2]=q;f=f+g|0,h=h+i|0,j=j+k|0,l=l+m|0,n=n+o|0}e[b+320>>2]=f,e[b+324>>2]=h,e[b+328>>2]=j,e[b+332>>2]=l,e[b+336>>2]=n}var e=new a.Int32Array(c);return{hash:d}}if("undefined"!=typeof module?module.exports=a:"undefined"!=typeof window&&(window.Rusha=a),"undefined"!=typeof FileReaderSync){var c=new FileReaderSync,d=new a(4194304);self.onmessage=function(a){var b,c=a.data.data;try{b=d.digest(c),self.postMessage({id:a.data.id,hash:b})}catch(e){self.postMessage({id:a.data.id,error:e.name})}}}var e={getDataType:function(a){if("string"==typeof a)return"string";if(a instanceof Array)return"array";if("undefined"!=typeof global&&global.Buffer&&global.Buffer.isBuffer(a))return"buffer";if(a instanceof ArrayBuffer)return"arraybuffer";if(a.buffer instanceof ArrayBuffer)return"view";if(a instanceof Blob)return"blob";throw new Error("Unsupported data type.")}}}();!function(a){"use strict";var b=a.HTMLCanvasElement&&a.HTMLCanvasElement.prototype,c=a.Blob&&function(){try{return Boolean(new Blob)}catch(a){return!1}}(),d=c&&a.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(a){return!1}}(),e=a.BlobBuilder||a.WebKitBlobBuilder||a.MozBlobBuilder||a.MSBlobBuilder,f=(c||e)&&a.atob&&a.ArrayBuffer&&a.Uint8Array&&function(a){var b,f,g,h,i,j;for(b=a.split(",")[0].indexOf("base64")>=0?atob(a.split(",")[1]):decodeURIComponent(a.split(",")[1]),f=new ArrayBuffer(b.length),g=new Uint8Array(f),h=0;h<b.length;h+=1)g[h]=b.charCodeAt(h);return i=a.split(",")[0].split(":")[1].split(";")[0],c?new Blob([d?g:f],{type:i}):(j=new e,j.append(f),j.getBlob(i))};a.HTMLCanvasElement&&!b.toBlob&&(b.mozGetAsFile?b.toBlob=function(a,c,d){d&&b.toDataURL&&f?a(f(this.toDataURL(c,d))):a(this.mozGetAsFile("blob",c))}:b.toDataURL&&f&&(b.toBlob=function(a,b,c){a(f(this.toDataURL(b,c)))})),"function"==typeof define&&define.amd?define(function(){return f}):a.dataURLtoBlob=f}(this)}()); |
Modified src/www/admin/static/scripts/wiki_editor.js from [c0f5f73faf] to [2dad10610c].
︙ | ︙ | |||
54 55 56 57 58 59 60 | var openFileInsert = function () { openIFrame(g.admin_url + 'wiki/_fichiers.php?page=' + wiki_id); }; window.te_insertFile = function (file) { | | > > > > > > > > > > > > > > > > > | 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 | var openFileInsert = function () { openIFrame(g.admin_url + 'wiki/_fichiers.php?page=' + wiki_id); }; window.te_insertFile = function (file) { var tag = '<<fichier|'+file+'>>'; t.insertAtPosition(t.getSelection().start, tag); closeIFrame(); }; window.te_insertImage = function (file, position, caption) { var tag = '<<image|' + file; if (position) tag += '|' + position; if (caption) tag += '|' + caption; tag += '>>'; t.insertAtPosition(t.getSelection().start, tag); closeIFrame(); }; var openIFrame = function(url) |
︙ | ︙ |
Modified src/www/admin/wiki/_fichiers.php from [6646d8add2] to [0e02822f72].
︙ | ︙ | |||
50 51 52 53 54 55 56 | $uri = '/admin/wiki/_fichiers.php?page=' . $page['id'] . '&sent'; if (isset($_POST['uploadHelper_status'])) { echo json_encode([ 'redirect' => WWW_URL . $uri, 'callback' => 'insertHelper', | | > > > > > | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | $uri = '/admin/wiki/_fichiers.php?page=' . $page['id'] . '&sent'; if (isset($_POST['uploadHelper_status'])) { echo json_encode([ 'redirect' => WWW_URL . $uri, 'callback' => 'insertHelper', 'file' => [ 'image' => (int)$fichier->image, 'id' => (int)$fichier->id, 'nom' => $fichier->nom, 'thumb' => $fichier->image ? $fichier->getURL(200) : false ], ]); exit; } Utils::redirect($uri); } catch (UserException $e) |
︙ | ︙ |
Modified src/www/file.php from [994f0ee89a] to [f417e4bfb3].
1 2 3 4 5 6 7 | <?php namespace Garradin; require __DIR__ . '/_inc.php'; $id = isset($_GET['id']) ? $_GET['id'] : false; | < > > > > > > > > > > | | | 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 | <?php namespace Garradin; require __DIR__ . '/_inc.php'; $id = isset($_GET['id']) ? $_GET['id'] : false; $filename = !empty($_GET['file']) ? $_GET['file'] : false; $size = false; if (empty($id)) { throw new UserException('Fichier inconnu.'); } foreach ($_GET as $key=>$value) { if (substr($key, -2) == 'px') { $size = (int)substr($key, 0, -2); break; } } $id = base_convert($id, 36, 10); $file = new Fichiers((int)$id); $membres = new Membres; $is_logged = $membres->isLogged(); if (!$file->checkAccess($membres->getLoggedUser())) { header('HTTP/1.1 403 Forbidden', true, 403); throw new UserException('Vous n\'avez pas accès à ce fichier.'); } if ($size) { $file->serveThumbnail($size); } else { $file->serve(); } |