/module/thread/get.php

https://github.com/imeyer/pgBoard · PHP · 266 lines · 207 code · 51 blank · 8 comment · 24 complexity · 6f82505cfb03d99bad76c61a55688a11 MD5 · raw file

  1. <?php
  2. function main_get() { list_get(); }
  3. function list_get()
  4. {
  5. global $DB,$Core,$_title_;
  6. $Query = new BoardQuery;
  7. $List = new BoardList;
  8. $List->type(LIST_THREAD);
  9. $_title_ = TITLE_BOARD;
  10. if(FUNDRAISER_ID != -1)
  11. {
  12. $goal = $Core->fundraiser_goal();
  13. $total = $Core->fundraiser_total();
  14. $remaining = number_format(str_replace(array("$",","),"",$goal)-str_replace(array("$",","),"",$total),2);
  15. $_title_ .= " <span class=\"smaller\">&raquo; $$remaining left to raise!</span>";
  16. }
  17. $List->title($_title_);
  18. $List->header();
  19. // stickies
  20. $DB->query($Query->list_thread(true,false,false));
  21. $List->data($DB->load_all());
  22. $List->thread(true);
  23. // the rest
  24. $DB->query($Query->list_thread(false,cmd(2,true),cmd(3,true)));
  25. $List->data($DB->load_all());
  26. $List->thread();
  27. $List->footer();
  28. }
  29. function view_get()
  30. {
  31. global $DB,$Core;
  32. if(!id(true)) return to_index();
  33. $Query = new BoardQuery;
  34. $View = new BoardView;
  35. $View->type(VIEW_THREAD);
  36. $View->increment_views();
  37. $subtitle = "";
  38. if(session('hidemedia'))
  39. {
  40. if(get('media')) $subtitle .= "<a href=\"".url()."\">hide images</a>";
  41. if(!get('media')) $subtitle .= "<a href=\"".url()."&media=true\">show images</a>";
  42. }
  43. if(!session('hidemedia'))
  44. {
  45. if(!get('media')) $subtitle .= "<a href=\"".url()."&media=true\">hide images</a>";
  46. if(get('media')) $subtitle .= "<a href=\"".url()."\">show images</a>";
  47. }
  48. if(session('id'))
  49. {
  50. if(!$Core->check_favorite(id())) $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"javascript:;\" onclick=\"toggle_favorite(".id().");\"><span id=\"fcmd\">add</span> favorite</a>\n";
  51. else
  52. $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"javascript:;\" onclick=\"toggle_favorite(".id().");\"><span id=\"fcmd\">remove</span> favorite</a>\n";
  53. }
  54. if(session('admin'))
  55. {
  56. $Admin = new BoardAdmin;
  57. $sticky = $Admin->check_flag("sticky",id());
  58. $locked = $Admin->check_flag("locked",id());
  59. $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"/admin/togglesticky/".id()."\">".($sticky ? "unsticky" :"sticky")."</a>";
  60. $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"/admin/togglelocked/".id()."\">".($locked ? "unlock" :"lock")."</a>";
  61. }
  62. $View->title($View->subject(id()));
  63. $View->subtitle($subtitle);
  64. $View->header();
  65. $DB->query($Query->view_thread(id(true),cmd(3,true),cmd(4,true)));
  66. $View->data($DB->load_all());
  67. $View->thread();
  68. $View->footer();
  69. $View->member_update();
  70. }
  71. function firstpost_get()
  72. {
  73. global $DB,$Parse;
  74. if(!id()) return;
  75. $body = $DB->value("SELECT body FROM thread_post WHERE thread_id=$1 ORDER BY date_posted LIMIT 1",array(id()));
  76. print $Parse->run($body);
  77. }
  78. function viewpost_get()
  79. {
  80. global $DB;
  81. if(!id()) return;
  82. $body = $DB->value("SELECT body FROM thread_post WHERE id=$1",array(id()));
  83. print htmlentities($body);
  84. }
  85. function listbymember_get()
  86. {
  87. global $DB,$Core;
  88. // get info
  89. $id = $Core->idfromname(id());
  90. $name = $Core->namefromid($id);
  91. $page = cmd(3,true)+1;
  92. if(!$id || !$name) return to_index();
  93. $Query = new BoardQuery;
  94. $List = new BoardList;
  95. $List->type(LIST_THREAD_HISTORY);
  96. $List->title("Threads Created: $name");
  97. $List->subtitle("page: $page");
  98. $List->header();
  99. $DB->query($Query->list_thread_bymember($id,cmd(3,true),cmd(4,true)));
  100. $List->data($DB->load_all());
  101. $List->thread();
  102. $List->footer();
  103. }
  104. function listbymemberposted_get()
  105. {
  106. global $DB,$Core;
  107. // get info
  108. $id = $Core->idfromname(id());
  109. $name = $Core->namefromid($id);
  110. $page = cmd(3,true)+1;
  111. // get threads participiated in
  112. $DB->query("SELECT
  113. tm.thread_id
  114. FROM
  115. thread_member tm
  116. LEFT JOIN
  117. thread t
  118. ON
  119. t.id = tm.thread_id
  120. WHERE
  121. tm.member_id=$1
  122. AND
  123. tm.date_posted IS NOT null
  124. ORDER BY
  125. t.date_last_posted DESC",array($id));
  126. $threads = $DB->load_all('thread_id');
  127. if(!$id || !$name) return to_index();
  128. $Query = new BoardQuery;
  129. $List = new BoardList;
  130. $List->type(LIST_THREAD_HISTORY);
  131. $List->title("Threads Participated: $name");
  132. $List->subtitle("page: $page");
  133. $List->header();
  134. $DB->query($Query->list_thread(false,cmd(3,true),cmd(4,true),$threads));
  135. $List->data($DB->load_all());
  136. $List->thread();
  137. $List->footer();
  138. }
  139. function listfavoritesbymember_get()
  140. {
  141. global $DB,$Core;
  142. // get info
  143. $id = $Core->idfromname(id());
  144. $name = $Core->namefromid($id);
  145. $page = cmd(3,true)+1;
  146. // get threads participiated in
  147. $DB->query("SELECT
  148. f.thread_id
  149. FROM
  150. favorite f
  151. LEFT JOIN
  152. thread t
  153. ON
  154. t.id = f.thread_id
  155. WHERE
  156. f.member_id=$1
  157. ORDER BY
  158. t.date_last_posted DESC",array($id));
  159. $threads = $DB->load_all('thread_id');
  160. if(!$id || !$name) return to_index();
  161. $Query = new BoardQuery;
  162. $List = new BoardList;
  163. $List->type(LIST_THREAD_HISTORY);
  164. $List->title("Favorites: $name");
  165. $List->subtitle("page: $page");
  166. $List->header();
  167. $DB->query($Query->list_thread(false,cmd(3,true),cmd(4,true),$threads));
  168. $List->data($DB->load_all());
  169. $List->thread();
  170. $List->footer();
  171. }
  172. function viewbymember_get()
  173. {
  174. global $DB,$Core;
  175. // get info
  176. $id = $Core->idfromname(id());
  177. $name = $Core->namefromid($id);
  178. $page = cmd(3,true)+1;
  179. if(!$id || !$name) return to_index();
  180. $Query = new BoardQuery;
  181. $View = new BoardView;
  182. $View->type(VIEW_THREAD_HISTORY);
  183. $View->title("Posts Created: $name");
  184. $View->subtitle("page $page");
  185. $View->header();
  186. $DB->query($Query->view_thread_bymember($id,cmd(3,true),cmd(4,true)));
  187. $View->data($DB->load_all());
  188. $View->thread();
  189. $View->footer();
  190. }
  191. function togglefavorite_get()
  192. {
  193. global $DB,$Core;
  194. if(!session('id'))
  195. {
  196. print "failed to change";
  197. exit_clean();
  198. }
  199. if($Core->check_favorite(id()))
  200. {
  201. $DB->query("DELETE FROM favorite WHERE thread_id=$1 AND member_id=$2",array(id(),session('id')));
  202. print "add";
  203. exit_clean();
  204. }
  205. else
  206. {
  207. $insert = array();
  208. $insert['thread_id'] = id();
  209. $insert['member_id'] = session('id');
  210. $DB->insert("favorite",$insert);
  211. print "remove";
  212. exit_clean();
  213. }
  214. }
  215. ?>