stem['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/stripe.php?status=success&handle=packages&package_id=$id"; $URL['cancel'] = $system['system_url'] . "/webhooks/stripe.php?status=cancel"; break; case 'wallet': $product = __($system['system_title']) . " " . __('Wallet'); $description = __('Pay For') . " " . __($system['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/stripe.php?status=success&handle=wallet"; $URL['cancel'] = $system['system_url'] . "/webhooks/stripe.php?status=cancel"; $_SESSION['wallet_replenish_amount'] = $price; break; case 'donate': $product = __($system['system_title']) . " " . __('Funding Donation'); $description = __('Pay For') . " " . __($system['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/stripe.php?status=success&handle=donate&post_id=$id"; $URL['cancel'] = $system['system_url'] . "/webhooks/stripe.php?status=cancel"; $_SESSION['donation_amount'] = $price; break; case 'subscribe': $product = __($system['system_title']) . " " . __('Subscribe'); $description = __('Pay For') . " " . __($system['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/stripe.php?status=success&handle=subscribe&plan_id=$id"; $URL['cancel'] = $system['system_url'] . "/webhooks/stripe.php?status=cancel"; break; case 'movies': $product = __($system['system_title']) . " " . __('Movies'); $description = __('Pay For') . " " . __($system['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/stripe.php?status=success&handle=movies&movie_id=$id"; $URL['cancel'] = $system['system_url'] . "/webhooks/stripe.php?status=cancel"; break; default: _error(400); break; } $method = ($method == 'credit') ? 'card' : 'alipay'; /* Stripe */ $secret_key = ($system['stripe_mode'] == "live") ? $system['stripe_live_secret'] : $system['stripe_test_secret']; \Stripe\Stripe::setApiKey($secret_key); $product = \Stripe\Product::create([ 'name' => $product, 'type' => 'service', ]); $session = \Stripe\Checkout\Session::create([ 'payment_method_types' => [$method], 'line_items' => [[ 'price_data' => [ 'product' => $product->id, 'unit_amount' => ($system['system_currency'] == 'JPY') ? $price : $price * 100, 'currency' => $system['system_currency'], ], 'quantity' => 1, ]], 'mode' => 'payment', 'success_url' => $URL['success'], 'cancel_url' => $URL['cancel'], ]); $_SESSION['stripe_session'] = $session; return $session; } /** * stripe_check * * @return boolean */ function stripe_check() { global $system; if ($_SESSION['stripe_session']) { $secret_key = ($system['stripe_mode'] == "live") ? $system['stripe_live_secret'] : $system['stripe_test_secret']; \Stripe\Stripe::setApiKey($secret_key); $session = \Stripe\Checkout\Session::retrieve($_SESSION['stripe_session']['id']); unset($_SESSION['stripe_session']); if ($session->payment_status == "paid") { return true; } } return false; } /* ------------------------------- */ /* Paystack */ /* ------------------------------- */ /** * paystack * * @param string $handle * @param string $price * @param integer $id * @return string */ function paystack($handle, $price, $id = null) { global $system, $user; /* prepare */ switch ($handle) { case 'packages': $callback = $system['system_url'] . "/webhooks/paystack.php?status=success&handle=packages&package_id=$id"; break; case 'wallet': $callback = $system['system_url'] . "/webhooks/paystack.php?status=success&handle=wallet"; $_SESSION['wallet_replenish_amount'] = $price; break; case 'donate': $callback = $system['system_url'] . "/webhooks/paystack.php?status=success&handle=donate&post_id=$id"; $_SESSION['donation_amount'] = $price; break; case 'subscribe': $callback = $system['system_url'] . "/webhooks/paystack.php?status=success&handle=subscribe&plan_id=$id"; break; case 'movies': $callback = $system['system_url'] . "/webhooks/paystack.php?status=success&handle=movies&movie_id=$id"; break; default: _error(400); break; } /* Paystack */ $data = [ 'email' => $user->_data['user_email'], 'amount' => $price * 100, 'callback_url' => $callback ]; $headers = [ 'Authorization: Bearer ' . $system['paystack_secret'], 'Content-Type: application/json', ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.paystack.co/transaction/initialize"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); $responseJson = json_decode($response, true); if (!$responseJson['status']) { throw new Exception($responseJson['message']); } return $responseJson['data']['authorization_url']; } /** * paystack_check * * @param string $reference * @return boolean */ function paystack_check($reference) { global $system; $headers = [ 'Authorization: Bearer ' . $system['paystack_secret'] ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.paystack.co/transaction/verify/" . $reference); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $responseJson = json_decode($response, true); if ($responseJson['data']['status'] == 'success') { return true; } return false; } /* ------------------------------- */ /* Razorpay */ /* ------------------------------- */ /** * razorpay_check * * @param string $payment_id * @param integer $amount * @return boolean */ function razorpay_check($payment_id, $amount) { global $system; $url = 'https://api.razorpay.com/v1/payments/' . $payment_id . '/capture'; $params = http_build_query(['amount' => $amount * 100, 'currency' => $system['currency']]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, $system['razorpay_key_id'] . ':' . $system['razorpay_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); $response = curl_exec($ch); $responseJson = json_decode($response, true); if ($responseJson['error_code']) { return false; } return true; } /* ------------------------------- */ /* Cashfree */ /* ------------------------------- */ /** * cashfree * * @param string $handle * @param string $price * @param integer $id * @param string $billing_name * @param string $billing_email * @param string $billing_phone * @return string */ function cashfree($handle, $price, $id, $billing_name, $billing_email, $billing_phone) { global $system; /* prepare */ $return_url = $system['system_url'] . "/webhooks/cashfree.php?orderId={order_id}&token={order_token}"; switch ($handle) { case 'packages': $return_url .= "&handle=packages&package_id=$id"; break; case 'wallet': $return_url .= "&handle=wallet"; $_SESSION['wallet_replenish_amount'] = $price; break; case 'donate': $return_url .= "&handle=donate&post_id=$id"; $_SESSION['donation_amount'] = $price; break; case 'subscribe': $return_url .= "&handle=subscribe&plan_id=$id"; break; case 'movies': $return_url .= "&handle=movies&movie_id=$id"; break; default: _error(400); break; } $headers = array( "content-type: application/json", "x-client-id: " . $system['cashfree_client_id'], "x-client-secret: " . $system['cashfree_client_secret'], "x-api-version: " . "2021-05-21", ); $data = array( "order_amount" => $price, "order_currency" => $system['system_currency'], "customer_details" => array( "customer_id" => uniqid(), "customer_email" => $billing_email, "customer_phone" => $billing_phone ), "order_meta" => array( "return_url" => $return_url, "notify_url" => "", ) ); $apiBase = ($system['cashfree_mode'] == 'sandbox') ? 'https://sandbox.cashfree.com/pg/' : 'https://api.cashfree.com/pg'; $apiURL = $apiBase . "/orders"; /* Cashfree */ $ch = curl_init($apiURL); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_URL, $apiURL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($ch); if (curl_errno($ch)) { throw new Exception("Error Processing Request"); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $responseJson = json_decode($response, true); curl_close($ch); if ($httpCode != 200) { throw new Exception($responseJson['message']); } return $responseJson["payment_link"]; } /** * cashfree_check * * @param string $orderId * @return boolean */ function cashfree_check($orderId) { global $system; /* prepare */ $headers = array( "content-type: application/json", "x-client-id: " . $system['cashfree_client_id'], "x-client-secret: " . $system['cashfree_client_secret'], "x-api-version: " . "2021-05-21", ); $apiBase = ($system['cashfree_mode'] == 'sandbox') ? 'https://sandbox.cashfree.com/pg/' : 'https://api.cashfree.com/pg'; $apiURL = $apiBase . "/orders/" . $orderId; /* Cashfree */ $ch = curl_init($apiURL); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if ($response === false) { throw new Exception("Unable to get to cashfree"); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $responseJson = json_decode($response, true); curl_close($ch); if ($httpCode == 200 && $responseJson['order_status'] == 'PAID') { return true; } return false; } /* ------------------------------- */ /* Coinbase */ /* ------------------------------- */ /** * coinbase * * @param string $handle * @param string $price * @param integer $id * @return array */ function coinbase($handle, $price, $id = null) { global $system; /* prepare */ $coinbase_hash = get_hash_token(); switch ($handle) { case 'packages': $product = __($system['system_title']) . " " . __('Pro Package'); $description = __('Pay For') . " " . __($system['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/coinbase.php?status=success&handle=packages&package_id=$id&coinbase_hash=$coinbase_hash"; $URL['cancel'] = $system['system_url'] . "/webhooks/coinbase.php?status=cancel"; break; case 'wallet': $product = __($system['system_title']) . " " . __('Wallet'); $description = __('Pay For') . " " . __($system['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/coinbase.php?status=success&handle=wallet&coinbase_hash=$coinbase_hash"; $URL['cancel'] = $system['system_url'] . "/webhooks/coinbase.php?status=cancel"; $_SESSION['wallet_replenish_amount'] = $price; break; case 'donate': $product = __($system['system_title']) . " " . __('Funding Donation'); $description = __('Pay For') . " " . __($system['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/coinbase.php?status=success&handle=donate&post_id=$id&coinbase_hash=$coinbase_hash"; $URL['cancel'] = $system['system_url'] . "/webhooks/coinbase.php?status=cancel"; $_SESSION['donation_amount'] = $price; break; case 'subscribe': $product = __($system['system_title']) . " " . __('Subscribe'); $description = __('Pay For') . " " . __($system['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/coinbase.php?status=success&handle=subscribe&plan_id=$id&coinbase_hash=$coinbase_hash"; $URL['cancel'] = $system['system_url'] . "/webhooks/coinbase.php?status=cancel"; break; case 'movies': $product = __($system['system_title']) . " " . __('Movies'); $description = __('Pay For') . " " . __($system['system_title']); $URL['success'] = $system['system_url'] . "/webhooks/coinbase.php?status=success&handle=movies&movie_id=$id&coinbase_hash=$coinbase_hash"; $URL['cancel'] = $system['system_url'] . "/webhooks/coinbase.php?status=cancel"; break; default: _error(400); break; } $headers = [ "content-type: application/json", "X-Cc-Api-Key: " . $system['coinbase_api_key'], "X-Cc-Version: " . "2018-03-22", ]; $data = [ 'name' => $product, 'description' => $description, 'pricing_type' => 'fixed_price', 'local_price' => [ 'amount' => $price, 'currency' => $system['system_currency'] ], 'metadata' => [ 'coinbase_hash' => $coinbase_hash ], "redirect_url" => $URL['success'], 'cancel_url' => $URL['cancel'] ]; /* Coinbase */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.commerce.coinbase.com/charges'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($ch); if (curl_errno($ch)) { throw new Exception("Error Processing Request"); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $responseJson = json_decode($response, true); curl_close($ch); return [ "coinbase_hash" => $coinbase_hash, "coinbase_code" => $responseJson['data']['code'], "hosted_url" => $responseJson["data"]["hosted_url"] ]; } /** * coinbase_check * * @param string $coinbase_code * @return boolean */ function coinbase_check($coinbase_code) { global $system; /* prepare */ $headers = [ "content-type: application/json", "X-Cc-Api-Key: " . $system['coinbase_api_key'], "X-Cc-Version: " . "2018-03-22", ]; /* Coinbase */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.commerce.coinbase.com/charges/' . $coinbase_code); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $responseJson = json_decode($response, true); curl_close($ch); if (!empty($responseJson) && $responseJson['data']['payments'][0]['status'] == 'CONFIRMED') { return true; } return false; } /* ------------------------------- */ /* SecurionPay */ /* ------------------------------- */ /** * securionpay * * @param string $price * @return string */ function securionpay($price) { global $system; $securionPay = new SecurionPay\SecurionPayGateway($system['securionpay_api_secret']); $checkoutCharge = new SecurionPay\Request\CheckoutRequestCharge(); $checkoutCharge->amount($price * 100)->currency($system['system_currency']); $checkoutRequest = new SecurionPay\Request\CheckoutRequest(); $checkoutRequest->charge($checkoutCharge); $signedCheckoutRequest = $securionPay->signCheckoutRequest($checkoutRequest); return $signedCheckoutRequest; } /** * securionpay_check * * @param string $charge_id * @return boolean */ function securionpay_check($charge_id) { global $system; /* SecurionPay */ $url = "https://api.securionpay.com/charges?limit=10"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_USERPWD, $system['securionpay_api_secret'] . ":password"); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $responseJson = json_decode($response, true); curl_close($ch); if (!empty($responseJson) && $responseJson['list'][0]['id'] == $charge_id) { return true; } return false; } /* ------------------------------- */ /* MoneyPoolsCash */ /* ------------------------------- */ /** * moneypoolscash_payment_token * * @return string */ function moneypoolscash_payment_token() { global $system; $curl = curl_init(); $post_fileds = [ 'merchant_email' => $system['moneypoolscash_merchant_email'] ]; $headers = [ 'Content-Type: application/json', 'API-KEY: ' . $system['moneypoolscash_api_key'], ]; curl_setopt_array($curl, [ CURLOPT_URL => 'https://moneypoolscash.com/gettoken?merchant_email=' . $system['moneypoolscash_merchant_email'], CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_POSTFIELDS => json_encode($post_fileds), CURLOPT_HTTPHEADER => $headers, ]); $response = curl_exec($curl); curl_close($curl); $response = json_decode($response, true); if ($response['status'] != 'success') { throw new Exception(__("Error Processing Request")); } $token = $response['data']['token']; return $token; } /** * moneypoolscash_wallet_token * * @return string */ function moneypoolscash_wallet_token() { global $system; $curl = curl_init(); $post_fileds = [ 'user' => [ 'email' => $system['moneypoolscash_merchant_email'], 'password' => $system['moneypoolscash_merchant_password'] ], ]; $headers = [ 'Content-Type: application/json', 'User-Agent: Sngine', 'API-KEY: ' . $system['moneypoolscash_api_key'], ]; curl_setopt_array($curl, [ CURLOPT_URL => 'https://moneypoolscash.com/api/loginapp', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => json_encode($post_fileds), CURLOPT_HTTPHEADER => $headers, ]); $response = curl_exec($curl); curl_close($curl); $response = json_decode($response, true); if ($response['result'] != 'success') { throw new Exception(__("Error Processing Request")); } $token = $response['token']; return $token; } /** * moneypoolscash * * @param string $handle * @param string $price * @param integer $id * @return string */ function moneypoolscash($handle, $price, $id = null) { global $system; /* get token */ $token = moneypoolscash_payment_token(); /* prepare */ switch ($handle) { case 'packages': $URL['success'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=success&handle=packages&package_id=$id"; $URL['cancel'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=cancel"; break; case 'wallet': $URL['success'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=success&handle=wallet"; $URL['cancel'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=cancel"; $_SESSION['wallet_replenish_amount'] = $price; break; case 'donate': $URL['success'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=success&handle=donate&post_id=$id"; $URL['cancel'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=cancel"; $_SESSION['donation_amount'] = $price; break; case 'subscribe': $URL['success'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=success&handle=subscribe&plan_id=$id"; $URL['cancel'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=cancel"; break; case 'movies': $URL['success'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=success&handle=movies&movie_id=$id"; $URL['cancel'] = $system['system_url'] . "/webhooks/moneypoolscash.php?status=cancel"; break; default: _error(400); break; } /* make payment request */ $merchant_ref = md5(time() . rand(1111, 9999)); $post_fields = [ 'merchant_email' => $system['moneypoolscash_merchant_email'], 'amount' => $price, 'currency' => $system['system_currency'], 'return_url' => $URL['success'], 'cancel_url' => $URL['cancel'], 'merchant_ref' => $merchant_ref, ]; $headers = [ 'Content-Type: application/json', 'API-KEY: ' . $system['moneypoolscash_api_key'], 'token: ' . $token, ]; $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => 'https://moneypoolscash.com/payrequest', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_POSTFIELDS => json_encode($post_fields), CURLOPT_HTTPHEADER => $headers, ]); $response = curl_exec($curl); curl_close($curl); $response = json_decode($response, true); $_SESSION['moneypoolscash_merchant_ref'] = $merchant_ref; $_SESSION['moneypoolscash_trx'] = $response['data']['trx']; return $response['data']['redirect_url']; } /** * moneypoolscash_check * * @return boolean */ function moneypoolscash_check() { global $system; /* get token */ $token = moneypoolscash_payment_token(); $post_fields = [ 'merchant_email' => $system['moneypoolscash_merchant_email'], 'trx' => $_SESSION['moneypoolscash_trx'], 'merchant_ref' => $_SESSION['moneypoolscash_merchant_ref'], ]; $headers = [ 'Content-Type: application/json', 'API-KEY: ' . $system['moneypoolscash_api_key'], 'token: ' . $token, ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://moneypoolscash.com/gettrx', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_POSTFIELDS => json_encode($post_fields), CURLOPT_HTTPHEADER => $headers, )); $response = curl_exec($curl); curl_close($curl); $response = json_decode($response, true); if ($response['code'] == '200' && $response['status'] == 'completed') { return true; } return false; } /** * process_automatic_withdrawal * * @param string $method * @param integer $amount * @param string $transfer_to * @return void */ function process_automatic_withdrawal($method, $amount, $transfer_to) { global $system; switch ($method) { case 'moneypoolscash': /* get token */ $token = moneypoolscash_wallet_token(); $post_fields = [ 'toemail' => $transfer_to, 'amount' => $amount, 'currency' => $system['system_currency'], ]; /* make payment request */ $headers = [ 'Content-Type: application/json', 'User-Agent: Sngine', 'API-KEY: ' . $system['moneypoolscash_api_key'], 'token: ' . $token, 'email: ' . $system['moneypoolscash_merchant_email'], ]; $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => 'https://moneypoolscash.com/api/transferfunds', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => json_encode($post_fields), CURLOPT_HTTPHEADER => $headers, ]); $response = curl_exec($curl); curl_close($curl); $response = json_decode($response, true); if ($response['code'] != '200') { throw new Exception($response['message']); } break; } } /* ------------------------------- */ /* User Access */ /* ------------------------------- */ /** * user_access * * @param boolean $is_ajax * @param boolean $bypass_subscription * @return void */ function user_access($is_ajax = false, $bypass_subscription = false) { global $user, $system; if ($is_ajax) { /* check user logged in */ if (!$user->_logged_in) { modal('LOGIN'); } /* check user activated */ if ($system['activation_enabled'] && !$user->_data['user_activated']) { modal("MESSAGE", __("Not Activated"), __("Before you can interact with other users, you need to confirm your email address")); } /* check registration type */ if ($system['registration_type'] == "paid" && $user->_data['user_group'] > '1' && !$user->_data['user_subscribed'] && !$bypass_subscription) { modal("MESSAGE", __("Subscription Needed"), __("Before you can interact with other users, you need to buy subscription package")); } } else { if (!$user->_logged_in) { user_login(); } else { /* check registration type */ if ($system['registration_type'] == "paid" && $user->_data['user_group'] > '1' && !$user->_data['user_subscribed']) { redirect('/packages'); } /* check user activated */ if ($system['activation_enabled'] && $system['activation_required'] && !$user->_data['user_activated']) { _error('ACTIVATION'); } /* check user getted started */ if ($system['getting_started'] && !$user->_data['user_started']) { redirect('/started'); } } } } /** * user_login * * @return void */ function user_login() { global $user, $smarty; $smarty->assign('genders', $user->get_genders()); $smarty->assign('custom_fields', $user->get_custom_fields()); $smarty->assign('highlight', __("You must sign in to see this page")); page_header(__("Sign in")); page_footer('sign'); exit; } /* ------------------------------- */ /* Modal */ /* ------------------------------- */ /** * modal * * @return json */ function modal() { $args = func_get_args(); switch ($args[0]) { case 'LOGIN': return_json(array("callback" => "modal('#modal-login')")); break; case 'MESSAGE': return_json(array("callback" => "modal('#modal-message', {title: '" . $args[1] . "', message: '" . addslashes($args[2]) . "'})")); break; case 'ERROR': return_json(array("callback" => "modal('#modal-error', {title: '" . $args[1] . "', message: '" . addslashes($args[2]) . "'})")); break; case 'SUCCESS': return_json(array("callback" => "modal('#modal-success', {title: '" . $args[1] . "', message: '" . addslashes($args[2]) . "'})")); break; default: if (isset($args[1])) { return_json(array("callback" => "modal('" . $args[0] . "', " . $args[1] . ")")); } else { return_json(array("callback" => "modal('" . $args[0] . "')")); } break; } } /* ------------------------------- */ /* Popover */ /* ------------------------------- */ /** * popover * * @param integer $uid * @param string $username * @param string $name * @return string */ function popover($uid, $username, $name) { global $system; $popover = '' . $name . ''; return $popover; } /* ------------------------------- */ /* Page */ /* ------------------------------- */ /** * page_header * * @param string $title * @param string $description * @return void */ function page_header($title, $description = '', $image = '') { global $smarty, $system; $description = ($description != '') ? $description : __($system['system_description']); if ($image == '') { if ($system['system_ogimage']) { $image = $system['system_uploads'] . '/' . $system['system_ogimage']; } else { $image = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/og-image.jpg'; } } $smarty->assign('page_title', $title); $smarty->assign('page_description', $description); $smarty->assign('page_image', $image); } /** * page_footer * * @param string $page * @return void */ function page_footer($page) { global $smarty; $smarty->assign('page', $page); $smarty->display("$page.tpl"); } /* ------------------------------- */ /* Post Feelings */ /* ------------------------------- */ /** * get_feelings * * @return array */ function get_feelings() { $feelings = array( array("icon" => "grinning-face-with-smiling-eyes", "action" => "Feeling", "text" => __("Feeling"), "placeholder" => __("How are you feeling?")), array("icon" => "headphone", "action" => "Listening To", "text" => __("Listening To"), "placeholder" => __("What are you listening to?")), array("icon" => "glasses", "action" => "Watching", "text" => __("Watching"), "placeholder" => __("What are you watching?")), array("icon" => "video-game", "action" => "Playing", "text" => __("Playing"), "placeholder" => __("What are you playing?")), array("icon" => "shortcake", "action" => "Eating", "text" => __("Eating"), "placeholder" => __("What are you eating?")), array("icon" => "tropical-drink", "action" => "Drinking", "text" => __("Drinking"), "placeholder" => __("What are you drinking?")), array("icon" => "airplane", "action" => "Traveling To", "text" => __("Traveling To"), "placeholder" => __("Where are you going?")), array("icon" => "books", "action" => "Reading", "text" => __("Reading"), "placeholder" => __("What are you reading?")), array("icon" => "calendar", "action" => "Attending", "text" => __("Attending"), "placeholder" => __("What are you attending?")), array("icon" => "birthday-cake", "action" => "Celebrating", "text" => __("Celebrating"), "placeholder" => __("What are you celebrating?")), array("icon" => "magnifying-glass-tilted-left", "action" => "Looking For", "text" => __("Looking For"), "placeholder" => __("What are you looking for?")) ); return $feelings; } /** * get_feelings_types * * @return array */ function get_feelings_types() { $feelings_types = array( array("icon" => "grinning-face-with-smiling-eyes", "action" => "Happy", "text" => __("Happy")), array("icon" => "smiling-face-with-heart-eyes", "action" => "Loved", "text" => __("Loved")), array("icon" => "relieved-face", "action" => "Satisfied", "text" => __("Satisfied")), array("icon" => "flexed-biceps", "action" => "Strong", "text" => __("Strong")), array("icon" => "disappointed-face", "action" => "Sad", "text" => __("Sad")), array("icon" => "winking-face-with-tongue", "action" => "Crazy", "text" => __("Crazy")), array("icon" => "downcast-face-with-sweat", "action" => "Tired", "text" => __("Tired")), array("icon" => "sleeping-face", "action" => "Sleepy", "text" => __("Sleepy")), array("icon" => "confused-face", "action" => "Confused", "text" => __("Confused")), array("icon" => "worried-face", "action" => "Worried", "text" => __("Worried")), array("icon" => "angry-face", "action" => "Angry", "text" => __("Angry")), array("icon" => "pouting-face", "action" => "Annoyed", "text" => __("Annoyed")), array("icon" => "face-with-open-mouth", "action" => "Shocked", "text" => __("Shocked")), array("icon" => "pensive-face", "action" => "Down", "text" => __("Down")), array("icon" => "confounded-face", "action" => "Confounded", "text" => __("Confounded")) ); return $feelings_types; } /** * get_feeling_icon * * @param string $needle * @param array $array * @param string $key * @return string */ function get_feeling_icon($needle, $array, $key = "action") { foreach ($array as $_key => $_val) { if ($_val[$key] === $needle) { return $array[$_key]['icon']; } } return false; } /* ------------------------------- */ /* Censored Words */ /* ------------------------------- */ /** * censored_words * * @param string $text * @return string */ function censored_words($text) { global $system; if ($system['censored_words_enabled'] && $text) { $bad_words = explode(',', trim($system['censored_words'])); if ($bad_words) { foreach ($bad_words as $word) { $word = trim($word); $pattern = '/\b' . $word . '\b/iu'; $text = preg_replace($pattern, str_repeat('*', strlen($word)), $text); } } } return $text; } /* ------------------------------- */ /* Images */ /* ------------------------------- */ /** * get_picture * * @param string $picture * @param string $type * @return string */ function get_picture($picture, $type) { global $system; if ($picture == "") { switch ($type) { case 'page': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_page.png'; break; case 'group': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_group.png'; break; case 'event': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_event.png'; break; case 'article': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_article.png'; break; case 'movie': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_movie.png'; break; case 'game': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_game.png'; break; case 'package': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_package.png'; break; case 'flag': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_flag.png'; break; case 'system': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/svg/dashboard.svg'; break; case '1': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_profile_male.png'; break; case '2': $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_profile_female.png'; break; default: $picture = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/blank_profile.png'; break; } } else { $picture = $system['system_uploads'] . '/' . $picture; } return $picture; } /** * save_picture_from_url * * @param string $file * @param boolean $cropped * @return string */ function save_picture_from_url($file, $cropped = false, $resize = false) { global $system; /* check & create uploads dir */ $folder = 'photos'; $directory = $folder . '/' . date('Y') . '/' . date('m') . '/'; // init image & prepare image name & path require_once(ABSPATH . 'includes/class-image.php'); $image = new Image($file); $prefix = $system['uploads_prefix'] . '_' . get_hash_token(); if ($cropped) { $image_name = $directory . $prefix . "_cropped" . $image->_img_ext; if ($resize) { $image->resizeWidth($_POST['resize_width']); } $_POST['width'] = (isset($_POST['width'])) ? $_POST['width'] : $image->getWidth(); $_POST['height'] = (isset($_POST['height'])) ? $_POST['height'] : $image->getHeight(); $image->crop($_POST['width'], $_POST['height'], $_POST['x'], $_POST['y']); } else { $image_name = $directory . $prefix . $image->_img_ext; } $path = ABSPATH . $system['uploads_directory'] . '/' . $image_name; /* set uploads directory */ if (!file_exists(ABSPATH . $system['uploads_directory'] . '/' . $folder)) { @mkdir(ABSPATH . $system['uploads_directory'] . '/' . $folder, 0777, true); } if (!file_exists(ABSPATH . $system['uploads_directory'] . '/' . $folder . '/' . date('Y'))) { @mkdir(ABSPATH . $system['uploads_directory'] . '/' . $folder . '/' . date('Y'), 0777, true); } if (!file_exists($system['uploads_directory'] . '/' . $folder . '/' . date('Y') . '/' . date('m'))) { @mkdir(ABSPATH . $system['uploads_directory'] . '/' . $folder . '/' . date('Y') . '/' . date('m'), 0777, true); } /* save the new image */ $image->save($path, $system['uploads_quality']); /* cloud storage */ save_file_to_cloud($path, $image_name); return $image_name; } /** * watermark_image * * @param string $image_path * @param string $image_type * @return void */ function watermark_image($image_path, $image_type) { global $system; if (!is_empty($system['watermark_icon'])) { try { $image = new claviska\SimpleImage(); $image ->fromFile($image_path) ->autoOrient() ->overlay($system['system_uploads'] . "/" . $system['watermark_icon'], $system['watermark_position'], $system['watermark_opacity'], $system['watermark_xoffset'], $system['watermark_yoffset']) ->toFile($image_path, $image_type); } catch (Exception $e) { return $e->getMessage(); } } } /* ------------------------------- */ /* Utilities */ /* ------------------------------- */ /** * _getallheaders * * @return array */ function _getallheaders() { return array_change_key_case(getallheaders(), CASE_LOWER); } /** * get_ip * * @return string */ function get_user_ip() { /* handle CloudFlare IP addresses */ return (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER['REMOTE_ADDR']); } /** * get_os * * @return string */ function get_user_os() { $os_platform = "Unknown OS Platform"; $os_array = array( '/windows nt 10/i' => 'Windows 10', '/windows nt 6.3/i' => 'Windows 8.1', '/windows nt 6.2/i' => 'Windows 8', '/windows nt 6.1/i' => 'Windows 7', '/windows nt 6.0/i' => 'Windows Vista', '/windows nt 5.2/i' => 'Windows Server 2003/XP x64', '/windows nt 5.1/i' => 'Windows XP', '/windows xp/i' => 'Windows XP', '/windows nt 5.0/i' => 'Windows 2000', '/windows me/i' => 'Windows ME', '/win98/i' => 'Windows 98', '/win95/i' => 'Windows 95', '/win16/i' => 'Windows 3.11', '/macintosh|mac os x/i' => 'Mac OS X', '/mac_powerpc/i' => 'Mac OS 9', '/linux/i' => 'Linux', '/ubuntu/i' => 'Ubuntu', '/iphone/i' => 'iPhone', '/ipod/i' => 'iPod', '/ipad/i' => 'iPad', '/android/i' => 'Android', '/blackberry/i' => 'BlackBerry', '/webos/i' => 'Mobile' ); foreach ($os_array as $regex => $value) { if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) { $os_platform = $value; } } return $os_platform; } /** * get_browser * * @return string */ function get_user_browser() { $browser = "Unknown Browser"; $browser_array = array( '/msie/i' => 'Internet Explorer', '/firefox/i' => 'Firefox', '/safari/i' => 'Safari', '/chrome/i' => 'Chrome', '/edge/i' => 'Edge', '/opera/i' => 'Opera', '/netscape/i' => 'Netscape', '/maxthon/i' => 'Maxthon', '/konqueror/i' => 'Konqueror', '/mobile/i' => 'Handheld Browser' ); foreach ($browser_array as $regex => $value) { if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) { $browser = $value; } } return $browser; } /** * get_extension * * @param string $path * @return string */ function get_extension($path) { return strtolower(pathinfo($path, PATHINFO_EXTENSION)); } /** * get_origin_url * * @param string $url * @return string */ function get_origin_url($url) { stream_context_set_default(array( 'http' => array( 'ignore_errors' => true, 'method' => 'HEAD', 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', ) )); $headers = get_headers($url, 1); if ($headers !== false && (isset($headers['location']) || isset($headers['Location']))) { $location = (isset($headers['location'])) ? $headers['location'] : $headers['Location']; return is_array($location) ? array_pop($location) : $location; } return $url; } /** * decode_urls * * @param string $text * @return string */ function decode_urls($text) { $text = ($text) ? preg_replace('/(https?:\/\/[^\s]+)/', "$1", $text) : $text; return $text; } /** * get_url_text * * @param string $string * @param integer $length * @return string */ function get_url_text($string, $length = 10) { $string = htmlspecialchars_decode($string, ENT_QUOTES); $string = preg_replace('/[^\\pL\d]+/u', '-', $string); $string = trim($string, '-'); $words = explode("-", $string); if (count($words) > $length) { $string = ""; for ($i = 0; $i < $length; $i++) { $string .= "-" . $words[$i]; } $string = trim($string, '-'); } return $string; } /** * remove_querystring_var * * @param string $url * @param string $key * @return string */ function remove_querystring_var($url, $key) { $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&'); $url = substr($url, 0, -1); return $url; } /** * get_snippet_text * * @param string $string * @return string */ function get_snippet_text($string) { $string = htmlspecialchars_decode($string, ENT_QUOTES); $string = strip_tags($string); return $string; } /** * get_tag * * @param string $string * @return string */ function get_tag($string) { $string = trim($string); $string = preg_replace('/\s+/', '_', $string); return $string; } /** * get_youtube_id * * @param string $url * @param boolean $embed * @return string */ function get_youtube_id($url, $embed = true) { if ($embed) { preg_match('/youtube\.com\/embed\/([^\&\?\/]+)/', $url, $id); return $id[1]; } else { parse_str(parse_url($url, PHP_URL_QUERY), $id); return $id['v']; } } /** * get_vimeo_id * * @param string $url * @return string */ function get_vimeo_id($url) { return (int) substr(parse_url($url, PHP_URL_PATH), 1); } /** * get_video_type * * @param string $url * @return string */ function get_video_type($url) { if (strpos($url, 'youtube') > 0) { return 'youtube'; } elseif (strpos($url, 'vimeo') > 0) { return 'vimeo'; } else { return 'link'; } } /** * get_array_key * * @param array $array * @param integer $current * @param integer $offset * @return mixed */ function get_array_key($array, $current, $offset = 1) { $keys = array_keys($array); $index = array_search($current, $keys); if (isset($keys[$index + $offset])) { return $keys[$index + $offset]; } return false; } /** * print_money * * @param string $amount * @param string $symbol * @param string $dir * @return string */ function print_money($amount, $symbol = null, $dir = null) { global $system; $symbol = ($symbol) ? $symbol : $system['system_currency_symbol']; $dir = ($dir) ? $dir : $system['system_currency_dir']; if ($dir == "right") { return $amount . $symbol; } else { return $symbol . $amount; } }