You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

323 lines
9.4 KiB

  1. <?php
  2. namespace modl;
  3. class PostnDAO extends ModlSQL {
  4. function set(Postn $post) {
  5. $this->_sql = '
  6. update postn
  7. set aname = :aname,
  8. aid = :aid,
  9. aemail = :aemail,
  10. title = :title,
  11. content = :content,
  12. commentplace = :commentplace,
  13. published = :published,
  14. updated = :updated,
  15. delay = :delay,
  16. lat = :lat,
  17. lon = :lon,
  18. links = :links,
  19. tags = :tags,
  20. hash = :hash
  21. where session = :session
  22. and jid = :jid
  23. and node = :node
  24. and nodeid = :nodeid';
  25. $this->prepare(
  26. 'Postn',
  27. array(
  28. 'aname' => $post->aname,
  29. 'aid' => $post->aid,
  30. 'aemail' => $post->aemail,
  31. 'title' => $post->title,
  32. 'content' => $post->content,
  33. 'commentplace' => $post->commentplace,
  34. 'published' => $post->published,
  35. 'updated' => $post->updated,
  36. 'delay' => $post->delay,
  37. 'lat' => $post->lat,
  38. 'lon' => $post->lon,
  39. 'links' => $post->links,
  40. 'tags' => $post->tags,
  41. 'hash' => $post->hash,
  42. 'session' => $post->session,
  43. 'jid' => $post->jid,
  44. 'node' => $post->node,
  45. 'nodeid' => $post->nodeid
  46. )
  47. );
  48. $this->run('Postn');
  49. if(!$this->_effective) {
  50. $this->_sql ='
  51. insert into postn
  52. (
  53. session,
  54. jid,
  55. node,
  56. nodeid,
  57. aname,
  58. aid,
  59. aemail,
  60. title,
  61. content,
  62. commentplace,
  63. published,
  64. updated,
  65. delay,
  66. lat,
  67. lon,
  68. links,
  69. tags,
  70. hash)
  71. values(
  72. :session,
  73. :jid,
  74. :node,
  75. :nodeid,
  76. :aname,
  77. :aid,
  78. :aemail,
  79. :title,
  80. :content,
  81. :commentplace,
  82. :published,
  83. :updated,
  84. :delay,
  85. :lat,
  86. :lon,
  87. :links,
  88. :tags,
  89. :hash
  90. )';
  91. $this->prepare(
  92. 'Postn',
  93. array(
  94. 'aname' => $post->aname,
  95. 'aid' => $post->aid,
  96. 'aemail' => $post->aemail,
  97. 'title' => $post->title,
  98. 'content' => $post->content,
  99. 'commentplace' => $post->commentplace,
  100. 'published' => $post->published,
  101. 'updated' => $post->updated,
  102. 'delay' => $post->delay,
  103. 'lat' => $post->lat,
  104. 'lon' => $post->lon,
  105. 'links' => $post->links,
  106. 'tags' => $post->tags,
  107. 'hash' => $post->hash,
  108. 'session' => $post->session,
  109. 'jid' => $post->jid,
  110. 'node' => $post->node,
  111. 'nodeid' => $post->nodeid
  112. )
  113. );
  114. $this->run('Postn');
  115. }
  116. }
  117. function delete($nodeid) {
  118. $this->_sql = '
  119. delete from postn
  120. where nodeid = :nodeid';
  121. $this->prepare(
  122. 'Postn',
  123. array(
  124. 'nodeid' => $nodeid
  125. )
  126. );
  127. return $this->run('Message');
  128. }
  129. function getNode($from, $node, $limitf = false, $limitr = false) {
  130. $this->_sql = '
  131. select *, postn.aid, privacy.value as privacy from postn
  132. left outer join contact on postn.aid = contact.jid
  133. left outer join privacy on postn.nodeid = privacy.pkey
  134. where postn.session = :session
  135. and postn.jid = :jid
  136. and postn.node = :node
  137. order by postn.published desc';
  138. if($limitr)
  139. $this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf;
  140. $this->prepare(
  141. 'Postn',
  142. array(
  143. 'session' => $this->_user,
  144. 'jid' => $from,
  145. 'node' => $node
  146. )
  147. );
  148. return $this->run('ContactPostn');
  149. }
  150. function getFeed($limitf = false, $limitr = false) {
  151. $this->_sql = '
  152. select *, postn.aid as jid, privacy.value as privacy from postn
  153. left outer join contact on postn.aid = contact.jid
  154. left outer join privacy on postn.nodeid = privacy.pkey
  155. where postn.session = :session
  156. and postn.node like \'urn:xmpp:microblog:0\'
  157. and (postn.jid in (select rosterlink.jid from rosterlink where rosterlink.session = :session)
  158. or postn.jid = :session)
  159. order by postn.published desc';
  160. if($limitr)
  161. $this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf;
  162. $this->prepare(
  163. 'Postn',
  164. array(
  165. 'session' => $this->_user
  166. )
  167. );
  168. return $this->run('ContactPostn');
  169. }
  170. function getNews($limitf = false, $limitr = false) {
  171. $this->_sql = '
  172. select *, postn.aid as jid from postn
  173. left outer join contact on postn.aid = contact.jid
  174. left outer join subscription on
  175. postn.session = subscription.jid and
  176. postn.jid = subscription.server and
  177. postn.node = subscription.node
  178. where postn.session = :session
  179. and postn.node not like \'urn:xmpp:microblog:0:comments/%\'
  180. and postn.node not like \'urn:xmpp:inbox\'
  181. and subscription is not null
  182. order by postn.published desc';
  183. if($limitr)
  184. $this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf;
  185. $this->prepare(
  186. 'Postn',
  187. array(
  188. 'session' => $this->_user
  189. )
  190. );
  191. return $this->run('ContactPostn');
  192. }
  193. function getPublic($jid, $node) {
  194. $this->_sql = '
  195. select *, postn.aid, privacy.value as privacy from postn
  196. left outer join contact on postn.aid = contact.jid
  197. left outer join privacy on postn.nodeid = privacy.pkey
  198. where postn.jid = :jid
  199. and postn.session = :jid
  200. and postn.node = :node
  201. and privacy.value = 1
  202. order by postn.published desc';
  203. $this->prepare(
  204. 'Postn',
  205. array(
  206. 'jid' => $jid,
  207. 'node' => $node
  208. )
  209. );
  210. return $this->run('ContactPostn');
  211. }
  212. function getComments($posts) {
  213. $commentsid = '';
  214. if(is_array($posts)) {
  215. $i = 0;
  216. foreach($posts as $post) {
  217. if($i == 0)
  218. $commentsid = "'urn:xmpp:microblog:0:comments/".$post->nodeid."'";
  219. else
  220. $commentsid .= ",'urn:xmpp:microblog:0:comments/".$post->nodeid."'";
  221. $i++;
  222. }
  223. } else {
  224. $commentsid = "'urn:xmpp:microblog:0:comments/".$posts->nodeid."'";
  225. }
  226. // We request all the comments relative to our messages
  227. $this->_sql = '
  228. select *, postn.aid as jid from postn
  229. left outer join contact on postn.aid = contact.jid
  230. where postn.session = :session
  231. and postn.node in ('.$commentsid.')
  232. order by postn.published';
  233. $this->prepare(
  234. 'Postn',
  235. array(
  236. 'session' => $this->_user
  237. )
  238. );
  239. return $this->run('ContactPostn');
  240. }
  241. function clearPost() {
  242. $this->_sql = '
  243. delete from postn
  244. where session = :session';
  245. $this->prepare(
  246. 'Postn',
  247. array(
  248. 'session' => $this->_user
  249. )
  250. );
  251. return $this->run('Postn');
  252. }
  253. }