From acd2607842ce4c24066d444fbe2243ed6990dea3 Mon Sep 17 00:00:00 2001 From: iCodr8 Date: Mon, 30 May 2016 00:57:19 +0200 Subject: [PATCH] init --- .gitignore | 18 + LICENSE | 19 + README.md | 47 +++ composer.json | 34 ++ src/Account/Account.php | 362 ++++++++++++++++++ src/Account/Member/Account.php | 27 ++ src/Account/User/Account.php | 27 ++ src/CraffftAccountmailBundle.php | 21 + src/DependencyInjection/Configuration.php | 38 ++ .../CraffftAccountmailExtension.php | 38 ++ src/Resources/config/services.yml | 3 + src/Resources/contao/config/config.php | 35 ++ src/Resources/contao/dca/tl_email.php | 103 +++++ src/Resources/contao/dca/tl_member.php | 63 +++ src/Resources/contao/dca/tl_settings.php | 33 ++ src/Resources/contao/dca/tl_user.php | 53 +++ src/Resources/contao/languages/de/default.php | 17 + src/Resources/contao/languages/de/modules.php | 15 + .../contao/languages/de/tl_email.php | 64 ++++ .../contao/languages/de/tl_member.php | 16 + .../contao/languages/de/tl_settings.php | 21 + src/Resources/contao/languages/de/tl_user.php | 16 + src/Resources/contao/languages/en/default.php | 17 + src/Resources/contao/languages/en/modules.php | 15 + .../contao/languages/en/tl_email.php | 64 ++++ .../contao/languages/en/tl_member.php | 16 + .../contao/languages/en/tl_settings.php | 21 + src/Resources/contao/languages/en/tl_user.php | 16 + src/Resources/public/icon.png | Bin 0 -> 3319 bytes src/Util/Email.php | 167 ++++++++ src/Util/Helpwizard.php | 62 +++ src/Util/InsertTags.php | 35 ++ src/Util/Updater.php | 94 +++++ 33 files changed, 1577 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 composer.json create mode 100644 src/Account/Account.php create mode 100644 src/Account/Member/Account.php create mode 100644 src/Account/User/Account.php create mode 100644 src/CraffftAccountmailBundle.php create mode 100644 src/DependencyInjection/Configuration.php create mode 100644 src/DependencyInjection/CraffftAccountmailExtension.php create mode 100644 src/Resources/config/services.yml create mode 100644 src/Resources/contao/config/config.php create mode 100644 src/Resources/contao/dca/tl_email.php create mode 100644 src/Resources/contao/dca/tl_member.php create mode 100644 src/Resources/contao/dca/tl_settings.php create mode 100644 src/Resources/contao/dca/tl_user.php create mode 100644 src/Resources/contao/languages/de/default.php create mode 100644 src/Resources/contao/languages/de/modules.php create mode 100644 src/Resources/contao/languages/de/tl_email.php create mode 100644 src/Resources/contao/languages/de/tl_member.php create mode 100644 src/Resources/contao/languages/de/tl_settings.php create mode 100644 src/Resources/contao/languages/de/tl_user.php create mode 100644 src/Resources/contao/languages/en/default.php create mode 100644 src/Resources/contao/languages/en/modules.php create mode 100644 src/Resources/contao/languages/en/tl_email.php create mode 100644 src/Resources/contao/languages/en/tl_member.php create mode 100644 src/Resources/contao/languages/en/tl_settings.php create mode 100644 src/Resources/contao/languages/en/tl_user.php create mode 100644 src/Resources/public/icon.png create mode 100644 src/Util/Email.php create mode 100644 src/Util/Helpwizard.php create mode 100644 src/Util/InsertTags.php create mode 100644 src/Util/Updater.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ff8e188 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# OS +.DS_Store +Thumbs.db + +# IDEs +.buildpath +.project +.settings/ +.build/ +.external*/ +.idea/ +nbproject/ + +# composer related +vendor/ + +# build +build/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d8fe9ba --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2014-2016 Daniel Kiesel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..be01379 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +Contao 4 Accountmail Bundle +======================= + +Adds a accountmail frontend module for Contao OpenSource CMS + +Installation +------------ + +### Step 1: Download the Bundle + +Open a command console, enter your project directory and execute the +following command to download the latest stable version of this bundle: + +```bash +$ composer require craffft/accountmail-bundle "dev-master" +``` + +This command requires you to have Composer installed globally, as explained +in the [installation chapter](https://getcomposer.org/doc/00-intro.md) +of the Composer documentation. + +### Step 2: Enable the Bundle + +Then, enable the bundle by adding it to the list of registered bundles +in the `app/AppKernel.php` file of your project: + +```php +=5.4.0", + "contao/core-bundle": "~4.1" + }, + "conflict": { + "contao/core": "*" + }, + "autoload": { + "psr-4": { + "Craffft\\AccountmailBundle\\": "src/" + } + }, + "extra": { + "branch-alias": { + "dev-develop": "4.2.x-dev" + } + } +} diff --git a/src/Account/Account.php b/src/Account/Account.php new file mode 100644 index 0000000..12a1e55 --- /dev/null +++ b/src/Account/Account.php @@ -0,0 +1,362 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle\Account; + +use Contao\Controller; +use Contao\Database; +use Contao\DataContainer; +use Contao\Date; +use Contao\Encryption; +use Contao\Input; +use Contao\Message; +use Contao\Model; +use Craffft\AccountmailBundle\Util\Email; + +abstract class Account extends Controller +{ + /** + * @var array + */ + protected $arrParameters = array(); + + /** + * @param DataContainer $dc + * @return mixed + */ + abstract protected function isDisabledAccountmail(DataContainer $dc); + + /** + * @param null $dc + */ + public function handlePalettesAndSubpalettes($dc = null) + { + // Front end call + if (!$dc instanceof DataContainer) { + return; + } + + if ($this->isDisabledAccountmail($dc)) { + // Palettes + if (is_array($GLOBALS['TL_DCA'][$dc->table]['palettes'])) { + foreach ($GLOBALS['TL_DCA'][$dc->table]['palettes'] as $k => $v) { + $GLOBALS['TL_DCA'][$dc->table]['palettes'][$k] = str_replace( + ',sendLoginData', + '', + $GLOBALS['TL_DCA'][$dc->table]['palettes'][$k] + ); + } + } + + // Subpalettes + if (is_array($GLOBALS['TL_DCA'][$dc->table]['subpalettes'])) { + foreach ($GLOBALS['TL_DCA'][$dc->table]['subpalettes'] as $k => $v) { + $GLOBALS['TL_DCA'][$dc->table]['subpalettes'][$k] = str_replace( + ',sendLoginData', + '', + $GLOBALS['TL_DCA'][$dc->table]['subpalettes'][$k] + ); + } + } + } + } + + /** + * @param null $dc + * @throws \Exception + */ + public function setAutoPassword($dc = null) + { + // Front end call + if (!$dc instanceof DataContainer) { + return; + } + + if ($this->isDisabledAccountmail($dc)) { + return; + } + + $intId = $dc->id; + + if (Input::get('act') == 'overrideAll' && Input::get('fields') && $intId === null) { + // Define indicator for given or not given password on overrideAll mode + if (!isset($GLOBALS['ACCOUNTMAIL']['AUTO_PASSWORD'])) { + $strPassword = $this->getPostPassword(); + $GLOBALS['ACCOUNTMAIL']['AUTO_PASSWORD'] = ($strPassword == '' || $strPassword == '*****') ? true : false; + + if ($GLOBALS['ACCOUNTMAIL']['AUTO_PASSWORD'] === true) { + // Set password, that no error occurs with "password not set" + $strNewPassword = substr(str_shuffle('abcdefghkmnpqrstuvwxyzABCDEFGHKMNOPQRSTUVWXYZ0123456789'), 0, 8); + $this->setPostPassword($strNewPassword); + } + + Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['pw_changed']); + } + + return; + } + + $strPassword = $this->getPostPassword($intId); + + if ($strPassword !== null && $strPassword == '') { + $strModel = Model::getClassFromTable($dc->table); + $objAccount = $strModel::findByPk($intId); + + if ($objAccount !== null) { + $strNewPassword = substr(str_shuffle('abcdefghkmnpqrstuvwxyzABCDEFGHKMNOPQRSTUVWXYZ0123456789'), 0, 8); + $this->setPostPassword($strNewPassword, $intId); + Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['pw_changed']); + + $objAccount->password = Encryption::hash($strNewPassword); + $objAccount->save(); + } + } + } + + /** + * @param null $dc + */ + public function sendPasswordEmail($dc = null) + { + // Front end call + if (!$dc instanceof DataContainer) { + return; + } + + if ($this->isDisabledAccountmail($dc)) { + return; + } + + // Return if there is no active record + if (!$dc->activeRecord) { + return; + } + + // Send login data + if ($dc->activeRecord->sendLoginData == 1) { + // Set different passwords on overrideAll mode, when no password was given + if (Input::get('act') == 'overrideAll' && $GLOBALS['ACCOUNTMAIL']['AUTO_PASSWORD'] === true) { + $this->setPostPassword('', $dc->id); + } + + if ($this->getPostPassword($dc->id) == '' || $this->getPostPassword($dc->id) == '*****') { + // Set empty password + $this->setPostPassword('', $dc->id); + + // Generate new password + $this->setAutoPassword($dc); + } + + if ($this->getPostPassword($dc->id) != '' && $this->getPostPassword($dc->id) != '*****') { + $strType = $this->getType($dc); + $arrParameters = $this->getParameters($dc); + $strLanguage = $this->getAccountLanguage($dc); + + if (!strlen($strType)) { + return; + } + + if ($this->sendEmail($dc->activeRecord->email, $strType, $arrParameters, $strLanguage)) { + // Disable sendLoginData field + $dc->activeRecord->sendLoginData = ''; + + // Disable sendLoginData field in the database + Database::getInstance()->prepare("UPDATE " . $dc->table . " SET sendLoginData='', loginDataAlreadySent='1' WHERE id=?")->execute($dc->activeRecord->id); + + // Show success message + Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['login_data_send']); + } else { + // Show error message + Message::addError($GLOBALS['TL_LANG']['MSC']['login_data_not_send']); + } + } + } + } + + /** + * @param null $intId + * @return mixed + */ + protected function getPostPassword($intId = null) + { + return (Input::get('act') == 'editAll' && is_numeric($intId)) ? Input::post('password_' . $intId) : Input::post('password'); + } + + /** + * @param $strNewPassword + * @param null $intId + */ + protected function setPostPassword($strNewPassword, $intId = null) + { + if ((Input::get('act') == 'editAll' && is_numeric($intId))) { + Input::setPost('password_' . $intId, $strNewPassword); + Input::setPost('password_' . $intId . '_confirm', $strNewPassword); + } else { + Input::setPost('password', $strNewPassword); + Input::setPost('password_confirm', $strNewPassword); + } + } + + /** + * @param DataContainer $dc + * @return string + */ + protected function getType(DataContainer $dc) + { + $strType = 'emailNew%s'; + + if ($dc->activeRecord->loginDataAlreadySent) { + $strType = 'emailChanged%sPassword'; + } + + switch ($dc->table) { + case 'tl_member': + $strType = sprintf($strType, 'Member'); + break; + + case 'tl_user': + $strType = sprintf($strType, 'User'); + break; + + default: + $strType = ''; + break; + } + + return $strType; + } + + /** + * @param DataContainer $dc + * @return array + */ + protected function getParameters(DataContainer $dc) + { + if (!$dc->activeRecord) { + return array(); + } + + $dc->loadDataContainer($dc->table); + + $strType = $this->getType($dc); + + $arrParameters = array(); + $arrFields = $GLOBALS['TL_DCA'][$dc->table]['fields']; + + if (is_array($arrFields)) { + foreach ($arrFields as $strField => $arrField) { + if (isset($dc->activeRecord->$strField)) { + $arrParameters[$strField] = $this->renderParameterValue( + $dc->table, + $this->getAccountLanguage($dc), + $strField, + $dc->activeRecord->$strField); + } + } + } + + // Replace the password, because it's generated new + $arrParameters['password'] = $this->getPostPassword($dc->id); + + // HOOK: replaceAccountmailParameters + if (isset($GLOBALS['TL_HOOKS']['replaceAccountmailParameters']) && is_array($GLOBALS['TL_HOOKS']['replaceAccountmailParameters'])) { + foreach ($GLOBALS['TL_HOOKS']['replaceAccountmailParameters'] as $callback) { + if (is_array($callback)) { + $this->import($callback[0]); + $arrParameters = $this->$callback[0]->$callback[1]($strType, $arrParameters, $dc); + } elseif (is_callable($callback)) { + $arrParameters = $callback($strType, $arrParameters, $dc); + } + } + } + + return $arrParameters; + } + + /** + * @param $strTable + * @param $strLanguage + * @param $strName + * @param $varValue + * @return string + */ + protected function renderParameterValue($strTable, $strLanguage, $strName, $varValue) + { + if ($varValue == '') { + return ''; + } + + $this->loadLanguageFile('default', $strLanguage, true); + $this->loadLanguageFile($strTable, $strLanguage, true); + $this->loadDataContainer($strTable); + + if ($GLOBALS['TL_DCA'][$strTable]['fields'][$strName]['inputType'] == 'password') { + return ''; + } + + $varValue = deserialize($varValue); + $rgxp = $GLOBALS['TL_DCA'][$strTable]['fields'][$strName]['eval']['rgxp']; + $opts = $GLOBALS['TL_DCA'][$strTable]['fields'][$strName]['options']; + $rfrc = $GLOBALS['TL_DCA'][$strTable]['fields'][$strName]['reference']; + + if ($rgxp == 'date') { + $varValue = Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $varValue); + } elseif ($rgxp == 'time') { + $varValue = Date::parse($GLOBALS['TL_CONFIG']['timeFormat'], $varValue); + } elseif ($rgxp == 'datim') { + $varValue = Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $varValue); + } elseif (is_array($varValue)) { + $varValue = implode(', ', $varValue); + } elseif (is_array($opts) && array_is_assoc($opts)) { + $varValue = isset($opts[$varValue]) ? $opts[$varValue] : $varValue; + } elseif (is_array($rfrc)) { + $varValue = isset($rfrc[$varValue]) ? ((is_array($rfrc[$varValue])) ? $rfrc[$varValue][0] : $rfrc[$varValue]) : $varValue; + } + + $varValue = specialchars($varValue); + + return (string)$varValue; + } + + /** + * @param DataContainer $dc + * @return string + */ + protected function getAccountLanguage(DataContainer $dc) + { + if ($dc->activeRecord->language) { + return $dc->activeRecord->language; + } + + return ''; + } + + /** + * @param $strRecipient + * @param $strType + * @param $arrParameters + * @param null $strForceLanguage + * @return bool + */ + protected function sendEmail($strRecipient, $strType, $arrParameters, $strForceLanguage = null) + { + $objEmail = new Email($strType, $strForceLanguage); + + if (is_array($arrParameters)) { + foreach ($arrParameters as $k => $v) { + $objEmail->addParameter($k, $v); + } + } + + // Send email + return $objEmail->sendTo($strRecipient); + } +} diff --git a/src/Account/Member/Account.php b/src/Account/Member/Account.php new file mode 100644 index 0000000..9644704 --- /dev/null +++ b/src/Account/Member/Account.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle\Account\Member; + +use Contao\DataContainer; +use Craffft\AccountmailBundle\Account\Account as AccountParent; + +class Account extends AccountParent +{ + protected function isDisabledAccountmail(DataContainer $dc) + { + if ($GLOBALS['TL_CONFIG']['disableMemberAccountmail']) { + return true; + } + + return false; + } +} diff --git a/src/Account/User/Account.php b/src/Account/User/Account.php new file mode 100644 index 0000000..ff1e448 --- /dev/null +++ b/src/Account/User/Account.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle\Account\User; + +use Contao\DataContainer; +use Craffft\AccountmailBundle\Account\Account as AccountParent; + +class Account extends AccountParent +{ + protected function isDisabledAccountmail(DataContainer $dc) + { + if ($GLOBALS['TL_CONFIG']['disableUserAccountmail']) { + return true; + } + + return false; + } +} diff --git a/src/CraffftAccountmailBundle.php b/src/CraffftAccountmailBundle.php new file mode 100644 index 0000000..b966ddc --- /dev/null +++ b/src/CraffftAccountmailBundle.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +/** + * Configures the Craffft Accountmail Bundle. + */ +class CraffftAccountmailBundle extends Bundle +{ +} diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php new file mode 100644 index 0000000..a075c5a --- /dev/null +++ b/src/DependencyInjection/Configuration.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle\DependencyInjection; + +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; + +/** + * This is the class that validates and merges configuration from your app/config files + * + * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} + */ +class Configuration implements ConfigurationInterface +{ + /** + * @return TreeBuilder + */ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('craffft_accountmail'); + + // Here you should define the parameters that are allowed to + // configure your bundle. See the documentation linked above for + // more information on that topic. + + return $treeBuilder; + } +} diff --git a/src/DependencyInjection/CraffftAccountmailExtension.php b/src/DependencyInjection/CraffftAccountmailExtension.php new file mode 100644 index 0000000..52c3873 --- /dev/null +++ b/src/DependencyInjection/CraffftAccountmailExtension.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle\DependencyInjection; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\Loader; + +/** + * This is the class that loads and manages your bundle configuration + * + * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} + */ +class CraffftAccountmailExtension extends Extension +{ + /** + * @param array $configs + * @param ContainerBuilder $container + */ + public function load(array $configs, ContainerBuilder $container) + { + $configuration = new Configuration(); + $config = $this->processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } +} diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml new file mode 100644 index 0000000..2eddc00 --- /dev/null +++ b/src/Resources/config/services.yml @@ -0,0 +1,3 @@ +services: + craffft.accountmail.util.helpwizard: + class: Craffft\AccountmailBundle\Util\Helpwizard diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php new file mode 100644 index 0000000..0f26c27 --- /dev/null +++ b/src/Resources/contao/config/config.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * EMAIL CONFIGURATION + */ +$GLOBALS['TL_EMAIL'] = array +( + 'emailNewMember', + 'emailChangedMemberPassword', + 'emailNewUser', + 'emailChangedUserPassword' +); + +/** + * BACK END MODULES + */ +$GLOBALS['BE_MOD']['content']['email'] = array +( + 'tables' => array('tl_email'), + 'icon' => 'bundle/craffftaccountmail/icon.png' +); + +/** + * HOOKS + */ +$GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array('\\Craffft\\AccountmailBundle\\Util\\InsertTags', 'replaceInsertTags'); diff --git a/src/Resources/contao/dca/tl_email.php b/src/Resources/contao/dca/tl_email.php new file mode 100644 index 0000000..3437c94 --- /dev/null +++ b/src/Resources/contao/dca/tl_email.php @@ -0,0 +1,103 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Table tl_email + */ +$GLOBALS['TL_DCA']['tl_email'] = array +( + // Config + 'config' => array + ( + 'dataContainer' => 'File' + ), + // Palettes + 'palettes' => array + ( + 'default' => '{emailSender_legend},emailFrom,emailFromName' + ), + // Fields + 'fields' => array + ( + // Email sender + 'emailFrom' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_email']['emailFrom'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => true, 'rgxp' => 'email', 'tl_class' => 'w50') + ), + 'emailFromName' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_email']['emailFromName'], + 'exclude' => true, + 'inputType' => 'TranslationTextField', + 'eval' => array('mandatory' => true, 'rgxp' => 'alpha', 'tl_class' => 'w50') + ) + ) +); + +/** + * Add email fields dynamically + */ +if (is_array($GLOBALS['TL_EMAIL'])) { + foreach ($GLOBALS['TL_EMAIL'] as $strName) { + $arrReferences = array(); + $arrReferences[] = $GLOBALS['TL_LANG']['tl_email']['helpwizard']; + + switch ($strName) { + case 'emailNewMember': + case 'emailChangedMemberPassword': + $arrReferences = array_merge($arrReferences, \System::getContainer()->get('craffft.accountmail.util.helpwizard')->getHelpwizardReferencesByMember()); + break; + + case 'emailNewUser': + case 'emailChangedUserPassword': + $arrReferences = array_merge($arrReferences, \System::getContainer()->get('craffft.accountmail.util.helpwizard')->getHelpwizardReferencesByUser()); + break; + } + + $GLOBALS['TL_DCA']['tl_email']['palettes']['default'] .= sprintf(';{%s_legend:hide}', $strName); + $GLOBALS['TL_DCA']['tl_email']['palettes']['default'] .= sprintf(',%s%s', $strName, 'Subject'); + $GLOBALS['TL_DCA']['tl_email']['palettes']['default'] .= sprintf(',%s%s', $strName, 'Template'); + $GLOBALS['TL_DCA']['tl_email']['palettes']['default'] .= sprintf(',%s%s', $strName, 'Content'); + + $GLOBALS['TL_DCA']['tl_email']['fields'][$strName . 'Subject'] = array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_email']['emailSubject'], + 'exclude' => true, + 'inputType' => 'TranslationTextField', + 'reference' => $arrReferences, + 'eval' => array('mandatory' => true, 'helpwizard' => true, 'tl_class' => 'w50') + ); + + $GLOBALS['TL_DCA']['tl_email']['fields'][$strName . 'Template'] = array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_email']['emailTemplate'], + 'default' => 'mail_default', + 'exclude' => true, + 'inputType' => 'select', + 'options_callback' => function () { + return \Contao\Backend::getTemplateGroup('mail_'); + }, + 'eval' => array('mandatory' => true, 'tl_class' => 'w50') + ); + + $GLOBALS['TL_DCA']['tl_email']['fields'][$strName . 'Content'] = array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_email']['emailContent'], + 'exclude' => true, + 'inputType' => 'TranslationTextArea', + 'reference' => $arrReferences, + 'eval' => array('mandatory' => true, 'helpwizard' => true, 'rte' => 'tinyFlash', 'tl_class' => 'clr') + ); + } +} diff --git a/src/Resources/contao/dca/tl_member.php b/src/Resources/contao/dca/tl_member.php new file mode 100644 index 0000000..b708fa0 --- /dev/null +++ b/src/Resources/contao/dca/tl_member.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +// Config +$GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'][] = array( + 'Craffft\\AccountmailBundle\\Account\\Member\\Account', + 'handlePalettesAndSubpalettes' +); +$GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'][] = array( + 'Craffft\\AccountmailBundle\\Account\\Member\\Account', + 'setAutoPassword' +); +$GLOBALS['TL_DCA']['tl_member']['config']['onsubmit_callback'][] = array( + 'Craffft\\AccountmailBundle\\Account\\Member\\Account', + 'sendPasswordEmail' +); + +// Palettes +if (is_array($GLOBALS['TL_DCA']['tl_member']['palettes'])) { + foreach ($GLOBALS['TL_DCA']['tl_member']['palettes'] as $k => $v) { + $GLOBALS['TL_DCA']['tl_member']['palettes'][$k] = preg_replace( + '#([,;]+)password([,;]?)#', + '$1password,sendLoginData$2', + $v + ); + } +} + +// Subpalettes +if (is_array($GLOBALS['TL_DCA']['tl_member']['subpalettes'])) { + foreach ($GLOBALS['TL_DCA']['tl_member']['subpalettes'] as $k => $v) { + $GLOBALS['TL_DCA']['tl_member']['subpalettes'][$k] = preg_replace( + '#([,;]+)password([,;]?)#', + '$1password,sendLoginData$2', + $v + ); + } +} + +// Fields +$GLOBALS['TL_DCA']['tl_member']['fields']['sendLoginData'] = array +( + 'label' => &$GLOBALS['TL_LANG']['tl_member']['sendLoginData'], + 'exclude' => true, + 'default' => 1, + 'inputType' => 'checkbox', + 'eval' => array('tl_class' => 'w50'), + 'sql' => "char(1) NOT NULL default ''" +); + +$GLOBALS['TL_DCA']['tl_member']['fields']['loginDataAlreadySent'] = array +( + 'label' => &$GLOBALS['TL_LANG']['tl_member']['loginDataAlreadySent'], + 'sql' => "char(1) NOT NULL default ''" +); diff --git a/src/Resources/contao/dca/tl_settings.php b/src/Resources/contao/dca/tl_settings.php new file mode 100644 index 0000000..99c18a8 --- /dev/null +++ b/src/Resources/contao/dca/tl_settings.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +// Palettes +$strPalette = '{accountmail_legend},disableMemberAccountmail,disableUserAccountmail'; +$GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] = preg_replace( + '#([;]?)$#', + ';' . $strPalette, + $GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] +); + +// Fields +$GLOBALS['TL_DCA']['tl_settings']['fields']['disableMemberAccountmail'] = array +( + 'label' => &$GLOBALS['TL_LANG']['tl_settings']['disableMemberAccountmail'], + 'inputType' => 'checkbox', + 'eval' => array('tl_class' => 'w50') +); + +$GLOBALS['TL_DCA']['tl_settings']['fields']['disableUserAccountmail'] = array +( + 'label' => &$GLOBALS['TL_LANG']['tl_settings']['disableUserAccountmail'], + 'inputType' => 'checkbox', + 'eval' => array('tl_class' => 'w50') +); diff --git a/src/Resources/contao/dca/tl_user.php b/src/Resources/contao/dca/tl_user.php new file mode 100644 index 0000000..f1065df --- /dev/null +++ b/src/Resources/contao/dca/tl_user.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +// Config +$GLOBALS['TL_DCA']['tl_user']['config']['onload_callback'][] = array( + 'Craffft\\AccountmailBundle\\Account\\User\\Account', + 'handlePalettesAndSubpalettes' +); +$GLOBALS['TL_DCA']['tl_user']['config']['onload_callback'][] = array( + 'Craffft\\AccountmailBundle\\Account\\User\\Account', + 'setAutoPassword' +); +$GLOBALS['TL_DCA']['tl_user']['config']['onsubmit_callback'][] = array( + 'Craffft\\AccountmailBundle\\Account\\User\\Account', + 'sendPasswordEmail' +); + +// Palettes +if (is_array($GLOBALS['TL_DCA']['tl_user']['palettes'])) { + foreach ($GLOBALS['TL_DCA']['tl_user']['palettes'] as $k => $v) { + if ($k == 'login') { + continue; + } + + $GLOBALS['TL_DCA']['tl_user']['palettes'][$k] = preg_replace('#([,;]+)password([,;]?)#', + '$1password,sendLoginData$2', $v); + } +} + +// Fields +$GLOBALS['TL_DCA']['tl_user']['fields']['sendLoginData'] = array +( + 'label' => &$GLOBALS['TL_LANG']['tl_user']['sendLoginData'], + 'exclude' => true, + 'default' => 1, + 'inputType' => 'checkbox', + 'eval' => array('tl_class' => 'w50'), + 'sql' => "char(1) NOT NULL default ''" +); + +$GLOBALS['TL_DCA']['tl_user']['fields']['loginDataAlreadySent'] = array +( + 'label' => &$GLOBALS['TL_LANG']['tl_user']['loginDataAlreadySent'], + 'sql' => "char(1) NOT NULL default ''" +); diff --git a/src/Resources/contao/languages/de/default.php b/src/Resources/contao/languages/de/default.php new file mode 100644 index 0000000..c33fd5c --- /dev/null +++ b/src/Resources/contao/languages/de/default.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Miscellaneous + */ +$GLOBALS['TL_LANG']['MSC']['helpwizard_insert_tag'] = 'Gibt das Feld "%s" anstelle des Insert-Tags aus.'; +$GLOBALS['TL_LANG']['MSC']['login_data_send'] = 'Die neuen Zugangsdaten wurden per E-Mail zugesendet.'; +$GLOBALS['TL_LANG']['MSC']['login_data_not_send'] = 'Die neuen Zugangsdaten konnten leider nicht per E-Mail zugesendet werden.'; diff --git a/src/Resources/contao/languages/de/modules.php b/src/Resources/contao/languages/de/modules.php new file mode 100644 index 0000000..d9d4f10 --- /dev/null +++ b/src/Resources/contao/languages/de/modules.php @@ -0,0 +1,15 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Back end modules + */ +$GLOBALS['TL_LANG']['MOD']['email'] = array('E-Mail Inhalte', 'Hier können Sie die Inhalte der automatischen Account E-Mails verändern.'); diff --git a/src/Resources/contao/languages/de/tl_email.php b/src/Resources/contao/languages/de/tl_email.php new file mode 100644 index 0000000..3c3b908 --- /dev/null +++ b/src/Resources/contao/languages/de/tl_email.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Title + */ +$GLOBALS['TL_LANG']['tl_email']['edit'] = 'Automatisierte E-Mails bearbeiten'; + +/** + * Labels + */ +$GLOBALS['TL_LANG']['tl_email']['emailSender_legend'] = 'E-Mail Absender'; +$GLOBALS['TL_LANG']['tl_email']['emailNewMember_legend'] = 'Neues Mitglied'; +$GLOBALS['TL_LANG']['tl_email']['emailChangedMemberPassword_legend'] = 'Passwort bei Mitglied geändert'; +$GLOBALS['TL_LANG']['tl_email']['emailNewUser_legend'] = 'Neuer Benutzer'; +$GLOBALS['TL_LANG']['tl_email']['emailChangedUserPassword_legend'] = 'Passwort bei Benutzer geändert'; + +/** + * Fields + */ +$GLOBALS['TL_LANG']['tl_email']['emailFrom'] = array('Absender E-Mail Adresse', 'Bitte geben Sie die E-Mail Adresse des Absenders ein.'); +$GLOBALS['TL_LANG']['tl_email']['emailFromName'] = array('Absender Name', 'Bitte geben Sie den Name des Absenders ein.'); +$GLOBALS['TL_LANG']['tl_email']['emailSubject'] = array('Betreff', 'Bitte geben Sie den Betreff ein.'); +$GLOBALS['TL_LANG']['tl_email']['emailTemplate'] = array('Template', 'Bitte wählen Sie das E-Mail Template aus.'); +$GLOBALS['TL_LANG']['tl_email']['emailContent'] = array('Inhalt', 'Bitte geben Sie den Inhalt der E-Mail ein.'); + +/** + * Helpwizard + */ +$GLOBALS['TL_LANG']['tl_email']['helpwizard'] = array('Allgemeine Beschreibung', 'Sie können in diesem Feld die Contao Insert-Tags und die, der Erweiterung "Inserttags" verwenden.
WICHTIG: Jeder Insert-Tag muss das Flag "|refresh" haben, denn sonst kann es zu fehlerhaften E-Mails kommen.
Unter anderem können Sie auch die folgenden Platzhalter nutzen:'); + +/** + * Default contents + */ +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailFromName'] = 'Contao CMS'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailNewMemberSubject'] = 'Neuer Mitglieder Account'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailNewMemberContent'] = '

