SettingsController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <?php
  2. namespace Typemill\Controllers;
  3. use \Symfony\Component\Yaml\Yaml;
  4. use Typemill\Models\Write;
  5. use Typemill\Models\Fields;
  6. use Typemill\Models\Validation;
  7. use Typemill\Models\User;
  8. class SettingsController extends Controller
  9. {
  10. /*********************
  11. ** BASIC SETTINGS **
  12. *********************/
  13. public function showSettings($request, $response, $args)
  14. {
  15. $user = new User();
  16. $settings = $this->c->get('settings');
  17. $defaultSettings = \Typemill\Settings::getDefaultSettings();
  18. $copyright = $this->getCopyright();
  19. $languages = $this->getLanguages();
  20. $locale = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2) : 'en';
  21. $users = $user->getUsers();
  22. $route = $request->getAttribute('route');
  23. return $this->render($response, 'settings/system.twig', array('settings' => $settings, 'copyright' => $copyright, 'languages' => $languages, 'locale' => $locale, 'formats' => $defaultSettings['formats'] ,'users' => $users, 'route' => $route->getName() ));
  24. }
  25. public function saveSettings($request, $response, $args)
  26. {
  27. if($request->isPost())
  28. {
  29. $referer = $request->getHeader('HTTP_REFERER');
  30. $uri = $request->getUri();
  31. $base_url = $uri->getBaseUrl();
  32. # security, users should not be able to fake post with settings from other typemill pages.
  33. if(!isset($referer[0]) OR $referer[0] !== $base_url . '/tm/settings' )
  34. {
  35. $this->c->flash->addMessage('error', 'illegal referer');
  36. return $response->withRedirect($this->c->router->pathFor('settings.show'));
  37. }
  38. $settings = \Typemill\Settings::getUserSettings();
  39. $defaultSettings = \Typemill\Settings::getDefaultSettings();
  40. $params = $request->getParams();
  41. $newSettings = isset($params['settings']) ? $params['settings'] : false;
  42. $validate = new Validation();
  43. if($newSettings)
  44. {
  45. /* make sure only allowed fields are stored */
  46. $newSettings = array(
  47. 'title' => $newSettings['title'],
  48. 'author' => $newSettings['author'],
  49. 'copyright' => $newSettings['copyright'],
  50. 'year' => $newSettings['year'],
  51. 'language' => $newSettings['language'],
  52. 'editor' => $newSettings['editor'],
  53. 'formats' => $newSettings['formats'],
  54. );
  55. $copyright = $this->getCopyright();
  56. $validate->settings($newSettings, $copyright, $defaultSettings['formats'], 'settings');
  57. }
  58. else
  59. {
  60. $this->c->flash->addMessage('error', 'Wrong Input');
  61. return $response->withRedirect($this->c->router->pathFor('settings.show'));
  62. }
  63. if(isset($_SESSION['errors']))
  64. {
  65. $this->c->flash->addMessage('error', 'Please correct the errors');
  66. return $response->withRedirect($this->c->router->pathFor('settings.show'));
  67. }
  68. /* store updated settings */
  69. \Typemill\Settings::updateSettings(array_merge($settings, $newSettings));
  70. $this->c->flash->addMessage('info', 'Settings are stored');
  71. return $response->withRedirect($this->c->router->pathFor('settings.show'));
  72. }
  73. }
  74. /*********************
  75. ** THEME SETTINGS **
  76. *********************/
  77. public function showThemes($request, $response, $args)
  78. {
  79. $userSettings = $this->c->get('settings');
  80. $themes = $this->getThemes();
  81. $themedata = array();
  82. $fieldsModel = new Fields();
  83. foreach($themes as $themeName)
  84. {
  85. /* if theme is active, list it first */
  86. if($userSettings['theme'] == $themeName)
  87. {
  88. $themedata = array_merge(array($themeName => null), $themedata);
  89. }
  90. else
  91. {
  92. $themedata[$themeName] = null;
  93. }
  94. $themeSettings = \Typemill\Settings::getObjectSettings('themes', $themeName);
  95. # add standard-textarea for custom css
  96. $themeSettings['forms']['fields']['customcss'] = ['type' => 'textarea', 'label' => 'Custom CSS', 'rows' => 10, 'class' => 'codearea', 'description' => 'You can overwrite the theme-css with your own css here.'];
  97. # load custom css-file
  98. $write = new write();
  99. $customcss = $write->getFile('cache', $themeName . '-custom.css');
  100. $themeSettings['settings']['customcss'] = $customcss;
  101. if($themeSettings)
  102. {
  103. /* store them as default theme data with author, year, default settings and field-definitions */
  104. $themedata[$themeName] = $themeSettings;
  105. }
  106. if(isset($themeSettings['forms']['fields']))
  107. {
  108. $fields = $fieldsModel->getFields($userSettings, 'themes', $themeName, $themeSettings);
  109. /* overwrite original theme form definitions with enhanced form objects */
  110. $themedata[$themeName]['forms']['fields'] = $fields;
  111. }
  112. /* add the preview image */
  113. $img = getcwd() . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $themeName . DIRECTORY_SEPARATOR . $themeName;
  114. $image = false;
  115. if(file_exists($img . '.jpg'))
  116. {
  117. $image = $themeName . '.jpg';
  118. }
  119. if(file_exists($img . '.png'))
  120. {
  121. $image = $themeName . '.png';
  122. }
  123. $themedata[$themeName]['img'] = $image;
  124. }
  125. /* add the users for navigation */
  126. $user = new User();
  127. $users = $user->getUsers();
  128. $route = $request->getAttribute('route');
  129. return $this->render($response, 'settings/themes.twig', array('settings' => $userSettings, 'themes' => $themedata, 'users' => $users, 'route' => $route->getName() ));
  130. }
  131. public function showPlugins($request, $response, $args)
  132. {
  133. $userSettings = $this->c->get('settings');
  134. $plugins = array();
  135. $fieldsModel = new Fields();
  136. $fields = array();
  137. /* iterate through the plugins in the stored user settings */
  138. foreach($userSettings['plugins'] as $pluginName => $pluginUserSettings)
  139. {
  140. /* add plugin to plugin Data, if active, set it first */
  141. /* if plugin is active, list it first */
  142. if($userSettings['plugins'][$pluginName]['active'] == true)
  143. {
  144. $plugins = array_merge(array($pluginName => null), $plugins);
  145. }
  146. else
  147. {
  148. $plugins[$pluginName] = Null;
  149. }
  150. /* Check if the user has deleted a plugin. Then delete it in the settings and store the updated settings. */
  151. if(!is_dir($userSettings['rootPath'] . 'plugins' . DIRECTORY_SEPARATOR . $pluginName))
  152. {
  153. /* remove the plugin settings and store updated settings */
  154. \Typemill\Settings::removePluginSettings($pluginName);
  155. continue;
  156. }
  157. /* load the original plugin definitions from the plugin folder (author, version and stuff) */
  158. $pluginOriginalSettings = \Typemill\Settings::getObjectSettings('plugins', $pluginName);
  159. if($pluginOriginalSettings)
  160. {
  161. /* store them as default plugin data with plugin author, plugin year, default settings and field-definitions */
  162. $plugins[$pluginName] = $pluginOriginalSettings;
  163. }
  164. /* check, if the plugin has been disabled in the form-session-data */
  165. if(isset($_SESSION['old']) && !isset($_SESSION['old'][$pluginName]['active']))
  166. {
  167. $plugins[$pluginName]['settings']['active'] = false;
  168. }
  169. /* if the plugin defines forms and fields, so that the user can edit the plugin settings in the frontend */
  170. if(isset($pluginOriginalSettings['forms']['fields']))
  171. {
  172. # if the plugin defines frontend fields
  173. if(isset($pluginOriginalSettings['public']))
  174. {
  175. $pluginOriginalSettings['forms']['fields']['recaptcha'] = ['type' => 'checkbox', 'label' => 'Google Recaptcha', 'checkboxlabel' => 'Activate Recaptcha' ];
  176. $pluginOriginalSettings['forms']['fields']['recaptcha_webkey'] = ['type' => 'text', 'label' => 'Recaptcha Website Key', 'help' => 'Add the recaptcha website key here. You can get the key from the recaptcha website.', 'description' => 'The website key is mandatory if you activate the recaptcha field'];
  177. $pluginOriginalSettings['forms']['fields']['recaptcha_secretkey'] = ['type' => 'text', 'label' => 'Recaptcha Secret Key', 'help' => 'Add the recaptcha secret key here. You can get the key from the recaptcha website.', 'description' => 'The secret key is mandatory if you activate the recaptcha field'];
  178. }
  179. /* get all the fields and prefill them with the dafault-data, the user-data or old input data */
  180. $fields = $fieldsModel->getFields($userSettings, 'plugins', $pluginName, $pluginOriginalSettings);
  181. /* overwrite original plugin form definitions with enhanced form objects */
  182. $plugins[$pluginName]['forms']['fields'] = $fields;
  183. }
  184. }
  185. $user = new User();
  186. $users = $user->getUsers();
  187. $route = $request->getAttribute('route');
  188. return $this->render($response, 'settings/plugins.twig', array('settings' => $userSettings, 'plugins' => $plugins, 'users' => $users, 'route' => $route->getName() ));
  189. }
  190. /*************************************
  191. ** SAVE THEME- AND PLUGIN-SETTINGS **
  192. *************************************/
  193. public function saveThemes($request, $response, $args)
  194. {
  195. if($request->isPost())
  196. {
  197. $referer = $request->getHeader('HTTP_REFERER');
  198. $uri = $request->getUri();
  199. $base_url = $uri->getBaseUrl();
  200. # users should not be able to fake post with settings from other typemill pages.
  201. if(!isset($referer[0]) OR $referer[0] !== $base_url . '/tm/themes' )
  202. {
  203. $this->c->flash->addMessage('error', 'illegal referer');
  204. return $response->withRedirect($this->c->router->pathFor('themes.show'));
  205. }
  206. $userSettings = \Typemill\Settings::getUserSettings();
  207. $params = $request->getParams();
  208. $themeName = isset($params['theme']) ? $params['theme'] : false;
  209. $userInput = isset($params[$themeName]) ? $params[$themeName] : false;
  210. $validate = new Validation();
  211. $themeSettings = \Typemill\Settings::getObjectSettings('themes', $themeName);
  212. if(isset($themeSettings['settings']['images']))
  213. {
  214. # get the default settings
  215. $defaultSettings = \Typemill\Settings::getDefaultSettings();
  216. # merge the default image settings with the theme image settings, delete all others (image settings from old theme)
  217. $userSettings['images'] = array_merge($defaultSettings['images'], $themeSettings['settings']['images']);
  218. }
  219. /* set theme name and delete theme settings from user settings for the case, that the new theme has no settings */
  220. $userSettings['theme'] = $themeName;
  221. # extract the custom css from user input
  222. $customcss = isset($userInput['customcss']) ? $userInput['customcss'] : false;
  223. # delete custom css from userinput
  224. unset($userInput['customcss']);
  225. $write = new write();
  226. # make sure no file is set if there is no custom css
  227. if(!$customcss OR $customcss == '')
  228. {
  229. # delete the css file if exists
  230. $write->deleteFileWithPath('cache' . DIRECTORY_SEPARATOR . $themeName . '-custom.css');
  231. }
  232. else
  233. {
  234. if ( $customcss != strip_tags($customcss) )
  235. {
  236. $_SESSION['errors'][$themeName]['customcss'][] = 'custom css contains html';
  237. }
  238. else
  239. {
  240. # store css
  241. $write = new write();
  242. $write->writeFile('cache', $themeName . '-custom.css', $customcss);
  243. }
  244. }
  245. if($userInput)
  246. {
  247. /* validate the user-input */
  248. $this->validateInput('themes', $themeName, $userInput, $validate);
  249. /* set user input as theme settings */
  250. $userSettings['themes'][$themeName] = $userInput;
  251. }
  252. /* check for errors and redirect to path, if errors found */
  253. if(isset($_SESSION['errors']))
  254. {
  255. $this->c->flash->addMessage('error', 'Please correct the errors');
  256. return $response->withRedirect($this->c->router->pathFor('themes.show'));
  257. }
  258. /* store updated settings */
  259. \Typemill\Settings::updateSettings($userSettings);
  260. $this->c->flash->addMessage('info', 'Settings are stored');
  261. return $response->withRedirect($this->c->router->pathFor('themes.show'));
  262. }
  263. }
  264. public function savePlugins($request, $response, $args)
  265. {
  266. if($request->isPost())
  267. {
  268. $referer = $request->getHeader('HTTP_REFERER');
  269. $uri = $request->getUri();
  270. $base_url = $uri->getBaseUrl();
  271. # security, users should not be able to fake post with settings from other typemill pages.
  272. if(!isset($referer[0]) OR $referer[0] !== $base_url . '/tm/plugins' )
  273. {
  274. $this->c->flash->addMessage('error', 'illegal referer');
  275. return $response->withRedirect($this->c->router->pathFor('plugins.show'));
  276. }
  277. $userSettings = \Typemill\Settings::getUserSettings();
  278. $pluginSettings = array();
  279. $userInput = $request->getParams();
  280. $validate = new Validation();
  281. /* use the stored user settings and iterate over all original plugin settings, so we do not forget any... */
  282. foreach($userSettings['plugins'] as $pluginName => $pluginUserSettings)
  283. {
  284. /* if there are no input-data for this plugin, then use the stored plugin settings */
  285. if(!isset($userInput[$pluginName]))
  286. {
  287. $pluginSettings[$pluginName] = $pluginUserSettings;
  288. }
  289. else
  290. {
  291. /* validate the user-input */
  292. $this->validateInput('plugins', $pluginName, $userInput[$pluginName], $validate);
  293. /* use the input data */
  294. $pluginSettings[$pluginName] = $userInput[$pluginName];
  295. }
  296. /* deactivate the plugin, if there is no active flag */
  297. if(!isset($userInput[$pluginName]['active']))
  298. {
  299. $pluginSettings[$pluginName]['active'] = false;
  300. }
  301. }
  302. if(isset($_SESSION['errors']))
  303. {
  304. $this->c->flash->addMessage('error', 'Please correct the errors below');
  305. }
  306. else
  307. {
  308. /* if everything is valid, add plugin settings to base settings again */
  309. $userSettings['plugins'] = $pluginSettings;
  310. /* store updated settings */
  311. \Typemill\Settings::updateSettings($userSettings);
  312. $this->c->flash->addMessage('info', 'Settings are stored');
  313. }
  314. return $response->withRedirect($this->c->router->pathFor('plugins.show'));
  315. }
  316. }
  317. private function validateInput($objectType, $objectName, $userInput, $validate)
  318. {
  319. /* fetch the original settings from the folder (plugin or theme) to get the field definitions */
  320. $originalSettings = \Typemill\Settings::getObjectSettings($objectType, $objectName);
  321. if(isset($originalSettings['forms']['fields']))
  322. {
  323. /* flaten the multi-dimensional array with fieldsets to a one-dimensional array */
  324. $originalFields = array();
  325. foreach($originalSettings['forms']['fields'] as $fieldName => $fieldValue)
  326. {
  327. if(isset($fieldValue['fields']))
  328. {
  329. foreach($fieldValue['fields'] as $subFieldName => $subFieldValue)
  330. {
  331. $originalFields[$subFieldName] = $subFieldValue;
  332. }
  333. }
  334. else
  335. {
  336. $originalFields[$fieldName] = $fieldValue;
  337. }
  338. }
  339. # if the plugin defines frontend fields
  340. if(isset($originalSettings['public']))
  341. {
  342. $originalFields['recaptcha'] = ['type' => 'checkbox', 'label' => 'Google Recaptcha', 'checkboxlabel' => 'Activate Recaptcha' ];
  343. $originalFields['recaptcha_webkey'] = ['type' => 'text', 'label' => 'Recaptcha Website Key', 'help' => 'Add the recaptcha website key here. You can get the key from the recaptcha website.', 'description' => 'The website key is mandatory if you activate the recaptcha field'];
  344. $originalFields['recaptcha_secretkey'] = ['type' => 'text', 'label' => 'Recaptcha Secret Key', 'help' => 'Add the recaptcha secret key here. You can get the key from the recaptcha website.', 'description' => 'The secret key is mandatory if you activate the recaptcha field'];
  345. }
  346. # if plugin is not active, then skip required
  347. $skiprequired = false;
  348. if($objectType == 'plugins' && !isset($userInput['active']))
  349. {
  350. $skiprequired = true;
  351. }
  352. /* take the user input data and iterate over all fields and values */
  353. foreach($userInput as $fieldName => $fieldValue)
  354. {
  355. /* get the corresponding field definition from original plugin settings */
  356. $fieldDefinition = isset($originalFields[$fieldName]) ? $originalFields[$fieldName] : false;
  357. if($fieldDefinition)
  358. {
  359. /* validate user input for this field */
  360. $validate->objectField($fieldName, $fieldValue, $objectName, $fieldDefinition, $skiprequired);
  361. }
  362. if(!$fieldDefinition && $fieldName != 'active')
  363. {
  364. $_SESSION['errors'][$objectName][$fieldName] = array('This field is not defined!');
  365. }
  366. }
  367. }
  368. }
  369. /***********************
  370. ** USER MANAGEMENT **
  371. ***********************/
  372. public function showUser($request, $response, $args)
  373. {
  374. if($_SESSION['role'] == 'editor' && $_SESSION['user'] !== $args['username'])
  375. {
  376. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $_SESSION['user']] ));
  377. }
  378. $validate = new Validation();
  379. if($validate->username($args['username']))
  380. {
  381. $user = new User();
  382. $users = $user->getUsers();
  383. $userrole = $user->getUserroles();
  384. $userdata = $user->getUser($args['username']);
  385. $settings = $this->c->get('settings');
  386. if($userdata)
  387. {
  388. return $this->render($response, 'settings/user.twig', array('settings' => $settings, 'users' => $users, 'userdata' => $userdata, 'userrole' => $userrole, 'username' => $args['username'] ));
  389. }
  390. }
  391. $this->c->flash->addMessage('error', 'User does not exists');
  392. return $response->withRedirect($this->c->router->pathFor('user.list'));
  393. }
  394. public function listUser($request, $response)
  395. {
  396. $user = new User();
  397. $users = $user->getUsers();
  398. $userdata = array();
  399. $route = $request->getAttribute('route');
  400. $settings = $this->c->get('settings');
  401. foreach($users as $username)
  402. {
  403. $userdata[] = $user->getUser($username);
  404. }
  405. return $this->render($response, 'settings/userlist.twig', array('settings' => $settings, 'users' => $users, 'userdata' => $userdata, 'route' => $route->getName() ));
  406. }
  407. public function newUser($request, $response, $args)
  408. {
  409. $user = new User();
  410. $users = $user->getUsers();
  411. $userrole = $user->getUserroles();
  412. $route = $request->getAttribute('route');
  413. $settings = $this->c->get('settings');
  414. return $this->render($response, 'settings/usernew.twig', array('settings' => $settings, 'users' => $users, 'userrole' => $userrole, 'route' => $route->getName() ));
  415. }
  416. public function createUser($request, $response, $args)
  417. {
  418. if($request->isPost())
  419. {
  420. $referer = $request->getHeader('HTTP_REFERER');
  421. $uri = $request->getUri();
  422. $base_url = $uri->getBaseUrl();
  423. # security, users should not be able to fake post with settings from other typemill pages.
  424. if(!isset($referer[0]) OR $referer[0] !== $base_url . '/tm/user/new' )
  425. {
  426. $this->c->flash->addMessage('error', 'illegal referer');
  427. return $response->withRedirect($this->c->router->pathFor('user.new'));
  428. }
  429. $params = $request->getParams();
  430. $user = new User();
  431. $userroles = $user->getUserroles();
  432. $validate = new Validation();
  433. if($validate->newUser($params, $userroles))
  434. {
  435. $userdata = array('username' => $params['username'], 'firstname' => $params['firstname'], 'lastname' => $params['lastname'], 'email' => $params['email'], 'userrole' => $params['userrole'], 'password' => $params['password']);
  436. $user->createUser($userdata);
  437. $this->c->flash->addMessage('info', 'Welcome, there is a new user!');
  438. return $response->withRedirect($this->c->router->pathFor('user.list'));
  439. }
  440. $this->c->flash->addMessage('error', 'Please correct your input');
  441. return $response->withRedirect($this->c->router->pathFor('user.new'));
  442. }
  443. }
  444. public function updateUser($request, $response, $args)
  445. {
  446. if($request->isPost())
  447. {
  448. $referer = $request->getHeader('HTTP_REFERER');
  449. $uri = $request->getUri();
  450. $base_url = $uri->getBaseUrl();
  451. # security, users should not be able to fake post with settings from other typemill pages.
  452. if(!isset($referer[0]) OR strpos($referer[0], $base_url . '/tm/user/') === false )
  453. {
  454. $this->c->flash->addMessage('error', 'illegal referer');
  455. return $response->withRedirect($this->c->router->pathFor('user.list'));
  456. }
  457. $params = $request->getParams();
  458. $user = new User();
  459. $userroles = $user->getUserroles();
  460. $validate = new Validation();
  461. /* non admins have different update rights */
  462. if($_SESSION['role'] !== 'administrator')
  463. {
  464. /* if an editor tries to update other userdata than its own */
  465. if($_SESSION['user'] !== $params['username'])
  466. {
  467. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $_SESSION['user']] ));
  468. }
  469. /* non admins cannot change his userrole */
  470. $params['userrole'] = $_SESSION['role'];
  471. }
  472. if($validate->existingUser($params, $userroles))
  473. {
  474. $userdata = array('username' => $params['username'], 'firstname' => $params['firstname'], 'lastname' => $params['lastname'], 'email' => $params['email'], 'userrole' => $params['userrole']);
  475. if(empty($params['password']) AND empty($params['newpassword']))
  476. {
  477. $user->updateUser($userdata);
  478. $this->c->flash->addMessage('info', 'Saved all changes');
  479. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $params['username']]));
  480. }
  481. elseif($validate->newPassword($params))
  482. {
  483. $userdata['password'] = $params['newpassword'];
  484. $user->updateUser($userdata);
  485. $this->c->flash->addMessage('info', 'Saved all changes');
  486. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $params['username']]));
  487. }
  488. }
  489. $this->c->flash->addMessage('error', 'Please correct your input');
  490. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $params['username']]));
  491. }
  492. }
  493. public function deleteUser($request, $response, $args)
  494. {
  495. if($request->isPost())
  496. {
  497. $referer = $request->getHeader('HTTP_REFERER');
  498. $uri = $request->getUri();
  499. $base_url = $uri->getBaseUrl();
  500. # security, users should not be able to fake post with settings from other typemill pages.
  501. if(!isset($referer[0]) OR strpos($referer[0], $base_url . '/tm/user/') === false )
  502. {
  503. $this->c->flash->addMessage('error', 'illegal referer');
  504. return $response->withRedirect($this->c->router->pathFor('user.list'));
  505. }
  506. $params = $request->getParams();
  507. $validate = new Validation();
  508. $user = new User();
  509. /* non admins have different update rights */
  510. if($_SESSION['role'] !== 'administrator')
  511. {
  512. /* if an editor tries to delete other user than its own */
  513. if($_SESSION['user'] !== $params['username'])
  514. {
  515. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $_SESSION['user']] ));
  516. }
  517. }
  518. if($validate->username($params['username']))
  519. {
  520. $user->deleteUser($params['username']);
  521. # if user deleted his own account
  522. if($_SESSION['user'] == $params['username'])
  523. {
  524. session_destroy();
  525. return $response->withRedirect($this->c->router->pathFor('auth.show'));
  526. }
  527. $this->c->flash->addMessage('info', 'Say goodbye, the user is gone!');
  528. return $response->withRedirect($this->c->router->pathFor('user.list'));
  529. }
  530. $this->c->flash->addMessage('error', 'Ups, we did not find that user');
  531. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $params['username']]));
  532. }
  533. }
  534. private function getThemes()
  535. {
  536. $themeFolder = $this->c->get('settings')['rootPath'] . $this->c->get('settings')['themeFolder'];
  537. $themeFolderC = scandir($themeFolder);
  538. $themes = array();
  539. foreach ($themeFolderC as $key => $theme)
  540. {
  541. if (!in_array($theme, array(".","..")))
  542. {
  543. if (is_dir($themeFolder . DIRECTORY_SEPARATOR . $theme))
  544. {
  545. $themes[] = $theme;
  546. }
  547. }
  548. }
  549. return $themes;
  550. }
  551. private function getCopyright()
  552. {
  553. return array(
  554. "©",
  555. "CC-BY",
  556. "CC-BY-NC",
  557. "CC-BY-NC-ND",
  558. "CC-BY-NC-SA",
  559. "CC-BY-ND",
  560. "CC-BY-SA",
  561. "None"
  562. );
  563. }
  564. private function getLanguages()
  565. {
  566. return array(
  567. 'nl' => 'Dutch, Flemish',
  568. 'en' => 'English',
  569. 'de' => 'German',
  570. 'it' => 'Italian',
  571. );
  572. }
  573. }