PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/controller/publisher/settings.php

#
PHP | 171 lines | 121 code | 34 blank | 16 comment | 22 complexity | 55de257b69e224df46f6c11d193f43cc MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. Copyright (C) 2009-2010 Fabio Mattei <burattino@gmail.com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. define('STARTPATH', '../../../');
  16. require_once(STARTPATH.'costants.php');
  17. require_once(STARTPATH.SYSTEMPATH.'config.php');
  18. require_once(STARTPATH.DATAMODELPATH.'option.php');
  19. require_once(STARTPATH.DATAMODELPATH.'user.php');
  20. require_once(STARTPATH.UTILSPATH.'fileWriter.php');
  21. require_once(STARTPATH.UTILSPATH.'directoryrunner.php');
  22. require_once(STARTPATH.CONTROLLERPATH.'all_controllers_commons.php');
  23. session_start();
  24. AllControllersCommons::loadlanguage();
  25. function index() {
  26. $out = array();
  27. $settingsindb = Option::findByType('settings');
  28. $out['settingsindb'] = array();
  29. foreach ($settingsindb as $stdb) {
  30. $name = $stdb->getName();
  31. $out['settingsindb']["$name"] = $stdb;
  32. }
  33. if (!isset($out['settingsindb']['title'])) { $out['settingsindb']['title'] = new Option(Option::NEW_OPTION, 'title', 'settings', ''); }
  34. if (!isset($out['settingsindb']['description'])) { $out['settingsindb']['description'] = new Option(Option::NEW_OPTION, 'description', 'settings', ''); }
  35. if (!isset($out['settingsindb']['urltype'])) { $out['settingsindb']['urltype'] = new Option(Option::NEW_OPTION, 'urltype', 'settings', 'optimized'); }
  36. if (!isset($out['settingsindb']['publisher'])) { $out['settingsindb']['publisher'] = new Option(Option::NEW_OPTION, 'publisher', 'settings', ''); }
  37. if (!isset($out['settingsindb']['rights'])) { $out['settingsindb']['rights'] = new Option(Option::NEW_OPTION, 'rights', 'settings', ''); }
  38. if (!isset($out['settingsindb']['email'])) { $out['settingsindb']['email'] = new Option(Option::NEW_OPTION, 'email', 'settings', ''); }
  39. if (!isset($out['settingsindb']['language'])) { $out['settingsindb']['language'] = new Option(Option::NEW_OPTION, 'language', 'settings', 'en'); }
  40. if (!isset($out['settingsindb']['epubname'])) { $out['settingsindb']['epubname'] = new Option(Option::NEW_OPTION, 'epubname', 'settings', 'easymagazine'); }
  41. if (!isset($out['settingsindb']['siteurl'])) { $out['settingsindb']['siteurl'] = new Option(Option::NEW_OPTION, 'siteurl', 'settings', 'http://www.easymagazine.org/'); }
  42. if (!isset($out['settingsindb']['facebookbutton'])) { $out['settingsindb']['facebookbutton'] = new Option(Option::NEW_OPTION, 'facebookbutton', 'settings', 'OFF'); }
  43. if (!isset($out['settingsindb']['twitterbutton'])) { $out['settingsindb']['twitterbutton'] = new Option(Option::NEW_OPTION, 'twitterbutton', 'settings', 'OFF'); }
  44. return $out;
  45. }
  46. function update($get, $post) {
  47. $out = array();
  48. Option::cleanType('settings');
  49. $toSave = new Option();
  50. $toSave->setName('title');
  51. $toSave->setType('settings');
  52. $toSave->setValue($post['title']);
  53. $toSave->save();
  54. $toSave = new Option();
  55. $toSave->setName('description');
  56. $toSave->setType('settings');
  57. $toSave->setValue($post['description']);
  58. $toSave->save();
  59. $toSave = new Option();
  60. $toSave->setName('urltype');
  61. $toSave->setType('settings');
  62. $toSave->setValue($post['urltype']);
  63. $toSave->save();
  64. $toSave = new Option();
  65. $toSave->setName('publisher');
  66. $toSave->setType('settings');
  67. $toSave->setValue($post['publisher']);
  68. $toSave->save();
  69. $toSave = new Option();
  70. $toSave->setName('rights');
  71. $toSave->setType('settings');
  72. $toSave->setValue($post['rights']);
  73. $toSave->save();
  74. $toSave = new Option();
  75. $toSave->setName('email');
  76. $toSave->setType('settings');
  77. $toSave->setValue($post['email']);
  78. $toSave->save();
  79. $toSave = new Option();
  80. $toSave->setName('language');
  81. $toSave->setType('settings');
  82. $toSave->setValue($post['language']);
  83. $toSave->save();
  84. $toSave = new Option();
  85. $toSave->setName('epubname');
  86. $toSave->setType('settings');
  87. $toSave->setValue($post['epubname']);
  88. $toSave->save();
  89. $toSave = new Option();
  90. $toSave->setName('siteurl');
  91. $toSave->setType('settings');
  92. $toSave->setValue($post['siteurl']);
  93. $toSave->save();
  94. $toSave = new Option();
  95. $toSave->setName('facebookbutton');
  96. $toSave->setType('settings');
  97. $toSave->setValue($post['facebookbutton']);
  98. $toSave->save();
  99. $toSave = new Option();
  100. $toSave->setName('twitterbutton');
  101. $toSave->setType('settings');
  102. $toSave->setValue($post['twitterbutton']);
  103. $toSave->save();
  104. $settingsindb = Option::findByType('settings');
  105. $out['settingsindb'] = array();
  106. foreach ($settingsindb as $stdb) {
  107. $name = $stdb->getName();
  108. $out['settingsindb']["$name"] = $stdb;
  109. }
  110. FileWriter::writeSettingsFile($out['settingsindb']);
  111. return $out;
  112. }
  113. if (isset($_GET['action'])) { $action = $_GET['action']; }
  114. else { $action = 'index'; }
  115. if (isset($_SESSION['user'])) {
  116. switch ($action) {
  117. case 'index': $out = index(); break;
  118. case 'update': $out = update($_GET, $_POST); break;
  119. }
  120. }
  121. $settingsindb = $out['settingsindb'];
  122. if (isset($out['get'])) { $get = $out['get']; }
  123. if (isset($out['post'])) { $post = $out['post']; }
  124. if (isset($out['files'])) { $files = $out['files']; }
  125. $infoarray = array();
  126. $warningarray = array();
  127. $questionarray = array();
  128. $errorarray = array();
  129. if (isset($out['info'])) { $infoarray[] = $out['info']; }
  130. if (isset($out['warning'])) { $warningarray[] = $out['warning']; }
  131. if (isset($out['question'])) { $questionarray[] = $out['question']; }
  132. if (isset($out['error'])) { $errorarray[] = $out['error']; }
  133. include('../../view/publisher/settings.php');
  134. ?>