Hallo {{accountmail::firstname|refresh}} {{accountmail::lastname|refresh}},

+

Es wurde ein neuer Account für Sie erstellt.

+

Ihre Zugangsdaten lauten wie folgt:
Name: {{accountmail::username|refresh}}
Passwort: {{accountmail::password|refresh}}

+

Gesendet mit der Contao CMS Accountmail Erweiterung.

'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailChangedMemberPasswordSubject'] = 'Neues Mitglieder Passwort'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailChangedMemberPasswordContent'] = '

Hallo {{accountmail::firstname|refresh}} {{accountmail::lastname|refresh}},

+

Sie haben ein neues Passwort für Ihren Mitglieder Account "{{accountmail::username|refresh}}" erhalten.

+

Es lautet:
{{accountmail::password|refresh}}

+

Gesendet mit der Contao CMS Accountmail Erweiterung.

'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailNewUserSubject'] = 'Neuer Contao Benutzer Account'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailNewUserContent'] = '

Hallo {{accountmail::name|refresh}},

+

Es wurde ein neuer Contao Account für Sie erstellt.

+

Sie können sich unter folgender Adresse einloggen:
http://{{env::host|refresh}}/contao

+

Ihre Zugangsdaten lauten wie folgt:
Name: {{accountmail::username|refresh}}
Passwort: {{accountmail::password|refresh}}

