/**
  * action preview iframe
  *
  * @param int $uid
  * @return void
  */
 public function previewIframeAction($uid = 0)
 {
     if ($uid > 0) {
         $template = $this->templateRepository->findByUid($uid);
         $data['item']['name'] = "Hans Mustermann";
         $data['item']['email'] = "*****@*****.**";
         $data['item']['title'] = "Dies ist ein Kommentar";
         $data['item']['comment'] = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
         $data['item']['rating'] = "5.3";
         $data['confirm-url'] = "http://example.net/confirm.html";
         $data['delete-url'] = "http://example.net/delete.html";
         $data['target']['type'] = "tx_mooxnews_domain_model_news";
         $data['target']['uid'] = "1234";
         $data['target']['title'] = "Eine Kommentarfunktion ist cool";
         $data['target']['url'] = "http://example.net/target.html";
         $data['user']['gender'] = 1;
         $data['user']['title'] = "Dr.";
         $data['user']['username'] = "******";
         $data['user']['name'] = "Hans Mustermann";
         $data['user']['auto_name'] = "Hans Mustermann";
         $data['user']['first_name'] = "Hans";
         $data['user']['middle_name'] = "Jürgen";
         $data['user']['last_name'] = "Mustermann";
         $data['user']['email'] = "*****@*****.**";
         $data['receiver']['gender'] = 1;
         $data['receiver']['title'] = "Dr.";
         $data['receiver']['username'] = "******";
         $data['receiver']['name'] = "Hans Mustermann";
         $data['receiver']['auto_name'] = "Hans Mustermann";
         $data['receiver']['first_name'] = "Hans";
         $data['receiver']['middle_name'] = "Jürgen";
         $data['receiver']['last_name'] = "Mustermann";
         $data['receiver']['email'] = "*****@*****.**";
         if (!empty($this->extConf['mailRenderingPartialRoot'])) {
             $partialRootPath = GeneralUtility::getFileAbsFileName($this->extConf['mailRenderingPartialRoot']);
             if (!is_dir($partialRootPath)) {
                 unset($partialRootPath);
             }
         }
         if ($partialRootPath == "") {
             $conf = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
             $partialRootPath = GeneralUtility::getFileAbsFileName(str_replace("Backend/", "", $conf['view']['partialRootPaths'][0]) . "Mail");
         }
         $previewView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
         $previewView->setFormat('html');
         $previewView->setTemplateSource($template->getTemplate());
         if ($partialRootPath != "") {
             $previewView->setPartialRootPath($partialRootPath);
         }
         $previewView->assignMultiple($data);
         $preview = $previewView->render();
         $this->view->assign('preview', $preview);
     } else {
         $this->view->assign('preview', "Vorschau kann nicht angezeigt werden.");
     }
 }
