Location: PHPKode > projects > EgO News, Blog and General CMS > ego-news-blog-and-general-cms/includes/functions.php
<?php
////////////////////////////////////////////////////////////////////
// EgO v_0.6b by VairuX                                           //
// WARNING: This is unsupported beta version, download and        //
// install it at your own risk.                                   //
//                                                                //
// This software is property of VairuX (http://www.vairux.da.ru)  //
//   You may copy, distribute and sell this program as            //
//   indicated in Artistic License (See LICENSE.TXT).             //
//                                                                //
// This program may contain pieces of code from other systems     //
// that aren't property and/or responsability of VairuX.          //
//                                                                //
//  (C) Copyright 2004 VairuX Systems                             //
//        http://www.vairux.da.ru/ -                              //
////////////////////////////////////////////////////////////////////

if (eregi("functions.php",$_SERVER[PHP_SELF])) {
    Header("Location: ../index.php");
    die();
}

function exectime() {
	global $system_exectime;
    list($system_usec, $system_sec) = explode(" ",microtime()); 
    $system_exectime = ((float)$system_usec + (float)$system_sec) - $system_exectime; 
	return $system_exectime;
}

function sign() {
	echo "\n<!-- Exectime: ".exectime()." seconds -->";
	echo "\n<!-- System powered by EgO v_0.6b http://www.vairux.da.ru/ -->";
}

function docookie($login, $password) {
//	global $system_admincookie;
	setcookie("admincookie[login]",$login,time()+3133731337);
	setcookie("admincookie[pass]",md5($password),time()+3133731337);
}

function is_admin() {
global $system_set;

// Crypt password before do anything...
// $passcrypt = md5($system_set[pass]);
// this is a temporary workaround... later, the password will be stored in the database and allready encrypted.

	if ($_COOKIE[admincookie][pass] == $system_set[pass] AND $_COOKIE[admincookie][login] == $system_set[login]) {
		return true;
	} else {
		return false;
	}
}

function formattime($system_string) {
	if ($system_string == "00000000000000") { return ""; exit; }
	$system_hour = $system_string[8].$system_string[9];
	$system_min = $system_string[10].$system_string[11];
	if ($system_hour > 12) { 
		$system_hour = $system_hour-12; $system_htype = "pm";
	} elseif($system_hour == 0) {
		$system_hour = 12; $system_htype = "am";
	} elseif ($system_hour == 12) {
		$system_htype = "pm"; 
	} else {
		$system_htype = "am";
	}
return "$system_hour:$system_min $system_htype";
}

function str2timestamp($system_string){
	if ($system_string == "00000000000000") { return ""; exit; }
	$system_hour = $system_string[8].$system_string[9];
	$system_min = $system_string[10].$system_string[11];
	$system_secs = $system_string[12].$system_string[13];
	$system_year = $system_string[0].$system_string[1].$system_string[2].$system_string[3];
	$system_day = $system_string[6].$system_string[7];
	$system_month = $system_string[4].$system_string[5];
	return mktime($system_hour,$system_min,$system_secs,$system_month, $system_day, $system_year);
}

function formatdma($system_string) {
if ($system_string == "00000000000000") { return ""; exit; }
$system_year = substr($system_string, 0, 4);
$system_day = substr($system_string, 6, 2);
$system_month = substr($system_string, 4, 2);
$system_trans = array("0" => "Domingo", 
				"1" => "Lunes",
				"2" => "Martes",
				"3" => "Miercoles",
				"4" => "Jueves",
				"5" => "Viernes",
				"6" => "Sábado");
$system_dayname = strtr(date ("w", mktime(0,0,0,$system_month, $system_day, $system_year)), $system_trans);
$system_trans = array("01" => "Enero", 
				"02" => "Febrero",
				"03" => "Marzo",
				"04" => "Abril",
				"05" => "Mayo",
				"06" => "Junio",
				"07" => "Julio",
				"08" => "Agosto",
				"09" => "Septiembre",
				"10" => "Octubre",
				"11" => "Noviembre",
				"12" => "Diciembre");
$system_monthname = strtr($system_month, $system_trans);

return "$system_dayname $system_day de $system_monthname de $system_year";
}

