PageRenderTime 28ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/libraries/joomla/facebook/facebook.php

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