Beispiel #1
0
 /**
  * Returns the EmailGateway to send emails with.
  * Calling this function multiple times will return unique objects.
  *
  * @param string $gateway
  *    The name of the gateway to use. Please only supply if specific
  *  gateway functions are being used.
  *  If the gateway is not found, it will throw an EmailException
  * @throws Exception
  * @return EmailGateway
  */
 public function create($gateway = null)
 {
     $email_gateway_manager = new EmailGatewayManager();
     if ($gateway) {
         return $email_gateway_manager->create($gateway);
     } else {
         return $email_gateway_manager->create($email_gateway_manager->getDefaultGateway());
     }
 }
 public function view()
 {
     $this->setPageType('form');
     $this->setTitle(__('%1$s – %2$s', array(__('Preferences'), __('Symphony'))));
     $this->appendSubheading(__('Preferences'));
     $bIsWritable = true;
     $formHasErrors = is_array($this->_errors) && !empty($this->_errors);
     if (!is_writable(CONFIG)) {
         $this->pageAlert(__('The Symphony configuration file, %s, is not writable. You will not be able to save changes to preferences.', array('<code>/manifest/config.php</code>')), Alert::ERROR);
         $bIsWritable = false;
     } else {
         if ($formHasErrors) {
             $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR);
         } else {
             if (isset($this->_context[0]) && $this->_context[0] == 'success') {
                 $this->pageAlert(__('Preferences saved.'), Alert::SUCCESS);
             }
         }
     }
     // Get available languages
     $languages = Lang::getAvailableLanguages();
     if (count($languages) > 1) {
         // Create language selection
         $group = new XMLElement('fieldset');
         $group->setAttribute('class', 'settings');
         $group->appendChild(new XMLElement('legend', __('System Language')));
         $label = Widget::Label();
         // Get language names
         asort($languages);
         foreach ($languages as $code => $name) {
             $options[] = array($code, $code == Symphony::Configuration()->get('lang', 'symphony'), $name);
         }
         $select = Widget::Select('settings[symphony][lang]', $options);
         $label->appendChild($select);
         $group->appendChild($label);
         $group->appendChild(new XMLElement('p', __('Authors can set up a differing language in their profiles.'), array('class' => 'help')));
         // Append language selection
         $this->Form->appendChild($group);
     }
     // Get available EmailGateways
     $email_gateway_manager = new EmailGatewayManager($this);
     $email_gateways = $email_gateway_manager->listAll();
     if (count($email_gateways) >= 1) {
         $group = new XMLElement('fieldset', NULL, array('class' => 'settings picker'));
         $group->appendChild(new XMLElement('legend', __('Default Email Settings')));
         $label = Widget::Label(__('Gateway'));
         // Get gateway names
         ksort($email_gateways);
         $default_gateway = $email_gateway_manager->getDefaultGateway();
         $selected_is_installed = $email_gateway_manager->__getClassPath($default_gateway);
         $options = array();
         foreach ($email_gateways as $handle => $details) {
             $options[] = array($handle, $handle == $default_gateway || $selected_is_installed == false && $handle == 'sendmail', $details['name']);
         }
         $select = Widget::Select('settings[Email][default_gateway]', $options);
         $label->appendChild($select);
         $group->appendChild($label);
         // Append email gateway selection
         $this->Form->appendChild($group);
     }
     foreach ($email_gateways as $gateway) {
         $gateway_settings = $email_gateway_manager->create($gateway['handle'])->getPreferencesPane();
         if (is_a($gateway_settings, 'XMLElement')) {
             $this->Form->appendChild($gateway_settings);
         }
     }
     /**
      * Add Extension custom preferences. Use the $wrapper reference to append objects.
      *
      * @delegate AddCustomPreferenceFieldsets
      * @param string $context
      * '/system/preferences/'
      * @param XMLElement $wrapper
      *  An XMLElement of the current page
      * @param array $errors
      *  An array of errors
      */
     Symphony::ExtensionManager()->notifyMembers('AddCustomPreferenceFieldsets', '/system/preferences/', array('wrapper' => &$this->Form, 'errors' => $this->_errors));
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $attr = array('accesskey' => 's');
     if (!$bIsWritable) {
         $attr['disabled'] = 'disabled';
     }
     $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', $attr));
     $this->Form->appendChild($div);
 }
 public function view()
 {
     $this->setPageType('form');
     $this->setTitle(__('%1$s &ndash; %2$s', array(__('Preferences'), __('Symphony'))));
     $this->appendSubheading(__('Preferences'));
     $bIsWritable = true;
     $formHasErrors = is_array($this->_errors) && !empty($this->_errors);
     if (!is_writable(CONFIG)) {
         $this->pageAlert(__('The Symphony configuration file, %s, is not writable. You will not be able to save changes to preferences.', array('<code>/manifest/config.php</code>')), Alert::ERROR);
         $bIsWritable = false;
     } elseif ($formHasErrors) {
         $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR);
     } elseif (isset($this->_context[0]) && $this->_context[0] == 'success') {
         $this->pageAlert(__('Preferences saved.'), Alert::SUCCESS);
     }
     // Get available languages
     $languages = Lang::getAvailableLanguages();
     if (count($languages) > 1) {
         // Create language selection
         $group = new XMLElement('fieldset');
         $group->setAttribute('class', 'settings');
         $group->appendChild(new XMLElement('legend', __('System Language')));
         $label = Widget::Label();
         // Get language names
         asort($languages);
         foreach ($languages as $code => $name) {
             $options[] = array($code, $code == Symphony::Configuration()->get('lang', 'symphony'), $name);
         }
         $select = Widget::Select('settings[symphony][lang]', $options);
         $label->appendChild($select);
         $group->appendChild($label);
         $group->appendChild(new XMLElement('p', __('Authors can set up a differing language in their profiles.'), array('class' => 'help')));
         // Append language selection
         $this->Form->appendChild($group);
     }
     // Get available EmailGateways
     $email_gateway_manager = new EmailGatewayManager();
     $email_gateways = $email_gateway_manager->listAll();
     if (count($email_gateways) >= 1) {
         $group = new XMLElement('fieldset', NULL, array('class' => 'settings condensed'));
         $group->appendChild(new XMLElement('legend', __('Default Email Settings')));
         $label = Widget::Label(__('Gateway'));
         // Get gateway names
         ksort($email_gateways);
         $default_gateway = $email_gateway_manager->getDefaultGateway();
         $selected_is_installed = $email_gateway_manager->__getClassPath($default_gateway);
         $options = array();
         foreach ($email_gateways as $handle => $details) {
             $options[] = array($handle, $handle == $default_gateway || $selected_is_installed == false && $handle == 'sendmail', $details['name']);
         }
         $select = Widget::Select('settings[Email][default_gateway]', $options, array('class' => 'picker', 'data-interactive' => 'data-interactive'));
         $label->appendChild($select);
         $group->appendChild($label);
         // Append email gateway selection
         $this->Form->appendChild($group);
     }
     foreach ($email_gateways as $gateway) {
         $gateway_settings = $email_gateway_manager->create($gateway['handle'])->getPreferencesPane();
         if (is_a($gateway_settings, 'XMLElement')) {
             $this->Form->appendChild($gateway_settings);
         }
     }
     // Get available cache drivers
     $caches = Symphony::ExtensionManager()->getProvidersOf('cache');
     // Add default Symphony cache driver..
     $caches['database'] = 'Database';
     if (count($caches) > 1) {
         $group = new XMLElement('fieldset', NULL, array('class' => 'settings condensed'));
         $group->appendChild(new XMLElement('legend', __('Default Cache Settings')));
         /**
          * Add custom Caching groups. For example a Datasource extension might want to add in the ability
          * for set a cache driver for it's functionality. This should usually be a dropdown, which allows
          * a developer to select what driver they want to use for caching. This choice is stored in the
          * Configuration in a Caching node.
          * eg.
          *  'caching' => array (
          *        'remote_datasource' => 'database',
          *        'dynamic_ds' => 'YourCachingExtensionClassName'
          *  )
          *
          * @since Symphony 2.4
          * @delegate AddCachingOpportunity
          * @param string $context
          * '/system/preferences/'
          * @param XMLElement $wrapper
          *  An XMLElement of the current Caching fieldset
          * @param string $config_path
          *  The node in the Configuration where this information will be stored. Read only.
          * @param array $available_caches
          *  An array of the available cache providers
          * @param array $errors
          *  An array of errors
          */
         Symphony::ExtensionManager()->notifyMembers('AddCachingOpportunity', '/system/preferences/', array('wrapper' => &$group, 'config_path' => 'caching', 'available_caches' => $caches, 'errors' => $this->_errors));
         $this->Form->appendChild($group);
     }
     /**
      * Add Extension custom preferences. Use the $wrapper reference to append objects.
      *
      * @delegate AddCustomPreferenceFieldsets
      * @param string $context
      * '/system/preferences/'
      * @param XMLElement $wrapper
      *  An XMLElement of the current page
      * @param array $errors
      *  An array of errors
      */
     Symphony::ExtensionManager()->notifyMembers('AddCustomPreferenceFieldsets', '/system/preferences/', array('wrapper' => &$this->Form, 'errors' => $this->_errors));
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array('id' => 'version'));
     $div->appendChild($version);
     $attr = array('accesskey' => 's');
     if (!$bIsWritable) {
         $attr['disabled'] = 'disabled';
     }
     $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', $attr));
     $this->Form->appendChild($div);
 }
 function __viewEdit($new = false)
 {
     $this->setPageType('form');
     if ($this->_context[2] == 'saved' || $this->_context[3] == 'saved') {
         $this->pageAlert(__(__('Email Sender updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Senders</a>'), array(Widget::Time()->generate(), SYMPHONY_URL . '/extension/email_newsletter_manager/senders/new/', SYMPHONY_URL . '/extension/email_newsletter_manager/senders/')), Alert::SUCCESS);
     }
     $senders = new XMLElement('senders');
     $title = __('New Sender');
     $breadcrumbs = array(Widget::Anchor(__('Email Newsletter Senders'), SYMPHONY_URL . '/extension/email_newsletter_manager/senders/'));
     // Fix for 2.4 and XSRF
     if (Symphony::Configuration()->get("enable_xsrf", "symphony") == "yes" && class_exists('XSRF')) {
         $xsrf_input = new XMLElement('xsrf_input');
         $xsrf_input->appendChild(XSRF::formToken());
         $this->_XML->appendChild($xsrf_input);
     }
     if (!$new) {
         $sender = SenderManager::create($this->_context[1]);
         // Make sure the POSTED values are always shown when present.
         // This will make sure the form is always up-to-date, even where there are errors.
         if (!empty($_POST['fields']) && !empty($_POST['settings'])) {
             $posted_array = $_POST['fields'];
             $posted_array[$_POST['settings']['gateway']] = $_POST['settings']['email_' . $_POST['settings']['gateway']];
         }
         $about = empty($_POST['fields']) && empty($_POST['settings']) ? (array) $sender->about() : $posted_array;
         $about['handle'] = Lang::createHandle($about['name'], 225, '-');
         $entry = new XMLElement('entry');
         General::array_to_xml($entry, $about);
         $senders->appendChild($entry);
         $title = $about['name'];
         //$breadcrumbs[] = Widget::Anchor('hi', SYMPHONY_URL . '/extension/email_newsletter_manager/senders/edit/' . $sender->getHandle());
     }
     $el_gateways = new XMLElement('gateways');
     $gateways = EmailGatewayManager::listAll();
     foreach ($gateways as $gateway) {
         // to be removed in later versions. Right now only smtp and sendmail are supported.
         if (in_array($gateway['handle'], array('smtp', 'sendmail', 'amazon_ses'))) {
             $gw = EmailGatewayManager::create($gateway['handle']);
             if (!empty($about[$gateway['handle']])) {
                 $config = $about[$gateway['handle']];
                 if ($gateway['handle'] == 'smtp') {
                     $gw->setFrom($config['from_address'], $config['from_name']);
                     $gw->setHost($config['host']);
                     $gw->setSecure($config['secure']);
                     $gw->setPort($config['port']);
                     $gw->setAuth($config['auth']);
                     $gw->setUser($config['username']);
                     $gw->setPass($config['password']);
                 }
                 if ($gateway['handle'] == 'amazon_ses') {
                     $gw->setFrom($config['from_address'], $config['from_name']);
                     $gw->setAwsKey($config['aws_key']);
                     $gw->setAwsSecretKey($config['aws_secret_key']);
                     $gw->setFallback($config['fallback']);
                     $gw->setReturnPath($config['return_path']);
                 }
                 if ($gateway['handle'] == 'sendmail') {
                     $gw->setFrom($config['from_address'], $config['from_name']);
                 }
             }
             $entry = new XMLElement('entry');
             General::array_to_xml($entry, $gateway);
             $config_panel = new XMLElement('config_panel');
             $config_panel->appendChild($gw->getPreferencesPane());
             $entry->appendChild($config_panel);
             $el_gateways->appendChild($entry);
         }
     }
     $senders->appendChild($el_gateways);
     $this->insertBreadcrumbs($breadcrumbs);
     $this->appendSubheading($title);
     $this->_XML->appendChild($senders);
 }