/**
  * Edits and saves an image.
  *
  * @param  array  $arrData  Contains $_POST array.
  * @return bool             True on success, false otherwise.
  */
 public function editImage($arrData)
 {
     global $_ARRAYLANG, $objTemplate;
     $objFile = new \File();
     $orgFile = $arrData['orgName'] . '.' . $arrData['orgExt'];
     $newName = $arrData['newName'];
     $newFile = $newName . '.' . $arrData['orgExt'];
     \Cx\Lib\FileSystem\FileSystem::clean_path($newFile);
     // If new image name is set, image will be copied. Otherwise, image will be overwritten
     if ($newName != '') {
         $this->fileLog = $objFile->copyFile($this->path, $orgFile, $this->path, $newFile);
         if ($this->fileLog == 'error') {
             throw new \Exception('Could not copy image');
         }
     } else {
         $this->fileLog = $orgFile;
     }
     // Edit image
     if (!empty($this->path) && !empty($this->fileLog)) {
         // Image loader
         if (!$this->_objImage->loadImage($this->path . $this->fileLog)) {
             throw new \Exception('Could not load image');
         }
         // Rotate image
         if (!empty($arrData['d'])) {
             $this->_objImage->rotateImage(intval($arrData['d']));
         }
         // Crop image
         if (isset($arrData['x']) && isset($arrData['y']) && !empty($arrData['w']) && !empty($arrData['h'])) {
             $this->_objImage->cropImage(intval($arrData['x']), intval($arrData['y']), intval($arrData['w']), intval($arrData['h']));
         }
         // Resize image
         if (!empty($arrData['rw']) && !empty($arrData['rh']) && !empty($arrData['q'])) {
             if (!$this->_objImage->resizeImage(intval($arrData['rw']), intval($arrData['rh']), intval($arrData['q']))) {
                 throw new \Exception('Could not resize image');
             }
         }
         // Save new image
         if (!$this->_objImage->saveNewImage($this->path . $this->fileLog, true)) {
             throw new \Exception('Is not a valid image or image type');
         }
         // If no error occured, return true
         return $this->fileLog;
     }
     throw new \Exception('Path or file is empty');
 }
