summaryrefslogtreecommitdiff
path: root/classes/pluginhost.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-04-09 14:01:30 +0300
committerAndrew Dolgov <[email protected]>2021-04-09 14:01:30 +0300
commita61348e2b727a0671987b16458603fd028b89a1f (patch)
tree9a7767f2cc5a4e474937b4417455515809aa6464 /classes/pluginhost.php
parenta5af15cfe9f1185c24d5d8ee3eb0e4b6bbacfeb5 (diff)
pluginhost: add profile_get/profile_set helpers
Diffstat (limited to 'classes/pluginhost.php')
-rwxr-xr-xclasses/pluginhost.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/classes/pluginhost.php b/classes/pluginhost.php
index 6fbc13a9c..ee4107ae7 100755
--- a/classes/pluginhost.php
+++ b/classes/pluginhost.php
@@ -469,6 +469,29 @@ class PluginHost {
}
}
+ // same as set(), but sets data to current preference profile
+ function profile_set(Plugin $sender, string $name, $value) {
+ $profile_id = $_SESSION["profile"] ?? null;
+
+ if ($profile_id) {
+ $idx = get_class($sender);
+
+ if (!isset($this->storage[$idx])) {
+ $this->storage[$idx] = [];
+ }
+
+ if (!isset($this->storage[$idx][$profile_id])) {
+ $this->storage[$idx][$profile_id] = [];
+ }
+
+ $this->storage[$idx][$profile_id][$name] = $value;
+
+ $this->save_data(get_class($sender));
+ } else {
+ return $this->set($sender, $name, $value);
+ }
+ }
+
function set(Plugin $sender, string $name, $value) {
$idx = get_class($sender);
@@ -492,6 +515,26 @@ class PluginHost {
$this->save_data(get_class($sender));
}
+ // same as get(), but sets data to current preference profile
+ function profile_get(Plugin $sender, string $name, $default_value = false) {
+ $profile_id = $_SESSION["profile"] ?? null;
+
+ if ($profile_id) {
+ $idx = get_class($sender);
+
+ $this->load_data();
+
+ if (isset($this->storage[$idx][$profile_id][$name])) {
+ return $this->storage[$idx][$profile_id][$name];
+ } else {
+ return $default_value;
+ }
+
+ } else {
+ return $this->get($sender, $name, $default_value);
+ }
+ }
+
function get(Plugin $sender, string $name, $default_value = false) {
$idx = get_class($sender);