2001-03-10 11:07:52 +00:00
< ? php
2000-12-23 23:25:28 +00:00
2001-04-29 12:39:55 +00:00
$na = " <I>na</I> " ;
2001-02-18 15:14:56 +00:00
function conf_init () {
2001-02-04 22:09:38 +00:00
global $HTTP_HOST , $REQUEST_URI ;
2001-03-10 18:38:47 +00:00
$file = strtolower ( strtr ( $HTTP_HOST . " " . substr ( $REQUEST_URI , 0 , strrpos ( $REQUEST_URI , " / " )), " /: " , " .. " ));
2001-05-15 18:38:57 +00:00
while ( $file && ! file_exists ( " includes/ $file .php " )) $file = substr ( $file , 0 , strrpos ( $file , " . " ));
2001-05-20 13:51:40 +00:00
return $file ? $file : " conf " ;
2001-02-04 22:09:38 +00:00
}
2001-05-06 17:19:58 +00:00
function error_handler ( $errno , $message , $filename , $line , $variables ) {
$types = array ( 1 => " error " , 2 => " warning " , 4 => " parse error " , 8 => " notice " , 16 => " core error " , 32 => " core warning " , 64 => " compile error " , 128 => " compile warning " , 256 => " user error " , 512 => " user warning " , 1024 => " user notice " );
$entry = $types [ $errno ] . " : $message in $filename on line $line . " ;
if ( $errno == 1 || $errno == 2 || $errno == 4 ) {
watchdog ( " error " , $types [ $errno ] . " : $message in $filename on line $line . " );
print $entry ;
}
}
2001-04-06 14:14:16 +00:00
function watchdog ( $type , $message ) {
global $user , $watchdog , $PHP_SELF ;
$link = ( $mod ) ? $mod : substr ( strrchr ( $PHP_SELF , " / " ), 1 , strrchr ( $PHP_SELF , " / " ) - 4 );
db_query ( " INSERT INTO watchdog (user, type, link, message, location, hostname, timestamp) VALUES (' $user->id ', ' " . check_input ( $type ) . " ', ' " . check_input ( $link ) . " ', ' " . check_input ( $message ) . " ', ' " . check_input ( getenv ( " REQUEST_URI " )) . " ', ' " . check_input ( getenv ( " REMOTE_ADDR " )) . " ', ' " . time () . " ') " );
}
function throttle ( $type , $rate ) {
2001-04-07 15:02:28 +00:00
global $user ;
2001-04-06 14:14:16 +00:00
if ( ! ( user_access ( $user , " watchdog " ) || user_access ( $user , " comment " ) || user_access ( $user , " node " ))) {
if ( $throttle = db_fetch_object ( db_query ( " SELECT * FROM watchdog WHERE type = ' $type ' AND hostname = ' " . getenv ( " REMOTE_ADDR " ) . " ' AND " . time () . " - timestamp < $rate " ))) {
watchdog ( " warning " , " throttle: ' " . getenv ( " REMOTE_ADDR " ) . " ' exceeded submission rate - $throttle->type " );
header ( " Location: error.php?op=throttle " );
2001-05-05 13:57:29 +00:00
die ( " submission rate exceeded " );
2001-04-06 14:14:16 +00:00
}
else {
watchdog ( $type , " throttle control " );
}
}
}
2001-05-15 18:38:57 +00:00
function path_uri () {
global $HTTP_HOST , $REQUEST_URI ;
return " http:// " . $HTTP_HOST . substr ( $REQUEST_URI , 0 , strrpos ( $REQUEST_URI , " / " )) . " / " ;
}
function path_img () {
// use "http://your-image-server.com/ if you want to host images on a seperate server.
return " ./images/ " ;
}
function notice_account () {
return t ( " This page requires a valid user account. Please <A HREF= \" account.php \" >create a user account</A> and <A HREF= \" account.php \" >login</A> prior to accessing it. " );
}
2001-04-29 12:39:55 +00:00
2001-05-20 13:51:40 +00:00
function check_form ( $text ) {
return htmlspecialchars ( stripslashes ( $text ));
2001-04-29 12:39:55 +00:00
}
2001-05-20 13:51:40 +00:00
function check_export ( $text ) {
return htmlspecialchars ( stripslashes ( $text ));
2001-04-29 12:39:55 +00:00
}
2001-05-20 13:51:40 +00:00
function check_code ( $text ) {
return $text ;
2001-04-29 12:39:55 +00:00
}
function check_mail ( $mail ) {
return eregi ( " ^[_ \ .0-9a-z-]+@([0-9a-z][0-9a-z-]+ \ .)+[a-z] { 2,3} $ " , $mail ) ? 1 : 0 ;
}
function check_name ( $name ) {
return ereg ( " [^a-zA-Z0-9_-] " , $name ) ? 0 : 1 ;
}
2001-05-20 13:51:40 +00:00
function check_preview ( $text ) {
2001-05-24 08:53:07 +00:00
return check_output ( check_input ( $text ));
2001-05-20 13:51:40 +00:00
}
2001-05-20 19:30:39 +00:00
function check_query ( $text ) {
return addslashes ( stripslashes ( $text ));
}
2001-05-20 13:51:40 +00:00
function check_input ( $text ) {
foreach ( module_list () as $module ) $text = module_invoke ( $module , " filter " , $text );
return addslashes ( stripslashes ( substr ( $text , 0 , variable_get ( " max_input_size " , 10000 ))));
}
function check_output ( $text , $nl2br = 0 ) {
global $na ;
2001-05-24 08:53:07 +00:00
return ( $text ) ? ( $nl2br ? nl2br ( stripslashes ( $text )) : stripslashes ( $text )) : $na ;
2001-04-29 12:39:55 +00:00
}
function format_plural ( $count , $singular , $plural ) {
return ( $count == 1 ) ? " $count " . t ( $singular ) : " $count " . t ( $plural );
}
function format_interval ( $timestamp ) {
2001-05-17 19:14:50 +00:00
$units = array ( " year|years " => 31536000 , " week|weeks " => 604800 , " day|days " => 86400 , " hour|hours " => 3600 , " min|min " => 60 , " sec|sec " => 1 );
2001-05-17 18:25:08 +00:00
foreach ( $units as $key => $value ) {
2001-05-17 19:14:50 +00:00
$key = explode ( " | " , $key );
2001-05-17 18:25:08 +00:00
if ( $timestamp >= $value ) {
$output .= ( $output ? " " : " " ) . format_plural ( floor ( $timestamp / $value ), $key [ 0 ], $key [ 1 ]);
$timestamp %= $value ;
}
2001-04-29 12:39:55 +00:00
}
return ( $output ) ? $output : " 0 sec " ;
}
function format_date ( $timestamp , $type = " medium " , $format = " " ) {
global $user ;
$timestamp += ( $user -> timezone ) ? $user -> timezone - date ( " Z " ) : 0 ;
switch ( $type ) {
case " small " :
$date = date ( " m/d/y - H:i " , $timestamp );
break ;
case " medium " :
$date = t ( date ( " l " , $timestamp )) . " , " . date ( " m/d/Y - H:i " , $timestamp );
break ;
case " large " :
$date = t ( date ( " l " , $timestamp )) . " , " . t ( date ( " F " , $timestamp )) . " " . date ( " d, Y - H:i " , $timestamp );
break ;
case " custom " :
2001-05-17 19:14:50 +00:00
for ( $i = strlen ( $format ); $i >= 0 ; $c = $format [ -- $i ]) {
if ( strstr ( " DFlMSw " , $c )) {
$date = t ( date ( $c , $timestamp )) . $date ;
}
else if ( strstr ( " AaBdgGhHiIjLmnrstTUYyZz " , $c )) {
$date = date ( $c , $timestamp ) . $date ;
}
else {
$date = $c . $date ;
}
2001-05-17 17:56:52 +00:00
}
2001-04-29 12:39:55 +00:00
break ;
default :
$date = t ( date ( " l " , $timestamp )) . " , " . date ( " m/d/Y - H:i " , $timestamp );
}
return $date ;
}
function format_username ( $username ) {
global $user ;
if ( $username ) return ( user_access ( $user , " account " ) ? " <A HREF= \" admin.php?mod=account&op=view&name= $username\ " > $username </ A > " : " < A HREF = \ " account.php?op=view&name= $username\ " > $username </ A > " );
else return variable_get ( anonymous , " Anonymous " );
}
function format_email ( $address ) {
global $na ;
return ( $address ) ? " <A HREF= \" mailto: $address\ " > $address </ A > " : $na ;
}
function format_url ( $address , $description = " " ) {
global $na ;
$description = ( $description ) ? $description : $address ;
return ( $address ) ? " <A HREF= \" $address\ " > " . check_output( $description ) . " </ A > " : $na ;
}
function format_tag ( $link , $text ) {
return " '<a href= \" node.php?title='. urlencode(' $link ') .' \" >'. (' $text ' ? ' $text ' : ' $link ') .'</a>' " ;
}
2001-05-17 19:14:50 +00:00
function form ( $action , $form , $method = " post " , $options = 0 ) {
return " <FORM ACTION= \" $action\ " METHOD = \ " $method\ " " . ( $options ? " $options " : " " ) . " > \n $form </ FORM > \n " ;
2001-04-30 17:13:08 +00:00
}
2001-04-29 12:39:55 +00:00
function form_item ( $title , $value , $description = 0 ) {
2001-04-30 17:13:08 +00:00
return ( $description ) ? " <B> $title :</B><BR> $value <BR><SMALL><I> $description </I></SMALL><P> \n " : " <B> $title :</B><BR> $value <P> \n " ;
2001-04-29 12:39:55 +00:00
}
function form_textfield ( $title , $name , $value , $size , $maxlength , $description = 0 ) {
2001-05-20 13:51:40 +00:00
return form_item ( $title , " <INPUT MAXLENGTH= \" $maxlength\ " NAME = \ " edit[ $name ] \" SIZE= \" $size\ " VALUE = \ " " . check_form ( $value ) . " \" > " , $description );
2001-04-29 12:39:55 +00:00
}
function form_textarea ( $title , $name , $value , $cols , $rows , $description = 0 ) {
2001-05-20 13:51:40 +00:00
return form_item ( $title , " <TEXTAREA WRAP= \" virtual \" COLS= \" $cols\ " ROWS = \ " $rows\ " NAME = \ " edit[ $name ] \" > " . check_form ( $value ) . " </TEXTAREA> " , $description );
2001-04-29 12:39:55 +00:00
}
2001-04-30 17:13:08 +00:00
function form_select ( $title , $name , $value , $options , $description = 0 ) {
2001-05-20 13:51:40 +00:00
foreach ( $options as $key => $choice ) $select .= " <OPTION VALUE= \" $key\ " " . ( $key == $value ? " SELECTED " : " " ) . " > " . check_form( $choice ) . " </ OPTION > " ;
2001-04-29 12:39:55 +00:00
return form_item ( $title , " <SELECT NAME= \" edit[ $name ] \" > $select </SELECT> " , $description );
}
2001-05-18 09:17:00 +00:00
function form_file ( $title , $name , $size , $description = 0 ) {
return form_item ( $title , " <INPUT TYPE= \" file \" NAME= \" edit[ $name ] \" SIZE= \" $size\ " >< P > \n " , $description );
2001-04-29 12:39:55 +00:00
}
2001-05-18 09:17:00 +00:00
function form_hidden ( $name , $value ) {
2001-05-20 13:51:40 +00:00
return " <INPUT TYPE= \" hidden \" NAME= \" edit[ $name ] \" VALUE= \" " . check_form ( $value ) . " \" > \n " ;
2001-05-17 11:49:19 +00:00
}
2001-04-29 12:39:55 +00:00
function form_submit ( $value ) {
2001-05-20 13:51:40 +00:00
return " <INPUT TYPE= \" submit \" NAME= \" op \" VALUE= \" " . check_form ( $value ) . " \" > \n " ;
2001-04-29 12:39:55 +00:00
}
2001-05-17 20:50:15 +00:00
function field_get ( $string , $name ) {
foreach ( explode ( " ; " , $string ) as $data ) {
$entry = explode ( " : " , $data );
if ( $entry [ 0 ] == $name ) return $entry [ 1 ];
2001-05-16 20:54:37 +00:00
}
}
2001-05-17 20:50:15 +00:00
function field_set ( $string , $name , $value ) {
2001-05-16 20:54:37 +00:00
if ( ! $value ) {
// remove entry:
2001-05-17 20:50:15 +00:00
foreach ( explode ( " ; " , $string ) as $data ) {
$entry = explode ( " : " , $data );
2001-05-16 20:54:37 +00:00
if ( $entry [ 0 ] != $name ) $rval .= " $entry[0] : $entry[1] ; " ;
}
}
2001-05-17 20:50:15 +00:00
else if ( strstr ( $string , " $name : " )) {
2001-05-16 20:54:37 +00:00
// found: update exsisting entry:
2001-05-17 20:50:15 +00:00
foreach ( explode ( " ; " , $string ) as $data ) {
$entry = explode ( " : " , $data );
2001-05-16 20:54:37 +00:00
if ( $entry [ 0 ] == $name ) $entry [ 1 ] = $value ;
$rval .= " $entry[0] : $entry[1] ; " ;
}
}
else {
// not found:
2001-05-17 20:50:15 +00:00
$rval = " $string $name : $value ; " ;
2001-05-16 20:54:37 +00:00
}
return $rval ;
}
2001-05-20 13:51:40 +00:00
function timer_start () {
global $timer ;
$timer = explode ( " " , microtime ());
}
function timer_print () {
global $timer ;
$stop = explode ( " " , microtime ());
$diff = $stop [ 0 ] - $timer [ 0 ];
print " <PRE>execution time: $diff ms</PRE> " ;
}
function page_header () {
if ( variable_get ( " dev_timer " , 0 )) timer_start ();
}
function page_footer () {
if ( variable_get ( " dev_timer " , 0 )) timer_print ();
}
2001-02-18 15:14:56 +00:00
$conf = conf_init ();
2001-02-04 22:09:38 +00:00
2001-05-14 19:41:18 +00:00
include_once " includes/ $conf .php " ;
2001-04-16 13:26:38 +00:00
include_once " includes/structure.inc " ;
2000-12-23 23:25:28 +00:00
include_once " includes/database.inc " ;
2001-04-05 20:33:36 +00:00
include_once " includes/variable.inc " ;
2001-03-18 08:44:01 +00:00
include_once " includes/comment.inc " ;
2001-02-10 11:59:06 +00:00
include_once " includes/module.inc " ;
2001-02-17 12:59:24 +00:00
include_once " includes/locale.inc " ;
include_once " includes/search.inc " ;
2000-12-23 23:25:28 +00:00
include_once " includes/theme.inc " ;
include_once " includes/user.inc " ;
2001-03-24 17:04:11 +00:00
include_once " includes/node.inc " ;
2000-12-23 23:25:28 +00:00
2001-05-06 17:19:58 +00:00
// initialize user session:
2001-02-18 15:14:56 +00:00
user_init ();
2001-05-06 17:19:58 +00:00
// initialize installed modules:
2001-05-05 13:57:29 +00:00
module_init ();
2001-05-06 17:19:58 +00:00
// initialize localization system:
2001-02-18 15:14:56 +00:00
$locale = locale_init ();
2001-05-06 17:19:58 +00:00
// initialize configuration variables:
2001-04-05 20:33:36 +00:00
$conf = variable_init ();
2001-05-06 17:19:58 +00:00
// initialize theme:
2001-02-18 15:14:56 +00:00
$theme = theme_init ();
2000-12-23 23:25:28 +00:00
2001-05-06 17:19:58 +00:00
// set error handler:
set_error_handler ( " error_handler " );
2001-05-17 19:14:50 +00:00
?>