Advertisement
manchumahara

Related Time in php for Omar

Mar 20th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.57 KB | None | 0 0
  1. //relative time for twitter and facebook
  2.     function getRelativeTime($utimestamp) {
  3.         $reltime = '';
  4.         if (isset($utimestamp)) {
  5.             $types      = Array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
  6.             $duration   = Array(60, 60, 24, 7, 4.35, 12, 10);
  7.             $gap = (time() - $utimestamp);
  8.             if ($gap > 0) {
  9.                 $end = "ago";
  10.                 //$end = JText::_('COM_MYSOCIALTIMELINE_TIME_AGO');
  11.             } else {
  12.                 $gap = - $gap;
  13.                 $end = "to go";
  14.                 //$end = JText::_('COM_MYSOCIALTIMELINE_TIME_TOGO');
  15.             }
  16.             for ($i = 0; $gap >= $duration[$i]; $i++) {
  17.                 $gap /= $duration[$i];
  18.                 $gap = round($gap);
  19.             }
  20.             if ($gap != 1) {
  21.                 $types[$i].= "s";
  22.                 $typelang = $types[$i];                
  23.                 $typelang = strtoupper($types[$i]);
  24.                 $typelang = 'COM_MYSOCIALTIMELINE_TIME_'.$typelang;
  25.                 $reltime = $gap . ' ' . $types[$i] . ' ' . $end;
  26.                 //$reltime = $gap . ' ' . JText::_($typelang) . ' ' . $end;
  27.             }
  28.             else{
  29.                 //$types[$i].= "s";
  30.                 $typelang = $types[$i];                
  31.                 $typelang = strtoupper($types[$i]);
  32.                 $typelang = 'COM_MYSOCIALTIMELINE_TIME_'.$typelang;
  33.                 $reltime = $gap . ' ' . $types[$i] . ' ' . $end;
  34.                 //$reltime = $gap . ' ' . JText::_($typelang) . ' ' . $end;
  35.             }
  36.             return $reltime;
  37.         }
  38.     }//end function getRelativeTime
  39.  
  40.  
  41.  
  42. /**
  43.      * Linkify url and hashtag
  44.      *
  45.      * @param type $status_text
  46.      * @return type
  47.      */
  48.     function linkify_linkedin_status($status_text){
  49.        
  50.         // linkify URLs
  51.         $status_text = preg_replace(
  52.             '/(https?:\/\/\S+)/',
  53.             '<a href="\1">\1</a>',
  54.             $status_text
  55.         );
  56.        
  57.        
  58.         // linkify twitter users
  59.         //please note that any thing tagged using @ in linkedin takes to twitter
  60.         $status_text = preg_replace(
  61.             '/(^|\s)@(\w+)/',
  62.             '\1@<a target="_blank" href="http://twitter.com/\2">\2</a>',
  63.             $status_text
  64.         );
  65.        
  66.  
  67.         // linkify hash tags
  68.         $status_text = preg_replace(
  69.             '/(^|\s)#(\w+)/',
  70.             '\1#<a target="_blank" href="http://www.linkedin.com/signal/?keywords=%23\2">\2</a>',
  71.             $status_text
  72.         );
  73.  
  74.         return $status_text;
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement