简体   繁体   English

Roundcube-SQL-Global-Address-Books自定义vCard

[英]Roundcube-SQL-Global-Address-Books custom vCard

I found this global address book plugin for RoundCube with iRedMail . 我找到了这个带有iRedMail的 RoundCube 全球通讯录插件。 I'm using hMailServer as my e-mail server though since I'm working with Windows. 因为我正在使用Windows,所以我使用hMailServer作为我的电子邮件服务器。 I still tried this plugin and works fine with the default fields ( name , email and domain ). 我仍尝试使用此插件,并使用默认字段( 名称电子邮件 )。 I added vcard field in the table though you can't find it in the documentation. 我在表中添加了vcard字段,但是在文档中找不到它。 I also tweaked the sql_global_backend.php and add some codes coming originally from rcube_contacts.php : 我还调整了sql_global_backend.php并添加了一些最初来自rcube_contacts.php代码:

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;
}

This code enables the view(template of roundcube) to read the vcard field. 此代码使视图(roundcube模板)能够读取vcard字段。 But it can't read all. 但它无法全部阅读。

BEGIN:VCARD
VERSION:3.0
N:John;Doe;;;                                // can read
FN:John Doe                                  // can read
EMAIL;TYPE=INTERNET;TYPE=WORK:john@doe.com   // 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

UPDATED 更新

My table global_addressbook look like this: 我的表global_addressbook看起来像这样:

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

And it look like this in the RoundCube view: 它在RoundCube视图中看起来像这样:

在此输入图像描述

Try this way by extracting vcard as string using the export method. 通过使用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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM