Location: PHPKode > projects > Chirp: The Microblog > chirp.v.1.1/includes/messages.inc.php
<?php



function getDBNFO($sesID, $sesquery, $page=0) {

	include("includes/config.inc.php");

	include("includes/emoticon.inc.php");

	include("language/language.".$language.".php");

	

	$msgblock = file_get_contents('themes/'.$theme.'/msg_block.theme.html');

	$msgstream = '';

	$num_per_page = $num_msg_to_show;

	$curpage = 'is_empty';

	$curpagenext = '';

	$curpageback = '';

	

	$result = mysql_query($sesquery." ORDER BY ENTRYDATE ASC");

//================== Top Pagination Section ======================================	

	$num = @mysql_num_rows($result);

	$pages = intval($num/$num_per_page); // Number of results pages.

	if ($num%$num_per_page) {

		$pages++;

	} // has remainder so add one page

	$current = ($page/$num_per_page) + 1; // Current page number.

	if (($pages < 1) || ($pages == 0)) {

		$total = 1;

	} else {

		$total = $pages;

	} // Else total pages is $pages value.

	$first = $page + 1; // The first result.

	if (!((($page + $num_per_page) / $num_per_page) >= $pages) && $pages != 1) {

		$last = $page + $num_per_page;

	} else {

		$last = $num;

	} // If last results page, last result equals total number of results.

//================== Top Pagination Section ======================================	

	

	$result = mysql_query($sesquery." ORDER BY ENTRYDATE DESC LIMIT ".$page.", ".$num_per_page);

	if (mysql_errno()) {

          die("<br />" . mysql_errno() . ": " . mysql_error() . "<br />");

     }

	$num = @mysql_num_rows($result);

	if ( $num > 0 ) {

		while($row = @mysql_fetch_assoc($result)){

			$myuser = mysql_query("SELECT users.USERNAME FROM users WHERE users.USERID = " . $row['USERID'] . " LIMIT 1");

			$myrow = @mysql_fetch_array($myuser);

			$username 	= '<a href="%URL%@'.$myrow['USERNAME'].'" title="'.$myrow['USERNAME'].'">'.$myrow['USERNAME'].'</a>';

			$userimg 	= '<img src="%URL%image.php?img='. $row['USERID'].'" width="48" height="48" />';

			$usermsg 	= stripslashes($row['USERMSG']);

			$userdate 	= TimeToJourJ($row['ENTRYDATE']);

			

//==========================================================

//============= START MANIPULATE $usermsg HERE =============

//==========================================================

			$usermsg = stripslashes($usermsg);

			$usermsg = autolink($usermsg);

			$usermsg = findnames($usermsg);

			if ($enable_emoticons == 1){

				$usermsg = smiley2emoticons($usermsg);

			}

			

			// Determine if friend or not

			$isfrnd = mysql_query("SELECT * FROM friends WHERE FRIENDID = ".$row['USERID']." AND USERID = ".$sesID." LIMIT 1");

			if (mysql_errno()) {

          		die("<br />" . mysql_errno() . ": " . mysql_error() . "<br />");

      		} else {

        		$isfrndcnt = mysql_num_rows($isfrnd);

				if($isfrndcnt > 0){

					$isfrndact = $msgblock2;

					$isfrndimg = "greendot.gif";

				}else{

					$isfrndact = $msgblock1;

					$isfrndimg = "chat.gif";

				}

      		}

			// Determine if favorite or not

			//echo "SELECT * FROM favorites WHERE MSGID = ".$row['ID']." AND USERID = ".$sesID." LIMIT 1";

			$isfav = mysql_query("SELECT * FROM favorites WHERE MSGID = '".$row['ID']."' AND USERID = ".$sesID." LIMIT 1");

			if (mysql_errno()) {

          		die("<br />" . mysql_errno() . ": " . mysql_error() . "<br />");

      		} else {

        		$isfavcnt = mysql_num_rows($isfav);

				if($isfavcnt > 0){

					$isfavact = $msgblock4;

					$isfavimg = "greendot.gif";

				}else{

					$isfavact = $msgblock3;

					$isfavimg = "flag.gif";

				}

      		}

			if ($row['USERID'] == $sesID){

				$adDel = '<a href="%URL%'.$_SESSION['loc'].'/fav/'.$row['ID'].'" title="'.$isfavact.'"><img src="%URL%themes/'.$theme.'/images/'.$isfavimg.'" border="0" align="absmiddle"></a><a href="%URL%'.$_SESSION['loc'].'/del/' . $row['ID'] . '" title="'.$msgblock5.'"><img src="%URL%themes/'.$theme.'/images/trash.gif" border="0" align="absmiddle"></a>';

			}else{

				$adDel = '<a href="%URL%'.$_SESSION['loc'].'/fav/'.$row['ID'].'" title="'.$isfavact.'"><img src="%URL%themes/'.$theme.'/images/'.$isfavimg.'" border="0" align="absmiddle"></a><a href="%URL%'.$_SESSION['loc'].'/friend/'. $row['USERID'] . '" title="'.$isfrndact.'"><img src="%URL%themes/'.$theme.'/images/'.$isfrndimg.'" border="0" align="absmiddle"></a>';

			}

			

//========================================================

//============= END MANIPULATE $usermsg HERE =============

//========================================================



//========================================================

//================ THEME INDUCTION SECTION ===============

//========================================================

			if(strpos($msgblock,"%PROFPIX%") !== false){

				$msglist = str_replace('%PROFPIX%',$userimg,$msgblock);

			}

			if(strpos($msglist,"%USERNAME%") !== false){

				$msglist = str_replace('%USERNAME%',$username,$msglist);

			}

			if(strpos($msglist,"%MSSGSTREAM%") !== false){

				$msglist = str_replace('%MSSGSTREAM%',$usermsg,$msglist);

			}

			if(strpos($msglist,"%ENTRYDATE%") !== false){

				$msglist = str_replace('%ENTRYDATE%',$userdate,$msglist);

			}

			if(strpos($msglist,"%MSSGMENU%") !== false){

				$msglist = str_replace('%MSSGMENU%',$adDel,$msglist);

			}

			$msgstream .= $msglist;

		}

	}



//================== Bottom Pagination Section ======================================

	if ($page != 0) { // Don't show back link if current page is first page.

		$back_page = $page - $num_per_page;

		$msgstream .= "<a href=\"%URL%index.php?loc=".$_SESSION['loc']."&page=" . $back_page . "\">".$msgblock6."</a>&nbsp;&nbsp;\n";

	}

	if (!((($page+$num_per_page) / $num_per_page) >= $pages) && $pages != 1) { // If last page don't give next link.

		$next_page = $page + $num_per_page;

		$msgstream .= "&nbsp;&nbsp;<a href=\"%URL%index.php?loc=".$_SESSION['loc']."&page=" . $next_page . "\" >".$msgblock7."</a>\n";

	}

//================== Bottom Pagination Section ======================================



	return $msgstream;

}



