convertServer2Client() public method

Strips the UID (primary key) information as client and server might use different ones. Charset conversions might be added here too.
public convertServer2Client ( string $content, string $contentType, string $database ) : array
$content string The content to convert
$contentType string The content type of content as returned from the backend
$database string The server database URI.
return array Three-element array with the converted content, the (possibly changed) new content type, and encoding type (like b64 as used by Funambol).
Esempio n. 1
0
 /**
  * Converts the content from the backend to a format suitable for the
  * client device.
  *
  * Strips the UID (primary key) information as client and server might use
  * different ones.
  *
  * Charset conversions might be added here too.
  *
  * @param string $content      The content to convert
  * @param string $contentType  The content type of content as returned
  *                             from the backend
  * @param string $database     The server database URI.
  *
  * @return array  Three-element array with the converted content, the
  *                (possibly changed) new content type, and encoding type
  *                (like b64 as used by Funambol).
  */
 public function convertServer2Client($content, $contentType, $database)
 {
     $database = $GLOBALS['backend']->normalize($database);
     list($content, $contentType, $encodingType) = parent::convertServer2Client($content, $contentType, $database);
     $content = preg_replace('/(\\r\\n|\\r|\\n)PHOTO;ENCODING=b[^:]*:(.+?)(\\r\\n|\\r|\\n)/', '\\1PHOTO;ENCODING=BASE64:\\1\\2\\1\\1', $content, 1);
     $GLOBALS['backend']->logFile(Horde_SyncMl_Backend::LOGFILE_DATA, "\nOutput converted for client ({$contentType}):\n{$content}\n");
     return array($content, $contentType, null);
 }
Esempio n. 2
0
 /**
  * Converts the content from the backend to a format suitable for the
  * client device.
  *
  * Strips the uid (primary key) information as client and server might use
  * different ones.
  *
  * @param string $content      The content to convert
  * @param string $contentType  The content type of content as returned
  *                             from the backend
  * @param string $database     The server database URI.
  *
  * @return array  Three-element array with the converted content, the
  *                (possibly changed) new content type, and encoding type
  *                (like b64 as used by Funambol).
  */
 public function convertServer2Client($content, $contentType, $database)
 {
     $database = $GLOBALS['backend']->normalize($database);
     list($content, $contentType, $encodingType) = parent::convertServer2Client($content, $contentType, $database);
     if ($this->requestedContentType == $contentType) {
         if ($contentType == 'text/calendar' || $contentType == 'text/x-vcalendar') {
             $si = $GLOBALS['backend']->state->sourceURI;
             if (stristr($si, 'fol-') !== false) {
                 // The Funambol Outlook connector uses invalid STATUS
                 // values. Actually it maps MeetingStatus values of the
                 // Outlook event to the STATUS property, which is
                 // completely useless. So drop the STATUS altogether.
                 $content = preg_replace('/^STATUS:.*\\r?\\n/im', '', $content);
             }
         }
         return array($content, $contentType, $encodingType);
     }
     switch ($contentType) {
         case 'text/calendar':
         case 'text/x-vcalendar':
             switch ($database) {
                 case 'calendar':
                     $content = Horde_SyncMl_Device_sync4j::vevent2sif($content);
                     $content = base64_encode($content);
                     $contentType = 'text/x-s4j-sife';
                     break 2;
                 case 'tasks':
                     $content = Horde_SyncMl_Device_sync4j::vtodo2sif($content);
                     $content = base64_encode($content);
                     $contentType = 'text/x-s4j-sift';
                     break 2;
             }
             break;
         case 'text/x-vcard':
             $content = Horde_SyncMl_Device_sync4j::vcard2sif($content);
             $content = base64_encode($content);
             $contentType = 'text/x-s4j-sifc';
             break;
         case 'text/x-vnote':
         case 'text/plain':
             $content = Horde_SyncMl_Device_sync4j::vnote2sif($content);
             $content = base64_encode($content);
             $contentType = 'text/x-s4j-sifn';
             break;
     }
     $l = "\nOutput converted for client ({$contentType}):\n" . base64_decode($content) . "\n";
     $GLOBALS['backend']->logFile(Horde_SyncMl_Backend::LOGFILE_DATA, $l);
     return array($content, $contentType, 'b64');
 }
