Skip to content

Commit

Permalink
Merge pull request 'hotfix: use user's timezone for watermark' from h…
Browse files Browse the repository at this point in the history
…otfix/timestamp-date into develop
  • Loading branch information
LinneyS committed Sep 18, 2024
2 parents 476fe16 + 5a4fe92 commit e7288cb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/Controller/EditorApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\QueryException;
use OCA\DAV\CalDAV\TimezoneService;
use OCP\Constants;
use OCP\Files\File;
use OCP\Files\Folder;
Expand Down Expand Up @@ -155,6 +156,13 @@ class EditorApiController extends OCSController {
*/
private $avatarManager;

/**
* Timezone service
*
* @var TimezoneService
*/
private $timezoneService;

/**
* Mobile regex from https://github.com/ONLYOFFICE/CommunityServer/blob/v9.1.1/web/studio/ASC.Web.Studio/web.appsettings.config#L35
*/
Expand All @@ -175,6 +183,7 @@ class EditorApiController extends OCSController {
* @param ISession $ISession - Session
* @param ITagManager $tagManager - Tag manager
* @param ILockManager $lockManager - Lock manager
* @param TimezoneService $timezoneService - Timezone service
*/
public function __construct(
$AppName,
Expand All @@ -190,7 +199,8 @@ public function __construct(
IManager $shareManager,
ISession $session,
ITagManager $tagManager,
ILockManager $lockManager
ILockManager $lockManager,
TimezoneService $timezoneService
) {
parent::__construct($AppName, $request);

Expand All @@ -204,6 +214,7 @@ public function __construct(
$this->crypt = $crypt;
$this->tagManager = $tagManager;
$this->lockManager = $lockManager;
$this->timezoneService = $timezoneService;

if ($this->config->getAdvanced()
&& \OC::$server->getAppManager()->isInstalled("files_sharing")) {
Expand Down Expand Up @@ -833,9 +844,10 @@ private function setWatermark($params, $isPublic, $userId, $file) {
);

if ($watermarkTemplate !== false) {
$timezone = $this->timezoneService->getUserTimezone($userId) ?? $this->timezoneService->getDefaultTimezone();
$replacements = [
"userId" => isset($userId) ? $userId : $this->trans->t('Anonymous'),
"date" => (new \DateTime())->format("Y-m-d H:i:s"),
"date" => (new \DateTime("now", new \DateTimeZone($timezone)))->format("Y-m-d H:i:s"),
"themingName" => \OC::$server->getThemingDefaults()->getName()
];
$watermarkTemplate = preg_replace_callback("/{(.+?)}/", function ($matches) use ($replacements) {
Expand Down

0 comments on commit e7288cb

Please sign in to comment.