check if valid user exists
[tine20] / tine20 / Calendar / Convert / Event / VCalendar / Factory.php
1 <?php
2 /**
3  * Tine 2.0
4  *
5  * @package     Calendar
6  * @subpackage  Convert
7  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
8  * @author      Lars Kneschke <l.kneschke@metaways.de>
9  * @copyright   Copyright (c) 2011-2013 Metaways Infosystems GmbH (http://www.metaways.de)
10  */
11
12 /**
13  * calendar VCALENDAR converter factory class
14  *
15  * @package     Calendar
16  * @subpackage  Convert
17  */
18 class Calendar_Convert_Event_VCalendar_Factory
19 {
20     const CLIENT_GENERIC     = 'generic';
21     const CLIENT_IPHONE      = 'iphone';
22     const CLIENT_KDE         = 'kde';
23     const CLIENT_MACOSX      = 'macosx';
24     const CLIENT_THUNDERBIRD = 'thunderbird';
25     const CLIENT_EMCLIENT    = 'emclient';
26     const CLIENT_TINE        = 'tine';
27     
28     /**
29      * factory function to return a selected vcalendar backend class
30      *
31      * @param   string $_backend
32      * @param   string $_version
33      * @return  Tinebase_Convert_Interface
34      */
35     static public function factory($_backend, $_version = null)
36     {
37         switch ($_backend) {
38             case Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC:
39                 return new Calendar_Convert_Event_VCalendar_Generic($_version);
40                 break;
41                 
42             case Calendar_Convert_Event_VCalendar_Factory::CLIENT_IPHONE:
43                 return new Calendar_Convert_Event_VCalendar_Iphone($_version);
44                 break;
45                 
46             case Calendar_Convert_Event_VCalendar_Factory::CLIENT_KDE:
47                 return new Calendar_Convert_Event_VCalendar_KDE($_version);
48                 break;
49                 
50             case Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX:
51                 return new Calendar_Convert_Event_VCalendar_MacOSX($_version);
52                 break;
53                 
54             case Calendar_Convert_Event_VCalendar_Factory::CLIENT_THUNDERBIRD:
55                 return new Calendar_Convert_Event_VCalendar_Thunderbird($_version);
56                 break;
57  
58             case Calendar_Convert_Event_VCalendar_Factory::CLIENT_EMCLIENT:
59                 return new Calendar_Convert_Event_VCalendar_EMClient($_version);
60                 break;
61
62             case Calendar_Convert_Event_VCalendar_Factory::CLIENT_TINE:
63                 return new Calendar_Convert_Event_VCalendar_Tine($_version);
64         }
65     }
66     
67     /**
68      * parse useragent and return backend and version
69      * 
70      * @return array
71      */
72     static public function parseUserAgent($_userAgent)
73     {
74         // MacOS X
75         if (preg_match(Calendar_Convert_Event_VCalendar_MacOSX::HEADER_MATCH, $_userAgent, $matches)) {
76             $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX;
77             $version = $matches['version'];
78         
79         // iPhone
80         } elseif (preg_match(Calendar_Convert_Event_VCalendar_Iphone::HEADER_MATCH, $_userAgent, $matches)) {
81             $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_IPHONE;
82             $version = $matches['version'];
83         
84         // KDE
85         } elseif (preg_match(Calendar_Convert_Event_VCalendar_KDE::HEADER_MATCH, $_userAgent, $matches)) {
86             $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_KDE;
87             $version = $matches['version'];
88         
89         // Thunderbird
90         } elseif (preg_match(Calendar_Convert_Event_VCalendar_Thunderbird::HEADER_MATCH, $_userAgent, $matches)) {
91             $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_THUNDERBIRD;
92             $version = $matches['version'];
93         
94         // EMClient
95         } elseif (preg_match(Calendar_Convert_Event_VCalendar_EMClient::HEADER_MATCH, $_userAgent, $matches)) {
96             $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_EMCLIENT;
97             $version = $matches['version'];
98
99         // Tine 2.0
100         } elseif (preg_match(Calendar_Convert_Event_VCalendar_Tine::HEADER_MATCH, $_userAgent, $matches)) {
101             $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_TINE;
102             $version = $matches['version'];
103
104
105         } else {
106             $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC;
107             $version = null;
108         }
109
110         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) 
111             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " $_userAgent ->  backend: $backend version: $version");
112         
113         return array($backend, $version);
114     }
115 }