Exemplo n.º 2
0
 /**
  * action add
  *
  * @param array $add form data
  * @param bool $ajax is ajax request?
  * @param string $settings settings
  * @return void
  */
 public function addAction($add = NULL, $ajax = FALSE, $settings = NULL)
 {
     // init action arrays and booleans
     $messages = [];
     $errors = [];
     $moderators = [];
     $confirmed = false;
     $isModerator = false;
     $isConfirmable = false;
     // overwrite settings
     $this->settings = $this->helperService->overwriteSettings($this->settings, $settings);
     // get moderators
     if ($this->settings['feGroupsAdmin']) {
         $feGroupsAdmin = explode(",", $this->settings['feGroupsAdmin']);
         if (count($feGroupsAdmin)) {
             $usergroups = [];
             foreach ($this->frontendUserGroupRepository->findByUidList($feGroupsAdmin) as $usergroup) {
                 $usergroups[] = $usergroup;
             }
             $moderators = $this->frontendUserRepository->findByUsergroups($usergroups);
         }
     }
     // check and get logged in user
     if (TRUE === $this->accessControllService->hasLoggedInFrontendUser()) {
         $feUser = $this->frontendUserRepository->findByUid($this->accessControllService->getFrontendUserUid());
         if (is_object($feUser) && count($moderators)) {
             // check if user is moderator
             foreach ($moderators as $moderator) {
                 if ($feUser->getUid() == $moderator->getUid()) {
                     $isModerator = true;
                     $isConfirmable = true;
                     break;
                 }
             }
         }
     }
     // check fields
     $this->helperService->checkFields($this->fields, $add, $messages, $errors);
     // no errors -> add comment
     if (!count($errors)) {
         // set item values
         $item = $this->objectManager->get('DCNGmbH\\MooxComment\\Domain\\Model\\Comment');
         $item->setUidForeign($add['uid_foreign']);
         $item->setTitleForeign($add['title_foreign']);
         $item->setUrlForeign($add['url_foreign']);
         $item->setTablenames($add['tablenames']);
         if (!$feUser) {
             $item->setName(trim($add['name']));
             $item->setEmail(trim($add['email']));
             if ($this->settings['autoConfirmPublicUsers']) {
                 $item->setConfirmed(time());
                 $confirmed = true;
             }
         } else {
             $item->setName($feUser->getName());
             $item->setEmail($feUser->getEmail());
             $item->setFeUser($feUser);
             if ($this->settings['autoConfirmLoggedInUsers'] || $isConfirmable) {
                 $item->setConfirmed(time());
                 $confirmed = true;
             }
         }
         $item->setTitle(trim($add['title']));
         $item->setComment(trim($add['comment']));
         // set pid (bugfix ignoring global setting);
         if (!$item->getPid()) {
             $item->setPid($this->settings['storagePid']);
         }
         // save item to database and reload
         $this->commentRepository->add($item);
         $this->persistenceManager->persistAll();
         $item->setCrdate($GLOBALS['EXEC_TIME']);
         // need to send notifications?
         if (!$isConfirmable && count($moderators) && $this->settings['newEntryEmailTemplate'] > 0) {
             // load mail template
             $template = $this->templateRepository->findByUid($this->settings['newEntryEmailTemplate']);
             // if mail template exists
             if ($template) {
                 // set user mail field
                 if ($feUser) {
                     $user = [];
                     foreach (["username", "first_name", "last_name", "auto_name", "email", "gender"] as $fieldname) {
                         $getMethod = "get" . GeneralUtility::underscoredToUpperCamelCase($fieldname);
                         if (method_exists($feUser, $getMethod)) {
                             $user[$fieldname] = $feUser->{$getMethod}();
                         }
                     }
                 } else {
                     $user['auto_name'] = $item->getName();
                     $user['email'] = $item->getEmail();
                 }
                 $subject = $this->helperService->prepareMailSubject($template->getSubject(), $user);
                 $deleteUrl = $this->uriBuilder->reset()->setNoCache(true)->setTargetPageUid($GLOBALS["TSFE"]->id)->setCreateAbsoluteUri(TRUE)->uriFor('delete', array("uid" => $item->getUid(), "hash" => $item->getHash()), 'Pi1', 'MooxComment', 'Pi1');
                 if (!$item->getConfirmed()) {
                     $confirmUrl = $this->uriBuilder->reset()->setNoCache(true)->setTargetPageUid($GLOBALS["TSFE"]->id)->setCreateAbsoluteUri(TRUE)->uriFor('confirm', array("uid" => $item->getUid(), "hash" => $item->getHash()), 'Pi1', 'MooxComment', 'Pi1');
                 }
                 foreach ($moderators as $moderator) {
                     if ($moderator->getEmail() != "") {
                         // set user mail field
                         $receiver = [];
                         foreach (["username", "first_name", "last_name", "auto_name", "email", "gender"] as $fieldname) {
                             $getMethod = "get" . GeneralUtility::underscoredToUpperCamelCase($fieldname);
                             if (method_exists($moderator, $getMethod)) {
                                 $receiver[$fieldname] = $moderator->{$getMethod}();
                             }
                         }
                         // set info mail array
                         $mail = ['sender_name' => $this->settings['notificationsSenderName'], 'sender_address' => $this->settings['notificationsSenderAddress'], 'receiver_name' => $moderator->getFirstName() != "" ? $moderator->getFirstName() . " " . $moderator->getLastName() : $moderator->getLastName(), 'receiver_address' => $moderator->getEmail(), 'subject' => $subject, 'pid' => $GLOBALS["TSFE"]->id, 'confirm-url' => $confirmUrl, 'delete-url' => $deleteUrl, 'user' => $user, 'receiver' => $receiver, 'item' => ['name' => $item->getName(), 'email' => $item->getEmail(), 'title' => $item->getTitle(), 'comment' => $item->getComment()], 'target' => ['type' => $item->getTablenames(), 'uid' => $item->getUidForeign(), 'title' => $item->getTitleForeign(), 'url' => $item->getUrlForeign()]];
                         // set mail body
                         $mail['body'] = $this->helperService->prepareMailBody($template, $mail);
                         // send mail
                         $this->helperService->sendMail($mail);
                     }
                 }
             } else {
                 // add message
                 $messages[] = ["icon" => '<span class="glyphicon glyphicon-warning-sign icon-alert" aria-hidden="true"></span>', "title" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add', $this->extensionName), "text" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add.error.no_template', $this->extensionName), "type" => FlashMessage::ERROR];
             }
         }
         // add message
         if ($confirmed) {
             $messages[] = ["icon" => '<span class="glyphicon glyphicon-ok icon-alert" aria-hidden="true"></span>', "title" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add', $this->extensionName), "text" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add.success', $this->extensionName), "type" => FlashMessage::OK];
         } else {
             $messages[] = ["icon" => '<span class="glyphicon glyphicon-ok icon-alert" aria-hidden="true"></span>', "title" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add', $this->extensionName), "text" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add.success_moderated', $this->extensionName), "type" => FlashMessage::OK];
         }
     }
     // unset register object
     unset($add);
     // end request
     if ($ajax) {
         if (count($messages)) {
             // set flash messages
             $this->helperService->setFlashMessages($this, $messages);
         } else {
             $this->view = NULL;
             header("HTTP/1.0 200 Ok");
             exit;
         }
     } else {
         if (count($messages)) {
             // set flash messages
             $this->helperService->setFlashMessages($this, $messages);
         } else {
             $this->view = NULL;
         }
     }
 }