diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-04-19 12:34:14 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-04-19 12:34:14 +0200 |
commit | 6278839230ae3c27c205550889511531d09cbf20 (patch) | |
tree | d41e0177b8d72451315df43f96394a6bd681d1e3 /app | |
parent | 1c4182d9d88bb4471f86b08329f1b68a5290872b (diff) | |
download | wcms-6278839230ae3c27c205550889511531d09cbf20.tar.gz wcms-6278839230ae3c27c205550889511531d09cbf20.zip |
finish PSR 12 error cleaning
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Controllerfont.php | 20 | ||||
-rw-r--r-- | app/fn/fn.php | 446 |
2 files changed, 244 insertions, 222 deletions
diff --git a/app/class/Controllerfont.php b/app/class/Controllerfont.php index 63b3ced..91a7936 100644 --- a/app/class/Controllerfont.php +++ b/app/class/Controllerfont.php @@ -13,18 +13,23 @@ class Controllerfont extends Controller { parent::__construct($router); $this->fontmanager = new Modelfont(); - } public function desktop() { - if($this->user->iseditor()) { - + if ($this->user->iseditor()) { $this->fontmanager->fontdircheck(); $fontlist = $this->fontmanager->getfontlist(); - $this->showtemplate('font', ['fontlist' => $fontlist, 'fonttypes' => $this->fontmanager->getfonttypes(), 'fontfile' => Model::globalpath().'fonts.css']); + $this->showtemplate( + 'font', + [ + 'fontlist' => $fontlist, + 'fonttypes' => $this->fontmanager->getfonttypes(), + 'fontfile' => Model::globalpath() . 'fonts.css' + ] + ); } else { $this->routedirect('home'); } @@ -38,19 +43,16 @@ class Controllerfont extends Controller public function add() { - if(isset($_POST['fontname'])) { + if (isset($_POST['fontname'])) { $fontname = $_POST['fontname']; } else { $fontname = ''; } $message = $this->fontmanager->upload($_FILES, 2 ** 16, $fontname); - if($message !== true) { + if ($message !== true) { echo $message; } else { $this->render(); } } } - - -?>
\ No newline at end of file diff --git a/app/fn/fn.php b/app/fn/fn.php index 01e643b..2d17a3f 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -6,30 +6,30 @@ use function Clue\StreamFilter\fun; function readablesize($bytes, $base = 2 ** 10) { - $format = ' %d %s'; - - if ($base === 2 ** 10) { - $i = 'i'; - } else { - $i = ''; - } - - $unit = ''; - - if ($bytes < $base) { - $num = $bytes; - } elseif ($bytes < $base ** 2) { - $num = round($bytes / $base, 1); - $unit = 'K' . $i; - } elseif ($bytes < $base ** 3) { - $num = round($bytes / $base ** 2, 1); - $unit = 'M' . $i; - } elseif ($bytes < $base ** 4) { - $num = round($bytes / $base ** 3, 1); - $unit = 'G' . $i; - } - - return sprintf($format, $num, $unit); + $format = ' %d %s'; + + if ($base === 2 ** 10) { + $i = 'i'; + } else { + $i = ''; + } + + $unit = ''; + + if ($bytes < $base) { + $num = $bytes; + } elseif ($bytes < $base ** 2) { + $num = round($bytes / $base, 1); + $unit = 'K' . $i; + } elseif ($bytes < $base ** 3) { + $num = round($bytes / $base ** 2, 1); + $unit = 'M' . $i; + } elseif ($bytes < $base ** 4) { + $num = round($bytes / $base ** 3, 1); + $unit = 'G' . $i; + } + + return sprintf($format, $num, $unit); } /* human readable date interval @@ -38,77 +38,97 @@ function readablesize($bytes, $base = 2 ** 10) */ function hrdi(DateInterval $diff) { - $str = ""; - if ($diff->y > 1) return $str . $diff->y . ' years'; - if ($diff->y == 1) return $str . ' 1 year and ' . $diff->m . ' months'; - if ($diff->m > 1) return $str . $diff->m . ' months'; - if ($diff->m == 1) return $str . ' 1 month and ' . $diff->d . ($diff->d > 1 ? ' days' : ' day'); - if ($diff->d > 1) return $str . $diff->d . ' days'; - if ($diff->d == 1) return $str . ' 1 day and ' . $diff->h . ($diff->h > 1 ? ' hours' : ' hour'); - if ($diff->h > 1) return $str . $diff->h . ' hours'; - if ($diff->h == 1) return $str . ' 1 hour and ' . $diff->i . ($diff->i > 1 ? ' minutes' : ' minute'); - if ($diff->i > 1) return $str . $diff->i . ' minutes'; - if ($diff->i == 1) return $str . ' 1 minute'; - return $str . ' a few secondes'; + $str = ""; + if ($diff->y > 1) { + return $str . $diff->y . ' years'; + } + if ($diff->y == 1) { + return $str . ' 1 year and ' . $diff->m . ' months'; + } + if ($diff->m > 1) { + return $str . $diff->m . ' months'; + } + if ($diff->m == 1) { + return $str . ' 1 month and ' . $diff->d . ($diff->d > 1 ? ' days' : ' day'); + } + if ($diff->d > 1) { + return $str . $diff->d . ' days'; + } + if ($diff->d == 1) { + return $str . ' 1 day and ' . $diff->h . ($diff->h > 1 ? ' hours' : ' hour'); + } + if ($diff->h > 1) { + return $str . $diff->h . ' hours'; + } + if ($diff->h == 1) { + return $str . ' 1 hour and ' . $diff->i . ($diff->i > 1 ? ' minutes' : ' minute'); + } + if ($diff->i > 1) { + return $str . $diff->i . ' minutes'; + } + if ($diff->i == 1) { + return $str . ' 1 minute'; + } + return $str . ' a few secondes'; } function arrayclean($input) { - $output = []; - foreach ($input as $key => $value) { - if (is_array($value)) { - $output[$key] = array_filter($value); - } else { - $output[$key] = $value; - } - } - return $output; + $output = []; + foreach ($input as $key => $value) { + if (is_array($value)) { + $output[$key] = array_filter($value); + } else { + $output[$key] = $value; + } + } + return $output; } function idclean(string $input) -{ - $input = urldecode($input); - $search = ['é', 'à', 'è', 'ç', 'ù', 'ï', 'î', ' ']; - $replace = ['e', 'a', 'e', 'c', 'u', 'i', 'i', '-']; - $input = str_replace($search, $replace, $input); +{ + $input = urldecode($input); + $search = ['é', 'à', 'è', 'ç', 'ù', 'ï', 'î', ' ']; + $replace = ['e', 'a', 'e', 'c', 'u', 'i', 'i', '-']; + $input = str_replace($search, $replace, $input); - $input = preg_replace('%[^a-z0-9-_+]%', '', strtolower(trim($input))); + $input = preg_replace('%[^a-z0-9-_+]%', '', strtolower(trim($input))); - $input = substr($input, 0, Wcms\Model::MAX_ID_LENGTH); + $input = substr($input, 0, Wcms\Model::MAX_ID_LENGTH); - return $input; + return $input; } function isreportingerrors() { - return function_exists('Sentry\init') && !empty(Wcms\Config::sentrydsn()); + return function_exists('Sentry\init') && !empty(Wcms\Config::sentrydsn()); } function getversion() { - if(file_exists('VERSION')) { - $version = trim(file_get_contents('VERSION')); - } else { - $version = 'unknown'; - } - return $version; + if (file_exists('VERSION')) { + $version = trim(file_get_contents('VERSION')); + } else { + $version = 'unknown'; + } + return $version; } function array_update($base, $new) { - foreach ($base as $key => $value) { - if (array_key_exists($key, $new)) { - if (gettype($base[$key]) == gettype($new[$key])) { - $base[$key] = $new[$key]; - } - } - } - return $base; + foreach ($base as $key => $value) { + if (array_key_exists($key, $new)) { + if (gettype($base[$key]) == gettype($new[$key])) { + $base[$key] = $new[$key]; + } + } + } + return $base; } function contains($needle, $haystack) @@ -119,7 +139,7 @@ function contains($needle, $haystack) function str_clean(string $string) { - return str_replace(' ', '_', strtolower(strip_tags($string))); + return str_replace(' ', '_', strtolower(strip_tags($string))); } @@ -127,88 +147,88 @@ function str_clean(string $string) function changekey($array, $oldkey, $newkey) { - if (!array_key_exists($oldkey, $array)) - return $array; + if (!array_key_exists($oldkey, $array)) { + return $array; + } - $keys = array_keys($array); - $keys[array_search($oldkey, $keys)] = $newkey; + $keys = array_keys($array); + $keys[array_search($oldkey, $keys)] = $newkey; - return array_combine($keys, $array); + return array_combine($keys, $array); } function compare($stringa, $stringb) { - $arraya = explode(PHP_EOL, $stringa); - $arrayb = explode(PHP_EOL, $stringb); - - $lnb = -1; - $commonlines = []; - foreach ($arraya as $na => $linea) { - $found = false; - foreach ($arrayb as $nb => $lineb) { - if($linea === $lineb && $nb > $lnb && !$found && !empty($linea)) { - $commonlines[$na] = $nb; - $merge[] = $arrayb[$nb]; - $lnb = $nb; - $found = true; - } - } - } - - - $merge = []; - $lnb = 0; - foreach ($arraya as $na => $linea) { - if(array_key_exists($na, $commonlines)) { - for ($j=$lnb; $j <= $commonlines[$na]; $j++) { - $merge[] = $arrayb[$j]; - } - $lnb = $j; - } else { - $merge[] = $arraya[$na]; - } - } - for ($k=$lnb; ; $k++) { - if(array_key_exists($k, $arrayb)) { - $merge[] = $arrayb[$k]; - } else { - break; - } - } - - return implode(PHP_EOL, $merge); + $arraya = explode(PHP_EOL, $stringa); + $arrayb = explode(PHP_EOL, $stringb); + + $lnb = -1; + $commonlines = []; + foreach ($arraya as $na => $linea) { + $found = false; + foreach ($arrayb as $nb => $lineb) { + if ($linea === $lineb && $nb > $lnb && !$found && !empty($linea)) { + $commonlines[$na] = $nb; + $merge[] = $arrayb[$nb]; + $lnb = $nb; + $found = true; + } + } + } + + + $merge = []; + $lnb = 0; + foreach ($arraya as $na => $linea) { + if (array_key_exists($na, $commonlines)) { + for ($j = $lnb; $j <= $commonlines[$na]; $j++) { + $merge[] = $arrayb[$j]; + } + $lnb = $j; + } else { + $merge[] = $arraya[$na]; + } + } + for ($k = $lnb;; $k++) { + if (array_key_exists($k, $arrayb)) { + $merge[] = $arrayb[$k]; + } else { + break; + } + } + + return implode(PHP_EOL, $merge); } function findsize($file) { - if(substr(PHP_OS, 0, 3) == "WIN") - { - exec('for %I in ("'.$file.'") do @echo %~zI', $output); + if (substr(PHP_OS, 0, 3) == "WIN") { + exec('for %I in ("' . $file . '") do @echo %~zI', $output); $return = $output[0]; - } - else - { + } else { $return = filesize($file); } return $return; } -function array_diff_assoc_recursive($array1, $array2) { - $difference=array(); - foreach($array1 as $key => $value) { - if( is_array($value) ) { - if( !isset($array2[$key]) || !is_array($array2[$key]) ) { +function array_diff_assoc_recursive($array1, $array2) +{ + $difference = array(); + foreach ($array1 as $key => $value) { + if (is_array($value)) { + if (!isset($array2[$key]) || !is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = array_diff_assoc_recursive($value, $array2[$key]); - if( !empty($new_diff) ) + if (!empty($new_diff)) { $difference[$key] = $new_diff; + } } - } else if( !array_key_exists($key,$array2) || $array2[$key] !== $value ) { + } elseif (!array_key_exists($key, $array2) || $array2[$key] !== $value) { $difference[$key] = $value; } } @@ -219,22 +239,28 @@ function array_diff_assoc_recursive($array1, $array2) { /** * Generate a clickable folder tree based on reccurive array */ -function treecount(array $dirlist, string $dirname, int $deepness, string $path, string $currentdir, Medialist $mediaopt) -{ - if ($path . '/' === $currentdir) { - $folder = '├─📂<span id="currentdir">' . $dirname . '<span>'; - } else { - $folder = '├─📁' . $dirname; - } - echo '<tr>'; - echo '<td><a href="' . $mediaopt->getpathadress($path) . '">' . str_repeat(' ', $deepness) . $folder . '</a></td>'; - echo '<td>' . $dirlist['dirfilecount'] . '</td>'; - echo '</tr>'; - foreach ($dirlist as $key => $value) { - if (is_array($value)) { - treecount($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir, $mediaopt); - } - } +function treecount( + array $dirlist, + string $dirname, + int $deepness, + string $path, + string $currentdir, + Medialist $mediaopt +) { + if ($path . '/' === $currentdir) { + $folder = '├─📂<span id="currentdir">' . $dirname . '<span>'; + } else { + $folder = '├─📁' . $dirname; + } + echo '<tr>'; + echo '<td><a href="' . $mediaopt->getpathadress($path) . '">' . str_repeat(' ', $deepness) . $folder . '</a></td>'; + echo '<td>' . $dirlist['dirfilecount'] . '</td>'; + echo '</tr>'; + foreach ($dirlist as $key => $value) { + if (is_array($value)) { + treecount($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir, $mediaopt); + } + } } @@ -244,100 +270,94 @@ function treecount(array $dirlist, string $dirname, int $deepness, string $path, function basictree(array $dirlist, string $dirname, int $deepness, string $path, string $currentdir) { - if ($path === $currentdir) { - $folder = '├─📂<span id="currentdir">' . $dirname . '<span>'; - $checked = 'checked'; - } else { - $folder = '├─📁' . $dirname; - $checked = ''; - } - - if($deepness === 1) { - $radio = '<input type="radio" name="pagetable" value="' . $dirname . '" id="db_' . $path . '" ' . $checked . '>'; - } else { - $radio = ''; - } - - echo '<tr>'; - echo '<td>' . $radio . '</td>'; - echo '<td><label for="db_' . $path . '">' . str_repeat(' ', $deepness) . $folder . '</label></td>'; - echo '<td>' . $dirlist['dirfilecount'] . '</td>'; - echo '</tr>'; - foreach ($dirlist as $key => $value) { - if (is_array($value)) { - basictree($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir); - } - } + if ($path === $currentdir) { + $folder = '├─📂<span id="currentdir">' . $dirname . '<span>'; + $checked = 'checked'; + } else { + $folder = '├─📁' . $dirname; + $checked = ''; + } + + if ($deepness === 1) { + $radio = '<input type="radio" name="pagetable" value="' . $dirname . '" id="db_' . $path . '" ' . $checked . '>'; + } else { + $radio = ''; + } + + echo '<tr>'; + echo '<td>' . $radio . '</td>'; + echo '<td><label for="db_' . $path . '">' . str_repeat(' ', $deepness) . $folder . '</label></td>'; + echo '<td>' . $dirlist['dirfilecount'] . '</td>'; + echo '</tr>'; + foreach ($dirlist as $key => $value) { + if (is_array($value)) { + basictree($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir); + } + } } function checkboxes(string $name, array $optionlist = [], array $checkedlist = []) { - $checkboxes = ''; - foreach ($optionlist as $option) { - $checkboxes .= '<li><input type="checkbox" name="' . $name . '[]" id="' . $option . '" value="' . $option . '"'; - if(in_array($option, $checkedlist)) { - $checkboxes .= ' checked'; - } - $checkboxes .= '><label for="' . $option . '">' . $option . '</label></li>'; - $checkboxes .= PHP_EOL; - } - return '<ul>' . PHP_EOL . $checkboxes . PHP_EOL . '</ul>'; + $checkboxes = ''; + foreach ($optionlist as $option) { + $checkboxes .= '<li><input type="checkbox" name="' . $name . '[]" id="' . $option . '" value="' . $option . '"'; + if (in_array($option, $checkedlist)) { + $checkboxes .= ' checked'; + } + $checkboxes .= '><label for="' . $option . '">' . $option . '</label></li>'; + $checkboxes .= PHP_EOL; + } + return '<ul>' . PHP_EOL . $checkboxes . PHP_EOL . '</ul>'; } -function recurse_copy($src,$dst) { - $dir = opendir($src); - mkdir($dst); - while(false !== ( $file = readdir($dir)) ) { - if (( $file != '.' ) && ( $file != '..' )) { - if ( is_dir($src . '/' . $file) ) { - recurse_copy($src . '/' . $file,$dst . '/' . $file); - } - else { - copy($src . '/' . $file,$dst . '/' . $file); - } - } - } - closedir($dir); +function recurse_copy($src, $dst) +{ + $dir = opendir($src); + mkdir($dst); + while (false !== ( $file = readdir($dir))) { + if (( $file != '.' ) && ( $file != '..' )) { + if (is_dir($src . '/' . $file)) { + recurse_copy($src . '/' . $file, $dst . '/' . $file); + } else { + copy($src . '/' . $file, $dst . '/' . $file); + } + } + } + closedir($dir); } /** * Generate a list of <options> html drop down list - * + * * @param array $options as `value => title` * @param string|int $selected value of actualy selected option - * + * * @return string HTML list of options */ -function options(array $options, $selected = null) : string +function options(array $options, $selected = null): string { - $html = ''; - foreach ($options as $value => $title) { - if($value == $selected) { - $attribute = 'selected'; - } else { - $attribute = ''; - } - $html .= '<option value="' . $value . '" ' . $attribute . '>' . $title . '</option>' . PHP_EOL; - } - return $html; + $html = ''; + foreach ($options as $value => $title) { + if ($value == $selected) { + $attribute = 'selected'; + } else { + $attribute = ''; + } + $html .= '<option value="' . $value . '" ' . $attribute . '>' . $title . '</option>' . PHP_EOL; + } + return $html; } /** * Hash a Token using secret key and sha256 - * + * * @param string $token Input token - * + * * @return string Hashed mac */ -function secrethash(string $token) : string +function secrethash(string $token): string { - return hash_hmac('sha256', $token, Wcms\Config::secretkey()); + return hash_hmac('sha256', $token, Wcms\Config::secretkey()); } - - - - - -?>
\ No newline at end of file |