1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Folks_Api extends Horde_Registry_Api
14: {
15: 16: 17: 18: 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: 33: 34: 35: 36: 37: 38: 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: 48: 49: 50: 51: 52:
53: public function ($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:
74: $result = $GLOBALS['folks_driver']->updateComments($id);
75: if ($result instanceof PEAR_Error) {
76: return $result;
77: }
78:
79:
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: 92:
93: public function ()
94: {
95: return $GLOBALS['conf']['comments']['allow'];
96: }
97:
98: 99: 100:
101: public function getOnlineUsers()
102: {
103: require_once dirname(__FILE__) . '/base.php';
104:
105: return $GLOBALS['folks_driver']->getOnlineUsers();
106: }
107:
108: 109: 110: 111: 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: 123: 124: 125: 126: 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: 139: 140: 141: 142: 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: 155: 156: 157: 158: 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: 171: 172: 173: 174: 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: 187: 188: 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: 201: 202: 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: 215: 216: 217: 218: 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: 231:
232: public function listTimeObjectCategories()
233: {
234: return array('birthday_friends' => _("Friends Birthdays"));
235: }
236:
237: 238: 239: 240: 241: 242: 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: 289: 290: 291: 292: 293: 294: 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: 312: 313: 314: 315: 316: 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: 327: 328: 329: 330: 331: 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: 352: 353: 354: 355: 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: