Location: PHPKode > projects > Particle Blogger > particle-blogger/includes/functions.php
<?php
include("functions_admin.php");
include("functions_blog.php");
include("functions_get.php");
include("functions_fetch.php");

function dbSecure($code){
	if (!get_magic_quotes_gpc()) {
	   $code = addslashes($code);
	}
	return $code;
}

function un($code){
	if (get_magic_quotes_gpc()) {
	   $code = stripslashes($code);
	}
	return $code;
}

// encode the messages
function Encode($code){
	//$code = str_replace("\n", "<br />", $code);
	return $code;
}

function StartSession(){
	ini_set('url_rewriter.tags', '');
	session_start();
}

function redirect($url){
	Header("Location: " . $url);
	echo($url);
	die();
}

// 404 error function pretty much
function notfound(){
	header("HTTP/1.0 404 Not Found");
	echo("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">");
	echo("<HTML><HEAD>");
	echo("<TITLE>404 Not Found</TITLE>");
	echo("</HEAD><BODY>");
	echo("<H1>Not Found</H1>");
	echo("The requested URL was not found on this server.<P>");
	echo("</BODY></HTML>");
	die();
}

// cut down a post to give a description
function ChopText($text, $chars = 50){
	$text = Encode($text);
	$text = strip_tags($text);
	$text = str_replace("\n", " ", $text);
	$text = str_replace("\r", " ", $text);
	$text = $text . " ";
	$text = substr($text,0,$chars);
	$text = substr($text,0,strrpos($text," "));
	$text = $text."...";
	return $text;
}

// custom JavaScript alerts
function DoAlert($msg = "Uknown error"){
	echo("<script language=\"JavaScript\">alert('" . $msg . "');</script>");
}

// generate a random password
function GeneratePassword() {
	
    $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	srand((double)microtime()*1000000);  
    $i = 0;
    while ($i < 8) {  // change for other length
        $num = rand() % 33;
        $tmp = substr($salt, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }
    
    return $pass;
}

// for sanitizing a title
function purify($x){
	$x = strip_tags($x);
	$x = strtolower($x);
	
	$x = str_replace(" ", "-", $x);
	$x = str_replace("_", "-", $x);
	$x = str_replace("&", "and", $x);
	$x = str_replace("---", "-", $x);
	
	$x = str_replace("ú", "u", $x);
	$x = str_replace("é", "e", $x);
	$x = str_replace("ï", "l", $x);
	$x = str_replace("º", "o", $x);
	$x = str_replace("Ö", "o", $x);
	$x = str_replace("á", "a", $x);
	
	$x = eregi_replace("([^a-z0-9-])", "", $x);
	
	return $x;
}

function summarise($text){
	$text = explode("</p>", $text);
	$text = explode("<br /><br />", $text[0]);
	$text = explode("<br/><br/>", $text[0]);
	$text = explode("<br><br>", $text[0]);
	$text = strip_tags($text[0]);
	
	return $text;
}

function SkinList($defaultvalue){
	
	// globalise variables
	global $config;
	
	// Open a known directory, and proceed to read its contents
	$codelist = "<select id=c_defaultskin name=c_defaultskin>\n";
	$tdir = $config["root"] . "skins/";
	$tdir = "skins/";
	if (is_dir($tdir)) {
		if ($dh = opendir($tdir)) {
			while (($file = readdir($dh)) !== false) {
				if ($file <> "." && $file <> ".." && filetype($tdir . $file) == "dir"){
					//echo "filename: $file : filetype: " . filetype($tdir . $file) . "<br />";
					$extracode = ($file == $config["defaultskin"]) ? " selected" : "";
					$codelist .= "		<option value=\"" . $file . "\"" . $extracode . ">" . $file . "</option>\n";
				}
			}
			closedir($dh);
		}
	}
	
	// finish the list
	$codelist .= "	</selected>";
	
	// return the list
	return $codelist;
}
?>
Return current item: Particle Blogger