From 485d1e68d21fb4b62bc5050300d854aba0281b0e Mon Sep 17 00:00:00 2001 From: "Duck (Jakob Munih)" Date: Wed, 18 Feb 2009 16:44:31 +0100 Subject: [PATCH] Prepare friends UI for groups --- folks/edit/{ => friends}/approve.php | 9 +- folks/edit/{ => friends}/blacklist.php | 32 +++-- folks/edit/friends/for.php | 46 +++++++ folks/edit/friends/friends.php | 84 ++++++++++++ folks/edit/friends/from.php | 46 +++++++ folks/edit/{ => friends}/groups.php | 10 +- folks/edit/{friends.php => friends/index.php} | 34 +---- folks/edit/friends/invite.php | 61 +++++++++ folks/edit/friends/of.php | 46 +++++++ folks/edit/{ => friends}/reject.php | 9 +- folks/edit/tabs.php | 13 +- folks/lib/Driver.php | 7 +- folks/lib/Folks.php | 15 +-- folks/lib/Friends.php | 49 ++++--- folks/lib/Friends/application.php | 2 +- folks/lib/Friends/shared.php | 177 +++----------------------- folks/lib/Friends/sql.php | 2 +- folks/lib/api.php | 14 +- folks/templates/edit/activity.php | 4 +- folks/templates/edit/blacklist.php | 28 ---- folks/templates/edit/friends.php | 85 +++++-------- folks/templates/edit/groups.php | 28 ++-- folks/templates/edit/invite.php | 3 + folks/templates/edit/tabs.php | 35 +++++ 24 files changed, 498 insertions(+), 341 deletions(-) rename folks/edit/{ => friends}/approve.php (83%) rename folks/edit/{ => friends}/blacklist.php (67%) create mode 100644 folks/edit/friends/for.php create mode 100644 folks/edit/friends/friends.php create mode 100644 folks/edit/friends/from.php rename folks/edit/{ => friends}/groups.php (90%) rename folks/edit/{friends.php => friends/index.php} (77%) create mode 100644 folks/edit/friends/invite.php create mode 100644 folks/edit/friends/of.php rename folks/edit/{ => friends}/reject.php (81%) delete mode 100644 folks/templates/edit/blacklist.php create mode 100644 folks/templates/edit/invite.php create mode 100644 folks/templates/edit/tabs.php diff --git a/folks/edit/approve.php b/folks/edit/friends/approve.php similarity index 83% rename from folks/edit/approve.php rename to folks/edit/friends/approve.php index d63cd1d65..820e28642 100644 --- a/folks/edit/approve.php +++ b/folks/edit/friends/approve.php @@ -11,8 +11,7 @@ * @package Folks */ -define('FOLKS_BASE', dirname(__FILE__) . '/..'); -require_once FOLKS_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/../../lib/base.php'; require_once FOLKS_BASE . '/lib/Friends.php'; if (!Auth::isAuthenticated()) { @@ -22,7 +21,7 @@ if (!Auth::isAuthenticated()) { $user = Util::getGet('user'); if (empty($user)) { $notification->push(_("You must supply a username.")); - header('Location: ' . Horde::applicationUrl('edit/friends.php')); + header('Location: ' . Horde::applicationUrl('edit/friends/index.php')); exit; } @@ -31,7 +30,7 @@ $result = $friends->approveFriend($user); if ($result instanceof PEAR_Error) { $notification->push($result); $notification->push($result->getDebugInfo()); - header('Location: ' . Horde::applicationUrl('edit/friends.php')); + header('Location: ' . Horde::applicationUrl('edit/friends/index.php')); exit; } @@ -51,5 +50,5 @@ $friends->sendNotification($user, $title, $body); $link = '' . $user . ''; $folks_driver->logActivity(sprintf(_("Added user %s as a friend."), $link)); -header('Location: ' . Horde::applicationUrl('edit/friends.php')); +header('Location: ' . Horde::applicationUrl('edit/friends/index.php')); exit; \ No newline at end of file diff --git a/folks/edit/blacklist.php b/folks/edit/friends/blacklist.php similarity index 67% rename from folks/edit/blacklist.php rename to folks/edit/friends/blacklist.php index d241a213b..b0e861fc3 100644 --- a/folks/edit/blacklist.php +++ b/folks/edit/friends/blacklist.php @@ -11,13 +11,12 @@ * @package Folks */ -define('FOLKS_BASE', dirname(__FILE__) . '/..'); -require_once FOLKS_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/../../lib/base.php'; require_once FOLKS_BASE . '/lib/Forms/AddFriend.php'; -require_once 'tabs.php'; +require_once FOLKS_BASE . '/edit/tabs.php'; $title = _("Blacklist"); -$remove_url = Util::addParameter(Horde::applicationUrl('edit/blacklist.php'), 'user', null); +$remove_url = Util::addParameter(Horde::applicationUrl('edit/friends/blacklist.php'), 'user', null); $remove_img = Horde::img('delete.png', '', '', $registry->getImageDir('horde')); $profile_img = Horde::img('user.png', '', '', $registry->getImageDir('horde')); @@ -34,6 +33,8 @@ if ($user) { $notification->push($result); } else { $notification->push(sprintf(_("User \"%s\" was removed from your blacklist."), $user), 'horde.success'); + header('Location: ' . Horde::applicationUrl('edit/friends/blacklist.php')); + exit; } } else { $result = $friends->addBlacklisted($user); @@ -41,17 +42,32 @@ if ($user) { $notification->push($result); } else { $notification->push(sprintf(_("User \"%s\" was added to your blacklist."), $user), 'horde.success'); + header('Location: ' . Horde::applicationUrl('edit/friends/blacklist.php')); + exit; } } } // Get blacklist -$blacklist = $friends->getBlacklist(); -if ($blacklist instanceof PEAR_Error) { - $notification->push($blacklist); +$list = $friends->getBlacklist(); +if ($list instanceof PEAR_Error) { + $notification->push($list); $blacklist = array(); } +// Users online +$online = $folks_driver->getOnlineUsers(); +if ($online instanceof PEAR_Error) { + return $online; +} + +// Get groups +$groups = $friends->getGroups(); +if ($groups instanceof PEAR_Error) { + $notification->push($groups); + $groups = array(); +} + $form = new Folks_AddFriend_Form($vars, _("Add or remove user"), 'blacklist'); Horde::addScriptFile('tables.js', 'horde', true); @@ -60,6 +76,6 @@ require FOLKS_TEMPLATES . '/common-header.inc'; require FOLKS_TEMPLATES . '/menu.inc'; echo $tabs->render('blacklist'); -require FOLKS_TEMPLATES . '/edit/blacklist.php'; +require FOLKS_TEMPLATES . '/edit/friends.php'; require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/folks/edit/friends/for.php b/folks/edit/friends/for.php new file mode 100644 index 000000000..3410d87d0 --- /dev/null +++ b/folks/edit/friends/for.php @@ -0,0 +1,46 @@ + + * @package Folks + */ + +require_once dirname(__FILE__) . '/../../lib/base.php'; +require_once FOLKS_BASE . '/lib/Forms/AddFriend.php'; +require_once FOLKS_BASE . '/edit/tabs.php'; + +$title = _("Users waiting our approval"); + +$letter_url = ''; +$profile_img = Horde::img('user.png', '', '', $registry->getImageDir('horde')); +if ($registry->hasInterface('letter')) { + $letter_url = $registry->get('webroot', 'letter') . '/compose.php'; + $letter_img = Horde::img('letter.png', '', '', $registry->getImageDir('letter')); +} + +// Load driver +require_once FOLKS_BASE . '/lib/Friends.php'; +$friends = Folks_Friends::singleton(); + +// Get list +$list = $friends->waitingApprovalFrom(); +if ($list instanceof PEAR_Error) { + $notification->push($list); + $list = array(); +} + +Horde::addScriptFile('tables.js', 'horde', true); + +require FOLKS_TEMPLATES . '/common-header.inc'; +require FOLKS_TEMPLATES . '/menu.inc'; + +echo $tabs->render('friendsof'); +require FOLKS_TEMPLATES . '/edit/friends.php'; + +require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/folks/edit/friends/friends.php b/folks/edit/friends/friends.php new file mode 100644 index 000000000..85b1eb5af --- /dev/null +++ b/folks/edit/friends/friends.php @@ -0,0 +1,84 @@ + + * @package Folks + */ + +require_once dirname(__FILE__) . '/../../lib/base.php'; +require_once FOLKS_BASE . '/lib/Forms/AddFriend.php'; +require_once FOLKS_BASE . '/edit/tabs.php'; + +$title = _("Friends"); +$remove_url = Horde::applicationUrl('edit/friends/index.php'); +$remove_img = Horde::img('delete.png', '', '', $registry->getImageDir('horde')); +$profile_img = Horde::img('user.png', '', '', $registry->getImageDir('horde')); +$letter_url = ''; +if ($registry->hasInterface('letter')) { + $letter_url = $registry->get('webroot', 'letter') . '/compose.php'; + $letter_img = Horde::img('letter.png', '', '', $registry->getImageDir('letter')); +} + +// Load driver +require_once FOLKS_BASE . '/lib/Friends.php'; +$friends = Folks_Friends::singleton(); + +// Perform action +$user = Util::getGet('user'); +if ($user) { + if ($friends->isFriend($user)) { + $result = $friends->removeFriend($user); + if ($result instanceof PEAR_Error) { + $notification->push($result); + } else { + $notification->push(sprintf(_("User \"%s\" was removed from your friend list."), $user), 'horde.success'); + } + } else { + $result = $friends->addFriend($user); + if ($result instanceof PEAR_Error) { + $notification->push($result); + } elseif ($friends->needsApproval($user)) { + $notification->push(sprintf(_("A confirmation was send to \"%s\"."), $user), 'horde.warning'); + $title = sprintf(_("%s added you as a friend on %s"), + Auth::getAuth(), + $GLOBALS['registry']->get('name', 'horde')); + $body = sprintf(_("User %s added you to his firends list on %s. \nTo approve, go to: %s \nTo reject, go to: %s \nTo see to his profile, go to: %s \n"), + Auth::getAuth(), + $registry->get('name', 'horde'), + Util::addParameter(Horde::applicationUrl('edit/friends/approve.php', true, -1), 'user', Auth::getAuth()), + Util::addParameter(Horde::applicationUrl('edit/friends/reject.php', true, -1), 'user', Auth::getAuth()), + Folks::getUrlFor('user', Auth::getAuth(), true, -1)); + $friends->sendNotification($user, $title, $body); + } else { + $notification->push(sprintf(_("User \"%s\" was added as your friend."), $user), 'horde.success'); + } + } + + header('Location: ' . Horde::applicationUrl('edit/friends/index.php')); + exit; +} + +// Get friends +$list = $friends->getFriends(); +if ($list instanceof PEAR_Error) { + $notification->push($list); + $list = array(); +} + +$form = new Folks_AddFriend_Form($vars, _("Add or remove user"), 'blacklist'); + +Horde::addScriptFile('tables.js', 'horde', true); + +require FOLKS_TEMPLATES . '/common-header.inc'; +require FOLKS_TEMPLATES . '/menu.inc'; + +echo $tabs->render('friends'); +require FOLKS_TEMPLATES . '/edit/friends.php'; + +require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/folks/edit/friends/from.php b/folks/edit/friends/from.php new file mode 100644 index 000000000..1bc6b193c --- /dev/null +++ b/folks/edit/friends/from.php @@ -0,0 +1,46 @@ + + * @package Folks + */ + +require_once dirname(__FILE__) . '/../../lib/base.php'; +require_once FOLKS_BASE . '/lib/Forms/AddFriend.php'; +require_once FOLKS_BASE . '/edit/tabs.php'; + +$title = _("Friends we are waiting approval from"); + +$letter_url = ''; +$profile_img = Horde::img('user.png', '', '', $registry->getImageDir('horde')); +if ($registry->hasInterface('letter')) { + $letter_url = $registry->get('webroot', 'letter') . '/compose.php'; + $letter_img = Horde::img('letter.png', '', '', $registry->getImageDir('letter')); +} + +// Load driver +require_once FOLKS_BASE . '/lib/Friends.php'; +$friends = Folks_Friends::singleton(); + +// Get list +$list = $friends->waitingApprovalFrom(); +if ($list instanceof PEAR_Error) { + $notification->push($list); + $list = array(); +} + +Horde::addScriptFile('tables.js', 'horde', true); + +require FOLKS_TEMPLATES . '/common-header.inc'; +require FOLKS_TEMPLATES . '/menu.inc'; + +echo $tabs->render('friendsof'); +require FOLKS_TEMPLATES . '/edit/friends.php'; + +require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/folks/edit/groups.php b/folks/edit/friends/groups.php similarity index 90% rename from folks/edit/groups.php rename to folks/edit/friends/groups.php index eba47dc21..4d91c0339 100644 --- a/folks/edit/groups.php +++ b/folks/edit/friends/groups.php @@ -11,9 +11,9 @@ * @package Folks */ -define('FOLKS_BASE', dirname(__FILE__) . '/..'); +require_once dirname(__FILE__) . '/../../lib/base.php'; require_once FOLKS_BASE . '/lib/base.php'; -require_once 'tabs.php'; +require_once FOLKS_BASE . '/edit/tabs.php'; $title = _("Groups"); @@ -110,12 +110,14 @@ switch ($action) { break; } -$remove_url = Util::addParameter(Horde::applicationUrl('edit/groups.php'), 'action', 'delete'); +$remove_url = Util::addParameter(Horde::applicationUrl('edit/friends/groups.php'), 'action', 'delete'); $remove_img = Horde::img('delete.png', '', '', $registry->getImageDir('horde')); -$edit_url = Util::addParameter(Horde::applicationUrl('edit/groups.php'), 'action', 'edit'); +$edit_url = Util::addParameter(Horde::applicationUrl('edit/friends/groups.php'), 'action', 'edit'); $edit_img = Horde::img('edit.png', '', '', $registry->getImageDir('horde')); $perms_url = Horde::applicationUrl('perms.php'); $perms_img = Horde::img('perms.png', '', '', $registry->getImageDir('horde')); +$members_url = Horde::applicationUrl('edit/friends/friends.php'); +$members_img = Horde::img('group.png', '', '', $registry->getImageDir('horde')); Horde::addScriptFile('popup.js', 'horde', true); diff --git a/folks/edit/friends.php b/folks/edit/friends/index.php similarity index 77% rename from folks/edit/friends.php rename to folks/edit/friends/index.php index e3362e6b2..e018c6397 100644 --- a/folks/edit/friends.php +++ b/folks/edit/friends/index.php @@ -11,10 +11,9 @@ * @package Folks */ -define('FOLKS_BASE', dirname(__FILE__) . '/..'); -require_once FOLKS_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/../../lib/base.php'; require_once FOLKS_BASE . '/lib/Forms/AddFriend.php'; -require_once 'tabs.php'; +require_once FOLKS_BASE . '/edit/tabs.php'; $title = _("Friends"); $remove_url = Horde::applicationUrl('edit/friends.php'); @@ -66,31 +65,10 @@ if ($user) { } // Get friends -$friend_list = $friends->getFriends(); -if ($friend_list instanceof PEAR_Error) { - $notification->push($friend_list); - $friend_list = array(); -} - -// Get friends we are waiting approval from -$waitingFrom = $friends->waitingApprovalFrom(); -if ($waitingFrom instanceof PEAR_Error) { - $notification->push($waitingFrom); - $waitingFrom = array(); -} - -// Get friends we are waiting approval from -$waitingFor = $friends->waitingApprovalFor(); -if ($waitingFor instanceof PEAR_Error) { - $notification->push($waitingFor); - $waitingFor = array(); -} - -// Get users who have you on friendlist -$possibilities = $friends->getPossibleFriends(); -if ($possibilities instanceof PEAR_Error) { - $notification->push($waiting); - $possibilities = array(); +$list = $friends->getFriends(); +if ($list instanceof PEAR_Error) { + $notification->push($list); + $list = array(); } $form = new Folks_AddFriend_Form($vars, _("Add or remove user"), 'blacklist'); diff --git a/folks/edit/friends/invite.php b/folks/edit/friends/invite.php new file mode 100644 index 000000000..0239ea067 --- /dev/null +++ b/folks/edit/friends/invite.php @@ -0,0 +1,61 @@ + + * @package Folks + */ + +require_once dirname(__FILE__) . '/../../lib/base.php'; +require_once FOLKS_BASE . '/lib/base.php'; +require_once FOLKS_BASE . '/edit/tabs.php'; + +$title = _("Invite friend"); + +// Load driver +require_once FOLKS_BASE . '/lib/Friends.php'; +$friends = Folks_Friends::singleton(); + +// Manage adding groups +$form = new Horde_Form($vars, $title, 'addgroup'); +$translated = Horde::loadConfiguration('groups.php', 'groups', 'folks'); +asort($translated); +$form->addVariable(_("Friend's e-mail"), 'email', 'email', true); +$form->addVariable(_("Subject"), 'subject', 'text', false); +$form->addVariable(_("Body"), 'subject', 'longtext', false); + +if ($form->validate()) { + $form->getInfo(null, $info); + + // Fix title + if (empty($info['subject'])) { + $info['subject'] = sprintf(_("%s Invited to join %s."), Auth::getAuth(), $registry->get('name', 'horde')); + } + + // Add body + $info['body'] = sprintf(_("%s Invited to join %s."), Auth::getAuth(), $registry->get('name', 'horde')) + . ' ' + . sprintf(_("Sign up at %s"), Horde::applicationUrl('account/signup.php', true)); + + $result = Folks::sendMail($info['email'], $info['subject'], $info['body']); + if ($result instanceof PEAR_Error) { + $notification->push($result); + } else { + $notification->push(sprintf(_("Friend \"%s\" was invited to join %s."), $info['email'], $registry->get('name', 'horde')), 'horde.success'); + } +} + +Horde::addScriptFile('popup.js', 'horde', true); + +require FOLKS_TEMPLATES . '/common-header.inc'; +require FOLKS_TEMPLATES . '/menu.inc'; + +echo $tabs->render('friends'); +require FOLKS_TEMPLATES . '/edit/invite.php'; + +require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/folks/edit/friends/of.php b/folks/edit/friends/of.php new file mode 100644 index 000000000..8bf654001 --- /dev/null +++ b/folks/edit/friends/of.php @@ -0,0 +1,46 @@ + + * @package Folks + */ + +require_once dirname(__FILE__) . '/../../lib/base.php'; +require_once FOLKS_BASE . '/lib/Forms/AddFriend.php'; +require_once FOLKS_BASE . '/edit/tabs.php'; + +$title = _("We are friends of"); + +$letter_url = ''; +$profile_img = Horde::img('user.png', '', '', $registry->getImageDir('horde')); +if ($registry->hasInterface('letter')) { + $letter_url = $registry->get('webroot', 'letter') . '/compose.php'; + $letter_img = Horde::img('letter.png', '', '', $registry->getImageDir('letter')); +} + +// Load driver +require_once FOLKS_BASE . '/lib/Friends.php'; +$friends = Folks_Friends::singleton(); + +// Get list +$list = $friends->getPossibleFriends(); +if ($list instanceof PEAR_Error) { + $notification->push($list); + $list = array(); +} + +Horde::addScriptFile('tables.js', 'horde', true); + +require FOLKS_TEMPLATES . '/common-header.inc'; +require FOLKS_TEMPLATES . '/menu.inc'; + +echo $tabs->render('friendsof'); +require FOLKS_TEMPLATES . '/edit/friends.php'; + +require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/folks/edit/reject.php b/folks/edit/friends/reject.php similarity index 81% rename from folks/edit/reject.php rename to folks/edit/friends/reject.php index 6a16ffbf6..3f17323f3 100644 --- a/folks/edit/reject.php +++ b/folks/edit/friends/reject.php @@ -11,8 +11,7 @@ * @package Folks */ -define('FOLKS_BASE', dirname(__FILE__) . '/..'); -require_once FOLKS_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/../../lib/base.php'; require_once FOLKS_BASE . '/lib/Friends.php'; if (!Auth::isAuthenticated()) { @@ -22,7 +21,7 @@ if (!Auth::isAuthenticated()) { $user = Util::getGet('user'); if (empty($user)) { $notification->push(_("You must supply a username.")); - header('Location: ' . Horde::applicationUrl('edit/friends.php')); + header('Location: ' . Horde::applicationUrl('edit/friends/index.php')); exit; } @@ -30,7 +29,7 @@ $friends = Folks_Friends::singleton($conf['friends'], array('user' => $user)); $result = $friends->removeFriend(Auth::getAuth()); if ($result instanceof PEAR_Error) { $notification->push($result); - header('Location: ' . Horde::applicationUrl('edit/friends.php')); + header('Location: ' . Horde::applicationUrl('edit/friends/index.php')); exit; } @@ -47,5 +46,5 @@ $body = sprintf(_("User %s rejected you as a friend on %s.. \nTo see to his prof $friends->sendNotification($user, $title, $body); -header('Location: ' . Horde::applicationUrl('edit/friends.php')); +header('Location: ' . Horde::applicationUrl('edit/friends/index.php')); exit; \ No newline at end of file diff --git a/folks/edit/tabs.php b/folks/edit/tabs.php index fbed6c1a1..6f406f221 100644 --- a/folks/edit/tabs.php +++ b/folks/edit/tabs.php @@ -19,12 +19,13 @@ require_once 'Horde/Variables.php'; $vars = Variables::getDefaultVariables(); $tabs = new Horde_UI_Tabs('what', $vars); -$tabs->addTab(_("Edit my profile"), 'edit.php', 'edit'); -$tabs->addTab(_("Privacy"), 'privacy.php', 'privacy'); -$tabs->addTab(_("Blacklist"), 'blacklist.php', 'blacklist'); -$tabs->addTab(_("Friends"), 'friends.php', 'friends'); -$tabs->addTab(_("Activity"), 'activity.php', 'activity'); -$tabs->addTab(_("Password"), 'password.php', 'password'); +$tabs->addTab(_("Edit my profile"), Horde::applicationUrl('edit.php'), 'edit'); +$tabs->addTab(_("Privacy"), Horde::applicationUrl('edit/privacy.php'), 'privacy'); +$tabs->addTab(_("Blacklist"), Horde::applicationUrl('edit/friends/blacklist.php'), 'blacklist'); +$tabs->addTab(_("Friends"), Horde::applicationUrl('edit/friends/index.php'), 'friends'); +$tabs->addTab(_("Groups"), Horde::applicationUrl('edit/friends/groups.php'), 'groups'); +$tabs->addTab(_("Activity"), Horde::applicationUrl('edit/activity.php'), 'activity'); +$tabs->addTab(_("Password"), Horde::applicationUrl('edit/password.php'), 'password'); if ($conf['comments']['allow'] != 'never' && $registry->hasMethod('forums/doComments')) { diff --git a/folks/lib/Driver.php b/folks/lib/Driver.php index f803b1a8b..241681862 100644 --- a/folks/lib/Driver.php +++ b/folks/lib/Driver.php @@ -201,8 +201,11 @@ class Folks_Driver { { require_once FOLKS_BASE . '/lib/Friends.php'; $friends = Folks_Friends::singleton(null, array('user' => $user)); - - return $friends->getFriends(); + if ($friends) { + return array(); + } else { + return $friends->getFriends(); + } } /** diff --git a/folks/lib/Folks.php b/folks/lib/Folks.php index 3eaaffdb1..ee0e116b5 100644 --- a/folks/lib/Folks.php +++ b/folks/lib/Folks.php @@ -226,18 +226,20 @@ class Folks { { global $conf; - require_once FOLKS_BASE . '/lib/version.php'; - require_once 'Horde/MIME/Mail.php'; + $mail = new Horde_Mime_Mail($subject, $body, $to, $conf['support'], NLS::getCharset()); - $mail = new MIME_Mail($subject, $body, $to, $conf['support'], NLS::getCharset()); + require_once FOLKS_BASE . '/lib/version.php'; $mail->addHeader('User-Agent', 'Folks ' . FOLKS_VERSION); + foreach ($attaches as $file) { if (file_exists($file)) { $mail->addAttachment($file, null, null, NLS::getCharset()); } } - return $mail->send($conf['mailer']['type'], $conf['mailer']['params']); + list($mail_driver, $mail_params) = Horde::getMailerConfig(); + + return $mail->send($mail_driver, $mail_params); } /** @@ -290,11 +292,6 @@ class Folks { $menu->add(Horde::applicationUrl('services.php'), _("Services"), 'horde.png', $img); $menu->add(Horde::applicationUrl('search.php'), _("Search"), 'search.png', $img); $menu->add(self::getUrlFor('list', 'online'), _("List"), 'group.png', $img); - // $menu->add(self::getUrlFor('list', 'list'), _("List"), 'group.png', $img); - // $menu->add(self::getUrlFor('list', 'online'), _("Online"), 'group.png', $img); - // $menu->add(self::getUrlFor('list', 'popularity'), _("Popularity"), 'group.png', $img); - // $menu->add(self::getUrlFor('list', 'activity'), _("Activity"), 'group.png', $img); - // $menu->add(self::getUrlFor('list', 'birthday'), _("Birthday"), 'guest.png', $img); if ($returnType == 'object') { return $menu; diff --git a/folks/lib/Friends.php b/folks/lib/Friends.php index 0cd722450..f3b463fba 100644 --- a/folks/lib/Friends.php +++ b/folks/lib/Friends.php @@ -115,6 +115,19 @@ class Folks_Friends { } /** + * Queries the current object to find out if it supports the given + * capability. + * + * @param string $capability The capability to test for. + * + * @return boolean Whether or not the capability is supported. + */ + public function hasCapability($capability) + { + return !empty($this->_capabilities[$capability]); + } + + /** * Check if a users requies his approval to be added as a friend * * @param string $user Usersame @@ -408,31 +421,33 @@ class Folks_Friends { } /** - * Get user groups - */ - public function getGroups() - { - return array(); - } - - /** - * Delete user friend group + * Get user owning group * - * @param string $group Group to delete + * @param integer Get group ID + * + * @param string Owner */ - public function removeGroup($group) + public function getGroupOwner($group) { - return false; + return $this->_user; } /** - * Add group - * - * @param string $group Group name + * Get user groups */ - public function addGroup($name) + public function getGroups() { - return false; + $groups = $this->_cache->get('folksGroups' . $this->_user, $GLOBALS['conf']['cache']['default_lifetime']); + if ($groups) { + return unserialize($groups); + } else { + $groups = $this->_getGroups(); + if ($groups instanceof PEAR_Error) { + return $groups; + } + $this->_cache->set('folksGroups' . $this->_user, serialize($groups)); + return $groups; + } } /** diff --git a/folks/lib/Friends/application.php b/folks/lib/Friends/application.php index 9f4b6607b..037f2b90c 100644 --- a/folks/lib/Friends/application.php +++ b/folks/lib/Friends/application.php @@ -107,7 +107,7 @@ class Folks_Friends_application extends Folks_Friends { /** * Get avaiable groups */ - public function getGroups() + protected function _getGroups() { if (!$GLOBALS['registry']->hasMethod('getGroups', $this->_params['app'])) { return array(); diff --git a/folks/lib/Friends/shared.php b/folks/lib/Friends/shared.php index 02174bec8..df8678007 100644 --- a/folks/lib/Friends/shared.php +++ b/folks/lib/Friends/shared.php @@ -26,191 +26,47 @@ class Folks_Friends_shared extends Folks_Friends_sql { private $_shares; /** - * friends list ID + * An array of capabilities, so that the driver can report which + * operations it supports and which it doesn't. * - * @var int - */ - private $_whitelist; - - /** - * Black list ID - * - * @var int - */ - 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->_whitelist && $this->_blacklist) { - return; - } - - $GLOBALS['folks_shares'] = Horde_Share::singleton('folks'); - $groups = $GLOBALS['folks_shares']->listShares($this->_user, PERMS_READ); - if ($groups instanceof PEAR_Error) { - return $groups; - } - - foreach ($groups as $id => $group) { - if ($group->get('name') == '__FRIENDS__') { - $this->_whitelist = $group->getId(); - } - } - } - - /** - * Get user blacklist - * - * @return array of users blacklist - */ - protected function _getBlacklist() - { - $this->_getIds(); - - // No blacklist even created - if (empty($this->_blacklist)) { - return array(); - } - - return parent::_getBlacklist(); - } - - /** - * Add user to a blacklist list - * - * @param string $user Usersame - */ - protected function _addBlacklisted($user) - { - $this->_getIds(); - - // Create blacklist - if (empty($this->_blacklist)) { - $group_id = $this->addGroup('_BLACKLIST_', self::BLACKLIST); - if ($group_id instanceof PEAR_Error) { - return $group_id; - } - $this->_blacklist = $group_id; - } - - return parent::_addBlacklisted($user); - } - - /** - * Remove user from blacklist list - * - * @param string $user Usersame - */ - protected function _removeBlacklisted($user) - { - $this->_getIds(); - - if (empty($this->_blacklist)) { - return false; - } - - parent::_removeBlacklisted($user); - } - - /** - * Add user to a friend list - * - * @param string $friend Friend's usersame - * @param string $group Group to add friend to + * @var array */ - protected function _addFriend($friend, $group = null) - { - $this->_getIds(); - - 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); - } - - /** - * 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) - { - $this->_getIds(); - - if (empty($this->_whitelist)) { - return true; - } - - parent::_removeFriend($friend, $group); - } + protected $_capabilities = array('groups_add' => true); /** - * Get user friends + * Get user owning group * - * @param string $group Get friens only from this group + * @param integer Get group ID * - * @return array of users (in group) + * @param string Owner */ - protected function _getFriends($group = null) + public function getGroupOwner($group) { - $this->_getIds(); + $GLOBALS['folks_shares'] = Horde_Share::singleton('folks'); - if (empty($this->_whitelist)) { - return array(); + $share = $GLOBALS['folks_shares']->getShareById($group); + if ($share instanceof PEAR_Error) { + return $share; } - parent::_getFriends($group); + return $share->get('owner'); } /** * Get user groups */ - public function getGroups() + protected function _getGroups() { $GLOBALS['folks_shares'] = Horde_Share::singleton('folks'); + $groups = $GLOBALS['folks_shares']->listShares($this->_user, PERMS_READ); if ($groups instanceof PEAR_Error) { return $groups; } - /** TODO: USE TRANSLATEDN NAMES ??? */ - $list = array(); foreach ($groups as $group) { - if ($group->get('name') == '__FRIENDS__') { - $this->_whitelist = $id; - $list[$group->getId()] = _("Friends"); - } else { - $list[$group->getId()] = $group->get('name'); - } + $list[$group->getId()] = $group->get('name'); } return $list; @@ -274,6 +130,7 @@ class Folks_Friends_shared extends Folks_Friends_sql { $query = 'DELETE FROM ' . $this->_params['friends'] . ' WHERE user_uid = ' . $share->_shareOb->_write_db->quote($this->_user) . ' AND group_id = ' . $share->_shareOb->_write_db->quote($share->getId()); + $result = $share->_shareOb->_write_db->exec($query); if ($result instanceof PEAR_Error) { return $result; diff --git a/folks/lib/Friends/sql.php b/folks/lib/Friends/sql.php index 65d85d515..3b905abac 100644 --- a/folks/lib/Friends/sql.php +++ b/folks/lib/Friends/sql.php @@ -187,7 +187,7 @@ class Folks_Friends_sql extends Folks_Friends { /** * Get user groups */ - public function getGroups() + protected function _getGroups() { return array(_("Whitelist")); } diff --git a/folks/lib/api.php b/folks/lib/api.php index d4506af82..29dc7c099 100644 --- a/folks/lib/api.php +++ b/folks/lib/api.php @@ -202,7 +202,7 @@ function _folks_getFriends($user = null) { require_once dirname(__FILE__) . '/Friends.php'; - $friends = Folks_Friends::singleton(null, array('user' => $user)); + $friends = Folks_Friends::singleton('sql', array('user' => $user)); return $friends->getFriends(); } @@ -218,7 +218,7 @@ function _folks_addFriend($user = null) { require_once dirname(__FILE__) . '/Friends.php'; - $friends = Folks_Friends::singleton(null, array('user' => $user)); + $friends = Folks_Friends::singleton('sql', array('user' => $user)); return $friends->addFriend($user); } @@ -234,7 +234,7 @@ function _folks_removeFriend($user = null) { require_once dirname(__FILE__) . '/Friends.php'; - $friends = Folks_Friends::singleton(null, array('user' => $user)); + $friends = Folks_Friends::singleton('sql', array('user' => $user)); return $friends->removeFriend($user); } @@ -250,7 +250,7 @@ function _folks_getBlacklist($user = null) { require_once dirname(__FILE__) . '/Friends.php'; - $friends = Folks_Friends::singleton(null, array('user' => $user)); + $friends = Folks_Friends::singleton('sql', array('user' => $user)); return $friends->getBlacklist(); } @@ -264,7 +264,7 @@ function _folks_addBlacklisted($user = null) { require_once dirname(__FILE__) . '/Friends.php'; - $friends = Folks_Friends::singleton(null, array('user' => $user)); + $friends = Folks_Friends::singleton('sql', array('user' => $user)); return $friends->addBlacklisted($user); } @@ -278,7 +278,7 @@ function _folks_removeBlacklisted($user = null) { require_once dirname(__FILE__) . '/Friends.php'; - $friends = Folks_Friends::singleton(null, array('user' => $user)); + $friends = Folks_Friends::singleton('sql', array('user' => $user)); return $friends->removeBlacklisted($user); } @@ -294,7 +294,7 @@ function _folks_isBlacklisted($user = null) { require_once dirname(__FILE__) . '/Friends.php'; - $friends = Folks_Friends::singleton(null, array('user' => $user)); + $friends = Folks_Friends::singleton('sql', array('user' => $user)); return $friends->isBlacklisted(Auth::getAuth()); } diff --git a/folks/templates/edit/activity.php b/folks/templates/edit/activity.php index 2aa128ce4..a20a65374 100644 --- a/folks/templates/edit/activity.php +++ b/folks/templates/edit/activity.php @@ -5,7 +5,7 @@ echo $form->renderActive(); if (empty($activities)) { echo ''; return; } ?> @@ -27,7 +27,7 @@ if (empty($activities)) { get('name', $activity['activity_scope']) ?> - + "/> diff --git a/folks/templates/edit/blacklist.php b/folks/templates/edit/blacklist.php deleted file mode 100644 index 055a699c9..000000000 --- a/folks/templates/edit/blacklist.php +++ /dev/null @@ -1,28 +0,0 @@ -
  • '; - echo _("There are no users in your blacklist."); - echo '
  • '; -} else { -?> -

    - - - - - - - - - - - - - - - -
    ' . $user ?>
    - -renderActive(); \ No newline at end of file diff --git a/folks/templates/edit/friends.php b/folks/templates/edit/friends.php index a84f9870f..060021220 100644 --- a/folks/templates/edit/friends.php +++ b/folks/templates/edit/friends.php @@ -1,67 +1,52 @@ + + +

    +
  • '; - echo _("There are no users listed as your friend."); - echo '
  • '; -} else { + +if (empty($list)) { + echo ''; + return true; +} ?> -

    - + +
    + - + - + + + + + + + +
    ' . $user ?> +
    ' . $user ?> +
    + isOnline($user)) { + echo '' . _("Online") . ''; + } else { + echo '' . _("Offline") . ''; + } + ?> + - - - - + + + +
    - -'; -echo $form->renderActive(); - -if (!empty($waitingFrom)) { - echo '

    ' . _("We are waiting this users to approve our friendship") .'

    '; - foreach ($waitingFrom as $user) { - echo ' ' - . '' - . ' ' . $user . ' '; - } -} - -if (!empty($waitingFor)) { - echo '

    ' . _("Users winting us to approve their friendship") .'

    '; - foreach ($waitingFor as $user) { - echo ' ' - . '' - . ' ' . $user . ' ' - . ' ' - . ' ' - . ' ' - . ''; - } -} - -if (!empty($possibilities)) { - echo '

    ' . _("Users that has you listed as a friend") .'

    '; - foreach ($possibilities as $user) { - echo ' ' - . '' - . ' ' . $user . ' '; - } -} diff --git a/folks/templates/edit/groups.php b/folks/templates/edit/groups.php index a34663b18..c59064919 100644 --- a/folks/templates/edit/groups.php +++ b/folks/templates/edit/groups.php @@ -1,20 +1,32 @@ -renderActive(null, null, '', 'post'); ?> +hasCapability('groups_add')) { + echo $form->renderActive(null, null, '', 'post'); +} + +?>

    - +
    - + + $grouo_name) { - echo ''; - echo ''; - echo ''; - echo ''; + +foreach ($groups as $group_id => $group_name) { + echo ''; + $owner = $friends->getGroupOwner($group_id); + echo ''; + echo ''; + if ($friends->hasCapability('groups_add')) { + echo ''; + echo ''; + echo ''; + } echo ''; } ?> diff --git a/folks/templates/edit/invite.php b/folks/templates/edit/invite.php new file mode 100644 index 000000000..5542bf3a7 --- /dev/null +++ b/folks/templates/edit/invite.php @@ -0,0 +1,3 @@ + + +renderActive(null, null, null, 'post')?> \ No newline at end of file diff --git a/folks/templates/edit/tabs.php b/folks/templates/edit/tabs.php new file mode 100644 index 000000000..3af326a2e --- /dev/null +++ b/folks/templates/edit/tabs.php @@ -0,0 +1,35 @@ +

    +
    +
    + +getOnlineUsers(); +if ($online instanceof PEAR_Error) { + return $online; +} + +// Get groups +$groups = $friends->getGroups(); +if ($groups instanceof PEAR_Error) { + $notification->push($groups); + $groups = array(); +} + +$vars = Variables::getDefaultVariables(); +$ftabs = new Horde_UI_Tabs('ftab', $vars); + +$ftabs->addTab(_("All"), Horde::applicationUrl('edit/friends/index.php'), 'all'); +$ftabs->addTab(_("Invite"), Horde::applicationUrl('edit/friends/invite.php'), 'invite'); + +foreach ($groups as $group_id => $group_name) { + $ftabs->addTab($group_name, Horde::applicationUrl('edit/friends/friends.php'), $group_id); +} + +$ftabs->addTab(_("Wainting for"), Horde::applicationUrl('edit/friends/for.php'), 'for'); +$ftabs->addTab(_("Wainting from"), Horde::applicationUrl('edit/friends/from.php'), 'from'); +$ftabs->addTab(_("I am friend of"), Horde::applicationUrl('edit/friends/of.php'), 'of'); + +echo $ftabs->render(); + -- 2.11.0
    ' . $grouo_name . '' . $edit_img . ' ' . _("Rename") . '' . $remove_img . ' ' . _("Delete") . '' . $perms_img . ' ' . _("Permissions") . '
    ' . $group_name . '
    ' . $owner . '
    ' . $members_img . ' ' . _("Members") . '' . $edit_img . ' ' . _("Rename") . '' . $remove_img . ' ' . _("Delete") . '' . $perms_img . ' ' . _("Permissions") . '