From 741a0bfc673ecf64a1c37a89f5fe7c01458b74f6 Mon Sep 17 00:00:00 2001 From: wunschtacho Date: Sun, 6 Feb 2011 22:19:40 +0000 Subject: [PATCH] Scheduler integration git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/powermail/trunk@43181 735d13b6-9817-0410-8766-e36946ffe9aa --- cli/class.tx_powermail_scheduler.php | 117 +++++++++++++++++- cli/class.tx_powermail_scheduler_addField.php | 55 -------- ext_autoload.php | 14 ++- ext_localconf.php | 3 +- 4 files changed, 124 insertions(+), 65 deletions(-) delete mode 100644 cli/class.tx_powermail_scheduler_addField.php diff --git a/cli/class.tx_powermail_scheduler.php b/cli/class.tx_powermail_scheduler.php index 8b36fcfd..88dfa8f8 100644 --- a/cli/class.tx_powermail_scheduler.php +++ b/cli/class.tx_powermail_scheduler.php @@ -1,19 +1,130 @@ init('en'); + + if (intval($this->pid) === 0) { + $this->msg = 'No Page ID given!'; + return false; + } + + // tsconfig + $tmp_defaultconfig = array ( + 'time' => 86400, // default setting 1 day + 'body' => 'See XLS file in attachment', // default body + 'subject' => 'New powermail export email', // default subject + 'email_receiver' => '', // default: no receiver mail + 'email_receiver_cc' => '', // default: no cc mail + 'email_sender' => 'noreply@einpraegsam.net', // default sender address + 'sender' => 'powermail', // default sender name + 'format' => 'email_csv', // export in format email_csv or email_html or email_xls + 'attachedFilename' => '' // overwrite filename + ); + $tmp_tsconfig = t3lib_BEfunc::getModTSconfig($this->pid, 'tx_powermail_cli'); // get whole tsconfig from backend + $tsconfig = array_merge((array) $tmp_defaultconfig, (array) $tmp_tsconfig['properties']['exportmail.']); + + if (!t3lib_div::validEmail($tsconfig['email_receiver'])) { // if receiver email is set + $this->msg = 'Wrong receiver mail given!'; + return false; + } + + if (!t3lib_extMgm::isLoaded('phpexcel_library') && $tsconfig['format'] == 'email_xls') { + $this->msg = 'Please use csv or install extension phpexcel_library'; + return false; + } + // Generate the xls file + $export = t3lib_div::makeInstance('tx_powermail_export'); + $export->pid = $pid; // set page id + $export->startDateTime = (time() - $tsconfig['time']); // set starttime + $export->endDateTime = time(); // set endtime + $export->export = (stristr($tsconfig['format'], 'email_') ? $tsconfig['format'] : $this->tmp_defaultconfig['format']); // set + $export->LANG = $LANG; + if (!empty($tsconfig['attachedFilename'])) { + $export->overwriteFilename = $tsconfig['attachedFilename']; // overwrite filename with this + } + $export->main(); // generate file + $file = t3lib_div::getFileAbsFileName('typo3temp/' . $export->filename); // read filename + + if (!empty($file)) { // if file is not empty + // Generate the mail + $htmlMail = t3lib_div::makeInstance('t3lib_htmlmail'); // New object: TYPO3 mail class + $htmlMail->start(); // start htmlmail + $htmlMail->recipient = $tsconfig['email_receiver']; // main receiver + $htmlMail->recipient_copy = $tsconfig['email_receiver_cc']; // cc + $htmlMail->subject = $tsconfig['subject']; // mail subject + $htmlMail->from_email = $tsconfig['email_sender']; // sender email + $htmlMail->from_name = $tsconfig['sender']; // sender name + $htmlMail->addAttachment($file); // add attachment + $htmlMail->addPlain($tsconfig['body']); // add plaintext + $htmlMail->setHTML($htmlMail->encodeMsg($tsconfig['body'])); // html format if active via constants + $htmlMail->setHeaders(); + $htmlMail->setContent(); + if ($htmlMail->sendTheMail()) { + $this->msg = 'Mail successfully sent'; + } else { + $this->msg = 'Powermail Error in sending mail'; + } + } else { + $content = 'There are no mails to export in the last ' . intval($tsconfig['time']) . ' seconds in pid ' . $this->pid; + } + + return true; + } - mail('ake@conject.com', 'scheduler', 'scheduler'); - return 'fehler'; + /** + * Return message for backend + * + * @return bool + */ + public function getAdditionalInformation() { + return $this->msg; } } +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/powermail/cli/class.tx_powermail_scheduler.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/powermail/cli/class.tx_powermail_scheduler.php']); +} ?> \ No newline at end of file diff --git a/cli/class.tx_powermail_scheduler_addField.php b/cli/class.tx_powermail_scheduler_addField.php deleted file mode 100644 index 5c81d1cd..00000000 --- a/cli/class.tx_powermail_scheduler_addField.php +++ /dev/null @@ -1,55 +0,0 @@ -CMD == 'edit') { - $taskInfo['ip'] = $task->ip; - } else { - $taskInfo['ip'] = ''; - } - } - - if (empty($taskInfo['port'])) { - if($parentObject->CMD == 'add') { - $taskInfo['port'] = '80'; - } elseif($parentObject->CMD == 'edit') { - $taskInfo['port'] = $task->port; - } else { - $taskInfo['port'] = ''; - } - } - - // Write the code for the field - $fieldID = 'task_ip'; - $fieldCode = ''; - $additionalFields = array(); - $additionalFields[$fieldID] = array( - 'code' => $fieldCode, - 'label' => 'IP-Adresse/Webseite' - ); - - // Write the code for the field - $fieldID = 'task_port'; - $fieldCode = ''; - $additionalFields[$fieldID] = array( - 'code' => $fieldCode, - 'label' => 'Port' - ); - - return $additionalFields; - } - - public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $parentObject) { - $submittedData['ip'] = trim($submittedData['ip']); - $submittedData['port'] = trim($submittedData['port']); - return true; - } - - public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) { - $task->ip = $submittedData['ip']; - $task->port = $submittedData['port']; - } -} -?> \ No newline at end of file diff --git a/ext_autoload.php b/ext_autoload.php index daf78f1a..ba198759 100644 --- a/ext_autoload.php +++ b/ext_autoload.php @@ -5,21 +5,23 @@ $powermailExtPath = t3lib_extMgm::extPath('powermail'); -return array( +$arr = array( /* ajax actions*/ - 'tx_powermail_action' => $powermailExtPath . 'mod1/class.tx_powermail_action.php', + 'tx_powermail_action' => $powermailExtPath . 'mod1/class.tx_powermail_action.php', /* ajax repositories */ - 'tx_powermail_repository' => $powermailExtPath . 'mod1/class.tx_powermail_repository.php', - 'tx_powermail_export' => $powermailExtPath . 'mod1/class.tx_powermail_export.php', + 'tx_powermail_repository' => $powermailExtPath . 'mod1/class.tx_powermail_repository.php', + 'tx_powermail_export' => $powermailExtPath . 'mod1/class.tx_powermail_export.php', /* div */ - 'tx_powermail_functions_div' => $powermailExtPath . 'lib/class.tx_powermail_functions_div.php', + 'tx_powermail_functions_div' => $powermailExtPath . 'lib/class.tx_powermail_functions_div.php', /* scheduler */ 'tx_powermail_scheduler' => $powermailExtPath . 'cli/class.tx_powermail_scheduler.php', - 'tx_powermail_scheduler_addField' => $powermailExtPath . 'cli/class.tx_powermail_scheduler_addField.php' + 'tx_powermail_scheduler_addFields' => $powermailExtPath . 'cli/class.tx_powermail_scheduler_addFields.php' ); + +return $arr; ?> diff --git a/ext_localconf.php b/ext_localconf.php index fe016933..64a11b09 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -14,6 +14,7 @@ include_once(t3lib_extMgm::extPath('powermail') . 'lib/user_powermail_misc.php'); // Some powermail userFunc (Conditions if any further step) include_once(t3lib_extMgm::extPath('powermail') . 'lib/user_checkT3jquery.php'); // Conditions for Check if t3jquery is loaded or not include_once(t3lib_extMgm::extPath('powermail') . 'lib/user_checkT3jqueryCDNMode.php'); // Conditions for Check if t3jquery is in CDN Mode +include_once(t3lib_extMgm::extPath('powermail') . 'cli/class.tx_powermail_scheduler_addFields.php'); // Scheduler addFields class t3lib_extMgm::addPageTSConfig(''); @@ -33,7 +34,7 @@ 'extension' => 'powermail', 'title' => 'Automatic Export Mails', 'description' => 'Send your CSV or XLS exports via Email to a defined target', - 'additionalFields' => 'tx_powermail_scheduler_addField' + 'additionalFields' => 'tx_powermail_scheduler_addFields' ); ?> \ No newline at end of file