<?php
	function btn_edit($uri){
		return anchor($uri, 'Edit', 'class="btn mr-1 mb-1 btn-success btn-sm"');
	}

	function btn_view($uri){
		return anchor($uri, 'View', 'class="btn mr-1 mb-1 btn-warning btn-sm"');
	}

	function btn_delete($uri){
		$a = '<a href="javascript:void(0);" title="Delete" class = "btn mr-1 mb-1 btn-sm btn-danger" onclick="delete_row('."'".trim(base_url().$uri)."'".')">Delete</a>';
		return $a;
	}

	function cleanInput($string) {

		$search = array(
	        '@<script[^>]*?>.*?</script>@si'        // Strip multi-line comments
	    );
	    $string = preg_replace($search, '', $string);
		return htmlspecialchars($string,ENT_QUOTES,'UTF-8');
	}

	if (!function_exists('dump')) {
	    function dump ($var, $label = 'Dump', $echo = TRUE)
	    {
	        // Store dump in variable 
	        ob_start();
	        var_dump($var);
	        $output = ob_get_clean();
	        
	        // Add formatting
	        $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
	        $output = '<pre style="background: #FFFEEF; color: #000; border: 1px dotted #000; padding: 10px; margin: 10px 0; text-align: left;">' . $label . ' => ' . $output . '</pre>';
	        
	        // Output
	        if ($echo == TRUE) {
	            echo $output;
	        }
	        else {
	            return $output;
	        }
	    }
	}


	if (!function_exists('dump_exit')) {
	    function dump_exit($var, $label = 'Dump', $echo = TRUE) {
	        dump ($var, $label, $echo);
	        exit;
	    }
	}


	if (!function_exists('set_shoutout_cookie')) {
	    function set_shoutout_cookie ($mycookie, $mycookievalue = 1, $expiry = 30){
	    	setcookie($mycookie, $mycookievalue, $expiry);
	    }
	}

	if (!function_exists('get_shoutout_cookie')) {
	    function get_shoutout_cookie ($mycookie){
	    	if (isset($_COOKIE[$mycookie])) {
	    		list($value, $expiry) = explode("|", $_COOKIE[$mycookie]);
	    		if($value == 1){
		    		if(time() > $expiry){
		    			return 0;
		    		}else{
		    			return $value;
		    		}
		    	}else{
		    		return 0;
		    	}
	    	}else{
	    		return 0;
	    	}
	    }
	}


	if(!function_exists("slugify")){
		function slugify($text){
			// replace non letter or digits by -
			$text = preg_replace('~[^\pL\d]+~u', '-', $text);

			// transliterate
			//$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

			// remove unwanted characters
			$text = preg_replace('~[^-\w]+~', '', $text);

			// trim
			$text = trim($text, '-');

			// remove duplicate -
			$text = preg_replace('~-+~', '-', $text);

			// lowercase
			$text = strtolower($text);



			if (empty($text)) {
			return 'n-a';
			}

			return $text;
		}

		if(!function_exists("my_hash")){
			function my_hash($string){
				return hash('sha512', $string . config_item('encryption_key'));
			}
		}


		if (!function_exists('random_string')) {

			function random_string($length = 4){
		        $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
		        $str = '';
		        $max = strlen($characters) - 1;
		        for ($i = 0; $i < $length  ; $i++) {
		            $str .= $characters[mt_rand(0, $max)];
		        }
		        return $str; 
		    }
		}

		if (!function_exists('random_numeric_string')) {

			function random_numeric_string($length = 4){
		        $characters = '0123456789012345678998745632147890123564789';
		        $str = '';
		        $max = strlen($characters) - 1;
		        for ($i = 0; $i < $length  ; $i++) {
		            $str .= $characters[mt_rand(0, $max)];
		        }
		        return $str; 
		    }
		}
	}
?>