ajgkqsldxvkqsldkqs azelfkqsmkqsmlkdqsmld azmlekdqmskdmlqskd nkldsfkqsmldkqsmdmlskd decrypt($_POST['id']); $title = $mcrypt->decrypt($_POST['title']); $desc = $mcrypt->decrypt($_POST['desc']); /* Fetch the information */ $con = db_connect(); $sql = session($con,$session); $success = 0; $message = ""; if(db_rows($con,$sql)>0){ /* fetch userid and create session token */ $query = mysqli_query($con,$sql); while($row=mysqli_fetch_array($query)){ $userid = $row['userid']; $name = $row['name']; $pic = $row['picture']; if(empty($pic)){ $pic = "no_image.png"; } $pic = pic_url($pic); } /* Validate image */ if(empty($title)){ $response['message'] = $mcrypt->encrypt("Please enter title"); }else if(empty($desc)){ $response['message'] = $mcrypt->encrypt("Please enter description of offer"); }else{ $image = ""; $image_ok = 1; if(!empty($_FILES['image']['name'])){ $target_folder = "../closeapp/newsfeed/"; if (isset($_FILES['image']['name'])) { $ext = strtolower(pathinfo($_FILES['image']['name'],PATHINFO_EXTENSION)); $allowed_file = array('jpg', 'jpeg','png','gif'); /* give the file a new name */ $image = md5($userid.$_FILES['image']['name'].time().generateShortToken()).".".$ext; $target_path = $target_folder.$image; $size = $_FILES['image']["size"]; if(!in_array($ext,$allowed_file)){ $response['message'] = $mcrypt->encrypt('Only jpg,jpeg,png or gif files is allowed!'); $image_ok = 0; }else if($size>1000000){ $response['message'] = $mcrypt->encrypt('Image is too large. Maximum image size is 1MB!'); $image_ok = 0; }else{ if($size<=70000){ move_uploaded_file($_FILES['image']['tmp_name'], $target_path); }else{ $quality = image_quality($size); compressImage($_FILES['image']['tmp_name'],$target_path,$quality); } } } } if($image_ok==1){ $sql = record_newsfeed($con,$userid,$title,$desc,$image); if(mysqli_query($con,$sql)){ $success = 1; $response['message'] = $mcrypt->encrypt('Newsfeed is successfully posted.'); /* Send notification alerts to people who have subscribed to receive post from this user */ $sql = "Select n.subscriber,u.ac_type from newsfeed_subscriptions as n inner join users as u on n.subscriber=u.id where n.userid=".intval($userid); if(db_rows($con,$sql)>0){ $priority = "high"; $data_title=$name." posted a news feed."; $message = $title; $data = array ( 'action' => '8', 'title' => $mcrypt->encrypt($data_title), 'message' => $mcrypt->encrypt($message), 'name' => $mcrypt->encrypt($name), 'image' => $mcrypt->encrypt($pic), 'id' => $mcrypt->encrypt($userid) ); $query = mysqli_query($con,$sql); while($row=mysqli_fetch_array($query)){ $subscriber = $row['subscriber']; /* Send the notification */ $firebase_sql = user_push_tokens($subscriber); $firebase_query = mysqli_query($con,$firebase_sql); while($firebase_row=mysqli_fetch_array($firebase_query)){ $pushid = $firebase_row['token']; /* Send data and push notification */ $ac_type = $firebase_row['ac_type']; /* if account is business, use the closeapp business firebase id */ if(!(empty($pushid))){ if($ac_type==1){ sendPushData($pushid,$data,$priority); }else{ sendPushDataCloseApp($pushid,$data,$priority); } } } } } }else{ $response['message'] = $mcrypt->encrypt('Server error. Please try again later.'); } } } }else{ $response['message'] = $mcrypt->encrypt("You don't have right to access this content."); } $response['success'] = $success; echo json_encode($response); db_close($con); }