SettingsController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. <?php
  2. namespace Typemill\Controllers;
  3. use \Symfony\Component\Yaml\Yaml;
  4. use Typemill\Models\Fields;
  5. use Typemill\Models\Validation;
  6. use Typemill\Models\User;
  7. class SettingsController extends Controller
  8. {
  9. /*********************
  10. ** BASIC SETTINGS **
  11. *********************/
  12. public function showSettings($request, $response, $args)
  13. {
  14. $user = new User();
  15. $settings = $this->c->get('settings');
  16. $copyright = $this->getCopyright();
  17. $languages = $this->getLanguages();
  18. $locale = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2) : 'en';
  19. $users = $user->getUsers();
  20. $route = $request->getAttribute('route');
  21. return $this->render($response, 'settings/system.twig', array('settings' => $settings, 'copyright' => $copyright, 'languages' => $languages, 'locale' => $locale, 'users' => $users, 'route' => $route->getName() ));
  22. }
  23. public function saveSettings($request, $response, $args)
  24. {
  25. if($request->isPost())
  26. {
  27. $referer = $request->getHeader('HTTP_REFERER');
  28. $uri = $request->getUri();
  29. $base_url = $uri->getBaseUrl();
  30. # security, users should not be able to fake post with settings from other typemill pages.
  31. if(!isset($referer[0]) OR $referer[0] !== $base_url . '/tm/settings' )
  32. {
  33. $this->c->flash->addMessage('error', 'illegal referer');
  34. return $response->withRedirect($this->c->router->pathFor('settings.show'));
  35. }
  36. $settings = \Typemill\Settings::getUserSettings();
  37. $params = $request->getParams();
  38. $newSettings = isset($params['settings']) ? $params['settings'] : false;
  39. $validate = new Validation();
  40. if($newSettings)
  41. {
  42. /* make sure only allowed fields are stored */
  43. $newSettings = array(
  44. 'title' => $newSettings['title'],
  45. 'author' => $newSettings['author'],
  46. 'copyright' => $newSettings['copyright'],
  47. 'year' => $newSettings['year'],
  48. 'language' => $newSettings['language'],
  49. 'startpage' => isset($newSettings['startpage']) ? true : false,
  50. 'editor' => $newSettings['editor'],
  51. );
  52. $copyright = $this->getCopyright();
  53. $validate->settings($newSettings, $copyright, 'settings');
  54. }
  55. else
  56. {
  57. $this->c->flash->addMessage('error', 'Wrong Input');
  58. return $response->withRedirect($this->c->router->pathFor('settings.show'));
  59. }
  60. if(isset($_SESSION['errors']))
  61. {
  62. $this->c->flash->addMessage('error', 'Please correct the errors');
  63. return $response->withRedirect($this->c->router->pathFor('settings.show'));
  64. }
  65. /* store updated settings */
  66. \Typemill\Settings::updateSettings(array_merge($settings, $newSettings));
  67. $this->c->flash->addMessage('info', 'Settings are stored');
  68. return $response->withRedirect($this->c->router->pathFor('settings.show'));
  69. }
  70. }
  71. /*********************
  72. ** THEME SETTINGS **
  73. *********************/
  74. public function showThemes($request, $response, $args)
  75. {
  76. $userSettings = $this->c->get('settings');
  77. $themes = $this->getThemes();
  78. $themedata = array();
  79. $fieldsModel = new Fields();
  80. foreach($themes as $themeName)
  81. {
  82. /* if theme is active, list it first */
  83. if($userSettings['theme'] == $themeName)
  84. {
  85. $themedata = array_merge(array($themeName => null), $themedata);
  86. }
  87. else
  88. {
  89. $themedata[$themeName] = null;
  90. }
  91. $themeSettings = \Typemill\Settings::getObjectSettings('themes', $themeName);
  92. if($themeSettings)
  93. {
  94. /* store them as default theme data with author, year, default settings and field-definitions */
  95. $themedata[$themeName] = $themeSettings;
  96. }
  97. if(isset($themeSettings['forms']['fields']))
  98. {
  99. $fields = $fieldsModel->getFields($userSettings, 'themes', $themeName, $themeSettings);
  100. /* overwrite original theme form definitions with enhanced form objects */
  101. $themedata[$themeName]['forms']['fields'] = $fields;
  102. }
  103. /* add the preview image */
  104. $img = getcwd() . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $themeName . DIRECTORY_SEPARATOR . $themeName . '.jpg';
  105. $img = file_exists($img) ? $img : false;
  106. $themedata[$themeName]['img'] = $img;
  107. }
  108. /* add the users for navigation */
  109. $user = new User();
  110. $users = $user->getUsers();
  111. $route = $request->getAttribute('route');
  112. return $this->render($response, 'settings/themes.twig', array('settings' => $userSettings, 'themes' => $themedata, 'users' => $users, 'route' => $route->getName() ));
  113. }
  114. public function showPlugins($request, $response, $args)
  115. {
  116. $userSettings = $this->c->get('settings');
  117. $plugins = array();
  118. $fieldsModel = new Fields();
  119. $fields = array();
  120. /* iterate through the plugins in the stored user settings */
  121. foreach($userSettings['plugins'] as $pluginName => $pluginUserSettings)
  122. {
  123. /* add plugin to plugin Data, if active, set it first */
  124. /* if plugin is active, list it first */
  125. if($userSettings['plugins'][$pluginName]['active'] == true)
  126. {
  127. $plugins = array_merge(array($pluginName => null), $plugins);
  128. }
  129. else
  130. {
  131. $plugins[$pluginName] = Null;
  132. }
  133. /* Check if the user has deleted a plugin. Then delete it in the settings and store the updated settings. */
  134. if(!is_dir($userSettings['rootPath'] . 'plugins' . DIRECTORY_SEPARATOR . $pluginName))
  135. {
  136. /* remove the plugin settings and store updated settings */
  137. \Typemill\Settings::removePluginSettings($pluginName);
  138. continue;
  139. }
  140. /* load the original plugin definitions from the plugin folder (author, version and stuff) */
  141. $pluginOriginalSettings = \Typemill\Settings::getObjectSettings('plugins', $pluginName);
  142. if($pluginOriginalSettings)
  143. {
  144. /* store them as default plugin data with plugin author, plugin year, default settings and field-definitions */
  145. $plugins[$pluginName] = $pluginOriginalSettings;
  146. }
  147. /* check, if the plugin has been disabled in the form-session-data */
  148. if(isset($_SESSION['old']) && !isset($_SESSION['old'][$pluginName]['active']))
  149. {
  150. $plugins[$pluginName]['settings']['active'] = false;
  151. }
  152. /* if the plugin defines forms and fields, so that the user can edit the plugin settings in the frontend */
  153. if(isset($pluginOriginalSettings['forms']['fields']))
  154. {
  155. # if the plugin defines frontend fields
  156. if(isset($pluginOriginalSettings['public']))
  157. {
  158. $pluginOriginalSettings['forms']['fields']['recaptcha'] = ['type' => 'checkbox', 'label' => 'Google Recaptcha', 'checkboxlabel' => 'Activate Recaptcha' ];
  159. $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'];
  160. $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'];
  161. }
  162. /* get all the fields and prefill them with the dafault-data, the user-data or old input data */
  163. $fields = $fieldsModel->getFields($userSettings, 'plugins', $pluginName, $pluginOriginalSettings);
  164. /* overwrite original plugin form definitions with enhanced form objects */
  165. $plugins[$pluginName]['forms']['fields'] = $fields;
  166. }
  167. }
  168. $user = new User();
  169. $users = $user->getUsers();
  170. $route = $request->getAttribute('route');
  171. return $this->render($response, 'settings/plugins.twig', array('settings' => $userSettings, 'plugins' => $plugins, 'users' => $users, 'route' => $route->getName() ));
  172. }
  173. /*************************************
  174. ** SAVE THEME- AND PLUGIN-SETTINGS **
  175. *************************************/
  176. public function saveThemes($request, $response, $args)
  177. {
  178. if($request->isPost())
  179. {
  180. $referer = $request->getHeader('HTTP_REFERER');
  181. $uri = $request->getUri();
  182. $base_url = $uri->getBaseUrl();
  183. # users should not be able to fake post with settings from other typemill pages.
  184. if(!isset($referer[0]) OR $referer[0] !== $base_url . '/tm/themes' )
  185. {
  186. $this->c->flash->addMessage('error', 'illegal referer');
  187. return $response->withRedirect($this->c->router->pathFor('themes.show'));
  188. }
  189. $userSettings = \Typemill\Settings::getUserSettings();
  190. $params = $request->getParams();
  191. $themeName = isset($params['theme']) ? $params['theme'] : false;
  192. $userInput = isset($params[$themeName]) ? $params[$themeName] : false;
  193. $validate = new Validation();
  194. $themeSettings = \Typemill\Settings::getObjectSettings('themes', $themeName);
  195. if(isset($themeSettings['settings']['images']))
  196. {
  197. # get the default settings
  198. $defaultSettings = \Typemill\Settings::getDefaultSettings();
  199. # merge the default image settings with the theme image settings, delete all others (image settings from old theme)
  200. $userSettings['images'] = array_merge($defaultSettings['images'], $themeSettings['settings']['images']);
  201. }
  202. /* set theme name and delete theme settings from user settings for the case, that the new theme has no settings */
  203. $userSettings['theme'] = $themeName;
  204. if($userInput)
  205. {
  206. /* validate the user-input */
  207. $this->validateInput('themes', $themeName, $userInput, $validate);
  208. /* set user input as theme settings */
  209. $userSettings['themes'][$themeName] = $userInput;
  210. }
  211. /* check for errors and redirect to path, if errors found */
  212. if(isset($_SESSION['errors']))
  213. {
  214. $this->c->flash->addMessage('error', 'Please correct the errors');
  215. return $response->withRedirect($this->c->router->pathFor('themes.show'));
  216. }
  217. /* store updated settings */
  218. \Typemill\Settings::updateSettings($userSettings);
  219. $this->c->flash->addMessage('info', 'Settings are stored');
  220. return $response->withRedirect($this->c->router->pathFor('themes.show'));
  221. }
  222. }
  223. public function savePlugins($request, $response, $args)
  224. {
  225. if($request->isPost())
  226. {
  227. $referer = $request->getHeader('HTTP_REFERER');
  228. $uri = $request->getUri();
  229. $base_url = $uri->getBaseUrl();
  230. # security, users should not be able to fake post with settings from other typemill pages.
  231. if(!isset($referer[0]) OR $referer[0] !== $base_url . '/tm/plugins' )
  232. {
  233. $this->c->flash->addMessage('error', 'illegal referer');
  234. return $response->withRedirect($this->c->router->pathFor('plugins.show'));
  235. }
  236. $userSettings = \Typemill\Settings::getUserSettings();
  237. $pluginSettings = array();
  238. $userInput = $request->getParams();
  239. $validate = new Validation();
  240. /* use the stored user settings and iterate over all original plugin settings, so we do not forget any... */
  241. foreach($userSettings['plugins'] as $pluginName => $pluginUserSettings)
  242. {
  243. /* if there are no input-data for this plugin, then use the stored plugin settings */
  244. if(!isset($userInput[$pluginName]))
  245. {
  246. $pluginSettings[$pluginName] = $pluginUserSettings;
  247. }
  248. else
  249. {
  250. /* validate the user-input */
  251. $this->validateInput('plugins', $pluginName, $userInput[$pluginName], $validate);
  252. /* use the input data */
  253. $pluginSettings[$pluginName] = $userInput[$pluginName];
  254. }
  255. /* deactivate the plugin, if there is no active flag */
  256. if(!isset($userInput[$pluginName]['active']))
  257. {
  258. $pluginSettings[$pluginName]['active'] = false;
  259. }
  260. }
  261. if(isset($_SESSION['errors']))
  262. {
  263. $this->c->flash->addMessage('error', 'Please correct the errors below');
  264. }
  265. else
  266. {
  267. /* if everything is valid, add plugin settings to base settings again */
  268. $userSettings['plugins'] = $pluginSettings;
  269. /* store updated settings */
  270. \Typemill\Settings::updateSettings($userSettings);
  271. $this->c->flash->addMessage('info', 'Settings are stored');
  272. }
  273. return $response->withRedirect($this->c->router->pathFor('plugins.show'));
  274. }
  275. }
  276. private function validateInput($objectType, $objectName, $userInput, $validate)
  277. {
  278. /* fetch the original settings from the folder (plugin or theme) to get the field definitions */
  279. $originalSettings = \Typemill\Settings::getObjectSettings($objectType, $objectName);
  280. if(isset($originalSettings['forms']['fields']))
  281. {
  282. /* flaten the multi-dimensional array with fieldsets to a one-dimensional array */
  283. $originalFields = array();
  284. foreach($originalSettings['forms']['fields'] as $fieldName => $fieldValue)
  285. {
  286. if(isset($fieldValue['fields']))
  287. {
  288. foreach($fieldValue['fields'] as $subFieldName => $subFieldValue)
  289. {
  290. $originalFields[$subFieldName] = $subFieldValue;
  291. }
  292. }
  293. else
  294. {
  295. $originalFields[$fieldName] = $fieldValue;
  296. }
  297. }
  298. # if the plugin defines frontend fields
  299. if(isset($originalSettings['public']))
  300. {
  301. $originalFields['recaptcha'] = ['type' => 'checkbox', 'label' => 'Google Recaptcha', 'checkboxlabel' => 'Activate Recaptcha' ];
  302. $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'];
  303. $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'];
  304. }
  305. /* take the user input data and iterate over all fields and values */
  306. foreach($userInput as $fieldName => $fieldValue)
  307. {
  308. /* get the corresponding field definition from original plugin settings */
  309. $fieldDefinition = isset($originalFields[$fieldName]) ? $originalFields[$fieldName] : false;
  310. if($fieldDefinition)
  311. {
  312. /* validate user input for this field */
  313. $validate->objectField($fieldName, $fieldValue, $objectName, $fieldDefinition);
  314. }
  315. if(!$fieldDefinition && $fieldName != 'active')
  316. {
  317. $_SESSION['errors'][$objectName][$fieldName] = array('This field is not defined!');
  318. }
  319. }
  320. }
  321. }
  322. /***********************
  323. ** USER MANAGEMENT **
  324. ***********************/
  325. public function showUser($request, $response, $args)
  326. {
  327. if($_SESSION['role'] == 'editor' && $_SESSION['user'] !== $args['username'])
  328. {
  329. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $_SESSION['user']] ));
  330. }
  331. $validate = new Validation();
  332. if($validate->username($args['username']))
  333. {
  334. $user = new User();
  335. $users = $user->getUsers();
  336. $userrole = $user->getUserroles();
  337. $userdata = $user->getUser($args['username']);
  338. $settings = $this->c->get('settings');
  339. if($userdata)
  340. {
  341. return $this->render($response, 'settings/user.twig', array('settings' => $settings, 'users' => $users, 'userdata' => $userdata, 'userrole' => $userrole, 'username' => $args['username'] ));
  342. }
  343. }
  344. $this->c->flash->addMessage('error', 'User does not exists');
  345. return $response->withRedirect($this->c->router->pathFor('user.list'));
  346. }
  347. public function listUser($request, $response)
  348. {
  349. $user = new User();
  350. $users = $user->getUsers();
  351. $userdata = array();
  352. $route = $request->getAttribute('route');
  353. $settings = $this->c->get('settings');
  354. foreach($users as $username)
  355. {
  356. $userdata[] = $user->getUser($username);
  357. }
  358. return $this->render($response, 'settings/userlist.twig', array('settings' => $settings, 'users' => $users, 'userdata' => $userdata, 'route' => $route->getName() ));
  359. }
  360. public function newUser($request, $response, $args)
  361. {
  362. $user = new User();
  363. $users = $user->getUsers();
  364. $userrole = $user->getUserroles();
  365. $route = $request->getAttribute('route');
  366. $settings = $this->c->get('settings');
  367. return $this->render($response, 'settings/usernew.twig', array('settings' => $settings, 'users' => $users, 'userrole' => $userrole, 'route' => $route->getName() ));
  368. }
  369. public function createUser($request, $response, $args)
  370. {
  371. if($request->isPost())
  372. {
  373. $referer = $request->getHeader('HTTP_REFERER');
  374. $uri = $request->getUri();
  375. $base_url = $uri->getBaseUrl();
  376. # security, users should not be able to fake post with settings from other typemill pages.
  377. if(!isset($referer[0]) OR $referer[0] !== $base_url . '/tm/user/new' )
  378. {
  379. $this->c->flash->addMessage('error', 'illegal referer');
  380. return $response->withRedirect($this->c->router->pathFor('user.new'));
  381. }
  382. $params = $request->getParams();
  383. $user = new User();
  384. $userroles = $user->getUserroles();
  385. $validate = new Validation();
  386. if($validate->newUser($params, $userroles))
  387. {
  388. $userdata = array('username' => $params['username'], 'email' => $params['email'], 'userrole' => $params['userrole'], 'password' => $params['password']);
  389. $user->createUser($userdata);
  390. $this->c->flash->addMessage('info', 'Welcome, there is a new user!');
  391. return $response->withRedirect($this->c->router->pathFor('user.list'));
  392. }
  393. $this->c->flash->addMessage('error', 'Please correct your input');
  394. return $response->withRedirect($this->c->router->pathFor('user.new'));
  395. }
  396. }
  397. public function updateUser($request, $response, $args)
  398. {
  399. if($request->isPost())
  400. {
  401. $referer = $request->getHeader('HTTP_REFERER');
  402. $uri = $request->getUri();
  403. $base_url = $uri->getBaseUrl();
  404. # security, users should not be able to fake post with settings from other typemill pages.
  405. if(!isset($referer[0]) OR strpos($referer[0], $base_url . '/tm/user/') === false )
  406. {
  407. $this->c->flash->addMessage('error', 'illegal referer');
  408. return $response->withRedirect($this->c->router->pathFor('user.list'));
  409. }
  410. $params = $request->getParams();
  411. $user = new User();
  412. $userroles = $user->getUserroles();
  413. $validate = new Validation();
  414. /* non admins have different update rights */
  415. if($_SESSION['role'] !== 'administrator')
  416. {
  417. /* if an editor tries to update other userdata than its own */
  418. if($_SESSION['user'] !== $params['username'])
  419. {
  420. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $_SESSION['user']] ));
  421. }
  422. /* non admins cannot change his userrole */
  423. $params['userrole'] = $_SESSION['role'];
  424. }
  425. if($validate->existingUser($params, $userroles))
  426. {
  427. $userdata = array('username' => $params['username'], 'email' => $params['email'], 'userrole' => $params['userrole']);
  428. if(empty($params['password']) AND empty($params['newpassword']))
  429. {
  430. $user->updateUser($userdata);
  431. $this->c->flash->addMessage('info', 'Saved all changes');
  432. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $params['username']]));
  433. }
  434. elseif($validate->newPassword($params))
  435. {
  436. $userdata['password'] = $params['newpassword'];
  437. $user->updateUser($userdata);
  438. $this->c->flash->addMessage('info', 'Saved all changes');
  439. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $params['username']]));
  440. }
  441. }
  442. $this->c->flash->addMessage('error', 'Please correct your input');
  443. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $params['username']]));
  444. }
  445. }
  446. public function deleteUser($request, $response, $args)
  447. {
  448. if($request->isPost())
  449. {
  450. $referer = $request->getHeader('HTTP_REFERER');
  451. $uri = $request->getUri();
  452. $base_url = $uri->getBaseUrl();
  453. # security, users should not be able to fake post with settings from other typemill pages.
  454. if(!isset($referer[0]) OR strpos($referer[0], $base_url . '/tm/user/') === false )
  455. {
  456. $this->c->flash->addMessage('error', 'illegal referer');
  457. return $response->withRedirect($this->c->router->pathFor('user.list'));
  458. }
  459. $params = $request->getParams();
  460. $validate = new Validation();
  461. $user = new User();
  462. /* non admins have different update rights */
  463. if($_SESSION['role'] !== 'administrator')
  464. {
  465. /* if an editor tries to delete other user than its own */
  466. if($_SESSION['user'] !== $params['username'])
  467. {
  468. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $_SESSION['user']] ));
  469. }
  470. }
  471. if($validate->username($params['username']))
  472. {
  473. $user->deleteUser($params['username']);
  474. # if user deleted his own account
  475. if($_SESSION['user'] == $params['username'])
  476. {
  477. session_destroy();
  478. return $response->withRedirect($this->c->router->pathFor('auth.show'));
  479. }
  480. $this->c->flash->addMessage('info', 'Say goodbye, the user is gone!');
  481. return $response->withRedirect($this->c->router->pathFor('user.list'));
  482. }
  483. $this->c->flash->addMessage('error', 'Ups, we did not find that user');
  484. return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $params['username']]));
  485. }
  486. }
  487. private function getThemes()
  488. {
  489. $themeFolder = $this->c->get('settings')['rootPath'] . $this->c->get('settings')['themeFolder'];
  490. $themeFolderC = scandir($themeFolder);
  491. $themes = array();
  492. foreach ($themeFolderC as $key => $theme)
  493. {
  494. if (!in_array($theme, array(".","..")))
  495. {
  496. if (is_dir($themeFolder . DIRECTORY_SEPARATOR . $theme))
  497. {
  498. $themes[] = $theme;
  499. }
  500. }
  501. }
  502. return $themes;
  503. }
  504. private function getCopyright()
  505. {
  506. return array(
  507. "©",
  508. "CC-BY",
  509. "CC-BY-NC",
  510. "CC-BY-NC-ND",
  511. "CC-BY-NC-SA",
  512. "CC-BY-ND",
  513. "CC-BY-SA",
  514. "None"
  515. );
  516. }
  517. private function getLanguages()
  518. {
  519. return array(
  520. 'ab' => 'Abkhazian',
  521. 'aa' => 'Afar',
  522. 'af' => 'Afrikaans',
  523. 'ak' => 'Akan',
  524. 'sq' => 'Albanian',
  525. 'am' => 'Amharic',
  526. 'ar' => 'Arabic',
  527. 'an' => 'Aragonese',
  528. 'hy' => 'Armenian',
  529. 'as' => 'Assamese',
  530. 'av' => 'Avaric',
  531. 'ae' => 'Avestan',
  532. 'ay' => 'Aymara',
  533. 'az' => 'Azerbaijani',
  534. 'bm' => 'Bambara',
  535. 'ba' => 'Bashkir',
  536. 'eu' => 'Basque',
  537. 'be' => 'Belarusian',
  538. 'bn' => 'Bengali',
  539. 'bh' => 'Bihari languages',
  540. 'bi' => 'Bislama',
  541. 'bs' => 'Bosnian',
  542. 'br' => 'Breton',
  543. 'bg' => 'Bulgarian',
  544. 'my' => 'Burmese',
  545. 'ca' => 'Catalan, Valencian',
  546. 'km' => 'Central Khmer',
  547. 'ch' => 'Chamorro',
  548. 'ce' => 'Chechen',
  549. 'ny' => 'Chichewa, Chewa, Nyanja',
  550. 'zh' => 'Chinese',
  551. 'cu' => 'Church Slavonic, Old Bulgarian, Old Church Slavonic',
  552. 'cv' => 'Chuvash',
  553. 'kw' => 'Cornish',
  554. 'co' => 'Corsican',
  555. 'cr' => 'Cree',
  556. 'hr' => 'Croatian',
  557. 'cs' => 'Czech',
  558. 'da' => 'Danish',
  559. 'dv' => 'Divehi, Dhivehi, Maldivian',
  560. 'nl' => 'Dutch, Flemish',
  561. 'dz' => 'Dzongkha',
  562. 'en' => 'English',
  563. 'eo' => 'Esperanto',
  564. 'et' => 'Estonian',
  565. 'ee' => 'Ewe',
  566. 'fo' => 'Faroese',
  567. 'fj' => 'Fijian',
  568. 'fi' => 'Finnish',
  569. 'fr' => 'French',
  570. 'ff' => 'Fulah',
  571. 'gd' => 'Gaelic, Scottish Gaelic',
  572. 'gl' => 'Galician',
  573. 'lg' => 'Ganda',
  574. 'ka' => 'Georgian',
  575. 'de' => 'German',
  576. 'ki' => 'Gikuyu, Kikuyu',
  577. 'el' => 'Greek (Modern)',
  578. 'kl' => 'Greenlandic, Kalaallisut',
  579. 'gn' => 'Guarani',
  580. 'gu' => 'Gujarati',
  581. 'ht' => 'Haitian, Haitian Creole',
  582. 'ha' => 'Hausa',
  583. 'he' => 'Hebrew',
  584. 'hz' => 'Herero',
  585. 'hi' => 'Hindi',
  586. 'ho' => 'Hiri Motu',
  587. 'hu' => 'Hungarian',
  588. 'is' => 'Icelandic',
  589. 'io' => 'Ido',
  590. 'ig' => 'Igbo',
  591. 'id' => 'Indonesian',
  592. 'ia' => 'Interlingua (International Auxiliary Language Association)',
  593. 'ie' => 'Interlingue',
  594. 'iu' => 'Inuktitut',
  595. 'ik' => 'Inupiaq',
  596. 'ga' => 'Irish',
  597. 'it' => 'Italian',
  598. 'ja' => 'Japanese',
  599. 'jv' => 'Javanese',
  600. 'kn' => 'Kannada',
  601. 'kr' => 'Kanuri',
  602. 'ks' => 'Kashmiri',
  603. 'kk' => 'Kazakh',
  604. 'rw' => 'Kinyarwanda',
  605. 'kv' => 'Komi',
  606. 'kg' => 'Kongo',
  607. 'ko' => 'Korean',
  608. 'kj' => 'Kwanyama, Kuanyama',
  609. 'ku' => 'Kurdish',
  610. 'ky' => 'Kyrgyz',
  611. 'lo' => 'Lao',
  612. 'la' => 'Latin',
  613. 'lv' => 'Latvian',
  614. 'lb' => 'Letzeburgesch, Luxembourgish',
  615. 'li' => 'Limburgish, Limburgan, Limburger',
  616. 'ln' => 'Lingala',
  617. 'lt' => 'Lithuanian',
  618. 'lu' => 'Luba-Katanga',
  619. 'mk' => 'Macedonian',
  620. 'mg' => 'Malagasy',
  621. 'ms' => 'Malay',
  622. 'ml' => 'Malayalam',
  623. 'mt' => 'Maltese',
  624. 'gv' => 'Manx',
  625. 'mi' => 'Maori',
  626. 'mr' => 'Marathi',
  627. 'mh' => 'Marshallese',
  628. 'ro' => 'Moldovan, Moldavian, Romanian',
  629. 'mn' => 'Mongolian',
  630. 'na' => 'Nauru',
  631. 'nv' => 'Navajo, Navaho',
  632. 'nd' => 'Northern Ndebele',
  633. 'ng' => 'Ndonga',
  634. 'ne' => 'Nepali',
  635. 'se' => 'Northern Sami',
  636. 'no' => 'Norwegian',
  637. 'nb' => 'Norwegian Bokmål',
  638. 'nn' => 'Norwegian Nynorsk',
  639. 'ii' => 'Nuosu, Sichuan Yi',
  640. 'oc' => 'Occitan (post 1500)',
  641. 'oj' => 'Ojibwa',
  642. 'or' => 'Oriya',
  643. 'om' => 'Oromo',
  644. 'os' => 'Ossetian, Ossetic',
  645. 'pi' => 'Pali',
  646. 'pa' => 'Panjabi, Punjabi',
  647. 'ps' => 'Pashto, Pushto',
  648. 'fa' => 'Persian',
  649. 'pl' => 'Polish',
  650. 'pt' => 'Portuguese',
  651. 'qu' => 'Quechua',
  652. 'rm' => 'Romansh',
  653. 'rn' => 'Rundi',
  654. 'ru' => 'Russian',
  655. 'sm' => 'Samoan',
  656. 'sg' => 'Sango',
  657. 'sa' => 'Sanskrit',
  658. 'sc' => 'Sardinian',
  659. 'sr' => 'Serbian',
  660. 'sn' => 'Shona',
  661. 'sd' => 'Sindhi',
  662. 'si' => 'Sinhala, Sinhalese',
  663. 'sk' => 'Slovak',
  664. 'sl' => 'Slovenian',
  665. 'so' => 'Somali',
  666. 'st' => 'Sotho, Southern',
  667. 'nr' => 'South Ndebele',
  668. 'es' => 'Spanish, Castilian',
  669. 'su' => 'Sundanese',
  670. 'sw' => 'Swahili',
  671. 'ss' => 'Swati',
  672. 'sv' => 'Swedish',
  673. 'tl' => 'Tagalog',
  674. 'ty' => 'Tahitian',
  675. 'tg' => 'Tajik',
  676. 'ta' => 'Tamil',
  677. 'tt' => 'Tatar',
  678. 'te' => 'Telugu',
  679. 'th' => 'Thai',
  680. 'bo' => 'Tibetan',
  681. 'ti' => 'Tigrinya',
  682. 'to' => 'Tonga (Tonga Islands)',
  683. 'ts' => 'Tsonga',
  684. 'tn' => 'Tswana',
  685. 'tr' => 'Turkish',
  686. 'tk' => 'Turkmen',
  687. 'tw' => 'Twi',
  688. 'ug' => 'Uighur, Uyghur',
  689. 'uk' => 'Ukrainian',
  690. 'ur' => 'Urdu',
  691. 'uz' => 'Uzbek',
  692. 've' => 'Venda',
  693. 'vi' => 'Vietnamese',
  694. 'vo' => 'Volap_k',
  695. 'wa' => 'Walloon',
  696. 'cy' => 'Welsh',
  697. 'fy' => 'Western Frisian',
  698. 'wo' => 'Wolof',
  699. 'xh' => 'Xhosa',
  700. 'yi' => 'Yiddish',
  701. 'yo' => 'Yoruba',
  702. 'za' => 'Zhuang, Chuang',
  703. 'zu' => 'Zulu'
  704. );
  705. }
  706. }