qlConnect, $query_one); if (mysqli_num_rows($query)) { while ($fetched_data = mysqli_fetch_assoc($query)) { $fetched_data['user_name'] = ''; $fetched_data['user_url'] = ''; if (!empty($fetched_data['invited_id'])) { $user_data = Wo_UserData($fetched_data['invited_id']); $fetched_data['user_name'] = $user_data['name']; $fetched_data['user_url'] = $user_data['url']; } $data[] = $fetched_data; } } return $data; } function Wo_AddInvitedUser($user_id, $code) { global $wo, $sqlConnect, $db; if (empty($user_id) || !is_numeric($user_id) || $user_id < 1 || empty($code)) { return false; } $user_id = Wo_Secure($user_id); $code = Wo_Secure($code); $db->where('code', $code)->update(T_INVITAION_LINKS, array( 'invited_id' => $user_id )); } function Wo_IsUserInvitationExists($code = false) { global $sqlConnect, $wo; if (!$code) { return false; } $code = Wo_Secure($code); $data_rows = mysqli_query($sqlConnect, "SELECT `id` FROM " . T_INVITAION_LINKS . " WHERE `code` = '$code' AND `invited_id` = 0"); return mysqli_num_rows($data_rows) > 0; } function Wo_GetAllInvitaionCodes() { global $wo, $sqlConnect; if ($wo['loggedin'] == false) { return false; } $data = array(); $query_one = " SELECT * FROM " . T_INVITAION_LINKS; $query = mysqli_query($sqlConnect, $query_one); if (mysqli_num_rows($query)) { while ($fetched_data = mysqli_fetch_assoc($query)) { $fetched_data['user_name'] = ''; $fetched_data['user_url'] = ''; if (!empty($fetched_data['invited_id'])) { $user_data = Wo_UserData($fetched_data['invited_id']); $fetched_data['user_name'] = $user_data['name']; $fetched_data['user_url'] = $user_data['url']; } $data[] = $fetched_data; } } return $data; } function Wo_DeleteUserInvitation($col = '', $val = false) { global $sqlConnect, $wo; if (!$val && !$col) { return false; } $val = Wo_Secure($val); $col = Wo_Secure($col); return mysqli_query($sqlConnect, "DELETE FROM " . T_INVITAION_LINKS . " WHERE `$col` = '$val'"); } function Wo_notifyUsersLive($post_id) { global $sqlConnect, $wo; if ($wo['loggedin'] == false || empty($post_id) || !is_numeric($post_id) || $post_id < 1) { return false; } $post_id = Wo_Secure($post_id); $data = array(); $time = time() - 30; $user_id = Wo_Secure($wo['user']['user_id']); $query_text = "SELECT `user_id` FROM " . T_USERS . " WHERE `user_id` IN (SELECT `follower_id` FROM " . T_FOLLOWERS . " WHERE `follower_id` <> {$user_id} AND `following_id` = {$user_id} AND `user_id` NOT IN (SELECT `blocked` FROM " . T_BLOCKS . " WHERE `blocker` = '{$user_id}') AND `user_id` NOT IN (SELECT `blocker` FROM " . T_BLOCKS . " WHERE `blocked` = '{$user_id}') AND `active` = '1') AND `lastseen` > {$time}"; $query_text .= " AND `active` = '1' ORDER BY `lastseen` DESC"; $query = mysqli_query($sqlConnect, $query_text); if (mysqli_num_rows($query)) { while ($fetched_data = mysqli_fetch_assoc($query)) { $notification_data = array( 'recipient_id' => $fetched_data['user_id'], 'notifier_id' => $wo['user']['id'], 'type' => 'live_video', 'post_id' => $post_id, 'url' => 'index.php?link1=post&id=' . $post_id ); Wo_RegisterNotification($notification_data); } } return $data; } function Wo_CheckRazorpayPayment($payment_id, $data) { global $wo; if (empty($payment_id) || empty($data)) { return false; } $url = 'https://api.razorpay.com/v1/payments/' . $payment_id . '/capture'; $key_id = $wo['config']['razorpay_key_id']; $key_secret = $wo['config']['razorpay_key_secret']; $params = http_build_query($data); //cURL Request $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, $key_id . ':' . $key_secret); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); $request = curl_exec($ch); curl_close($ch); return json_decode($request); } function Wo_CheckAnonymous($id, $type) { global $sqlConnect, $wo; if (empty($id) || empty($type)) { return false; } $sub = ""; if ($type == 'reply') { $sub = " AND P.`post_id` = (SELECT `post_id` FROM " . T_COMMENTS . " C WHERE C.`id` = (SELECT `comment_id` FROM " . T_COMMENTS_REPLIES . " R WHERE R.`id` = '{$id}' AND R.`user_id` = P.`user_id`)) "; } $query_one = "SELECT COUNT(id) as count FROM " . T_POSTS . " P WHERE P.`postPrivacy` = '4'" . $sub; $sql = mysqli_query($sqlConnect, $query_one); if (mysqli_num_rows($sql)) { $fetched_data = mysqli_fetch_assoc($sql); if (empty($fetched_data)) { return false; } return $fetched_data['count']; } } function StartCloudRecording($vendor, $region, $bucket, $accessKey, $secretKey, $cname, $uid, $post_id, $token) { global $sqlConnect, $wo, $db; $post_id = Wo_Secure($post_id); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.agora.io/v1/apps/" . $wo['config']['agora_app_id'] . "/cloud_recording/acquire"); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Basic ' . base64_encode($wo['config']['agora_customer_id'] . ":" . $wo['config']['agora_customer_certificate']), 'Content-Type: application/json;charset=utf-8' )); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "cname": "' . $cname . '", "uid": "' . $uid . '", "clientRequest":{ } }'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response); $resourceId = $data->resourceId; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.agora.io/v1/apps/" . $wo['config']['agora_app_id'] . "/cloud_recording/resourceid/" . $resourceId . "/mode/mix/start"); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Basic ' . base64_encode($wo['config']['agora_customer_id'] . ":" . $wo['config']['agora_customer_certificate']), 'Content-Type: application/json;charset=utf-8' )); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "cname":"' . $cname . '", "uid":"' . $uid . '", "clientRequest":{ "token":"' . $token . '", "recordingConfig":{ "channelType":1, "streamTypes":2, "audioProfile":1, "videoStreamType":1, "maxIdleTime":120, "transcodingConfig":{ "width":480, "height":480, "fps":24, "bitrate":800, "maxResolutionUid":"1", "mixedVideoLayout":1 } }, "storageConfig":{ "vendor":' . $vendor . ', "region":' . $region . ', "bucket":"' . $bucket . '", "accessKey":"' . $accessKey . '", "secretKey":"' . $secretKey . '", "fileNamePrefix": [ "upload", "videos", "' . date('Y') . '", "' . date('m') . '" ] } } } '); // curl_setopt($ch, CURLOPT_POSTFIELDS,'{ // "cname":"'.$cname.'", // "uid":"'.$uid.'", // "clientRequest":{ // "recordingConfig": { // "maxIdleTime": 30, // "streamTypes": 2, // "channelType": 1, // "videoStreamType": 1, // "subscribeUidGroup": 0, // "maxIdleTime": 30000 // }, // "storageConfig":{ // "vendor":'.$vendor.', // "region":'.$region.', // "bucket":"'.$bucket.'", // "accessKey":"'.$accessKey.'", // "secretKey":"'.$secretKey.'" // } // } // } // '); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response); if (!empty($data->sid) && !empty($resourceId)) { $db->where('id', $post_id)->update(T_POSTS, array( 'agora_resource_id' => $resourceId, 'agora_sid' => $data->sid )); } return true; } function StopCloudRecording($data) { global $sqlConnect, $wo, $db; if (empty($data) || $wo['config']['agora_live_video'] != 1 || empty($data['resourceId']) || empty($data['sid']) || empty($data['cname']) || empty($data['uid']) || empty($data['post_id'])) { return false; } $post_id = Wo_Secure($data['post_id']); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.agora.io/v1/apps/" . $wo['config']['agora_app_id'] . "/cloud_recording/resourceid/" . $data['resourceId'] . "/sid/" . $data['sid'] . "/mode/mix/stop"); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Basic ' . base64_encode($wo['config']['agora_customer_id'] . ":" . $wo['config']['agora_customer_certificate']), 'Content-Type: application/json;charset=utf-8' )); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "cname": "' . $data['cname'] . '", "uid": "' . $data['uid'] . '", "clientRequest":{ "token":"' . $data['token'] . '" } }'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $data2 = json_decode($response); if (!empty($data2) && !empty($data2->serverResponse) && !empty($data2->serverResponse->fileList)) { $db->where('id', $post_id)->update(T_POSTS, array( 'postFile' => $data2->serverResponse->fileList )); } // else{ // $file = "upload/videos/".date('Y')."/".date('m')."/".$data['sid']."_".$data['cname'].".m3u8"; // $db->where('id',$post_id)->update(T_POSTS,array('postFile' => $file)); // } return true; } function GetVideoTime($first, $second) { $first_date = new DateTime(); $first_date->setTimestamp($first); $second_date = new DateTime(); $second_date->setTimestamp($second); $difference = $first_date->diff($second_date); $time = '00:'; $minuts = floor($difference->h * 60) + $difference->i; $current_time = ($minuts * 60) + $difference->s; if ($minuts > 0) { if ($minuts < 10) { $time = '0' . $minuts . ':'; } else { $time = $minuts . ':'; } } $seconds_time = '00'; if ($difference->s < 10) { $seconds_time = '0' . $difference->s; } else { $seconds_time = $difference->s; } return array( 'time' => $time . $seconds_time, 'current_time' => $current_time ); } function getPageFromPath($path = '') { if (empty($path)) { return false; } $path = explode("//", $path); $data = array(); $data['options'] = array(); if (!empty($path[0])) { $data['page'] = $path[0]; } if (!empty($path[1])) { unset($path[0]); $data['options'] = $path; foreach ($path as $key => $value) { preg_match_all('/(.*)=(.*)/m', $value, $matches); if (!empty($matches) && !empty($matches[1]) && !empty($matches[1][0]) && !empty($matches[2]) && !empty($matches[2][0])) { $_GET[$matches[1][0]] = $matches[2][0]; } } } return $data; } function GetBroadcastChatById($id, $user_id = 0) { global $wo, $sqlConnect, $db; if ($wo['loggedin'] == false) { return false; } if (empty($id) || !is_numeric($id) || $id < 1) { return false; } if (!empty($user_id) && is_numeric($user_id) && $user_id > 0) { $user_id = Wo_Secure($user_id); } else { $user_id = $wo['user']['id']; } $broadcast = $db->where('id', Wo_Secure($id))->where('user_id', $user_id)->getOne(T_CAST); if (!empty($broadcast)) { $broadcast->org_image = $broadcast->image; $broadcast->image = Wo_GetMedia($broadcast->image); $broadcast->users = array(); $users = $db->where('broadcast_id', $broadcast->id)->get(T_CAST_USERS); foreach ($users as $key => $value) { $broadcast->users[] = Wo_UserData($value->user_id); } return $broadcast; } return false; } function GetBroadcastChatByUserId($user_id = 0, $limit = 10, $offset = 0) { global $wo, $sqlConnect, $db; if ($wo['loggedin'] == false) { return false; } if (!empty($user_id) && is_numeric($user_id) && $user_id > 0) { $user_id = Wo_Secure($user_id); } else { $user_id = $wo['user']['id']; } $data = array(); if (!empty($offset) && is_numeric($offset) && $offset > 0) { $db->where('time', Wo_Secure($offset), '<'); } $limit = Wo_Secure($limit); $broadcast = $db->where('user_id', $user_id)->orderBy('time', 'DESC')->get(T_CAST, $limit); if (!empty($broadcast)) { foreach ($broadcast as $key => $value) { $data[] = GetBroadcastChatById($value->id); } } return $data; } function FFMPEGUpload($data) { global $wo, $sqlConnect, $db; if ($wo['loggedin'] == false || $wo['config']['ffmpeg_system'] != 'on' || empty($data) || empty($data['post_data']) || empty($data['filename'])) { return false; } $ffmpeg_b = $wo['config']['ffmpeg_binary_file']; if (!file_exists('upload/videos/' . date('Y'))) { @mkdir('upload/videos/' . date('Y'), 0777, true); } if (!file_exists('upload/videos/' . date('Y') . '/' . date('m'))) { @mkdir('upload/videos/' . date('Y') . '/' . date('m'), 0777, true); } if (!file_exists('upload/photos/' . date('Y'))) { @mkdir('upload/photos/' . date('Y'), 0777, true); } if (!file_exists('upload/photos/' . date('Y') . '/' . date('m'))) { @mkdir('upload/photos/' . date('Y') . '/' . date('m'), 0777, true); } $explode_video = explode('_video', $data['filename']); $video_file_full_path = dirname(dirname(__DIR__)) . '/' . $data['filename']; $dir = dirname(dirname(__DIR__)); $video_path_water = $explode_video[0] . "_video_water.mp4"; $video_path_240 = $explode_video[0] . "_video_240p_converted.mp4"; $video_path_360 = $explode_video[0] . "_video_360p_converted.mp4"; $video_path_480 = $explode_video[0] . "_video_480p_converted.mp4"; $video_path_720 = $explode_video[0] . "_video_720p_converted.mp4"; $video_path_1080 = $explode_video[0] . "_video_1080p_converted.mp4"; $video_path_2048 = $explode_video[0] . "_video_2048p_converted.mp4"; $video_path_4096 = $explode_video[0] . "_video_4096p_converted.mp4"; $video_output_full_path_water = $dir . "/" . $video_path_water; $video_output_full_path_240 = $dir . "/" . $video_path_240; $video_output_full_path_360 = $dir . "/" . $video_path_360; $video_output_full_path_480 = $dir . "/" . $video_path_480; $video_output_full_path_720 = $dir . "/" . $video_path_720; $video_output_full_path_1080 = $dir . "/" . $video_path_1080; $video_output_full_path_2048 = $dir . "/" . $video_path_2048; $video_output_full_path_4096 = $dir . "/" . $video_path_4096; $video_info = shell_exec("$ffmpeg_b -i " . $video_file_full_path . " 2>&1"); $re = '/[0-9]{3}+x[0-9]{3}/m'; preg_match_all($re, $video_info, $min_str); $resolution = 0; if (!empty($min_str) && !empty($min_str[0]) && !empty($min_str[0][0])) { $substr = substr($video_info, strpos($video_info, $min_str[0][0]) - 3, 15); $re = '/[0-9]+x[0-9]+/m'; preg_match_all($re, $substr, $resolutions); if (!empty($resolutions) && !empty($resolutions[0]) && !empty($resolutions[0][0])) { $resolution = substr($resolutions[0][0], 0, strpos($resolutions[0][0], 'x')); } } $ptrn = '/Duration: ([0-9]{2}):([0-9]{2}):([^ ,])+/'; $time = 1; if (preg_match($ptrn, $video_info, $matches)) { $time = str_replace("Duration: ", "", $matches[0]); $time_breakdown = explode(":", $time); $time = round(($time_breakdown[0] * 60 * 60) + ($time_breakdown[1] * 60) + $time_breakdown[2]); } if ($time > 1) { $time = (int) ($time / 2); } if ($wo['config']['watermark'] == 1) { $water = dirname(dirname(__DIR__))."/themes/{$wo['config']['theme']}/img/icon.png"; $shell = shell_exec("{$ffmpeg_b} -i {$video_file_full_path} -i {$water} -filter_complex \"[1]geq=r='r(X,Y)':a='0.5*alpha(X,Y)'[a];[0][a]overlay=(W-w)/2:(H-h)/2\" $video_output_full_path_water"); @unlink($video_file_full_path); $video_file_full_path = $video_output_full_path_water; } $shell = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset " . $wo['config']['convert_speed'] . " -filter:v scale=426:-2 -crf 26 $video_output_full_path_240 2>&1"); $data['post_data']['postFile'] = $video_path_240; $data['id'] = Wo_RegisterPost($data['post_data']); if (file_exists($video_output_full_path_240)) { if ($wo['config']['amazone_s3'] == 1 || $wo['config']['wasabi_storage'] == 1 || $wo['config']['ftp_upload'] == 1 || $wo['config']['spaces'] == 1 || $wo['config']['cloud_upload'] == 1 || $wo['config']['backblaze_storage'] == 1) { $upload_s3 = Wo_UploadToS3($video_path_240); } $processing = 0; if ($resolution >= 640 || $resolution == 0) { $processing = 1; } $db->where('id', $data['id'])->update(T_POSTS, array( '240p' => 1, 'processing' => $processing )); $notification_data_array = array( 'recipient_id' => $wo['user']['user_id'], 'type' => 'admin_notification', 'time' => time(), 'url' => 'index.php?link1=post&id=' . $data['id'], 'text' => $wo['lang']['video_ready_to_view'], 'type2' => 'ffmpeg' ); $db->insert(T_NOTIFICATION, $notification_data_array); } if (empty($data['video_thumb'])) { $uniq_id = rand(1111, 9999); $hash = sha1(time() + time() - rand(9999, 9999)) . Wo_GenerateKey(); $file_thumb = "upload/photos/" . date('Y') . '/' . date('m') . "/$hash.video_thumb_$uniq_id" . ".jpeg"; $thumb = $dir . "/" . $file_thumb; shell_exec("$ffmpeg_b -ss \"$time\" -i $video_file_full_path -vframes 1 -f mjpeg $thumb 2<&1"); if ($wo['config']['amazone_s3'] == 1 || $wo['config']['wasabi_storage'] == 1 || $wo['config']['ftp_upload'] == 1 || $wo['config']['spaces'] == 1 || $wo['config']['cloud_upload'] == 1 || $wo['config']['backblaze_storage'] == 1) { if (!empty($_POST) && !empty($_POST['postPrivacy']) && $_POST['postPrivacy'] == 6) { $wo['removeFromLocal'] = 1; $blur_url = blur_image($file_thumb); $db->where('post_id',$data['id'])->update(T_POSTS,['blur_url' => $blur_url]); Wo_UploadToS3($blur_url); } $upload_s3 = Wo_UploadToS3($file_thumb); } $db->where('id', $data['id'])->update(T_POSTS, array( 'postFileThumb' => $file_thumb )); } if ($resolution >= 640 || $resolution == 0) { $shell = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset " . $wo['config']['convert_speed'] . " -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1"); if (file_exists($video_output_full_path_360)) { if ($wo['config']['amazone_s3'] == 1 || $wo['config']['wasabi_storage'] == 1 || $wo['config']['ftp_upload'] == 1 || $wo['config']['spaces'] == 1 || $wo['config']['cloud_upload'] == 1 || $wo['config']['backblaze_storage'] == 1) { $upload_s3 = Wo_UploadToS3($video_path_360); } $db->where('id', $data['id'])->update(T_POSTS, array( '360p' => 1 )); } } if ($resolution >= 854 || $resolution == 0) { $shell = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset " . $wo['config']['convert_speed'] . " -filter:v scale=854:-2 -crf 26 $video_output_full_path_480 2>&1"); if (file_exists($video_output_full_path_480)) { if ($wo['config']['amazone_s3'] == 1 || $wo['config']['wasabi_storage'] == 1 || $wo['config']['ftp_upload'] == 1 || $wo['config']['spaces'] == 1 || $wo['config']['cloud_upload'] == 1 || $wo['config']['backblaze_storage'] == 1) { $upload_s3 = Wo_UploadToS3($video_path_480); } $db->where('id', $data['id'])->update(T_POSTS, array( '480p' => 1 )); } } if ($resolution >= 1280 || $resolution == 0) { $shell = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset " . $wo['config']['convert_speed'] . " -filter:v scale=1280:-2 -crf 26 $video_output_full_path_720 2>&1"); if (file_exists($video_output_full_path_720)) { if ($wo['config']['amazone_s3'] == 1 || $wo['config']['wasabi_storage'] == 1 || $wo['config']['ftp_upload'] == 1 || $wo['config']['spaces'] == 1 || $wo['config']['cloud_upload'] == 1 || $wo['config']['backblaze_storage'] == 1) { $upload_s3 = Wo_UploadToS3($video_path_720); } $db->where('id', $data['id'])->update(T_POSTS, array( '720p' => 1 )); } } if ($resolution >= 1920 || $resolution == 0) { $shell = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset " . $wo['config']['convert_speed'] . " -filter:v scale=1920:-2 -crf 26 $video_output_full_path_1080 2>&1"); if (file_exists($video_output_full_path_1080)) { if ($wo['config']['amazone_s3'] == 1 || $wo['config']['wasabi_storage'] == 1 || $wo['config']['ftp_upload'] == 1 || $wo['config']['spaces'] == 1 || $wo['config']['cloud_upload'] == 1 || $wo['config']['backblaze_storage'] == 1) { $upload_s3 = Wo_UploadToS3($video_path_1080); } $db->where('id', $data['id'])->update(T_POSTS, array( '1080p' => 1 )); } } if ($resolution >= 2048 || $resolution == 0) { $shell = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset " . $wo['config']['convert_speed'] . " -filter:v scale=2048:-2 -crf 26 $video_output_full_path_2048 2>&1"); if (file_exists($video_output_full_path_2048)) { if ($wo['config']['amazone_s3'] == 1 || $wo['config']['wasabi_storage'] == 1 || $wo['config']['ftp_upload'] == 1 || $wo['config']['spaces'] == 1 || $wo['config']['cloud_upload'] == 1 || $wo['config']['backblaze_storage'] == 1) { $upload_s3 = Wo_UploadToS3($video_path_2048); } $db->where('id', $data['id'])->update(T_POSTS, array( '2048p' => 1 )); } } if ($resolution >= 3840 || $resolution == 0) { $shell = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset " . $wo['config']['convert_speed'] . " -filter:v scale=3840:-2 -crf 26 $video_output_full_path_4096 2>&1"); if (file_exists($video_output_full_path_4096)) { if ($wo['config']['amazone_s3'] == 1 || $wo['config']['wasabi_storage'] == 1 || $wo['config']['ftp_upload'] == 1 || $wo['config']['spaces'] == 1 || $wo['config']['cloud_upload'] == 1 || $wo['config']['backblaze_storage'] == 1) { $upload_s3 = Wo_UploadToS3($video_path_4096); } $db->where('id', $data['id'])->update(T_POSTS, array( '4096p' => 1 )); } } $update_data = array( 'processing' => 0 ); if ($data['post_data']['postPrivacy'] == 6) { if($file_thumb) { $update_data['blur_url'] = blur_image($file_thumb); } } $db->where('id', $data['id'])->update(T_POSTS, $update_data); @unlink($video_file_full_path); return $data['id']; } function Check_Recaptcha($recaptcha_data) { if (empty($recaptcha_data) || !is_array($recaptcha_data)) { return false; } $responseData = Wo_SendCurlRequest([ 'url' => 'https://www.google.com/recaptcha/api/siteverify', 'post' => true, 'return_transfer' => true, 'timeout' => 10, 'connect_timeout' => 5, 'ssl_verify' => false, 'http_headers' => [ 'Content-Type: application/x-www-form-urlencoded' ], 'post_fields' => http_build_query($recaptcha_data) ]); $response = $responseData['response'] ?? false; return $response ? json_decode($response) : null; } function ffmpeg_duration($filename = false) { global $wo; $ffmpeg_b = $wo['config']['ffmpeg_binary_file']; $output = shell_exec("$ffmpeg_b -i {$filename} 2>&1"); $ptrn = '/Duration: ([0-9]{2}):([0-9]{2}):([^ ,])+/'; $time = 30; if (preg_match($ptrn, $output, $matches)) { $time = str_replace("Duration: ", "", $matches[0]); $time_breakdown = explode(":", $time); $time = round(($time_breakdown[0] * 60 * 60) + ($time_breakdown[1] * 60) + $time_breakdown[2]); } return $time; } function GetReview($id) { global $wo, $sqlConnect, $db; if (empty($id) || !is_numeric($id)) { return false; } $review = $db->where('id', Wo_Secure($id))->getOne(T_PRODUCT_REVIEW); $images = $db->where('review_id', $review->id)->get(T_ALBUMS_MEDIA); $images_data = array(); foreach ($images as $key => $value) { $new = array(); $new['org_image'] = $value->image; $new['image'] = Wo_GetMedia($value->image); $review->images[] = $new; } $review->user_data = Wo_UserData($review->user_id); return $review; } function EnableForMode($value, $class = false, $title = false) { global $wo, $sqlConnect, $db; if (empty($value)) { return true; } if ((!empty($wo['website_modes_off']) && !empty($wo['website_modes_off'][$wo['config']['website_mode']]) && in_array($value, $wo['website_modes_off'][$wo['config']['website_mode']]))) { if ($class == true) { return 'ch_light_color'; } if ($title == true) { return 'title="Your website in ' . ucfirst($wo['config']['website_mode']) . ' Mode You will not be able to enable this feature"'; } return 'disabled'; } return true; } function TextForMode($value) { global $wo, $sqlConnect, $db; if (empty($value)) { return ''; } $wo['website_modes_text'] = array( 'askfm' => array( 'write_comment' => 'write_answer', 'publisher_box_placeholder' => 'askfm_box_placeholder', 'post_mention' => 'question_mention', 'posted_on_timeline' => 'asked_you_a_question', 'liked_post' => 'liked_question', 'commented_on_post' => 'answered_your_question', 'replied_to_comment' => 'replied_to_answer', 'popular_posts' => 'trending_questions', 'popular_posts_comments' => 'trending_questions', 'users_liked_post' => 'people_liked_question', 'users_liked_comment' => 'users_liked_answer', 'no_comments_found' => 'no_answers_found', 'search_header_label' => 'search_header_people', 'share' => 'ask', 'posts' => 'questions', 'reply_to_comment' => 'reply_to_answer', 'comment_mention' => 'answer_mention' ), 'twitter' => array( 'share' => 'tweet', 'posts' => 'tweets', 'popular_posts' => 'trending_tweets', 'popular_posts_comments' => 'trending_tweets', 'users_liked_post' => 'people_liked_tweet', 'liked_post' => 'liked_tweet', 'generate_ai_post' => 'generate_ai_tweet', 'saved_posts' => 'saved_tweets', 'create_post' => 'tweet', 'share_new_post' => 'share_new_tweet', 'users_shared_post' => 'users_shared_tweet', 'shared_a_post' => 'shared_a_tweet', ), 'instagram' => array( 'search_header_label' => 'search_header_people' ) ); if (!empty($wo['website_modes_text'][$wo['config']['website_mode']]) && !empty($wo['website_modes_text'][$wo['config']['website_mode']][$value])) { if (!empty($wo['notification']) && !empty($wo['notification']['post_id'])) { $is_live = $db->where('post_id', $wo['notification']['post_id'])->where("live_time", 0, '!=')->getValue(T_POSTS, 'COUNT(*)'); if ($is_live > 0) { return $wo['lang'][$value]; } } return $wo['lang'][$wo['website_modes_text'][$wo['config']['website_mode']][$value]]; } return $wo['lang'][$value]; } function GetModeBtn($value) { global $wo, $sqlConnect, $db; if (empty($value)) { return ''; } $wo['website_modes_btn'] = array( 'askfm' => array( 'liked_btn' => "", "like_btn" => "", "comments_btn" => "", "share_btn" => "", "like_icon" => "", "liked_comment" => "", "like_comment" => "", ), "twitter" => array( "liked_btn" => "", "like_btn" => "", "comments_btn" => "", "share_btn" => "", "like_icon" => "", "liked_comment" => "", "like_comment" => "", ), "instagram" => array( "liked_btn" => "", "like_btn" => "", "comments_btn" => "", "share_btn" => "", "like_icon" => "", "liked_comment" => "", "like_comment" => "", ), ); if (!empty($wo['website_modes_btn'][$wo['config']['website_mode']]) && !empty($wo['website_modes_btn'][$wo['config']['website_mode']][$value])) { return $wo['website_modes_btn'][$wo['config']['website_mode']][$value]; } if ($wo['config']['theme'] == 'sunshine') { $btns = array( 'liked_btn' => " " . $wo['lang']['liked'] . "", 'like_btn' => " " . $wo['lang']['like'], 'comments_btn' => ' ' . $wo['lang']['comment_post_label'] . '', 'share_btn' => ' ' . $wo['lang']['share'] . '', 'like_icon' => ' ', 'liked_comment' => " ", 'like_comment' => " ", ); } else { $btns = array( 'liked_btn' => " " . $wo['lang']['liked'] . "", 'like_btn' => " " . $wo['lang']['like'], 'comments_btn' => ' ' . $wo['lang']['comment_post_label'] . ' ', 'share_btn' => ' ' . $wo['lang']['share'] . '', 'like_icon' => ' ', 'liked_comment' => " ", 'like_comment' => " ", ); } return $btns[$value]; } function PatreonPostBlur() { global $wo, $sqlConnect, $db; if ($wo['config']['website_mode'] != 'patreon') { return ''; } if ($wo['loggedin'] == false) { return 'filter: blur(3px);'; } if ($wo['story']['user_id'] == $wo['user']['id'] || Wo_IsAdmin()) { return ''; } $is_subscribed = $db->where('user_id', $wo['story']['user_id'])->where('subscriber_id', $wo['user']['id'])->getValue(T_PATREON_SUBSCRIBERS, 'COUNT(*)'); if ($is_subscribed > 0) { return ''; } return 'filter: blur(3px);'; } function PatreonSubscribed($user_id) { global $wo, $sqlConnect, $db; if ($wo['config']['website_mode'] != 'patreon') { return true; } if ($wo['loggedin'] == false) { return false; } if (empty($user_id) || !is_numeric($user_id)) { return false; } if ($user_id == $wo['user']['id'] || Wo_IsAdmin()) { return true; } $is_subscribed = $db->where('user_id', $user_id)->where('subscriber_id', $wo['user']['id'])->getValue(T_PATREON_SUBSCRIBERS, 'COUNT(*)'); if ($is_subscribed > 0) { return true; } return false; } function PatreonPostSubscribed($user_id, $post_id) { global $wo, $sqlConnect, $db; if ($wo['config']['website_mode'] != 'patreon') { return true; } if ($wo['loggedin'] == false) { return false; } if (empty($user_id) || !is_numeric($user_id) || empty($post_id) || !is_numeric($post_id)) { return false; } if ($user_id == $wo['user']['id'] || Wo_IsAdmin()) { return true; } $post_patron = $db->where('id', Wo_Secure($post_id))->where('user_id', Wo_Secure($user_id))->where('postPrivacy', '5')->getValue(T_POSTS, 'COUNT(*)'); if ($post_patron > 0) { $is_subscribed = $db->where('user_id', $user_id)->where('subscriber_id', $wo['user']['id'])->getValue(T_PATREON_SUBSCRIBERS, 'COUNT(*)'); if ($is_subscribed > 0) { return true; } } else { return true; } return false; } function Wo_GetSearchServices($query = '') { global $wo, $sqlConnect, $db; $data = array(); if (empty($query)) { return array(); } $query = Wo_Secure($query); $sql = "(`services` LIKE '%$query%' OR `description` LIKE '%$query%' OR `job_location` LIKE '%$query%')"; $services = $db->where($sql)->where('type', 'service')->get(T_USER_OPEN_TO); if (!empty($services)) { foreach ($services as $key => $value) { $data[$value->user_id] = Wo_UserData($value->user_id); } return $data; } return array(); } function Wo_UserSugServices($limit = 20) { global $wo, $sqlConnect, $db; if (!is_numeric($limit)) { return false; } $data = array(); $user_id = Wo_Secure($wo['user']['user_id']); $query_one = " SELECT `user_id` FROM " . T_USERS . " WHERE `active` = '1' AND `user_id` NOT IN (SELECT `blocked` FROM " . T_BLOCKS . " WHERE `blocker` = '{$user_id}') AND `user_id` NOT IN (SELECT `blocker` FROM " . T_BLOCKS . " WHERE `blocked` = '{$user_id}') AND `user_id` NOT IN (SELECT `following_id` FROM " . T_FOLLOWERS . " WHERE `follower_id` = {$user_id}) AND `user_id` IN (SELECT `user_id` FROM " . T_USER_OPEN_TO . " WHERE `type` = 'service') AND `user_id` <> {$user_id}"; if (isset($limit)) { $query_one .= " ORDER BY RAND() LIMIT {$limit}"; } $sql = mysqli_query($sqlConnect, $query_one); if (mysqli_num_rows($sql)) { while ($fetched_data = mysqli_fetch_assoc($sql)) { $user = Wo_UserData($fetched_data['user_id']); if (!empty($user['providing_service']) && !empty($user['providing_service']->services)) { $data[] = $user; } } } return $data; } function Wo_GetOpenToWorkPosts($limit = 10, $offset = 0) { global $wo, $sqlConnect, $db; if ($wo['config']['website_mode'] != 'linkedin') { return array(); } if ($wo['loggedin'] == false) { return array(); } $data = array(); $user_id = Wo_Secure($wo['user']['user_id']); $query_one = " SELECT `id` FROM " . T_POSTS . " WHERE `active` = '1' AND `postPrivacy` = '5' AND `user_id` NOT IN (SELECT `blocked` FROM " . T_BLOCKS . " WHERE `blocker` = '{$user_id}') AND `user_id` NOT IN (SELECT `blocker` FROM " . T_BLOCKS . " WHERE `blocked` = '{$user_id}') "; if (!empty($offset) && is_numeric($offset) && $offset > 0) { $offset = Wo_Secure($offset); $query_one .= " AND `id` < '{$offset}'"; } if (!empty($limit) && is_numeric($limit) && $limit > 0) { $limit = Wo_Secure($limit); $query_one .= " ORDER BY `id` DESC LIMIT {$limit}"; } $sql = mysqli_query($sqlConnect, $query_one); if (mysqli_num_rows($sql)) { while ($fetched_data = mysqli_fetch_assoc($sql)) { $post = Wo_PostData($fetched_data['id']); if (!empty($post)) { $data[] = $post; } } } return $data; } function AddNewRef($ref_id, $user_id, $amount) { global $wo, $sqlConnect, $db; if (empty($ref_id) || !is_numeric($ref_id) || empty($user_id) || !is_numeric($user_id) || empty($amount) || !is_numeric($amount)) { return false; } if ($wo['config']['affiliate_level'] < 2) { return false; } $user_id = Wo_Secure($user_id); $ref_id = Wo_Secure($ref_id); $amount = Wo_Secure($amount); $pre_user = 0; $parents = array(); for ($i = 0; $i < $wo['config']['affiliate_level']; $i++) { $user = $db->where('user_id', $ref_id)->getOne(T_USERS, array( 'referrer', 'ref_level' )); $ref_level = array(); $update_array = array(); if (empty($user->ref_level)) { $ref_level = array( $user_id => array() ); if ($i == 0) { //$update_array['balance'] = $db->inc($amount); } $update_array['ref_level'] = json_encode($ref_level); $db->where('user_id', $ref_id)->update(T_USERS, $update_array); } else { $ref_level = json_decode($user->ref_level, true); if ($i == 0) { //$update_array['balance'] = $db->inc($amount); $ref_level[$user_id] = array(); } $update_array['ref_level'] = json_encode($ref_level); $db->where('user_id', $ref_id)->update(T_USERS, $update_array); } cache($ref_id, 'users', 'delete'); if (!empty($user->referrer)) { if (!in_array($ref_id, $parents)) { $parents[] = $ref_id; } $pre_user_data = $db->where('user_id', $user->referrer)->getOne(T_USERS, array( 'ref_level' )); $pre_ref_level = json_decode($pre_user_data->ref_level, true); $pre_ref_level[$ref_id] = $ref_level; $db->where('user_id', $user->referrer)->update(T_USERS, array( 'ref_level' => json_encode($pre_ref_level) )); $ref_id = $user->referrer; cache($ref_id, 'users', 'delete'); } else { if (!in_array($ref_id, $parents)) { $parents[] = $ref_id; } break; } } if (!empty($parents)) { foreach ($parents as $key => $value) { $u_amount = ($amount / ($key + 1)); $db->where('user_id', $value)->update(T_USERS, array( 'balance' => $db->inc($u_amount) )); cache($value, 'users', 'delete'); //unset($parents[$key]); } } } function messageMarkup($message_info=[]) { global $wo, $sqlConnect, $db,$non_allowed; foreach ($non_allowed as $key => $value) { unset($message_info[0]['messageUser'][$value]); } if (empty($wo['user']['timezone'])) { $wo['user']['timezone'] = 'UTC'; } $timezone = new DateTimeZone($wo['user']['timezone']); $messages = array(); foreach ($message_info as $key => $message) { $message['time_text'] = Wo_Time_Elapsed_String($message['time']); $message_po = 'left'; if ($message['from_id'] == $wo['user']['user_id']) { $message_po = 'right'; } $message['position'] = $message_po; $message['type'] = Wo_GetFilePosition($message['media']); if ($message['type_two'] == 'contact') { $message['type'] = 'contact'; } if (!empty($message['lng']) && !empty($message['lat'])) { $message['type'] = 'map'; } $message['type'] = $message_po . '_' . $message['type']; $message['file_size'] = 0; if (!empty($message['media'])) { $message['file_size'] = '0MB'; if (file_exists($message['file_size'])) { $message['file_size'] = Wo_SizeFormat(filesize($message['media'])); } $message['media'] = Wo_GetMedia($message['media']); } if (!empty($message['time'])) { $time_today = time() - 86400; if ($message['time'] < $time_today) { $message['time_text'] = date('m.d.y', $message['time']); } else { $time = new DateTime('now', $timezone); $time->setTimestamp($message['time']); $message['time_text'] = $time->format('H:i'); } } $message['message_hash_id'] = ''; if (!empty($_POST['message_hash_id'])) { $message['message_hash_id'] = $_POST['message_hash_id']; } if (!empty($message['reply'])) { foreach ($non_allowed as $key => $value) { unset($message['reply']['messageUser'][$value]); } $message['reply']['time_text'] = Wo_Time_Elapsed_String($message['reply']['time']); $message_po = 'left'; if ($message['reply']['from_id'] == $wo['user']['user_id']) { $message_po = 'right'; } $message['reply']['position'] = $message_po; $message['reply']['type'] = Wo_GetFilePosition($message['reply']['media']); if ($message['reply']['type_two'] == 'contact') { $message['reply']['type'] = 'contact'; } if (!empty($message['reply']['lng']) && !empty($message['reply']['lat'])) { $message['reply']['type'] = 'map'; } $message['reply']['type'] = $message_po . '_' . $message['reply']['type']; $message['reply']['file_size'] = 0; if (!empty($message['reply']['media'])) { $message['reply']['file_size'] = '0MB'; if (file_exists($message['reply']['file_size'])) { $message['reply']['file_size'] = Wo_SizeFormat(filesize($message['reply']['media'])); } $message['reply']['media'] = Wo_GetMedia($message['reply']['media']); } if (!empty($message['reply']['time'])) { $time_today = time() - 86400; if ($message['reply']['time'] < $time_today) { $message['reply']['time_text'] = date('m.d.y', $message['reply']['time']); } else { $time = new DateTime('now', $timezone); $time->setTimestamp($message['reply']['time']); $message['reply']['time_text'] = $time->format('H:i'); } } $message['reply']['message_hash_id'] = ''; if (!empty($_POST['message_hash_id'])) { $message['reply']['message_hash_id'] = $_POST['message_hash_id']; } } array_push($messages, $message); } foreach ($messages as $m_id => $value) { foreach ($non_allowed as $key => $value) { unset($messages[$m_id]['user_data'][$value]); } } return $messages; } function deleteDisappearingMessages($conversation_user_id,$user_id) { Wo_NotifyMessageSocket('delete-disappearing-messages', [ 'user_id' => $user_id, 'conversation_user_id' => $conversation_user_id ], [ 'return_transfer' => false, 'timeout' => 0.2, 'connect_timeout' => 0.2, 'fresh_connect' => true, 'forbid_reuse' => true ]); } function deleteOneTimeMessages() { Wo_NotifyMessageSocket('delete-one-time-messages', [], [ 'return_transfer' => false, 'timeout' => 0.2, 'connect_timeout' => 0.2, 'fresh_connect' => true, 'forbid_reuse' => true ]); } function isSticker($path='') { global $wo, $sqlConnect, $db,$non_allowed; $path = substr($path, strpos($path, 'upload/')); return $db->where('media_file',$path)->getValue(T_STICKERS,'COUNT(*)') > 0 ? true : false; } /** * Builds a SQL condition fragment that restricts a Wo_Tickets query to departments * the current staff user is allowed to see. A department with an empty/missing * `privacy` list is visible to everyone; a department with at least one user in * `privacy` is visible ONLY to those users (admins bypass this via $is_admin, not here). */ function Wo_TicketDeptPrivacySQL($department_column = '`department_id`') { global $wo; $user_id = (int)$wo['user']['user_id']; return " AND ( NOT EXISTS (SELECT 1 FROM `Wo_TicketDepartment` d WHERE d.id = {$department_column} AND d.privacy IS NOT NULL AND d.privacy <> '' AND d.privacy <> '[]') OR EXISTS (SELECT 1 FROM `Wo_TicketDepartment` d WHERE d.id = {$department_column} AND d.privacy LIKE '%\"{$user_id}\"%') )"; } /** * Whether $user_id is allowed to see tickets belonging to $department_id, per the * department's `privacy` list (empty list = visible to all staff). Does not consider * admin status or ticket ownership - callers should check those separately. */ function Wo_CanUserSeeTicketDepartment($department_id, $user_id) { global $sqlConnect; $department_id = (int)$department_id; $user_id = (int)$user_id; $stmt = mysqli_prepare($sqlConnect, "SELECT `privacy` FROM `Wo_TicketDepartment` WHERE `id` = ?"); mysqli_stmt_bind_param($stmt, "i", $department_id); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); if (mysqli_num_rows($result) == 0) { return true; } $privacy = json_decode(mysqli_fetch_assoc($result)['privacy'] ?? '[]', true); if (!is_array($privacy) || count($privacy) == 0) { return true; } foreach ($privacy as $allowed_id) { if ((int)$allowed_id === $user_id) { return true; } } return false; } function Wo_SavedPostFolderLimit($user = array()) { global $wo; if (empty($user) && !empty($wo['user'])) { $user = $wo['user']; } $limit = isset($wo['config']['saved_post_folder_limit']) && is_numeric($wo['config']['saved_post_folder_limit']) ? max(0, (int) $wo['config']['saved_post_folder_limit']) : 2; if (!empty($user['is_pro']) && !empty($user['pro_type']) && isset($wo['pro_packages'][$user['pro_type']])) { $package = $wo['pro_packages'][$user['pro_type']]; if (!empty($package['saved_post_folders']) && is_numeric($package['saved_post_folders']) && (int) $package['saved_post_folders'] > 0) { $limit = (int) $package['saved_post_folders']; } } return $limit; } function Wo_SavedPostFolderNameMaxLength() { return 30; } function Wo_NormalizeSavedPostFolderName($name) { $name = preg_replace('/[\x00-\x1F\x7F]/u', ' ', strip_tags((string) $name)); return trim(preg_replace('/\s+/u', ' ', $name)); } function Wo_CountSavedPostFolders($user_id) { global $sqlConnect; $user_id = (int) $user_id; $query = mysqli_query($sqlConnect, "SELECT COUNT(`id`) AS count FROM " . T_SAVED_POST_FOLDERS . " WHERE `user_id` = {$user_id}"); return $query ? (int) mysqli_fetch_assoc($query)['count'] : 0; } function Wo_GetSavedPostFolder($folder_id, $user_id) { global $sqlConnect; $folder_id = (int) $folder_id; $user_id = (int) $user_id; if ($folder_id < 1 || $user_id < 1) { return false; } $query = mysqli_query($sqlConnect, "SELECT * FROM " . T_SAVED_POST_FOLDERS . " WHERE `id` = {$folder_id} AND `user_id` = {$user_id} LIMIT 1"); if ($query && mysqli_num_rows($query) == 1) { return mysqli_fetch_assoc($query); } return false; } function Wo_GetSavedPostFolders($user_id) { global $sqlConnect; $user_id = (int) $user_id; $data = array(); $query = mysqli_query($sqlConnect, "SELECT f.`id`, f.`name`, (SELECT COUNT(sp.`id`) FROM " . T_SAVED_POSTS . " sp WHERE sp.`user_id` = {$user_id} AND sp.`folder_id` = f.`id`) AS posts_count FROM " . T_SAVED_POST_FOLDERS . " f WHERE f.`user_id` = {$user_id} ORDER BY f.`id` ASC"); if ($query) { while ($row = mysqli_fetch_assoc($query)) { $row['id'] = (int) $row['id']; $row['posts_count'] = (int) $row['posts_count']; $data[] = $row; } } return $data; } function Wo_CountSavedPosts($user_id, $folder = 'all') { global $sqlConnect; $user_id = (int) $user_id; $folder_sql = ''; if ($folder !== 'all') { $folder_sql = " AND `folder_id` = " . (int) $folder; } $query = mysqli_query($sqlConnect, "SELECT COUNT(`id`) AS count FROM " . T_SAVED_POSTS . " WHERE `user_id` = {$user_id}{$folder_sql}"); return $query ? (int) mysqli_fetch_assoc($query)['count'] : 0; } function Wo_ValidateSavedPostFolderName($user_id, $name, $ignore_id = 0) { global $sqlConnect; $name = Wo_NormalizeSavedPostFolderName($name); if ($name === '') { return 'Klasör adı boş olamaz.'; } if (mb_strlen($name) > Wo_SavedPostFolderNameMaxLength()) { return 'Klasör adı en fazla ' . Wo_SavedPostFolderNameMaxLength() . ' karakter olabilir.'; } $user_id = (int) $user_id; $ignore_id = (int) $ignore_id; $escaped = mysqli_real_escape_string($sqlConnect, $name); $query = mysqli_query($sqlConnect, "SELECT `id` FROM " . T_SAVED_POST_FOLDERS . " WHERE `user_id` = {$user_id} AND `id` <> {$ignore_id} AND `name` = '{$escaped}' LIMIT 1"); if ($query && mysqli_num_rows($query) > 0) { return 'Bu isimde bir klasörünüz zaten var.'; } return ''; } function Wo_CreateSavedPostFolder($user_id, $name) { global $wo, $sqlConnect; $user_id = (int) $user_id; $error = Wo_ValidateSavedPostFolderName($user_id, $name); if ($error !== '') { return array('status' => 400, 'message' => $error); } $limit = Wo_SavedPostFolderLimit(); if (Wo_CountSavedPostFolders($user_id) >= $limit) { return array('status' => 403, 'message' => 'Klasör sınırınıza ulaştınız (' . $limit . '). Pro paketle daha fazla klasör oluşturabilirsiniz.'); } $name = mysqli_real_escape_string($sqlConnect, Wo_NormalizeSavedPostFolderName($name)); $time = time(); if (!mysqli_query($sqlConnect, "INSERT INTO " . T_SAVED_POST_FOLDERS . " (`user_id`, `name`, `time`) VALUES ({$user_id}, '{$name}', {$time})")) { return array('status' => 500, 'message' => $wo['lang']['oops_something_went_wrong']); } return array('status' => 200, 'id' => (int) mysqli_insert_id($sqlConnect)); } function Wo_RenameSavedPostFolder($user_id, $folder_id, $name) { global $wo, $sqlConnect; $user_id = (int) $user_id; $folder_id = (int) $folder_id; if (Wo_GetSavedPostFolder($folder_id, $user_id) === false) { return array('status' => 404, 'message' => 'Klasör bulunamadı.'); } $error = Wo_ValidateSavedPostFolderName($user_id, $name, $folder_id); if ($error !== '') { return array('status' => 400, 'message' => $error); } $name = mysqli_real_escape_string($sqlConnect, Wo_NormalizeSavedPostFolderName($name)); if (!mysqli_query($sqlConnect, "UPDATE " . T_SAVED_POST_FOLDERS . " SET `name` = '{$name}' WHERE `id` = {$folder_id} AND `user_id` = {$user_id}")) { return array('status' => 500, 'message' => $wo['lang']['oops_something_went_wrong']); } return array('status' => 200); } function Wo_DeleteSavedPostFolder($user_id, $folder_id) { global $sqlConnect; $user_id = (int) $user_id; $folder_id = (int) $folder_id; if (Wo_GetSavedPostFolder($folder_id, $user_id) === false) { return array('status' => 404, 'message' => 'Klasör bulunamadı.'); } mysqli_query($sqlConnect, "UPDATE " . T_SAVED_POSTS . " SET `folder_id` = 0 WHERE `user_id` = {$user_id} AND `folder_id` = {$folder_id}"); mysqli_query($sqlConnect, "DELETE FROM " . T_SAVED_POST_FOLDERS . " WHERE `id` = {$folder_id} AND `user_id` = {$user_id}"); return array('status' => 200); } function Wo_MoveSavedPost($user_id, $post_id, $folder_id) { global $sqlConnect; $user_id = (int) $user_id; $post_id = (int) $post_id; $folder_id = (int) $folder_id; if ($post_id < 1 || !Wo_IsPostSaved($post_id, $user_id)) { return array('status' => 404, 'message' => 'Kayıtlı gönderi bulunamadı.'); } if ($folder_id > 0 && Wo_GetSavedPostFolder($folder_id, $user_id) === false) { return array('status' => 404, 'message' => 'Klasör bulunamadı.'); } mysqli_query($sqlConnect, "UPDATE " . T_SAVED_POSTS . " SET `folder_id` = {$folder_id} WHERE `user_id` = {$user_id} AND `post_id` = {$post_id}"); return array('status' => 200); } function Wo_GetSavedPostsPage($user_id, $folder = 'all', $before_id = 0, $limit = 10) { global $sqlConnect; $user_id = (int) $user_id; $limit = max(1, (int) $limit); $before_id = (int) $before_id; $where = "`user_id` = {$user_id}"; if ($folder !== 'all') { $where .= " AND `folder_id` = " . (int) $folder; } if ($before_id > 0) { $where .= " AND `id` < {$before_id}"; } $posts = array(); $last_id = 0; $fetched = 0; $query = mysqli_query($sqlConnect, "SELECT `id`, `post_id`, `folder_id` FROM " . T_SAVED_POSTS . " WHERE {$where} ORDER BY `id` DESC LIMIT {$limit}"); if ($query) { while ($row = mysqli_fetch_assoc($query)) { $fetched++; $last_id = (int) $row['id']; $post = Wo_PostData($row['post_id']); if (is_array($post)) { $post['spf_folder_id'] = (int) $row['folder_id']; $posts[] = $post; } } } return array('posts' => $posts, 'last_id' => $last_id, 'has_more' => ($fetched == $limit)); } function Wo_RegisterProfileVisit($profile_user_id) { global $wo, $sqlConnect; $profile_user_id = (int) $profile_user_id; if ($profile_user_id < 1) { return false; } if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'GET') { return false; } $agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) $_SERVER['HTTP_USER_AGENT'] : ''; if ($agent === '' || preg_match('/bot|crawl|spider|slurp|facebookexternalhit|preview|headless|curl|wget/i', $agent)) { return false; } $viewer_id = (!empty($wo['loggedin']) && !empty($wo['user']['user_id'])) ? (int) $wo['user']['user_id'] : 0; if ($viewer_id === $profile_user_id) { return false; } $member = ($viewer_id > 0) ? 1 : 0; $guest = 1 - $member; try { $day = (new DateTime('now', Wo_ScheduledPostTimezone()))->format('Y-m-d'); return (bool) mysqli_query($sqlConnect, "INSERT INTO " . T_PROFILE_VISIT_STATS . " (`user_id`, `visit_date`, `total_count`, `member_count`, `guest_count`) VALUES ({$profile_user_id}, '{$day}', 1, {$member}, {$guest}) ON DUPLICATE KEY UPDATE `total_count` = `total_count` + 1, `member_count` = `member_count` + {$member}, `guest_count` = `guest_count` + {$guest}"); } catch (Throwable $e) { return false; } } function Wo_PictureHistoryLimit() { return 5; } function Wo_PictureHistoryType($type) { if ($type === 'cover') { return 'cover'; } return ($type === 'avatar') ? 'avatar' : ''; } function Wo_PictureHistoryIsDefault($file, $type) { global $wo; if ($file === '') { return true; } if ($type === 'cover') { return $file == $wo['userDefaultCover']; } return $file == $wo['userDefaultAvatar'] || $file == $wo['userDefaultFAvatar']; } function Wo_PictureHistoryFullPath($file) { $info = pathinfo($file); if (empty($info['extension'])) { return $file; } return $info['dirname'] . '/' . $info['filename'] . '_full.' . $info['extension']; } function Wo_PictureHistoryCurrent($user_id, $type) { global $sqlConnect; $column = ($type === 'cover') ? 'cover' : 'avatar'; $query = mysqli_query($sqlConnect, "SELECT `{$column}` FROM " . T_USERS . " WHERE `user_id` = " . (int) $user_id . " LIMIT 1"); if ($query && $row = mysqli_fetch_assoc($query)) { return (string) $row[$column]; } return ''; } function Wo_PictureHistoryDeleteFiles($file) { foreach (array($file, Wo_PictureHistoryFullPath($file)) as $path) { if ($path === '') { continue; } Wo_DeleteFromToS3($path); if (file_exists($path)) { @unlink($path); } } } function Wo_PictureHistoryTrim($user_id, $type) { global $sqlConnect; $user_id = (int) $user_id; $type = Wo_PictureHistoryType($type); if ($user_id < 1 || $type === '') { return; } $current = Wo_PictureHistoryCurrent($user_id, $type); $type_sql = mysqli_real_escape_string($sqlConnect, $type); $post_type = ($type === 'cover') ? 'profile_cover_picture' : 'profile_picture'; $rows = array(); $query = mysqli_query($sqlConnect, "SELECT `id`, `file` FROM " . T_USER_PICTURE_HISTORY . " WHERE `user_id` = {$user_id} AND `type` = '{$type_sql}' ORDER BY `created_at` ASC, `id` ASC"); if ($query) { while ($row = mysqli_fetch_assoc($query)) { $rows[] = $row; } } $excess = count($rows) - Wo_PictureHistoryLimit(); foreach ($rows as $row) { if ($excess < 1) { break; } if ($row['file'] === $current) { continue; } Wo_PictureHistoryDeleteFiles($row['file']); $full_sql = mysqli_real_escape_string($sqlConnect, Wo_PictureHistoryFullPath($row['file'])); mysqli_query($sqlConnect, "UPDATE " . T_POSTS . " SET `delete_admin` = {$user_id}, `archive_time` = NOW() WHERE `user_id` = {$user_id} AND `postType` = '{$post_type}' AND `postFile` = '{$full_sql}'"); mysqli_query($sqlConnect, "DELETE FROM " . T_USER_PICTURE_HISTORY . " WHERE `id` = " . (int) $row['id']); $excess--; } } function Wo_PictureHistoryAdd($user_id, $type, $file) { global $sqlConnect; $user_id = (int) $user_id; $type = Wo_PictureHistoryType($type); $file = (string) $file; if ($user_id < 1 || $type === '' || Wo_PictureHistoryIsDefault($file, $type)) { return false; } $type_sql = mysqli_real_escape_string($sqlConnect, $type); $file_sql = mysqli_real_escape_string($sqlConnect, $file); $exists = mysqli_query($sqlConnect, "SELECT `id` FROM " . T_USER_PICTURE_HISTORY . " WHERE `user_id` = {$user_id} AND `type` = '{$type_sql}' AND `file` = '{$file_sql}' LIMIT 1"); if ($exists && mysqli_num_rows($exists) > 0) { return true; } $inserted = mysqli_query($sqlConnect, "INSERT INTO " . T_USER_PICTURE_HISTORY . " (`user_id`, `type`, `file`, `created_at`) VALUES ({$user_id}, '{$type_sql}', '{$file_sql}', " . time() . ")"); if (!$inserted) { return false; } Wo_PictureHistoryTrim($user_id, $type); return true; } function Wo_PictureHistoryReplace($user_id, $type, $old_file, $new_file) { global $sqlConnect; $type = Wo_PictureHistoryType($type); if ($type === '' || $old_file === '' || $new_file === '') { return false; } return mysqli_query($sqlConnect, "UPDATE " . T_USER_PICTURE_HISTORY . " SET `file` = '" . mysqli_real_escape_string($sqlConnect, $new_file) . "' WHERE `user_id` = " . (int) $user_id . " AND `type` = '" . mysqli_real_escape_string($sqlConnect, $type) . "' AND `file` = '" . mysqli_real_escape_string($sqlConnect, $old_file) . "'"); } function Wo_PictureHistoryList($user_id, $type) { global $sqlConnect; $user_id = (int) $user_id; $type = Wo_PictureHistoryType($type); if ($user_id < 1 || $type === '') { return array(); } $current = Wo_PictureHistoryCurrent($user_id, $type); if (!Wo_PictureHistoryIsDefault($current, $type)) { Wo_PictureHistoryAdd($user_id, $type, $current); } $items = array(); $query = mysqli_query($sqlConnect, "SELECT `id`, `file`, `created_at` FROM " . T_USER_PICTURE_HISTORY . " WHERE `user_id` = {$user_id} AND `type` = '" . mysqli_real_escape_string($sqlConnect, $type) . "' ORDER BY `created_at` DESC, `id` DESC LIMIT " . Wo_PictureHistoryLimit()); if ($query) { while ($row = mysqli_fetch_assoc($query)) { $items[] = array( 'id' => (int) $row['id'], 'url' => Wo_GetMedia($row['file']), 'current' => ($row['file'] === $current), 'time' => Wo_Time_Elapsed_String((int) $row['created_at']) ); } } return $items; } function Wo_PictureHistoryUse($user_id, $type, $history_id) { global $sqlConnect; $user_id = (int) $user_id; $history_id = (int) $history_id; $type = Wo_PictureHistoryType($type); if ($user_id < 1 || $history_id < 1 || $type === '') { return array('status' => 400); } $query = mysqli_query($sqlConnect, "SELECT `file` FROM " . T_USER_PICTURE_HISTORY . " WHERE `id` = {$history_id} AND `user_id` = {$user_id} AND `type` = '" . mysqli_real_escape_string($sqlConnect, $type) . "' LIMIT 1"); $row = $query ? mysqli_fetch_assoc($query) : null; if (empty($row)) { return array('status' => 404); } $update = ($type === 'cover') ? array('cover' => $row['file'], 'last_cover_mod' => time()) : array('avatar' => $row['file'], 'last_avatar_mod' => time()); if (!Wo_UpdateUserData($user_id, $update)) { return array('status' => 500); } cache($user_id, 'users', 'delete'); $fresh = Wo_UserData($user_id); if ($type === 'cover') { return array( 'status' => 200, 'img' => $fresh['cover'], 'cover_or' => $fresh['cover_org'], 'cover_full' => Wo_GetMedia($fresh['cover_full']), 'cover_full_or' => $fresh['cover_full'] ); } return array( 'status' => 200, 'img' => $fresh['avatar'] . '?cache=' . rand(11, 22), 'img_or' => $fresh['avatar_org'], 'avatar_full' => Wo_GetMedia($fresh['avatar_full']) . '?cache=' . rand(11, 22), 'avatar_full_or' => $fresh['avatar_full'] ); } LifeInvader
LifeInvader

Yakında Geri Döneceğiz!

Yaşadığınız rahatsızlıktan dolayı özür dileriz; ancak şu anda LifeInvader’ı en güncel sürümüne yükseltme çalışması yürütüyoruz. Daha istikrarlı ve görsel açıdan daha çekici bir LifeInvader için bizi takip etmeye devam edin!

Bakımda
Sistem Durumu