<?php
//echo $st = date("d-M-Y H:i:s");
//echo "<br>".time2str($st);
error_reporting(0);
session_start();
function time2str($ts)
{
    if(!ctype_digit($ts))
        $ts = strtotime($ts);

    $diff = time() - $ts;
    if($diff == 0)
        return '0 minute ago';
    elseif($diff > 0)
    {
        $day_diff = floor($diff / 86400);
        if($day_diff == 0)
        {
            if($diff < 60) return '0 minute ago';
            if($diff < 120) return '1 minute ago';
            if($diff < 3600) return floor($diff / 60) . ' minutes ago';
            if($diff < 7200) return '1 hour ago';
            if($diff < 86400) return floor($diff / 3600) . ' hours ago';
        }
        if($day_diff == 1) return 'Yesterday';
        if($day_diff < 7) return $day_diff . ' days ago';
        if($day_diff < 31) return ceil($day_diff / 7) . ' weeks ago';
        if($day_diff < 60) return 'last month';
        return date('F Y', $ts);
    }
    else
    {
        $diff = abs($diff);
        $day_diff = floor($diff / 86400);
        if($day_diff == 0)
        {
            if($diff < 120) return 'in a minute';
            if($diff < 3600) return 'in ' . floor($diff / 60) . ' minutes';
            if($diff < 7200) return 'in an hour';
            if($diff < 86400) return 'in ' . floor($diff / 3600) . ' hours';
        }
        if($day_diff == 1) return 'Tomorrow';
        if($day_diff < 4) return date('l', $ts);
        if($day_diff < 7 + (7 - date('w'))) return 'next week';
        if(ceil($day_diff / 7) < 4) return 'in ' . ceil($day_diff / 7) . ' weeks';
        if(date('n', $ts) == date('n') + 1) return 'next month';
        return date('F Y', $ts);
    }
}

function DisplayContent($val){
	$url =explode('/',$val);
	if($url[2]=='vimeo.com' || $url[2]=='www.vimeo.com'){
		$count_url = count($url);
		$vimeo_link =  'http://vimeo.com/'.$url[$count_url-1];
		$vimeo_link = str_replace('http://vimeo.com/', 'http://vimeo.com/api/v2/video/', $vimeo_link) . '.php';
		$html_returned = unserialize(file_get_contents($vimeo_link));
		$title_vimo = $html_returned[0]['title'];
		$thumb_url = $html_returned[0]['thumbnail_medium'];
		return '<label>'.$title_vimo.'</label><br><a href="videos.php?vimeo='.$url[$count_url-1].'"  class="a" target="_blank" ><img src="'.$thumb_url.'" style="width: 120px;height: 90px;"></a>';
	}else if($url[2]=='youtube.com' || $url[2]=='www.youtube.com'){
		$youtube_count = count($url);
		$youtubecode = explode('=',$url[$youtube_count-1]);
		$video_code = $youtubecode[1];
		$content = file_get_contents("http://www.youtube.com/get_video_info?video_id=".$video_code);
		parse_str($content, $ytarr);
		return '<label>'.$ytarr['title'].'</label><br><a href="videos.php?youtube='.$video_code.'"  class="a" target="_blank" ><img src="http://img.youtube.com/vi/'.$video_code.'/1.jpg"></a>';
	}else{
		$img =explode('-',$val);
		if($img[0]=='images'){
			$rand = rand();
			$_SESSION["'".$rand."'"] = $img[1];
			return '<a href="videos.php?images='.$rand.'"  class="a" target="_blank" ><img src="uploads/statusimg/'.$img[1].'" style="max-width: 300px;"></a>';
		}else{
			$val = str_replace('o:)','<img src="emotions/angel.gif" title="angel" /> ',$val);
			$val = str_replace(':3','<img src="emotions/colonthree.gif" title="colonthree" /> ',$val);
			$val = str_replace('o.O','<img src="emotions/confused.gif" title="confused" /> ',$val);
			$val = str_replace(":'(",'<img src="emotions/cry.gif" title="cry" /> ',$val);
			$val = str_replace('3:)','<img src="emotions/devil.gif" title="devil" /> ',$val);
			$val = str_replace(':(','<img src="emotions/frown.gif" title="frown" /> ',$val);
			$val = str_replace(':O','<img src="emotions/gasp.gif" title="gasp" /> ',$val);
			$val = str_replace('8)','<img src="emotions/glasses.gif" title="glasses" /> ',$val);
			$val = str_replace(':D','<img src="emotions/grin.gif" title="grin" /> ',$val);
			$val = str_replace('>:(','<img src="emotions/grumpy.gif" title="grumpy" /> ',$val);

			$val = str_replace('<3','<img src="emotions/kissto.png" title="kiki" /> ',$val);
			$val = str_replace('^_^','<img src="emotions/kiki.gif" title="kiki" /> ',$val);
			$val = str_replace(':*:','<img src="emotions/kiss.png" title="kiss" /> ',$val);
$val = str_replace(':*','<img src="emotions/kiss.gif" title="kiss" /> ',$val);
			$val = str_replace(':v','<img src="emotions/pacman.gif" title="pacman" /> ',$val);
			$val = str_replace(':)','<img src="emotions/smile.gif" title="smile" /> ',$val);
			$val = str_replace('-_-','<img src="emotions/squint.gif" title="squint" /> ',$val);
			$val = str_replace('8|','<img src="emotions/sunglasses.gif" title="sunglasses" /> ',$val);
			$val = str_replace(':/','<img src="emotions/unsure.gif" title="unsure" /> ',$val);
			$val = str_replace(':p','<img src="emotions/tongue.gif" title="tongue" /> ',$val);
			$val = str_replace('>:O','<img src="emotions/upset.gif" title="upset" /> ',$val);
			$val = str_replace(';)','<img src="emotions/wink.gif" title="wink" /> ',$val);
$val = str_replace('cry1','<img src="emotions/cry.gif" title="wink" /> ',$val);
$val = str_replace('cry2','<img src="emotions/cry2.jpg" title="wink" /> ',$val);
$val = str_replace('cry3','<img src="emotions/cry3.jpeg" title="wink" /> ',$val);
$val = str_replace('cry4','<img src="emotions/cry4.png" title="wink" /> ',$val);
$val = str_replace('cry5','<img src="emotions/cry5.jpeg" title="wink" /> ',$val);
$val = str_replace('cry6','<img src="emotions/cry6.png" title="wink" /> ',$val);
//$val = str_replace('love','<img src="emotions/love.jpg" title="wink" /> ',$val);
			return $val;
		}
	}
}
?>