/src/system/application/controllers/feed.php

https://github.com/dstockto/joind.in · PHP · 229 lines · 132 code · 28 blank · 69 comment · 1 complexity · 22ba1e2fdf0cb985abb47cf78c706679 MD5 · raw file

  1. <?php
  2. /**
  3. * RSS Feed controller.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Joind.in
  8. * @package Controllers
  9. * @copyright 2009 - 2010 Joind.in
  10. * @license http://github.com/joindin/joind.in/blob/master/doc/LICENSE JoindIn
  11. * @link http://github.com/joindin/joind.in
  12. */
  13. /**
  14. * RSS Feed controller.
  15. *
  16. * Responsible for generating and outputting the RSS Feeds.
  17. *
  18. * @category Joind.in
  19. * @package Controllers
  20. * @copyright 2009 - 2010 Joind.in
  21. * @license http://github.com/joindin/joind.in/blob/master/doc/LICENSE JoindIn
  22. * @link http://github.com/joindin/joind.in
  23. *
  24. * @property CI_Config $config
  25. * @property CI_Loader $load
  26. * @property CI_Template $template
  27. * @property CI_Input $input
  28. * @property User_model $user_model
  29. */
  30. class Feed extends Controller
  31. {
  32. /**
  33. * Constructor, checks whether the user is logged in and passes this to
  34. * the template.
  35. *
  36. * @return void
  37. */
  38. function Feed()
  39. {
  40. parent::Controller();
  41. // check login status and fill the 'logged' parameter in the template
  42. $this->user_model->logStatus();
  43. }
  44. /**
  45. * The index page redirects the user to the homepage.
  46. *
  47. * @return void
  48. */
  49. function index()
  50. {
  51. redirect();
  52. }
  53. /**
  54. * Outputs a feed with the comments of a specific talk.
  55. *
  56. * @param integer $tid The id of the talk
  57. *
  58. * @return void
  59. */
  60. function talk($tid)
  61. {
  62. $this->load->helper('form');
  63. $this->load->model('talks_model');
  64. $com = $this->talks_model->getTalkComments($tid, null, null);
  65. $tlk = $this->talks_model->getTalks($tid);
  66. foreach ($com as $k => $v) {
  67. $guid = $this->config->site_url() . 'talk/view/' . $v->talk_id;
  68. $items[] = array(
  69. 'guid' => $guid,
  70. 'title' => 'Comment on: ' . $tlk[0]->talk_title,
  71. 'link' => $guid,
  72. 'description' => $v->comment,
  73. 'pubDate' => date('r', $v->date_made)
  74. );
  75. }
  76. $this->load->view(
  77. 'feed/feed', array(
  78. 'items' => $items
  79. )
  80. );
  81. }
  82. /**
  83. * Outputs a feed with the posts of the blog.
  84. *
  85. * @return void
  86. */
  87. function blog()
  88. {
  89. $this->load->model('blog_posts_model', 'bpm');
  90. $items = array();
  91. foreach ($this->bpm->getPostDetail() as $k => $v) {
  92. $guid = $this->config->site_url() . 'blog/view/' . $v->ID;
  93. $items[] = array(
  94. 'guid' => $guid,
  95. 'title' => $v->title,
  96. 'link' => $guid,
  97. 'description' => $v->content,
  98. 'pubDate' => date('r', $v->date_posted)
  99. );
  100. }
  101. $this->load->view(
  102. 'feed/feed', array(
  103. 'items' => $items
  104. )
  105. );
  106. }
  107. /**
  108. * Outputs a feed with the comments of a specific event.
  109. *
  110. * @param integer $eid The id of the event
  111. *
  112. * @return void
  113. */
  114. function event($eid)
  115. {
  116. $this->load->model('event_model');
  117. $this->load->model('event_comments_model', 'ecm');
  118. $ret = $this->ecm->getEventComments($eid);
  119. $edata = $this->event_model->getEventDetail($eid);
  120. $event_name = $edata[0]->event_name;
  121. $items = array();
  122. foreach ($ret as $k => $v) { //print_r($v);
  123. $guid = $this->config->site_url() . 'event/view/' . $eid . '#comments';
  124. $items[] = array(
  125. 'guid' => $guid,
  126. 'title' => 'Comment on Event "' . $event_name . '"',
  127. 'link' => $guid,
  128. 'description' => $v->comment,
  129. 'pubDate' => date('r', $v->date_made)
  130. );
  131. }
  132. $this->load->view(
  133. 'feed/feed', array(
  134. 'items' => $items,
  135. 'title' => 'Event Comments - "' . $event_name . '"'
  136. )
  137. );
  138. }
  139. /**
  140. * Outputs a feed with the event and talk comments of a specific user.
  141. *
  142. * @param integer $userId Id of the user
  143. *
  144. * @return void
  145. */
  146. function user($userId)
  147. {
  148. $this->load->model('talks_model');
  149. $this->load->model('talk_comments_model', 'tcm');
  150. $this->load->model('event_comments_model', 'ecm');
  151. $udata = $this->user_model->getUserById($userId);
  152. $talks = array();
  153. $comments = array();
  154. if (!empty($udata)) {
  155. $userId = $udata[0]->ID;
  156. //get the upcoming talks for this user
  157. $ret = $this->talks_model->getUserTalks($userId);
  158. //re-sort them by date_given
  159. $tmp = array();
  160. $out = array();
  161. foreach ($ret as $k => $v) {
  162. $tmp[$k] = $v->date_given;
  163. }
  164. arsort($tmp);
  165. foreach ($tmp as $k => $v) {
  166. $out[] = $ret[$k];
  167. }
  168. foreach ($out as $k => $v) {
  169. $talks[] = array(
  170. 'title' => $v->talk_title, 'desc' => $v->talk_desc,
  171. 'speaker' => $v->speaker,
  172. 'date' => date('r', $v->date_given), 'tid' => $v->tid,
  173. 'link' => $this->config->site_url() . 'talk/view/' . $v->tid
  174. );
  175. }
  176. //on to the comments!
  177. $ecom = $this->ecm->getUserComments($userId);
  178. foreach ($ecom as $k => $v) {
  179. $comments[] = array(
  180. 'content' => $v->comment,
  181. 'date' => date('r', $v->date_made), 'type' => 'event',
  182. 'event_id' => $v->event_id
  183. );
  184. }
  185. $tcom = $this->tcm->getUserComments($userId);
  186. foreach ($tcom as $k => $v) {
  187. $comments[] = array(
  188. 'content' => $v->comment,
  189. 'date' => date('r', $v->date_made), 'type' => 'talk',
  190. 'event_id' => ''
  191. );
  192. }
  193. }
  194. $data = array(
  195. 'talks' => $talks,
  196. 'comments' => $comments,
  197. 'username' => $this->session->userdata('username')
  198. );
  199. $this->load->view('feed/user', $data);
  200. }
  201. }