From 7ff5000cb367520c3221612df16a1018cb02d3f7 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 12 Oct 2023 20:51:13 +0200 Subject: [PATCH] refactoring --- lam/lib/account.inc | 4 ++-- lam/lib/adminHeader.inc | 2 +- lam/lib/config.inc | 6 +++--- lam/lib/configPages.inc | 2 +- lam/lib/ldap.inc | 4 ++-- lam/lib/modules.inc | 4 ++-- lam/lib/modules/freeRadius.inc | 2 +- lam/lib/modules/inetOrgPerson.inc | 10 +++++----- lam/lib/pdf.inc | 2 +- lam/lib/pdfstruct.inc | 2 +- lam/lib/security.inc | 6 +++--- lam/lib/tools.inc | 2 +- lam/lib/webauthn.inc | 2 +- lam/templates/lists/userlink.php | 9 +++++---- lam/templates/login.php | 2 +- 15 files changed, 30 insertions(+), 29 deletions(-) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index fab1a17e5..06dba321b 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -1961,7 +1961,7 @@ function printHeaderContents($title, $prefix) { echo $title; echo "\n"; // include CSS files - $cssDirName = dirname(__FILE__) . '/../style'; + $cssDirName = __DIR__ . '/../style'; $cssDir = dir($cssDirName); $cssFiles = array(); $cssEntry = $cssDir->read(); @@ -1985,7 +1985,7 @@ function printHeaderContents($title, $prefix) { * @param string $prefix prefix to LAM main folder (e.g. "..") */ function printJsIncludes($prefix) { - $jsDirName = dirname(__FILE__) . '/../templates/lib'; + $jsDirName = __DIR__ . '/../templates/lib'; $jsDir = dir($jsDirName); $jsFiles = array(); $jsEntry = $jsDir->read(); diff --git a/lam/lib/adminHeader.inc b/lam/lib/adminHeader.inc index fc40db914..2822e1812 100644 --- a/lam/lib/adminHeader.inc +++ b/lam/lib/adminHeader.inc @@ -181,7 +181,7 @@ function printHeader(string $headerPrefix): void { parseHtml(null, $toolGroup, array(), false, null); } - if (is_dir(dirname(__FILE__) . '/../docs/manual')) { + if (is_dir(__DIR__ . '/../docs/manual')) { ?> diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 47fe43d6b..0f0b7a976 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -269,7 +269,7 @@ function isAccountTypeHidden($type) { function getLanguages() { $languages = array(); // loading available languages from language.conf file - $languagefile = dirname(__FILE__) . "/../config/language"; + $languagefile = __DIR__ . "/../config/language"; if(is_file($languagefile)) { $file = fopen($languagefile, "r"); while(!feof($file)) { @@ -3608,7 +3608,7 @@ class LAMCfgMain { * @return boolean copied */ public function installSampleConfig() { - $samplePath = dirname(dirname(__FILE__)) . '/config/config.cfg.sample'; + $samplePath = __DIR__ . '/../config/config.cfg.sample'; return file_exists($samplePath) && copy($samplePath, $this->conffile); } @@ -3631,7 +3631,7 @@ class LAMCfgMain { * @return String file name */ private function getInternalSSLCaCertFileName() { - return dirname(__FILE__) . '/../config/serverCerts.pem'; + return __DIR__ . '/../config/serverCerts.pem'; } /** diff --git a/lam/lib/configPages.inc b/lam/lib/configPages.inc index 81c16f0e7..e26634f58 100644 --- a/lam/lib/configPages.inc +++ b/lam/lib/configPages.inc @@ -75,7 +75,7 @@ function printConfigurationPageHeaderBar($conf) { menu diff --git a/lam/lib/ldap.inc b/lam/lib/ldap.inc index 6efdec882..1957f1def 100644 --- a/lam/lib/ldap.inc +++ b/lam/lib/ldap.inc @@ -175,7 +175,7 @@ class Ldap{ public function __wakeup() { $this->is_connected = false; // delete PDF files and images which are older than 15 min - $tmpDir = dirname(__FILE__) . '/../tmp/'; + $tmpDir = __DIR__ . '/../tmp/'; $time = time(); $dir = @opendir($tmpDir); $file = @readdir($dir); @@ -190,7 +190,7 @@ class Ldap{ } @closedir($dir); // clean internal files that are older than 24 hours - $tmpDir = dirname(__FILE__) . '/../tmp/internal/'; + $tmpDir = __DIR__ . '/../tmp/internal/'; $time = time(); $dir = @opendir($tmpDir); $file = @readdir($dir); diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 79e0253c1..b360d516b 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -2920,7 +2920,7 @@ class ScopeAndModuleValidation { return false; } if (self::$cachedScopeNames === null) { - $dirname = dirname(__FILE__) . "/types"; + $dirname = __DIR__ . "/types"; $dir = dir($dirname); $scopeNames = array(); while ($entry = $dir->read()) { @@ -2948,7 +2948,7 @@ class ScopeAndModuleValidation { return false; } if (self::$cachedModuleNames === null) { - $dirname = dirname(__FILE__) . "/modules"; + $dirname = __DIR__ . "/modules"; $dir = dir($dirname); $moduleNames = array(); while ($entry = $dir->read()) { diff --git a/lam/lib/modules/freeRadius.inc b/lam/lib/modules/freeRadius.inc index 473b2231d..e1f8c0bb2 100644 --- a/lam/lib/modules/freeRadius.inc +++ b/lam/lib/modules/freeRadius.inc @@ -843,7 +843,7 @@ class freeRadius extends baseModule { if (interface_exists('\LAM\JOB\Job', false)) { - include_once dirname(__FILE__) . '/../passwordExpirationJob.inc'; + include_once __DIR__ . '/../passwordExpirationJob.inc'; /** * Job to delete or move users on account expiration. diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index d7f3449e9..975410f9c 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -1664,7 +1664,7 @@ class inetOrgPerson extends baseModule implements passwordService,AccountStatusP if (isset($_POST['form_subpage_' . get_class($this) . '_attributes_crop'])) { $messages = array(); try { - include_once dirname(__FILE__) . '/../imageutils.inc'; + include_once __DIR__ . '/../imageutils.inc'; $imageManipulator = ImageManipulationFactory::getImageManipulator($this->attributes['jpegPhoto'][0]); $imageManipulator->crop($_POST['croppingDataX'], $_POST['croppingDataY'], $_POST['croppingDataWidth'], $_POST['croppingDataHeight']); $this->attributes['jpegPhoto'][0] = $imageManipulator->getImageData(); @@ -1707,7 +1707,7 @@ class inetOrgPerson extends baseModule implements passwordService,AccountStatusP } // convert to JPG try { - include_once dirname(__FILE__) . '/../imageutils.inc'; + include_once __DIR__ . '/../imageutils.inc'; $imageManipulator = ImageManipulationFactory::getImageManipulator($data); // resize if maximum values specified if (!empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxWidth'][0]) || !empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxHeight'][0])) { @@ -3205,7 +3205,7 @@ class inetOrgPerson extends baseModule implements passwordService,AccountStatusP elseif (!empty($data) && (empty($attributes['jpegPhoto'][0]) || ($data != $attributes['jpegPhoto'][0]))) { $moduleSettings = $this->selfServiceSettings->moduleSettings; try { - include_once dirname(__FILE__) . '/../imageutils.inc'; + include_once __DIR__ . '/../imageutils.inc'; $imageManipulator = ImageManipulationFactory::getImageManipulator($data); $imageManipulator->crop($_POST['croppingDataX'], $_POST['croppingDataY'], $_POST['croppingDataWidth'], $_POST['croppingDataHeight']); $data = $imageManipulator->getImageData(); @@ -3319,7 +3319,7 @@ class inetOrgPerson extends baseModule implements passwordService,AccountStatusP * @return array binary image data */ private static function resizeAndConvertImage($data, $settings) { - include_once dirname(__FILE__) . '/../imageutils.inc'; + include_once __DIR__ . '/../imageutils.inc'; $imageManipulator = ImageManipulationFactory::getImageManipulator($data); // resize if maximum values specified if (!empty($settings['inetOrgPerson_jpegPhoto_maxWidth'][0]) || !empty($settings['inetOrgPerson_jpegPhoto_maxHeight'][0])) { @@ -3412,7 +3412,7 @@ class inetOrgPerson extends baseModule implements passwordService,AccountStatusP $data = base64_decode($data); } try { - include_once dirname(__FILE__) . '/../imageutils.inc'; + include_once __DIR__ . '/../imageutils.inc'; $imageManipulator = ImageManipulationFactory::getImageManipulator($data); $imageManipulator->convertToJpeg(); $data = $imageManipulator->getImageData(); diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc index 2bc9463d5..10f5c0763 100644 --- a/lam/lib/pdf.inc +++ b/lam/lib/pdf.inc @@ -250,7 +250,7 @@ function printTable(&$pdf, $table, $fontName) { * @param string $fontName font name */ function printImage(&$pdf, $imageEntry, $fontName) { - include_once dirname(__FILE__) . '/imageutils.inc'; + include_once __DIR__ . '/imageutils.inc'; $imageManipulator = ImageManipulationFactory::getImageManipulator($imageEntry->getImageData()); $height = $imageManipulator->getHeight() / 2.9; if ($height > 40) { diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index 243a591ed..1cc828b17 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -931,7 +931,7 @@ class PdfStructurePersistenceStrategyFiles implements PdfStructurePersistenceStr * @return string file name */ private function getPdfStructureFileName(string $confName, string $typeId, string $name) : string { - return dirname(__FILE__) . '/../config/pdf/' . $confName . '/' . $name . '.' . $typeId . '.xml'; + return __DIR__ . '/../config/pdf/' . $confName . '/' . $name . '.' . $typeId . '.xml'; } } diff --git a/lam/lib/security.inc b/lam/lib/security.inc index 29a94b757..17307f579 100644 --- a/lam/lib/security.inc +++ b/lam/lib/security.inc @@ -77,7 +77,7 @@ function startSecureSession($redirectToLogin = true, $initSecureData = false) { unset($_SESSION); } if (isFileBasedSession()) { - $sessionDir = dirname(__FILE__) . "/../sess"; + $sessionDir = __DIR__ . "/../sess"; session_save_path($sessionDir); // enable garbage collection (fix for Debian based systems) if (@ini_get("session.gc_probability") == 0) { @@ -826,7 +826,7 @@ class LamTemporaryFilesManager { if (!$this->isValidFileName($fileName)) { throw new LAMException(_('Unable to create temporary file.')); } - $path = dirname(__FILE__) . '/../tmp/' . $fileName; + $path = __DIR__ . '/../tmp/' . $fileName; $handle = @fopen($path, "wb"); if ($handle) { @chmod($path, 0600); @@ -960,7 +960,7 @@ class LamTemporaryFilesManager { if (!$this->isValidFileName($fileName) || !$this->isRegisteredFile($fileName)) { throw new LAMException(_('Unable to read file.')); } - return dirname(__FILE__) . '/../tmp/' . $fileName; + return __DIR__ . '/../tmp/' . $fileName; } } diff --git a/lam/lib/tools.inc b/lam/lib/tools.inc index e5488b812..923c93f60 100644 --- a/lam/lib/tools.inc +++ b/lam/lib/tools.inc @@ -34,7 +34,7 @@ * @return array list of LAMTool objects */ function getTools() : array { - $toolsDirName = dirname(__FILE__) . '/tools'; + $toolsDirName = __DIR__ . '/tools'; $toolsDir = dir($toolsDirName); $entry = $toolsDir->read(); // include all files in the tools directory diff --git a/lam/lib/webauthn.inc b/lam/lib/webauthn.inc index 34a4f59a9..2f3aaa5b7 100644 --- a/lam/lib/webauthn.inc +++ b/lam/lib/webauthn.inc @@ -757,7 +757,7 @@ class PublicKeyCredentialSourceRepositorySQLite extends PublicKeyCredentialSourc * @return string the PDO URL */ public function getPdoUrl(): string { - $fileName = dirname(__FILE__) . '/../config/__lam.webauthn.sqlite'; + $fileName = __DIR__ . '/../config/__lam.webauthn.sqlite'; if (!file_exists($fileName)) { $handle = fopen($fileName, 'w'); fclose($handle); diff --git a/lam/templates/lists/userlink.php b/lam/templates/lists/userlink.php index dab33c0fe..b158d15be 100644 --- a/lam/templates/lists/userlink.php +++ b/lam/templates/lists/userlink.php @@ -1,11 +1,12 @@ addVerticalSpacer('1rem'); $container->add(new htmlStatusMessage("ERROR", _("This user was not found!"), htmlspecialchars($user)), 12); $container->addVerticalSpacer('1rem'); - $container->add(new \htmlLink(_("Back to group list"), 'javascript:history.back()'), 12); - parseHtml(null, $container, array(), false, 'user'); + $container->add(new htmlLink(_("Back to group list"), 'javascript:history.back()'), 12); + parseHtml(null, $container, [], false, 'user'); include __DIR__ . '/../../lib/adminFooter.inc'; } @@ -78,7 +79,7 @@ * @return string DN */ function search_username(string $name): ?string { - $entries = searchLDAPByAttribute('uid', $name, null, array('dn'), array('user')); + $entries = searchLDAPByAttribute('uid', $name, null, ['dn'], ['user']); if (sizeof($entries) > 0 ) { return $entries[0]['dn']; } diff --git a/lam/templates/login.php b/lam/templates/login.php index e5a23d113..3c8820108 100644 --- a/lam/templates/login.php +++ b/lam/templates/login.php @@ -71,7 +71,7 @@ // set session save path if (isFileBasedSession()) { - session_save_path(dirname(__FILE__) . '/../sess'); + session_save_path(__DIR__ . '/../sess'); } // start empty session and change ID for security reasons