From a61348e2b727a0671987b16458603fd028b89a1f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 9 Apr 2021 14:01:30 +0300 Subject: [PATCH] pluginhost: add profile_get/profile_set helpers --- classes/pluginhost.php | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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);