Overview

Packages

  • None
  • SyncMl

Classes

  • Horde_SyncMl
  • Horde_SyncMl_Backend
  • Horde_SyncMl_Backend_Horde
  • Horde_SyncMl_Command
  • Horde_SyncMl_Command_Alert
  • Horde_SyncMl_Command_Final
  • Horde_SyncMl_Command_Get
  • Horde_SyncMl_Command_Map
  • Horde_SyncMl_Command_Put
  • Horde_SyncMl_Command_Replace
  • Horde_SyncMl_Command_Results
  • Horde_SyncMl_Command_Status
  • Horde_SyncMl_Command_Sync
  • Horde_SyncMl_Command_SyncHdr
  • Horde_SyncMl_ContentHandler
  • Horde_SyncMl_DataStore
  • Horde_SyncMl_Device
  • Horde_SyncMl_Device_Nokia
  • Horde_SyncMl_Device_P800
  • Horde_SyncMl_Device_sync4j
  • Horde_SyncMl_Device_Sync4JMozilla
  • Horde_SyncMl_Device_Synthesis
  • Horde_SyncMl_DeviceInfo
  • Horde_SyncMl_Property
  • Horde_SyncMl_PropertyParameter
  • Horde_SyncMl_State
  • Horde_SyncMl_Sync
  • Horde_SyncMl_SyncElement
  • Horde_SyncMl_Translation
  • Horde_SyncMl_XmlOutput
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_SyncMl_Device_Synthesis:: class provides functionality that is
  4:  * specific to the Synthesis.ch SyncML clients.
  5:  *
  6:  * Copyright 2005-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (LGPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 10:  *
 11:  * @author  Karsten Fourmont <karsten@horde.org>
 12:  * @package SyncMl
 13:  */
 14: class Horde_SyncMl_Device_Synthesis extends Horde_SyncMl_Device
 15: {
 16:     /**
 17:      * Converts the content from the backend to a format suitable for the
 18:      * client device.
 19:      *
 20:      * Strips the uid (primary key) information as client and server might use
 21:      * different ones.
 22:      *
 23:      * @param string $content      The content to convert
 24:      * @param string $contentType  The content type of content as returned
 25:      *                             from the backend
 26:      * @param string $database     The server database URI.
 27:      *
 28:      * @return array  Three-element array with the converted content, the
 29:      *                (possibly changed) new content type, and encoding type
 30:      *                (like b64 as used by Funambol).
 31:      */
 32:     public function convertServer2Client($content, $contentType, $database)
 33:     {
 34:         list($content, $contentType, $encodingType) =
 35:             parent::convertServer2Client($content, $contentType, $database);
 36: 
 37:         $di = $GLOBALS['backend']->state->deviceInfo;
 38:         if (stristr($di->Mod,'palm') === false) {
 39:             // Some special priority handling is required. Synthesis uses
 40:             // 1 (high), 2 (medium), 3(low), at least for my windows mobile device.
 41:             // convert these to valid priority settings:
 42:             $content = preg_replace('/(\r\n|\r|\n)PRIORITY:[1-2](\r\n|\r|\n)/', '\1PRIORITY:1\2', $content, 1);
 43:             $content = preg_replace('/(\r\n|\r|\n)PRIORITY:[3](\r\n|\r|\n)/', '\1PRIORITY:2\2', $content, 1);
 44:             $content = preg_replace('/(\r\n|\r|\n)PRIORITY:[4-9](\r\n|\r|\n)/', '\1PRIORITY:3\2', $content, 1);
 45:         }
 46:         // Windows Mobile also expects DUE DATES like DUE:20060419T000000
 47:         if (preg_match('/(\r\n|\r|\n)DUE:(........T......Z)(\r\n|\r|\n)/',
 48:                 $content,$m)) {
 49:             $m[2] = $this->UTC2LocalDate($m[2]);
 50:             $content = preg_replace('/(\r\n|\r|\n)DUE:(........T......Z)(\r\n|\r|\n)/',
 51:                 '\1DUE:' . $m[2] . '\3', $content, 1);
 52:         }
 53: 
 54:         $l = "\noutput converted for client ($contentType):\n" . $content . "\n";
 55:         $GLOBALS['backend']->logFile(Horde_SyncMl_Backend::LOGFILE_DATA, $l);
 56: 
 57:         return array($content, $contentType, $encodingType);
 58:     }
 59: 
 60:     /**
 61:      * Convert the content.
 62:      *
 63:      * @param string $content       The content to convert.
 64:      * @param string $contentType   The contentType of the content.
 65:      * @return array                array($newcontent, $newcontentType):
 66:      *                              the converted content and the
 67:      *                              (possibly changed) new ContentType.
 68:      */
 69:     public function convertClient2Server($content, $contentType)
 70:     {
 71:         list($content, $contentType) =
 72:             parent::convertClient2Server($content, $contentType);
 73: 
 74:         $di = $GLOBALS['backend']->state->deviceInfo;
 75:         if (stristr($di->Mod, 'palm') === false) {
 76:             // Some special priority handling is required. Synthesis uses 1
 77:             // (high), 2 (medium), 3(low), at least for my windows mobile
 78:             // device.  convert these to valid priority settings:
 79:             $content = preg_replace('/(\r\n|\r|\n)PRIORITY:3(\r\n|\r|\n)/',
 80:                                     '\1PRIORITY:5\2', $content, 1);
 81:             $content = preg_replace('/(\r\n|\r|\n)PRIORITY:2(\r\n|\r|\n)/',
 82:                                     '\1PRIORITY:3\2', $content, 1);
 83:         }
 84: 
 85:         $GLOBALS['backend']->logFile(
 86:             Horde_SyncMl_Backend::LOGFILE_DATA,
 87:             "\ninput converted for server ($contentType):\n$content\n");
 88: 
 89:         return array($content, $contentType);
 90: 
 91:     }
 92: 
 93: 
 94:     /* Static helper function: converts a UTC Timestamp like 20060418T220000Z
 95:      * into a local date like 20060419T000000. This is actually more than
 96:      * stripping the time part: we need to convert to local time first to ensure
 97:      * we get the right date!
 98:      */
 99:     public function UTC2LocalDate($s)
100:     {
101:         $date = new Horde_Date($s);
102:         $date->setTimezone(date_default_timezone_get());
103:         return $date->format('Ymd') . 'T000000';
104:     }
105: }
106: 
API documentation generated by ApiGen