HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/kofejob-wp/wp-content/plugins/kofejob-core/inc/basic-function.php
<?php
if ( ! function_exists( 'kofejob_get_excerpt' ) ) 
{
	function kofejob_get_excerpt($num, $post_id)
	{
		$excerpt = wp_trim_words(get_the_excerpt(),$num);
        return $excerpt;
    }
}
if ( ! function_exists( 'kofejob_get_username' ) ) 
{
	function kofejob_get_username( $user_type, $user_id = '', $show_badge = '', $badge_position = 'left')
	{
		if($user_id == '')
		{
			$current_user_id = get_current_user_id();
			$emp_id = get_user_meta( $current_user_id, 'employer_id' , true );
			$fre_id = get_user_meta( $current_user_id, 'freelancer_id' , true );
		}
		else
		{
			$emp_id = $user_id;
			$fre_id = $user_id;
		}
		$user_name = $verified = '';
		if($user_type == 'employer')
		{
			if($show_badge == 'badge')
			{
				$verifed_badge = get_post_meta( $emp_id, '_is_employer_verified' , true );

				if(isset($verifed_badge) && $verifed_badge == 1)
				{
					$verified = ' <i class="fas fa-check-circle text-success verified" data-pt-position="top" data-pt-scheme="black" data-pt-title="'.esc_html__( ' Verified', 'kofejob_core' ).'"></i> ';	
				}
				else
				{
					$verified = ' <i class="fas fa-check-circle text-success verified"></i>';
				}
			}
			//echo $emp_id;
			$user_name = get_post_meta( $emp_id, '_employer_dispaly_name' , true );
			if($user_name == '')
			{
				$post	=	get_post($emp_id);	

				if($post != null)
				{
					$user_name = $post->post_title;
				}
				else
				{
					$user_name = '';
				}
			}
		}
		if($user_type == 'freelancer')
		{
			if($show_badge == 'badge')
			{
				$verifed_badge = get_post_meta( $fre_id, '_is_freelancer_verified' , true );
				if(isset($verifed_badge) && $verifed_badge == 1)
				{
					$verified = '<i class="fa fa-check-circle text-success verified protip" data-pt-position="top" data-pt-scheme="black" data-pt-title="'.esc_html__( 'Verified', 'kofejob_core' ).'"></i> ';	
				}
				else
				{
					$verified = ' <i class="fas fa-check-circle text-success verified"></i>';
				}
			}
			else
			{
				$verified = '';
			}
			
			$user_name = get_post_meta( $fre_id, '_freelancer_dispaly_name' , true );
			if($user_name == '')
			{
				$post	=	get_post($fre_id);
				if($post != null)
				{
					$user_name = $post->post_title;
				}
				else
				{
					$user_name = '';
				}
			}
		}
		
		if($badge_position == 'left')
		{
			return $user_name.$verified;
		}
		else if($badge_position == 'right')
		{
			return $user_name.$verified;
		}
	}
}
if ( ! function_exists( 'kofejob_get_service_post_image' ) )
{
    function kofejob_get_service_post_image($id)
    {
        global $kofejob_theme_options;
        $alt_id= '';
        $services_img_id ='';
        $services_img_id = get_post_meta( $id, '_service_attachment_ids', true );
        if(wp_attachment_is_image($services_img_id))
        {
            if(isset($services_img_id) && $services_img_id != '')
            {
                $atatchment_arr = explode( ',', $services_img_id );
                foreach ($atatchment_arr as $value)
                {
                    $full_link = wp_get_attachment_url($value);
                    $img_atts = wp_get_attachment_image_src($value, 'service_grid_img');
                    $image = '<img src="'.esc_url($img_atts[0]).'" alt="'.esc_attr(get_post_meta($value, '_wp_attachment_image_alt', TRUE)).'" class="img-fluid">';
                    break;
                }
            }
//				return $image;
            return '<a href="'.get_the_permalink($id) .'"><img src="'.esc_url($img_atts[0]).'" alt="'.esc_attr(get_post_meta($value, '_wp_attachment_image_alt', TRUE)).'" class="img-fluid"></a>';

        }
        else
        {
            return '<a href="'.get_the_permalink($id) .'"><img src="'.esc_url($kofejob_theme_options['services_default_img']['url']).'" alt="'.esc_attr(get_post_meta($alt_id, '_wp_attachment_image_alt', TRUE)).'" class="img-fluid"></a>';
        }
    }
}

if ( ! function_exists( 'kofejob_get_service_post_image_slider' ) )
{
	function kofejob_get_service_post_image_slider($id)
	{
		global $kofejob_theme_options;
		$alt_id= '';
		$services_img_id ='';
			$services_img_id = get_post_meta( $id, '_service_attachment_ids', true );
			if(wp_attachment_is_image($services_img_id))
			{
                $image =  "";
				if(isset($services_img_id) && $services_img_id != '')
				{
					$atatchment_arr = explode( ',', $services_img_id );

					foreach ($atatchment_arr as $value)
					{
						$full_link = wp_get_attachment_url($value);
						$img_atts = wp_get_attachment_image_src($value, 'service_grid_img');
						if(isset($img_atts[0])) {
                            $image .= '<img src="' . esc_url($img_atts[0]) . '" alt="' . esc_attr(get_post_meta($value, '_wp_attachment_image_alt', TRUE)) . '" class="img-fluid check">';
                        }
					}
				}
//				return $image;
                return    $image;  // '<a href="'.get_the_permalink($id) .'"><img src="'.esc_url($img_atts[0]).'" alt="'.esc_attr(get_post_meta($value, '_wp_attachment_image_alt', TRUE)).'" class="img-fluid"></a>';

            }
			else
			{
				return '<a href="'.get_the_permalink($id) .'"><img src="'.esc_url($kofejob_theme_options['services_default_img']['url']).'" alt="'.esc_attr(get_post_meta($alt_id, '_wp_attachment_image_alt', TRUE)).'" class="img-fluid"></a>';
			}
	}
}


if ( ! function_exists( 'kofejob_no_result_found' ) ) 
{
	function kofejob_no_result_found($bgcolor = '', $text = '')
	{
		$image_id = '';
		$text_detail = esc_html__( 'No Result Found', 'kofejob_core' );
		if(isset($text) && $text != '')
		{
			$text_detail = $text;	
		}
		return '<div class="nothing-found '.$bgcolor.'">
					<img src="'.get_template_directory_uri().'/assets/images/nothing-found.png" alt="'.get_post_meta($image_id, '_wp_attachment_image_alt', TRUE).'">
					<h3>'.$text_detail.'</h3>
				</div>';
	}
}
if ( ! function_exists( 'kofejob_find_results_ajax' ) )
{
    function kofejob_find_results_ajax($bgcolor = '', $text = '')
    {
        $image_id = '';
        $text_detail = esc_html__( 'Please Select Any Project', 'kofejob_core' );
        if(isset($text) && $text != '')
        {
            $text_detail = $text;
        }
        return '<div class="nothing-found '.$bgcolor.'">
					<img src="'.get_template_directory_uri().'/assets/images/click.png" alt="'.get_post_meta($image_id, '_wp_attachment_image_alt', TRUE).'">
					<h3 class="select_project">'.$text_detail.'</h3>
				</div>';
    }
}


/*GET ALL POSTS COUNT*/

if ( ! function_exists( 'kofejob_get_posts_count' ) ) 
{
	function kofejob_get_posts_count($uid, $post_type, $limit = '', $status='', $meta_query = '')
	{
		$author_in ='';
		if($uid != '')
		{
			$author_in = array( $uid );
		}
		$the_query = new WP_Query( 
									array( 
											'author__in' => $author_in ,
											'post_type' => $post_type,
											'posts_per_page' => $limit,
											//'paged' => $paged,	
											'post_status'     => $status,
											'orderby' => 'date',
											'order'   => 'DESC',
											'meta_query'    => array($meta_query),
											)
										);
		$total_posts = $the_query->found_posts;
		if($total_posts <= $total_posts)
		{
			$total_posts = sprintf("%01d", $total_posts);		
		}
		//$total_posts_count = str_pad($total_posts, 2, '0', STR_PAD_LEFT);
		return $total_posts ;
	}
}
if ( ! function_exists( 'kofejob_get_services_count' ) ) 
{
	function kofejob_get_services_count($seller_id, $status)
	{
		global $wpdb;
		$table =  KOFEJOB_PURCHASED_SERVICES_TBL;

		if($wpdb->get_var("SHOW TABLES LIKE '$table'") == $table)
		{
			$query = "SELECT * FROM ".$table." WHERE `seller_id` = '" . $seller_id . "' AND `status` ='".$status."' ORDER BY timestamp DESC";

			$result = $wpdb->get_results($query, ARRAY_A );

			$count_result = count($result);
			if($count_result <= 9)
			{
				$count_result = sprintf("%02d", $count_result);	
			}
			return $count_result ;
		}
	}
}

if ( ! function_exists( 'kofejob_demo_disable' ) ) 
{
	function kofejob_demo_disable($param = '')
	{
		if(kofejob_fl_framework_get_options('kofejob_demo_mode') == true)
		{
			if(isset($param) && $param == 'echo' )
			{
				echo '0|' .__( 'Disabled for demo', 'kofejob_core' );
				die;
			}
			else if(isset($param) && $param == 'json')
			{
				$return = array('message' => esc_html__( 'Disabled for demo', 'kofejob_core' ));
				wp_send_json_error($return);
			}
		}
	}
}

if ( ! function_exists( 'kofejob_generate_code_registeration' ) ) 
{
	function kofejob_generate_code_registeration($user_id)
	{
		if(kofejob_fl_framework_get_options('fl_user_email_verification') !== null && kofejob_fl_framework_get_options('fl_user_email_verification') == true)
		{
			$code = '';
			$length = 30;
			$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
			$charactersLength = strlen($characters);
			for ($i = 0; $i < $length; $i++) {
				$code .= $characters[rand(0, $charactersLength - 1)];
			}

			$string = array('id'=>$user_id, 'code'=>$code);

			//update_user_meta($user_id, '_kofejob_account_activated', 0);
			update_user_meta($user_id, '_user_activation_code', $code);

			$signinlink = get_home_url();
			$verification_link = esc_url($signinlink.'?activation_key=' .base64_encode( serialize($string)));

			fl_account_activation_email($user_id,$verification_link);

		}
			
	}
}
add_action('wp_ajax_kofejob_resend_activation_email', 'kofejob_resend_activation_email');
if ( ! function_exists( 'kofejob_resend_activation_email' ) ) 
{
	function kofejob_resend_activation_email()
	{
		$uid = get_current_user_id();
		if(isset($uid) && $uid != '')
		{
			$now = time();
			$startDateTime = date('d-m-Y H:i:s', $now);

			$stored_dateTime = date('d-m-Y H:i:s',strtotime('+6 minutes',strtotime($startDateTime)));
			update_user_meta($uid, '_verify_email_resend_time', $stored_dateTime);
			kofejob_generate_code_registeration($uid);
			$return = array('message' => esc_html__( 'Activation email sent.', 'kofejob_core' ));
			wp_send_json_success($return);
		}
		else
		{
			$return = array('message' => esc_html__( 'Activation email is not sent. Please contact admin', 'kofejob_core' ));
			wp_send_json_error($return);
		}
	}
}
if ( ! function_exists( 'kofejob_check_register_user_type' ) ) 
{
	function kofejob_check_register_user_type($user_type)
	{
		global $kofejob_theme_options;
		if(isset($kofejob_theme_options['user_registration_type']) && $kofejob_theme_options['user_registration_type'] == 'both_selected')
		{
			$current_user_id = get_current_user_id();
			if(isset($user_type) && $user_type == 1)
			{
				$emp_id = get_user_meta( $current_user_id, 'employer_id' , true );
				if($emp_id == '')
				{
					$return = array('message' => esc_html__( 'Please register as an employer first', 'kofejob_core' ));
					wp_send_json_error($return);
				}
			}
			
			if(isset($user_type) && $user_type == 2)
			{
				$fre_id = get_user_meta( $current_user_id, 'freelancer_id' , true );
				if($fre_id == '')
				{
					$return = array('message' => esc_html__( 'Please register as a freelancer first', 'kofejob_core' ));
					wp_send_json_error($return);
				}
			}			

		}
    }
}
//generate random strng for verification

if (!function_exists('kofejob_randomString')) {

    function kofejob_randomString($length = 5)
    {
        $str = "";
        $characters = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
        $max = count($characters) - 1;
        for ($i = 0; $i < $length; $i++) {
            $rand = mt_rand(0, $max);
            $str .= $characters[$rand];
        }
        return $str;
    }

}