diff --git a/Config/config.php b/Config/config.php index ce976ad..3dc57b3 100644 --- a/Config/config.php +++ b/Config/config.php @@ -5,31 +5,31 @@ 'description' => 'User can add multiple tracking domains for emails.', 'author' => 'Abdullah Kiser / Friendly Automate', 'version' => '1.0.1', - 'routes' => [ + 'routes' => [ 'main' => [ 'mautic_multidomain_index' => [ 'path' => '/multidomain/{page}', - 'controller' => 'MauticMultiDomainBundle:Multidomain:index', + 'controller' => 'MauticPlugin\MauticMultiDomainBundle\Controller\MultidomainController:indexAction', ], 'mautic_multidomain_action' => [ 'path' => '/multidomain/{objectAction}/{objectId}', - 'controller' => 'MauticMultiDomainBundle:Multidomain:execute', + 'controller' => 'MauticPlugin\MauticMultiDomainBundle\Controller\MultidomainController:executeAction', ], ], 'api' => [ 'mautic_api_multidomainstandard' => [ 'standard_entity' => true, - 'name' => 'multidomain', - 'path' => '/multidomain', - 'controller' => 'MauticMultiDomainBundle:Api\MultidomainApi', + 'name' => 'multidomain', + 'path' => '/multidomain', + 'controller' => 'MauticPlugin\MauticMultiDomainBundle\Controller\Api\MultidomainApiController', ], ], ], 'menu' => [ 'main' => [ 'mautic.multidomain.menu' => [ - 'route' => 'mautic_multidomain_index', - 'priority' => 10, + 'route' => 'mautic_multidomain_index', + 'priority' => 10, 'iconClass' => 'fa-globe', ], ], @@ -37,28 +37,13 @@ 'services' => [ 'forms' => [ 'mautic.form.type.multidomain' => [ - 'class' => \MauticPlugin\MauticMultiDomainBundle\Form\Type\MultidomainType::class, - ], - ], - 'models' => [ - 'mautic.multidomain.model.multidomain' => [ - 'class' => \MauticPlugin\MauticMultiDomainBundle\Model\MultidomainModel::class, - 'arguments' => [ - 'mautic.form.model.form', - 'mautic.page.model.trackable', - 'mautic.helper.templating', - 'event_dispatcher', - 'mautic.lead.model.field', - 'mautic.tracker.contact', - 'doctrine.orm.entity_manager', - ], - //'public' => true, - 'alias' => 'model.multidomain.multidomain' + 'class' => MauticPlugin\MauticMultiDomainBundle\Form\Type\MultidomainType::class, ], ], + 'models' => [], 'events' => [ 'mautic.multidomain.subscriber.multidomain' => [ - 'class' => \MauticPlugin\MauticMultiDomainBundle\EventListener\MultidomianSubscriber::class, + 'class' => MauticPlugin\MauticMultiDomainBundle\EventListener\MultidomianSubscriber::class, 'arguments' => [ 'router', 'mautic.helper.ip_lookup', @@ -71,7 +56,7 @@ ], ], 'mautic.multidomain.subscriber.emailbuilder' => [ - 'class' => \MauticPlugin\MauticMultiDomainBundle\EventListener\BuilderSubscriber::class, + 'class' => MauticPlugin\MauticMultiDomainBundle\EventListener\BuilderSubscriber::class, 'arguments' => [ 'mautic.helper.core_parameters', 'mautic.email.model.email', @@ -83,14 +68,6 @@ 'router', ], ], - 'mautic.multidomain.subscriber.buildjssubscriber' => [ - 'class' => \MauticPlugin\MauticMultiDomainBundle\EventListener\BuildJsSubscriber::class, - 'arguments' => [ - 'templating.helper.assets', - 'request_stack', - 'router', - ], - ], ], ], ]; diff --git a/Config/services.php b/Config/services.php new file mode 100644 index 0000000..b01b7b8 --- /dev/null +++ b/Config/services.php @@ -0,0 +1,34 @@ +services() + ->defaults() + ->autowire() + ->autoconfigure() + ->public(); + + $excludes = [ + 'Permissions', + ]; + + $services->load( + 'MauticPlugin\\MauticMultiDomainBundle\\', + __DIR__.'/../' + ) + ->exclude('../{'.implode(',', array_merge(MauticCoreExtension::DEFAULT_EXCLUDES, $excludes)).'}'); + + $services->load( + 'MauticPlugin\\MauticMultiDomainBundle\\Entity\\', + __DIR__.'/../Entity/*Repository.php' + ); + + $services->alias( + 'mautic.multidomain.model.multidomain', + MauticPlugin\MauticMultiDomainBundle\Model\MultidomainModel::class + ); +}; diff --git a/Controller/Api/MultidomainApiController.php b/Controller/Api/MultidomainApiController.php index 7e17469..76e1963 100644 --- a/Controller/Api/MultidomainApiController.php +++ b/Controller/Api/MultidomainApiController.php @@ -3,8 +3,8 @@ namespace MauticPlugin\MauticMultiDomainBundle\Controller\Api; use Mautic\ApiBundle\Controller\CommonApiController; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use MauticPlugin\MauticMultiDomainBundle\Entity\Multidomain; +use Symfony\Component\HttpKernel\Event\FilterControllerEvent; /** * Class MultidomainApiController. @@ -24,4 +24,4 @@ public function initialize(FilterControllerEvent $event) parent::initialize($event); } -} \ No newline at end of file +} diff --git a/Controller/MultidomainController.php b/Controller/MultidomainController.php index d5926eb..f5ec091 100644 --- a/Controller/MultidomainController.php +++ b/Controller/MultidomainController.php @@ -3,32 +3,24 @@ namespace MauticPlugin\MauticMultiDomainBundle\Controller; use Mautic\CoreBundle\Controller\AbstractStandardFormController; -use Mautic\CoreBundle\Form\Type\DateRangeType; -use MauticPlugin\MauticSpintaxBundle\Model\EmailVariation; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * Class MultidomainController. */ class MultidomainController extends AbstractStandardFormController { - /** - * @return string - */ - protected function getControllerBase() + protected function getModelName(): string { - return 'MauticMultiDomainBundle:Multidomain'; + return 'multidomain'; } - /** - * @return string - */ - protected function getModelName() + protected function getTemplateBase() { - return 'multidomain'; + return '@MauticMultiDomain/Multidomain'; } /** @@ -44,9 +36,9 @@ protected function getDefaultOrderColumn() * * @return JsonResponse|RedirectResponse|Response */ - public function indexAction($page = 1) + public function indexAction(Request $request, $page = 1) { - return parent::indexStandard($page); + return parent::indexStandard($request, $page); } /** @@ -54,9 +46,9 @@ public function indexAction($page = 1) * * @return JsonResponse|Response */ - public function newAction() + public function newAction(Request $request) { - return parent::newStandard(); + return parent::newStandard($request); } /** @@ -67,21 +59,19 @@ public function newAction() * * @return JsonResponse|Response */ - public function editAction($objectId, $ignorePost = false) + public function editAction(Request $request, $objectId, $ignorePost = false) { - return parent::editStandard($objectId, $ignorePost); - } + return parent::editStandard($request, $objectId, $ignorePost); + } /** * Displays details on a spintax. * - * @param $objectId - * * @return array|JsonResponse|RedirectResponse|Response */ - public function viewAction($objectId) + public function viewAction(Request $request, $objectId) { - return parent::viewStandard($objectId, 'maultidomain', 'plugin.maultidomain'); + return parent::viewStandard($request, $objectId, 'maultidomain', 'plugin.maultidomain'); } /** @@ -91,9 +81,9 @@ public function viewAction($objectId) * * @return JsonResponse|RedirectResponse|Response */ - public function cloneAction($objectId) + public function cloneAction(Request $request, $objectId) { - return parent::cloneStandard($objectId); + return parent::cloneStandard($request, $objectId); } /** @@ -103,9 +93,9 @@ public function cloneAction($objectId) * * @return JsonResponse|RedirectResponse */ - public function deleteAction($objectId) + public function deleteAction(Request $request, $objectId) { - return parent::deleteStandard($objectId); + return parent::deleteStandard($request, $objectId); } /** @@ -113,10 +103,8 @@ public function deleteAction($objectId) * * @return JsonResponse|RedirectResponse */ - public function batchDeleteAction() + public function batchDeleteAction(Request $request) { - return parent::batchDeleteStandard(); + return parent::batchDeleteStandard($request); } - - -} \ No newline at end of file +} diff --git a/DependencyInjection/MauticMultiDomainExtension.php b/DependencyInjection/MauticMultiDomainExtension.php new file mode 100644 index 0000000..d00d06b --- /dev/null +++ b/DependencyInjection/MauticMultiDomainExtension.php @@ -0,0 +1,22 @@ +load('services.php'); + } +} diff --git a/Entity/Multidomain.php b/Entity/Multidomain.php index 96f83bb..5981e13 100644 --- a/Entity/Multidomain.php +++ b/Entity/Multidomain.php @@ -4,18 +4,15 @@ use Doctrine\ORM\Mapping as ORM; use Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver; -use Symfony\Component\Validator\Constraints as Assert; -use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; -use Mautic\CategoryBundle\Entity\Category; use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder; use Mautic\CoreBundle\Entity\FormEntity; -use Mautic\FormBundle\Entity\Form; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; +use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Mapping\ClassMetadata; /** * This class processes payment requests from Webpayment - * Class Multidomain - * @package MauticPlugin\MauticMultiDomainBundle\Entity + * Class Multidomain. */ class Multidomain extends FormEntity { @@ -25,7 +22,6 @@ class Multidomain extends FormEntity private $id; /** - * * @var string */ private $email; @@ -37,7 +33,6 @@ class Multidomain extends FormEntity public static function loadValidatorMetadata(ClassMetadata $metadata) { - $metadata->addConstraint(new UniqueEntity([ 'fields' => 'email', ])); @@ -74,10 +69,7 @@ public static function loadValidatorMetadata(ClassMetadata $metadata) ); } - /** - * @param ORM\ClassMetadata $metadata - */ - public static function loadMetadata (ORM\ClassMetadata $metadata) + public static function loadMetadata(ORM\ClassMetadata $metadata): void { $builder = new ClassMetadataBuilder($metadata); @@ -86,7 +78,7 @@ public static function loadMetadata (ORM\ClassMetadata $metadata) // Helper functions $builder->addId(); - + $builder->createField('email', 'string') ->columnName('email') ->build(); @@ -94,15 +86,12 @@ public static function loadMetadata (ORM\ClassMetadata $metadata) $builder->createField('domain', 'text') ->columnName('domain') ->build(); - } /** * Prepares the metadata for API usage. - * - * @param $metadata */ - public static function loadApiMetadata(ApiMetadataDriver $metadata) + public static function loadApiMetadata(ApiMetadataDriver $metadata): void { $metadata->setGroupPrefix('multidomain') ->addListProperties( @@ -131,6 +120,7 @@ public function getEmail(): ?string public function setEmail(string $email): Multidomain { $this->email = $email; + return $this; } @@ -142,11 +132,12 @@ public function getDomain(): ?string public function setDomain(string $text): Multidomain { $this->domain = $text; + return $this; } /** - * Get Fake name to be compatable with getName of commonEntity. + * Get Fake name to be compatable with getName of commonEntity. */ public function getName() { @@ -154,12 +145,12 @@ public function getName() } /** - * Set Fake name to be compatable with getName of commonEntity. - * + * Set Fake name to be compatable with getName of commonEntity. */ public function setName(string $email): Multidomain { $this->email = $email; + return $this; } -} \ No newline at end of file +} diff --git a/Entity/MultidomainRepository.php b/Entity/MultidomainRepository.php index 3b4f7ca..16b33ed 100644 --- a/Entity/MultidomainRepository.php +++ b/Entity/MultidomainRepository.php @@ -5,7 +5,7 @@ use Mautic\CoreBundle\Entity\CommonRepository; /** - * MultidomainRepository + * MultidomainRepository. */ class MultidomainRepository extends CommonRepository { @@ -15,8 +15,8 @@ public function getByPublished($isPublished = true) $q->select('md') ->from(Multidomain::class, 'md') ->where('md.isPublished = :isPublished') - ->setParameters(['isPublished' => $isPublished]) - ; + ->setParameters(['isPublished' => $isPublished]); + return $q->getQuery()->getResult(); } -} \ No newline at end of file +} diff --git a/Event/MultidomainEvent.php b/Event/MultidomainEvent.php index a735244..df1833b 100644 --- a/Event/MultidomainEvent.php +++ b/Event/MultidomainEvent.php @@ -1,14 +1,5 @@ [ ['onEmailGenerate', 0], // Ensure this is done last in order to catch all tokenized URLs @@ -119,14 +101,14 @@ public static function getSubscribedEvents() } public function onEmailGenerate(EmailSendEvent $event) - { - $idHash = $event->getIdHash(); - $lead = $event->getLead(); - $email = $event->getEmail(); - $senderEmail = null; + { + $idHash = $event->getIdHash(); + $lead = $event->getLead(); + $email = $event->getEmail(); + $senderEmail = null; $senderDomain = null; - if(!$email instanceof Email){ + if (!$email instanceof Email) { return; } @@ -134,37 +116,38 @@ public function onEmailGenerate(EmailSendEvent $event) // Generate a bogus idHash to prevent errors for routes that may include it $idHash = uniqid(); } - + $unsubscribeText = $this->coreParametersHelper->get('unsubscribe_text'); - $webviewText = $this->coreParametersHelper->get('webview_text'); - + $webviewText = $this->coreParametersHelper->get('webview_text'); + // Check if the Mailer is Owner is set, if not then search the sender email from Email channels From address // And finally if nothing is set, use the mailer from email if it is not blank. - $senderEmail = $this->coreParametersHelper->get("mailer_from_email"); + $senderEmail = $this->coreParametersHelper->get('mailer_from_email'); $mailerIsOwnerGlobal = $this->coreParametersHelper->get('mailer_is_owner'); $mailerIsOwner = $email->getUseOwnerAsMailer(); - if(($mailerIsOwnerGlobal || $mailerIsOwner) && $lead['id']){ + if (($mailerIsOwnerGlobal || $mailerIsOwner) && $lead['id']) { $ownerEmail = $event->getTokens()['{ownerfield=email}'] ?? null; if (!empty($ownerEmail)) { $senderEmail = $ownerEmail; } } - if(empty($ownerEmail) && $email && $email->getFromAddress()){ + if (empty($ownerEmail) && $email && $email->getFromAddress()) { $senderEmail = $email->getFromAddress(); } - if($senderEmail){ + if ($senderEmail) { // Get the Domain from the MultiDomain Configuration by email. $multiDomain = $this->multidomainModel->getRepository()->findOneBy(['email' => $senderEmail]); - if($multiDomain){ + + if ($multiDomain) { $senderDomain = $multiDomain->getDomain(); - $messageId = $this->multidomainModel->generateMessageId($multiDomain); + $messageId = $this->multidomainModel->generateMessageId($multiDomain); $event->addTextHeader('Message-ID', $messageId); } } - + if (!$unsubscribeText) { $unsubscribeText = $this->translator->trans('mautic.email.unsubscribe.text', ['%link%' => '|URL|']); } @@ -173,7 +156,6 @@ public function onEmailGenerate(EmailSendEvent $event) $event->addToken('{unsubscribe_url}', $this->buildUrl('mautic_email_unsubscribe', ['idHash' => $idHash], true, [], [], $senderDomain)); - if (!$webviewText) { $webviewText = $this->translator->trans('mautic.email.webview.text', ['%link%' => '|URL|']); } @@ -232,8 +214,6 @@ public function convertUrlsToTokens(EmailSendEvent $event) /** * Parses content for URLs and tokens. * - * @param $emailId - * * @return mixed */ private function parseContentForUrls(EmailSendEvent $event, $emailId) @@ -277,26 +257,23 @@ private function parseContentForUrls(EmailSendEvent $event, $emailId) } private function buildUrl( - $route, - $routeParams = [], - $absolute = true, - $clickthrough = [], - $utmTags = [], + $route, + $routeParams = [], + $absolute = true, + $clickthrough = [], + $utmTags = [], $domain = null - ) - { - - - if($domain){ + ) { + if ($domain) { $parseUrl = parse_url($domain); - $context = $this->router->getGenerator()->getContext(); + $context = $this->router->getGenerator()->getContext(); $context->setHost($parseUrl['host']); $context->setScheme($parseUrl['scheme']); } - $referenceType = ($absolute) ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH; + $referenceType = ($absolute) ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH; $url = $this->router->generate($route, $routeParams, $referenceType); - + return $url.((!empty($clickthrough)) ? '?ct='.$this->encodeArrayForUrl($clickthrough) : ''); } } diff --git a/EventListener/MultidomianSubscriber.php b/EventListener/MultidomianSubscriber.php index dacdae4..1adc18c 100644 --- a/EventListener/MultidomianSubscriber.php +++ b/EventListener/MultidomianSubscriber.php @@ -1,14 +1,5 @@ router = $router; - $this->ipHelper = $ipLookupHelper; - $this->auditLogModel = $auditLogModel; - $this->trackableModel = $trackableModel; - $this->pageTokenHelper = $pageTokenHelper; - $this->assetTokenHelper = $assetTokenHelper; + $this->router = $router; + $this->ipHelper = $ipLookupHelper; + $this->auditLogModel = $auditLogModel; + $this->trackableModel = $trackableModel; + $this->pageTokenHelper = $pageTokenHelper; + $this->assetTokenHelper = $assetTokenHelper; $this->multidomainModel = $multidomainModel; - $this->requestStack = $requestStack; + $this->requestStack = $requestStack; } /** @@ -98,19 +89,19 @@ public function __construct( public static function getSubscribedEvents() { return [ - KernelEvents::REQUEST => ['onKernelRequest', 0], - 'mautic.multidomain_post_save' => ['onMultidomainPostSave', 0], - 'mautic.multidomain_delete' => ['onMultidomainDelete', 0], - 'mautic.multidomain_replacement' => ['onTokenReplacement', 0], + KernelEvents::REQUEST => ['onKernelRequest', 0], + 'mautic.multidomain_post_save' => ['onMultidomainPostSave', 0], + 'mautic.multidomain_delete' => ['onMultidomainDelete', 0], + 'mautic.multidomain_replacement' => ['onTokenReplacement', 0], ]; } /* * Check and hijack the form's generate link if the ID has mf- in it */ - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event) { - if ($event->isMasterRequest()) { + if ($event->isMainRequest()) { // get the current event request $request = $event->getRequest(); $requestUri = $request->getRequestUri(); @@ -120,7 +111,7 @@ public function onKernelRequest(GetResponseEvent $event) if (false !== strpos($requestUri, $formGenerateUrl)) { $id = InputHelper::_($this->requestStack->getCurrentRequest()->get('id')); if (0 === strpos($id, 'mf-')) { - $mfId = str_replace('mf-', '', $id); + $mfId = str_replace('mf-', '', $id); $multidomainGenerateUrl = $this->router->generate('mautic_multidomain_action', ['id' => $mfId]); $event->setResponse(new RedirectResponse($multidomainGenerateUrl)); @@ -144,9 +135,8 @@ public function onMultidomainPostSave(MultidomainEvent $event) 'details' => $details, 'ipAddress' => $this->ipHelper->getIpAddressFromRequest(), ]; - + $this->auditLogModel->writeToLog($log); - } } diff --git a/Form/Type/MultidomainType.php b/Form/Type/MultidomainType.php index 00e12c0..76b54ee 100644 --- a/Form/Type/MultidomainType.php +++ b/Form/Type/MultidomainType.php @@ -2,48 +2,42 @@ namespace MauticPlugin\MauticMultiDomainBundle\Form\Type; +use Mautic\CoreBundle\Form\Type\FormButtonsType; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; -use Symfony\Component\Form\Extension\Core\Type\SubmitType; -use Mautic\CoreBundle\Form\Type\FormButtonsType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Validator\Constraints\Callback; -use Symfony\Component\Validator\Context\ExecutionContextInterface; class MultidomainType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { - $builder ->add('email', TextType::class, [ - 'label' => 'plugin.multidomain.email', + 'label' => 'plugin.multidomain.email', 'required' => true, - 'attr' => ['class' => 'form-control'] + 'attr' => ['class' => 'form-control'], ]) ->add('domain', TextType::class, [ - 'label' => 'plugin.multidomain.domain', + 'label' => 'plugin.multidomain.domain', 'required' => true, - 'attr' => ['class' => 'form-control'] - ]) - ; - - $builder->add( - 'buttons', - FormButtonsType::class - ); + 'attr' => ['class' => 'form-control'], + ]); + + $builder->add( + 'buttons', + FormButtonsType::class + ); if (!empty($options['action'])) { $builder->setAction($options['action']); - } + } } - + /** * {@inheritdoc} */ - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'multidomain_type'; } -} \ No newline at end of file +} diff --git a/MauticMultiDomainBundle.php b/MauticMultiDomainBundle.php index 1dafee0..31b5681 100644 --- a/MauticMultiDomainBundle.php +++ b/MauticMultiDomainBundle.php @@ -2,8 +2,8 @@ namespace MauticPlugin\MauticMultiDomainBundle; -use Mautic\PluginBundle\Bundle\PluginBundleBase; use Mautic\CoreBundle\Factory\MauticFactory; +use Mautic\PluginBundle\Bundle\PluginBundleBase; use Mautic\PluginBundle\Entity\Plugin; /** @@ -11,7 +11,7 @@ */ class MauticMultiDomainBundle extends PluginBundleBase { - public static function onPluginInstall(Plugin $plugin, MauticFactory $factory, $metadata = null, $installedSchema = null) + public static function onPluginInstall(Plugin $plugin, MauticFactory $factory, $metadata = null, $installedSchema = null): void { if (null === $metadata) { $metadata = self::getMetadata($factory->getEntityManager()); diff --git a/Model/MultidomainModel.php b/Model/MultidomainModel.php index e616fc3..84fb4a4 100644 --- a/Model/MultidomainModel.php +++ b/Model/MultidomainModel.php @@ -1,44 +1,34 @@ formModel = $formModel; $this->trackableModel = $trackableModel; - $this->templating = $templating; - $this->dispatcher = $dispatcher; $this->leadFieldModel = $leadFieldModel; $this->contactTracker = $contactTracker; - static::$entityManager = $entityManager; } + /** + * MultidomainModel constructor. + */ + /*public function __construct( + \Mautic\FormBundle\Model\FormModel $formModel, + TrackableModel $trackableModel, + EventDispatcherInterface $dispatcher, + FieldModel $leadFieldModel, + ContactTracker $contactTracker, + EntityManager $entityManager + ) { + $this->formModel = $formModel; + $this->trackableModel = $trackableModel; + // $this->templating = $templating; + $this->dispatcher = $dispatcher; + $this->leadFieldModel = $leadFieldModel; + $this->contactTracker = $contactTracker; + + }*/ + /** * @return string */ @@ -117,7 +137,7 @@ public function getPermissionBase() * * @throws NotFoundHttpException */ - public function createForm($entity, $formFactory, $action = null, $options = []) + public function createForm($entity, $formFactory, $action = null, $options = []): \Symfony\Component\Form\FormInterface { if (!$entity instanceof Multidomain) { throw new MethodNotAllowedHttpException(['Multidomain']); @@ -147,7 +167,7 @@ public function getRepository() * * @return Multidomain */ - public function getEntity($id = null) + public function getEntity($id = null): ?object { if (null === $id) { return new Multidomain(); @@ -159,33 +179,31 @@ public function getEntity($id = null) /** * {@inheritdoc} * - * @param Multidomain $entity - * @param bool|false $unlock + * @param Multidomain $entity + * @param bool|false $unlock */ - public function saveEntity($entity, $unlock = true) + public function saveEntity($entity, $unlock = true): void { parent::saveEntity($entity, $unlock); $this->getRepository()->saveEntity($entity); } - public function generateMessageId(Multidomain $multidomain) { - $url = $multidomain->getDomain(); + public function generateMessageId(Multidomain $multidomain) + { + $url = $multidomain->getDomain(); $parts = parse_url($url); if (!isset($parts['host'])) { - throw new \Exception("InvalidDomainError"); + throw new \Exception('InvalidDomainError'); } - $messageIdSuffix = '@' . $parts['host']; + $messageIdSuffix = '@'.$parts['host']; + return bin2hex(random_bytes(16)).$messageIdSuffix; } - /** * Get whether the color is light or dark. * - * @param $hex - * @param $level - * * @return bool */ public static function isLightColor($hex, $level = 200) @@ -205,9 +223,9 @@ public static function isLightColor($hex, $level = 200) * * @return bool|MultidomainEvent|void * - * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException + * @throws MethodNotAllowedHttpException */ - protected function dispatchEvent($action, &$entity, $isNew = false, Event $event = null) + protected function dispatchEvent($action, &$entity, $isNew = false, Event $event = null): ?Event { if (!$entity instanceof Multidomain) { throw new MethodNotAllowedHttpException(['Multidomain']); @@ -236,7 +254,7 @@ protected function dispatchEvent($action, &$entity, $isNew = false, Event $event $event->setEntityManager($this->em); } - $this->dispatcher->dispatch($name, $event); + $this->dispatcher->dispatch($event, $name); return $event; } else { @@ -249,5 +267,4 @@ public function getConfiArray() { return include dirname(__DIR__).'/Config/config.php'; } - } diff --git a/Permissions/MultidomainPermissions.php b/Permissions/MultidomainPermissions.php index da41a10..be0f5a1 100644 --- a/Permissions/MultidomainPermissions.php +++ b/Permissions/MultidomainPermissions.php @@ -1,14 +1,5 @@ +
+ +
+
+
+ {{ 'plugin.multidomain.email'|trans }}: +
+
+ {{ item.getEmail() }} +
+
+
+
+ {{ 'plugin.multidomain.domain'|trans }}: +
+
+

{{ item.getDomain() }}

+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/Resources/views/Multidomain/form.html.twig b/Resources/views/Multidomain/form.html.twig new file mode 100644 index 0000000..d121264 --- /dev/null +++ b/Resources/views/Multidomain/form.html.twig @@ -0,0 +1,47 @@ +{% extends '@MauticCore/Default/content.html.twig' %} + +{% block mauticContent %} + multidomain +{% endblock %} + +{% set header = entity.getId() + ? 'mautic.multidomain.edit'|trans({'%title%': entity.getEmail()|trans}) + : 'mautic.multidomain.new'|trans +%} +{% block headerTitle %} + {{ header }} +{% endblock %} + + + +{% block content %} + +{{ form_start(form) }} + + +
+ +
+ +
+

+ {{ 'mautic.multidomain.add.warning'|trans }} +

+
+
+
+ {{ form_row(form.email) }} +
+
+
+
+ {{ form_row(form.domain) }} +
+
+
+
+ + +{{ form_end(form) }} +{% endblock %} \ No newline at end of file diff --git a/Resources/views/Multidomain/index.html.twig b/Resources/views/Multidomain/index.html.twig new file mode 100644 index 0000000..152537c --- /dev/null +++ b/Resources/views/Multidomain/index.html.twig @@ -0,0 +1,39 @@ +{# + * @copyright 2016 Mautic, Inc. All rights reserved + * @author Mautic, Inc + * + * @link https://mautic.org + * + * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html +#} +{% extends '@MauticCore/Default/content.html.twig' %} + +{% block mauticContent %} + multidomain +{% endblock %} + +{% block headerTitle %} + {{ 'mautic.multidomain.title'|trans }} +{% endblock %} + +{% block actions %} + {{ include('@MauticCore/Helper/page_actions.html.twig', { + 'templateButtons': { + 'new': permissions['multidomain:items:create'] + }, + 'routeBase': 'multidomain' + }) }} +{% endblock %} + +{% block content %} +
+ {{ include('@MauticCore/Helper/list_toolbar.html.twig', { + 'searchValue': searchValue, + 'searchHelp': 'mautic.core.help.searchcommands', + 'action': currentRoute + }) }} +
+ {{ block('_content') }} +
+
+{% endblock %} \ No newline at end of file diff --git a/Resources/views/Multidomain/list.html.twig b/Resources/views/Multidomain/list.html.twig new file mode 100644 index 0000000..ea6c779 --- /dev/null +++ b/Resources/views/Multidomain/list.html.twig @@ -0,0 +1,89 @@ +{# + * @copyright 2016 Mautic, Inc. All rights reserved + * @author Mautic, Inc + * + * @link https://mautic.org + * + * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html +#} + +{% set isIndex = 'index' == tmpl ? true : false %} +{% set tmpl = 'list' %} +{% extends isIndex ? '@MauticMultiDomain/Multidomain/index.html.twig' : 'MauticCore/Default/raw_output.html.twig' %} + +{% block content %} +{% if items|length %} +
+ + + + {{ include('@MauticCore/Helper/tableheader.html.twig', { + 'checkall': 'true', + 'target': '#multidomainTable', + 'routeBase': 'multidomain', + 'templateButtons': { + 'delete': permissions['multidomain:items:delete'] + } + }) }} + {{ include('@MauticCore/Helper/tableheader.html.twig', { + 'sessionVar': 'multidomain', + 'orderBy': 'f.email', + 'text': 'plugin.multidomain.email', + 'class': 'col-multidomain-name', + 'default': true + }) }} + + + + {% for item in items %} + + + + + {% endfor %} + +
+ {{ include('@MauticCore/Helper/list_actions.html.twig', { + 'item': item, + 'templateButtons': { + 'edit': securityHasEntityAccess( + permissions['multidomain:items:editown'], + permissions['multidomain:items:editother'], + item.getCreatedBy() + ), + 'clone': permissions['multidomain:items:create'], + 'delete': securityHasEntityAccess( + permissions['multidomain:items:deleteown'], + permissions['multidomain:items:deleteother'], + item.getCreatedBy() + ) + }, + 'routeBase': 'multidomain' + }) }} + +
+ {# {{ include('MauticCore:Helper:publishstatus_icon.html.twig', {'item': item, 'model': 'multidomain'}) }} #} + + {{ item.getEmail() }} + +
+ {% if item.getDomain() %} +
+ {{ item.getDomain() }} +
+ {% endif %} +
+
+ +{% else %} + {{ include('@MauticCore/Helper/noresults.html.twig', {'tip': 'mautic.multidomain.noresults.tip'}) }} +{% endif %} +{% endblock %} diff --git a/Views/Multidomain/details.html.php b/Views/Multidomain/details.html.php deleted file mode 100644 index 7bc01cc..0000000 --- a/Views/Multidomain/details.html.php +++ /dev/null @@ -1,58 +0,0 @@ -extend('MauticCoreBundle:Default:content.html.php'); - $view['slots']->set('mauticContent', 'multidomain'); - $view['slots']->set('headerTitle', $item->getEmail()); - - $view['slots']->set( - 'actions', - $view->render( - 'MauticCoreBundle:Helper:page_actions.html.php', - [ - 'item' => $item, - 'templateButtons' => [ - 'edit' => $view['security']->hasEntityAccess( - $permissions['multidomain:items:editown'], - $permissions['multidomain:items:editother'], - $item->getCreatedBy() - ), - 'clone' => $permissions['multidomain:items:create'], - 'delete' => $view['security']->hasEntityAccess( - $permissions['multidomain:items:deleteown'], - $permissions['multidomain:items:deleteother'], - $item->getCreatedBy() - ), - 'close' => $view['security']->isGranted('multidomain:items:view'), - ], - 'routeBase' => 'multidomain', - 'langVar' => 'multidomain', - ] - ) - ); - -?> - - -
- - -
-
-
- trans('plugin.multidomain.email'); ?>: -
-
- getEmail();?> -
-
- -
-
- trans('plugin.multidomain.domain'); ?>: -
-
-

getDomain();?>

-
-
-
-
\ No newline at end of file diff --git a/Views/Multidomain/form.html.php b/Views/Multidomain/form.html.php deleted file mode 100644 index fe56c1a..0000000 --- a/Views/Multidomain/form.html.php +++ /dev/null @@ -1,49 +0,0 @@ -extend('MauticCoreBundle:Default:content.html.php'); - - -$view['slots']->set('mauticContent', 'multidomain'); - -$header = ($entity->getId()) - ? - $view['translator']->trans( - 'mautic.multidomain.edit', - ['%title%' => $view['translator']->trans($entity->getEmail())] - ) - : - $view['translator']->trans('mautic.multidomain.new'); -$view['slots']->set('headerTitle', $header); - -//$attr = $form->vars['attr']; -echo $view['form']->start($form); -?> - - -
- -
- -
-

- trans('mautic.multidomain.add.warning'); ?> -

-
-
-
- row($form['email']); ?> -
- -
- -
-
- row($form['domain']); ?> -
- -
-
-
- -end($form); ?> \ No newline at end of file diff --git a/Views/Multidomain/index.html.php b/Views/Multidomain/index.html.php deleted file mode 100644 index 1c0eb0e..0000000 --- a/Views/Multidomain/index.html.php +++ /dev/null @@ -1,42 +0,0 @@ -extend('MauticCoreBundle:Default:content.html.php'); -$view['slots']->set('mauticContent', 'multidomain'); -$view['slots']->set('headerTitle', $view['translator']->trans('mautic.multidomain.title')); - -$view['slots']->set( - 'actions', - $view->render( - 'MauticCoreBundle:Helper:page_actions.html.php', - [ - 'templateButtons' => [ - 'new' => $permissions['multidomain:items:create'], - ], - 'routeBase' => 'multidomain', - ] - ) -); - -?> - -
- render( - 'MauticCoreBundle:Helper:list_toolbar.html.php', - [ - 'searchValue' => $searchValue, - 'searchHelp' => 'mautic.core.help.searchcommands', - 'action' => $currentRoute, - ] - ); ?> -
- output('_content'); ?> -
-
diff --git a/Views/Multidomain/list.html.php b/Views/Multidomain/list.html.php deleted file mode 100644 index 3656d41..0000000 --- a/Views/Multidomain/list.html.php +++ /dev/null @@ -1,109 +0,0 @@ -extend('MauticMultiDomainBundle:Multidomain:index.html.php'); -} -?> - - -
- - - - render( - 'MauticCoreBundle:Helper:tableheader.html.php', - [ - 'checkall' => 'true', - 'target' => '#multidomainTable', - 'routeBase' => 'multidomain', - 'templateButtons' => [ - 'delete' => $permissions['multidomain:items:delete'], - ], - ] - ); - - echo $view->render( - 'MauticCoreBundle:Helper:tableheader.html.php', - [ - 'sessionVar' => 'multidomain', - 'orderBy' => 'f.email', - 'text' => 'plugin.multidomain.email', - 'class' => 'col-multidomain-name', - 'default' => true, - ] - ); - ?> - - - - - - - - - - -
- render( - 'MauticCoreBundle:Helper:list_actions.html.php', - [ - 'item' => $item, - 'templateButtons' => [ - 'edit' => $view['security']->hasEntityAccess( - $permissions['multidomain:items:editown'], - $permissions['multidomain:items:editother'], - $item->getCreatedBy() - ), - 'clone' => $permissions['multidomain:items:create'], - 'delete' => $view['security']->hasEntityAccess( - $permissions['multidomain:items:deleteown'], - $permissions['multidomain:items:deleteother'], - $item->getCreatedBy() - ), - ], - 'routeBase' => 'multidomain', - ] - ); - ?> - - - getDomain()): ?> -
- -
- -
-
- - - render('MauticCoreBundle:Helper:noresults.html.php', ['tip' => 'mautic.multidomain.noresults.tip']); ?> -