/backend/modules/blog/actions/settings.php

https://github.com/DoFken/forkcms · PHP · 148 lines · 77 code · 23 blank · 48 comment · 10 complexity · 9aa7f22295fe85259568a0815ef2b782 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of Fork CMS.
  4. *
  5. * For the full copyright and license information, please view the license
  6. * file that was distributed with this source code.
  7. */
  8. /**
  9. * This is the settings-action, it will display a form to set general blog settings
  10. *
  11. * @author Tijs Verkoyen <tijs@sumocoders.be>
  12. * @author Dave Lens <dave.lens@netlash.com>
  13. * @author Jelmer Snoeck <jelmer.snoeck@netlash.com>
  14. */
  15. class BackendBlogSettings extends BackendBaseActionEdit
  16. {
  17. /**
  18. * Is the user a god user?
  19. *
  20. * @var bool
  21. */
  22. protected $isGod = false;
  23. /**
  24. * Execute the action
  25. */
  26. public function execute()
  27. {
  28. parent::execute();
  29. $this->loadForm();
  30. $this->validateForm();
  31. $this->parse();
  32. $this->display();
  33. }
  34. /**
  35. * Loads the settings form
  36. */
  37. private function loadForm()
  38. {
  39. $this->isGod = BackendAuthentication::getUser()->isGod();
  40. $this->frm = new BackendForm('settings');
  41. // add fields for pagination
  42. $this->frm->addDropdown('overview_number_of_items', array_combine(range(1, 30), range(1, 30)), BackendModel::getModuleSetting($this->URL->getModule(), 'overview_num_items', 10));
  43. $this->frm->addDropdown('recent_articles_full_number_of_items', array_combine(range(1, 10), range(1, 10)), BackendModel::getModuleSetting($this->URL->getModule(), 'recent_articles_full_num_items', 5));
  44. $this->frm->addDropdown('recent_articles_list_number_of_items', array_combine(range(1, 10), range(1, 10)), BackendModel::getModuleSetting($this->URL->getModule(), 'recent_articles_list_num_items', 5));
  45. // add fields for spam
  46. $this->frm->addCheckbox('spamfilter', BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false));
  47. // no Akismet-key, so we can't enable spam-filter
  48. if(BackendModel::getModuleSetting('core', 'akismet_key') == '')
  49. {
  50. $this->frm->getField('spamfilter')->setAttribute('disabled', 'disabled');
  51. $this->tpl->assign('noAkismetKey', true);
  52. }
  53. // add fields for comments
  54. $this->frm->addCheckbox('allow_comments', BackendModel::getModuleSetting($this->URL->getModule(), 'allow_comments', false));
  55. $this->frm->addCheckbox('moderation', BackendModel::getModuleSetting($this->URL->getModule(), 'moderation', false));
  56. // add fields for notifications
  57. $this->frm->addCheckbox('notify_by_email_on_new_comment_to_moderate', BackendModel::getModuleSetting($this->URL->getModule(), 'notify_by_email_on_new_comment_to_moderate', false));
  58. $this->frm->addCheckbox('notify_by_email_on_new_comment', BackendModel::getModuleSetting($this->URL->getModule(), 'notify_by_email_on_new_comment', false));
  59. // add fields for SEO
  60. $this->frm->addCheckbox('ping_services', BackendModel::getModuleSetting($this->URL->getModule(), 'ping_services', false));
  61. // add fields for RSS
  62. $this->frm->addCheckbox('rss_meta', BackendModel::getModuleSetting($this->URL->getModule(), 'rss_meta_' . BL::getWorkingLanguage(), true));
  63. $this->frm->addText('rss_title', BackendModel::getModuleSetting($this->URL->getModule(), 'rss_title_' . BL::getWorkingLanguage()));
  64. $this->frm->addTextarea('rss_description', BackendModel::getModuleSetting($this->URL->getModule(), 'rss_description_' . BL::getWorkingLanguage()));
  65. $this->frm->addText('feedburner_url', BackendModel::getModuleSetting($this->URL->getModule(), 'feedburner_url_' . BL::getWorkingLanguage()));
  66. // god user?
  67. if($this->isGod) $this->frm->addCheckbox('show_image_form', BackendModel::getModuleSetting($this->URL->getModule(), 'show_image_form', true));
  68. }
  69. /**
  70. * Parse the form
  71. */
  72. protected function parse()
  73. {
  74. parent::parse();
  75. // parse additional variables
  76. $this->tpl->assign('commentsRSSURL', SITE_URL . BackendModel::getURLForBlock($this->URL->getModule(), 'comments_rss'));
  77. $this->tpl->assign('isGod', $this->isGod);
  78. }
  79. /**
  80. * Validates the settings form
  81. */
  82. private function validateForm()
  83. {
  84. if($this->frm->isSubmitted())
  85. {
  86. // shorten fields
  87. $feedburnerURL = $this->frm->getField('feedburner_url');
  88. // validation
  89. $this->frm->getField('rss_title')->isFilled(BL::err('FieldIsRequired'));
  90. // feedburner URL is set
  91. if($feedburnerURL->isFilled())
  92. {
  93. // check if http:// is set and add if necessary
  94. $feedburner = !strstr($feedburnerURL->getValue(), 'http://') ? 'http://' . $feedburnerURL->getValue() : $feedburnerURL->getValue();
  95. // check if feedburner URL is valid
  96. if(!SpoonFilter::isURL($feedburner)) $feedburnerURL->addError(BL::err('InvalidURL'));
  97. }
  98. // init variable
  99. else $feedburner = null;
  100. if($this->frm->isCorrect())
  101. {
  102. // set our settings
  103. BackendModel::setModuleSetting($this->URL->getModule(), 'overview_num_items', (int) $this->frm->getField('overview_number_of_items')->getValue());
  104. BackendModel::setModuleSetting($this->URL->getModule(), 'recent_articles_full_num_items', (int) $this->frm->getField('recent_articles_full_number_of_items')->getValue());
  105. BackendModel::setModuleSetting($this->URL->getModule(), 'recent_articles_list_num_items', (int) $this->frm->getField('recent_articles_list_number_of_items')->getValue());
  106. BackendModel::setModuleSetting($this->URL->getModule(), 'spamfilter', (bool) $this->frm->getField('spamfilter')->getValue());
  107. BackendModel::setModuleSetting($this->URL->getModule(), 'allow_comments', (bool) $this->frm->getField('allow_comments')->getValue());
  108. BackendModel::setModuleSetting($this->URL->getModule(), 'moderation', (bool) $this->frm->getField('moderation')->getValue());
  109. BackendModel::setModuleSetting($this->URL->getModule(), 'notify_by_email_on_new_comment_to_moderate', (bool) $this->frm->getField('notify_by_email_on_new_comment_to_moderate')->getValue());
  110. BackendModel::setModuleSetting($this->URL->getModule(), 'notify_by_email_on_new_comment', (bool) $this->frm->getField('notify_by_email_on_new_comment')->getValue());
  111. BackendModel::setModuleSetting($this->URL->getModule(), 'ping_services', (bool) $this->frm->getField('ping_services')->getValue());
  112. BackendModel::setModuleSetting($this->URL->getModule(), 'rss_title_' . BL::getWorkingLanguage(), $this->frm->getField('rss_title')->getValue());
  113. BackendModel::setModuleSetting($this->URL->getModule(), 'rss_description_' . BL::getWorkingLanguage(), $this->frm->getField('rss_description')->getValue());
  114. BackendModel::setModuleSetting($this->URL->getModule(), 'rss_meta_' . BL::getWorkingLanguage(), $this->frm->getField('rss_meta')->getValue());
  115. BackendModel::setModuleSetting($this->URL->getModule(), 'feedburner_url_' . BL::getWorkingLanguage(), $feedburner);
  116. if($this->isGod) BackendModel::setModuleSetting($this->URL->getModule(), 'show_image_form', (bool) $this->frm->getField('show_image_form')->getChecked());
  117. if(BackendModel::getModuleSetting('core', 'akismet_key') === null) BackendModel::setModuleSetting($this->URL->getModule(), 'spamfilter', false);
  118. // trigger event
  119. BackendModel::triggerEvent($this->getModule(), 'after_saved_settings');
  120. // redirect to the settings page
  121. $this->redirect(BackendModel::createURLForAction('settings') . '&report=saved');
  122. }
  123. }
  124. }
  125. }