function findnames( &$text ){

	

	$pattern = '/@[a-zA-Z0-9]*/';

	

	preg_match_all($pattern, $text, $matches);



	for ($i=0;$i <= count($matches[0])-1; $i++){

		$name = substr($matches[0][$i],1,strlen($matches[0][$i]));

		$nameresult = mysql_query("SELECT * FROM users WHERE USERNAME = '".$name."' LIMIT 1");

		$namecnt = mysql_num_rows($nameresult);

		if($namecnt > 0){

			$text = eregi_replace('@'.$name,'@<a href="@'.$name.'" target="_blank">'.$name.'</a>',$text);

		}

	}

	return $text;

}



/*=======================================*/

//   NAME        : autolink()

//   VERSION     : 1.0

//   AUTHOR      : J de Silva

//   URL		 : http://www.desilva.biz

//   DESCRIPTION : returns VOID; handles converting

//                 URLs into clickable links off a string.

//   TYPE        : functions

/*=======================================*/

//               START



function autolink( &$text, $target='_blank', $nofollow=true )

{

		

  // grab anything that looks like a URL...

  $urls  =  _autolink_find_URLS( $text );

  if( !empty($urls) ) // i.e. there were some URLS found in the text

  {

    array_walk( $urls, '_autolink_create_html_tags', array('target'=>$target, 'nofollow'=>$nofollow) );

    $text  =  strtr( $text, $urls );

  }

  

  return $text;

}



