PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/campsite/src/include/phorum/common.php

https://github.com/joechrysler/Campsite
PHP | 835 lines | 595 code | 117 blank | 123 comment | 179 complexity | 42f58ba7a9dc68677a78a79d72e7112e MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // Copyright (C) 2006 Phorum Development Team //
  5. // http://www.phorum.org //
  6. // //
  7. // This program is free software. You can redistribute it and/or modify //
  8. // it under the terms of either the current Phorum License (viewable at //
  9. // phorum.org) or the Phorum License that was distributed with this file //
  10. // //
  11. // This program is distributed in the hope that it will be useful, //
  12. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  14. // //
  15. // You should have received a copy of the Phorum License //
  16. // along with this program. //
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Check that this file is not loaded directly.
  19. if ( basename( __FILE__ ) == basename( $_SERVER["PHP_SELF"] ) ) exit();
  20. // all other constants in ./include/constants.php
  21. define( "PHORUM", "5.1-dev" );
  22. // our internal version in format of year-month-day-serial
  23. define( "PHORUMINTERNAL", "2006032300" );
  24. define( "DEBUG", 0 );
  25. include_once( "./include/constants.php" );
  26. // setup the PHORUM var
  27. $PHORUM = array();
  28. // temp member to hold arrays and such in templates
  29. $PHORUM["TMP"] = array();
  30. // The data member is the data the templates can access
  31. $PHORUM["DATA"] = array();
  32. $PHORUM["DATA"]["GET_VARS"] = array();
  33. $PHORUM["DATA"]["POST_VARS"] = "";
  34. // get the forum id if set with a post
  35. if ( isset( $_REQUEST["forum_id"] ) && is_numeric( $_REQUEST["forum_id"] ) ) {
  36. $PHORUM["forum_id"] = $_REQUEST["forum_id"];
  37. }
  38. // strip the slashes off of POST data if magic_quotes is on
  39. if ( get_magic_quotes_gpc() && count( $_REQUEST ) ) {
  40. foreach( $_POST as $key => $value ) {
  41. if ( !is_array( $value ) )
  42. $_POST[$key] = stripslashes( $value );
  43. else
  44. $_POST[$key] = phorum_recursive_stripslashes( $value );
  45. }
  46. foreach( $_GET as $key => $value ) {
  47. if ( !is_array( $value ) )
  48. $_GET[$key] = stripslashes( $value );
  49. else
  50. $_GET[$key] = phorum_recursive_stripslashes( $value );
  51. }
  52. }
  53. // look for and parse the QUERY_STRING
  54. // this only applies to urls that we create.
  55. // scrips using urls from forms (search) should use $_GET or $_POST
  56. if ( !defined( "PHORUM_ADMIN" ) ) {
  57. if ( isset( $_SERVER["QUERY_STRING"] ) || isset( $PHORUM["CUSTOM_QUERY_STRING"] ) ) {
  58. $Q_STR = empty( $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"] ) ? $_SERVER["QUERY_STRING"]: $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"];
  59. // ignore stuff past a #
  60. if ( strstr( $Q_STR, "#" ) ) list( $Q_STR, $other ) = explode( "#", $Q_STR );
  61. // explode it on comma
  62. $PHORUM["args"] = explode( ",", $Q_STR );
  63. // check for any assigned values
  64. if ( strstr( $Q_STR, "=" ) ) {
  65. foreach( $PHORUM["args"] as $key => $arg ) {
  66. // if an arg has an = create an element in args
  67. // with left part as key and right part as value
  68. if ( strstr( $arg, "=" ) ) {
  69. list( $var, $value ) = explode( "=", $arg );
  70. $PHORUM["args"][$var] = urldecode( $value );
  71. // get rid of the numbered arg, it is useless.
  72. unset( $PHORUM["args"][$key] );
  73. }
  74. }
  75. }
  76. // set forum_id if not set already by
  77. if ( empty( $PHORUM["forum_id"] ) && isset( $PHORUM["args"][0] ) ) {
  78. $PHORUM["forum_id"] = ( int )$PHORUM["args"][0];
  79. }
  80. }
  81. }
  82. // set the forum_id to 0 if not set by now.
  83. if ( empty( $PHORUM["forum_id"] ) ) $PHORUM["forum_id"] = 0;
  84. // Get the database settings.
  85. if ( empty( $GLOBALS["PHORUM_ALT_DBCONFIG"] ) || $GLOBALS["PHORUM_ALT_DBCONFIG"]==$_REQUEST["PHORUM_ALT_DBCONFIG"] || !defined("PHORUM_WRAPPER") ) {
  86. // Backup display_errors setting.
  87. $orig = ini_get("display_errors");
  88. ini_set("display_errors", 0);
  89. // Load configuration.
  90. if (! include_once( "./include/db/config.php" )) {
  91. print '<html><head><title>Phorum error</title></head><body>';
  92. print '<h2>Phorum database configuration error</h2>';
  93. // No database configuration found.
  94. if (!file_exists("./include/db/config.php")) { ?>
  95. Phorum has been installed on this server, but the configuration<br/>
  96. for the database connection has not yet been made. Please read<br/>
  97. <a href="docs/install.txt">docs/install.txt</a> for installation instructions. <?php
  98. } else {
  99. $fp = fopen("./include/db/config.php", "r");
  100. // Unable to read the configuration file.
  101. if (!$fp) { ?>
  102. A database configuration file was found in ./include/db/config.php,<br/>
  103. but Phorum was unable to read it. Please check the file permissions<br/>
  104. for this file. <?php
  105. // Unknown error.
  106. } else {
  107. fclose($fp); ?>
  108. A database configuration file was found in ./include/dbconfig.php,<br/>
  109. but it could not be loaded. It possibly contains one or more errors.<br/>
  110. Please check your configuration file. <?php
  111. }
  112. }
  113. print '</body></html>';
  114. exit(1);
  115. }
  116. // Restore original display_errors setting.
  117. ini_set("display_errors", $orig);
  118. } else {
  119. $PHORUM["DBCONFIG"] = $GLOBALS["PHORUM_ALT_DBCONFIG"];
  120. }
  121. // Load the database layer.
  122. include_once( "./include/db/{$PHORUM['DBCONFIG']['type']}.php" );
  123. if(!phorum_db_check_connection()){
  124. if(isset($PHORUM["DBCONFIG"]["down_page"])){
  125. header("Location: ".$PHORUM["DBCONFIG"]["down_page"]);
  126. exit();
  127. } else {
  128. echo "The database connection failed. Please check your database configuration in include/db/config.php. If the configuration is okay, check if the database server is running.";
  129. exit();
  130. }
  131. }
  132. // get the Phorum settings
  133. phorum_db_load_settings();
  134. // a hook for rewriting vars at the beginning of common.php,
  135. //right after loading the settings from the database
  136. phorum_hook( "common_pre", "" );
  137. include_once( "./include/cache.php" );
  138. // stick some stuff from the settings into the DATA member
  139. $PHORUM["DATA"]["TITLE"] = ( isset( $PHORUM["title"] ) ) ? $PHORUM["title"] : "";
  140. $PHORUM["DATA"]["HTML_TITLE"] = ( !empty( $PHORUM["html_title"] ) ) ? $PHORUM["html_title"] : $PHORUM["DATA"]["TITLE"];
  141. $PHORUM["DATA"]["HEAD_TAGS"] = ( isset( $PHORUM["head_tags"] ) ) ? $PHORUM["head_tags"] : "";
  142. $PHORUM["DATA"]["FORUM_ID"] = $PHORUM["forum_id"];
  143. ////////////////////////////////////////////////////////////
  144. // only do this stuff if we are not in the admin
  145. if ( !defined( "PHORUM_ADMIN" ) ) {
  146. // if the Phorum is disabled, display a message.
  147. if(isset($PHORUM["status"]) && $PHORUM["status"]=="disabled"){
  148. if(!empty($PHORUM["disabled_url"])){
  149. header("Location: ".$PHORUM["disabled_url"]);
  150. exit();
  151. } else {
  152. echo "This Phorum is currently disabled. Please contact the web site owner at ".$PHORUM['system_email_from_address']." for more information.\n";
  153. exit();
  154. }
  155. }
  156. // checking for upgrade or new install
  157. if ( !isset( $PHORUM['internal_version'] ) ) {
  158. echo "<html><head><title>Phorum error</title></head><body>No Phorum settings were found. Either this is a brand new installation of Phorum or there is an error with your database server. If this is a new install, please <a href=\"admin.php\">go to the admin page</a> to complete the installation. If not, check your database server.</body></html>";
  159. exit();
  160. } elseif ( $PHORUM['internal_version'] < PHORUMINTERNAL ) {
  161. echo "<html><head><title>Error</title></head><body>Looks like you have installed a new version. Go to the admin to complete the upgrade!</body></html>";
  162. exit();
  163. }
  164. // load the forum's settings
  165. if ( !empty( $PHORUM["forum_id"] ) ) {
  166. $forum_settings = phorum_db_get_forums( $PHORUM["forum_id"] );
  167. if ( empty( $forum_settings[$PHORUM["forum_id"]] ) ) {
  168. phorum_hook( "common_no_forum", "" );
  169. phorum_redirect_by_url( phorum_get_url( PHORUM_INDEX_URL ) );
  170. exit();
  171. }
  172. $PHORUM = array_merge( $PHORUM, $forum_settings[$PHORUM["forum_id"]] );
  173. } else {
  174. // some defaults we might need if no forum is set (i.e. on the index-page)
  175. $PHORUM['vroot']=0;
  176. $PHORUM['parent_id']=0;
  177. $PHORUM['active']=1;
  178. $PHORUM['folder_flag']=1;
  179. }
  180. // stick some stuff from the settings into the DATA member
  181. $PHORUM["DATA"]["NAME"] = ( isset( $PHORUM["name"] ) ) ? $PHORUM["name"] : "";
  182. $PHORUM["DATA"]["DESCRIPTION"] = ( isset( $PHORUM["description"] ) ) ? $PHORUM["description"] : "";
  183. $PHORUM["DATA"]["ENABLE_PM"] = ( isset( $PHORUM["enable_pm"] ) ) ? $PHORUM["enable_pm"] : "";
  184. if ( !empty( $PHORUM["DATA"]["HTML_TITLE"] ) && !empty( $PHORUM["DATA"]["NAME"] ) ) {
  185. $PHORUM["DATA"]["HTML_TITLE"] .= PHORUM_SEPARATOR;
  186. }
  187. $PHORUM["DATA"]["HTML_TITLE"] .= $PHORUM["DATA"]["NAME"];
  188. // check the user session
  189. include_once( "./include/users.php" );
  190. if ( phorum_user_check_session() ) {
  191. $PHORUM["DATA"]["LOGGEDIN"] = true;
  192. if(!$PHORUM["tight_security"] || phorum_user_check_session( PHORUM_SESSION_SHORT_TERM )){
  193. $PHORUM["DATA"]["FULLY_LOGGEDIN"] = true;
  194. } else {
  195. $PHORUM["DATA"]["FULLY_LOGGEDIN"] = false;
  196. }
  197. // Let the templates know whether we have new private messages.
  198. $PHORUM["DATA"]["NEW_PRIVATE_MESSAGES"] = 0;
  199. if ( $PHORUM["enable_pm"] && isset($PHORUM["user"]["new_private_messages"]) ) {
  200. $PHORUM["DATA"]["NEW_PRIVATE_MESSAGES"] = $PHORUM["user"]["new_private_messages"];
  201. }
  202. $PHORUM["DATA"]["notice_messages"] = false;
  203. $PHORUM["DATA"]["notice_users"] = false;
  204. $PHORUM["DATA"]["notice_groups"] = false;
  205. // if moderator notifications are on and the person is a mod, lets find out if anything is new
  206. if ( $PHORUM["enable_moderator_notifications"] ) {
  207. $forummodlist = phorum_user_access_list( PHORUM_USER_ALLOW_MODERATE_MESSAGES );
  208. if ( count( $forummodlist ) > 0 ) {
  209. $PHORUM["DATA"]["notice_messages"] = ( count( phorum_db_get_unapproved_list( $forummodlist, true ) ) > 0 );
  210. $PHORUM["DATA"]["notice_messages_url"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_UNAPPROVED );
  211. }
  212. if ( phorum_user_access_allowed( PHORUM_USER_ALLOW_MODERATE_USERS ) ) {
  213. $PHORUM["DATA"]["notice_users"] = ( count( phorum_db_user_get_unapproved() ) > 0 );
  214. $PHORUM["DATA"]["notice_users_url"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_USERS );
  215. }
  216. if ( phorum_user_allow_moderate_group() ) {
  217. $groups = phorum_user_get_moderator_groups();
  218. if ( count( $groups ) > 0 ) {
  219. $PHORUM["DATA"]["notice_groups"] = count( phorum_db_get_group_members( array_keys( $groups ), PHORUM_USER_GROUP_UNAPPROVED ) );
  220. $PHORUM["DATA"]["notice_groups_url"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_GROUP_MODERATION );
  221. }
  222. }
  223. }
  224. $PHORUM["DATA"]["notice_all"] = ( $PHORUM["enable_pm"] && phorum_page!="pm" && $PHORUM["DATA"]["NEW_PRIVATE_MESSAGES"] ) || $PHORUM["DATA"]["notice_messages"] || $PHORUM["DATA"]["notice_users"] || $PHORUM["DATA"]["notice_groups"];
  225. // if the user has overridden thread settings, change it here.
  226. if ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) {
  227. if ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_ON ) {
  228. $PHORUM["threaded_list"] = true;
  229. } elseif ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_OFF ) {
  230. $PHORUM["threaded_list"] = false;
  231. }
  232. if ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_ON ) {
  233. $PHORUM["threaded_read"] = true;
  234. } elseif ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_OFF ) {
  235. $PHORUM["threaded_read"] = false;
  236. }
  237. }
  238. }
  239. // set up the blank user if not logged in
  240. if ( empty( $PHORUM["user"] ) ) {
  241. $PHORUM["user"] = array( "user_id" => 0, "username" => "", "admin" => false, "newinfo" => array() );
  242. $PHORUM["DATA"]["LOGGEDIN"] = false;
  243. }
  244. // a hook for rewriting vars in common.php after loading the user
  245. phorum_hook( "common_post_user", "" );
  246. // set up the template
  247. // check for a template being passed on the url
  248. // only use valid template names
  249. if ( !empty( $PHORUM["args"]["template"] ) ) {
  250. $template = basename( $PHORUM["args"]["template"] );
  251. if ($template != '..') {
  252. $PHORUM["template"] = $template;
  253. }
  254. }
  255. // user output buffering so we don't get header errors
  256. // not loaded if we are running an external or scheduled script
  257. if (! defined('PHORUM_SCRIPT')) {
  258. ob_start();
  259. include_once( phorum_get_template( "settings" ) );
  260. ob_end_clean();
  261. }
  262. // get the language file
  263. if ( ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) && isset( $PHORUM['user']['user_language'] ) && !empty($PHORUM['user']['user_language']) )
  264. $PHORUM['language'] = $PHORUM['user']['user_language'];
  265. if ( !isset( $PHORUM["language"] ) || empty( $PHORUM["language"] ) || !file_exists( "./include/lang/$PHORUM[language].php" ) )
  266. $PHORUM["language"] = $PHORUM["default_language"];
  267. if ( file_exists( "./include/lang/$PHORUM[language].php" ) ) {
  268. include_once( "./include/lang/$PHORUM[language].php" );
  269. }
  270. // load languages for localized modules
  271. if ( isset( $PHORUM["hooks"]["lang"] ) && is_array($PHORUM["hooks"]["lang"]) ) {
  272. foreach( $PHORUM["hooks"]["lang"]["mods"] as $mod ) {
  273. // load mods for this hook
  274. if ( file_exists( "./mods/$mod/lang/$PHORUM[language].php" ) ) {
  275. include_once "./mods/$mod/lang/$PHORUM[language].php";
  276. }
  277. elseif ( file_exists( "./mods/$mod/lang/english.php" ) ) {
  278. include_once "./mods/$mod/lang/english.php";
  279. }
  280. }
  281. }
  282. // HTML titles can't contain HTML code, so we strip HTML tags
  283. // and HTML escape the title.
  284. $PHORUM["DATA"]["HTML_TITLE"] = htmlentities(strip_tags($PHORUM["DATA"]["HTML_TITLE"]), ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
  285. // if the Phorum is disabled, display a message.
  286. if(isset($PHORUM["status"]) && $PHORUM["status"]=="admin-only" && !$PHORUM["user"]["admin"]){
  287. // set all our URL's
  288. phorum_build_common_urls();
  289. $PHORUM["DATA"]["MESSAGE"]=$PHORUM["DATA"]["LANG"]["AdminOnlyMessage"];
  290. include phorum_get_template("header");
  291. phorum_hook("after_header");
  292. include phorum_get_template("message");
  293. phorum_hook("before_footer");
  294. include phorum_get_template("footer");
  295. exit();
  296. }
  297. // a hook for rewriting vars at the end of common.php
  298. phorum_hook( "common", "" );
  299. $PHORUM['DATA']['USERINFO'] = $PHORUM['user'];
  300. $PHORUM['DATA']['PHORUM_PAGE'] = phorum_page;
  301. $PHORUM['DATA']['USERTRACK'] = $PHORUM['track_user_activity'];
  302. }
  303. //////////////////////////////////////////////////////////
  304. // functions
  305. /**
  306. * A common function to check that a user is logged in
  307. */
  308. function phorum_require_login()
  309. {
  310. $PHORUM = $GLOBALS['PHORUM'];
  311. if ( !$PHORUM["user"]["user_id"] ) {
  312. $url = phorum_get_url( PHORUM_LOGIN_URL, "redir=" . urlencode( $PHORUM["http_path"] . "/" . basename( $_SERVER["PHP_SELF"] ) . "?" . $_SERVER["QUERY_STRING"] ) );
  313. phorum_redirect_by_url( $url );
  314. exit();
  315. }
  316. }
  317. /**
  318. * A common function for checking the read-permissions for a forum-page
  319. * returns false if access is not allowed and an error page-was output
  320. */
  321. function phorum_check_read_common()
  322. {
  323. $PHORUM = $GLOBALS['PHORUM'];
  324. $retval = true;
  325. if ( $PHORUM["forum_id"] > 0 && !$PHORUM["folder_flag"] && !phorum_user_access_allowed( PHORUM_USER_ALLOW_READ ) ) {
  326. if ( $PHORUM["DATA"]["LOGGEDIN"] ) {
  327. // if they are logged in and not allowed, they don't have rights
  328. $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["NoRead"];
  329. } else {
  330. // check if they could read if logged in.
  331. // if so, let them know to log in.
  332. if ( ( empty( $PHORUM["DATA"]["POST"]["parentid"] ) && $PHORUM["reg_perms"] &PHORUM_USER_ALLOW_READ ) ) {
  333. $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["PleaseLoginRead"];
  334. } else {
  335. $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["NoRead"];
  336. }
  337. }
  338. phorum_build_common_urls();
  339. include phorum_get_template( "header" );
  340. phorum_hook( "after_header" );
  341. include phorum_get_template( "message" );
  342. phorum_hook( "before_footer" );
  343. include phorum_get_template( "footer" );
  344. $retval = false;
  345. }
  346. return $retval;
  347. }
  348. // used for all url creation.
  349. function phorum_get_url()
  350. {
  351. $PHORUM = $GLOBALS["PHORUM"];
  352. $args = "";
  353. $url = "";
  354. $suffix = "";
  355. $add_forum_id = false;
  356. $add_get_vars = true;
  357. $argv = func_get_args();
  358. $type = array_shift( $argv );
  359. switch ( $type ) {
  360. case PHORUM_LIST_URL:
  361. $page = "list";
  362. if ( empty( $argv ) ) $add_forum_id = true;
  363. break;
  364. case PHORUM_READ_URL:
  365. $page = "read";
  366. $add_forum_id = true;
  367. if ( !empty( $argv[1] ) && is_numeric( $argv[1] ) ) $suffix = "#msg-$argv[1]";
  368. break;
  369. case PHORUM_FOREIGN_READ_URL:
  370. $page = "read";
  371. if ( !empty( $argv[2] ) && is_numeric( $argv[2] ) ) $suffix = "#msg-$argv[2]";
  372. break;
  373. case PHORUM_REPLY_URL:
  374. if(isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]){
  375. $page = "read";
  376. $suffix = "#REPLY";
  377. } else {
  378. $page = "posting";
  379. // For reply on a separate page, we call posting.php on its own.
  380. // In that case argv[0] is the editor mode we want to use
  381. // (reply in this case). Currently, the thread id is in argv[0],
  382. // but we don't need that one for posting.php. So we simply
  383. // replace argv[0] with the correct argument.
  384. $argv[0] = "reply";
  385. }
  386. $add_forum_id = true;
  387. break;
  388. case PHORUM_POSTING_URL:
  389. $page = "posting";
  390. $add_forum_id = true;
  391. break;
  392. case PHORUM_REDIRECT_URL:
  393. $page = "redirect";
  394. $add_forum_id = false;
  395. break;
  396. case PHORUM_SEARCH_URL:
  397. $page = "search";
  398. $add_forum_id = true;
  399. break;
  400. case PHORUM_SEARCH_ACTION_URL:
  401. $page = "search";
  402. $add_get_vars = true;
  403. break;
  404. case PHORUM_DOWN_URL:
  405. $page = "down";
  406. $add_forum_id = true;
  407. break;
  408. case PHORUM_VIOLATION_URL:
  409. $page = "violation";
  410. $add_forum_id = true;
  411. break;
  412. case PHORUM_INDEX_URL:
  413. $page = "index";
  414. break;
  415. case PHORUM_LOGIN_URL:
  416. $page = "login";
  417. $add_forum_id = true;
  418. break;
  419. case PHORUM_LOGIN_ACTION_URL:
  420. $page = "login";
  421. break;
  422. case PHORUM_REGISTER_URL:
  423. $page = "register";
  424. $add_forum_id = true;
  425. break;
  426. case PHORUM_REGISTER_ACTION_URL:
  427. $page = "register";
  428. break;
  429. case PHORUM_PROFILE_URL:
  430. $page = "profile";
  431. $add_forum_id = true;
  432. break;
  433. case PHORUM_SUBSCRIBE_URL:
  434. $page = "subscribe";
  435. $add_forum_id = true;
  436. break;
  437. case PHORUM_MODERATION_URL:
  438. $page = "moderation";
  439. $add_forum_id = true;
  440. break;
  441. case PHORUM_MODERATION_ACTION_URL:
  442. $page = "moderation";
  443. $add_get_vars = false;
  444. break;
  445. case PHORUM_PREPOST_URL:
  446. $page = "control";
  447. $argv[] = "panel=messages";
  448. $add_forum_id = true;
  449. break;
  450. case PHORUM_CONTROLCENTER_URL:
  451. $page = "control";
  452. $add_forum_id = true;
  453. break;
  454. case PHORUM_CONTROLCENTER_ACTION_URL:
  455. $page = "control";
  456. break;
  457. case PHORUM_PM_URL:
  458. $page = "pm";
  459. $add_forum_id = true;
  460. break;
  461. case PHORUM_PM_ACTION_URL:
  462. $page = "pm";
  463. break;
  464. case PHORUM_FILE_URL:
  465. $page = "file";
  466. $add_forum_id = true;
  467. break;
  468. case PHORUM_FOLLOW_URL:
  469. $page = "follow";
  470. $add_forum_id = true;
  471. break;
  472. case PHORUM_FOLLOW_ACTION_URL:
  473. $page = "follow";
  474. $add_forum_id = false;
  475. break;
  476. case PHORUM_REPORT_URL:
  477. $page = "report";
  478. $add_forum_id = true;
  479. break;
  480. case PHORUM_RSS_URL:
  481. switch(phorum_page){
  482. case "list":
  483. $add_forum_id = true;
  484. break;
  485. case "read":
  486. $add_forum_id = true;
  487. array_push($argv, $PHORUM["args"]["1"]);
  488. break;
  489. }
  490. $page = "rss";
  491. break;
  492. // this is for adding own generic urls
  493. case PHORUM_CUSTOM_URL:
  494. $page = array_shift($argv); // first arg is our page
  495. $add_forum_id_tmp=array_shift($argv); // second determining if we should add the forum_id
  496. $add_forum_id = $add_forum_id_tmp?true:false;
  497. break;
  498. case PHORUM_BASE_URL:
  499. // only to flag phorum_custom_get_url() that base url is requested
  500. $page = '';
  501. break;
  502. default:
  503. trigger_error( "Unhandled page type.", E_USER_WARNING );
  504. break;
  505. }
  506. // build the query string
  507. $query_items = array();
  508. if ( $add_forum_id ) {
  509. $query_items[] = ( int )$PHORUM["forum_id"];
  510. }
  511. if ( count( $argv ) > 0 ) {
  512. $query_items = array_merge( $query_items, $argv );
  513. }
  514. if ( !empty( $PHORUM["DATA"]["GET_VARS"] ) && $add_get_vars ) {
  515. $query_items = array_merge( $query_items, $PHORUM["DATA"]["GET_VARS"] );
  516. }
  517. // build the url
  518. if ( !function_exists( "phorum_custom_get_url" ) ) {
  519. if ($type == PHORUM_BASE_URL) return $PHORUM["http_path"] . '/';
  520. $url = "$PHORUM[http_path]/$page." . PHORUM_FILE_EXTENSION;
  521. if ( count( $query_items ) ) $url .= "?" . implode( ",", $query_items );
  522. if ( !empty( $suffix ) ) $url .= $suffix;
  523. } else {
  524. $url = phorum_custom_get_url( $page, $query_items, $suffix );
  525. }
  526. return $url;
  527. }
  528. // retrieve the appropriate template file name
  529. function phorum_get_template( $page, $is_include = false )
  530. {
  531. $PHORUM = $GLOBALS["PHORUM"];
  532. if ( ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) && isset( $PHORUM['user']['user_template'] ) && !empty($PHORUM['user']['user_template'])) {
  533. $PHORUM['template'] = $PHORUM['user']['user_template'];
  534. }
  535. // If no user template is set or if the template folder cannot be found,
  536. // fallback to the default template.
  537. if (empty($PHORUM["template"]) || !file_exists("./templates/{$PHORUM['template']}")) {
  538. $PHORUM["template"] = $PHORUM["default_template"];
  539. }
  540. $tpl = "./templates/$PHORUM[template]/$page";
  541. // check for straight PHP file
  542. if ( file_exists( "$tpl.php" ) ) {
  543. $phpfile = "$tpl.php";
  544. } else {
  545. // not there, look for a template
  546. $tplfile = "$tpl.tpl";
  547. $safetemplate = str_replace("-", "_", $PHORUM["template"]);
  548. $safepage = str_replace("-", "_", $page);
  549. $phpfile = "$PHORUM[cache]/tpl-$safetemplate-$safepage-" .
  550. ($is_include ? "include" : "toplevel") . "-" .
  551. md5( dirname( __FILE__ ) ) . ".php";
  552. if ( $is_include || !file_exists( $phpfile ) ) {
  553. include_once "./include/templates.php";
  554. phorum_import_template( $tplfile, $phpfile );
  555. }
  556. }
  557. return $phpfile;
  558. }
  559. // creates URLs used on most pages
  560. function phorum_build_common_urls()
  561. {
  562. $PHORUM=$GLOBALS['PHORUM'];
  563. // those links are only needed in forums, not in folders
  564. if(isset($PHORUM['folder_flag']) && !$PHORUM['folder_flag']) {
  565. $GLOBALS["PHORUM"]["DATA"]["URL"]["TOP"] = phorum_get_url( PHORUM_LIST_URL );
  566. $GLOBALS["PHORUM"]["DATA"]["URL"]["MARKREAD"] = phorum_get_url( PHORUM_LIST_URL, "markread=1" );
  567. $GLOBALS["PHORUM"]["DATA"]["URL"]["POST"] = phorum_get_url( PHORUM_POSTING_URL );
  568. $GLOBALS["PHORUM"]["DATA"]["URL"]["SUBSCRIBE"] = phorum_get_url( PHORUM_SUBSCRIBE_URL );
  569. }
  570. // those are general urls, needed nearly everywhere
  571. $GLOBALS["PHORUM"]["DATA"]["URL"]["SEARCH"] = phorum_get_url( PHORUM_SEARCH_URL );
  572. // RSS-Url only makes sense on a couple of pages
  573. if(isset($PHORUM['use_rss']) && $PHORUM['use_rss']
  574. && (phorum_page=="index" || phorum_page=="list" || phorum_page=="read")){
  575. $GLOBALS["PHORUM"]["DATA"]["URL"]["RSS"] = phorum_get_url( PHORUM_RSS_URL );
  576. }
  577. $index_id=-1;
  578. // in a folder
  579. if( $PHORUM['folder_flag'] && phorum_page != 'index'
  580. && ($PHORUM['forum_id'] == 0 || $PHORUM['vroot'] == $PHORUM['forum_id'])) {
  581. // folder where we usually don't show the index-link but on
  582. // additional pages like search and login its shown
  583. $index_id=$PHORUM['forum_id'];
  584. } elseif( ( $PHORUM['folder_flag'] &&
  585. ($PHORUM['forum_id'] != 0 && $PHORUM['vroot'] != $PHORUM['forum_id'])) ||
  586. (!$PHORUM['folder_flag'] && $PHORUM['active'])) {
  587. // either a folder where the link should be shown (not vroot or root)
  588. // or an active forum where the link should be shown
  589. if(isset($PHORUM["use_new_folder_style"]) && $PHORUM["use_new_folder_style"] ) {
  590. // go to root or vroot
  591. $index_id=$PHORUM["vroot"]; // vroot is either 0 (root) or another id
  592. } else {
  593. // go to parent
  594. $index_id=$PHORUM["parent_id"]; // parent_id is always set now
  595. }
  596. }
  597. if($index_id > -1) {
  598. // check if its the full root, avoid adding an id in this case (SE-optimized ;))
  599. if (!empty($index_id))
  600. $GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_get_url( PHORUM_INDEX_URL, $index_id );
  601. else
  602. $GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_get_url( PHORUM_INDEX_URL );
  603. }
  604. // these urls depend on the login-status of a user
  605. if ( $GLOBALS["PHORUM"]["DATA"]["LOGGEDIN"] ) {
  606. $GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_get_url( PHORUM_LOGIN_URL, "logout=1" );
  607. $GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_get_url( PHORUM_CONTROLCENTER_URL );
  608. $GLOBALS["PHORUM"]["DATA"]["URL"]["PM"] = phorum_get_url( PHORUM_PM_URL );
  609. } else {
  610. $GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_get_url( PHORUM_LOGIN_URL );
  611. $GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_get_url( PHORUM_REGISTER_URL );
  612. }
  613. }
  614. // calls phorum mod functions
  615. function phorum_hook( $hook, $arg = "" )
  616. {
  617. $PHORUM = $GLOBALS["PHORUM"];
  618. if ( isset( $PHORUM["hooks"][$hook] ) && is_array($PHORUM["hooks"][$hook])) {
  619. foreach( $PHORUM["hooks"][$hook]["mods"] as $mod ) {
  620. // load mods for this hook
  621. if ( file_exists( "./mods/$mod/$mod.php" ) ) {
  622. include_once "./mods/$mod/$mod.php";
  623. } elseif ( file_exists( "./mods/$mod.php" ) ) {
  624. include_once "./mods/$mod.php";
  625. }
  626. }
  627. foreach( $PHORUM["hooks"][$hook]["funcs"] as $func ) {
  628. // call functions for this hook
  629. if ( function_exists( $func ) ) {
  630. $arg = call_user_func( $func, $arg );
  631. }
  632. }
  633. }
  634. return $arg;
  635. }
  636. // HTML encodes a string
  637. function phorum_html_encode( $string )
  638. {
  639. $ret_string = "";
  640. $len = strlen( $string );
  641. for( $x = 0;$x < $len;$x++ ) {
  642. $ord = ord( $string[$x] );
  643. $ret_string .= "&#$ord;";
  644. }
  645. return $ret_string;
  646. }
  647. // removes slashes from all array-entries
  648. function phorum_recursive_stripslashes( $array )
  649. {
  650. if ( !is_array( $array ) ) {
  651. return $array;
  652. } else {
  653. foreach( $array as $key => $value ) {
  654. if ( !is_array( $value ) )
  655. $array[$key] = stripslashes( $value );
  656. else
  657. $array[$key] = phorum_recursive_stripslashes( $value );
  658. }
  659. }
  660. return $array;
  661. }
  662. // returns the available templates as an array
  663. function phorum_get_template_info()
  664. {
  665. $tpls = array();
  666. $d = dir( "./templates" );
  667. while ( false !== ( $entry = $d->read() ) ) {
  668. if ( $entry != "." && $entry != ".." && file_exists( "./templates/$entry/info.php" ) ) {
  669. include "./templates/$entry/info.php";
  670. if ( !isset( $template_hide ) || empty( $template_hide ) || defined( "PHORUM_ADMIN" ) ) {
  671. $tpls[$entry] = "$name $version";
  672. } else {
  673. unset( $template_hide );
  674. }
  675. }
  676. }
  677. return $tpls;
  678. }
  679. // returns the available languages as an array
  680. function phorum_get_language_info()
  681. {
  682. $langs = array();
  683. $d = dir( "./include/lang" );
  684. while ( false !== ( $entry = $d->read() ) ) {
  685. if ( substr( $entry, -4 ) == ".php" && is_file( "./include/lang/$entry" ) ) {
  686. @include "./include/lang/$entry";
  687. if ( !isset( $language_hide ) || empty( $language_hide ) || defined( "PHORUM_ADMIN" ) ) {
  688. $langs[str_replace( ".php", "", $entry )] = $language;
  689. } else {
  690. unset( $language_hide );
  691. }
  692. }
  693. }
  694. return $langs;
  695. }
  696. function phorum_redirect_by_url( $redir_url )
  697. {
  698. if ( stristr( $_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS" ) ) {
  699. // the ugly IIS-hack to avoid crashing IIS
  700. print "<html><head>\n<title>Redirecting ...</title>\n";
  701. print "<meta http-equiv=\"refresh\" content=\"0; URL=$redir_url\">";
  702. print "</head>\n";
  703. print "<body><a href=\"$redir_url\">Redirecting ...</a></body>\n";
  704. print "</html>";
  705. } else {
  706. // our standard-way
  707. header( "Location: $redir_url" );
  708. }
  709. exit(0);
  710. }
  711. // might remove these, might not. Need it for debugging.
  712. function print_var( $var )
  713. {
  714. echo "<xmp>";
  715. print_r( $var );
  716. echo "</xmp>";
  717. }
  718. ?>