PageRenderTime 27ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/module/thread/get.php

https://github.com/pgBoard/pgBoard
PHP | 412 lines | 324 code | 71 blank | 17 comment | 56 complexity | 919e1b11338312f4ddbbb1a443e0aa86 MD5 | raw file
  1. <?php
  2. function main_get() { list_get(); }
  3. function list_get()
  4. {
  5. global $DB,$Core,$_title_;
  6. // Container for XML data
  7. $xmldata = '';
  8. $Query = new BoardQuery;
  9. $List = new BoardList;
  10. $List->type(LIST_THREAD);
  11. $_title_ = TITLE_BOARD;
  12. if(FUNDRAISER_ID != -1)
  13. {
  14. $goal = $Core->fundraiser_goal();
  15. $total = $Core->fundraiser_total();
  16. $remaining = number_format(str_replace(array("$",","),"",$goal)-str_replace(array("$",","),"",$total),2);
  17. $days = round((strtotime("2011-02-01")-time())/86400)+round((substr($total,1)/6.53));
  18. // $_title_ .= " <span class=\"smaller\">&raquo; $$remaining left to raise ($days days until bco shuts down)</span>";
  19. $_title_ .= " <span class=\"smaller\">&raquo; $$remaining left to raise</span>";
  20. }
  21. $List->title($_title_);
  22. $List->header();
  23. // stickies
  24. $DB->query($Query->list_thread(true,false,false));
  25. $List->data($DB->load_all());
  26. if (get('xml')) {
  27. $xmldata .= $List->thread_xml(true);
  28. } else {
  29. $List->thread(true);
  30. }
  31. // the rest
  32. $DB->query($Query->list_thread(false,cmd(2,true),cmd(3,true)));
  33. $List->data($DB->load_all());
  34. if (get('xml')) {
  35. $xmldata .= $List->thread_xml();
  36. } else {
  37. $List->thread();
  38. }
  39. // Build XML output
  40. if (get('xml')) {
  41. header("Content-type: text/xml");
  42. print "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
  43. print "<threads>\n";
  44. print $xmldata;
  45. print "</threads>";
  46. }
  47. $List->footer();
  48. }
  49. function view_get()
  50. {
  51. global $DB,$Core;
  52. $xmldata = '';
  53. if(!id(true)) return to_index();
  54. $Query = new BoardQuery;
  55. $View = new BoardView;
  56. $View->type(VIEW_THREAD);
  57. $View->increment_views();
  58. $subtitle="";
  59. // set flags for media link
  60. $flags="";
  61. if(!get('media')) $flags .= "&media=true";
  62. if(get('uncollapse')) $flags .= "&uncollapse=true";
  63. if(session('hidemedia'))
  64. {
  65. if(get('media')) $subtitle .= "<a href=\"".url()."$flags\">hide images</a>";
  66. if(!get('media')) $subtitle .= "<a href=\"".url()."$flags\">show images</a>";
  67. }
  68. if(!session('hidemedia'))
  69. {
  70. if(!get('media')) $subtitle .= "<a href=\"".url()."$flags\">hide images</a>";
  71. if(get('media')) $subtitle .= "<a href=\"".url()."$flags\">show images</a>";
  72. }
  73. // set flags for collase link
  74. $flags="";
  75. if(!get('uncollapse')) $flags .= "&uncollapse=true";
  76. if(get('media')) $flags .= "&media=true";
  77. if(!session('nocollapse'))
  78. {
  79. if(!get('uncollapse')) $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"".url()."$flags\">uncollapse</a>";
  80. if(get('uncollapse')) $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"".url()."$flags\">collapse</a>";
  81. }
  82. if(session('id'))
  83. {
  84. 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";
  85. else
  86. $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"javascript:;\" onclick=\"toggle_favorite(".id().");\"><span id=\"fcmd\">remove</span> favorite</a>\n";
  87. if(!$Core->check_ignored_thread(id()))
  88. $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"javascript:;\" onclick=\"toggle_ignore_thread(".id().");\"><span id=\"ignorecmd\">ignore</span></a>\n";
  89. else
  90. $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"javascript:;\" onclick=\"toggle_ignore_thread(".id().");\"><span id=\"ignorecmd\">unignore</span></a>\n";
  91. // undot
  92. if($Core->check_dotted(id())) $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"javascript:;\" onclick=\"undot(".id().");\" id=\"undot\">undot</a>\n";
  93. $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"#bottom\" id=\"last\">last &#8681;</a>\n";
  94. }
  95. if(session('admin'))
  96. {
  97. $Admin = new BoardAdmin;
  98. $sticky = $Admin->check_flag("thread","sticky",id());
  99. $locked = $Admin->check_flag("thread","locked",id());
  100. $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"/admin/togglesticky/".id()."/".md5(session_id())."/\">".($sticky ? "unsticky" :"sticky")."</a>";
  101. $subtitle .= SPACE.ARROW_RIGHT.SPACE."<a href=\"/admin/togglelocked/".id()."/".md5(session_id())."/\">".($locked ? "unlock" :"lock")."</a>";
  102. }
  103. $View->title($View->subject(id()));
  104. $View->subtitle($subtitle);
  105. $View->header();
  106. $DB->query($Query->view_thread(id(true),cmd(3,true),cmd(4,true)));
  107. $View->data($DB->load_all());
  108. if(get('xml'))
  109. {
  110. header("Content-type: text/xml");
  111. print "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
  112. print "<posts>\n";
  113. $View->thread_xml();
  114. print "</posts>";
  115. }
  116. else
  117. {
  118. if(get('uncollapse') && !session('nocollapse')) $_SESSION['nocollapse']=true;
  119. $View->thread();
  120. if(get('uncollapse')) unset($_SESSION['nocollapse']);
  121. }
  122. $View->footer();
  123. $View->member_update();
  124. }
  125. function firstpost_get()
  126. {
  127. global $DB,$Parse;
  128. if(!id()) return;
  129. $body = $DB->value("SELECT body FROM thread_post WHERE thread_id=$1 ORDER BY date_posted LIMIT 1",array(id()));
  130. print $Parse->run($body);
  131. }
  132. function viewpost_get()
  133. {
  134. global $DB;
  135. if(!id()) return;
  136. $body = $DB->value("SELECT body FROM thread_post WHERE id=$1",array(id()));
  137. print htmlentities($body);
  138. }
  139. function listbymember_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. if(!$id || !$name) return to_index();
  147. $Query = new BoardQuery;
  148. $List = new BoardList;
  149. $List->type(LIST_THREAD_HISTORY);
  150. $List->title("Threads Created: $name");
  151. $List->subtitle("page: $page");
  152. $List->header();
  153. $DB->query($Query->list_thread_bymember($id,cmd(3,true),cmd(4,true)));
  154. $List->data($DB->load_all());
  155. $List->thread();
  156. $List->footer();
  157. }
  158. function listbymemberposted_get()
  159. {
  160. global $DB,$Core;
  161. // get info
  162. $id = $Core->idfromname(id());
  163. $name = $Core->namefromid($id);
  164. $page = cmd(3,true)+1;
  165. if(!$id || !$name) return to_index();
  166. // get threads participiated in
  167. $DB->query("SELECT
  168. tm.thread_id
  169. FROM
  170. thread_member tm
  171. LEFT JOIN
  172. thread t
  173. ON
  174. t.id = tm.thread_id
  175. WHERE
  176. tm.member_id=$1
  177. AND
  178. tm.date_posted IS NOT null
  179. ORDER BY
  180. t.date_last_posted DESC",array($id));
  181. $threads = $DB->load_all('thread_id');
  182. if (!$threads) $threads = array(0);
  183. $Query = new BoardQuery;
  184. $List = new BoardList;
  185. $List->type(LIST_THREAD_HISTORY);
  186. $List->title("Threads Participated: $name");
  187. $List->subtitle("page: $page");
  188. $List->header();
  189. $DB->query($Query->list_thread(false,cmd(3,true),cmd(4,true),$threads));
  190. $List->data($DB->load_all());
  191. $List->thread();
  192. $List->footer();
  193. }
  194. function listfavoritesbymember_get()
  195. {
  196. global $DB,$Core;
  197. // get info
  198. $id = $Core->idfromname(id());
  199. $name = $Core->namefromid($id);
  200. $page = cmd(3,true)+1;
  201. if(!$id || !$name) return to_index();
  202. if(!FAVORITES_PUBLIC && $id != session('id')) return to_index();
  203. // get threads participiated in
  204. $DB->query("SELECT
  205. f.thread_id
  206. FROM
  207. favorite f
  208. LEFT JOIN
  209. thread t
  210. ON
  211. t.id = f.thread_id
  212. WHERE
  213. f.member_id=$1
  214. ORDER BY
  215. t.date_last_posted DESC",array($id));
  216. $threads = $DB->load_all('thread_id');
  217. if (!$threads) $threads = array(0);
  218. $Query = new BoardQuery;
  219. $List = new BoardList;
  220. $List->type(LIST_THREAD_HISTORY);
  221. $List->title("Favorites: $name");
  222. $List->subtitle("page: $page");
  223. $List->header();
  224. $DB->query($Query->list_thread(false,cmd(3,true),cmd(4,true),$threads));
  225. $List->data($DB->load_all());
  226. $List->thread();
  227. $List->footer();
  228. }
  229. function listignoredthreadsbymember_get()
  230. {
  231. global $DB,$Core;
  232. // get info
  233. $id = $Core->idfromname(id());
  234. $name = $Core->namefromid($id);
  235. $page = cmd(3,true)+1;
  236. if(!$id || !$name) return to_index();
  237. if(!IGNORED_THREADS_PUBLIC && $id != session('id')) return to_index();
  238. // get threads participiated in
  239. $DB->query("SELECT
  240. tm.thread_id
  241. FROM
  242. thread_member tm
  243. LEFT JOIN
  244. thread t
  245. ON
  246. t.id = tm.thread_id
  247. WHERE
  248. tm.member_id=$1 AND tm.ignore=true
  249. ORDER BY
  250. t.date_last_posted DESC",array($id));
  251. $threads = $DB->load_all('thread_id');
  252. if (!$threads) $threads = array(0);
  253. $Query = new BoardQuery;
  254. $List = new BoardList;
  255. $List->type(LIST_THREAD_HISTORY);
  256. $List->title("Ignored threads: $name");
  257. $List->subtitle("page: $page");
  258. $List->header();
  259. $DB->query($Query->list_thread(false,cmd(3,true),cmd(4,true),$threads, false, false));
  260. $List->data($DB->load_all());
  261. $List->thread();
  262. $List->footer();
  263. }
  264. function viewbymember_get()
  265. {
  266. global $DB,$Core;
  267. // get info
  268. $id = $Core->idfromname(id());
  269. $name = $Core->namefromid($id);
  270. $page = cmd(3,true)+1;
  271. if(!$id || !$name) return to_index();
  272. $Query = new BoardQuery;
  273. $View = new BoardView;
  274. $View->type(VIEW_THREAD_HISTORY);
  275. $View->title("Posts Created: $name");
  276. $View->subtitle("page $page");
  277. $View->header();
  278. $DB->query($Query->view_thread_bymember($id,cmd(3,true),cmd(4,true)));
  279. $View->data($DB->load_all());
  280. $View->thread();
  281. $View->footer();
  282. }
  283. function toggleignore_get()
  284. {
  285. global $DB,$Core;
  286. if(!session('id'))
  287. {
  288. print "failed to change";
  289. exit_clean();
  290. }
  291. if($Core->check_ignored_thread(id()))
  292. {
  293. // It's ignored -- unignore it
  294. $DB->query("UPDATE thread_member SET ignore=false WHERE thread_id=$1 AND member_id=$2",array(id(),session('id')));
  295. print "ignore";
  296. exit_clean();
  297. }
  298. else
  299. {
  300. $DB->query("UPDATE thread_member SET ignore=true WHERE thread_id=$1 AND member_id=$2",array(id(),session('id')));
  301. print "unignore";
  302. exit_clean();
  303. }
  304. }
  305. function togglefavorite_get()
  306. {
  307. global $DB,$Core;
  308. if(!session('id'))
  309. {
  310. print "failed to change";
  311. exit_clean();
  312. }
  313. if($Core->check_favorite(id()))
  314. {
  315. $DB->query("DELETE FROM favorite WHERE thread_id=$1 AND member_id=$2",array(id(),session('id')));
  316. print "add";
  317. exit_clean();
  318. }
  319. else
  320. {
  321. $insert = array();
  322. $insert['thread_id'] = id();
  323. $insert['member_id'] = session('id');
  324. $DB->insert("favorite",$insert);
  325. print "remove";
  326. exit_clean();
  327. }
  328. }
  329. function undot_get()
  330. {
  331. global $DB,$Core;
  332. if(!session('id'))
  333. {
  334. print "undot failed.";
  335. exit_clean();
  336. }
  337. $DB->query("UPDATE thread_member SET undot=true WHERE thread_id=$1 AND member_id=$2",array(id(),session('id')));
  338. print "undotted";
  339. exit_clean();
  340. }
  341. ?>