PageRenderTime 69ms CodeModel.GetById 42ms RepoModel.GetById 0ms app.codeStats 0ms

/index.php

https://bitbucket.org/mpercy/deeemm-cms
PHP | 457 lines | 201 code | 89 blank | 167 comment | 47 complexity | ef2b51a520519836a1d40f84394ea062 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*[Info]=====================================================================
  3. index.php
  4. Original File Created on 24/12/04 20:15 by Mick Percy
  5. DMCMS is an open source Content Management System (CMS) provided free for use
  6. under the GNU General Public License.
  7. ==[Support]=====================================================================
  8. Support for DMCMS is provided via the following channels:
  9. The DeeEmm forum at http://www.deeemm.com/forum
  10. The DeeEmm wiki at http://www.deeemm.com/wiki
  11. The DMCMS support tracker hosted at the DMCMS SourceForge project page at
  12. http://sourceforge.net/projects/dmcms/
  13. ==[Bug Tracking / Feature Requests]=============================================
  14. Please report all bugs using the tracker which can be found at
  15. http://sourceforge.net/tracker/?group_id=189064
  16. ==[Copyright]===================================================================
  17. DMCMS (Also known as DeeEmm CMS), and all constituent files including
  18. this file are copyright (C) 2007 Mick Percy. All rights reserved.
  19. ==[License]=====================================================================
  20. This file is part of DMCMS (Also known as DeeEmm CMS).
  21. DMCMS is free software; you can redistribute it and/or modify it under
  22. the terms of the GNU General Public License as published by the Free
  23. Software Foundation; either version 2 of the License, or (at your option)
  24. any later version.
  25. DMCMS is distributed in the hope that it will be useful, but WITHOUT ANY
  26. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  27. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  28. details.
  29. You should have received a copy of the GNU General Public License along
  30. with DMCMS; if not, write to the Free Software Foundation, Inc.,
  31. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA or alternatively
  32. you can visit http://www.gnu.org/copyleft/gpl.html
  33. ==[Changelog]===================================================================
  34. Please refer to README.TXT for the changelog
  35. ==[Installation]================================================================
  36. Please refer to README.TXT for installation instructions
  37. ==============================================================================*/
  38. /*===========================================================================
  39. Start the stopwatch
  40. ===========================================================================*/
  41. $start_time = explode( ' ', microtime() );
  42. $start_time = $start_time[1] + $start_time[0];
  43. /*===========================================================================
  44. Start session
  45. ===========================================================================*/
  46. ob_start();
  47. session_start();
  48. define('_INDM', TRUE);
  49. /*===========================================================================
  50. Get required files
  51. ===========================================================================*/
  52. require 'config.php';
  53. require $abs_path . $core_dir . 'definitions.php';
  54. require $abs_path . $core_dir . 'initialisations.php';
  55. require $abs_path . $core_dir . 'functions.php';
  56. require $abs_path . $core_dir . 'db_access.php';
  57. require $abs_path . $core_dir . 'structure.php';
  58. require $abs_path . $core_dir . 'variables.php';
  59. require $abs_path . $core_dir . 'language.php';
  60. require $abs_path . $core_dir . 'plugins.php';
  61. require $abs_path . $includes_dir . 'static_content.php';
  62. //Get tempalate files
  63. $templates_dir .= $conf[current_template] . '/';
  64. require $abs_path . $templates_dir . 'template_config.php';
  65. require $abs_path . $templates_dir . 'template_actions.php';
  66. /*===========================================================================
  67. Get navigation string query from browser
  68. ===========================================================================*/
  69. $page = anti_inject(htmlspecialchars($_GET["page"], ENT_QUOTES));
  70. $child = anti_inject(htmlspecialchars($_GET["child"], ENT_QUOTES));
  71. $category = anti_inject(htmlspecialchars($_GET["category"], ENT_QUOTES));
  72. $id = anti_inject(htmlspecialchars($_GET["id"], ENT_QUOTES));
  73. $search_text = anti_inject(htmlspecialchars($_GET["search"], ENT_QUOTES));
  74. $action = anti_inject(htmlspecialchars($_GET["action"], ENT_QUOTES));
  75. $popmess = anti_inject(htmlspecialchars($_GET["popmess"], ENT_QUOTES));
  76. $popban = anti_inject(htmlspecialchars($_GET["popban"], ENT_QUOTES));
  77. /*===========================================================================
  78. Check $id only contains numbers
  79. ===========================================================================*/
  80. if (preg_match_all("/[^0-9]/", $id, $matches)){
  81. echo 'Possible Hack Attempt';
  82. exit;
  83. }
  84. /*===========================================================================
  85. Check $page only contains valid characters
  86. ===========================================================================*/
  87. if (preg_match_all("/[^ _A-Za-z0-9]/", $page, $matches)){
  88. echo 'Possible Hack Attempt';
  89. exit;
  90. }
  91. /*===========================================================================
  92. Process any messages
  93. ===========================================================================*/
  94. if ($popban) {
  95. $popban = $lan[$popban];
  96. $javascript_onload .= 'popup_banner();';
  97. }
  98. if ($popmess) {
  99. $popdiv = $lan[$popmess];
  100. $javascript_onload .= 'popup_div();$("#popup_divClose").click(function(){disablePopup();});';
  101. }
  102. /*===========================================================================
  103. Check user priviledges
  104. ===========================================================================*/
  105. require VALIDATE;
  106. /*===========================================================================
  107. If user is admin - show admin navbar
  108. ===========================================================================*/
  109. if ($user == 'ADMIN') {
  110. $admin_navbar = read_file($default_url . $admin_dir . "templates/admin_navbar.tpl");
  111. $admin_navbar = replace_variables($admin_navbar);
  112. }
  113. /*===========================================================================
  114. If maintenance mode send maintenance page to browser
  115. [TODO] make maintenance page a 'static page' so it can be edited
  116. ===========================================================================*/
  117. if ($conf[site_is_active] !== 'on' && $user !== 'ADMIN' && $page !== 'login') {
  118. $page = 'maintenance';
  119. $page_title .= $cookie_trial_seperator . $lan[maintenance];
  120. }
  121. /*===========================================================================
  122. Set the page title + cookie trial
  123. ===========================================================================*/
  124. if ($page !== 'login' && $page !== 'maintenance') {
  125. $cookie_trial = '<a href="' . $default_url . 'index.php?page=sitemap">[ ' . $lan[sitemap] . ' ]</a>' . $cookie_trial_seperator . '<a href="' . $default_url . '">' . $conf[site_name] . '</A>';
  126. $page_title = $cookie_trial_seperator . ucfirst($page);
  127. if ($page !== 'orphan' && $page !== '') {
  128. $cookie_trial .= $cookie_trial_seperator . '<a href = "' . $default_url . 'index.php?page=' . $page . '&id=1">' . ucfirst($page) . '</a>';
  129. }
  130. } else {
  131. $cookie_trial = "<A class='navmenulinks' href='$default_url"."index.php?page=login' title='Log In'>[ Log In ]</A>";
  132. }
  133. /*===========================================================================
  134. If no page set get page ranked highest by order (i.e. index / home page)
  135. NOTE this acts as a catch all - could be modified for custom 404
  136. ===========================================================================*/
  137. if ($page == '' || !isset($page)) {
  138. unset($action);
  139. $sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . "core_structure` WHERE `order`=(select min(`order`) FROM `" . $db_table_prefix . "core_structure`)");
  140. while($sql_result = mysql_fetch_array($sql_query)) {
  141. $page = $sql_result[table];
  142. }
  143. $sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . 'cat_' . $page . "` WHERE `order`=(select min(`order`) FROM `" . $db_table_prefix . "core_structure`)");
  144. while($sql_result = mysql_fetch_array($sql_query)) {
  145. $id = $sql_result[id];
  146. }
  147. }
  148. /*===========================================================================
  149. Set page metadata
  150. [TODO] Get metadata from database and add to metadata vars
  151. ===========================================================================*/
  152. $meta_title = $page_title;
  153. $meta_description = $meta_description;
  154. $meta_keywords = $meta_keywords;
  155. $meta_description = $meta_description;
  156. /*===========================================================================
  157. Get standard page header
  158. ===========================================================================*/
  159. $header = read_file($default_url . $templates_dir . "header.tpl");
  160. /*===========================================================================
  161. Get standard page banner
  162. ===========================================================================*/
  163. $banner = read_file($default_url . $templates_dir . "banner.tpl");
  164. /*===========================================================================
  165. If site active or user is admin get content
  166. ===========================================================================*/
  167. if ($conf[site_is_active] || $user == 'ADMIN') {
  168. //[FIXME] Columns only for current template - need to make layout dynamic
  169. //get left and right columns
  170. $left_column = read_file($default_url . $templates_dir . "left_column.tpl");
  171. $right_column = read_file($default_url . $templates_dir . "right_column.tpl");
  172. //if search enabled add searchbox
  173. if ($conf[search_enabled]) {
  174. $content = $default_url . $templates_dir . "searchbox.tpl";
  175. $searchbox = read_file($content);
  176. $searchbox = replace_variables($searchbox);
  177. } else {
  178. $searchbox = '';
  179. }
  180. //[FIXME]change this to a plugin
  181. //select random list item(s)
  182. if (count($newsbox_libraries) > 0) {
  183. include $includes_dir . 'build_newsbox_content.php';
  184. }
  185. //[FIXME]change this to a plugin
  186. //select random media library picture(s)
  187. if (count($imagebox_libraries) > 0) {
  188. include $includes_dir . 'build_imagebox_content.php';
  189. }
  190. //[FIXME]change multilanguage to dynamic
  191. //if enabled create multi language navigation box
  192. if ($conf[multi_language]) {
  193. $multi_language_nav = read_file($default_url . $templates_dir . "multi_language_nav.tpl");
  194. $multi_language_nav = replace_variables($multi_language_nav);
  195. } else {
  196. $multi_language_nav = '';
  197. }
  198. if ($conf[login_link_enabled]) {
  199. $login_link = "<A class='navmenulinks' href='$default_url"."index.php?page=login' title='Log In'>Log In</A>";
  200. } else {
  201. $login_link = '';
  202. }
  203. }
  204. /*===========================================================================
  205. USER functions
  206. ===========================================================================*/
  207. //check if active user
  208. if ($user=='USER' || $user=='ADMIN'){
  209. switch ($action) {
  210. //[TODO] Add user handling
  211. // //edit / save profile
  212. // case 'edit_profile';
  213. // case 'save_profile';
  214. // require $includes_dir . 'edit_profile.php';
  215. // break;
  216. }
  217. }
  218. /*===========================================================================
  219. Build navigation menu
  220. ===========================================================================*/
  221. if ($conf[site_is_active] == 'on' || $user == 'ADMIN') {
  222. include $includes_dir . 'build_navigation.php';
  223. }
  224. /*===========================================================================
  225. Perform search if search string present
  226. ===========================================================================*/
  227. if (strlen($search_text) > 0){
  228. include $includes_dir . 'perform_site_search.php';
  229. $page = 'search';
  230. }
  231. /*===========================================================================
  232. Generate page from navigation query result
  233. ===========================================================================*/
  234. switch ($page) {
  235. //add cases here where you do not want any action to be carried out
  236. //otherwise case '$page' will pick up all not specified
  237. case 'messagebox';
  238. $main = read_file($default_url . $templates_dir . "message_box.tpl");
  239. $admin_href = $empty_media_page_admin_href;
  240. break;
  241. case 'maintenance';
  242. $main = read_file($default_url . $templates_dir . "maintenance.tpl");
  243. break;
  244. case 'user';
  245. break;
  246. case 'search';
  247. $main = read_file($default_url . $templates_dir . "search.tpl");
  248. break;
  249. //rss2 feed create
  250. case 'rss2';
  251. case 'rss1';
  252. case 'atom';
  253. include $includes_dir . 'build_rss_feed.php';
  254. exit;
  255. break;
  256. //display sitemap content
  257. case 'sitemap';
  258. include $includes_dir . 'build_sitemap.php';
  259. break;
  260. //check login / display login form
  261. case 'login';
  262. include $includes_dir . 'login.php';
  263. break;
  264. //check logout / cancel session
  265. case 'logout';
  266. setcookie ("deeemm", "", time() - 3600);
  267. header("Location: " . $default_url . "index.php");
  268. exit;
  269. exit;
  270. //build pages based on type
  271. case $page :
  272. if ($page == 'orphan') $type = 'orphan';
  273. if (!$id || $id == 'id') { //fix for strange bug where $id becomes id!!?!
  274. $sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . 'cat_' . $page . "` WHERE `order`=(select min(`order`) FROM `" . $db_table_prefix . "core_structure`)");
  275. while($sql_result = mysql_fetch_array($sql_query)) {
  276. $id = $sql_result[id];
  277. }
  278. }
  279. //get page type from database
  280. $sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . "core_structure` WHERE `table` = '$page'");
  281. while($sql_result = mysql_fetch_array($sql_query)) {
  282. $type = $sql_result[type];
  283. }
  284. //process page type
  285. switch ($type) {
  286. //build normal / home pages
  287. case 'normal' :
  288. case 'orphan' :
  289. include $includes_dir . 'build_normal_content.php';
  290. break;
  291. //build news / list / blog type page
  292. case 'list' :
  293. case 'list + newsbox' :
  294. include $includes_dir . 'build_list_content.php';
  295. break;
  296. //build media pages
  297. case 'media' :
  298. include $includes_dir . 'build_media_content.php';
  299. break;
  300. //build forum
  301. case 'forum' :
  302. //include $includes_dir . 'build_normal_content.php';
  303. break;
  304. //if no other cases match
  305. default :
  306. // include $includes_dir . 'build_normal_content.php';
  307. break;
  308. }
  309. }
  310. /*===========================================================================
  311. Build standard page footer
  312. ===========================================================================*/
  313. $footer = read_file($default_url . $templates_dir ."footer.tpl");
  314. /*===========================================================================
  315. Construct the page
  316. template elements need to be generated automatically!!
  317. ===========================================================================*/
  318. $template_elements = array(
  319. "header" => $header,
  320. "banner" => $banner,
  321. "main" => $main,
  322. "left_column" => $left_column,
  323. "right_column" => $right_column,
  324. "footer" => $footer
  325. );
  326. $page_html = construct($template_elements);
  327. /*===========================================================================
  328. Replace template markers with variables
  329. ===========================================================================*/
  330. $page_html = replace_variables($page_html);
  331. $page_html = replace_dm_code($page_html);
  332. $page_html = replace_language($page_html);
  333. /*===========================================================================
  334. Stop the stopwatch
  335. ===========================================================================*/
  336. $end_time = explode( ' ', microtime() );
  337. $end_time = $end_time[1] + $end_time[0];
  338. $page_timer = $end_time-$start_time;
  339. /*===========================================================================
  340. Display testmode stuff
  341. ===========================================================================*/
  342. $test_mode = FALSE;
  343. if ($test_mode == TRUE && $user == 'ADMIN'){
  344. //display page timer
  345. echo 'Benchmark - Page generated in ' . $page_timer .' seconds<hr>';
  346. }
  347. /*===========================================================================
  348. Send page to browser
  349. ===========================================================================*/
  350. echo $page_html;
  351. /*===========================================================================
  352. Tidy up
  353. ===========================================================================*/
  354. mysql_close($db_connection);
  355. ob_end_flush();
  356. ?>