/home2/kerimkazan/dvf/magaza/lib/functions.php
<?php

function m_url_get($url,$ref=false)
{
		if(!$ref)
		{
		$ref = $url;
		}
		$ch = curl_init();
		$timeout = 5;
		curl_setopt ($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
		curl_setopt($ch, CURLOPT_REFERER,$ref);
		curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$data= curl_exec($ch);
		curl_close($ch);
		return $data;
}
function m_u_p($key)
{
	return trim(htmlspecialchars(strip_tags(@$_POST[$key])));
}
function m_u_g($key)
{
	return trim(htmlspecialchars(strip_tags(@$_GET[$key])));
}
function m_a_p($key)
{
	return @trim($_POST[$key]);
}
function m_a_g($key)
{
	return @trim($_GET[$key]);
}
function m_password($data)
{
	return md5($data);
}
function m_set_session($name,$data)
{
	$_SESSION[$name] = $data;
}
function m_delete_session($name)
{
	unset($_SESSION[$name]);
	session_destroy();
}
function m_get_session($name)
{
	return @$_SESSION[$name];
}
function m_image_url($image,$thumb=false)
{		
	if($image=='')		
	{		
		$return = UPLOAD_URL.'/images/blank.png';	
	}		
	else	
	{
		if(file_exists(UPLOAD_DIR.'/images/'.$image))
		{
			if($thumb)
			{
				$return = UPLOAD_URL.'/images/thumb/'.$image;	
			}
			else
			{
				$return = UPLOAD_URL.'/images/'.$image;	
			}
		}
		else
		{
			$return = UPLOAD_URL.'/images/blank.png';	
		}
	}
	return $return;
}
function m_sef($str)
{
     return URLify::slug($str);
}
function m_redirect($url)
{
	header('Location: '.$url.'');
	exit();
}
function m_time_db_format($tarih)
{

	$tarih = date('Y-m-d H:i:s',$tarih);
	return $tarih;
}
function m_date_db_format($tarih)
{
	$tarih = strtotime($tarih);
	$tarih = date('Y-m-d H:i:s',$tarih);
	return $tarih;
}
function m_date_to_tr($tarih)
{
	if($tarih=='')
	{
		return '-';
	}
	else
	{
		return date('d.m.Y H:i',strtotime($tarih));
	}
}
function m_date($tarih)
{
	if($tarih=='')
	{
		return '-';
	}
	else
	{
		return date('d.m.Y',strtotime($tarih));
	}
}
function m_date_full_to_tr($tarih)
{
	if($tarih=='')
	{
		return '-';
	}
	else
	{
		return date('d.m.Y H:i:s',strtotime($tarih));
	}
}
function m_time_to_tr($tarih)
{
	if($tarih=='')
	{
		return '-';
	}
	else
	{
		return date('H:i',strtotime($tarih));
	}
}
function m_time_ago($datetime, $full = false) {
	$now = new DateTime;
	$ago = new DateTime($datetime);
	$diff = $now->diff($ago);

	$diff->w = floor($diff->d / 7);
	$diff->d -= $diff->w * 7;

	$string = array(
		'y' => 'yıl',
		'm' => 'ay',
		'w' => 'hafta',
		'd' => 'gün',
		'h' => 'saat',
		'i' => 'dakika',
		's' => 'saniye',
	);
	foreach ($string as $k => &$v) {
		if ($diff->$k) {
			$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? '' : '');
		} else {
			unset($string[$k]);
		}
	}

	if (!$full) $string = array_slice($string, 0, 1);
	return $string ? implode(', ', $string) . ' önce' : 'şimdi';
}
function m_time_ago_s($datetime, $full = false) {
	$now = new DateTime;
	$ago = new DateTime($datetime);
	$diff = $now->diff($ago);

	$diff->w = floor($diff->d / 7);
	$diff->d -= $diff->w * 7;

	$string = array(
		'y' => 'y',
		'm' => 'a',
		'w' => 'h',
		'd' => 'g',
		'h' => 's',
		'i' => 'd',
		's' => 'sn',
	);
	foreach ($string as $k => &$v) {
		if ($diff->$k) {
			$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? '' : '');
		} else {
			unset($string[$k]);
		}
	}

	if (!$full) $string = array_slice($string, 0, 1);
	return $string ? implode(',', $string).' önce':'1sn';
}
function m_explode($data,$start,$finish,$s,$f)
{
	$return = explode($start,$data);
	$return = explode($finish,$return[$s]);
	return $return[$f];
}
function m_ip()
{
	 if(getenv("HTTP_CLIENT_IP")) {
	 $ip = getenv("HTTP_CLIENT_IP");
	 } elseif(getenv("HTTP_X_FORWARDED_FOR")) {
	 $ip = getenv("HTTP_X_FORWARDED_FOR");
	 if (strstr($ip, ',')) {
	 $tmp = explode (',', $ip);
	 $ip = trim($tmp[0]);
	 }
	 } else {
	 $ip = getenv("REMOTE_ADDR");
	 }
	 return $ip;
}
function m_numbers_only($_input) 
{ 
    return floatval($_input); 
}
function m_currency($number)
{
	if($number=='')
	{
		$number = '0.00';
	}
	else
	{
	$number = number_format($number,2,',','.');
	}
	return $number;
}

