Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: /home/inri/public_html/daCode-HEAD/daCode/src/phplib/utils.php3
daCode -

Utils

Utils

Will contain all usefull functions that don't fit somewhere else

 

private class Utils

Will contain all usefull functions that don't fit somewhere else

daCode http://www.dacode.org/
src/phplib/utils.php3
$Id: utils.php3,v 1.142 2002/05/13 21:34:03 jbcombes Exp $

 

Public Method Summary

void

Utils()

Constructor. Loads class DB and launches ip_start().
string

ip([ integer $i ])

Return IP of the $HTTP_SERVER_VARS['REMOTE_ADDR'] or
string

convertip(int $ip)

Convert hexadecimal IP into decimal IP
array

stamp2array(string $t)

Converts a SQL timestamp into an array (YYYY, MM, DD)
string

stamp2datetime(string $t)

Converts a SQL timestamp into YYYY-MM-DD hh:mm:ss
string

stamp2date(string $t, string $mode, [ integer $type ])

Function which takes a timestamp as input and returns the date
string

stamp2time(string $t, string $mode)

Function which takes a timestamp(14) as input and returns the time
string

interval(string $t1, string $t2)

This returns the time elapsed between two SGBD timestamps.
string

makerand([ integer $nb ])

Returns random caracters
string

spec_chars(string $text)

Change accent to visible thing for WAP
bool

createdir([ string $dir, integer (octal) $mode ])

Create directories recursively
string

getcwd()

Define the getcwd function, for compatibility with PHP 3
string

realpath(string $path)

Define the realpath function, for compatibility with PHP 3
void

write_file(string $file, [ string $text ])

Write text to a file using a temporary file to avoid
array

gettimestampnews(integer $news_id)

Returns the timestamp of the news
bool

loadishigh()

Checks if server load is not too high
string

loadis()

Returns the actual load of the server
bool

cmp_array(array $table1, array $table2)

Compare two arrays and return true if they are equal.
string

make_topics_button()

Returns the html <select> with the list of a topics
string

make_sections_button()

Returns the html <select> with the list of a sections
string

htmlspecial_board(string $text)

Escape unauthorized tags for the board
string

htmlspecial(string $text, [ string $url_conv ])

Escape unauthaurized tags
string

url_conv(string $text)

Function to replace URL by link and reduce the length of the link.
mixed

crypt_dacode(string $passwd, [ string $encrypted_password ])

Function to encrypt password
bool

send_email([ string $to, string $subject, string $message, string $from ])

Function to send a mail.
bool

html_safe(mixed $var)

Make sure there is no '<' sign in text
string

quote_text(string $text, [ integer $quote, integer $buff_size, string $end_quote, string $begin_quote ])

Wraps the text:
string

warn_referer()

Warns the user about the HTTP_REFERER http header.
void

debug(string $debugMsg)

Function to direct debugging output.
string

debug_dump(mixed $var, [ integer $level ])

Traps a var_dump call and directs it to the selected debug output.
string

no_access_msg()

Generates the No Access message

Private Method Summary

void

ip_start()

We set up the right REMOTE_ADDR and right HTTP_HOST
integer

timestamp14_to_unix_stamp(string $t)

Function which takes a timestamp(14) as input and returns a Unix timestamp
string

unix_stamp_to_timestamp14(integer $t)

Function which takes a Unix timestamp as input and returns a timestamp(14)
string

make_ipsession()

Create new ipsession and returns it
bool

check_ipsession([ string $idsession ])

Check ipsession

Private Field Summary

object db

$db

Public Method Details

Utils

public void Utils( )

  Constructor. Loads class DB and launches ip_start().

Returns void


ip

public string ip( [ integer $i ] )

  Return IP of the $HTTP_SERVER_VARS['REMOTE_ADDR'] or
$HTTP_SERVER_VARS['HTTP_X_FORWARDED']_FOR if it exists

Parameter
integer $i = >>0<<
if 0, converts the decimal IP into hexadecimal one
Returns string

the IP in decimal.


