From 532d5964d91cde555f741620d524547247bf82bb Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 1 Dec 2020 18:21:18 +0100 Subject: [PATCH 1/6] call filter function before notification can be used to filter out certain notifications --- inc/inc.Authentication.php | 2 +- inc/inc.ClassNotificationService.php | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/inc/inc.Authentication.php b/inc/inc.Authentication.php index 36fb1dd6a..c5d3f066c 100644 --- a/inc/inc.Authentication.php +++ b/inc/inc.Authentication.php @@ -102,7 +102,7 @@ if(isset($GLOBALS['SEEDDMS_HOOKS']['notification'])) { } if($settings->_enableEmail) { - $notifier->addService(new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword)); + $notifier->addService(new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword), 'email'); } if(isset($GLOBALS['SEEDDMS_HOOKS']['notification'])) { diff --git a/inc/inc.ClassNotificationService.php b/inc/inc.ClassNotificationService.php index c44c4018d..bb1ff71c2 100644 --- a/inc/inc.ClassNotificationService.php +++ b/inc/inc.ClassNotificationService.php @@ -30,25 +30,35 @@ class SeedDMS_NotificationService { $this->services = array(); } - public function addService($service) { - $this->services[] = $service; + public function addService($service, $name='') { + $this->services[$name ? $name : md5(uniqid())] = $service; + } + + public function getServices() { + return $this->services; } public function toIndividual($sender, $recipient, $subject, $message, $params=array()) { - foreach($this->services as $service) { - return $service->toIndividual($sender, $recipient, $subject, $message, $params); + foreach($this->services as $name => $service) { + if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipient, $subject, $message, $params)) { + return $service->toIndividual($sender, $recipient, $subject, $message, $params); + } } } public function toGroup($sender, $groupRecipient, $subject, $message, $params=array()) { - foreach($this->services as $service) { - return $service->toGroup($sender, $groupRecipient, $subject, $message, $params); + foreach($this->services as $name => $service) { + if(!is_callable([$service, 'filter']) || $service->filter($sender, $groupRecipient, $subject, $message, $params)) { + return $service->toGroup($sender, $groupRecipient, $subject, $message, $params); + } } } public function toList($sender, $recipients, $subject, $message, $params=array()) { - foreach($this->services as $service) { - return $service->toList($sender, $recipients, $subject, $message, $params); + foreach($this->services as $name => $service) { + if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipients, $subject, $message, $params)) { + return $service->toList($sender, $recipients, $subject, $message, $params); + } } } From 0124f6cc743a32e829af6db7e7005155022511e2 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 1 Dec 2020 18:23:48 +0100 Subject: [PATCH 2/6] use require_once instead of include --- op/op.Ajax.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/op/op.Ajax.php b/op/op.Ajax.php index 6c965d60b..d27678ce5 100644 --- a/op/op.Ajax.php +++ b/op/op.Ajax.php @@ -16,21 +16,21 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -include("../inc/inc.Settings.php"); -include("../inc/inc.LogInit.php"); -include("../inc/inc.Utils.php"); -include("../inc/inc.Language.php"); -include("../inc/inc.Init.php"); -include("../inc/inc.Extension.php"); -include("../inc/inc.DBInit.php"); -include("../inc/inc.ClassNotificationService.php"); -include("../inc/inc.ClassEmailNotify.php"); -include("../inc/inc.ClassUI.php"); -include("../inc/inc.ClassController.php"); +require_once("../inc/inc.Settings.php"); +require_once("../inc/inc.LogInit.php"); +require_once("../inc/inc.Utils.php"); +require_once("../inc/inc.Language.php"); +require_once("../inc/inc.Init.php"); +require_once("../inc/inc.Extension.php"); +require_once("../inc/inc.DBInit.php"); +require_once("../inc/inc.ClassNotificationService.php"); +require_once("../inc/inc.ClassEmailNotify.php"); +require_once("../inc/inc.ClassUI.php"); +require_once("../inc/inc.ClassController.php"); require_once("../inc/inc.ClassSession.php"); -include("../inc/inc.ClassPasswordStrength.php"); -include("../inc/inc.ClassPasswordHistoryManager.php"); +require_once("../inc/inc.ClassPasswordStrength.php"); +require_once("../inc/inc.ClassPasswordHistoryManager.php"); /* Load session */ if (isset($_COOKIE["mydms_session"])) { From 132c643433345ef709e50b74c016ae85c977c9cf Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 1 Dec 2020 18:24:29 +0100 Subject: [PATCH 3/6] user getReadableDate() instead of date() --- views/bootstrap/class.Bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/bootstrap/class.Bootstrap.php b/views/bootstrap/class.Bootstrap.php index 07a9cc4d9..caf807779 100644 --- a/views/bootstrap/class.Bootstrap.php +++ b/views/bootstrap/class.Bootstrap.php @@ -2650,7 +2650,7 @@ $('body').on('click', '[id^=\"table-row-folder\"] td:nth-child(2)', function(ev) $content .= "" . htmlspecialchars($document->getName()) . ""; if(isset($extracontent['below_title'])) $content .= $extracontent['below_title']; - $content .= "
".getMLText('owner').": ".htmlspecialchars($owner->getFullName()).", ".getMLText('creation_date').": ".date('Y-m-d', $document->getDate()).", ".getMLText('version')." ".$version." - ".date('Y-m-d', $latestContent->getDate())."".($document->expires() ? ", ".getMLText('expires').": ".getReadableDate($document->getExpires())."" : "").""; + $content .= "
".getMLText('owner').": ".htmlspecialchars($owner->getFullName()).", ".getMLText('creation_date').": ".getReadableDate($document->getDate()).", ".getMLText('version')." ".$version." - ".getReadableDate($latestContent->getDate())."".($document->expires() ? ", ".getMLText('expires').": ".getReadableDate($document->getExpires())."" : "").""; if($comment) { $content .= "
".htmlspecialchars($comment).""; } From f482c42db389d945b9224e781ad8014bb9b030b9 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 1 Dec 2020 18:24:55 +0100 Subject: [PATCH 4/6] pass 'asc' as order dir to hook searchHeaderList --- views/bootstrap/class.Search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/bootstrap/class.Search.php b/views/bootstrap/class.Search.php index b88d8a1dd..5ac7a1810 100644 --- a/views/bootstrap/class.Search.php +++ b/views/bootstrap/class.Search.php @@ -535,7 +535,7 @@ foreach($facets as $facetname=>$values) { $this->pageList($pageNumber, $totalpages, "../out/out.Search.php", $urlparams); // $this->contentContainerStart(); - $txt = $this->callHook('searchListHeader', $orderby, $orderdir); + $txt = $this->callHook('searchListHeader', $orderby, 'asc'); if(is_string($txt)) echo $txt; else { From 6bb4218e44961ff29d8400d0e7da05d476452d8c Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 1 Dec 2020 18:25:22 +0100 Subject: [PATCH 5/6] initial support customizable date format --- inc/inc.ClassSettings.php | 8 ++++++++ inc/inc.Utils.php | 12 ++++++++++-- op/op.Settings.php | 2 ++ views/bootstrap/class.Settings.php | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/inc/inc.ClassSettings.php b/inc/inc.ClassSettings.php index 3f302c050..3b14e6889 100644 --- a/inc/inc.ClassSettings.php +++ b/inc/inc.ClassSettings.php @@ -132,6 +132,10 @@ class Settings { /* {{{ */ var $_availablelanguages = array(); // default language (name of a subfolder in folder "languages") var $_language = "en_GB"; + // default date format + var $_dateformat = "Y-m-d"; + // default date/time format + var $_datetimformat = "Y-m-d H:i:s"; // users are notified about document-changes that took place within the last $_updateNotifyTime seconds var $_updateNotifyTime = 86400; // files with one of the following endings can be viewed online @@ -453,6 +457,8 @@ class Settings { /* {{{ */ $this->_footNote = strval($tab["footNote"]); $this->_printDisclaimer = Settings::boolVal($tab["printDisclaimer"]); $this->_language = strval($tab["language"]); + $this->_dateformat = strval($tab["dateformat"]); + $this->_datetimeformat = strval($tab["datetimeformat"]); if(trim(strval($tab["availablelanguages"]))) $this->_availablelanguages = explode(',',strval($tab["availablelanguages"])); $this->_theme = strval($tab["theme"]); @@ -826,6 +832,8 @@ class Settings { /* {{{ */ $this->setXMLAttributValue($node, "footNote", $this->_footNote); $this->setXMLAttributValue($node, "printDisclaimer", $this->_printDisclaimer); $this->setXMLAttributValue($node, "language", $this->_language); + $this->setXMLAttributValue($node, "dateformat", $this->_dateformat); + $this->setXMLAttributValue($node, "datetimeformat", $this->_datetimeformat); $this->setXMLAttributValue($node, "availablelanguages", implode(',', $this->_availablelanguages)); $this->setXMLAttributValue($node, "theme", $this->_theme); $this->setXMLAttributValue($node, "overrideTheme", $this->_overrideTheme); diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 750d9226c..73a1c33a0 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -27,11 +27,19 @@ function formatted_size($size_bytes) { /* {{{ */ } /* }}} */ function getReadableDate($timestamp) { /* {{{ */ - return date("Y-m-d", $timestamp); + global $settings; + if($settings->_dateformat) + return date($settings->_dateformat, $timestamp); + else + return date("Y-m-d", $timestamp); } /* }}} */ function getLongReadableDate($timestamp) { /* {{{ */ - return date("Y-m-d H:i:s", $timestamp); + global $settings; + if($settings->_datetimeformat) + return date($settings->_datetimeformat, $timestamp); + else + return date("Y-m-d H:i:s", $timestamp); } /* }}} */ /* diff --git a/op/op.Settings.php b/op/op.Settings.php index 908e4ef75..5a45bef32 100644 --- a/op/op.Settings.php +++ b/op/op.Settings.php @@ -59,6 +59,8 @@ if ($action == "saveSettings") $settings->_footNote = $_POST["footNote"]; $settings->_printDisclaimer = getBoolValue("printDisclaimer"); $settings->_language = $_POST["language"]; + $settings->_dateformat = $_POST["dateformat"]; + $settings->_datetimeformat = $_POST["datetimeformat"]; if(empty($_POST["availablelanguages"])) $settings->_availablelanguages = array(); else diff --git a/views/bootstrap/class.Settings.php b/views/bootstrap/class.Settings.php index c30bbaf3e..5733c6302 100644 --- a/views/bootstrap/class.Settings.php +++ b/views/bootstrap/class.Settings.php @@ -284,6 +284,8 @@ $this->showStartPaneContent('site', (!$currenttab || $currenttab == 'site')); showConfigCheckbox('settings_printDisclaimer', 'printDisclaimer'); ?> showConfigOption('settings_available_languages', 'availablelanguages', getAvailableLanguages(), true, true); ?> showConfigOption('settings_language', 'language', getAvailableLanguages(), false, true); ?> +showConfigText('settings_dateformat', 'dateformat'); ?> +showConfigText('settings_datetimeformat', 'datetimeformat'); ?> showConfigOption('settings_theme', 'theme', UI::getStyles(), false, false); ?> showConfigCheckbox('settings_overrideTheme', 'overrideTheme'); ?> showConfigCheckbox('settings_onePageMode', 'onePageMode'); ?> From 363ce485e36c76aea281885bdc2b509aec714232 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 1 Dec 2020 18:33:30 +0100 Subject: [PATCH 6/6] get[Long]ReadableDate() takes argument as 'yyyy-mm-dd hh:ii:ss' --- inc/inc.Utils.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 73a1c33a0..cbda98f98 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -28,6 +28,8 @@ function formatted_size($size_bytes) { /* {{{ */ function getReadableDate($timestamp) { /* {{{ */ global $settings; + if(!is_numeric($timestamp)) + $timestamp = strtotime($timestamp); if($settings->_dateformat) return date($settings->_dateformat, $timestamp); else @@ -36,6 +38,8 @@ function getReadableDate($timestamp) { /* {{{ */ function getLongReadableDate($timestamp) { /* {{{ */ global $settings; + if(!is_numeric($timestamp)) + $timestamp = strtotime($timestamp); if($settings->_datetimeformat) return date($settings->_datetimeformat, $timestamp); else