From 75b65e92b21d45e2b09fb12daef169fb214a7acd Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 23 Mar 2018 15:03:09 +0000 Subject: [PATCH] Refactoring. Replacing getKey() with get(). --- WEB-INF/lib/I18n.class.php | 15 +++++++---- WEB-INF/lib/form/Calendar.class.php | 2 +- WEB-INF/lib/form/CheckboxGroup.class.php | 4 +-- WEB-INF/lib/form/DateField.class.php | 6 ++--- WEB-INF/lib/ttAdmin.class.php | 32 ++++++++++++------------ WEB-INF/lib/ttImportHelper.class.php | 6 ++--- WEB-INF/lib/ttInvoiceHelper.class.php | 30 +++++++++++----------- WEB-INF/lib/ttRegistrator.class.php | 28 ++++++++++----------- WEB-INF/templates/footer.tpl | 2 +- 9 files changed, 65 insertions(+), 60 deletions(-) diff --git a/WEB-INF/lib/I18n.class.php b/WEB-INF/lib/I18n.class.php index 7155edb0..ed7497d7 100644 --- a/WEB-INF/lib/I18n.class.php +++ b/WEB-INF/lib/I18n.class.php @@ -35,23 +35,28 @@ class I18n { var $holidays; var $keys = array(); // These are our localized strings. - // The getKey obtains localized keyword value. - function getKey($kword) { + // get - obtains a localized value from $keys array. + function get($key) { $value = ''; - $pos = strpos($kword, '.'); // Keywords can have separating dots such as in form.login.about. + $pos = strpos($key, '.'); // Keywords can have separating dots such as in form.login.about. if (!($pos === false)) { - $words = explode('.', $kword); + $words = explode('.', $key); $str = ''; foreach ($words as $word) { $str .= "['".$word."']"; } eval("\$value = \$this->keys".$str.";"); } else { - $value = $this->keys[$kword]; + $value = $this->keys[$key]; } return $value; } + // getKey is a legacy function that we are replacing with get. + function getKey($kword) { + return $this->get($kword); + } + // TODO: refactoring ongoing down from here... function getWeekDayName($id) { $id = (int) $id; diff --git a/WEB-INF/lib/form/Calendar.class.php b/WEB-INF/lib/form/Calendar.class.php index 555b6e14..4c835f62 100644 --- a/WEB-INF/lib/form/Calendar.class.php +++ b/WEB-INF/lib/form/Calendar.class.php @@ -207,7 +207,7 @@ class Calendar extends FormElement { $str .= "\n"; } - $str .= "controlName."=".strftime(DB_DATEFORMAT)."\" tabindex=\"-1\">".$i18n->getKey('label.today')."\n"; + $str .= "controlName."=".strftime(DB_DATEFORMAT)."\" tabindex=\"-1\">".$i18n->get('label.today')."\n"; $str .= "\n"; $str .= "controlName\" value=\"$indate\">\n"; diff --git a/WEB-INF/lib/form/CheckboxGroup.class.php b/WEB-INF/lib/form/CheckboxGroup.class.php index 810c9631..9488b5cc 100644 --- a/WEB-INF/lib/form/CheckboxGroup.class.php +++ b/WEB-INF/lib/form/CheckboxGroup.class.php @@ -60,8 +60,8 @@ class CheckboxGroup extends FormElement { function localize() { global $i18n; - $this->lSelAll = $i18n->getKey('label.select_all'); - $this->lSelNone = $i18n->getKey('label.select_none'); + $this->lSelAll = $i18n->get('label.select_all'); + $this->lSelNone = $i18n->get('label.select_none'); } function getHtml() { diff --git a/WEB-INF/lib/form/DateField.class.php b/WEB-INF/lib/form/DateField.class.php index f8eef8cb..9016dff0 100644 --- a/WEB-INF/lib/form/DateField.class.php +++ b/WEB-INF/lib/form/DateField.class.php @@ -52,9 +52,9 @@ class DateField extends TextField { $this->mMonthNames = $i18n->monthNames; $this->mWeekDayShortNames = $i18n->weekdayShortNames; - $this->lToday = $i18n->getKey('label.today'); - $this->lCalendarButtons['today'] = $i18n->getKey('label.today'); - $this->lCalendarButtons['close'] = $i18n->getKey('button.close'); + $this->lToday = $i18n->get('label.today'); + $this->lCalendarButtons['today'] = $i18n->get('label.today'); + $this->lCalendarButtons['close'] = $i18n->get('button.close'); $this->mDateFormat = $user->date_format; $this->mWeekStartDay = $user->week_start; diff --git a/WEB-INF/lib/ttAdmin.class.php b/WEB-INF/lib/ttAdmin.class.php index d4b72e2e..fbcabd47 100644 --- a/WEB-INF/lib/ttAdmin.class.php +++ b/WEB-INF/lib/ttAdmin.class.php @@ -189,42 +189,42 @@ class ttAdmin { $result = true; if (!ttValidString($fields['group_name'], true)) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.team_name')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.team_name')); $result = false; } if (!ttValidString($fields['user_name'])) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_name')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.manager_name')); $result = false; } if (!ttValidString($fields['new_login'])) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_login')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.manager_login')); $result = false; } // If we change login, it must be unique. if ($fields['new_login'] != $fields['old_login']) { if (ttUserHelper::getUserByLogin($fields['new_login'])) { - $this->err->add($i18n->getKey('error.user_exists')); + $this->err->add($i18n->get('error.user_exists')); $result = false; } } if (!$auth->isPasswordExternal() && ($fields['password1'] || $fields['password2'])) { if (!ttValidString($fields['password1'])) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.password')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.password')); $result = false; } if (!ttValidString($fields['password2'])) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.confirm_password')); $result = false; } if ($fields['password1'] !== $fields['password2']) { - $this->err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password')); + $this->err->add($i18n->get('error.not_equal'), $i18n->get('label.password'), $i18n->get('label.confirm_password')); $result = false; } } if (!ttValidEmail($fields['email'], true)) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.email')); $result = false; } @@ -271,36 +271,36 @@ class ttAdmin { $result = true; if (!ttValidString($fields['name'])) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.person_name')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.person_name')); $result = false; } if (!ttValidString($fields['login'])) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.login')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.login')); $result = false; } // If we change login, it must be unique. if ($fields['login'] != $user->login) { if (ttUserHelper::getUserByLogin($fields['login'])) { - $this->err->add($i18n->getKey('error.user_exists')); + $this->err->add($i18n->get('error.user_exists')); $result = false; } } if (!$auth->isPasswordExternal() && ($fields['password1'] || $fields['password2'])) { if (!ttValidString($fields['password1'])) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.password')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.password')); $result = false; } if (!ttValidString($fields['password2'])) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.confirm_password')); $result = false; } if ($fields['password1'] !== $fields['password2']) { - $this->err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password')); + $this->err->add($i18n->get('error.not_equal'), $i18n->get('label.password'), $i18n->get('label.confirm_password')); $result = false; } } if (!ttValidEmail($fields['email'], true)) { - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.email')); $result = false; } @@ -326,7 +326,7 @@ class ttAdmin { $sql = 'update tt_users set '.$login_part.$password_part.$name_part.$email_part.$modified_part.'where id = '.$user_id; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) { - $this->err->add($i18n->getKey('error.db')); + $this->err->add($i18n->get('error.db')); return false; } diff --git a/WEB-INF/lib/ttImportHelper.class.php b/WEB-INF/lib/ttImportHelper.class.php index 55fd1540..ca717cae 100644 --- a/WEB-INF/lib/ttImportHelper.class.php +++ b/WEB-INF/lib/ttImportHelper.class.php @@ -371,13 +371,13 @@ class ttImportHelper { // If the file is compressed - uncompress it. if ($compressed) { if (!$this->uncompress($_FILES['xmlfile']['tmp_name'], $filename)) { - $this->errors->add($i18n->getKey('error.sys')); + $this->errors->add($i18n->get('error.sys')); return; } unlink($_FILES['xmlfile']['tmp_name']); } else { if (!move_uploaded_file($_FILES['xmlfile']['tmp_name'], $filename)) { - $this->errors->add($i18n->getKey('error.upload')); + $this->errors->add($i18n->get('error.upload')); return; } } @@ -397,7 +397,7 @@ class ttImportHelper { xml_get_current_line_number($parser))); } if (!$this->canImport) { - $this->errors->add($i18n->getKey('error.user_exists')); + $this->errors->add($i18n->get('error.user_exists')); break; } } diff --git a/WEB-INF/lib/ttInvoiceHelper.class.php b/WEB-INF/lib/ttInvoiceHelper.class.php index fd701fe5..d58bc116 100644 --- a/WEB-INF/lib/ttInvoiceHelper.class.php +++ b/WEB-INF/lib/ttInvoiceHelper.class.php @@ -429,16 +429,16 @@ class ttInvoiceHelper { $body .= ''; // Output title. - $body .= '

'.$i18n->getKey('title.invoice').' '.htmlspecialchars($invoice['name']).'

'; + $body .= '

'.$i18n->get('title.invoice').' '.htmlspecialchars($invoice['name']).'

'; // Output comment. if($comment) $body .= '

'.htmlspecialchars($comment).'

'; // Output invoice info. $body .= ''; - $body .= ''; - $body .= ''; - $body .= ''; + $body .= ''; + $body .= ''; + $body .= ''; $body .= '
'.$i18n->getKey('label.date').': '.$invoice['date'].'
'.$i18n->getKey('label.client').': '.htmlspecialchars($client['name']).'
'.$i18n->getKey('label.client_address').': '.htmlspecialchars($client['address']).'
'.$i18n->get('label.date').': '.$invoice['date'].'
'.$i18n->get('label.client').': '.htmlspecialchars($client['name']).'
'.$i18n->get('label.client_address').': '.htmlspecialchars($client['address']).'
'; $body .= '

'; @@ -446,15 +446,15 @@ class ttInvoiceHelper { // Output invoice items. $body .= ''; $body .= ''; - $body .= ''; - $body .= ''; + $body .= ''; + $body .= ''; if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->tracking_mode) - $body .= ''; + $body .= ''; if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode) - $body .= ''; - $body .= ''; - $body .= ''; - $body .= ''; + $body .= ''; + $body .= ''; + $body .= ''; + $body .= ''; $body .= ''; foreach ($invoice_items as $item) { $body .= ''; @@ -477,15 +477,15 @@ class ttInvoiceHelper { $colspan += 2; $body .= ''; if ($tax) { - $body .= ''; - $body .= ''; + $body .= ''; + $body .= ''; } - $body .= ''; + $body .= ''; $body .= '
'.$i18n->getKey('label.date').''.$i18n->getKey('form.invoice.person').''.$i18n->get('label.date').''.$i18n->get('form.invoice.person').''.$i18n->getKey('label.project').''.$i18n->get('label.project').''.$i18n->getKey('label.task').''.$i18n->getKey('label.note').''.$i18n->getKey('label.duration').''.$i18n->getKey('label.cost').''.$i18n->get('label.task').''.$i18n->get('label.note').''.$i18n->get('label.duration').''.$i18n->get('label.cost').'
 
'.$i18n->getKey('label.subtotal').':'.$subtotal.'
'.$i18n->getKey('label.tax').':'.$tax.'
'.$i18n->get('label.subtotal').':'.$subtotal.'
'.$i18n->get('label.tax').':'.$tax.'
'.$i18n->getKey('label.total').':'.$total.'
'.$i18n->get('label.total').':'.$total.'
'; // Output footer. if (!defined('REPORT_FOOTER') || !(REPORT_FOOTER == false)) - $body .= '

'.$i18n->getKey('form.mail.footer').'

'; + $body .= '

'.$i18n->get('form.mail.footer').'

'; // Finish creating email body. $body .= ''; diff --git a/WEB-INF/lib/ttRegistrator.class.php b/WEB-INF/lib/ttRegistrator.class.php index 71f49e69..7082e6bc 100644 --- a/WEB-INF/lib/ttRegistrator.class.php +++ b/WEB-INF/lib/ttRegistrator.class.php @@ -62,21 +62,21 @@ class ttRegistrator { global $i18n; if (!ttValidString($this->group_name, true)) - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.team_name')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.team_name')); if (!ttValidString($this->currency, true)) - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.currency')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.currency')); if (!ttValidString($this->user_name)) - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_name')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.manager_name')); if (!ttValidString($this->login)) - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_login')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.manager_login')); if (!ttValidString($this->password1)) - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.password')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.password')); if (!ttValidString($this->password2)) - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.confirm_password')); if ($this->password1 !== $this->password2) - $this->err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password')); + $this->err->add($i18n->get('error.not_equal'), $i18n->get('label.password'), $i18n->get('label.confirm_password')); if (!ttValidEmail($this->email, true)) - $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.email')); } // The register function registers a user in Time Tracker. @@ -88,27 +88,27 @@ class ttRegistrator { import('ttUserHelper'); if (ttUserHelper::getUserByLogin($this->login)) { // User login already exists. - $this->err->add($i18n->getKey('error.user_exists')); + $this->err->add($i18n->get('error.user_exists')); return false; } // Create a new group. $this->group_id = $this->createGroup(); if (!$this->group_id) { - $this->err->add($i18n->getKey('error.db')); + $this->err->add($i18n->get('error.db')); return false; } import('ttRoleHelper'); if (!ttRoleHelper::createPredefinedRoles($this->group_id, $this->lang)) { - $err->add($i18n->getKey('error.db')); + $err->add($i18n->get('error.db')); return false; } $this->role_id = ttRoleHelper::getTopManagerRoleID(); $this->user_id = $this->createUser(); if (!$this->user_id) { - $err->add($i18n->getKey('error.db')); + $err->add($i18n->get('error.db')); return false; } @@ -171,7 +171,7 @@ class ttRegistrator { $sql = "update tt_teams set created_by = $user_id where id = $this->group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) { - $this->err->add($i18n->getKey('error.db')); + $this->err->add($i18n->get('error.db')); return false; } @@ -179,7 +179,7 @@ class ttRegistrator { $sql = "update tt_users set created_by = $user_id where id = $user_id and team_id = $this->group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) { - $this->err->add($i18n->getKey('error.db')); + $this->err->add($i18n->get('error.db')); return false; } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 881616e0..d92f371a 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.17.67.4141 | Copyright © Anuko | +  Anuko Time Tracker 1.17.67.4142 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1