+

Gesendet mit der Contao CMS Accountmail Erweiterung.

'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailChangedUserPasswordSubject'] = 'Neues Contao Benutzer Passwort'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailChangedUserPasswordContent'] = '

Hallo {{accountmail::name|refresh}},

+

Sie haben ein neues Passwort für Ihren Benutzer Account "{{accountmail::username|refresh}}" erhalten.

+

Es lautet:
{{accountmail::password|refresh}}

+

Gesendet mit der Contao CMS Accountmail Erweiterung.

'; diff --git a/src/Resources/contao/languages/de/tl_member.php b/src/Resources/contao/languages/de/tl_member.php new file mode 100644 index 0000000..827e592 --- /dev/null +++ b/src/Resources/contao/languages/de/tl_member.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Fields + */ +$GLOBALS['TL_LANG']['tl_member']['sendLoginData'] = array('Login zusenden', 'Bitte wählen Sie dieses Feld aus, wenn Sie die Zugangsdaten per E-Mail zusenden möchten.'); +$GLOBALS['TL_LANG']['tl_member']['loginDataAlreadySent'] = array('Login gesendet', 'Dieses Feld ist aktiv, wenn die Logindaten bereits einmal dem Mitglied zugesendet wurden.'); diff --git a/src/Resources/contao/languages/de/tl_settings.php b/src/Resources/contao/languages/de/tl_settings.php new file mode 100644 index 0000000..e116580 --- /dev/null +++ b/src/Resources/contao/languages/de/tl_settings.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Legends + */ +$GLOBALS['TL_LANG']['tl_settings']['accountmail_legend'] = 'Account Mail'; + +/** + * Fields + */ +$GLOBALS['TL_LANG']['tl_settings']['disableMemberAccountmail'] = array('Mitglieder E-Mail Versand deaktivieren', 'Bitte wählen Sie dieses Feld aus, wenn Sie den E-Mail Versand für die Mitglieder deaktivieren möchten.'); +$GLOBALS['TL_LANG']['tl_settings']['disableUserAccountmail'] = array('Benutzer E-Mail Versand deaktivieren', 'Bitte wählen Sie dieses Feld aus, wenn Sie den E-Mail Versand für die Benutzer deaktivieren möchten.'); diff --git a/src/Resources/contao/languages/de/tl_user.php b/src/Resources/contao/languages/de/tl_user.php new file mode 100644 index 0000000..2d9b16c --- /dev/null +++ b/src/Resources/contao/languages/de/tl_user.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Fields + */ +$GLOBALS['TL_LANG']['tl_user']['sendLoginData'] = array('Login zusenden', 'Bitte wählen Sie dieses Feld aus, wenn Sie die Zugangsdaten per E-Mail zusenden möchten.'); +$GLOBALS['TL_LANG']['tl_user']['loginDataAlreadySent'] = array('Login gesendet', 'Dieses Feld ist aktiv, wenn die Logindaten bereits einmal dem Benutzer zugesendet wurden.'); diff --git a/src/Resources/contao/languages/en/default.php b/src/Resources/contao/languages/en/default.php new file mode 100644 index 0000000..b0e0a7d --- /dev/null +++ b/src/Resources/contao/languages/en/default.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Miscellaneous + */ +$GLOBALS['TL_LANG']['MSC']['helpwizard_insert_tag'] = 'Is the "%s" field instead of insert tags.'; +$GLOBALS['TL_LANG']['MSC']['login_data_send'] = 'The new login details have been sent via email.'; +$GLOBALS['TL_LANG']['MSC']['login_data_not_send'] = 'Unfortunately, the new access could not be sent via email.'; diff --git a/src/Resources/contao/languages/en/modules.php b/src/Resources/contao/languages/en/modules.php new file mode 100644 index 0000000..bcf61ef --- /dev/null +++ b/src/Resources/contao/languages/en/modules.php @@ -0,0 +1,15 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Back end modules + */ +$GLOBALS['TL_LANG']['MOD']['email'] = array('Email contents', 'Here you can change the contents of the automatic account emails.'); diff --git a/src/Resources/contao/languages/en/tl_email.php b/src/Resources/contao/languages/en/tl_email.php new file mode 100644 index 0000000..de459fb --- /dev/null +++ b/src/Resources/contao/languages/en/tl_email.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Title + */ +$GLOBALS['TL_LANG']['tl_email']['edit'] = 'Edit automated emails'; + +/** + * Labels + */ +$GLOBALS['TL_LANG']['tl_email']['emailSender_legend'] = 'Email sender'; +$GLOBALS['TL_LANG']['tl_email']['emailNewMember_legend'] = 'New member'; +$GLOBALS['TL_LANG']['tl_email']['emailChangedMemberPassword_legend'] = 'Password changed for member'; +$GLOBALS['TL_LANG']['tl_email']['emailNewUser_legend'] = 'New user'; +$GLOBALS['TL_LANG']['tl_email']['emailChangedUserPassword_legend'] = 'Password changed for user'; + +/** + * Fields + */ +$GLOBALS['TL_LANG']['tl_email']['emailFrom'] = array('Sender’s email address', 'Please enter the sender’s email address.'); +$GLOBALS['TL_LANG']['tl_email']['emailFromName'] = array('Sender’s name', 'Please enter the sender’s name.'); +$GLOBALS['TL_LANG']['tl_email']['emailSubject'] = array('Subject line', 'Please enter the subject here.'); +$GLOBALS['TL_LANG']['tl_email']['emailTemplate'] = array('Template', 'Please select the email template.'); +$GLOBALS['TL_LANG']['tl_email']['emailContent'] = array('Email content', 'Please enter the content of the email here.'); + +/** + * Helpwizard + */ +$GLOBALS['TL_LANG']['tl_email']['helpwizard'] = array('General description', 'You can use in this field the Contao insert tags and the extension "insert tags".
IMPORTANT: Each insert-tag must have the flag "| refresh", because otherwise it could lead to erroneous emails.
Among other things, you can also use the following wildcards:'); + +/** + * Default contents + */ +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailFromName'] = 'Contao CMS'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailNewMemberSubject'] = 'New member account'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailNewMemberContent'] = '

