Use icons to represent actions
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Thu, 13 Jul 2006 15:39:06 +0000 (15:39 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:34:56 +0000 (00:34 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@94 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/misc.inc.php
banana/post.inc.php
banana/spool.inc.php
css/style.css
img/cancel.gif [new file with mode: 0644]
img/next.gif [new file with mode: 0644]
img/next_thread.gif [new file with mode: 0644]
img/post.gif [new file with mode: 0644]
img/prev.gif [new file with mode: 0644]
img/prev_thread.gif [new file with mode: 0644]
img/reply.gif [new file with mode: 0644]

index d956a0f..9a8307f 100644 (file)
@@ -83,7 +83,7 @@ function makeLink($params)
 /** Format a link to be use in a link
  * @ref makeLink
  */
-function makeHREF($params, $text = null, $popup = null)
+function makeHREF($params, $text = null, $popup = null, $class = null)
 {
     $link = makeLink($params);
     if (is_null($text)) {
@@ -92,11 +92,14 @@ function makeHREF($params, $text = null, $popup = null)
     if (!is_null($popup)) {
         $popup = ' title="' . $popup . '"';
     }
+    if (!is_null($class)) {
+        $class = ' class="' . $class . '"';
+    }
     $target = null;
     if (isset($params['action']) && $params['action'] == 'view') {
         $target = ' target="_blank"';
     }
-    return '<a href="' . htmlentities($link) . $target . '"' . $popup . '>' . $text . '</a>';
+    return '<a href="' . htmlentities($link) . $target . '"' . $popup . $class . '>' . $text . '</a>';
 }
 
 /** Format tree images links
@@ -122,12 +125,22 @@ function makeImg($img, $alt, $height = null, $width = null)
     
     $proto = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
     $host  = $_SERVER['HTTP_HOST'];
-    $file  = dirname($_SERVER['PHP_SELF']) . '/img/' . $img . '.gif';
+    $file  = dirname($_SERVER['PHP_SELF']) . '/img/' . $img;
     $url   = $proto . $host . $file; 
 
     return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
 }
 
+/** Make a link using an image
+ */
+function makeImgLink($params, $img, $alt, $height = null, $width = null, $class = null)
+{
+    return makeHREF($params,
+                    makeImg($img, ' [' . $alt . ']', $height, $width),
+                    $alt,
+                    $class);
+}
+
 /********************************************************************************
  * HTML STUFF
  * Taken from php.net
@@ -365,53 +378,44 @@ function formatFrom($text) {
     return preg_replace("/\\\(\(|\))/","\\1",$result);
 }
 
-function displayshortcuts($first = -1) {
+function displayShortcuts($first = -1)
+{
     global $banana;
     extract($banana->state);
-
+    
     $res  = '<div class="banana_scuts">';
-    $res .= '[' . makeHREF(Array(), _b_('Liste des forums')) . '] ';
-    if (is_null($group)) {
-        return $res.'[' . makeHREF(Array('subscribe' => 1), _b_('Abonnements')) . ']</div>';
+    $res .= '<span class="title"> Profil :</span> ' . makeHREF(Array('subscribe' => 1), _b_('Abonnements'));
+    if (function_exists('hook_shortcuts') && $cstm = hook_shortcuts()) {
+        $res .= ' . ' . $cstm;
     }
-   
-    $res .= '[' . makeHREF(Array('group' => $group), $group) . '] ';
-
-    if (is_null($artid)) {
-        $res .= '[' . makeHREF(Array('group'  => $group,
-                                     'action' => 'new'),
-                               _b_('Nouveau message'))
-              . '] ';
-        if (sizeof($banana->spool->overview)>$banana->tmax) {
-            $res .= '<br />Page : ';
-            $n = intval(log(count($banana->spool->overview), 10))+1;
-            $i = 1;
-            for ($ndx = 1 ; $ndx <= sizeof($banana->spool->overview) ; $ndx += $banana->tmax) {
-                if ($first==$ndx) {
-                    $fmt = $i . ' ';
-                } else {
-                    $fmt = makeHREF(Array('group' => $group,
-                                          'first' => $ndx),
-                                    $i, 
-                                    '%0' . $n . 'u-%0' . $n . 'u')
-                         . ' ';
+    $res .= '<br />';
+    
+    $res .=  '<span class="title">Navigation :</span> '
+         . (is_null($group) ? 'Les forums' : makeHREF(Array(), _b_('Les forums')));
+
+    if (!is_null($group)) {
+        $res .= ' > ' . makeHREF(Array('group' => $group), $group);
+        if (is_null($artid)) {
+            if (sizeof($banana->spool->overview)>$banana->tmax) {
+                $res .= ' > Pages<br />';
+                $n = intval(log(count($banana->spool->overview), 10))+1;
+                $i = 1;
+                for ($ndx = 1 ; $ndx <= sizeof($banana->spool->overview) ; $ndx += $banana->tmax) {
+                    if ($first==$ndx) {
+                        $fmt = $i . ' ';
+                    } else {
+                        $fmt = makeHREF(Array('group' => $group,
+                                              'first' => $ndx),
+                                        $i, 
+                                        '%0' . $n . 'u-%0' . $n . 'u')
+                             . ' ';
+                    }
+                    $i++;
+                    $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)));
                 }
-                $i++;
-                $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)));
             }
-        }
-    } else {
-        $res .= '[' . makeHREF(Array('group'  => $group,
-                                     'artid'  => $artid,
-                                     'action' => 'new'),
-                               _b_('Répondre'))
-              . '] ';
-        if ($banana->post && $banana->post->checkcancel()) {
-            $res .= '[' . makeHREF(Array('group'  => $group,
-                                         'artid'  => $artid,
-                                         'action' => 'cancel'), 
-                                   _b_('Annuler ce message'))
-                  . '] ';
+        } else {
+            $res .= ' > Message';
         }
     }
     return $res.'</div>';
index e02c500..93e36a6 100644 (file)
@@ -315,7 +315,32 @@ class BananaPost
         if (function_exists('hook_checkcancel')) {
             return hook_checkcancel($this->headers);
         }
-        return ($this->headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">");
+        if (!isset($_SESSION)) {
+            return false;
+        }
+        return ($this->headers['from'] == $_SESSION['name'] . ' <' . $_SESSION['mail']. '>');
+    }
+
+    /** Make some links to browse the current newsgroup
+     */
+    function _browser()
+    {
+        global $banana;
+        $ret = '<div class="banana_menu">';
+        $actions = Array('prevThread' => Array('prev_thread', 'Discussion précédente'),
+                         'prevPost'   => Array('prev',        'Article précédent'),
+                         'nextPost'   => Array('next',        'Article suivant'),
+                         'nextThread' => Array('next_thread', 'Discussion suivante'));
+        foreach ($actions as $method=>$params) {
+            $id = $banana->spool->$method($this->id);
+            if (!is_null($id)) {
+                $ret .= makeImgLink(Array('group' => $banana->state['group'],
+                                          'artid' => $id),
+                                    $params[0] . '.gif',
+                                    $params[1]);
+            }
+        }
+        return $ret . '</div>';
     }
 
     /** convert message to html
@@ -352,9 +377,28 @@ class BananaPost
 
         $res  = '<table class="bicol banana_msg" cellpadding="0" cellspacing="0">';
         $res .= '<tr><th colspan="2" class="subject">'
-             . formatdisplayheader('subject', $this->headers['subject'])
-             . '</th></tr>';
-        $res .= '<tr class="pair"><td class="headers"><table cellpadding="0" cellspacing="0">';
+             . $this->_browser()
+             . '<div class="banana_action">'
+             . makeImgLink(Array('group'  => $this->group,
+                                 'action' => 'new'),
+                           'post.gif',
+                           'Nouveau message')
+             . makeImgLink(Array('group'  => $banana->state['group'],
+                                 'artid'  => $this->id,
+                                 'action' => 'new'),
+                           'reply.gif',
+                           'Répondre');
+        if ($this->checkCancel()) {
+            $res .= makeImgLink(Array('group'  => $banana->state['group'],
+                                      'artid'  => $this->id,
+                                      'action' => 'cancel'),
+                                'cancel.gif',
+                                'Annuler');
+        }
+        $res .= '</div>'
+             . formatDisplayHeader('subject', $this->headers['subject'])
+             . '</th></tr>'
+             . '<tr class="pair"><td class="headers"><table cellpadding="0" cellspacing="0">';
 
         foreach ($banana->show_hdr as $hdr) {
             if (isset($this->headers[$hdr])) {
@@ -428,10 +472,6 @@ class BananaPost
             $res .= '</td></tr>';
         }
         
-        $res .= '<tr><th colspan="2">' . _b_('Apercu de ')
-             . makeHREF(Array('group' => $banana->state['group']),
-                        $banana->state['group'])
-             . '</th></tr>';
         $ndx  = $banana->spool->getndx($this->id);
         $res .= '<tr><td class="thrd" colspan="2">'
              . $banana->spool->to_html($ndx-$banana->tbefore, $ndx+$banana->tafter, $ndx)
index 705f4b0..94897b9 100644 (file)
@@ -317,16 +317,16 @@ class BananaSpool
 
     function _to_html($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true)
     {
-        $spfx_f   = makeImg('k1',       'o', 21, 9); 
-        $spfx_n   = makeImg('k2',       '*', 21, 9);
-        $spfx_Tnd = makeImg('T-direct', '+', 21, 12);
-        $spfx_Lnd = makeImg('L-direct', '`', 21, 12);
-        $spfx_snd = makeImg('s-direct', '-', 21, 5);
-        $spfx_T   = makeImg('T',        '+', 21, 12);
-        $spfx_L   = makeImg('L',        '`', 21, 12);
-        $spfx_s   = makeImg('s',        '-', 21, 5);
-        $spfx_e   = makeImg('e',        '&nbsp;', 21, 12);
-        $spfx_I   = makeImg('I',        '|', 21, 12);
+        $spfx_f   = makeImg('k1.gif',       'o', 21, 9); 
+        $spfx_n   = makeImg('k2.gif',       '*', 21, 9);
+        $spfx_Tnd = makeImg('T-direct.gif', '+', 21, 12);
+        $spfx_Lnd = makeImg('L-direct.gif', '`', 21, 12);
+        $spfx_snd = makeImg('s-direct.gif', '-', 21, 5);
+        $spfx_T   = makeImg('T.gif',        '+', 21, 12);
+        $spfx_L   = makeImg('L.gif',        '`', 21, 12);
+        $spfx_s   = makeImg('s.gif',        '-', 21, 5);
+        $spfx_e   = makeImg('e.gif',        '&nbsp;', 21, 12);
+        $spfx_I   = makeImg('I.gif',        '|', 21, 12);
 
         if ($_index + $this->overview[$_id]->desc < $_first || $_index > $_last) {
             return;
@@ -397,10 +397,22 @@ class BananaSpool
     {
         $res  = '<table class="bicol banana_thread" cellpadding="0" cellspacing="0">';
        
+        $new  = '<div class="banana_action">'
+              . makeImgLink(Array('group'  => $this->group,
+                               'action' => 'new'),
+                            'post.gif',
+                            'Nouveau message');
+        $new .= '</div>';
+        
         if (is_null($_ref)) {
             $res .= '<tr><th>'._b_('Date').'</th>';
             $res .= '<th>'._b_('Sujet').'</th>';
-            $res .= '<th>'._b_('Auteur').'</th></tr>';
+            $res .= '<th>'. $new . _b_('Auteur').'</th></tr>';
+        } else {
+            $res .= '<tr><th colspan="3">' . _b_('Aperçu de ')
+                 . makeHREF(Array('group' => $this->group),
+                            $this->group)
+                 . '</th></tr>';
         }
 
         $index = 1;
@@ -420,10 +432,6 @@ class BananaSpool
                  . $banana->groups->to_html()
                  . '</td></tr>';
         }
-        $res .= '<tr><th colspan="3" class="subs">'
-             . makeHREF(Array('subscribe' => 1), _b_('Gérer mes abonnements'))
-             . '</th></tr>';
-
         return $res .= '</table>';
     }
 
@@ -457,6 +465,102 @@ class BananaSpool
         }
         return $ndx;
     }
+
+    /** Return root message of the given thread
+     * @param id INTEGER id of a message
+     */
+     function root($id)
+     {
+        $id_cur = $id;
+        while (true) {
+            $id_parent = $this->overview[$id_cur]->parent;
+            if (is_null($id_parent)) break;
+            $id_cur = $id_parent;
+        }
+        return $id_cur;
+    }
+
+    /** Returns previous thread root index
+     * @param id INTEGER message number
+     */
+    function prevThread($id)
+    {
+        $root = $this->root($id);
+        $last = null;
+        foreach ($this->roots as $i) {
+            if ($i == $root) {
+                return $last;
+            }
+            $last = $i;
+        }
+        return $last;
+    }
+
+    /** Returns next thread root index
+     * @param id INTEGER message number
+     */
+    function nextThread($id)
+    {
+        $root = $this->root($id);
+        $ok   = false;
+        foreach ($this->roots as $i) {
+            if ($ok) {
+                return $i;
+            }
+            if ($i == $root) {
+                $ok = true;
+            }
+        }
+        return null;
+    }
+
+    /** Return prev post in the thread
+     * @param id INTEGER message number
+     */
+    function prevPost($id)
+    {
+        $parent = $this->overview[$id]->parent;
+        if (is_null($parent)) {
+            return null;
+        }
+        $last = $parent;
+        foreach ($this->overview[$parent]->children as $child) {
+            if ($child == $id) {
+                return $last;
+            }
+            $last = $child;
+        }
+        return null;
+    }
+
+    /** Return next post in the thread
+     * @param id INTEGER message number
+     */
+    function nextPost($id)
+    {
+        if (count($this->overview[$id]->children) != 0) {
+            return $this->overview[$id]->children[0];
+        }
+        
+        $cur    = $id;
+        while (true) {
+            $parent = $this->overview[$cur]->parent;
+            if (is_null($parent)) {
+                return null;
+            }
+            $ok = false;
+            foreach ($this->overview[$parent]->children as $child) {
+                if ($ok) {
+                    return $child;
+                }
+                if ($child == $cur) {
+                    $ok = true;
+                }
+            }
+            $cur = $parent;
+        }
+        return null;
+    }
 }
 
 // vim:set et sw=4 sts=4 ts=4
index a9fd064..8cd185d 100644 (file)
@@ -10,6 +10,12 @@ div.banana_scuts {
     text-align: left;
     padding: 0.5em 0em;
 }
+div.banana_scuts .title {
+    font-weight: bold;
+}
+div.banana_action { float: right; }
+div.banana_menu { float: left; }
+
 
 /** GROUP LIST **/
 
diff --git a/img/cancel.gif b/img/cancel.gif
new file mode 100644 (file)
index 0000000..ce4b1fa
Binary files /dev/null and b/img/cancel.gif differ
diff --git a/img/next.gif b/img/next.gif
new file mode 100644 (file)
index 0000000..20eb60b
Binary files /dev/null and b/img/next.gif differ
diff --git a/img/next_thread.gif b/img/next_thread.gif
new file mode 100644 (file)
index 0000000..752b4e1
Binary files /dev/null and b/img/next_thread.gif differ
diff --git a/img/post.gif b/img/post.gif
new file mode 100644 (file)
index 0000000..3aa195e
Binary files /dev/null and b/img/post.gif differ
diff --git a/img/prev.gif b/img/prev.gif
new file mode 100644 (file)
index 0000000..72b5865
Binary files /dev/null and b/img/prev.gif differ
diff --git a/img/prev_thread.gif b/img/prev_thread.gif
new file mode 100644 (file)
index 0000000..f0830ee
Binary files /dev/null and b/img/prev_thread.gif differ
diff --git a/img/reply.gif b/img/reply.gif
new file mode 100644 (file)
index 0000000..3c156c8
Binary files /dev/null and b/img/reply.gif differ