Overview

Packages

  • Folks
  • None

Classes

  • Folks
  • Folks_Activity_Form
  • Folks_Api
  • Folks_Application
  • Folks_Block_Activities
  • Folks_Block_Friends
  • Folks_Block_Know
  • Folks_Block_New
  • Folks_Block_Random
  • Folks_Block_Recent
  • Folks_Driver
  • Folks_Driver_sql
  • Folks_Friends
  • Folks_Friends_application
  • Folks_Friends_facebook
  • Folks_Friends_prefs
  • Folks_Friends_shared
  • Folks_Friends_sql
  • Folks_Login_Form
  • Folks_Notification
  • Folks_Notification_facebook
  • Folks_Notification_letter
  • Folks_Notification_mail
  • Folks_Notification_tickets
  • Folks_Search_Form
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Folks internal firends implementaton
  4:  *
  5:  * NOTE: You must add this prefs to your application
  6:  *
  7:  *  $_prefs['whitelist'] = array(
  8:  *      'value' => '',
  9:  *      'locked' => false,
 10:  *     'type' => 'implicit'
 11:  *  );
 12:  *
 13:  *  $_prefs['blacklist'] = array(
 14:  *      'value' => '',
 15:  *      'locked' => false,
 16:  *      'type' => 'implicit'
 17:  *  );
 18:  *
 19:  * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
 20:  *
 21:  * See the enclosed file COPYING for license information (GPL). If you
 22:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 23:  *
 24:  * @author  Duck <duck@obala.net>
 25:  * @package Folks
 26:  */
 27: class Folks_Friends_prefs extends Folks_Friends {
 28: 
 29:     /**
 30:      * Add user to a friend list
 31:      *
 32:      * @param string $friend   Friend's usersame
 33:      */
 34:     protected function _addFriend($friend)
 35:     {
 36:         return $this->_addrem_lists('whitelist', $friend);
 37:     }
 38: 
 39:     /**
 40:      * Remove user from a fiend list
 41:      *
 42:      * @param string $friend   Friend's usersame
 43:      */
 44:     public function removeFriend($friend)
 45:     {
 46:         return $this->_addrem_lists('whitelist', $friend);
 47:     }
 48: 
 49:     /**
 50:      * Get user friends
 51:      *
 52:      * @return array of users
 53:      */
 54:     public function getFriends()
 55:     {
 56:         return $this->_lists('whitelist');
 57:     }
 58: 
 59:     /**
 60:      * Get user blacklist
 61:      *
 62:      * @return array of users blacklist
 63:      */
 64:     public function getBlacklist()
 65:     {
 66:         return $this->_lists('blacklist');
 67:     }
 68: 
 69:     /**
 70:      * Add user to a blacklist list
 71:      *
 72:      * @param string $user   Usersame
 73:      */
 74:     protected function _addBlacklisted($user)
 75:     {
 76:         return $this->_addrem_lists('blacklist', $user);
 77:     }
 78: 
 79:     /**
 80:      * Add user to a blacklist list
 81:      *
 82:      * @param string $user   Usersame
 83:      */
 84:     public function removeBlacklisted($user)
 85:     {
 86:         return $this->_addrem_lists('blacklist', $user);
 87:     }
 88: 
 89:     /**
 90:      * Returns array of usernames in a list of false if list is empty
 91:      * splits list by any number of commas or space characters
 92:      * which include " ", \r, \t, \n and \f
 93:      *
 94:      * @param string $type List type to retreive
 95:      * @param string $user Username to check
 96:      *
 97:      * @return array $list array fo usernames
 98:      */
 99:     private function _lists($type, $user = null)
100:     {
101:         if (empty($user)) {
102:             $user = $GLOBALS['registry']->getAuth();
103:         }
104: 
105:         $u_prefs = $GLOBALS['injector']->getInstance('Horde_Prefs')->getPrefs($GLOBALS['registry']->getApp(), array(
106:             'user' => $user
107:         ));
108: 
109:         $list = $u_prefs->getValue($type);
110: 
111:         if ($list) {
112:             $users = preg_split("/[\s,]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
113:             if (sizeof($users) > 0) {
114:                 $list = array();
115:                 foreach ($users as $value) {
116:                    $list[$value] = $value;
117:                 }
118:                 return $list;
119:             }
120:         }
121: 
122:         return array();
123:     }
124: 
125:     /**
126:      * Add/remove a user from a list
127:      *
128:      * @param string $type of the list
129:      * @param string $user user to applay
130:      */
131:     private function _addrem_lists($type, $user)
132:     {
133:         global $prefs;
134: 
135:         $list = $prefs->getValue($type);
136: 
137:         if ($list) {
138:             $users = preg_split("/[\s,]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
139:             if (in_array($user, $users)) {
140:                 $key = array_search($user, $users);
141:                 unset($users[$key]);
142:                 sort($users);
143:                 $prefs->setValue($type, implode($users, ' '));
144:             } else {
145:                 $users[] = $user;
146:                 sort($users);
147:                 $prefs->setValue($type, implode($users, ' '));
148:             }
149:         } else {
150:             $prefs->setValue($type, $user);
151:         }
152: 
153:         return false;
154:     }
155: 
156:     /**
157:      * Get avaiable groups
158:      */
159:     public function getGroups()
160:     {
161:         return array('whitelist' => _("Friends"));
162:     }
163: }
164: 
API documentation generated by ApiGen