From f92aba3918575f30f577542753a2912df5729374 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 29 Jul 2008 08:32:19 -0400
Subject: [PATCH] Add microformats to address book + fix html output + codestyle

---
 program/include/html.php           |    8 ++--
 program/steps/addressbook/edit.inc |    2 
 program/steps/addressbook/show.inc |   56 ++++++++++++++-------------
 3 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/program/include/html.php b/program/include/html.php
index 68bc66b..4a79def 100644
--- a/program/include/html.php
+++ b/program/include/html.php
@@ -33,7 +33,7 @@
     protected $content;
 
     public static $common_attrib = array('id','class','style','title','align');
-    public static $containers = array('div','span','p','h1','h2','h3','form','textarea');
+    public static $containers = array('div','span','p','h1','h2','h3','form','textarea','table','tr','th','td');
     public static $lc_tags = true;
 
     /**
@@ -607,10 +607,10 @@
      */
     public function show($attrib = null)
     {
-	if (is_array($attrib))
-    	    $this->attrib = array_merge($this->attrib, $attrib);
+        if (is_array($attrib))
+            $this->attrib = array_merge($this->attrib, $attrib);
         
-	$thead = $tbody = "";
+        $thead = $tbody = "";
 
         // include <thead>
         if (!empty($this->header)) {
diff --git a/program/steps/addressbook/edit.inc b/program/steps/addressbook/edit.inc
index 71983fc..61c660d 100644
--- a/program/steps/addressbook/edit.inc
+++ b/program/steps/addressbook/edit.inc
@@ -90,7 +90,7 @@
   if (!strlen($EDIT_FORM))
     {
     $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
-    $hiddenfields->add(array('name' => '_action', 'value' => 'save', 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
+    $hiddenfields->add(array('name' => '_action', 'value' => 'save'));
     $hiddenfields->add(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
     $hiddenfields->add(array('name' => '_framed', 'value' => (empty($_REQUEST['_framed']) ? 0 : 1)));
     
diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc
index 75f1e74..96ee5bb 100644
--- a/program/steps/addressbook/show.inc
+++ b/program/steps/addressbook/show.inc
@@ -5,7 +5,7 @@
  | program/steps/addressbook/show.inc                                    |
  |                                                                       |
  | This file is part of the RoundCube Webmail client                     |
- | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
+ | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                 |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
@@ -21,50 +21,52 @@
 
 
 // read contact record
-if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true)))
+if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true))) {
   $OUTPUT->set_env('cid', $record['ID']);
-
+}
 
 function rcmail_contact_details($attrib)
-  {
+{
   global $CONTACTS, $OUTPUT;
 
   // check if we have a valid result
-  if (!(($result = $CONTACTS->get_result()) && ($record = $result->first())))
-  {
+  if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
     $OUTPUT->show_message('contactnotfound');
     return false;
   }
   
   // a specific part is requested
-  if ($attrib['part'])
+  if ($attrib['part']) {
     return Q($record[$attrib['part']]);
+  }
 
   // return the complete address record as table
-  $out = "<table>\n\n";
+  $table = new html_table(array('cols' => 2));
 
   $a_show_cols = array('name', 'firstname', 'surname', 'email');
-  foreach ($a_show_cols as $col)
-    {
-    if ($col=='email' && !empty($record[$col]))
-      $value = sprintf(
-        '<a href="#compose" onclick="%s.command(\'compose\', \'%s\')" title="%s">%s</a>',
-        JS_OBJECT_NAME,
-        JQ($record[$col]),
-        rcube_label('composeto'),
-        Q($record[$col]));
-    else
-      $value = Q($record[$col]);
-    
-    $out .= sprintf("<tr><td class=\"title\">%s</td><td>%s</td></tr>\n",
-                    Q(rcube_label($col)),
-                    $value);
+  $microformats = array('name' => 'fn', 'email' => 'email');
+
+  foreach ($a_show_cols as $col) {
+    if ($col == 'email' && !empty($record[$col])) {
+      $value = html::a(array(
+        'href' => 'mailto:' . $record[$col],
+        'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($record[$col])),
+        'title' => rcube_label('composeto'),
+        'class' => $microformats[$col],
+      ), Q($record[$col]));
     }
-  
-  $out .= "\n</table>";
-  
-  return $out;  
+    else if (!empty($record[$col])) {
+      $value = html::span($microformats[$col], Q($record[$col]));
+    }
+    else
+      $value = '';
+    
+    $table->add('title', Q(rcube_label($col)));
+    $table->add(null, $value);
   }
+  
+  return $table->show($attrib + array('class' => 'vcard'));
+}
 
 
 //$OUTPUT->framed = $_framed;

--
Gitblit v1.9.1