SettingsController.php 24 KB

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