1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Twitter
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 Twitter API instance.
16 *
17 * @since 12.3
18 * @deprecated 4.0 Use the `joomla/twitter` package via Composer instead
19 */
20 class JTwitter
21 {
22 /**
23 * @var Registry Options for the JTwitter object.
24 * @since 12.3
25 */
26 protected $options;
27
28 /**
29 * @var JHttp The HTTP client object to use in sending HTTP requests.
30 * @since 12.3
31 */
32 protected $client;
33
34 /**
35 * @var JTwitterOAuth The OAuth client.
36 * @since 12.3
37 */
38 protected $oauth;
39
40 /**
41 * @var JTwitterFriends Twitter API object for friends.
42 * @since 12.3
43 */
44 protected $friends;
45
46 /**
47 * @var JTwitterUsers Twitter API object for users.
48 * @since 12.3
49 */
50 protected $users;
51
52 /**
53 * @var JTwitterHelp Twitter API object for help.
54 * @since 12.3
55 */
56 protected $help;
57
58 /**
59 * @var JTwitterStatuses Twitter API object for statuses.
60 * @since 12.3
61 */
62 protected $statuses;
63
64 /**
65 * @var JTwitterSearch Twitter API object for search.
66 * @since 12.3
67 */
68 protected $search;
69
70 /**
71 * @var JTwitterFavorites Twitter API object for favorites.
72 * @since 12.3
73 */
74 protected $favorites;
75
76 /**
77 * @var JTwitterDirectMessages Twitter API object for direct messages.
78 * @since 12.3
79 */
80 protected $directMessages;
81
82 /**
83 * @var JTwitterLists Twitter API object for lists.
84 * @since 12.3
85 */
86 protected $lists;
87
88 /**
89 * @var JTwitterPlaces Twitter API object for places & geo.
90 * @since 12.3
91 */
92 protected $places;
93
94 /**
95 * @var JTwitterTrends Twitter API object for trends.
96 * @since 12.3
97 */
98 protected $trends;
99
100 /**
101 * @var JTwitterBlock Twitter API object for block.
102 * @since 12.3
103 */
104 protected $block;
105
106 /**
107 * @var JTwitterProfile Twitter API object for profile.
108 * @since 12.3
109 */
110 protected $profile;
111
112 /**
113 * Constructor.
114 *
115 * @param JTwitterOauth $oauth The oauth client.
116 * @param Registry $options Twitter options object.
117 * @param JHttp $client The HTTP client object.
118 *
119 * @since 12.3
120 */
121 public function __construct(JTwitterOAuth $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://api.twitter.com/1.1');
129 }
130
131 /**
132 * Magic method to lazily create API objects
133 *
134 * @param string $name Name of property to retrieve
135 *
136 * @return JTwitterObject Twitter API object (statuses, users, favorites, etc.).
137 *
138 * @since 12.3
139 * @throws InvalidArgumentException
140 */
141 public function __get($name)
142 {
143 $class = 'JTwitter' . 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 JTwitter instance.
160 *
161 * @param string $key The name of the option to get.
162 *
163 * @return mixed The option value.
164 *
165 * @since 12.3
166 */
167 public function getOption($key)
168 {
169 return $this->options->get($key);
170 }
171
172 /**
173 * Set an option for the JTwitter 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 JTwitter This object for method chaining.
179 *
180 * @since 12.3
181 */
182 public function setOption($key, $value)
183 {
184 $this->options->set($key, $value);
185
186 return $this;
187 }
188 }
189