function m_r_time($bitmesi_gereken)
{
	
	$tarih1 = new DateTime(date('Y-m-d H:i:s'));
	$tarih2 = new DateTime($bitmesi_gereken);
	$interval = $tarih1->diff($tarih2);
	$fark_gun = $interval->format("%d");
	$fark_saat = $interval->format("%h");
	$fark_dakika = $interval->format("%i");
	if(time()>strtotime($bitmesi_gereken))
	{
		return '0 Dakika';
	}
	else
	{
		return ''.$fark_saat.' Saat '.$fark_dakika.' Dakika';
	}
}


function strip_tags_content($text, $tags = '', $invert = FALSE) 
{

  preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
  $tags = array_unique($tags[1]);
   
  if(is_array($tags) AND count($tags) > 0) {
	if($invert == FALSE) {
	  return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
	}
	else {
	  return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
	}
  }
  elseif($invert == FALSE) {
	return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
  }
  return $text;
}

function entities( $string ) 
{
	$stringBuilder = "";
	$offset = 0;

	if ( empty( $string ) ) {
		return "";
	}

	while ( $offset >= 0 ) {
		$decValue = ordutf8( $string, $offset );
		$char = unichr($decValue);

		$htmlEntited = htmlentities( $char );
		if( $char != $htmlEntited ){
			$stringBuilder .= $htmlEntited;
		} elseif( $decValue >= 128 ){
			$stringBuilder .= "&#" . $decValue . ";";
		} else {
			$stringBuilder .= $char;
		}
	}

	return $stringBuilder;
}
function ordutf8($string, &$offset) 
{
	$code = ord(substr($string, $offset,1));
	if ($code >= 128) {        //otherwise 0xxxxxxx
		if ($code < 224) $bytesnumber = 2;                //110xxxxx
		else if ($code < 240) $bytesnumber = 3;        //1110xxxx
		else if ($code < 248) $bytesnumber = 4;    //11110xxx
		$codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0);
		for ($i = 2; $i <= $bytesnumber; $i++) {
			$offset ++;
			$code2 = ord(substr($string, $offset, 1)) - 128;        //10xxxxxx
			$codetemp = $codetemp*64 + $code2;
		}
		$code = $codetemp;
	}
	$offset += 1;
	if ($offset >= strlen($string)) $offset = -1;
	return $code;
}
function unichr($u) {
	return mb_convert_encoding('&#' . intval($u) . ';', 'UTF-8', 'HTML-ENTITIES');
}


function m_alert($title,$data)
{
	switch($title)
	{
		case 'Hata':
		$type = 'danger';
		$icon = 'fa-exclamation-triangle';
		break;
		case 'Bilgi':
		$type = 'info';
		$icon = 'fa-info';
		break;
		case 'Başarılı':
		$type = 'success';
		$icon = 'fa-check';
		break;
		default;
		$type = "info";
	}
	return '<div class="alert alert-'.$type.'"  style="word-break: break-word;"> <i class="fa '.$icon.'"></i> 
  '.$title.' - '.$data.'
</div>';
}
function m_status($data)
{
	if($data==0)
	{
		return '<span class="badge bg-warning">Pasif</span>';
	}
	if($data==1)
	{
		return '<span class="badge bg-success">Aktif</span>';
	}
	
}

function m_setting($data)
{
	$db = new DB();
	
	$return = $db->table('settings')->where('id','=','1')->get_var($data);
	
	return $return;
}



function m_authority($authoritys,$authority)
{

	$authority_check = m_explode($authoritys,'<'.$authority.'>','</'.$authority.'>',1,0);
	if($authority_check=='1')
	{
		return true;
	}
	else
	{
		return false;
	}
}


function variant_types()
{
	$list = array('Beden','Renk','Numara','Gram','Kilo','Ağırlık','Uzunluk','Genişlik','Metre');
	
	return $list;
}

function price_types()
{
	$list = array('TL','$','€');
	
	return $list;
}


function m_percent($number,$percent){ 
    return ($number*$percent)/100;
}

?>