initPrefPrefix(); $this->name = strtolower(TikiLib::remove_non_word_characters_and_accents($name)); if (! empty($this->name) && ! empty($prefs[$this->getPrefName()])) { $this->loadPref(); } else { $this->initData(); } } abstract public function initPrefPrefix(); // to be declared to set $this->prefPrefix = 'your_pref_prefix_' abstract public function initData(); // func to set $this->data as you need it /** * @param $params * @return mixed */ abstract public function setData($params); // func to set the date public function getData() { return $this->data; } /** * @return string */ public function getName() { return $this->name; } /** * @return string */ public function getPrefName() { return $this->prefPrefix . $this->name; } /** * @return string */ public function getListName() { return $this->prefPrefix . 'list'; } /** * @return array|mixed */ public function getPrefList() { global $prefs; if (isset($prefs[$this->getListName()])) { $custom = @unserialize($prefs[$this->getListName()]); sort($custom); } else { $custom = []; } return $custom; } /** * @return mixed */ public function loadPref() { global $prefs, $tikilib; $this->data = unserialize($prefs[$this->getPrefName()]); return $this->data; } public function savePref() { global $prefs, $tikilib; $list = $this->getPrefList(); $tikilib->set_preference($this->getPrefName(), serialize($this->data)); if (! in_array($this->name, $list)) { $list[] = $this->name; $tikilib->set_preference($this->getListName(), serialize($list)); } } public function deletePref() { global $prefs, $tikilib; $prefName = $this->getPrefName(); if (isset($prefs[$prefName])) { $tikilib->delete_preference($prefName); } $list = $this->getPrefList(); if (in_array($this->name, $list)) { $list = array_diff($list, [$this->name]); $tikilib->set_preference($this->getListName(), serialize($list)); } } }