diff --git a/inc/inc.ClassEmailNotify.php b/inc/inc.ClassEmailNotify.php index 514d6694c..fbd9c2ad9 100644 --- a/inc/inc.ClassEmailNotify.php +++ b/inc/inc.ClassEmailNotify.php @@ -36,6 +36,8 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify { */ protected $_dms; + protected $_translator; + protected $smtp_server; protected $smtp_port; @@ -52,8 +54,9 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify { protected $debug; - function __construct($dms, $from_address='', $smtp_server='', $smtp_port='', $smtp_username='', $smtp_password='', $lazy_ssl=true, $force_from=false) { /* {{{ */ + function __construct($dms, $translator, $from_address='', $smtp_server='', $smtp_port='', $smtp_username='', $smtp_password='', $lazy_ssl=true, $force_from=false) { /* {{{ */ $this->_dms = $dms; + $this->_translator = $translator; $this->smtp_server = $smtp_server; $this->smtp_port = $smtp_port; $this->smtp_user = $smtp_username; @@ -125,38 +128,38 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify { $body = ''; if(!isset($params['__skip_header__']) || !$params['__skip_header__']) { if(!isset($params['__header__'])) - $body .= getMLText("email_header", $params, null, $lang)."\r\n\r\n"; + $body .= $this->_translator->translate("email_header", $params, null, $lang)."\r\n\r\n"; elseif($params['__header__']) - $body .= getMLText($params['__header__'], $params, null, $lang)."\r\n\r\n"; + $body .= $this->_translator->translate($params['__header__'], $params, null, $lang)."\r\n\r\n"; } if(isset($params['__body__'])) $body .= $params['__body__']; else - $body .= getMLText($messagekey, $params, null, $lang); + $body .= $this->_translator->translate($messagekey, $params, null, $lang); if(!isset($params['__skip_footer__']) || !$params['__skip_footer__']) { if(!isset($params['__footer__'])) - $body .= "\r\n\r\n".getMLText("email_footer", $params, null, $lang); + $body .= "\r\n\r\n".$this->_translator->translate("email_footer", $params, null, $lang); elseif($params['__footer__']) - $body .= "\r\n\r\n".getMLText($params['__footer__'], $params, null, $lang); + $body .= "\r\n\r\n".$this->_translator->translate($params['__footer__'], $params, null, $lang); } $bodyhtml = ''; - if(isset($params['__body_html__']) || getMLText($messagekey.'_html', $params, null, $lang)) { + if(isset($params['__body_html__']) || $this->_translator->translate($messagekey.'_html', $params, null, $lang)) { if(!isset($params['__skip_header__']) || !$params['__skip_header__']) { if(!isset($params['__header_html__'])) - $bodyhtml .= getMLText("email_header_html", $params, null, $lang)."\r\n\r\n"; + $bodyhtml .= $this->_translator->translate("email_header_html", $params, null, $lang)."\r\n\r\n"; elseif($params['__header_html__']) - $bodyhtml .= getMLText($params['__header_html__'], $params, null, $lang)."\r\n\r\n"; + $bodyhtml .= $this->_translator->translate($params['__header_html__'], $params, null, $lang)."\r\n\r\n"; } if(isset($params['__body_html__'])) $bodyhtml .= $params['__body_html__']; else - $bodyhtml .= getMLText($messagekey.'_html', $params, null, $lang); + $bodyhtml .= $this->_translator->translate($messagekey.'_html', $params, null, $lang); if(!isset($params['__skip_footer__']) || !$params['__skip_footer__']) { if(!isset($params['__footer_html__'])) - $bodyhtml .= "\r\n\r\n".getMLText("email_footer_html", $params, null, $lang); + $bodyhtml .= "\r\n\r\n".$this->_translator->translate("email_footer_html", $params, null, $lang); elseif($params['__footer_html__']) - $bodyhtml .= "\r\n\r\n".getMLText($params['__footer_html__'], $params, null, $lang); + $bodyhtml .= "\r\n\r\n".$this->_translator->translate($params['__footer_html__'], $params, null, $lang); } } @@ -206,7 +209,7 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify { $headers['Return-Path'] = $returnpath; $headers['To'] = $to; $preferences = array("input-charset" => "UTF-8", "output-charset" => "UTF-8", "scheme"=>"Q"); - $encoded_subject = iconv_mime_encode("Subject", getMLText($subject, $params, null, $lang), $preferences); + $encoded_subject = iconv_mime_encode("Subject", $this->_translator->translate($subject, $params, null, $lang), $preferences); $headers['Subject'] = substr($encoded_subject, strlen('Subject: ')); $headers['Date'] = date('r', time()); $headers['MIME-Version'] = "1.0"; @@ -239,7 +242,7 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify { if (isset($GLOBALS['SEEDDMS_HOOKS']['mailqueue'])) { foreach($GLOBALS['SEEDDMS_HOOKS']['mailqueue'] as $queueService) { if(method_exists($queueService, 'queueMailJob')) { - $ret = $queueService->queueMailJob($mail_params, $to, $hdrs, getMLText($subject, $params, null, $lang), $message); + $ret = $queueService->queueMailJob($mail_params, $to, $hdrs, $this->_translator->translate($subject, $params, null, $lang), $message); if($ret !== null) return $ret; } diff --git a/inc/inc.ClassNotificationService.php b/inc/inc.ClassNotificationService.php index ce50677a0..c106857e9 100644 --- a/inc/inc.ClassNotificationService.php +++ b/inc/inc.ClassNotificationService.php @@ -41,6 +41,11 @@ class SeedDMS_NotificationService { */ protected $settings; + /* + * Translator + */ + protected $translator; + /* * Possible types of receivers */ @@ -54,11 +59,12 @@ class SeedDMS_NotificationService { const RECV_REVISOR = 7; const RECV_RECIPIENT = 8; - public function __construct($logger = null, $settings = null) { /* {{{ */ + public function __construct($logger = null, $settings = null, $translator=null) { /* {{{ */ $this->services = array(); $this->errors = array(); $this->logger = $logger; $this->settings = $settings; + $this->translator = $translator; } /* }}} */ public function addService($service, $name='') { /* {{{ */ @@ -68,6 +74,10 @@ class SeedDMS_NotificationService { $this->errors[$name] = true; } /* }}} */ + public function getTranslator() { /* {{{ */ + return $this->translator; + } /* }}} */ + public function getServices() { /* {{{ */ return $this->services; } /* }}} */ diff --git a/inc/inc.ClassSettings.php b/inc/inc.ClassSettings.php index 924246ca9..2b84527b7 100644 --- a/inc/inc.ClassSettings.php +++ b/inc/inc.ClassSettings.php @@ -460,7 +460,10 @@ class Settings { /* {{{ */ // Load config file if (!defined("SEEDDMS_INSTALL")) { if(!file_exists($configFilePath)) { - echo "You do not seem to have a valid configuration. Run the install tool first."; + if(php_sapi_name() === 'cli') + echo "You do not seem to have a valid configuration. Set SEEDDMS_CONFIG_FILE to the path of the configuration file.\n"; + else + echo "You do not seem to have a valid configuration. Run the install tool first."; exit; } } @@ -470,17 +473,14 @@ class Settings { /* {{{ */ echo "Your configuration contains errors."; exit; } - -// if (!is_null($this->_maxExecutionTime)) -// ini_set("max_execution_time", $this->_maxExecutionTime); } /* }}} */ /** - * Check if a variable has the string 'true', 'on', 'yes' or 'y' - * and returns true. + * Check if the passed parameter equals to 'true', 'on', 'yes' or 'y' + * and returns true, if it does. * * @param string $var value - * @return true/false + * @return boolean true if $var is 'true', 'on', 'yes' or 'y', otherwise false */ protected static function boolVal($var) { /* {{{ */ $var = strtolower(strval($var)); @@ -510,10 +510,10 @@ class Settings { /* {{{ */ } /* }}} */ /** - * Return ';' seperated string from array + * Create ';' seperated string from array * * @param array $value - * + * @return string */ function arrayToString($value) { /* {{{ */ return implode(";", $value); @@ -523,14 +523,14 @@ class Settings { /* {{{ */ * Return array from ';' seperated string * * @param string $value - * + * @return array */ function stringToArray($value) { /* {{{ */ return explode(";", $value); } /* }}} */ /** - * set $_viewOnlineFileTypes + * Set $_viewOnlineFileTypes * * @param string $stringValue string value * @@ -540,7 +540,7 @@ class Settings { /* {{{ */ } /* }}} */ /** - * get $_viewOnlineFileTypes in a string value + * Get $_viewOnlineFileTypes in a string value * * @return string value * @@ -550,7 +550,7 @@ class Settings { /* {{{ */ } /* }}} */ /** - * set $_editOnlineFileTypes + * Set $_editOnlineFileTypes * * @param string $stringValue string value * @@ -560,7 +560,7 @@ class Settings { /* {{{ */ } /* }}} */ /** - * get $_editOnlineFileTypes in a string value + * Get $_editOnlineFileTypes in a string value * * @return string value * @@ -573,8 +573,7 @@ class Settings { /* {{{ */ * Load config file * * @param string $configFilePath config file path - * - * @return true/false + * @return boolean true, if loading was successful, otherwise false */ public function load($configFilePath) { /* {{{ */ $contents = file_get_contents($configFilePath); @@ -1397,7 +1396,7 @@ class Settings { /* {{{ */ // Save return $xml->asXML($configFilePath); - } /* }}} */ + } /* }}} */ /** * search and return Config File Path @@ -1948,5 +1947,33 @@ class Settings { /* {{{ */ return $this->getBaseUrl().$this->_httpRoot; } /* }}} */ + public function getAvailableLanguages() { /* {{{ */ + $languages = array(); + + $path = $this->_rootDir . "languages/"; + $handle = opendir($path); + + while ($entry = readdir($handle) ) + { + if ($entry == ".." || $entry == ".") { + continue; + } elseif (is_dir($path . $entry)) { + array_push($languages, $entry); + } + } + closedir($handle); + + asort($languages); + return $languages; + } /* }}} */ + + function getLanguages() { /* {{{ */ + if($this->_availablelanguages) { + return $this->_availablelanguages; + } + + return getAvailableLanguages(); + } /* }}} */ + } /* }}} */ diff --git a/inc/inc.ClassTranslator.php b/inc/inc.ClassTranslator.php index aa05d8fef..ef2e5577e 100644 --- a/inc/inc.ClassTranslator.php +++ b/inc/inc.ClassTranslator.php @@ -13,6 +13,8 @@ namespace Seeddms\Seeddms; +use SeedDMS_Core_AttributeDefinition; + /** * Class for translation and language handling * @@ -50,7 +52,7 @@ class Translator { /* {{{ */ } /* }}} */ public function init() { /* {{{ */ - $__languages = $this->getLanguages(); + $__languages = $this->settings->getLanguages(); if(!in_array($this->settings->_language, $__languages)) $__languages[] = $this->settings->_language; foreach($__languages as $_lang) { @@ -68,34 +70,6 @@ class Translator { /* {{{ */ $this->lang[$lang] = $data; } /* }}} */ - function getAvailableLanguages() { /* {{{ */ - $languages = array(); - - $path = $this->settings->_rootDir . "languages/"; - $handle = opendir($path); - - while ($entry = readdir($handle) ) - { - if ($entry == ".." || $entry == ".") { - continue; - } elseif (is_dir($path . $entry)) { - array_push($languages, $entry); - } - } - closedir($handle); - - asort($languages); - return $languages; - } /* }}} */ - - function getLanguages() { /* {{{ */ - if($this->settings->_availablelanguages) { - return $this->settings->_availablelanguages; - } - - return getAvailableLanguages(); - } /* }}} */ - /** * Get translation * diff --git a/inc/inc.Language.php b/inc/inc.Language.php index 7b479aecd..c9f3e609e 100644 --- a/inc/inc.Language.php +++ b/inc/inc.Language.php @@ -24,13 +24,21 @@ $translator = new Translator($settings); $translator->init(); function getAvailableLanguages() { /* {{{ */ - error_log('getAvailableLanguages() is deprecated'); + trigger_error("getAvailableLanguages() is deprecated.", E_USER_DEPRECATED); + foreach(debug_backtrace() as $n) { + trigger_error($n['file'].": Line ".$n['line'], E_USER_DEPRECATED); + } - return $GLOBALS['translator']->getAvailableLanguages(); + return $GLOBALS['settings']->getAvailableLanguages(); } /* }}} */ function getLanguages() { /* {{{ */ - return $GLOBALS['translator']->getLanguages(); + trigger_error("getLanguages() is deprecated.", E_USER_DEPRECATED); + foreach(debug_backtrace() as $n) { + trigger_error($n['file'].": Line ".$n['line'], E_USER_DEPRECATED); + } + + return $GLOBALS['settings']->getLanguages(); } /* }}} */ /** @@ -48,10 +56,10 @@ function getLanguages() { /* {{{ */ * @param string $lang use this language instead of the currently set lang */ function getMLText($key, $replace = array(), $defaulttext = null, $lang="") { /* {{{ */ - trigger_error("getMLText() is deprecated.", E_USER_DEPRECATED); - foreach(debug_backtrace() as $n) { - trigger_error($n['file'].": Line ".$n['line'], E_USER_DEPRECATED); - } +// trigger_error("getMLText() is deprecated.", E_USER_DEPRECATED); +// foreach(debug_backtrace() as $n) { +// trigger_error($n['file'].": Line ".$n['line'], E_USER_DEPRECATED); +// } return $GLOBALS['translator']->translate($key, $replace, $defaulttext, $lang); } /* }}} */ diff --git a/inc/inc.Notification.php b/inc/inc.Notification.php index 86eab8cbe..400740d9b 100644 --- a/inc/inc.Notification.php +++ b/inc/inc.Notification.php @@ -12,7 +12,7 @@ * @version Release: @package_version@ */ -$notifier = new SeedDMS_NotificationService($logger, $settings); +$notifier = new SeedDMS_NotificationService($logger, $settings, $translator); if(isset($GLOBALS['SEEDDMS_HOOKS']['notification'])) { foreach($GLOBALS['SEEDDMS_HOOKS']['notification'] as $notificationObj) { @@ -23,7 +23,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, $settings->_smtpLazySSL, $settings->_smtpForceFrom), 'email'); + $notifier->addService(new SeedDMS_EmailNotify($dms, $translator, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword, $settings->_smtpLazySSL, $settings->_smtpForceFrom), 'email'); } if(isset($GLOBALS['SEEDDMS_HOOKS']['notification'])) { diff --git a/op/op.Ajax.php b/op/op.Ajax.php index a9de9e871..efcb954d0 100644 --- a/op/op.Ajax.php +++ b/op/op.Ajax.php @@ -297,7 +297,7 @@ switch($command) { case 'testmail': /* {{{ */ if($user && $user->isAdmin()) { if($user->getEmail()) { - $emailobj = new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword, $settings->_smtpLazySSL, $settings->_smtpForceFrom); + $emailobj = new SeedDMS_EmailNotify($dms, $translator, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword, $settings->_smtpLazySSL, $settings->_smtpForceFrom); $emailobj->setDebug(true); $params = array(); $params['url'] = getBaseUrl().$settings->_httpRoot; diff --git a/op/op.PasswordForgotten.php b/op/op.PasswordForgotten.php index c1e8e0fb9..a4c111f76 100644 --- a/op/op.PasswordForgotten.php +++ b/op/op.PasswordForgotten.php @@ -45,7 +45,7 @@ if (empty($email) || empty($login)) { $user = $dms->getUserByLogin($login, $email); if($user) { if($hash = $dms->createPasswordRequest($user)) { - $emailobj = new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword); + $emailobj = new SeedDMS_EmailNotify($dms, $translator, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword); $subject = "password_forgotten_email_subject"; $message = "password_forgotten_email_body"; $params = array(); diff --git a/out/out.ExtensionMgr.php b/out/out.ExtensionMgr.php index f31e7c4c2..ce407741e 100644 --- a/out/out.ExtensionMgr.php +++ b/out/out.ExtensionMgr.php @@ -49,7 +49,7 @@ if($view) { $view->setParam('extdir', $settings->_rootDir."/ext"); $view->setParam('version', $v); $view->setParam('accessobject', $accessop); - $view->setParam('extmgr', $extMgr); + $view->setParam('extmgr', $extmgr); $view->setParam('currenttab', $currenttab); $view->setParam('extname', $extname); $view($_GET); diff --git a/out/out.Info.php b/out/out.Info.php index 0c15a94e5..95321feda 100644 --- a/out/out.Info.php +++ b/out/out.Info.php @@ -54,14 +54,11 @@ if(@ini_get('allow_url_fopen') == '1') { } } -//$reposurl = $settings->_repositoryUrl; -//$extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir, $reposurl); - if($view) { $view->setParam('version', $v); $view->setParam('availversions', $versions); $view->setParam('accessobject', $accessop); - $view->setParam('extmgr', $extMgr); + $view->setParam('extmgr', $extmgr); $view($_GET); exit; } diff --git a/out/out.Settings.php b/out/out.Settings.php index ff9259865..14185a3b1 100644 --- a/out/out.Settings.php +++ b/out/out.Settings.php @@ -40,7 +40,7 @@ $groups = $dms->getAllGroups(); if($view) { $view->setParam('settings', $settings); - $view->setParam('extmgr', $extMgr); + $view->setParam('extmgr', $extmgr); $view->setParam('currenttab', (isset($_REQUEST['currenttab']) ? $_REQUEST['currenttab'] : '')); $view->setParam('extname', (isset($_REQUEST['extensionname']) ? $_REQUEST['extensionname'] : '')); $view->setParam('allusers', $users); diff --git a/out/out.UserImage.php b/out/out.UserImage.php index 3f0378472..dfb8f0189 100644 --- a/out/out.UserImage.php +++ b/out/out.UserImage.php @@ -22,6 +22,7 @@ if(!isset($settings)) require_once("../inc/inc.Settings.php"); require_once("inc/inc.Utils.php"); require_once("inc/inc.LogInit.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"); diff --git a/restapi/index.php b/restapi/index.php index 8aae6f415..dc369221f 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -24,6 +24,7 @@ use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\MiddlewareInterface; use DI\ContainerBuilder; use Slim\Factory\AppFactory; +use Seeddms\Seeddms\Translator; final class JsonRenderer { /* {{{ */ public function json( @@ -3119,6 +3120,7 @@ final class SeedDMS_TestController { /* {{{ */ } public function echoData($request, $response, $args) { /* {{{ */ + $translator = $this->container->get('translator'); return $this->renderer->json($response, ['success'=>true, 'message'=>'This is the result of the echo call.', 'data'=>$args['data']]); } /* }}} */ @@ -3372,6 +3374,9 @@ $container->set('logger', $logger); $container->set('fulltextservice', $fulltextservice); $container->set('notifier', $notifier); $container->set('authenticator', $authenticator); +$translator = new Translator($settings); +$translator->init(); +$container->set('translator', $translator); $app->setBasePath($settings->_httpRoot."restapi/index.php"); diff --git a/views/bootstrap/class.Bootstrap.php b/views/bootstrap/class.Bootstrap.php index 06fcb5953..c279c2cc9 100644 --- a/views/bootstrap/class.Bootstrap.php +++ b/views/bootstrap/class.Bootstrap.php @@ -458,7 +458,7 @@ background-image: linear-gradient(to bottom, #882222, #111111);; echo "