diff --git a/ajax/contact.php b/ajax/contact.php index bbbf92f730400a40a00edc2f474de00a022b7b54..0f5e54faaad7b1e34d558845005add88f74f8c89 100644 --- a/ajax/contact.php +++ b/ajax/contact.php @@ -13,14 +13,14 @@ */ QUI::$Ajax->registerFunction( 'package_quiqqer_bricks_ajax_contact', - function ($brickId, $project, $siteId, $message, $email, $name) { + function ($brickId, $project, $siteId, $message, $name, $email) { // check if email correct if (!QUI\Utils\Security\Orthos::checkMailSyntax($email)) { throw new QUI\Exception( QUI::getLocale()->get( - 'quiqqer/system', - 'exception.contact.wrong.email' + 'quiqqer/bricks', + 'brick.control.simpleContact.error.wrongEmail' ) ); } @@ -38,7 +38,8 @@ function ($brickId, $project, $siteId, $message, $email, $name) { $receiver = $Brick->getSetting('mailTo'); } - if ($receiver == '') { + // fallback: admin email + if (!QUI\Utils\Security\Orthos::checkMailSyntax($receiver)) { $receiver = (QUI::conf('mail', 'admin_mail')); } @@ -60,14 +61,16 @@ function ($brickId, $project, $siteId, $message, $email, $name) { try { $Mailer->send(); } catch (\Exception $Exception) { + + \QUI\System\Log::writeException($Exception); + throw new QUI\Exception( - $Exception->getMessage(), - $Exception->getCode() + QUI::getLocale()->get('quiqqer/bricks', 'brick.control.simpleContact.error.serverError') ); } return true; }, - array('brickId', 'project', 'siteId', 'message', 'email', 'name'), + array('brickId', 'project', 'siteId', 'message', 'name', 'email'), false ); diff --git a/bin/BrickEdit.js b/bin/BrickEdit.js index af23a4728c393d3d8329e6f41b7eb44f966c8ee1..46757f3477590463dc63527d02fae78d895aa995 100644 --- a/bin/BrickEdit.js +++ b/bin/BrickEdit.js @@ -374,9 +374,6 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ if (unload === 'content' && this.$Editor) { data.attributes.content = this.$Editor.getContent(); - - this.$Editor.destroy(); - this.$Editor = false; } this.setAttribute('data', data); diff --git a/bin/Controls/SimpleContact.js b/bin/Controls/SimpleContact.js index ddc3875b61e7ff02b7923d511bb30a634e917559..6608ef738b8eb0734c1128fa0bd98f68740eaf44 100644 --- a/bin/Controls/SimpleContact.js +++ b/bin/Controls/SimpleContact.js @@ -54,18 +54,20 @@ define('package/quiqqer/bricks/bin/Controls/SimpleContact', [ var self = this; this.Loader.inject(this.$Elm); - - var Button = this.$Elm.getElement('.quiqqer-simple-contact-button'); - - Button.set('disabled', false); - Button.set('html', QUILocale.get('quiqqer/bricks', 'control.simpleContact.sendButton')); - - Button.addEvents({ - click: function () { - self.$Elm.getElement('form').fireEvent('submit'); + this.Form = this.$Elm.getElement('form'); + + var Button = new Element('button', { + 'class' : 'quiqqer-simple-contact-button', + 'type': 'button', + 'html' : QUILocale.get('quiqqer/bricks', 'control.simpleContact.sendButton'), + events: { + click: function () { + self.$Elm.getElement('form').fireEvent('submit'); + } } }); + Button.inject(this.Form); this.$Elm.getElement('form').addEvent('submit', function (event) { if (typeof event !== 'undefined') { @@ -106,11 +108,10 @@ define('package/quiqqer/bricks/bin/Controls/SimpleContact', [ this.Loader.show(); Ajax.post('package_quiqqer_bricks_ajax_contact', function (result) { - if (result) { var html = '<span class="fa fa-check fa-check-simple-contact control-color"></span>'; - html += QUILocale.get('quiqqer/system', 'message.contact.successful'); - self.$Elm.set('html', html); + html += QUILocale.get('quiqqer/bricks', 'brick.control.simpleContact.successful'); + self.Form.set('html', html); } self.Loader.hide(); @@ -128,6 +129,7 @@ define('package/quiqqer/bricks/bin/Controls/SimpleContact', [ self.Loader.hide(); QUI.getMessageHandler(function (MH) { + MH.options.displayTimeMessages = 8000; MH.addError(Exception.getMessage(), self.$Elm); }); } diff --git a/locale.xml b/locale.xml index 386b36fc4c1ca2becd8a33743db9161e9acbde39..7804a87cf5642de58b83fe1f5ac930d7f4aa8880 100644 --- a/locale.xml +++ b/locale.xml @@ -131,11 +131,34 @@ <pl><![CDATA[Wyślij]]></pl> </locale> <locale name="brick.control.simpleContact.mailTo"> - <de><![CDATA[Ihre E-Mail Adresse]]></de> - <en><![CDATA[Your email]]></en> - <pl><![CDATA[Twój adres e-mail]]></pl> + <de><![CDATA[E-Mail Adresse, wo die Nachricht gesendet wird]]></de> + <en><![CDATA[Email where the message will send to]]></en> + <pl><![CDATA[Adres mailowy, na który zostanie wysłania wiadomość]]></pl> </locale> + <locale name="brick.control.simpleContact.successful"> + <de><![CDATA[Vielen Dank für Ihre E-Mail. Wir werden uns schnellstmöglich bei Ihnen melden.]]></de> + <en><![CDATA[Thank you for your email. We will contact you as soon as possible.]]></en> + <pl><![CDATA[Dziękujemy za wiadomość. Skontaktujemy się tak szybko, jak to możliwe.]]></pl> + </locale> + <locale name="brick.control.simpleContact.error.serverError"> + <de><![CDATA[Ihre Nachricht konnte nicht gesendet werden. Bitte versuchen Sie es später noch einmal oder kontaktieren Sie den Support per E-Mail.]]></de> + <en><![CDATA[Your message could not be sent. Please try again later or contact our support by e-mail.]]></en> + <pl><![CDATA[Wiadomość nie mogła zostać wysłana. Spróbuj ponownie później lub skontaktuj się przez e-mail z naszym dzialem pomocy.]]></pl> + </locale> + + <locale name="brick.control.simpleContact.error.serverError"> + <de><![CDATA[Ihre Nachricht konnte nicht gesendet werden. Bitte versuchen Sie es später noch einmal oder kontaktieren Sie den Support per E-Mail.]]></de> + <en><![CDATA[Your message could not be sent. Please try again later or contact our support by e-mail.]]></en> + <pl><![CDATA[Wiadomość nie mogła zostać wysłana. Spróbuj ponownie później lub skontaktuj się przez e-mail z naszym dzialem pomocy.]]></pl> + </locale> + <locale name="brick.control.simpleContact.error.wrongEmail"> + <de><![CDATA[Die eingegebene E-mail Adresse ist nicht korrekt. Bitte geben Sie eine korrekte E-Mail an.]]></de> + <en><![CDATA[The entered e-mail address is not correct. Please enter a correct one.]]></en> + <pl><![CDATA[Wprowadzony adres e-mail nie jest poprawny. Proszę podać prawidłowy adres e-mail.]]></pl> + </locale> + + <locale name="brick.control.navigation.title"> <de><![CDATA[Bausteine: Navigation]]></de> <en><![CDATA[Bricks: Navigation]]></en> diff --git a/src/QUI/Bricks/Controls/SimpleContact.css b/src/QUI/Bricks/Controls/SimpleContact.css index 1a1e6d700464b4dac575883109442966b6beb1a8..9b114734307d0d1e8c67205d45059a821aa5f67f 100644 --- a/src/QUI/Bricks/Controls/SimpleContact.css +++ b/src/QUI/Bricks/Controls/SimpleContact.css @@ -32,7 +32,6 @@ .quiqqer-simple-contact-message { border: 1px solid #555; clear: both; - float: left; margin: 1em 0; padding: 0.8em; position: relative; @@ -52,7 +51,6 @@ /* check icon */ - .fa-check-simple-contact { margin: 10% auto; width: 60px; diff --git a/src/QUI/Bricks/Controls/SimpleContact.html b/src/QUI/Bricks/Controls/SimpleContact.html index ca3df11d7eff6b6c5f84e78edeea1d10681337c4..bf11142eb2b38e0d029682cc0fee12d5b4679609 100644 --- a/src/QUI/Bricks/Controls/SimpleContact.html +++ b/src/QUI/Bricks/Controls/SimpleContact.html @@ -1,16 +1,28 @@ -<form class="quiqqer-simple-contact" method="POST" action=""> +{if $this->getAttribute('showTitle') && $this->getAttribute('frontendTitle')} +<header class="control-header"> + <h1>{$this->getAttribute('frontendTitle')}</h1> +</header> +{/if} - {if $this->getAttribute('showTitle') && $this->getAttribute('frontendTitle')} - <header class="control-header"> - <h1>{$this->getAttribute('frontendTitle')}</h1> - </header> - {/if} +{if $this->getAttribute('content') != ""} +<div class="control-content"> + {$this->getAttribute('content')} +</div> +{/if} - {if $this->getAttribute('content') != ""} - <div class="control-content"> - {$this->getAttribute('content')} - </div> - {/if} +{if isset( $successMessage )} +<div class="quiqqer-simple-contact-message quiqqer-simple-contact-message-success"> + {$successMessage} +</div> +{/if} + +{if isset( $errorMessage )} +<div class="quiqqer-simple-contact-message quiqqer-simple-contact-message-error"> + {$errorMessage} +</div> +{/if} + +<form class="quiqqer-simple-contact" method="POST" action=""> {if $this->getAttribute('labels')} <label for="qui-contact-name"> @@ -21,7 +33,7 @@ name="name" id="qui-contact-name" required="required" - value="" + value="{$name}" placeholder="{locale group="quiqqer/bricks" value="control.simpleContact.name.placeholder"}" /> @@ -30,11 +42,11 @@ {locale group="quiqqer/bricks" value="control.simpleContact.email"} </label> {/if} - <input type="email" + <input type="" name="email" id="qui-contact-email" required="required" - value="" + value="{$email}" placeholder="{locale group="quiqqer/bricks" value="control.simpleContact.email.placeholder"}" /> @@ -47,10 +59,11 @@ id="qui-contact-message" required="required" placeholder="{locale group="quiqqer/bricks" value="control.simpleContact.message.placeholder"}" - ></textarea> + >{$message}</textarea> - <button class="quiqqer-simple-contact-button" type="button" disabled="disabled"> - <span class="fa fa-spinner fa-spin"></span> - </button> + <noscript> + <input class="quiqqer-simple-contact-button" type="submit" + value="{locale group='quiqqer/bricks' value='control.simpleContact.sendButton'}" /> + </noscript> </form> \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/SimpleContact.php b/src/QUI/Bricks/Controls/SimpleContact.php index a3b70270160f522a5f0f5a977503c0f0a88280a0..47630500c8f0ae4a7c32094654336c4c0df2bb28 100644 --- a/src/QUI/Bricks/Controls/SimpleContact.php +++ b/src/QUI/Bricks/Controls/SimpleContact.php @@ -12,7 +12,7 @@ * Mini contact control * {control control="\QUI\Bricks\Controls\SimpleContact" labels=false} * - * @author www.pcsg.de (Henning Leutz) + * @author www.pcsg.de (Henning Leutz, Michael Danielczok) * @licence For copyright and license information, please view the /README.md */ class SimpleContact extends QUI\Control @@ -24,16 +24,20 @@ class SimpleContact extends QUI\Control */ public function __construct($attributes = array()) { + $this->setAttributes(array( + 'class' => 'quiqqer-simple-contact', + 'qui-class' => 'package/quiqqer/bricks/bin/Controls/SimpleContact', + 'labels' => true, + 'data-brickid' => true, + 'mailTo' => '' // receiver email + )); + + parent::__construct($attributes); $this->addCSSFile( dirname(__FILE__) . '/SimpleContact.css' ); - - $this->setAttribute('class', 'quiqqer-simple-contact'); - $this->setAttribute('qui-class', "package/quiqqer/bricks/bin/Controls/SimpleContact"); - $this->setAttribute('labels', true); - $this->setAttribute('data-brickid', true); } /** @@ -43,12 +47,116 @@ public function __construct($attributes = array()) */ public function getBody() { - $Engine = QUI::getTemplateManager()->getEngine(); + $Engine = QUI::getTemplateManager()->getEngine(); + $name = ''; + $email = ''; + $message = ''; + + // is javascript disabled? + if (isset($_POST['name']) + && isset($_POST['email']) + && isset($_POST['message']) + ) { + try { + $this->sendMail($Engine); + } catch (\Exception $Exception) { + + $name = $_POST['name']; + $email = $_POST['email']; + $message = $_POST['message']; + + $Engine->assign(array( + 'errorMessage' => $Exception->getMessage() + )); + } + } $Engine->assign(array( - 'this' => $this + 'this' => $this, + 'name' => $name, + 'email' => $email, + 'message' => $message )); return $Engine->fetch(dirname(__FILE__) . '/SimpleContact.html'); } + + /** + * Send email per post request if javascript is disabled + * + * @param $Engine + * @throws QUI\Exception + */ + public function sendMail($Engine) + { + $Site = $this->getSite(); + + // email correct? + if (!QUI\Utils\Security\Orthos::checkMailSyntax($_POST['email'])) { + throw new QUI\Exception( + QUI::getLocale()->get( + 'quiqqer/bricks', + 'brick.control.simpleContact.error.wrongEmail' + ) + ); + } + + $receiver = $this->getAttribute('mailTo'); + $url = $this->getProject()->getHost() . $Site->getUrlRewritten(); + + // fallback: admin email + if (!QUI\Utils\Security\Orthos::checkMailSyntax($receiver)) { + $receiver = (QUI::conf('mail', 'admin_mail')); + } + + $Mailer = QUI::getMailManager()->getMailer(); + + $Mailer->addRecipient($receiver); + $Mailer->addReplyTo($_POST['email']); + $Mailer->setSubject($Site->getAttribute('title') . ' | ' . $url); + + $Mailer->setBody(" + <span style=\"font-weight: bold;\">From:</span> {$_POST['name']}<br /> + <span style=\"font-weight: bold;\">E-mail:</span> {$_POST['email']}<br /> + <span style=\"font-weight: bold;\">Message:</span><br /><br /> + <div style=\"white-space: pre-line;\">{$_POST['message']} + </div> + "); + + try { + $Mailer->send(); + $Engine->assign(array( + 'successMessage' => QUI::getLocale()->get( + 'quiqqer/bricks', 'brick.control.simpleContact.successful' + ) + )); + + } catch (\Exception $Exception) { + + QUI\System\Log::writeException($Exception); + + throw new QUI\Exception( + QUI::getLocale()->get( + 'quiqqer/bricks', + 'brick.control.simpleContact.error.serverError' + ) + ); + } + } + + /** + * @return mixed|QUI\Projects\Site + */ + protected function getSite() + { + if ($this->getAttribute('Site')) { + return $this->getAttribute('Site'); + } + + $Site = \QUI::getRewrite()->getSite(); + + $this->setAttribute('Site', $Site); + + return $Site; + } } diff --git a/src/QUI/Bricks/Events.php b/src/QUI/Bricks/Events.php index 751ea05270f8a13f7a36f134a7abf889fa3a25ed..ec68e4ba98fcc1a6a66954c49559332ebc8417fe 100644 --- a/src/QUI/Bricks/Events.php +++ b/src/QUI/Bricks/Events.php @@ -24,6 +24,7 @@ class Events * Create site brick cache, for inheritance * * @param Site|Edit $Site + * @throws QUI\Exception */ public static function onSiteSave($Site) { @@ -164,6 +165,7 @@ public static function onSiteSave($Site) * add new brickarea function * * @param \Smarty $Smarty + * @throws \SmartyException */ public static function onSmartyInit($Smarty) { @@ -219,7 +221,7 @@ public static function onPackageSetup(QUI\Package\Package $Package) if ($Package->getName() !== 'quiqqer/bricks') { return; } - + $php = 'php'; if (defined('PHP_BINARY')) { diff --git a/src/QUI/Bricks/Manager.php b/src/QUI/Bricks/Manager.php index 65db8084f2079cb0a5c5c2cd653b82adfa1b26cb..5d0af2855f82aca27a2e132b370a6fb99b875568 100644 --- a/src/QUI/Bricks/Manager.php +++ b/src/QUI/Bricks/Manager.php @@ -106,6 +106,8 @@ public static function getUIDTable() * @param Brick $Brick * * @return integer - Brick-ID + * + * @throws QUI\Exception */ public function createBrickForProject(Project $Project, Brick $Brick) { @@ -133,10 +135,12 @@ public function createBrickForProject(Project $Project, Brick $Brick) * @param Site $Site * @param array $brickData * @return string - Unique ID + * + * @throws QUI\Exception */ public function createUniqueSiteBrick(Site $Site, $brickData = array()) { - if (isset($brickData['uid']) || empty($brickData['uid'])) { + if (!empty($brickData['uid'])) { $uid = $brickData['uid']; if ($this->existsUniqueBrickId($uid) === false) { @@ -172,6 +176,8 @@ public function createUniqueSiteBrick(Site $Site, $brickData = array()) * @param integer $brickId - Brick ID * @param Site $Site - Current Site * @return bool + * + * @throws QUI\Exception */ protected function createUniqueBrickId($brickId, $Site) { @@ -222,6 +228,7 @@ public function clearCache() * Delete the brick * * @param integer $brickId - Brick-ID + * @throws QUI\Exception */ public function deleteBrick($brickId) { @@ -687,8 +694,9 @@ public function getBricksByArea($brickArea, QUI\Interfaces\Projects\Site $Site) * Return a list with \QUI\Bricks\Brick which are assigned to a project * * @param Project $Project - * * @return array + * + * @throws QUI\Exception */ public function getBricksFromProject(Project $Project) { @@ -712,6 +720,7 @@ public function getBricksFromProject(Project $Project) /** * @param string|integer $brickId - Brick-ID * @param array $brickData - Brick data + * @throws QUI\Exception */ public function saveBrick($brickId, array $brickData) {