root / branches / 2.1.x / actions / SavePreferences.php @ 1111
View | Annotate | Download (6.4 KB)
| 1 | <?php
|
|---|---|
| 2 | |
| 3 | /*
|
| 4 | * @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com |
| 5 | * @license http://creativecommons.org/licenses/BSD/ BSD License |
| 6 | * @author Keyboard Monkeys Ltd. |
| 7 | * @since Sciret 1.2 |
| 8 | * @package Sciret |
| 9 | * @packager Keyboard Monkeys |
| 10 | */ |
| 11 | |
| 12 | require 'actions/Action.php'; |
| 13 | |
| 14 | class SavePreferences extends Action |
| 15 | {
|
| 16 | function dispatch()
|
| 17 | {
|
| 18 | if (in_array($_POST['startBrowsing'], array('all', 'articles', 'bookmarks'))) { |
| 19 | $this->user->setPreference('startBrowsing', $_POST['startBrowsing']); |
| 20 | } |
| 21 | |
| 22 | if (in_array($_POST['articlesPerPage'], array(10, 20, 30, 50, 100))) { |
| 23 | $this->user->setPreference('articlesPerPage', $_POST['articlesPerPage']); |
| 24 | } |
| 25 | |
| 26 | if (in_array($_POST['dateFormat'], array('Month Day, Year', 'MM/DD/YYYY', 'MM-DD-YYYY', 'DD/MM/YYYY', 'DD-MM-YYYY'))) { |
| 27 | $this->user->setPreference('dateFormat', $_POST['dateFormat']); |
| 28 | } |
| 29 | |
| 30 | $this->user->setPreference('language', $_POST['language']); |
| 31 | |
| 32 | if (in_array($_POST['navigationType'], array('currentCat', 'catAndSubCats'))) { |
| 33 | $this->user->setPreference('navigationType', $_POST['navigationType']); |
| 34 | } |
| 35 | |
| 36 | $errors = array();
|
| 37 | if (($this->user->role & Users_Model_User::ROLE_ADMIN) == Users_Model_User::ROLE_ADMIN) { |
| 38 | $this->configuration->setConfigValue('publishKB', $_POST['publishKB'] == '1'? '1' : '0'); |
| 39 | $this->configuration->setConfigValue('anonymousRegistration', $_POST['anonymousRegistration'] == '1'? '1' : '0'); |
| 40 | $this->configuration->setConfigValue('questionsEnabled', $_POST['questionsEnabled'] == '1'? '1' : '0'); |
| 41 | $this->configuration->setConfigValue('publishArticlesAuto', $_POST['publishArticlesAuto'] == '1'? '1' : '0'); |
| 42 | $this->configuration->setConfigValue('publishBookmarksAuto', $_POST['publishBookmarksAuto'] == '1'? '1' : '0'); |
| 43 | $this->configuration->setConfigValue('publishCommentsAuto', $_POST['publishCommentsAuto'] == '1'? '1' : '0'); |
| 44 | $this->configuration->setConfigValue('publishQuestionsAuto', $_POST['publishQuestionsAuto'] == '1'? '1' : '0'); |
| 45 | $this->configuration->setConfigValue('internalByDefault', $_POST['internalByDefault'] == '1'? '1' : '0'); |
| 46 | $this->configuration->setConfigValue('allowCommentsRatings', $_POST['allowCommentsRatings'] == '1'? '1' : '0'); |
| 47 | $this->configuration->setConfigValue('restrictEditDelete', $_POST['restrictEditDelete'] == '1'? '1' : '0'); |
| 48 | $this->configuration->setConfigValue('passwordExpirationDays', $_POST['passwordExpirationDays']); |
| 49 | $this->configuration->setConfigValue('mailTransport', $_POST['mailTransport'] == 'smtp' ? 'smtp' : 'sendmail'); |
| 50 | $this->configuration->setConfigValue('mailFromName', $_POST['mailFromName']); |
| 51 | $this->configuration->setConfigValue('mailFromMail', $_POST['mailFromMail']); |
| 52 | $this->configuration->setConfigValue('mailCategoryRequest', $_POST['mailCategoryRequest']); |
| 53 | $this->configuration->setConfigValue('mailArticleReports', $_POST['mailArticleReports']); |
| 54 | $this->configuration->setConfigValue('smtpServer', $_POST['smtpServer']); |
| 55 | $this->configuration->setConfigValue('smtpUser', $_POST['smtpUser']); |
| 56 | $this->configuration->setConfigValue('smtpPassword', $_POST['smtpPassword']); |
| 57 | $this->configuration->setConfigValue('smtpPort', $_POST['smtpPort']); |
| 58 | $this->configuration->setConfigValue('usePiwik', $_POST['usePiwik']); |
| 59 | $this->configuration->setConfigValue('piwikSiteId', $_POST['piwikSiteId']); |
| 60 | $this->configuration->setConfigValue('piwikPhpUrl', $_POST['piwikPhpUrl']); |
| 61 | $this->configuration->setConfigValue('piwikJsUrl', $_POST['piwikJsUrl']); |
| 62 | $this->configuration->setConfigValue('piwikTrackAdmin', $_POST['piwikTrackAdmin']); |
| 63 | $this->configuration->setConfigValue('useClamAV', $_POST['useClamAV']); |
| 64 | $this->configuration->setConfigValue('akismetEnabled', isset($_POST['akismetEnabled'])); |
| 65 | $this->configuration->setConfigValue('typePadAntiSpamEnabled', isset($_POST['typePadAntiSpamEnabled'])); |
| 66 | $this->configuration->setConfigValue('badBehaviorEnabled', isset($_POST['badBehaviorEnabled'])); |
| 67 | $this->configuration->setConfigValue('akismetKey', $_POST['akismetKey']); |
| 68 | $this->configuration->setConfigValue('typePadAntiSpamKey', $_POST['typePadAntiSpamKey']); |
| 69 | |
| 70 | if ($_POST['useClamAV'] == '1') { |
| 71 | $clamav = new Kb_Model_ClamAV();
|
| 72 | if (!$clamav->canExecuteClamscan()) {
|
| 73 | $errors[] = $this->translate('Couldn\'t attempt to use ClamAV: clamscan was not found (looking for %s)', |
| 74 | $clamav->getClamscanLocation()); |
| 75 | $this->configuration->setConfigValue('useClamAV', '0'); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (isset($_POST['typePadAntiSpamEnabled'])) { |
| 80 | $antiSpam = new AntiSpam($this->configuration, AntiSpam::TYPE_TYPEPAD); |
| 81 | if (!$antiSpam->verifyKey()) {
|
| 82 | $errors[] = $this->translate('Your TypePad AntiSpam key is wrong. Please verify.'); |
| 83 | $this->configuration->setConfigValue('typePadAntiSpamEnabled', false); |
| 84 | $this->configuration->setConfigValue('typePadAntiSpamKey', ''); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (isset($_POST['akismetEnabled'])) { |
| 89 | $antiSpam = new AntiSpam($this->configuration, AntiSpam::TYPE_AKISMET); |
| 90 | if (!$antiSpam->verifyKey()) {
|
| 91 | $errors[] = $this->translate('Your Akismet key is wrong. Please verify.'); |
| 92 | $this->configuration->setConfigValue('akismetEnabled', false); |
| 93 | $this->configuration->setConfigValue('akismetKey', ''); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | $this->configuration->save();
|
| 98 | } |
| 99 | |
| 100 | if (!$this->user->isAnonymous()) { |
| 101 | $this->user->save();
|
| 102 | } |
| 103 | |
| 104 | $_SESSION['message'] = $this->translate('Preferences saved successfully'); |
| 105 | if ($errors) {
|
| 106 | $errors = implode('<br />', $errors);
|
| 107 | $_SESSION['message'] .= '<br />' . $errors; |
| 108 | Library::redirect(Library::getLink(array('view' => 'EditPreferences'))); |
| 109 | } else {
|
| 110 | Library::redirect(Library::getLink(array('view' => 'MainView', 'set' => $this->user->getPreference('startBrowsing')))); |
| 111 | } |
| 112 | } |
| 113 | } |