[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/settings/panel/ -> PhabricatorSettingsPanelEmailFormat.php (source)

   1  <?php
   2  
   3  final class PhabricatorSettingsPanelEmailFormat
   4    extends PhabricatorSettingsPanel {
   5  
   6    public function getPanelKey() {
   7      return 'emailformat';
   8    }
   9  
  10    public function getPanelName() {
  11      return pht('Email Format');
  12    }
  13  
  14    public function getPanelGroup() {
  15      return pht('Email');
  16    }
  17  
  18    public function processRequest(AphrontRequest $request) {
  19      $user = $request->getUser();
  20  
  21      $preferences = $user->loadPreferences();
  22  
  23      $pref_re_prefix = PhabricatorUserPreferences::PREFERENCE_RE_PREFIX;
  24      $pref_vary = PhabricatorUserPreferences::PREFERENCE_VARY_SUBJECT;
  25      $prefs_html_email = PhabricatorUserPreferences::PREFERENCE_HTML_EMAILS;
  26  
  27      $errors = array();
  28      if ($request->isFormPost()) {
  29  
  30        if (PhabricatorMetaMTAMail::shouldMultiplexAllMail()) {
  31          if ($request->getStr($pref_re_prefix) == 'default') {
  32            $preferences->unsetPreference($pref_re_prefix);
  33          } else {
  34            $preferences->setPreference(
  35              $pref_re_prefix,
  36              $request->getBool($pref_re_prefix));
  37          }
  38  
  39          if ($request->getStr($pref_vary) == 'default') {
  40            $preferences->unsetPreference($pref_vary);
  41          } else {
  42            $preferences->setPreference(
  43              $pref_vary,
  44              $request->getBool($pref_vary));
  45          }
  46  
  47          if ($request->getStr($prefs_html_email) == 'default') {
  48            $preferences->unsetPreference($prefs_html_email);
  49          } else {
  50            $preferences->setPreference(
  51              $prefs_html_email,
  52              $request->getBool($prefs_html_email));
  53          }
  54        }
  55  
  56        $preferences->save();
  57  
  58        return id(new AphrontRedirectResponse())
  59          ->setURI($this->getPanelURI('?saved=true'));
  60      }
  61  
  62      $re_prefix_default = PhabricatorEnv::getEnvConfig('metamta.re-prefix')
  63        ? pht('Enabled')
  64        : pht('Disabled');
  65  
  66      $vary_default = PhabricatorEnv::getEnvConfig('metamta.vary-subjects')
  67        ? pht('Vary')
  68        : pht('Do Not Vary');
  69  
  70      $html_emails_default = 'Plain Text';
  71  
  72      $re_prefix_value = $preferences->getPreference($pref_re_prefix);
  73      if ($re_prefix_value === null) {
  74        $re_prefix_value = 'default';
  75      } else {
  76        $re_prefix_value = $re_prefix_value
  77          ? 'true'
  78          : 'false';
  79      }
  80  
  81      $vary_value = $preferences->getPreference($pref_vary);
  82      if ($vary_value === null) {
  83        $vary_value = 'default';
  84      } else {
  85        $vary_value = $vary_value
  86          ? 'true'
  87          : 'false';
  88      }
  89  
  90      $html_emails_value = $preferences->getPreference($prefs_html_email);
  91      if ($html_emails_value === null) {
  92        $html_emails_value = 'default';
  93      } else {
  94        $html_emails_value = $html_emails_value
  95          ? 'true'
  96          : 'false';
  97      }
  98  
  99      $form = new AphrontFormView();
 100      $form
 101        ->setUser($user);
 102  
 103      if (PhabricatorMetaMTAMail::shouldMultiplexAllMail()) {
 104        $html_email_control = id(new AphrontFormSelectControl())
 105          ->setName($prefs_html_email)
 106          ->setOptions(
 107            array(
 108              'default'   => pht('Default (%s)', $html_emails_default),
 109              'true'      => pht('Send HTML Email'),
 110              'false'     => pht('Send Plain Text Email'),
 111            ))
 112          ->setValue($html_emails_value);
 113  
 114        $re_control = id(new AphrontFormSelectControl())
 115          ->setName($pref_re_prefix)
 116          ->setOptions(
 117            array(
 118              'default'   => pht('Use Server Default (%s)', $re_prefix_default),
 119              'true'      => pht('Enable "Re:" prefix'),
 120              'false'     => pht('Disable "Re:" prefix'),
 121            ))
 122          ->setValue($re_prefix_value);
 123  
 124        $vary_control = id(new AphrontFormSelectControl())
 125          ->setName($pref_vary)
 126          ->setOptions(
 127            array(
 128              'default'   => pht('Use Server Default (%s)', $vary_default),
 129              'true'      => pht('Vary Subjects'),
 130              'false'     => pht('Do Not Vary Subjects'),
 131            ))
 132          ->setValue($vary_value);
 133      } else {
 134        $html_email_control = id(new AphrontFormStaticControl())
 135          ->setValue('Server Default ('.$html_emails_default.')');
 136  
 137        $re_control = id(new AphrontFormStaticControl())
 138          ->setValue('Server Default ('.$re_prefix_default.')');
 139  
 140        $vary_control = id(new AphrontFormStaticControl())
 141          ->setValue('Server Default ('.$vary_default.')');
 142      }
 143  
 144      $form
 145        ->appendRemarkupInstructions(
 146          pht(
 147            'These settings fine-tune some technical aspects of how email is '.
 148            'formatted. You may be able to adjust them to make mail more '.
 149            'useful or improve threading.'));
 150  
 151      if (!PhabricatorMetaMTAMail::shouldMultiplexAllMail()) {
 152        $form->appendRemarkupInstructions(
 153          pht(
 154            'NOTE: This install of Phabricator is configured to send a '.
 155            'single mail message to all recipients, so all settings are '.
 156            'locked at the server default value.'));
 157      }
 158  
 159      $form
 160        ->appendRemarkupInstructions(
 161          pht(
 162            "You can use the **HTML Email** setting to control whether ".
 163            "Phabricator send you HTML email (which has more color and ".
 164            "formatting) or plain text email (which is more compatible).\n".
 165            "\n".
 166            "WARNING: This feature is new and experimental! If you enable ".
 167            "it, mail may not render properly and replying to mail may not ".
 168            "work as well."))
 169        ->appendChild(
 170          $html_email_control
 171            ->setLabel(pht('HTML Email')))
 172        ->appendRemarkupInstructions('')
 173        ->appendRemarkupInstructions(
 174          pht(
 175            'The **Add "Re:" Prefix** setting adds "Re:" in front of all '.
 176            'messages, even if they are not replies. If you use **Mail.app** on '.
 177            'Mac OS X, this may improve mail threading.'.
 178            "\n\n".
 179            "| Setting                | Example Mail Subject\n".
 180            "|------------------------|----------------\n".
 181            "| Enable \"Re:\" Prefix  | ".
 182            "`Re: [Differential] [Accepted] D123: Example Revision`\n".
 183            "| Disable \"Re:\" Prefix | ".
 184            "`[Differential] [Accepted] D123: Example Revision`"))
 185        ->appendChild(
 186          $re_control
 187            ->setLabel(pht('Add "Re:" Prefix')))
 188        ->appendRemarkupInstructions('')
 189        ->appendRemarkupInstructions(
 190          pht(
 191            'With **Vary Subjects** enabled, most mail subject lines will '.
 192            'include a brief description of their content, like **[Closed]** '.
 193            'for a notification about someone closing a task.'.
 194            "\n\n".
 195            "| Setting              | Example Mail Subject\n".
 196            "|----------------------|----------------\n".
 197            "| Vary Subjects        | ".
 198            "`[Maniphest] [Closed] T123: Example Task`\n".
 199            "| Do Not Vary Subjects | ".
 200            "`[Maniphest] T123: Example Task`\n".
 201            "\n".
 202            'This can make mail more useful, but some clients have difficulty '.
 203            'threading these messages. Disabling this option may improve '.
 204            'threading, at the cost of less useful subject lines.'))
 205        ->appendChild(
 206          $vary_control
 207            ->setLabel(pht('Vary Subjects')));
 208  
 209      $form
 210        ->appendChild(
 211          id(new AphrontFormSubmitControl())
 212            ->setValue(pht('Save Preferences')));
 213  
 214      $form_box = id(new PHUIObjectBoxView())
 215        ->setHeaderText(pht('Email Format'))
 216        ->setFormSaved($request->getStr('saved'))
 217        ->setFormErrors($errors)
 218        ->setForm($form);
 219  
 220      return id(new AphrontNullView())
 221        ->appendChild(
 222          array(
 223            $form_box,
 224          ));
 225    }
 226  
 227  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1