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.

148 lines
4.2 KiB

  1. <?php
  2. use Moxl\Xec\Action\Pubsub\GetItems;
  3. class Menu extends WidgetCommon
  4. {
  5. private $_paging = 15;
  6. function load()
  7. {
  8. $this->registerEvent('post', 'onPost');
  9. $this->addjs('menu.js');
  10. }
  11. function onStream($count)
  12. {
  13. $view = $this->tpl();
  14. $view->assign('count', $count);
  15. $view->assign('refresh', $this->call('ajaxGetAll'));
  16. RPC::call('movim_posts_unread', $count);
  17. RPC::call('movim_fill', 'menu_refresh', $view->draw('_menu_refresh', true));
  18. }
  19. function onPost($packet)
  20. {
  21. $pd = new \Modl\PostnDAO;
  22. $count = $pd->getCountSince(Cache::c('since'));
  23. if($count > 0) {
  24. $post = $packet->content;
  25. if($post->isMicroblog()) {
  26. $cd = new \Modl\ContactDAO;
  27. $contact = $cd->get($post->jid);
  28. if($post->title == null) {
  29. $title = __('post.default_title');
  30. } else {
  31. $title = $post->title;
  32. }
  33. if(!$post->isMine()) Notification::append('news', $contact->getTrueName(), $title, $contact->getPhoto('s'), 2);
  34. } else {
  35. Notification::append('news', $post->title, $post->node, null, 2);
  36. }
  37. $this->onStream($count);
  38. }
  39. }
  40. function ajaxGetAll($page = 0)
  41. {
  42. $this->ajaxGet('all', null, null, $page);
  43. }
  44. function ajaxGetNews($page = 0)
  45. {
  46. $this->ajaxGet('news', null, null, $page);
  47. }
  48. function ajaxGetFeed($page = 0)
  49. {
  50. $this->ajaxGet('feed', null, null, $page);
  51. }
  52. function ajaxGetNode($server = null, $node = null, $page = 0)
  53. {
  54. $this->ajaxGet('node', $server, $node, $page);
  55. }
  56. function ajaxGet($type = 'all', $server = null, $node = null, $page = 0)
  57. {
  58. $html = $this->prepareList($type, $server, $node, $page);
  59. if($page > 0) {
  60. RPC::call('movim_append', 'menu_wrapper', $html);
  61. } else {
  62. RPC::call('movim_fill', 'menu_widget', $html);
  63. RPC::call('movim_posts_unread', 0);
  64. }
  65. RPC::call('Menu.refresh');
  66. }
  67. function ajaxRefresh()
  68. {
  69. Notification::append(null, $this->__('menu.refresh'));
  70. $sd = new \modl\SubscriptionDAO();
  71. $subscriptions = $sd->getSubscribed();
  72. foreach($subscriptions as $s) {
  73. $r = new GetItems;
  74. $r->setTo($s->server)
  75. ->setNode($s->node)
  76. ->request();
  77. }
  78. }
  79. function prepareList($type = 'all', $server = null, $node = null, $page = 0) {
  80. $view = $this->tpl();
  81. $pd = new \Modl\PostnDAO;
  82. $count = $pd->getCountSince(Cache::c('since'));
  83. // getting newer, not older
  84. if($page == 0 || $page == ""){
  85. $count = 0;
  86. Cache::c('since', date(DATE_ISO8601, strtotime($pd->getLastDate())));
  87. }
  88. $next = $page + 1;
  89. switch($type) {
  90. case 'all' :
  91. $view->assign('history', $this->call('ajaxGetAll', $next));
  92. $items = $pd->getAllPosts(false, $page * $this->_paging + $count, $this->_paging);
  93. break;
  94. case 'news' :
  95. $view->assign('history', $this->call('ajaxGetNews', $next));
  96. $items = $pd->getNews($page * $this->_paging + $count, $this->_paging);
  97. break;
  98. case 'feed' :
  99. $view->assign('history', $this->call('ajaxGetFeed', $next));
  100. $items = $pd->getFeed($page * $this->_paging + $count, $this->_paging);
  101. break;
  102. case 'node' :
  103. $view->assign('history', $this->call('ajaxGetNode', '"'.$server.'"', '"'.$node.'"', '"'.$next.'"'));
  104. $items = $pd->getNode($server, $node, $page * $this->_paging + $count, $this->_paging);
  105. break;
  106. }
  107. $view->assign('items', $items);
  108. $view->assign('page', $page);
  109. $view->assign('paging', $this->_paging);
  110. $html = $view->draw('_menu_list', true);
  111. if($page == 0 || $page == ""){
  112. $view = $this->tpl();
  113. $html .= $view->draw('_menu_add', true);
  114. }
  115. return $html;
  116. }
  117. function display()
  118. {
  119. }
  120. }