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

function FUNCT_USER_SEARCH($search){

	

	/*$kt=split(",",$search);

	$sql = '';

	while(list($key,$val)=each($kt)){

		if($val<>" " and strlen($val) > 0){

			$sql .= "USERNAME LIKE '%" . trim($val) . "%' OR EMAIL LIKE '%" . trim($val)  ."%' OR CITY LIKE '%" .  trim($val) . "%' OR STATE LIKE '%" .  trim($val) . "%' OR FIRSTNAME LIKE '%" .  trim($val) . "%' OR LASTNAME LIKE '%" .  trim($val) . "%' OR ZIPCODE LIKE '%" .  trim($val) . "%' or ";

		}

	}*/

	//$sql = substr($sql,0,(strlen($sql)-3));

	//$sql = "SELECT * FROM users WHERE (" . $sql . ")";

		

	//I decided to go with a full text search.  

	$sql = 'SELECT * FROM users WHERE MATCH(USERNAME,FIRSTNAME,LASTNAME,EMAIL,CITY,STATE,ZIPCODE) AGAINST("'.$search.'" IN BOOLEAN MODE)';



	return $sql;

}



function SEARCH_FORM(){

	$retval = '

    <form  method="post" action="%URL%search"  id="searchform"> 

      <input  type="text" name="name" style="min-width:150px;max-width:350px;width:auto;"> 

      <input  type="submit" name="submit" value="Search"> 

    </form>';

	

	return $retval;	

}



function FUNCT_WORD_FILTER($msg1){

	$retval = $msg1;

	

	$result = mysql_query("SELECT * FROM wordfilter");

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

		if (strpos($msg1,$row['BADWORD']) !== false){

			$retval = str_replace($row['BADWORD'],$row['GOODWORD'],$msg1);

		}

	}

	return $retval;

}



function keywords_funct($usermsg) {

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



	$usermsg = strtoupper($usermsg);

	$tmpbad = strtoupper($keywords);

	$keywords = explode(",",$tmpbad);

	$ding = "GOOD";

	$i = 0;

	

	while (($ding == "GOOD") && ($i <= count($keywords)-1)){

		if (strpos($usermsg, $keywords[$i]) !== FALSE) {

			$ding = "BAD";	

		}

		$i++;

	}

	return $ding;

}



function FUNCT_GET_LOGIN($uname='', $pword = ''){

	$uname = mysql_real_escape_string($uname);

	$pword = mysql_real_escape_string($pword);

	$sql = 'SELECT * FROM users WHERE (EMAIL = "'.$uname.'" OR USERNAME = "'.$uname.'") AND PASSWORD = "'.md5($pword).'" LIMIT 1';

	$result = mysql_query($sql);

	if (mysql_errno()){

		return false;

	}else{

		$cnt = mysql_num_rows($result);

		if ($cnt > 0){

			$row = mysql_fetch_array($result);

			if ($row['BANNED'] == 'no'){

				$_SESSION['USERID'] = $row['USERID'];

				$_SESSION['USERNAME'] = $row['USERNAME'];

				$_SESSION['EMAIL'] = $row['EMAIL'];

				$_SESSION['loggedon'] = true;

				$_SESSION['ISADMIN'] = $row['ISADMIN'];

				return true;

			}else{

				die('<center><strong>The account has been banned.  Please contact support.</strong></center>');

			} 

		}else{

			return false;

		}

	}

}



function USER_MENU_SPAN(){

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

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

	

	$usermenu = '

	<a href="%URL%home"><span>'.$mnumsg1.'</span></a>

	<a href="%URL%profile"><span>'.$mnumsg2.'</span></a>

	<a href="%URL%account"><span>'.$mnumsg3.'</span></a>

	<a href="%URL%logout"><span>'.$mnumsg4.'</span></a>';

	

	return $usermenu;	

}





