Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberroland committed Oct 12, 2023
1 parent aaa1a97 commit 7ff5000
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lam/lib/account.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ function printHeaderContents($title, $prefix) {
echo $title;
echo "</title>\n";
// include CSS files
$cssDirName = dirname(__FILE__) . '/../style';
$cssDirName = __DIR__ . '/../style';
$cssDir = dir($cssDirName);
$cssFiles = array();
$cssEntry = $cssDir->read();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lam/lib/adminHeader.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
?>
<a class="lam-menu-entry" target="_blank" href="<?php echo $headerPrefix; ?>/docs/manual/index.html">
<span class="padding0"><?php echo _("Help") ?></span>
Expand Down
6 changes: 3 additions & 3 deletions lam/lib/config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -3631,7 +3631,7 @@ class LAMCfgMain {
* @return String file name
*/
private function getInternalSSLCaCertFileName() {
return dirname(__FILE__) . '/../config/serverCerts.pem';
return __DIR__ . '/../config/serverCerts.pem';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lam/lib/configPages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function printConfigurationPageHeaderBar($conf) {
</span>
</div>
<?php
if (is_dir(dirname(__FILE__) . '/../docs/manual')) {
if (is_dir(__DIR__ . '/../docs/manual')) {
?>
<a class="lam-header-right lam-menu-icon hide-on-tablet" href="javascript:void(0);" class="icon" onclick="window.lam.topmenu.toggle();">
<img class="align-middle" width="16" height="16" alt="menu" src="../../graphics/menu.svg">
Expand Down
4 changes: 2 additions & 2 deletions lam/lib/ldap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lam/lib/modules.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion lam/lib/modules/freeRadius.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions lam/lib/modules/inetOrgPerson.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lam/lib/pdf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lam/lib/pdfstruct.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

}
Expand Down
6 changes: 3 additions & 3 deletions lam/lib/security.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

}
Expand Down
2 changes: 1 addition & 1 deletion lam/lib/tools.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lam/lib/webauthn.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions lam/templates/lists/userlink.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
namespace LAM\ACCOUNTLIST;
use htmlLink;
use \htmlResponsiveRow;
use \htmlStatusMessage;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2022 Roland Gruber
Copyright (C) 2003 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -65,8 +66,8 @@
$container->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';
}

Expand All @@ -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'];
}
Expand Down
2 changes: 1 addition & 1 deletion lam/templates/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ff5000

Please sign in to comment.