convertip

public string convertip( int $ip )

  Convert hexadecimal IP into decimal IP

Parameter
int $ip
IP in hexadecimal
Returns string

IP in decimal type (XXX.XXX.XXX.XXX)


stamp2array

public array stamp2array( string $t )

  Converts a SQL timestamp into an array (YYYY, MM, DD)
Input: timestamp(14)
Output: array( YYYY, MM, DD)

Parameter
string $t
the SQL timestamp(14)
Returns array

(Year, Month, Day)


stamp2datetime

public string stamp2datetime( string $t )

  Converts a SQL timestamp into YYYY-MM-DD hh:mm:ss
Input: timestamp(14)
Output: YYYY-MM-DD hh:mm:ss

Parameter
string $t
the SQL timestamp(14)
Returns string

the formatted date YYYY-MM-DD hh:mm:ss


stamp2date

public string stamp2date( string $t, string $mode, [ integer $type ] )

  Function which takes a timestamp as input and returns the date
Thanks to mose mose@mose.com
type=0 $t timestamp 14
type=1 $t UNIX timestamp
type=2 $t unused

Parameter
string $t
the timestamp
string $mode
the output format.
integer $type = >>0<<
the type of the timestamp
Returns string

the formated date.


stamp2time

public string stamp2time( string $t, string $mode )

  Function which takes a timestamp(14) as input and returns the time
Thanks to mose mose@mose.com

Parameter
string $t
the timestamp
string $mode
the format of the output
Returns string

the formated time


interval

public string interval( string $t1, string $t2 )

  This returns the time elapsed between two SGBD timestamps.
"1, 10:20" means one day, ten hours, twenty minutes.

Parameter
string $t1
the first SQL timestamp
string $t2
the second SQL timestamp
Returns string

the time difference.


makerand

public string makerand( [ integer $nb ] )

  Returns random caracters

Parameter
integer $nb = >>8<<
the number of caracters to return
Returns string

a random string of $nb characters


spec_chars

public string spec_chars( string $text )

  Change accent to visible thing for WAP
FIXME: unused

Parameter
string $text
the text to escape
Returns string

the escaped text.


createdir

public bool createdir( [ string $dir, integer (octal) $mode ] )

  Create directories recursively

Parameter
string $dir = >>""<<
the directory hierarchy to create
integer (octal) $mode = >>493 (0755)<<
the mode of the created dirs
Returns bool

1 if success, 0 otherwise


getcwd

public string getcwd( )

  Define the getcwd function, for compatibility with PHP 3

Returns string

the current working directory


realpath

public string realpath( string $path )

  Define the realpath function, for compatibility with PHP 3

Parameter
string $path
path to convert
Returns string

"Canonicalized absolute pathname"


write_file

public void write_file( string $file, [ string $text ] )

  Write text to a file using a temporary file to avoid
concurrent writings.

Parameter
string $file
the filename
string $text = >>""<<
the text to write
Returns void


gettimestampnews

public array gettimestampnews( integer $news_id )

  Returns the timestamp of the news
FIXME: MIGHT BE MOVED INTO THE NEWS CLASS

Parameter
integer $news_id
of the news
Returns array

year , month, day, id


loadishigh

public bool loadishigh( )

  Checks if server load is not too high
Returns 1 if actual load is higher than a level which is configured in
config.php3
else returns 0

Returns bool

1 if too high, 0 otherwise


loadis

public string loadis( )

  Returns the actual load of the server

Returns string

the server load


cmp_array

public bool cmp_array( array $table1, array $table2 )

  Compare two arrays and return true if they are equal.
PHP3 does not handle compar. of objects.

Parameter
array $table1
array $table2
Returns bool

1 if identical, 0 otherwise


make_topics_button

public string make_topics_button( )

  Returns the html <select> with the list of a topics

Returns string

the HTML list of topics


make_sections_button

public string make_sections_button( )

  Returns the html <select> with the list of a sections

Returns string

the HTML list


htmlspecial_board

