PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 112 lines | 56 code | 14 blank | 42 comment | 15 complexity | 8cd86385b11739153a0fd01eefe537c2 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) - PM
  5. $LastChangedDate: 2010-12-30 17:02:14 -0700 (Thu, 30 Dec 2010) $
  6. $Rev: 5210 $
  7. */
  8. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
  9. die('Access Denied');
  10. }
  11. /* =====================================================================================
  12. sf_pm_tag($display)
  13. template tag to display number of new PMs in the current user inbox. This tag includes
  14. default text that is output with the pm count data and inbox hyperlink. This text can
  15. be supressed by setting $display to false. If supressed, the new PM count and hyperlink
  16. are returned to the call in an array. A -1 count and empty url will be returned for
  17. guests or user that do not have PM permissions. Additionally, if the default text is used,
  18. the no permissions for pm default text can be supressed or those without permissions.
  19. parameters:
  20. $display Determines whether to display pm count plus informational text
  21. $usersonly If $display is true, only display pm text for users with pm permissions
  22. ===================================================================================*/
  23. function sf_pm_tag($display=true, $usersonly=false)
  24. {
  25. global $wpdb, $current_user, $sfvars;
  26. sf_initialise_globals($sfvars['forumid']);
  27. $pm = array();
  28. if ($current_user->sfusepm)
  29. {
  30. $pm['count'] = $wpdb->get_var("SELECT COUNT(message_id) AS cnt FROM ".SFMESSAGES." WHERE (to_id = ".$current_user->ID." AND message_status = 0 AND inbox=1)");
  31. $pm['url'] = SFURL."private-messaging/inbox/";
  32. } else {
  33. $pm['count'] = -1;
  34. $pm['url'] = '';
  35. }
  36. if ($display)
  37. {
  38. $out = '';
  39. if ($current_user->sfusepm)
  40. {
  41. $out .= '<p class="sfpmcount">';
  42. $out .= __("You have ", "sforum").$pm['count'].__(" PM(s) in your ", "sforum").'<a href="'.$pm['url'].'">'.__("inbox", "sforum").'</a>.';
  43. $out .= '</p>';
  44. } else if (!$usersonly){
  45. $out .= '<p class="sfpmcount">';
  46. $out .= __("You do not have PM permissions.", "sforum");
  47. $out .= '</p>';
  48. }
  49. echo $out;
  50. }
  51. return $pm;
  52. }
  53. /* =====================================================================================
  54. sf_sendpm_tag($userid, $text)
  55. template tag to send a pm to a user. Default text will be used for the link unless the
  56. optional $text argument is sent. If you specify the $text argument, you need to specify
  57. where in the string you want the link inserted by the sequence %%. For example:
  58. $text = '<a href="%%" title="Send PM">Send PM</a>';
  59. If the person viewing the site is not a registered member or does not have PM permissions,
  60. then an empty string is returned.
  61. parameters:
  62. $userid user to send a PM to
  63. $text optional parameter to specify text, img or html for the link
  64. ===================================================================================*/
  65. function sf_sendpm_tag($userid, $text='')
  66. {
  67. global $current_user, $sfvars, $wpdb;
  68. $userid = sf_esc_int($userid);
  69. if ($current_user->ID == '' || !$current_user->sfusepm || empty($userid)) return;
  70. sf_initialise_globals($sfvars['forumid']);
  71. $out = '';
  72. if ($userid)
  73. {
  74. $user = $wpdb->get_var("SELECT user_login FROM ".SFUSERS." WHERE ID=".$userid);
  75. $url = SFURL.'private-messaging/send/'.urlencode($user).'/';
  76. if ($text == '')
  77. {
  78. $out.= '<a class="sfsendpmtag" href="'.$url.'"><img src="'.SFRESOURCES.'sendpm-small.png" title="'.esc_attr(__("Send PM", "sforum")).'" />&nbsp;'.sf_render_icons("Send PM").'</a>';
  79. } else {
  80. $out.= str_replace('%%', $url, $text);
  81. }
  82. }
  83. echo $out;
  84. return;
  85. }
  86. ?>