/libraries/joomla/facebook/group.php

https://gitlab.com/vitaliylukin91/lavka · PHP · 251 lines · 90 code · 25 blank · 136 comment · 9 complexity · 355ef04d7587837daf558e0482632bf9 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Facebook
  5. *
  6. * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die();
  10. /**
  11. * Facebook API Group class for the Joomla Platform.
  12. *
  13. * @see http://developers.facebook.com/docs/reference/api/group/
  14. * @since 13.1
  15. */
  16. class JFacebookGroup extends JFacebookObject
  17. {
  18. /**
  19. * Method to read a group. Requires authentication and user_groups or friends_groups permission for non-public groups.
  20. *
  21. * @param string $group The group id.
  22. *
  23. * @return mixed The decoded JSON response or false if the client is not authenticated.
  24. *
  25. * @since 13.1
  26. */
  27. public function getGroup($group)
  28. {
  29. return $this->get($group);
  30. }
  31. /**
  32. * Method to get the group's wall. Requires authentication and user_groups or friends_groups permission for non-public groups.
  33. *
  34. * @param string $group The group id.
  35. * @param integer $limit The number of objects per page.
  36. * @param integer $offset The object's number on the page.
  37. * @param string $until A unix timestamp or any date accepted by strtotime.
  38. * @param string $since A unix timestamp or any date accepted by strtotime.
  39. *
  40. * @return mixed The decoded JSON response or false if the client is not authenticated.
  41. *
  42. * @since 13.1
  43. */
  44. public function getFeed($group, $limit = 0, $offset = 0, $until = null, $since = null)
  45. {
  46. return $this->getConnection($group, 'feed', '', $limit, $offset, $until, $since);
  47. }
  48. /**
  49. * Method to get the group's members. Requires authentication and user_groups or friends_groups permission for non-public groups.
  50. *
  51. * @param string $group The group id.
  52. * @param integer $limit The number of objects per page.
  53. * @param integer $offset The object's number on the page.
  54. *
  55. * @return mixed The decoded JSON response or false if the client is not authenticated.
  56. *
  57. * @since 13.1
  58. */
  59. public function getMembers($group, $limit = 0, $offset = 0)
  60. {
  61. return $this->getConnection($group, 'members', '', $limit, $offset);
  62. }
  63. /**
  64. * Method to get the group's docs. Requires authentication and user_groups or friends_groups permission for non-public groups.
  65. *
  66. * @param string $group The group id.
  67. * @param integer $limit The number of objects per page.
  68. * @param integer $offset The object's number on the page.
  69. * @param string $until A unix timestamp or any date accepted by strtotime.
  70. * @param string $since A unix timestamp or any date accepted by strtotime.
  71. *
  72. * @return mixed The decoded JSON response or false if the client is not authenticated.
  73. *
  74. * @since 13.1
  75. */
  76. public function getDocs($group, $limit = 0, $offset = 0, $until = null, $since = null)
  77. {
  78. return $this->getConnection($group, 'docs', '', $limit, $offset, $until, $since);
  79. }
  80. /**
  81. * Method to get the groups's picture. Requires authentication and user_groups or friends_groups permission.
  82. *
  83. * @param string $group The group id.
  84. * @param string $type To request a different photo use square | small | normal | large.
  85. *
  86. * @return string The URL to the group's picture.
  87. *
  88. * @since 13.1
  89. */
  90. public function getPicture($group, $type = null)
  91. {
  92. if ($type)
  93. {
  94. $type = '?type=' . $type;
  95. }
  96. return $this->getConnection($group, 'picture', $type);
  97. }
  98. /**
  99. * Method to post a link on group's wall. Requires authentication and publish_stream permission.
  100. *
  101. * @param string $group The group id.
  102. * @param string $link Link URL.
  103. * @param strin $message Link message.
  104. *
  105. * @return mixed The decoded JSON response or false if the client is not authenticated.
  106. *
  107. * @since 13.1
  108. */
  109. public function createLink($group, $link, $message = null)
  110. {
  111. // Set POST request parameters.
  112. $data = array();
  113. $data['link'] = $link;
  114. if ($message)
  115. {
  116. $data['message'] = $message;
  117. }
  118. return $this->createConnection($group, 'feed', $data);
  119. }
  120. /**
  121. * Method to delete a link. Requires authentication.
  122. *
  123. * @param mixed $link The Link ID.
  124. *
  125. * @return boolean Returns true if successful, and false otherwise.
  126. *
  127. * @since 13.1
  128. */
  129. public function deleteLink($link)
  130. {
  131. return $this->deleteConnection($link);
  132. }
  133. /**
  134. * Method to post on group's wall. Message or link parameter is required. Requires authentication and publish_stream permission.
  135. *
  136. * @param string $group The group id.
  137. * @param string $message Post message.
  138. * @param string $link Post URL.
  139. * @param string $picture Post thumbnail image (can only be used if link is specified)
  140. * @param string $name Post name (can only be used if link is specified).
  141. * @param string $caption Post caption (can only be used if link is specified).
  142. * @param string $description Post description (can only be used if link is specified).
  143. * @param array $actions Post actions array of objects containing name and link.
  144. *
  145. * @return mixed The decoded JSON response or false if the client is not authenticated.
  146. *
  147. * @since 13.1
  148. */
  149. public function createPost($group, $message = null, $link = null, $picture = null, $name = null, $caption = null,
  150. $description = null, $actions = null)
  151. {
  152. // Set POST request parameters.
  153. if ($message)
  154. {
  155. $data['message'] = $message;
  156. }
  157. if ($link)
  158. {
  159. $data['link'] = $link;
  160. }
  161. if ($name)
  162. {
  163. $data['name'] = $name;
  164. }
  165. if ($caption)
  166. {
  167. $data['caption'] = $caption;
  168. }
  169. if ($description)
  170. {
  171. $data['description'] = $description;
  172. }
  173. if ($actions)
  174. {
  175. $data['actions'] = $actions;
  176. }
  177. if ($picture)
  178. {
  179. $data['picture'] = $picture;
  180. }
  181. return $this->createConnection($group, 'feed', $data);
  182. }
  183. /**
  184. * Method to delete a post. Note: you can only delete the post if it was created by the current user. Requires authentication.
  185. *
  186. * @param string $post The Post ID.
  187. *
  188. * @return boolean Returns true if successful, and false otherwise.
  189. *
  190. * @since 13.1
  191. */
  192. public function deletePost($post)
  193. {
  194. return $this->deleteConnection($post);
  195. }
  196. /**
  197. * Method to post a status message on behalf of the user on the group's wall. Requires authentication and publish_stream permission.
  198. *
  199. * @param string $group The group id.
  200. * @param string $message Status message content.
  201. *
  202. * @return mixed The decoded JSON response or false if the client is not authenticated.
  203. *
  204. * @since 13.1
  205. */
  206. public function createStatus($group, $message)
  207. {
  208. // Set POST request parameters.
  209. $data = array();
  210. $data['message'] = $message;
  211. return $this->createConnection($group, 'feed', $data);
  212. }
  213. /**
  214. * Method to delete a status. Note: you can only delete the status if it was created by the current user. Requires authentication.
  215. *
  216. * @param string $status The Status ID.
  217. *
  218. * @return boolean Returns true if successful, and false otherwise.
  219. *
  220. * @since 13.1
  221. */
  222. public function deleteStatus($status)
  223. {
  224. return $this->deleteConnection($status);
  225. }
  226. }