Overview
Comment:Modernisation/remise en fonctionnement des fichiers dans le wiki
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 2db443930dd65171f7d621c98534ec9a7e874194
User & Date: bohwaz on 2017-05-19 05:46:53
Other Links: branch diff | manifest | tags
Context
2017-05-19
07:25
Modernisation compta / changement aussi de la gestion des forms pour faire de l'objet check-in: 61ac1e5c2a user: bohwaz tags: dev
05:46
Modernisation/remise en fonctionnement des fichiers dans le wiki check-in: 2db443930d user: bohwaz tags: dev
2017-05-18
07:29
Modernisation admin wiki et fichiers check-in: 9f46f9067f user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/DB.php from [fec2e78e68] to [9faaff99f4].

209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
            if (is_array($args) && count($args) == 1 && is_array(current($args)))
            {
                $args = current($args);
            }
            
            if (count($args) != $nb)
            {
                throw new \LengthException('Arguments error: '.count($args).' supplied, but '.$nb.' are required by query.');

            }

            reset($args);

            if (is_int(key($args)))
            {
                foreach ($args as $i=>$arg)







|
>







209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
            if (is_array($args) && count($args) == 1 && is_array(current($args)))
            {
                $args = current($args);
            }
            
            if (count($args) != $nb)
            {
                throw new \LengthException(sprintf('Arguments error: %d supplied, but %d are required by query.', 
                    count($args), $nb));
            }

            reset($args);

            if (is_int(key($args)))
            {
                foreach ($args as $i=>$arg)
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
                {
                    if (is_int($key))
                    {
                        throw new \InvalidArgumentException(sprintf('%s requires argument to be a named-associative array, but key %s is an integer.', __FUNCTION__, $key));
                    }

                    $type = $this->getArgType($value, $key);
                    $statement->bindValue(':'.$key, $value, $type);
                }
            }
        }

        try {
            // Return a boolean for write queries to avoid accidental duplicate execution
            // see https://bugs.php.net/bug.php?id=64531







|







238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
                {
                    if (is_int($key))
                    {
                        throw new \InvalidArgumentException(sprintf('%s requires argument to be a named-associative array, but key %s is an integer.', __FUNCTION__, $key));
                    }

                    $type = $this->getArgType($value, $key);
                    $statement->bindValue(':' . $key, $value, $type);
                }
            }
        }

        try {
            // Return a boolean for write queries to avoid accidental duplicate execution
            // see https://bugs.php.net/bug.php?id=64531

Modified src/include/lib/Garradin/Fichiers.php from [a32f5a5338] to [a5bf15ced2].

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
		$check = [self::LIEN_MEMBRES, self::LIEN_WIKI, self::LIEN_COMPTA];

		if (!in_array($type, $check))
		{
			throw new \LogicException('Type de lien de fichier inconnu.');
		}

		// Ne pas chercher dans le type qu'on veut lier
		unset($check[array_search($type, $check)]);

		// Vérifier que le fichier n'est pas déjà lié à un autre type
		$query = [];

		foreach ($check as $type)
		{






			$query[] = sprintf('SELECT 1 FROM fichiers_%s WHERE fichier = %d', $type, $this->id);
		}

		$query = implode(' UNION ', $query) . ';';

		if ($db->firstColumn($query))
		{
			throw new \LogicException('Ce fichier est déjà lié à un autre contenu : ' . $check_type);
		}

		return $db->query('INSERT OR IGNORE INTO fichiers_' . $type . ' (fichier, id) VALUES (?, ?);',
			(int)$this->id, (int)$foreign_id);
	}

	/**
	 * Vérifie que l'utilisateur a bien le droit d'accéder à ce fichier
	 * @param  mixed   $user Tableau contenant les infos sur l'utilisateur connecté, provenant de Membres::getLoggedUser, ou false
	 * @return boolean       TRUE si l'utilisateur a le droit d'accéder au fichier, sinon FALSE
	 */







<
<
<



|

>
>
>
>
>
>
|










