/libraries/joomla/facebook/facebook.php

https://github.com/fastslack/joomla-cms · PHP · 188 lines · 50 code · 26 blank · 112 comment · 3 complexity · e10f562016e348039536b318301f0333 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Facebook
  5. *
  6. * @copyright Copyright (C) 2005 - 2017 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. use Joomla\Registry\Registry;
  11. /**
  12. * Joomla Platform class for interacting with a Facebook API instance.
  13. *
  14. * @since 13.1
  15. * @deprecated 4.0 Use the `joomla/facebook` package via Composer instead
  16. */
  17. class JFacebook
  18. {
  19. /**
  20. * @var Registry Options for the Facebook object.
  21. * @since 13.1
  22. */
  23. protected $options;
  24. /**
  25. * @var JHttp The HTTP client object to use in sending HTTP requests.
  26. * @since 13.1
  27. */
  28. protected $client;
  29. /**
  30. * @var JFacebookOAuth The OAuth client.
  31. * @since 13.1
  32. */
  33. protected $oauth;
  34. /**
  35. * @var JFacebookUser Facebook API object for user.
  36. * @since 13.1
  37. */
  38. protected $user;
  39. /**
  40. * @var JFacebookStatus Facebook API object for status.
  41. * @since 13.1
  42. */
  43. protected $status;
  44. /**
  45. * @var JFacebookCheckin Facebook API object for checkin.
  46. * @since 13.1
  47. */
  48. protected $checkin;
  49. /**
  50. * @var JFacebookEvent Facebook API object for event.
  51. * @since 13.1
  52. */
  53. protected $event;
  54. /**
  55. * @var JFacebookGroup Facebook API object for group.
  56. * @since 13.1
  57. */
  58. protected $group;
  59. /**
  60. * @var JFacebookLink Facebook API object for link.
  61. * @since 13.1
  62. */
  63. protected $link;
  64. /**
  65. * @var JFacebookNote Facebook API object for note.
  66. * @since 13.1
  67. */
  68. protected $note;
  69. /**
  70. * @var JFacebookPost Facebook API object for post.
  71. * @since 13.1
  72. */
  73. protected $post;
  74. /**
  75. * @var JFacebookComment Facebook API object for comment.
  76. * @since 13.1
  77. */
  78. protected $comment;
  79. /**
  80. * @var JFacebookPhoto Facebook API object for photo.
  81. * @since 13.1
  82. */
  83. protected $photo;
  84. /**
  85. * @var JFacebookVideo Facebook API object for video.
  86. * @since 13.1
  87. */
  88. protected $video;
  89. /**
  90. * @var JFacebookAlbum Facebook API object for album.
  91. * @since 13.1
  92. */
  93. protected $album;
  94. /**
  95. * Constructor.
  96. *
  97. * @param JFacebookOAuth $oauth OAuth client.
  98. * @param Registry $options Facebook options object.
  99. * @param JHttp $client The HTTP client object.
  100. *
  101. * @since 13.1
  102. */
  103. public function __construct(JFacebookOAuth $oauth = null, Registry $options = null, JHttp $client = null)
  104. {
  105. $this->oauth = $oauth;
  106. $this->options = isset($options) ? $options : new Registry;
  107. $this->client = isset($client) ? $client : new JHttp($this->options);
  108. // Setup the default API url if not already set.
  109. $this->options->def('api.url', 'https://graph.facebook.com/');
  110. }
  111. /**
  112. * Magic method to lazily create API objects
  113. *
  114. * @param string $name Name of property to retrieve
  115. *
  116. * @return JFacebookObject Facebook API object (status, user, friends etc).
  117. *
  118. * @since 13.1
  119. * @throws InvalidArgumentException
  120. */
  121. public function __get($name)
  122. {
  123. $class = 'JFacebook' . ucfirst($name);
  124. if (class_exists($class))
  125. {
  126. if (false == isset($this->$name))
  127. {
  128. $this->$name = new $class($this->options, $this->client, $this->oauth);
  129. }
  130. return $this->$name;
  131. }
  132. throw new InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class));
  133. }
  134. /**
  135. * Get an option from the JFacebook instance.
  136. *
  137. * @param string $key The name of the option to get.
  138. *
  139. * @return mixed The option value.
  140. *
  141. * @since 13.1
  142. */
  143. public function getOption($key)
  144. {
  145. return $this->options->get($key);
  146. }
  147. /**
  148. * Set an option for the JFacebook instance.
  149. *
  150. * @param string $key The name of the option to set.
  151. * @param mixed $value The option value to set.
  152. *
  153. * @return JFacebook This object for method chaining.
  154. *
  155. * @since 13.1
  156. */
  157. public function setOption($key, $value)
  158. {
  159. $this->options->set($key, $value);
  160. return $this;
  161. }
  162. }