| Server IP : 185.143.234.238 / Your IP : 185.215.232.195 Web Server : LiteSpeed System : Linux saman.shetabanhost.com 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64 User : behrakir ( 1361) PHP Version : 8.1.34 Disable Function : symlink,shell_exec,show_source,exec,popen,system,passthru,proc_open,proc_close,pcntl_exec,mail MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/behrakir/khanomam.com/wp-content/plugins/wp-score-gamification/app/classes/ |
Upload File : |
<?php namespace Avans;
use Avans\parts\completeProfile;
use Avans\parts\coupons;
use Avans\parts\lockPost;
use Avans\parts\referer;
use stdClass;
class front
{
// private static $instance = null;
public function __construct()
{
add_action('woocommerce_after_checkout_billing_form', array($this,'avans_after_checkout_billing_form') , 88 );
add_action('woocommerce_cart_calculate_fees', array($this,'avans_cart_calculate_fees'),99);
add_action('woocommerce_review_order_after_order_total', array($this,'avans_after_order_total_checkout') , 99);
add_action('woocommerce_single_product_summary',array($this,'avans_woocommerce_add_shortcode_show_product_score'),$this->get_sort_wc_single_product_score());
add_filter('get_avatar', array($this,'avans_change_avatar'),999999, 5);
add_filter('get_avatar_url', array($this,'avans_change_avatar_url'),999999, 2);
add_filter('woocommerce_coupon_get_discount_amount', array($this,'avans_wc_coupon_get_discount_amount') , 20, 5);
add_filter('the_content', array( static::class ,'avans_check_lock_post'));
add_filter('woocommerce_is_purchasable', array($this,'avans_filter_is_purchasable_callback'), 10, 2 );
add_filter('woocommerce_variation_is_purchasable', array($this,'avans_filter_is_purchasable_callback'), 10, 2 );
// add_action( 'woocommerce_before_add_to_cart_button', array($this , 'avans_change_product_html') , 10, 2 );
}
function avans_change_product_html( ) {
global $product;
$dataScoreAmount = [];
if( is_array( $product->get_children() ) ){
foreach($product->get_children() as $child):
$buy_score = get_post_meta( $child , AVANS_PREFIX.'product_buy_score' , true);
$dataScoreAmount[$child] = $buy_score;
endforeach;
if(count($dataScoreAmount) > 0):
?>
<div class="amount-score" data-amount="<?php echo htmlspecialchars(json_encode($dataScoreAmount) , ENT_QUOTES, 'UTF-8') ?>"><span> یا </span><span class="value"> </span><span class="unit"> <?php echo func::get_score_label(); ?> </span></div>
<?php
endif;
}else{
$buy_score = get_post_meta( $product->ID , AVANS_PREFIX.'product_buy_score' , true);
?>
<div class="amount-score"><span> یا </span><span class="value"> <?php echo $buy_score; ?> </span><span class="unit"> <?php echo func::get_score_label(); ?> </span></div>
<?php
}
}
public function avans_filter_is_purchasable_callback($purchasable, $product){
$result = lockPost::is_permision(null,$product->get_id());
if(!$result['status']){
return false;
}
return $purchasable;
}
public static function get_user_missons($settings){
$avs_panel = (array)AVANS_SETTINGS['panel_settings'];
$missons = [];
if($settings->show_spin_wheel){
$missons[] = [
'href' => $avs_panel['link_spin_wheel'],
'class' => 'spinwheel',
'icon' => 'avans-ic avs-icon-dharmachakra-solid',
'label' => __("Game Optin Wheel", AVANS_TEXT_DOMAIN),
];
}
if($settings->show_complete_profile){
$missons[] = [
'href' => add_query_arg('avans_page','complete_user_info'),
'class' => 'complete_profiles',
'icon' => 'avans-ic avs-icon-user-check-solid',
'label' => __("Complete user profile", AVANS_TEXT_DOMAIN),
];
}
return apply_filters("avans_get_user_missons",$missons);
}
public static function avans_check_lock_post($content,$atts=null){
$result = lockPost::is_permision($atts);
if($result['status']){
return $content;
}else{
$output = '<div class="avans_wrapper_lock_post">
<i class="avans-ic avs-icon-user-lock-solid"></i>
<h4>'.__("You do not have permission to view this page!" , AVANS_TEXT_DOMAIN).'</h4>
<p>'.__("To view this page, you must have the following conditions." , AVANS_TEXT_DOMAIN).'</p>
<div class="avans_condition_open_lock">';
if($result['score']['isset']):
$output .= '<div class="score earned-'.$result['score']['success'].' ">
<i class="avans-ic avs-icon-gem-solid"></i>
<p class="description">
<span class="label">'.__("At least" , AVANS_TEXT_DOMAIN) . ' ' .func::get_score_label().' </span>
<span>'.number_format($result['score']['value']).'</span>
<span> '.func::get_score_label().' </span>
</p>
</div>';
endif;
if($result['level']['isset']):
$output .= '<div class="level earned-'.$result['level']['success'].' ">
<i class="avans-ic avs-icon-award"></i>
<p class="description">
<span class="label"> '.__("Minimum user level" , AVANS_TEXT_DOMAIN).' </span>
<span>'.$result['level']['value'].'</span>
</p>
</div>';
endif;
if($result['roles']['isset']):
$output .= '<div class="roles earned-'.$result['roles']['success'].' ">
<i class="avans-ic avs-icon-user-tag-solid"></i>
<p class="description">
<span class="label"> '.__("Authorized user roles" , AVANS_TEXT_DOMAIN).' </span>
<span>'.$result['roles']['value'].'</span>
</p>
</div>';
endif;
if($result['badges']['isset']):
$output .= '<div class="badges earned-'.$result['badges']['success'].' ">
<i class="avans-ic avs-icon-medal-solid"></i>
<p class="description">
<span class="label"> '.__("Required badges" , AVANS_TEXT_DOMAIN).' </span>
<span>'.$result['badges']['value'].'</span>
</p>
</div>';
endif;
$output .= '</div></div>';
return $output;
}
}
public function avans_wc_coupon_get_discount_amount($discount, $discounting_amount, $cart_item, $single, $coupon)
{
$max_discount = get_post_meta($coupon->get_id(), 'max_discount', true);
if (is_numeric($max_discount) && ! is_null($cart_item) && WC()->cart->subtotal_ex_tax) {
$cart_item_qty = is_null($cart_item) ? 1 : $cart_item['quantity'];
$ex_price = $this->avans_get_exclude_price_for_coupon($coupon);
if (wc_prices_include_tax()) {
$totalPrice = WC()->cart->subtotal - $ex_price;
$discount_percent = (wc_get_price_including_tax($cart_item['data']) * $cart_item_qty) / $totalPrice;
} else {
$totalPrice = WC()->cart->subtotal_ex_tax - $ex_price;
$discount_percent = (wc_get_price_excluding_tax($cart_item['data']) * $cart_item_qty) / $totalPrice;
}
$_discount = $max_discount * $discount_percent;
$discount = min($_discount, $discount);
}
return $discount;
}
public function avans_get_exclude_price_for_coupon($coupon){
global $woocommerce;
$product_ids = $coupon->get_product_ids();
$exclude_product_ids = $coupon->get_excluded_product_ids();
$cats_ids = $coupon->get_product_categories();
$exclude_cats_ids = $coupon->get_excluded_product_categories();
$ex_price = 0;
$cart = $woocommerce->cart;
$items = $cart->get_cart();
foreach ($items as $index => $values) {
$exclude = false;
$item = $values['data'];
$id = $item->get_id();
$price = $item->get_price() * $values['quantity'];
$category_ids = $item->get_category_ids();
if(!empty($product_ids) && !in_array($id,$product_ids)){
$exclude = true;
}
if(!empty($exclude_product_ids) && in_array($id,$exclude_product_ids)){
$exclude = true;
}
foreach ($category_ids as $cat_id) {
if (!empty($cats_ids) && !in_array($cat_id, $cats_ids)) {
$exclude = true;
break;
}
if (!empty($exclude_cats_ids) && in_array($cat_id, $exclude_cats_ids)) {
$exclude = true;
break;
}
}
if($exclude){
$ex_price += $price;
}
}
return $ex_price;
}
public function avans_change_avatar($avatar, $id_or_email, $size, $default, $alt ){
$user = false;
if ( is_numeric( $id_or_email ) ) {
$id = (int) $id_or_email;
$user = get_user_by( 'ID' , $id );
} elseif ( is_object( $id_or_email ) ) {
if ( ! empty( $id_or_email->user_id ) ) {
$id = (int) $id_or_email->user_id;
$user = get_user_by( 'ID' , $id );
}
} else {
$user = get_user_by( 'email', $id_or_email );
}
if ( $user && is_object( $user ) ) {
$avans_avatar = completeProfile::get_avans_avatar_url($user->ID);
if($avans_avatar){
$avatar = "<img alt='{$alt}' src='{$avans_avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
}
return $avatar;
}
public function avans_change_avatar_url($url, $id_or_email){
$user = false;
if (is_numeric($id_or_email)) {
$id = (int) $id_or_email;
$user = get_user_by('ID', $id);
} elseif (is_object($id_or_email)) {
if (! empty($id_or_email->user_id)) {
$id = (int) $id_or_email->user_id;
$user = get_user_by('ID', $id);
}
} else {
$user = get_user_by('email', $id_or_email);
}
if ($user && is_object($user)) {
$avans_avatar = completeProfile::get_avans_avatar_url($user->ID);
if ($avans_avatar) {
return $avans_avatar;
}
}
return $url;
}
public function avans_woocommerce_add_shortcode_show_product_score(){
$settings = AVANS_SETTINGS['score_settings']['purchase']['single_text'];
if (!isset($settings) || (isset($settings) && $settings['active']) ) {
$text = [
'before' => __("You get" , AVANS_TEXT_DOMAIN),
'after' => func::get_score_label().__("by buying this product" , AVANS_TEXT_DOMAIN)
];
if(isset($settings['text']) && !empty($settings['text'])){
$text_exp = explode('{score}',$settings['text']);
$text = [
'before' => $text_exp[0],
'after' => $text_exp[1]
];
}
$text = apply_filters('avans_set_text_single_product', $text);
$before = $text['before'];
$after = $text['after'];
$product_id = get_the_ID();
echo do_shortcode("[avans-product-score before ='$before' after='$after' product_id='$product_id' ]");
}
}
public function get_sort_wc_single_product_score(){
if(null !== AVANS_SETTINGS['score_settings']['purchase']['single_text']){
$settings = AVANS_SETTINGS['score_settings']['purchase']['single_text'];
return (int)$settings['type'];
}
return 40;
}
public function avans_after_order_total_checkout(){
global $woocommerce;
$user_id = get_current_user_id();
if ($user_id > 0) {
$score = data::get_sum_score_for_purchase($user_id, null, $woocommerce->cart);
$permision = user::is_permision_get_score('wc_order', $user_id);
$score = user::get_valid_score($user_id, $score,true);
$settings = AVANS_SETTINGS['score_settings']['purchase'];
$text = sprintf(__('The %s you earn after completing this order', AVANS_TEXT_DOMAIN),func::get_score_label());
if(isset($settings['checkout_text']) && $settings['checkout_text']['active'] && !empty($settings['checkout_text']['text'])){
$text = $settings['checkout_text']['text'];
}
if ($score != 0 && $permision && $settings['checkout_text']['active'] ) {
echo '<tr class="cart-discount">
<th>'.$text.'</th>
<td>'. $score .' '.func::get_score_label().'</td>
</tr>';
}
}
}
public function avans_after_checkout_billing_form($checkout)
{
$settings = AVANS_SETTINGS['referer_settings']['referer'];
$guset_checkout = get_option('woocommerce_enable_guest_checkout');
if ( (is_user_logged_in() || $guset_checkout !== 'yes') && $settings['active']) {
echo '<div id="message_fields">';
woocommerce_form_field('avans_ref_code_field', array(
'type' => 'text',
'class' => array('avans_ref_code_field form-row-wide'),
'label' => __('Referer code' , AVANS_TEXT_DOMAIN),
'placeholder' => '',
), $checkout->get_value('avans_ref_code_field'));
echo '</div>';
}
}
public function avans_cart_calculate_fees($cart)
{
if (! $_POST || (is_admin() && ! is_ajax())) {
return;
}
if (isset($_POST['post_data'])) {
parse_str($_POST['post_data'], $post_data);
} else {
$post_data = $_POST;
}
$settings = AVANS_SETTINGS['referer_settings']['referer'];
$guset_checkout = get_option('woocommerce_enable_guest_checkout');
$user_id = get_current_user_id();
if ($settings['active'] && ($user_id > 0 || $guset_checkout !== 'yes') ) :
if(count(WC()->cart->applied_coupons) > 0){
return;
}
if(isset($post_data['avans_ref_code_field'])){
referer::check_fee($user_id, $cart, $post_data['avans_ref_code_field'] );
}
endif;
}
}