|







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
		$check = [self::LIEN_MEMBRES, self::LIEN_WIKI, self::LIEN_COMPTA];

		if (!in_array($type, $check))
		{
			throw new \LogicException('Type de lien de fichier inconnu.');
		}




		// Vérifier que le fichier n'est pas déjà lié à un autre type
		$query = [];

		foreach ($check as $check_type)
		{
			// Ne pas chercher dans le type qu'on veut lier
			if ($check_type == $type)
			{
				continue;
			}

			$query[] = sprintf('SELECT 1 FROM fichiers_%s WHERE fichier = %d', $check_type, $this->id);
		}

		$query = implode(' UNION ', $query) . ';';

		if ($db->firstColumn($query))
		{
			throw new \LogicException('Ce fichier est déjà lié à un autre contenu : ' . $check_type);
		}

		return $db->query('INSERT OR IGNORE INTO fichiers_' . $type . ' (fichier, id) VALUES (?, ?);',
			[(int)$this->id, (int)$foreign_id]);
	}

	/**
	 * Vérifie que l'utilisateur a bien le droit d'accéder à ce fichier
	 * @param  mixed   $user Tableau contenant les infos sur l'utilisateur connecté, provenant de Membres::getLoggedUser, ou false
	 * @return boolean       TRUE si l'utilisateur a le droit d'accéder au fichier, sinon FALSE
	 */
485
486
487
488
489
490
491

