/libraries/joomla/facebook/photo.php

https://gitlab.com/vitaliylukin91/lavka · PHP · 246 lines · 84 code · 24 blank · 138 comment · 8 complexity · b3b3650b90956cf35af3eb11c2396a25 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 Photo class for the Joomla Platform.
  12. *
  13. * @see http://developers.facebook.com/docs/reference/api/photo/
  14. * @since 13.1
  15. */
  16. class JFacebookPhoto extends JFacebookObject
  17. {
  18. /**
  19. * Method to get a photo. Requires authentication and user_photos or friends_photos permission for private photos.
  20. *
  21. * @param string $photo The photo 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 getPhoto($photo)
  28. {
  29. return $this->get($photo);
  30. }
  31. /**
  32. * Method to get a photo's comments. Requires authentication and user_photos or friends_photos permission for private photos.
  33. *
  34. * @param string $photo The photo 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 getComments($photo, $limit = 0, $offset = 0, $until = null, $since = null)
  45. {
  46. return $this->getConnection($photo, 'comments', '', $limit, $offset, $until, $since);
  47. }
  48. /**
  49. * Method to comment on a photo. Requires authentication and publish_stream permission, user_photos or friends_photos permission for private photos.
  50. *
  51. * @param string $photo The photo id.
  52. * @param string $message The comment's text.
  53. *
  54. * @return mixed The decoded JSON response or false if the client is not authenticated.
  55. *
  56. * @since 13.1
  57. */
  58. public function createComment($photo, $message)
  59. {
  60. // Set POST request parameters.
  61. $data['message'] = $message;
  62. return $this->createConnection($photo, 'comments', $data);
  63. }
  64. /**
  65. * Method to delete a comment. Requires authentication and publish_stream permission, user_photos or friends_photos permission for private photos.
  66. *
  67. * @param string $comment The comment's id.
  68. *
  69. * @return boolean Returns true if successful, and false otherwise.
  70. *
  71. * @since 13.1
  72. */
  73. public function deleteComment($comment)
  74. {
  75. return $this->deleteConnection($comment);
  76. }
  77. /**
  78. * Method to get photo's likes. Requires authentication and user_photos or friends_photos permission for private photos.
  79. *
  80. * @param string $photo The photo id.
  81. * @param integer $limit The number of objects per page.
  82. * @param integer $offset The object's number on the page.
  83. * @param string $until A unix timestamp or any date accepted by strtotime.
  84. * @param string $since A unix timestamp or any date accepted by strtotime.
  85. *
  86. * @return mixed The decoded JSON response or false if the client is not authenticated.
  87. *
  88. * @since 13.1
  89. */
  90. public function getLikes($photo, $limit = 0, $offset = 0, $until = null, $since = null)
  91. {
  92. return $this->getConnection($photo, 'likes', '', $limit, $offset, $until, $since);
  93. }
  94. /**
  95. * Method to like a photo. Requires authentication and publish_stream permission, user_photos or friends_photos permission for private photos.
  96. *
  97. * @param string $photo The photo id.
  98. *
  99. * @return boolean Returns true if successful, and false otherwise.
  100. *
  101. * @since 13.1
  102. */
  103. public function createLike($photo)
  104. {
  105. return $this->createConnection($photo, 'likes');
  106. }
  107. /**
  108. * Method to unlike a photo. Requires authentication and publish_stream permission, user_photos or friends_photos permission for private photos.
  109. *
  110. * @param string $photo The photo id.
  111. *
  112. * @return boolean Returns true if successful, and false otherwise.
  113. *
  114. * @since 13.1
  115. */
  116. public function deleteLike($photo)
  117. {
  118. return $this->deleteConnection($photo, 'likes');
  119. }
  120. /**
  121. * Method to get the Users tagged in the photo. Requires authentication and user_photos or friends_photos permission for private photos.
  122. *
  123. * @param string $photo The photo id.
  124. * @param integer $limit The number of objects per page.
  125. * @param integer $offset The object's number on the page.
  126. * @param string $until A unix timestamp or any date accepted by strtotime.
  127. * @param string $since A unix timestamp or any date accepted by strtotime.
  128. *
  129. * @return mixed The decoded JSON response or false if the client is not authenticated.
  130. *
  131. * @since 13.1
  132. */
  133. public function getTags($photo, $limit = 0, $offset = 0, $until = null, $since = null)
  134. {
  135. return $this->getConnection($photo, 'tags', '', $limit, $offset, $until, $since);
  136. }
  137. /**
  138. * Method to tag one or more Users in a photo. $to or $tag_text required.
  139. * Requires authentication and publish_stream permission, user_photos permission for private photos.
  140. *
  141. * @param string $photo The photo id.
  142. * @param mixed $to ID of the User or an array of Users to tag in the photo: [{"id":"1234"}, {"id":"12345"}].
  143. * @param string $tag_text A text string to tag.
  144. * @param integer $x x coordinate of tag, as a percentage offset from the left edge of the picture.
  145. * @param integer $y y coordinate of tag, as a percentage offset from the top edge of the picture.
  146. *
  147. * @return boolean Returns true if successful, and false otherwise.
  148. *
  149. * @since 13.1
  150. */
  151. public function createTag($photo, $to = null, $tag_text = null, $x = null, $y = null)
  152. {
  153. // Set POST request parameters.
  154. if (is_array($to))
  155. {
  156. $data['tags'] = $to;
  157. }
  158. else
  159. {
  160. $data['to'] = $to;
  161. }
  162. if ($tag_text)
  163. {
  164. $data['tag_text'] = $tag_text;
  165. }
  166. if ($x)
  167. {
  168. $data['x'] = $x;
  169. }
  170. if ($y)
  171. {
  172. $data['y'] = $y;
  173. }
  174. return $this->createConnection($photo, 'tags', $data);
  175. }
  176. /**
  177. * Method to update the position of the tag for a particular Users in a photo.
  178. * Requires authentication and publish_stream permission, user_photos permission for private photos.
  179. *
  180. * @param string $photo The photo id.
  181. * @param string $to ID of the User to update tag in the photo.
  182. * @param integer $x x coordinate of tag, as a percentage offset from the left edge of the picture.
  183. * @param integer $y y coordinate of tag, as a percentage offset from the top edge of the picture.
  184. *
  185. * @return boolean Returns true if successful, and false otherwise.
  186. *
  187. * @since 13.1
  188. */
  189. public function updateTag($photo, $to, $x = null, $y = null)
  190. {
  191. // Set POST request parameters.
  192. $data['to'] = $to;
  193. if ($x)
  194. {
  195. $data['x'] = $x;
  196. }
  197. if ($y)
  198. {
  199. $data['y'] = $y;
  200. }
  201. return $this->createConnection($photo, 'tags', $data);
  202. }
  203. /**
  204. * Method to get the album-sized view of the photo. Requires authentication and user_photos or friends_photos permission for private photos.
  205. *
  206. * @param string $photo The photo id.
  207. * @param boolean $redirect If false this will return the URL of the picture without a 302 redirect.
  208. *
  209. * @return string URL of the picture.
  210. *
  211. * @since 13.1
  212. */
  213. public function getPicture($photo, $redirect = true)
  214. {
  215. $extra_fields = '';
  216. if ($redirect == false)
  217. {
  218. $extra_fields = '?redirect=false';
  219. }
  220. return $this->getConnection($photo, 'picture', $extra_fields);
  221. }
  222. }