/** * On FormBuilderSubmittedEvent * * @param FormBuilderSubmittedEvent $event */ public function onFormBuilderSubmittedEvent(FormBuilderSubmittedEvent $event) { if ($this->modulesSettings->get('Mailmotor', 'automatically_subscribe_from_form_builder_submitted_form', false)) { $form = $event->getForm(); $data = $event->getData(); $email = null; // Check if we have a replyTo email set foreach ($form['fields'] as $field) { if (array_key_exists('reply_to', $field['settings']) && $field['settings']['reply_to'] === true) { $email = unserialize($data[$field['id']]['value']); } } // Define language $language = array_key_exists('language', $form) ? $form['language'] : $this->modulesSettings->get('Core', 'default_language', 'en'); // We subscribe the replyTo email try { // Does email exists or not in our mailing list $exists = (bool) $this->subscriber->exists($email); // We only need to subscribe when not exists if (!$exists) { $this->subscriber->subscribe($email, $language, array(), array(), false); } } catch (NotImplementedException $e) { // We do nothing as fallback when no mail-engine is chosen in the Backend } } }
/** * Handle * * @param Subscription $subscription */ public function handle(Subscription $subscription) { // Init variables $mergeFields = array(); $interests = array(); try { // We must overwrite existing interests if ($this->modulesSettings->get('Mailmotor', 'overwrite_interests', true)) { $possibleInterests = $this->subscriber->getInterests(); // Loop interests foreach ($possibleInterests as $categoryId => $categoryInterest) { foreach ($categoryInterest['children'] as $categoryChildId => $categoryChildTitle) { // Add interest $interests[$categoryChildId] = in_array($categoryChildId, $subscription->interests); } } } elseif (!empty($subscription->interests)) { // Loop checked interests foreach ($subscription->interests as $checkedInterestId) { // Add interest $interests[$checkedInterestId] = true; } } // Fallback for when no mail-engine is chosen in the Backend } catch (NotImplementedException $e) { } // Subscribing the user, will dispatch an event $this->subscriber->subscribe($subscription->email, $subscription->language, $mergeFields, $interests); }
/** * Build up the form */ private function build() { $properties = $this->googleServiceAnalytics->management_webproperties->listManagementWebproperties($this->settings->get('Analytics', 'account')); $propertiesForDropDown = []; foreach ($properties->getItems() as $property) { $propertiesForDropDown[$property->getId()] = $property->getName(); } $this->form->addDropdown('web_property_id', $propertiesForDropDown); }
/** * Creates a google client * * @return Google_Client */ public function createClient() { $config = new \Google_Config(); $config->setClassConfig('Google_Cache_File', array('directory' => $this->cacheDir)); $client = new \Google_Client($config); // set assertion credentials $client->setAssertionCredentials(new \Google_Auth_AssertionCredentials($this->settings->get('Analytics', 'email'), array('https://www.googleapis.com/auth/analytics.readonly'), base64_decode($this->settings->get('Analytics', 'certificate')))); $client->setAccessType('offline_access'); return $client; }
public function testDeletingAValueDeletesIt() { $databaseMock = $this->getDatabaseMock(); $databaseMock->expects($this->once())->method('delete'); $modulesSettings = new ModulesSettings($databaseMock, new InMemoryCache()); $this->assertEquals('triton', $modulesSettings->get('Core', 'theme')); $modulesSettings->delete('Core', 'theme'); $this->assertNull($modulesSettings->get('Core', 'theme')); $this->assertEquals('default_value', $modulesSettings->get('Core', 'theme', 'default_value')); }
/** * @return bool */ public function handle() { $this->form->cleanupFields(); if (!$this->form->isSubmitted() || !$this->isValid()) { return false; } $certificate = base64_encode(file_get_contents($this->form->getField('certificate')->getTempFileName())); $this->settings->set('Analytics', 'certificate', $certificate); $this->settings->set('Analytics', 'email', $this->form->getField('email')->getValue()); return true; }
/** * On NotImplementedUnsubscribedEvent * * @param NotImplementedUnsubscribedEvent $event */ public function onNotImplementedUnsubscribedEvent(NotImplementedUnsubscribedEvent $event) { // define title $title = sprintf(Language::lbl('MailTitleUnsubscribeSubscriber'), $event->getUnsubscription()->email, strtoupper($event->getUnsubscription()->language)); // define sender/receiver(s) $to = $this->modulesSettings->get('Core', 'mailer_to'); $from = $this->modulesSettings->get('Core', 'mailer_from'); $replyTo = $this->modulesSettings->get('Core', 'mailer_reply_to'); // define message $message = Message::newInstance($title)->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.html.twig', array('message' => $title), true); // send mail $this->mailer->send($message); }
/** * @param ModulesSettings $modulesSettings */ public function __construct(ModulesSettings $modulesSettings) { // Define settings $settings = $modulesSettings->getForModule('Mailmotor'); // Define mail engine $this->mailEngine = array_key_exists('mail_engine', $settings) ? $settings['mail_engine'] : null; // Define api key $this->apiKey = array_key_exists('api_key', $settings) ? $settings['api_key'] : null; // Define list id $this->listId = array_key_exists('list_id', $settings) ? $settings['list_id'] : null; // Define overwrite interests $this->overwriteInterests = array_key_exists('overwrite_interests', $settings) ? (bool) $settings['overwrite_interests'] : null; // Define automatically subscribe from form builder submitted form $this->automaticallySubscribeFromFormBuilderSubmittedForm = array_key_exists('automatically_subscribe_from_form_builder_submitted_form', $settings) ? (bool) $settings['automatically_subscribe_from_form_builder_submitted_form'] : false; }
public function onKernelRequest(GetResponseEvent $event) { try { $transport = TransportFactory::create($this->modulesSettings->get('Core', 'mailer_type', 'mail'), $this->modulesSettings->get('Core', 'smtp_server'), $this->modulesSettings->get('Core', 'smtp_port', 25), $this->modulesSettings->get('Core', 'smtp_username'), $this->modulesSettings->get('Core', 'smtp_password'), $this->modulesSettings->get('Core', 'smtp_secure_layer')); $this->container->set('swiftmailer.mailer.default.transport', $transport); } catch (PDOException $e) { // we'll just use the mail transport thats pre-configured } }
/** @todo Refactor out constants #1106 * We need to deprecate this asap * * @param Twig_Environment $twig */ protected function startGlobals(&$twig) { // some old globals $twig->addGlobal('var', ''); $twig->addGlobal('CRLF', "\n"); $twig->addGlobal('TAB', "\t"); $twig->addGlobal('now', time()); $twig->addGlobal('LANGUAGE', $this->language); $twig->addGlobal('is' . strtoupper($this->language), true); $twig->addGlobal('debug', $this->debugMode); $twig->addGlobal('timestamp', time()); // constants that should be protected from usage in the template $notPublicConstants = array('DB_TYPE', 'DB_DATABASE', 'DB_HOSTNAME', 'DB_USERNAME', 'DB_PASSWORD'); // get all defined constants $constants = get_defined_constants(true); // remove protected constants aka constants that should not be used in the template foreach ($constants['user'] as $key => $value) { if (!in_array($key, $notPublicConstants)) { $twig->addGlobal($key, $value); } } /* Setup Backend for the Twig environment. */ if (!$this->forkSettings) { return; } $twig->addGlobal('timeFormat', $this->forkSettings->get('Core', 'time_format')); $twig->addGlobal('dateFormatShort', $this->forkSettings->get('Core', 'date_format_short')); $twig->addGlobal('dateFormatLong', $this->forkSettings->get('Core', 'date_format_long')); // old theme checker if ($this->forkSettings->get('Core', 'theme') !== null) { $twig->addGlobal('THEME', $this->forkSettings->get('Core', 'theme', 'default')); $twig->addGlobal('THEME_URL', '/src/Frontend/Themes/' . $this->forkSettings->get('Core', 'theme', 'default')); } // settings $twig->addGlobal('SITE_TITLE', $this->forkSettings->get('Core', 'site_title_' . $this->language, SITE_DEFAULT_TITLE)); $twig->addGlobal('SITE_URL', SITE_URL); $twig->addGlobal('SITE_DOMAIN', SITE_DOMAIN); // facebook stuff if ($this->forkSettings->get('Core', 'facebook_admin_ids', null) !== null) { $twig->addGlobal('FACEBOOK_ADMIN_IDS', $this->forkSettings->get('Core', 'facebook_admin_ids', null)); } if ($this->forkSettings->get('Core', 'facebook_app_id', null) !== null) { $twig->addGlobal('FACEBOOK_APP_ID', $this->forkSettings->get('Core', 'facebook_app_id', null)); } if ($this->forkSettings->get('Core', 'facebook_app_secret', null) !== null) { $twig->addGlobal('FACEBOOK_APP_SECRET', $this->forkSettings->get('Core', 'facebook_app_secret', null)); } // twitter stuff if ($this->forkSettings->get('Core', 'twitter_site_name', null) !== null) { // strip @ from twitter username $twig->addGlobal('TWITTER_SITE_NAME', ltrim($this->forkSettings->get('Core', 'twitter_site_name', null), '@')); } }
/** * @param OptionsResolver $resolver */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['data_class' => Subscription::class, 'validation_groups' => function (FormInterface $form) { // Define overwrite interests $overwriteInterests = $this->modulesSettings->get('Mailmotor', 'overwrite_interests', true); if (!empty($this->interests) && $overwriteInterests) { return array('Default', 'has_interests'); } else { return array('Default'); } }]); }
/** * @param FormBuilderSubmittedEvent $event */ public function onFormSubmitted(FormBuilderSubmittedEvent $event) { $form = $event->getForm(); // need to send mail if ($form['method'] == 'database_email') { // build our message $from = $this->modulesSettings->get('Core', 'mailer_from'); $fieldData = $this->getEmailFields($event->getData()); $message = Message::newInstance(sprintf(Language::getMessage('FormBuilderSubject'), $form['name']))->parseHtml('/FormBuilder/Layout/Templates/Mails/Form.html.twig', array('sentOn' => time(), 'name' => $form['name'], 'fields' => $fieldData), true)->setTo($form['email'])->setFrom(array($from['email'] => $from['name'])); // check if we have a replyTo email set foreach ($form['fields'] as $field) { if (array_key_exists('reply_to', $field['settings']) && $field['settings']['reply_to'] === true) { $email = $fieldData[$field['id']]['value']; $message->setReplyTo(array($email => $email)); } } if ($message->getReplyTo() === null) { $replyTo = $this->modulesSettings->get('Core', 'mailer_reply_to'); $message->setReplyTo(array($replyTo['email'] => $replyTo['name'])); } $this->mailer->send($message); } }
/** * @param SaveSettings $settings */ public function handle(SaveSettings $settings) { // Define module $module = 'Mailmotor'; // set our settings $this->modulesSettings->set($module, 'mail_engine', $settings->mailEngine); $this->modulesSettings->set($module, 'overwrite_interests', $settings->overwriteInterests); $this->modulesSettings->set($module, 'automatically_subscribe_from_form_builder_submitted_form', $settings->automaticallySubscribeFromFormBuilderSubmittedForm); // mail engine is empty if ($settings->mailEngine === 'not_implemented') { $this->modulesSettings->delete($module, 'api_key'); $this->modulesSettings->delete($module, 'list_id'); return; } $this->modulesSettings->set($module, 'api_key', $settings->apiKey); $this->modulesSettings->set($module, 'list_id', $settings->listId); }
/** * @param string $name * @param ModulesSettings $settings * @param Google_Service_Analytics $googleServiceAnalytics */ public function __construct($name, ModulesSettings $settings, Google_Service_Analytics $googleServiceAnalytics) { // we don't even have a auth config file yet, let the user upload it if ($settings->get('Analytics', 'certificate') === null) { $this->form = new SettingsStepAuthConfigFileType($name, $settings); return; } // we are authenticated! Let's see which account the user wants to use if ($settings->get('Analytics', 'account') === null) { $this->form = new SettingsStepAccountType($name, $settings, $googleServiceAnalytics); return; } // we have an account, but don't know which property to track if ($settings->get('Analytics', 'web_property_id') === null) { $this->form = new SettingsStepWebPropertyType($name, $settings, $googleServiceAnalytics); return; } // we have an account, but don't know which property to track if ($settings->get('Analytics', 'profile') === null) { $this->form = new SettingsStepProfileType($name, $settings, $googleServiceAnalytics); return; } $this->form = new Form($name); }
/** * @param bool $force */ private function installWorkingLocale($force = false) { $installLocaleCommand = $this->getApplication()->find('forkcms:locale:import'); $installBackendLocaleCommandArguments = ['-f' => PATH_WWW . '/src/Backend/Core/Installer/Data/locale.xml', '-o' => $force, '-l' => $this->workingLocale]; $this->formatter->writeln('<info>Installing Core locale</info>'); $installLocaleCommand->run(new ArrayInput($installBackendLocaleCommandArguments), $this->output); foreach ($this->installedModules as $installedModule) { $installModuleLocaleCommandArguments = ['-m' => $installedModule, '-o' => $force, '-l' => $this->workingLocale]; $this->formatter->writeln('<info>Installing ' . $installedModule . ' locale</info>'); try { $installLocaleCommand->run(new ArrayInput($installModuleLocaleCommandArguments), $this->output); } catch (Exception $exception) { $this->formatter->error($installedModule . ': skipped because ' . $exception->getMessage()); } } if (!array_key_exists($this->workingLocale, $this->installedLocale)) { // add the working locale to the installed locale $this->installedLocale = array_flip($this->installedLocale); $this->installedLocale[] = $this->workingLocale; $this->settings->set('Core', 'languages', $this->installedLocale); $this->installedLocale = array_flip($this->installedLocale); } }
public function testFetchingSettingsForAModule() { $modulesSettings = new ModulesSettings($this->getDatabaseMock(), new Pool(new MemoryStore())); $this->assertEquals(array('theme' => 'triton'), $modulesSettings->getForModule('Core')); $this->assertEquals(array(), $modulesSettings->getForModule('Fake')); }
/** * Returns Analytics data for our coupled profile * * @param int $startDate * @param int $endDate * @param string $metrics A comma-separated list of Analytics metrics. * @param array $optParams Optional parameters. * @return Google_Service_Analytics_GaData */ private function getAnalyticsData($startDate, $endDate, $metrics, $optParams = array()) { return $this->analytics->data_ga->get('ga:' . $this->settings->get('Analytics', 'profile'), date('Y-m-d', $startDate), date('Y-m-d', $endDate), $metrics, $optParams); }