function FUNCT_USER_INFO(){

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

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

		

		$usersql = 'SELECT * FROM users WHERE USERID = '.$_SESSION['USERID'].' LIMIT 1';

		$msgsql = 'SELECT USERID FROM chirpmsg WHERE USERID = '.$_SESSION['USERID'];

		$followingsql = 'SELECT * FROM friends WHERE USERID = '.$_SESSION['USERID'];

		$followedby = 'SELECT FRIENDID FROM friends WHERE FRIENDID = '.$_SESSION['USERID'];

		

		$result = mysql_query($usersql) or die();

		$cnt = mysql_num_rows($result);

		if($cnt > 0){

			$row = mysql_fetch_array($result);

			$userinfo = '<div style="float:left;width:auto;width:45px;margin-right:15px;"><img src="%URL%image.php?img='.$_SESSION['USERID'].'" alt='.$row['USERNAME'].' width="30" height="30" align="absmiddle" class="profilepic"></div>&nbsp;&nbsp;<span class="profilename">'.$row['USERNAME']."</span>";

		}

		$result = mysql_query($msgsql) or die();

		$cnt1 = mysql_num_rows($result);

		$result = mysql_query($followingsql) or die();

		$cnt2 = mysql_num_rows($result);

		$result = mysql_query($followedby) or die();

		$cnt3 = mysql_num_rows($result);

		$userinfo .= '<span class="profilemsg">'.$profmsg1.$cnt1.'</span><br />';

		$userinfo .= '<table border="0" width="100%" class="profcnttbl">

			<tr>

				<td align="left"><span class="profcnt">'.$cnt2.'</span><br /><a href="%URL%following">'.$profmsg2.'</a></td><td align="left"><span class="profcnt">'.$cnt3.'</span><br /><a href="%URL%followers">'.$profmsg3.'</a></td>

			</tr>

		</table>';

		$userinfo = '<div class="profile">'.$userinfo.'</div>';



		return $userinfo;

}



function USER_ACTION_MENU(){

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

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

		

	$actionmenu = '<div class="actionmenu">

	<span><a href="%URL%home">'.$mnumsg1.'</a></span>

	<span><a href="%URL%mentions">'.$mnumsg5.'</a></span>

	<span><a href="%URL%users/messages">'.$mnumsg6.'</a></span>

	<span><a href="%URL%favorites">'.$mnumsg7.'</a></span>

	<span><a href="%URL%recent">'.$mnumsg8.'</a></span></div>';

	

	return $actionmenu;

}



function wp_fix_server_vars() {

	global $PHP_SELF;



	$default_server_values = array(

		'SERVER_SOFTWARE' => '',

		'REQUEST_URI' => '',

	);



	$_SERVER = array_merge( $default_server_values, $_SERVER );



	// Fix for IIS when running with PHP ISAPI

	if ( empty( $_SERVER['REQUEST_URI'] ) || ( php_sapi_name() != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {



		// IIS Mod-Rewrite

		if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {

			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];

		}

		// IIS Isapi_Rewrite

		else if ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {

			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];

		} else {

			// Use ORIG_PATH_INFO if there is no PATH_INFO

			if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) )

				$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];



			// Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)

			if ( isset( $_SERVER['PATH_INFO'] ) ) {

				if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )

					$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];

				else

					$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];

			}



			// Append the query string if it exists and isn't null

			if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {

				$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];

			}

		}

	}



	// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests

	if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) )

		$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];



	// Fix for Dreamhost and other PHP as CGI hosts

	if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false )

		unset( $_SERVER['PATH_INFO'] );



	// Fix empty PHP_SELF

	$PHP_SELF = $_SERVER['PHP_SELF'];

	if ( empty( $PHP_SELF ) )

		$_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );

}



