[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * P800/P900/P910: 4 * --------------- 5 * Charset: 6 * This device is able to handle UTF-8 and sends its XML packages in UTF8. 7 * However even though the XML itself is UTF-8, it expects the enclosed 8 * vcard-data to be ISO-8859-1 unless explicitly stated otherwise (using the 9 * CHARSET option, which is deprecated for VCARD 3.0) 10 * 11 * Encoding: 12 * String values are encoded "QUOTED-PRINTABLE" 13 * 14 * Other: 15 * This devices handles tasks and events in one database. 16 * 17 * As the P800 was the first device to work with package, most of the 18 * required conversions are in Device.php's default handling. 19 * 20 * Copyright 2005-2006 Karsten Fourmont <karsten@horde.org> 21 * 22 * See the enclosed file COPYING for license information (LGPL). If you did not 23 * receive this file, see http://www.fsf.org/copyleft/lgpl.html. 24 * 25 * $Horde: framework/SyncML/SyncML/Device/P800.php,v 1.7.2.5 2006/05/01 12:05:14 jan Exp $ 26 * 27 * @author Karsten Fourmont <karsten@horde.org> 28 * @package SyncML 29 */ 30 class SyncML_Device_P800 extends SyncML_Device { 31 32 /** 33 * Convert the content. 34 * 35 * Currently strips uid (primary key) information as client and 36 * server might use different ones. 37 * 38 * @param string $content The content to convert. 39 * @param string $contentType The contentType of the content. 40 * @return array array($newcontent, $newcontentType): 41 * the converted content and the 42 * (possibly changed) new ContentType. 43 */ 44 function convertClient2Server($content, $contentType) 45 { 46 list($content, $contentType) = 47 parent::convertClient2Server($content, $contentType); 48 49 /* P800 sends categories as "X-Category". Remove the "X-": */ 50 $content = preg_replace('/(\r\n|\r|\n)CATEGORIES:X-/', '\1CATEGORIES:', $content, 1); 51 52 /* P800 sends all day events as s.th. like 53 * DTSTART:20050505T000000Z^M 54 * DTEND:20050505T240000Z^M 55 * This is no longer an all day event when converted to local timezone. 56 * So manually handle this. 57 * */ 58 if (preg_match('/(\r\n|\r|\n)DTSTART:.*T000000Z(\r\n|\r|\n)/', 59 $content) 60 && preg_match('/(\r\n|\r|\n)DTEND:(\d\d\d\d)(\d\d)(\d\d)T240000Z(\r\n|\r|\n)/', 61 $content, $m)) { 62 $content = preg_replace('/(\r\n|\r|\n)DTSTART:(.*)T000000Z(\r\n|\r|\n)/', 63 "$1DTSTART;VALUE=DATE:$2$3", $content); 64 /* End timestamp must be converted to next day's date. */ 65 $s = date('Ymd', mktime(0, 0, 0, $m[3], $m[4], $m[2]) + 24*3600); 66 $content = preg_replace('/(\r\n|\r|\n)DTEND:(.*)T240000Z(\r\n|\r|\n)/', 67 "$1DTEND;VALUE=DATE:$s$3", $content); 68 } 69 70 if (DEBUGLOG_ICALENDARDATA) { 71 $fp = @fopen('/tmp/sync/log.txt', 'a'); 72 if ($fp) { 73 @fwrite($fp, "\ninput converted for server: $contentType\n"); 74 @fwrite($fp,$content . "\n"); 75 @fclose($fp); 76 } 77 } 78 79 return array($content, $contentType); 80 } 81 82 /** 83 * Converts the content from the backend to a format suitable for the 84 * client device. 85 * 86 * Strips the uid (primary key) information as client and server might use 87 * different ones. 88 * 89 * @param string $content The content to convert. 90 * @param string $contentType The contentType of content as returned from 91 * the backend. 92 * @return array array($newcontent, $newcontentType): 93 * the converted content and the 94 * (possibly changed) new ContentType. 95 */ 96 function convertServer2Client($content, $contentType) 97 { 98 global $backend; 99 100 list($content, $contentType) = 101 parent::convertServer2Client($content, $contentType); 102 103 /* Convert all day events. */ 104 if (preg_match('/(\r\n|\r|\n)DTSTART;VALUE=DATE:(\d{8})/', 105 $content) 106 && preg_match('/(\r\n|\r|\n)DTEND;VALUE=DATE:(\d\d\d\d)(\d\d)(\d\d)/', 107 $content, $m)) { 108 $content = preg_replace('/(\r\n|\r|\n)DTSTART;VALUE=DATE:(\d{8})/', 109 "$1DTSTART:$2T000000Z", $content); 110 /* End date must be converted to timestamp. */ 111 $s = date('Ymd', mktime(0, 0, 0, $m[3], $m[4], $m[2]) - 24*3600); 112 $content = preg_replace('/(\r\n|\r|\n)DTEND;VALUE=DATE:(\d{8})/', 113 "$1DTEND;:$s}T240000Z", $content); 114 } 115 116 if (DEBUGLOG_ICALENDARDATA) { 117 $fp = @fopen('/tmp/sync/log.txt', 'a'); 118 if ($fp) { 119 @fwrite($fp, "\noutput converted for client ($contentType):\n"); 120 @fwrite($fp, $content . "\n"); 121 @fclose($fp); 122 } 123 } 124 125 return array($content, $contentType); 126 } 127 128 /** 129 * Some devices like the Sony Ericsson P800/P900/P910 handle vtodos (tasks) 130 * and vevents in the same "calendar" sync. 131 * This requires special actions on our side as we store this in different 132 * databases (nag and kronolith). 133 * This function could directly return true but tries to be a bit more 134 * generic so it might work for other phones as well. 135 */ 136 function handleTasksInCalendar() 137 { 138 $di = $this->deviceInfo(); 139 140 if (!empty($di->_CTCap['text/x-vcalendar']['BEGIN']->_ValEnum['VEVENT']) && 141 !empty($di->_CTCap['text/x-vcalendar']['BEGIN']->_ValEnum['VTODO'])) { 142 return true; 143 } 144 145 return parent::handleTasksInCalendar(); 146 } 147 148 function needsCategoryMapping() 149 { 150 // P800 uses numeric category codes. 151 return true; 152 } 153 154 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |