2017-02-09 55 views
4

我發現這個global address book插件RoundCubeiRedMail。儘管我使用Windows,但我使用的是hMailServer作爲我的電子郵件服務器。我仍然試過這個插件,並使用默認字段(名稱,電子郵件域名)正常工作。我在表中添加了vcard字段,儘管在文檔中找不到它。我還調整了sql_global_backend.php並添加一些代碼從原來rcube_contacts.php未來:Roundcube-SQL全局地址書籍定製名片

public function get_record($id, $assoc=false) { 
    $db = rcube::get_instance()->db; 
    $db->query('SELECT * FROM global_addressbook WHERE `ID`=?', $id); 
    if ($sql_arr = $db->fetch_assoc()) { 
     // $sql_arr['email'] = explode(',', $sql_arr['email']); // edited 
     $record = $this->convert_db_data($sql_arr);    // edited 
     $this->result = new rcube_result_set(1); 
     $this->result->add($record);       // edited 
    } 

    return $assoc && $record ? $record : $this->result; 

} 

/** 
* Convert data stored in the database into output format 
* Note: this code is originally from rcube_contacts.php 
*/ 
private function convert_db_data($sql_arr) 
{ 

    $record = array(); 
    $record['ID'] = $sql_arr[$this->primary_key]; 

    if ($sql_arr['vcard']) { 
     unset($sql_arr['email']); 
     $vcard = new rcube_vcard($sql_arr['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap); 
     $record += $vcard->get_assoc() + $sql_arr; 
    } 
    else { 
     $record += $sql_arr; 
     $record['email'] = explode(self::SEPARATOR, $record['email']); 
     $record['email'] = array_map('trim', $record['email']); 
    } 

    return $record; 
} 

此代碼使視圖(roundcube的模板)來讀取虛擬卡場。但它不能全部閱讀。

BEGIN:VCARD 
VERSION:3.0 
N:John;Doe;;;        // can read 
FN:John Doe         // can read 
EMAIL;TYPE=INTERNET;TYPE=WORK:[email protected] // can read 
TITLE:Programmer        // can't read 
ORG:John Doe Org        // can't read 
X-DEPARTMENT:Management System Department // can't read 
TEL:09123456789        // can't read 
END:VCARD 

修訂

我的表global_addressbook這個樣子的:

_______________________________________________________________________________________________________________ 
| |   |    |   |   |   |            | 
| ID | name | email  | firstname | surname | domain | vcard          | 
|____|__________|______________|___________|_________|_________|_______________________________________________| 
| |   |    |   |   |   |            | 
| 1 | John Doe | [email protected] | John | doe | doe.com | BEGIN:VCARD         | 
| |   |    |   |   |   | VERSION:3.0         | 
                   | N:John;Doe;;;        | 
                   | FN:John Doe         | 
                   | EMAIL;TYPE=INTERNET;TYPE=WORK:[email protected] | 
                   | TITLE:Programmer        | 
                   | ORG:John Doe Org        | 
                   | X-DEPARTMENT:Management System Department | 
                   | TEL:09123456789        | 
                   | END:VCARD         | 

它看起來像這樣在RoundCube觀點:

enter image description here

+0

你可以發佈convert_db_data()函數中使用的函數rcube_vcard()嗎? –

+0

@KetanMalhotra。代碼幾乎是數千行。我上週剛剛下載了我的'RoundCube',並沒有對它進行重新編碼。如果你可以下載它,你可以看到相同的內容。 –

回答

0

嘗試通過使用export方法提取vcard作爲字符串來嘗試此方法。

private function convert_db_data($sql_arr) { 
    if ($sql_arr['vcard']) { 
     unset($sql_arr['email']); 
     $vcard = new rcube_vcard($sql_arr['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap); 
     $sql_arr['vcard'] = $vcard->export(); 
    } else { 
     unset($sql_arr['vcard']); 
    } 

    return $sql_arr; 
} 
+0

現在只顯示「組」選項卡。現在'Name'和'Display Name'缺失。是否有其他需要重新配置的塊代碼? –

+0

@LekzFlores我認爲我編輯的答案必須是你需要的......! –

+0

無法得到這個工作。 –