soclever_login - Version 1.1.1

Version Notes

Stable Version 1.1.1 - Option to send welcome email

Download this release

Release Info

Developer Soclever Social
Extension soclever_login
Version 1.1.1
Comparing to
See all releases


Code changes from version 1.1.0 to 1.1.1

Files changed (28) hide show
  1. app/code/local/Soclever/Sociallogin/Block/Scslhead.php +0 -13
  2. app/code/local/Soclever/Sociallogin/Block/Scsltrackpixel.php +0 -13
  3. app/code/local/Soclever/Sociallogin/Helper/Data.php +0 -6
  4. app/code/local/Soclever/Sociallogin/Model/Observer.php +0 -33
  5. app/code/local/Soclever/Sociallogin/controllers/IndexController.php +0 -446
  6. app/code/local/Soclever/{Sociallogin → Socialloginsc}/Block/Help.php +1 -1
  7. app/code/local/Soclever/{Sociallogin/Block/Scslheadfb.php → Socialloginsc/Block/Scslhead.php} +12 -12
  8. app/code/local/Soclever/{Sociallogin → Socialloginsc}/Block/Scslshow.php +2 -2
  9. app/code/local/Soclever/Socialloginsc/Helper/Data.php +6 -0
  10. app/code/local/Soclever/{Sociallogin → Socialloginsc}/Model/Info.php +3 -3
  11. app/code/local/Soclever/Socialloginsc/Model/Observer.php +33 -0
  12. app/code/local/Soclever/{Sociallogin → Socialloginsc}/Model/Providers.php +2 -1
  13. app/code/local/Soclever/Socialloginsc/controllers/IndexController.php +900 -0
  14. app/code/local/Soclever/Socialloginsc/controllers/http.php +2080 -0
  15. app/code/local/Soclever/Socialloginsc/controllers/oauth_client.php +1850 -0
  16. app/code/local/Soclever/{Sociallogin → Socialloginsc}/controllers/openid.php +0 -0
  17. app/code/local/Soclever/{Sociallogin → Socialloginsc}/etc/config.xml +38 -38
  18. app/code/local/Soclever/{Sociallogin → Socialloginsc}/etc/system.xml +25 -16
  19. app/design/frontend/base/default/layout/sociallogin.xml +0 -28
  20. app/design/frontend/base/default/layout/socialloginsc.xml +28 -0
  21. app/design/frontend/base/default/template/sociallogin/scsl_buttons.phtml +0 -38
  22. app/design/frontend/base/default/template/sociallogin/sociallogin_trackpixel.phtml +0 -13
  23. app/design/frontend/base/default/template/socialloginsc/scsl_buttons.phtml +57 -0
  24. app/design/frontend/base/default/template/{sociallogin → socialloginsc}/sociallogin_fb.phtml +0 -0
  25. app/design/frontend/base/default/template/{sociallogin → socialloginsc}/sociallogin_head.phtml +3 -3
  26. app/design/frontend/base/default/template/socialloginsc/sociallogin_trackpixel.phtml +13 -0
  27. app/etc/modules/{soclever_sociallogin.xml → soclever_socialloginsc.xml} +2 -2
  28. package.xml +5 -5
