From 7faef0e6d81444ad3ae10d1a2ce62fa753c80a9f Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Wed, 21 Nov 2018 15:42:59 +0000 Subject: [PATCH] Improved isTrue() function and its usage to streamline code. --- WEB-INF/lib/Auth.class.php | 6 +++--- WEB-INF/lib/I18n.class.php | 4 ---- WEB-INF/lib/auth/Auth_db.class.php | 2 +- WEB-INF/lib/auth/Auth_ldap.class.php | 24 ++++++++++++------------ WEB-INF/lib/common.lib.php | 2 +- WEB-INF/lib/mail/Mailer.class.php | 6 +++--- WEB-INF/templates/footer.tpl | 2 +- time.php | 2 +- tofile.php | 8 ++++---- 9 files changed, 26 insertions(+), 30 deletions(-) diff --git a/WEB-INF/lib/Auth.class.php b/WEB-INF/lib/Auth.class.php index 354d34ba..d57a0c4a 100644 --- a/WEB-INF/lib/Auth.class.php +++ b/WEB-INF/lib/Auth.class.php @@ -64,7 +64,7 @@ class Auth { function doLogin($login, $password) { $auth = $this->authenticate($login, $password); - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '
'; var_dump($auth); echo '
'; } @@ -77,13 +77,13 @@ class Auth { $sql = "SELECT id FROM tt_users WHERE login = ".$mdb2->quote($login)." AND status = 1"; $res = $mdb2->query($sql); if (is_a($res, 'PEAR_Error')) { - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) + if (isTrue(AUTH_DEBUG)) echo 'db error!
'; return false; } $val = $res->fetchRow(); if (!$val['id']) { - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) + if (isTrue(AUTH_DEBUG)) echo 'login "'.$login.'" does not exist in Time Tracker database.
'; return false; } diff --git a/WEB-INF/lib/I18n.class.php b/WEB-INF/lib/I18n.class.php index 0e3dd02a..15799c23 100644 --- a/WEB-INF/lib/I18n.class.php +++ b/WEB-INF/lib/I18n.class.php @@ -70,9 +70,7 @@ class I18n { $this->weekdayNames = $i18n_weekdays; $this->weekdayShortNames = $i18n_weekdays_short; -// if (defined('SHOW_HOLIDAYS') && isTrue(SHOW_HOLIDAYS)) { $this->holidays = $i18n_holidays; -// } foreach ($i18n_key_words as $kword=>$value) { $pos = strpos($kword, "."); @@ -97,9 +95,7 @@ class I18n { $this->monthNames = $i18n_months; $this->weekdayNames = $i18n_weekdays; $this->weekdayShortNames = $i18n_weekdays_short; -// if (defined('SHOW_HOLIDAYS') && isTrue(SHOW_HOLIDAYS)) { $this->holidays = $i18n_holidays; -// } foreach ($i18n_key_words as $kword=>$value) { if (!$value) continue; $pos = strpos($kword, "."); diff --git a/WEB-INF/lib/auth/Auth_db.class.php b/WEB-INF/lib/auth/Auth_db.class.php index 937ad3cc..c380330c 100644 --- a/WEB-INF/lib/auth/Auth_db.class.php +++ b/WEB-INF/lib/auth/Auth_db.class.php @@ -58,7 +58,7 @@ class Auth_db extends Auth { } else { // If the OLD_PASSWORDS option is defined - set it. - if (defined('OLD_PASSWORDS') && isTrue(OLD_PASSWORDS)) { + if (isTrue(OLD_PASSWORDS)) { $sql = "SET SESSION old_passwords = 1"; $res = $mdb2->query($sql); if (is_a($res, 'PEAR_Error')) { diff --git a/WEB-INF/lib/auth/Auth_ldap.class.php b/WEB-INF/lib/auth/Auth_ldap.class.php index e17b6e7c..23ea127e 100644 --- a/WEB-INF/lib/auth/Auth_ldap.class.php +++ b/WEB-INF/lib/auth/Auth_ldap.class.php @@ -96,7 +96,7 @@ class Auth_ldap extends Auth { $lc = ldap_connect($this->params['server']); - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '
'; echo '$lc='; var_dump($lc); echo '
'; echo 'ldap_error()='; echo ldap_error($lc); echo '
'; @@ -106,7 +106,7 @@ class Auth_ldap extends Auth { ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($lc, LDAP_OPT_REFERRALS, 0); - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { ldap_set_option($lc, LDAP_OPT_DEBUG_LEVEL, 7); } @@ -119,13 +119,13 @@ class Auth_ldap extends Auth { $login .= '@' . $this->params['default_domain']; } - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$login='; var_dump($login); echo '
'; } $lb = @ldap_bind($lc, $login, $password); - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$lb='; var_dump($lb); echo '
'; echo 'ldap_error()='; echo ldap_error($lc); echo '
'; } @@ -142,7 +142,7 @@ class Auth_ldap extends Auth { $fields = array('memberof'); $sr = @ldap_search($lc, $this->params['base_dn'], $filter, $fields); - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$sr='; var_dump($sr); echo '
'; echo 'ldap_error()='; echo ldap_error($lc); echo '
'; } @@ -154,7 +154,7 @@ class Auth_ldap extends Auth { $entries = @ldap_get_entries($lc, $sr); - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$entries='; var_dump($entries); echo '
'; echo 'ldap_error()='; echo ldap_error($lc); echo '
'; } @@ -173,7 +173,7 @@ class Auth_ldap extends Auth { $groups[] = substr($grp_fields[0], 3); } - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$member_of'; var_dump($member_of); echo '
'; }; @@ -195,7 +195,7 @@ class Auth_ldap extends Auth { // Assuming OpenLDAP server. $login_oldap = 'uid='.$login.','.$this->params['base_dn']; - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$login_oldap='; var_dump($login_oldap); echo '
'; } @@ -207,7 +207,7 @@ class Auth_ldap extends Auth { $lb = @ldap_bind($lc, $login_oldap, $password); - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$lb='; var_dump($lb); echo '
'; echo 'ldap_error()='; echo ldap_error($lc); echo '
'; } @@ -225,7 +225,7 @@ class Auth_ldap extends Auth { $fields = array('samaccountname', 'mail', 'memberof', 'department', 'displayname', 'telephonenumber', 'primarygroupid'); $sr = @ldap_search($lc, $this->params['base_dn'], $filter, $fields); - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$sr='; var_dump($sr); echo '
'; echo 'ldap_error()='; echo ldap_error($lc); echo '
'; } @@ -238,7 +238,7 @@ class Auth_ldap extends Auth { $entries = @ldap_get_entries($lc, $sr); - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$entries='; var_dump($entries); echo '
'; echo 'ldap_error()='; echo ldap_error($lc); echo '
'; } @@ -258,7 +258,7 @@ class Auth_ldap extends Auth { $groups[] = substr($grp_fields[0], 3); } - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { + if (isTrue(AUTH_DEBUG)) { echo '$member_of'; var_dump($member_of); echo '
'; } diff --git a/WEB-INF/lib/common.lib.php b/WEB-INF/lib/common.lib.php index d29ba1a1..4411fb58 100644 --- a/WEB-INF/lib/common.lib.php +++ b/WEB-INF/lib/common.lib.php @@ -165,7 +165,7 @@ function check_extension($ext) // isTrue is a helper function to return correct false for older config.php values defined as a string 'false'. function isTrue($val) { - return ($val == false || $val === 'false') ? false : true; + return ($val === true); } // ttValidString is used to check user input to validate a string. diff --git a/WEB-INF/lib/mail/Mailer.class.php b/WEB-INF/lib/mail/Mailer.class.php index 2d674ac3..68142028 100644 --- a/WEB-INF/lib/mail/Mailer.class.php +++ b/WEB-INF/lib/mail/Mailer.class.php @@ -104,8 +104,8 @@ class Mailer { $port = defined('MAIL_SMTP_PORT') ? MAIL_SMTP_PORT : '25'; $username = defined('MAIL_SMTP_USER') ? MAIL_SMTP_USER : null; $password = defined('MAIL_SMTP_PASSWORD') ? MAIL_SMTP_PASSWORD : null; - $auth = (defined('MAIL_SMTP_AUTH') && isTrue(MAIL_SMTP_AUTH)) ? true : false; - $debug = (defined('MAIL_SMTP_DEBUG') && isTrue(MAIL_SMTP_DEBUG)) ? true : false; + $auth = isTrue(MAIL_SMTP_AUTH); + $debug = isTrue(MAIL_SMTP_DEBUG); $mail = Mail::factory('smtp', array ('host' => $host, 'port' => $port, @@ -116,7 +116,7 @@ class Mailer { break; } - if (defined('MAIL_SMTP_DEBUG') && isTrue(MAIL_SMTP_DEBUG)) + if (isTrue(MAIL_SMTP_DEBUG)) PEAR::setErrorHandling(PEAR_ERROR_PRINT); $res = $mail->send($recipients, $headers, $data); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index f1450a13..73cd97e0 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.25.4482 | Copyright © Anuko | +  Anuko Time Tracker 1.18.25.4483 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/time.php b/time.php index 68aaf40e..9e6be9a8 100644 --- a/time.php +++ b/time.php @@ -107,7 +107,7 @@ $_SESSION['task'] = $cl_task; // Elements of timeRecordForm. $form = new Form('timeRecordForm'); -if (defined('SUBGROUP_DEBUG') && isTrue(SUBGROUP_DEBUG)) { +if (isTrue(SUBGROUP_DEBUG)) { if ($user->can('manage_subgroups')) { $groups = $user->getGroups(); if (count($groups) > 1) { diff --git a/tofile.php b/tofile.php index 07bbc11a..445b32d9 100644 --- a/tofile.php +++ b/tofile.php @@ -94,7 +94,7 @@ if ('xml' == $type) { print "\t<".$group_by_tag.">\n"; if ($bean->getAttribute('chduration')) { $val = $subtotal['time']; - if($val && defined('EXPORT_DECIMAL_DURATION') && isTrue(EXPORT_DECIMAL_DURATION)) + if($val && isTrue(EXPORT_DECIMAL_DURATION)) $val = time_to_decimal($val); print "\t\n"; } @@ -126,7 +126,7 @@ if ('xml' == $type) { if ($bean->getAttribute('chfinish')) print "\t\n"; if ($bean->getAttribute('chduration')) { $duration = $item['duration']; - if($duration && defined('EXPORT_DECIMAL_DURATION') && isTrue(EXPORT_DECIMAL_DURATION)) + if($duration && isTrue(EXPORT_DECIMAL_DURATION)) $duration = time_to_decimal($duration); print "\t\n"; } @@ -179,7 +179,7 @@ if ('csv' == $type) { print '"'.$subtotal['name'].'"'; if ($bean->getAttribute('chduration')) { $val = $subtotal['time']; - if($val && defined('EXPORT_DECIMAL_DURATION') && isTrue(EXPORT_DECIMAL_DURATION)) + if($val && isTrue(EXPORT_DECIMAL_DURATION)) $val = time_to_decimal($val); print ',"'.$val.'"'; } @@ -223,7 +223,7 @@ if ('csv' == $type) { if ($bean->getAttribute('chfinish')) print ',"'.$item['finish'].'"'; if ($bean->getAttribute('chduration')) { $val = $item['duration']; - if($val && defined('EXPORT_DECIMAL_DURATION') && isTrue(EXPORT_DECIMAL_DURATION)) + if($val && isTrue(EXPORT_DECIMAL_DURATION)) $val = time_to_decimal($val); print ',"'.$val.'"'; } -- 2.20.1