Hello {{accountmail::firstname|refresh}} {{accountmail::lastname|refresh}},

+

It was created a new account for you.

+

Your data are as follows:
Name: {{accountmail::username|refresh}}
Password: {{accountmail::password|refresh}}

+

Sent with the Contao CMS accountmail extension.

'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailChangedMemberPasswordSubject'] = 'New member password'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailChangedMemberPasswordContent'] = '

Hello {{accountmail::firstname|refresh}} {{accountmail::lastname|refresh}},

+

You receive a new password for your member account "{{accountmail::username|refresh}}".

+

It reads:
{{accountmail::password|refresh}}

+

Sent with the Contao CMS accountmail extension.

'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailNewUserSubject'] = 'New Contao user account'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailNewUserContent'] = '

Hello {{accountmail::name|refresh}},

+

It was a new Contao account created for you.

+

You can log in at the following address:
http://{{env::host|refresh}}/contao

+

Your data are as follows:
Name: {{accountmail::username|refresh}}
Password: {{accountmail::password|refresh}}

+

Sent with the Contao CMS accountmail extension.

'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailChangedUserPasswordSubject'] = 'New Contao user password'; +$GLOBALS['TL_LANG']['tl_email']['defaultContents']['emailChangedUserPasswordContent'] = '

