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