PageRenderTime 82ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/dbtech/livewall/contenttypes/aut.php

https://gitlab.com/elasa/vb-elasa.ir
PHP | 196 lines | 176 code | 5 blank | 15 comment | 4 complexity | 45652b62903abbe7c5e0de4913e226ec MD5 | raw file
  1. <?php
  2. class LiveWall_ContentType_aut extends LiveWall_ContentType_Core
  3. {
  4. /**
  5. * Function to call before every action
  6. */
  7. public function preCheck()
  8. {
  9. if (
  10. !$this->registry->products['dbtech_usertag']
  11. )
  12. {
  13. // This type is inactive
  14. return false;
  15. }
  16. // We made it!
  17. return parent::preCheck();
  18. }
  19. /**
  20. * Fetches data newer than the lastId
  21. *
  22. * @param integer Last ID or -1 for initial load
  23. * @param integer If we're fetching data for only one userID
  24. */
  25. public function fetchData($lastId = -1, $onlyUser = 0, $limit = -1, $fetchOne = false)
  26. {
  27. // Grab excluded usergroups
  28. $excludedGroups = $this->getUserGroupIds();
  29. return LIVEWALL::$db->fetchAll('
  30. SELECT
  31. mention.*,
  32. user.*,
  33. post.postid,
  34. post.title AS posttitle,
  35. thread.title AS threadtitle,
  36. thread.title AS title,
  37. thread.threadid,
  38. thread.forumid,
  39. recipient.username AS recipientusername,
  40. recipient.userid AS recipientuserid,
  41. mention.dateline,
  42. mention.entryid AS contentid,
  43. \':contentType\' AS contenttypeid,
  44. favourite.userid IS NOT NULL AS isfavourite
  45. :avatarQuery
  46. FROM (SELECT entryid FROM $dbtech_thanks_entry ' . ($lastId != -1 ? 'WHERE entryid > ' . intval($lastId) : '') . ' ORDER BY entryid DESC LIMIT ' . $this->registry->options['dbtech_livewall_maxentries'] . ') AS tmp
  47. LEFT JOIN $dbtech_thanks_entry AS entry ON(mention.entryid = tmp.entryid)
  48. LEFT JOIN $user AS user ON(user.userid = mention.userid)
  49. LEFT JOIN $user AS recipient ON(recipient.userid = mention.mentionedid)
  50. LEFT JOIN $dbtech_livewall_settings AS currentuser_settings ON(currentuser_settings.userid = :currentUser)
  51. LEFT JOIN $dbtech_livewall_settings AS actionuser_settings ON(actionuser_settings.userid = user.userid)
  52. LEFT JOIN $dbtech_livewall_favourite AS favourite ON(favourite.userid = :currentUser AND favourite.contenttypeid = \':contentType\' AND favourite.contentid = mention.entryid)
  53. LEFT JOIN $dbtech_livewall_settings AS recipientuser_settings ON(recipientuser_settings.userid = mention.mentionedid)
  54. LEFT JOIN $userlist AS actionuser_friend ON(actionuser_friend.userid = mention.userid AND actionuser_friend.relationid = :currentUser)
  55. LEFT JOIN $userlist AS recipientuser_friend ON(recipientuser_friend.userid = mention.mentionedid AND recipientuser_friend.relationid = :currentUser)
  56. LEFT JOIN $post AS post ON(post.postid = mention.contentid)
  57. LEFT JOIN $thread AS thread ON(thread.threadid = post.threadid)
  58. :avatarJoin
  59. WHERE 1=1
  60. AND NOT FIND_IN_SET(:memberGroupIdsSetUser, user.membergroupids)
  61. AND NOT FIND_IN_SET(:memberGroupIdsSetRecipient, recipient.membergroupids)
  62. AND user.usergroupid NOT :memberGroupIds
  63. AND recipient.usergroupid NOT :memberGroupIds
  64. AND
  65. (
  66. mention.userid = :currentUser OR
  67. (
  68. (
  69. ISNULL(currentuser_settings.:contentType_display) OR
  70. (
  71. currentuser_settings.:contentType_display = 0 OR
  72. (
  73. currentuser_settings.:contentType_display = 1 AND
  74. :currentUser > 0
  75. )
  76. OR
  77. (
  78. currentuser_settings.:contentType_display = 2 AND
  79. actionuser_friend.type = \'buddy\'
  80. )
  81. OR
  82. (
  83. currentuser_settings.:contentType_display = 3 AND
  84. actionuser_friend.type = \'buddy\' AND
  85. actionuser_friend.friend = \'yes\'
  86. )
  87. )
  88. )
  89. AND
  90. (
  91. ISNULL(actionuser_settings.:contentType_privacy) OR
  92. (
  93. actionuser_settings.:contentType_privacy = 0 OR
  94. (
  95. actionuser_settings.:contentType_privacy = 1 AND
  96. :currentUser > 0
  97. )
  98. OR
  99. (
  100. actionuser_settings.:contentType_privacy = 2 AND
  101. actionuser_friend.type = \'buddy\'
  102. )
  103. OR
  104. (
  105. actionuser_settings.:contentType_privacy = 3 AND
  106. actionuser_friend.type = \'buddy\' AND
  107. actionuser_friend.friend = \'yes\'
  108. )
  109. )
  110. )
  111. )
  112. )
  113. AND
  114. (
  115. mention.mentionedid = :currentUser OR
  116. (
  117. (
  118. ISNULL(currentuser_settings.:contentType_display) OR
  119. (
  120. currentuser_settings.:contentType_display = 0 OR
  121. (
  122. currentuser_settings.:contentType_display = 1 AND
  123. :currentUser > 0
  124. )
  125. OR
  126. (
  127. currentuser_settings.:contentType_display = 2 AND
  128. recipientuser_friend.type = \'buddy\'
  129. )
  130. OR
  131. (
  132. currentuser_settings.:contentType_display = 3 AND
  133. recipientuser_friend.type = \'buddy\' AND
  134. recipientuser_friend.friend = \'yes\'
  135. )
  136. )
  137. )
  138. AND
  139. (
  140. ISNULL(recipientuser_settings.:contentType_privacy) OR
  141. (
  142. recipientuser_settings.:contentType_privacy = 0 OR
  143. (
  144. recipientuser_settings.:contentType_privacy = 1 AND
  145. :currentUser > 0
  146. )
  147. OR
  148. (
  149. recipientuser_settings.:contentType_privacy = 2 AND
  150. recipientuser_friend.type = \'buddy\'
  151. )
  152. OR
  153. (
  154. recipientuser_settings.:contentType_privacy = 3 AND
  155. recipientuser_friend.type = \'buddy\' AND
  156. recipientuser_friend.friend = \'yes\'
  157. )
  158. )
  159. )
  160. )
  161. )
  162. :onlyUser
  163. :fetchOne
  164. :limit
  165. ', array(
  166. ':avatarQuery' => ($this->registry->options['avatarenabled'] ? ', avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline, customavatar.width AS avwidth, customavatar.height AS avheight, customavatar.height_thumb AS avheight_thumb, customavatar.width_thumb AS avwidth_thumb, customavatar.filedata_thumb' : ''),
  167. ':avatarJoin' => ($this->registry->options['avatarenabled'] ? 'LEFT JOIN $avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN $customavatar AS customavatar ON (customavatar.userid = user.userid)' : ''),
  168. ':currentUser' => intval($this->registry->userinfo['userid']),
  169. ':contentType' => 'aut',
  170. ':memberGroupIdsSetUser' => implode(', user.membergroupids) AND NOT FIND_IN_SET(', $excludedGroups),
  171. ':memberGroupIdsSetRecipient' => implode(', recipient.membergroupids) AND NOT FIND_IN_SET(', $excludedGroups),
  172. ':memberGroupIds' => LIVEWALL::$db->queryList($excludedGroups),
  173. ':onlyUser' => ($onlyUser ? 'AND (user.userid = ' . intval($onlyUser) . ' OR mention.mentionedid = ' . intval($onlyUser) . ')' : ''),
  174. ':fetchOne' => ($fetchOne ? 'LIMIT 1' : ''),
  175. ':limit' => ($lastId == -1 ? 'LIMIT ' . ($limit == -1 ? $this->registry->options['dbtech_livewall_perpage'] : $limit) : '')
  176. ));
  177. }
  178. /**
  179. * Creates a phrase based on the action in question
  180. */
  181. public function constructPhrase($info)
  182. {
  183. global $vbphrase;
  184. return construct_phrase($vbphrase['dbtech_usertag_x_mentioned_y_in_z'],
  185. '<a href="' . (LIVEWALL::$permissions['canviewuserwall'] ? 'livewall.php?' : 'member.php?') . $this->registry->session->vars['sessionurl'] . 'u=' . $info['userid'] . '" target="_blank">' . $info['username'] . '</a>',
  186. '<a href="member.php?' . $this->registry->session->vars['sessionurl'] . 'u=' . $info['recipientuserid'] . '" target="_blank">' . $info['recipientusername'] . '</a>',
  187. '<a href="showthread.php?' . $this->registry->session->vars['sessionurl'] . 'p=' . $info['postid'] . '#post' . $info['postid'] . '">' . $info['threadtitle'] . '</a>'
  188. );
  189. }
  190. }
  191. ?>