diff --git a/.idea/dictionaries/osboxes.xml b/.idea/dictionaries/osboxes.xml new file mode 100644 index 0000000..cfd3f23 --- /dev/null +++ b/.idea/dictionaries/osboxes.xml @@ -0,0 +1,17 @@ + + + + caldesc + calendarimporter + filepath + ical + importattachment + kopano + mapi + mapisession + storeid + uids + vtimezone + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f000ac4..e3ee7ea 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,31 +2,8 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -47,22 +24,24 @@ - - + + - - + + - - + + - - - + + + + + @@ -70,47 +49,46 @@ - - + + - - - - + - - + + - - + + - - + + - - + + - + - - + + - - - + + + + + @@ -136,27 +114,30 @@ @@ -171,10 +152,10 @@ - @@ -202,6 +183,7 @@ + @@ -220,6 +202,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + @@ -356,22 +387,22 @@ - - + - + - @@ -382,6 +413,7 @@ + @@ -404,6 +436,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -424,7 +480,6 @@ - @@ -433,7 +488,7 @@ - + @@ -442,7 +497,6 @@ - @@ -458,7 +512,6 @@ - @@ -466,7 +519,6 @@ - @@ -474,7 +526,6 @@ - @@ -482,7 +533,6 @@ - @@ -498,7 +548,6 @@ - @@ -506,7 +555,6 @@ - @@ -515,7 +563,7 @@ - + @@ -524,7 +572,6 @@ - @@ -553,7 +600,6 @@ - @@ -569,7 +615,6 @@ - @@ -585,7 +630,6 @@ - @@ -593,7 +637,6 @@ - @@ -609,19 +652,6 @@ - - - - - - - - - - - - - @@ -637,9 +667,6 @@ - - - @@ -647,7 +674,6 @@ - @@ -655,7 +681,6 @@ - @@ -664,7 +689,6 @@ - @@ -678,87 +702,110 @@ - + - - + + + + + + + + + - + - - - - - + + + + + + + + + + - - + + - - + + - + - + - - - + + + + + - + - - - + + + + + - - + + - - - - + - + - - + + - + - - + + + + + + + + + + + + \ No newline at end of file diff --git a/js/data/Actions.js b/js/data/Actions.js index f52f6d2..3274c47 100644 --- a/js/data/Actions.js +++ b/js/data/Actions.js @@ -34,6 +34,58 @@ Ext.namespace('Zarafa.plugins.calendarimporter.data'); * @singleton */ Zarafa.plugins.calendarimporter.data.Actions = { + /** + * Generates a request to download the selected records as vCard. + * + * @param storeId + * @param recordIds + */ + exportToICS: function (storeId, recordIds, recordFolder) { + if ((typeof recordIds != "undefined" && recordIds.length < 1) || (typeof recordFolder != "undefined" && recordFolder.get('content_count') < 1)) { + Zarafa.common.dialogs.MessageBox.show({ + title: dgettext('plugin_calendarimporter', 'Error'), + msg: dgettext('plugin_calendarimporter', 'No events found. Export skipped!'), + icon: Zarafa.common.dialogs.MessageBox.ERROR, + buttons: Zarafa.common.dialogs.MessageBox.OK + }); + } else { + + var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({ + successCallback: Zarafa.plugins.calendarimporter.data.Actions.downloadICS + }); + + var recordcount = 0; + var exportPayload = { + storeid: storeId, + records: undefined, + folder: undefined + }; + + if (typeof recordIds != "undefined") { + exportPayload.records = recordIds; + recordcount = recordIds.length; + } + + if (typeof recordFolder != "undefined") { + exportPayload.folder = recordFolder.get("entryid"); + recordcount = recordFolder.get('content_count'); + } + + // Notify user + // # TRANSLATORS: {0} will be replaced by the number of contacts that will be exported + container.getNotifier().notify('info', dgettext('plugin_contactimporter', 'Calendar Export'), String.format(dgettext('plugin_calendarimporter', 'Exporting {0} events. Please wait...'), recordcount)); + + + // request attachment preperation + container.getRequest().singleRequest( + 'calendarmodule', + 'export', + exportPayload, + responseHandler + ); + } + }, + /** * Callback for the export request. * @param {Object} response diff --git a/js/dialogs/ImportPanel.js b/js/dialogs/ImportPanel.js index bda38c6..14e6060 100644 --- a/js/dialogs/ImportPanel.js +++ b/js/dialogs/ImportPanel.js @@ -432,7 +432,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { this.submitAllButton.disable(); Zarafa.common.dialogs.MessageBox.show({ title: _('Error'), - msg: _(action.result.error), + msg: action.result.error, icon: Zarafa.common.dialogs.MessageBox.ERROR, buttons: Zarafa.common.dialogs.MessageBox.OK }); diff --git a/js/plugin.calendarimporter.js b/js/plugin.calendarimporter.js index 2e751ae..a5838f1 100644 --- a/js/plugin.calendarimporter.js +++ b/js/plugin.calendarimporter.js @@ -95,26 +95,7 @@ Zarafa.plugins.calendarimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, { recordIds.push(btn.records[i].get("entryid")); } - var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({ - successCallback: Zarafa.plugins.calendarimporter.data.Actions.downloadICS, - scope: this - }); - - // Notify user - // # TRANSLATORS: {0} will be replaced by the number of contacts that will be exported - container.getNotifier().notify('info', dgettext('plugin_contactimporter', 'Calendar Export'), String.format(dgettext('plugin_calendarimporter', 'Exporting {0} events. Please wait...'), recordIds.length)); - - - // request attachment preperation - container.getRequest().singleRequest( - 'calendarmodule', - 'export', - { - storeid: btn.records[0].get("store_entryid"), - records: recordIds - }, - responseHandler - ); + Zarafa.plugins.calendarimporter.data.Actions.exportToICS(btn.records[0].get("store_entryid"), recordIds, undefined); }, /** diff --git a/js/ui/ContextMenu.js b/js/ui/ContextMenu.js index 3eb82da..d8bee7e 100644 --- a/js/ui/ContextMenu.js +++ b/js/ui/ContextMenu.js @@ -94,25 +94,7 @@ Zarafa.plugins.calendarimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui. * @private */ onContextItemExport: function () { - var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({ - successCallback: Zarafa.plugins.calendarimporter.data.Actions.downloadICS, - scope: this - }); - - // Notify user - // # TRANSLATORS: {0} will be replaced by the number of contacts that will be exported - container.getNotifier().notify('info', dgettext('plugin_contactimporter', 'Calendar Export'), String.format(dgettext('plugin_calendarimporter', 'Exporting {0} events. Please wait...'), this.records.get('content_count'))); - - // request attachment preperation - container.getRequest().singleRequest( - 'calendarmodule', - 'export', - { - storeid: this.records.get("store_entryid"), - folder: this.records.get("entryid") - }, - responseHandler - ); + Zarafa.plugins.calendarimporter.data.Actions.exportToICS(this.records.get("store_entryid"), undefined, this.records); }, /** diff --git a/php/download.php b/php/download.php index 75829ef..12be79c 100644 --- a/php/download.php +++ b/php/download.php @@ -1,5 +1,4 @@ + * Copyright (C) 2012-2016 Christoph Haas + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + + +namespace calendarimporter; + + +class Helper +{ + /** + * Generates a random string with variable length. + * + * @param $length the lenght of the generated string, defaults to 6 + * @return string a random string + */ + public static function randomstring($length = 6) + { + // $chars - all allowed charakters + $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + + srand((double)microtime() * 1000000); + $i = 0; + $pass = ""; + while ($i < $length) { + $num = rand() % strlen($chars); + $tmp = substr($chars, $num, 1); + $pass = $pass . $tmp; + $i++; + } + return $pass; + } + + /** + * respond/echo JSON + * + * @param $arr + * @return string JSON encoded string + */ + public static function respondJSON($arr) + { + echo json_encode($arr); + } +} \ No newline at end of file diff --git a/php/module.calendar.php b/php/module.calendar.php index 7a4e3cc..80da133 100644 --- a/php/module.calendar.php +++ b/php/module.calendar.php @@ -21,20 +21,22 @@ * */ -include_once('vendor/autoload.php'); +include_once(__DIR__ . "/vendor/autoload.php"); +include_once(__DIR__ . "/helper.php"); use Sabre\VObject; +use calendarimporter\Helper; class CalendarModule extends Module { private $DEBUG = false; // enable error_log debugging - private $busystates = null; + private $busyStates = null; private $labels = null; - private $attendeetype = null; + private $attendeeType = null; /** * @constructor @@ -49,7 +51,7 @@ class CalendarModule extends Module date_default_timezone_set(PLUGIN_CALENDARIMPORTER_DEFAULT_TIMEZONE); // init mappings - $this->busystates = array( + $this->busyStates = array( "FREE", "TENTATIVE", "BUSY", @@ -70,7 +72,7 @@ class CalendarModule extends Module "PHONE INTERVIEW" ); - $this->attendeetype = array( + $this->attendeeType = array( "NON-PARTICIPANT", // needed as zarafa starts counting at 1 "REQ-PARTICIPANT", "OPT-PARTICIPANT", @@ -81,6 +83,7 @@ class CalendarModule extends Module /** * Executes all the actions in the $data variable. * Exception part is used for authentication errors also + * * @return boolean true on success or false on failure. */ public function execute() @@ -130,58 +133,44 @@ class CalendarModule extends Module return $result; } - /** - * Generates a random string with variable length. - * @param $length the lenght of the generated string - * @return string a random string - */ - private function randomstring($length = 6) - { - // $chars - all allowed charakters - $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; - - srand((double)microtime() * 1000000); - $i = 0; - $pass = ""; - while ($i < $length) { - $num = rand() % strlen($chars); - $tmp = substr($chars, $num, 1); - $pass = $pass . $tmp; - $i++; - } - return $pass; - } - /** * Get a property from the array. + * * @param $props - * @param $propname + * @param $propName * @return string */ - private function getProp($props, $propname) + private function getProp($props, $propName) { - if (isset($props["props"][$propname])) { - return $props["props"][$propname]; + if (isset($props["props"][$propName])) { + return $props["props"][$propName]; } return ""; } - private function getDurationStringFromMintues($minutes, $pos = false) + /** + * Get a duration string form given minutes + * + * @param $minutes + * @param bool $pos + * @return string + */ + private function getDurationStringFromMinutes($minutes, $pos = false) { $pos = $pos === true ? "+" : "-"; $str = $pos . "P"; // variables for holding values - $mins = intval($minutes); + $min = intval($minutes); $hours = 0; $days = 0; $weeks = 0; // calculations - if ($mins >= 60) { - $hours = (int)($mins / 60); - $mins = $mins % 60; + if ($min >= 60) { + $hours = (int)($min / 60); + $min = $min % 60; } if ($hours >= 24) { $days = (int)($hours / 24); @@ -202,8 +191,8 @@ class CalendarModule extends Module if ($hours) { $str .= "{$hours}H"; } - if ($mins) { - $str .= "{$mins}M"; + if ($min) { + $str .= "{$min}M"; } return $str; @@ -211,15 +200,16 @@ class CalendarModule extends Module /** * The main export function, creates the ics file for download + * * @param $actionType * @param $actionData */ private function exportCalendar($actionType, $actionData) { // Get store id - $storeid = false; + $storeId = false; if (isset($actionData["storeid"])) { - $storeid = $actionData["storeid"]; + $storeId = $actionData["storeid"]; } // Get records @@ -239,17 +229,17 @@ class CalendarModule extends Module $error_msg = ""; // write csv - $token = $this->randomstring(16); + $token = Helper::randomstring(16); $file = PLUGIN_CALENDARIMPORTER_TMP_UPLOAD . "ics_" . $token . ".ics"; file_put_contents($file, ""); - $store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid)); + $store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeId)); if ($store) { // load folder first if ($folder !== false) { - $mapifolder = mapi_msgstore_openentry($store, hex2bin($folder)); + $mapiFolder = mapi_msgstore_openentry($store, hex2bin($folder)); - $table = mapi_folder_getcontentstable($mapifolder); + $table = mapi_folder_getcontentstable($mapiFolder); $list = mapi_table_queryallrows($table, array(PR_ENTRYID)); foreach ($list as $item) { @@ -257,12 +247,12 @@ class CalendarModule extends Module } } - $vcalendar = new VObject\Component\VCalendar(); + $vCalendar = new VObject\Component\VCalendar(); - // Add static stuff to vcalendar - $vcalendar->add('METHOD', 'PUBLISH'); - $vcalendar->add('X-WR-CALDESC', 'Exported Zarafa Calendar'); - $vcalendar->add('X-WR-TIMEZONE', date_default_timezone_get()); + // Add static stuff to vCalendar + $vCalendar->add('METHOD', 'PUBLISH'); + $vCalendar->add('X-WR-CALDESC', 'Exported Kopano Calendar'); + $vCalendar->add('X-WR-TIMEZONE', date_default_timezone_get()); // TODO: add VTIMEZONE object to ical. @@ -274,43 +264,43 @@ class CalendarModule extends Module $plaintext = true; $messageProps = $GLOBALS['operations']->getMessageProps($store, $message, $properties, $plaintext); - $vevent = $vcalendar->add('VEVENT', [ + $vEvent = $vCalendar->add('VEVENT', [ 'SUMMARY' => $this->getProp($messageProps, "subject"), 'DTSTART' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "startdate")), 'DTEND' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "duedate")), 'CREATED' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "creation_time")), 'LAST-MODIFIED' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "last_modification_time")), 'PRIORITY' => $this->getProp($messageProps, "importance"), - 'X-MICROSOFT-CDO-INTENDEDSTATUS' => $this->busystates[intval($this->getProp($messageProps, "busystatus"))], // both seem to be valid... - 'X-MICROSOFT-CDO-BUSYSTATUS' => $this->busystates[intval($this->getProp($messageProps, "busystatus"))], // both seem to be valid... + 'X-MICROSOFT-CDO-INTENDEDSTATUS' => $this->busyStates[intval($this->getProp($messageProps, "busystatus"))], // both seem to be valid... + 'X-MICROSOFT-CDO-BUSYSTATUS' => $this->busyStates[intval($this->getProp($messageProps, "busystatus"))], // both seem to be valid... 'X-ZARAFA-LABEL' => $this->labels[intval($this->getProp($messageProps, "label"))], 'CLASS' => $this->getProp($messageProps, "private") ? "PRIVATE" : "PUBLIC", 'COMMENT' => "eid:" . $records[$index] ]); // Add organizer - $vevent->add('ORGANIZER', 'mailto:' . $this->getProp($messageProps, "sender_email_address")); - $vevent->ORGANIZER['CN'] = $this->getProp($messageProps, "sender_name"); + $vEvent->add('ORGANIZER', 'mailto:' . $this->getProp($messageProps, "sender_email_address")); + $vEvent->ORGANIZER['CN'] = $this->getProp($messageProps, "sender_name"); // Add Attendees if (isset($messageProps["recipients"]) && count($messageProps["recipients"]["item"]) > 0) { foreach ($messageProps["recipients"]["item"] as $attendee) { - $att = $vevent->add('ATTENDEE', "mailto:" . $this->getProp($attendee, "email_address")); + $att = $vEvent->add('ATTENDEE', "mailto:" . $this->getProp($attendee, "email_address")); $att["CN"] = $this->getProp($attendee, "display_name"); - $att["ROLE"] = $this->attendeetype[intval($this->getProp($attendee, "recipient_type"))]; + $att["ROLE"] = $this->attendeeType[intval($this->getProp($attendee, "recipient_type"))]; } } // Add alarms if (!empty($this->getProp($messageProps, "reminder")) && $this->getProp($messageProps, "reminder") == 1) { - $valarm = $vevent->add('VALARM', [ + $vAlarm = $vEvent->add('VALARM', [ 'ACTION' => 'DISPLAY', 'DESCRIPTION' => $this->getProp($messageProps, "subject") // reuse the event summary ]); // Add trigger - $durationValue = $this->getDurationStringFromMintues($this->getProp($messageProps, "reminder_minutes"), false); - $valarm->add('TRIGGER', $durationValue); // default trigger type is duration (see 4.8.6.3) + $durationValue = $this->getDurationStringFromMinutes($this->getProp($messageProps, "reminder_minutes"), false); + $vAlarm->add('TRIGGER', $durationValue); // default trigger type is duration (see 4.8.6.3) /* $valarm->add('TRIGGER', date_timestamp_set(new DateTime(), $this->getProp($messageProps, "reminder_time"))); // trigger type "DATE-TIME" @@ -320,18 +310,18 @@ class CalendarModule extends Module // Add location if (!empty($this->getProp($messageProps, "location"))) { - $vevent->add('LOCATION', $this->getProp($messageProps, "location")); + $vEvent->add('LOCATION', $this->getProp($messageProps, "location")); } // Add description $body = $this->getProp($messageProps, "isHTML") ? $this->getProp($messageProps, "html_body") : $this->getProp($messageProps, "body"); if (!empty($body)) { - $vevent->add('DESCRIPTION', $body); + $vEvent->add('DESCRIPTION', $body); } } // write combined ics file - file_put_contents($file, file_get_contents($file) . $vcalendar->serialize()); + file_put_contents($file, file_get_contents($file) . $vCalendar->serialize()); } if (count($records) > 0) { @@ -356,9 +346,9 @@ class CalendarModule extends Module private function importCalendar($actionType, $actionData) { // Get uploaded vcf path - $icsfile = false; + $icsFile = false; if (isset($actionData["ics_filepath"])) { - $icsfile = $actionData["ics_filepath"]; + $icsFile = $actionData["ics_filepath"]; } // Get store id @@ -368,9 +358,9 @@ class CalendarModule extends Module } // Get folder entryid - $folderid = false; + $folderId = false; if (isset($actionData["folderid"])) { - $folderid = $actionData["folderid"]; + $folderId = $actionData["folderid"]; } // Get uids @@ -387,7 +377,7 @@ class CalendarModule extends Module $parser = null; try { $parser = VObject\Reader::read( - fopen($icsfile, 'r') + fopen($icsFile, 'r') ); } catch (Exception $e) { $error = true; @@ -398,11 +388,11 @@ class CalendarModule extends Module if (count($parser->VEVENT) > 0) { $events = $this->parseCalendarToArray($parser); $store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid)); - $folder = mapi_msgstore_openentry($store, hex2bin($folderid)); + $folder = mapi_msgstore_openentry($store, hex2bin($folderId)); - $importall = false; + $importAll = false; if (count($uids) == count($events)) { - $importall = true; + $importAll = true; } $propValuesMAPI = array(); @@ -414,7 +404,7 @@ class CalendarModule extends Module // iterate through all events and import them :) foreach ($events as $event) { - if (isset($event["startdate"]) && ($importall || in_array($event["internal_fields"]["event_uid"], $uids))) { + if (isset($event["startdate"]) && ($importAll || in_array($event["internal_fields"]["event_uid"], $uids))) { $message = mapi_folder_createmessage($folder); @@ -469,15 +459,15 @@ class CalendarModule extends Module private function getAttachmentPath($actionType, $actionData) { // Get store id - $storeid = false; + $storeId = false; if (isset($actionData["store"])) { - $storeid = $actionData["store"]; + $storeId = $actionData["store"]; } // Get message entryid - $entryid = false; + $entryId = false; if (isset($actionData["entryid"])) { - $entryid = $actionData["entryid"]; + $entryId = $actionData["entryid"]; } // Check which type isset @@ -490,13 +480,13 @@ class CalendarModule extends Module } // Check if storeid and entryid isset - if ($storeid && $entryid) { + if ($storeId && $entryId) { // Open the store - $store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid)); + $store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeId)); if ($store) { // Open the message - $message = mapi_msgstore_openentry($store, hex2bin($entryid)); + $message = mapi_msgstore_openentry($store, hex2bin($entryId)); if ($message) { $attachment = false; @@ -506,10 +496,10 @@ class CalendarModule extends Module // Loop through the attachNums, message in message in message ... for ($i = 0; $i < (count($attachNum) - 1); $i++) { // Open the attachment - $tempattach = mapi_message_openattach($message, (int)$attachNum[$i]); - if ($tempattach) { + $tempAttach = mapi_message_openattach($message, (int)$attachNum[$i]); + if ($tempAttach) { // Open the object in the attachment - $message = mapi_attach_openobj($tempattach); + $message = mapi_attach_openobj($tempAttach); } } @@ -553,7 +543,7 @@ class CalendarModule extends Module $ext_found = false; while (!feof($fh) && !$ext_found) { $line = fgets($fh); - preg_match("/(\.[a-z0-9]+)[ \t]+([^ \t\n\r]*)/i", $line, $result); + preg_match('/(\.[a-z0-9]+)[ \t]+([^ \t\n\r]*)/i', $line, $result); if ($extension == $result[1]) { $ext_found = true; $contentType = $result[2]; @@ -565,25 +555,26 @@ class CalendarModule extends Module } - $tmpname = tempnam(TMP_PATH, stripslashes($filename)); + $tmpName = tempnam(TMP_PATH, stripslashes($filename)); // Open a stream to get the attachment data $stream = mapi_openpropertytostream($attachment, PR_ATTACH_DATA_BIN); $stat = mapi_stream_stat($stream); // File length = $stat["cb"] - $fhandle = fopen($tmpname, 'w'); + $fHandle = fopen($tmpName, 'w'); $buffer = null; for ($i = 0; $i < $stat["cb"]; $i += BLOCK_SIZE) { // Write stream $buffer = mapi_stream_read($stream, BLOCK_SIZE); - fwrite($fhandle, $buffer, strlen($buffer)); + fwrite($fHandle, $buffer, strlen($buffer)); } - fclose($fhandle); + fclose($fHandle); $response = array(); - $response['tmpname'] = $tmpname; + $response['tmpname'] = $tmpName; $response['filename'] = $filename; + $response['contenttype'] = $contentType; $response['status'] = true; $this->addActionData($actionType, $response); $GLOBALS["bus"]->addData($this->getResponseData()); @@ -611,7 +602,7 @@ class CalendarModule extends Module private function loadCalendar($actionType, $actionData) { $error = false; - $error_msg = ""; + $errorMsg = ""; if (is_readable($actionData["ics_filepath"])) { $parser = null; @@ -623,11 +614,11 @@ class CalendarModule extends Module //error_log(print_r($parser->VTIMEZONE, true)); } catch (Exception $e) { $error = true; - $error_msg = $e->getMessage(); + $errorMsg = $e->getMessage(); } if ($error) { $response['status'] = false; - $response['message'] = $error_msg; + $response['message'] = $errorMsg; } else { if (count($parser->VEVENT) == 0) { $response['status'] = false; @@ -681,7 +672,7 @@ class CalendarModule extends Module $properties["comment"] = (string)$vEvent->COMMENT; $properties["timezone"] = (string)$vEvent->DTSTART["TZID"]; $properties["organizer"] = (string)$vEvent->ORGANIZER; - $properties["busystatus"] = array_search((string)$vEvent->{'X-MICROSOFT-CDO-INTENDEDSTATUS'}, $this->busystates); // X-MICROSOFT-CDO-BUSYSTATUS + $properties["busystatus"] = array_search((string)$vEvent->{'X-MICROSOFT-CDO-INTENDEDSTATUS'}, $this->busyStates); // X-MICROSOFT-CDO-BUSYSTATUS $properties["transp"] = (string)$vEvent->TRANSP; //$properties["trigger"] = (string)$vEvent->COMMENT; $properties["priority"] = (string)$vEvent->PRIORITY; diff --git a/php/upload.php b/php/upload.php index bd5f928..d2400ec 100644 --- a/php/upload.php +++ b/php/upload.php @@ -21,53 +21,35 @@ * */ -require_once("../config.php"); +require_once(__DIR__ . "/../config.php"); +require_once(__DIR__ . "/helper.php"); + +require_once(__DIR__ . '/../../../init.php'); +require_once(__DIR__ . "/../../../server/includes/core/class.webappauthentication.php"); // for checking the session + +use calendarimporter\Helper; /* disable error printing - otherwise json communication might break... */ ini_set('display_errors', '0'); -/** - * respond/echo JSON - * @param $arr - */ -function respondJSON($arr) -{ - echo json_encode($arr); +// check session +// otherwise a DOS attack might be possible +if (!WebAppAuthentication::getUserName() || WebAppAuthentication::getUserName() == "") { + Helper::respondJSON(array('success' => false, 'error' => dgettext("plugin_calendarimporter", "Not authenticated!"))); + die(); } -/** - * Generates a random string with variable length. - * @param $length the lenght of the generated string - * @return string a random string - */ -function randomstring($length = 6) -{ - // $chars - all allowed charakters - $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; +if (isset($_FILES['icsdata']['tmp_name']) && is_readable($_FILES['icsdata']['tmp_name'])) { + $destpath = PLUGIN_CALENDARIMPORTER_TMP_UPLOAD; + $destpath .= $_FILES['icsdata']['name'] . Helper::randomstring(); - srand((double)microtime() * 1000000); - $i = 0; - $pass = ""; - while ($i < $length) { - $num = rand() % strlen($chars); - $tmp = substr($chars, $num, 1); - $pass = $pass . $tmp; - $i++; - } - return $pass; -} - -$destpath = PLUGIN_CALENDARIMPORTER_TMP_UPLOAD; -$destpath .= $_FILES['icsdata']['name'] . randomstring(); - -if (is_readable($_FILES['icsdata']['tmp_name'])) { $result = move_uploaded_file($_FILES['icsdata']['tmp_name'], $destpath); if ($result) { - respondJSON(array('success' => true, 'ics_file' => $destpath)); + Helper::respondJSON(array('success' => true, 'ics_file' => $destpath)); } else { - respondJSON(array('success' => false, 'error' => dgettext("plugin_calendarimporter", "File could not be moved to TMP path! Check plugin config and folder permissions!"))); + Helper::respondJSON(array('success' => false, 'error' => dgettext("plugin_calendarimporter", "File could not be moved to TMP path! Check plugin config and folder permissions!"))); } } else { - respondJSON(array('success' => false, 'error' => dgettext("plugin_calendarimporter", "File could not be read by server, upload error!"))); + Helper::respondJSON(array('success' => false, 'error' => dgettext("plugin_calendarimporter", "File could not be read by server, upload error!"))); } \ No newline at end of file diff --git a/resources/css/calendarimporter-main.css b/resources/css/calendarimporter-main.css index d101e01..f4e3106 100644 --- a/resources/css/calendarimporter-main.css +++ b/resources/css/calendarimporter-main.css @@ -1,5 +1,5 @@ .icon_calendarimporter_button { - background: url(../images/import_icon.png) no-repeat !important; + background: url(../images/import_icon.png) no-repeat; background-repeat: no-repeat; background-position: center; } diff --git a/resources/images/import_icon.png b/resources/images/import_icon.png index 6bcfdc9..0f675e0 100644 Binary files a/resources/images/import_icon.png and b/resources/images/import_icon.png differ diff --git a/resources/images/import_icon.xcf b/resources/images/import_icon.xcf index ed5dac7..4e4a4eb 100644 Binary files a/resources/images/import_icon.xcf and b/resources/images/import_icon.xcf differ