|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/crm.outerorbittech.com/application/models/ | |
|
Path: /home2/outerorb/crm.outerorbittech.com/application/models/Api_model.php
Size: 16.67 KB
Permissions: 0664
<?php
class Api_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->db->db_debug = false;
$this->load->helper('string');
$this->load->helper('sms');
}
public function register($data)
{
$name = $data['name'];
$count = strlen($data['mobile']);
if ($count != 10) {
return false;
}
$username = str_replace(' ','',(strtolower($data['name']))).random_string('numeric', 4);
$token = md5(date('Y-m-d H:i:s') . $name);
$upload_path = './assets/images/';
$allowed_types = 'gif|jpg|jpeg|png';
if (!empty($_FILES["image"]['name'])) {
$path = upload_file("image", $upload_path, $allowed_types, time());
$data['image'] = file_url($path['path']);
}
$data['token'] = $token;
$data['username'] = $username;
$data['created_at'] = date('Y-m-d H:i:s');
$insertdata = $this->db->insert('register', $data);
if ($insertdata == true) {
return true;
} else {
return false;
}
}
public function save_post($data)
{
if ($data['user_id'] == '') {
return false;
}
$upload_path = './assets/images/';
$allowed_types = 'gif|jpg|jpeg|png|gif|mp4|avi|mkv|webm';
if (!empty($_FILES["image"]['name'])) {
$path = upload_file("image", $upload_path, $allowed_types, time());
$data['image'] = file_url($path['path']);
}
if (!empty($data['description'])) {
$description = json_encode($data['description']);
$data['description'] = $description;
}
if (!empty($data['title'])) {
$title = json_encode($data['title']);
$data['title'] = $title;
}
$data['created_at'] = date('Y-m-d H:i:s');
$insertdata = $this->db->insert('posts', $data);
if ($insertdata == true) {
return true;
} else {
return false;
}
}
public function add_login($data)
{
$user = $this->db->get_where('register', array('email' => $data['email'], 'password' => $data['password'], 'status' => 1))->row_array();
if (!empty($user)) {
$ar['reg_id'] = $data['reg_id'];
$this->db->where('email', $data['email']);
$this->db->where('password', $data['password']);
$update = $this->db->update('register', $ar);
} else {
return false;
}
if ($update == true) {
$update_user = $this->db->get_where('register', array('email' => $data['email'], 'password' => $data['password']))->row_array();
return $update_user;
} else {
return false;
}
}
public function save_like($data)
{
$postdata = $this->db->get_where('posts', array('id' => $data['post_id']))->row_array();
if (empty($postdata)) {
return false;
}
$post_id = $data['post_id'];
$user_id = $data['user_id'];
$lk = $this->db->get_where('like', array('user_id' => $user_id, 'post_id' => $post_id))->row_array();
if (!empty($lk)) {
$ar['status'] = 0;
$this->db->where('post_id', $post_id);
$this->db->where('user_id', $user_id);
$insertdata = $this->db->update('like', $ar);
} else {
$data['created_at'] = date('Y-m-d H:i:s');
$insertdata = $this->db->insert('like', $data);
}
if ($insertdata == true) {
$update_like = $this->db->get_where('like', array('user_id' => $user_id, 'post_id' => $post_id))->row_array();
return $update_like;
} else {
return false;
}
}
public function device_varify($data)
{
$user = $this->db->get_where('register', array('email' => $data['email'], 'reg_id' => $data['reg_id'], 'status' => 1))->row_array();
if (!empty($user)) {
return true;
} else {
return false;
}
}
public function myposts($data)
{
$other_id = $data['other_id'];
$user_id = $data['user_id'];
if ($user_id == $other_id) {
$post = $this->db->order_by('created_at', 'DESC')->get_where('posts', array('user_id' => $user_id))->result_array();
} else if ($other_id != $user_id) {
$req1 = $this->db->get_where('follow_request', array('follow_id' => $other_id, 'requested_id' => $user_id, 'status' => 1));
$req2 = $this->db->get_where('follow_request', array('follow_id' => $user_id, 'requested_id' => $other_id, 'status' => 1));
if ($req1 == true && $req2 == false) {
$this->db->select('*');
$this->db->where('user_id', $user_id);
$this->db->group_start();
$this->db->where('type=', 'followme');
$this->db->or_where('type=', 'everyone');
$this->db->group_end();
$post = $this->db->order_by('created_at', 'DESC')->get('posts')->result_array();
} elseif ($req1 == false && $req2 == true) {
$this->db->select('*');
$this->db->where('user_id', $user_id);
$this->db->group_start();
$this->db->where('type=', 'ifollow');
$this->db->or_where('type=', 'everyone');
$this->db->group_end();
$post = $this->db->order_by('created_at', 'DESC')->get('posts')->result_array();
} elseif ($req1 == true && $req2 == true) {
$this->db->select('*');
$this->db->where('user_id', $user_id);
$this->db->group_start();
$this->db->where('type=', 'followme');
$this->db->or_where('type=', 'everyone');
$this->db->or_where('type=', 'ifollow');
$this->db->group_end();
$post = $this->db->order_by('created_at', 'DESC')->get('posts')->result_array();
} else {
$this->db->select('*');
$this->db->where('user_id', $user_id);
$this->db->group_start();
$this->db->or_where('type=', 'everyone');
$this->db->group_end();
$post = $this->db->order_by('created_at', 'DESC')->get('posts')->result_array();
}
}
if (!empty($post)) {
return $post;
} else {
return false;
}
}
public function save_comment($data)
{
$data['created_at'] = date('Y-m-d H:i:s');
$insertdata = $this->db->insert('comment', $data);
if ($insertdata == true) {
return true;
} else {
return false;
}
}
public function total_comment($data)
{
$post['result'] = $this->db->order_by('created_at', 'DESC')->get_where('comment', array('post_id' => $data['post_id']))->result_array();
$post['total'] = $this->db->get_where('comment', array('post_id' => $data['post_id']))->num_rows();
if (!empty($post)) {
return $post;
} else {
return false;
}
}
public function save_postviews($data)
{
$views = $this->db->get_where('post_views', array('post_id' => $data['post_id'], 'user_id' => $data['user_id']))->row_array();
if (!empty($views)) {
$ar['status'] = 1;
$this->db->where('post_id', $data['post_id']);
$this->db->where('user_id', $data['user_id']);
$insertdata = $this->db->update('like', $ar);
} else {
$data['created_at'] = date('Y-m-d H:i:s');
$insertdata = $this->db->insert('post_views', $data);
}
if ($insertdata == true) {
return true;
} else {
return false;
}
}
public function total_like($data)
{
$post['result'] = $this->db->order_by('created_at', 'DESC')->get_where('like', array('post_id' => $data['post_id']))->result_array();
$post['total'] = $this->db->get_where('like', array('post_id' => $data['post_id']))->num_rows();
if (!empty($post)) {
return $post;
} else {
return false;
}
}
public function download_posts($data)
{
$down = $this->db->get_where('posts', array('id' => $data['post_id']))->row_array();
if (!empty($down)) {
$data['created_at'] = date('Y-m-d H:i:s');
$insertdata = $this->db->insert('download_post', $data);
} else {
return false;
}
if ($insertdata == true) {
return true;
} else {
return false;
}
}
public function follow_request($data)
{
$req = $this->db->get_where('follow_request', array('follow_id' => $data['follow_id'], 'requested_id' => $data['requested_id'], 'status' => 0))->row_array();
if (!empty($req)) {
$ar['status'] = 0;
$this->db->where('follow_id', $data['follow_id']);
$this->db->where('requested_id', $data['requested_id']);
$insertdata = $this->db->update('follow_request', $ar);
} else {
$data['created_at'] = date('Y-m-d H:i:s');
$insertdata = $this->db->insert('follow_request', $data);
}
if ($insertdata == true) {
return true;
} else {
return false;
}
}
public function accept_request($data)
{
$req = $this->db->get_where('follow_request', array('follow_id' => $data['follow_id'], 'requested_id' => $data['requested_id'], 'status' => 0))->row_array();
if (!empty($req)) {
$ar['status'] = 1;
$this->db->where('follow_id', $data['follow_id']);
$this->db->where('requested_id', $data['requested_id']);
$insertdata = $this->db->update('follow_request', $ar);
} else {
return false;
}
if ($insertdata == true) {
return true;
} else {
return false;
}
}
public function homeposts($data)
{
$user_id = $data['user_id'];
$last_id = $data['last_id'];
$req1 = $this->db->select('requested_id')->get_where('follow_request', array('follow_id' => $user_id, 'status' => 1))->result();
$req2 = $this->db->select('follow_id')->get_where('follow_request', array('requested_id' => $user_id, 'status' => 1))->result();
if ($last_id == 0) { //if user check post first time last id will be 0
if (!empty($req1) || !empty($req2)) {
$ar = array();
foreach ($req1 as $rq) {
$ar[] = $rq->requested_id;
}
foreach ($req2 as $rq2) {
$ar[] = $rq2->follow_id;
}
$this->db->select('*');
$this->db->where(array('user_id!=' => $user_id, 'type!=' => 'only', 'type=' => 'followme'));
$this->db->where_in('user_id', $ar);
$this->db->or_where('user_id', $user_id);
$this->db->or_where('type=', 'everyone');
$this->db->where('status', 1);
$this->db->limit(10);
$rest = $this->db->get('posts');
if ($rest == true) {
$post = $rest->result_array();
$id = end($post);
$lasts_id = $id['id'];
$next = $this->Api_model->check_post($user_id, $lasts_id, $ar);
if ($next == true) {
$nextpage = true;
} else {
$nextpage = false;
}
} else {
$post = $this->db->error();
}
} else {
$this->db->select('*');
$this->db->where(array('user_id!=' => $user_id, 'type!=' => 'only'));
$this->db->where('type=', 'everyone');
$this->db->or_where('user_id', $user_id);
$this->db->where('status', 1);
$this->db->limit(10);
$post = $this->db->get('posts')->result_array();
$id = end($post);
$lasts_id = $id['id'];
$next = $this->Api_model->check_post($user_id, $lasts_id);
if ($next == true) {
$nextpage = true;
} else {
$nextpage = false;
}
}
} else {
if (!empty($req1) || !empty($req2)) {
$ar = array();
foreach ($req1 as $rq) {
$ar[] = $rq->requested_id;
}
foreach ($req2 as $rq2) {
$ar[] = $rq2->follow_id;
}
$val = implode(',', $ar);
$rest = $this->db->query("SELECT * FROM `vc_posts`WHERE `user_id` != '$user_id'AND `type` != 'only'AND `type` = 'followme'AND `user_id` IN($val)AND `id` >'$last_id'OR `user_id` = '$user_id'AND `id` >'$last_id'OR `type` = 'everyone' AND `id` >'$last_id'AND `status` = 1 LIMIT 10"); // fetch friends post
if ($rest) {
$post = $rest->result_array();
if (!empty($post)) {
$id = end($post);
$lasts_id = $id['id'];
$next = $this->Api_model->check_post($user_id, $lasts_id, $ar);
if ($next == true) {
$nextpage = true;
} else {
$nextpage = false;
}
}
} else {
$post = $this->db->error();
}
} else {
$rest = $this->db->query("SELECT * FROM `vc_posts` WHERE `id` > '$last_id' AND `user_id` != '$user_id' AND `type` != 'only' AND `type` = 'everyone' OR `user_id` = '$user_id'AND `status` = 1 LIMIT 10"); //fetch users posts if he has no friends
if ($rest) {
$post = $rest->result_array();
$id = end($post);
$lasts_id = $id['id'];
$next = $this->Api_model->check_post($user_id, $lasts_id);
if ($next == true) {
$nextpage = true;
} else {
$nextpage = false;
}
}
}
}
if (!empty($post)) {
$result = array('post' => $post, 'nextpage' => $nextpage);
return $result;
} else {
return false;
}
}
public function total_views($data)
{
$post['result'] = $this->db->order_by('created_at', 'DESC')->get_where('post_views', array('post_id' => $data['post_id']))->result_array();
$post['total'] = $this->db->get_where('post_views', array('post_id' => $data['post_id']))->num_rows();
if (!empty($post)) {
return $post;
} else {
return false;
}
}
public function check_post($user_id, $lasts_id, $ar = array())
{
$this->db->select('*');
$this->db->where(array('user_id!=' => $user_id, 'type!=' => 'only', 'type=' => 'followme'));
if (!empty($ar)) {
$this->db->where_in('user_id', $ar);
}
$this->db->group_start();
$this->db->or_where(array('user_id' => $user_id));
$this->db->group_end();
$this->db->or_where(array('type=' => 'everyone'));
$this->db->where('id>', $lasts_id);
$this->db->where('status', 1);
$last = $this->db->get('posts')->result(); // check more than 10 data or not
if ($last) {
$data = true;
} else {
$data = false;
}
return $data;
}
public function block_user($data)
{
$data['created_at'] = date('Y-m-d H:i:s');
$insertdata = $this->db->insert('block_user', $data);
if ($insertdata == true) {
return true;
} else {
return false;
}
}
public function reset_pass($data)
{
$sms['mobile'] = $data['mobile'];
$sms['message'] = $data['message'];
$send = send_sms($sms);
if ($send == true) {
return true;
} else {
return false;
}
}
public function update_pass($data)
{
$ar['password']=$data['new_pass'];
$this->db->where('mobile', $data['mobile']);
$this->db->where('password', $data['old_pass']);
$update = $this->db->update('register', $ar);
if ($update == true) {
return true;
} else {
return false;
}
}
}