From eea02347924702351576ed4ff0378a47f66f04e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Tempez?= Date: Sat, 1 Oct 2022 16:31:20 +0200 Subject: [PATCH] =?UTF-8?q?Couleur=20du=20texte=20dans=20les=20en-t=C3=AAt?= =?UTF-8?q?es=20des=20tableaux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/helper.class.php | 264 ++++++++++++++++++++---------------- core/core.php | 8 +- 2 files changed, 151 insertions(+), 121 deletions(-) diff --git a/core/class/helper.class.php b/core/class/helper.class.php index 1d7948c8..510d90e9 100644 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -1,6 +1,7 @@ 0 ){ + if (strpos(self::baseUrl(), 'free.fr') > 0) { return false; } - if(function_exists('file_get_contents') && - ini_get('allow_url_fopen') ){ - $url_get_contents_data = @file_get_contents($url); // Masque un warning éventuel - }elseif(function_exists('curl_version')){ - $ch = curl_init(); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_URL, $url); - $url_get_contents_data = curl_exec($ch); - curl_close($ch); - }elseif(function_exists('fopen') && - function_exists('stream_get_contents') && - ini_get('allow_url_fopen')){ - $handle = fopen ($url, "r"); - $url_get_contents_data = stream_get_contents($handle); - }else{ - $url_get_contents_data = false; - } + if ( + function_exists('file_get_contents') && + ini_get('allow_url_fopen') + ) { + $url_get_contents_data = @file_get_contents($url); // Masque un warning éventuel + } elseif (function_exists('curl_version')) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_URL, $url); + $url_get_contents_data = curl_exec($ch); + curl_close($ch); + } elseif ( + function_exists('fopen') && + function_exists('stream_get_contents') && + ini_get('allow_url_fopen') + ) { + $handle = fopen($url, "r"); + $url_get_contents_data = stream_get_contents($handle); + } else { + $url_get_contents_data = false; + } return $url_get_contents_data; } @@ -105,13 +111,14 @@ class helper { * @param string $sort Type de tri à appliquer au tableau (SORT_ASC, SORT_DESC, ou null) * @return array */ - public static function arraycolumn($array, $column, $sort = null) { + public static function arraycolumn($array, $column, $sort = null) + { $newArray = []; - if(empty($array) === false) { - $newArray = array_map(function($element) use($column) { + if (empty($array) === false) { + $newArray = array_map(function ($element) use ($column) { return $element[$column]; }, $array); - switch($sort) { + switch ($sort) { case 'SORT_ASC': asort($newArray); break; @@ -126,7 +133,8 @@ class helper { /** * Compatibilité avec les anciens modules */ - public static function arrayCollumn($array, $column, $sort = null) { + public static function arrayCollumn($array, $column, $sort = null) + { return (helper::arrayColumn($array, $column, $sort)); } @@ -139,9 +147,10 @@ class helper { * @return string nom du fichier de sauvegarde */ - public static function autoBackup($folder, $filter = ['backup','tmp'] ) { + public static function autoBackup($folder, $filter = ['backup', 'tmp']) + { // Creation du ZIP - $baseName = str_replace('/','',helper::baseUrl(false,false)); + $baseName = str_replace('/', '', helper::baseUrl(false, false)); $baseName = empty($baseName) ? 'ZwiiCMS' : $baseName; $fileName = $baseName . '-backup-' . date('Y-m-d-H-i-s', time()) . '.zip'; $zip = new ZipArchive(); @@ -150,17 +159,17 @@ class helper { //$filter = array('backup','tmp','file'); $files = new RecursiveIteratorIterator( new RecursiveCallbackFilterIterator( - new RecursiveDirectoryIterator( - $directory, - RecursiveDirectoryIterator::SKIP_DOTS - ), - function ($fileInfo, $key, $iterator) use ($filter) { - return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter); - } + new RecursiveDirectoryIterator( + $directory, + RecursiveDirectoryIterator::SKIP_DOTS + ), + function ($fileInfo, $key, $iterator) use ($filter) { + return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter); + } ) - ); - foreach ($files as $name => $file) { - if (!$file->isDir()) { + ); + foreach ($files as $name => $file) { + if (!$file->isDir()) { $filePath = $file->getRealPath(); $relativePath = substr($filePath, strlen(realpath($directory)) + 1); $zip->addFile($filePath, $relativePath); @@ -177,61 +186,61 @@ class helper { * du nom réel * du numéro de version */ - public static function getModules() { + public static function getModules() + { $modules = array(); $dirs = array_diff(scandir('module'), array('..', '.')); foreach ($dirs as $key => $value) { // Dossier non vide if (file_exists('module/' . $value . '/' . $value . '.php')) { // Lire les constantes en gérant les erreurs de nom de classe - try { + try { $class_reflex = new \ReflectionClass($value); $class_constants = $class_reflex->getConstants(); // Constante REALNAME if (array_key_exists('REALNAME', $class_constants)) { - $realName = $value::REALNAME; + $realName = $value::REALNAME; } else { - $realName = ucfirst($value); + $realName = ucfirst($value); } // Constante VERSION if (array_key_exists('VERSION', $class_constants)) { - $version = $value::VERSION; + $version = $value::VERSION; } else { - $version = '0.0'; + $version = '0.0'; } // Constante UPDATE if (array_key_exists('UPDATE', $class_constants)) { - $update = $value::UPDATE; + $update = $value::UPDATE; } else { - $update = '0.0'; + $update = '0.0'; } // Constante DELETE if (array_key_exists('DELETE', $class_constants)) { - $delete = $value::DELETE; + $delete = $value::DELETE; } else { - $delete = true; + $delete = true; } // Constante DATADIRECTORY - if ( array_key_exists('DATADIRECTORY', $class_constants)) { - $dataDirectory = $value::DATADIRECTORY; + if (array_key_exists('DATADIRECTORY', $class_constants)) { + $dataDirectory = $value::DATADIRECTORY; } else { - $dataDirectory = ''; + $dataDirectory = ''; } // Affection - $modules [$value] = [ - 'realName' => $realName, - 'version' => $version, - 'update' => $update, - 'delete' => $delete, - 'dataDirectory' => $dataDirectory + $modules[$value] = [ + 'realName' => $realName, + 'version' => $version, + 'update' => $update, + 'delete' => $delete, + 'dataDirectory' => $dataDirectory ]; - - } catch (Exception $e){ + } catch (Exception $e) { // on ne fait rien } } } - return($modules); + return ($modules); } @@ -240,10 +249,11 @@ class helper { * Retourne true si le protocole est en TLS * @return bool */ - public static function isHttps() { - if( - (empty($_SERVER['HTTPS']) === false AND $_SERVER['HTTPS'] !== 'off') - OR $_SERVER['SERVER_PORT'] === 443 + public static function isHttps() + { + if ( + (empty($_SERVER['HTTPS']) === false and $_SERVER['HTTPS'] !== 'off') + or $_SERVER['SERVER_PORT'] === 443 ) { return true; } else { @@ -258,20 +268,20 @@ class helper { * @param bool $host Affiche ou non l'host * @return string */ - public static function baseUrl($queryString = true, $host = true) { + public static function baseUrl($queryString = true, $host = true) + { // Protocole $protocol = helper::isHttps() === true ? 'https://' : 'http://'; // Host - if($host) { + if ($host) { $host = $protocol . $_SERVER['HTTP_HOST']; } // Pathinfo $pathInfo = pathinfo($_SERVER['PHP_SELF']); // Querystring - if($queryString AND helper::checkRewrite() === false) { + if ($queryString and helper::checkRewrite() === false) { $queryString = '?'; - } - else { + } else { $queryString = ''; } return $host . rtrim($pathInfo['dirname'], ' ' . DIRECTORY_SEPARATOR) . '/' . $queryString; @@ -281,11 +291,12 @@ class helper { * Check le statut de l'URL rewriting * @return bool */ - public static function checkRewrite() { + public static function checkRewrite() + { // N'interroge que le serveur Apache if (strpos($_SERVER["SERVER_SOFTWARE"], 'Apache') > 0) { self::$rewriteStatus === false; - } elseif(self::$rewriteStatus === null) { + } elseif (self::$rewriteStatus === null) { // Ouvre et scinde le fichier .htaccess $htaccess = explode('# URL rewriting', file_get_contents('.htaccess')); // Retourne un boolean en fonction du contenu de la partie réservée à l'URL rewriting @@ -299,7 +310,8 @@ class helper { * Renvoie le numéro de version de Zwii est en ligne * @return string */ - public static function getOnlineVersion() { + public static function getOnlineVersion() + { return (helper::getUrlContents(common::ZWII_UPDATE_URL . common::ZWII_UPDATE_CHANNEL . '/version')); } @@ -308,12 +320,12 @@ class helper { * Check si une nouvelle version de Zwii est disponible * @return bool */ - public static function checkNewVersion() { + public static function checkNewVersion() + { $version = helper::getOnlineVersion(); - if( !empty($version) ) { + if (!empty($version)) { return ((version_compare(common::ZWII_VERSION, $version)) === -1); - } - else { + } else { return false; } } @@ -324,7 +336,8 @@ class helper { * @param string $rgba Code rgba de la couleur * @return array */ - public static function colorVariants($rgba) { + public static function colorVariants($rgba) + { preg_match('#\(+(.*)\)+#', $rgba, $matches); $rgba = explode(', ', $matches[1]); return [ @@ -332,7 +345,12 @@ class helper { 'darken' => 'rgba(' . max(0, $rgba[0] - 15) . ',' . max(0, $rgba[1] - 15) . ',' . max(0, $rgba[2] - 15) . ',' . $rgba[3] . ')', 'veryDarken' => 'rgba(' . max(0, $rgba[0] - 20) . ',' . max(0, $rgba[1] - 20) . ',' . max(0, $rgba[2] - 20) . ',' . $rgba[3] . ')', 'text' => self::relativeLuminanceW3C($rgba) > .22 ? "#222" : "#DDD", - 'rgb' => 'rgb(' . $rgba[0] . ',' . $rgba[1] . ',' . $rgba[2] . ')' + 'rgb' => 'rgb(' . $rgba[0] . ',' . $rgba[1] . ',' . $rgba[2] . ')', + 'invert' => 'rgba (' . + ($rgba[0] < 128 ? 255 : 0) . ',' . + ($rgba[1] < 128 ? 255 : 0) . ',' . + ($rgba[1] < 128 ? 255 : 0) . ',' . + ($rgba[0] < 128 ? 255 : 0) . ')' ]; } @@ -340,7 +358,8 @@ class helper { * Supprime un cookie * @param string $cookieKey Clé du cookie à supprimer */ - public static function deleteCookie($cookieKey) { + public static function deleteCookie($cookieKey) + { unset($_COOKIE[$cookieKey]); setcookie($cookieKey, '', time() - 3600, helper::baseUrl(false, false), '', false, true); } @@ -351,9 +370,10 @@ class helper { * @param int $filter Type de filtre à appliquer * @return string */ - public static function filter($text, $filter) { + public static function filter($text, $filter) + { $text = trim($text); - switch($filter) { + switch ($filter) { case self::FILTER_BOOLEAN: $text = (bool) $text; break; @@ -378,13 +398,13 @@ class helper { // Supprime les emoji $text = preg_replace('/[[:^print:]]/', '', $text); // Supprime les tirets en fin de chaine (emoji en fin de nom) - $text = rtrim($text,'-'); + $text = rtrim($text, '-'); // Cas où un identifiant est vide if (empty($text)) { $text = uniqid(''); } // Un ID ne peut pas être un entier, pour éviter les conflits avec le système de pagination - if(intval($text) !== 0) { + if (intval($text) !== 0) { $text = '_' . $text; } break; @@ -419,17 +439,18 @@ class helper { * @param array $array Tableau à vérifier * @return string */ - public static function increment($key, $array = []) { + public static function increment($key, $array = []) + { // Pas besoin d'incrémenter si la clef n'existe pas - if($array === []) { + if ($array === []) { return $key; } // Incrémente la clef else { // Si la clef est numérique elle est incrémentée - if(is_numeric($key)) { + if (is_numeric($key)) { $newKey = $key; - while(array_key_exists($newKey, $array) OR in_array($newKey, $array)) { + while (array_key_exists($newKey, $array) or in_array($newKey, $array)) { $newKey++; } } @@ -437,7 +458,7 @@ class helper { else { $i = 2; $newKey = $key; - while(array_key_exists($newKey, $array) OR in_array($newKey, $array)) { + while (array_key_exists($newKey, $array) or in_array($newKey, $array)) { $newKey = $key . '-' . $i; $i++; } @@ -451,11 +472,12 @@ class helper { * @param string $css Css à minimiser * @return string */ - public static function minifyCss($css) { + public static function minifyCss($css) + { // Supprime les commentaires $css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css); // Supprime les tabulations, espaces, nouvelles lignes, etc... - $css = str_replace(["\r\n", "\r", "\n" ,"\t", ' ', ' ', ' '], '', $css); + $css = str_replace(["\r\n", "\r", "\n", "\t", ' ', ' ', ' '], '', $css); $css = preg_replace(['(( )+{)', '({( )+)'], '{', $css); $css = preg_replace(['(( )+})', '(}( )+)', '(;( )*})'], '}', $css); $css = preg_replace(['(;( )+)', '(( )+;)'], ';', $css); @@ -468,7 +490,8 @@ class helper { * @param string $js Js à minimiser * @return string */ - public static function minifyJs($js) { + public static function minifyJs($js) + { // Supprime les commentaires $js = preg_replace('/\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\/|\s*(? $nbElements) ? $nbElements : $lastElement; // Mise en forme de la liste des pages $pages = ''; - if($nbPage > 1) { - for($i = 1; $i <= $nbPage; $i++) { + if ($nbPage > 1) { + for ($i = 1; $i <= $nbPage; $i++) { $disabled = ($i === $currentPage) ? ' class="disabled"' : false; $pages .= '' . $i . ''; } @@ -524,7 +548,8 @@ class helper { /** * Calcul de la luminance relative d'une couleur */ - public static function relativeLuminanceW3C($rgba) { + public static function relativeLuminanceW3C($rgba) + { // Conversion en sRGB $RsRGB = $rgba[0] / 255; $GsRGB = $rgba[1] / 255; @@ -546,7 +571,8 @@ class helper { * @param array $exclude Clés à ignorer ($key) * @return string */ - public static function sprintAttributes(array $array = [], array $exclude = []) { + public static function sprintAttributes(array $array = [], array $exclude = []) + { $exclude = array_merge( [ 'before', @@ -557,15 +583,15 @@ class helper { $exclude ); $attributes = []; - foreach($array as $key => $value) { - if(($value OR $value === 0) AND in_array($key, $exclude) === false) { + foreach ($array as $key => $value) { + if (($value or $value === 0) and in_array($key, $exclude) === false) { // Désactive le message de modifications non enregistrées pour le champ - if($key === 'noDirty') { + if ($key === 'noDirty') { $attributes[] = 'data-no-dirty'; } // Disabled // Readonly - elseif(in_array($key, ['disabled', 'readonly'])) { + elseif (in_array($key, ['disabled', 'readonly'])) { $attributes[] = sprintf('%s', $key); } // Autres @@ -584,9 +610,10 @@ class helper { * @param int $length (voir substr de PHP pour fonctionnement) * @return string */ - public static function subword($text, $start, $length) { + public static function subword($text, $start, $length) + { $text = trim($text); - if(strlen($text) > $length) { + if (strlen($text) > $length) { $text = mb_substr($text, $start, $length); $text = mb_substr($text, 0, min(mb_strlen($text), mb_strrpos($text, ' '))); } @@ -599,7 +626,8 @@ class helper { * @param string $payload la chaine à coder * @return string */ - public static function encrypt($key, $payload) { + public static function encrypt($key, $payload) + { $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc')); $encrypted = openssl_encrypt($payload, 'aes-256-cbc', $key, 0, $iv); return base64_encode($encrypted . '::' . $iv); @@ -611,9 +639,9 @@ class helper { * @param string $garble la chaine à décoder * @return string */ - public static function decrypt($key, $garble) { + public static function decrypt($key, $garble) + { list($encrypted_data, $iv) = explode('::', base64_decode($garble), 2); return openssl_decrypt($encrypted_data, 'aes-256-cbc', $key, 0, $iv); } - } diff --git a/core/core.php b/core/core.php index 02850692..ad5c6db7 100644 --- a/core/core.php +++ b/core/core.php @@ -2681,9 +2681,11 @@ class core extends common $css .= 'body h1, h2, h3, h4 a, h5, h6 {font-family:' . $fonts[$this->getData(['admin', 'fontTitle'])] . ';color:' . $this->getData(['admin', 'colorTitle']) . ';}'; // TinyMCE - $css .= 'body:not(.editorWysiwyg),span .zwiico-help {color:' . $this->getData(['admin', 'colorText']) . ';}'; - $css .= 'table thead tr, table thead tr .zwiico-help{ background-color:' . $this->getData(['admin', 'colorText']) . '; color:' . $colors['text'] . ';}'; - $css .= 'table thead th { color: ' . $this->getData(['admin', 'colorText']) . '; filter: invert(100%);}'; + $colors = helper::colorVariants($this->getData(['admin', 'colorText'])); + $css .= 'body:not(.editorWysiwyg),span .zwiico-help {color:' . $colors['normal'] . ';}'; + echo $colors['invert']; + $css .= 'table thead tr, table thead tr .zwiico-help{ background-color:' . $colors['normal'] . '; color:' . $colors['text'] . ';}'; + $css .= 'table thead th { color:' . $colors['text'] . ';}'; $colors = helper::colorVariants($this->getData(['admin', 'backgroundColorButton'])); $css .= 'input[type="checkbox"]:checked + label::before,.speechBubble{background-color:' . $colors['normal'] . ';color:' . $colors['text'] . ';}'; $css .= '.speechBubble::before {border-color:' . $colors['normal'] . ' transparent transparent transparent;}';