Public paste
Undefined
By: Guest | Date: Aug 3 2011 14:12 | Format: None | Expires: never | Size: 5.76 KB | Hits: 1225

  1. <?php
  2. /* INCLUDING FILES FROM WORDPRESS. */
  3. /* START */
  4.  
  5. require_once ('wp-config.php');
  6. require_once( 'wp-includes/registration.php');
  7. require_once( 'wp-includes/user.php');
  8.  
  9. /* END */
  10.  
  11.  
  12. /* API CALL FROM BIGADDA TO GET USER DETAILS */
  13. /* START OF CALL */
  14.  
  15. $apiurl = "http://s.api.bigadda.com/ws/custom/profile/_user/";
  16. $useridprofilecall ="http://s.api.bigadda.com/ws/custom/profile/_profile/";
  17.  
  18. /* END OF CALL */
  19.  
  20. /* MYSQL CONNECTION FOR DATABASE */
  21.  
  22. $conn = mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD) or die ('Error connecting to mu wordpress');
  23.  
  24. mysql_query("USE adda_production",$conn);
  25.  
  26. $sqlselectuniqueblogusers = "SELECT * FROM clone_users" ;
  27. $addauseridresult = mysql_query($sqlselectuniqueblogusers,$conn);
  28. $num_rows = mysql_num_rows($addauseridresult);
  29. echo "<br>NUMBER OF RECORDS IN BLOGS TABLE = ".$num_rows;
  30. /* LOOPING ALL UNIQUE USERS FROM BLOGS TABLE */
  31. while($row=mysql_fetch_array($addauseridresult))
  32. {
  33.             mysql_query("USE adda_production",$conn);
  34.         $user_loginid=$row['id']; /* USERID FROM BLOGS TABLE */
  35.         echo "<br>user_loginid = ".$user_loginid;
  36.          
  37.           /* EXTRACTING DETAILS OF USERS THROUGH API CALL */
  38.  
  39.         /* END OF CALL*/
  40.         /* CHECK IF API CALL RETURNS ERROR */
  41.         if(strstr($result,"Error:"))
  42.       {
  43.         echo $user_loginid ;
  44.             echo "<br>error no user found so moving on with other users </br>" ;
  45.       }
  46.       else
  47.       {
  48.                 /* UNCOMMENT THIS BELOW CODE TO GET DATA FROM API CALL*/
  49.                 // $json1 = json_decode($result,true);    
  50.          //  $addausername = $json1[0]['profile_id'];
  51.          $addausername = $row['username'];
  52.            echo $addausername ;
  53.            echo "<br>";
  54.      
  55.         $email        = $row['email'];    
  56.                    $password     = $row['password'];
  57.                 echo "<br>user_loginid = ".$user_loginid;
  58.  
  59.                 echo "<br>addausername = ".$addausername;
  60.                
  61.        
  62.                 /* END OF USER DETAILS FROM  USERS TABLE IN ADDA_PRODUCTION*/
  63.                
  64.                 /* SHIFT OF DATABASE FROM ADDA_PRODUCTION TO WORDPRESS */
  65.                 mysql_query("USE wordpress",$conn);
  66.                
  67.                 /* CHECK IF USER IS ALREADY HAS WORDPRESS ACCOUNT */
  68.        
  69.                 $sql_user_mu = mysql_query("select * from wp_users where user_login='$addausername'");
  70.         $num_rec = mysql_num_rows($sql_user_mu);
  71.  
  72.                  echo "<br>num_rec = ".$num_rec;
  73.                
  74.                 if($num_rec == 0 )
  75.                 {
  76.                        
  77.                     /* BIGADDA USER DOESNT HAVE ACCOUNT ON WORDPRESS */
  78.                     /* DEFINING VARIABLES TO CREATE USER ON WORDPRESS */
  79.             echo $addausername;
  80.                     $user_login = $addausername ;
  81.                     $test_login =str_replace(".","dot",$user_login);
  82.                     $test_login =strtolower($test_login);
  83.             $domain         =$current_site->domain;
  84.             $path='/'.$test_login.'/';
  85.             $title          =$user_login;
  86.             $user           =$user_login;
  87.                     $user_email =$email;
  88.                     $registered='NOW()';
  89.             $activation_key=$user_login."key";
  90.             $meta='a:2:{s:7:"lang_id";i:1;s:6:"public";i:1;}';
  91.                     /* END OF DEFINING VARIABLES*/             
  92.  
  93.                     /* CHECK IF USER IS IN WORDPRESS IF NOT THEN ADD DETAILS IN WP_SIGNUP TABLE */     
  94.             $sql_insert_check=mysql_query("select * from wp_signups where user_login='$user_login'",$conn);
  95.             $num_insert=mysql_num_rows($sql_insert_check);
  96.              echo "<br>num_insert = ".$num_insert;
  97.                     if($num_insert==0)
  98.             {
  99.                         /* INSERTING USER IN WP_SIGNUP TABLE IN WORDPRESS */
  100.                       echo "<br>CREATEBLOG FOR USING WPMU_SIGNUP_BLOG FUNCTION FOR  = ".$user_loginid;
  101.                          wpmu_signup_blog($domain, $path, $title, $user, $user_email, $meta='' ) ;
  102.            
  103.  
  104.  
  105.                     /* CHECK FOR USER DETAILS IN WP_SIGNUPS TABLE FOR ACTIVATING ACCOUNT  */   
  106.                     $sql_activate=mysql_query("select * from wp_signups where user_login='$user_login' and active='0'",$conn);
  107.             $num_activate=mysql_num_rows($sql_activate);
  108.             echo "<br>num_activate = ".$num_activate;
  109.                     if($num_activate==1)
  110.                 {
  111.                           /* START OF ACTIVATING ACCOUNT FOR NEWLY CREATED USER*/      
  112.                     $key_row=mysql_fetch_array($sql_activate);
  113.                     $key=$key_row['activation_key'];
  114.                           /* WORDPRESS FUNCTION TO ACTIVATE ACCOUNT */
  115.                     echo "<br>ACTIVATE USER ACCOUNT FOR = ".$user_loginid;
  116.                     wpmu_activate_signup($key);
  117.                     $sql_password=mysql_query("select * from wp_users where user_login='$user_login'",$conn);
  118.                     $num_password=mysql_num_rows($sql_password);
  119.                     $key_password=mysql_fetch_array($sql_password);
  120.                     $id=$key_password['ID'];
  121.                     $new_password = $password; //MD5 PASSWORD FROM API CALL OR FROM DATABASE
  122.                          /* WORDPRESS FUNCTION TO CHANGE PASSWORD */
  123.                            echo "<br>CHANGE PASSWORD FOR  = ".$user_loginid;
  124.                        wp_set_password( $new_password, $id);
  125.                      
  126.                      /* END OF ACTIVATING ACCOUNT FOR NEWLY CREATED USER*/
  127.  
  128.                          /* CREATE BLOG POST FOR NEWLY CREATED USER FROM ADDA_PRODUCTION ON WORDPRESS */
  129.                          /* SWIFTING DATABASE TO ADDA_PRODUCTION */
  130.                 //       mysql_query("USE adda_production",$conn);
  131.  
  132.                          echo "<br>FUNCTION CALL FOR CREATING BLOG= ".$user_loginid;
  133.                
  134.                                 // create_blog_user($user_loginid,$addausername,$conn,$domain,$path);
  135.              
  136.                         /* END OF CREATING BLOG POST FOR NEWLY CREATED USER*/
  137.                     }
  138.                    
  139.                 else
  140.                 {
  141.                         /* BIGADDA USER HAS ACCOUNT ON WORDPRESS */
  142.                        
  143.            // mysql_query("USE adda_production",$conn);
  144.                     echo "<br>FUNCTION CALL FOR CREATING BLOG IF USER ALREADY HAS WORDPRESS ACCOUNT= ".$user_loginid;
  145.                    
  146.                             //create_blog_user($user_loginid,$addausername,$conn,$domain,$path);
  147.                 } /* END OF IF*/       
  148.  
  149.  
  150.  
  151.         } /* END OF IF*/
  152.  
  153.     }
  154. }/* END OF WHILE LOOP FROM BLOGS TABLE */
  155.  
  156. }
  157. ?>