function td2str($system_tdstamp) {
	if ($system_tdstamp == "00000000000000") { return ""; exit; }
// Esta funcion convierte un Timestamp SQL a un string en formato Dia/Mes/Año Hora:Min AM/PM
	$system_year = $system_tdstamp[0].$system_tdstamp[1].$system_tdstamp[2].$system_tdstamp[3];
	$system_month = $system_tdstamp[4].$system_tdstamp[5];
	$system_day = $system_tdstamp[6].$system_tdstamp[7];
	$system_hour = $system_tdstamp[8].$system_tdstamp[9];
	$system_min = $system_tdstamp[10].$system_tdstamp[11];
	$system_secs = $system_tdstamp[12].$system_tdstamp[13];
	
	if ($system_hour > 12) { 
		$system_hour = $system_hour-12; $system_htype = "pm";
	} elseif($system_hour == 0) {
		$system_hour = 12; $system_htype = "am";
	} elseif ($system_hour == 12) {
		$system_htype = "pm"; 
	} else {
		$system_htype = "am";
	}
	
	return $system_day."/".$system_month."/".$system_year." ".$system_hour.":".$system_min." ".$system_htype;
}

function tdnow() {
// Regresa la fecha/hora actual en timestamp SQL
	$system_today = getdate();
	return $system_today["year"]."/".$system_today["mon"]."/".$system_today["mday"]."/".$system_today["hours"]."/".$system_today["minutes"]."/".$system_today["seconds"];
}

function str2td ($system_str) {
// Esta funcion convierte un string en formato Dia/Mes/Año Hora:Minutos am/pm a un Timestamp sql.
	list ($system_day, $system_month, $system_year, $system_hour, $system_min, $system_htype) = split ('[ :/-]', $system_str);
		if (eregi("pm", $system_htype) and $system_hour < 12) { $system_hour = $system_hour+12; } elseif(eregi("am",$system_htype) and $system_hour == 12) { $system_hour = 0; }
	$system_secs = 0;
	return $system_year."/".$system_month."/".$system_day."/".$system_hour."/".$system_min."/".$system_secs;
}

function str2epoch($system_string){
// this function returns an unix timestamp from a SQL timestamp.
	if ($system_string == "00000000000000") { return ""; exit; }
	$system_hour = $system_string[8].$system_string[9];
	$system_min = $system_string[10].$system_string[11];
	$system_secs = $system_string[12].$system_string[13];
	$system_year = $system_string[0].$system_string[1].$system_string[2].$system_string[3];
	$system_day = $system_string[6].$system_string[7];
	$system_month = $system_string[4].$system_string[5];
	return mktime($system_hour,$system_min,$system_secs,$system_month, $system_day, $system_year);
}

function str2rfc($system_string){
// this function returns an RFC 822 date format.
	if ($system_string == "00000000000000") {
		return gmdate("D, d M Y H:i:s", time())." GMT";
	} else {
		return gmdate("D, d M Y H:i:s", str2epoch($system_string))." GMT";
	}
}

function cleanhtml($system_input) {
// This function cleans all <html> tags and returns a plaintext data.
	return eregi_replace("\n|\r|<[^>]*>", " " ,$system_input);
}

function showhtml($system_input) {
// Changes html's special characters, to be displayed on html / xml.
	$system_input = eregi_replace("\&", "&amp;", $system_input);
	$system_input = eregi_replace("<", "&lt;", $system_input);
	$system_input = eregi_replace(">", "&gt;", $system_input);
	$system_input = eregi_replace("\"", "&quot;", $system_input);
	return $system_input;
}

?>
Return current item: EgO News, Blog and General CMS