<configtab name="general" desc="General">
<configstring name="support" desc="Email from which support messages will be sent">support@example.com</configstring>
- <configenum name="friends" desc="Driver for friends storage">sql
- <values>
- <value desc="Internal - friends and blacklist only">sql</value>
- <value desc="Internal - shared lists">shared</value>
- <value desc="Letter app">letter</value>
- </values>
- </configenum>
+ <configswitch name="friends" desc="Driver for friends storage">sql
+ <case name="prefs" desc="Prefs - friends and blacklist only sored"></case>
+ <case name="sql" desc="SQL - friends and blacklist only"></case>
+ <case name="shared" desc="Shared - custom shared groups lists"></case>
+ <case name="application" desc="Application">
+ <configsection name="params">
+ <configenum name="app" desc="The application which is providing friends">letter
+ <values>
+ <configspecial name="list-horde-apps"/>
+ </values>
+ </configenum>
+ </configsection>
+ </case>
+ </configswitch>
<configsection name="images">
<configheader>Images</configheader>
* @return Folks_Friends The newly created concrete Folks_Friends
* instance, or false on an error.
*/
- static public function factory($driver = null, $params = null)
+ private static function factory($driver = null, $params = null)
{
if ($driver === null) {
$driver = $GLOBALS['conf']['friends'];
* @param array $params A hash containing any additional configuration
* or connection parameters a subclass might need.
*/
- public function __construct($params)
+ protected function __construct($params)
{
$this->_user = empty($params['user']) ? Auth::getAuth() : $params['user'];
+++ /dev/null
-<?php
-/**
- * Folks_Friends:: defines an API for implementing storage backends for
- * Folks.
- *
- * $Id: letter.php 777 2008-08-21 09:23:07Z duck $
- *
- * Copyright Obala d.o.o. (www.obala.si)
- *
- * 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 <duck@obala.net>
- * @package Folks
- */
-class Folks_Friends_letter extends Folks_Friends {
-
- /**
- * Get user blacklist
- *
- * @return array of users blacklist
- */
- protected function _getBlacklist()
- {
- return $GLOBALS['registry']->callByPackage('letter', 'getBlacklist', array($this->_user));
- }
-
- /**
- * Add user to a blacklist list
- *
- * @param string $user Usersame
- */
- protected function _addBlacklisted($user)
- {
- return $GLOBALS['registry']->callByPackage('letter', 'addFriend', array($user, 'blacklist', $this->_user));
- }
-
- /**
- * Remove user from a fiend list
- *
- * @param string $user Usersame
- */
- protected function _removeBlacklisted($user)
- {
- return $GLOBALS['registry']->callByPackage('letter', 'addFriend', array($user, 'blacklist', $this->_user));
- }
-
- /**
- * Add user to a friend list
- *
- * @param string $friend Friend's usersame
- * @param string $group Group to add friend to
- */
- protected function _addFriend($friend, $group = null)
- {
- return $GLOBALS['registry']->callByPackage('letter', 'addFriend', array($friend, 'whitelist', $this->_user));
- }
-
- /**
- * Remove user from a fiend list
- *
- * @param string $friend Friend's usersame
- * @param string $group Group to remove friend from
- */
- protected function _removeFriend($friend, $group = null)
- {
- return $GLOBALS['registry']->callByPackage('letter', 'addFriend', array($friend, 'whitelist', $this->_user));
- }
-
- /**
- * Get user friends
- *
- * @param string $group Get friens only from this group
- *
- * @return array of users (in group)
- */
- protected function _getFriends($group = null)
- {
- return $GLOBALS['registry']->callByPackage('letter', 'getFriends', array($this->_user, 'whitelist'));
- }
-
- /**
- * Get user groups
- */
- public function getGroups()
- {
- return array('whitelist' => _("Whitelist"),
- 'blacklist' => _("Blacklist"));
- }
-}
-
*
* $Id: shared.php 1247 2009-01-30 15:01:34Z duck $
*
- * Copyright Obala d.o.o. (www.obala.si)
+ * 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 <duck@obala.net>
* @package Folks
*/
-class Folks_Friends_shared extends Folks_Friends_sql {
+class Folks_Friends_shared extends Folks_Friends_sql {
+
+ const CUSTOM = 3;
/**
* friends list ID
*
* @var int
*/
- private $_friends;
+ private $_whitelist;
/**
* Black list ID
private $_blacklist;
/**
+ * Get whitelist ID
+ */
+ protected function _id($id)
+ {
+ switch ($id) {
+
+ case self::BLACKLIST;
+ return $this->_blacklist;
+
+ case self::WHITELIST;
+ return $this->_whitelist;
+
+ default:
+ return $id;
+
+ }
+ }
+
+ /**
* Get user friends and blacklist group id
*/
private function _getIds()
{
- if ($this->_friends && $this->_blacklist) {
+ if ($this->_whitelist && $this->_blacklist) {
return;
}
if ($groups instanceof PEAR_Error) {
return $groups;
}
-
+var_dump($groups);
foreach ($groups as $id => $group) {
if ($group->get('type') == self::BLACKLIST) {
$this->_blacklist = $group->getId();
} elseif ($group->get('type') == self::WHITELIST) {
- $this->_friends = $group->getId();
+ $this->_whitelist = $group->getId();
}
}
}
{
$this->_getIds();
+ // No blacklist even created
if (empty($this->_blacklist)) {
return array();
}
- parent::_getBlacklist();
+ return parent::_getBlacklist();
}
/**
{
$this->_getIds();
+ // Create blacklist
if (empty($this->_blacklist)) {
- $result = $this->addGroup('_BLACKLIST_', self::BLACKLIST);
- if ($result instanceof PEAR_Error) {
- return $result;
+ $group_id = $this->addGroup('_BLACKLIST_', self::BLACKLIST);
+ if ($group_id instanceof PEAR_Error) {
+ return $group_id;
}
+ $this->_blacklist = $group_id;
}
- parent::_addBlacklisted($user);
+ return parent::_addBlacklisted($user);
}
/**
{
$this->_getIds();
- if (empty($this->_friends)) {
- $result = $this->addGroup('_FRIENDS_', self::WHITELIST);
- if ($result instanceof PEAR_Error) {
- return $result;
+ if (empty($this->_whitelist)) {
+ $group_id = $this->addGroup('_FRIENDS_', self::WHITELIST);
+ if ($group_id instanceof PEAR_Error) {
+ return $group_id;
}
+ $this->_whitelist = $group_id;
}
parent::_addFriend($friend, $group);
{
$this->_getIds();
- if (empty($this->_friends)) {
+ if (empty($this->_whitelist)) {
return true;
}
* Get user friends
*
* @param string $group Get friens only from this group
- * @param boolean $ask Show all users or only them who approved us
*
* @return array of users (in group)
*/
- protected function _getFriends($group = null, $ask = false)
+ protected function _getFriends($group = null)
{
$this->_getIds();
- if (empty($this->_friends)) {
+ if (empty($this->_whitelist)) {
return array();
}
- parent::_getFriends($group, $ask);
+ parent::_getFriends($group);
}
/**
$list = array();
foreach ($groups as $id => $group) {
- $list[$id] = $group->get('name');
-
// set friends ids
if ($group->get('type') == self::BLACKLIST) {
$this->_blacklist = $id;
+ $list[$id] = _("Blacklist");
} elseif ($group->get('type') == self::WHITELIST) {
- $this->_friends = $id;
+ $this->_whitelist = $id;
+ $list[$id] = _("Friends");
+ } else {
+ $list[$id] = $group->get('name');
}
}
if ($type !== null) {
$share->set('type', $type);
+ } else {
+ $share->set('type', self::CUSTOM);
}
return $GLOBALS['folks_shares']->addShare($share);
*
* $Id: sql.php 1247 2009-01-30 15:01:34Z duck $
*
- * Copyright Obala d.o.o. (www.obala.si)
+ * 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.
*
* @param array $params A hash containing connection parameters.
*/
- public function __construct($params = array())
+ protected function __construct($params = array())
{
parent::__construct($params);
+
$this->_params = $params;
$this->_connect();
}
*/
protected function _getBlacklist()
{
- $query = 'SELECT friend_uid FROM ' . $this->_params['friends']
- . ' WHERE user_uid = ? AND group_id = ? '
+ $query = 'SELECT friend_uid FROM ' . $this->_params['blacklist']
+ . ' WHERE user_uid = ? '
. ' ORDER BY friend_uid ASC';
- return $this->_db->getCol($query, 0, array($this->_user, self::BLACKLIST));
+ return $this->_db->getCol($query, 0, array($this->_user));
}
/**
*/
protected function _addBlacklisted($user)
{
- $query = 'INSERT INTO ' . $this->_params['friends']
- . ' (user_uid, group_id, friend_uid, friend_ask) VALUES (?, ?, ?, ?)';
- return $this->_write_db->query($query, array($this->_user, self::BLACKLIST, $user, 0));
+ $query = 'INSERT INTO ' . $this->_params['blacklist']
+ . ' (user_uid, friend_uid) VALUES (?, ?)';
+
+ return $this->_write_db->query($query, array($this->_user, $user));
}
/**
*/
protected function _removeBlacklisted($user)
{
- $query = 'DELETE FROM ' . $this->_params['friends'] . ' WHERE user_uid = ? AND group_id = ? AND friend_uid = ?';
- return $this->_write_db->query($query, array($this->_user, self::BLACKLIST, $user));
+ $query = 'DELETE FROM ' . $this->_params['blacklist']
+ . ' WHERE user_uid = ? AND friend_uid = ?';
+
+ return $this->_write_db->query($query, array($this->_user, $user));
}
/**
* Add user to a friend list
*
* @param string $friend Friend's usersame
- * @param string $group Group to add friend to
*/
- protected function _addFriend($friend, $group = null)
+ protected function _addFriend($friend)
{
$approve = $this->needsApproval($friend) ? 1 : 0;
$query = 'INSERT INTO ' . $this->_params['friends']
- . ' (user_uid, group_id, friend_uid, friend_ask) VALUES (?, ?, ?, ?)';
- return $this->_write_db->query($query, array($this->_user, self::WHITELIST, $friend, $approve));
+ . ' (user_uid, friend_uid, friend_ask) VALUES (?, ?, ?, ?)';
+
+ return $this->_write_db->query($query, array($this->_user, $friend, $approve));
}
/**
{
$query = 'UPDATE ' . $this->_params['friends']
. ' SET friend_ask = ? WHERE user_uid = ? AND friend_uid = ?';
+
$result = $this->_write_db->query($query, array(0, $friend, $this->_user));
if ($result instanceof PEAR_Error) {
return $result;
// Add user even to firend's friend list
$query = 'REPLACE INTO ' . $this->_params['friends']
- . ' (user_uid, group_id, friend_uid, friend_ask) VALUES (?, ?, ?, ?)';
- return $this->_write_db->query($query, array($this->_user, self::WHITELIST, $friend, 0));
+ . ' (user_uid, friend_uid, friend_ask) VALUES (?, ?, ?)';
+
+ return $this->_write_db->query($query, array($this->_user, $friend, 0));
}
/**
* Remove user from a fiend list
*
* @param string $friend Friend's usersame
- * @param string $group Group to remove friend from
*/
- protected function _removeFriend($friend, $group = null)
+ protected function _removeFriend($friend)
{
- $query = 'DELETE FROM ' . $this->_params['friends'] . ' WHERE user_uid = ? AND group_id = ? AND friend_uid = ?';
- return $this->_write_db->query($query, array($this->_user, self::WHITELIST, $friend));
+ $query = 'DELETE FROM ' . $this->_params['friends']
+ . ' WHERE user_uid = ? AND friend_uid = ?';
+
+ return $this->_write_db->query($query, array($this->_user, $friend));
}
/**
* Get user friends
*
- * @param string $group Get friens only from this group
- *
- * @return array of users (in group)
+ * @return array of user's friends
*/
- protected function _getFriends($group = null)
+ protected function _getFriends()
{
$query = 'SELECT friend_uid FROM ' . $this->_params['friends']
- . ' WHERE user_uid = ? AND group_id = ?'
+ . ' WHERE user_uid = ?'
. ' ORDER BY friend_uid ASC';
- return $this->_db->getCol($query, 0, array($this->_user, self::WHITELIST));
+ return $this->_db->getCol($query, 0, array($this->_user));
}
/**
public function getPossibleFriends()
{
$query = 'SELECT user_uid FROM ' . $this->_params['friends']
- . ' WHERE friend_uid = ? AND group_id = ? AND friend_ask = ?'
+ . ' WHERE friend_uid = ? AND friend_ask = ?'
. ' ORDER BY friend_uid ASC';
- return $this->_db->getCol($query, 0, array($this->_user, self::WHITELIST, 0));
- }
-
- /**
- * Get users friends birthdays
- *
- * @return array users
- */
- public function getBirthdays()
- {
- return false;
+ return $this->_db->getCol($query, 0, array($this->_user, 0));
}
/**
if (!isset($this->_params['hostspec'])) {
$this->_params['hostspec'] = '';
}
+ if (!isset($this->_params['friends'])) {
+ $this->_params['friends'] = 'folks_friends';
+ }
+ if (!isset($this->_params['blacklist'])) {
+ $this->_params['blacklist'] = 'folks_blacklist';
+ }
/* Connect to the SQL server using the supplied parameters. */
+ require_once 'DB.php';
$this->_write_db = DB::connect($this->_params,
array('persistent' => !empty($this->_params['persistent'])));
if ($this->_write_db instanceof PEAR_Error) {
KEY attributes_group (attributes_group)
);
+-- friends SQL
+CREATE TABLE IF NOT EXISTS `folks_friends` (
+ `user_uid` VARCHAR(32) NOT NULL,
+ `friend_uid` VARCHAR(32) NOT NULL,
+ `friend_ask` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
+ PRIMARY KEY (`user_uid`, `friend_uid`),
+ KEY `friend_ask` (`friend_ask`)
+);
+
+-- friends SHARED
CREATE TABLE IF NOT EXISTS `folks_friends` (
`user_uid` VARCHAR(32) NOT NULL,
`group_id` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
KEY `friend_ask` (`friend_ask`)
);
+-- BLACKLIST
+CREATE TABLE IF NOT EXISTS `folks_blacklist` (
+ `user_uid` VARCHAR(32) NOT NULL,
+ `friend_uid` VARCHAR(32) NOT NULL,
+ PRIMARY KEY (`user_uid`, `friend_uid`)
+);
+
CREATE TABLE IF NOT EXISTS folks_notify_counts (
user_uid VARCHAR(32) NOT NULL,
count_news SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
--- /dev/null
+CREATE TABLE IF NOT EXISTS `folks_blacklist` (
+ `user_uid` VARCHAR(32) NOT NULL,
+ `friend_uid` VARCHAR(32) NOT NULL,
+ PRIMARY KEY (`user_uid`, `friend_uid`)
+);
+
+INSERT folks_blacklist (`user_uid`, `friend_uid`)
+ SELECT `user_uid`, `friend_uid` FROM `folks_friends` WHERE `group_id` = 0;
\ No newline at end of file