/include/includes/classes/info.class.php

https://github.com/pschichtel/Infected-CMS · PHP · 390 lines · 234 code · 27 blank · 129 comment · 17 complexity · b5560584c5413b1ed5ee562b67c8465a MD5 · raw file

  1. <?php
  2. defined('MODE') or die('<strong>Access denied!</strong>');
  3. class Info
  4. {
  5. /**
  6. * the name of the current modul
  7. *
  8. * @access public
  9. * @var string
  10. */
  11. public $modul;
  12. /**
  13. * the absolute HTTP path to the modul file
  14. *
  15. * @access public
  16. * @var string
  17. */
  18. public $modulFile;
  19. /**
  20. * the absolute HTTP path to the modul
  21. *
  22. * @access public
  23. * @var string
  24. */
  25. public $modulSelf;
  26. /**
  27. * the current querystring
  28. *
  29. * @access public
  30. * @var string
  31. */
  32. public $modulQueryString;
  33. /**
  34. * the current language token
  35. *
  36. * @access public
  37. * @var string
  38. */
  39. public $lang;
  40. /**
  41. * the name of the current design
  42. *
  43. * @access public
  44. * @var string
  45. */
  46. public $design;
  47. /**
  48. * the absolute HTTP path of the CMS
  49. *
  50. * @access public
  51. * @var string
  52. */
  53. public $cmsPath;
  54. /**
  55. * wraps $_SERVER['REQUEST_URI']
  56. *
  57. * @access public
  58. * @var string the requested URI
  59. */
  60. public $requestUri;
  61. /**
  62. * the array with the params
  63. *
  64. * @access private
  65. * @var array
  66. */
  67. private $modulParams;
  68. /**
  69. * the global database connection
  70. *
  71. * @access private
  72. * @var Database
  73. */
  74. private $db;
  75. /**
  76. * the global configuration object
  77. *
  78. * @access private
  79. * @var Config
  80. */
  81. private $config;
  82. /**
  83. * the info Log object
  84. *
  85. * @access private
  86. * @var Log
  87. */
  88. private $log;
  89. const KEY_VALUE_DELIM = '-';
  90. const PAIR_DELIM = '.';
  91. /**
  92. * initiates the Config object
  93. *
  94. * @global Database $db
  95. * @global Config $cfg
  96. */
  97. public function __construct()
  98. {
  99. global $db;
  100. $this->db = $db;
  101. global $cfg;
  102. $this->config = $cfg;
  103. $this->log = new Log('info');
  104. $this->log->write(1, 'init', 'Empty signature, calling private getter-functions');
  105. $this->modulParams = array();
  106. $this->getCmsPath();
  107. $this->getModul();
  108. $this->getModulSelf();
  109. $this->getModulParams();
  110. $this->getModulQueryString();
  111. $this->getLang();
  112. $this->getDesign();
  113. $this->requestUri = &$_SERVER['REQUEST_URI'];
  114. }
  115. /**
  116. * destructs the object
  117. */
  118. public function __destruct()
  119. {
  120. unset($this->modulParams);
  121. unset($this->log);
  122. }
  123. /**
  124. * return a translated status message or a empty string
  125. *
  126. * @access public
  127. * @param Lang $lang a lang object to get the translated message
  128. * @return string the translated status-message
  129. */
  130. public function statusMessage(&$lang)
  131. {
  132. if (!isset($this->modulParams['status']))
  133. {
  134. return '';
  135. }
  136. return $lang->{'status_' . $this->modulParams['status']};
  137. }
  138. /**
  139. * returns the requested param or null if it does not exist
  140. *
  141. * @param string $index the index of the param
  142. * @return mixed string if the param exists, otherwise null
  143. */
  144. public function modulParams($index)
  145. {
  146. if (isset($this->modulParams[$index]))
  147. {
  148. return $this->modulParams[$index];
  149. }
  150. else
  151. {
  152. return null;
  153. }
  154. }
  155. /**
  156. * gets the absolute http path of the CMS
  157. *
  158. * @access private
  159. */
  160. private function getCmsPath()
  161. {
  162. $this->cmsPath = dirname($_SERVER['PHP_SELF']) . '/';
  163. $this->log->write(2, 'info', "CMS path: {$this->cmsPath}");
  164. }
  165. /**
  166. * gets the current modul name
  167. *
  168. * @access private
  169. */
  170. private function getModul()
  171. {
  172. $path = 'include/' . (MODE ? 'admin' : 'contents') . '/';
  173. $this->log->write(2, 'info', '#> ' . $path);
  174. if (isset($_GET['modul']))
  175. {
  176. $modul = &$_GET['modul'];
  177. $path .= 'moduls/';
  178. if (
  179. substr_count($modul, '.') ||
  180. !file_exists($path . $_GET['modul'] . '.modul.php')
  181. )
  182. {
  183. $this->log->write(1, 'error', 'modul not loaded, redirecting to cfg::cms_std_modul');
  184. headerTo(SEO::makeAddress($this->config->cms_std_modul));
  185. }
  186. $this->modul = &$modul;
  187. $this->modulFile = $path . $modul . '.modul.php';
  188. }
  189. elseif (isset($_GET['helper']))
  190. {
  191. $helper = &$_GET['helper'];
  192. $path .= 'helper/';
  193. if (
  194. mb_substr_count('.', $helper) ||
  195. !file_exists($path . $helper . '.helper.php')
  196. )
  197. {
  198. die('Helper-modul not found!');
  199. }
  200. $this->modul = &$helper;
  201. $this->modulFile = $path . $helper . '.helper.php';
  202. }
  203. else
  204. {
  205. $path .= 'moduls/';
  206. if (MODE)
  207. {
  208. $this->modul = 'overview';
  209. $this->modulFile = $path . $this->modul . '.modul.php';
  210. }
  211. else
  212. {
  213. $this->modul = $this->config->cms_std_modul;
  214. $this->modulFile = $path . $this->modul . '.modul.php';
  215. }
  216. }
  217. $this->log->write(2, 'info', "Current modul: {$this->modul}");
  218. }
  219. /**
  220. * gets the absolute path to the current modul
  221. *
  222. * @access private
  223. */
  224. private function getModulSelf()
  225. {
  226. if (MODE)
  227. {
  228. $this->modulSelf = $_SERVER['PHP_SELF'] . '?modul=' . $this->modul;
  229. }
  230. else
  231. {
  232. $this->modulSelf = SEO::makeAddress($this->modul);
  233. }
  234. $this->log->write(2, 'info', "Modul path: {$this->modulSelf}");
  235. }
  236. /**
  237. * gets the params passed to the current modul
  238. *
  239. * @access private
  240. */
  241. private function getModulParams()
  242. {
  243. if (MODE)
  244. {
  245. $this->modulParams = &$_GET;
  246. }
  247. else
  248. {
  249. if (isset($_GET['params']))
  250. {
  251. $paramPairs = explode(self::PAIR_DELIM, $_GET['params']);
  252. $params = array();
  253. foreach ($paramPairs as $paramsPair)
  254. {
  255. $pair = explode('-', $paramsPair);
  256. if (count($pair) > 1)
  257. {
  258. $params[$pair[0]] = rawurldecode($pair[1]);
  259. }
  260. elseif (count($pair) == 1)
  261. {
  262. $params[$pair[0]] = null;
  263. }
  264. }
  265. $this->modulParams = array_merge($this->modulParams, $params);
  266. }
  267. }
  268. $this->log->write(2, 'info', 'param count: ' . count($this->modulParams) . ', params: {' . serialize($this->modulParams) . '}');
  269. }
  270. /**
  271. * gets the querystring
  272. *
  273. * @access private
  274. */
  275. private function getModulQueryString()
  276. {
  277. if (MODE)
  278. {
  279. $params = $this->modulParams;
  280. unset($params['modul']);
  281. $this->modulQueryString = '';
  282. foreach ($params as $index => $value)
  283. {
  284. $value = trim($value);
  285. if ($value !== '')
  286. {
  287. $this->modulQueryString .= '&' . $index . '=' . $value;
  288. }
  289. }
  290. $this->modulQueryString = mb_substr($this->modulQueryString, 1);
  291. }
  292. else
  293. {
  294. $this->modulQueryString = &$_GET['params'];
  295. }
  296. $this->log->write(2, 'info', "Querystring: {$this->modulQueryString}");
  297. }
  298. /**
  299. * gets the current language
  300. *
  301. * @access private
  302. */
  303. private function getLang()
  304. {
  305. $path = 'include/' . (MODE ? 'admin' : 'contents') . '/lang/';
  306. if (
  307. isset($_GET['lang']) &&
  308. preg_match('/[a-z]{2}/si', $_GET['lang']) &&
  309. file_exists($path . $_GET['lang'])
  310. )
  311. {
  312. $this->lang = $_GET['lang'];
  313. $_SESSION['ci_lang'] = $_GET['lang'];
  314. }
  315. elseif (
  316. isset($_POST['lang']) &&
  317. preg_match('/[a-z]{2}/si', $_POST['lang']) &&
  318. file_exists($path . $_POST['lang'])
  319. )
  320. {
  321. $this->lang = $_POST['lang'];
  322. $_SESSION['ci_lang'] = $_POST['lang'];
  323. }
  324. elseif (isset($_SESSION['ci_lang']))
  325. {
  326. $this->lang = $_SESSION['ci_lang'];
  327. }
  328. else
  329. {
  330. $this->lang = $this->config->cms_std_lang;
  331. }
  332. $this->log->write(2, 'info', "Lang: {$this->lang}");
  333. }
  334. /**
  335. * gets the current design
  336. *
  337. * @access private
  338. */
  339. private function getDesign()
  340. {
  341. $path = 'include/designs/';
  342. if (isset($_GET['design']) && file_exists($path . $_GET['design']))
  343. {
  344. $this->design = $_GET['design'];
  345. $_SESSION['ci_design'] = $_GET['design'];
  346. }
  347. elseif (isset($_POST['design']) && file_exists($path . $_POST['design']))
  348. {
  349. $this->design = $_POST['design'];
  350. $_SESSION['ci_design'] = $_POST['design'];
  351. }
  352. elseif (isset($_SESSION['ci_design']))
  353. {
  354. $this->design = $_SESSION['ci_design'];
  355. }
  356. else
  357. {
  358. $this->design = $this->config->cms_std_design;
  359. }
  360. $this->log->write(2, 'info', "Design: {$this->design}");
  361. }
  362. }
  363. ?>