SettingsController.php 26 KB

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