PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/simple-forum/template-tags/sf-template-tags-general.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 320 lines | 209 code | 36 blank | 75 comment | 64 complexity | a31ccfe7a70dcd9960770deaf603eecf 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. Template Tag(s) - General
  5. $LastChangedDate: 2011-03-06 17:03:08 -0700 (Sun, 06 Mar 2011) $
  6. $Rev: 5639 $
  7. */
  8. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
  9. die('Access Denied');
  10. }
  11. /* =====================================================================================
  12. sf_sidedash_tag()
  13. Allows display of a common SPF dashboard on pages
  14. parameters:
  15. show_avatar display user avatar true/false true
  16. show_pm display pm template tag true/false true
  17. redirect controls login/logout redirection 1=home, 2=admin, 3=cur page, 4=forum 4
  18. show_admin_link display link to admin dashboard true/false true
  19. show_login_link display login form and lost pw link true/false true
  20. ===================================================================================*/
  21. function sf_sidedash_tag($show_avatar=true, $show_pm=true, $redirect=4, $show_admin_link=true, $show_login_link=true)
  22. {
  23. include_once (SF_PLUGIN_DIR.'/template-tags/sf-template-tags-pm.php');
  24. include_once (SF_PLUGIN_DIR.'/template-tags/sf-template-tags-avatars.php');
  25. global $current_user, $sfvars, $sfglobals;
  26. sf_initialise_globals($sfvars['forumid']);
  27. $sflogin = sf_get_option('sflogin');
  28. if ($redirect == 1)
  29. {
  30. $redirect_to = SFHOMEURL;
  31. } else if ($redirect == 2) {
  32. $redirect_to = admin_url();
  33. } else if ($redirect == 3) {
  34. $redirect_to = $_SERVER['REQUEST_URI'];
  35. } else {
  36. $redirect_to = SFURL;
  37. }
  38. if($current_user->guest)
  39. {
  40. # are we showing login form and lost password
  41. if ($show_login_link)
  42. {
  43. # display login form
  44. echo '<form action="'.SFSITEURL.'wp-login.php?action=login" method="post">'."\n";
  45. echo '<div class="sftagusername"><label for="sftaglog">'.__("Username: ", "sforum").'<input type="text" name="log" id="sftaglog" value="" size="15" /></label></div>'."\n";
  46. echo '<div class="sftagpassword"><label for="sftagpwd">'.__("Password: ", "sforum").'<input type="password" name="pwd" id="sftagpwd" value="" size="15" /></label></div>'."\n";
  47. echo '<div class="sftagremember"><input type="checkbox" id="rememberme" name="rememberme" value="forever" /><label for="rememberme">'.__("Remember me", "sforum").'</label></div>';
  48. echo '<input type="submit" name="submit" id="submit" value="'.esc_attr(__("Login", "sforum")).'" />'."\n";
  49. echo '<input type="hidden" name="redirect_to" value="'.esc_attr($redirect_to).'" />'."\n";
  50. echo '</form>'."\n";
  51. echo '<p class="sftagguest"><a href="'.$sflogin['sflostpassurl'].'">'.__("Lost Password", "sforum").'</a>'."\n";
  52. # if registrations allowed, display register link
  53. if (TRUE == get_option('users_can_register') && !$sfglobals['lockdown'])
  54. {
  55. $sfpolicy = sf_get_option('sfpolicy');
  56. if($sfpolicy['sfregtext'])
  57. {
  58. echo '<br /><a href="'.SFREGPOLICY.'">'.__("Register", "sforum").'</a></p>'."\n";
  59. } else {
  60. echo '<br /><a href="'.$sflogin['sfregisterurl'].'">'.__("Register", "sforum").'</a></p>'."\n";
  61. }
  62. }
  63. }
  64. } else {
  65. echo '<div class="sftagavatar">'.sf_show_avatar().'</div>';
  66. echo '<p class="sftag-loggedin">'.__("Logged in as", "sforum").' <strong>'.sf_filter_name_display($current_user->display_name).'</strong></p>'."\n";
  67. if ($show_pm)
  68. {
  69. sf_pm_tag(true, false);
  70. }
  71. if ($show_admin_link)
  72. {
  73. echo '<p class="sftag-admin"><a href="'.admin_url().'">'.__('Dashboard', "sforum").'</a></p>';
  74. }
  75. echo '<p class="sftag-logout"><a href="'.wp_nonce_url(SFSITEURL.'wp-login.php?action=logout&amp;redirect_to='.esc_attr($redirect_to), 'log-out').'">'.__('Logout', "sforum").'</a></p>'."\n";
  76. }
  77. }
  78. /* =====================================================================================
  79. sf_admin_mod_status($mod=true, $custom=true)
  80. displays online status of admins and moderators
  81. parameters:
  82. $mod Display moderator status true/false true (default)
  83. $custom Display custom status text if set true/false true (default)
  84. ===================================================================================*/
  85. function sf_admin_mod_status($mod=true, $custom=true)
  86. {
  87. global $wpdb, $current_user, $sfvars;
  88. if(!defined('SFTRACK')) {
  89. sf_setup_sitewide_constants();
  90. }
  91. if(!defined('SFRESOURCES')) {
  92. sf_setup_global_constants();
  93. }
  94. sf_initialise_globals($sfvars['forumid']);
  95. $out = "\n";
  96. if ($mod) $where = ' OR moderator = 1';
  97. $admins = $wpdb->get_results("SELECT user_id, display_name, admin_options FROM ".SFMEMBERS." WHERE admin = 1".$where);
  98. if ($admins)
  99. {
  100. foreach ($admins as $admin)
  101. {
  102. $username = sf_build_name_display($admin->user_id, sf_filter_name_display($admin->display_name));
  103. $out.= '<li class="sfadmin-onlinestatus'."\n";
  104. $status = $wpdb->get_var("SELECT id FROM ".SFTRACK." WHERE trackuserid=".$admin->user_id);
  105. $opts = sf_get_member_item($admin->user_id, 'user_options');
  106. $sfmemberopts = sf_get_option('sfmemberopts');
  107. if (($current_user->forumadmin || (!$sfmemberopts['sfhidestatus'] || !$opts['hidestatus'])) && sf_is_online($admin->user_id))
  108. {
  109. $out.= ' sfadmin-online"><img class="sfonline-icon" src="'.SFRESOURCES.'online.png" alt="" title="'.esc_attr(__("On-Line", "sforum")).'" />'.$username."\n";
  110. } else {
  111. $out.= ' sfadmin-offline"><img class="sfonline-icon" src="'.SFRESOURCES.'offline.png" alt="" title="'.esc_attr(__("Off-Line", "sforum")).'" />'.$username."\n";
  112. if ($custom)
  113. {
  114. $options = unserialize($admin->admin_options);
  115. if (isset($options['sfstatusmsgtext']))
  116. {
  117. $msg = sf_filter_text_display($options['sfstatusmsgtext']);
  118. if ($msg != '')
  119. {
  120. $out.= '<span class="sfcustom-onlinestatus">'.$msg.'</span>'."\n";
  121. }
  122. }
  123. }
  124. }
  125. $out.= '</li>'."\n";
  126. }
  127. } else {
  128. $out.= '<li class="sfadmin-onlinestatus">'."\n";
  129. $out.= __("No Admins or Moderators", "sforum")."\n";
  130. $out.= '</li>'."\n";
  131. }
  132. echo $out;
  133. return;
  134. }
  135. /* =====================================================================================
  136. sf_new_posts_tag($unreadmsg='', $nonemsg='')
  137. Displays a message if the current user has unread posts. If a message is not supplied
  138. a default one is used
  139. parameters:
  140. $unreadmsg message to display when unread text optional
  141. $nonemsg message to display when no uread text optional
  142. ===================================================================================*/
  143. function sf_new_posts_tag($unreadmsg='', $nonemsg='')
  144. {
  145. global $current_user, $sfglobals, $sfvars;
  146. sf_initialise_globals($sfvars['forumid']);
  147. if ($current_user->member)
  148. {
  149. $count = 0;
  150. $newpostlist = $sfglobals['member']['newposts'];
  151. if($newpostlist['topics'][0] == 0 || empty($newpostlist))
  152. {
  153. sf_construct_users_newposts(true);
  154. }
  155. if($newpostlist['topics'][0] != 0) $count = count($newpostlist['topics']);
  156. if ($count != 0)
  157. {
  158. if ($unreadmsg != '')
  159. {
  160. echo $unreadmsg;
  161. } else {
  162. echo sprintf(__('You have %s Topics with Unread Posts in the ', 'sforum'), $count).' <a href="'.SFURL.'">'.__('Forum', 'sforum').' </a>';
  163. }
  164. } else {
  165. if ($nonemsg = '')
  166. {
  167. echo $nonemsg;
  168. } else {
  169. echo __('You have no Unread Posts in the ', 'sforum').' <a href="'.SFURL.'">'.__('Forum', 'sforum').' </a>';
  170. }
  171. }
  172. }
  173. return;
  174. }
  175. /* =====================================================================================
  176. sf_subscribed_topics_tag($display)
  177. template tag to display number of unread subscribed topics. This tag includes
  178. default text that is output with the unread count data. This text can
  179. be suppressed by setting $display to false. If suppressed, the new unread count is returned
  180. to the caller. Nothing is displayed and 0 returned for guests.
  181. parameters:
  182. $display Determines whether to display unread count plus informational text
  183. ===================================================================================*/
  184. function sf_subscribed_topics_tag($display=true)
  185. {
  186. global $current_user, $sfglobals, $sfvars;
  187. sf_initialise_globals($sfvars['forumid']);
  188. $count = 0;
  189. if ($current_user->member)
  190. {
  191. $list = $sfglobals['member']['subscribe'];
  192. if (!empty($list))
  193. {
  194. $newpostlist = $sfglobals['member']['newposts'];
  195. if($newpostlist['topics'][0] == 0 || empty($newpostlist))
  196. {
  197. sf_construct_users_newposts(true);
  198. }
  199. foreach ($list as $topicid)
  200. {
  201. if (sf_is_in_users_newposts($topicid)) $count++;
  202. }
  203. }
  204. }
  205. if ($display)
  206. {
  207. $out = '';
  208. if ($current_user->member)
  209. {
  210. $out .= '<p class="sfsubscribed">';
  211. $out .= __("You have", "sforum").' '.$count.' '.__("unread subscribed topics", "sforum").'.';
  212. $out .= '</p>';
  213. }
  214. echo $out;
  215. }
  216. return $count;
  217. }
  218. /* =====================================================================================
  219. sf_watched_topics_tag($display)
  220. template tag to display number of unread watched topics. This tag includes
  221. default text that is output with the unread count data. This text can
  222. be suppressed by setting $display to false. If suppressed, the new unread count is returned
  223. to the caller. Nothing is displayed and 0 returned for guests.
  224. parameters:
  225. $display Determines whether to display unread count plus informational text
  226. ===================================================================================*/
  227. function sf_watched_topics_tag($display=true)
  228. {
  229. global $current_user, $sfglobals, $sfvars;
  230. sf_initialise_globals($sfvars['forumid']);
  231. $count = 0;
  232. if ($current_user->member)
  233. {
  234. $list = $sfglobals['member']['watches'];
  235. if (!empty($list))
  236. {
  237. $newpostlist = $sfglobals['member']['newposts'];
  238. if($newpostlist['topics'][0] == 0 || empty($newpostlist))
  239. {
  240. sf_construct_users_newposts(true);
  241. }
  242. foreach ($list as $topicid)
  243. {
  244. if (sf_is_in_users_newposts($topicid)) $count++;
  245. }
  246. }
  247. }
  248. if ($display)
  249. {
  250. $out = '';
  251. if ($current_user->member)
  252. {
  253. $out .= '<p class="sfwatched">';
  254. $out .= __("You have", "sforum").' '.$count.' '.__("unread watched topics", "sforum").'.';
  255. $out .= '</p>';
  256. }
  257. echo $out;
  258. }
  259. return $count;
  260. }
  261. ?>