Advertisement
Guest User

Untitled

a guest
Feb 12th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.45 KB | None | 0 0
  1. <?php
  2. /**
  3.  
  4. * Plugin Name: Social Login Lite For WooCommerce
  5. * Plugin URI: http://www.phoeniixx.com/
  6. * Description: Social Login plugin allows you to let customers associate their social (Facebook and Google+) profiles with your ecommerce site.
  7. * Version: 1.4.6
  8. * Author: phoeniixx
  9. * Text Domain: phoen_social_login
  10. * Domain Path: /languages
  11. * Author URI: http://www.phoeniixx.com/
  12. * License: GPLv2 or later
  13. * License URI: http://www.gnu.org/licenses/gpl-2.0.html
  14.  
  15. **/
  16.  
  17. ob_start();
  18.  
  19. if ( ! defined( 'ABSPATH' ) ) {
  20. exit; // Exit if accessed directly
  21. }
  22.  
  23. if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
  24.  
  25. session_start();
  26. // Put your plugin code here
  27. require_once('social_login_settings.php');
  28. require_once('my_account_login_hook.php');
  29. require_once('my_account_register_hook.php');
  30. require_once('login_page_hook.php');
  31. include_once('checkout_page_hook.php');
  32.  
  33. add_action('admin_enqueue_scripts', 'updimg_scripts');
  34.  
  35. function updimg_scripts()
  36. {
  37.  
  38. if (isset($_GET['page']) && $_GET['page'] == 'psl-social-login')
  39. {
  40.  
  41. wp_enqueue_media();
  42.  
  43. }
  44. }
  45.  
  46. register_activation_hook(__FILE__, 'psl_plugin_activation');
  47.  
  48. function psl_plugin_activation() {
  49.  
  50. update_option( 'psl_enable_plugin', 1 );
  51.  
  52. $social_setting=array('facebook_details'=>array('enable_facebook'=> '' ,'facebook_id'=> '','fb_icon_url'=> ''),'google_plus_details'=>array('enable_google_plus'=> '','google_id'=> '','google_api'=> '','google_icon_url'=> ''),'change_text_details'=>array('sign_in'=> '','sign_up'=> ''),'change_text_details'=>array('login_label'=> '','checkout_label'=> ''));
  53.  
  54. update_option('psl_social_plugin', $social_setting);
  55.  
  56. }
  57.  
  58. register_deactivation_hook(__FILE__, 'psl_plugin_deactivation');
  59.  
  60. function psl_plugin_deactivation() {
  61.  
  62. update_option( 'psl_enable_plugin', 0 );
  63.  
  64. }
  65.  
  66. add_action('wp_head', 'social_login_lite_head');
  67.  
  68. add_action('admin_head', 'social_login_lite_head');
  69.  
  70. function social_login_lite_head()
  71. {
  72. ?>
  73. <style>
  74.  
  75. .login-txt {
  76. margin: 4px 0 0 4px;
  77. }
  78.  
  79. #logo-link {
  80. margin: 8px 3px;
  81. max-height: 50px;
  82. }
  83.  
  84. .form-row.form-row-first.login-checkout {
  85. float: none;
  86. text-align: center;
  87. width: 100%;
  88. }
  89.  
  90. .phoenixx_promt_msg{
  91. border-left-color: #46b450;
  92. background: #fff none repeat scroll 0 0;
  93. border-left: 4px solid #46b450;
  94. box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
  95. margin: 5px 0px 2px;
  96. padding: 1px 12px;
  97. }
  98.  
  99. </style>
  100.  
  101. <div id="fb-root"></div>
  102.  
  103. <script>
  104.  
  105. <?php
  106.  
  107. $setting_data=get_option('psl_social_plugin');
  108.  
  109. extract($setting_data['facebook_details']);
  110.  
  111. ?>
  112.  
  113. window.fbAsyncInit = function() {
  114.  
  115. FB.init({
  116.  
  117. appId : '<?php echo $facebook_id;?>', // Set YOUR APP ID
  118. status : true, // check login status
  119. cookie : true, // enable cookies to allow the server to access the session
  120. xfbml : true // parse XFBML
  121.  
  122. });
  123.  
  124. FB.getLoginStatus( function(response) {
  125.  
  126. console.log(response);
  127.  
  128. }, true);
  129.  
  130. };
  131.  
  132.  
  133. function facebook_login(){
  134.  
  135. FB.login(function(response) {
  136.  
  137. if (response.authResponse)
  138. {
  139. getUserInfo();
  140. }
  141. else
  142. {
  143. console.log('User cancelled login or did not fully authorize.');
  144. }
  145.  
  146. },{auth_type: 'rerequest',scope: 'email,user_photos,user_videos'});
  147.  
  148. }
  149.  
  150. function getUserInfo() {
  151.  
  152. FB.api('/me?fields=email,first_name,last_name,name', function(response) {
  153.  
  154. response.email=jQuery.trim(response.email);
  155.  
  156. if(response.email!='')
  157. {
  158.  
  159. var str=response.name;
  160.  
  161. str +="*"+response.email;
  162. str += "*" + "face";
  163. str += "*" + getPhoto();
  164.  
  165. var data = {
  166.  
  167. 'action': 'psl_data_retrive',
  168.  
  169. 'data': str // We pass php values differently!
  170.  
  171. };
  172. }
  173. else
  174. {
  175.  
  176. alert("NO Email is provided");
  177.  
  178. }
  179.  
  180. // We can also pass the url value separately from ajaxurl for front end AJAX implementations
  181.  
  182. jQuery.post('<?php echo site_url();?>/wp-admin/admin-ajax.php', data, function(response,status) {
  183.  
  184. if(response=='success')
  185. {
  186.  
  187. fb_login=<?php echo get_option('psl_fb_login');?>
  188.  
  189. <?php
  190.  
  191. if( is_checkout() ){
  192.  
  193. ?>
  194.  
  195. window.location.href = "<?php echo $_SERVER['REQUEST_URI']; ?>";
  196.  
  197. <?php
  198.  
  199. }
  200. else
  201. {
  202. ?>
  203.  
  204. window.location.href = "<?php echo site_url();?>/";
  205.  
  206. <?php
  207. }
  208.  
  209. ?>
  210.  
  211.  
  212. }
  213.  
  214. });
  215.  
  216. });
  217.  
  218. }
  219.  
  220. function getPhoto(){
  221.  
  222. FB.api('/me/picture?type=normal', function(response) {
  223.  
  224. return response.data.url;
  225.  
  226. });
  227.  
  228. }
  229.  
  230. // Load the SDK asynchronously
  231.  
  232. (function(d){
  233.  
  234. var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
  235.  
  236. if (d.getElementById(id)) {return;}
  237.  
  238. js = d.createElement('script'); js.id = id; js.async = true;
  239.  
  240. if(document.documentElement.lang=="en-US"){
  241. js.src = "//connect.facebook.net/en_US/all.js";
  242. } else {
  243. js.src = "//connect.facebook.net/pl_PL/all.js";
  244. }
  245.  
  246. ref.parentNode.insertBefore(js, ref);
  247.  
  248. }(document));
  249.  
  250. </script>
  251.  
  252. <div id="profile"></div>
  253.  
  254. <script src="https://apis.google.com/js/client:plusone.js" type="text/javascript"></script>
  255.  
  256. <script src="https://apis.google.com/js/platform.js?onload=onLoadCallback" async defer></script>
  257.  
  258. <script type="text/javascript">
  259.  
  260. <?php
  261.  
  262. $setting_data=get_option('psl_social_plugin');
  263.  
  264. extract($setting_data['google_plus_details']);
  265.  
  266. ?>
  267. function google_login()
  268. {
  269.  
  270. var myParams = {
  271.  
  272. 'clientid' : '<?php echo $google_id;?>',
  273.  
  274. 'cookiepolicy' : 'single_host_origin',
  275.  
  276. 'callback' : 'loginCallback',
  277.  
  278. 'approvalprompt':'force',
  279.  
  280. 'scope' : 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read'
  281.  
  282. };
  283.  
  284. gapi.auth.signIn(myParams);
  285.  
  286. }
  287.  
  288. function loginCallback(result)
  289. {
  290.  
  291. if(result['status']['signed_in'])
  292. {
  293.  
  294. var request = gapi.client.plus.people.get(
  295. {
  296.  
  297. 'userId': 'me'
  298.  
  299. });
  300.  
  301. request.execute(function (resp)
  302. {
  303.  
  304. if(resp['emails'])
  305. {
  306.  
  307. for(i = 0; i < resp['emails'].length; i++)
  308. {
  309.  
  310. if(resp['emails'][i]['type'] == 'account')
  311. {
  312.  
  313. var email = resp['emails'][i]['value'];
  314. email=jQuery.trim(email);
  315.  
  316. }
  317.  
  318. }
  319.  
  320. }
  321.  
  322. var user_name=resp['displayName'];
  323.  
  324. if(email!='' && user_name!=''){
  325.  
  326. var str = resp['displayName'];
  327.  
  328. str += "*" + email;
  329.  
  330. str += "*" + "gplus";
  331.  
  332. //document.getElementById("profile").innerHTML = str;
  333.  
  334. var data = {
  335.  
  336. 'action': 'psl_data_retrive',
  337.  
  338. 'data': str // We pass php values differently!
  339.  
  340. };
  341.  
  342. }else{
  343. alert("NO Email is provided");
  344. }
  345.  
  346. // We can also pass the url value separately from ajaxurl for front end AJAX implementations
  347.  
  348. jQuery.post('<?php echo site_url();?>/wp-admin/admin-ajax.php', data, function(response) {
  349.  
  350. if(response=='success'){
  351.  
  352. <?php
  353.  
  354. if( is_checkout() ){
  355.  
  356. ?>
  357.  
  358. window.location.href = "<?php echo $_SERVER['REQUEST_URI']; ?>";
  359.  
  360. <?php
  361.  
  362. }
  363. else
  364. {
  365. ?>
  366.  
  367. window.location.href = "<?php echo stm_get_author_link('');?>";
  368.  
  369. <?php
  370. }
  371.  
  372. ?>
  373.  
  374. }
  375.  
  376. });
  377.  
  378. });
  379.  
  380. }
  381.  
  382. }
  383.  
  384. function onLoadCallback()
  385. {
  386.  
  387. gapi.client.setApiKey('<?php echo $google_api;?>');
  388.  
  389. gapi.client.load('plus', 'v1',function(){});
  390.  
  391. }
  392.  
  393. (function() {
  394.  
  395. var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  396.  
  397. po.src = 'https://apis.google.com/js/client.js?onload=onLoadCallback';
  398.  
  399. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  400.  
  401. })();
  402.  
  403. </script>
  404. <?php
  405.  
  406. }
  407.  
  408. $setting_data=get_option('psl_social_plugin');
  409.  
  410. add_action('admin_menu', 'pctm_social_login');
  411.  
  412. function pctm_social_login(){
  413.  
  414. $plugin_dir_url = plugin_dir_url( __FILE__ );
  415.  
  416. //add_menu_page( 'phoeniixx', __( 'Phoeniixx', 'phe' ), 'nosuchcapability', 'phoeniixx', NULL, $plugin_dir_url.'/images/logo-wp.png', 57 );
  417.  
  418. //add_submenu_page( 'phoeniixx', 'Social Login', 'Social Login', 'manage_options', 'psl-social-login', 'social_login_settings' );
  419.  
  420. }
  421.  
  422. add_action( 'wp_ajax_psl_data_retrive', 'psl_data_retrive' );
  423.  
  424. add_action( 'wp_ajax_nopriv_psl_data_retrive', 'psl_data_retrive' );
  425.  
  426. function convert_text($text) {
  427.  
  428. $t = $text;
  429.  
  430. $specChars = array(
  431. ' ' => '', '!' => '', '"' => '',
  432. '#' => '', '$' => '', '%' => '',
  433. '&' => '', '\'' => '', '(' => '',
  434. ')' => '', '*' => '', '+' => '',
  435. ',' => '', '-' => '', '.' => '',
  436. '/' => '', ':' => '', ';' => '',
  437. '<' => '', '=' => '', '>' => '',
  438. '?' => '', '@' => '', '[' => '',
  439. '\\' => '', ']' => '', '^' => '',
  440. '_' => '', '`' => '', '{' => '',
  441. '|' => '', '}' => '', '~' => '',
  442. );
  443.  
  444. foreach ($specChars as $k => $v) {
  445. $t = str_replace($k, $v, $t);
  446. }
  447.  
  448. return $t;
  449. }
  450.  
  451. function psl_data_retrive()
  452. {
  453.  
  454. extract($_POST);
  455.  
  456. $user_details=explode("*",$data);
  457.  
  458. $parts = explode("@", $user_details[1]);
  459. $profile_name = convert_text($parts[0]);
  460.  
  461. $user_name = $user_details[0];
  462.  
  463. $profile_email=$user_details[1];
  464.  
  465. $social_type=$user_details[2];
  466.  
  467. $profile_img=$user_details[3];
  468.  
  469. $profile_name = trim($profile_name);
  470.  
  471. if( !email_exists( $profile_email )&& username_exists( $profile_name )){
  472.  
  473. $profile_id=rand(1000, 9999);
  474.  
  475. $profile_name=$profile_name.$profile_id;
  476.  
  477. }
  478.  
  479. $user_id = username_exists( $profile_name );
  480.  
  481. if ( !$user_id and email_exists($profile_email) == false ) {
  482.  
  483. $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
  484.  
  485. $user_idd = wp_create_user( $profile_name, $random_password, $profile_email );
  486.  
  487. }
  488.  
  489. if(isset($user_idd))
  490. {
  491.  
  492. $user1 = get_user_by('id',$user_idd);
  493. wp_set_current_user( $user1->ID, $user1->user_login );
  494. wp_set_auth_cookie( $user1->ID );
  495. do_action( 'wp_login', $user1->user_login );
  496. update_user_meta( $user1->ID, 'email_verified', 1 );
  497. update_user_meta( $user1->ID, 'account_status', 1 );
  498.  
  499. $user_name = explode(" ", $user_name);
  500. update_user_meta( $user1->ID, 'first_name', $user_name[0] );
  501. update_user_meta( $user1->ID, 'last_name', $user_name[1] );
  502. $user1->set_role( '' );
  503. $user1->add_role( 'stm_dealer' );
  504. //update_user_meta( $user1->ID, 'stm_user_avatar', $profile_img );
  505.  
  506.  
  507.  
  508. $to=$profile_email;
  509.  
  510.  
  511. $sub = get_bloginfo( 'name' )." Details";
  512.  
  513. $msg='<div style="background-color:#f5f5f5;width:100%;margin:0;padding:70px 0 70px 0">
  514. <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
  515. <tbody>
  516. <tr>
  517. <td valign="top" align="center">
  518. <table width="600" cellspacing="0" cellpadding="0" border="0" style="border-radius:6px!important;background-color:#fdfdfd;border:1px solid #dcdcdc;border-radius:6px!important">
  519. <tbody>
  520. <tr>
  521. <td valign="top" align="center">
  522. <table width="600" cellspacing="0" cellpadding="0" border="0" bgcolor="#557da1" style="background-color:#557da1;color:#ffffff;border-top-left-radius:6px!important;border-top-right-radius:6px!important;border-bottom:0;font-family:Arial;font-weight:bold;line-height:100%;vertical-align:middle">
  523. <tbody>
  524. <tr>
  525. <td>
  526. <h1 style="color:#ffffff;margin:0;padding:28px 24px;display:block;font-family:Arial;font-size:30px;font-weight:bold;text-align:left;line-height:150%">'.get_bloginfo( 'name' ).' Login Details</h1>
  527. </td>
  528. </tr>
  529. </tbody>
  530. </table>
  531. </td>
  532. </tr>
  533. <tr>
  534. <td valign="top" align="center">
  535. <table width="600" cellspacing="0" cellpadding="0" border="0">
  536. <tbody>
  537. <tr>
  538. <td valign="top" style="background-color:#fdfdfd;border-radius:6px!important">
  539. <table width="100%" cellspacing="0" cellpadding="20" border="0">
  540. <tbody>
  541. <tr>
  542. <td valign="top">
  543. <div style="color:#737373;font-family:Arial;font-size:14px;line-height:150%;text-align:left">
  544. <p>Your '. get_bloginfo( 'name' ).' Login Details Are:</p>
  545. <p>Username: '.$profile_name.'</p>
  546. <p>Password: '.$random_password.'<br/></p>
  547. </div>
  548. </td>
  549. </tr>
  550. </tbody>
  551. </table>
  552. </td>
  553. </tr>
  554. </tbody>
  555. </table>
  556. </td>
  557. </tr>
  558. <tr>
  559. <td valign="top" align="center">
  560. <table width="600" cellspacing="0" cellpadding="10" border="0" style="border-top:0">
  561. <tbody>
  562. <tr>
  563. <td valign="top">
  564. <table width="100%" cellspacing="0" cellpadding="10" border="0">
  565. <tbody>
  566. <tr>
  567. <td valign="middle" style="border:0;color:#99b1c7;font-family:Arial;font-size:12px;line-height:125%;text-align:center" colspan="2">
  568. <p>'.get_bloginfo( 'name' ).'</p>
  569. </td>
  570. </tr>
  571. </tbody>
  572. </table>
  573. </td>
  574. </tr>
  575. </tbody>
  576. </table>
  577. </td>
  578. </tr>
  579. </tbody>
  580. </table>
  581. </td>
  582. </tr>
  583. </tbody>
  584. </table>
  585. </div>' ;
  586.  
  587. $header = "MIME-Version: 1.0\r\n";
  588.  
  589. $header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  590.  
  591. wp_mail($to,$sub,$msg,$header);
  592.  
  593. if($social_type=='gplus'){
  594.  
  595. $gp_count=get_option('psl_gp_count');
  596.  
  597. if($gp_count==''){
  598.  
  599. $gp_count=0;
  600.  
  601. }
  602.  
  603. $gp_count=$gp_count+1;
  604.  
  605. update_option('psl_gp_count',$gp_count);
  606.  
  607. }
  608.  
  609. if($social_type=='face'){
  610.  
  611. $fb_count=get_option('psl_fb_count');
  612.  
  613. if($fb_count==''){
  614.  
  615. $fb_count=0;
  616.  
  617. }
  618.  
  619. $fb_count=$fb_count+1;
  620.  
  621. update_option('psl_fb_count',$fb_count);
  622.  
  623. }
  624.  
  625. echo "success";
  626.  
  627. exit;
  628.  
  629. }
  630. else
  631. {
  632.  
  633. $user1 = get_user_by( 'email', $profile_email);
  634.  
  635. wp_set_current_user( $user1->ID, $user1->user_login );
  636.  
  637. wp_set_auth_cookie( $user1->ID );
  638.  
  639. do_action( 'wp_login', $user1->user_login );
  640.  
  641. if($social_type=='gplus'){
  642.  
  643. $gp_count=get_option('psl_gp_count');
  644.  
  645. if($gp_count=='')
  646. {
  647.  
  648. $gp_count=0;
  649.  
  650. }
  651.  
  652. $gp_count=$gp_count+1;
  653.  
  654. update_option('psl_gp_count',$gp_count);
  655.  
  656. }
  657.  
  658. if($social_type=='face'){
  659.  
  660. $fb_count=get_option('psl_fb_count');
  661.  
  662. if($fb_count==''){
  663.  
  664. $fb_count=0;
  665.  
  666. }
  667.  
  668. $fb_count=$fb_count+1;
  669.  
  670. update_option('psl_fb_count',$fb_count);
  671.  
  672. }
  673.  
  674. echo "success";
  675.  
  676. exit;
  677.  
  678. }
  679. }
  680.  
  681. }
  682. else
  683. {
  684.  
  685. add_action('admin_notices', 'pctm_my_plugin_admin_notices');
  686.  
  687. function pctm_my_plugin_admin_notices() {
  688.  
  689. if (!is_plugin_active('plugin-directory/plugin-file.php')) {
  690.  
  691. echo "<div class='error'><p>Please active WooCommerce First To Use WooCommerce Social Login</p></div>";
  692.  
  693. }
  694.  
  695. }
  696.  
  697. }
  698.  
  699. ob_clean();
  700.  
  701. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement