PageRenderTime 98ms CodeModel.GetById 27ms RepoModel.GetById 10ms app.codeStats 1ms

/wp-content/plugins/simple-forum/library/sf-support.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 1738 lines | 1158 code | 192 blank | 388 comment | 356 complexity | be105db9ecf2e81b0e50233f2d23b8d3 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Simple:Press
  4. Support Routines
  5. $LastChangedDate: 2011-04-28 20:08:44 -0700 (Thu, 28 Apr 2011) $
  6. $Rev: 5994 $
  7. */
  8. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
  9. die('Access Denied');
  10. }
  11. # ******************************************************************
  12. # USER TRACKING AND USER NEW POST LIST MANAGEMENT
  13. # ******************************************************************
  14. # ------------------------------------------------------------------
  15. # sf_track_online()
  16. #
  17. # Tracks online users. Creates their new-post-list when they first
  18. # appear through to saving their last visit date when they go again
  19. # (either logout or time out - 15 minutes)
  20. # ------------------------------------------------------------------
  21. function sf_track_online()
  22. {
  23. global $wpdb, $current_user, $sfvars;
  24. $lastvisit = 0;
  25. if($current_user->member)
  26. {
  27. # it's a member
  28. $trackuserid = $current_user->ID;
  29. $trackname = $current_user->user_login;
  30. $wpdb->query("DELETE FROM ".SFTRACK." WHERE trackname='".$_SERVER['REMOTE_ADDR']."'");
  31. } elseif(!empty($current_user->guestname)) {
  32. # it's a returning guest
  33. $trackuserid=0;
  34. $trackname = $current_user->guestname.$_SERVER['REMOTE_ADDR'];
  35. } else {
  36. # Unklnown guest
  37. $trackuserid=0;
  38. $trackname = $_SERVER['REMOTE_ADDR'];
  39. }
  40. # Update tracking
  41. $id=$wpdb->get_var("SELECT id FROM ".SFTRACK." WHERE trackname='".$trackname."'");
  42. $now = current_time('mysql');
  43. # Set up forum/topic values for tracking
  44. switch($sfvars['pageview'])
  45. {
  46. case 'forum':
  47. $forumid = $sfvars['forumid'];
  48. $topicid = "0";
  49. break;
  50. case 'topic':
  51. $forumid = $sfvars['forumid'];
  52. $topicid = $sfvars['topicid'];
  53. break;
  54. default:
  55. $forumid = "0";
  56. $topicid = "0";
  57. break;
  58. }
  59. if($id)
  60. {
  61. # they are still here
  62. $wpdb->query(
  63. "UPDATE ".SFTRACK."
  64. SET trackdate='".$now."',
  65. forum_id=".$forumid.",
  66. topic_id=".$topicid."
  67. WHERE id=".$id
  68. );
  69. } else {
  70. # newly arrived
  71. $wpdb->query(
  72. "INSERT INTO ".SFTRACK."
  73. (trackuserid, trackname, forum_id, topic_id, trackdate)
  74. VALUES (
  75. ".$trackuserid.",
  76. '".$trackname."',
  77. ".$forumid.",
  78. ".$topicid.",
  79. '".$now."')
  80. ");
  81. if($current_user->member)
  82. {
  83. sf_construct_users_newposts();
  84. }
  85. }
  86. # Check for expired tracking - so may have left the scene
  87. $expired=$wpdb->get_results("SELECT * FROM ".SFTRACK." WHERE trackdate < DATE_SUB('".$now."', INTERVAL 20 MINUTE)");
  88. if($expired)
  89. {
  90. # if any Members expired - update user meta
  91. foreach($expired as $expire)
  92. {
  93. if($expire->trackuserid > 0)
  94. {
  95. sf_set_last_visited($expire->trackuserid);
  96. sf_destroy_users_newposts($expire->trackuserid);
  97. }
  98. }
  99. # finally delete them
  100. $wpdb->query("DELETE FROM ".SFTRACK." WHERE trackdate < DATE_SUB('".$now."', INTERVAL 20 MINUTE)");
  101. }
  102. return;
  103. }
  104. # ------------------------------------------------------------------
  105. # sf_construct_users_newposts()
  106. #
  107. # Constructs the new users personalised new/unread posts list when
  108. # they first appear on the system and creates the timestamp for
  109. # their creation
  110. #
  111. # $nosave if called from a tempate tag and this is true
  112. # do NOT save checktime
  113. # ------------------------------------------------------------------
  114. function sf_construct_users_newposts($nosave = false)
  115. {
  116. global $wpdb, $current_user, $sfglobals;
  117. $newpostlist=array();
  118. $newpostlist['topics']=array();
  119. $newpostlist['forums']=array();
  120. # NOTE: Use $sfglobals['member']['lastvisit'] as this holds te correct timezone date/time
  121. $records=$wpdb->get_results("SELECT DISTINCT topic_id, forum_id FROM ".SFPOSTS." WHERE post_status = 0 AND post_date > '".$sfglobals['member']['lastvisit']."' AND user_id != ".$current_user->ID." ORDER BY topic_id DESC LIMIT 50;", ARRAY_A);
  122. if($records)
  123. {
  124. foreach($records as $record)
  125. {
  126. $newpostlist['topics'][]=$record['topic_id'];
  127. $newpostlist['forums'][]=$record['forum_id'];
  128. }
  129. }
  130. $newpostlist = sf_add_waiting_post_list($newpostlist);
  131. if(count($newpostlist['topics'])==0) $newpostlist['topics'][0]=0;
  132. if(count($newpostlist['forums'])==0) $newpostlist['forums'][0]=0;
  133. sf_update_member_item($current_user->ID, 'newposts', $newpostlist);
  134. if($nosave == false)
  135. {
  136. sf_update_member_item($current_user->ID, 'checktime', 0);
  137. }
  138. $current_user->newpostlist = true;
  139. return;
  140. }
  141. # ------------------------------------------------------------------
  142. # sf_set_last_visited()
  143. #
  144. # Set the last visited timestamp after user has disappeared
  145. # $userid: Users ID
  146. # ------------------------------------------------------------------
  147. function sf_set_last_visited($userid)
  148. {
  149. sf_update_member_item($userid, 'lastvisit', 0);
  150. return;
  151. }
  152. # ------------------------------------------------------------------
  153. # sf_destroy_users_newposts()
  154. #
  155. # Destroy users new-post-list now they have departed
  156. # $userid: Users ID
  157. # ------------------------------------------------------------------
  158. function sf_destroy_users_newposts($userid)
  159. {
  160. $newpostlist['topics'][0]=0;
  161. $newpostlist['forums'][0]=0;
  162. sf_update_member_item($userid, 'newposts', $newpostlist);
  163. return;
  164. }
  165. # ------------------------------------------------------------------
  166. # sf_update_users_newposts()
  167. #
  168. # Updates a users new-post-list on subsequent page loads
  169. # $newpostlist: new-post-list
  170. # ------------------------------------------------------------------
  171. function sf_update_users_newposts($newpostlist)
  172. {
  173. global $wpdb, $current_user, $sfglobals;
  174. if($newpostlist['topics'][0] == 0)
  175. {
  176. unset($newpostlist);
  177. $newpostlist=array();
  178. $newpostlist['topics']=array();
  179. $newpostlist['forums']=array();
  180. }
  181. $checktime=$sfglobals['member']['checktime'];
  182. $newpostlist['topics']=array_reverse($newpostlist['topics']);
  183. $newpostlist['forums']=array_reverse($newpostlist['forums']);
  184. $where = '';
  185. if (!$current_user->forumadmin)
  186. {
  187. # limit to viewable forums based on permissions
  188. $forums = sf_get_forum_memberships($current_user->ID);
  189. if ($forums)
  190. {
  191. $forum_ids = '';
  192. foreach ($forums as $forum)
  193. {
  194. if (sf_can_view_forum($forum->forum_id))
  195. {
  196. $forum_ids[] = $forum->forum_id;
  197. }
  198. }
  199. }
  200. # create where clause based on forums that current user can view
  201. if ($forum_ids != '')
  202. {
  203. $where.= "forum_id IN (" . implode(",", $forum_ids) . ") AND ";
  204. }
  205. }
  206. if ($where != '')
  207. {
  208. $records = $wpdb->get_results("SELECT DISTINCT topic_id, forum_id FROM ".SFPOSTS." WHERE ".$where."post_status = 0 AND (post_date > '".$checktime."') AND user_id != ".$current_user->ID." ORDER BY topic_id DESC LIMIT 50;", ARRAY_A);
  209. } else {
  210. $records = '';
  211. }
  212. if (!empty($records))
  213. {
  214. foreach($records as $record)
  215. {
  216. if(!in_array($record['topic_id'], $newpostlist['topics']))
  217. {
  218. $newpostlist['topics'][]=$record['topic_id'];
  219. $newpostlist['forums'][]=$record['forum_id'];
  220. }
  221. }
  222. }
  223. $newpostlist = sf_add_waiting_post_list($newpostlist);
  224. $newpostlist['topics']=array_reverse($newpostlist['topics']);
  225. $newpostlist['forums']=array_reverse($newpostlist['forums']);
  226. if(count($newpostlist['topics'])==0) $newpostlist['topics'][0]=0;
  227. if(count($newpostlist['forums'])==0) $newpostlist['forums'][0]=0;
  228. sf_update_member_item($current_user->ID, 'newposts', $newpostlist);
  229. sf_update_member_item($current_user->ID, 'checktime', 0);
  230. $current_user->newpostlist = true;
  231. return $newpostlist;
  232. }
  233. # ------------------------------------------------------------------
  234. # sf_remove_users_newposts()
  235. #
  236. # Removes items from users new-post-list upon viewing them
  237. # $topicid: the topic to remove from new-post-list
  238. # ------------------------------------------------------------------
  239. function sf_remove_users_newposts($topicid)
  240. {
  241. global $current_user, $sfglobals;
  242. if ($current_user->member)
  243. {
  244. $newpostlist = $sfglobals['member']['newposts'];
  245. if (($newpostlist) && ($newpostlist['topics'][0] != 0))
  246. {
  247. if ((count($newpostlist['topics']) == 1) && ($newpostlist['topics'][0] == $topicid))
  248. {
  249. sf_destroy_users_newposts($current_user->ID);
  250. } else {
  251. $remove = -1;
  252. for ($x=0; $x < count($newpostlist['topics']); $x++)
  253. {
  254. if ($newpostlist['topics'][$x] == $topicid)
  255. {
  256. $remove = $x;
  257. break;
  258. }
  259. }
  260. if ($remove != -1)
  261. {
  262. array_splice($newpostlist['topics'], $remove, 1);
  263. array_splice($newpostlist['forums'], $remove, 1);
  264. sf_update_member_item($current_user->ID, 'newposts', $newpostlist);
  265. }
  266. }
  267. }
  268. }
  269. return;
  270. }
  271. # ------------------------------------------------------------------
  272. # sf_is_in_users_newposts()
  273. #
  274. # Determines if topic is in current users new-post-list
  275. # $topicid: the topic to look for
  276. # ------------------------------------------------------------------
  277. function sf_is_in_users_newposts($topicid)
  278. {
  279. global $current_user, $sfglobals;
  280. if ($current_user->member)
  281. {
  282. $newpostlist = $sfglobals['member']['newposts'];
  283. }
  284. $found = false;
  285. if (($newpostlist['topics']) && ($newpostlist['topics'][0] != 0))
  286. {
  287. for ($x=0; $x < count($newpostlist['topics']); $x++)
  288. {
  289. if ($newpostlist['topics'][$x] == $topicid) $found=true;
  290. }
  291. }
  292. return $found;
  293. }
  294. # ------------------------------------------------------------------
  295. # sf_add_waiting_post_list()
  296. #
  297. # Adds posts in waiting to admins new post list
  298. # $topics: Current topics in list
  299. # ------------------------------------------------------------------
  300. function sf_add_waiting_post_list($newpostlist)
  301. {
  302. global $wpdb, $current_user, $sfglobals;
  303. # If a moderator but not allowed to remove from queue then exclude queued posts from personal new post list
  304. if(($current_user->forumadmin == false) && ($current_user->moderator == true) && ($sfglobals['admin']['sfmodasadmin'] == false))
  305. {
  306. return $newpostlist;
  307. }
  308. if (empty($newpostlist['topics'][0]))
  309. {
  310. unset($newpostlist);
  311. $newpostlist=array();
  312. $newpostlist['topics']=array();
  313. $newpostlist['forums']=array();
  314. }
  315. # Add waiting if admin or moderator (->moderator covers both)
  316. if($current_user->moderator)
  317. {
  318. $records=$wpdb->get_results("SELECT DISTINCT topic_id, forum_id FROM ".SFWAITING, ARRAY_A);
  319. if($records)
  320. {
  321. foreach($records as $record)
  322. {
  323. if(!in_array($record['topic_id'], $newpostlist['topics']))
  324. {
  325. $newpostlist['topics'][]=$record['topic_id'];
  326. $newpostlist['forums'][]=$record['forum_id'];
  327. }
  328. }
  329. }
  330. }
  331. return $newpostlist;
  332. }
  333. # ******************************************************************
  334. # ADMINS NEW POST QUEUE MANAGEMENT
  335. # ******************************************************************
  336. # ------------------------------------------------------------------
  337. # sf_approve_post()
  338. #
  339. # Approve a post and take it out of moderation and the queue (if allowed)
  340. # if postid is set then work on just that post and if topicid is set
  341. # as well, then check with waiting for removal of the one post.
  342. # if postid is zero and topicid is set - approve all in topic.
  343. # $fromBar Set to true if called from Admins Bar
  344. # $postid: the post to approve
  345. # $topicid the topic to approve (if set then 'all')
  346. # $show true if no return message is required
  347. # ------------------------------------------------------------------
  348. function sf_approve_post($fromBar, $postid=0, $topicid=0, $show=true)
  349. {
  350. global $wpdb, $sfvars, $current_user, $sfglobals;
  351. if($postid == 0 && $topicid == 0) return;
  352. if(!$current_user->sfapprove)
  353. {
  354. if($show) update_sfnotice('sfmessage', '1@'.__('Access Denied', "sforum"));
  355. return;
  356. }
  357. if($postid != 0)
  358. {
  359. $wpdb->query("UPDATE ".SFPOSTS." SET post_status = 0 WHERE post_id=".$postid);
  360. }
  361. if($postid == 0 && $topicid != 0)
  362. {
  363. $wpdb->query("UPDATE ".SFPOSTS." SET post_status = 0 WHERE topic_id=".$topicid);
  364. }
  365. if($wpdb === false)
  366. {
  367. if($show) update_sfnotice('sfmessage', '1@'.__("Post Approval Failed", "sforum"));
  368. } else {
  369. if($show) update_sfnotice('sfmessage', '0@'.__("Post Approved", "sforum"));
  370. if($topicid == 0) $topicid = $sfvars['topicid'];
  371. if(($sfglobals['admin']['sfbaronly']==true && $fromBar==true) || ($sfglobals['admin']['sfbaronly'] == false))
  372. {
  373. sf_remove_from_waiting($fromBar, $topicid, $postid);
  374. }
  375. }
  376. return;
  377. }
  378. # ------------------------------------------------------------------
  379. # sf_remove_from_waiting()
  380. #
  381. # Removes an item from admins queue when it is viewed (or from Bar)
  382. # $fromBar Set to true if called from Admins Bar
  383. # $topicid: the topic to remove (all posts is postid is 0)
  384. # $postid: if specified removed the one post from topic
  385. # ------------------------------------------------------------------
  386. function sf_remove_from_waiting($fromBar, $topicid, $postid=0)
  387. {
  388. global $wpdb, $current_user, $sfglobals;
  389. if(empty($topicid) || $topicid==0) return;
  390. $remove = false;
  391. if(($current_user->forumadmin) || ($current_user->moderator && $sfglobals['admin']['sfmodasadmin']))
  392. {
  393. if(($sfglobals['admin']['sfbaronly']==true && $fromBar==true) || ($sfglobals['admin']['sfbaronly'] == false))
  394. {
  395. $remove = true;
  396. }
  397. } else {
  398. # if moderator and mods posts are to be shown get out quick
  399. if($current_user->forumadmin == false && $current_user->moderator && $sfglobals['admin']['sfshowmodposts'])
  400. {
  401. return;
  402. }
  403. }
  404. if($remove == true)
  405. {
  406. # are we removing the whole topic?
  407. if($postid == 0)
  408. {
  409. # first check there are no posts still to be moderated in this topic...
  410. $rows = $wpdb->get_col("SELECT post_status FROM ".SFPOSTS." WHERE topic_id=".$topicid." AND post_status=1");
  411. If($rows)
  412. {
  413. return;
  414. } else {
  415. $wpdb->query("DELETE FROM ".SFWAITING." WHERE topic_id=".$topicid);
  416. }
  417. } else {
  418. # get the current row to see if the postid matches - and the post count is more than 1)
  419. $current = $wpdb->get_row("SELECT * FROM ".SFWAITING." WHERE topic_id=".$topicid);
  420. if($current)
  421. {
  422. # if post count is 1 may as well delete the row
  423. if($current->post_count == 1)
  424. {
  425. $wpdb->query("DELETE FROM ".SFWAITING." WHERE topic_id=".$topicid);
  426. } elseif($current->post_id != $postid)
  427. {
  428. $wpdb->query("UPDATE ".SFWAITING." SET post_count = ".($current->post_count-1)." WHERE topic_id=".$topicid);
  429. } else {
  430. $newpostid = $wpdb->get_var("SELECT post_id FROM ".SFPOSTS." WHERE topic_id=".$topicid." AND post_id > ".$postid." ORDER BY post_id DESC LIMIT 1");
  431. if($newpostid)
  432. {
  433. $wpdb->query("UPDATE ".SFWAITING." SET post_count = ".($current->post_count-1).", post_id = ".$newpostid." WHERE topic_id=".$topicid);
  434. } else {
  435. $wpdb->query("DELETE FROM ".SFWAITING." WHERE topic_id=".$topicid);
  436. }
  437. }
  438. }
  439. }
  440. }
  441. return;
  442. }
  443. # ------------------------------------------------------------------
  444. # sf_remove_waiting_queue()
  445. #
  446. # Removes the admin queue unless a post is awaiting approval
  447. # ------------------------------------------------------------------
  448. function sf_remove_waiting_queue()
  449. {
  450. global $wpdb;
  451. $rows = $wpdb->get_col("SELECT topic_id FROM ".SFWAITING);
  452. if($rows)
  453. {
  454. $queued = array();
  455. foreach($rows as $row)
  456. {
  457. $queued[]=$row;
  458. }
  459. foreach($queued as $topic)
  460. {
  461. sf_remove_from_waiting(true, $topic);
  462. }
  463. }
  464. return;
  465. }
  466. # ------------------------------------------------------------------
  467. # sf_get_waiting_url()
  468. #
  469. # Creates the new post urls and counts in the Admin Bar
  470. # $postlist: array from the admin queue of posts
  471. # ------------------------------------------------------------------
  472. function sf_get_waiting_url($postlist, $pageview, $shownew)
  473. {
  474. global $sfvars, $current_user, $sfglobals;
  475. # check if topic in url - if yes and it is in postlist - remove it.
  476. $newposts = array();
  477. $index = 0;
  478. $modcount = 0;
  479. $readcount = 0;
  480. $fixed = '0';
  481. if ($sfglobals['member']['admin_options']['sfbarfix']) $fixed = '1';
  482. if ($postlist)
  483. {
  484. if (!empty($sfvars['topicid']))
  485. {
  486. $topicid=$sfvars['topicid'];
  487. foreach ($postlist as $forum)
  488. {
  489. if (isset($forum['topics']))
  490. {
  491. foreach ($forum['topics'] as $topic)
  492. {
  493. if (isset($topic['posts']))
  494. {
  495. foreach ($topic['posts'] as $post)
  496. {
  497. $readcount++;
  498. if (!isset($post['topic_id']) || $post['topic_id'] != $topicid)
  499. {
  500. $newposts[$index]->post_id=$post['post_id'];
  501. # increment mod count for this user
  502. if ($post['post_status'] == 1) $modcount++;
  503. $index++;
  504. } else {
  505. if ($post['post_status'] == 1)
  506. {
  507. $modcount++;
  508. $newposts[$index]->post_id=$post['post_id'];
  509. $index++;
  510. }
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. } else {
  518. $newposts = $postlist;
  519. foreach ($postlist as $forum)
  520. {
  521. if (isset($forum['topics']))
  522. {
  523. foreach ($forum['topics'] as $topic)
  524. {
  525. if (isset($topic['posts']))
  526. {
  527. foreach ($topic['posts'] as $post)
  528. {
  529. $readcount++;
  530. # increment mod count for this user
  531. if ($post['post_status'] == 1) $modcount++;
  532. }
  533. }
  534. }
  535. }
  536. }
  537. }
  538. }
  539. if($newposts)
  540. {
  541. $readcount = $readcount - $modcount;
  542. } else {
  543. $readcount = 0;
  544. $modcount = 0;
  545. }
  546. $unreadclass='sfrednumber';
  547. $needmodclass='sfbluenumber';
  548. if($readcount == 0) $unreadclass='sfrednumberzero';
  549. if($modcount == 0) $needmodclass='sfbluenumberzero';
  550. $site = SFHOMEURL."index.php?sf_ahah=newposts";
  551. $numbersurl = SFHOMEURL."index.php?sf_ahah=autoupdate";
  552. $href = 'javascript:void(0)';
  553. $jscall = ' onclick="sfjgetNewPostList(\''.$site.'\', \''.$numbersurl.'\', \''.$fixed.'\' )"';
  554. $spinner = '<img class="inline_edit" id="sfbarspinner" src="'.SFADMINIMAGES.'working.gif" alt="" />';
  555. $out = '<span><a class="sficon" href="'.$href.'" '.$jscall.'><img class="sfalignleft" src="'. SFRESOURCES .'newpost.png" alt="" title="'.esc_attr(__("New Posts", "sforum")).'" /><span id="sfunread" class="'.$unreadclass.' sfalignleft" title="'.esc_attr(__("New Posts", "sforum")).'">'.$readcount.'</span><span id="sfmod" class="'.$needmodclass.' sfalignleft" title="'.esc_attr(__("Awaiting Approval", "sforum")).'">'.$modcount.'</span>&nbsp;'.sf_render_icons("New Posts").'</a></span>'.$spinner."\n";
  556. return $out;
  557. }
  558. # ******************************************************************
  559. # URL GENERATION
  560. # ******************************************************************
  561. # ------------------------------------------------------------------
  562. # sf_get_forum_url_newposts()
  563. #
  564. # Builds the admin new post url
  565. # $forumslug: forum slug
  566. # $forumname: forum name
  567. # ------------------------------------------------------------------
  568. function sf_get_forum_url_newposts($forumslug, $forumname)
  569. {
  570. $out = '<a href="'.sf_build_url($forumslug, '', 1, 0).'">Forum: '.$forumname.'</a>'."\n";
  571. return $out;
  572. }
  573. # ------------------------------------------------------------------
  574. # sf_get_topic_url_newpost()
  575. #
  576. # Builds the admin new post url
  577. # $forumslug: forum slug
  578. # $topicid: id of topic
  579. # $postid: if of post
  580. # $postindex: index of post if known
  581. # ------------------------------------------------------------------
  582. function sf_get_topic_url_newpost($forumslug, $topicid, $postid, $postindex=0)
  583. {
  584. $topic=sf_get_topic_record($topicid);
  585. $out = '<a href="'.sf_build_url($forumslug, $topic->topic_slug, 0, $postid, $postindex).'">'.sf_filter_title_display($topic->topic_name).'</a>'."\n";
  586. return $out;
  587. }
  588. # RELACEMENT FUNCTION FOR ABOVE EXCEPT THE ABOVE IS USED BY TWO TEMPLATE TAGS THAT NEED RE-ENGINEERING
  589. function sf_get_topic_newpost_url($forumslug, $topicslug, $topicname, $postid, $postindex=0)
  590. {
  591. $out = '<a href="'.sf_build_url($forumslug, $topicslug, 0, $postid, $postindex).'">'.$topicname.'</a>'."\n";
  592. return $out;
  593. }
  594. # ------------------------------------------------------------------
  595. # sf_get_topic_url()
  596. #
  597. # Builds a topic url including all icons etc
  598. # $forumslug: forum slug for url
  599. # $topicslug: topic slug for url
  600. # etc.
  601. # ------------------------------------------------------------------
  602. function sf_get_topic_url($forumslug, $topicslug, $topicname)
  603. {
  604. global $sfvars;
  605. $topicname=sf_filter_title_display($topicname);
  606. if($sfvars['searchvalue'])
  607. {
  608. $out.= '<a href="'.sf_build_url($forumslug, $topicslug, 1, 0);
  609. if(strpos(SFURL, '?') === false)
  610. {
  611. $out.= '?value';
  612. } else {
  613. $out.= '&amp;value';
  614. }
  615. $out.= '='.$sfvars['searchvalue'].'&amp;type='.$sfvars['searchtype'].'&amp;include='.$sfvars['searchinclude'].'&amp;search='.$sfvars['searchpage'].'">'.sf_filter_title_display($topicname).'</a>'."\n";
  616. } else {
  617. $out = '<a href="'.sf_build_url($forumslug, $topicslug, 1, 0).'">'.sf_filter_title_display($topicname).'</a>'."\n";
  618. }
  619. return $out;
  620. }
  621. # ------------------------------------------------------------------
  622. # sf_get_post_url()
  623. #
  624. # Builds a post url including all icons etc
  625. # $forumslug: forum slug for url
  626. # $topicslug: topic slug for url
  627. # $postid id of the post
  628. # $postindex: position of post within the topic (for paging)
  629. # ------------------------------------------------------------------
  630. function sf_get_post_url($forumslug, $topicslug, $postid, $postindex=0, $title='', $posttip='')
  631. {
  632. $out = '<a href="'.sf_build_url($forumslug, $topicslug, 0, $postid, $postindex).'"';
  633. if($title != '' && $posttip != '')
  634. {
  635. $out.= ' title="'.$posttip.'"';
  636. }
  637. $out.= '>';
  638. if($title=='')
  639. {
  640. if($posttip=='') $posttip = esc_attr(__("Go to Post", "sforum"));
  641. $out.= '<img src="'. SFRESOURCES .'gopost.png" alt="" title="'.$posttip.'" />';
  642. } else {
  643. $out.= $title;
  644. }
  645. $out.= '</a>';
  646. return $out;
  647. }
  648. # ------------------------------------------------------------------
  649. # sf_get_forum_search_url()
  650. #
  651. # Builds a forum search url with the query vars
  652. # ------------------------------------------------------------------
  653. function sf_get_forum_search_url()
  654. {
  655. global $sfvars;
  656. if(isset($_GET['ret']))
  657. {
  658. $forumid='all';
  659. } else {
  660. $forumid=$sfvars['forumid'];
  661. }
  662. $out = '<a class="sficon" href="'.sf_build_qurl('forum='.$forumid, 'value='.$sfvars['searchvalue'], 'type='.$sfvars['searchtype'], 'include='.$sfvars['searchinclude'], 'search='.$sfvars['searchpage']).'">'."\n";
  663. return $out;
  664. }
  665. # ------------------------------------------------------------------
  666. # sf_build_subforum_list()
  667. #
  668. # Constructs array of subforums for later display control
  669. # ------------------------------------------------------------------
  670. function sf_build_subforum_list($forums, $parent)
  671. {
  672. global $subforums, $subforumids, $sfglobals;
  673. foreach($forums as $forum)
  674. {
  675. if($forum['parent'] == $parent && $forum['forum_id'] != $parent)
  676. {
  677. $subforums[]=$forum;
  678. $subforumids[]=$forum['forum_id'];
  679. if($sfglobals['display']['groups']['showallsubs'] && $forum['children'])
  680. {
  681. $subforums = sf_build_subforum_list($forums, $forum['forum_id']);
  682. }
  683. }
  684. }
  685. return $subforums;
  686. }
  687. # ------------------------------------------------------------------
  688. # sf_build_subforum_list()
  689. #
  690. # Adds subforum counts into man forum (Group View) if option set
  691. # and swaps in last topic/post data if subforum last post newer
  692. # ------------------------------------------------------------------
  693. function sf_massage_forum_counts($parent, &$stats, $subforums)
  694. {
  695. if($subforums)
  696. {
  697. foreach($subforums as $sub)
  698. {
  699. $thissub = $sub['forum_id'];
  700. # only check if subforum actually has some topics
  701. if (!empty($stats[$thissub]['topic_count']))
  702. {
  703. # default the parent counts?
  704. if (empty($stats[$parent]['topic_count']))
  705. {
  706. $stats[$parent]['topic_count'] = 0;
  707. $stats[$parent]['post_count'] = 0;
  708. $stats[$parent]['udate'] = 0;
  709. }
  710. # add topc and post counts to parent
  711. $stats[$parent]['topic_count']+= $stats[$thissub]['topic_count'];
  712. $stats[$parent]['post_count']+= $stats[$thissub]['post_count'];
  713. # now check if the last subforum post is newer than parent or if no topics in parent
  714. if (empty($stats[$parent]['topic_count']) || (($stats[$thissub]['udate'] > $stats[$parent]['udate']) && $stats[$thissub]['post_status'] == 0))
  715. {
  716. # copy it over
  717. $stats[$parent]['proxy'] = $stats[$thissub]['forum_id'];
  718. $stats[$parent]['proxy_slug'] = $sub['forum_slug'];
  719. $stats[$parent]['post_id'] = $stats[$thissub]['post_id'];
  720. $stats[$parent]['topic_id'] = $stats[$thissub]['topic_id'];
  721. $stats[$parent]['topic_name'] = $stats[$thissub]['topic_name'];
  722. $stats[$parent]['post_date'] = $stats[$thissub]['post_date'];
  723. $stats[$parent]['udate'] = $stats[$thissub]['udate'];
  724. $stats[$parent]['guest_name'] = $stats[$thissub]['guest_name'];
  725. $stats[$parent]['user_id'] = $stats[$thissub]['user_id'];
  726. $stats[$parent]['post_status'] = $stats[$thissub]['post_status'];
  727. $stats[$parent]['display_name'] = $stats[$thissub]['display_name'];
  728. $stats[$parent]['post_index'] = $stats[$thissub]['post_index'];
  729. $stats[$parent]['topic_slug'] = $stats[$thissub]['topic_slug'];
  730. $stats[$parent]['post_tip'] = $stats[$thissub]['post_tip'];
  731. }
  732. }
  733. }
  734. }
  735. return $stats;
  736. }
  737. # ******************************************************************
  738. # MISCELLANEOUS ROUTINES
  739. # ******************************************************************
  740. # ------------------------------------------------------------------
  741. # sf_push_topic_page()
  742. #
  743. # called on forum display to note current topic page user is viewing.
  744. # $forumid:
  745. # $page:
  746. # ------------------------------------------------------------------
  747. function sf_push_topic_page($forumid, $page)
  748. {
  749. update_sfsetting($_SERVER['REMOTE_ADDR'], $forumid.'@'.$page);
  750. return;
  751. }
  752. # ------------------------------------------------------------------
  753. # sf_pop_topic_page()
  754. #
  755. # called on topic display to set breadcrumb to correct page
  756. # if same forum
  757. # $forumid:
  758. # ------------------------------------------------------------------
  759. function sf_pop_topic_page($forumid)
  760. {
  761. $page = 1;
  762. $check = get_sfsetting($_SERVER['REMOTE_ADDR']);
  763. # if no record then resprt to page 1
  764. if($check == -1) return $page;
  765. $check = explode('@', $check);
  766. # is it the same forum?
  767. if($check[0] == $forumid)
  768. {
  769. $page = $check[1];
  770. }
  771. return $page;
  772. }
  773. # ------------------------------------------------------------------
  774. # sf_display_banner()
  775. #
  776. # displays optional banner instead of page title
  777. # ------------------------------------------------------------------
  778. function sf_display_banner()
  779. {
  780. global $sfglobals;
  781. if(!empty($sfglobals['display']['pagetitle']['banner']))
  782. {
  783. return '<img id="sfbanner" src="'.esc_url($sfglobals['display']['pagetitle']['banner']).'" alt="" />';
  784. }
  785. return '';
  786. }
  787. # ------------------------------------------------------------------
  788. # sf_render_icons()
  789. #
  790. # displays an icon text if not turned off in the options
  791. # $icontext: text to display if needed
  792. # ------------------------------------------------------------------
  793. function sf_render_icons($icontext)
  794. {
  795. global $sfglobals;
  796. if ($sfglobals['icons'][$icontext] == 1)
  797. {
  798. return ' '.__($icontext, "sforum").' ';
  799. } else {
  800. return '';
  801. }
  802. }
  803. # ------------------------------------------------------------------
  804. # sf_get_topic_status_flag()
  805. #
  806. # Returns status entry $pos for forums set $statusset
  807. # $statusset: stats set name used in forum
  808. # $pos: position in list (base 1 so take 1 off)
  809. # ------------------------------------------------------------------
  810. function sf_get_topic_status_flag($statusset, $pos)
  811. {
  812. global $session_topicstatus;
  813. if(!isset($session_topicstatus[$statusset]))
  814. {
  815. $list=sf_get_sfmeta('topic-status', false, $statusset);
  816. $session_topicstatus[$statusset] = explode(',', $list[0]['meta_value']);
  817. }
  818. return $session_topicstatus[$statusset][$pos-1];
  819. }
  820. # ------------------------------------------------------------------
  821. # sf_topic_status_select()
  822. #
  823. # Returns status entry $pos for forums set $statusset
  824. # $statusset: stats set name used in forum
  825. # $current: current position in list (base 1 so take 1 off)
  826. # $inline: Sets up the auto changng of status
  827. # $search: If search operation do not check permissions
  828. # ------------------------------------------------------------------
  829. function sf_topic_status_select($statusset, $current = -1, $inline = false, $search = false)
  830. {
  831. global $wpdb, $sfvars, $current_user;
  832. if(!$search)
  833. {
  834. if(!$current_user->sftopicstatus) return '';
  835. }
  836. $set = sf_get_sfmeta('topic-status', false, $statusset);
  837. if($set)
  838. {
  839. $list = $set[0]['meta_value'];
  840. $list = explode(',', $list);
  841. $out='';
  842. if($inline)
  843. {
  844. $site = SFHOMEURL."index.php?sf_ahah=admintools&action=ss&amp;id=".$sfvars['topicid']."&amp;set=".$statusset;
  845. $out.= '<select class="sfcontrol" name="statvalue" onchange="javascript:sfjsetStatus(this, \''.$site.'\')" >'."\n";
  846. } else {
  847. $out.= '<select class="sfquicklinks sfcontrol" name="statvalue">'."\n";
  848. }
  849. $out.= '<option value="0">'.__("Select Status:", "sforum").'</option>'."\n";
  850. $default='';
  851. for($x=0; $x<count($list); $x++)
  852. {
  853. if(($current-1) == $x)
  854. {
  855. $default = 'selected="selected" ';
  856. } else {
  857. $default - null;
  858. }
  859. $out.='<option '.$default.'value="'.($x+1).'">'.sf_filter_title_display(trim($list[$x])).'</option>'."\n";
  860. $default='';
  861. }
  862. }
  863. $out.='</select>';
  864. return $out;
  865. }
  866. # ------------------------------------------------------------------
  867. # sf_create_stats_keys()
  868. #
  869. # Create list of stats keys for first/last post column
  870. # Ensures that 0 and 1 are the same if only one post
  871. # ------------------------------------------------------------------
  872. function sf_create_stats_keys($keys)
  873. {
  874. $list=array();
  875. if(is_array($keys))
  876. {
  877. $list = array_keys($keys);
  878. if(count($keys) == 2)
  879. {
  880. $list[2]=$list[1];
  881. $list[1]=$list[0];
  882. }
  883. } else {
  884. $list[1] = $keys;
  885. $list[2] = $keys;
  886. }
  887. return $list;
  888. }
  889. # ------------------------------------------------------------------
  890. # sf_check_unlogged_user()
  891. #
  892. # checks if 'guest' is a user not logged in and returns their name
  893. # ------------------------------------------------------------------
  894. function sf_check_unlogged_user()
  895. {
  896. $sfmemberopts = sf_get_option('sfmemberopts');
  897. if(isset($_COOKIE['sforum_'.COOKIEHASH]) && $sfmemberopts['sfcheckformember'])
  898. {
  899. # Yes it is - a user not logged in
  900. $username = $_COOKIE['sforum_'.COOKIEHASH];
  901. return $username;
  902. }
  903. return 0;
  904. }
  905. # ------------------------------------------------------------------
  906. # sf_report_post_send()
  907. #
  908. # Send 'report post' email to forum admin
  909. # ------------------------------------------------------------------
  910. function sf_report_post_send()
  911. {
  912. global $current_user;
  913. $eol = "\r\n";
  914. $msg = '';
  915. # if either the posturl or the comments are empty then just forget it
  916. if(empty($_POST['posturl']) || empty($_POST['postreport'])) return;
  917. # clean up the content for the plain text email
  918. $post_content = html_entity_decode($_POST['postcontent']);
  919. $post_content = sf_filter_content_display($post_content);
  920. if($current_user->guest && $current_user->guestname='')
  921. {
  922. $reporter = __('A Guest Visitor', 'sforum');
  923. } else {
  924. # if it got ths far but there is no display name then it's bogus - leave
  925. if(empty($current_user->display_name)) return;
  926. $reporter = __('Member', 'sforum').' '.sf_filter_name_display($current_user->display_name);
  927. }
  928. $msg.= sprintf(__("%s has reported the following post as questionable", "sforum"), $reporter).$eol.$eol;
  929. $msg.= $_POST['posturl'].$eol;
  930. $msg.= stripslashes($_POST['postauthor']).$eol;
  931. $msg.= $post_content.$eol.$eol;
  932. $msg.= __("Comments", "sforum").$eol;
  933. $msg.= $_POST['postreport'].$eol;
  934. $email_sent = sf_send_email(get_option('admin_email'), sprintf(__('[%s] Questionable Post Report', "sforum"), get_option('blogname')), $msg);
  935. if($email_sent[0])
  936. {
  937. $returnmsg = '0@';
  938. } else {
  939. $returnmsg = '1@';
  940. }
  941. update_sfnotice('sfmessage', $returnmsg.$email_sent[1]);
  942. return;
  943. }
  944. # ------------------------------------------------------------------
  945. # sf_zone_datetime()
  946. #
  947. # Sets date time for sql queries based on user options
  948. # $datefield: sql field being queried
  949. # ------------------------------------------------------------------
  950. function sf_zone_datetime($datefield)
  951. {
  952. global $current_user;
  953. $zone = $current_user->timezone;
  954. if($zone == 0) return $datefield;
  955. if($zone < 0)
  956. {
  957. $out='DATE_SUB('.$datefield.', INTERVAL '.abs($zone).' HOUR) as '.$datefield;
  958. } else {
  959. $out='DATE_ADD('.$datefield.', INTERVAL '.abs($zone).' HOUR) as '.$datefield;
  960. }
  961. return $out;
  962. }
  963. # ------------------------------------------------------------------
  964. # sf_date()
  965. #
  966. # Formats a date and time for display
  967. # $type 't'=time 'd'=date
  968. # $data The actual date string
  969. # ------------------------------------------------------------------
  970. function sf_date($type, $data)
  971. {
  972. if($type == 'd')
  973. {
  974. return date_i18n(SFDATES, mysql2date('U', $data));
  975. } else {
  976. return date_i18n(SFTIMES, mysql2date('U', $data));
  977. }
  978. }
  979. # ------------------------------------------------------------------
  980. # sf_check_url()
  981. #
  982. # Check url has http (else browser will assume relative link
  983. # $url: URL to be checked
  984. # ------------------------------------------------------------------
  985. function sf_check_url($url)
  986. {
  987. if($url == 'http://' || $url == 'https://')
  988. {
  989. $url='';
  990. }
  991. return $url;
  992. }
  993. # ******************************************************************
  994. # POST & USER DISPLAY AND FILTERS AND USERS EDITOR CHOICE
  995. # ******************************************************************
  996. # ------------------------------------------------------------------
  997. # sf_push_newuser()
  998. #
  999. # Adds new user stats new user list
  1000. # $name: new users disp0lay name
  1001. # ------------------------------------------------------------------
  1002. function sf_push_newuser($id, $name)
  1003. {
  1004. $sfcontrols = sf_get_option('sfcontrols');
  1005. $num = $sfcontrols['shownewcount'];
  1006. if ($num == 0 || empty($num)) return;
  1007. $newuserlist = $sfcontrols['newuserlist'];
  1008. if (is_array($newuserlist))
  1009. {
  1010. # is this name already listed?
  1011. foreach ($newuserlist as $user)
  1012. {
  1013. if ($user['name'] == $name) return;
  1014. }
  1015. # is the array full? if so pop one off
  1016. $ccount = count($newuserlist);
  1017. while ($ccount > ($num-1))
  1018. {
  1019. array_pop($newuserlist);
  1020. $ccount--;
  1021. }
  1022. # add new user
  1023. array_unshift($newuserlist, array('id' => esc_sql($id), 'name' => esc_sql($name)));
  1024. } else {
  1025. # first name nto the emoty array
  1026. $newuserlist[0]['id'] = esc_sql($id);
  1027. $newuserlist[0]['name'] = esc_sql($name);
  1028. }
  1029. $sfcontrols['newuserlist'] = $newuserlist;
  1030. sf_update_option('sfcontrols', $sfcontrols);
  1031. return;
  1032. }
  1033. # ------------------------------------------------------------------
  1034. # sf_remove_newuser()
  1035. #
  1036. # Adds new user stats new user list
  1037. # $id: new users id
  1038. # ------------------------------------------------------------------
  1039. function sf_remove_newuser($id)
  1040. {
  1041. $sfcontrols = sf_get_option('sfcontrols');
  1042. $newuserlist = $sfcontrols['newuserlist'];
  1043. if (is_array($newuserlist))
  1044. {
  1045. # remove the user if present
  1046. foreach ($newuserlist as $index => $user)
  1047. {
  1048. if ($user['id'] == $id)
  1049. {
  1050. unset($newuserlist[$index]);
  1051. }
  1052. }
  1053. $newuserlist = array_values($newuserlist);
  1054. }
  1055. $sfcontrols['newuserlist'] = $newuserlist;
  1056. sf_update_option('sfcontrols', $sfcontrols);
  1057. return;
  1058. }
  1059. # ------------------------------------------------------------------
  1060. # sf_update_newuser_name()
  1061. #
  1062. # Updates users name of changed in profile
  1063. # $oldname: users old name
  1064. # $newname: users new name
  1065. # ------------------------------------------------------------------
  1066. function sf_update_newuser_name($oldname, $newname)
  1067. {
  1068. $sfcontrols = sf_get_option('sfcontrols');
  1069. $newuserlist = $sfcontrols['newuserlist'];
  1070. if(is_array($newuserlist))
  1071. {
  1072. for($x=0; $x<count($newuserlist)+1; $x++)
  1073. {
  1074. if($newuserlist[$x]['name'] == $oldname)
  1075. {
  1076. $newuserlist[$x]['name'] = $newname;
  1077. }
  1078. }
  1079. }
  1080. $sfcontrols['newuserlist'] = $newuserlist;
  1081. sf_update_option('sfcontrols', $sfcontrols);
  1082. return;
  1083. }
  1084. # ------------------------------------------------------------------
  1085. # sf_build_name_display()
  1086. #
  1087. # Cleans user name and attaches profile or website link if set
  1088. # $userid: id of the user
  1089. # $username: name of the user or guest
  1090. # $stats: Optional - if stats set to true
  1091. # ------------------------------------------------------------------
  1092. function sf_build_name_display($userid, $username, $stats=false)
  1093. {
  1094. global $current_user;
  1095. if(!$userid) return $username;
  1096. if($current_user->sfprofiles)
  1097. {
  1098. $sfprofile=sf_get_option('sfprofile');
  1099. # is profile linked to user name
  1100. if(($sfprofile['profilelink'] == 1 || ($sfprofile['profileinstats']==1 && $stats==true)))
  1101. {
  1102. # link to profile
  1103. return sf_attach_user_profilelink($userid, $username);
  1104. } elseif($sfprofile['weblink'] == 1)
  1105. {
  1106. # link to website
  1107. return sf_attach_user_weblink($userid, $username);
  1108. }
  1109. }
  1110. # neither permission or profile/web link
  1111. return $username;
  1112. }
  1113. # ------------------------------------------------------------------
  1114. # sf_build_avatar_display()
  1115. #
  1116. # Attaches profile or website link if set to Avatar
  1117. # $userid: id of the user
  1118. # $avatar: Avatar display code
  1119. # ------------------------------------------------------------------
  1120. function sf_build_avatar_display($userid, $avatar, $link)
  1121. {
  1122. global $current_user;
  1123. if(!$userid) return $avatar;
  1124. if($current_user->sfprofiles)
  1125. {
  1126. $sfprofile=sf_get_option('sfprofile');
  1127. # is profile linked to user name
  1128. if($sfprofile['profilelink'] == 2)
  1129. {
  1130. # link to profile
  1131. if ($link){
  1132. return sf_attach_user_profilelink($userid, $avatar);
  1133. } else {
  1134. return $avatar;
  1135. }
  1136. } elseif($sfprofile['weblink'] == 2)
  1137. {
  1138. # link to website
  1139. return sf_attach_user_weblink($userid, $avatar);
  1140. }
  1141. }
  1142. # neither permission or profile/web link
  1143. return $avatar;
  1144. }
  1145. # ------------------------------------------------------------------
  1146. # sf_attach_user_weblink()
  1147. #
  1148. # Create a link to a users website if they have entered one in their
  1149. # profile record.
  1150. # $userid: id of the user
  1151. # $targetitem: user name, avatar or web icon - sent as code
  1152. # $returnitem: return targetitem if nothing found
  1153. # ------------------------------------------------------------------
  1154. function sf_attach_user_weblink($userid, $targetitem, $returnitem=true)
  1155. {
  1156. global $wpdb, $session_weblink;
  1157. if(isset($session_weblink[$userid]))
  1158. {
  1159. $website=$session_weblink[$userid];
  1160. } else {
  1161. $website = $wpdb->get_var("SELECT user_url FROM ".SFUSERS." WHERE ID=".$userid);
  1162. if(empty($website))
  1163. {
  1164. $website='#';
  1165. $session_weblink[$userid]=$website;
  1166. }
  1167. }
  1168. if($website != '#')
  1169. {
  1170. $website = sf_check_url($website);
  1171. $session_weblink[$userid]=$website;
  1172. if($website != '')
  1173. {
  1174. return '<a href="'.$website.'" target="_blank">'.$targetitem.'</a>';
  1175. }
  1176. }
  1177. # No wesbite link exists
  1178. if($returnitem)
  1179. {
  1180. return $targetitem;
  1181. } else {
  1182. return '';
  1183. }
  1184. }
  1185. # ------------------------------------------------------------------
  1186. # sf_attach_user_profilelink()
  1187. #
  1188. # Create a link to a users profile using the global profile display
  1189. # settings
  1190. # $userid: id of the user
  1191. # $targetitem: user name, avatar or web icon - sent as code
  1192. # ------------------------------------------------------------------
  1193. function sf_attach_user_profilelink($userid, $targetitem)
  1194. {
  1195. global $wpdb;
  1196. $sfprofile=sf_get_option('sfprofile');
  1197. switch($sfprofile['displaymode'])
  1198. {
  1199. case 1:
  1200. # SF Popup profile
  1201. $site = SFHOMEURL."index.php?sf_ahah=profile&u=".$userid;
  1202. return '<a rel="nofollow" href="'.$site.'" onclick="return hs.htmlExpand(this, { objectType: \'ajax\', preserveContent: true, height:675, width: 750} )">'.$targetitem.'</a>';
  1203. break;
  1204. case 2:
  1205. # SF Profile page
  1206. $user = new WP_User($userid);
  1207. $site = SFURL.'profile/'.urlencode($user->user_login).'/';
  1208. return '<a href="'.$site.'">'.$targetitem.'</a>';
  1209. break;
  1210. case 3:
  1211. # BuddyPress Profile page
  1212. $user = new WP_User($userid);
  1213. $site = SFHOMEURL.'members/'.str_replace(' ', '', $user->user_login).'/profile/';
  1214. return '<a href="'.$site.'">'.$targetitem.'</a>';
  1215. break;
  1216. case 4:
  1217. # WordPress Authors page
  1218. $userkey = $wpdb->get_var("SELECT user_nicename FROM ".SFUSERS." WHERE ID=".$userid);
  1219. if($userkey)
  1220. {
  1221. $site = SFSITEURL.'author/'.$userkey.'/';
  1222. return '<a href="'.$site.'">'.$targetitem.'</a>';
  1223. } else {
  1224. return $targetitem;
  1225. }
  1226. break;
  1227. case 5:
  1228. # Handoff to user specified page
  1229. if($sfprofile['displaypage'])
  1230. {
  1231. $out = '<a href="'.$sfprofile['displaypage'];
  1232. if($sfprofile['displayquery']) $out.= '?'.sf_filter_title_display($sfprofile['displayquery']).'='.$userid;
  1233. $out.= '">'.$targetitem.'</a>';
  1234. } else {
  1235. $out = $targetitem;
  1236. }
  1237. return $out;
  1238. break;
  1239. default:
  1240. return $targetitem;
  1241. break;
  1242. }
  1243. }
  1244. # ------------------------------------------------------------------
  1245. # sf_build_profile_formlink()
  1246. #
  1247. # Create a link to the profile form preferred
  1248. # $userid: id of the user
  1249. # ------------------------------------------------------------------
  1250. function sf_build_profile_formlink($userid)
  1251. {
  1252. global $current_user;
  1253. $sfprofile=sf_get_option('sfprofile');
  1254. switch($sfprofile['formmode'])
  1255. {
  1256. case 1:
  1257. # SPF form
  1258. $edit = '';
  1259. if ($userid != $current_user->ID)
  1260. {
  1261. $user = new WP_User($userid);
  1262. $edit = urlencode($user->user_login).'/edit/';
  1263. }
  1264. $site = SFURL.'profile/'.$edit;
  1265. return $site;
  1266. break;
  1267. case 2:
  1268. # WordPress form
  1269. return trailingslashit(admin_url('user-edit.php?user_id='.$userid));
  1270. break;
  1271. case 3:
  1272. # BuddyPress Profile page
  1273. $user = new WP_User($userid);
  1274. $site = SFHOMEURL.'members/'.str_replace(' ', '', $user->user_login).'/profile/edit/';
  1275. return $site;
  1276. break;
  1277. case 4:
  1278. # Handoff to user specified form
  1279. if($sfprofile['formpage'])
  1280. {
  1281. $out = $sfprofile['formpage'];
  1282. if($sfprofile['formquery']) $out.= '?'.sf_filter_title_display($sfprofile['formquery']).'='.$userid;
  1283. } else {
  1284. $out = '';
  1285. }
  1286. return $out;
  1287. break;
  1288. }
  1289. }
  1290. # ------------------------------------------------------------------
  1291. # sf_filter_wp_ampersand()
  1292. #
  1293. # Replace & with &amp; in urls
  1294. # $url: url to be filtered
  1295. # ------------------------------------------------------------------
  1296. function sf_filter_wp_ampersand($url)
  1297. {
  1298. return str_replace('&', '&amp;', $url);
  1299. }
  1300. # ------------------------------------------------------------------
  1301. # sf_retrieve_policy_document()
  1302. #
  1303. # $policy registration or privacy
  1304. # ------------------------------------------------------------------
  1305. function sf_retrieve_policy_document($policy)
  1306. {
  1307. $sfpolicy = sf_get_option('sfpolicy');
  1308. if($policy == 'privacy' ? $item='sfprivfile' : $item='sfregfile');
  1309. if(!empty($sfpolicy[$item]))
  1310. {
  1311. # text file option
  1312. $sfconfig = sf_get_option('sfconfig');
  1313. $filename = WP_CONTENT_DIR.'/'.$sfconfig['policies'].'/'.$sfpolicy[$item];
  1314. if (file_exists($filename) == false)
  1315. {
  1316. return __("Policy Document Not Found", "sforum");
  1317. } else {
  1318. $handle = fopen($filename, "r");
  1319. $contents = fread($handle, filesize($filename));
  1320. fclose($handle);
  1321. return $contents;
  1322. }
  1323. } else {
  1324. # sfmeta option
  1325. $policytext = sf_get_sfmeta($policy, 'policy');
  1326. return sf_filter_text_display($policytext[0]['meta_value']);
  1327. }
  1328. }
  1329. # ------------------------------------------------------------------
  1330. # sf_wp_list_pages()
  1331. #
  1332. # Filter Call
  1333. # Sorts bug in wp_list_pages by swapping out modified title
  1334. # $ptext: Page titles html string
  1335. # ------------------------------------------------------------------
  1336. function sf_wp_list_pages($ptext)
  1337. {
  1338. global $sfvars, $sfglobals;
  1339. if(!empty($sfvars['seotitle']))
  1340. {
  1341. $seotitle = $sfvars['seotitle'];
  1342. $ptext = str_replace($seotitle, SFPAGETITLE, $ptext);
  1343. $seotitle=html_entity_decode($seotitle, ENT_QUOTES);
  1344. $seotitle=htmlspecialchars($seotitle, ENT_QUOTES);
  1345. $ptext = str_replace($seotitle, SFPAGETITLE, $ptext);
  1346. $seotitle = sf_filter_title_save($seotitle);
  1347. $ptext = str_replace($seotitle, SFPAGETITLE, $ptext);
  1348. $ptext = str_replace(strtoupper($seotitle), SFPAGETITLE, $ptext);
  1349. } else {
  1350. if($sfglobals['display']['pagetitle']['banner'] || $sfglobals['display']['pagetitle']['notitle'])
  1351. {
  1352. $ptext = str_replace('></a>', '>'.SFPAGETITLE.'</a>', $ptext);
  1353. }
  1354. }
  1355. return $ptext;
  1356. }
  1357. # ------------------------------------------------------------------
  1358. # sf_setup_page_title()
  1359. #
  1360. # Filter Call
  1361. # Sets up the page title option
  1362. # $title: Page title
  1363. # ------------------------------------------------------------------
  1364. function sf_setup_page_title($title)
  1365. {
  1366. global $sfglobals, $sfvars;
  1367. if (trim($title) == trim(SFPAGETITLE))
  1368. {
  1369. if (!empty($sfglobals['display']['pagetitle']['banner'])) return '';
  1370. if ($sfglobals['display']['pagetitle']['notitle']) return '';
  1371. $seo = array();
  1372. $seo = sf_get_option('sfseo');
  1373. $title = sf_setup_title($title, ' '.$seo['sfseo_sep'].' ');
  1374. $sfvars['seotitle']=$title;
  1375. }
  1376. return $title;
  1377. }
  1378. # ------------------------------------------------------------------
  1379. # sf_setup_title()
  1380. #
  1381. # Support Routine
  1382. # Sets up the page title option
  1383. # ------------------------------------------------------------------
  1384. function sf_setup_title($title, $sep)
  1385. {
  1386. global $sfvars;
  1387. $sfseo = sf_get_option('sfseo');
  1388. $forumslug = $sfvars['forumslug'];
  1389. if (!empty($forumslug) && $forumslug != 'all' && $sfseo['sfseo_forum'])
  1390. {
  1391. $title = sf_get_forum_name($forumslug).$sep.$title;
  1392. }
  1393. $topicslug = $sfvars['topicslug'];
  1394. if (!empty($topicslug) && $sfseo['sfseo_topic'])
  1395. {
  1396. $title = sf_get_topic_name($topicslug).$sep.$title;
  1397. }
  1398. if ($sfseo['sfseo_page'])
  1399. {
  1400. $pm = urlencode($sfvars['pm']);
  1401. if (!empty($pm))
  1402. {
  1403. $pmview = "inbox";
  1404. $box = urlencode($sfvars['box']);
  1405. if (!empty($box)) $pmview = $box;
  1406. return __("Private Messaging", "sforum").' '.ucfirst($pmview).$sep.$title;
  1407. }
  1408. $profile = urlencode($sfvars['profile']);
  1409. if (!empty($profile) && $profile == 'edit') return __("Edit Member Profile", "sforum").$sep.$title;
  1410. if (!empty($profile) && $profile == 'show') return __("Member Profile", "sforum").$sep.$title;
  1411. if (!empty($profile) && $profile == 'permissions') return __("Member Permissions", "sforum").$sep.$title;
  1412. if (!empty($profile) && $profile == 'buddies') return __("Member Buddies List", "sforum").$sep.$title;
  1413. $newposts = urlencode($sfvars['newposts']);
  1414. if (!empty($newposts) && $newposts == 'all') return __("New/Unread Posts", "sforum").$sep.$title;
  1415. $list = urlencode($sfvars['list']);
  1416. if (!empty($list) && $list == 'members') return __("List of Members", "sforum").$sep.$title;
  1417. $policy = urlencode($sfvars['policy']);
  1418. if (!empty($policy) && $policy == 'show') return __("Site Policy", "sforum").$sep.$title;
  1419. if (isset($_POST['rpaction'])) return __("Report Post", "sforum").$sep.$title;
  1420. }
  1421. return $title;
  1422. }
  1423. function sf_canonical_url()
  1424. {
  1425. global $sfvars;
  1426. if ($sfvars['pageview'] == 'profileshow' || $sfvars['pageview'] == 'profileedit')
  1427. {
  1428. $url = SFURL.'profile/';
  1429. } else if ($sfvars['pageview'] == 'permissions') {
  1430. $url = SFURL.'permissions/';
  1431. } else if ($sfvars['pageview'] == 'buddies') {
  1432. $url = SFURL.'profile/buddies/';
  1433. } else if ($sfvars['pageview'] == 'permissions') {
  1434. $url = SFURL.'profile/permissions/';
  1435. } else if ($sfvars['pageview'] == 'newposts') {
  1436. $url = SFURL.'newposts/';
  1437. } else if ($sfvars['pageview'] == 'list') {
  1438. $page = '';
  1439. if ($sfvars['page'] > 0) $page = '/page-'.$sfvars['page'];
  1440. $url = SFURL.'members'.$page.'/';
  1441. } else if ($sfvars['pageview'] == 'policy') {
  1442. $url = SFURL.'policy/';
  1443. } else if ($sfvars['pageview'] == 'pm' && $sfvars['box'] == 'inbox') {
  1444. $url = SFURL.'private-messaging/inbox/';
  1445. } else if ($sfvars['pageview'] == 'pm' && $sfvars['box'] == 'sentbox') {
  1446. $url = SFURL.'private-messaging/sentbox/';
  1447. } else {
  1448. # check for linked topic
  1449. $sfpostlinking = sf_get_option('sfpostlinking');
  1450. $topic = sf_get_topic_record_from_slug($sfvars['topicslug']);
  1451. if (!empty($topic) && $topic->blog_post_id && $sfpostlinking['sflinkurls'] == 3) # pointing linke topic to blog post?
  1452. {
  1453. $url = get_permalink($topic->blog_post_id);
  1454. } else {
  1455. $url = sf_build_url($sfvars['forumslug'], $sfvars['topicslug'], $sfvars['page'], 0);
  1456. }
  1457. }
  1458. return $url;
  1459. }
  1460. function sf_get_permalink($link, $id, $sample)
  1461. {
  1462. if ($id == sf_get_option('sfpage') && in_the_loop()) $link = sf_canonical_url();
  1463. return $link;
  1464. }
  1465. function sf_avatar($avatar, $id_or_email, $size)
  1466. {
  1467. $uid = 0;
  1468. $icon = 'guest';
  1469. $email = '';
  1470. $guest_email = '';
  1471. if (is_numeric($id_or_email))
  1472. {
  1473. $id = (int) $id_or_email;
  1474. $user = get_userdata($id);
  1475. if ($user)
  1476. {
  1477. $uid = $id;
  1478. $email = sf_filter_email_display($user->user_email);
  1479. if (sf_is_forum_admin($id) ? $icon = 'admin' : $icon = 'user');
  1480. }
  1481. } elseif (is_object($id_or_email)) {
  1482. if (!empty($id_or_email->user_id))
  1483. {
  1484. $id = (int) $id_or_email->user_id;
  1485. $user = get_userdata($id);
  1486. if ($user)
  1487. {
  1488. $uid = $id;
  1489. $email = sf_filter_email_display($user->user_email);
  1490. if (sf_is_forum_admin($id) ? $icon = 'admin' : $icon = 'user');
  1491. }

Large files files are truncated, but you can click here to view the full file