1
|
|
|
<?php |
2
|
|
|
namespace SEOstats\Services; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* SEOstats extension for Social-Media data. |
6
|
|
|
* |
7
|
|
|
* @package SEOstats |
8
|
|
|
* @author Stephan Schmitz <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2010 - present Stephan Schmitz |
10
|
|
|
* @license http://eyecatchup.mit-license.org/ MIT License |
11
|
|
|
* @updated 2014/01/19 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
use SEOstats\SEOstats as SEOstats; |
15
|
|
|
use SEOstats\Config as Config; |
16
|
|
|
use SEOstats\Helper as Helper; |
17
|
|
|
|
18
|
|
|
class Social extends SEOstats |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* For backward compatibility |
22
|
|
|
* @deprecated |
23
|
|
|
*/ |
24
|
|
|
public static function getGoogleShares($url = false) { |
25
|
|
|
return self::getGooglePlusShares($url); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
/** |
28
|
|
|
* Returns the total count of +1s for $url on Google+. |
29
|
|
|
* |
30
|
|
|
* @access public |
31
|
|
|
* @param url string The URL to check. |
32
|
|
|
* @return integer Returns the total count of Plus Ones for a URL. |
33
|
|
|
*/ |
34
|
|
|
public static function getGooglePlusShares($url = false) |
35
|
|
|
{ |
36
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
37
|
|
|
$dataUrl = sprintf(Config\Services::GOOGLE_PLUSONE_URL, urlencode($url)); |
38
|
|
|
$html = parent::_getPage($dataUrl); |
|
|
|
|
39
|
|
|
@preg_match_all('/window\.__SSR\s\=\s\{c:\s(\d+?)\./', $html, $match, PREG_SET_ORDER); |
|
|
|
|
40
|
|
|
|
41
|
|
|
return (1 === sizeof($match) && 2 === sizeof($match[0])) ? intval($match[0][1]) : parent::noDataDefaultValue(); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns an array of interaction counts (shares, likes, comments, clicks) for $url on Facebook. |
46
|
|
|
* |
47
|
|
|
* @access public |
48
|
|
|
* @link http://developers.facebook.com/docs/reference/fql/link_stat/ |
49
|
|
|
* @param url string The URL to check. |
50
|
|
|
* @return array Returns an array of total counts for 1. all Facebook interactions, |
51
|
|
|
* 2. FB shares, 3. FB likes, 4. FB comments and 5. outgoing clicks for a URL. |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
public static function getFacebookShares($url = false) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
56
|
|
|
$fql = sprintf('SELECT total_count, share_count, like_count, comment_count, commentsbox_count, click_count FROM link_stat WHERE url="%s"', $url); |
57
|
|
|
$dataUrl = sprintf(Config\Services::FB_LINKSTATS_URL, rawurlencode($fql)); |
58
|
|
|
|
59
|
|
|
$jsonData = parent::_getPage($dataUrl); |
|
|
|
|
60
|
|
|
$phpArray = Helper\Json::decode($jsonData, true); |
61
|
|
|
|
62
|
|
|
return isset($phpArray[0]) ? $phpArray[0] : parent::noDataDefaultValue(); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the total count of mentions of $url on Twitter. |
67
|
|
|
* |
68
|
|
|
* @access public |
69
|
|
|
* @param url string The URL to check. |
70
|
|
|
* @return integer Returns the total count of Twitter mentions for a URL. |
71
|
|
|
* @link https://dev.twitter.com/discussions/5653#comment-11514 |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public static function getTwitterShares($url = false) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
76
|
|
|
$dataUrl = sprintf(Config\Services::TWEETCOUNT_URL, urlencode($url)); |
77
|
|
|
|
78
|
|
|
$jsonData = parent::_getPage($dataUrl); |
|
|
|
|
79
|
|
|
$phpArray = Helper\Json::decode($jsonData, true); |
80
|
|
|
|
81
|
|
|
return isset($phpArray['count']) ? intval($phpArray['count']) : parent::noDataDefaultValue(); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the total count of shares for $url via Delicious. |
86
|
|
|
* |
87
|
|
|
* @access public |
88
|
|
|
* @param url string The URL to check. |
89
|
|
|
* @return integer Returns the total count of URL shares. |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public static function getDeliciousShares($url = false) |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
94
|
|
|
$dataUrl = sprintf(Config\Services::DELICIOUS_INFO_URL, urlencode($url)); |
95
|
|
|
|
96
|
|
|
$jsonData = parent::_getPage($dataUrl); |
|
|
|
|
97
|
|
|
$phpArray = Helper\Json::decode($jsonData, true); |
98
|
|
|
|
99
|
|
|
return isset($phpArray[0]['total_posts']) ? intval($phpArray[0]['total_posts']) : parent::noDataDefaultValue(); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Returns the Top10 tags for $url from Delicious. |
104
|
|
|
* |
105
|
|
|
* @access public |
106
|
|
|
* @param url string The URL to check. |
107
|
|
|
* @return array Returns the top ten delicious tags for a URL (if exist; else an empty array). |
108
|
|
|
*/ |
109
|
|
|
public static function getDeliciousTopTags($url = false) |
110
|
|
|
{ |
111
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
112
|
|
|
$dataUrl = sprintf(Config\Services::DELICIOUS_INFO_URL, urlencode($url)); |
113
|
|
|
|
114
|
|
|
$jsonData = parent::_getPage($dataUrl); |
|
|
|
|
115
|
|
|
$phpArray = Helper\Json::decode($jsonData, true); |
116
|
|
|
|
117
|
|
|
$ret = array(); |
118
|
|
|
if (isset($phpArray[0]['top_tags']) && 0 < sizeof($phpArray[0]['top_tags'])) { |
119
|
|
|
foreach($phpArray[0]['top_tags'] as $k => $v) { |
120
|
|
|
$ret[] = $k; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
return $ret; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Returns the total count of shares for $url via Digg. |
128
|
|
|
* |
129
|
|
|
* @access public |
130
|
|
|
* @param url string The URL to check. |
131
|
|
|
* @return integer Returns the total count of URL shares. |
132
|
|
|
*/ |
133
|
|
View Code Duplication |
public static function getDiggShares($url = false) |
|
|
|
|
134
|
|
|
{ |
135
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
136
|
|
|
$dataUrl = sprintf(Config\Services::DIGG_INFO_URL, urlencode($url)); |
137
|
|
|
|
138
|
|
|
$jsonData = parent::_getPage($dataUrl); |
|
|
|
|
139
|
|
|
$phpArray = Helper\Json::decode(substr($jsonData, 2, -2), true); |
140
|
|
|
|
141
|
|
|
return isset($phpArray['diggs']) ? intval($phpArray['diggs']) : parent::noDataDefaultValue(); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Returns the total count of shares for $url via LinkedIn. |
146
|
|
|
* |
147
|
|
|
* @access public |
148
|
|
|
* @param url string The URL to check. |
149
|
|
|
* @return integer Returns the total count of URL shares. |
150
|
|
|
*/ |
151
|
|
View Code Duplication |
public static function getLinkedInShares($url = false) |
|
|
|
|
152
|
|
|
{ |
153
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
154
|
|
|
$dataUrl = sprintf(Config\Services::LINKEDIN_INFO_URL, urlencode($url)); |
155
|
|
|
|
156
|
|
|
$jsonData = parent::_getPage($dataUrl); |
|
|
|
|
157
|
|
|
$phpArray = Helper\Json::decode(substr($jsonData, 2, -2), true); |
158
|
|
|
|
159
|
|
|
return isset($phpArray['count']) ? intval($phpArray['count']) : parent::noDataDefaultValue(); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Returns the total count of shares for $url via Pinterest. |
164
|
|
|
* |
165
|
|
|
* @access public |
166
|
|
|
* @param url string The URL to check. |
167
|
|
|
* @return integer Returns the total count of URL shares. |
168
|
|
|
*/ |
169
|
|
View Code Duplication |
public static function getPinterestShares($url = false) |
|
|
|
|
170
|
|
|
{ |
171
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
172
|
|
|
$dataUrl = sprintf(Config\Services::PINTEREST_INFO_URL, urlencode($url)); |
173
|
|
|
|
174
|
|
|
$jsonData = parent::_getPage($dataUrl); |
|
|
|
|
175
|
|
|
$phpArray = Helper\Json::decode(substr($jsonData, 2, -1), true); |
176
|
|
|
|
177
|
|
|
return isset($phpArray['count']) ? intval($phpArray['count']) : parent::noDataDefaultValue(); |
|
|
|
|
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Returns the total count of shares for $url via StumpleUpon. |
182
|
|
|
* |
183
|
|
|
* @access public |
184
|
|
|
* @param url string The URL to check. |
185
|
|
|
* @return integer Returns the total count of URL shares. |
186
|
|
|
*/ |
187
|
|
|
public static function getStumbleUponShares($url = false) |
188
|
|
|
{ |
189
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
190
|
|
|
$dataUrl = sprintf(Config\Services::STUMBLEUPON_INFO_URL, urlencode($url)); |
191
|
|
|
|
192
|
|
|
$jsonData = parent::_getPage($dataUrl); |
|
|
|
|
193
|
|
|
$phpArray = Helper\Json::decode($jsonData, true); |
194
|
|
|
|
195
|
|
|
return isset($phpArray['result']['in_index']) && true == $phpArray['result']['in_index'] |
196
|
|
|
? intval($phpArray['result']['views']) : parent::noDataDefaultValue(); |
|
|
|
|
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Returns the total count of shares for $url via VKontakte. |
201
|
|
|
* |
202
|
|
|
* @access public |
203
|
|
|
* @param url string The URL to check. |
204
|
|
|
* @return integer Returns the total count of URL shares. |
205
|
|
|
*/ |
206
|
|
View Code Duplication |
public static function getVKontakteShares($url = false) |
|
|
|
|
207
|
|
|
{ |
208
|
|
|
$url = parent::getUrl($url); |
|
|
|
|
209
|
|
|
$dataUrl = sprintf(Config\Services::VKONTAKTE_INFO_URL, urlencode($url)); |
210
|
|
|
|
211
|
|
|
$htmlData = parent::_getPage($dataUrl); |
|
|
|
|
212
|
|
|
@preg_match_all('#^VK\.Share\.count\(1, (\d+)\);$#si', $htmlData, $matches); |
|
|
|
|
213
|
|
|
|
214
|
|
|
return isset($matches[1][0]) ? intval($matches[1][0]) : parent::noDataDefaultValue(); |
|
|
|
|
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Returns an array of interaction counts (shares, comments, clicks, reach) for host of $url on Xing. |
219
|
|
|
* |
220
|
|
|
* @access public |
221
|
|
|
* @param url string The URL to check. |
222
|
|
|
* @return array Returns URL shares, comments, clicks and 'reach'. |
223
|
|
|
* @link https://blog.xing.com/2012/01/xing-share-button/ Return values explained (German) |
224
|
|
|
*/ |
225
|
|
|
public static function getXingShares($url = false) |
226
|
|
|
{ |
227
|
|
|
$host = parent::getHost($url); |
|
|
|
|
228
|
|
|
$dataUrl = sprintf(Config\Services::XING_SHAREBUTTON_URL, urlencode($host)); |
229
|
|
|
|
230
|
|
|
$htmlData = parent::_getPage($dataUrl); |
|
|
|
|
231
|
|
|
@preg_match_all('/\r?\n(\d+)\r?\n/s', $htmlData, $matches); |
|
|
|
|
232
|
|
|
|
233
|
|
|
if (isset($matches[1]) && 4 == sizeof($matches[1])) { |
234
|
|
|
return array( |
235
|
|
|
'shares' => intval($matches[1][0]), |
236
|
|
|
'comments' => intval($matches[1][1]), |
237
|
|
|
'clicks' => intval($matches[1][2]), |
238
|
|
|
'reach' => intval($matches[1][3]), |
239
|
|
|
); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
return parent::noDataDefaultValue(); |
|
|
|
|
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: