PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/simple-forum/sf-header-forum.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 758 lines | 566 code | 93 blank | 99 comment | 198 complexity | f5badc21594fb5450eb11ffb6e628f33 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /*
  3. Simple:Press
  4. Start Up Functions to support the forum
  5. $LastChangedDate: 2011-03-05 07:42:11 -0700 (Sat, 05 Mar 2011) $
  6. $Rev: 5631 $
  7. */
  8. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
  9. die('Access Denied');
  10. }
  11. # ------------------------------------------------------------------
  12. # sf_load_front_js()
  13. #
  14. # Enqueue's necessary javascript and inline header script
  15. # ------------------------------------------------------------------
  16. function sf_load_front_js()
  17. {
  18. global $sfvars;
  19. # set up the sfvars array
  20. sf_populate_query_vars();
  21. # determine page view type
  22. sf_setup_page_type();
  23. if(sf_get_option('sfscriptfoot') ? $footer = true : $footer = false);
  24. # Load up the javascript files
  25. wp_register_script('jquery', SFWPJSCRIPT.'jquery.js', false, false, $footer);
  26. wp_enqueue_script('jquery');
  27. if(SF_USE_PRETTY_CBOX)
  28. {
  29. wp_enqueue_script('jquery.checkboxes', SFJSCRIPT.'checkboxes/prettyCheckboxes.js', array('jquery'), false, $footer);
  30. }
  31. wp_enqueue_script('highslide', SFJSCRIPT.'highslide/highslide.js', false, false, $footer);
  32. wp_enqueue_script('sftags', SFJSCRIPT.'tags/sf-tags.js', array('jquery'), false, $footer);
  33. wp_localize_script('sftags', 'sfSettings', array('url' => SFHOMEURL));
  34. wp_enqueue_script('sfprint', SFJSCRIPT.'print/jquery.jqprint.js', array('jquery'), false, $footer);
  35. if($sfvars['pageview'] == 'topic')
  36. {
  37. wp_enqueue_script('sfcookie', SFJSCRIPT.'jquery/jcookie.js', array('jquery'), false, $footer);
  38. }
  39. # hack for pm detection since sfvars not set up yet
  40. $pmstuff = explode('/', $_SERVER['QUERY_STRING']);
  41. $pmpage = get_query_var('sf_pm');
  42. if (isset($_GET['pmaction'])) $pmoldpage = $_GET['pmaction'];
  43. if (!empty($pmpage) || !empty($pmoldpage) || (isset($pmstuff[1]) && $pmstuff[1] == 'private-messaging'))
  44. {
  45. wp_enqueue_script('sfautoc', SFJSCRIPT.'autocomplete/jquery.autocomplete.js', array('jquery'), false, $footer);
  46. wp_enqueue_script('sfsplitter', SFJSCRIPT.'jquery/splitter.js', array('jquery'), false, $footer);
  47. wp_enqueue_script('sfcookie', SFJSCRIPT.'jquery/jcookie.js', array('jquery'), false, $footer);
  48. wp_enqueue_script('sfpmjs', SFJSCRIPT.'messaging/sf-messaging.js', array('jquery'), false, $footer);
  49. }
  50. # syntax Highlighting
  51. $sfsyntax = sf_get_option('sfsyntax');
  52. if($sfsyntax['sfsyntaxforum'] == true)
  53. {
  54. wp_enqueue_script('sfsyntax', SFJSCRIPT.'syntax/jquery.syntax.js', array('jquery'), false, $footer);
  55. wp_enqueue_script('sfsyntaxcache', SFJSCRIPT.'syntax/jquery.syntax.cache.js', array('jquery'), false, $footer);
  56. }
  57. # Special case: if profile edit load uploader support
  58. if($sfvars['pageview'] == 'profileedit')
  59. {
  60. wp_enqueue_script('sfupload', SFJSCRIPT.'ajaxupload/ajaxupload.js', array('jquery'), false, $footer);
  61. wp_enqueue_script('sfform', SFWPJSCRIPT.'jquery.form.js', array('jquery'), false, $footer);
  62. }
  63. wp_enqueue_script('spf', SFJSCRIPT.'forum/sf-forum.js', array('jquery'), false, $footer);
  64. if(SF_USE_PRETTY_CBOX)
  65. {
  66. ?>
  67. <script type='text/javascript'>
  68. var pcbExclusions = new Array(
  69. <?php
  70. $exc = sf_get_option('sfcbexclusions');
  71. if($exc)
  72. {
  73. $exc = rtrim($exc, ",");
  74. $exclist = explode(",", $exc);
  75. foreach($exclist as $item)
  76. {
  77. echo '"'.trim($item).'",';
  78. }
  79. }
  80. echo '"sfcbdummy"'."\n";
  81. ?>
  82. );
  83. </script>
  84. <?php
  85. }
  86. return;
  87. }
  88. # ------------------------------------------------------------------
  89. # sf_setup_header()
  90. #
  91. # Constructs the header for the forum - Javascript and CSS
  92. # ------------------------------------------------------------------
  93. function sf_setup_header()
  94. {
  95. global $wp_query, $current_user, $wp_rewrite, $sfglobals, $sfvars, $SFSTATUS, $SFMOBILE;
  96. # The CSS is being set early in case we have to bow out quickly due to
  97. # the forum needing to be ugraded. This is to ensure that
  98. # this is the very FIRST thing to happen in the header
  99. echo '<link rel="stylesheet" type="text/css" href="' . SFSKINCSS .'" />' . "\n";
  100. if(get_bloginfo('text_direction') == 'rtl')
  101. {
  102. echo '<link rel="stylesheet" type="text/css" href="' . SFCSSRTL . '" />' . "\n";
  103. }
  104. # So - check if it needs to be upgraded...
  105. if($SFSTATUS != 'ok')
  106. {
  107. return sf_forum_unavailable();
  108. }
  109. # If page is password protected, ensure it matches before starting
  110. if (!empty($wp_query->post->post_password))
  111. {
  112. if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $wp_query->post->post_password)
  113. {
  114. return;
  115. }
  116. }
  117. while ($x = has_filter('the_content', 'wpautop'))
  118. {
  119. remove_filter('the_content', 'wpautop', $x);
  120. }
  121. remove_filter('the_content', 'convert_smilies');
  122. $value = SFSIZE;
  123. if(!empty($value))
  124. {
  125. $value=trim($value, '%');
  126. if(intval($value) != 0)
  127. {
  128. echo '<style type="text/css">';
  129. echo '#sforum {font-size: '.$value.'%; }';
  130. echo '</style>'."\n";
  131. }
  132. }
  133. # --------------------------------------------------------
  134. # now to start populatng all of the variables we need
  135. # set up the sfvars array - should be already done but no ham checking
  136. sf_populate_query_vars();
  137. # filemanager - hive off sfvars for fm to use
  138. if(($sfvars['pageview']=='profileedit' && $current_user->sfuploadsig) ||
  139. (($sfvars['pageview']=='forum' || $sfvars['pageview']=='topic') &&
  140. ($current_user->sfuploadimg || $current_user->sfuploadmedia || $current_user->sfuploadfile)));
  141. {
  142. $key = $current_user->ID.'keys';
  143. update_sfsetting($key, serialize($sfvars));
  144. }
  145. # determine page view type - - should be already done but no ham checking
  146. sf_setup_page_type();
  147. # do meta stuff
  148. sf_setup_meta_tags();
  149. # load page specific css
  150. if ($sfvars['pageview'] == 'topic')
  151. {
  152. echo '<link rel="stylesheet" type="text/css" href="'.SFPOSTCSS.'" />' . "\n";
  153. # if setting for post content width apply word-wrap
  154. if($sfvars['postwidth'] > 0)
  155. {
  156. ?>
  157. <style type="text/css">
  158. .sfpostcontent {
  159. max-width: <?php echo($sfvars['postwidth']); ?>px !important; }
  160. .sfpostcontent p, .sfpostcontent pre, .sfpostcontent blockquote, .sfpostcontent table {
  161. max-width: <?php echo($sfvars['postwidth']); ?>px !important;
  162. text-wrap: normal;
  163. word-wrap: break-word; }
  164. .sfpostcontent .sfcode table.syntax {
  165. max-width: <?php echo($sfvars['postwidth']-5); ?>px !important;
  166. text-wrap: normal;
  167. word-wrap: break-word; }
  168. .sfpostcontent .sfcode table.syntax tr.line {
  169. max-width: <?php echo($sfvars['postwidth']-2); ?>px !important;
  170. text-wrap: normal;
  171. word-wrap: break-word; }
  172. .sfpostcontent .sfcode table.syntax td.number {
  173. max-width: 15px;
  174. min-width: 15px; }
  175. .sfpostcontent .sfcode table.syntax td.source span {
  176. max-width: <?php echo($sfvars['postwidth']-18); ?>px !important;
  177. text-wrap: normal;
  178. word-wrap: break-word; }
  179. </style>
  180. <?php
  181. }
  182. }
  183. if ($sfvars['pageview'] == 'pm')
  184. echo '<link rel="stylesheet" type="text/css" href="'.SFPMCSS.'" />' . "\n";
  185. if ($sfvars['pageview'] == 'profileedit' || $sfvars['pageview'] == 'profileshow')
  186. echo '<link rel="stylesheet" type="text/css" href="'.SFPROFILECSS.'" />' . "\n";
  187. # --------------------------------------------------------
  188. # Set up the rest of the header info
  189. ?>
  190. <link rel="stylesheet" type="text/css" href="<?php echo(SFADMINCSS); ?>highslide/highslide.css" />
  191. <?php
  192. # load HTML or bbCode editor if required. TinyMCE can be loaded in footer
  193. if(strpos("forum topic pm profileedit", $sfvars['pageview']) !== false)
  194. {
  195. if ($SFMOBILE)
  196. {
  197. $sfglobals['editor']['sfeditor'] == PLAIN;
  198. } else {
  199. switch($sfglobals['editor']['sfeditor'])
  200. {
  201. case HTML:
  202. include_once(SFEDITORDIR."html/sf-htmlinit.php");
  203. break;
  204. case BBCODE:
  205. include_once(SFEDITORDIR."bbcode/sf-bbcodeinit.php");
  206. break;
  207. }
  208. }
  209. }
  210. }
  211. # ------------------------------------------------------------------
  212. # sf_setup_footer()
  213. #
  214. # Constructs the footer for the forum - Javascript
  215. # ------------------------------------------------------------------
  216. function sf_setup_footer()
  217. {
  218. global $sfvars, $sfglobals, $current_user, $SFMOBILE;
  219. # wait for page load and run JS inits
  220. ?>
  221. <script type="text/javascript">
  222. var jspf = jQuery.noConflict();
  223. jspf(document).ready(function() {
  224. <?php
  225. # Checkboxes/radio buttons
  226. if(SF_USE_PRETTY_CBOX) { ?>
  227. jspf("input[type=checkbox],input[type=radio]").prettyCheckboxes();
  228. <?php } ?>
  229. <?php
  230. # syntax Highlighting - optional maybe and may need loading outside of SP
  231. $sfsyntax = sf_get_option('sfsyntax');
  232. if($sfsyntax['sfsyntaxforum'] == true) { ?>
  233. Syntax.root = "<?php echo SFJSCRIPT.'syntax/'; ?>";
  234. jspf.syntax({layout: 'table', replace: true});
  235. <?php } ?>
  236. <?php
  237. # Sets cookies with content and paragraph widths
  238. $docookie = true;
  239. $sfpostwrap = array();
  240. $sfpostwrap = sf_get_option('sfpostwrap');
  241. if($sfpostwrap['postwrap'] == false) $docookie = false;
  242. if($sfvars['postwidth'] > 0) $docookie = false;
  243. if($sfvars['displaymode'] == 'edit') $docookie = false;
  244. if($sfvars['pageview'] != 'topic') $docookie = false;
  245. if($current_user->forumadmin == false) $docookie = false;
  246. if($docookie) { ?>
  247. var c = jspf(".sfpostcontent").width();
  248. var p = jspf(".sfpostcontent p").width();
  249. if(c && p) {
  250. jspf.cookie('c_width', c, { path: '/' });
  251. jspf.cookie('p_width', p, { path: '/' });
  252. }
  253. <?php } ?>
  254. <?php
  255. # set up Highslide...
  256. ?>
  257. hs.graphicsDir = "<?php echo(SFJSCRIPT); ?>highslide/support/";
  258. hs.outlineType = "rounded-white";
  259. hs.outlineWhileAnimating = true;
  260. hs.cacheAjax = false;
  261. hs.showCredits = false;
  262. hs.lang = {
  263. cssDirection : '<?php bloginfo('text_direction'); ?>',
  264. closeText : '',
  265. closeTitle : '<?php echo esc_js(__("Close", "sforum")); ?>',
  266. moveText : '',
  267. moveTitle : '<?php echo esc_js(__("Move", "sforum")); ?>',
  268. loadingText : '<?php echo esc_js(__("Loading", "sforum")); ?>'
  269. };
  270. /* pre-load wait image */
  271. waitImage = new Image(27,27);
  272. waitImage.src = '<?php echo(SFRESOURCES."wait.png"); ?>';
  273. <?php
  274. # turn on auto update of required
  275. $sfauto=array();
  276. $sfauto=sf_get_option('sfauto');
  277. if($sfauto['sfautoupdate']) {
  278. $timer = ($sfauto['sfautotime'] * 1000);
  279. $url = SFHOMEURL."index.php?sf_ahah=autoupdate";
  280. ?>
  281. sfjAutoUpdate("<?php echo($url); ?>", "<?php echo($timer); ?>");
  282. <?php } ?>
  283. });
  284. </script>
  285. <?php
  286. # load editor if required
  287. if(strpos("forum topic pm profileedit", $sfvars['pageview']) !== false)
  288. {
  289. if ($SFMOBILE)
  290. {
  291. $sfglobals['editor']['sfeditor'] == PLAIN;
  292. } else {
  293. switch($sfglobals['editor']['sfeditor'])
  294. {
  295. case RICHTEXT:
  296. include_once(SFEDITORDIR."tinymce/sf-tinyinit.php");
  297. break;
  298. }
  299. }
  300. }
  301. }
  302. # ------------------------------------------------------------------
  303. # sf_populate_query_vars()
  304. #
  305. # Populate the forum query variables from the URL
  306. # ------------------------------------------------------------------
  307. function sf_populate_query_vars()
  308. {
  309. global $sfvars, $sfglobals, $wp_rewrite;
  310. if ($sfglobals['queryvarsdone'] == true) return;
  311. # load query vars
  312. $sfglobals['queryvarsdone'] = true;
  313. $sfvars['error'] = false;
  314. $sfvars['forumid'] = 0;
  315. $sfvars['topicid'] = 0;
  316. # Special var for post content width if being used
  317. $sfvars['postwidth'] = 0;
  318. $sfpostwrap = array();
  319. $sfpostwrap = sf_get_option('sfpostwrap');
  320. if($sfpostwrap['postwrap'])
  321. {
  322. $sfvars['postwidth'] = $sfpostwrap['postwidth'];
  323. # if not set then try and get from cookie
  324. if($sfvars['postwidth'] == false)
  325. {
  326. if(isset($_COOKIE["p_width"]) && isset($_COOKIE["c_width"]))
  327. {
  328. $c_width = $_COOKIE["c_width"];
  329. $p_width = $_COOKIE["p_width"];
  330. if($p_width > $c_width ? $w = ($c_width-80) : $w = $p_width);
  331. $sfpostwrap['postwidth'] = $w;
  332. sf_update_option('sfpostwrap', $sfpostwrap);
  333. $sfvars['postwidth'] = $w;
  334. }
  335. }
  336. }
  337. # We can check to see if the url is a pre V3 url
  338. # this checks for numeric value. Fine as long as
  339. # someone doesn't name their forum with simply a number!
  340. if((isset($_GET['forum'])) && (is_numeric($_GET['forum'])))
  341. {
  342. # suggests an old url
  343. $sfvars['forumslug'] = sf_get_forum_slug(sf_esc_int($_GET['forum']));
  344. if(isset($_GET['topic'])) $sfvars['topicslug'] = sf_get_topic_slug(sf_esc_int($_GET['topic']));
  345. sf_populate_support_vars();
  346. return;
  347. }
  348. # if V3 link and user has permalinks
  349. if($wp_rewrite->using_permalinks())
  350. {
  351. # post V3 permalinks
  352. # using permalinks so get the values from the query vars
  353. $sfvars['forumslug'] = sf_esc_str(get_query_var('sf_forum'));
  354. if(empty($sfvars['forumslug']) && isset($_GET['search']))
  355. {
  356. $sfvars['forumslug']=sf_esc_str($_GET['forum']);
  357. }
  358. $sfvars['topicslug'] = sf_esc_str(get_query_var('sf_topic'));
  359. $sfvars['profile'] = sf_esc_str(get_query_var('sf_profile'));
  360. $sfvars['member'] = sf_esc_str(get_query_var('sf_member'));
  361. $sfvars['list'] = sf_esc_str(get_query_var('sf_list'));
  362. $sfvars['policy'] = sf_esc_str(get_query_var('sf_policy'));
  363. $sfvars['newposts'] = sf_esc_str(get_query_var('sf_newposts'));
  364. $sfvars['pm'] = sf_esc_str(get_query_var('sf_pm'));
  365. $sfvars['box'] = sf_esc_str(get_query_var('sf_box'));
  366. if (get_query_var('sf_page') != '')
  367. {
  368. $sfvars['page'] = sf_esc_int(get_query_var('sf_page'));
  369. }
  370. sf_populate_support_vars();
  371. return;
  372. } else {
  373. # post V3 but using default
  374. # Not using permalinks so we need to parse the query string from the url and do it ourselves
  375. $stuff=array();
  376. $stuff=explode('/', $_SERVER['QUERY_STRING']);
  377. # deal with non-standard cases first
  378. if (isset($_GET['search']))
  379. {
  380. sf_build_search_vars($stuff);
  381. } else {
  382. sf_build_standard_vars($stuff);
  383. }
  384. sf_populate_support_vars();
  385. if(empty($sfvars['forumid'])) $sfvars['forumid']=0;
  386. if(empty($sfvars['topicid'])) $sfvars['topicid']=0;
  387. if(empty($sfvars['profile'])) $sfvars['profile']=0;
  388. if(empty($sfvars['member'])) $sfvars['member']=0;
  389. if(empty($sfvars['list'])) $sfvars['list']=0;
  390. if(empty($sfvars['policy'])) $sfvars['policy']=0;
  391. if(empty($sfvars['newposts'])) $sfvars['newposts']=0;
  392. if(empty($sfvars['pm'])) $sfvars['pm']=0;
  393. if(empty($sfvars['box'])) $sfvars['box']=0;
  394. return;
  395. }
  396. }
  397. # ------------------------------------------------------------------
  398. # sf_populate_support_vars()
  399. #
  400. # Query Variables support routine
  401. # ------------------------------------------------------------------
  402. function sf_populate_support_vars()
  403. {
  404. global $sfvars;
  405. # Populate the rest of sfvars
  406. if(empty($sfvars['page']))
  407. {
  408. $sfvars['page'] = 1;
  409. }
  410. if(!empty($sfvars['forumslug']) && $sfvars['forumslug'] != 'all')
  411. {
  412. $record = sf_get_forum_record_from_slug($sfvars['forumslug']);
  413. $sfvars['forumid'] = $record->forum_id;
  414. if(empty($sfvars['forumid'])) $sfvars['forumid']=0;
  415. $sfvars['forumname'] = $record->forum_name;
  416. # Is it a subforum?
  417. $forumparent = $record->parent;
  418. while($forumparent > 0)
  419. {
  420. $parent = sf_get_forum_record($forumparent);
  421. $sfvars['parentforumid'][] = $forumparent;
  422. $sfvars['parentforumslug'][] = $parent->forum_slug;
  423. $sfvars['parentforumname'][] = $parent->forum_name;
  424. $forumparent = $parent->parent;
  425. }
  426. }
  427. if(!empty($sfvars['topicslug']))
  428. {
  429. $record = sf_get_topic_record_from_slug($sfvars['topicslug']);
  430. $sfvars['topicid'] = $record->topic_id;
  431. if(empty($sfvars['topicid'])) $sfvars['topicid']=0;
  432. $sfvars['topicname'] = $record->topic_name;
  433. }
  434. # Add Search Vars
  435. if(isset($_GET['search']))
  436. {
  437. if($_GET['search'] != '') $sfvars['searchpage'] = intval($_GET['search']);
  438. $sfvars['searchpage'] = sf_esc_int($sfvars['searchpage']);
  439. if(isset($_GET['type']) ? $sfvars['searchtype'] = intval($_GET['type']) : $sfvars['searchtype'] = 1);
  440. $sfvars['searchtype'] = sf_esc_int($sfvars['searchtype']);
  441. if($sfvars['searchtype'] == 0 || empty($sfvars['searchtype'])) $sfvars['searchtype'] =1;
  442. if(isset($_GET['include']) ? $sfvars['searchinclude'] = intval($_GET['include']) : $sfvars['searchinclude'] = 1);
  443. $sfvars['searchinclude'] = sf_esc_int($sfvars['searchinclude']);
  444. if($sfvars['searchinclude'] == 0 || empty($sfvars['searchinclude'])) $sfvars['searchinclude'] =1;
  445. if(isset($_GET['value']) ? $sfvars['searchvalue'] = sf_filter_save_nohtml(urldecode($_GET['value'])) : $sfvars['searchvalue'] = '');
  446. # if 'type' 6,8,9 then value must be integer
  447. if($sfvars['searchtype'] > 5 && isset($_GET['value']))
  448. {
  449. $sfvars['searchvalue'] = sf_esc_int(intval($sfvars['searchvalue']));
  450. } else {
  451. $sfvars['searchvalue'] = stripslashes($sfvars['searchvalue']);
  452. }
  453. $sfvars['searchvalue'] = sf_filter_table_prefix($sfvars['searchvalue']);
  454. if(empty($sfvars['searchvalue']))
  455. {
  456. $sfvars['searchpage'] = 0;
  457. $sfvars['searchtype'] = 0;
  458. $sfvars['searchinclude'] = 0;
  459. update_sfnotice('sfmessage', '1@'.__("Invalid Search Query", "sforum"));
  460. }
  461. } else {
  462. $sfvars['searchpage'] = 0;
  463. }
  464. $sfvars['searchresults']=0;
  465. return;
  466. }
  467. # ------------------------------------------------------------------
  468. # sf_build_search_vars()
  469. #
  470. # Query Variables support routine
  471. # ------------------------------------------------------------------
  472. function sf_build_search_vars($stuff)
  473. {
  474. global $sfvars;
  475. if(isset($_GET['forum']))
  476. {
  477. # means searching all
  478. $sfvars['forumslug'] = sf_esc_str($_GET['forum']);
  479. } else {
  480. # searching single forum
  481. if(!empty($stuff[1]))
  482. {
  483. $sfvars['forumslug'] = $stuff[1];
  484. }
  485. # (2) topic
  486. if(!empty($stuff[2]))
  487. {
  488. $parts = explode("&", $stuff[2]);
  489. $sfvars['topicslug'] = $parts[0];
  490. }
  491. }
  492. return;
  493. }
  494. # ------------------------------------------------------------------
  495. # sf_build_standard_vars()
  496. #
  497. # Query Variables support routine
  498. # ------------------------------------------------------------------
  499. function sf_build_standard_vars($stuff)
  500. {
  501. global $sfvars, $current_user;
  502. # (1) forum first
  503. if(!empty($stuff[1]))
  504. {
  505. if ($stuff[1] == 'profile')
  506. {
  507. if ($stuff[2] == 'permissions' || $stuff[2] == 'buddies') {
  508. $sfvars['profile'] = sf_esc_str($stuff[2]);
  509. } else {
  510. if (empty($stuff[2]))
  511. {
  512. $sfvars['member'] = urlencode($current_user->login_name);
  513. $sfvars['profile'] = 'edit';
  514. } else if (empty ($stuff[3])) {
  515. $sfvars['member'] = sf_esc_str($stuff[2]);
  516. $sfvars['profile'] = 'show';
  517. } else {
  518. $sfvars['member'] = sf_esc_str($stuff[2]);
  519. $sfvars['profile'] = 'edit';
  520. }
  521. }
  522. } else if ($stuff[1] == 'members') {
  523. $sfvars['list'] = 'members';
  524. if (preg_match("/page-(\d+)/", $stuff[2], $matches))
  525. {
  526. $sfvars['page'] = intval($matches[1]);
  527. }
  528. } else if ($stuff[1] == 'newposts') {
  529. $sfvars['newposts'] = 'all';
  530. } else if ($stuff[1] == 'policy') {
  531. $sfvars['policy'] = 'show';
  532. } else if ($stuff[1] == 'private-messaging') {
  533. if ($stuff[2] == 'send')
  534. {
  535. $sfvars['pm'] = $stuff[2];
  536. $sfvars['box'] = 'inbox';
  537. $sfvars['member'] = $stuff[3];
  538. } else {
  539. $sfvars['box'] = $stuff[2];
  540. $sfvars['pm'] = $stuff[2];
  541. }
  542. } else {
  543. $substuff = explode('&', $stuff[1]);
  544. $sfvars['forumslug'] = $substuff[0];
  545. # (2) topic or page?
  546. if(!empty($stuff[2]))
  547. {
  548. $matches = array();
  549. if(preg_match("/page-(\d+)/", $stuff[2], $matches))
  550. {
  551. $sfvars['page'] = intval($matches[1]);
  552. } else {
  553. $substuff = explode('&', $stuff[2]);
  554. $sfvars['topicslug'] = $substuff[0];
  555. }
  556. }
  557. # (3) if here must be page
  558. if(!empty($stuff[3]))
  559. {
  560. if(preg_match("/page-(\d+)/", $stuff[3], $matches))
  561. {
  562. $sfvars['page'] = intval($matches[1]);
  563. }
  564. }
  565. }
  566. }
  567. return;
  568. }
  569. function sf_setup_page_type()
  570. {
  571. global $sfvars, $sfglobals, $current_user, $CACHE;
  572. if (isset($sfglobals['pagetypedone']) && $sfglobals['pagetypedone'] == true) return;
  573. $sfglobals['pagetypedone'] = true;
  574. sf_initialise_globals($sfvars['forumid']);
  575. # Maybe a profile edit or first time logged in?
  576. # If user has made no posts yet optionaly load the profile form
  577. $pageview = '';
  578. $sfvars['newuser'] = false;
  579. if ($current_user->member)
  580. {
  581. if ($sfglobals['member']['posts'] == -1 || empty($current_user->user_email))
  582. {
  583. # Add to new user list
  584. sf_push_newuser($current_user->ID, $current_user->display_name);
  585. sf_update_member_item($current_user->ID, 'posts', 0);
  586. $sfprofile = sf_get_option('sfprofile');
  587. if ($sfprofile['firstvisit'] || empty($current_user->user_email))
  588. {
  589. $sfprofile = sf_get_option('sfprofile');
  590. $sfvars['newuser'] = $sfprofile['firstvisit'];
  591. $sfvars['member'] = urlencode($current_user->login_name);
  592. $pageview = 'profileedit';
  593. $sfvars['forumslug'] = '';
  594. $sfvars['topicslug'] = '';
  595. }
  596. }
  597. }
  598. if ($pageview == '')
  599. {
  600. if (!empty($sfvars['forumslug'])) {
  601. $pageview = 'forum';
  602. } else if (!empty($sfvars['profile'])) {
  603. if ($sfvars['profile'] == 'edit') $pageview = 'profileedit';
  604. if ($sfvars['profile'] == 'show') $pageview = 'profileshow';
  605. if ($sfvars['profile'] == 'permissions') $pageview = 'permissions';
  606. if ($sfvars['profile'] == 'buddies') $pageview = 'buddies';
  607. } else if (!empty($sfvars['newposts'])) {
  608. $pageview = 'newposts';
  609. } else if (!empty($sfvars['list'])) {
  610. $pageview = 'list';
  611. } else if (!empty($sfvars['policy'])) {
  612. $pageview = 'policy';
  613. } else if (!empty($sfvars['pm'])) {
  614. $pageview = 'pm';
  615. } else {
  616. $pageview = 'group';
  617. # Check if single forum only is on
  618. if (isset($sfglobals['display']['forums']['singleforum']) && $sfglobals['display']['forums']['singleforum'])
  619. {
  620. $fid = sf_single_forum_user();
  621. if ($fid)
  622. {
  623. $cforum = sf_get_forum_record($fid);
  624. $sfvars['forumid'] = $fid;
  625. $sfvars['forumslug'] = $cforum->forum_slug;
  626. $sfvars['forumname'] = $cforum->forum_name;
  627. $CACHE = '';
  628. sf_initialise_globals($sfvars['forumid']);
  629. $pageview = 'forum';
  630. }
  631. }
  632. }
  633. if (!empty($sfvars['topicslug'])) $pageview = 'topic';
  634. }
  635. $sfvars['pageview'] = $pageview;
  636. }
  637. function sf_setup_meta_tags()
  638. {
  639. global $sfglobals;
  640. if (empty($sfglobals['metadescription']))
  641. {
  642. $description = sfc_get_metadescription();
  643. if ($description != '')
  644. {
  645. $description = str_replace('"', '', $description);
  646. echo '<meta name="description" content="'.$description.'" />'."\n";
  647. }
  648. }
  649. if (empty($sfglobals['metakeywords']))
  650. {
  651. $keywords = sfc_get_metakeywords();
  652. if ($keywords != '')
  653. {
  654. $keywords = str_replace('"', '', $keywords);
  655. echo '<meta name="keywords" content="'.$keywords.'" />'."\n";
  656. }
  657. }
  658. if (empty($sfglobals['canonicalurl']))
  659. {
  660. # output the canonical url
  661. $url = sf_canonical_url();
  662. echo '<link rel="canonical" href="'.$url.'" />'."\n";
  663. }
  664. }
  665. ?>