492
493
494
495
496
497
498
		$db->commit();

		return new Fichiers($db->lastInsertRowID());
	}

	/**
	 * Envoie un fichier déjà stocké

	 * @param  string $name Nom du fichier
	 * @param  string $hash Hash SHA1 du contenu du fichier
	 * @return object       Un objet Fichiers en cas de succès
	 */
	static public function uploadExistingHash($name, $hash)
	{
		$db = DB::getInstance();







>







488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
		$db->commit();

		return new Fichiers($db->lastInsertRowID());
	}

	/**
	 * Envoie un fichier déjà stocké
	 * 
	 * @param  string $name Nom du fichier
	 * @param  string $hash Hash SHA1 du contenu du fichier
	 * @return object       Un objet Fichiers en cas de succès
	 */
	static public function uploadExistingHash($name, $hash)
	{
		$db = DB::getInstance();
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
585
586
587
			'type'       =>	$file->type,
			'image'      =>	(int)$file->image,
		]);

		return new Fichiers($db->lastInsertRowID());
	}

    /**
     * Récupère la liste des fichiers liés à une ressource
     * 
     * @param  string  $type    Type de ressource
     * @param  integer $id      Numéro de ressource
     * @param  boolean $images  TRUE pour retourner seulement les images,
     * FALSE pour retourner les fichiers sans images, NULL pour tout retourner
     * @return array          Liste des fichiers
     */
    static public function listLinkedFiles($type, $id, $images = false)
    {
		$check = [self::LIEN_MEMBRES, self::LIEN_WIKI, self::LIEN_COMPTA];

		if (!in_array($type, $check))
		{
			throw new \LogicException('Type de lien de fichier inconnu.');
		}

    	$images = is_null($images) ? '' : ' AND image = ' . (int)$images;

        $files = DB::getInstance()->get('SELECT fichiers.*, c.hash, c.taille
        	FROM fichiers 
            INNER JOIN fichiers_'.$type.' AS fwp ON fwp.fichier = fichiers.id
            INNER JOIN fichiers_contenu AS c ON c.id = fichiers.id_contenu
            WHERE fwp.id = ? '.$images.'
            ORDER BY fichiers.nom COLLATE NOCASE;', (int)$id);



        foreach ($files as &$file)
        {
        	$file->url = self::_getURL($file->id, $file->nom);
        	$file->thumb = $file->image ? self::_getURL($file->id, $file->nom, 200) : false;
        }

        return $files;
    }

    /**
     * Enlève d'une liste de fichiers ceux qui sont mentionnés dans un texte wiki
     * @param  array $files Liste de fichiers
     * @param  string $text  texte wiki
     * @return array        Un tableau qui ne contient pas les fichiers mentionnés dans $text
     */
    static public function filterFilesUsedInText($files, $text)
    {
    	$used = self::listFilesUsedInText($text);

    	return array_filter($files, function ($row) use ($used) {
    		return !in_array($row->id, $used);
    	});
    }

    /**
     * Renvoie une liste d'ID de fichiers mentionnées dans un texte wiki
     * @param  string $text Texte wiki
     * @return array       Liste des IDs de fichiers mentionnés
     */
    static public function listFilesUsedInText($text)
	{
    	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]);
	}

	/**
	 * 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







|
|
|
|
|
|
|
|
|
|
|







|

|
|
|
|
|
|
>
>

|
|
|
|
|

|
|

|
|
|
|
|
|
|
|
|

|
|
|
|

|
|
|
|
|
|

|
|
|
|







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
585
586
587
588
589
590
591
592
593
			'type'       =>	$file->type,
			'image'      =>	(int)$file->image,
		]);

		return new Fichiers($db->lastInsertRowID());
	}

	/**
	 * Récupère la liste des fichiers liés à une ressource
	 * 
	 * @param  string  $type    Type de ressource
	 * @param  integer $id      Numéro de ressource
	 * @param  boolean $images  TRUE pour retourner seulement les images,
	 * FALSE pour retourner les fichiers sans images, NULL pour tout retourner
	 * @return array          Liste des fichiers
	 */
	static public function listLinkedFiles($type, $id, $images = false)
	{
		$check = [self::LIEN_MEMBRES, self::LIEN_WIKI, self::LIEN_COMPTA];

		if (!in_array($type, $check))
		{
			throw new \LogicException('Type de lien de fichier inconnu.');
		}

		$images = is_null($images) ? '' : ' AND image = ' . (int)$images;

		$query = sprintf('SELECT fichiers.*, c.hash, c.taille
			FROM fichiers 
			INNER JOIN fichiers_%s AS fwp ON fwp.fichier = fichiers.id
			INNER JOIN fichiers_contenu AS c ON c.id = fichiers.id_contenu
			WHERE fwp.id = ? %s
			ORDER BY fichiers.nom COLLATE NOCASE;', $type, $images);

		$files = DB::getInstance()->get($query, (int)$id);

		foreach ($files as &$file)
		{
			$file->url = self::_getURL($file->id, $file->nom);
			$file->thumb = $file->image ? self::_getURL($file->id, $file->nom, 200) : false;
		}

		return $files;
	}

	/**
	 * Enlève d'une liste de fichiers ceux qui sont mentionnés dans un texte wiki
	 * @param  array $files Liste de fichiers
	 * @param  string $text  texte wiki
	 * @return array        Un tableau qui ne contient pas les fichiers mentionnés dans $text
	 */
	static public function filterFilesUsedInText($files, $text)
	{
		$used = self::listFilesUsedInText($text);

		return array_filter($files, function ($row) use ($used) {
			return !in_array($row->id, $used);
		});
	}

	/**
	 * Renvoie une liste d'ID de fichiers mentionnées dans un texte wiki
	 * @param  string $text Texte wiki
	 * @return array       Liste des IDs de fichiers mentionnés
	 */
	static public function listFilesUsedInText($text)
	{
		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]);
	}

	/**
	 * 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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657

		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;
			}







|







649
650
651
652
653
654
655
656
657
658
659
660
661
662
663

		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;
			}

Modified src/templates/admin/wiki/page.tpl from [453f6fcd36] to [998e3daac8].

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
                <h3>Fichiers liés à cette page</h3>

                {if !empty($images)}
                <ul class="gallery">
                    {foreach from=$images item="file"}
                        <li>
                            <figure>
                                <a href="{$file.url}"><img src="{$file.thumb}" alt="" title="{$file.nom}" /></a>
                            </figure>
                        </li>
                    {/foreach}
                </ul>
                {/if}

                {if !empty($fichiers)}







|







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
                <h3>Fichiers liés à cette page</h3>

                {if !empty($images)}
                <ul class="gallery">
                    {foreach from=$images item="file"}
                        <li>
                            <figure>
                                <a class="internal-image" href="{$file.url}"><img src="{$file.thumb}" alt="" title="{$file.nom}" /></a>
                            </figure>
                        </li>
                    {/foreach}
                </ul>
                {/if}

                {if !empty($fichiers)}

Modified src/www/admin/static/scripts/upload_helper.min.js from [ce426371a6] to [05df43b6a9].

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)}());
|
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\/jpe?g/))){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('uploadHelper_mode','hash_only');data.append('uploadHelper_fileName',file.name);}else if(resizedBlob){data.append('uploadHelper_mode','upload');data.append(element.getAttribute('name'),resizedBlob,file.name);}else{data.append('uploadHelper_mode','upload');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_gallery.js from [295d9c1bd1] to [baf8189a4f].

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
(function () {
    var enableGallery = function () {
        var gallery = document.getElementsByClassName('gallery');

        if (gallery.length == 1 && document.querySelector)

        {
            var items = gallery[0].getElementsByTagName('li');

            for (var i = 0; i < items.length; i++)
            {
                var a = items[i].querySelector('figure > a');
                a.pos = i;
                a.onclick= function (e) {
                    e.preventDefault();
                    openImageBrowser(items, this.pos);
                    return false;
                };
            }
        }
    };

    if (document.addEventListener)
        document.addEventListener('DOMContentLoaded', enableGallery, false);
    else
        document.attachEvent('onDOMContentLoaded', callback);


|
|
|
>
|
|

|
|
|
|
|
|
|
|
|
<







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
(function () {
    var enableGallery = function () {
        if (!document.querySelectorAll)
        {
            return false;
        }

        var items = document.querySelectorAll('a.internal-image');

        for (var i = 0; i < items.length; i++)
        {
            var a = items[i];
            a.pos = i;
            a.onclick= function (e) {
                e.preventDefault();
                openImageBrowser(items, this.pos);
                return false;
            };

        }
    };

    if (document.addEventListener)
        document.addEventListener('DOMContentLoaded', enableGallery, false);
    else
        document.attachEvent('onDOMContentLoaded', callback);
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

        img.onclick = function (e) {
            e.stopPropagation();
            openImage(img, items);
        };

        var fig = document.createElement('figure');


        div.onclick = function (e) {

            div.parentNode.removeChild(div);
        };

        fig.appendChild(img);
        div.appendChild(fig);
        document.body.appendChild(div);

        openImage(img, items);
    }

    function openImage(img, items)
    {
        // Pour animation
        img.style.opacity = 0;

        if (++img.pos == items.length)
        {

            img.pos = 0;


        }

        var newImg = new Image;
        newImg.onload = function (e) {
            img.src = e.target.src;


            img.style.opacity = 1;

        };

        newImg.src = items[img.pos].querySelector('figure > a').href;
        return false;   
    }

}());







>


>
|












|



>
|
>
>




|
>
>
|
>


|




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

        img.onclick = function (e) {
            e.stopPropagation();
            openImage(img, items);
        };

        var fig = document.createElement('figure');
        fig.style.opacity = 0;

        div.onclick = function (e) {
            div.style.opacity = 0;
            window.setTimeout(function() { div.parentNode.removeChild(div); }, 500);
        };

        fig.appendChild(img);
        div.appendChild(fig);
        document.body.appendChild(div);

        openImage(img, items);
    }

    function openImage(img, items)
    {
        // Pour animation
        img.parentNode.style.opacity = 0;

        if (++img.pos == items.length)
        {
            var div = img.parentNode.parentNode;
            div.style.opacity = 0;
            window.setTimeout(function() { div.parentNode.removeChild(div); }, 500);
            return;
        }

        var newImg = new Image;
        newImg.onload = function (e) {
            var new_src = e.target.src;
            window.setTimeout(function() {
                img.src = new_src;
                img.parentNode.style.opacity = 1;
            }, img.src ? 250 : 0);
        };

        newImg.src = items[img.pos].href;
        return false;   
    }

}());

Modified src/www/admin/static/wiki.css from [bda497e43c] to [5907c3bd49].

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
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: rgb(0, 0, 0);
    background: rgba(0, 0, 0, 0.75);
    text-align: center;

}

.imageBrowser figure {
    margin: 5%;
    width: 90%;
    height: 90%;

}

.imageBrowser figure img {
    top: 50%;
    transform: translateY(-50%);
    position: relative;
    max-width: 100%;
    width: auto;
    height: auto;
    background: #fff;
    padding: 2%;
    max-height: 90%;
    max-width: 90%;
    border-radius: .5em;
    cursor: pointer;
    transition: all .5s;
}







>






>















<

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
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: rgb(0, 0, 0);
    background: rgba(0, 0, 0, 0.75);
    text-align: center;
    transition: opacity .5s;
}

.imageBrowser figure {
    margin: 5%;
    width: 90%;
    height: 90%;
    transition: all .5s;
}

.imageBrowser figure img {
    top: 50%;
    transform: translateY(-50%);
    position: relative;
    max-width: 100%;
    width: auto;
    height: auto;
    background: #fff;
    padding: 2%;
    max-height: 90%;
    max-width: 90%;
    border-radius: .5em;
    cursor: pointer;

}

Modified src/www/admin/wiki/_fichiers.php from [abc1a885cc] to [621f8f7b9e].

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

// Vérification des hash avant upload
if ($hash_check = f('uploadHelper_hashCheck'))
{
    echo json_encode(Fichiers::checkHashList($hash_check));
    exit;
}

if (f('delete'))
{
    if (fc('wiki_files_'.$page->id, [], $form_errors))
    {
        try {
            $fichier = new Fichiers(f('delete'));
            
            if (!$fichier->checkAccess($user))
            {
                throw new UserException('Vous n\'avez pas accès à ce fichier.');
            }

            $fichier->remove();
            Utils::redirect('/admin/wiki/_fichiers.php?page=' . $page->id);
        }
        catch (UserException $e)
        {
            $form_errors[] = $e->getMessage();
        }
    }
}



if (f('upload') || f('uploadHelper_status') !== null)

{






    fc('wiki_files_'.$page->id, [], $form_errors);

    if (f('uploadHelper_status') > 0)
    {
        $form_errors[] = 'Un seul fichier peut être envoyé en même temps.';
    }
    
    if (f('fichier') && count($form_errors) === 0)
    {
        try {
            if (null !== f('uploadHelper_status') && f('fichier'))
            {
                $fichier = Fichiers::uploadExistingHash(f('fichier'), f('uploadHelper_fileHash'));
            }
            else
            {
                $fichier = Fichiers::upload(f('fichier'));
            }

            // Lier le fichier à la page wiki
            $fichier->linkTo(Fichiers::LIEN_WIKI, $page->id);
            $uri = '/admin/wiki/_fichiers.php?page=' . $page->id . '&sent';

            if (f('uploadHelper_status') !== null)







<
|




















>
|
>
|
>
|
>
>
>
>
>
>
|






|


|

|



|







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

// Vérification des hash avant upload
if ($hash_check = f('uploadHelper_hashCheck'))
{
    echo json_encode(Fichiers::checkHashList($hash_check));
    exit;
}

elseif (f('delete'))
{
    if (fc('wiki_files_'.$page->id, [], $form_errors))
    {
        try {
            $fichier = new Fichiers(f('delete'));
            
            if (!$fichier->checkAccess($user))
            {
                throw new UserException('Vous n\'avez pas accès à ce fichier.');
            }

            $fichier->remove();
            Utils::redirect('/admin/wiki/_fichiers.php?page=' . $page->id);
        }
        catch (UserException $e)
        {
            $form_errors[] = $e->getMessage();
        }
    }
}
elseif (f('upload') || f('uploadHelper_mode'))
{
    $validate = ['fichier' => 'file|required'];

    if (f('uploadHelper_mode') == 'hash_only')
    {
        $validate = [
            'uploadHelper_fileHash' => 'required',
            'uploadHelper_fileName' => 'required',
        ];
    }

    fc('wiki_files_'.$page->id, $validate, $form_errors);

    if (f('uploadHelper_status') > 0)
    {
        $form_errors[] = 'Un seul fichier peut être envoyé en même temps.';
    }
    
    if (count($form_errors) === 0)
    {
        try {
            if (f('uploadHelper_mode') == 'hash_only' && f('uploadHelper_fileHash') && f('uploadHelper_fileName'))
            {
                $fichier = Fichiers::uploadExistingHash(f('uploadHelper_fileName'), f('uploadHelper_fileHash'));
            }
            else
            {
                $fichier = Fichiers::upload($_FILES['fichier']);
            }

            // Lier le fichier à la page wiki
            $fichier->linkTo(Fichiers::LIEN_WIKI, $page->id);
            $uri = '/admin/wiki/_fichiers.php?page=' . $page->id . '&sent';

            if (f('uploadHelper_status') !== null)
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
            Utils::redirect($uri);
        }
        catch (UserException $e)
        {
            $form_errors[] = $e->getMessage();
        }
    }
    else
    {
        $form_errors[] = 'Aucun fichier envoyé.';
    }

    if (f('uploadHelper_status') !== null)
    {
        echo json_encode(['error' => implode(PHP_EOL, $form_errors)]);
        exit;
    }
}

$tpl->assign('fichiers', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page->id, false));







<
|
<
<
<
|







93
94
95
96
97
98
99

100



101
102
103
104
105
106
107
108
            Utils::redirect($uri);
        }
        catch (UserException $e)
        {
            $form_errors[] = $e->getMessage();
        }
    }





    if (f('uploadHelper_mode') !== null)
    {
        echo json_encode(['error' => implode(PHP_EOL, $form_errors)]);
        exit;
    }
}

$tpl->assign('fichiers', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page->id, false));

Modified src/www/file.php from [62df87e6f0] to [20b291aa1b].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
	$file = new Fichiers((int)$id);
}
catch (\InvalidArgumentException $e)
{
	throw new UserException('Ce fichier n\'existe pas.');
}

$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();
}







|
<

|













28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
	$file = new Fichiers((int)$id);
}
catch (\InvalidArgumentException $e)
{
	throw new UserException('Ce fichier n\'existe pas.');
}

$session = Membres\Session::get();


if (!$session || !$file->checkAccess($session->getUser()))
{
	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();
}