From d16599f3519ac15c05a913821f64be49eaa5117f Mon Sep 17 00:00:00 2001 From: "Duck (Jakob Munih)" Date: Sun, 15 Feb 2009 18:01:05 +0100 Subject: [PATCH] Add Letter implementation of prefs dirver --- folks/lib/Friends/prefs.php | 166 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 folks/lib/Friends/prefs.php diff --git a/folks/lib/Friends/prefs.php b/folks/lib/Friends/prefs.php new file mode 100644 index 000000000..40ad3e0b6 --- /dev/null +++ b/folks/lib/Friends/prefs.php @@ -0,0 +1,166 @@ + '', + * 'locked' => false, + * 'shared' => false, + * 'type' => 'implicit' + * ); + * + * $_prefs['blacklist'] = array( + * 'value' => '', + * 'locked' => false, + * 'shared' => false, + * 'type' => 'implicit' + * ); + * + * $Horde: incubator/letter/lib/Friends/letter.php,v 1.9 2009/01/06 17:50:52 jan Exp $ + * + * Copyright 2007-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Duck + * @package Folks + */ +class Folks_Friends_prefs extends Folks_Friends { + + /** + * Add user to a friend list + * + * @param string $friend Friend's usersame + */ + protected function _addFriend($friend) + { + return $this->_addrem_lists('whitelist', $friend); + } + + /** + * Remove user from a fiend list + * + * @param string $friend Friend's usersame + */ + public function removeFriend($friend) + { + return $this->_addrem_lists('whitelist', $friend); + } + + /** + * Get user friends + * + * @return array of users + */ + public function getFriends() + { + return $this->_lists('whitelist'); + } + + /** + * Get user blacklist + * + * @return array of users blacklist + */ + public function getBlacklist() + { + return $this->_lists('blacklist'); + } + + /** + * Add user to a blacklist list + * + * @param string $user Usersame + */ + protected function _addBlacklisted($user) + { + return $this->_addrem_lists('blacklist', $user); + } + + /** + * Add user to a blacklist list + * + * @param string $user Usersame + */ + public function removeBlacklisted($user) + { + return $this->_addrem_lists('blacklist', $user); + } + + /** + * Returns array of usernames in a list of false if list is empty + * splits list by any number of commas or space characters + * which include " ", \r, \t, \n and \f + * + * @param string $type List type to retreive + * @param string $user Username to check + * + * @return array $list array fo usernames + */ + private function _lists($type, $user = null) + { + if (empty($user)) { + $user = Auth::getAuth(); + } + + $u_prefs = Prefs::singleton($GLOBALS['conf']['prefs']['driver'], $GLOBALS['registry']->getApp(), $user); + $u_prefs->retrieve(); + + $list = $u_prefs->getValue($type); + + if ($list) { + $users = preg_split("/[\s,]+/", $list, -1, PREG_SPLIT_NO_EMPTY); + if (sizeof($users) > 0) { + $list = array(); + foreach ($users as $value) { + $list[$value] = $value; + } + return $list; + } + } + + return array(); + } + + /** + * Add/remove a user from a list + * + * @param string $type of the list + * @param string $user user to applay + */ + private function _addrem_lists($type, $user) + { + global $prefs; + + $list = $prefs->getValue($type); + + if ($list) { + $users = preg_split("/[\s,]+/", $list, -1, PREG_SPLIT_NO_EMPTY); + if (in_array($user, $users)) { + $key = array_search($user, $users); + unset($users[$key]); + sort($users); + $prefs->setValue($type, implode($users, ' ')); + } else { + $users[] = $user; + sort($users); + $prefs->setValue($type, implode($users, ' ')); + } + } else { + $prefs->setValue($type, $user); + } + + return false; + } + + /** + * Get avaiable groups + */ + public function getGroups() + { + return array('whitelist' => _("Whitelist")); + } +} \ No newline at end of file -- 2.11.0