1
0
mirror of https://github.com/misterunknown/ifm.git synced 2025-08-10 18:14:00 +02:00

fix code style warnings by latest psr

This commit is contained in:
Dmitriy Novash
2022-12-22 18:37:26 +02:00
parent 096a391809
commit 6ab7e569ef
5 changed files with 167 additions and 134 deletions

View File

@@ -26,16 +26,19 @@ $IFM_SRC_PHP = [
$options = getopt(null, ["language::", "languages::", "lang::", "cdn"]);
// build CDN version?
if (isset($options['cdn']))
if (isset($options['cdn'])) {
define("IFM_CDN", true);
else
} else {
define("IFM_CDN", false);
}
// process languages
$langs = [];
foreach ($options as $key => $value)
if (substr($key, 0, 4) == "lang")
foreach ($options as $key => $value) {
if (substr($key, 0, 4) == "lang") {
$langs = array_merge($langs, explode(",", $value));
}
}
$langs = array_unique($langs);
if (!empty($langs)) {
@@ -45,8 +48,9 @@ if (!empty($langs)) {
}
// ensure english is available, as it gets merged with the other languages
// in case of missing keys in other languages.
if (!in_array("all", $langs) || !in_array("en", $langs))
if (!in_array("all", $langs) || !in_array("en", $langs)) {
array_push($langs, "en");
}
if (in_array("all", $langs))
$langs = array_map(
@@ -55,15 +59,17 @@ if (in_array("all", $langs))
);
$vars['languageincludes'] = "";
foreach ($langs as $l)
if (file_exists("src/i18n/".$l.".json"))
foreach ($langs as $l) {
if (file_exists("src/i18n/".$l.".json")) {
$vars['languageincludes'] .=
'$i18n["'.$l.'"] = <<<\'f00bar\'' . "\n"
. file_get_contents( "src/i18n/".$l.".json" ) . "\n"
. 'f00bar;' . "\n"
. '$i18n["'.$l.'"] = json_decode( $i18n["'.$l.'"], true );' . "\n" ;
else
} else {
print "WARNING: Language file src/i18n/".$l.".json not found.\n";
}
}
// Concat PHP Files
$compiled = ["<?php"];
@@ -79,13 +85,14 @@ $compiled = str_replace("@@@ASSETS_CSS@@@", file_get_contents("src/assets".(IFM_
$compiled = str_replace("@@@ASSETS_JS@@@", file_get_contents("src/assets".(IFM_CDN?".cdn":"").".js"), $compiled);
// Process file includes
$includes = NULL;
$includes = null;
preg_match_all("/\@\@\@file:([^\@]+)\@\@\@/", $compiled, $includes, PREG_SET_ORDER);
foreach ($includes as $file)
foreach ($includes as $file) {
$compiled = str_replace($file[0], file_get_contents($file[1]), $compiled);
}
// Process ace includes
$includes = NULL;
$includes = null;
$vars['ace_includes'] = "";
preg_match_all("/\@\@\@acedir:([^\@]+)\@\@\@/", $compiled, $includes, PREG_SET_ORDER);
foreach ($includes as $dir) {
@@ -100,15 +107,17 @@ foreach ($includes as $dir) {
}
// Process variable includes
$includes = NULL;
$includes = null;
preg_match_all("/\@\@\@vars:([^\@]+)\@\@\@/", $compiled, $includes, PREG_SET_ORDER);
foreach( $includes as $var )
foreach ($includes as $var) {
$compiled = str_replace($var[0], $vars[$var[1]], $compiled);
}
$compiled = str_replace('IFM_VERSION', IFM_VERSION, $compiled);
if (!is_dir(IFM_RELEASE_DIR))
if (!is_dir(IFM_RELEASE_DIR)) {
mkdir(IFM_RELEASE_DIR);
}
// build standalone ifm
file_put_contents(IFM_RELEASE_DIR . (IFM_CDN ? 'cdn.' : '') . IFM_STANDALONE, $compiled);

View File

@@ -7,9 +7,10 @@ class Htpasswd {
public $users = [];
public function __construct($filename="") {
if( $filename )
if ($filename) {
$this->load($filename);
}
}
/**
* Load a new htpasswd file
@@ -23,9 +24,10 @@ class Htpasswd {
$this->users[$user] = trim($pass);
}
return true;
} else
} else {
return false;
}
}
public function getUsers() {
return array_keys($this->users);
@@ -50,7 +52,7 @@ class Htpasswd {
$apr1 = new APR1_MD5();
return $apr1->check($pass, $hash);
} elseif (substr($hash, 0, 5) == '{SHA}') {
return base64_encode( sha1( $pass, TRUE ) ) == substr( $hash, 5 );
return base64_encode(sha1($pass, true)) == substr($hash, 5);
} else { // assume CRYPT
return crypt($pass, $hash) == $hash;
}
@@ -75,21 +77,28 @@ class APR1_MD5 {
// Wikipedia
public static function hash($mdp, $salt = null) {
if (is_null($salt))
if (is_null($salt)) {
$salt = self::salt();
}
$salt = substr($salt, 0, 8);
$max = strlen($mdp);
$context = $mdp.'$apr1$'.$salt;
$binary = pack('H32', md5($mdp.$salt.$mdp));
for($i=$max; $i>0; $i-=16)
for ($i=$max; $i>0; $i-=16) {
$context .= substr($binary, 0, min(16, $i));
for($i=$max; $i>0; $i>>=1)
}
for ($i=$max; $i>0; $i>>=1) {
$context .= ($i & 1) ? chr(0) : $mdp[0];
}
$binary = pack('H32', md5($context));
for ($i=0; $i<1000; $i++) {
$new = ($i & 1) ? $mdp : $binary;
if($i % 3) $new .= $salt;
if($i % 7) $new .= $mdp;
if ($i % 3) {
$new .= $salt;
}
if ($i % 7) {
$new .= $mdp;
}
$new .= ($i & 1) ? $binary : $mdp;
$binary = pack('H32', md5($new));
}
@@ -97,7 +106,9 @@ class APR1_MD5 {
for ($i = 0; $i < 5; $i++) {
$k = $i+6;
$j = $i+12;
if($j == 16) $j = 5;
if ($j == 16) {
$j = 5;
}
$hash = $binary[$i].$binary[$k].$binary[$j].$hash;
}
$hash = chr(0).chr(0).$binary[11].$hash;

View File

@@ -24,8 +24,9 @@ class IFMArchive {
* Add a folder to an archive
*/
private static function addFolder(&$archive, $folder, $offset=0, $exclude_callback=null) {
if ($offset == 0)
if ($offset == 0) {
$offset = strlen(dirname($folder)) + 1;
}
$archive->addEmptyDir(substr($folder, $offset));
$handle = opendir($folder);
while (false !== $f = readdir($handle)) {
@@ -33,17 +34,19 @@ class IFMArchive {
$filePath = $folder . '/' . $f;
if (file_exists($filePath) && is_readable($filePath)) {
if (is_file($filePath)) {
if (!is_callable($exclude_callback) || $exclude_callback($f))
if (!is_callable($exclude_callback) || $exclude_callback($f)) {
$archive->addFile($filePath, substr($filePath, $offset));
}
} elseif (is_dir($filePath)) {
if (is_callable($exclude_callback))
if (is_callable($exclude_callback)) {
self::addFolder($archive, $filePath, $offset, $exclude_callback);
else
} else {
self::addFolder($archive, $filePath, $offset);
}
}
}
}
}
closedir($handle);
}
@@ -54,18 +57,22 @@ class IFMArchive {
$a = new ZipArchive();
$a->open($archivename, ZIPARCHIVE::CREATE);
if (!is_array($filenames))
if (!is_array($filenames)) {
$filenames = array($filenames);
}
foreach ($filenames as $f)
if (is_dir($f))
if (is_callable($exclude_callback))
if (is_dir($f)) {
if (is_callable($exclude_callback)) {
self::addFolder($a, $f, null, $exclude_callback);
else
} else {
self::addFolder($a, $f);
elseif (is_file($f))
if (!is_callable($exclude_callback) || $exclude_callback($f))
}
} elseif (is_file($f)) {
if (!is_callable($exclude_callback) || $exclude_callback($f)) {
$a->addFile($f, pathinfo($f, PATHINFO_BASENAME));
}
}
try {
return $a->close();
@@ -78,17 +85,19 @@ class IFMArchive {
* Unzip a zip file
*/
public static function extractZip($file, $destination="./") {
if (!file_exists($file))
if (!file_exists($file)) {
return false;
}
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === true) {
$zip->extractTo($destination);
$zip->close();
return true;
} else
} else {
return false;
}
}
/**
* Creates a tar archive
@@ -98,14 +107,17 @@ class IFMArchive {
$a = new PharData($tmpf);
try {
if (!is_array($filenames))
if (!is_array($filenames)) {
$filenames = array($filenames);
}
foreach ($filenames as $f)
if (is_dir($f))
foreach ($filenames as $f) {
if (is_dir($f)) {
self::addFolder($a, $f);
elseif (is_file($f))
} elseif (is_file($f)) {
$a->addFile($f, pathinfo($f, PATHINFO_BASENAME));
}
}
switch ($format) {
case "tar.gz":
$a->compress(Phar::GZ);
@@ -127,8 +139,9 @@ class IFMArchive {
* Extracts a tar archive
*/
public static function extractTar($file, $destination="./") {
if (!file_exists($file))
if (!file_exists($file)) {
return false;
}
$tar = new PharData($file);
try {
$tar->extractTo($destination, null, true);