diff --git a/config.inc.php.dist b/config.inc.php.dist
index 2a0d3ff..24dcd45 100644
--- a/config.inc.php.dist
+++ b/config.inc.php.dist
@@ -39,7 +39,7 @@ $config["nextcloud_attachment_folder_layout"] = "flat";
// (Dis)Allow user to change the layout
// true => layout is locked, i.e. not user-changeable
// false => user may change the layout on their settings page
-$config["nextcloud_attachment_folder_layout_lock"] = true;
+$config["nextcloud_attachment_folder_layout_locked"] = true;
// Limit to show a warning at for large attachments.
// has to be smaller then $config['max_message_size']
@@ -65,6 +65,27 @@ $config["nextcloud_attachment_folder_translate_name"] = false;
// see https://www.php.net/manual/en/function.hash-algos.php
$config["nextcloud_attachment_checksum"] = "sha256";
+// Generate Password protected link.
+// Passwords will be included in the message body only, not in the HTML attachment
+// Defaults to false
+$config["nextcloud_attachment_password_protected_links"] = false;
+
+// Allow/Disallow user to change the password protection option for themself
+// true => user can not change the setting
+// false => user may change the setting
+$config["nextcloud_attachment_password_protected_links_locked"] = true;
+
+// Expire share links after amount of days.
+// Links will expire on the last valid day at 11:59:59pm AoE-Time
+// Setting to "false" or negative value disables link expiry
+// Defaults to false
+$config["nextcloud_attachment_expire_links"] = false;
+
+// Allow/Disallow user to change the link expiry option for themself
+// true => user can not change the setting
+// false => user may change the setting
+$config["nextcloud_attachment_expire_links_locked"] = true;
+
// List of users to exclude
// They won't be able to interact with the plugin at all
// No prompts, no automatic uploading, no settings.
diff --git a/hooks.php b/hooks.php
index d65669c..fb4b137 100644
--- a/hooks.php
+++ b/hooks.php
@@ -44,6 +44,8 @@ public function add_preferences(array $param): array
{
$prefs = $this->rcmail->user->get_prefs();
+ self::log($prefs);
+
$server = $this->rcmail->config->get(__("server"));
$blocks = $param["blocks"];
@@ -66,11 +68,13 @@ public function add_preferences(array $param): array
$tokens[1] ?? "Y/LLLL"
);
- $layout_select = new \html_select(["id" => __("folder_layout"), "value" => $prefs[__("folder_layout")] ?? "default", "name" => "_".__("folder_layout")]);
+ $layout_select = new \html_select(["id" => __("folder_layout"), "value" => $prefs[__("user_folder_layout")] ?? "default", "name" => "_".__("folder_layout")]);
$pp_links = new \html_checkbox(["id" => __("password_protected_links"), "value" => "1", "name" => "_".__("password_protected_links")]);
$exp_links = new \html_checkbox(["id" => __("expire_links"), "value" => "1", "name" => "_".__("expire_links")]);
- $server_format_tokens = explode(":", $this->rcmail->config->get(__("folder_layout", "flat")));
+ $server_format_tokens = explode(":", $this->rcmail->config->get(__("folder_layout"), "flat"));
+
+ self::log($server_format_tokens);
$server_format = match ($server_format_tokens[0]) {
"flat" => $this->gettext("folder_layout_flat"),
@@ -123,34 +127,76 @@ function ($method, $depth) {
$this->gettext("connected_as") . " " . $username . ($can_disconnect ? " (" . $this->gettext("disconnect") . ")" : "") :
$this->gettext("not_connected") . " (" . $this->gettext("connect") . ")"
],
- "folder_layout" => [
- "title" => $this->gettext("folder_layout"),
- "content" => $layout_select->show()
- ],
- "password_protected_links" => [
- "title" => $this->gettext("password_protected_links"),
- "content" => $pp_links->show($prefs[__("password_protected_links")] ?? "0")
- ],
- "expire_links" => [
- "title" => $this->gettext("expire_links"),
- "content" => $exp_links->show($prefs[__("expire_links")] ?? "0")
- ],
- "expire_links_after" => [
- "title" => $this->gettext("expire_links_after"),
- "content" => (new \html_inputfield([
- "type" => "number",
- "min" => "1",
- "id" => __("expire_links_after"),
- "name" => "_".__("expire_links_after"),
- "value" => $prefs[__("expire_links_after")] ?? $this->rcmail->config->get(__("expire_links_after"), 7)]))->show()
- ]
+
+
]
];
+
+ if (!$this->rcmail->config->get("nextcloud_attachment_folder_layout_locked", true)) {
+ $blocks["plugin.nextcloud_attachments"]["options"]["folder_layout"] = [
+ "title" => $this->gettext("folder_layout"),
+ "content" => $layout_select->show()
+ ];
+ }
+
+ if (!$this->rcmail->config->get("nextcloud_attachment_password_protected_links_locked", true)) {
+ $def = $this->rcmail->config->get("nextcloud_attachment_password_protected_links", false) ? "1" : "0";
+ $blocks["plugin.nextcloud_attachments"]["options"]["password_protected_links"] = [
+ "title" => $this->gettext("password_protected_links"),
+ "content" => $pp_links->show($prefs[__("user_password_protected_links")] ?? $def)
+ ];
+ }
+
+ if (!$this->rcmail->config->get(__("expire_links_locked"), true)) {
+ $def = $this->rcmail->config->get(__("expire_links"), false);
+ $blocks["plugin.nextcloud_attachments"]["options"]["expire_links"] = [
+ "title" => $this->gettext("expire_links"),
+ "content" => $exp_links->show($prefs[__("user_expire_links")] ?? ($def === false ? "0" : "1"))
+ ];
+ $blocks["plugin.nextcloud_attachments"]["options"]["expire_links_after"] = [
+ "title" => $this->gettext("expire_links_after"),
+ "content" => (new \html_inputfield([
+ "type" => "number",
+ "min" => "1",
+ "id" => __("expire_links_after"),
+ "name" => "_".__("expire_links_after"),
+ "value" => $prefs[__("user_expire_links_after")] ?? ($def !== false ? $def : 7)]))->show()
+ ];
+ }
}
return ["blocks" => $blocks];
}
+ private function save_preferences(array $param) : array
+ {
+ $formats = ["default", "flat", "date:Y", "date:Y/LLLL", "date:Y/LLLL/dd", "date:Y/LL", "date:Y/LL/dd",
+ "date:Y/ww","date:Y/ww/EEEE","date:Y/ww/E", "hash:sha1:2", "hash:sha1:3", "hash:sha1:4", "hash:sha1:5"];
+ $folder_layout = $_POST["_".__("folder_layout")] ?? null;
+ if (!$this->rcmail->config->get("nextcloud_attachment_folder_layout_locked", true) &&
+ in_array($folder_layout, $formats)) {
+ $param["prefs"][__("user_folder_layout")] = $folder_layout;
+ }
+
+ $pass_prot = $_POST["_".__("password_protected_links")] ?? null;
+ if (!$this->rcmail->config->get("nextcloud_attachment_password_protected_links_locked", true) && $pass_prot == 1) {
+ $param["prefs"][__("user_password_protected_links")] = true;
+ }
+
+ $expire_links = $_POST["_".__("expire_links")] ?? null;
+ $expire_links_after = $_POST["_".__("expire_links_after")] ?? null;
+ if (!$this->rcmail->config->get("nextcloud_attachment_expire_links_locked", true)) {
+ $param["prefs"][__("user_expire_links")] = ($expire_links == 1 && intval($expire_links_after) > 0);
+ if (intval($expire_links_after) > 0) {
+ $param["user_prefs"][__("expire_links_after")] = intval($expire_links_after);
+ }
+ }
+
+ self::log($param);
+
+ return $param;
+ }
+
/**
* (message_ready hook) correct attachment parameters for nextcloud attachments where
* parameters couldn't be set otherwise
diff --git a/nextcloud_attachments.php b/nextcloud_attachments.php
index a2e06b0..f3411b2 100644
--- a/nextcloud_attachments.php
+++ b/nextcloud_attachments.php
@@ -114,7 +114,7 @@ public function init(): void
$this->add_hook("preferences_list", function ($param) { return $this->add_preferences($param); });
- $this->add_hook("preferences_save", function ($param) { self::log($param); return $param; });
+ $this->add_hook("preferences_save", function ($param) { return $this->save_preferences($param); });
$this->add_hook("attachment_delete", function ($param) { return $this->delete($param); });