Example #2
0
 function send()
 {
     global $objDatabase, $_ARRAYLANG, $_CONFIG;
     $this->_objTpl->setTemplate($this->pageContent);
     // Initialize variables
     $code = substr(md5(rand()), 1, 10);
     $url = \Cx\Core\Routing\Url::fromModuleAndCmd('Ecard', 'show', '', array('code' => $code))->toString();
     // Initialize POST variables
     $id = intval($_POST['selectedEcard']);
     $message = contrexx_addslashes($_POST['ecardMessage']);
     $recipientSalutation = contrexx_stripslashes($_POST['ecardRecipientSalutation']);
     $senderName = contrexx_stripslashes($_POST['ecardSenderName']);
     $senderEmail = \FWValidator::isEmail($_POST['ecardSenderEmail']) ? $_POST['ecardSenderEmail'] : '';
     $recipientName = contrexx_stripslashes($_POST['ecardRecipientName']);
     $recipientEmail = \FWValidator::isEmail($_POST['ecardRecipientEmail']) ? $_POST['ecardRecipientEmail'] : '';
     if (empty($senderEmail) || empty($recipientEmail)) {
         $this->_objTpl->setVariable(array('STATUS_MESSAGE' => $_ARRAYLANG['TXT_ECARD_SENDING_ERROR']));
         return false;
     }
     $query = "\n            SELECT `setting_name`, `setting_value`\n              FROM " . DBPREFIX . "module_ecard_settings";
     $objResult = $objDatabase->Execute($query);
     while (!$objResult->EOF) {
         switch ($objResult->fields['setting_name']) {
             case 'validdays':
                 $validdays = $objResult->fields['setting_value'];
                 break;
                 // Never used
                 //                case 'greetings':
                 //                    $greetings = $objResult->fields['setting_value'];
                 //                    break;
             // Never used
             //                case 'greetings':
             //                    $greetings = $objResult->fields['setting_value'];
             //                    break;
             case 'subject':
                 $subject = $objResult->fields['setting_value'];
                 break;
             case 'emailText':
                 $emailText = strip_tags($objResult->fields['setting_value']);
                 break;
         }
         $objResult->MoveNext();
     }
     $timeToLife = $validdays * 86400;
     // Replace placeholders with used in notification mail with user data
     $emailText = str_replace('[[ECARD_RECIPIENT_SALUTATION]]', $recipientSalutation, $emailText);
     $emailText = str_replace('[[ECARD_RECIPIENT_NAME]]', $recipientName, $emailText);
     $emailText = str_replace('[[ECARD_RECIPIENT_EMAIL]]', $recipientEmail, $emailText);
     $emailText = str_replace('[[ECARD_SENDER_NAME]]', $senderName, $emailText);
     $emailText = str_replace('[[ECARD_SENDER_EMAIL]]', $senderEmail, $emailText);
     $emailText = str_replace('[[ECARD_VALID_DAYS]]', $validdays, $emailText);
     $emailText = str_replace('[[ECARD_URL]]', $url, $emailText);
     $body = $emailText;
     // Insert ecard to DB
     $query = "\n            INSERT INTO `" . DBPREFIX . "module_ecard_ecards` (\n                code, date, TTL, salutation,\n                senderName, senderEmail,\n                recipientName, recipientEmail,\n                message\n            ) VALUES (\n                '" . $code . "',\n                '" . time() . "',\n                '" . $timeToLife . "',\n                '" . addslashes($recipientSalutation) . "',\n                '" . addslashes($senderName) . "',\n                '" . $senderEmail . "',\n                '" . addslashes($recipientName) . "',\n                '" . $recipientEmail . "',\n                '" . $message . "');";
     if ($objDatabase->Execute($query)) {
         $query = "\n                SELECT setting_value\n                  FROM " . DBPREFIX . "module_ecard_settings\n                 WHERE setting_name='motive_{$id}'";
         $objResult = $objDatabase->SelectLimit($query, 1);
         // Copy motive to new file with $code as filename
         $fileExtension = preg_replace('/^.+(\\.[^\\.]+)$/', '$1', $objResult->fields['setting_value']);
         $fileName = $objResult->fields['setting_value'];
         $objFile = new \File();
         if ($objFile->copyFile(ASCMS_ECARD_OPTIMIZED_PATH . '/', $fileName, ASCMS_ECARD_SEND_ECARDS_PATH . '/', $code . $fileExtension)) {
             $objMail = new \phpmailer();
             // Check e-mail settings
             if ($_CONFIG['coreSmtpServer'] > 0 && @(include_once ASCMS_CORE_PATH . '/SmtpSettings.class.php')) {
                 $objSmtpSettings = new \SmtpSettings();
                 if (($arrSmtp = $objSmtpSettings->getSmtpAccount($_CONFIG['coreSmtpServer'])) !== false) {
                     $objMail->IsSMTP();
                     $objMail->Host = $arrSmtp['hostname'];
                     $objMail->Port = $arrSmtp['port'];
                     $objMail->SMTPAuth = true;
                     $objMail->Username = $arrSmtp['username'];
                     $objMail->Password = $arrSmtp['password'];
                 }
             }
             // Send notification mail to ecard-recipient
             $objMail->CharSet = CONTREXX_CHARSET;
             $objMail->SetFrom($senderEmail, $senderName);
             $objMail->Subject = $subject;
             $objMail->IsHTML(false);
             $objMail->Body = $body;
             $objMail->AddAddress($recipientEmail);
             if ($objMail->Send()) {
                 $this->_objTpl->setVariable(array('STATUS_MESSAGE' => $_ARRAYLANG['TXT_ECARD_HAS_BEEN_SENT']));
             } else {
                 $this->_objTpl->setVariable(array('STATUS_MESSAGE' => $_ARRAYLANG['TXT_ECARD_MAIL_SENDING_ERROR']));
             }
         }
     } else {
         $this->_objTpl->setVariable(array('STATUS_MESSAGE' => $_ARRAYLANG['TXT_ECARD_SENDING_ERROR']));
     }
 }
Example #3
0
 function copyPicture($fileName)
 {
     $fileNameOri = $fileName;
     if (!empty($fileName)) {
         $path = "pictures/";
         $info = pathinfo($fileName);
         $exte = $info['extension'];
         $exte = !empty($exte) ? '.' . $exte : '';
         $part1 = substr($fileName, 0, strlen($fileName) - strlen($exte));
         $rand = rand(10, 99);
         $fileName = md5($rand . $fileName) . $exte;
         //check file
         // TODO: $x is not defined
         $x = 0;
         if (file_exists($this->mediaPath . $path . $fileName)) {
             $fileName = $rand . $part1 . '_' . (time() + $x) . $exte;
             $fileName = md5($fileName) . $exte;
         }
         $objFile = new \File();
         $objFile->copyFile($this->mediaPath . $path, $fileNameOri, $this->mediaPath . $path, $fileName);
         $objFile->setChmod($this->mediaPath, $this->mediaWebPath, $path . $fileName);
         return $fileName;
     } else {
         return '';
     }
 }