function _autolink_find_URLS( $text )

{

  // build the patterns

  $scheme         =       '(http:\/\/|https:\/\/)';

  $www            =       'www\.';

  $ip             =       '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';

  $subdomain      =       '[-a-z0-9_]+\.';

  $name           =       '[a-z][-a-z0-9]+\.';

  $tld            =       '[a-z]+(\.[a-z]{2,2})?';

  $the_rest       =       '\/?[a-z0-9._\/~#&=;%+?-]+[a-z0-9\/#=?]{1,1}';            

  $pattern        =       "$scheme?(?(1)($ip|($subdomain)?$name$tld)|($www$name$tld))$the_rest";

    

  $pattern        =       '/'.$pattern.'/is';

  $c              =       preg_match_all( $pattern, $text, $m );

  unset( $text, $scheme, $www, $ip, $subdomain, $name, $tld, $the_rest, $pattern );

  if( $c )

  {

    return( array_flip($m[0]) );

  }

  return( array() );

}



function _autolink_create_html_tags( &$value, $key, $other=null )

{

  $target = $nofollow = null;

  if( is_array($other) )

  {

    $target      =  ( $other['target']   ? " target=\"$other[target]\"" : null );

    $nofollow    =  ( $other['nofollow'] ? ' rel="nofollow"'            : null );     

  }

  $pos = strrpos($key, "http://");

  if ($pos === false) {

  	$key = "http://".$key;

  }

  $value = '<a href="'.$key.'" '.$target.' '.$nofollow.' id="msglnk">'.$key.'</a>';

} 

//               END

/*=======================================*/

//   NAME        : autolink()

//   VERSION     : 1.0

//   AUTHOR      : J de Silva

//   URL		 : http://www.desilva.biz

//   DESCRIPTION : returns VOID; handles converting

//                 URLs into clickable links off a string.

//   TYPE        : functions

/*=======================================*/





function Date_ConvertSqlTab($date_sql) {



    $jour = substr($date_sql, 8, 2);

    $mois = substr($date_sql, 5, 2);

    $annee = substr($date_sql, 0, 4);

    $heure = substr($date_sql, 11, 2);

    $minute = substr($date_sql, 14, 2);

    $seconde = substr($date_sql, 17, 2);

	

    

    $key = array('annee', 'mois', 'jour', 'heure', 'minute', 'seconde');

    $value = array($annee, $mois, $jour, $heure, $minute, $seconde);

    

    $tab_retour = array_combine($key, $value);

    

    return $tab_retour;

}



function AuPluriel($chiffre) {

    if(($chiffre>1) || ($chiffre=0)) {

        return 's';

    };

}



function TimeToJourJ($date_sql) {

    $tab_date = Date_ConvertSqlTab($date_sql);

    $mkt_jourj = mktime($tab_date['heure'],

                    $tab_date['minute'],

                    $tab_date['seconde'],

                    $tab_date['mois'],

                    $tab_date['jour'],

                    $tab_date['annee']);



    $mkt_now = time();

	

	$dateDiff = $mkt_now - $mkt_jourj;

	$fullDays    = floor($dateDiff/(60*60*24));

	$fullHours   = floor(($dateDiff-($fullDays*60*60*24))/(60*60));

	$fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);

	

	if($fullDays > 0){

		return '<strong>'.$fullDays.' day'.AuPluriel($fullDays).' ago</strong>.';

	}elseif($fullHours > 0){

		return '<strong>'.$fullHours.' hour'.AuPluriel($fullHours).' ago</strong>.';

	}elseif($fullMinutes >= 0){

		return '<strong>'.$fullMinutes.' minute'.AuPluriel($fullMinutes).' ago</strong>.';

	}

}



?>
Return current item: Chirp: The Microblog