grommunio /
grommunio-web
| 1 | <?php |
||
| 2 | // required to handle php errors |
||
| 3 | require_once(__DIR__ . '/exceptions/class.ZarafaErrorException.php'); |
||
| 4 | require_once(__DIR__ . '/download_base.php'); |
||
| 5 | |||
| 6 | /** |
||
| 7 | * DownloadContact |
||
| 8 | * |
||
| 9 | * A class to manage downloading of contact as a file, |
||
| 10 | * it will generate the contact as RFC6350-formatted vCard stream. |
||
| 11 | * It extends the DownloadBase class. |
||
| 12 | */ |
||
| 13 | class DownloadContact extends DownloadBase |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Function get contact-stream using respective mapi function. |
||
| 17 | * It also sends the vcf file to the client. |
||
| 18 | */ |
||
| 19 | function downloadContactAsFile() |
||
| 20 | { |
||
| 21 | if($this->message && $this->store) { |
||
| 22 | // Get addressbook for current session |
||
| 23 | $addrBook = $GLOBALS['mapisession']->getAddressbook(); |
||
| 24 | |||
| 25 | // get message properties. |
||
| 26 | $messageProps = mapi_getprops($this->message, array(PR_DISPLAY_NAME)); |
||
| 27 | |||
| 28 | // Read the contact as RFC6350-formatted vCard stream. |
||
| 29 | $contactStream = mapi_mapitovcf($GLOBALS['mapisession']->getSession(), $addrBook, $this->message, array()); |
||
| 30 | |||
| 31 | $filename = (!empty($messageProps[PR_DISPLAY_NAME])) ? $messageProps[PR_DISPLAY_NAME] : _('Untitled'); |
||
| 32 | $filename .= '.vcf'; |
||
| 33 | |||
| 34 | $this->setNecessaryHeaders($filename, strlen($contactStream)); |
||
| 35 | |||
| 36 | $split = str_split($contactStream, BLOCK_SIZE); |
||
| 37 | foreach ($split as $s) echo $s; |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Generic function to check received data and download vcf file. |
||
| 43 | */ |
||
| 44 | public function download() |
||
| 45 | { |
||
| 46 | // download contact as file |
||
| 47 | $this->downloadContactAsFile(); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | // create instance of class to download message as file |
||
| 52 | $messageInstance = new DownloadContact(); |
||
| 53 | |||
| 54 | try { |
||
| 55 | // initialize variables |
||
| 56 | $messageInstance->init($_GET); |
||
| 57 | |||
| 58 | // download message |
||
| 59 | $messageInstance->download(); |
||
| 60 | } catch (Exception $e) { |
||
| 61 | $messageInstance->handleSaveMessageException($e); |
||
| 62 | } |
||
| 63 | ?> |
||
|
0 ignored issues
–
show
|
|||
| 64 |
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.