public string htmlspecial_board( string $text )

  Escape unauthorized tags for the board

Parameter
string $text
the text to escape
Returns string

the escaped text


htmlspecial

public string htmlspecial( string $text, [ string $url_conv ] )

  Escape unauthaurized tags

Parameter
string $text
the text to escape
string $url_conv = >>"0"<<
1 to convert URLS into link
Returns string

the escaped text


url_conv

public string url_conv( string $text )

  Function to replace URL by link and reduce the length of the link.
will fail on URL containing )

Parameter
string $text
Returns string


crypt_dacode

public mixed crypt_dacode( string $passwd, [ string $encrypted_password ] )

  Function to encrypt password
so we can change the encrypt method if we need to.
Returns encrypted password if one argument,
Returns 1 if 2 arguments and they match,
Returns 0 if 2 arguments and they don't match.

Parameter
string $passwd
string $encrypted_password = >>""<<
Returns mixed


send_email

public bool send_email( [ string $to, string $subject, string $message, string $from ] )

  Function to send a mail.

Parameter
string $to = >>""<<
string $subject = >>""<<
string $message = >>""<<
string $from = >>""<<
Returns bool

1 if the mail has been sent, 0 otherwise


html_safe

public bool html_safe( mixed $var )

  Make sure there is no '<' sign in text

Parameter
mixed $var
(string) the text to check. May be an array of strings to check
Returns bool

1 if no <, 0 otherwise


quote_text

public string quote_text( string $text, [ integer $quote, integer $buff_size, string $end_quote, string $begin_quote ] )

  Wraps the text:

Parameter
string $text
Text to quote [necessary]
integer $quote = >>1<<
When set, $begin_quote is user. Set by default.
integer $buff_size = >>70<<
Size of the line in chars. 70 by default.
string $end_quote = >>"\n"<<
Chars to add at the end of the line. \n by default
string $begin_quote = >>'> '<<
Chars to add at the beginning of the line. '> ' by default.
Returns string

the wrapped text


warn_referer

public string warn_referer( )

  Warns the user about the HTTP_REFERER http header.

Returns string

the formated warning.


debug

public void debug( string $debugMsg )

  Function to direct debugging output.
The output may be directed to stdout, a file or socket
depending on Config::debug and Config::debugFile

Parameter
string $debugMsg
the message to print
Returns void


debug_dump

public string debug_dump( mixed $var, [ integer $level ] )

  Traps a var_dump call and directs it to the selected debug output.
Warning: don't try it with recursive structures ($GLOBALS)

Parameter
mixed $var
the variable to dump
integer $level = >>0<<
used to dump in php3
Returns string $level

if != 0


no_access_msg

public string no_access_msg( )

  Generates the No Access message

Returns string

the no access string, to be printed out by the caller


Private Method Details

ip_start

private void ip_start( )

  We set up the right REMOTE_ADDR and right HTTP_HOST

Returns void


timestamp14_to_unix_stamp

private integer timestamp14_to_unix_stamp( string $t )

  Function which takes a timestamp(14) as input and returns a Unix timestamp
timestamp(14): "20010806110649"
Unix timestamp: 997088809

Parameter
string $t
value in the SQL type timestamp(14)
Returns integer

the Unix timestamp corresponding (maybe a string?)


unix_stamp_to_timestamp14

private string unix_stamp_to_timestamp14( integer $t )

  Function which takes a Unix timestamp as input and returns a timestamp(14)
Unix timestamp: 997088809
timestamp(14): "20010806110649"

Parameter
integer $t
the Unix timestamp
Returns string

the same converted to SQL type timestamp(14)


make_ipsession

private string make_ipsession( )

  Create new ipsession and returns it
Calls exit on SQL failure
FIXME: unused

Returns string

the ID of the session.


check_ipsession

private bool check_ipsession( [ string $idsession ] )

  Check ipsession
FIXME: unused

Parameter
string $idsession = >>""<<
the session to check
Returns bool

true if the session is valid, false if not.


Private Field Details

$db

private object db $db

>><<




Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta