Create a lists of people someone know from user's friends list.
authorDuck (Jakob Munih) <duck@obala.net>
Sun, 22 Feb 2009 13:47:04 +0000 (14:47 +0100)
committerDuck (Jakob Munih) <duck@obala.net>
Sun, 22 Feb 2009 13:47:04 +0000 (14:47 +0100)
Clean up friends list template

folks/edit/friends/blacklist.php
folks/edit/friends/for.php
folks/edit/friends/friends.php
folks/edit/friends/from.php
folks/edit/friends/index.php
folks/edit/friends/of.php
folks/edit/friends/reject.php
folks/lib/Friends.php
folks/lib/Friends/sql.php
folks/templates/edit/friends.php
folks/templates/edit/tabs.php

index ce5267a..2dbd1cc 100644 (file)
@@ -68,9 +68,18 @@ if ($groups instanceof PEAR_Error) {
     $groups = array();
 }
 
-$friend_form = new Folks_AddFriend_Form($vars, _("Add or remove user"), 'blacklist');
+// Prepare actions
+$actions = array(
+    array('url' => Horde::applicationUrl('edit/friends/blacklist.php'),
+          'img' => Horde::img('delete.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Remove")),
+    array('url' => Horde::applicationUrl('user.php'),
+          'img' => Horde::img('user.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Profile")));
 
-Horde::addScriptFile('tables.js', 'horde', true);
+$friend_form = new Folks_AddFriend_Form($vars, _("Add or remove user"), 'blacklist');
 
 require FOLKS_TEMPLATES . '/common-header.inc';
 require FOLKS_TEMPLATES . '/menu.inc';
index f6ee604..16a35e5 100644 (file)
@@ -16,25 +16,37 @@ 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();
+$list = $friends->waitingApprovalFor();
 if ($list instanceof PEAR_Error) {
     $notification->push($list);
     $list = array();
 }
 
-Horde::addScriptFile('tables.js', 'horde', true);
+// Prepare actions
+$actions = array(
+    array('url' => Horde::applicationUrl('user.php'),
+          'img' => Horde::img('user.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Profile")),
+    array('url' => Horde::applicationUrl('edit/friends/approve.php'),
+          'img' => Horde::img('tick.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Approve")),
+    array('url' => Horde::applicationUrl('edit/friends/reject.php'),
+          'img' => Horde::img('cross.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Reject")));
+if ($registry->hasInterface('letter')) {
+    $actions[] = array('url' => Horde::applicationUrl('user.php'),
+                        'img' => Horde::img('letter.png', '', '', $registry->getImageDir('letter')),
+                        'id' => 'user_to',
+                        'name' => $registry->get('name', 'letter'));
+}
 
 require FOLKS_TEMPLATES . '/common-header.inc';
 require FOLKS_TEMPLATES . '/menu.inc';
index 85b1eb5..73c6b9d 100644 (file)
@@ -16,54 +16,11 @@ 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) {
@@ -71,9 +28,22 @@ if ($list instanceof PEAR_Error) {
     $list = array();
 }
 
-$form = new Folks_AddFriend_Form($vars, _("Add or remove user"), 'blacklist');
-
-Horde::addScriptFile('tables.js', 'horde', true);
+// Prepare actions
+$actions = array(
+    array('url' => Horde::applicationUrl('edit/friends/add.php'),
+          'img' => Horde::img('delete.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Remove")),
+    array('url' => Horde::applicationUrl('user.php'),
+          'img' => Horde::img('user.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Profile")));
+if ($registry->hasInterface('letter')) {
+    $actions[] = array('url' => Horde::applicationUrl('user.php'),
+                        'img' => Horde::img('letter.png', '', '', $registry->getImageDir('letter')),
+                        'id' => 'user_to',
+                        'name' => $registry->get('name', 'letter'));
+}
 
 require FOLKS_TEMPLATES . '/common-header.inc';
 require FOLKS_TEMPLATES . '/menu.inc';
index 5140ab3..da9e20f 100644 (file)
@@ -16,13 +16,6 @@ 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();
@@ -34,7 +27,18 @@ if ($list instanceof PEAR_Error) {
     $list = array();
 }
 
-Horde::addScriptFile('tables.js', 'horde', true);
+// Prepare actions
+$actions = array(
+    array('url' => Horde::applicationUrl('user.php'),
+          'img' => Horde::img('user.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Profile")));
+if ($registry->hasInterface('letter')) {
+    $actions[] = array('url' => Horde::applicationUrl('user.php'),
+                        'img' => Horde::img('letter.png', '', '', $registry->getImageDir('letter')),
+                        'id' => 'user_to',
+                        'name' => $registry->get('name', 'letter'));
+}
 
 require FOLKS_TEMPLATES . '/common-header.inc';
 require FOLKS_TEMPLATES . '/menu.inc';
index e6c2584..41ecc08 100644 (file)
 require_once dirname(__FILE__) . '/../../lib/base.php';
 require_once FOLKS_BASE . '/edit/tabs.php';
 
-$title = _("Friends");
-$remove_url = Horde::applicationUrl('edit/friends.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'));
-}
+$title = _("All");
 
 // Load driver
 require_once FOLKS_BASE . '/lib/Friends.php';
@@ -35,7 +27,22 @@ if ($list instanceof PEAR_Error) {
     $list = array();
 }
 
-Horde::addScriptFile('tables.js', 'horde', true);
+// Prepare actions
+$actions = array(
+    array('url' => Horde::applicationUrl('edit/friends/add.php'),
+          'img' => Horde::img('delete.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Remove")),
+    array('url' => Horde::applicationUrl('user.php'),
+          'img' => Horde::img('user.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Profile")));
+if ($registry->hasInterface('letter')) {
+    $actions[] = array('url' => Horde::applicationUrl('user.php'),
+                        'img' => Horde::img('letter.png', '', '', $registry->getImageDir('letter')),
+                        'id' => 'user_to',
+                        'name' => $registry->get('name', 'letter'));
+}
 
 require FOLKS_TEMPLATES . '/common-header.inc';
 require FOLKS_TEMPLATES . '/menu.inc';
index ecebbc5..11a7084 100644 (file)
@@ -16,13 +16,6 @@ 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();
@@ -34,7 +27,18 @@ if ($list instanceof PEAR_Error) {
     $list = array();
 }
 
-Horde::addScriptFile('tables.js', 'horde', true);
+// Prepare actions
+$actions = array(
+    array('url' => Horde::applicationUrl('user.php'),
+          'img' => Horde::img('user.png', '', '', $registry->getImageDir('horde')),
+          'id' => 'user',
+          'name' => _("Profile")));
+if ($registry->hasInterface('letter')) {
+    $actions[] = array('url' => Horde::applicationUrl('user.php'),
+                        'img' => Horde::img('letter.png', '', '', $registry->getImageDir('letter')),
+                        'id' => 'user_to',
+                        'name' => $registry->get('name', 'letter'));
+};
 
 require FOLKS_TEMPLATES . '/common-header.inc';
 require FOLKS_TEMPLATES . '/menu.inc';
index 3f17323..512cb26 100644 (file)
@@ -25,7 +25,7 @@ if (empty($user)) {
     exit;
 }
 
-$friends = Folks_Friends::singleton($conf['friends'], array('user' => $user));
+$friends = Folks_Friends::singleton(null, array('user' => $user));
 $result = $friends->removeFriend(Auth::getAuth());
 if ($result instanceof PEAR_Error) {
     $notification->push($result);
index f3b463f..4b06b28 100644 (file)
@@ -301,8 +301,8 @@ class Folks_Friends {
 
         // Add friend to backend
         $result = $this->_addFriend($friend, $group);
-        if ($friends instanceof PEAR_Error) {
-            return $friends;
+        if ($result instanceof PEAR_Error) {
+            return $result;
         }
 
         // If we do not need an approval just expire cache
@@ -411,7 +411,7 @@ class Folks_Friends {
     }
 
     /**
-     * Get users who have you on friendlist
+     * Get users who have us on their friendlist
      *
      * @return array users
      */
index 3b905ab..39e5c5f 100644 (file)
@@ -91,8 +91,9 @@ class Folks_Friends_sql extends Folks_Friends {
     protected function _addFriend($friend)
     {
         $approve = $this->needsApproval($friend) ? 1 : 0;
+
         $query = 'INSERT INTO ' . $this->_params['friends']
-                . ' (user_uid, friend_uid, friend_ask) VALUES (?, ?, ?, ?)';
+                . ' (user_uid, friend_uid, friend_ask) VALUES (?, ?, ?)';
 
         return $this->_write_db->query($query, array($this->_user, $friend, $approve));
     }
@@ -140,10 +141,10 @@ class Folks_Friends_sql extends Folks_Friends {
     protected function _getFriends()
     {
         $query = 'SELECT friend_uid FROM ' . $this->_params['friends']
-                . ' WHERE user_uid = ?'
+                . ' WHERE user_uid = ? and friend_ask = ?'
                 . ' ORDER BY friend_uid ASC';
 
-        return $this->_db->getCol($query, 0, array($this->_user));
+        return $this->_db->getCol($query, 0, array($this->_user, 0));
     }
 
     /**
index 0600212..0dee0a7 100644 (file)
@@ -22,7 +22,8 @@ if (empty($list)) {
 <?php foreach ($list as $user) { ?>
 <tr>
     <td style="text-align: center">
-        <?php echo '<img src="' . Folks::getImageUrl($user) . '" class="userMiniIcon" /><br />' . $user ?>
+        <?php echo '<a href="' . Folks::getUrlFor('user', $user) . '">'
+                . '<img src="' . Folks::getImageUrl($user) . '" class="userMiniIcon" /><br />' . $user ?></a>
     </td>
     <td>
     <?php
@@ -33,19 +34,14 @@ if (empty($list)) {
         }
     ?>
     </td>
-    <td>
-        <a href="<?php echo Folks::getUrlFor('user', $user) ?>"><?php echo $profile_img  . ' ' . _("View profile") ?></a>
-    </td>
-    <?php if (!empty($remove_url)): ?>
-        <td>
-        <a href="<?php echo Util::addParameter($remove_url, 'user', $user) ?>"><?php echo $remove_img  . ' ' . _("Remove") ?></a>
-        </td>
-    <?php endif; ?>
-    <?php if (!empty($letter_url)): ?>
-        <td>
-            <a href="<?php echo Util::addParameter($letter_url, 'user_to', $user) ?>"><?php echo $letter_img  . ' ' . _("Send message") ?></a>
-        </td>
-    <?php endif; ?>
+    <?php
+        foreach ($actions as $action) {
+            echo '<td>';
+            echo '<a href="' . Util::addParameter($action['url'], $action['id'], $user) . '">'
+                            . $action['img']  . ' ' . $action['name'] . '</a>';
+            echo '</td>';
+        }
+    ?>
 </tr>
 <?php } ?>
 </tbody>
index b471414..1f16753 100644 (file)
@@ -28,6 +28,7 @@ foreach ($groups as $group_id => $group_name) {
     $ftabs->addTab($group_name, Horde::applicationUrl('edit/friends/friends.php'), $group_id);
 }
 
+$ftabs->addTab(_("Might know"), Horde::applicationUrl('edit/friends/know.php'), 'know');
 $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');