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



function FUNCT_DM_FRM($username=''){

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

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

	

	$retval = '';

	

	if(strpos($username,"@") !== false){

		$tmpname = substr($username,1);

	}else{

		header("Location: ".$url."users/messages");

		exit();

	}

	

	$retval = '

	<SCRIPT Language="JavaScript">

		<!--

		function textCounter(field,cntfield,maxlimit) {

			if (field.value.length > maxlimit) // if too long...trim it!

				field.value = field.value.substring(0, maxlimit);

				// otherwise, update \'characters left\' counter

			else

				cntfield.value = maxlimit - field.value.length;

			}

			window.onload = function() {textCounter(document.chirpForm.message1,document.chirpForm.remLen1,141);

		}

		// --> 

	</script>



	<div class="txtbox">

		<form name="chirpForm" method="post" action="'.$url.'users/messages">

			'.$dmincmsg1a.$tmpname.$dmincmsg1b.'

			<input type="hidden" value="'.$username.'" name="username" />

			<TEXTAREA noscroll cols="55" rows="3" name="message1" onKeyDown="textCounter(document.chirpForm.message1,document.chirpForm.remLen1,141)"

			onKeyUp="textCounter(document.chirpForm.message1,document.chirpForm.remLen1,141)"></TEXTAREA>

			<br />

			<span style="float:right"><input readonly type="text" name="remLen1" size="3" maxlength="3" value="141" id="the151"><input type="SUBMIT" value="'.$dmincmsg2.'" /></span>

		</form>

	</div>';



	return $retval;	

}



function directDBNFO($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');

	$retval = '';

	$num_per_page = $num_msg_to_show;

	$curpage = 'is_empty';

	$curpagenext = '';

	$curpageback = '';

	

	$result = mysql_query('SELECT directmessages.MSGID, directmessages.TO_USERNAME, directmessages.FROM_USERNAME, directmessages.ENTRYDATE, directmessages.MESSAGE, users.USERID AS USERID FROM directmessages INNER JOIN users ON directmessages.FROM_USERNAME = users.USERNAME WHERE directmessages.TO_USERNAME = "'.$_SESSION["USERNAME"].'" 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('SELECT directmessages.MSGID, directmessages.TO_USERNAME, directmessages.FROM_USERNAME, directmessages.ENTRYDATE, directmessages.MESSAGE, users.USERID AS USERID FROM directmessages INNER JOIN users ON directmessages.FROM_USERNAME = users.USERNAME WHERE directmessages.TO_USERNAME = "'.$_SESSION["USERNAME"].'" 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){

		$retval = $dmincmsg3;

	}else{

		while ($row = mysql_fetch_array($result)){

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

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

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

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

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

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

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

			$usermsg = stripslashes($usermsg);

			$usermsg = autolink($usermsg);

			$usermsg = findnames($usermsg);

			if ($enable_emoticons == 1){

				$usermsg = smiley2emoticons($usermsg);

			}

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

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

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

			$adDel = '<a href="%URL%users/messages/deldm/' . $row['MSGID'] . '" title="'.$msgblock5.'"><img src="%URL%themes/'.$theme.'/images/trash.gif" border="0" align="absmiddle"></a><a href="%URL%users/messages/reply/@' . $row['FROM_USERNAME'] . '" title="Reply"><img src="%URL%themes/'.$theme.'/images/reply.gif" border="0" align="absmiddle"></a> ';

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

//================ 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);

			}

			$retval .= $msglist;



		}

	}

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

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

		$back_page = $page - $num_per_page;

		$retval .= "<a href=\"%URL%users.php?id=messages&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;

		$retval .= "&nbsp;&nbsp;<a href=\"%URL%users.php?id=messages&page=" . $next_page . "\" >".$msgblock7."</a>\n";

	}

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

	return $retval;

}



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.'">'.$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