PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/main/preprocess.php

https://github.com/chokoleytdesignoper/fluxcp_choko
PHP | 89 lines | 65 code | 16 blank | 8 comment | 26 complexity | 2de12b4e689d02d21cc2218645280757 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, BSD-3-Clause
  1. <?php
  2. if (!defined('FLUX_ROOT')) exit;
  3. // Check for "special" date fields.
  4. $__dates = array();
  5. foreach ($params->toArray() as $key => $value) {
  6. if (preg_match('&^(.+?)_(year|month|day|hour|minute|second)$&', $key, $m)) {
  7. $__dateParam = $m[1];
  8. $__dateType = $m[2];
  9. if (!array_key_exists($__dateParam, $__dates)) {
  10. // Not too sure why, but if I don't create a separate index for this array,
  11. // It will use the previous iteration's reference.
  12. $__dateArray[$__dateParam] = array();
  13. $__dates[$__dateParam] = new Flux_Config($__dateArray[$__dateParam]);
  14. }
  15. $__dates[$__dateParam]->set($__dateType, $value);
  16. }
  17. }
  18. foreach ($__dates as $__dateName => $__date) {
  19. $_year = $__date->get('year');
  20. $_month = $__date->get('month');
  21. $_day = $__date->get('day');
  22. $_hour = $__date->get('hour');
  23. $_minute = $__date->get('minute');
  24. $_second = $__date->get('second');
  25. // Construct DATE.
  26. if (!is_null($_year) && !is_null($_month) && !is_null($_day)) {
  27. $_format = sprintf('%04d-%02d-%02d', $_year, $_month, $_day);
  28. // Construct DATETIME.
  29. if (!is_null($_hour) && !is_null($_minute) && !is_null($_second)) {
  30. $_format .= sprintf(' %02d:%02d:%02d', $_hour, $_minute, $_second);
  31. }
  32. $params->set("{$__dateName}_date", $_format);
  33. }
  34. }
  35. $installer = Flux_Installer::getInstance();
  36. if ($installer->updateNeeded() && $params->get('module') != 'install') {
  37. $this->redirect($this->url('install'));
  38. }
  39. if (Flux::config('AutoUnholdAccount')) {
  40. Flux::processHeldCredits();
  41. }
  42. $ppReturn = array(
  43. 'txn_id' => $params->get('txn_id'),
  44. 'txn_type' => $params->get('txn_type'),
  45. 'first_name' => $params->get('first_name'),
  46. 'last_name' => $params->get('last_name'),
  47. 'item_name' => $params->get('item_name'),
  48. 'verify_sign' => $params->get('verify_sign')
  49. );
  50. if ($params->get('merchant_return_link') && $ppReturn['txn_id'] && $ppReturn['txn_type'] &&
  51. $ppReturn['first_name'] && $ppReturn['last_name'] && $ppReturn['item_name'] && $ppReturn['verify_sign']) {
  52. $session->setPpReturnData($ppReturn);
  53. $this->redirect($this->url('donate', 'complete'));
  54. }
  55. // Update preferred server.
  56. if (($preferred_server = $params->get('preferred_server')) && $session->getAthenaServer($preferred_server)) {
  57. $session->setAthenaServerNameData($params->get('preferred_server'));
  58. if (!array_key_exists('preferred_server', $_GET)) {
  59. $this->redirect($this->urlWithQs);
  60. }
  61. }
  62. // Preferred server.
  63. $server = $session->getAthenaServer();
  64. // WoE-based authorization.
  65. $_thisModule = $params->get('module');
  66. $_thisAction = $params->get('action');
  67. $woeDisallowModule = $server->woeDisallow->get($_thisModule);
  68. $woeDisallowAction = $server->woeDisallow->get("$_thisModule.$_thisAction");
  69. if (!$auth->allowedToViewWoeDisallowed && ($woeDisallowModule || $woeDisallowAction) && $server->isWoe()) {
  70. $session->setMessageData(Flux::message('DisallowedDuringWoE'));
  71. $this->redirect();
  72. }
  73. ?>