app/code/local/Soclever/Sociallogin/Block/Scslhead.php DELETED
@@ -1,13 +0,0 @@
1
- <?php
2
- class Soclever_Sociallogin_Block_Scslhead extends Mage_Core_Block_Template
3
- {
4
- protected function _construct(){
5
- parent::_construct();
6
-
7
- }
8
- public function _prepareLayout(){
9
- return parent::_prepareLayout();
10
- }
11
- }
12
-
13
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Soclever/Sociallogin/Block/Scsltrackpixel.php DELETED
@@ -1,13 +0,0 @@
1
- <?php
2
- class Soclever_Sociallogin_Block_Scsltrackpixel extends Mage_Core_Block_Template
3
- {
4
- protected function _construct(){
5
- parent::_construct();
6
-
7
- }
8
- public function _prepareLayout(){
9
- return parent::_prepareLayout();
10
- }
11
- }
12
-
13
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Soclever/Sociallogin/Helper/Data.php DELETED
@@ -1,6 +0,0 @@
1
- <?php
2
- class Soclever_Sociallogin_Helper_Data extends Mage_Core_Helper_Abstract
3
- {
4
-
5
- }
6
- ?>
 
 
 
 
 
 
app/code/local/Soclever/Sociallogin/Model/Observer.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
- class Soclever_Sociallogin_Model_Observer
3
- {
4
-
5
-
6
- public function writejs(Varien_Event_Observer $observer)
7
- {
8
-
9
- $site_id=Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid');
10
- $api_secret=Mage::getStoreConfig('sociallogin_options/apisettings/scsl_appsecret');
11
- $api_key=Mage::getStoreConfig('sociallogin_options/apisettings/scsl_appid');
12
-
13
-
14
-
15
- $valid_data=file_get_contents("https://www.socleversocial.com/dashboard/mage_login_activate.php?site_id=".$site_id."&api_key=".$api_key."&api_secret=".$api_secret."&csplatform=magentologin&type=preview");
16
- if($valid_data!='0')
17
- {
18
- Mage::getModel('core/config')->saveConfig('sociallogin_options/apisettings/scsl_validated',"1");
19
- Mage::getModel('core/config')->saveConfig('sociallogin_options/apisettings/valid_networks',$valid_data);
20
-
21
- }
22
- else
23
- {
24
- Mage::getModel('core/config')->saveConfig('sociallogin_options/apisettings/scsl_validated',"0");
25
- }
26
-
27
-
28
- }
29
-
30
- }
31
-
32
-
33
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Soclever/Sociallogin/controllers/IndexController.php DELETED
@@ -1,446 +0,0 @@
1
- <?php
2
- class Soclever_Sociallogin_IndexController extends Mage_Core_Controller_Front_Action
3
- {
4
- public function indexAction()
5
- {
6
- $this->loadLayout();
7
- $this->renderLayout();
8
- }
9
- protected function getSession(){
10
- return Mage::getSingleton('customer/session');
11
- }
12
- public function fbloginAction()
13
- {
14
-
15
- if(isset($_GET['lc']) && $_GET['lc']!='')
16
- {
17
- setcookie('lc',$_GET['lc'],time()+100,'/');
18
- setcookie('lch',$_GET['lch'],time()-100,'/');
19
-
20
- }
21
- if(isset($_GET['lch']) && $_GET['lch']!='')
22
- {
23
- setcookie('lch',$_GET['lch'],time()+100,'/');
24
- setcookie('lc',$_GET['lc'],time()-100,'/');
25
-
26
- }
27
- $get_fb=file_get_contents("https://www.socleversocial.com/dashboard/get_fb_data.php?siteid=".Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid')."");
28
-
29
- if($get_fb!='0')
30
- {
31
- $app_arr=explode("~",$get_fb);
32
- $app_id = $app_arr[0];
33
- $my_url="".Mage::getBaseUrl()."soclever_sociallogin/index/fblogin";
34
- $app_secret = $app_arr[1];
35
- $code = $_REQUEST["code"];
36
- if(isset($_REQUEST['error'])){
37
- if(isset($_REQUEST['error_reason']) && $_REQUEST['error_reason']=='user_denied'){
38
-
39
- echo $_REQUEST['error'];
40
- echo"<br/><a href='".Mage::getBaseUrl()."'>Go to site</a>";
41
- exit;
42
- }
43
- }
44
-
45
- if(empty($code)) {
46
- $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
47
- . $app_id . "&redirect_uri=" . urlencode($my_url)."&scope=email,user_birthday,user_relationships,user_location,user_hometown,user_friends,user_likes";
48
-
49
- echo("<script>top.location.href='".$dialog_url."'</script>");
50
- }
51
-
52
- $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
53
- . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
54
- . $app_secret . "&code=" . $code;
55
-
56
- $ch = curl_init();
57
-
58
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
59
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
60
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
61
- curl_setopt($ch, CURLOPT_TIMEOUT, 30);
62
- curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
63
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
64
-
65
- //Get Access Token
66
- curl_setopt($ch, CURLOPT_URL,$token_url);
67
- $access_token = curl_exec($ch);
68
-
69
- curl_close($ch);
70
-
71
-
72
- $graph_url = "https://graph.facebook.com/v2.2/me?" . $access_token."&fields=id,name,first_name,last_name,timezone,email,picture,gender,locale,birthday,relationship_status,location,hometown,friends.limit%280%29,likes{id,name}";
73
- $ch = curl_init();
74
- curl_setopt($ch, CURLOPT_HEADER, 0);
75
- curl_setopt($ch, CURLOPT_URL, $graph_url);
76
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
77
- curl_setopt($ch, CURLOPT_TIMEOUT, 30);
78
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
79
- $temp_user = curl_exec($ch);
80
- curl_close($ch);
81
- $fbuser_old = $temp_user;
82
- $fbuser=json_decode($fbuser_old);
83
-
84
- if($fbuser_old && $fbuser->email!="")
85
- {
86
- $request_url="https://www.socleversocial.com/dashboard/track_register_new.php?app_id=".$app_id."&is_fb=1&friend_data=".$fbuser->friends->summary->total_count."&siteid=".Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid')."&other=".urlencode($fbuser_old);
87
- $resPonse=file_get_contents($request_url);
88
- if($resPonse)
89
- {
90
- $fb_data=json_decode($resPonse);
91
-
92
- $resource = Mage::getSingleton('core/resource');
93
- $tableName = $resource->getTableName('customer_entity');
94
- $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
95
- $sql = "Select entity_id from ".$tableName." where email='".$fb_data->email."' limit 1";
96
- $rows= $connection->fetchAll($sql);
97
-
98
- $customer = Mage::getModel("customer/customer");
99
- if(count($rows) > 0)
100
- {
101
- $is_new='0';
102
- $username=$fb_data->email;
103
- $customer_id=$rows[0]['entity_id'];
104
- }
105
- else
106
- {
107
- $is_new='1';
108
- $store = Mage::app()->getStore();
109
-
110
- $customer->website_id = $websiteId;
111
- $customer->setStore($store);
112
- $password=rand("111111","9999999");
113
- $customer->firstname = $fb_data->first_name;
114
- $customer->lastname = $fb_data->last_name;
115
- $customer->email =$fb_data->email;
116
- $customer->password_hash = md5($password);
117
- $customer->save();
118
- $username=$fb_data->email;
119
- $sql= "Select entity_id from ".$tableName." where email='".$fb_data->email."' limit 1";
120
- $rows= $connection->fetchAll($sql);
121
- $customer_id=$rows[0]['entity_id'];
122
- }
123
-
124
- file_get_contents("https://www.socleversocial.com/dashboard/track_register_new.php?is_from=1&siteUid=".$customer_id."&is_new=".$is_new."&member_id=".$fb_data->member_id."&siteid=".Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid')."&action=notifycs");
125
- Mage::getModel('core/session', array('name' => 'frontend'));
126
- $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
127
- $customer->loadByEmail($username);
128
- $customer->setCustomerActivated(true);
129
- $customer->save();
130
-
131
-
132
- $redirect_location=($_COOKIE['lc']=='c')?Mage::getBaseUrl()."checkout/onepage/":Mage::getBaseUrl()."customer/account/";
133
- if(isset($_COOKIE['lch']) && $_COOKIE['lch']!='')
134
- {
135
- $redirect_location=$_COOKIE['lch'];
136
- }
137
- $is_from='1';
138
- Mage::getSingleton('core/session')->setSessionVariable($is_from);
139
- ?>
140
- <script type="text/javascript">
141
-
142
- setTimeout(function(){
143
-
144
-
145
- window.location.href="<?php echo $redirect_location;?>";
146
-
147
- },1000);
148
-
149
- /*setTimeout(function(){
150
-
151
-
152
- window.close();
153
- //window.opener.location = window.opener.window.location;
154
-
155
- /*try{
156
- if(parent.window.opener != null && ! parent.window.opener)
157
- {
158
- alert("good");
159
- }
160
-
161
- }catch(e){ alert("message="+e.description);}
162
- */
163
-
164
- //alert("called redirection=="+top.window.opener.document.URL+"=");
165
- //top.window.location.assign("<?php echo Mage::getBaseUrl();?>customer/account/edit/");
166
-
167
- // top.window.location.href="<?php echo Mage::getBaseUrl();?>customer/account/edit/";
168
- //close();
169
- //return false;
170
- /*if(top.window.opener.document.URL.indexOf('login') > -1)
171
- {
172
- top.window.opener.location.href="<?php echo Mage::getBaseUrl();?>customer/account/edit/";
173
- close();
174
- }
175
- else
176
- {
177
- top.window.opener.location.href="<?php echo Mage::getBaseUrl();?>checkout/onepage/";
178
- close();
179
-
180
- }*/
181
-
182
- /*}, 3000);*/
183
- </script>
184
- <?php
185
- //echo"<img src='https://www.socleversocial.com/dashboard/images/pw.gif' alt='wait!' title='wait!'>";
186
- $this->getSession()->loginById($customer->getId());
187
- exit;
188
- }
189
- }
190
- }
191
- else
192
- {
193
-
194
- echo"<h1>Login failed.</h1><a href='".Mage::getBaseUrl()."'>Go back to site.</a>";
195
- }
196
- }
197
- public function pploginAction()
198
- {
199
- $paypal_data=json_decode($_GET['data']);
200
-
201
- $resource = Mage::getSingleton('core/resource');
202
- $tableName = $resource->getTableName('customer_entity');
203
- $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
204
- $sql = "Select entity_id from ".$tableName." where email='".$paypal_data->email."' limit 1";
205
- $rows= $connection->fetchAll($sql);
206
-
207
- $customer = Mage::getModel("customer/customer");
208
- if(count($rows) > 0)
209
- {
210
- $is_new='0';
211
- $username=$paypal_data->email;
212
- $customer_id=$rows[0]['entity_id'];
213
- }
214
- else
215
- {
216
- $is_new='1';
217
- $store = Mage::app()->getStore();
218
-
219
- $customer->website_id = $websiteId;
220
- $customer->setStore($store);
221
- $password=rand("111111","9999999");
222
- $customer->firstname = $paypal_data->first_name;
223
- $customer->lastname = $paypal_data->last_name;
224
- $customer->email =$paypal_data->email;
225
- $customer->password_hash = md5($password);
226
- $customer->save();
227
- $username=$paypal_data->email;
228
- $sql= "Select entity_id from ".$tableName." where email='".$paypal_data->email."' limit 1";
229
- $rows= $connection->fetchAll($sql);
230
- $customer_id=$rows[0]['entity_id'];
231
- }
232
-
233
- file_get_contents("https://www.socleversocial.com/dashboard/track_register_new.php?is_from=7&siteUid=".$customer_id."&is_new=".$is_new."&member_id=".$paypal_data->member_id."&siteid=".Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid')."&action=notifycs");
234
- Mage::getModel('core/session', array('name' => 'frontend'));
235
- $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
236
- $customer->loadByEmail($username);
237
- $customer->setCustomerActivated(true);
238
- $customer->save();
239
-
240
- $redirect_location=($_GET['lc']=='c')?Mage::getBaseUrl()."checkout/onepage/":Mage::getBaseUrl()."customer/account/";
241
- $is_from='7';
242
- Mage::getSingleton('core/session')->setSessionVariable($is_from);
243
- ?>
244
- <script type="text/javascript">
245
- setTimeout(function(){ window.location.href="<?php echo $redirect_location; ?>"; },1000);
246
- </script>
247
- <?php
248
- //echo"<img src='https://www.socleversocial.com/dashboard/images/pw.gif' alt='wait!' title='wait!'>";
249
- $this->getSession()->loginById($customer->getId());
250
- exit;
251
- }
252
-
253
-
254
- public function cs_redirect($red)
255
- {
256
- echo $red;
257
- exit;
258
- }
259
- public function yahoologinAction()
260
- {
261
- require 'openid.php';
262
-
263
- try
264
- {
265
-
266
-
267
- $openid = new LightOpenID($_SERVER['HTTP_HOST']);
268
-
269
-
270
- if(!$openid->mode)
271
- {
272
-
273
- //do the login
274
- if(isset($_GET['login']))
275
- {
276
- //The google openid url
277
- $openid->identity = 'https://me.yahoo.com';
278
-
279
- //Get additional google account information about the user , name , email , country
280
- $openid->required = array('contact/email','person/guid','dob','birthDate','namePerson' , 'person/gender' , 'pref/language' , 'media/image/default','birthDate/birthday');
281
-
282
- //start discovery
283
-
284
-
285
- header('Location: ' . $openid->authUrl());
286
- }
287
-
288
-
289
- }
290
-
291
- else if($openid->mode == 'cancel')
292
- {
293
- echo 'User has canceled authentication!';
294
- //redirect back to login page ??
295
- }
296
-
297
- //Echo login information by default
298
- else
299
- {
300
- if($openid->validate())
301
- {
302
- $is_from='5';
303
- Mage::getSingleton('core/session')->setSessionVariable($is_from);
304
- $d = $openid->getAttributes();
305
- //echo "https://www.socleversocial.com/dashboard/track_register_new.php?is_yh=1&is_from=5&siteid=".Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid')."&other=".json_encode($d)."";
306
- /*$response_content=file_get_contents("https://www.socleversocial.com/dashboard/track_register_new.php?is_yh=1&is_from=5&siteid=".Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid')."&other=".json_encode($d)."");
307
- if($response_content)
308
- {
309
- $response_final=json_decode($response_content);
310
- print_r($response_final);
311
- exit;
312
- }*/
313
- ?>
314
- <script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
315
- <script type="text/javascript">
316
- var xmlhttp;
317
- if(window.XMLHttpRequest)
318
- {
319
- xmlhttp=new XMLHttpRequest();
320
- }
321
- else
322
- {
323
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
324
- }
325
- function track_info_yh(info)
326
- {
327
- xmlhttp.onreadystatechange=function()
328
- {
329
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
330
- {
331
- var gobj=JSON.parse(xmlhttp.responseText);
332
- var login_src='5';
333
-
334
- var request = new Ajax.Request("<?php echo Mage::getBaseUrl();?>soclever_sociallogin/index/login",
335
- {
336
- method: 'post',
337
- parameters: {member_id: gobj.member_id, email:gobj.email,first_name:gobj.first_name,last_name:gobj.last_name,site_id:<?php echo Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid'); ?>,is_from:login_src},
338
- onSuccess: function(transport){
339
- if(transport.responseText)
340
- {
341
-
342
- if(opener.document.URL.indexOf('checkout') > -1)
343
- {
344
- opener.location.href="<?php echo Mage::getBaseUrl();?>checkout/onepage/";
345
- close();
346
-
347
- }
348
- else
349
- {
350
- opener.location.href="<?php echo Mage::getBaseUrl();?>customer/account/";
351
- close();
352
-
353
- }
354
- }
355
-
356
- }
357
- });
358
-
359
-
360
-
361
- }
362
- }
363
- xmlhttp.open("GET",'https://www.socleversocial.com/dashboard/track_register_new.php?is_yh=1&is_from=5&siteid=<?php echo Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid'); ?>&other='+encodeURIComponent(info),true);
364
- xmlhttp.send();
365
-
366
- }
367
- track_info_yh('<?php echo json_encode($d); ?>');
368
- </script>
369
-
370
-
371
- <?php
372
- exit;
373
-
374
-
375
- }
376
- else
377
- {
378
- //user is not logged in
379
- }
380
- }
381
- }
382
-
383
- catch(ErrorException $e)
384
- {
385
- echo $e->getMessage();
386
- }
387
-
388
- }
389
- public function loginAction()
390
- {
391
-
392
- $resource = Mage::getSingleton('core/resource');
393
- $tableName = $resource->getTableName('customer_entity');
394
- $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
395
- $sql = "Select entity_id from ".$tableName." where email='{$_POST['email']}' limit 1";
396
- $rows =$connection->fetchAll($sql);
397
-
398
- $customer = Mage::getModel("customer/customer");
399
- if(count($rows) > 0)
400
- {
401
- $is_new='0';
402
- $username=$_POST['email'];
403
- $customer_id=$rows[0]['entity_id'];
404
- }
405
- else
406
- {
407
- $is_new='1';
408
- $store = Mage::app()->getStore();
409
-
410
- $customer->website_id = $websiteId;
411
- $customer->setStore($store);
412
- $password=rand("111111","9999999");
413
- $customer->firstname = $_POST['first_name'];
414
- $customer->lastname = $_POST['last_name'];
415
- $customer->email = $_POST['email'];
416
- $customer->password_hash = md5($password);
417
- $customer->save();
418
- $username=$_POST['email'];
419
- $sql = "Select entity_id from ".$tableName." where email='{$_POST['email']}' limit 1";
420
- $rows= $connection->fetchAll($sql);
421
- $customer_id=$rows[0]['entity_id'];
422
- }
423
-
424
- file_get_contents("https://www.socleversocial.com/dashboard/track_register_new.php?is_from=".$_POST['is_from']."&siteUid=".$customer_id."&is_new=".$is_new."&member_id=".$_POST['member_id']."&siteid=".$_POST['site_id']."&action=notifycs");
425
-
426
- Mage::getModel('core/session', array('name' => 'frontend'));
427
- $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
428
- $customer->loadByEmail($username);
429
- $customer->setCustomerActivated(true);
430
- $customer->save();
431
-
432
- $this->getSession()->loginById($customer->getId());
433
-
434
- if(Mage::getSingleton('customer/session')->isLoggedIn())
435
- {
436
- $is_from=$_POST['is_from'];
437
- Mage::getSingleton('core/session')->setSessionVariable($is_from);
438
- exit("1");
439
- }
440
-
441
-
442
-
443
- }
444
-
445
- }
446
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Soclever/{Sociallogin → Socialloginsc}/Block/Help.php RENAMED
@@ -1,5 +1,5 @@
1
  <?php
2
- class Soclever_Sociallogin_Block_Help extends Mage_Adminhtml_Block_System_Config_Form_Fieldset {
3
  public function render(Varien_Data_Form_Element_Abstract $element) {
4
  $html = $this->_getHeaderHtml($element);
5
  $html.= $this->_getFieldHtml($element);
1
  <?php
2
+ class Soclever_Socialloginsc_Block_Help extends Mage_Adminhtml_Block_System_Config_Form_Fieldset {
3
  public function render(Varien_Data_Form_Element_Abstract $element) {
4
  $html = $this->_getHeaderHtml($element);
5
  $html.= $this->_getFieldHtml($element);
app/code/local/Soclever/{Sociallogin/Block/Scslheadfb.php → Socialloginsc/Block/Scslhead.php} RENAMED
@@ -1,13 +1,13 @@
1
- <?php
2
- class Soclever_Sociallogin_Block_Scslheadfb extends Mage_Core_Block_Template
3
- {
4
- protected function _construct(){
5
- parent::_construct();
6
-
7
- }
8
- public function _prepareLayout(){
9
- return parent::_prepareLayout();
10
- }
11
- }
12
-
13
  ?>
1
+ <?php
2
+ class Soclever_Socialloginsc_Block_Scslhead extends Mage_Core_Block_Template
3
+ {
4
+ protected function _construct(){
5
+ parent::_construct();
6
+
7
+ }
8
+ public function _prepareLayout(){
9
+ return parent::_prepareLayout();
10
+ }
11
+ }
12
+
13
  ?>
app/code/local/Soclever/{Sociallogin → Socialloginsc}/Block/Scslshow.php RENAMED
@@ -1,9 +1,9 @@
1
  <?php
2
- class Soclever_Sociallogin_Block_Scslshow extends Mage_Core_Block_Template
3
  {
4
  protected function _construct(){
5
  parent::_construct();
6
- $this->setTemplate('sociallogin/scsl_buttons.phtml');
7
  }
8
  public function setPlace($place) {
9
  $this->place = $place;
1
  <?php
2
+ class Soclever_Socialloginsc_Block_Scslshow extends Mage_Core_Block_Template
3
  {
4
  protected function _construct(){
5
  parent::_construct();
6
+ $this->setTemplate('socialloginsc/scsl_buttons.phtml');
7
  }
8
  public function setPlace($place) {
9
  $this->place = $place;
app/code/local/Soclever/Socialloginsc/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Soclever_Socialloginsc_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ }
6
+ ?>
app/code/local/Soclever/{Sociallogin → Socialloginsc}/Model/Info.php RENAMED
@@ -1,5 +1,5 @@
1
  <?php
2
- class Soclever_Sociallogin_Model_Info extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
3
  {
4
 
5
 
@@ -48,12 +48,12 @@ class Soclever_Sociallogin_Model_Info extends Mage_Adminhtml_Block_Abstract impl
48
  <h4 class="ss_admin_fieldset_title"><strong><?php echo $this->__('Extension Information!') ?></strong></h4>
49
 
50
  <div style="margin:5px 0">
51
- <strong>Version: </strong>1.1.0 <br/>
52
  <strong>Author:</strong>Soclever Social<br/>
53
  <strong>Website:</strong> <a href="https://www.socleversocial.com" target="_blank">www.socleversocial.com</a>
54
  <br/>
55
 
56
- <div id="sociallogin_get_update" style="float:left;">To receive updates on new features and releases, Please follow us on one of our social media pages
57
  </div>
58
  <div id="ss_media_pages_container">
59
  <a target="_blank" href="https://www.facebook.com/socleversocial"><img
1
  <?php
2
+ class Soclever_Socialloginsc_Model_Info extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
3
  {
4
 
5
 
48
  <h4 class="ss_admin_fieldset_title"><strong><?php echo $this->__('Extension Information!') ?></strong></h4>
49
 
50
  <div style="margin:5px 0">
51
+ <strong>Version: </strong>1.1.1 <br/>
52
  <strong>Author:</strong>Soclever Social<br/>
53
  <strong>Website:</strong> <a href="https://www.socleversocial.com" target="_blank">www.socleversocial.com</a>
54
  <br/>
55
 
56
+ <div id="socialloginsc_get_update" style="float:left;">To receive updates on new features and releases, Please follow us on one of our social media pages
57
  </div>
58
  <div id="ss_media_pages_container">
59
  <a target="_blank" href="https://www.facebook.com/socleversocial"><img
app/code/local/Soclever/Socialloginsc/Model/Observer.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Soclever_Socialloginsc_Model_Observer
3
+ {
4
+
5
+
6
+ public function writejs(Varien_Event_Observer $observer)
7
+ {
8
+
9
+ $site_id=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid');
10
+ $api_secret=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_appsecret');
11
+ $api_key=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_appid');
12
+
13
+
14
+
15
+ $valid_data=file_get_contents("https://www.socleversocial.com/dashboard/mage_login_activate_sc.php?site_id=".$site_id."&api_key=".$api_key."&api_secret=".$api_secret."&csplatform=magentologin&type=preview");
16
+ if($valid_data!='0')
17
+ {
18
+ Mage::getModel('core/config')->saveConfig('socialloginsc_options/apisettings/scsl_validated',"1");
19
+ Mage::getModel('core/config')->saveConfig('socialloginsc_options/apisettings/valid_networks',$valid_data);
20
+
21
+ }
22
+ else
23
+ {
24
+ Mage::getModel('core/config')->saveConfig('socialloginsc_options/apisettings/scsl_validated',"0");
25
+ }
26
+
27
+
28
+ }
29
+
30
+ }
31
+
32
+
33
+ ?>
app/code/local/Soclever/{Sociallogin → Socialloginsc}/Model/Providers.php RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- class Soclever_Sociallogin_Model_Providers
4
  {
5
  public function getbuttonstyles()
6
  {
@@ -20,6 +20,7 @@ public function getloginproviders()
20
  array('value'=>0, 'label'=>'None'),
21
  array('value'=>2, 'label'=>'Facebook'),
22
  array('value'=>4, 'label'=>'Google+'),
 
23
  array('value'=>7, 'label'=>'LinkedIN'),
24
  array('value'=>15, 'label'=>'Yahoo!'),
25
  array('value'=>16, 'label'=>'Paypal'),
1
  <?php
2
 
3
+ class Soclever_Socialloginsc_Model_Providers
4
  {
5
  public function getbuttonstyles()
6
  {
20
  array('value'=>0, 'label'=>'None'),
21
  array('value'=>2, 'label'=>'Facebook'),
22
  array('value'=>4, 'label'=>'Google+'),
23
+ array('value'=>13, 'label'=>'Twitter'),
24
  array('value'=>7, 'label'=>'LinkedIN'),
25
  array('value'=>15, 'label'=>'Yahoo!'),
26
  array('value'=>16, 'label'=>'Paypal'),
app/code/local/Soclever/Socialloginsc/controllers/IndexController.php ADDED
@@ -0,0 +1,900 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Soclever_Socialloginsc_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+ $this->loadLayout();
7
+ $this->renderLayout();
8
+ }
9
+ protected function getSession(){
10
+ return Mage::getSingleton('customer/session');
11
+ }
12
+ public function twloginAction()
13
+ {
14
+ $site_id=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid');
15
+ if(isset($_GET['lc']) && $_GET['lc']!='')
16
+ {
17
+ setcookie('lc',$_GET['lc'],time()+100,'/');
18
+ setcookie('lch',$_GET['lch'],time()-100,'/');
19
+
20
+ }
21
+ if(isset($_GET['lch']) && $_GET['lch']!='')
22
+ {
23
+ setcookie('lch',$_GET['lch'],time()+100,'/');
24
+ setcookie('lc',$_GET['lc'],time()-100,'/');
25
+
26
+ }
27
+ if(isset($_POST['submit']) && $_POST['submit']=='Login' )
28
+ {
29
+ $this->scsl_general_login($_POST['response_str'],'4',$_POST['email']);
30
+
31
+ exit;
32
+ }
33
+
34
+ $get_fb=file_get_contents("https://www.socleversocial.com/dashboard/get_fb_data.php?siteid=".Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid')."&is_tw=1");
35
+
36
+ $my_Api=explode("~",$get_fb);
37
+ if($my_Api[0]!='0')
38
+ {
39
+
40
+ require('http.php');
41
+ require('oauth_client.php');
42
+ $client = new oauth_client_class;
43
+ $client->server = 'Twitter';
44
+ $client->redirect_uri = 'http://eurekadigital.com.au/mageonlylogin/index.php/soclever_socialloginsc/index/twlogin';
45
+
46
+ $client->client_id = $my_Api[0];
47
+ $application_line = __LINE__;
48
+ $client->client_secret = $my_Api[1];
49
+
50
+
51
+
52
+ if(strlen($client->client_id) == 0
53
+ || strlen($client->client_secret) == 0)
54
+ die('twitter failed.');
55
+
56
+ /* API permissions
57
+ */
58
+ $client->scope = 'wl.basic wl.emails wl.birthday';
59
+ if(($success = $client->Initialize()))
60
+ {
61
+ if(($success = $client->Process()))
62
+ {
63
+ if(strlen($client->authorization_error))
64
+ {
65
+ $client->error = $client->authorization_error;
66
+ exit($client->error);
67
+ $success = false;
68
+ }
69
+ elseif(strlen($client->access_token))
70
+ {
71
+ $success = $client->CallAPI(
72
+ 'https://api.twitter.com/'. '1.1/account/'. 'verify_credentials.json',
73
+ 'GET', array(), array('FailOnAccessError'=>true), $user);
74
+ }
75
+ }
76
+ $success = $client->Finalize($success);
77
+ }
78
+ if($client->exit)
79
+ {
80
+ exit;
81
+ }
82
+ if($success)
83
+ {
84
+
85
+ $your_data=json_encode($user);
86
+ $content=json_decode($your_data);
87
+ $twitter_arr=array();
88
+ $twitter_arr['full_name']=$content->name;
89
+ $twitter_arr['profile_id']=$content->id;
90
+ $twitter_arr['screen_name']=$content->screen_name;
91
+ $twitter_arr['location']=$content->location;
92
+ $twitter_arr['description']=$content->description;
93
+ $twitter_arr['following_count']=$content->friends_count;
94
+ $twitter_arr['follower_count']=$content->followers_count;
95
+ $twitter_arr['tweet_count']=$content->statuses_count;
96
+ $twitter_arr['is_verified']=$content->verified;
97
+ $twitter_arr['lang']=$content->lang;
98
+ $twitter_arr['profile_pic']=$content->profile_image_url;
99
+ $twitter_arr['time_zone']=$content->time_zone;
100
+
101
+ $chk_twitter=file_get_contents("https://www.socleversocial.com/dashboard/track_twitter.php?site_id=".$site_id."&twitter_id=".$twitter_arr['profile_id']."&action=chk_tw");
102
+ //$chk_twitter='1';
103
+ if($chk_twitter=='0')
104
+ {
105
+ ?>
106
+ <style>
107
+ #container_demo{
108
+ text-align: left;
109
+ margin: 0;
110
+ padding: 0;
111
+ margin: 0 auto;
112
+ font-family: "Trebuchet MS","Myriad Pro",Arial,sans-serif;
113
+ }
114
+
115
+ #wrapper{
116
+
117
+ right: 0px;
118
+ height: 400px;
119
+ margin: 0px auto;
120
+
121
+ position: relative;
122
+ }
123
+ #wrapper a{
124
+ color: rgb(95, 155, 198);
125
+ text-decoration: underline;
126
+ }
127
+
128
+ #wrapper h1{
129
+ font-size: 48px;
130
+ color: rgb(6, 106, 117);
131
+ padding: 2px 0 10px 0;
132
+ font-family: 'FranchiseRegular','Arial Narrow',Arial,sans-serif;
133
+ font-weight: bold;
134
+ text-align: center;
135
+ padding-bottom: 30px;
136
+ }
137
+
138
+ #wrapper h1{
139
+ background: -webkit-repeating-linear-gradient(-45deg,
140
+ rgb(18, 83, 93) ,
141
+ rgb(18, 83, 93) 20px,
142
+ rgb(64, 111, 118) 20px,
143
+ rgb(64, 111, 118) 40px,
144
+ rgb(18, 83, 93) 40px);
145
+ -webkit-text-fill-color: transparent;
146
+ -webkit-background-clip: text;
147
+ }
148
+ #wrapper h1:after{
149
+ content: ' ';
150
+ display: block;
151
+ width: 100%;
152
+ height: 2px;
153
+ margin-top: 10px;
154
+ background: -moz-linear-gradient(left, rgba(147,184,189,0) 0%, rgba(147,184,189,0.8) 20%, rgba(147,184,189,1) 53%, rgba(147,184,189,0.8) 79%, rgba(147,184,189,0) 100%);
155
+ background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(147,184,189,0)), color-stop(20%,rgba(147,184,189,0.8)), color-stop(53%,rgba(147,184,189,1)), color-stop(79%,rgba(147,184,189,0.8)), color-stop(100%,rgba(147,184,189,0)));
156
+ background: -webkit-linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%);
157
+ background: -o-linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%);
158
+ background: -ms-linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%);
159
+ background: linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%);
160
+ }
161
+
162
+ #wrapper p{
163
+ margin-bottom:15px;
164
+ }
165
+ #wrapper p:first-child{
166
+ margin: 0px;
167
+ }
168
+ #wrapper label{
169
+ color: rgb(64, 92, 96);
170
+ position: relative;
171
+ }
172
+
173
+ /**** advanced input styling ****/
174
+ /* placeholder */
175
+ ::-webkit-input-placeholder {
176
+ color: rgb(190, 188, 188);
177
+ font-style: italic;
178
+ }
179
+ input:-moz-placeholder,
180
+ textarea:-moz-placeholder{
181
+ color: rgb(190, 188, 188);
182
+ font-style: italic;
183
+ }
184
+ input {
185
+ outline: none;
186
+ }
187
+
188
+ /* all the input except submit and checkbox */
189
+ #wrapper input:not([type="checkbox"]){
190
+ width: 92%;
191
+ margin-top: 4px;
192
+ padding: 10px 5px 10px 32px;
193
+ border: 1px solid rgb(178, 178, 178);
194
+ -webkit-appearance: textfield;
195
+ -webkit-box-sizing: content-box;
196
+ -moz-box-sizing : content-box;
197
+ box-sizing : content-box;
198
+ -webkit-border-radius: 3px;
199
+ -moz-border-radius: 3px;
200
+ border-radius: 3px;
201
+ -webkit-box-shadow: 0px 1px 4px 0px rgba(168, 168, 168, 0.6) inset;
202
+ -moz-box-shadow: 0px 1px 4px 0px rgba(168, 168, 168, 0.6) inset;
203
+ box-shadow: 0px 1px 4px 0px rgba(168, 168, 168, 0.6) inset;
204
+ -webkit-transition: all 0.2s linear;
205
+ -moz-transition: all 0.2s linear;
206
+ -o-transition: all 0.2s linear;
207
+ transition: all 0.2s linear;
208
+ }
209
+
210
+ /*styling both submit buttons */
211
+ #wrapper p.button input{
212
+ width: 30%;
213
+ cursor: pointer;
214
+ background: rgb(61, 157, 179);
215
+ padding: 8px 5px;
216
+ font-family: 'BebasNeueRegular','Arial Narrow',Arial,sans-serif;
217
+ color: #fff;
218
+ font-size: 24px;
219
+ border: 1px solid rgb(28, 108, 122);
220
+ margin-bottom: 10px;
221
+ text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
222
+ -webkit-border-radius: 3px;
223
+ -moz-border-radius: 3px;
224
+ border-radius: 3px;
225
+ -webkit-box-shadow: 0px 1px 6px 4px rgba(0, 0, 0, 0.07) inset,
226
+ 0px 0px 0px 3px rgb(254, 254, 254),
227
+ 0px 5px 3px 3px rgb(210, 210, 210);
228
+ -moz-box-shadow:0px 1px 6px 4px rgba(0, 0, 0, 0.07) inset,
229
+ 0px 0px 0px 3px rgb(254, 254, 254),
230
+ 0px 5px 3px 3px rgb(210, 210, 210);
231
+ box-shadow:0px 1px 6px 4px rgba(0, 0, 0, 0.07) inset,
232
+ 0px 0px 0px 3px rgb(254, 254, 254),
233
+ 0px 5px 3px 3px rgb(210, 210, 210);
234
+ -webkit-transition: all 0.2s linear;
235
+ -moz-transition: all 0.2s linear;
236
+ -o-transition: all 0.2s linear;
237
+ transition: all 0.2s linear;
238
+ }
239
+ #wrapper p.button input:hover{
240
+ background: rgb(74, 179, 198);
241
+ }
242
+ #wrapper p.button input:active,
243
+ #wrapper p.button input:focus{
244
+ background: rgb(40, 137, 154);
245
+ position: relative;
246
+ top: 1px;
247
+ border: 1px solid rgb(12, 76, 87);
248
+ -webkit-box-shadow: 0px 1px 6px 4px rgba(0, 0, 0, 0.2) inset;
249
+ -moz-box-shadow: 0px 1px 6px 4px rgba(0, 0, 0, 0.2) inset;
250
+ box-shadow: 0px 1px 6px 4px rgba(0, 0, 0, 0.2) inset;
251
+ }
252
+ p.login.button,
253
+ p.signin.button{
254
+ text-align: right;
255
+ margin: 5px 0;
256
+ }
257
+
258
+
259
+
260
+
261
+ #login{
262
+ position: absolute;
263
+ top: 0px;
264
+ width: 88%;
265
+ padding: 18px 6% 60px 6%;
266
+ margin: 0 0 35px 0;
267
+ background: rgb(247, 247, 247);
268
+ border: 1px solid rgba(147, 184, 189,0.8);
269
+ -webkit-box-shadow: 0pt 2px 5px rgba(105, 108, 109, 0.7), 0px 0px 8px 5px rgba(208, 223, 226, 0.4) inset;
270
+ -moz-box-shadow: 0pt 2px 5px rgba(105, 108, 109, 0.7), 0px 0px 8px 5px rgba(208, 223, 226, 0.4) inset;
271
+ box-shadow: 0pt 2px 5px rgba(105, 108, 109, 0.7), 0px 0px 8px 5px rgba(208, 223, 226, 0.4) inset;
272
+ -webkit-box-shadow: 5px;
273
+ -moz-border-radius: 5px;
274
+ border-radius: 5px;
275
+ }
276
+
277
+ #login{
278
+ z-index: 22;
279
+ }
280
+ #toregister:target ~ #wrapper #register,
281
+ #tologin:target ~ #wrapper #login{
282
+ z-index: 22;
283
+ -webkit-animation-name: fadeInLeft;
284
+ -moz-animation-name: fadeInLeft;
285
+ -ms-animation-name: fadeInLeft;
286
+ -o-animation-name: fadeInLeft;
287
+ animation-name: fadeInLeft;
288
+ -webkit-animation-delay: .1s;
289
+ -moz-animation-delay: .1s;
290
+ -o-animation-delay: .1s;
291
+ -ms-animation-delay: .1s;
292
+ animation-delay: .1s;
293
+ }
294
+
295
+ .lt8 #wrapper input{
296
+ padding: 10px 5px 10px 32px;
297
+ width: 92%;
298
+ }
299
+
300
+ </style>
301
+
302
+ <div class="container">
303
+
304
+ <div class="codrops-top">
305
+ <div class="clr"></div>
306
+ </div>
307
+ <section>
308
+ <div id="container_demo" >
309
+ <div id="wrapper">
310
+ <div id="login" class="animate form">
311
+ <form action="" autocomplete="on" method="post">
312
+ <input type="hidden" name="response_str" value="<?php echo stripslashes(implode("~~~",$twitter_arr)); ?>" />
313
+ <h1>You are almost done!</h1>
314
+ <p>
315
+ <label for="email" class="uname">Your email</label>
316
+ <input id="email" name="email" required="required" type="text" placeholder="mymail@mail.com"/>
317
+ </p>
318
+
319
+
320
+ <p class="login button">
321
+ <input type="submit" value="Login" name="submit" onclick="return chk_submit_email();" />
322
+ </p>
323
+
324
+ </form>
325
+ </div>
326
+
327
+
328
+
329
+ </div>
330
+ </div>
331
+ </section>
332
+ </div>
333
+ <script type="text/javascript">
334
+
335
+
336
+ function isvalidemail_form(str){
337
+
338
+ var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-zA-Z]{2,6}(?:\.[a-zA-Z]{2})?)$/i
339
+ return (filter.test(str));
340
+ }
341
+
342
+ function isWhitespace(charToCheck) {
343
+ var whitespaceChars = " \t\n\r\f";
344
+ return (whitespaceChars.indexOf(charToCheck) != -1);
345
+ }
346
+ function chk_submit_email()
347
+ {
348
+ var email=document.getElementById('email').value;
349
+ if(!isWhitespace(email))
350
+ {
351
+ if(!isvalidemail_form(email))
352
+ {
353
+ alert("Please enter valid email address");
354
+ return false;
355
+ }
356
+ }
357
+ else
358
+ {
359
+ alert("Please provide your email address.");
360
+ return false;
361
+ }
362
+
363
+
364
+ }
365
+
366
+ </script>
367
+ <?php
368
+ exit;
369
+ }
370
+ else
371
+ {
372
+ $this->scsl_general_login(stripslashes(implode("~~~",$twitter_arr)),'4',$chk_twitter);
373
+ }
374
+
375
+ }
376
+
377
+ }
378
+
379
+
380
+
381
+
382
+
383
+ }
384
+ public function fbloginAction()
385
+ {
386
+
387
+ if(isset($_GET['lc']) && $_GET['lc']!='')
388
+ {
389
+ setcookie('lc',$_GET['lc'],time()+100,'/');
390
+ setcookie('lch',$_GET['lch'],time()-100,'/');
391
+
392
+ }
393
+ if(isset($_GET['lch']) && $_GET['lch']!='')
394
+ {
395
+ setcookie('lch',$_GET['lch'],time()+100,'/');
396
+ setcookie('lc',$_GET['lc'],time()-100,'/');
397
+
398
+ }
399
+ $get_fb=file_get_contents("https://www.socleversocial.com/dashboard/get_fb_data.php?siteid=".Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid')."");
400
+
401
+ if($get_fb!='0')
402
+ {
403
+ $app_arr=explode("~",$get_fb);
404
+ $app_id = $app_arr[0];
405
+ $my_url="".Mage::getBaseUrl()."soclever_socialloginsc/index/fblogin";
406
+ $app_secret = $app_arr[1];
407
+ $code = $_REQUEST["code"];
408
+ if(isset($_REQUEST['error'])){
409
+ if(isset($_REQUEST['error_reason']) && $_REQUEST['error_reason']=='user_denied'){
410
+
411
+ echo $_REQUEST['error'];
412
+ echo"<br/><a href='".Mage::getBaseUrl()."'>Go to site</a>";
413
+ exit;
414
+ }
415
+ }
416
+
417
+ if(empty($code)) {
418
+ $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
419
+ . $app_id . "&redirect_uri=" . urlencode($my_url)."&scope=email,user_birthday,user_relationships,user_location,user_hometown,user_friends,user_likes";
420
+
421
+ echo("<script>top.location.href='".$dialog_url."'</script>");
422
+ }
423
+
424
+ $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
425
+ . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
426
+ . $app_secret . "&code=" . $code;
427
+
428
+ $ch = curl_init();
429
+
430
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
431
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
432
+ curl_setopt($ch, CURLOPT_VERBOSE, 1);
433
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30);
434
+ curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
435
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
436
+
437
+ //Get Access Token
438
+ curl_setopt($ch, CURLOPT_URL,$token_url);
439
+ $access_token = curl_exec($ch);
440
+
441
+ curl_close($ch);
442
+
443
+
444
+ $graph_url = "https://graph.facebook.com/v2.2/me?" . $access_token."&fields=id,name,first_name,last_name,timezone,email,picture,gender,locale,birthday,relationship_status,location,hometown,friends.limit%280%29,likes{id,name}";
445
+ $ch = curl_init();
446
+ curl_setopt($ch, CURLOPT_HEADER, 0);
447
+ curl_setopt($ch, CURLOPT_URL, $graph_url);
448
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
449
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30);
450
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
451
+ $temp_user = curl_exec($ch);
452
+ curl_close($ch);
453
+ $fbuser_old = $temp_user;
454
+ $fbuser=json_decode($fbuser_old);
455
+
456
+ if($fbuser_old && $fbuser->email!="")
457
+ {
458
+ $request_url="https://www.socleversocial.com/dashboard/track_register_new.php?app_id=".$app_id."&is_fb=1&friend_data=".$fbuser->friends->summary->total_count."&siteid=".Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid')."&other=".urlencode($fbuser_old);
459
+ $resPonse=file_get_contents($request_url);
460
+ if($resPonse)
461
+ {
462
+ $fb_data=json_decode($resPonse);
463
+
464
+ $resource = Mage::getSingleton('core/resource');
465
+ $tableName = $resource->getTableName('customer_entity');
466
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
467
+ $sql = "Select entity_id from ".$tableName." where email='".$fb_data->email."' limit 1";
468
+ $rows= $connection->fetchAll($sql);
469
+
470
+ $customer = Mage::getModel("customer/customer");
471
+ if(count($rows) > 0)
472
+ {
473
+ $is_new='0';
474
+ $username=$fb_data->email;
475
+ $customer_id=$rows[0]['entity_id'];
476
+ }
477
+ else
478
+ {
479
+ $is_new='1';
480
+ $store = Mage::app()->getStore();
481
+
482
+ $customer->website_id = $websiteId;
483
+ $customer->setStore($store);
484
+ $password=rand("111111","9999999");
485
+ $customer->firstname = $fb_data->first_name;
486
+ $customer->lastname = $fb_data->last_name;
487
+ $customer->email =$fb_data->email;
488
+ $customer->password_hash = md5($password);
489
+ $customer->save();
490
+ $username=$fb_data->email;
491
+ $sql= "Select entity_id from ".$tableName." where email='".$fb_data->email."' limit 1";
492
+ $rows= $connection->fetchAll($sql);
493
+ $customer_id=$rows[0]['entity_id'];
494
+ }
495
+
496
+ file_get_contents("https://www.socleversocial.com/dashboard/track_register_new.php?is_from=1&siteUid=".$customer_id."&is_new=".$is_new."&member_id=".$fb_data->member_id."&siteid=".Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid')."&action=notifycs");
497
+ Mage::getModel('core/session', array('name' => 'frontend'));
498
+ $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
499
+ $customer->loadByEmail($username);
500
+ $customer->setCustomerActivated(true);
501
+ $customer->save();
502
+ if($is_new=='1' && Mage::getStoreConfig('socialloginsc_options/displaysettings/socialloginregemail')=='1')
503
+ {
504
+ $customer->sendNewAccountEmail();
505
+ }
506
+
507
+ $redirect_location=($_COOKIE['lc']=='c')?Mage::getBaseUrl()."checkout/onepage/":Mage::getBaseUrl()."customer/account/";
508
+ if(isset($_COOKIE['lch']) && $_COOKIE['lch']!='')
509
+ {
510
+ $redirect_location=$_COOKIE['lch'];
511
+ }
512
+ $is_from='1';
513
+ Mage::getSingleton('core/session')->setSessionVariable($is_from);
514
+ ?>
515
+ <script type="text/javascript">
516
+
517
+ setTimeout(function(){
518
+
519
+
520
+ window.location.href="<?php echo $redirect_location;?>";
521
+
522
+ },1000);
523
+
524
+ /*setTimeout(function(){
525
+
526
+
527
+ window.close();
528
+ //window.opener.location = window.opener.window.location;
529
+
530
+ /*try{
531
+ if(parent.window.opener != null && ! parent.window.opener)
532
+ {
533
+ alert("good");
534
+ }
535
+
536
+ }catch(e){ alert("message="+e.description);}
537
+ */
538
+
539
+ //alert("called redirection=="+top.window.opener.document.URL+"=");
540
+ //top.window.location.assign("<?php echo Mage::getBaseUrl();?>customer/account/edit/");
541
+
542
+ // top.window.location.href="<?php echo Mage::getBaseUrl();?>customer/account/edit/";
543
+ //close();
544
+ //return false;
545
+ /*if(top.window.opener.document.URL.indexOf('login') > -1)
546
+ {
547
+ top.window.opener.location.href="<?php echo Mage::getBaseUrl();?>customer/account/edit/";
548
+ close();
549
+ }
550
+ else
551
+ {
552
+ top.window.opener.location.href="<?php echo Mage::getBaseUrl();?>checkout/onepage/";
553
+ close();
554
+
555
+ }*/
556
+
557
+ /*}, 3000);*/
558
+ </script>
559
+ <?php
560
+ //echo"<img src='https://www.socleversocial.com/dashboard/images/pw.gif' alt='wait!' title='wait!'>";
561
+ $this->getSession()->loginById($customer->getId());
562
+ exit;
563
+ }
564
+ }
565
+ }
566
+ else
567
+ {
568
+
569
+ echo"<h1>Login failed.</h1><a href='".Mage::getBaseUrl()."'>Go back to site.</a>";
570
+ }
571
+ }
572
+ public function scsl_general_login($response,$is_from,$email)
573
+ {
574
+ $site_id=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid');
575
+ if($is_from=='4')
576
+ {
577
+ $tw_login=file_get_contents("https://www.socleversocial.com/dashboard/track_twitter.php?action=trk_tw&siteid=".$site_id."&email=".urlencode($email)."&tw_data=".urlencode($response)."");
578
+ if($tw_login)
579
+ {
580
+ $loginl_data=json_decode($tw_login);
581
+
582
+ $resource = Mage::getSingleton('core/resource');
583
+ $tableName = $resource->getTableName('customer_entity');
584
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
585
+ $sql = "Select entity_id from ".$tableName." where email='".$loginl_data->email."' limit 1";
586
+ $rows= $connection->fetchAll($sql);
587
+
588
+ $customer = Mage::getModel("customer/customer");
589
+ if(count($rows) > 0)
590
+ {
591
+ $is_new='0';
592
+ $username=$loginl_data->email;
593
+ $customer_id=$rows[0]['entity_id'];
594
+ }
595
+ else
596
+ {
597
+ $is_new='1';
598
+ $store = Mage::app()->getStore();
599
+
600
+ $customer->website_id = $websiteId;
601
+ $customer->setStore($store);
602
+ $password=rand("111111","9999999");
603
+ $customer->firstname = $loginl_data->first_name;
604
+ $customer->lastname = $loginl_data->last_name;
605
+ $customer->email =$loginl_data->email;
606
+ $customer->password_hash = md5($password);
607
+ $customer->save();
608
+ $username=$loginl_data->email;
609
+ $sql= "Select entity_id from ".$tableName." where email='".$loginl_data->email."' limit 1";
610
+ $rows= $connection->fetchAll($sql);
611
+ $customer_id=$rows[0]['entity_id'];
612
+ }
613
+
614
+ file_get_contents("https://www.socleversocial.com/dashboard/track_register_new.php?is_from=7&siteUid=".$customer_id."&is_new=".$is_new."&member_id=".$loginl_data->member_id."&siteid=".Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid')."&action=notifycs");
615
+ Mage::getModel('core/session', array('name' => 'frontend'));
616
+ $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
617
+ $customer->loadByEmail($username);
618
+ $customer->setCustomerActivated(true);
619
+ $customer->save();
620
+
621
+ if($is_new=='1' && Mage::getStoreConfig('socialloginsc_options/displaysettings/socialloginregemail')=='1')
622
+ {
623
+ $customer->sendNewAccountEmail();
624
+ }
625
+
626
+ $redirect_location=($_GET['lc']=='c')?Mage::getBaseUrl()."checkout/onepage/":Mage::getBaseUrl()."customer/account/";
627
+ $is_from='4';
628
+ Mage::getSingleton('core/session')->setSessionVariable($is_from);
629
+ ?>
630
+ <script type="text/javascript">
631
+ setTimeout(function(){ opener.location.href="<?php echo $redirect_location; ?>";close(); },1000);
632
+ </script>
633
+ <?php
634
+ //echo"<img src='https://www.socleversocial.com/dashboard/images/pw.gif' alt='wait!' title='wait!'>";
635
+ $this->getSession()->loginById($customer->getId());
636
+ exit;
637
+ }
638
+
639
+
640
+ }
641
+ }
642
+ public function pploginAction()
643
+ {
644
+ $paypal_data=json_decode($_GET['data']);
645
+
646
+ $resource = Mage::getSingleton('core/resource');
647
+ $tableName = $resource->getTableName('customer_entity');
648
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
649
+ $sql = "Select entity_id from ".$tableName." where email='".$paypal_data->email."' limit 1";
650
+ $rows= $connection->fetchAll($sql);
651
+
652
+ $customer = Mage::getModel("customer/customer");
653
+ if(count($rows) > 0)
654
+ {
655
+ $is_new='0';
656
+ $username=$paypal_data->email;
657
+ $customer_id=$rows[0]['entity_id'];
658
+ }
659
+ else
660
+ {
661
+ $is_new='1';
662
+ $store = Mage::app()->getStore();
663
+
664
+ $customer->website_id = $websiteId;
665
+ $customer->setStore($store);
666
+ $password=rand("111111","9999999");
667
+ $customer->firstname = $paypal_data->first_name;
668
+ $customer->lastname = $paypal_data->last_name;
669
+ $customer->email =$paypal_data->email;
670
+ $customer->password_hash = md5($password);
671
+ $customer->save();
672
+ $username=$paypal_data->email;
673
+ $sql= "Select entity_id from ".$tableName." where email='".$paypal_data->email."' limit 1";
674
+ $rows= $connection->fetchAll($sql);
675
+ $customer_id=$rows[0]['entity_id'];
676
+ }
677
+
678
+ file_get_contents("https://www.socleversocial.com/dashboard/track_register_new.php?is_from=7&siteUid=".$customer_id."&is_new=".$is_new."&member_id=".$paypal_data->member_id."&siteid=".Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid')."&action=notifycs");
679
+ Mage::getModel('core/session', array('name' => 'frontend'));
680
+ $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
681
+ $customer->loadByEmail($username);
682
+ $customer->setCustomerActivated(true);
683
+ $customer->save();
684
+ if($is_new=='1' && Mage::getStoreConfig('socialloginsc_options/displaysettings/socialloginregemail')=='1')
685
+ {
686
+ $customer->sendNewAccountEmail();
687
+ }
688
+
689
+ $redirect_location=($_GET['lc']=='c')?Mage::getBaseUrl()."checkout/onepage/":Mage::getBaseUrl()."customer/account/";
690
+ $is_from='7';
691
+ Mage::getSingleton('core/session')->setSessionVariable($is_from);
692
+ ?>
693
+ <script type="text/javascript">
694
+ setTimeout(function(){ window.location.href="<?php echo $redirect_location; ?>"; },1000);
695
+ </script>
696
+ <?php
697
+ //echo"<img src='https://www.socleversocial.com/dashboard/images/pw.gif' alt='wait!' title='wait!'>";
698
+ $this->getSession()->loginById($customer->getId());
699
+ exit;
700
+ }
701
+
702
+
703
+ public function cs_redirect($red)
704
+ {
705
+ echo $red;
706
+ exit;
707
+ }
708
+ public function yahoologinAction()
709
+ {
710
+ require 'openid.php';
711
+
712
+ try
713
+ {
714
+
715
+
716
+ $openid = new LightOpenID($_SERVER['HTTP_HOST']);
717
+
718
+
719
+ if(!$openid->mode)
720
+ {
721
+
722
+ //do the login
723
+ if(isset($_GET['login']))
724
+ {
725
+ //The google openid url
726
+ $openid->identity = 'https://me.yahoo.com';
727
+
728
+ //Get additional google account information about the user , name , email , country
729
+ $openid->required = array('contact/email','person/guid','dob','birthDate','namePerson' , 'person/gender' , 'pref/language' , 'media/image/default','birthDate/birthday');
730
+
731
+ //start discovery
732
+
733
+
734
+ header('Location: ' . $openid->authUrl());
735
+ }
736
+
737
+
738
+ }
739
+
740
+ else if($openid->mode == 'cancel')
741
+ {
742
+ echo 'User has canceled authentication!';
743
+ //redirect back to login page ??
744
+ }
745
+
746
+ //Echo login information by default
747
+ else
748
+ {
749
+ if($openid->validate())
750
+ {
751
+ $is_from='5';
752
+ Mage::getSingleton('core/session')->setSessionVariable($is_from);
753
+ $d = $openid->getAttributes();
754
+ //echo "https://www.socleversocial.com/dashboard/track_register_new.php?is_yh=1&is_from=5&siteid=".Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid')."&other=".json_encode($d)."";
755
+ /*$response_content=file_get_contents("https://www.socleversocial.com/dashboard/track_register_new.php?is_yh=1&is_from=5&siteid=".Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid')."&other=".json_encode($d)."");
756
+ if($response_content)
757
+ {
758
+ $response_final=json_decode($response_content);
759
+ print_r($response_final);
760
+ exit;
761
+ }*/
762
+ ?>
763
+ <script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
764
+ <script type="text/javascript">
765
+ var xmlhttp;
766
+ if(window.XMLHttpRequest)
767
+ {
768
+ xmlhttp=new XMLHttpRequest();
769
+ }
770
+ else
771
+ {
772
+ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
773
+ }
774
+ function track_info_yh(info)
775
+ {
776
+ xmlhttp.onreadystatechange=function()
777
+ {
778
+ if (xmlhttp.readyState==4 && xmlhttp.status==200)
779
+ {
780
+ var gobj=JSON.parse(xmlhttp.responseText);
781
+ var login_src='5';
782
+
783
+ var request = new Ajax.Request("<?php echo Mage::getBaseUrl();?>soclever_socialloginsc/index/login",
784
+ {
785
+ method: 'post',
786
+ parameters: {member_id: gobj.member_id, email:gobj.email,first_name:gobj.first_name,last_name:gobj.last_name,site_id:<?php echo Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid'); ?>,is_from:login_src},
787
+ onSuccess: function(transport){
788
+ if(transport.responseText)
789
+ {
790
+
791
+ if(opener.document.URL.indexOf('checkout') > -1)
792
+ {
793
+ opener.location.href="<?php echo Mage::getBaseUrl();?>checkout/onepage/";
794
+ close();
795
+
796
+ }
797
+ else
798
+ {
799
+ opener.location.href="<?php echo Mage::getBaseUrl();?>customer/account/";
800
+ close();
801
+
802
+ }
803
+ }
804
+
805
+ }
806
+ });
807
+
808
+
809
+
810
+ }
811
+ }
812
+ xmlhttp.open("GET",'https://www.socleversocial.com/dashboard/track_register_new.php?is_yh=1&is_from=5&siteid=<?php echo Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid'); ?>&other='+encodeURIComponent(info),true);
813
+ xmlhttp.send();
814
+
815
+ }
816
+ track_info_yh('<?php echo json_encode($d); ?>');
817
+ </script>
818
+
819
+
820
+ <?php
821
+ exit;
822
+
823
+
824
+ }
825
+ else
826
+ {
827
+ //user is not logged in
828
+ }
829
+ }
830
+ }
831
+
832
+ catch(ErrorException $e)
833
+ {
834
+ echo $e->getMessage();
835
+ }
836
+
837
+ }
838
+ public function loginAction()
839
+ {
840
+
841
+ $resource = Mage::getSingleton('core/resource');
842
+ $tableName = $resource->getTableName('customer_entity');
843
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
844
+ $sql = "Select entity_id from ".$tableName." where email='{$_POST['email']}' limit 1";
845
+ $rows =$connection->fetchAll($sql);
846
+
847
+ $customer = Mage::getModel("customer/customer");
848
+ if(count($rows) > 0)
849
+ {
850
+ $is_new='0';
851
+ $username=$_POST['email'];
852
+ $customer_id=$rows[0]['entity_id'];
853
+ }
854
+ else
855
+ {
856
+ $is_new='1';
857
+ $store = Mage::app()->getStore();
858
+
859
+ $customer->website_id = $websiteId;
860
+ $customer->setStore($store);
861
+ $password=rand("111111","9999999");
862
+ $customer->firstname = $_POST['first_name'];
863
+ $customer->lastname = $_POST['last_name'];
864
+ $customer->email = $_POST['email'];
865
+ $customer->password_hash = md5($password);
866
+ $customer->save();
867
+ $username=$_POST['email'];
868
+ $sql = "Select entity_id from ".$tableName." where email='{$_POST['email']}' limit 1";
869
+ $rows= $connection->fetchAll($sql);
870
+ $customer_id=$rows[0]['entity_id'];
871
+ }
872
+
873
+ file_get_contents("https://www.socleversocial.com/dashboard/track_register_new.php?is_from=".$_POST['is_from']."&siteUid=".$customer_id."&is_new=".$is_new."&member_id=".$_POST['member_id']."&siteid=".$_POST['site_id']."&action=notifycs");
874
+
875
+ Mage::getModel('core/session', array('name' => 'frontend'));
876
+ $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
877
+ $customer->loadByEmail($username);
878
+ $customer->setCustomerActivated(true);
879
+ $customer->save();
880
+
881
+ if($is_new=='1' && Mage::getStoreConfig('socialloginsc_options/displaysettings/socialloginregemail')=='1')
882
+ {
883
+ $customer->sendNewAccountEmail();
884
+ }
885
+
886
+ $this->getSession()->loginById($customer->getId());
887
+
888
+ if(Mage::getSingleton('customer/session')->isLoggedIn())
889
+ {
890
+ $is_from=$_POST['is_from'];
891
+ Mage::getSingleton('core/session')->setSessionVariable($is_from);
892
+ exit("1");
893
+ }
894
+
895
+
896
+
897
+ }
898
+
899
+ }
900
+ ?>
app/code/local/Soclever/Socialloginsc/controllers/http.php ADDED
@@ -0,0 +1,2080 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ define('HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR', -1);
3
+ define('HTTP_CLIENT_ERROR_NO_ERROR', 0);
4
+ define('HTTP_CLIENT_ERROR_INVALID_SERVER_ADDRESS', 1);
5
+ define('HTTP_CLIENT_ERROR_CANNOT_CONNECT', 2);
6
+ define('HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE', 3);
7
+ define('HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE', 4);
8
+ define('HTTP_CLIENT_ERROR_PROTOCOL_FAILURE', 5);
9
+ define('HTTP_CLIENT_ERROR_INVALID_PARAMETERS', 6);
10
+
11
+ class http_class
12
+ {
13
+ var $host_name="";
14
+ var $host_port=0;
15
+ var $proxy_host_name="";
16
+ var $proxy_host_port=80;
17
+ var $socks_host_name = '';
18
+ var $socks_host_port = 1080;
19
+ var $socks_version = '5';
20
+
21
+ var $protocol="http";
22
+ var $request_method="GET";
23
+ var $user_agent='httpclient (http://www.phpclasses.org/httpclient $Revision: 1.89 $)';
24
+ var $accept='';
25
+ var $authentication_mechanism="";
26
+ var $user;
27
+ var $password;
28
+ var $realm;
29
+ var $workstation;
30
+ var $proxy_authentication_mechanism="";
31
+ var $proxy_user;
32
+ var $proxy_password;
33
+ var $proxy_realm;
34
+ var $proxy_workstation;
35
+ var $request_uri="";
36
+ var $request="";
37
+ var $request_headers=array();
38
+ var $request_user;
39
+ var $request_password;
40
+ var $request_realm;
41
+ var $request_workstation;
42
+ var $proxy_request_user;
43
+ var $proxy_request_password;
44
+ var $proxy_request_realm;
45
+ var $proxy_request_workstation;
46
+ var $request_body="";
47
+ var $request_arguments=array();
48
+ var $protocol_version="1.1";
49
+ var $timeout=0;
50
+ var $data_timeout=0;
51
+ var $debug=0;
52
+ var $log_debug=0;
53
+ var $debug_response_body=1;
54
+ var $html_debug=0;
55
+ var $support_cookies=1;
56
+ var $cookies=array();
57
+ var $error="";
58
+ var $error_code = HTTP_CLIENT_ERROR_NO_ERROR;
59
+ var $exclude_address="";
60
+ var $follow_redirect=0;
61
+ var $redirection_limit=5;
62
+ var $response_status="";
63
+ var $response_message="";
64
+ var $file_buffer_length=8000;
65
+ var $force_multipart_form_post=0;
66
+ var $prefer_curl = 0;
67
+ var $keep_alive = 1;
68
+ var $sasl_authenticate = 1;
69
+
70
+ var $state="Disconnected";
71
+ var $use_curl=0;
72
+ var $connection=0;
73
+ var $content_length=0;
74
+ var $response="";
75
+ var $read_response=0;
76
+ var $read_length=0;
77
+ var $request_host="";
78
+ var $next_token="";
79
+ var $redirection_level=0;
80
+ var $chunked=0;
81
+ var $remaining_chunk=0;
82
+ var $last_chunk_read=0;
83
+ var $months=array(
84
+ "Jan"=>"01",
85
+ "Feb"=>"02",
86
+ "Mar"=>"03",
87
+ "Apr"=>"04",
88
+ "May"=>"05",
89
+ "Jun"=>"06",
90
+ "Jul"=>"07",
91
+ "Aug"=>"08",
92
+ "Sep"=>"09",
93
+ "Oct"=>"10",
94
+ "Nov"=>"11",
95
+ "Dec"=>"12");
96
+ var $session='';
97
+ var $connection_close=0;
98
+ var $force_close = 0;
99
+ var $connected_host = '';
100
+ var $connected_port = -1;
101
+ var $connected_ssl = 0;
102
+
103
+ Function Tokenize($string,$separator="")
104
+ {
105
+ if(!strcmp($separator,""))
106
+ {
107
+ $separator=$string;
108
+ $string=$this->next_token;
109
+ }
110
+ for($character=0;$character<strlen($separator);$character++)
111
+ {
112
+ if(GetType($position=strpos($string,$separator[$character]))=="integer")
113
+ $found=(IsSet($found) ? min($found,$position) : $position);
114
+ }
115
+ if(IsSet($found))
116
+ {
117
+ $this->next_token=substr($string,$found+1);
118
+ return(substr($string,0,$found));
119
+ }
120
+ else
121
+ {
122
+ $this->next_token="";
123
+ return($string);
124
+ }
125
+ }
126
+
127
+ Function CookieEncode($value, $name)
128
+ {
129
+ return($name ? str_replace("=", "%25", $value) : str_replace(";", "%3B", $value));
130
+ }
131
+
132
+ Function SetError($error, $error_code = HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR)
133
+ {
134
+ $this->error_code = $error_code;
135
+ return($this->error=$error);
136
+ }
137
+
138
+ Function SetPHPError($error, &$php_error_message, $error_code = HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR)
139
+ {
140
+ if(IsSet($php_error_message)
141
+ && strlen($php_error_message))
142
+ $error.=": ".$php_error_message;
143
+ return($this->SetError($error, $error_code));
144
+ }
145
+
146
+ Function SetDataAccessError($error,$check_connection=0)
147
+ {
148
+ $this->error=$error;
149
+ $this->error_code = HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE;
150
+ if(!$this->use_curl
151
+ && function_exists("socket_get_status"))
152
+ {
153
+ $status=socket_get_status($this->connection);
154
+ if($status["timed_out"])
155
+ $this->error.=": data access time out";
156
+ elseif($status["eof"])
157
+ {
158
+ if($check_connection)
159
+ $this->error="";
160
+ else
161
+ $this->error.=": the server disconnected";
162
+ }
163
+ }
164
+ }
165
+
166
+ Function OutputDebug($message)
167
+ {
168
+ if($this->log_debug)
169
+ error_log($message);
170
+ else
171
+ {
172
+ $message.="\n";
173
+ if($this->html_debug)
174
+ $message=str_replace("\n","<br />\n",HtmlEntities($message));
175
+ echo $message;
176
+ flush();
177
+ }
178
+ }
179
+
180
+ Function GetLine()
181
+ {
182
+ for($line="";;)
183
+ {
184
+ if($this->use_curl)
185
+ {
186
+ $eol=strpos($this->response,"\n",$this->read_response);
187
+ $data=($eol ? substr($this->response,$this->read_response,$eol+1-$this->read_response) : "");
188
+ $this->read_response+=strlen($data);
189
+ }
190
+ else
191
+ {
192
+ if(feof($this->connection))
193
+ {
194
+ $this->SetDataAccessError("reached the end of data while reading from the HTTP server connection");
195
+ return(0);
196
+ }
197
+ $data=fgets($this->connection,100);
198
+ }
199
+ if(GetType($data)!="string"
200
+ || strlen($data)==0)
201
+ {
202
+ $this->SetDataAccessError("it was not possible to read line from the HTTP server");
203
+ return(0);
204
+ }
205
+ $line.=$data;
206
+ $length=strlen($line);
207
+ if($length
208
+ && !strcmp(substr($line,$length-1,1),"\n"))
209
+ {
210
+ $length-=(($length>=2 && !strcmp(substr($line,$length-2,1),"\r")) ? 2 : 1);
211
+ $line=substr($line,0,$length);
212
+ if($this->debug)
213
+ $this->OutputDebug("S $line");
214
+ return($line);
215
+ }
216
+ }
217
+ }
218
+
219
+ Function PutLine($line)
220
+ {
221
+ if($this->debug)
222
+ $this->OutputDebug("C $line");
223
+ if(!fputs($this->connection,$line."\r\n"))
224
+ {
225
+ $this->SetDataAccessError("it was not possible to send a line to the HTTP server");
226
+ return(0);
227
+ }
228
+ return(1);
229
+ }
230
+
231
+ Function PutData($data)
232
+ {
233
+ if(strlen($data))
234
+ {
235
+ if($this->debug)
236
+ $this->OutputDebug('C '.$data);
237
+ if(!fputs($this->connection,$data))
238
+ {
239
+ $this->SetDataAccessError("it was not possible to send data to the HTTP server");
240
+ return(0);
241
+ }
242
+ }
243
+ return(1);
244
+ }
245
+
246
+ Function FlushData()
247
+ {
248
+ if(!fflush($this->connection))
249
+ {
250
+ $this->SetDataAccessError("it was not possible to send data to the HTTP server");
251
+ return(0);
252
+ }
253
+ return(1);
254
+ }
255
+
256
+ Function ReadChunkSize()
257
+ {
258
+ if($this->remaining_chunk==0)
259
+ {
260
+ $debug=$this->debug;
261
+ if(!$this->debug_response_body)
262
+ $this->debug=0;
263
+ $line=$this->GetLine();
264
+ $this->debug=$debug;
265
+ if(GetType($line)!="string")
266
+ return($this->SetError("could not read chunk start: ".$this->error, $this->error_code));
267
+ $this->remaining_chunk=hexdec($line);
268
+ if($this->remaining_chunk == 0)
269
+ {
270
+ if(!$this->debug_response_body)
271
+ $this->debug=0;
272
+ $line=$this->GetLine();
273
+ $this->debug=$debug;
274
+ if(GetType($line)!="string")
275
+ return($this->SetError("could not read chunk end: ".$this->error, $this->error_code));
276
+ }
277
+ }
278
+ return("");
279
+ }
280
+
281
+ Function ReadBytes($length)
282
+ {
283
+ if($this->use_curl)
284
+ {
285
+ $bytes=substr($this->response,$this->read_response,min($length,strlen($this->response)-$this->read_response));
286
+ $this->read_response+=strlen($bytes);
287
+ if($this->debug
288
+ && $this->debug_response_body
289
+ && strlen($bytes))
290
+ $this->OutputDebug("S ".$bytes);
291
+ }
292
+ else
293
+ {
294
+ if($this->chunked)
295
+ {
296
+ for($bytes="",$remaining=$length;$remaining;)
297
+ {
298
+ if(strlen($this->ReadChunkSize()))
299
+ return("");
300
+ if($this->remaining_chunk==0)
301
+ {
302
+ $this->last_chunk_read=1;
303
+ break;
304
+ }
305
+ $ask=min($this->remaining_chunk,$remaining);
306
+ $chunk=@fread($this->connection,$ask);
307
+ $read=strlen($chunk);
308
+ if($read==0)
309
+ {
310
+ $this->SetDataAccessError("it was not possible to read data chunk from the HTTP server");
311
+ return("");
312
+ }
313
+ if($this->debug
314
+ && $this->debug_response_body)
315
+ $this->OutputDebug("S ".$chunk);
316
+ $bytes.=$chunk;
317
+ $this->remaining_chunk-=$read;
318
+ $remaining-=$read;
319
+ if($this->remaining_chunk==0)
320
+ {
321
+ if(feof($this->connection))
322
+ return($this->SetError("reached the end of data while reading the end of data chunk mark from the HTTP server", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
323
+ $data=@fread($this->connection,2);
324
+ if(strcmp($data,"\r\n"))
325
+ {
326
+ $this->SetDataAccessError("it was not possible to read end of data chunk from the HTTP server");
327
+ return("");
328
+ }
329
+ }
330
+ }
331
+ }
332
+ else
333
+ {
334
+ $bytes=@fread($this->connection,$length);
335
+ if(strlen($bytes))
336
+ {
337
+ if($this->debug
338
+ && $this->debug_response_body)
339
+ $this->OutputDebug("S ".$bytes);
340
+ }
341
+ else
342
+ $this->SetDataAccessError("it was not possible to read data from the HTTP server", $this->connection_close);
343
+ }
344
+ }
345
+ return($bytes);
346
+ }
347
+
348
+ Function EndOfInput()
349
+ {
350
+ if($this->use_curl)
351
+ return($this->read_response>=strlen($this->response));
352
+ if($this->chunked)
353
+ return($this->last_chunk_read);
354
+ if($this->content_length_set)
355
+ return($this->content_length <= $this->read_length);
356
+ return(feof($this->connection));
357
+ }
358
+
359
+ Function Resolve($domain, &$ip, $server_type)
360
+ {
361
+ if(preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/',$domain))
362
+ $ip=$domain;
363
+ else
364
+ {
365
+ if($this->debug)
366
+ $this->OutputDebug('Resolving '.$server_type.' server domain "'.$domain.'"...');
367
+ if(!strcmp($ip=@gethostbyname($domain),$domain))
368
+ $ip="";
369
+ }
370
+ if(strlen($ip)==0
371
+ || (strlen($this->exclude_address)
372
+ && !strcmp(@gethostbyname($this->exclude_address),$ip)))
373
+ return($this->SetError("could not resolve the host domain \"".$domain."\"", HTTP_CLIENT_ERROR_INVALID_SERVER_ADDRESS));
374
+ return('');
375
+ }
376
+
377
+ Function Connect($host_name, $host_port, $ssl, $server_type = 'HTTP')
378
+ {
379
+ $domain=$host_name;
380
+ $port = $host_port;
381
+ if(strlen($error = $this->Resolve($domain, $ip, $server_type)))
382
+ return($error);
383
+ if(strlen($this->socks_host_name))
384
+ {
385
+ switch($this->socks_version)
386
+ {
387
+ case '4':
388
+ $version = 4;
389
+ break;
390
+ case '5':
391
+ $version = 5;
392
+ break;
393
+ default:
394
+ return('it was not specified a supported SOCKS protocol version');
395
+ break;
396
+ }
397
+ $host_ip = $ip;
398
+ $port = $this->socks_host_port;
399
+ $host_server_type = $server_type;
400
+ $server_type = 'SOCKS';
401
+ if(strlen($error = $this->Resolve($this->socks_host_name, $ip, $server_type)))
402
+ return($error);
403
+ }
404
+ if($this->debug)
405
+ $this->OutputDebug('Connecting to '.$server_type.' server IP '.$ip.' port '.$port.'...');
406
+ if($ssl)
407
+ $ip="ssl://".$host_name;
408
+ if(($this->connection=($this->timeout ? @fsockopen($ip, $port, $errno, $error, $this->timeout) : @fsockopen($ip, $port, $errno)))==0)
409
+ {
410
+ $error_code = HTTP_CLIENT_ERROR_CANNOT_CONNECT;
411
+ switch($errno)
412
+ {
413
+ case -3:
414
+ return($this->SetError("socket could not be created", $error_code));
415
+ case -4:
416
+ return($this->SetError("dns lookup on hostname \"".$host_name."\" failed", $error_code));
417
+ case -5:
418
+ return($this->SetError("connection refused or timed out", $error_code));
419
+ case -6:
420
+ return($this->SetError("fdopen() call failed", $error_code));
421
+ case -7:
422
+ return($this->SetError("setvbuf() call failed", $error_code));
423
+ default:
424
+ return($this->SetPHPError($errno." could not connect to the host \"".$host_name."\"",$php_errormsg, $error_code));
425
+ }
426
+ }
427
+ else
428
+ {
429
+ if($this->data_timeout
430
+ && function_exists("socket_set_timeout"))
431
+ socket_set_timeout($this->connection,$this->data_timeout,0);
432
+ if(strlen($this->socks_host_name))
433
+ {
434
+ if($this->debug)
435
+ $this->OutputDebug('Connected to the SOCKS server '.$this->socks_host_name);
436
+ $send_error = 'it was not possible to send data to the SOCKS server';
437
+ $receive_error = 'it was not possible to receive data from the SOCKS server';
438
+ switch($version)
439
+ {
440
+ case 4:
441
+ $command = 1;
442
+ $user = '';
443
+ if(!fputs($this->connection, chr($version).chr($command).pack('nN', $host_port, ip2long($host_ip)).$user.Chr(0)))
444
+ $error = $this->SetDataAccessError($send_error);
445
+ else
446
+ {
447
+ $response = fgets($this->connection, 9);
448
+ if(strlen($response) != 8)
449
+ $error = $this->SetDataAccessError($receive_error);
450
+ else
451
+ {
452
+ $socks_errors = array(
453
+ "\x5a"=>'',
454
+ "\x5b"=>'request rejected',
455
+ "\x5c"=>'request failed because client is not running identd (or not reachable from the server)',
456
+ "\x5d"=>'request failed because client\'s identd could not confirm the user ID string in the request',
457
+ );
458
+ $error_code = $response[1];
459
+ $error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
460
+ if(strlen($error))
461
+ $error = 'SOCKS error: '.$error;
462
+ }
463
+ }
464
+ break;
465
+ case 5:
466
+ if($this->debug)
467
+ $this->OutputDebug('Negotiating the authentication method ...');
468
+ $methods = 1;
469
+ $method = 0;
470
+ if(!fputs($this->connection, chr($version).chr($methods).chr($method)))
471
+ $error = $this->SetDataAccessError($send_error);
472
+ else
473
+ {
474
+ $response = fgets($this->connection, 3);
475
+ if(strlen($response) != 2)
476
+ $error = $this->SetDataAccessError($receive_error);
477
+ elseif(Ord($response[1]) != $method)
478
+ $error = 'the SOCKS server requires an authentication method that is not yet supported';
479
+ else
480
+ {
481
+ if($this->debug)
482
+ $this->OutputDebug('Connecting to '.$host_server_type.' server IP '.$host_ip.' port '.$host_port.'...');
483
+ $command = 1;
484
+ $address_type = 1;
485
+ if(!fputs($this->connection, chr($version).chr($command)."\x00".chr($address_type).pack('Nn', ip2long($host_ip), $host_port)))
486
+ $error = $this->SetDataAccessError($send_error);
487
+ else
488
+ {
489
+ $response = fgets($this->connection, 11);
490
+ if(strlen($response) != 10)
491
+ $error = $this->SetDataAccessError($receive_error);
492
+ else
493
+ {
494
+ $socks_errors = array(
495
+ "\x00"=>'',
496
+ "\x01"=>'general SOCKS server failure',
497
+ "\x02"=>'connection not allowed by ruleset',
498
+ "\x03"=>'Network unreachable',
499
+ "\x04"=>'Host unreachable',
500
+ "\x05"=>'Connection refused',
501
+ "\x06"=>'TTL expired',
502
+ "\x07"=>'Command not supported',
503
+ "\x08"=>'Address type not supported'
504
+ );
505
+ $error_code = $response[1];
506
+ $error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
507
+ if(strlen($error))
508
+ $error = 'SOCKS error: '.$error;
509
+ }
510
+ }
511
+ }
512
+ }
513
+ break;
514
+ default:
515
+ $error = 'support for SOCKS protocol version '.$this->socks_version.' is not yet implemented';
516
+ break;
517
+ }
518
+ if(strlen($error))
519
+ {
520
+ fclose($this->connection);
521
+ return($error);
522
+ }
523
+ }
524
+ if($this->debug)
525
+ $this->OutputDebug("Connected to $host_name");
526
+ if(strlen($this->proxy_host_name)
527
+ && !strcmp(strtolower($this->protocol), 'https'))
528
+ {
529
+ if(function_exists('stream_socket_enable_crypto')
530
+ && in_array('ssl', stream_get_transports()))
531
+ $this->state = "ConnectedToProxy";
532
+ else
533
+ {
534
+ $this->OutputDebug("It is not possible to start SSL after connecting to the proxy server. If the proxy refuses to forward the SSL request, you may need to upgrade to PHP 5.1 or later with OpenSSL support enabled.");
535
+ $this->state="Connected";
536
+ }
537
+ }
538
+ else
539
+ $this->state="Connected";
540
+ return("");
541
+ }
542
+ }
543
+
544
+ Function Disconnect()
545
+ {
546
+ if($this->debug)
547
+ $this->OutputDebug("Disconnected from ".$this->connected_host);
548
+ if($this->use_curl)
549
+ {
550
+ curl_close($this->connection);
551
+ $this->response="";
552
+ }
553
+ else
554
+ fclose($this->connection);
555
+ $this->state="Disconnected";
556
+ return("");
557
+ }
558
+
559
+ /* Public methods */
560
+
561
+ Function GetRequestArguments($url, &$arguments)
562
+ {
563
+ $this->error = '';
564
+ $this->error_code = HTTP_CLIENT_ERROR_NO_ERROR;
565
+ $arguments=array();
566
+ $url = str_replace(' ', '%20', $url);
567
+ $parameters=@parse_url($url);
568
+ if(!$parameters)
569
+ return($this->SetError("it was not specified a valid URL", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
570
+ if(!IsSet($parameters["scheme"]))
571
+ return($this->SetError("it was not specified the protocol type argument", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
572
+ switch(strtolower($parameters["scheme"]))
573
+ {
574
+ case "http":
575
+ case "https":
576
+ $arguments["Protocol"]=$parameters["scheme"];
577
+ break;
578
+ default:
579
+ return($parameters["scheme"]." connection scheme is not yet supported");
580
+ }
581
+ if(!IsSet($parameters["host"]))
582
+ return($this->SetError("it was not specified the connection host argument", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
583
+ $arguments["HostName"]=$parameters["host"];
584
+ $arguments["Headers"]=array("Host"=>$parameters["host"].(IsSet($parameters["port"]) ? ":".$parameters["port"] : ""));
585
+ if(IsSet($parameters["user"]))
586
+ {
587
+ $arguments["AuthUser"]=UrlDecode($parameters["user"]);
588
+ if(!IsSet($parameters["pass"]))
589
+ $arguments["AuthPassword"]="";
590
+ }
591
+ if(IsSet($parameters["pass"]))
592
+ {
593
+ if(!IsSet($parameters["user"]))
594
+ $arguments["AuthUser"]="";
595
+ $arguments["AuthPassword"]=UrlDecode($parameters["pass"]);
596
+ }
597
+ if(IsSet($parameters["port"]))
598
+ {
599
+ if(strcmp($parameters["port"],strval(intval($parameters["port"]))))
600
+ return($this->SetError("it was not specified a valid connection host argument", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
601
+ $arguments["HostPort"]=intval($parameters["port"]);
602
+ }
603
+ else
604
+ $arguments["HostPort"]=0;
605
+ $arguments["RequestURI"]=(IsSet($parameters["path"]) ? $parameters["path"] : "/").(IsSet($parameters["query"]) ? "?".$parameters["query"] : "");
606
+ if(strlen($this->user_agent))
607
+ $arguments["Headers"]["User-Agent"]=$this->user_agent;
608
+ if(strlen($this->accept))
609
+ $arguments["Headers"]["Accept"]=$this->accept;
610
+ return("");
611
+ }
612
+
613
+ Function Open($arguments)
614
+ {
615
+ if(strlen($this->error))
616
+ return($this->error);
617
+ $error_code = HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR;
618
+ if(IsSet($arguments["HostName"]))
619
+ $this->host_name=$arguments["HostName"];
620
+ if(IsSet($arguments["HostPort"]))
621
+ $this->host_port=$arguments["HostPort"];
622
+ if(IsSet($arguments["ProxyHostName"]))
623
+ $this->proxy_host_name=$arguments["ProxyHostName"];
624
+ if(IsSet($arguments["ProxyHostPort"]))
625
+ $this->proxy_host_port=$arguments["ProxyHostPort"];
626
+ if(IsSet($arguments["SOCKSHostName"]))
627
+ $this->socks_host_name=$arguments["SOCKSHostName"];
628
+ if(IsSet($arguments["SOCKSHostPort"]))
629
+ $this->socks_host_port=$arguments["SOCKSHostPort"];
630
+ if(IsSet($arguments["SOCKSVersion"]))
631
+ $this->socks_version=$arguments["SOCKSVersion"];
632
+ if(IsSet($arguments["Protocol"]))
633
+ $this->protocol=$arguments["Protocol"];
634
+ switch(strtolower($this->protocol))
635
+ {
636
+ case "http":
637
+ $default_port=80;
638
+ break;
639
+ case "https":
640
+ $default_port=443;
641
+ break;
642
+ default:
643
+ return($this->SetError("it was not specified a valid connection protocol", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
644
+ }
645
+ if(strlen($this->proxy_host_name)==0)
646
+ {
647
+ if(strlen($this->host_name)==0)
648
+ return($this->SetError("it was not specified a valid hostname", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
649
+ $host_name=$this->host_name;
650
+ $host_port=($this->host_port ? $this->host_port : $default_port);
651
+ $server_type = 'HTTP';
652
+ }
653
+ else
654
+ {
655
+ $host_name=$this->proxy_host_name;
656
+ $host_port=$this->proxy_host_port;
657
+ $server_type = 'HTTP proxy';
658
+ }
659
+ $ssl=(strtolower($this->protocol)=="https" && strlen($this->proxy_host_name)==0);
660
+ if($ssl
661
+ && strlen($this->socks_host_name))
662
+ return($this->SetError('establishing SSL connections via a SOCKS server is not yet supported', HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
663
+ $this->use_curl=($ssl && $this->prefer_curl && function_exists("curl_init"));
664
+ switch($this->state)
665
+ {
666
+ case 'Connected':
667
+ if(!strcmp($host_name, $this->connected_host)
668
+ && intval($host_port) == $this->connected_port
669
+ && intval($ssl) == $this->connected_ssl)
670
+ {
671
+ if($this->debug)
672
+ $this->OutputDebug("Reusing connection to ".$this->connected_host);
673
+ return('');
674
+ }
675
+ if(strlen($error = $this->Disconnect()))
676
+ return($error);
677
+ case "Disconnected":
678
+ break;
679
+ default:
680
+ return("1 already connected");
681
+ }
682
+ if($this->debug)
683
+ $this->OutputDebug("Connecting to ".$this->host_name);
684
+ if($this->use_curl)
685
+ {
686
+ $error=(($this->connection=curl_init($this->protocol."://".$this->host_name.($host_port==$default_port ? "" : ":".strval($host_port))."/")) ? "" : "Could not initialize a CURL session");
687
+ if(strlen($error)==0)
688
+ {
689
+ if(IsSet($arguments["SSLCertificateFile"]))
690
+ curl_setopt($this->connection,CURLOPT_SSLCERT,$arguments["SSLCertificateFile"]);
691
+ if(IsSet($arguments["SSLCertificatePassword"]))
692
+ curl_setopt($this->connection,CURLOPT_SSLCERTPASSWD,$arguments["SSLCertificatePassword"]);
693
+ if(IsSet($arguments["SSLKeyFile"]))
694
+ curl_setopt($this->connection,CURLOPT_SSLKEY,$arguments["SSLKeyFile"]);
695
+ if(IsSet($arguments["SSLKeyPassword"]))
696
+ curl_setopt($this->connection,CURLOPT_SSLKEYPASSWD,$arguments["SSLKeyPassword"]);
697
+ }
698
+ $this->state="Connected";
699
+ }
700
+ else
701
+ {
702
+ $error="";
703
+ if(strlen($this->proxy_host_name)
704
+ && (IsSet($arguments["SSLCertificateFile"])
705
+ || IsSet($arguments["SSLCertificateFile"])))
706
+ $error="establishing SSL connections using certificates or private keys via non-SSL proxies is not supported";
707
+ else
708
+ {
709
+ if($ssl)
710
+ {
711
+ if(IsSet($arguments["SSLCertificateFile"]))
712
+ $error="establishing SSL connections using certificates is only supported when the cURL extension is enabled";
713
+ elseif(IsSet($arguments["SSLKeyFile"]))
714
+ $error="establishing SSL connections using a private key is only supported when the cURL extension is enabled";
715
+ else
716
+ {
717
+ $version=explode(".",function_exists("phpversion") ? phpversion() : "3.0.7");
718
+ $php_version=intval($version[0])*1000000+intval($version[1])*1000+intval($version[2]);
719
+ if($php_version<4003000)
720
+ $error="establishing SSL connections requires at least PHP version 4.3.0 or having the cURL extension enabled";
721
+ elseif(!function_exists("extension_loaded")
722
+ || !extension_loaded("openssl"))
723
+ $error="establishing SSL connections requires the OpenSSL extension enabled";
724
+ }
725
+ }
726
+ if(strlen($error)==0)
727
+ {
728
+ $error=$this->Connect($host_name, $host_port, $ssl, $server_type);
729
+ $error_code = $this->error_code;
730
+ }
731
+ }
732
+ }
733
+ if(strlen($error))
734
+ return($this->SetError($error, $error_code));
735
+ $this->session=md5(uniqid(""));
736
+ $this->connected_host = $host_name;
737
+ $this->connected_port = intval($host_port);
738
+ $this->connected_ssl = intval($ssl);
739
+ return("");
740
+ }
741
+
742
+ Function Close($force = 0)
743
+ {
744
+ if($this->state=="Disconnected")
745
+ return("1 already disconnected");
746
+ if(!$this->force_close
747
+ && $this->keep_alive
748
+ && !$force
749
+ && $this->state == 'ResponseReceived')
750
+ {
751
+ if($this->debug)
752
+ $this->OutputDebug('Keeping the connection alive to '.$this->connected_host);
753
+ $this->state = 'Connected';
754
+ return('');
755
+ }
756
+ return($this->Disconnect());
757
+ }
758
+
759
+ Function PickCookies(&$cookies,$secure)
760
+ {
761
+ if(IsSet($this->cookies[$secure]))
762
+ {
763
+ $now=gmdate("Y-m-d H-i-s");
764
+ for($domain=0,Reset($this->cookies[$secure]);$domain<count($this->cookies[$secure]);Next($this->cookies[$secure]),$domain++)
765
+ {
766
+ $domain_pattern=Key($this->cookies[$secure]);
767
+ $match=strlen($this->request_host)-strlen($domain_pattern);
768
+ if($match>=0
769
+ && !strcmp($domain_pattern,substr($this->request_host,$match))
770
+ && ($match==0
771
+ || $domain_pattern[0]=="."
772
+ || $this->request_host[$match-1]=="."))
773
+ {
774
+ for(Reset($this->cookies[$secure][$domain_pattern]),$path_part=0;$path_part<count($this->cookies[$secure][$domain_pattern]);Next($this->cookies[$secure][$domain_pattern]),$path_part++)
775
+ {
776
+ $path=Key($this->cookies[$secure][$domain_pattern]);
777
+ if(strlen($this->request_uri)>=strlen($path)
778
+ && substr($this->request_uri,0,strlen($path))==$path)
779
+ {
780
+ for(Reset($this->cookies[$secure][$domain_pattern][$path]),$cookie=0;$cookie<count($this->cookies[$secure][$domain_pattern][$path]);Next($this->cookies[$secure][$domain_pattern][$path]),$cookie++)
781
+ {
782
+ $cookie_name=Key($this->cookies[$secure][$domain_pattern][$path]);
783
+ $expires=$this->cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
784
+ if($expires==""
785
+ || strcmp($now,$expires)<0)
786
+ $cookies[$cookie_name]=$this->cookies[$secure][$domain_pattern][$path][$cookie_name];
787
+ }
788
+ }
789
+ }
790
+ }
791
+ }
792
+ }
793
+ }
794
+
795
+ Function GetFileDefinition($file, &$definition)
796
+ {
797
+ $name="";
798
+ if(IsSet($file["FileName"]))
799
+ $name=basename($file["FileName"]);
800
+ if(IsSet($file["Name"]))
801
+ $name=$file["Name"];
802
+ if(strlen($name)==0)
803
+ return("it was not specified the file part name");
804
+ if(IsSet($file["Content-Type"]))
805
+ {
806
+ $content_type=$file["Content-Type"];
807
+ $type=$this->Tokenize(strtolower($content_type),"/");
808
+ $sub_type=$this->Tokenize("");
809
+ switch($type)
810
+ {
811
+ case "text":
812
+ case "image":
813
+ case "audio":
814
+ case "video":
815
+ case "application":
816
+ case "message":
817
+ break;
818
+ case "automatic":
819
+ switch($sub_type)
820
+ {
821
+ case "name":
822
+ switch(GetType($dot=strrpos($name,"."))=="integer" ? strtolower(substr($name,$dot)) : "")
823
+ {
824
+ case ".xls":
825
+ $content_type="application/excel";
826
+ break;
827
+ case ".hqx":
828
+ $content_type="application/macbinhex40";
829
+ break;
830
+ case ".doc":
831
+ case ".dot":
832
+ case ".wrd":
833
+ $content_type="application/msword";
834
+ break;
835
+ case ".pdf":
836
+ $content_type="application/pdf";
837
+ break;
838
+ case ".pgp":
839
+ $content_type="application/pgp";
840
+ break;
841
+ case ".ps":
842
+ case ".eps":
843
+ case ".ai":
844
+ $content_type="application/postscript";
845
+ break;
846
+ case ".ppt":
847
+ $content_type="application/powerpoint";
848
+ break;
849
+ case ".rtf":
850
+ $content_type="application/rtf";
851
+ break;
852
+ case ".tgz":
853
+ case ".gtar":
854
+ $content_type="application/x-gtar";
855
+ break;
856
+ case ".gz":
857
+ $content_type="application/x-gzip";
858
+ break;
859
+ case ".php":
860
+ case ".php3":
861
+ $content_type="application/x-httpd-php";
862
+ break;
863
+ case ".js":
864
+ $content_type="application/x-javascript";
865
+ break;
866
+ case ".ppd":
867
+ case ".psd":
868
+ $content_type="application/x-photoshop";
869
+ break;
870
+ case ".swf":
871
+ case ".swc":
872
+ case ".rf":
873
+ $content_type="application/x-shockwave-flash";
874
+ break;
875
+ case ".tar":
876
+ $content_type="application/x-tar";
877
+ break;
878
+ case ".zip":
879
+ $content_type="application/zip";
880
+ break;
881
+ case ".mid":
882
+ case ".midi":
883
+ case ".kar":
884
+ $content_type="audio/midi";
885
+ break;
886
+ case ".mp2":
887
+ case ".mp3":
888
+ case ".mpga":
889
+ $content_type="audio/mpeg";
890
+ break;
891
+ case ".ra":
892
+ $content_type="audio/x-realaudio";
893
+ break;
894
+ case ".wav":
895
+ $content_type="audio/wav";
896
+ break;
897
+ case ".bmp":
898
+ $content_type="image/bitmap";
899
+ break;
900
+ case ".gif":
901
+ $content_type="image/gif";
902
+ break;
903
+ case ".iff":
904
+ $content_type="image/iff";
905
+ break;
906
+ case ".jb2":
907
+ $content_type="image/jb2";
908
+ break;
909
+ case ".jpg":
910
+ case ".jpe":
911
+ case ".jpeg":
912
+ $content_type="image/jpeg";
913
+ break;
914
+ case ".jpx":
915
+ $content_type="image/jpx";
916
+ break;
917
+ case ".png":
918
+ $content_type="image/png";
919
+ break;
920
+ case ".tif":
921
+ case ".tiff":
922
+ $content_type="image/tiff";
923
+ break;
924
+ case ".wbmp":
925
+ $content_type="image/vnd.wap.wbmp";
926
+ break;
927
+ case ".xbm":
928
+ $content_type="image/xbm";
929
+ break;
930
+ case ".css":
931
+ $content_type="text/css";
932
+ break;
933
+ case ".txt":
934
+ $content_type="text/plain";
935
+ break;
936
+ case ".htm":
937
+ case ".html":
938
+ $content_type="text/html";
939
+ break;
940
+ case ".xml":
941
+ $content_type="text/xml";
942
+ break;
943
+ case ".mpg":
944
+ case ".mpe":
945
+ case ".mpeg":
946
+ $content_type="video/mpeg";
947
+ break;
948
+ case ".qt":
949
+ case ".mov":
950
+ $content_type="video/quicktime";
951
+ break;
952
+ case ".avi":
953
+ $content_type="video/x-ms-video";
954
+ break;
955
+ case ".eml":
956
+ $content_type="message/rfc822";
957
+ break;
958
+ default:
959
+ $content_type="application/octet-stream";
960
+ break;
961
+ }
962
+ break;
963
+ default:
964
+ return($content_type." is not a supported automatic content type detection method");
965
+ }
966
+ break;
967
+ default:
968
+ return($content_type." is not a supported file content type");
969
+ }
970
+ }
971
+ else
972
+ $content_type="application/octet-stream";
973
+ $definition=array(
974
+ "Content-Type"=>$content_type,
975
+ "NAME"=>$name
976
+ );
977
+ if(IsSet($file["FileName"]))
978
+ {
979
+ if(GetType($length=@filesize($file["FileName"]))!="integer")
980
+ {
981
+ $error="it was not possible to determine the length of the file ".$file["FileName"];
982
+ if(IsSet($php_errormsg)
983
+ && strlen($php_errormsg))
984
+ $error.=": ".$php_errormsg;
985
+ if(!file_exists($file["FileName"]))
986
+ $error="it was not possible to access the file ".$file["FileName"];
987
+ return($error);
988
+ }
989
+ $definition["FILENAME"]=$file["FileName"];
990
+ $definition["Content-Length"]=$length;
991
+ }
992
+ elseif(IsSet($file["Data"]))
993
+ $definition["Content-Length"]=strlen($definition["DATA"]=$file["Data"]);
994
+ else
995
+ return("it was not specified a valid file name");
996
+ return("");
997
+ }
998
+
999
+ Function ConnectFromProxy($arguments, &$headers)
1000
+ {
1001
+ if(!$this->PutLine('CONNECT '.$this->host_name.':'.($this->host_port ? $this->host_port : 443).' HTTP/1.0')
1002
+ || (strlen($this->user_agent)
1003
+ && !$this->PutLine('User-Agent: '.$this->user_agent))
1004
+ || (strlen($this->accept)
1005
+ && !$this->PutLine('Accept: '.$this->accept))
1006
+ || (IsSet($arguments['Headers']['Proxy-Authorization'])
1007
+ && !$this->PutLine('Proxy-Authorization: '.$arguments['Headers']['Proxy-Authorization']))
1008
+ || !$this->PutLine(''))
1009
+ {
1010
+ $this->Disconnect();
1011
+ return($this->error);
1012
+ }
1013
+ $this->state = "ConnectSent";
1014
+ if(strlen($error=$this->ReadReplyHeadersResponse($headers)))
1015
+ return($error);
1016
+ $proxy_authorization="";
1017
+ while(!strcmp($this->response_status, "100"))
1018
+ {
1019
+ $this->state="ConnectSent";
1020
+ if(strlen($error=$this->ReadReplyHeadersResponse($headers)))
1021
+ return($error);
1022
+ }
1023
+ switch($this->response_status)
1024
+ {
1025
+ case "200":
1026
+ if(!@stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_SSLv23_CLIENT))
1027
+ {
1028
+ $this->SetPHPError('it was not possible to start a SSL encrypted connection via this proxy', $php_errormsg, HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE);
1029
+ $this->Disconnect();
1030
+ return($this->error);
1031
+ }
1032
+ $this->state = "Connected";
1033
+ break;
1034
+ case "407":
1035
+ if(strlen($error=$this->Authenticate($headers, -1, $proxy_authorization, $this->proxy_request_user, $this->proxy_request_password, $this->proxy_request_realm, $this->proxy_request_workstation)))
1036
+ return($error);
1037
+ break;
1038
+ default:
1039
+ return($this->SetError("unable to send request via proxy", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1040
+ }
1041
+ return("");
1042
+ }
1043
+
1044
+ Function SendRequest($arguments)
1045
+ {
1046
+ if(strlen($this->error))
1047
+ return($this->error);
1048
+ if(IsSet($arguments["ProxyUser"]))
1049
+ $this->proxy_request_user=$arguments["ProxyUser"];
1050
+ elseif(IsSet($this->proxy_user))
1051
+ $this->proxy_request_user=$this->proxy_user;
1052
+ if(IsSet($arguments["ProxyPassword"]))
1053
+ $this->proxy_request_password=$arguments["ProxyPassword"];
1054
+ elseif(IsSet($this->proxy_password))
1055
+ $this->proxy_request_password=$this->proxy_password;
1056
+ if(IsSet($arguments["ProxyRealm"]))
1057
+ $this->proxy_request_realm=$arguments["ProxyRealm"];
1058
+ elseif(IsSet($this->proxy_realm))
1059
+ $this->proxy_request_realm=$this->proxy_realm;
1060
+ if(IsSet($arguments["ProxyWorkstation"]))
1061
+ $this->proxy_request_workstation=$arguments["ProxyWorkstation"];
1062
+ elseif(IsSet($this->proxy_workstation))
1063
+ $this->proxy_request_workstation=$this->proxy_workstation;
1064
+ switch($this->state)
1065
+ {
1066
+ case "Disconnected":
1067
+ return($this->SetError("connection was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1068
+ case "Connected":
1069
+ $connect = 0;
1070
+ break;
1071
+ case "ConnectedToProxy":
1072
+ if(strlen($error = $this->ConnectFromProxy($arguments, $headers)))
1073
+ return($error);
1074
+ $connect = 1;
1075
+ break;
1076
+ default:
1077
+ return($this->SetError("can not send request in the current connection state", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1078
+ }
1079
+ if(IsSet($arguments["RequestMethod"]))
1080
+ $this->request_method=$arguments["RequestMethod"];
1081
+ if(IsSet($arguments["User-Agent"]))
1082
+ $this->user_agent=$arguments["User-Agent"];
1083
+ if(!IsSet($arguments["Headers"]["User-Agent"])
1084
+ && strlen($this->user_agent))
1085
+ $arguments["Headers"]["User-Agent"]=$this->user_agent;
1086
+ if(IsSet($arguments["KeepAlive"]))
1087
+ $this->keep_alive=intval($arguments["KeepAlive"]);
1088
+ if(!IsSet($arguments["Headers"]["Connection"])
1089
+ && $this->keep_alive)
1090
+ $arguments["Headers"]["Connection"]='Keep-Alive';
1091
+ if(IsSet($arguments["Accept"]))
1092
+ $this->user_agent=$arguments["Accept"];
1093
+ if(!IsSet($arguments["Headers"]["Accept"])
1094
+ && strlen($this->accept))
1095
+ $arguments["Headers"]["Accept"]=$this->accept;
1096
+ if(strlen($this->request_method)==0)
1097
+ return($this->SetError("it was not specified a valid request method", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1098
+ if(IsSet($arguments["RequestURI"]))
1099
+ $this->request_uri=$arguments["RequestURI"];
1100
+ if(strlen($this->request_uri)==0
1101
+ || substr($this->request_uri,0,1)!="/")
1102
+ return($this->SetError("it was not specified a valid request URI", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1103
+ $this->request_arguments=$arguments;
1104
+ $this->request_headers=(IsSet($arguments["Headers"]) ? $arguments["Headers"] : array());
1105
+ $body_length=0;
1106
+ $this->request_body="";
1107
+ $get_body=1;
1108
+ if($this->request_method=="POST"
1109
+ || $this->request_method=="PUT")
1110
+ {
1111
+ if(IsSet($arguments['StreamRequest']))
1112
+ {
1113
+ $get_body = 0;
1114
+ $this->request_headers["Transfer-Encoding"]="chunked";
1115
+ }
1116
+ elseif(IsSet($arguments["PostFiles"])
1117
+ || ($this->force_multipart_form_post
1118
+ && IsSet($arguments["PostValues"])))
1119
+ {
1120
+ $boundary="--".md5(uniqid(time()));
1121
+ $this->request_headers["Content-Type"]="multipart/form-data; boundary=".$boundary.(IsSet($arguments["CharSet"]) ? "; charset=".$arguments["CharSet"] : "");
1122
+ $post_parts=array();
1123
+ if(IsSet($arguments["PostValues"]))
1124
+ {
1125
+ $values=$arguments["PostValues"];
1126
+ if(GetType($values)!="array")
1127
+ return($this->SetError("it was not specified a valid POST method values array", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1128
+ for(Reset($values),$value=0;$value<count($values);Next($values),$value++)
1129
+ {
1130
+ $input=Key($values);
1131
+ $headers="--".$boundary."\r\nContent-Disposition: form-data; name=\"".$input."\"\r\n\r\n";
1132
+ $data=$values[$input];
1133
+ $post_parts[]=array("HEADERS"=>$headers,"DATA"=>$data);
1134
+ $body_length+=strlen($headers)+strlen($data)+strlen("\r\n");
1135
+ }
1136
+ }
1137
+ $body_length+=strlen("--".$boundary."--\r\n");
1138
+ $files=(IsSet($arguments["PostFiles"]) ? $arguments["PostFiles"] : array());
1139
+ Reset($files);
1140
+ $end=(GetType($input=Key($files))!="string");
1141
+ for(;!$end;)
1142
+ {
1143
+ if(strlen($error=$this->GetFileDefinition($files[$input],$definition)))
1144
+ return("3 ".$error);
1145
+ $headers="--".$boundary."\r\nContent-Disposition: form-data; name=\"".$input."\"; filename=\"".$definition["NAME"]."\"\r\nContent-Type: ".$definition["Content-Type"]."\r\n\r\n";
1146
+ $part=count($post_parts);
1147
+ $post_parts[$part]=array("HEADERS"=>$headers);
1148
+ if(IsSet($definition["FILENAME"]))
1149
+ {
1150
+ $post_parts[$part]["FILENAME"]=$definition["FILENAME"];
1151
+ $data="";
1152
+ }
1153
+ else
1154
+ $data=$definition["DATA"];
1155
+ $post_parts[$part]["DATA"]=$data;
1156
+ $body_length+=strlen($headers)+$definition["Content-Length"]+strlen("\r\n");
1157
+ Next($files);
1158
+ $end=(GetType($input=Key($files))!="string");
1159
+ }
1160
+ $get_body=0;
1161
+ }
1162
+ elseif(IsSet($arguments["PostValues"]))
1163
+ {
1164
+ $values=$arguments["PostValues"];
1165
+ if(GetType($values)!="array")
1166
+ return($this->SetError("it was not specified a valid POST method values array", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1167
+ for(Reset($values),$value=0;$value<count($values);Next($values),$value++)
1168
+ {
1169
+ $k=Key($values);
1170
+ if(GetType($values[$k])=="array")
1171
+ {
1172
+ for($v = 0; $v < count($values[$k]); $v++)
1173
+ {
1174
+ if($value+$v>0)
1175
+ $this->request_body.="&";
1176
+ $this->request_body.=UrlEncode($k)."=".UrlEncode($values[$k][$v]);
1177
+ }
1178
+ }
1179
+ else
1180
+ {
1181
+ if($value>0)
1182
+ $this->request_body.="&";
1183
+ $this->request_body.=UrlEncode($k)."=".UrlEncode($values[$k]);
1184
+ }
1185
+ }
1186
+ $this->request_headers["Content-Type"]="application/x-www-form-urlencoded".(IsSet($arguments["CharSet"]) ? "; charset=".$arguments["CharSet"] : "");
1187
+ $get_body=0;
1188
+ }
1189
+ }
1190
+ if($get_body
1191
+ && (IsSet($arguments["Body"])
1192
+ || IsSet($arguments["BodyStream"])))
1193
+ {
1194
+ if(IsSet($arguments["Body"]))
1195
+ $this->request_body=$arguments["Body"];
1196
+ else
1197
+ {
1198
+ $stream=$arguments["BodyStream"];
1199
+ $this->request_body="";
1200
+ for($part=0; $part<count($stream); $part++)
1201
+ {
1202
+ if(IsSet($stream[$part]["Data"]))
1203
+ $this->request_body.=$stream[$part]["Data"];
1204
+ elseif(IsSet($stream[$part]["File"]))
1205
+ {
1206
+ if(!($file=@fopen($stream[$part]["File"],"rb")))
1207
+ return($this->SetPHPError("could not open upload file ".$stream[$part]["File"], $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE));
1208
+ while(!feof($file))
1209
+ {
1210
+ if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
1211
+ {
1212
+ $error=$this->SetPHPError("could not read body stream file ".$stream[$part]["File"], $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
1213
+ fclose($file);
1214
+ return($error);
1215
+ }
1216
+ $this->request_body.=$block;
1217
+ }
1218
+ fclose($file);
1219
+ }
1220
+ else
1221
+ return("5 it was not specified a valid file or data body stream element at position ".$part);
1222
+ }
1223
+ }
1224
+ if(!IsSet($this->request_headers["Content-Type"]))
1225
+ $this->request_headers["Content-Type"]="application/octet-stream".(IsSet($arguments["CharSet"]) ? "; charset=".$arguments["CharSet"] : "");
1226
+ }
1227
+ if(IsSet($arguments["AuthUser"]))
1228
+ $this->request_user=$arguments["AuthUser"];
1229
+ elseif(IsSet($this->user))
1230
+ $this->request_user=$this->user;
1231
+ if(IsSet($arguments["AuthPassword"]))
1232
+ $this->request_password=$arguments["AuthPassword"];
1233
+ elseif(IsSet($this->password))
1234
+ $this->request_password=$this->password;
1235
+ if(IsSet($arguments["AuthRealm"]))
1236
+ $this->request_realm=$arguments["AuthRealm"];
1237
+ elseif(IsSet($this->realm))
1238
+ $this->request_realm=$this->realm;
1239
+ if(IsSet($arguments["AuthWorkstation"]))
1240
+ $this->request_workstation=$arguments["AuthWorkstation"];
1241
+ elseif(IsSet($this->workstation))
1242
+ $this->request_workstation=$this->workstation;
1243
+ if(strlen($this->proxy_host_name)==0
1244
+ || $connect)
1245
+ $request_uri=$this->request_uri;
1246
+ else
1247
+ {
1248
+ switch(strtolower($this->protocol))
1249
+ {
1250
+ case "http":
1251
+ $default_port=80;
1252
+ break;
1253
+ case "https":
1254
+ $default_port=443;
1255
+ break;
1256
+ }
1257
+ $request_uri=strtolower($this->protocol)."://".$this->host_name.(($this->host_port==0 || $this->host_port==$default_port) ? "" : ":".$this->host_port).$this->request_uri;
1258
+ }
1259
+ if($this->use_curl)
1260
+ {
1261
+ $version=(GetType($v=curl_version())=="array" ? (IsSet($v["version"]) ? $v["version"] : "0.0.0") : (preg_match("/^libcurl\\/([0-9]+\\.[0-9]+\\.[0-9]+)/",$v,$m) ? $m[1] : "0.0.0"));
1262
+ $curl_version=100000*intval($this->Tokenize($version,"."))+1000*intval($this->Tokenize("."))+intval($this->Tokenize(""));
1263
+ $protocol_version=($curl_version<713002 ? "1.0" : $this->protocol_version);
1264
+ }
1265
+ else
1266
+ $protocol_version=$this->protocol_version;
1267
+ $this->request=$this->request_method." ".$request_uri." HTTP/".$protocol_version;
1268
+ if($body_length
1269
+ || ($body_length=strlen($this->request_body)))
1270
+ $this->request_headers["Content-Length"]=$body_length;
1271
+ for($headers=array(),$host_set=0,Reset($this->request_headers),$header=0;$header<count($this->request_headers);Next($this->request_headers),$header++)
1272
+ {
1273
+ $header_name=Key($this->request_headers);
1274
+ $header_value=$this->request_headers[$header_name];
1275
+ if(GetType($header_value)=="array")
1276
+ {
1277
+ for(Reset($header_value),$value=0;$value<count($header_value);Next($header_value),$value++)
1278
+ $headers[]=$header_name.": ".$header_value[Key($header_value)];
1279
+ }
1280
+ else
1281
+ $headers[]=$header_name.": ".$header_value;
1282
+ if(strtolower(Key($this->request_headers))=="host")
1283
+ {
1284
+ $this->request_host=strtolower($header_value);
1285
+ $host_set=1;
1286
+ }
1287
+ }
1288
+ if(!$host_set)
1289
+ {
1290
+ $headers[]="Host: ".$this->host_name;
1291
+ $this->request_host=strtolower($this->host_name);
1292
+ }
1293
+ if(count($this->cookies))
1294
+ {
1295
+ $cookies=array();
1296
+ $this->PickCookies($cookies,0);
1297
+ if(strtolower($this->protocol)=="https")
1298
+ $this->PickCookies($cookies,1);
1299
+ if(count($cookies))
1300
+ {
1301
+ $h=count($headers);
1302
+ $headers[$h]="Cookie:";
1303
+ for(Reset($cookies),$cookie=0;$cookie<count($cookies);Next($cookies),$cookie++)
1304
+ {
1305
+ $cookie_name=Key($cookies);
1306
+ $headers[$h].=" ".$cookie_name."=".$cookies[$cookie_name]["value"].";";
1307
+ }
1308
+ }
1309
+ }
1310
+ $next_state = "RequestSent";
1311
+ if($this->use_curl)
1312
+ {
1313
+ if(IsSet($arguments['StreamRequest']))
1314
+ return($this->SetError("Streaming request data is not supported when using Curl", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1315
+ if($body_length
1316
+ && strlen($this->request_body)==0)
1317
+ {
1318
+ for($request_body="",$success=1,$part=0;$part<count($post_parts);$part++)
1319
+ {
1320
+ $request_body.=$post_parts[$part]["HEADERS"].$post_parts[$part]["DATA"];
1321
+ if(IsSet($post_parts[$part]["FILENAME"]))
1322
+ {
1323
+ if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))
1324
+ {
1325
+ $this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
1326
+ $success=0;
1327
+ break;
1328
+ }
1329
+ while(!feof($file))
1330
+ {
1331
+ if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
1332
+ {
1333
+ $this->SetPHPError("could not read upload file", $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
1334
+ $success=0;
1335
+ break;
1336
+ }
1337
+ $request_body.=$block;
1338
+ }
1339
+ fclose($file);
1340
+ if(!$success)
1341
+ break;
1342
+ }
1343
+ $request_body.="\r\n";
1344
+ }
1345
+ $request_body.="--".$boundary."--\r\n";
1346
+ }
1347
+ else
1348
+ $request_body=$this->request_body;
1349
+ curl_setopt($this->connection,CURLOPT_HEADER,1);
1350
+ curl_setopt($this->connection,CURLOPT_RETURNTRANSFER,1);
1351
+ if($this->timeout)
1352
+ curl_setopt($this->connection,CURLOPT_TIMEOUT,$this->timeout);
1353
+ curl_setopt($this->connection,CURLOPT_SSL_VERIFYPEER,0);
1354
+ curl_setopt($this->connection,CURLOPT_SSL_VERIFYHOST,0);
1355
+ $request=$this->request."\r\n".implode("\r\n",$headers)."\r\n\r\n".$request_body;
1356
+ curl_setopt($this->connection,CURLOPT_CUSTOMREQUEST,$request);
1357
+ if($this->debug)
1358
+ $this->OutputDebug("C ".$request);
1359
+ if(!($success=(strlen($this->response=curl_exec($this->connection))!=0)))
1360
+ {
1361
+ $error=curl_error($this->connection);
1362
+ $this->SetError("Could not execute the request".(strlen($error) ? ": ".$error : ""), HTTP_CLIENT_ERROR_PROTOCOL_FAILURE);
1363
+ }
1364
+ }
1365
+ else
1366
+ {
1367
+ if(($success=$this->PutLine($this->request)))
1368
+ {
1369
+ for($header=0;$header<count($headers);$header++)
1370
+ {
1371
+ if(!$success=$this->PutLine($headers[$header]))
1372
+ break;
1373
+ }
1374
+ if($success
1375
+ && ($success=$this->PutLine("")))
1376
+ {
1377
+ if(IsSet($arguments['StreamRequest']))
1378
+ $next_state = "SendingRequestBody";
1379
+ elseif($body_length)
1380
+ {
1381
+ if(strlen($this->request_body))
1382
+ $success=$this->PutData($this->request_body);
1383
+ else
1384
+ {
1385
+ for($part=0;$part<count($post_parts);$part++)
1386
+ {
1387
+ if(!($success=$this->PutData($post_parts[$part]["HEADERS"]))
1388
+ || !($success=$this->PutData($post_parts[$part]["DATA"])))
1389
+ break;
1390
+ if(IsSet($post_parts[$part]["FILENAME"]))
1391
+ {
1392
+ if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))
1393
+ {
1394
+ $this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
1395
+ $success=0;
1396
+ break;
1397
+ }
1398
+ while(!feof($file))
1399
+ {
1400
+ if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
1401
+ {
1402
+ $this->SetPHPError("could not read upload file", $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
1403
+ $success=0;
1404
+ break;
1405
+ }
1406
+ if(!($success=$this->PutData($block)))
1407
+ break;
1408
+ }
1409
+ fclose($file);
1410
+ if(!$success)
1411
+ break;
1412
+ }
1413
+ if(!($success=$this->PutLine("")))
1414
+ break;
1415
+ }
1416
+ if($success)
1417
+ $success=$this->PutLine("--".$boundary."--");
1418
+ }
1419
+ if($success)
1420
+ $sucess=$this->FlushData();
1421
+ }
1422
+ }
1423
+ }
1424
+ }
1425
+ if(!$success)
1426
+ return($this->SetError("could not send the HTTP request: ".$this->error, $this->error_code));
1427
+ $this->state=$next_state;
1428
+ return("");
1429
+ }
1430
+
1431
+ Function SetCookie($name, $value, $expires="" , $path="/" , $domain="" , $secure=0, $verbatim=0)
1432
+ {
1433
+ if(strlen($this->error))
1434
+ return($this->error);
1435
+ if(strlen($name)==0)
1436
+ return($this->SetError("it was not specified a valid cookie name", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1437
+ if(strlen($path)==0
1438
+ || strcmp($path[0],"/"))
1439
+ return($this->SetError($path." is not a valid path for setting cookie ".$name, HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1440
+ if($domain==""
1441
+ || !strpos($domain,".",$domain[0]=="." ? 1 : 0))
1442
+ return($this->SetError($domain." is not a valid domain for setting cookie ".$name, HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1443
+ $domain=strtolower($domain);
1444
+ if(!strcmp($domain[0],"."))
1445
+ $domain=substr($domain,1);
1446
+ if(!$verbatim)
1447
+ {
1448
+ $name=$this->CookieEncode($name,1);
1449
+ $value=$this->CookieEncode($value,0);
1450
+ }
1451
+ $secure=intval($secure);
1452
+ $this->cookies[$secure][$domain][$path][$name]=array(
1453
+ "name"=>$name,
1454
+ "value"=>$value,
1455
+ "domain"=>$domain,
1456
+ "path"=>$path,
1457
+ "expires"=>$expires,
1458
+ "secure"=>$secure
1459
+ );
1460
+ return("");
1461
+ }
1462
+
1463
+ Function SendRequestBody($data, $end_of_data)
1464
+ {
1465
+ if(strlen($this->error))
1466
+ return($this->error);
1467
+ switch($this->state)
1468
+ {
1469
+ case "Disconnected":
1470
+ return($this->SetError("connection was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1471
+ case "Connected":
1472
+ case "ConnectedToProxy":
1473
+ return($this->SetError("request was not sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1474
+ case "SendingRequestBody":
1475
+ break;
1476
+ case "RequestSent":
1477
+ return($this->SetError("request body was already sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1478
+ default:
1479
+ return($this->SetError("can not send the request body in the current connection state", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1480
+ }
1481
+ $length = strlen($data);
1482
+ if($length)
1483
+ {
1484
+ $size = dechex($length)."\r\n";
1485
+ if(!$this->PutData($size)
1486
+ || !$this->PutData($data))
1487
+ return($this->error);
1488
+ }
1489
+ if($end_of_data)
1490
+ {
1491
+ $size = "0\r\n";
1492
+ if(!$this->PutData($size))
1493
+ return($this->error);
1494
+ $this->state = "RequestSent";
1495
+ }
1496
+ return("");
1497
+ }
1498
+
1499
+ Function ReadReplyHeadersResponse(&$headers)
1500
+ {
1501
+ $headers=array();
1502
+ if(strlen($this->error))
1503
+ return($this->error);
1504
+ switch($this->state)
1505
+ {
1506
+ case "Disconnected":
1507
+ return($this->SetError("connection was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1508
+ case "Connected":
1509
+ return($this->SetError("request was not sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1510
+ case "ConnectedToProxy":
1511
+ return($this->SetError("connection from the remote server from the proxy was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1512
+ case "SendingRequestBody":
1513
+ return($this->SetError("request body data was not completely sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1514
+ case "ConnectSent":
1515
+ $connect = 1;
1516
+ break;
1517
+ case "RequestSent":
1518
+ $connect = 0;
1519
+ break;
1520
+ default:
1521
+ return($this->SetError("can not get request headers in the current connection state", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1522
+ }
1523
+ $this->content_length=$this->read_length=$this->read_response=$this->remaining_chunk=0;
1524
+ $this->content_length_set=$this->chunked=$this->last_chunk_read=$chunked=0;
1525
+ $this->force_close = $this->connection_close=0;
1526
+ for($this->response_status="";;)
1527
+ {
1528
+ $line=$this->GetLine();
1529
+ if(GetType($line)!="string")
1530
+ return($this->SetError("could not read request reply: ".$this->error, $this->error_code));
1531
+ if(strlen($this->response_status)==0)
1532
+ {
1533
+ if(!preg_match($match="/^http\\/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$/i",$line,$matches))
1534
+ return($this->SetError("it was received an unexpected HTTP response status", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1535
+ $this->response_status=$matches[1];
1536
+ $this->response_message=$matches[2];
1537
+ }
1538
+ if($line=="")
1539
+ {
1540
+ if(strlen($this->response_status)==0)
1541
+ return($this->SetError("it was not received HTTP response status", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1542
+ $this->state=($connect ? "GotConnectHeaders" : "GotReplyHeaders");
1543
+ break;
1544
+ }
1545
+ $header_name=strtolower($this->Tokenize($line,":"));
1546
+ $header_value=Trim(Chop($this->Tokenize("\r\n")));
1547
+ if(IsSet($headers[$header_name]))
1548
+ {
1549
+ if(GetType($headers[$header_name])=="string")
1550
+ $headers[$header_name]=array($headers[$header_name]);
1551
+ $headers[$header_name][]=$header_value;
1552
+ }
1553
+ else
1554
+ $headers[$header_name]=$header_value;
1555
+ if(!$connect)
1556
+ {
1557
+ switch($header_name)
1558
+ {
1559
+ case "content-length":
1560
+ $this->content_length=intval($headers[$header_name]);
1561
+ $this->content_length_set=1;
1562
+ break;
1563
+ case "transfer-encoding":
1564
+ $encoding=$this->Tokenize($header_value,"; \t");
1565
+ if(!$this->use_curl
1566
+ && !strcmp($encoding,"chunked"))
1567
+ $chunked=1;
1568
+ break;
1569
+ case "set-cookie":
1570
+ if($this->support_cookies)
1571
+ {
1572
+ if(GetType($headers[$header_name])=="array")
1573
+ $cookie_headers=$headers[$header_name];
1574
+ else
1575
+ $cookie_headers=array($headers[$header_name]);
1576
+ for($cookie=0;$cookie<count($cookie_headers);$cookie++)
1577
+ {
1578
+ $cookie_name=trim($this->Tokenize($cookie_headers[$cookie],"="));
1579
+ $cookie_value=$this->Tokenize(";");
1580
+ $domain=$this->request_host;
1581
+ $path="/";
1582
+ $expires="";
1583
+ $secure=0;
1584
+ while(($name = strtolower(trim(UrlDecode($this->Tokenize("=")))))!="")
1585
+ {
1586
+ $value=UrlDecode($this->Tokenize(";"));
1587
+ switch($name)
1588
+ {
1589
+ case "domain":
1590
+ $domain=$value;
1591
+ break;
1592
+ case "path":
1593
+ $path=$value;
1594
+ break;
1595
+ case "expires":
1596
+ if(preg_match("/^((Mon|Monday|Tue|Tuesday|Wed|Wednesday|Thu|Thursday|Fri|Friday|Sat|Saturday|Sun|Sunday), )?([0-9]{2})\\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\-([0-9]{2,4}) ([0-9]{2})\\:([0-9]{2})\\:([0-9]{2}) GMT\$/",$value,$matches))
1597
+ {
1598
+ $year=intval($matches[5]);
1599
+ if($year<1900)
1600
+ $year+=($year<70 ? 2000 : 1900);
1601
+ $expires="$year-".$this->months[$matches[4]]."-".$matches[3]." ".$matches[6].":".$matches[7].":".$matches[8];
1602
+ }
1603
+ break;
1604
+ case "secure":
1605
+ $secure=1;
1606
+ break;
1607
+ }
1608
+ }
1609
+ if(strlen($this->SetCookie($cookie_name, $cookie_value, $expires, $path , $domain, $secure, 1)))
1610
+ $this->error="";
1611
+ }
1612
+ }
1613
+ break;
1614
+ case "connection":
1615
+ $this->force_close = $this->connection_close=!strcmp(strtolower($header_value),"close");
1616
+ break;
1617
+ }
1618
+ }
1619
+ }
1620
+ $this->chunked=$chunked;
1621
+ if($this->content_length_set)
1622
+ $this->connection_close=0;
1623
+ return("");
1624
+ }
1625
+
1626
+ Function Redirect(&$headers)
1627
+ {
1628
+ if($this->follow_redirect)
1629
+ {
1630
+ if(!IsSet($headers["location"])
1631
+ || (GetType($headers["location"])!="array"
1632
+ && strlen($location=$headers["location"])==0)
1633
+ || (GetType($headers["location"])=="array"
1634
+ && strlen($location=$headers["location"][0])==0))
1635
+ return($this->SetError("it was received a redirect without location URL", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1636
+ if(strcmp($location[0],"/"))
1637
+ {
1638
+ if(!($location_arguments=@parse_url($location)))
1639
+ return($this->SetError("the server did not return a valid redirection location URL", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1640
+ if(!IsSet($location_arguments["scheme"]))
1641
+ $location=((GetType($end=strrpos($this->request_uri,"/"))=="integer" && $end>1) ? substr($this->request_uri,0,$end) : "")."/".$location;
1642
+ }
1643
+ if(!strcmp($location[0],"/"))
1644
+ $location=$this->protocol."://".$this->host_name.($this->host_port ? ":".$this->host_port : "").$location;
1645
+ $error=$this->GetRequestArguments($location,$arguments);
1646
+ if(strlen($error))
1647
+ return($this->SetError("could not process redirect url: ".$error, HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1648
+ $arguments["RequestMethod"]="GET";
1649
+ if(strlen($error=$this->Close())==0
1650
+ && strlen($error=$this->Open($arguments))==0
1651
+ && strlen($error=$this->SendRequest($arguments))==0)
1652
+ {
1653
+ $this->redirection_level++;
1654
+ if($this->redirection_level>$this->redirection_limit)
1655
+ {
1656
+ $error="it was exceeded the limit of request redirections";
1657
+ $this->error_code = HTTP_CLIENT_ERROR_PROTOCOL_FAILURE;
1658
+ }
1659
+ else
1660
+ $error=$this->ReadReplyHeaders($headers);
1661
+ $this->redirection_level--;
1662
+ }
1663
+ if(strlen($error))
1664
+ return($this->SetError($error, $this->error_code));
1665
+ }
1666
+ return("");
1667
+ }
1668
+
1669
+ Function Authenticate(&$headers, $proxy, &$proxy_authorization, &$user, &$password, &$realm, &$workstation)
1670
+ {
1671
+ if($proxy)
1672
+ {
1673
+ $authenticate_header="proxy-authenticate";
1674
+ $authorization_header="Proxy-Authorization";
1675
+ $authenticate_status="407";
1676
+ $authentication_mechanism=$this->proxy_authentication_mechanism;
1677
+ }
1678
+ else
1679
+ {
1680
+ $authenticate_header="www-authenticate";
1681
+ $authorization_header="Authorization";
1682
+ $authenticate_status="401";
1683
+ $authentication_mechanism=$this->authentication_mechanism;
1684
+ }
1685
+ if(IsSet($headers[$authenticate_header])
1686
+ && $this->sasl_authenticate)
1687
+ {
1688
+ if(function_exists("class_exists")
1689
+ && !class_exists("sasl_client_class"))
1690
+ return($this->SetError("the SASL client class needs to be loaded to be able to authenticate".($proxy ? " with the proxy server" : "")." and access this site", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1691
+ if(GetType($headers[$authenticate_header])=="array")
1692
+ $authenticate=$headers[$authenticate_header];
1693
+ else
1694
+ $authenticate=array($headers[$authenticate_header]);
1695
+ for($response="", $mechanisms=array(),$m=0;$m<count($authenticate);$m++)
1696
+ {
1697
+ $mechanism=$this->Tokenize($authenticate[$m]," ");
1698
+ $response=$this->Tokenize("");
1699
+ if(strlen($authentication_mechanism))
1700
+ {
1701
+ if(!strcmp($authentication_mechanism,$mechanism))
1702
+ {
1703
+ $mechanisms[]=$mechanism;
1704
+ break;
1705
+ }
1706
+ }
1707
+ else
1708
+ $mechanisms[]=$mechanism;
1709
+ }
1710
+ $sasl=new sasl_client_class;
1711
+ if(IsSet($user))
1712
+ $sasl->SetCredential("user",$user);
1713
+ if(IsSet($password))
1714
+ $sasl->SetCredential("password",$password);
1715
+ if(IsSet($realm))
1716
+ $sasl->SetCredential("realm",$realm);
1717
+ if(IsSet($workstation))
1718
+ $sasl->SetCredential("workstation",$workstation);
1719
+ $sasl->SetCredential("uri",$this->request_uri);
1720
+ $sasl->SetCredential("method",$this->request_method);
1721
+ $sasl->SetCredential("session",$this->session);
1722
+ do
1723
+ {
1724
+ $status=$sasl->Start($mechanisms,$message,$interactions);
1725
+ }
1726
+ while($status==SASL_INTERACT);
1727
+ switch($status)
1728
+ {
1729
+ case SASL_CONTINUE:
1730
+ break;
1731
+ case SASL_NOMECH:
1732
+ return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".(strlen($authentication_mechanism) ? "authentication mechanism ".$authentication_mechanism." may not be used: " : "").$sasl->error, HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1733
+ default:
1734
+ return($this->SetError("Could not start the SASL ".($proxy ? "proxy " : "")."authentication client: ".$sasl->error, HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1735
+ }
1736
+ if($proxy >= 0)
1737
+ {
1738
+ for(;;)
1739
+ {
1740
+ if(strlen($error=$this->ReadReplyBody($body,$this->file_buffer_length)))
1741
+ return($error);
1742
+ if(strlen($body)==0)
1743
+ break;
1744
+ }
1745
+ }
1746
+ $authorization_value=$sasl->mechanism.(IsSet($message) ? " ".($sasl->encode_response ? base64_encode($message) : $message) : "");
1747
+ $request_arguments=$this->request_arguments;
1748
+ $arguments=$request_arguments;
1749
+ $arguments["Headers"][$authorization_header]=$authorization_value;
1750
+ if(!$proxy
1751
+ && strlen($proxy_authorization))
1752
+ $arguments["Headers"]["Proxy-Authorization"]=$proxy_authorization;
1753
+ if(strlen($error=$this->Close())
1754
+ || strlen($error=$this->Open($arguments)))
1755
+ return($this->SetError($error, $this->error_code));
1756
+ $authenticated=0;
1757
+ if(IsSet($message))
1758
+ {
1759
+ if($proxy < 0)
1760
+ {
1761
+ if(strlen($error=$this->ConnectFromProxy($arguments, $headers)))
1762
+ return($this->SetError($error, $this->error_code));
1763
+ }
1764
+ else
1765
+ {
1766
+ if(strlen($error=$this->SendRequest($arguments))
1767
+ || strlen($error=$this->ReadReplyHeadersResponse($headers)))
1768
+ return($this->SetError($error, $this->error_code));
1769
+ }
1770
+ if(!IsSet($headers[$authenticate_header]))
1771
+ $authenticate=array();
1772
+ elseif(GetType($headers[$authenticate_header])=="array")
1773
+ $authenticate=$headers[$authenticate_header];
1774
+ else
1775
+ $authenticate=array($headers[$authenticate_header]);
1776
+ for($mechanism=0;$mechanism<count($authenticate);$mechanism++)
1777
+ {
1778
+ if(!strcmp($this->Tokenize($authenticate[$mechanism]," "),$sasl->mechanism))
1779
+ {
1780
+ $response=$this->Tokenize("");
1781
+ break;
1782
+ }
1783
+ }
1784
+ switch($this->response_status)
1785
+ {
1786
+ case $authenticate_status:
1787
+ break;
1788
+ case "301":
1789
+ case "302":
1790
+ case "303":
1791
+ case "307":
1792
+ if($proxy >= 0)
1793
+ return($this->Redirect($headers));
1794
+ default:
1795
+ if(intval($this->response_status/100)==2)
1796
+ {
1797
+ if($proxy)
1798
+ $proxy_authorization=$authorization_value;
1799
+ $authenticated=1;
1800
+ break;
1801
+ }
1802
+ if($proxy
1803
+ && !strcmp($this->response_status,"401"))
1804
+ {
1805
+ $proxy_authorization=$authorization_value;
1806
+ $authenticated=1;
1807
+ break;
1808
+ }
1809
+ return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".$this->response_status." ".$this->response_message, HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1810
+ }
1811
+ }
1812
+ for(;!$authenticated;)
1813
+ {
1814
+ do
1815
+ {
1816
+ $status=$sasl->Step($response,$message,$interactions);
1817
+ }
1818
+ while($status==SASL_INTERACT);
1819
+ switch($status)
1820
+ {
1821
+ case SASL_CONTINUE:
1822
+ $authorization_value=$sasl->mechanism.(IsSet($message) ? " ".($sasl->encode_response ? base64_encode($message) : $message) : "");
1823
+ $arguments=$request_arguments;
1824
+ $arguments["Headers"][$authorization_header]=$authorization_value;
1825
+ if(!$proxy
1826
+ && strlen($proxy_authorization))
1827
+ $arguments["Headers"]["Proxy-Authorization"]=$proxy_authorization;
1828
+ if($proxy < 0)
1829
+ {
1830
+ if(strlen($error=$this->ConnectFromProxy($arguments, $headers)))
1831
+ return($this->SetError($error, $this->error_code));
1832
+ }
1833
+ else
1834
+ {
1835
+ if(strlen($error=$this->SendRequest($arguments))
1836
+ || strlen($error=$this->ReadReplyHeadersResponse($headers)))
1837
+ return($this->SetError($error, $this->error_code));
1838
+ }
1839
+ switch($this->response_status)
1840
+ {
1841
+ case $authenticate_status:
1842
+ if(GetType($headers[$authenticate_header])=="array")
1843
+ $authenticate=$headers[$authenticate_header];
1844
+ else
1845
+ $authenticate=array($headers[$authenticate_header]);
1846
+ for($response="",$mechanism=0;$mechanism<count($authenticate);$mechanism++)
1847
+ {
1848
+ if(!strcmp($this->Tokenize($authenticate[$mechanism]," "),$sasl->mechanism))
1849
+ {
1850
+ $response=$this->Tokenize("");
1851
+ break;
1852
+ }
1853
+ }
1854
+ if($proxy >= 0)
1855
+ {
1856
+ for(;;)
1857
+ {
1858
+ if(strlen($error=$this->ReadReplyBody($body,$this->file_buffer_length)))
1859
+ return($error);
1860
+ if(strlen($body)==0)
1861
+ break;
1862
+ }
1863
+ }
1864
+ $this->state="Connected";
1865
+ break;
1866
+ case "301":
1867
+ case "302":
1868
+ case "303":
1869
+ case "307":
1870
+ if($proxy >= 0)
1871
+ return($this->Redirect($headers));
1872
+ default:
1873
+ if(intval($this->response_status/100)==2)
1874
+ {
1875
+ if($proxy)
1876
+ $proxy_authorization=$authorization_value;
1877
+ $authenticated=1;
1878
+ break;
1879
+ }
1880
+ if($proxy
1881
+ && !strcmp($this->response_status,"401"))
1882
+ {
1883
+ $proxy_authorization=$authorization_value;
1884
+ $authenticated=1;
1885
+ break;
1886
+ }
1887
+ return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".$this->response_status." ".$this->response_message));
1888
+ }
1889
+ break;
1890
+ default:
1891
+ return($this->SetError("Could not process the SASL ".($proxy ? "proxy " : "")."authentication step: ".$sasl->error, HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1892
+ }
1893
+ }
1894
+ }
1895
+ return("");
1896
+ }
1897
+
1898
+ Function ReadReplyHeaders(&$headers)
1899
+ {
1900
+ if(strlen($error=$this->ReadReplyHeadersResponse($headers)))
1901
+ return($error);
1902
+ $proxy_authorization="";
1903
+ while(!strcmp($this->response_status, "100"))
1904
+ {
1905
+ $this->state="RequestSent";
1906
+ if(strlen($error=$this->ReadReplyHeadersResponse($headers)))
1907
+ return($error);
1908
+ }
1909
+ switch($this->response_status)
1910
+ {
1911
+ case "301":
1912
+ case "302":
1913
+ case "303":
1914
+ case "307":
1915
+ if(strlen($error=$this->Redirect($headers)))
1916
+ return($error);
1917
+ break;
1918
+ case "407":
1919
+ if(strlen($error=$this->Authenticate($headers, 1, $proxy_authorization, $this->proxy_request_user, $this->proxy_request_password, $this->proxy_request_realm, $this->proxy_request_workstation)))
1920
+ return($error);
1921
+ if(strcmp($this->response_status,"401"))
1922
+ return("");
1923
+ case "401":
1924
+ return($this->Authenticate($headers, 0, $proxy_authorization, $this->request_user, $this->request_password, $this->request_realm, $this->request_workstation));
1925
+ }
1926
+ return("");
1927
+ }
1928
+
1929
+ Function ReadReplyBody(&$body,$length)
1930
+ {
1931
+ $body="";
1932
+ if(strlen($this->error))
1933
+ return($this->error);
1934
+ switch($this->state)
1935
+ {
1936
+ case "Disconnected":
1937
+ return($this->SetError("connection was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1938
+ case "Connected":
1939
+ case "ConnectedToProxy":
1940
+ return($this->SetError("request was not sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1941
+ case "RequestSent":
1942
+ if(($error=$this->ReadReplyHeaders($headers))!="")
1943
+ return($error);
1944
+ break;
1945
+ case "GotReplyHeaders":
1946
+ break;
1947
+ case 'ResponseReceived':
1948
+ $body = '';
1949
+ return('');
1950
+ default:
1951
+ return($this->SetError("can not get request headers in the current connection state", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1952
+ }
1953
+ if($this->content_length_set)
1954
+ $length=min($this->content_length-$this->read_length,$length);
1955
+ $body = '';
1956
+ if($length>0)
1957
+ {
1958
+ if(!$this->EndOfInput()
1959
+ && ($body=$this->ReadBytes($length))=="")
1960
+ {
1961
+ if(strlen($this->error))
1962
+ return($this->SetError("could not get the request reply body: ".$this->error, $this->error_code));
1963
+ }
1964
+ $this->read_length+=strlen($body);
1965
+ if($this->EndOfInput())
1966
+ $this->state = 'ResponseReceived';
1967
+ }
1968
+ return("");
1969
+ }
1970
+
1971
+ Function ReadWholeReplyBody(&$body)
1972
+ {
1973
+ $body = '';
1974
+ for(;;)
1975
+ {
1976
+ if(strlen($error = $this->ReadReplyBody($block, $this->file_buffer_length)))
1977
+ return($error);
1978
+ if(strlen($block) == 0)
1979
+ return('');
1980
+ $body .= $block;
1981
+ }
1982
+ }
1983
+
1984
+ Function SaveCookies(&$cookies, $domain='', $secure_only=0, $persistent_only=0)
1985
+ {
1986
+ $now=gmdate("Y-m-d H-i-s");
1987
+ $cookies=array();
1988
+ for($secure_cookies=0,Reset($this->cookies);$secure_cookies<count($this->cookies);Next($this->cookies),$secure_cookies++)
1989
+ {
1990
+ $secure=Key($this->cookies);
1991
+ if(!$secure_only
1992
+ || $secure)
1993
+ {
1994
+ for($cookie_domain=0,Reset($this->cookies[$secure]);$cookie_domain<count($this->cookies[$secure]);Next($this->cookies[$secure]),$cookie_domain++)
1995
+ {
1996
+ $domain_pattern=Key($this->cookies[$secure]);
1997
+ $match=strlen($domain)-strlen($domain_pattern);
1998
+ if(strlen($domain)==0
1999
+ || ($match>=0
2000
+ && !strcmp($domain_pattern,substr($domain,$match))
2001
+ && ($match==0
2002
+ || $domain_pattern[0]=="."
2003
+ || $domain[$match-1]==".")))
2004
+ {
2005
+ for(Reset($this->cookies[$secure][$domain_pattern]),$path_part=0;$path_part<count($this->cookies[$secure][$domain_pattern]);Next($this->cookies[$secure][$domain_pattern]),$path_part++)
2006
+ {
2007
+ $path=Key($this->cookies[$secure][$domain_pattern]);
2008
+ for(Reset($this->cookies[$secure][$domain_pattern][$path]),$cookie=0;$cookie<count($this->cookies[$secure][$domain_pattern][$path]);Next($this->cookies[$secure][$domain_pattern][$path]),$cookie++)
2009
+ {
2010
+ $cookie_name=Key($this->cookies[$secure][$domain_pattern][$path]);
2011
+ $expires=$this->cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
2012
+ if((!$persistent_only
2013
+ && strlen($expires)==0)
2014
+ || (strlen($expires)
2015
+ && strcmp($now,$expires)<0))
2016
+ $cookies[$secure][$domain_pattern][$path][$cookie_name]=$this->cookies[$secure][$domain_pattern][$path][$cookie_name];
2017
+ }
2018
+ }
2019
+ }
2020
+ }
2021
+ }
2022
+ }
2023
+ }
2024
+
2025
+ Function SavePersistentCookies(&$cookies, $domain='', $secure_only=0)
2026
+ {
2027
+ $this->SaveCookies($cookies, $domain, $secure_only, 1);
2028
+ }
2029
+
2030
+ Function GetPersistentCookies(&$cookies, $domain='', $secure_only=0)
2031
+ {
2032
+ $this->SavePersistentCookies($cookies, $domain, $secure_only);
2033
+ }
2034
+
2035
+ Function RestoreCookies($cookies, $clear=1)
2036
+ {
2037
+ $new_cookies=($clear ? array() : $this->cookies);
2038
+ for($secure_cookies=0, Reset($cookies); $secure_cookies<count($cookies); Next($cookies), $secure_cookies++)
2039
+ {
2040
+ $secure=Key($cookies);
2041
+ if(GetType($secure)!="integer")
2042
+ return($this->SetError("invalid cookie secure value type (".serialize($secure).")", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
2043
+ for($cookie_domain=0,Reset($cookies[$secure]);$cookie_domain<count($cookies[$secure]);Next($cookies[$secure]),$cookie_domain++)
2044
+ {
2045
+ $domain_pattern=Key($cookies[$secure]);
2046
+ if(GetType($domain_pattern)!="string")
2047
+ return($this->SetError("invalid cookie domain value type (".serialize($domain_pattern).")", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
2048
+ for(Reset($cookies[$secure][$domain_pattern]),$path_part=0;$path_part<count($cookies[$secure][$domain_pattern]);Next($cookies[$secure][$domain_pattern]),$path_part++)
2049
+ {
2050
+ $path=Key($cookies[$secure][$domain_pattern]);
2051
+ if(GetType($path)!="string"
2052
+ || strcmp(substr($path, 0, 1), "/"))
2053
+ return($this->SetError("invalid cookie path value type (".serialize($path).")", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
2054
+ for(Reset($cookies[$secure][$domain_pattern][$path]),$cookie=0;$cookie<count($cookies[$secure][$domain_pattern][$path]);Next($cookies[$secure][$domain_pattern][$path]),$cookie++)
2055
+ {
2056
+ $cookie_name=Key($cookies[$secure][$domain_pattern][$path]);
2057
+ $expires=$cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
2058
+ $value=$cookies[$secure][$domain_pattern][$path][$cookie_name]["value"];
2059
+ if(GetType($expires)!="string"
2060
+ || (strlen($expires)
2061
+ && !preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\$/", $expires)))
2062
+ return($this->SetError("invalid cookie expiry value type (".serialize($expires).")", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
2063
+ $new_cookies[$secure][$domain_pattern][$path][$cookie_name]=array(
2064
+ "name"=>$cookie_name,
2065
+ "value"=>$value,
2066
+ "domain"=>$domain_pattern,
2067
+ "path"=>$path,
2068
+ "expires"=>$expires,
2069
+ "secure"=>$secure
2070
+ );
2071
+ }
2072
+ }
2073
+ }
2074
+ }
2075
+ $this->cookies=$new_cookies;
2076
+ return("");
2077
+ }
2078
+ };
2079
+
2080
+ ?>
app/code/local/Soclever/Socialloginsc/controllers/oauth_client.php ADDED
@@ -0,0 +1,1850 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * oauth_client.php
4
+ *
5
+ * @(#) $Id: oauth_client.php,v 1.46 2013/01/10 10:11:33 mlemos Exp $
6
+ *
7
+ */
8
+
9
+ /*
10
+ {metadocument}<?xml version="1.0" encoding="ISO-8859-1" ?>
11
+ <class>
12
+
13
+ <package>net.manuellemos.oauth</package>
14
+
15
+ <version>@(#) $Id: oauth_client.php,v 1.46 2013/01/10 10:11:33 mlemos Exp $</version>
16
+ <copyright>Copyright � (C) Manuel Lemos 2012</copyright>
17
+ <title>OAuth client</title>
18
+ <author>Manuel Lemos</author>
19
+ <authoraddress>mlemos-at-acm.org</authoraddress>
20
+
21
+ <documentation>
22
+ <idiom>en</idiom>
23
+ <purpose>This class serves two main purposes:<paragraphbreak />
24
+ 1) Implement the OAuth protocol to retrieve a token from a server to
25
+ authorize the access to an API on behalf of the current
26
+ user.<paragraphbreak />
27
+ 2) Perform calls to a Web services API using a token previously
28
+ obtained using this class or a token provided some other way by the
29
+ Web services provider.</purpose>
30
+ <usage>Regardless of your purposes, you always need to start calling
31
+ the class <functionlink>Initialize</functionlink> function after
32
+ initializing setup variables. After you are done with the class,
33
+ always call the <functionlink>Finalize</functionlink> function at
34
+ the end.<paragraphbreak />
35
+ This class supports either OAuth protocol versions 1.0, 1.0a and
36
+ 2.0. It abstracts the differences between these protocol versions,
37
+ so the class usage is the same independently of the OAuth
38
+ version of the server.<paragraphbreak />
39
+ The class also provides built-in support to several popular OAuth
40
+ servers, so you do not have to manually configure all the details to
41
+ access those servers. Just set the
42
+ <variablelink>server</variablelink> variable to configure the class
43
+ to access one of the built-in supported servers.<paragraphbreak />
44
+ If you need to access one type of server that is not yet directly
45
+ supported by the class, you need to configure it explicitly setting
46
+ the variables: <variablelink>oauth_version</variablelink>,
47
+ <variablelink>url_parameters</variablelink>,
48
+ <variablelink>authorization_header</variablelink>,
49
+ <variablelink>request_token_url</variablelink>,
50
+ <variablelink>dialog_url</variablelink>,
51
+ <variablelink>append_state_to_redirect_uri</variablelink> and
52
+ <variablelink>access_token_url</variablelink>.<paragraphbreak />
53
+ Before proceeding to the actual OAuth authorization process, you
54
+ need to have registered your application with the OAuth server. The
55
+ registration provides you values to set the variables
56
+ <variablelink>client_id</variablelink> and
57
+ <variablelink>client_secret</variablelink>.<paragraphbreak />
58
+ You also need to set the variables
59
+ <variablelink>redirect_uri</variablelink> and
60
+ <variablelink>scope</variablelink> before calling the
61
+ <functionlink>Process</functionlink> function to make the class
62
+ perform the necessary interactions with the OAuth
63
+ server.<paragraphbreak />
64
+ The OAuth protocol involves multiple steps that include redirection
65
+ to the OAuth server. There it asks permission to the current user to
66
+ grant your application access to APIs on his/her behalf. When there
67
+ is a redirection, the class will set the
68
+ <variablelink>exit</variablelink> variable to
69
+ <booleanvalue>1</booleanvalue>. Then your script should exit
70
+ immediately without outputting anything.<paragraphbreak />
71
+ When the OAuth access token is successfully obtained, the following
72
+ variables are set by the class with the obtained values:
73
+ <variablelink>access_token</variablelink>,
74
+ <variablelink>access_token_secret</variablelink>,
75
+ <variablelink>access_token_expiry</variablelink>,
76
+ <variablelink>access_token_type</variablelink>. You may want to
77
+ store these values to use them later when calling the server
78
+ APIs.<paragraphbreak />
79
+ If there was a problem during OAuth authorization process, check the
80
+ variable <variablelink>authorization_error</variablelink> to
81
+ determine the reason.<paragraphbreak />
82
+ Once you get the access token, you can call the server APIs using
83
+ the <functionlink>CallAPI</functionlink> function. Check the
84
+ <variablelink>access_token_error</variablelink> variable to
85
+ determine if there was an error when trying to to call the
86
+ API.<paragraphbreak />
87
+ If for some reason the user has revoked the access to your
88
+ application, you need to ask the user to authorize your application
89
+ again. First you may need to call the function
90
+ <functionlink>ResetAccessToken</functionlink> to reset the value of
91
+ the access token that may be cached in session variables.</usage>
92
+ </documentation>
93
+
94
+ {/metadocument}
95
+ */
96
+
97
+ class oauth_client_class
98
+ {
99
+ /*
100
+ {metadocument}
101
+ <variable>
102
+ <name>error</name>
103
+ <type>STRING</type>
104
+ <value></value>
105
+ <documentation>
106
+ <purpose>Store the message that is returned when an error
107
+ occurs.</purpose>
108
+ <usage>Check this variable to understand what happened when a call to
109
+ any of the class functions has failed.<paragraphbreak />
110
+ This class uses cumulative error handling. This means that if one
111
+ class functions that may fail is called and this variable was
112
+ already set to an error message due to a failure in a previous call
113
+ to the same or other function, the function will also fail and does
114
+ not do anything.<paragraphbreak />
115
+ This allows programs using this class to safely call several
116
+ functions that may fail and only check the failure condition after
117
+ the last function call.<paragraphbreak />
118
+ Just set this variable to an empty string to clear the error
119
+ condition.</usage>
120
+ </documentation>
121
+ </variable>
122
+ {/metadocument}
123
+ */
124
+ var $error = '';
125
+
126
+ /*
127
+ {metadocument}
128
+ <variable>
129
+ <name>debug</name>
130
+ <type>BOOLEAN</type>
131
+ <value>0</value>
132
+ <documentation>
133
+ <purpose>Control whether debug output is enabled</purpose>
134
+ <usage>Set this variable to <booleanvalue>1</booleanvalue> if you
135
+ need to check what is going on during calls to the class. When
136
+ enabled, the debug output goes either to the variable
137
+ <variablelink>debug_output</variablelink> and the PHP error log.</usage>
138
+ </documentation>
139
+ </variable>
140
+ {/metadocument}
141
+ */
142
+ var $debug = false;
143
+
144
+ /*
145
+ {metadocument}
146
+ <variable>
147
+ <name>debug_http</name>
148
+ <type>BOOLEAN</type>
149
+ <value>0</value>
150
+ <documentation>
151
+ <purpose>Control whether the dialog with the remote Web server
152
+ should also be logged.</purpose>
153
+ <usage>Set this variable to <booleanvalue>1</booleanvalue> if you
154
+ want to inspect the data exchange with the OAuth server.</usage>
155
+ </documentation>
156
+ </variable>
157
+ {/metadocument}
158
+ */
159
+ var $debug_http = false;
160
+
161
+ /*
162
+ {metadocument}
163
+ <variable>
164
+ <name>exit</name>
165
+ <type>BOOLEAN</type>
166
+ <value>0</value>
167
+ <documentation>
168
+ <purpose>Determine if the current script should be exited.</purpose>
169
+ <usage>Check this variable after calling the
170
+ <functionlink>Process</functionlink> function and exit your script
171
+ immediately if the variable is set to
172
+ <booleanvalue>1</booleanvalue>.</usage>
173
+ </documentation>
174
+ </variable>
175
+ {/metadocument}
176
+ */
177
+ var $exit = false;
178
+
179
+ /*
180
+ {metadocument}
181
+ <variable>
182
+ <name>debug_output</name>
183
+ <type>STRING</type>
184
+ <value></value>
185
+ <documentation>
186
+ <purpose>Capture the debug output generated by the class</purpose>
187
+ <usage>Inspect this variable if you need to see what happened during
188
+ the class function calls.</usage>
189
+ </documentation>
190
+ </variable>
191
+ {/metadocument}
192
+ */
193
+ var $debug_output = '';
194
+
195
+ /*
196
+ {metadocument}
197
+ <variable>
198
+ <name>debug_prefix</name>
199
+ <type>STRING</type>
200
+ <value>OAuth client: </value>
201
+ <documentation>
202
+ <purpose>Mark the lines of the debug output to identify actions
203
+ performed by this class.</purpose>
204
+ <usage>Change this variable if you prefer the debug output lines to
205
+ be prefixed with a different text.</usage>
206
+ </documentation>
207
+ </variable>
208
+ {/metadocument}
209
+ */
210
+ var $debug_prefix = 'OAuth client: ';
211
+
212
+ /*
213
+ {metadocument}
214
+ <variable>
215
+ <name>server</name>
216
+ <type>STRING</type>
217
+ <value></value>
218
+ <documentation>
219
+ <purpose>Identify the type of OAuth server to access.</purpose>
220
+ <usage>The class provides built-in support to several types of OAuth
221
+ servers. This means that the class can automatically initialize
222
+ several configuration variables just by setting this server
223
+ variable.<paragraphbreak />
224
+ Currently it supports the following servers:
225
+ <stringvalue>Bitbucket</stringvalue>,
226
+ <stringvalue>Dropbox</stringvalue>,
227
+ <stringvalue>Facebook</stringvalue>,
228
+ <stringvalue>Fitbit</stringvalue>,
229
+ <stringvalue>Flickr</stringvalue>,
230
+ <stringvalue>Foursquare</stringvalue>,
231
+ <stringvalue>github</stringvalue>,
232
+ <stringvalue>Google</stringvalue>,
233
+ <stringvalue>Instagram</stringvalue>,
234
+ <stringvalue>LinkedIn</stringvalue>,
235
+ <stringvalue>Microsoft</stringvalue>,
236
+ <stringvalue>Scoop.it</stringvalue>,
237
+ <stringvalue>Tumblr</stringvalue>,
238
+ <stringvalue>Twitter</stringvalue> and
239
+ <stringvalue>Yahoo</stringvalue>. Please contact the author if you
240
+ would like to ask to add built-in support for other types of OAuth
241
+ servers.<paragraphbreak />
242
+ If you want to access other types of OAuth servers that are not
243
+ yet supported, set this variable to an empty string and configure
244
+ other variables with values specific to those servers.</usage>
245
+ </documentation>
246
+ </variable>
247
+ {/metadocument}
248
+ */
249
+ var $server = '';
250
+
251
+ /*
252
+ {metadocument}
253
+ <variable>
254
+ <name>request_token_url</name>
255
+ <type>STRING</type>
256
+ <value></value>
257
+ <documentation>
258
+ <purpose>URL of the OAuth server to request the initial token for
259
+ OAuth 1.0 and 1.0a servers.</purpose>
260
+ <usage>Set this variable to the OAuth request token URL when you are
261
+ not accessing one of the built-in supported OAuth
262
+ servers.<paragraphbreak />
263
+ For OAuth 1.0 and 1.0a servers, the request token URL can have
264
+ certain marks that will act as template placeholders which will be
265
+ replaced with given values before requesting the authorization
266
+ token. Currently it supports the following placeholder
267
+ marks:<paragraphbreak />
268
+ {SCOPE} - scope of the requested permissions to the granted by the
269
+ OAuth server with the user permissions</usage>
270
+ </documentation>
271
+ </variable>
272
+ {/metadocument}
273
+ */
274
+ var $request_token_url = '';
275
+
276
+ /*
277
+ {metadocument}
278
+ <variable>
279
+ <name>dialog_url</name>
280
+ <type>STRING</type>
281
+ <value></value>
282
+ <documentation>
283
+ <purpose>URL of the OAuth server to redirect the browser so the user
284
+ can grant access to your application.</purpose>
285
+ <usage>Set this variable to the OAuth request token URL when you are
286
+ not accessing one of the built-in supported OAuth servers.<paragraphbreak />
287
+ For OAuth 2.0 servers, the dialog URL can have certain marks that
288
+ will act as template placeholders which will be replaced with
289
+ values defined before redirecting the users browser. Currently it
290
+ supports the following placeholder marks:<paragraphbreak />
291
+ {REDIRECT_URI} - URL to redirect when returning from the OAuth
292
+ server authorization page<paragraphbreak />
293
+ {CLIENT_ID} - client application identifier registered at the
294
+ server<paragraphbreak />
295
+ {SCOPE} - scope of the requested permissions to the granted by the
296
+ OAuth server with the user permissions<paragraphbreak />
297
+ {STATE} - identifier of the OAuth session state</usage>
298
+ </documentation>
299
+ </variable>
300
+ {/metadocument}
301
+ */
302
+ var $dialog_url = '';
303
+
304
+ /*
305
+ {metadocument}
306
+ <variable>
307
+ <name>append_state_to_redirect_uri</name>
308
+ <type>STRING</type>
309
+ <value></value>
310
+ <documentation>
311
+ <purpose>Pass the OAuth session state in a variable with a different
312
+ name to work around implementation bugs of certain OAuth
313
+ servers</purpose>
314
+ <usage>Set this variable when you are not accessing one of the
315
+ built-in supported OAuth servers if the OAuth server has a bug
316
+ that makes it not pass back the OAuth state identifier in a
317
+ request variable named state.</usage>
318
+ </documentation>
319
+ </variable>
320
+ {/metadocument}
321
+ */
322
+ var $append_state_to_redirect_uri = '';
323
+
324
+ /*
325
+ {metadocument}
326
+ <variable>
327
+ <name>access_token_url</name>
328
+ <type>STRING</type>
329
+ <value></value>
330
+ <documentation>
331
+ <purpose>OAuth server URL that will return the access token
332
+ URL.</purpose>
333
+ <usage>Set this variable to the OAuth access token URL when you are
334
+ not accessing one of the built-in supported OAuth servers.</usage>
335
+ </documentation>
336
+ </variable>
337
+ {/metadocument}
338
+ */
339
+ var $access_token_url = '';
340
+
341
+
342
+ /*
343
+ {metadocument}
344
+ <variable>
345
+ <name>oauth_version</name>
346
+ <type>STRING</type>
347
+ <value>2.0</value>
348
+ <documentation>
349
+ <purpose>Version of the protocol version supported by the OAuth
350
+ server.</purpose>
351
+ <usage>Set this variable to the OAuth server protocol version when
352
+ you are not accessing one of the built-in supported OAuth
353
+ servers.</usage>
354
+ </documentation>
355
+ </variable>
356
+ {/metadocument}
357
+ */
358
+ var $oauth_version = '2.0';
359
+
360
+ /*
361
+ {metadocument}
362
+ <variable>
363
+ <name>url_parameters</name>
364
+ <type>BOOLEAN</type>
365
+ <value>0</value>
366
+ <documentation>
367
+ <purpose>Determine if the API call parameters should be moved to the
368
+ call URL.</purpose>
369
+ <usage>Set this variable to <booleanvalue>1</booleanvalue> if the
370
+ API you need to call requires that the call parameters always be
371
+ passed via the API URL.</usage>
372
+ </documentation>
373
+ </variable>
374
+ {/metadocument}
375
+ */
376
+ var $url_parameters = false;
377
+
378
+ /*
379
+ {metadocument}
380
+ <variable>
381
+ <name>authorization_header</name>
382
+ <type>BOOLEAN</type>
383
+ <value>1</value>
384
+ <documentation>
385
+ <purpose>Determine if the OAuth parameters should be passed via HTTP
386
+ Authorization request header.</purpose>
387
+ <usage>Set this variable to <booleanvalue>1</booleanvalue> if the
388
+ OAuth server requires that the OAuth parameters be passed using
389
+ the HTTP Authorization instead of the request URI parameters.</usage>
390
+ </documentation>
391
+ </variable>
392
+ {/metadocument}
393
+ */
394
+ var $authorization_header = true;
395
+
396
+ /*
397
+ {metadocument}
398
+ <variable>
399
+ <name>redirect_uri</name>
400
+ <type>STRING</type>
401
+ <value></value>
402
+ <documentation>
403
+ <purpose>URL of the current script page that is calling this
404
+ class</purpose>
405
+ <usage>Set this variable to the current script page URL before
406
+ proceeding the the OAuth authorization process.</usage>
407
+ </documentation>
408
+ </variable>
409
+ {/metadocument}
410
+ */
411
+ var $redirect_uri = '';
412
+
413
+ /*
414
+ {metadocument}
415
+ <variable>
416
+ <name>client_id</name>
417
+ <type>STRING</type>
418
+ <value></value>
419
+ <documentation>
420
+ <purpose>Identifier of your application registered with the OAuth
421
+ server</purpose>
422
+ <usage>Set this variable to the application identifier that is
423
+ provided by the OAuth server when you register the
424
+ application.</usage>
425
+ </documentation>
426
+ </variable>
427
+ {/metadocument}
428
+ */
429
+ var $client_id = '';
430
+
431
+ /*
432
+ {metadocument}
433
+ <variable>
434
+ <name>client_secret</name>
435
+ <type>STRING</type>
436
+ <value></value>
437
+ <documentation>
438
+ <purpose>Secret value assigned to your application when it is
439
+ registered with the OAuth server.</purpose>
440
+ <usage>Set this variable to the application secret that is provided
441
+ by the OAuth server when you register the application.</usage>
442
+ </documentation>
443
+ </variable>
444
+ {/metadocument}
445
+ */
446
+ var $client_secret = '';
447
+
448
+ /*
449
+ {metadocument}
450
+ <variable>
451
+ <name>scope</name>
452
+ <type>STRING</type>
453
+ <value></value>
454
+ <documentation>
455
+ <purpose>Permissions that your application needs to call the OAuth
456
+ server APIs</purpose>
457
+ <usage>Check the documentation of the APIs that your application
458
+ needs to call to set this variable with the identifiers of the
459
+ permissions that the user needs to grant to your application.</usage>
460
+ </documentation>
461
+ </variable>
462
+ {/metadocument}
463
+ */
464
+ var $scope = '';
465
+
466
+ /*
467
+ {metadocument}
468
+ <variable>
469
+ <name>access_token</name>
470
+ <type>STRING</type>
471
+ <value></value>
472
+ <documentation>
473
+ <purpose>Access token obtained from the OAuth server</purpose>
474
+ <usage>Check this variable to get the obtained access token upon
475
+ successful OAuth authorization.</usage>
476
+ </documentation>
477
+ </variable>
478
+ {/metadocument}
479
+ */
480
+ var $access_token = '';
481
+
482
+ /*
483
+ {metadocument}
484
+ <variable>
485
+ <name>access_token_secret</name>
486
+ <type>STRING</type>
487
+ <value></value>
488
+ <documentation>
489
+ <purpose>Access token secret obtained from the OAuth server</purpose>
490
+ <usage>If the OAuth protocol version is 1.0 or 1.0a, check this
491
+ variable to get the obtained access token secret upon successful
492
+ OAuth authorization.</usage>
493
+ </documentation>
494
+ </variable>
495
+ {/metadocument}
496
+ */
497
+ var $access_token_secret = '';
498
+
499
+ /*
500
+ {metadocument}
501
+ <variable>
502
+ <name>access_token_expiry</name>
503
+ <type>STRING</type>
504
+ <value></value>
505
+ <documentation>
506
+ <purpose>Timestamp of the expiry of the access token obtained from
507
+ the OAuth server.</purpose>
508
+ <usage>Check this variable to get the obtained access token expiry
509
+ time upon successful OAuth authorization. If this variable is
510
+ empty, that means no expiry time was set.</usage>
511
+ </documentation>
512
+ </variable>
513
+ {/metadocument}
514
+ */
515
+ var $access_token_expiry = '';
516
+
517
+ /*
518
+ {metadocument}
519
+ <variable>
520
+ <name>access_token_type</name>
521
+ <type>STRING</type>
522
+ <value></value>
523
+ <documentation>
524
+ <purpose>Type of access token obtained from the OAuth server.</purpose>
525
+ <usage>Check this variable to get the obtained access token type
526
+ upon successful OAuth authorization.</usage>
527
+ </documentation>
528
+ </variable>
529
+ {/metadocument}
530
+ */
531
+ var $access_token_type = '';
532
+
533
+ /*
534
+ {metadocument}
535
+ <variable>
536
+ <name>access_token_error</name>
537
+ <type>STRING</type>
538
+ <value></value>
539
+ <documentation>
540
+ <purpose>Error message returned when a call to the API fails.</purpose>
541
+ <usage>Check this variable to determine if there was an error while
542
+ calling the Web services API when using the
543
+ <functionlink>CallAPI</functionlink> function.</usage>
544
+ </documentation>
545
+ </variable>
546
+ {/metadocument}
547
+ */
548
+ var $access_token_error = '';
549
+
550
+ /*
551
+ {metadocument}
552
+ <variable>
553
+ <name>authorization_error</name>
554
+ <type>STRING</type>
555
+ <value></value>
556
+ <documentation>
557
+ <purpose>Error message returned when it was not possible to obtain
558
+ an OAuth access token</purpose>
559
+ <usage>Check this variable to determine if there was an error while
560
+ trying to obtain the OAuth access token.</usage>
561
+ </documentation>
562
+ </variable>
563
+ {/metadocument}
564
+ */
565
+ var $authorization_error = '';
566
+
567
+ /*
568
+ {metadocument}
569
+ <variable>
570
+ <name>response_status</name>
571
+ <type>INTEGER</type>
572
+ <value>0</value>
573
+ <documentation>
574
+ <purpose>HTTP response status returned by the server when calling an
575
+ API</purpose>
576
+ <usage>Check this variable after calling the
577
+ <functionlink>CallAPI</functionlink> function if the API calls and you
578
+ need to process the error depending the response status.
579
+ <integervalue>200</integervalue> means no error.
580
+ <integervalue>0</integervalue> means the server response was not
581
+ retrieved.</usage>
582
+ </documentation>
583
+ </variable>
584
+ {/metadocument}
585
+ */
586
+ var $response_status = 0;
587
+
588
+ var $oauth_user_agent = 'PHP-OAuth-API (http://www.phpclasses.org/oauth-api $Revision: 1.46 $)';
589
+ var $session_started = false;
590
+
591
+ Function SetError($error)
592
+ {
593
+ $this->error = $error;
594
+ if($this->debug)
595
+ $this->OutputDebug('Error: '.$error);
596
+ return(false);
597
+ }
598
+
599
+ Function SetPHPError($error, &$php_error_message)
600
+ {
601
+ if(IsSet($php_error_message)
602
+ && strlen($php_error_message))
603
+ $error.=": ".$php_error_message;
604
+ return($this->SetError($error));
605
+ }
606
+
607
+ Function OutputDebug($message)
608
+ {
609
+ if($this->debug)
610
+ {
611
+ $message = $this->debug_prefix.$message;
612
+ $this->debug_output .= $message."\n";;
613
+ error_log($message);
614
+ }
615
+ return(true);
616
+ }
617
+
618
+ Function GetRequestTokenURL(&$request_token_url)
619
+ {
620
+ $request_token_url = $this->request_token_url;
621
+ return(true);
622
+ }
623
+
624
+ Function GetDialogURL(&$redirect_url)
625
+ {
626
+ $redirect_url = $this->dialog_url;
627
+ return(true);
628
+ }
629
+
630
+ Function GetAccessTokenURL(&$access_token_url)
631
+ {
632
+ $access_token_url = $this->access_token_url;
633
+ return(true);
634
+ }
635
+
636
+ Function GetStoredState(&$state)
637
+ {
638
+ if(IsSet($_SESSION['OAUTH_STATE']))
639
+ $state = $_SESSION['OAUTH_STATE'];
640
+ else
641
+ $state = $_SESSION['OAUTH_STATE'] = time().'-'.substr(md5(rand().time()), 0, 6);
642
+ return(true);
643
+ }
644
+
645
+ Function GetRequestState(&$state)
646
+ {
647
+ $check = (strlen($this->append_state_to_redirect_uri) ? $this->append_state_to_redirect_uri : 'state');
648
+ $state = (IsSet($_GET[$check]) ? $_GET[$check] : null);
649
+ return(true);
650
+ }
651
+
652
+ Function GetRequestCode(&$code)
653
+ {
654
+ $code = (IsSet($_GET['code']) ? $_GET['code'] : null);
655
+ return(true);
656
+ }
657
+
658
+ Function GetRequestError(&$error)
659
+ {
660
+ $error = (IsSet($_GET['error']) ? $_GET['error'] : null);
661
+ return(true);
662
+ }
663
+
664
+ Function GetRequestDenied(&$denied)
665
+ {
666
+ $denied = (IsSet($_GET['denied']) ? $_GET['denied'] : null);
667
+ return(true);
668
+ }
669
+
670
+ Function GetRequestToken(&$token, &$verifier)
671
+ {
672
+ $token = (IsSet($_GET['oauth_token']) ? $_GET['oauth_token'] : null);
673
+ $verifier = (IsSet($_GET['oauth_verifier']) ? $_GET['oauth_verifier'] : null);
674
+ return(true);
675
+ }
676
+
677
+ Function GetRedirectURI(&$redirect_uri)
678
+ {
679
+ if(strlen($this->redirect_uri))
680
+ $redirect_uri = $this->redirect_uri;
681
+ else
682
+ $redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
683
+ return true;
684
+ }
685
+
686
+ /*
687
+ {metadocument}
688
+ <function>
689
+ <name>StoreAccessToken</name>
690
+ <type>BOOLEAN</type>
691
+ <documentation>
692
+ <purpose>Store the values of the access token when it is succefully
693
+ retrieved from the OAuth server.</purpose>
694
+ <usage>This function is meant to be only be called from inside the
695
+ class. By default it stores access tokens in a session variable
696
+ named <stringvalue>OAUTH_ACCESS_TOKEN</stringvalue>.<paragraphbreak />
697
+ Actual implementations should create a sub-class and override this
698
+ function to make the access token values be stored in other types
699
+ of containers, like for instance databases.</usage>
700
+ <returnvalue>This function should return
701
+ <booleanvalue>1</booleanvalue> if the access token was stored
702
+ successfully.</returnvalue>
703
+ </documentation>
704
+ <argument>
705
+ <name>access_token</name>
706
+ <type>HASH</type>
707
+ <documentation>
708
+ <purpose>Associative array with properties of the access token.
709
+ The array may have set the following
710
+ properties:<paragraphbreak />
711
+ <stringvalue>value</stringvalue>: string value of the access
712
+ token<paragraphbreak />
713
+ <stringvalue>authorized</stringvalue>: boolean value that
714
+ determines if the access token was obtained
715
+ successfully<paragraphbreak />
716
+ <stringvalue>expiry</stringvalue>: (optional) timestamp in ISO
717
+ format relative to UTC time zone of the access token expiry
718
+ time<paragraphbreak />
719
+ <stringvalue>type</stringvalue>: (optional) type of OAuth token
720
+ that may determine how it should be used when sending API call
721
+ requests.</purpose>
722
+ </documentation>
723
+ </argument>
724
+ <do>
725
+ {/metadocument}
726
+ */
727
+ Function StoreAccessToken($access_token)
728
+ {
729
+ $_SESSION['OAUTH_ACCESS_TOKEN'][$this->access_token_url] = $access_token;
730
+ return true;
731
+ }
732
+ /*
733
+ {metadocument}
734
+ </do>
735
+ </function>
736
+ {/metadocument}
737
+ */
738
+
739
+ /*
740
+ {metadocument}
741
+ <function>
742
+ <name>GetAccessToken</name>
743
+ <type>BOOLEAN</type>
744
+ <documentation>
745
+ <purpose>Retrieve the OAuth access token if it was already
746
+ previously stored by the
747
+ <functionlink>StoreAccessToken</functionlink> function.</purpose>
748
+ <usage>This function is meant to be only be called from inside the
749
+ class. By default it retrieves access tokens stored in a session
750
+ variable named
751
+ <stringvalue>OAUTH_ACCESS_TOKEN</stringvalue>.<paragraphbreak />
752
+ Actual implementations should create a sub-class and override this
753
+ function to retrieve the access token values from other types of
754
+ containers, like for instance databases.</usage>
755
+ <returnvalue>This function should return
756
+ <booleanvalue>1</booleanvalue> if the access token was retrieved
757
+ successfully.</returnvalue>
758
+ </documentation>
759
+ <argument>
760
+ <name>access_token</name>
761
+ <type>STRING</type>
762
+ <out />
763
+ <documentation>
764
+ <purpose>Return the properties of the access token in an
765
+ associative array. If the access token was not yet stored, it
766
+ returns an empty array. Otherwise, the properties it may return
767
+ are the same that may be passed to the
768
+ <functionlink>StoreAccessToken</functionlink>.</purpose>
769
+ </documentation>
770
+ </argument>
771
+ <do>
772
+ {/metadocument}
773
+ */
774
+ Function GetAccessToken(&$access_token)
775
+ {
776
+ if(!$this->session_started
777
+ && !session_start())
778
+ return($this->SetPHPError('it was not possible to start the PHP session', $php_error_message));
779
+ $this->session_started = true;
780
+ if(IsSet($_SESSION['OAUTH_ACCESS_TOKEN'][$this->access_token_url]))
781
+ $access_token = $_SESSION['OAUTH_ACCESS_TOKEN'][$this->access_token_url];
782
+ else
783
+ $access_token = array();
784
+ return true;
785
+ }
786
+ /*
787
+ {metadocument}
788
+ </do>
789
+ </function>
790
+ {/metadocument}
791
+ */
792
+
793
+ /*
794
+ {metadocument}
795
+ <function>
796
+ <name>ResetAccessToken</name>
797
+ <type>BOOLEAN</type>
798
+ <documentation>
799
+ <purpose>Reset the access token to a state back when the user has
800
+ not yet authorized the access to the OAuth server API.</purpose>
801
+ <usage>Call this function if for some reason the token to access
802
+ the API was revoked and you need to ask the user to authorize
803
+ the access again.<paragraphbreak />
804
+ By default the class stores and retrieves access tokens in a
805
+ session variable named
806
+ <stringvalue>OAUTH_ACCESS_TOKEN</stringvalue>.<paragraphbreak />
807
+ This function must be called when the user is accessing your site
808
+ pages, so it can reset the information stored in session variables
809
+ that cache the state of a previously retrieved access
810
+ token.<paragraphbreak />
811
+ Actual implementations should create a sub-class and override this
812
+ function to reset the access token state when it is stored in
813
+ other types of containers, like for instance databases.</usage>
814
+ <returnvalue>This function should return
815
+ <booleanvalue>1</booleanvalue> if the access token was resetted
816
+ successfully.</returnvalue>
817
+ </documentation>
818
+ <do>
819
+ {/metadocument}
820
+ */
821
+ Function ResetAccessToken()
822
+ {
823
+ if($this->debug)
824
+ $this->OutputDebug('Resetting the access token status for OAuth server located at '.$this->access_token_url);
825
+ if(!$this->session_started
826
+ && !session_start())
827
+ return($this->SetPHPError('it was not possible to start the PHP session', $php_error_message));
828
+ $this->session_started = true;
829
+ if(IsSet($_SESSION['OAUTH_ACCESS_TOKEN'][$this->access_token_url]))
830
+ Unset($_SESSION['OAUTH_ACCESS_TOKEN'][$this->access_token_url]);
831
+ return true;
832
+ }
833
+ /*
834
+ {metadocument}
835
+ </do>
836
+ </function>
837
+ {/metadocument}
838
+ */
839
+
840
+ Function Encode($value)
841
+ {
842
+ return(is_array($value) ? $this->EncodeArray($value) : str_replace('%7E', '~', str_replace('+',' ', RawURLEncode($value))));
843
+ }
844
+
845
+ Function EncodeArray($array)
846
+ {
847
+ foreach($array as $key => $value)
848
+ $array[$key] = $this->Encode($value);
849
+ return $array;
850
+ }
851
+
852
+ Function HMAC($function, $data, $key)
853
+ {
854
+ switch($function)
855
+ {
856
+ case 'sha1':
857
+ $pack = 'H40';
858
+ break;
859
+ default:
860
+ if($this->debug)
861
+ $this->OutputDebug($function.' is not a supported an HMAC hash type');
862
+ return('');
863
+ }
864
+ if(strlen($key) > 64)
865
+ $key = pack($pack, $function($key));
866
+ if(strlen($key) < 64)
867
+ $key = str_pad($key, 64, "\0");
868
+ return(pack($pack, $function((str_repeat("\x5c", 64) ^ $key).pack($pack, $function((str_repeat("\x36", 64) ^ $key).$data)))));
869
+ }
870
+
871
+ Function SendAPIRequest($url, $method, $parameters, $oauth, $options, &$response)
872
+ {
873
+ $this->response_status = 0;
874
+ $http = new http_class;
875
+ $http->debug = ($this->debug && $this->debug_http);
876
+ $http->log_debug = true;
877
+ $http->sasl_authenticate = 0;
878
+ $http->user_agent = $this->oauth_user_agent;
879
+ if($this->debug)
880
+ $this->OutputDebug('Accessing the '.$options['Resource'].' at '.$url);
881
+ $arguments = array();
882
+ $method = strtoupper($method);
883
+ $authorization = '';
884
+ $type = (IsSet($options['RequestContentType']) ? strtolower(trim(strtok($options['RequestContentType'], ';'))) : 'application/x-www-form-urlencoded');
885
+ if(IsSet($oauth))
886
+ {
887
+ $values = array(
888
+ 'oauth_consumer_key'=>$this->client_id,
889
+ 'oauth_nonce'=>md5(uniqid(rand(), true)),
890
+ 'oauth_signature_method'=>'HMAC-SHA1',
891
+ 'oauth_timestamp'=>time(),
892
+ 'oauth_version'=>'1.0',
893
+ );
894
+ if($this->url_parameters
895
+ && $type === 'application/x-www-form-urlencoded'
896
+ && count($parameters))
897
+ {
898
+ $first = (strpos($url, '?') === false);
899
+ foreach($parameters as $parameter => $value)
900
+ $url .= ($first ? '?' : '&').UrlEncode($parameter).'='.UrlEncode($value);
901
+ $parameters = array();
902
+ }
903
+ $value_parameters = ($type !== 'application/x-www-form-urlencoded' ? array() : $parameters);
904
+ $values = array_merge($values, $oauth, $value_parameters);
905
+ $uri = strtok($url, '?');
906
+ $sign = $method.'&'.$this->Encode($uri).'&';
907
+ $first = true;
908
+ $sign_values = $values;
909
+ $u = parse_url($url);
910
+ if(IsSet($u['query']))
911
+ {
912
+ parse_str($u['query'], $q);
913
+ foreach($q as $parameter => $value)
914
+ $sign_values[$parameter] = $value;
915
+ }
916
+ KSort($sign_values);
917
+ foreach($sign_values as $parameter => $value)
918
+ {
919
+ $sign .= $this->Encode(($first ? '' : '&').$parameter.'='.$this->Encode($value));
920
+ $first = false;
921
+ }
922
+ $key = $this->Encode($this->client_secret).'&'.$this->Encode($this->access_token_secret);
923
+ $values['oauth_signature'] = base64_encode($this->HMAC('sha1', $sign, $key));
924
+ if($this->authorization_header)
925
+ {
926
+ $authorization = 'OAuth';
927
+ $first = true;
928
+ foreach($values as $parameter => $value)
929
+ {
930
+ $authorization .= ($first ? ' ' : ',').$parameter.'="'.$this->Encode($value).'"';
931
+ $first = false;
932
+ }
933
+ }
934
+ else
935
+ {
936
+ if($method === 'GET')
937
+ {
938
+ $first = (strcspn($url, '?') == strlen($url));
939
+ foreach($values as $parameter => $value)
940
+ {
941
+ $url .= ($first ? '?' : '&').$parameter.'='.$this->Encode($value);
942
+ $first = false;
943
+ }
944
+ $post_values = array();
945
+ }
946
+ else
947
+ $post_values = $values;
948
+ }
949
+ }
950
+ if(strlen($error = $http->GetRequestArguments($url, $arguments)))
951
+ return($this->SetError('it was not possible to open the '.$options['Resource'].' URL: '.$error));
952
+ if(strlen($error = $http->Open($arguments)))
953
+ return($this->SetError('it was not possible to open the '.$options['Resource'].' URL: '.$error));
954
+ $arguments['RequestMethod'] = $method;
955
+ switch($type)
956
+ {
957
+ case 'application/x-www-form-urlencoded':
958
+ if(IsSet($options['RequestBody']))
959
+ return($this->SetError('the request body is defined automatically from the parameters'));
960
+ $arguments['PostValues'] = $parameters;
961
+ break;
962
+ case 'application/json':
963
+ $arguments['Headers']['Content-Type'] = $options['RequestContentType'];
964
+ if(!IsSet($options['RequestBody']))
965
+ {
966
+ $arguments['Body'] = json_encode($parameters);
967
+ break;
968
+ }
969
+ default:
970
+ if(!IsSet($options['RequestBody']))
971
+ return($this->SetError('it was not specified the body value of the of the API call request'));
972
+ $arguments['Headers']['Content-Type'] = $options['RequestContentType'];
973
+ $arguments['Body'] = $options['RequestBody'];
974
+ break;
975
+ }
976
+ $arguments['Headers']['Accept'] = (IsSet($options['Accept']) ? $options['Accept'] : '*/*');
977
+ if(strlen($authorization))
978
+ $arguments['Headers']['Authorization'] = $authorization;
979
+ if(strlen($error = $http->SendRequest($arguments))
980
+ || strlen($error = $http->ReadReplyHeaders($headers)))
981
+ {
982
+ $http->Close();
983
+ return($this->SetError('it was not possible to retrieve the '.$options['Resource'].': '.$error));
984
+ }
985
+ $error = $http->ReadWholeReplyBody($data);
986
+ $http->Close();
987
+ if(strlen($error))
988
+ {
989
+ return($this->SetError('it was not possible to access the '.$options['Resource'].': '.$error));
990
+ }
991
+ $this->response_status = intval($http->response_status);
992
+ $content_type = (IsSet($headers['content-type']) ? strtolower(trim(strtok($headers['content-type'], ';'))) : 'unspecified');
993
+ switch($content_type)
994
+ {
995
+ case 'text/javascript':
996
+ case 'application/json':
997
+ if(!function_exists('json_decode'))
998
+ return($this->SetError('the JSON extension is not available in this PHP setup'));
999
+ $object = json_decode($data);
1000
+ switch(GetType($object))
1001
+ {
1002
+ case 'object':
1003
+ if(!IsSet($options['ConvertObjects'])
1004
+ || !$options['ConvertObjects'])
1005
+ $response = $object;
1006
+ else
1007
+ {
1008
+ $response = array();
1009
+ foreach($object as $property => $value)
1010
+ $response[$property] = $value;
1011
+ }
1012
+ break;
1013
+ case 'array':
1014
+ $response = $object;
1015
+ break;
1016
+ default:
1017
+ if(!IsSet($object))
1018
+ return($this->SetError('it was not returned a valid JSON definition of the '.$options['Resource'].' values'));
1019
+ $response = $object;
1020
+ break;
1021
+ }
1022
+ break;
1023
+ case 'application/x-www-form-urlencoded':
1024
+ case 'text/plain':
1025
+ case 'text/html':
1026
+ parse_str($data, $response);
1027
+ break;
1028
+ default:
1029
+ $response = $data;
1030
+ break;
1031
+ }
1032
+ if($this->response_status >= 200
1033
+ && $this->response_status < 300)
1034
+ $this->access_token_error = '';
1035
+ else
1036
+ {
1037
+ $this->access_token_error = 'it was not possible to access the '.$options['Resource'].': it was returned an unexpected response status '.$http->response_status.' Response: '.$data;
1038
+ if($this->debug)
1039
+ $this->OutputDebug('Could not retrieve the OAuth access. Error: '.$this->access_token_error);
1040
+ if(IsSet($options['FailOnAccessError'])
1041
+ && $options['FailOnAccessError'])
1042
+ {
1043
+ $this->error = $this->access_token_error;
1044
+ return false;
1045
+ }
1046
+ }
1047
+ return true;
1048
+ }
1049
+
1050
+ /*
1051
+ {metadocument}
1052
+ <function>
1053
+ <name>CallAPI</name>
1054
+ <type>BOOLEAN</type>
1055
+ <documentation>
1056
+ <purpose>Send a HTTP request to the Web services API using a
1057
+ previously obtained authorization token via OAuth.</purpose>
1058
+ <usage>This function can be used to call an API after having
1059
+ previously obtained an access token through the OAuth protocol
1060
+ using the <functionlink>Process</functionlink> function, or by
1061
+ directly setting the variables
1062
+ <variablelink>access_token</variablelink>, as well as
1063
+ <variablelink>access_token_secret</variablelink> in case of using
1064
+ OAuth 1.0 or 1.0a services.</usage>
1065
+ <returnvalue>This function returns <booleanvalue>1</booleanvalue> if
1066
+ the call was done successfully.</returnvalue>
1067
+ </documentation>
1068
+ <argument>
1069
+ <name>url</name>
1070
+ <type>STRING</type>
1071
+ <documentation>
1072
+ <purpose>URL of the API where the HTTP request will be sent.</purpose>
1073
+ </documentation>
1074
+ </argument>
1075
+ <argument>
1076
+ <name>method</name>
1077
+ <type>STRING</type>
1078
+ <documentation>
1079
+ <purpose>HTTP method that will be used to send the request. It can
1080
+ be <stringvalue>GET</stringvalue>,
1081
+ <stringvalue>POST</stringvalue>,
1082
+ <stringvalue>DELETE</stringvalue>, <stringvalue>PUT</stringvalue>,
1083
+ etc..</purpose>
1084
+ </documentation>
1085
+ </argument>
1086
+ <argument>
1087
+ <name>parameters</name>
1088
+ <type>HASH</type>
1089
+ <documentation>
1090
+ <purpose>Associative array with the names and values of the API
1091
+ call request parameters.</purpose>
1092
+ </documentation>
1093
+ </argument>
1094
+ <argument>
1095
+ <name>options</name>
1096
+ <type>HASH</type>
1097
+ <documentation>
1098
+ <purpose>Associative array with additional options to configure
1099
+ the request. Currently it supports the following
1100
+ options:<paragraphbreak />
1101
+ <stringvalue>Resource</stringvalue>: string with a label that
1102
+ will be used in the error messages and debug log entries to
1103
+ identify what operation the request is performing. The default
1104
+ value is <stringvalue>API call</stringvalue>.<paragraphbreak />
1105
+ <stringvalue>ConvertObjects</stringvalue>: boolean option that
1106
+ determines if objects should be converted into arrays when the
1107
+ response is returned in JSON format. The default value is
1108
+ <booleanvalue>0</booleanvalue>.<paragraphbreak />
1109
+ <stringvalue>FailOnAccessError</stringvalue>: boolean option
1110
+ that determines if this functions should fail when the server
1111
+ response status is not between 200 and 299. The default value
1112
+ is <booleanvalue>0</booleanvalue>.<paragraphbreak />
1113
+ <stringvalue>Accept</stringvalue>: content type value of the
1114
+ Accept HTTP header to be sent in the API call HTTP request.
1115
+ Some APIs require that a certain value be sent to specify
1116
+ which version of the API is being called. The default value is
1117
+ <stringvalue>*&#47;*</stringvalue>.<paragraphbreak />
1118
+ <stringvalue>RequestContentType</stringvalue>: content type that
1119
+ should be used to send the request values. It can be either
1120
+ <stringvalue>application/x-www-form-urlencoded</stringvalue>
1121
+ for sending values like from Web forms, or
1122
+ <stringvalue>application/json</stringvalue> for sending the
1123
+ values encoded in JSON format. Other types are accepted if the
1124
+ <stringvalue>RequestBody</stringvalue> option is specified.
1125
+ The default value is
1126
+ <stringvalue>application/x-www-form-urlencoded</stringvalue>.<paragraphbreak />
1127
+ <stringvalue>RequestBody</stringvalue>: request body data of a
1128
+ custom type. The <stringvalue>RequestContentType</stringvalue>
1129
+ option must be specified, so the
1130
+ <stringvalue>RequestBody</stringvalue> option is considered.</purpose>
1131
+ </documentation>
1132
+ </argument>
1133
+ <argument>
1134
+ <name>response</name>
1135
+ <type>STRING</type>
1136
+ <out />
1137
+ <documentation>
1138
+ <purpose>Return the value of the API response. If the value is
1139
+ JSON encoded, this function will decode it and return the value
1140
+ converted to respective types. If the value is form encoded,
1141
+ this function will decode the response and return it as an
1142
+ array. Otherwise, the class will return the value as a
1143
+ string.</purpose>
1144
+ </documentation>
1145
+ </argument>
1146
+ <do>
1147
+ {/metadocument}
1148
+ */
1149
+ Function CallAPI($url, $method, $parameters, $options, &$response)
1150
+ {
1151
+ if(!IsSet($options['Resource']))
1152
+ $options['Resource'] = 'API call';
1153
+ if(!IsSet($options['ConvertObjects']))
1154
+ $options['ConvertObjects'] = false;
1155
+ switch(intval($this->oauth_version))
1156
+ {
1157
+ case 1:
1158
+ $oauth = array(
1159
+ 'oauth_token'=>$this->access_token
1160
+ );
1161
+ break;
1162
+
1163
+ case 2:
1164
+ $oauth = null;
1165
+ $url .= (strcspn($url, '?') < strlen($url) ? '&' : '?').'access_token='.UrlEncode($this->access_token);
1166
+ break;
1167
+
1168
+ default:
1169
+ return($this->SetError($this->oauth_version.' is not a supported version of the OAuth protocol'));
1170
+ }
1171
+ return($this->SendAPIRequest($url, $method, $parameters, $oauth, $options, $response));
1172
+ }
1173
+ /*
1174
+ {metadocument}
1175
+ </do>
1176
+ </function>
1177
+ {/metadocument}
1178
+ */
1179
+
1180
+ /*
1181
+ {metadocument}
1182
+ <function>
1183
+ <name>Initialize</name>
1184
+ <type>BOOLEAN</type>
1185
+ <documentation>
1186
+ <purpose>Initialize the class variables and internal state. It must
1187
+ be called before calling other class functions.</purpose>
1188
+ <usage>Set the <variablelink>server</variablelink> variable before
1189
+ calling this function to let it initialize the class variables to
1190
+ work with the specified server type. Alternatively, you can set
1191
+ other class variables manually to make it work with servers that
1192
+ are not yet built-in supported.</usage>
1193
+ <returnvalue>This function returns <booleanvalue>1</booleanvalue> if
1194
+ it was able to successfully initialize the class for the specified
1195
+ server type.</returnvalue>
1196
+ </documentation>
1197
+ <do>
1198
+ {/metadocument}
1199
+ */
1200
+ Function Initialize()
1201
+ {
1202
+ switch($this->server)
1203
+ {
1204
+ case '';
1205
+ break;
1206
+
1207
+ case 'Bitbucket':
1208
+ $this->oauth_version = '1.0a';
1209
+ $this->request_token_url = 'https://bitbucket.org/!api/1.0/oauth/request_token';
1210
+ $this->dialog_url = 'https://bitbucket.org/!api/1.0/oauth/authenticate';
1211
+ $this->append_state_to_redirect_uri = '';
1212
+ $this->access_token_url = 'https://bitbucket.org/!api/1.0/oauth/access_token';
1213
+ $this->authorization_header = true;
1214
+ $this->url_parameters = true;
1215
+ break;
1216
+
1217
+ case 'Dropbox':
1218
+ $this->oauth_version = '1.0';
1219
+ $this->request_token_url = 'https://api.dropbox.com/1/oauth/request_token';
1220
+ $this->dialog_url = 'https://www.dropbox.com/1/oauth/authorize';
1221
+ $this->append_state_to_redirect_uri = '';
1222
+ $this->access_token_url = 'https://api.dropbox.com/1/oauth/access_token';
1223
+ $this->authorization_header = false;
1224
+ $this->url_parameters = false;
1225
+ break;
1226
+
1227
+ case 'Facebook':
1228
+ $this->oauth_version = '2.0';
1229
+ $this->request_token_url = '';
1230
+ $this->dialog_url = 'https://www.facebook.com/dialog/oauth?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&state={STATE}';
1231
+ $this->append_state_to_redirect_uri = '';
1232
+ $this->access_token_url = 'https://graph.facebook.com/oauth/access_token';
1233
+ $this->authorization_header = true;
1234
+ $this->url_parameters = false;
1235
+ break;
1236
+
1237
+ case 'Fitbit':
1238
+ $this->oauth_version = '1.0a';
1239
+ $this->request_token_url = 'http://api.fitbit.com/oauth/request_token';
1240
+ $this->dialog_url = 'http://api.fitbit.com/oauth/authorize';
1241
+ $this->append_state_to_redirect_uri = '';
1242
+ $this->access_token_url = 'http://api.fitbit.com/oauth/access_token';
1243
+ $this->authorization_header = true;
1244
+ $this->url_parameters = false;
1245
+ break;
1246
+
1247
+ case 'Flickr':
1248
+ $this->oauth_version = '1.0a';
1249
+ $this->request_token_url = 'http://www.flickr.com/services/oauth/request_token';
1250
+ $this->dialog_url = 'http://www.flickr.com/services/oauth/authorize';
1251
+ $this->append_state_to_redirect_uri = '';
1252
+ $this->access_token_url = 'http://www.flickr.com/services/oauth/access_token';
1253
+ $this->authorization_header = false;
1254
+ $this->url_parameters = false;
1255
+ break;
1256
+
1257
+ case 'Foursquare':
1258
+ $this->oauth_version = '2.0';
1259
+ $this->request_token_url = '';
1260
+ $this->dialog_url = 'https://foursquare.com/oauth2/authorize?client_id={CLIENT_ID}&scope={SCOPE}&response_type=code&redirect_uri={REDIRECT_URI}&state={STATE}';
1261
+ $this->append_state_to_redirect_uri = '';
1262
+ $this->access_token_url = 'https://foursquare.com/oauth2/access_token';
1263
+ $this->authorization_header = true;
1264
+ $this->url_parameters = false;
1265
+ break;
1266
+
1267
+ case 'github':
1268
+ $this->oauth_version = '2.0';
1269
+ $this->request_token_url = '';
1270
+ $this->dialog_url = 'https://github.com/login/oauth/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&state={STATE}';
1271
+ $this->append_state_to_redirect_uri = '';
1272
+ $this->access_token_url = 'https://github.com/login/oauth/access_token';
1273
+ $this->authorization_header = true;
1274
+ $this->url_parameters = false;
1275
+ break;
1276
+
1277
+ case 'Google':
1278
+ $this->oauth_version = '2.0';
1279
+ $this->request_token_url = '';
1280
+ $this->dialog_url = 'https://accounts.google.com/o/oauth2/auth?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&state={STATE}';
1281
+ $this->append_state_to_redirect_uri = '';
1282
+ $this->access_token_url = 'https://accounts.google.com/o/oauth2/token';
1283
+ $this->authorization_header = true;
1284
+ $this->url_parameters = false;
1285
+ break;
1286
+
1287
+ case 'Instagram':
1288
+ $this->oauth_version = '2.0';
1289
+ $this->request_token_url = '';
1290
+ $this->dialog_url ='https://api.instagram.com/oauth/authorize/?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&response_type=code&state={STATE}';
1291
+ $this->append_state_to_redirect_uri = '';
1292
+ $this->access_token_url = 'https://api.instagram.com/oauth/access_token';
1293
+ $this->authorization_header = true;
1294
+ $this->url_parameters = false;
1295
+ break;
1296
+
1297
+ case 'LinkedIn':
1298
+ $this->oauth_version = '1.0a';
1299
+ $this->request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken?scope={SCOPE}';
1300
+ $this->dialog_url = 'https://api.linkedin.com/uas/oauth/authenticate';
1301
+ $this->access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken';
1302
+ $this->append_state_to_redirect_uri = '';
1303
+ $this->authorization_header = true;
1304
+ $this->url_parameters = true;
1305
+ break;
1306
+
1307
+ case 'Microsoft':
1308
+ $this->oauth_version = '2.0';
1309
+ $this->request_token_url = '';
1310
+ $this->dialog_url = 'https://login.live.com/oauth20_authorize.srf?client_id={CLIENT_ID}&scope={SCOPE}&response_type=code&redirect_uri={REDIRECT_URI}&state={STATE}';
1311
+ $this->append_state_to_redirect_uri = '';
1312
+ $this->access_token_url = 'https://login.live.com/oauth20_token.srf';
1313
+ $this->authorization_header = true;
1314
+ $this->url_parameters = false;
1315
+ break;
1316
+
1317
+ case 'Scoop.it':
1318
+ $this->oauth_version = '1.0a';
1319
+ $this->request_token_url = 'https://www.scoop.it/oauth/request';
1320
+ $this->dialog_url = 'https://www.scoop.it/oauth/authorize';
1321
+ $this->append_state_to_redirect_uri = '';
1322
+ $this->access_token_url = 'https://www.scoop.it/oauth/access';
1323
+ $this->authorization_header = false;
1324
+ $this->url_parameters = false;
1325
+ break;
1326
+
1327
+ case 'Tumblr':
1328
+ $this->oauth_version = '1.0a';
1329
+ $this->request_token_url = 'http://www.tumblr.com/oauth/request_token';
1330
+ $this->dialog_url = 'http://www.tumblr.com/oauth/authorize';
1331
+ $this->append_state_to_redirect_uri = '';
1332
+ $this->access_token_url = 'http://www.tumblr.com/oauth/access_token';
1333
+ $this->authorization_header = true;
1334
+ $this->url_parameters = false;
1335
+ break;
1336
+
1337
+ case 'Twitter':
1338
+ $this->oauth_version = '1.0a';
1339
+ $this->request_token_url = 'https://api.twitter.com/oauth/request_token';
1340
+ $this->dialog_url = 'https://api.twitter.com/oauth/authenticate';
1341
+ $this->append_state_to_redirect_uri = '';
1342
+ $this->access_token_url = 'https://api.twitter.com/oauth/access_token';
1343
+ $this->authorization_header = true;
1344
+ $this->url_parameters = true;
1345
+ break;
1346
+
1347
+ case 'Yahoo':
1348
+ $this->oauth_version = '1.0a';
1349
+ $this->request_token_url = 'https://api.login.yahoo.com/oauth/v2/get_request_token';
1350
+ $this->dialog_url = 'https://api.login.yahoo.com/oauth/v2/request_auth';
1351
+ $this->access_token_url = 'https://api.login.yahoo.com/oauth/v2/get_token';
1352
+ $this->append_state_to_redirect_uri = '';
1353
+ $this->authorization_header = false;
1354
+ $this->url_parameters = false;
1355
+ break;
1356
+
1357
+ default:
1358
+ return($this->SetError($this->server.' is not yet a supported type of OAuth server. Please contact the author Manuel Lemos <mlemos@acm.org> to request adding built-in support to this type of OAuth server.'));
1359
+ }
1360
+ return(true);
1361
+ }
1362
+ /*
1363
+ {metadocument}
1364
+ </do>
1365
+ </function>
1366
+ {/metadocument}
1367
+ */
1368
+
1369
+ /*
1370
+ {metadocument}
1371
+ <function>
1372
+ <name>Process</name>
1373
+ <type>BOOLEAN</type>
1374
+ <documentation>
1375
+ <purpose>Process the OAuth protocol interaction with the OAuth
1376
+ server.</purpose>
1377
+ <usage>Call this function when you need to retrieve the OAuth access
1378
+ token. Check the <variablelink>access_token</variablelink> to
1379
+ determine if the access token was obtained successfully.</usage>
1380
+ <returnvalue>This function returns <booleanvalue>1</booleanvalue> if
1381
+ the OAuth protocol was processed without errors.</returnvalue>
1382
+ </documentation>
1383
+ <do>
1384
+ {/metadocument}
1385
+ */
1386
+ Function Process()
1387
+ {
1388
+ switch(intval($this->oauth_version))
1389
+ {
1390
+ case 1:
1391
+ $one_a = ($this->oauth_version === '1.0a');
1392
+ if($this->debug)
1393
+ $this->OutputDebug('Checking the OAuth token authorization state');
1394
+ if(!$this->GetAccessToken($access_token))
1395
+ return false;
1396
+ if(IsSet($access_token['authorized'])
1397
+ && IsSet($access_token['value']))
1398
+ {
1399
+ $expired = (IsSet($access_token['expiry']) && strcmp($access_token['expiry'], gmstrftime('%Y-%m-%d %H:%M:%S')) <= 0);
1400
+ if(!$access_token['authorized']
1401
+ || $expired)
1402
+ {
1403
+ if($this->debug)
1404
+ {
1405
+ if($expired)
1406
+ $this->OutputDebug('The OAuth token expired on '.$access_token['expiry'].'UTC');
1407
+ else
1408
+ $this->OutputDebug('The OAuth token is not yet authorized');
1409
+ $this->OutputDebug('Checking the OAuth token and verifier');
1410
+ }
1411
+ if(!$this->GetRequestToken($token, $verifier))
1412
+ return false;
1413
+ if(!IsSet($token)
1414
+ || ($one_a
1415
+ && !IsSet($verifier)))
1416
+ {
1417
+ if(!$this->GetRequestDenied($denied))
1418
+ return false;
1419
+ if(IsSet($denied)
1420
+ && $denied === $access_token['value'])
1421
+ {
1422
+ if($this->debug)
1423
+ $this->OutputDebug('The authorization request was denied');
1424
+ $this->authorization_error = 'the request was denied';
1425
+ return true;
1426
+ }
1427
+ else
1428
+ {
1429
+ if($this->debug)
1430
+ $this->OutputDebug('Reset the OAuth token state because token and verifier are not both set');
1431
+ $access_token = array();
1432
+ }
1433
+ }
1434
+ elseif($token !== $access_token['value'])
1435
+ {
1436
+ if($this->debug)
1437
+ $this->OutputDebug('Reset the OAuth token state because token does not match what as previously retrieved');
1438
+ $access_token = array();
1439
+ }
1440
+ else
1441
+ {
1442
+ if(!$this->GetAccessTokenURL($url))
1443
+ return false;
1444
+ $oauth = array(
1445
+ 'oauth_token'=>$token,
1446
+ );
1447
+ if($one_a)
1448
+ $oauth['oauth_verifier'] = $verifier;
1449
+ $this->access_token_secret = $access_token['secret'];
1450
+ if(!$this->SendAPIRequest($url, 'GET', array(), $oauth, array('Resource'=>'OAuth access token'), $response))
1451
+ return false;
1452
+ if(strlen($this->access_token_error))
1453
+ {
1454
+ $this->authorization_error = $this->access_token_error;
1455
+ return true;
1456
+ }
1457
+ if(!IsSet($response['oauth_token'])
1458
+ || !IsSet($response['oauth_token_secret']))
1459
+ {
1460
+ $this->authorization_error= 'it was not returned the access token and secret';
1461
+ return true;
1462
+ }
1463
+ $access_token = array(
1464
+ 'value'=>$response['oauth_token'],
1465
+ 'secret'=>$response['oauth_token_secret'],
1466
+ 'authorized'=>true
1467
+ );
1468
+ if(IsSet($response['oauth_expires_in']))
1469
+ {
1470
+ $expires = $response['oauth_expires_in'];
1471
+ if(strval($expires) !== strval(intval($expires))
1472
+ || $expires <= 0)
1473
+ return($this->SetError('OAuth server did not return a supported type of access token expiry time'));
1474
+ $this->access_token_expiry = gmstrftime('%Y-%m-%d %H:%M:%S', time() + $expires);
1475
+ if($this->debug)
1476
+ $this->OutputDebug('Access token expiry: '.$this->access_token_expiry.' UTC');
1477
+ $access_token['expiry'] = $this->access_token_expiry;
1478
+ }
1479
+ else
1480
+ $this->access_token_expiry = '';
1481
+
1482
+ if(!$this->StoreAccessToken($access_token))
1483
+ return false;
1484
+ if($this->debug)
1485
+ $this->OutputDebug('The OAuth token was authorized');
1486
+ }
1487
+ }
1488
+ elseif($this->debug)
1489
+ $this->OutputDebug('The OAuth token was already authorized');
1490
+ if(IsSet($access_token['authorized'])
1491
+ && $access_token['authorized'])
1492
+ {
1493
+ $this->access_token = $access_token['value'];
1494
+ $this->access_token_secret = $access_token['secret'];
1495
+ return true;
1496
+ }
1497
+ }
1498
+ else
1499
+ {
1500
+ if($this->debug)
1501
+ $this->OutputDebug('The OAuth access token is not set');
1502
+ $access_token = array();
1503
+ }
1504
+ if(!IsSet($access_token['authorized']))
1505
+ {
1506
+ if($this->debug)
1507
+ $this->OutputDebug('Requesting the unauthorized OAuth token');
1508
+ if(!$this->GetRequestTokenURL($url))
1509
+ return false;
1510
+ $url = str_replace('{SCOPE}', UrlEncode($this->scope), $url);
1511
+ if(!$this->GetRedirectURI($redirect_uri))
1512
+ return false;
1513
+ $oauth = array(
1514
+ 'oauth_callback'=>$redirect_uri,
1515
+ );
1516
+ if(!$this->SendAPIRequest($url, 'GET', array(), $oauth, array('Resource'=>'OAuth request token'), $response))
1517
+ return false;
1518
+ if(strlen($this->access_token_error))
1519
+ {
1520
+ $this->authorization_error = $this->access_token_error;
1521
+ return true;
1522
+ }
1523
+ if(!IsSet($response['oauth_token'])
1524
+ || !IsSet($response['oauth_token_secret']))
1525
+ {
1526
+ $this->authorization_error = 'it was not returned the requested token';
1527
+ return true;
1528
+ }
1529
+ $access_token = array(
1530
+ 'value'=>$response['oauth_token'],
1531
+ 'secret'=>$response['oauth_token_secret'],
1532
+ 'authorized'=>false
1533
+ );
1534
+ if(!$this->StoreAccessToken($access_token))
1535
+ return false;
1536
+ }
1537
+ if(!$this->GetDialogURL($url))
1538
+ return false;
1539
+ $url .= '?oauth_token='.$access_token['value'];
1540
+ if(!$one_a)
1541
+ {
1542
+ if(!$this->GetRedirectURI($redirect_uri))
1543
+ return false;
1544
+ $url .= '&oauth_callback='.UrlEncode($redirect_uri);
1545
+ }
1546
+ if($this->debug)
1547
+ $this->OutputDebug('Redirecting to OAuth authorize page '.$url);
1548
+ Header('HTTP/1.0 302 OAuth Redirection');
1549
+ Header('Location: '.$url);
1550
+ $this->exit = true;
1551
+ return true;
1552
+
1553
+ case 2:
1554
+ if($this->debug)
1555
+ $this->OutputDebug('Checking if OAuth access token was already retrieved from '.$this->access_token_url);
1556
+ if(!$this->GetAccessToken($access_token))
1557
+ return false;
1558
+ if(IsSet($access_token['value']))
1559
+ {
1560
+ if(IsSet($access_token['expiry'])
1561
+ && strcmp($this->access_token_expiry = $access_token['expiry'], gmstrftime('%Y-%m-%d %H:%M:%S')) < 0)
1562
+ {
1563
+ if($this->debug)
1564
+ $this->OutputDebug('The OAuth access token expired in '.$this->access_token_expiry);
1565
+ }
1566
+ else
1567
+ {
1568
+ $this->access_token = $access_token['value'];
1569
+ if(IsSet($access_token['type']))
1570
+ $this->access_token_type = $access_token['type'];
1571
+ if($this->debug)
1572
+ $this->OutputDebug('The OAuth access token '.$this->access_token.' is valid');
1573
+ if(strlen($this->access_token_type)
1574
+ && $this->debug)
1575
+ $this->OutputDebug('The OAuth access token is of type '.$this->access_token_type);
1576
+ return true;
1577
+ }
1578
+ }
1579
+ if($this->debug)
1580
+ $this->OutputDebug('Checking the authentication state in URI '.$_SERVER['REQUEST_URI']);
1581
+ if(!$this->GetStoredState($stored_state))
1582
+ return false;
1583
+ if(strlen($stored_state) == 0)
1584
+ return($this->SetError('it was not set the OAuth state'));
1585
+ if(!$this->GetRequestState($state))
1586
+ return false;
1587
+ if($state === $stored_state)
1588
+ {
1589
+ if($this->debug)
1590
+ $this->OutputDebug('Checking the authentication code');
1591
+ if(!$this->GetRequestCode($code))
1592
+ return false;
1593
+ if(strlen($code) == 0)
1594
+ {
1595
+ if(!$this->GetRequestError($this->authorization_error))
1596
+ return false;
1597
+ if(IsSet($this->authorization_error))
1598
+ {
1599
+ if($this->debug)
1600
+ $this->OutputDebug('Authorization failed with error code '.$this->authorization_error);
1601
+ switch($this->authorization_error)
1602
+ {
1603
+ case 'invalid_request':
1604
+ case 'unauthorized_client':
1605
+ case 'access_denied':
1606
+ case 'unsupported_response_type':
1607
+ case 'invalid_scope':
1608
+ case 'server_error':
1609
+ case 'temporarily_unavailable':
1610
+ case 'user_denied':
1611
+ return true;
1612
+ default:
1613
+ return($this->SetError('it was returned an unknown OAuth error code'));
1614
+ }
1615
+ }
1616
+ return($this->SetError('it was not returned the OAuth dialog code'));
1617
+ }
1618
+ if(!$this->GetAccessTokenURL($url))
1619
+ return false;
1620
+ if(!$this->GetRedirectURI($redirect_uri))
1621
+ return false;
1622
+ $values = array(
1623
+ 'code'=>$code,
1624
+ 'client_id'=>$this->client_id,
1625
+ 'client_secret'=>$this->client_secret,
1626
+ 'redirect_uri'=>$redirect_uri,
1627
+ 'grant_type'=>'authorization_code'
1628
+ );
1629
+ if(!$this->SendAPIRequest($url, 'POST', $values, null, array('Resource'=>'OAuth access token', 'ConvertObjects'=>true), $response))
1630
+ return false;
1631
+ if(strlen($this->access_token_error))
1632
+ {
1633
+ $this->authorization_error = $this->access_token_error;
1634
+ return true;
1635
+ }
1636
+ if(!IsSet($response['access_token']))
1637
+ {
1638
+ if(IsSet($response['error']))
1639
+ {
1640
+ $this->authorization_error = 'it was not possible to retrieve the access token: it was returned the error: '.$response['error'];
1641
+ return true;
1642
+ }
1643
+ return($this->SetError('OAuth server did not return the access token'));
1644
+ }
1645
+ $access_token = array(
1646
+ 'value'=>$this->access_token = $response['access_token'],
1647
+ 'authorized'=>true
1648
+ );
1649
+ if($this->debug)
1650
+ $this->OutputDebug('Access token: '.$this->access_token);
1651
+ if(IsSet($response['expires'])
1652
+ || IsSet($response['expires_in']))
1653
+ {
1654
+ $expires = (IsSet($response['expires']) ? $response['expires'] : $response['expires_in']);
1655
+ if(strval($expires) !== strval(intval($expires))
1656
+ || $expires <= 0)
1657
+ return($this->SetError('OAuth server did not return a supported type of access token expiry time'));
1658
+ $this->access_token_expiry = gmstrftime('%Y-%m-%d %H:%M:%S', time() + $expires);
1659
+ if($this->debug)
1660
+ $this->OutputDebug('Access token expiry: '.$this->access_token_expiry.' UTC');
1661
+ $access_token['expiry'] = $this->access_token_expiry;
1662
+ }
1663
+ else
1664
+ $this->access_token_expiry = '';
1665
+ if(IsSet($response['token_type']))
1666
+ {
1667
+ $this->access_token_type = $response['token_type'];
1668
+ if($this->debug)
1669
+ $this->OutputDebug('Access token type: '.$this->access_token_type);
1670
+ $access_token['type'] = $this->access_token_type;
1671
+ }
1672
+ else
1673
+ $this->access_token_type = '';
1674
+ if(!$this->StoreAccessToken($access_token))
1675
+ return false;
1676
+ }
1677
+ else
1678
+ {
1679
+ if(!$this->GetDialogURL($url))
1680
+ return false;
1681
+ if(strlen($url) == 0)
1682
+ return($this->SetError('it was not set the OAuth dialog URL'));
1683
+ if(!$this->GetRedirectURI($redirect_uri))
1684
+ return false;
1685
+ if(strlen($this->append_state_to_redirect_uri))
1686
+ $redirect_uri .= (strpos($redirect_uri, '?') === false ? '?' : '&').$this->append_state_to_redirect_uri.'='.$stored_state;
1687
+ $url = str_replace(
1688
+ '{REDIRECT_URI}', UrlEncode($redirect_uri), str_replace(
1689
+ '{CLIENT_ID}', UrlEncode($this->client_id), str_replace(
1690
+ '{SCOPE}', UrlEncode($this->scope), str_replace(
1691
+ '{STATE}', UrlEncode($stored_state),
1692
+ $url))));
1693
+ if($this->debug)
1694
+ $this->OutputDebug('Redirecting to OAuth Dialog '.$url);
1695
+ Header('HTTP/1.0 302 OAuth Redirection');
1696
+ Header('Location: '.$url);
1697
+ $this->exit = true;
1698
+ }
1699
+ break;
1700
+
1701
+ default:
1702
+ return($this->SetError($this->oauth_version.' is not a supported version of the OAuth protocol'));
1703
+ }
1704
+ return(true);
1705
+ }
1706
+ /*
1707
+ {metadocument}
1708
+ </do>
1709
+ </function>
1710
+ {/metadocument}
1711
+ */
1712
+
1713
+ /*
1714
+ {metadocument}
1715
+ <function>
1716
+ <name>Finalize</name>
1717
+ <type>BOOLEAN</type>
1718
+ <documentation>
1719
+ <purpose>Cleanup any resources that may have been used during the
1720
+ OAuth protocol processing or execution of API calls.</purpose>
1721
+ <usage>Always call this function as the last step after calling the
1722
+ functions <functionlink>Process</functionlink> or
1723
+ <functionlink>CallAPI</functionlink>.</usage>
1724
+ <returnvalue>This function returns <booleanvalue>1</booleanvalue> if
1725
+ the function cleaned up any resources successfully.</returnvalue>
1726
+ </documentation>
1727
+ <argument>
1728
+ <name>success</name>
1729
+ <type>BOOLEAN</type>
1730
+ <documentation>
1731
+ <purpose>Pass the last success state returned by the class or any
1732
+ external code processing the class function results.</purpose>
1733
+ </documentation>
1734
+ </argument>
1735
+ <do>
1736
+ {/metadocument}
1737
+ */
1738
+ Function Finalize($success)
1739
+ {
1740
+ return($success);
1741
+ }
1742
+ /*
1743
+ {metadocument}
1744
+ </do>
1745
+ </function>
1746
+ {/metadocument}
1747
+ */
1748
+
1749
+ /*
1750
+ {metadocument}
1751
+ <function>
1752
+ <name>Output</name>
1753
+ <type>VOID</type>
1754
+ <documentation>
1755
+ <purpose>Display the results of the OAuth protocol processing.</purpose>
1756
+ <usage>Only call this function if you are debugging the OAuth
1757
+ authorization process and you need to view what was its
1758
+ results.</usage>
1759
+ </documentation>
1760
+ <do>
1761
+ {/metadocument}
1762
+ */
1763
+ Function Output()
1764
+ {
1765
+ if(strlen($this->authorization_error)
1766
+ || strlen($this->access_token_error)
1767
+ || strlen($this->access_token))
1768
+ {
1769
+ ?>
1770
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1771
+ <html>
1772
+ <head>
1773
+ <title>OAuth client result</title>
1774
+ </head>
1775
+ <body>
1776
+ <h1>OAuth client result</h1>
1777
+ <?php
1778
+ if(strlen($this->authorization_error))
1779
+ {
1780
+ ?>
1781
+ <p>It was not possible to authorize the application.<?php
1782
+ if($this->debug)
1783
+ {
1784
+ ?>
1785
+ <br>Authorization error: <?php echo HtmlSpecialChars($this->authorization_error);
1786
+ }
1787
+ ?></p>
1788
+ <?php
1789
+ }
1790
+ elseif(strlen($this->access_token_error))
1791
+ {
1792
+ ?>
1793
+ <p>It was not possible to use the application access token.
1794
+ <?php
1795
+ if($this->debug)
1796
+ {
1797
+ ?>
1798
+ <br>Error: <?php echo HtmlSpecialChars($this->access_token_error);
1799
+ }
1800
+ ?></p>
1801
+ <?php
1802
+ }
1803
+ elseif(strlen($this->access_token))
1804
+ {
1805
+ ?>
1806
+ <p>The application authorization was obtained successfully.
1807
+ <?php
1808
+ if($this->debug)
1809
+ {
1810
+ ?>
1811
+ <br>Access token: <?php echo HtmlSpecialChars($this->access_token);
1812
+ if(IsSet($this->access_token_secret))
1813
+ {
1814
+ ?>
1815
+ <br>Access token secret: <?php echo HtmlSpecialChars($this->access_token_secret);
1816
+ }
1817
+ }
1818
+ ?></p>
1819
+ <?php
1820
+ if(strlen($this->access_token_expiry))
1821
+ {
1822
+ ?>
1823
+ <p>Access token expiry: <?php echo $this->access_token_expiry; ?> UTC</p>
1824
+ <?php
1825
+ }
1826
+ }
1827
+ ?>
1828
+ </body>
1829
+ </html>
1830
+ <?php
1831
+ }
1832
+ }
1833
+ /*
1834
+ {metadocument}
1835
+ </do>
1836
+ </function>
1837
+ {/metadocument}
1838
+ */
1839
+
1840
+ };
1841
+
1842
+ /*
1843
+
1844
+ {metadocument}
1845
+ </class>
1846
+ {/metadocument}
1847
+
1848
+ */
1849
+
1850
+ ?>
app/code/local/Soclever/{Sociallogin → Socialloginsc}/controllers/openid.php RENAMED
File without changes
app/code/local/Soclever/{Sociallogin → Socialloginsc}/etc/config.xml RENAMED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
- * Soclever SocialLogin Extension
5
  *
6
  * @category Extension
7
  * @copyright Copyright (c) 2014 Soclever (https://www.socleversocial.com)
@@ -15,47 +15,47 @@
15
 
16
  <config>
17
  <modules>
18
- <Soclever_Sociallogin>
19
  <version>1.1.1</version>
20
- </Soclever_Sociallogin>
21
  </modules>
22
  <default>
23
- <sociallogin_options>
24
  <displaysettings>
25
  <buttonstyle>ic</buttonstyle>
26
- <socialloginboxcaption>Login With:</socialloginboxcaption>
27
  </displaysettings>
28
- </sociallogin_options>
29
  </default>
30
 
31
  <frontend>
32
  <routers>
33
- <soclever_sociallogin>
34
  <use>standard</use>
35
  <args>
36
- <module>Soclever_Sociallogin</module>
37
- <frontName>soclever_sociallogin</frontName>
38
  </args>
39
- </soclever_sociallogin>
40
 
41
  </routers>
42
  <layout>
43
  <updates>
44
- <Soclever_Sociallogin>
45
- <file>sociallogin.xml</file>
46
- </Soclever_Sociallogin>
47
  </updates>
48
  </layout>
49
  </frontend>
50
  <admin>
51
  <routers>
52
- <sociallogin>
53
  <use>admin</use>
54
  <args>
55
- <module>Soclever_Sociallogin</module>
56
- <frontName>Sociallogin admin</frontName>
57
  </args>
58
- </sociallogin>
59
  </routers>
60
  </admin>
61
  <adminhtml>
@@ -67,9 +67,9 @@
67
  <children>
68
  <config>
69
  <children>
70
- <sociallogin_options>
71
  <title>Store Social Login Module Section</title>
72
- </sociallogin_options>
73
  </children>
74
  </config>
75
  </children>
@@ -81,50 +81,50 @@
81
  </adminhtml>
82
  <global>
83
  <models>
84
- <sociallogin>
85
- <class>Soclever_Sociallogin_Model</class>
86
- </sociallogin>
87
  </models>
88
  <resources>
89
- <soclever_sociallogin_setup>
90
  <setup>
91
- <module>Soclever_Sociallogin</module>
92
  </setup>
93
  <connection>
94
  <use>core_setup</use>
95
  </connection>
96
- </soclever_sociallogin_setup>
97
- <soclever_sociallogin_write>
98
  <connection>
99
  <use>core_write</use>
100
  </connection>
101
- </soclever_sociallogin_write>
102
- <soclever_sociallogin_read>
103
  <connection>
104
  <use>core_read</use>
105
  </connection>
106
- </soclever_sociallogin_read>
107
  </resources>
108
  <blocks>
109
- <sociallogin>
110
- <class>Soclever_Sociallogin_Block</class>
111
- </sociallogin>
112
  </blocks>
113
  <helpers>
114
- <sociallogin>
115
- <class>Soclever_Sociallogin_Helper</class>
116
- </sociallogin>
117
  </helpers>
118
  <events>
119
- <admin_system_config_changed_section_sociallogin_options>
120
  <observers>
121
  <myobserver>
122
  <type>singleton</type>
123
- <class>sociallogin/observer</class>
124
  <method>writejs</method>
125
  </myobserver>
126
  </observers>
127
- </admin_system_config_changed_section_sociallogin_options>
128
  </events>
129
  </global>
130
  </config>
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
+ * Soclever Socialloginsc Extension
5
  *
6
  * @category Extension
7
  * @copyright Copyright (c) 2014 Soclever (https://www.socleversocial.com)
15
 
16
  <config>
17
  <modules>
18
+ <Soclever_Socialloginsc>
19
  <version>1.1.1</version>
20
+ </Soclever_Socialloginsc>
21
  </modules>
22
  <default>
23
+ <socialloginsc_options>
24
  <displaysettings>
25
  <buttonstyle>ic</buttonstyle>
26
+ <socialloginscboxcaption>Login With:</socialloginscboxcaption>
27
  </displaysettings>
28
+ </socialloginsc_options>
29
  </default>
30
 
31
  <frontend>
32
  <routers>
33
+ <soclever_socialloginsc>
34
  <use>standard</use>
35
  <args>
36
+ <module>Soclever_Socialloginsc</module>
37
+ <frontName>soclever_socialloginsc</frontName>
38
  </args>
39
+ </soclever_socialloginsc>
40
 
41
  </routers>
42
  <layout>
43
  <updates>
44
+ <Soclever_Socialloginsc>
45
+ <file>socialloginsc.xml</file>
46
+ </Soclever_Socialloginsc>
47
  </updates>
48
  </layout>
49
  </frontend>
50
  <admin>
51
  <routers>
52
+ <socialloginsc>
53
  <use>admin</use>
54
  <args>
55
+ <module>Soclever_Socialloginsc</module>
56
+ <frontName>Socialloginsc admin</frontName>
57
  </args>
58
+ </socialloginsc>
59
  </routers>
60
  </admin>
61
  <adminhtml>
67
  <children>
68
  <config>
69
  <children>
70
+ <socialloginsc_options>
71
  <title>Store Social Login Module Section</title>
72
+ </socialloginsc_options>
73
  </children>
74
  </config>
75
  </children>
81
  </adminhtml>
82
  <global>
83
  <models>
84
+ <socialloginsc>
85
+ <class>Soclever_Socialloginsc_Model</class>
86
+ </socialloginsc>
87
  </models>
88
  <resources>
89
+ <soclever_socialloginsc_setup>
90
  <setup>
91
+ <module>Soclever_Socialloginsc</module>
92
  </setup>
93
  <connection>
94
  <use>core_setup</use>
95
  </connection>
96
+ </soclever_socialloginsc_setup>
97
+ <soclever_socialloginsc_write>
98
  <connection>
99
  <use>core_write</use>
100
  </connection>
101
+ </soclever_socialloginsc_write>
102
+ <soclever_socialloginsc_read>
103
  <connection>
104
  <use>core_read</use>
105
  </connection>
106
+ </soclever_socialloginsc_read>
107
  </resources>
108
  <blocks>
109
+ <socialloginsc>
110
+ <class>Soclever_Socialloginsc_Block</class>
111
+ </socialloginsc>
112
  </blocks>
113
  <helpers>
114
+ <socialloginsc>
115
+ <class>Soclever_Socialloginsc_Helper</class>
116
+ </socialloginsc>
117
  </helpers>
118
  <events>
119
+ <admin_system_config_changed_section_socialloginsc_options>
120
  <observers>
121
  <myobserver>
122
  <type>singleton</type>
123
+ <class>socialloginsc/observer</class>
124
  <method>writejs</method>
125
  </myobserver>
126
  </observers>
127
+ </admin_system_config_changed_section_socialloginsc_options>
128
  </events>
129
  </global>
130
  </config>
app/code/local/Soclever/{Sociallogin → Socialloginsc}/etc/system.xml RENAMED
@@ -1,15 +1,15 @@
1
  <?xml version="1.0"?>
2
  <config>
3
  <tabs>
4
- <socialloginsetting translate="label" module="sociallogin">
5
  <label>Soclever Social Login</label>
6
  <sort_order>3</sort_order>
7
- </socialloginsetting>
8
  </tabs>
9
  <sections>
10
- <sociallogin_options translate="label" module="sociallogin">
11
  <label>SoClever Social Login</label>
12
- <tab>socialloginsetting</tab>
13
  <frontend_type>text</frontend_type>
14
  <sort_order>1020</sort_order>
15
  <show_in_default>1</show_in_default>
@@ -17,7 +17,7 @@
17
  <show_in_store>1</show_in_store>
18
  <groups>
19
  <info translate="label">
20
- <frontend_model>Soclever_Sociallogin_Model_Info</frontend_model>
21
  <comment><![CDATA[]]></comment>
22
  <sort_order>1</sort_order>
23
  <show_in_default>1</show_in_default>
@@ -81,7 +81,7 @@
81
  <buttonstyle translate="label">
82
  <label>Select Button Style</label>
83
  <frontend_type>select</frontend_type>
84
- <source_model>sociallogin/providers::getbuttonstyles</source_model>
85
  <sort_order>200</sort_order>
86
  <show_in_default>1</show_in_default>
87
  <show_in_website>1</show_in_website>
@@ -90,22 +90,22 @@
90
  <buttonsize translate="label">
91
  <label>Button Size</label>
92
  <frontend_type>select</frontend_type>
93
- <source_model>sociallogin/providers::getsizes</source_model>
94
  <sort_order>199</sort_order>
95
  <show_in_default>1</show_in_default>
96
  <show_in_website>1</show_in_website>
97
  <show_in_store>1</show_in_store>
98
  </buttonsize>
99
- <socialloginproviders translate="label">
100
  <label>Select Providers</label>
101
  <frontend_type>multiselect</frontend_type>
102
- <source_model>sociallogin/providers::getloginproviders</source_model>
103
  <sort_order>201</sort_order>
104
  <show_in_default>1</show_in_default>
105
  <show_in_website>1</show_in_website>
106
  <show_in_store>1</show_in_store>
107
- </socialloginproviders>
108
- <socialloginboxcaption translate="label">
109
  <label>Login Box Caption</label>
110
  <frontend_type>text</frontend_type>
111
  <comment><![CDATA[Text to display on social login box i.e Social Login By]]></comment>
@@ -113,20 +113,29 @@
113
  <show_in_default>1</show_in_default>
114
  <show_in_website>1</show_in_website>
115
  <show_in_store>1</show_in_store>
116
- </socialloginboxcaption>
117
- <socialloginpowerby translate="label">
118
  <label>Show Powered by SoClever</label>
119
  <frontend_type>select</frontend_type>
120
- <source_model>sociallogin/providers::showpoweredby</source_model>
121
  <comment><![CDATA[At the bottom of login box will show "Powered By Socleversocial.com"]]></comment>
122
  <sort_order>202</sort_order>
123
  <show_in_default>1</show_in_default>
124
  <show_in_website>1</show_in_website>
125
  <show_in_store>1</show_in_store>
126
- </socialloginpowerby>
 
 
 
 
 
 
 
 
 
127
  </fields>
128
  </displaysettings>
129
  </groups>
130
- </sociallogin_options>
131
  </sections>
132
  </config>
1
  <?xml version="1.0"?>
2
  <config>
3
  <tabs>
4
+ <socialloginscsetting translate="label" module="socialloginsc">
5
  <label>Soclever Social Login</label>
6
  <sort_order>3</sort_order>
7
+ </socialloginscsetting>
8
  </tabs>
9
  <sections>
10
+ <socialloginsc_options translate="label" module="socialloginsc">
11
  <label>SoClever Social Login</label>
12
+ <tab>socialloginscsetting</tab>
13
  <frontend_type>text</frontend_type>
14
  <sort_order>1020</sort_order>
15
  <show_in_default>1</show_in_default>
17
  <show_in_store>1</show_in_store>
18
  <groups>
19
  <info translate="label">
20
+ <frontend_model>Soclever_Socialloginsc_Model_Info</frontend_model>
21
  <comment><![CDATA[]]></comment>
22
  <sort_order>1</sort_order>
23
  <show_in_default>1</show_in_default>
81
  <buttonstyle translate="label">
82
  <label>Select Button Style</label>
83
  <frontend_type>select</frontend_type>
84
+ <source_model>socialloginsc/providers::getbuttonstyles</source_model>
85
  <sort_order>200</sort_order>
86
  <show_in_default>1</show_in_default>
87
  <show_in_website>1</show_in_website>
90
  <buttonsize translate="label">
91
  <label>Button Size</label>
92
  <frontend_type>select</frontend_type>
93
+ <source_model>socialloginsc/providers::getsizes</source_model>
94
  <sort_order>199</sort_order>
95
  <show_in_default>1</show_in_default>
96
  <show_in_website>1</show_in_website>
97
  <show_in_store>1</show_in_store>
98
  </buttonsize>
99
+ <socialloginscproviders translate="label">
100
  <label>Select Providers</label>
101
  <frontend_type>multiselect</frontend_type>
102
+ <source_model>socialloginsc/providers::getloginproviders</source_model>
103
  <sort_order>201</sort_order>
104
  <show_in_default>1</show_in_default>
105
  <show_in_website>1</show_in_website>
106
  <show_in_store>1</show_in_store>
107
+ </socialloginscproviders>
108
+ <socialloginscboxcaption translate="label">
109
  <label>Login Box Caption</label>
110
  <frontend_type>text</frontend_type>
111
  <comment><![CDATA[Text to display on social login box i.e Social Login By]]></comment>
113
  <show_in_default>1</show_in_default>
114
  <show_in_website>1</show_in_website>
115
  <show_in_store>1</show_in_store>
116
+ </socialloginscboxcaption>
117
+ <socialloginscpowerby translate="label">
118
  <label>Show Powered by SoClever</label>
119
  <frontend_type>select</frontend_type>
120
+ <source_model>socialloginsc/providers::showpoweredby</source_model>
121
  <comment><![CDATA[At the bottom of login box will show "Powered By Socleversocial.com"]]></comment>
122
  <sort_order>202</sort_order>
123
  <show_in_default>1</show_in_default>
124
  <show_in_website>1</show_in_website>
125
  <show_in_store>1</show_in_store>
126
+ </socialloginscpowerby>
127
+ <socialloginregemail translate="label">
128
+ <label>Send welcome email?</label>
129
+ <frontend_type>select</frontend_type>
130
+ <source_model>adminhtml/system_config_source_yesno</source_model>
131
+ <sort_order>203</sort_order>
132
+ <show_in_default>1</show_in_default>
133
+ <show_in_website>1</show_in_website>
134
+ <show_in_store>1</show_in_store>
135
+ </socialloginregemail>
136
  </fields>
137
  </displaysettings>
138
  </groups>
139
+ </socialloginsc_options>
140
  </sections>
141
  </config>
app/design/frontend/base/default/layout/sociallogin.xml DELETED
@@ -1,28 +0,0 @@
1
- <?xml version="1.0"?>
2
- <layout version="1.0.0">
3
- <default>
4
- <reference name="head">
5
- <block type="sociallogin/scslhead" name="sociallogin_head" template="sociallogin/sociallogin_head.phtml" />
6
- <block type="sociallogin/scslheadfb" name="sociallogin_headfb" template="sociallogin/sociallogin_fb.phtml" />
7
- </reference>
8
- </default>
9
- <checkout_onepage_index>
10
- <reference name="checkout.onepage.login.before">
11
- <block type="sociallogin/scslshow" before="-" name="sociallogin_show">
12
-
13
- </block>
14
- </reference>
15
- </checkout_onepage_index>
16
- <customer_account_login>
17
- <reference name="content">
18
- <block type="sociallogin/scslshow" before="-" name="sociallogin_show">
19
-
20
- </block>
21
- </reference>
22
- </customer_account_login>
23
- <checkout_onepage_success>
24
- <reference name="content">
25
- <block type="sociallogin/scsltrackpixel" name="sociallogin_trackpixel" template="sociallogin/sociallogin_trackpixel.phtml" />
26
- </reference>
27
- </checkout_onepage_success>
28
- </layout>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/frontend/base/default/layout/socialloginsc.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="1.0.0">
3
+ <default>
4
+ <reference name="head">
5
+ <block type="socialloginsc/scslhead" name="socialloginsc_head" template="socialloginsc/socialloginsc_head.phtml" />
6
+ <block type="socialloginsc/scslheadfb" name="socialloginsc_headfb" template="socialloginsc/socialloginsc_fb.phtml" />
7
+ </reference>
8
+ </default>
9
+ <checkout_onepage_index>
10
+ <reference name="checkout.onepage.login.before">
11
+ <block type="socialloginsc/scslshow" before="-" name="socialloginsc_show">
12
+
13
+ </block>
14
+ </reference>
15
+ </checkout_onepage_index>
16
+ <customer_account_login>
17
+ <reference name="content">
18
+ <block type="socialloginsc/scslshow" before="-" name="socialloginsc_show">
19
+
20
+ </block>
21
+ </reference>
22
+ </customer_account_login>
23
+ <checkout_onepage_success>
24
+ <reference name="content">
25
+ <block type="socialloginsc/scsltrackpixel" name="socialloginsc_trackpixel" template="socialloginsc/socialloginsc_trackpixel.phtml" />
26
+ </reference>
27
+ </checkout_onepage_success>
28
+ </layout>
app/design/frontend/base/default/template/sociallogin/scsl_buttons.phtml DELETED
@@ -1,38 +0,0 @@
1
- <?php
2
- $site_id=Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid');
3
- $api_secret=Mage::getStoreConfig('sociallogin_options/apisettings/scsl_appsecret');
4
- $api_key=Mage::getStoreConfig('sociallogin_options/apisettings/scsl_appid');
5
- $btn_style=Mage::getStoreConfig('sociallogin_options/displaysettings/buttonstyle');
6
- $button_size=Mage::getStoreConfig('sociallogin_options/displaysettings/buttonsize');
7
- $loginboxcaption=Mage::getStoreConfig('sociallogin_options/displaysettings/socialloginboxcaption');
8
- $showpoweredby=Mage::getStoreConfig('sociallogin_options/displaysettings/socialloginpowerby');
9
-
10
- $is_validated=Mage::getStoreConfig('sociallogin_options/apisettings/scsl_validated');
11
-
12
- $selected_providers=Mage::getStoreConfig('sociallogin_options/displaysettings/socialloginproviders');
13
-
14
- if($is_validated=='1' && $selected_providers!='' && $selected_providers!='0')
15
- {
16
-
17
- $valid_data=file_get_contents("https://www.socleversocial.com/dashboard/mage_login_buttons.php?login_only=1&site_id=".$site_id."&api_key=".$api_key."&api_secret=".$api_secret."&csplatform=magentologin&rt=gp&bcaption=".base64_encode($loginboxcaption)."&bshow=".$showpoweredby."&bstyle=".$btn_style."&bsize=".$button_size."&providers=".$selected_providers);
18
-
19
- if($valid_data && $valid_data!='0~~0')
20
- {
21
- echo $valid_data;
22
- }
23
- else
24
- {
25
- echo"";
26
- }
27
- }
28
- echo"";
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/frontend/base/default/template/sociallogin/sociallogin_trackpixel.phtml DELETED
@@ -1,13 +0,0 @@
1
- <?php
2
- $is_validated=Mage::getStoreConfig('sociallogin_options/apisettings/scsl_validated');
3
- if($is_validated=='1')
4
- {
5
- $CsorderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
6
- $Csorder = Mage::getModel('sales/order')->loadByIncrementId($CsorderId);
7
-
8
- $sessionVariable = Mage::getSingleton('core/session')->getSessionVariable();
9
-
10
- echo"<img src='https://www.socleversocial.com/dashboard/trackPixel.php?site_id=".Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid')."&order_id=".$CsorderId."&ord_amt=".$Csorder->getGrandTotal()."&ord_cur=".$Csorder->base_currency_code."&siteUid=".$Csorder->customer_id."&is_from=".$sessionVariable."' />";
11
-
12
- }
13
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/frontend/base/default/template/socialloginsc/scsl_buttons.phtml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $site_id=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid');
3
+ $api_secret=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_appsecret');
4
+ $api_key=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_appid');
5
+ $btn_style=Mage::getStoreConfig('socialloginsc_options/displaysettings/buttonstyle');
6
+ $button_size=Mage::getStoreConfig('socialloginsc_options/displaysettings/buttonsize');
7
+ $loginboxcaption=Mage::getStoreConfig('socialloginsc_options/displaysettings/socialloginscboxcaption');
8
+ $showpoweredby=Mage::getStoreConfig('socialloginsc_options/displaysettings/socialloginscpowerby');
9
+
10
+ $is_validated=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_validated');
11
+
12
+ $selected_providers=Mage::getStoreConfig('socialloginsc_options/displaysettings/socialloginscproviders');
13
+
14
+ if($is_validated=='1' && $selected_providers!='' && $selected_providers!='0')
15
+ {
16
+
17
+ $valid_data=file_get_contents("https://www.socleversocial.com/dashboard/mage_login_buttons.php?login_only=2&site_id=".$site_id."&api_key=".$api_key."&api_secret=".$api_secret."&csplatform=magentologin&rt=gp&bcaption=".base64_encode($loginboxcaption)."&bshow=".$showpoweredby."&bstyle=".$btn_style."&bsize=".$button_size."&providers=".$selected_providers);
18
+
19
+ if($valid_data && $valid_data!='0~~0')
20
+ {
21
+ echo $valid_data;
22
+ }
23
+ else
24
+ {
25
+ echo"";
26
+ }
27
+ }
28
+ echo"";
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+ ?>
39
+
40
+
41
+
42
+
43
+
44
+ <script type="text/javascript">
45
+ function popupCenter(url) {
46
+ var title='Login with twitter';
47
+ var w=600;
48
+ var h=436;
49
+ var left = (screen.width/2)-(w/2);
50
+ var top = (screen.height/2)-(h/2);
51
+ return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
52
+ }
53
+ function showPopup(url){
54
+ win = new Window({ title: "Login With Twitter", url:url, zIndex:3000, destroyOnClose: true, recenterAuto:false, resizable: false, width:450, height:473, minimizable: false, maximizable: false, draggable: false});
55
+ win.showCenter(true);
56
+ }
57
+ </script>
app/design/frontend/base/default/template/{sociallogin → socialloginsc}/sociallogin_fb.phtml RENAMED
File without changes
app/design/frontend/base/default/template/{sociallogin → socialloginsc}/sociallogin_head.phtml RENAMED
@@ -1,12 +1,12 @@
1
  <?php
2
- $is_validated=Mage::getStoreConfig('sociallogin_options/apisettings/scsl_validated');
3
  if($is_validated=='1')
4
  {
5
  if(!Mage::getSingleton('customer/session')->isLoggedIn())
6
  {
7
- echo'<script type="text/javascript" src="https://www.socleversocial.com/dashboard/client_share_js/client_'.Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid').'_onlylogin.js"></script>'.PHP_EOL.
8
  '<script type="text/javascript">'.PHP_EOL.
9
- 'csloginjs.init([\''.Mage::getStoreConfig('sociallogin_options/apisettings/scsl_appid').'\', \''.Mage::getStoreConfig('sociallogin_options/apisettings/scsl_siteid').'\',\''.Mage::getStoreConfig('sociallogin_options/apisettings/scsl_appsecret').'\',\''.Mage::getStoreConfig('sociallogin_options/apisettings/scsl_validdomain').'\']);'.PHP_EOL.
10
  'csloginjs.validateCsApi();'.PHP_EOL.
11
  '</script>'.PHP_EOL;
12
 
1
  <?php
2
+ $is_validated=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_validated');
3
  if($is_validated=='1')
4
  {
5
  if(!Mage::getSingleton('customer/session')->isLoggedIn())
6
  {
7
+ echo'<script type="text/javascript" src="https://www.socleversocial.com/dashboard/client_share_js/client_'.Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid').'_onlylogin.js"></script>'.PHP_EOL.
8
  '<script type="text/javascript">'.PHP_EOL.
9
+ 'csloginjs.init([\''.Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_appid').'\', \''.Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid').'\',\''.Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_appsecret').'\',\''.Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_validdomain').'\']);'.PHP_EOL.
10
  'csloginjs.validateCsApi();'.PHP_EOL.
11
  '</script>'.PHP_EOL;
12
 
app/design/frontend/base/default/template/socialloginsc/sociallogin_trackpixel.phtml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $is_validated=Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_validated');
3
+ if($is_validated=='1')
4
+ {
5
+ $CsorderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
6
+ $Csorder = Mage::getModel('sales/order')->loadByIncrementId($CsorderId);
7
+
8
+ $sessionVariable = Mage::getSingleton('core/session')->getSessionVariable();
9
+
10
+ echo"<img src='https://www.socleversocial.com/dashboard/trackPixel.php?site_id=".Mage::getStoreConfig('socialloginsc_options/apisettings/scsl_siteid')."&order_id=".$CsorderId."&ord_amt=".$Csorder->getGrandTotal()."&ord_cur=".$Csorder->base_currency_code."&siteUid=".$Csorder->customer_id."&is_from=".$sessionVariable."' />";
11
+
12
+ }
13
+ ?>
app/etc/modules/{soclever_sociallogin.xml → soclever_socialloginsc.xml} RENAMED
@@ -1,9 +1,9 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <config>
3
  <modules>
4
- <Soclever_Sociallogin>
5
  <active>true</active>
6
  <codePool>local</codePool>
7
- </Soclever_Sociallogin>
8
  </modules>
9
  </config>
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <config>
3
  <modules>
4
+ <Soclever_Socialloginsc>
5
  <active>true</active>
6
  <codePool>local</codePool>
7
+ </Soclever_Socialloginsc>
8
  </modules>
9
  </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>soclever_login</name>
4
- <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
@@ -28,11 +28,11 @@
28
  Send personalised message to your visitors by using our birthday reports. &lt;/p&gt;&#xD;
29
  &lt;p&gt;&lt;strong&gt;Dynamic JavaScript&lt;/strong&gt;&lt;br /&gt;&#xD;
30
  Our asynchronous javascript loads faster without interfearing with the display or behaviour of the page. Dynamic JavaScript makes it easy to choose/sort social netork buttons for display.&lt;/p&gt;</description>
31
- <notes>Stable Version 1.1.0 - UX and UI Improvement</notes>
32
  <authors><author><name>Soclever Social</name><user>Socleversocial</user><email>hemang@socleversocial.com</email></author></authors>
33
- <date>2015-02-27</date>
34
- <time>06:40:14</time>
35
- <contents><target name="magelocal"><dir name="Soclever"><dir name="Sociallogin"><dir name="Block"><dir name="Adminhtml"><file name="Help.php" hash=""/><file name="Positions.php" hash=""/></dir><file name="Scslhead.php" hash="19915d8ad186673c4e068abcd2f700d8"/><file name="Scslshow.php" hash="3e868132953b63c93af6cb7b396b095a"/><file name="Scsltrackpixel.php" hash="865c3da829f0dc1cd384fb113e771c34"/><file name="Scslheadfb.php" hash="01f8e5fca1e7a59dcc7009a9d79d31f5"/><file name="Help.php" hash="215af72ed8f481563444f00b30fd39ca"/></dir><dir name="controllers"><file name="IndexController.php" hash="da5bc5c2e4abb2f238d6e544a66dc75f"/><file name="openid.php" hash="421d5936957b8ddda543b679d1876f04"/></dir><dir name="etc"><file name="config.xml" hash="6df38e3cbf3f83160f9bc95c4aca7156"/><file name="system.xml" hash="05a790199e16e6be233805eafd62c116"/></dir><dir name="Helper"><file name="Data.php" hash="89f8191f1442a7e56f7a4d0b54049d3a"/></dir><dir name="Model"><file name="Providers.php" hash="0c0d062acfd7730f739856ae045db6ff"/><file name="Info.php" hash="d1d93f2bc9861955c1a3027f6b56addd"/><file name="Observer.php" hash="b55f31f318d8be06c9e27d5220483f13"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="sociallogin.xml" hash="444082a425071b527e955ecd0ebedce8"/></dir><dir name="template"><dir name="sociallogin"><file name="scsl_buttons.phtml" hash="f782950bdd5e10911aa3c4ca50502fa8"/><file name="sociallogin_head.phtml" hash="bea2af51090eb0c1a5d0f8d7921aa81f"/><file name="sociallogin_fb.phtml" hash="718d8596a14d123d83afb0d5d6d6fd96"/><file name="sociallogin_trackpixel.phtml" hash="40ff5c12d2c4b3ba41c86695bd4a04c3"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="soclever_sociallogin.xml" hash="8f1fa6f55fc92b4474f696f3678c0281"/></dir></target></contents>
36
  <compatible/>
37
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
38
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>soclever_login</name>
4
+ <version>1.1.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
28
  Send personalised message to your visitors by using our birthday reports. &lt;/p&gt;&#xD;
29
  &lt;p&gt;&lt;strong&gt;Dynamic JavaScript&lt;/strong&gt;&lt;br /&gt;&#xD;
30
  Our asynchronous javascript loads faster without interfearing with the display or behaviour of the page. Dynamic JavaScript makes it easy to choose/sort social netork buttons for display.&lt;/p&gt;</description>
31
+ <notes>Stable Version 1.1.1 - Option to send welcome email</notes>
32
  <authors><author><name>Soclever Social</name><user>Socleversocial</user><email>hemang@socleversocial.com</email></author></authors>
33
+ <date>2015-03-13</date>
34
+ <time>09:12:41</time>
35
+ <contents><target name="magelocal"><dir name="Soclever"><dir name="Socialloginsc"><dir name="Block"><file name="Help.php" hash="f1b78eeb8572b294f147100852341b66"/><file name="Scslhead.php" hash="f160bb1f3bf06ac3d5529bccbf3eaeb1"/><file name="Scslhead.php" hash="f160bb1f3bf06ac3d5529bccbf3eaeb1"/><file name="Scslshow.php" hash="c24f579bd6899fda1b4dfbb745c96f4b"/></dir><dir name="controllers"><file name="IndexController.php" hash="ab66bc3566eb0db768f4373d5191d67e"/><file name="openid.php" hash="421d5936957b8ddda543b679d1876f04"/><file name="http.php" hash="1fe6b6ac5002ed03f3bb5e7f623b8682"/><file name="oauth_client.php" hash="c8b0e317336ba0dce0fee2e384987785"/></dir><dir name="etc"><file name="config.xml" hash="cb074a4803cd4bc99dc8cf6f9496c165"/><file name="system.xml" hash="e3c312194adbf4c6bc23045840812cbe"/></dir><dir name="Helper"><file name="Data.php" hash="ffe3beab121640dedd47db758a93fdaf"/></dir><dir name="Model"><file name="Providers.php" hash="c5398c99a67640139432b902c4ee54e5"/><file name="Info.php" hash="f25ff6c3c2b37b66cd49799bc3a5caab"/><file name="Observer.php" hash="6e0bf76cda07e33fd7b0fc59480d6c8a"/></dir></dir><dir name="Sociallogin"><dir name="Block"><file name="Scsltrackpixel.php" hash=""/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="socialloginsc.xml" hash="bf0ee0b3afbbc868e2ec66e33cccca67"/></dir><dir name="template"><dir name="socialloginsc"><file name="scsl_buttons.phtml" hash="8de79bcfad3686c5685636ade252d3b2"/><file name="sociallogin_head.phtml" hash="8176f3c9c6bfe49db0d51e5f448167be"/><file name="sociallogin_fb.phtml" hash="718d8596a14d123d83afb0d5d6d6fd96"/><file name="sociallogin_trackpixel.phtml" hash="4ec45f934b23b5e1961e409530d51672"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="soclever_socialloginsc.xml" hash="4bc33a8062ab5eabf3f3edf1e474c400"/></dir></target></contents>
36
  <compatible/>
37
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
38
  </package>