~ubuntu-branches/ubuntu/vivid/php-horde-icalendar/vivid-proposed

« back to all changes in this revision

Viewing changes to Horde_Icalendar-2.0.7/lib/Horde/Icalendar/Vcard.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2013-08-11 12:33:46 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20130811123346-jvp1p9qn0h6bv61d
Tags: 2.0.7-1
New upstream version 2.0.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Class representing vCard entries.
 
4
 *
 
5
 * Copyright 2003-2013 Horde LLC (http://www.horde.org/)
 
6
 *
 
7
 * See the enclosed file COPYING for license information (LGPL). If you
 
8
 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 
9
 *
 
10
 * @author   Karsten Fourmont <karsten@horde.org>
 
11
 * @category Horde
 
12
 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 
13
 * @package  Icalendar
 
14
 */
 
15
class Horde_Icalendar_Vcard extends Horde_Icalendar
 
16
{
 
17
    // The following were shamelessly yoinked from Contact_Vcard_Build
 
18
    // Part numbers for N components.
 
19
    const N_FAMILY = 0;
 
20
    const N_GIVEN = 1;
 
21
    const N_ADDL = 2;
 
22
    const N_PREFIX = 3;
 
23
    const N_SUFFIX = 4;
 
24
 
 
25
    // Part numbers for ADR components.
 
26
    const ADR_POB = 0;
 
27
    const ADR_EXTEND = 1;
 
28
    const ADR_STREET = 2;
 
29
    const ADR_LOCALITY = 3;
 
30
    const ADR_REGION = 4;
 
31
    const ADR_POSTCODE = 5;
 
32
    const ADR_COUNTRY = 6;
 
33
 
 
34
    // Part numbers for GEO components.
 
35
    const GEO_LAT = 0;
 
36
    const GEO_LON = 1;
 
37
 
 
38
    /**
 
39
     * The component type of this class.
 
40
     *
 
41
     * @var string
 
42
     */
 
43
    public $type = 'vcard';
 
44
 
 
45
    /**
 
46
     * Constructor.
 
47
     */
 
48
    public function __construct($version = '2.1')
 
49
    {
 
50
        parent::__construct($version);
 
51
    }
 
52
 
 
53
    /**
 
54
     * Sets the version of this component.
 
55
     *
 
56
     * @see $version
 
57
     * @see $oldFormat
 
58
     *
 
59
     * @param string  A float-like version string.
 
60
     */
 
61
    public function setVersion($version)
 
62
    {
 
63
        $this->_oldFormat = $version < 3;
 
64
        $this->_version = $version;
 
65
    }
 
66
 
 
67
    /**
 
68
     * Unlike vevent and vtodo, a vcard is normally not enclosed in an
 
69
     * iCalendar container. (BEGIN..END)
 
70
     *
 
71
     * @return TODO
 
72
     */
 
73
    public function exportvCalendar()
 
74
    {
 
75
        $requiredAttributes['VERSION'] = $this->_version;
 
76
        $requiredAttributes['N'] = ';;;;;;';
 
77
        if ($this->_version == '3.0') {
 
78
            $requiredAttributes['FN'] = '';
 
79
        }
 
80
 
 
81
        foreach ($requiredAttributes as $name => $default_value) {
 
82
            try {
 
83
                $this->getAttribute($name);
 
84
            } catch (Horde_Icalendar_Exception $e) {
 
85
                $this->setAttribute($name, $default_value);
 
86
            }
 
87
        }
 
88
 
 
89
        return $this->_exportvData('VCARD');
 
90
    }
 
91
 
 
92
    /**
 
93
     * Returns the contents of the "N" tag as a printable Name:
 
94
     * i.e. converts:
 
95
     *
 
96
     *   N:Duck;Dagobert;T;Professor;Sen.
 
97
     * to
 
98
     *   "Professor Dagobert T Duck Sen"
 
99
     *
 
100
     * @return string  Full name of vcard "N" tag or null if no N tag.
 
101
     */
 
102
    public function printableName()
 
103
    {
 
104
        try {
 
105
            $name_parts = $this->getAttributeValues('N');
 
106
        } catch (Horde_Icalendar_Exception $e) {
 
107
            return null;
 
108
        }
 
109
 
 
110
        $name_arr = array();
 
111
 
 
112
        foreach (array(self::N_PREFIX, self::N_GIVEN, self::N_ADDL, self::N_FAMILY, self::N_SUFFIX) as $val) {
 
113
            if (!empty($name_parts[$val])) {
 
114
                $name_arr[] = $name_parts[$val];
 
115
            }
 
116
        }
 
117
 
 
118
        return implode(' ', $name_arr);
 
119
    }
 
120
 
 
121
    /**
 
122
     * Static function to make a given email address rfc822 compliant.
 
123
     *
 
124
     * @param string $address  An email address.
 
125
     *
 
126
     * @return string  The RFC822-formatted email address.
 
127
     */
 
128
    static function getBareEmail($address)
 
129
    {
 
130
        $ob = new Horde_Mail_Rfc822_Address($address);
 
131
        return $ob->bare_address;
 
132
    }
 
133
 
 
134
}