Pages

English representation of a past date

Function given below returns an english representation of a past date within the last month.
function time2str($ts)
{
 if(!ctype_digit($ts))
  $ts = strtotime($ts);

 $diff = time() - $ts;
 if($diff == 0)
  return 'now';
 elseif($diff > 0)
 {
  $day_diff = floor($diff / 86400);
  if($day_diff == 0)
  {
   if($diff < 60) return 'just now';
   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);
 }
}
 

Google Hosted Javascript Libraries

The Google Hosted Libraries provides your applications with stable, reliable, high-speed, globally available access to all of the most popular, open-source JavaScript libraries.To load a hosted library, copy and paste the HTML snippet for that library (shown below) in your web page. For instance, to load jQuery, embed the <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> snippet in your web page.
jQuery
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

jQuery Mobile
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.css" />

<script src="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.js"></script> 

jQuery UI
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script> 

Open External Links in New Window - jQuery

Manually attributing all the external links on your site with "target="_blank"" might be an exceptionally disappointing assignment. You can stay away from this wild undertaking by utilizing the below given script.
$('a').each(function() {  
  var a = new RegExp('/' + [removed].host + '/');  
  if(!a.test(this.href)) {  
    $(this).click(function(event) {  
      event.preventDefault();  
      event.stopPropagation();  
      window.open(this.href, '_blank');  
    });  
 }  
});