Hello {{accountmail::name|refresh}},

+

You have a new password for your user account "{{accountmail::username|refresh}}" receive.

+

It reads:
{{accountmail::password|refresh}}

+

Sent with the Contao CMS accountmail extension.

'; diff --git a/src/Resources/contao/languages/en/tl_member.php b/src/Resources/contao/languages/en/tl_member.php new file mode 100644 index 0000000..cdc48b6 --- /dev/null +++ b/src/Resources/contao/languages/en/tl_member.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Fields + */ +$GLOBALS['TL_LANG']['tl_member']['sendLoginData'] = array('Send login details', 'Please select this field if you want to send the login details via email.'); +$GLOBALS['TL_LANG']['tl_member']['loginDataAlreadySent'] = array('Login details sent', 'This field is active when the login details have already been once sent to the member.'); diff --git a/src/Resources/contao/languages/en/tl_settings.php b/src/Resources/contao/languages/en/tl_settings.php new file mode 100644 index 0000000..33565ed --- /dev/null +++ b/src/Resources/contao/languages/en/tl_settings.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Legends + */ +$GLOBALS['TL_LANG']['tl_settings']['accountmail_legend'] = 'Account Mail'; + +/** + * Fields + */ +$GLOBALS['TL_LANG']['tl_settings']['disableMemberAccountmail'] = array('Disable member email shipping', 'Please select this field if you want to disable the emails to members.'); +$GLOBALS['TL_LANG']['tl_settings']['disableUserAccountmail'] = array('Disable user email shipping', 'Please select this field if you want to disable the emails to users.'); diff --git a/src/Resources/contao/languages/en/tl_user.php b/src/Resources/contao/languages/en/tl_user.php new file mode 100644 index 0000000..3c97509 --- /dev/null +++ b/src/Resources/contao/languages/en/tl_user.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Fields + */ +$GLOBALS['TL_LANG']['tl_user']['sendLoginData'] = array('Send login details', 'Please select this field if you want to send the login details via email.'); +$GLOBALS['TL_LANG']['tl_user']['loginDataAlreadySent'] = array('Login details sent', 'This field is active when the login details have already been once sent to the user.'); diff --git a/src/Resources/public/icon.png b/src/Resources/public/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..6c6c80a7cc2f1af8f0f0037f74ff296f331e2d5b GIT binary patch literal 3319 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 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle\Util; + +use Contao\BackendTemplate; +use Contao\BackendUser; +use Contao\Controller; +use Contao\Email as ContaoEmail; +use Contao\Environment; +use Contao\Idna; +use Contao\Session; +use Craffft\TranslationFieldsBundle\Service\Translator; + +class Email extends Controller +{ + /** + * @var + */ + protected $strType; + + /** + * @var + */ + protected $strForceLanguage; + + /** + * @var array + */ + protected $arrParameters = array(); + + /** + * @param $strType + * @param null $strForceLanguage + */ + public function __construct($strType, $strForceLanguage = null) + { + if (in_array($strType, $GLOBALS['TL_EMAIL'])) { + $this->strType = $strType; + } + + $this->strForceLanguage = $strForceLanguage; + + // Set default parameters + $this->addParameter('host', Idna::decode(Environment::get('host'))); + $this->addParameter('admin_name', BackendUser::getInstance()->name); + } + + /** + * @param $key + * @param $varValue + */ + public function addParameter($key, $varValue) + { + $this->arrParameters[$key] = $varValue; + } + + /** + * @param $key + */ + public function removeParameter($key) + { + if (isset($this->arrParameters[$key])) { + unset($this->arrParameters[$key]); + } + } + + /** + * @param $strRecipient + * @return bool + */ + public function sendTo($strRecipient) + { + if (!$this->strType) { + return false; + } + + $objEmail = new ContaoEmail(); + + $objEmail->from = $GLOBALS['TL_CONFIG']['emailFrom']; + $strEmailFromName = Translator::translateValue( + $GLOBALS['TL_CONFIG']['emailFromName'], + $this->strForceLanguage + ); + + // Add sender name + if ($strEmailFromName != '') { + $objEmail->fromName = $strEmailFromName; + } + + $strSubject = $this->getContent('subject'); + $strContent = $this->getContent(); + + $objEmail->embedImages = true; + $objEmail->imageDir = TL_ROOT . '/'; + $objEmail->subject = $strSubject; + + // Prepare html template + $objTemplate = new BackendTemplate($this->getEmailTemplate()); + + $objTemplate->title = $strSubject; + $objTemplate->body = $strContent; + $objTemplate->charset = $GLOBALS['TL_CONFIG']['characterSet']; + $objTemplate->css = ''; + $objTemplate->recipient = $strRecipient; + + // Parse html template + $objEmail->html = $objTemplate->parse(); + + // Send email + try { + $objEmail->sendTo($strRecipient); + } catch (\Swift_RfcComplianceException $e) { + return false; + } + + // Rejected recipients + if ($objEmail->hasFailures()) { + return false; + } + + return true; + } + + /** + * @return mixed + */ + protected function getEmailTemplate() + { + if (isset($GLOBALS['TL_CONFIG'][$this->strType . 'Template'])) { + return $GLOBALS['TL_CONFIG'][$this->strType . 'Template']; + } + } + + /** + * @param string $strName + * @return string + */ + protected function getContent($strName = 'content') + { + $strName = ucfirst(strtolower($strName)); + + if (isset($GLOBALS['TL_CONFIG'][$this->strType . $strName])) { + $strContent = Translator::translateValue( + $GLOBALS['TL_CONFIG'][$this->strType . $strName], + $this->strForceLanguage + ); + + $objSession = Session::getInstance(); + $objSession->set('ACCOUNTMAIL_PARAMETERS', $this->arrParameters); + + $strContent = $this->replaceInsertTags($strContent, false); + + $objSession->remove('ACCOUNTMAIL_PARAMETERS'); + + return $strContent; + } + } +} diff --git a/src/Util/Helpwizard.php b/src/Util/Helpwizard.php new file mode 100644 index 0000000..7d68913 --- /dev/null +++ b/src/Util/Helpwizard.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle\Util; + +use Contao\Controller; + +class Helpwizard extends Controller +{ + /** + * @return array + */ + public function getHelpwizardReferencesByMember() + { + return $this->getHelpwizardReferencesBy('tl_member'); + } + + /** + * @return array + */ + public function getHelpwizardReferencesByUser() + { + return $this->getHelpwizardReferencesBy('tl_user'); + } + + /** + * @param $strTable + * @return array + */ + protected function getHelpwizardReferencesBy($strTable) + { + $arrReferences = array(); + + $this->loadLanguageFile($strTable); + $this->loadDataContainer($strTable); + + if (isset($GLOBALS['TL_DCA'][$strTable]['fields']) && is_array($GLOBALS['TL_DCA'][$strTable]['fields'])) { + foreach ($GLOBALS['TL_DCA'][$strTable]['fields'] as $strField => $arrValues) { + $strLabel = $strField; + + if (isset($arrValues['label'][0]) && strlen($arrValues['label'][0])) { + $strLabel = $arrValues['label'][0]; + } + + $arrReferences[] = array( + sprintf('{{%s::%s|%s}}', 'accountmail', $strField, 'refresh'), + sprintf($GLOBALS['TL_LANG']['MSC']['helpwizard_insert_tag'], $strLabel) + ); + } + } + + return $arrReferences; + } +} diff --git a/src/Util/InsertTags.php b/src/Util/InsertTags.php new file mode 100644 index 0000000..664699f --- /dev/null +++ b/src/Util/InsertTags.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle\Util; + +use Contao\Session; + +class InsertTags +{ + public function replaceInsertTags($strTag) + { + $flags = explode('|', $strTag); + $tag = array_shift($flags); + list($strName, $strValue) = explode('::', $tag); + + if ($strName == 'accountmail') { + $objSession = Session::getInstance(); + $arrData = $objSession->get('ACCOUNTMAIL_PARAMETERS'); + + if (isset($arrData[$strValue])) { + return $arrData[$strValue]; + } + } + + return false; + } +} diff --git a/src/Util/Updater.php b/src/Util/Updater.php new file mode 100644 index 0000000..d906e14 --- /dev/null +++ b/src/Util/Updater.php @@ -0,0 +1,94 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\AccountmailBundle\Util; + +use Contao\ClassLoader; +use Contao\Controller; +use Contao\System; +use TranslationFields\TranslationFieldsModel; + +class Updater extends Controller +{ + public function __construct() + { + parent::__construct(); + + $this->import('Config'); + } + + /** + * Add default email contents to the configuration fields of the accountmail extension + */ + public function addDefaultEmailContents() + { + $this->addContentToField('emailFrom', $this->Config->get('adminEmail')); + $this->addContentToField('emailNewMemberTemplate', 'mail_default'); + $this->addContentToField('emailChangedMemberPasswordTemplate', 'mail_default'); + $this->addContentToField('emailNewUserTemplate', 'mail_default'); + $this->addContentToField('emailChangedUserPasswordTemplate', 'mail_default'); + + foreach ($this->getFieldNames() as $strField) { + $this->addTranslationContentToField($strField); + } + } + + /** + * @param $strField + * @param $strValue + */ + protected function addContentToField($strField, $strValue) + { + if ($this->Config->get($strField) === null) { + $this->Config->persist($strField, $strValue); + } + } + + /** + * @return array + */ + protected function getFieldNames() + { + $arrFields = array(); + $arrFields[] = 'emailFromName'; + + foreach ($GLOBALS['TL_EMAIL'] as $strField) { + $arrFields[] = $strField . 'Subject'; + $arrFields[] = $strField . 'Content'; + } + + return $arrFields; + } + + /** + * @param $strField + */ + protected function addTranslationContentToField($strField) + { + if ($this->Config->get($strField) === null) { + $arrValues = array(); + + System::loadLanguageFile('tl_email', 'de', true); + $arrValues['de'] = $GLOBALS['TL_LANG']['tl_email']['defaultContents'][$strField]; + + System::loadLanguageFile('tl_email', 'en', true); + $arrValues['en'] = $GLOBALS['TL_LANG']['tl_email']['defaultContents'][$strField]; + + // Load translation file by current language + System::loadLanguageFile('tl_email', null, true); + + $this->Config->persist( + $strField, + TranslationFieldsModel::saveValuesAndReturnFid($arrValues) + ); + } + } +}