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 api
  4:  *
  5:  * Copyright 2008 Obala d.o.o (www.obala.si)
  6:  *
  7:  * See the enclosed file LICENSE for license information (BSD). If you
  8:  * did not receive this file, see http://cvs.horde.org/co.php/folks/LICENSE.
  9:  *
 10:  * @author Duck <duck@obala.net>
 11:  * @package Folks
 12:  */
 13: class Folks_Api extends Horde_Registry_Api
 14: {
 15:     /**
 16:      * Links.
 17:      *
 18:      * @var array
 19:      */
 20:     public $links = array(
 21:         'show' => '%application%/user.php?user=|user|'
 22:     );
 23: 
 24:     public function __construct()
 25:     {
 26:         if (!$GLOBALS['registry']->isAdmin()) {
 27:             $this->disabled = array('removeUser', 'userList');
 28:         }
 29:     }
 30: 
 31:     /**
 32:      * Returns profile image URL.
 33:      *
 34:      * @param string  $user      User uid
 35:      * @param string $view       The view ('small', 'big') to show.
 36:      * @param boolean $full      Return a path that includes the server name?
 37:      *
 38:      * @return string  The image path.
 39:      */
 40:     public function getImageUrl($user, $view = 'small', $full = false)
 41:     {
 42:         require_once dirname(__FILE__) . '/base.php';
 43:         return Folks::getImageUrl($user, $view, $full);
 44:     }
 45: 
 46:     /**
 47:      * Callback for comment API.
 48:      *
 49:      * @param int $id       Internal data identifier.
 50:      * @param string $type  Type of data to retreive (title, owner...).
 51:      * @param array $params  Parameter to be passed to callback function
 52:      */
 53:     public function commentCallback($id, $type = 'title', $params = null)
 54:     {
 55:         static $info;
 56: 
 57:         if (!empty($info[$id][$type])) {
 58:             return $info[$id][$type];
 59:         }
 60: 
 61:         require_once dirname(__FILE__) . '/base.php';
 62: 
 63:         switch ($type) {
 64: 
 65:         case 'owner':
 66:             return $id;
 67: 
 68:         case 'link':
 69:             return Folks::getUrlFor('user', $id);
 70: 
 71:         case 'messages':
 72: 
 73:             // Update comments count
 74:             $result = $GLOBALS['folks_driver']->updateComments($id);
 75:             if ($result instanceof PEAR_Error) {
 76:                 return $result;
 77:             }
 78: 
 79:             // Update activity log
 80:             $link = '<a href="' . Folks::getUrlFor('user', $id) . '">' . $id . '</a>';
 81:             return $GLOBALS['folks_driver']->logActivity(sprintf(_("Commented user %s."), $link), 'folks:comments');
 82: 
 83:             return true;
 84: 
 85:         default:
 86:             return $id;
 87:         }
 88:     }
 89: 
 90:     /**
 91:      * Comments are enebled
 92:      */
 93:     public function hasComments()
 94:     {
 95:         return $GLOBALS['conf']['comments']['allow'];
 96:     }
 97: 
 98:     /**
 99:      * Get online users
100:      */
101:     public function getOnlineUsers()
102:     {
103:         require_once dirname(__FILE__) . '/base.php';
104: 
105:         return $GLOBALS['folks_driver']->getOnlineUsers();
106:     }
107: 
108:     /**
109:      * Get user profile
110:      *
111:      * @param string $user User to get profile for
112:      */
113:     public function getProfile($user = null)
114:     {
115:         require_once dirname(__FILE__) . '/base.php';
116: 
117:         return $GLOBALS['folks_driver']->getProfile($user);
118:     }
119: 
120: 
121:     /**
122:      * Get user friends
123:      *
124:      * @param string $user  Username to get friends for
125:      *
126:      * @return array of users
127:      */
128:     public function getFriends($user = null)
129:     {
130:         require_once dirname(__FILE__) . '/Friends.php';
131: 
132:         $friends = Folks_Friends::singleton('sql', array('user' => $user));
133: 
134:         return $friends->getFriends();
135:     }
136: 
137:     /**
138:      * Add user to our friend list
139:      *
140:      * @param string $friend   Friend's usersame
141:      *
142:      * @return true or PEAR_Error
143:      */
144:     public function addFriend($user = null)
145:     {
146:         require_once dirname(__FILE__) . '/Friends.php';
147: 
148:         $friends = Folks_Friends::singleton('sql', array('user' => $user));
149: 
150:         return $friends->addFriend($user);
151:     }
152: 
153:     /**
154:      * Remove user from a fiend list
155:      *
156:      * @param string $friend   Friend's usersame
157:      *
158:      * @return true or PEAR_Error
159:      */
160:     public function removeFriend($user = null)
161:     {
162:         require_once dirname(__FILE__) . '/Friends.php';
163: 
164:         $friends = Folks_Friends::singleton('sql', array('user' => $user));
165: 
166:         return $friends->removeFriend($user);
167:     }
168: 
169:     /**
170:      * Get user blacklist
171:      *
172:      * @param string $user  Username to get blacklist for
173:      *
174:      * @return array of users
175:      */
176:     public function getBlacklist($user = null)
177:     {
178:         require_once dirname(__FILE__) . '/Friends.php';
179: 
180:         $friends = Folks_Friends::singleton('sql', array('user' => $user));
181: 
182:         return $friends->getBlacklist();
183:     }
184: 
185:     /**
186:      * Add user to a blacklist list
187:      *
188:      * @param string $user   Usersame
189:      */
190:     public function addBlacklisted($user = null)
191:     {
192:         require_once dirname(__FILE__) . '/Friends.php';
193: 
194:         $friends = Folks_Friends::singleton('sql', array('user' => $user));
195: 
196:         return $friends->addBlacklisted($user);
197:     }
198: 
199:     /**
200:      * Remove user from a blacklist list
201:      *
202:      * @param string $user   Usersame
203:      */
204:     public function removeBlacklisted($user = null)
205:     {
206:         require_once dirname(__FILE__) . '/Friends.php';
207: 
208:         $friends = Folks_Friends::singleton('sql', array('user' => $user));
209: 
210:         return $friends->removeBlacklisted($user);
211:     }
212: 
213:     /**
214:      * Are we blackisted by user this user?
215:      *
216:      * @param string $user  Username to get blacklist for
217:      *
218:      * @return array of users
219:      */
220:     public function isBlacklisted($user = null)
221:     {
222:         require_once dirname(__FILE__) . '/Friends.php';
223: 
224:         $friends = Folks_Friends::singleton('sql', array('user' => $user));
225: 
226:         return $friends->isBlacklisted($GLOBALS['registry']->getAuth());
227:     }
228: 
229:     /**
230:      * Users categories
231:      */
232:     public function listTimeObjectCategories()
233:     {
234:         return array('birthday_friends' => _("Friends Birthdays"));
235:     }
236: 
237:     /**
238:      * Lists users with birthdays/goout dates as time objects.
239:      *
240:      * @param array $categories  The time categories (from listTimeObjectCategories) to list.
241:      * @param Horde_Date $start       The start date of the period.
242:      * @param Horde_Date $end         The end date of the period.
243:      */
244:     public function listTimeObjects($categories, $start, $end)
245:     {
246:         require_once dirname(__FILE__) . '/base.php';
247:         require_once FOLKS_BASE . '/lib/Friends.php';
248: 
249:         $friends_driver = Folks_Friends::singleton('sql');
250:         $friends = $friends_driver->getFriends();
251:         if ($friends instanceof PEAR_Error) {
252:             return array();
253:         }
254: 
255:         $objects = array();
256: 
257:         foreach ($friends as $friend) {
258:             $user = $GLOBALS['folks_driver']->getProfile($friend);
259:             if ($user instanceof PEAR_Error) {
260:                 continue;
261:             }
262: 
263:             $user['user_birthday'] = date('Y') . substr($user['user_birthday'], 4);
264:             $born = strtotime($user['user_birthday']);
265:             if ($born === false ||
266:                 $born < $start->timestamp() ||
267:                 $born > $end->timestamp()) {
268:                     continue;
269:                 }
270: 
271:             $age = Folks::calcAge($user['user_birthday']);
272:             $desc = $age['age'] . ' (' . $age['sign'] . ')';
273: 
274:             $objects[$friend] = array(
275:                 'title' => $friend,
276:                 'description' => $desc,
277:                 'id' => $friend,
278:                 'start' => date('Y-m-d\TH:i:s', $born),
279:                 'end' => date('Y-m-d\TH:i:s', $born + 1),
280:                 'params' => array('user' => $friend),
281:                 'link' => Folks::getUrlFor('user', $friend, true));
282:         }
283: 
284:         return $objects;
285:     }
286: 
287:     /**
288:      * Log user's activity
289:      *
290:      * @param mixed $message    Activity message or details
291:      * @param string $scope    Scope
292:      * @param string $user    $user
293:      *
294:      * @return boolean  True on success or a PEAR_Error object on failure.
295:      */
296:     public function logActivity($message, $scope = 'folks', $user = null)
297:     {
298:         if (empty($user)) {
299:             $user = $GLOBALS['registry']->getAuth();
300:         } elseif ($user !== $GLOBALS['registry']->getAuth() &&
301:                   !$GLOBALS['registry']->isAdmin(array('permission' => 'admin:' . $scope))) {
302:             return PEAR::raiseError(_("You cannot log activities for other users."));
303:         }
304: 
305:         require_once dirname(__FILE__) . '/base.php';
306: 
307:         return $GLOBALS['folks_driver']->logActivity($message, $scope, $user);
308:     }
309: 
310:     /**
311:      * Get user's activity
312:      *
313:      * @param string $user    Username
314:      * @param int $limit    Number of actions to return
315:      *
316:      * @return array    Activity log
317:      */
318:     public function getActivity($user, $limit = 10)
319:     {
320:         require_once dirname(__FILE__) . '/base.php';
321: 
322:         return $GLOBALS['folks_driver']->getActivity($user, $limit);
323:     }
324: 
325:     /**
326:      * Set user status
327:      *
328:      * @param booelan $online True to set user online, false to push it offline
329:      * @param string $user    Username
330:      *
331:      * @return boolean True if succes, PEAR_Error on failure
332:      */
333:     public function setStatus($online = true, $user = null)
334:     {
335:         require_once dirname(__FILE__) . '/base.php';
336: 
337:         if ($user == null) {
338:             $user = $GLOBALS['registry']->getAuth();
339:         }
340: 
341:         if ($online) {
342:             return $GLOBALS['folks_driver']->resetOnlineUsers();
343:         } else {
344:             $result = $GLOBALS['folks_driver']->deleteOnlineUser($user);
345:             $GLOBALS['cache']->expire('folksOnlineUsers');
346:             return $result;
347:         }
348:     }
349: 
350:     /**
351:      * Get user status
352:      *
353:      * @param string $user    Username
354:      *
355:      * @return boolean True if user is online, false otherwise
356:      */
357:     public function getStatus($user = null)
358:     {
359:         require_once dirname(__FILE__) . '/base.php';
360: 
361:         if ($user == null) {
362:             $user = $GLOBALS['registry']->getAuth();
363:         }
364: 
365:         return $GLOBALS['folks_driver']->isOnline($user);
366:     }
367: 
368: }
369: 
API documentation generated by ApiGen