source: github/program/steps/addressbook/export.inc @ 0203f16

HEADcourier-fixdev-browser-capabilitiespdorelease-0.8
Last change on this file since 0203f16 was 0203f16, checked in by alecpl <alec@…>, 16 months ago
  • Fix duplicate names handling in addressbook searches (#1488375)
  • Property mode set to 100644
File size: 3.6 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/export.inc                                  |
6 |                                                                       |
7 | This file is part of the Roundcube Webmail client                     |
8 | Copyright (C) 2008-2011, The Roundcube Dev Team                       |
9 | Copyright (C) 2011, Kolab Systems AG                                  |
10 |                                                                       |
11 | Licensed under the GNU General Public License version 3 or            |
12 | any later version with exceptions for skins & plugins.                |
13 | See the README file for a full license statement.                     |
14 |                                                                       |
15 | PURPOSE:                                                              |
16 |   Export the selected address book as vCard file                      |
17 |                                                                       |
18 +-----------------------------------------------------------------------+
19 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
20 | Author: Aleksander Machniak <machniak@kolabsys.com>                   |
21 +-----------------------------------------------------------------------+
22
23 $Id$
24
25*/
26
27// Use search result
28if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
29{
30    $sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name');
31    $search  = (array)$_SESSION['search'][$_REQUEST['_search']];
32    $records = array();
33
34    // Get records from all sources
35    foreach ($search as $s => $set) {
36        $source = $RCMAIL->get_address_book($s);
37
38        // reset page
39        $source->set_page(1);
40        $source->set_pagesize(99999);
41        $source->set_search_set($set);
42
43        // get records
44        $result = $source->list_records();
45
46        while ($row = $result->next()) {
47            $row['sourceid'] = $s;
48            $key = rcmail_contact_key($row, $sort_col);
49            $records[$key] = $row;
50        }
51        unset($result);
52    }
53
54    // sort the records
55    ksort($records, SORT_LOCALE_STRING);
56
57    // create resultset object
58    $count  = count($records);
59    $result = new rcube_result_set($count);
60    $result->records = array_values($records);
61}
62// selected directory/group
63else {
64    $CONTACTS = rcmail_contact_source(null, true);
65
66    // get contacts for this user
67    $CONTACTS->set_page(1);
68    $CONTACTS->set_pagesize(99999);
69    $result = $CONTACTS->list_records(null, 0, true);
70}
71
72// send downlaod headers
73header('Content-Type: text/x-vcard; charset='.RCMAIL_CHARSET);
74header('Content-Disposition: attachment; filename="rcube_contacts.vcf"');
75
76while ($result && ($row = $result->next())) {
77    // we already have a vcard record
78    if ($row['vcard'] && $row['name']) {
79        $row['vcard'] = preg_replace('/\r?\n/', rcube_vcard::$eol, $row['vcard']);
80        echo rcube_vcard::rfc2425_fold($row['vcard']) . rcube_vcard::$eol;
81    }
82    // copy values into vcard object
83    else {
84        $vcard = new rcube_vcard();
85        $vcard->extend_fieldmap($CONTACTS->vcard_map);
86        $vcard->load($row['vcard']);
87        $vcard->reset();
88
89        foreach ($row as $key => $values) {
90            list($field, $section) = explode(':', $key);
91            foreach ((array)$values as $value) {
92                if (is_array($value) || strlen($value))
93                    $vcard->set($field, $value, strtoupper($section));
94            }
95        }
96
97        echo $vcard->export(true) . rcube_vcard::$eol;
98    }
99}
100
101exit;
Note: See TracBrowser for help on using the repository browser.