function PAGE_PROCESSING($wpage,$statmsg = '',$msgstr = ''){

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

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



	if (isset($_SESSION['loggedon']) && ($_SESSION['loggedon'] == true)){

		if(strpos($wpage,"%LOGINBOX%") !== false){

			$wpage = str_replace('%LOGINBOX%','',$wpage);

		}

		if(strpos($wpage,"%REGISTERBOX%") !== false){

			$wpage = str_replace('%REGISTERBOX%','',$wpage);

		}

		if(strpos($wpage,"%NONLOGGEDONLEFT%") !== false){

			$wpage = str_replace('%NONLOGGEDONLEFT%','',$wpage);

		}

		if(strpos($wpage,"%NONLOGGEDONCENTER%") !== false){

			$wpage = str_replace('%NONLOGGEDONCENTER%','',$wpage);

		}

		if(strpos($wpage,"%NONLOGGEDONRIGHT%") !== false){

			$wpage = str_replace('%NONLOGGEDONRIGHT%','',$wpage);

		}

		if(strpos($wpage,"%MAINTXTBOX%") !== false){

			$wpage = str_replace('%MAINTXTBOX%',file_get_contents('themes/'.$theme.'/main_txt_box.theme.html'),$wpage);

		}

		if(strpos($wpage,"%MSGMENU%") !== false){

			$wpage = str_replace('%MSGMENU%',file_get_contents('themes/'.$theme.'/msg_menu.theme.html'),$wpage);

		}

		if(strpos($wpage,"%MSGLIST%") !== false){

			$wpage = str_replace('%MSGLIST%',$msgstr,$wpage);

		}

		if(strpos($wpage,"%USERMENU%") !== false){

			$wpage = str_replace('%USERMENU%',USER_MENU_SPAN(),$wpage);

		}

		if(strpos($wpage,"%USERINFO%") !== false){

			$wpage = str_replace('%USERINFO%',FUNCT_USER_INFO().'<br />'.USER_ACTION_MENU(),$wpage);

		}

		if(strpos($wpage,"%SEARCHBOX%") !== false){

			$wpage = str_replace('%SEARCHBOX%',SEARCH_FORM(),$wpage);

		}

	}else{

		if(strpos($wpage,"%SEARCHBOX%") !== false){

			$wpage = str_replace('%SEARCHBOX%','',$wpage);

		}

		if(strpos($wpage,"%LOGINBOX%") !== false){

			$wpage = str_replace('%LOGINBOX%',file_get_contents('themes/'.$theme.'/login_box.theme.html'),$wpage);

		}

		if(strpos($wpage,"%REGISTERBOX%") !== false){

			$wpage = str_replace('%REGISTERBOX%',file_get_contents('themes/'.$theme.'/registration.theme.html'),$wpage);

			if($enable_recaptcha == 1){

				$error = '';

				require_once('includes/recaptchalib.php');

				$wpage = str_replace('%RECAPTCHA%',recaptcha_get_html($recaptcha_public_key, $error),$wpage);

			}else{

				$wpage = str_replace('%RECAPTCHA%','',$wpage);

			}

		}

		if(strpos($wpage,"%NONLOGGEDONLEFT%") !== false){

			$wpage = str_replace('%NONLOGGEDONLEFT%',file_get_contents('themes/'.$theme.'/non_loggedon_left.theme.html'),$wpage);

		}

		if(strpos($wpage,"%NONLOGGEDONCENTER%") !== false){

			$wpage = str_replace('%NONLOGGEDONCENTER%',file_get_contents('themes/'.$theme.'/non_loggedon_center.theme.html'),$wpage);

		}

		if(strpos($wpage,"%NONLOGGEDONRIGHT%") !== false){

			$wpage = str_replace('%NONLOGGEDONRIGHT%',file_get_contents('themes/'.$theme.'/non_loggedon_right.theme.html'),$wpage);

		}

		if(strpos($wpage,"%MAINTXTBOX%") !== false){

			$wpage = str_replace('%MAINTXTBOX%','',$wpage);

		}

		if(strpos($wpage,"%MSGMENU%") !== false){

			$wpage = str_replace('%MSGMENU%','',$wpage);

		}

		if(strpos($wpage,"%MSGLIST%") !== false){

			$wpage = str_replace('%MSGLIST%','',$wpage);

		}

		if(strpos($wpage,"%USERMENU%") !== false){

			$wpage = str_replace('%USERMENU%','',$wpage);

		}

		if(strpos($wpage,"%USERINFO%") !== false){

			$wpage = str_replace('%USERINFO%','',$wpage);

		}

	}

	if(strpos($wpage,"%SITENAME%") !== false){

		$wpage = str_replace('%SITENAME%',stripslashes($sitename),$wpage);

	}

	

	if(strpos($wpage,"%URL%") !== false){

		$wpage = str_replace('%URL%',$url,$wpage);

	}

	if(strpos($wpage,"%STATUSMSG%") !== false){

		$wpage = str_replace('%STATUSMSG%',$statmsg,$wpage);

	}else{

		$wpage = str_replace('%STATUSMSG%','',$wpage);

	}	

	return $wpage;

}

?>
Return current item: Chirp: The Microblog