Esempio n. 3
0
 /**
  * Converts the content from the backend to a format suitable for the
  * client device.
  *
  * Strips the uid (primary key) information as client and server might use
  * different ones.
  *
  * @param string $content      The content to convert
  * @param string $contentType  The content type of content as returned
  *                             from the backend
  * @param string $database     The server database URI.
  *
  * @return array  Three-element array with the converted content, the
  *                (possibly changed) new content type, and encoding type
  *                (like b64 as used by Funambol).
  */
 public function convertServer2Client($content, $contentType, $database)
 {
     list($content, $contentType, $encodingType) = parent::convertServer2Client($content, $contentType, $database);
     /* Convert all day events. */
     if (preg_match('/(\\r\\n|\\r|\\n)DTSTART:(\\d{8})T000000/', $content) && preg_match('/(\\r\\n|\\r|\\n)DTEND:(\\d\\d\\d\\d)(\\d\\d)(\\d\\d)T235959/', $content, $m)) {
         /* @TODO: This is for P990. Check if it's different for P900.
          * This might require T000000Z rather than T000000 */
         /* The P990 seems to require this to recognize an entry as all day: */
         $a = $m[1] . 'X-EPOCAGENDAENTRYTYPE:EVENT';
         $content = preg_replace('/(\\r\\n|\\r|\\n)DTSTART:(\\d{8})T000000/', "{$a}\$1DTSTART:\$2T000000", $content);
         /* End date must be converted to timestamp. */
         $s = date('Ymd', mktime(0, 0, 0, $m[3], $m[4] + 1, $m[2]));
         $content = preg_replace('/(\\r\\n|\\r|\\n)DTEND:(\\d{8})T235959/', "\$1DTEND:{$s}T000000", $content);
     }
     $l = "\noutput converted for client ({$contentType}):\n" . $content . "\n";
     $GLOBALS['backend']->logFile(Horde_SyncMl_Backend::LOGFILE_DATA, $l);
     return array($content, $contentType, $encodingType);
 }
Esempio n. 4
0
 /**
  * Converts the content from the backend to a format suitable for the
  * client device.
  *
  * Strips the uid (primary key) information as client and server might use
  * different ones.
  *
  * @param string $content      The content to convert
  * @param string $contentType  The content type of content as returned
  *                             from the backend
  * @param string $database     The server database URI.
  *
  * @return array  Three-element array with the converted content, the
  *                (possibly changed) new content type, and encoding type
  *                (like b64 as used by Funambol).
  */
 public function convertServer2Client($content, $contentType, $database)
 {
     list($content, $contentType, $encodingType) = parent::convertServer2Client($content, $contentType, $database);
     /* The plugin does currently not handle lines that are both folded
      * and QUOTED-PRINTABLE encoded. Like this one with a note "abc":
      * NOTE;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:=
      * a=
      * bc
      */
     if (preg_match_all('/\\r\\n[^:]*ENCODING=QUOTED-PRINTABLE[^:]*:.*?=\\r\\n.*?[^=](?=\\r\\n)/mis', $content, $m)) {
         foreach ($m[0] as $v) {
             /* Remove line folding */
             $content = str_replace($v, str_replace("=\r\n", '', $v), $content);
         }
     }
     $l = "\noutput converted for client ({$contentType}):\n" . $content . "\n";
     $GLOBALS['backend']->logFile(Horde_SyncMl_Backend::LOGFILE_DATA, $l);
     return array($content, $contentType, $encodingType);
 }
Esempio n. 5
0
 /**
  * Converts the content from the backend to a format suitable for the
  * client device.
  *
  * Strips the uid (primary key) information as client and server might use
  * different ones.
  *
  * @param string $content      The content to convert
  * @param string $contentType  The content type of content as returned
  *                             from the backend
  * @param string $database     The server database URI.
  *
  * @return array  Three-element array with the converted content, the
  *                (possibly changed) new content type, and encoding type
  *                (like b64 as used by Funambol).
  */
 public function convertServer2Client($content, $contentType, $database)
 {
     list($content, $contentType, $encodingType) = parent::convertServer2Client($content, $contentType, $database);
     $di = $GLOBALS['backend']->state->deviceInfo;
     if (stristr($di->Mod, 'palm') === false) {
         // Some special priority handling is required. Synthesis uses
         // 1 (high), 2 (medium), 3(low), at least for my windows mobile device.
         // convert these to valid priority settings:
         $content = preg_replace('/(\\r\\n|\\r|\\n)PRIORITY:[1-2](\\r\\n|\\r|\\n)/', '\\1PRIORITY:1\\2', $content, 1);
         $content = preg_replace('/(\\r\\n|\\r|\\n)PRIORITY:[3](\\r\\n|\\r|\\n)/', '\\1PRIORITY:2\\2', $content, 1);
         $content = preg_replace('/(\\r\\n|\\r|\\n)PRIORITY:[4-9](\\r\\n|\\r|\\n)/', '\\1PRIORITY:3\\2', $content, 1);
     }
     // Windows Mobile also expects DUE DATES like DUE:20060419T000000
     if (preg_match('/(\\r\\n|\\r|\\n)DUE:(........T......Z)(\\r\\n|\\r|\\n)/', $content, $m)) {
         $m[2] = $this->UTC2LocalDate($m[2]);
         $content = preg_replace('/(\\r\\n|\\r|\\n)DUE:(........T......Z)(\\r\\n|\\r|\\n)/', '\\1DUE:' . $m[2] . '\\3', $content, 1);
     }
     $l = "\noutput converted for client ({$contentType}):\n" . $content . "\n";
     $GLOBALS['backend']->logFile(Horde_SyncMl_Backend::LOGFILE_DATA, $l);
     return array($content, $contentType, $encodingType);
 }