Add block template
authorDuck (Jakob Munih) <duck@obala.net>
Mon, 23 Feb 2009 18:57:20 +0000 (19:57 +0100)
committerDuck (Jakob Munih) <duck@obala.net>
Mon, 23 Feb 2009 18:57:20 +0000 (19:57 +0100)
folks/lib/Block/friends.php
folks/lib/Block/new.php
folks/lib/Block/random.php
folks/lib/Block/recent.php
folks/templates/block/users.php [new file with mode: 0644]

index 3a75348..1139a55 100644 (file)
@@ -29,7 +29,7 @@ class Horde_Block_Folks_friends extends Horde_Block {
      */
     function _params()
     {
-        $params = array('display' => array('name' => _("Show friends that are"),
+        return array('display' => array('name' => _("Show friends that are"),
                                             'type' => 'enum',
                                             'default' => 'online',
                                             'values' => array('all' => _("All"),
@@ -58,30 +58,38 @@ class Horde_Block_Folks_friends extends Horde_Block {
             return $users;
         }
 
-        $online = '';
-        $offline = '';
-
-        foreach ($friends as $friend) {
-            if (array_key_exists($friend, $users)) {
-                $online .= '<a href="' . Folks::getUrlFor('user', $friend) . '">' . $friend . '</a> ';
-            } else {
-                $offline .= '<a href="' . Folks::getUrlFor('user', $friend) . '">' . $friend . '</a> ';
+        if (empty($this->_params['display']) || $this->_params['display'] == 'all') {
+            $list = $friends;
+        } else {
+            $list = array();
+            foreach ($friends as $friend) {
+                if ($this->_params['display'] == 'online') {
+                    if (array_key_exists($friend, $users)) {
+                        $list[] = $friend;
+                    }
+                } elseif ($this->_params['display'] == 'offline') {
+                    if (!array_key_exists($friend, $users)) {
+                        $list[] = $friend;
+                    }
+                }
             }
         }
 
-        switch ($this->_params['display']) {
-
-        case 'online':
-            return $online;
-            break;
+        // Prepare actions
+        $actions = array(
+            array('url' => Horde::applicationUrl('user.php'),
+                'id' => 'user',
+                'name' => _("View profile")));
+        if ($GLOBALS['registry']->hasInterface('letter')) {
+            $actions[] = array('url' => $GLOBALS['registry']->callByPackage('letter', 'compose', ''),
+                                'id' => 'user_to',
+                                'name' => _("Send message"));
+        }
 
-        case 'offline':
-            return $offline;
-            break;
+        Horde::addScriptFile('stripe.js', 'horde', true);
 
-        default:
-            return $online . $offline;
-            break;
-        }
+        ob_start();
+        require FOLKS_TEMPLATES . '/block/users.php';
+        return ob_get_clean();
     }
 }
\ No newline at end of file
index cf8b5b4..244abc8 100644 (file)
@@ -48,12 +48,26 @@ class Horde_Block_Folks_new extends Horde_Block {
             return $new;
         }
 
-        $html = '';
+        $list = array();
+        foreach ($new as $u) {
+            $list[] = $u['user_uid'];
+        }
 
-        foreach ($new as $user) {
-            $html .= '<a href="' . Folks::getUrlFor('user', $user['user_uid']) . '">' . $user['user_uid'] . '</a> ';
+        // Prepare actions
+        $actions = array(
+            array('url' => Horde::applicationUrl('user.php'),
+                'id' => 'user',
+                'name' => _("View profile")));
+        if ($GLOBALS['registry']->hasInterface('letter')) {
+            $actions[] = array('url' => $GLOBALS['registry']->callByPackage('letter', 'compose', ''),
+                                'id' => 'user_to',
+                                'name' => _("Send message"));
         }
 
-        return $html;
+        Horde::addScriptFile('stripe.js', 'horde', true);
+
+        ob_start();
+        require FOLKS_TEMPLATES . '/block/users.php';
+        return ob_get_clean();
     }
 }
\ No newline at end of file
index 1582bb3..bf9436a 100644 (file)
@@ -48,17 +48,27 @@ class Horde_Block_Folks_random extends Horde_Block {
     {
         require_once dirname(__FILE__) . '/../base.php';
 
-        $recent = $GLOBALS['folks_driver']->getRandomUsers($this->_params['limit'], $this->_params['online'] == 'online');
-        if ($recent instanceof PEAR_Error) {
-            return $recent;
+        $list = $GLOBALS['folks_driver']->getRandomUsers($this->_params['limit'],
+                                                        $this->_params['online'] == 'online');
+        if ($list instanceof PEAR_Error) {
+            return $list;
         }
 
-        $html = '';
-
-        foreach ($recent as $user) {
-            $html .= '<a href="' . Folks::getUrlFor('user', $user) . '">' . $user . '</a> ';
+        // Prepare actions
+        $actions = array(
+            array('url' => Horde::applicationUrl('user.php'),
+                'id' => 'user',
+                'name' => _("View profile")));
+        if ($GLOBALS['registry']->hasInterface('letter')) {
+            $actions[] = array('url' => $GLOBALS['registry']->callByPackage('letter', 'compose', ''),
+                                'id' => 'user_to',
+                                'name' => _("Send message"));
         }
 
-        return '';
+        Horde::addScriptFile('stripe.js', 'horde', true);
+
+        ob_start();
+        require FOLKS_TEMPLATES . '/block/users.php';
+        return ob_get_clean();
     }
 }
\ No newline at end of file
index df3e016..7a57e85 100644 (file)
@@ -43,17 +43,26 @@ class Horde_Block_Folks_recent extends Horde_Block {
     {
         require_once dirname(__FILE__) . '/../base.php';
 
-        $recent = $GLOBALS['folks_driver']->getRecentVisitors($this->_params['limit']);
-        if ($recent instanceof PEAR_Error) {
-            return $recent;
+        $list = $GLOBALS['folks_driver']->getRecentVisitors($this->_params['limit']);
+        if ($list instanceof PEAR_Error) {
+            return $list;
         }
 
-        $html = '';
-
-        foreach ($recent as $user) {
-            $html .= '<a href="' . Folks::getUrlFor('user', $user) . '">' . $user . '</a>';
+        // Prepare actions
+        $actions = array(
+            array('url' => Horde::applicationUrl('user.php'),
+                'id' => 'user',
+                'name' => _("View profile")));
+        if ($GLOBALS['registry']->hasInterface('letter')) {
+            $actions[] = array('url' => $GLOBALS['registry']->callByPackage('letter', 'compose', ''),
+                                'id' => 'user_to',
+                                'name' => _("Send message"));
         }
 
-        return $html;
+        Horde::addScriptFile('stripe.js', 'horde', true);
+
+        ob_start();
+        require FOLKS_TEMPLATES . '/block/users.php';
+        return ob_get_clean();
     }
 }
\ No newline at end of file
diff --git a/folks/templates/block/users.php b/folks/templates/block/users.php
new file mode 100644 (file)
index 0000000..735a883
--- /dev/null
@@ -0,0 +1,25 @@
+<table class="striped" style="width: 100%">
+<?php foreach ($list as $user): ?>
+<tr valign="top">
+<td>
+<a href="<?php echo Folks::getUrlFor('user', $user) ?>" alt="<?php echo $user ?>" title="<?php echo $user ?>">
+<img src="<?php echo Folks::getImageUrl($user) ?>" class="userMiniIcon" style="float: left" />
+<strong><?php echo $user ?></strong></a><br />
+<span class="small">
+<?php foreach ($actions as $action): ?>
+<a href="<?php echo Util::addParameter($action['url'], $action['id'], $user) ?>"><?php echo $action['name'] ?> </a>
+<?php endforeach; ?>
+<br />
+<?php
+    if ($GLOBALS['folks_driver']->isOnline($user)) {
+        echo '<span class="online">' . _("Online") . '</span>';
+    } else {
+        echo '<span class="offline">' . _("Offline") . '</span>';
+    }
+?>
+
+</span>
+</td>
+</tr>
+<?php endforeach; ?>
+</table>