/** * Execute the command. * * @param InputInterface $input * @param OutputInterface $output * * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $this->formatter = new SymfonyStyle($input, $output); if (!$this->multiLanguageIsEnabled) { $this->formatter->error(['site.multilanguage should be set to true in parameters.yml.', 'Warning: All your urls will change from example.com/page to example.com/[locale]/page']); return; } $this->installedLocale = array_flip($this->settings->get('Core', 'languages')); $this->interfaceLocale = array_flip($this->settings->get('Core', 'interface_languages')); $this->enabledLocale = array_flip($this->settings->get('Core', 'active_languages')); $this->redirectLocale = array_flip($this->settings->get('Core', 'redirect_languages')); $this->defaultEnabledLocale = $this->settings->get('Core', 'default_language'); $this->defaultInterfaceLocale = $this->settings->get('Core', 'default_interface_language'); $this->output->writeln($this->formatter->title('Fork CMS locale enable')); $this->showLocaleOverview(); $this->selectWorkingLocale(); if (!$this->askToInstall()) { return; } $this->askToAddInterfaceLocale(); if ($this->askToMakeTheLocaleAccessibleToVisitors()) { $this->askToEnableTheLocaleForRedirecting(); } }
/** * 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); }
/** * 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 } } }
/** * 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); }
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')); }
/** * 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; }
/** * 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); }
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 } }
/** * @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'); } }]); }
/** @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 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 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); }
public function testDefaultValueWillBeReturned() { $modulesSettings = new ModulesSettings($this->getDatabaseMock(), new Pool(new MemoryStore())); $this->assertEquals('default_value', $modulesSettings->get('Test', 'Blub', 'default_value')); }
/** * 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); }