diff --git a/lib/Common/SmartyPage.php b/lib/Common/SmartyPage.php index e4e7cdbc8..55249b9fe 100644 --- a/lib/Common/SmartyPage.php +++ b/lib/Common/SmartyPage.php @@ -22,11 +22,6 @@ class SmartyPage extends Smarty */ protected $Resources = null; - /** - * @var null|string - */ - protected $RootPath = null; - /** * @var bool */ @@ -35,13 +30,13 @@ class SmartyPage extends Smarty /** * * @param Resources $resources - * @param string $rootPath + * @param string $RootPath */ - public function __construct(Resources &$resources = null, $rootPath = null) + public function __construct(Resources &$resources = null, protected $RootPath = null) { parent::__construct(); - $base = dirname(__FILE__) . '/../../'; + $base = __DIR__ . '/../../'; $this->debugging = isset($_GET['debug']); $this->AddTemplateDirectory($base . 'tpl'); @@ -63,11 +58,11 @@ public function __construct(Resources &$resources = null, $rootPath = null) } $this->Resources = &$resources; - $this->RootPath = $rootPath; $this->AddTemplateDirectory($base . 'lang/' . $this->Resources->CurrentLanguage); $this->RegisterFunctions(); + $this->RegisterClasses(); } public function AddTemplateDirectory($templateDirectory) @@ -93,7 +88,7 @@ public function FetchLocalized($templateName, bool $enforceCustomTemplate, strin $localizedPath = $langPath . $languageCode; $customTemplateName = str_replace('.tpl', '-custom.tpl', $templateName); $hasCustomTemplate = file_exists($localizedPath . '/' . $customTemplateName); - + if ($enforceCustomTemplate && !$hasCustomTemplate) { $defaultLanguageCode = Configuration::Instance()->GetKey(ConfigKeys::LANGUAGE); $defaultLocalizedPath = $langPath . $defaultLanguageCode; @@ -120,55 +115,125 @@ public function FetchLocalized($templateName, bool $enforceCustomTemplate, strin return $this->fetch($templateName); } + protected function RegisterClasses() + { + // Classes that should be registered + $classesToRegister = [ + 'Actions', + 'AutoCompleteType', + 'CalendarActions', + 'CalendarTypes', + 'CannedReport', + 'ColumnNames', + 'ConfigActions', + 'ConfigKeys', + 'ConfigSettingType', + 'CookieKeys', + 'CustomAttributeCategory', + 'CustomAttributeTypes', + 'Date', + 'DayOfWeek', + 'EmailTemplatesActions', + 'FormKeys', + 'InvitationAction', + 'ManageAccessoriesActions', + 'ManageAnnouncementsActions', + 'ManageAttributesActions', + 'ManageBlackoutsActions', + 'ManageGroupsActions', + 'ManageQuotasActions', + 'ManageReservationsActions', + 'ManageResourcesActions', + 'ManageSchedules', + 'ManageUsersActions', + 'Pages', + 'ProfileActions', + 'QueryStringKeys', + 'QuotaDuration', + 'QuotaScope', + 'QuotaUnit', + 'RepeatMonthlyType', + 'ReportActions', + 'Report_GroupBy', + 'Report_Range', + 'Report_ResultSelection', + 'Report_Usage', + 'ReservationAction', + 'ReservationConflictResolution', + 'ReservationEvent', + 'ReservationStatus', + 'ResourceStatus', + 'Schedule', + 'ScheduleLayout', + 'ScheduleStyle', + 'SeriesUpdateScope', + 'TermsOfService', + + ]; + + foreach ($classesToRegister as $className) { + try { + if (class_exists($className)) { + $this->registerClass($className, $className); + } + } catch (Exception $ex) { + error_log("Error registering $className : " . $ex->getMessage()); + } + } + } + protected function RegisterFunctions() { - $this->registerPlugin('function', 'translate', [$this, 'SmartyTranslate']); - $this->registerPlugin('function', 'formatdate', [$this, 'FormatDate']); - $this->registerPlugin('function', 'format_date', [$this, 'FormatDate']); - $this->registerPlugin('function', 'html_link', [$this, 'PrintLink']); - $this->registerPlugin('function', 'html_image', [$this, 'PrintImage']); - $this->registerPlugin('function', 'control', [$this, 'DisplayControl']); - $this->registerPlugin('function', 'validator', [$this, 'Validator']); - $this->registerPlugin('function', 'textbox', [$this, 'Textbox']); - $this->registerPlugin('function', 'object_html_options', [$this, 'ObjectHtmlOptions']); - $this->registerPlugin('block', 'validation_group', [$this, 'ValidationGroup']); - $this->registerPlugin('function', 'setfocus', [$this, 'SetFocus']); - $this->registerPlugin('function', 'formname', [$this, 'GetFormName']); - $this->registerPlugin('modifier', 'url2link', [$this, 'CreateUrl']); - $this->registerPlugin('function', 'pagelink', [$this, 'CreatePageLink']); - $this->registerPlugin('function', 'pagination', [$this, 'CreatePagination']); - $this->registerPlugin('function', 'js_array', [$this, 'CreateJavascriptArray']); - $this->registerPlugin('function', 'async_validator', [$this, 'AsyncValidator']); - $this->registerPlugin('function', 'fullname', [$this, 'DisplayFullName']); - $this->registerPlugin('function', 'add_querystring', [$this, 'AddQueryString']); - $this->registerPlugin('function', 'resource_image', [$this, 'GetResourceImage']); - $this->registerPlugin('modifier', 'escapequotes', [$this, 'EscapeQuotes']); - $this->registerPlugin('function', 'flush', [$this, 'Flush']); - $this->registerPlugin('function', 'jsfile', [$this, 'IncludeJavascriptFile']); - $this->registerPlugin('function', 'cssfile', [$this, 'IncludeCssFile']); - $this->registerPlugin('function', 'indicator', [$this, 'DisplayIndicator']); - $this->registerPlugin('function', 'read_only_attribute', [$this, 'ReadOnlyAttribute']); - $this->registerPlugin('function', 'csrf_token', [$this, 'CSRFToken']); - $this->registerPlugin('function', 'cancel_button', [$this, 'CancelButton']); - $this->registerPlugin('function', 'update_button', [$this, 'UpdateButton']); - $this->registerPlugin('function', 'add_button', [$this, 'AddButton']); - $this->registerPlugin('function', 'delete_button', [$this, 'DeleteButton']); - $this->registerPlugin('function', 'reset_button', [$this, 'ResetButton']); - $this->registerPlugin('function', 'filter_button', [$this, 'FilterButton']); - $this->registerPlugin('function', 'ok_button', [$this, 'OkButton']); - $this->registerPlugin('function', 'showhide_icon', [$this, 'ShowHideIcon']); - $this->registerPlugin('function', 'sort_column', [$this, 'SortColumn']); - $this->registerPlugin('function', 'formatcurrency', [$this, 'FormatCurrency']); - $this->registerPlugin('function', 'linebreak', [$this, 'LineBreak']); - $this->registerPlugin('modifier', 'urlencode', [$this, 'UrlEncode']); - $this->registerPlugin('modifier', 'explode', [$this, 'Explode']); - $this->registerPlugin('modifier', 'html_entity_decode', [$this, 'HtmlEntityDecode']); - $this->registerPlugin('modifier', 'implode', [$this, 'Implode']); - $this->registerPlugin('modifier', 'join', [$this, 'Join']); - $this->registerPlugin('modifier', 'intval', [$this, 'Intval']); - $this->registerPlugin('modifier', 'strtolower', [$this, 'Strtolower']); - $this->registerPlugin('function', 'datatable', [$this, 'CreateDataTable']); - $this->registerPlugin('function', 'datatablefilter', [$this, 'CreateDataTableFilter']); + $this->registerPlugin('function', 'translate', $this->SmartyTranslate(...)); + $this->registerPlugin('function', 'formatdate', $this->FormatDate(...)); + $this->registerPlugin('function', 'format_date', $this->FormatDate(...)); + $this->registerPlugin('function', 'html_link', $this->PrintLink(...)); + $this->registerPlugin('function', 'html_image', $this->PrintImage(...)); + $this->registerPlugin('function', 'control', $this->DisplayControl(...)); + $this->registerPlugin('function', 'validator', $this->Validator(...)); + $this->registerPlugin('function', 'textbox', $this->Textbox(...)); + $this->registerPlugin('function', 'object_html_options', $this->ObjectHtmlOptions(...)); + $this->registerPlugin('block', 'validation_group', $this->ValidationGroup(...)); + $this->registerPlugin('function', 'setfocus', $this->SetFocus(...)); + $this->registerPlugin('function', 'formname', $this->GetFormName(...)); + $this->registerPlugin('modifier', 'url2link', $this->CreateUrl(...)); + $this->registerPlugin('function', 'pagelink', $this->CreatePageLink(...)); + $this->registerPlugin('function', 'pagination', $this->CreatePagination(...)); + $this->registerPlugin('function', 'js_array', $this->CreateJavascriptArray(...)); + $this->registerPlugin('function', 'async_validator', $this->AsyncValidator(...)); + $this->registerPlugin('function', 'fullname', $this->DisplayFullName(...)); + $this->registerPlugin('function', 'add_querystring', $this->AddQueryString(...)); + $this->registerPlugin('function', 'resource_image', $this->GetResourceImage(...)); + $this->registerPlugin('modifier', 'escapequotes', $this->EscapeQuotes(...)); + $this->registerPlugin('function', 'flush', $this->Flush(...)); + $this->registerPlugin('function', 'jsfile', $this->IncludeJavascriptFile(...)); + $this->registerPlugin('function', 'cssfile', $this->IncludeCssFile(...)); + $this->registerPlugin('function', 'indicator', $this->DisplayIndicator(...)); + $this->registerPlugin('function', 'read_only_attribute', $this->ReadOnlyAttribute(...)); + $this->registerPlugin('function', 'csrf_token', $this->CSRFToken(...)); + $this->registerPlugin('function', 'cancel_button', $this->CancelButton(...)); + $this->registerPlugin('function', 'update_button', $this->UpdateButton(...)); + $this->registerPlugin('function', 'add_button', $this->AddButton(...)); + $this->registerPlugin('function', 'delete_button', $this->DeleteButton(...)); + $this->registerPlugin('function', 'reset_button', $this->ResetButton(...)); + $this->registerPlugin('function', 'filter_button', $this->FilterButton(...)); + $this->registerPlugin('function', 'ok_button', $this->OkButton(...)); + $this->registerPlugin('function', 'showhide_icon', $this->ShowHideIcon(...)); + $this->registerPlugin('function', 'sort_column', $this->SortColumn(...)); + $this->registerPlugin('function', 'formatcurrency', $this->FormatCurrency(...)); + $this->registerPlugin('function', 'linebreak', $this->LineBreak(...)); + $this->registerPlugin('modifier', 'urlencode', $this->UrlEncode(...)); + $this->registerPlugin('modifier', 'explode', $this->Explode(...)); + $this->registerPlugin('modifier', 'html_entity_decode', $this->HtmlEntityDecode(...)); + $this->registerPlugin('modifier', 'implode', $this->Implode(...)); + $this->registerPlugin('modifier', 'join', $this->Join(...)); + $this->registerPlugin('modifier', 'intval', $this->Intval(...)); + $this->registerPlugin('modifier', 'strtolower', $this->Strtolower(...)); + $this->registerPlugin('function', 'datatable', $this->CreateDataTable(...)); + $this->registerPlugin('function', 'datatablefilter', $this->CreateDataTableFilter(...)); + $this->registerPlugin('modifier', 'microtime', $this->Microtime(...)); + $this->registerPlugin('modifier', 'array_key_exists', $this->ArrayKeyExists(...)); + $this->registerPlugin('modifier', 'count', $this->Count(...)); /** * PageValidators @@ -271,7 +336,7 @@ public function FormatDate($params, $smarty) $formatted = $date->Format($format); - if (strpos($format, 'l') !== false) { + if (str_contains((string) $format, 'l')) { // correct english day name to translated day name $english_days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; $days = $this->Resources->GetDays('full'); @@ -282,10 +347,10 @@ public function FormatDate($params, $smarty) public function PrintImage($params, $smarty) { - $alt = isset($params['alt']) ? $params['alt'] : ''; - $altKey = isset($params['altKey']) ? $params['altKey'] : ''; - $width = isset($params['width']) ? $params['width'] : ''; - $height = isset($params['height']) ? $params['height'] : ''; + $alt = $params['alt'] ?? ''; + $altKey = $params['altKey'] ?? ''; + $width = $params['width'] ?? ''; + $height = $params['height'] ?? ''; $imgPath = sprintf('%simg/%s', $this->RootPath, $params['src']); $knownAttributes = ['alt', 'width', 'height', 'src', 'title', 'altKey']; @@ -324,7 +389,7 @@ public function ValidationGroup($params, $content, $smarty, &$repeat) } if (!$repeat) { - $actualContent = trim($content); + $actualContent = trim((string) $content); return empty($actualContent) ? '' : '