Update RFM + WebP

This commit is contained in:
Fred Tempez 2021-12-21 22:46:30 +01:00
parent f95eedb798
commit ce304140ba
11 changed files with 6178 additions and 5482 deletions

View File

@ -45,7 +45,7 @@ class common {
// Numéro de version // Numéro de version
const ZWII_UPDATE_URL = 'https://forge.chapril.org/ZwiiCMS-Team/update/raw/branch/master/'; const ZWII_UPDATE_URL = 'https://forge.chapril.org/ZwiiCMS-Team/update/raw/branch/master/';
const ZWII_VERSION = '11.2.00.27'; const ZWII_VERSION = '11.2.00.28';
const ZWII_UPDATE_CHANNEL = "test"; const ZWII_UPDATE_CHANNEL = "test";
public static $actions = []; public static $actions = [];

View File

@ -41,6 +41,7 @@ class UploadHandler
const IMAGETYPE_GIF = 1; const IMAGETYPE_GIF = 1;
const IMAGETYPE_JPEG = 2; const IMAGETYPE_JPEG = 2;
const IMAGETYPE_PNG = 3; const IMAGETYPE_PNG = 3;
const IMAGETYPE_WEBP = 4;
protected $image_objects = array(); protected $image_objects = array();
@ -493,14 +494,17 @@ class UploadHandler
$name = $this->upcount_name($name); $name = $this->upcount_name($name);
} }
// Keep an existing filename if this is part of a chunked upload: // Keep an existing filename if this is part of a chunked upload:
$uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]); $uploaded_bytes =!empty($content_range[1]) ? $this->fix_integer_overflow((int)$content_range[1]) : 0;
while (is_file($this->get_upload_path($name))) { while (is_file($this->get_upload_path($name))) {
if(isset($uploaded_bytes)){
if ($uploaded_bytes === $this->get_file_size( if ($uploaded_bytes === $this->get_file_size(
$this->get_upload_path($name))) { $this->get_upload_path($name))) {
break; break;
} }
}
$name = $this->upcount_name($name); $name = $this->upcount_name($name);
} }
return $name; return $name;
} }
@ -508,7 +512,7 @@ class UploadHandler
$index, $content_range) { $index, $content_range) {
// Add missing file extension for known image types: // Add missing file extension for known image types:
if (strpos($name, '.') === false && if (strpos($name, '.') === false &&
preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) { preg_match('/^image\/(gif|jpe?g|png|webp)/', $type, $matches)) {
$name .= '.'.$matches[1]; $name .= '.'.$matches[1];
} }
if ($this->options['correct_image_extensions']) { if ($this->options['correct_image_extensions']) {
@ -522,6 +526,9 @@ class UploadHandler
case self::IMAGETYPE_GIF: case self::IMAGETYPE_GIF:
$extensions = array('gif'); $extensions = array('gif');
break; break;
case self::IMAGETYPE_WEBP:
$extensions = array('webp');
break;
} }
// Adjust incorrect image file extensions: // Adjust incorrect image file extensions:
if (!empty($extensions)) { if (!empty($extensions)) {
@ -734,6 +741,12 @@ class UploadHandler
$image_quality = isset($options['png_quality']) ? $image_quality = isset($options['png_quality']) ?
$options['png_quality'] : 9; $options['png_quality'] : 9;
break; break;
case 'webp':
$src_func = 'imagecreatefromwebp';
$write_func = 'imagewebp';
$image_quality = isset($options['webp_quality']) ?
$options['webp_quality'] : 75;
break;
default: default:
return false; return false;
} }
@ -1083,6 +1096,9 @@ class UploadHandler
if (bin2hex(@$data[0]).substr($data, 1, 4) === '89PNG') { if (bin2hex(@$data[0]).substr($data, 1, 4) === '89PNG') {
return self::IMAGETYPE_PNG; return self::IMAGETYPE_PNG;
} }
if ($data === 'RIFF') {
return self::IMAGETYPE_WEBP;
}
return false; return false;
} }
@ -1111,7 +1127,7 @@ class UploadHandler
} }
if (count($failed_versions)) { if (count($failed_versions)) {
$file->error = $this->get_error_message('image_resize') $file->error = $this->get_error_message('image_resize')
.' ('.implode($failed_versions, ', ').')'; .' ('.implode(', ', $failed_versions).')';
} }
// Free memory: // Free memory:
$this->destroy_image_object($file_path); $this->destroy_image_object($file_path);
@ -1203,13 +1219,21 @@ class UploadHandler
} }
protected function get_query_param($id) { protected function get_query_param($id) {
if (isset($_GET[$id])) {
return @$_GET[$id]; return @$_GET[$id];
} }
return false;
}
protected function get_server_var($id) { protected function get_server_var($id) {
if (isset($_SERVER[$id])) {
return @$_SERVER[$id]; return @$_SERVER[$id];
} }
return false;
}
protected function handle_form_data($file, $index) { protected function handle_form_data($file, $index) {
// Handle form data, e.g. $_POST['description'][$index] // Handle form data, e.g. $_POST['description'][$index]
} }
@ -1426,7 +1450,7 @@ class UploadHandler
$name = $file_name ? $file_name : $upload['name'][0]; $name = $file_name ? $file_name : $upload['name'][0];
$res = $this->generate_response($response, $print_response); $res = $this->generate_response($response, $print_response);
if(is_file($this->get_upload_path($name))){ if(is_file($this->get_upload_path($name))){
$uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]); $uploaded_bytes =!empty($content_range[1]) ? $this->fix_integer_overflow((int)$content_range[1]) : 0;
$totalSize = $this->get_file_size($this->get_upload_path($name)); $totalSize = $this->get_file_size($this->get_upload_path($name));
if ($totalSize - $uploaded_bytes - $this->options['readfile_chunk_size'] < 0) { if ($totalSize - $uploaded_bytes - $this->options['readfile_chunk_size'] < 0) {
$this->onUploadEnd($res); $this->onUploadEnd($res);
@ -1451,11 +1475,13 @@ class UploadHandler
if (!is_dir($targetPathThumb)) { if (!is_dir($targetPathThumb)) {
mkdir($targetPathThumb, $this->options['mkdir_mode'], true); mkdir($targetPathThumb, $this->options['mkdir_mode'], true);
} }
if(is_function_callable('chmod')){
if(is_file($targetFile)) { if(is_file($targetFile)) {
chmod($targetFile, $this->options['config']['filePermission']); chmod($targetFile, $this->options['config']['filePermission']);
}elseif(is_dir($targetFile)){ }elseif(is_dir($targetFile)){
chmod($targetFile, $this->options['config']['folderPermission']); chmod($targetFile, $this->options['config']['folderPermission']);
} }
}
}else{ }else{
$targetFile = $this->options['config']['ftp_temp_folder'].$res['files'][0]->name; $targetFile = $this->options['config']['ftp_temp_folder'].$res['files'][0]->name;
$targetFileThumb = $this->options['config']['ftp_temp_folder']."thumbs/". $res['files'][0]->name; $targetFileThumb = $this->options['config']['ftp_temp_folder']."thumbs/". $res['files'][0]->name;

View File

@ -454,7 +454,7 @@ $config = array(
//********************** //**********************
//Allowed extensions (lowercase insert) //Allowed extensions (lowercase insert)
//********************** //**********************
'ext_img' => array( 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff','svg', 'ico' ), //Images 'ext_img' => array( 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff','svg', 'ico', 'webp' ), //Images
'ext_file' => array( 'doc', 'docx', 'rtf', 'pdf', 'xls', 'xlsx', 'txt', 'csv', 'html', 'xhtml', 'psd', 'sql', 'log', 'fla', 'xml', 'ade', 'adp', 'mdb', 'accdb', 'ppt', 'pptx', 'odt', 'ots', 'ott', 'odb', 'odg', 'otp', 'otg', 'odf', 'ods', 'odp', 'css', 'ai', 'kmz','dwg', 'dxf', 'hpgl', 'plt', 'spl', 'step', 'stp', 'iges', 'igs', 'sat', 'cgm', 'ics', 'gpx', 'kml', ''), //Files 'ext_file' => array( 'doc', 'docx', 'rtf', 'pdf', 'xls', 'xlsx', 'txt', 'csv', 'html', 'xhtml', 'psd', 'sql', 'log', 'fla', 'xml', 'ade', 'adp', 'mdb', 'accdb', 'ppt', 'pptx', 'odt', 'ots', 'ott', 'odb', 'odg', 'otp', 'otg', 'odf', 'ods', 'odp', 'css', 'ai', 'kmz','dwg', 'dxf', 'hpgl', 'plt', 'spl', 'step', 'stp', 'iges', 'igs', 'sat', 'cgm', 'ics', 'gpx', 'kml', ''), //Files
'ext_video' => array( 'mov', 'mpeg', 'm4v', 'mp4', 'avi', 'mpg', 'wma', "flv", "webm" ), //Video 'ext_video' => array( 'mov', 'mpeg', 'm4v', 'mp4', 'avi', 'mpg', 'wma', "flv", "webm" ), //Video
'ext_music' => array( 'mp3', 'mpga', 'm4a', 'ac3', 'aiff', 'mid', 'ogg', 'wav' ), //Audio 'ext_music' => array( 'mp3', 'mpga', 'm4a', 'ac3', 'aiff', 'mid', 'ogg', 'wav' ), //Audio

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,21 @@ while ($cycle && $i < $max_cycles) {
} }
if (file_exists($path . "config.php")) { if (file_exists($path . "config.php")) {
require_once $path . "config.php"; $configMain = $config;
$configTemp = include $path . "config.php";
if(is_array($configTemp) && count($configTemp) > 0){
$config = array_merge($configMain, $configTemp);
$config['ext'] = array_merge(
$config['ext_img'],
$config['ext_file'],
$config['ext_misc'],
$config['ext_video'],
$config['ext_music']
);
}
else{
$config = $configMain;
}
$cycle = false; $cycle = false;
} }
$path = fix_dirname($path) . "/"; $path = fix_dirname($path) . "/";

View File

@ -0,0 +1,75 @@
<?php
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*
* This code was originally taken from:
* https://github.com/ktomk/Miscellaneous/blob/master/get_png_imageinfo/get_png_imageinfo.php
* It has been modified to fix bugs and improve code formatting
*
* Get image-information from PNG file
*
* php's getimagesize does not support additional image information
* from PNG files like channels or bits.
*
* get_png_imageinfo() can be used to obtain this information
* from PNG files.
*
* @author Tom Klingenberg <lastflood.net>
* @license Apache 2.0
* @link https://github.com/ktomk/Miscellaneous/blob/master/get_png_imageinfo/get_png_imageinfo.php
* @link http://www.libpng.org/pub/png/spec/iso/index-object.html#11IHDR
*
* @param string $file filename
* @return array|bool image information, FALSE on error
*/
function get_png_imageinfo($file) {
if (! is_file($file)) {
return false;
}
$info = unpack(
'a8sig/Nchunksize/A4chunktype/Nwidth/Nheight/Cbit-depth/Ccolor/Ccompression/Cfilter/Cinterface',
file_get_contents($file, 0, null, 0, 29)
);
if (empty($info)) {
return false;
}
if ("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A" != array_shift($info)) {
return false; // no PNG signature
}
if (13 != array_shift($info)) {
return false; // wrong length for IHDR chunk
}
if ('IHDR'!==array_shift($info)) {
return false; // a non-IHDR chunk singals invalid data
}
$color = $info['color'];
$type = array(
0 => 'Greyscale',
2 => 'Truecolour',
3 => 'Indexed-colour',
4 => 'Greyscale with alpha',
6 => 'Truecolour with alpha'
);
if (empty($type[$color])) {
return false; // invalid color value
}
$info['color-type'] = $type[$color];
$samples = ((($color % 4) % 3) ? 3 : 1) + ($color > 3 ? 1 : 0);
$info['channels'] = $samples;
$info['bits'] = $info['bit-depth'];
return $info;
}

View File

@ -17,6 +17,7 @@ $mime_types = array(
"application/mac-compactpro" => "cpt", "application/mac-compactpro" => "cpt",
"application/x-csh" => "csh", "application/x-csh" => "csh",
"text/css" => "css", "text/css" => "css",
"text/csv" => "csv",
"application/x-director" => "dxr", "application/x-director" => "dxr",
"image/vnd.djvu" => "djvu", "image/vnd.djvu" => "djvu",
"application/x-dvi" => "dvi", "application/x-dvi" => "dvi",
@ -133,6 +134,8 @@ $mime_types = array(
"audio/x-ms-wax" => "wax", "audio/x-ms-wax" => "wax",
"image/vnd.wap.wbmp" => "wbmp", "image/vnd.wap.wbmp" => "wbmp",
"application/vnd.wap.wbxml" => "wbxml", "application/vnd.wap.wbxml" => "wbxml",
"video/webm" => "webm",
"image/webp" => "webp",
"video/x-ms-wm" => "wm", "video/x-ms-wm" => "wm",
"audio/x-ms-wma" => "wma", "audio/x-ms-wma" => "wma",
"text/vnd.wap.wml" => "wml", "text/vnd.wap.wml" => "wml",

View File

@ -229,7 +229,6 @@ class imageLib {
// *** Open up the file // *** Open up the file
$this->image = $this->openImage($fileName); $this->image = $this->openImage($fileName);
// *** Assign here so we don't modify the original // *** Assign here so we don't modify the original
$this->imageResized = $this->image; $this->imageResized = $this->image;
@ -2729,6 +2728,9 @@ class imageLib {
case 'jpeg': case 'jpeg':
$img = @imagecreatefromjpeg($file); $img = @imagecreatefromjpeg($file);
break; break;
case 'webp':
$img = @imagecreatefromwebp($file);
break;
case 'gif': case 'gif':
$img = @imagecreatefromgif($file); $img = @imagecreatefromgif($file);
break; break;
@ -2736,6 +2738,7 @@ class imageLib {
$img = @imagecreatefrompng($file); $img = @imagecreatefrompng($file);
break; break;
case 'bmp': case 'bmp':
case 'x-ms-bmp':
$img = @$this->imagecreatefrombmp($file); $img = @$this->imagecreatefrombmp($file);
break; break;
case 'psd': case 'psd':
@ -2781,6 +2784,7 @@ class imageLib {
# Reference: # Reference:
# Notes: * gif doesn't have a quality parameter # Notes: * gif doesn't have a quality parameter
# * jpg has a quality setting 0-100 (100 being the best) # * jpg has a quality setting 0-100 (100 being the best)
# * webp has a quality setting 0-100 (100 being the best)
# * png has a quality setting 0-9 (0 being the best) # * png has a quality setting 0-9 (0 being the best)
# #
# * bmp files have no native support for bmp files. We use a # * bmp files have no native support for bmp files. We use a
@ -2788,7 +2792,7 @@ class imageLib {
{ {
// *** Perform a check or two. // *** Perform a check or two.
if ( ! is_resource($this->imageResized)) if (! is_resource($this->imageResized) && ! $this->imageResized instanceof \GdImage)
{ {
if ($this->debug) if ($this->debug)
{ {
@ -2834,6 +2838,17 @@ class imageLib {
} }
break; break;
case '.webp':
if (imagetypes() & IMG_WEBP)
{
imagewebp($this->imageResized, $savePath, $imageQuality);
}
else
{
$error = 'webp';
}
break;
case '.gif': case '.gif':
$this->checkInterlaceImage($this->isInterlace); $this->checkInterlaceImage($this->isInterlace);
if (imagetypes() & IMG_GIF) if (imagetypes() & IMG_GIF)
@ -2899,7 +2914,7 @@ class imageLib {
# #
{ {
if ( ! is_resource($this->imageResized)) if (! is_resource($this->imageResized) && ! $this->imageResized instanceof \GdImage)
{ {
if ($this->debug) if ($this->debug)
{ {
@ -2918,6 +2933,10 @@ class imageLib {
header('Content-type: image/jpeg'); header('Content-type: image/jpeg');
imagejpeg($this->imageResized, '', $imageQuality); imagejpeg($this->imageResized, '', $imageQuality);
break; break;
case 'webp':
header('Content-type: image/webp');
imagewebp($this->imageResized, '', $imageQuality);
break;
case 'gif': case 'gif':
header('Content-type: image/gif'); header('Content-type: image/gif');
imagegif($this->imageResized); imagegif($this->imageResized);
@ -3469,7 +3488,7 @@ class imageLib {
# Notes: # Notes:
# #
{ {
if ( ! is_resource($img)) if (! is_resource($img) && ! $img instanceof \GdImage)
{ {
return false; return false;
} }
@ -3718,7 +3737,7 @@ class imageLib {
public function __destruct() public function __destruct()
{ {
if (is_resource($this->imageResized)) if (is_resource($this->imageResized) || $this->imageResized instanceof \GdImage)
{ {
imagedestroy($this->imageResized); imagedestroy($this->imageResized);
} }

File diff suppressed because it is too large Load Diff

View File

@ -50,8 +50,21 @@ try {
$cycle = false; $cycle = false;
} }
if (file_exists($path . "config.php")) { if (file_exists($path . "config.php")) {
$configMain = $config;
$configTemp = include $path . 'config.php'; $configTemp = include $path . 'config.php';
$config = array_merge($config, $configTemp); if(is_array($configTemp) && count($configTemp) > 0){
$config = array_merge($configMain, $configTemp);
$config['ext'] = array_merge(
$config['ext_img'],
$config['ext_file'],
$config['ext_misc'],
$config['ext_video'],
$config['ext_music']
);
}
else{
$config = $configMain;
}
//TODO switch to array //TODO switch to array
$cycle = false; $cycle = false;
} }
@ -63,7 +76,7 @@ try {
if (trans("Upload_error_messages") !== "Upload_error_messages") { if (trans("Upload_error_messages") !== "Upload_error_messages") {
$messages = trans("Upload_error_messages"); $messages = trans("Upload_error_messages");
} }
if ($config['url_upload']) {
// make sure the length is limited to avoid DOS attacks // make sure the length is limited to avoid DOS attacks
if (isset($_POST['url']) && strlen($_POST['url']) < 2000) { if (isset($_POST['url']) && strlen($_POST['url']) < 2000) {
$url = $_POST['url']; $url = $_POST['url'];
@ -94,6 +107,7 @@ try {
throw new Exception('Is not a valid URL.'); throw new Exception('Is not a valid URL.');
} }
} }
}
if ($config['mime_extension_rename']) { if ($config['mime_extension_rename']) {