Advertisement
Guest User

ajax.php by Xaph

a guest
Jun 4th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.00 KB | None | 0 0
  1. <?php
  2.    
  3. if ( !defined('ABSPATH') ) {
  4. /** Set up WordPress environment */
  5. require_once( dirname( __FILE__ ) . '/../../../wp-load.php' );
  6. }
  7.  
  8.    
  9. if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
  10. if (isset($_GET['like'])) {
  11.     $likes = get_option("term_likes_".(int)$_GET['like'],(int)$_GET['id']);
  12.     update_option("term_likes_".(int)$_GET['like'],$likes++);
  13. }
  14. if (isset($_GET['update_post_view'])) {
  15.     $views = (int)get_option("views_".(int)$_GET['update_post_view']);
  16.     $views++;
  17.     update_option("views_".(int)$_GET['update_post_view'],$views);
  18.     echo esc_html($views);
  19. }
  20. if (isset($_GET['cordovaget'])) {
  21.     echo get_option("cordova_img").";";
  22.     echo get_option("cordova_config");
  23. }
  24. if (isset($_GET['msg_send'])) {
  25.     $wpdb->insert(
  26.         'dialog',
  27.         array(
  28.             'user1' => get_current_user_id(),
  29.             'user2' => (int)$_GET['msg_send'],
  30.             'dataadd' => time(),
  31.             'msg' => esc_textarea ( $_POST['msg'] )
  32.         ),
  33.         array(
  34.             '%d',
  35.             '%d',
  36.             '%d',
  37.             '%s'
  38.         )
  39.     );
  40.     mycity_chat_messages(get_current_user_id(),esc_textarea($_GET['msg_send']));
  41. }
  42. if (isset($_GET['msg_get'])) {
  43.     $id = get_current_user_id();
  44.     mycity_chat_messages($id,esc_textarea($_GET['msg_get']));
  45.    
  46. }
  47. if (isset($_GET['togglefollow'])) {
  48.     if (mycity_is_follow(get_current_user_id(), (int)$_GET['togglefollow'])) {
  49.         //unfollow
  50.         $wpdb->query(
  51.             "
  52.             DELETE FROM follow
  53.             WHERE user1 = '".get_current_user_id()."' AND user2 = '".(int)$_GET['togglefollow']."'
  54.             "
  55.         );
  56.         echo esc_html__("Follow","mycity");;
  57.        
  58.     } else {
  59.         //
  60.         $wpdb->insert(
  61.             'follow',
  62.             array(
  63.                 'user1' => get_current_user_id(),
  64.                 'user2' => (int)$_GET['togglefollow'],
  65.                 'dataadd' => time(),
  66.             ),
  67.             array(
  68.                 '%d',
  69.                 '%d',
  70.                 '%d'
  71.             )
  72.         );
  73.         $wpdb->insert(
  74.             'dialog',
  75.             array(
  76.                 'user1' => get_current_user_id(),
  77.                 'user2' => (int)$_GET['togglefollow'],
  78.                 'dataadd' => time(),
  79.                 'msg' => ":)"
  80.             ),
  81.             array(
  82.                 '%d',
  83.                 '%d',
  84.                 '%d',
  85.                 '%s'
  86.             )
  87.         );
  88.         echo esc_html__("Unfollow","mycity");
  89.     }
  90. }
  91. if (isset($_GET['sendsms'])) {
  92.    
  93.     $to = str_replace("+","", sanitize_text_field($_GET['sendsms']));
  94.     if (!is_numeric($to)) die("Enter valid number");
  95.     $code = rand(1111,9999);
  96.    
  97.     $user = get_user_by( "email", $to."@".$_SERVER['HTTP_HOST']);
  98.    
  99.     if ($user) {
  100.         wp_set_password( $code, $user->ID);
  101.     } else {
  102.         $user = wp_create_user($to, $code, $to."@".$_SERVER['HTTP_HOST']);
  103.         //print_R($user);
  104.     }
  105.     // Authorisation details.
  106.     $message = $_SERVER['HTTP_HOST']." : Your code is ".$code;
  107.     $return = mycity_send_sms($to,$message);
  108. }
  109.  
  110. if (isset($_GET['check_email'])) {
  111.     if (email_exists($_POST['email'])) { echo esc_html__("This email already registered","mycity"); } else { echo "OK"; }
  112. }
  113. if (isset($_GET['trylogin'])) {
  114.     $creds = array();
  115.  
  116.    
  117.     if (substr_count($_POST['login'],'+') && get_option("allow_sms_registration") == 1) {
  118.         $to = str_replace("+","", sanitize_text_field($_POST['login']));
  119.         if (!is_numeric($to)) die("enter valid tel");
  120.         $creds['user_login'] = $to;
  121.         $creds['user_email'] = $to."@".$_SERVER['HTTP_HOST'];
  122.        
  123.     } else if (substr_count($_POST['login'],'@')) {
  124.         $creds['user_email'] =  sanitize_text_field($_POST['login']);
  125.         $user = get_user_by( "email",sanitize_email( $creds['user_email']));
  126.         if (isset($user->user_login)) { $creds['user_login'] = $user->user_login; } else {$creds['user_login'] = $_POST['login'];}
  127.     } else {
  128.         $creds['user_login'] =  sanitize_text_field($_POST['login']);
  129.     }
  130.    
  131.     $creds['user_password'] =  sanitize_text_field($_POST['pass']);
  132.     $creds['remember'] = true;
  133.    
  134.     $user = wp_signon( $creds, false );
  135.     if ( is_wp_error($user) ) {
  136.         echo $user->get_error_message();
  137.     } else {
  138.         $userID = $user->ID;
  139.         wp_set_current_user( $userID, $user_login );
  140.         wp_set_auth_cookie( $userID, true, false );
  141.         do_action( 'wp_login', $user_login );
  142.            $place = "/places/";
  143.         if(strlen(fmr_get_permalink_by_template('Places_map2.php')) > 1){
  144.             $place = fmr_get_permalink_by_template('Places_map2.php');
  145.         }
  146.         if(strlen(fmr_get_permalink_by_template('Places_map.php')) > 1){
  147.             $place = fmr_get_permalink_by_template('Places_map.php');
  148.          }
  149.    
  150.         ?>
  151.         <script>
  152.  
  153.             window.location = '<?php echo esc_url($place); ?>';
  154.         </script>
  155.         <?php
  156.     }
  157.  
  158. }
  159. if (isset($_GET['tryreg'])){
  160.     $user_name = sanitize_user($_POST['display_name']);
  161.    
  162.     $user_id = username_exists($user_name);
  163.     if (substr_count($_POST['login'],"@")) $_POST['regemail'] =sanitize_text_field($_POST['login']);
  164.     $user_email = sanitize_email($_POST['regemail']);
  165.    
  166.     if ( !$user_id and email_exists($_POST['regemail']) == false ) {
  167.         $random_password = wp_generate_password( $length=6, $include_standard_special_chars=false );
  168.         if ($_POST['pass']) $random_password = $_POST['pass'];
  169.         $user_email = $_POST['regemail'];
  170.         //print_R($_POST);
  171.         //die();
  172.         $user_id = wp_create_user( $user_name, $random_password, $user_email );
  173.        
  174.         wp_set_current_user( $user_id, sanitize_user($user_name) );
  175.         wp_set_auth_cookie( $user_id, true, false );
  176.         do_action( 'wp_login', $user_login );
  177.    
  178.         wp_new_user_notification( $user_id, $random_password );
  179.      
  180.         $place = "/places/";
  181.         if(strlen(fmr_get_permalink_by_template('Places_map2.php')) > 1){
  182.             $place = fmr_get_permalink_by_template('Places_map2.php');
  183.         }
  184.         if(strlen(fmr_get_permalink_by_template('Places_map.php')) > 1){
  185.             $place = fmr_get_permalink_by_template('Places_map.php');
  186.          }
  187.    
  188.         ?>
  189.         <script>
  190.  
  191.             window.location = '<?php echo esc_url($place); ?>';
  192.         </script>
  193.         <?php
  194.     } else {
  195.         echo __('User already exists.','mycity');
  196.     }
  197.    
  198. }
  199.  
  200. if (isset($_GET['editmain'])) {
  201.     //print_R($_POST);
  202.     if (current_user_can('administrator')) {
  203.         update_option(sanitize_text_field($_POST['option']),sanitize_text_field(strip_tags($_POST['val'])));
  204.         echo get_option(sanitize_text_field($_POST['option']));
  205.     } else {
  206.     echo "123";
  207.     }
  208. }
  209. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement