<?php
/**
 * The helper file for framework.
 *
 * @package Smart_Post_Show_Pro
 * @subpackage Smart_Post_Show_Pro/admin/views
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
} // Cannot access directly.

if ( ! function_exists( 'spf_array_search' ) ) {
	/**
	 *
	 * Array search key & value
	 *
	 * @param mixed $array array.
	 * @param mixed $key key.
	 * @param mixed $value value.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_array_search( $array, $key, $value ) {

		$results = array();

		if ( is_array( $array ) ) {
			if ( isset( $array[ $key ] ) && $array[ $key ] == $value ) {
				$results[] = $array;
			}

			foreach ( $array as $sub_array ) {
				$results = array_merge( $results, spf_array_search( $sub_array, $key, $value ) );
			}
		}

		return $results;

	}
}

if ( ! function_exists( 'spf_get_var' ) ) {
	/**
	 *
	 * Getting POST Var
	 *
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_get_var( $var, $default = '' ) {

		if ( isset( $_POST[ $var ] ) ) {
			return $_POST[ $var ];
		}

		if ( isset( $_GET[ $var ] ) ) {
			return $_GET[ $var ];
		}

		return $default;

	}
}


if ( ! function_exists( 'spf_get_vars' ) ) {
	/**
	 *
	 * Getting POST Vars
	 *
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_get_vars( $var, $depth, $default = '' ) {

		if ( isset( $_POST[ $var ][ $depth ] ) ) {
			return $_POST[ $var ][ $depth ];
		}

		if ( isset( $_GET[ $var ][ $depth ] ) ) {
			return $_GET[ $var ][ $depth ];
		}

		return $default;

	}
}

if ( ! function_exists( 'spf_pcp_microtime' ) ) {
	/**
	 *
	 * Between Microtime
	 *
	 * @param mixed $timenow curren time.
	 * @param mixed $starttime start time.
	 * @param mixed $timeout timeout.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_pcp_timeout( $timenow, $starttime, $timeout = 30 ) {

		return ( ( $timenow - $starttime ) < $timeout ) ? true : false;

	}
}

