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.

240 lines
7.9 KiB

  1. <?php
  2. /**
  3. * @package Widgets
  4. *
  5. * @file Node.php
  6. * This file is part of MOVIM.
  7. *
  8. * @brief The items of a node
  9. *
  10. * @author Timothée Jaussoin <edhelas_at_gmail_dot_com>
  11. *
  12. * @version 1.0
  13. * @date 20 October 2010
  14. *
  15. * Copyright (C)2010 MOVIM project
  16. *
  17. * See COPYING for licensing information.
  18. */
  19. class Node extends WidgetCommon
  20. {
  21. function WidgetLoad()
  22. {
  23. $this->registerEvent('stream', 'onStream');
  24. $this->registerEvent('nostream', 'onStream');
  25. $this->registerEvent('pubsubsubscribed', 'onPubsubSubscribed');
  26. $this->registerEvent('pubsubsubscribederror', 'onPubsubSubscribedError');
  27. $this->registerEvent('pubsubunsubscribed', 'onPubsubUnsubscribed');
  28. }
  29. function onPubsubSubscribed($params)
  30. {
  31. $html = $this->prepareGroup($params[0], $params[1]);
  32. RPC::call('setBookmark');
  33. RPC::call('movim_fill', 'node', $html);
  34. RPC::call('movim_reload_this');
  35. }
  36. function onPubsubSubscribedError($params)
  37. {
  38. $this->onPubsubSubscribed($params);
  39. }
  40. function onPubsubUnsubscribed($params)
  41. {
  42. $this->onPubsubSubscribed($params);
  43. }
  44. function onStream($payload) {
  45. $html = $this->prepareGroup($payload['from'], $payload['node']);
  46. if($html == '')
  47. $html = t("Your feed cannot be loaded.");
  48. RPC::call('movim_fill', md5($payload['from'].$payload['node']), $html);
  49. }
  50. function ajaxGetItems($server, $node)
  51. {
  52. $r = new moxl\PubsubGetItems();
  53. $r->setTo($server)
  54. ->setNode($node)
  55. ->request();
  56. }
  57. function ajaxSubscribe($data, $server, $node)
  58. {
  59. $g = new moxl\PusubSubscribe();
  60. $g->setTo($server)
  61. ->setNode($node)
  62. ->setFrom($this->user->getLogin())
  63. ->setData($data)
  64. ->request();
  65. }
  66. function ajaxUnsubscribe($server, $node)
  67. {
  68. $sd = new \modl\SubscriptionDAO();
  69. foreach($sd->get($server, $node) as $s) {
  70. $g = new moxl\PubsubUnsubscribe();
  71. $g->setTo($server)
  72. ->setNode($node)
  73. ->setSubid($s->subid)
  74. ->setFrom($this->user->getLogin())
  75. ->request();
  76. }
  77. }
  78. function ajaxGetSubscriptions($server, $node)
  79. {
  80. $r = new moxl\PubsubGetSubscriptions();
  81. $r->setTo($server)
  82. ->setNode($node)
  83. ->request();
  84. }
  85. function prepareGroup($serverid, $groupid) {
  86. if($this->searchSubscription($serverid, $groupid))
  87. $button = '
  88. <a
  89. href="#"
  90. class="button color icon back"
  91. onclick="movim_toggle_display(\'#groupunsubscribe\')">
  92. '.t('Unsubscribe').'
  93. </a>';
  94. else
  95. $button = '
  96. <a
  97. href="#"
  98. class="button color green icon next"
  99. onclick="movim_toggle_display(\'#groupsubscribe\')">
  100. '.t('Subscribe').'
  101. </a>';
  102. $html = '
  103. <div class="breadcrumb">
  104. <a href="'.Route::urlize('explore').'">
  105. '.t('Explore').'
  106. </a>
  107. <a href="'.Route::urlize('server', $serverid).'">
  108. '.$serverid.'
  109. </a>
  110. <a href="'.Route::urlize('node', array($serverid, $groupid)).'">
  111. '.$groupid.'
  112. </a>
  113. <a>'.t('Posts').'</a>
  114. </div>
  115. <div class="posthead">
  116. '.$button.'
  117. <a
  118. href="#"
  119. onclick="'.$this->genCallAjax('ajaxGetItems', "'".$serverid."'", "'".$groupid."'").'
  120. this.className=\'button tiny icon loading\'; this.onclick=null;"
  121. class="button color blue icon refresh">
  122. '.('Refresh').'
  123. </a>
  124. <a
  125. class="button color orange icon yes"
  126. onclick="
  127. '.$this->genCallAjax('ajaxGetSubscriptions', "'".$serverid."'", "'".$groupid."'").'"
  128. >'.t('Get Subscription').'</a>
  129. </div>
  130. <div class="popup" id="groupsubscribe">
  131. <form name="groupsubscribe">
  132. <fieldset>
  133. <legend>'.t('Subscribe').'</legend>
  134. <div class="element large mini">
  135. <input type="checkbox" name="listgroup" id="listgroup"/>
  136. <span><label for="listgroup">'.t('Make your membership to this group public to your friends').'</label></span>
  137. </div>
  138. <div class="element large mini">
  139. <input type="text" name="title" value="'.$groupid.'" id="grouptitle"/>
  140. <span><label for="grouptitle">'.t('Give a nickname to this group if you want').'</label></span>
  141. </div>
  142. </fieldset>
  143. <a
  144. class="button tiny icon yes black merged left"
  145. onclick="
  146. '.$this->genCallAjax('ajaxSubscribe', "movim_parse_form('groupsubscribe')", "'".$serverid."'", "'".$groupid."'").'
  147. this.onclick=null;"
  148. >'.t('Subscribe').'</a><a
  149. class="button tiny icon black merged right"
  150. onclick="
  151. movim_toggle_display(\'#groupsubscribe\');"
  152. >'.t('Close').'</a>
  153. </form>
  154. </div>
  155. <div class="popup" id="groupunsubscribe">
  156. <form name="groupunsubscribe">
  157. <fieldset>
  158. <legend>'.t('Unsubscribe').'</legend>
  159. <div class="element large mini">
  160. <span>'.t('Are you sure ?').'</span>
  161. </div>
  162. </fieldset>
  163. <a
  164. class="button tiny icon yes black merged left"
  165. onclick="
  166. '.$this->genCallAjax('ajaxUnsubscribe', "'".$serverid."'", "'".$groupid."'").'
  167. this.onclick=null;"
  168. >'.t('Unsubscribe').'</a><a
  169. class="button tiny icon black merged right"
  170. onclick="
  171. movim_toggle_display(\'#groupunsubscribe\');"
  172. >'.t('Close').'</a>
  173. </form>
  174. </div>';
  175. $title = '';
  176. $pd = new modl\PostnDAO();
  177. $posts = $pd->getNode($serverid, $groupid, 0, 10);
  178. $html .= $title;
  179. if($this->searchSubscription($serverid, $groupid))
  180. $html .= $this->prepareSubmitForm($serverid, $groupid);
  181. $html .= $this->preparePosts($posts);
  182. return $html;
  183. }
  184. function searchSubscribed($server, $node) {
  185. $c = Cache::c('bookmark');
  186. foreach($c as $bookmark) {
  187. if(
  188. $bookmark['type'] == 'subscription' &&
  189. $bookmark['server'] == $server &&
  190. $bookmark['node'] == $node) {
  191. return true;
  192. }
  193. }
  194. return false;
  195. }
  196. function searchSubscription($server, $node) {
  197. $sd = new \modl\SubscriptionDAO();
  198. foreach($sd->get($server, $node) as $s) {
  199. if($s->subscription == 'subscribed')
  200. return true;
  201. }
  202. return false;
  203. }
  204. function build()
  205. {
  206. ?>
  207. <div class="tabelem protect red" id="node" title="<?php echo t('Posts'); ?>">
  208. <div id="<?php echo md5($_GET['s'].$_GET['n']); ?>">
  209. <?php echo $this->prepareGroup($_GET['s'], $_GET['n']); ?>
  210. </div>
  211. </div>
  212. <?php
  213. }
  214. }