DSite Technical Documentation

functions.inc File Reference

Contains main operative functions
Revision
4.92
. More...


Classes

class  UserParams
 current user security params defines user access level to some DSite actions More...

Enumerations

enum  USER_ACCESS_DEFAULT
 Access Levels for users Currently only two access levels. More...
enum  USER_ACCESS_ADVANCED
 < default and minimum 'the pot' level More...
enum  USER_ACCESS_CONFIGURED
 < minimum but with the preview mode on More...
enum  USER_ACCESS_PHP
 < acess level, configured by plugin More...
enum  USER_SESSION_COOKIE
 Имена кук Введено, так как имя gsession оказалось зарезервированным где-то. More...
enum  USER_COOKIELIVES
enum  USER_SESSION_TIMEOUT
 < the cookie that specifies the other cookies lives More...
enum  LOGFILEPATH
 < user session timeout More...

Functions

 GetAdminRoot ()
 
Returns:
the root path of admin modules

 GetLastUpdateVersion ()
 returns last update version (stored in DB, table dsite_version)
 GetServerName ($optionalname=false)
 returns string containing server name
 GetRevision ($revstr)
 retrieves revision info from string created by CVS
 print_r_get ($arr)
 retrieves the array
 ConfirmMessage ($subj, $msg)
 sends message to the address specified in the configurational file
 SetCookies ($cookielife=false, $cookies=false, $busercookie=false)
 this function sets all cookies that are need to be set, during page loading in order to use from a form, use the followin syntax:
 GetCookie ($cookiename, $busercookie=false)
 returns a cookie or variable passed as parameter value if everything is empty, returns empty string
 WriteLog ($str)
 writes the line with time stamp into the log file
 SQLProcessError ($errno, $tablename='news_cat')
 this function process MySQL error and reacts on it.
 DoSqlQuery ($sqlname)
 Runs an Sql Query, returns result link (for fetch array and other functions.
 AddDateTime ($srctime, $aY, $aM=0, $aD=0, $aHrs=0, $aMin=0, $aSec=0)
 Date/Time additing function.
 InsertBannerBlock ($blockid, $bannerType=0, $target='_blank')
 Banner block function.
 InsertContentBlock ($blockid)
 Inserts contents of the specified block into current place.
 InsertBlock ($blockid)
 Inserts specified block or an applicable banner if allowed.
 hasPHP ($htmlsource)
 determines whether the page containg a PHP code
 MakeURL ($url)
 this function returns URL, formatted by the following rules: if this is an URL - it is formatted like an url: http://www.dsite.ru, if this is e-mail - it is formatted like e-mail: mailto:info@webmedia.ru
 IsProhibitedServerFile ($filename)
 
Parameters:
filename string - the file name to be checked

 MakeSafeRootPath ($folderPath)
 this function performes simple test for a folder name (to be viewed or created).
 MoveUploadedFileSafe ($filename, $destination)
 the safe version of php function move_uploaded_file
 ImageUpload ($userfile, $filepath, $userfile_name, $bsilent=false, $boverwrite=false)
 Image upload helper.
 GetButtonMaxForPart ($partid)
 retrieves the maximal part button id
 SwapFields ($table, $idfieldname, $id1, $id2, $additionalsql= '')
 Swaps two `ID` fields.
 getAlignment ($ph, $aligndef)
 returns alignment checking first symbol in $ph: '<' - left; '>' - right; '=' - center;
 PrintError500 ($moreinfo='')
 returns WWW server error
used internally and called on fatal errors only
 CheckSignatureFile ($filename= 'sig.tmp')
 checks signature file, that enables ConfirmMessage function to be executed
 AutoTable ($text, $alignc='center')
 Creates a table with 2 columns from a string.
 echo_trans ($language_str)
 translates text into current language and prints it to output if no available value, prints not found symbol.
 trans ($language_str)
 
Parameters:
language_str string - the constant string, that identifies language line translates text into current language, if no available value, prints not found symbol.

 CleanUpHtmlSource ($htmlsource, $xmlonly=false)
 clears php code (and other) from the html source.
 CleanLogin ($strlogin)
 cleans login from unexpected symbols, like ', preventing some hacking attempts
 ReplaceSRCAttr2Full ($htmlsource)
 replaces SRC attributes to make them absolute from DOMAIN constant
 ReplaceSRCAttr2Relative ($htmlsource)
 replaces SRC attributes to make them relative from DOMAIN constant
 IsButton ($nButtonID, $nPartID=false)
 checks whether button with the specified id exists or not
 GetSectionName ()
 returns an active Section name
 GetSectionButtonName ()
 returns an active Section Button name (even when no button ID supplied)
 IsActiveButton ($nButtonID, $nPartID=false)
 determines whether the button with specified id is active or not
 get_PageSelector ($url, &$pg, $totalrows, $rpp=MAXROWSPERPAGE, $additionalurl='')
 Interface function that return values for printing in header [1, 2 .
 urlencoderepl ($arg, $replacements=NULL, $qfrm='?=&')
 encodes url, replacing additional values
 create_PageSelector ($query, $printfunc, $rpp=MAXROWSPERPAGE, $additionalurl='')
 this function shows select query using pages printing performed by specialized function $printfunc
 ConnectDatabase ($dbhost, $db, $dbuser, $dbpass, $silent, $ntries=1)
 connects to the specified database.
 CheckLoginPrintForm ($bAdmin)
 Prints form for filling login data.
 SetGlobalCookie ($strCookieName, $strValue)
 sets global DSite admin system cookie
 ClearCookie ($strCookieName)
 clears cookie with the specified name
 CheckLogin ($bAdmin=false)
 Checks user login, asks for it, if needed.
 CheckLoginByDBAccess ()
 This method of authentication is used from the display web-site system This method is more safe than CheckLogin, because user will not have access parameters for global users table.
 GetUpdateDefinesDBTbl ($dbhost, $db, $dbuser, $dbpwd, &$vars, $update=false, $silent=false, $tablename= 'dsite_config', $link=false, $prohibited_vars=array())
 the function uses specified table with format 'DESCR' 'NAME' 'VALUE' in order to do the following:
1) select from the specified database the values;
2) set defines [NAME] = [VALUE];
3) set global variables $fv_{NAME} = {VALUE} for forms post data;
4) if $update is set to true, update every record with values, stored in a forms variables with name $fv_{NAME}
5) close database

 ConfigGlobalVarsUpdate ()
 sets some global variables for compatibility reasons
 CheckReferer ()
 checs referers with DOMAIN.
 RedirectMe ($urlto, $timed=false, $bnotdies=false)
 this function performs redirection from one page to another
 mysql_time ($atime, $gmt=false)
 returns the specified time in a mysql format as string
 SaveCookiesVars ($vars, $add='', $cookielife='')
 this function will save in cookies all variables
 GetSavedVars ($vars, $add='')
 retrieves variable value, saved by SaveCookiesVars
 GetSectionId ()
 
Returns:
the selected section id or the page id when usepages flag is on

 GetSecFromButton ($nButtonID, $nPartID=false)
 
Returns:
Section ID by Button ID and Part ID

 GetMeta ()
 
Returns:
the text line of the meta-tags for the current section

 GetWWWPath ()
 get current document www path correctly $PHP_SELF зависит от documentroot, который, в случае если установлен неправильно, может портить ссылки, поэтому оптимальнее взять $REQUEST_URI
 PrintButtons ($printfunc)
 goes through the buttons and calls function, specified as a parameter
 PrintButtonsEx ($printfunc)
 goes through the buttons and calls function, specified as a parameter
 GetButton ($bstart=false)
 retrieves next button parameters (for current Part)
 InsertButtonURL ($buttonid=-1)
 obsolete, for backward compatibility only
 InsertButtonText ($buttonid=-1)
 obsolete, for backward compatibility only
 InsertButtonImage ($buttonid=-1)
 obsolete, for backward compatibility only
 GetExtension ($filename)
 
Returns:
the right part of the right dot in filename (extension)

 FinishSlash ($folder, $slash='/')
 appends the slash '/' at the end of the directory path string
 GetRequestString ($bRequestURI=true)
 tries to re-create full path of browser request
 GetPageByID ($id, $bcheckflag=false)
 returns page file name by the page ID
 DSiteError ($errortext, $bfatal=true)
 displays an error in a way, defined by the DSite system.
 GetDSiteDBVersion ()
 get current DSite global DB version
 SetDSiteVersionToDB ($ver)
 store to DB current DSite global DB version
 CheckAndUpdateDSiteDBStruct ()
 set check and update DSite global DB version

 GetHRFileSize ($size)
 convert size in bytes into Kb or Mb or Gb, depending on the value
 MailSafe ($strto, $strsubj, $strmessage, $strfrom=false, $content_type="text/html; charset=windows-1251")
 Sends an HTML coded e-mail message, preventing spam exploits.
 IsSafe2Include ($strPath)
 in several cases you cannot use RequireSafe function, then you can use simple require but checking the validity of the path
 RequireSafe ($require_module)
 when you use require_once with variable parameter, use this function to avoid vulnarabilities
 ParseStaticURI ($bMakeGlobal=false)
 parses url in a form /param/value/param/value and gets some parameters from it
 GetAliasFor ($alias_str)
 returns an alias for specified name
 ParseURIAlias ($bMakeGlobal=false)
 parses url using aliases table for which object in the system you can define an alias: section, page, news etc.
 IsAdminMode ()
 returns whether calling script is in admin part of the system
 CreateDSiteUrl ($id, $part=false, $usepages=false, $params=array())
 creates a valid url, using current web-site url-creation mode defined for the site

Variables

global $glog_file
 global Log file, most of cases used internally, externally defined by DSITELOGFILE value
global $gsql
 global SQL holder - array of SQL strings in a form of $gsql['SQLQUERYNAME']
global $gDSiteVersion
global $gUserCookieLives
 defines how long registration cookie lives (not used from version 3.90)
global $id
 global selected section id
global $theme
 global selected theme name
global $gPartID
 global selected Part ID
global $gEditMode
 edit mode on, section visualizer, contains admin path
global $gActiveSection
 active section parameters array. contains the following parameters: SectionName,ButtonName,Keywords,Description
global $gMenuButtons
 all menu buttons array in a form $gMenuButtons[$button_id][$button_part]['section'], where last parameter can be one of the following: section (section id), text (button name), url (button url), sectionname (section name)
global $gHTMLBodyFound
 user internally for BODY found sign
global $gBlockData
 specific block data
global $gFileVersion
 contains file versions, array
 $gDSiteVersion
 set DSite version by functions.inc revision
 $gFileVersion [__FILE__] = $gDSiteVersion
 $gHTMLBodyFound = false
 $reggl = ini_get('register_globals')
 set the default registration cookie life time (depricated) $gUserCookieLives = GetCookie('USER_COOKIELIVES');; //!< minutes cookie lives if (empty($gUserCookieLives)) { $gUserCookieLives = 20; }


Detailed Description

Contains main operative functions
Revision
4.92
.

===========================================================
Module : functions.inc
Project (part) : DSITE
CopyRight : MPG Ltd, 2002
Function : Defines content management functions
Author : Efimov Andrei
Created : 1.03.2002
Comments :
===========================================================

Enumeration Type Documentation

enum LOGFILEPATH

< user session timeout

enum USER_ACCESS_ADVANCED

< default and minimum 'the pot' level

enum USER_ACCESS_CONFIGURED

< minimum but with the preview mode on

enum USER_ACCESS_DEFAULT

Access Levels for users Currently only two access levels.

В дальнейшем, возможно, появится доступ по работе с блоками и прочая ... Все рассматриваемые уровни доступа идут на увеличение (т.е. доступ 3 включает в себя 3,2,1,0)

enum USER_ACCESS_PHP

< acess level, configured by plugin

enum USER_COOKIELIVES

enum USER_SESSION_COOKIE

Имена кук Введено, так как имя gsession оказалось зарезервированным где-то.

..

enum USER_SESSION_TIMEOUT

< the cookie that specifies the other cookies lives


Function Documentation

AddDateTime ( srctime,
aY,
aM = 0,
aD = 0,
aHrs = 0,
aMin = 0,
aSec = 0 
)

Date/Time additing function.

Adds day, month, hour etc. to a specified timestamp

Parameters:
$srctime - source time;
$aY - years to add;
$aM - months to add;
$aD - days to add;
$aHrs - hours to add;
$aMin - minutes to add;
$aSec - seconds to add;
Returns:
the result time

AutoTable ( text,
alignc = 'center' 
)

Creates a table with 2 columns from a string.

Each \n is a next column. If one column is void, then left column is stretched.

Parameters:
$text - the source text
$alignc - default alignment of the column
Remarks:
function does not create a "table" tag, only "tr", "td" tags are created

use first symbol of the line to determine alignment: '<' - left; '>' - right; '=' - center;

See also:
getAlignment()

CheckAndUpdateDSiteDBStruct (  ) 

set check and update DSite global DB version

CheckLogin ( bAdmin = false  ) 

Checks user login, asks for it, if needed.

Parameters:
$bAdmin set true if login is from administrative interface, otherwise and default false
Remarks:
On success sets global $guserDataBase, $guserDataHost to the name of the database

if glogout in GET is set, then user is logged out. glogout can be 1 or 2 value (1 - logout to a logout page (specified in config), 2 - logout, but stay in admin)

CheckLoginByDBAccess (  ) 

This method of authentication is used from the display web-site system This method is more safe than CheckLogin, because user will not have access parameters for global users table.

Remarks:
When you install multi-site system, you must create one user for a global database (full access) and one user for each project (access to local web-site database). Specify in local web-site config file only the last one. Specify in amin config the first one. Secure the admin config for reading from user domain accounts.

As the part of DSite configuration there are a set of defines, that depend on database.
there are the following defines may be found in the database (dsite_config):

  • BLOCKS_COLORS - Block colors, `;` delimited'
  • PIC_TYPES - Picture Extensions (GIF;JPG;JPEG;PNG')
  • DEFAULT_THEME - Default Theme Name (can be defined in parts also)
  • DEFAULT_PART - Default Part ID
  • MAXBLOCKS - Maximum Blocks Number
  • MAXROWSPERPAGE - Display Rows Per Page
  • WWWPICPATH - Relative Path to Images (with / at end)
  • BANNERPATH - Relative Path to Banners (with / at end)
  • PICSTORE - Server Path to Images (auto)
  • FILESTORE - Server Path to WebPages (auto)
  • BANNERSTORE - Server Path to Banners (auto)
  • THEMESPATH - Server Path to Themes (auto)
  • BACKUPPATH - Backup Path (with / at end)
  • TEMPLATESPATH - Path to templates (with / at end) for templater
  • MYSQLCHARSET - MySQL Charset, for example cp1251 if needed
  • LOCKWAIT - Pages Lock Wait in minutes ('in use' message)
  • DOMAIN - web-site fully qualified name (no / at the end), for instance http://www.dsite.ru
  • PLUGINS - installed plugins `;` delimited
  • SERVERROOT - Server Root Path (with / at end)
  • DSTMPDIR - DSite Temporary Files directory

CheckLoginPrintForm ( bAdmin  ) 

Prints form for filling login data.

Parameters:
bAdmin - admin mode if true

CheckReferer (  ) 

checs referers with DOMAIN.

Returns:
true if the referer is from this domain, otherwise returns false

CheckSignatureFile ( filename = 'sig.tmp'  ) 

checks signature file, that enables ConfirmMessage function to be executed

Parameters:
filename string - the signature filename, 'sig.tmp' by default
Remarks:
you have to delete this file manually
Returns:
true if file exists, and it is not at least a day old, otherwise tries to create file and returns false
Remarks:
if the file can't be created returns true.
In this case you can receive mass messages from DSite system and owerflow log file!
See also:
ConfirmMessage, PrintError500

CleanLogin ( strlogin  ) 

cleans login from unexpected symbols, like ', preventing some hacking attempts

Parameters:
$strlogin string - login to be cleared
Returns:
the valid login without prohibited symbols

CleanUpHtmlSource ( htmlsource,
xmlonly = false 
)

clears php code (and other) from the html source.

Parameters:
$htmlsource - the source itself
$xmlonly - clean only xml entries
Returns:
modified source

ClearCookie ( strCookieName  ) 

clears cookie with the specified name

Parameters:
strCookieName string - the name of the cookie to be cleared

ConfigGlobalVarsUpdate (  ) 

sets some global variables for compatibility reasons

ConfirmMessage ( subj,
msg 
)

sends message to the address specified in the configurational file

Parameters:
subj string - subject of the message (must contain only DSite information!)
msg string - message body (must contain only DSite information!)
Returns:
true if the message has been sent

ConnectDatabase ( dbhost,
db,
dbuser,
dbpass,
silent,
ntries = 1 
)

connects to the specified database.

Prints error messages on the screen. $dbhost - the host $db - the database name $dbuser - database user $dbpass - database password $silent - if true - no messages on screen $ntries int - the number of retries

Returns:
the link to the opened database

create_PageSelector ( query,
printfunc,
rpp = MAXROWSPERPAGE,
additionalurl = '' 
)

this function shows select query using pages printing performed by specialized function $printfunc

Parameters:
$query - the query to process
$printfunc - printing function, takes:
  1. index (1,2,...) on this page for the first parameter
  2. an array with each line results as a second paramter
  3. the third parameter is passed only for the first row and is equal to the page selector line code (if any)
rpp - rows per pages
additionalurl string - the addition to url appended to page url*
Returns:
false on error, page selector line on success
Remarks:
uses and sets global variable $pg this function also echoes for page selector

Uses global constant MAXROWSPERPAGE

See also:
get_PageSelector

CreateDSiteUrl ( id,
part = false,
usepages = false,
params = array() 
)

creates a valid url, using current web-site url-creation mode defined for the site

Parameters:
id int - the id of a section or page (when usepages is not false), use GetSectionId() to specify current section, if false - default section for part is used
part int - the id of a part, if false not specified
usepages int - the usepages flag, default false
params array - additional params to pass: array ( 'paramname' => paramvalue, ...), optional
Returns:
the url string
Remarks:
uses global define STATIC_PATHS
Example of use
<img src="<?=CreateDSiteUrl(34, false, 1, array('obj_id'=>intval($_GET['obj_id']),'main'=>1)); ?>" border="0">

DoSqlQuery ( sqlname  ) 

Runs an Sql Query, returns result link (for fetch array and other functions.

..)

Parameters:
$sqlname the name of the sql query in global $gsql array or (if starts from `:` symbol the sql query itself).
Remarks:
(...) other optional params are specified according to format of sql, same as sprintf function
Returns:
false on error, result link on success
Remarks:
writes log on error and debug

DSiteError ( errortext,
bfatal = true 
)

displays an error in a way, defined by the DSite system.


Use only this function to display internal errors

Parameters:
errortext string - error text
bfatal bool - optional fatality of error, if true (default) stops executing.
Returns:
nothing
See also:
PrintError500

echo_trans ( language_str  ) 

translates text into current language and prints it to output if no available value, prints not found symbol.

optional additional arguments can be used like in "printf" function.

Parameters:
language_str string - the constant string, that identifies language line
See also:
trans

FinishSlash ( folder,
slash = '/' 
)

appends the slash '/' at the end of the directory path string

Parameters:
folder string - usually the directory name to append a slash
slash string - the slash symbol, '/' by default (depends on OS, usually, and can be found in PHP constant PATH_SEPARATOR)
Returns:
the string containing the path with '/' at the end

get_PageSelector ( url,
&$  pg,
totalrows,
rpp = MAXROWSPERPAGE,
additionalurl = '' 
)

Interface function that return values for printing in header [1, 2 .

..] for pages

Remarks:
This function is deprecated use class pages
See also:
pages
Parameters:
$url - the url to make href to
$pg - the currently selected page number
$totalrows - the number of actually available rows
additionalurl string - the addition to url appended to page url, may contain macro command PG% that is replaced by current page id
rpp int - rows per pages
Returns:
the line to print
Remarks:
Uses global constant MAXROWSPERPAGE

url is called with parameter $pg

GetAdminRoot (  ) 

Returns:
the root path of admin modules

Remarks:
usually ADMINROOT specified in config.php and containes the path, but using this function is safier

DO not use ADMINROOT constant directly!

GetAliasFor ( alias_str  ) 

returns an alias for specified name

Parameters:
$alias_str string - the name
Returns:
the specified alias form DB, or empty string

getAlignment ( ph,
aligndef 
)

returns alignment checking first symbol in $ph: '<' - left; '>' - right; '=' - center;

Parameters:
$ph - source line
$aligndef - default alignment string
Returns:
array of two elements: 1) modified line* 2) alignment
See also:
AutoTable()

GetButton ( bstart = false  ) 

retrieves next button parameters (for current Part)

Parameters:
bstart bool - if true starts from the beginning
Returns:
false if no more buttons, otherwise returns button as array with keys 'text', 'url', 'section', 'sectionname', 'id'

GetButtonMaxForPart ( partid  ) 

retrieves the maximal part button id

Returns:
ID on success, -1 on errors
Parameters:
partid int - the part ID
Remarks:
does not take into account the section visibility flag (used from admin interface only)

GetCookie ( cookiename,
busercookie = false 
)

returns a cookie or variable passed as parameter value if everything is empty, returns empty string

Parameters:
$cookiename - the name of variable or cookie
busercookie bool - if true uses current DSite user name to retrieve cookie for
Remarks:
If there is a global variable with the same name is set, then this function returns the value of this variable

The priority of variables follows:

  1. gSetCookies variable array
  2. GET vars
  3. POST vars
  4. COOKIE vars
  5. GLOBALS
See also:
SetCookies

GetDSiteDBVersion (  ) 

get current DSite global DB version

Returns:
current DSite global DB version or 3 if version not found

GetExtension ( filename  ) 

Returns:
the right part of the right dot in filename (extension)

Parameters:
filename string - the name of the file

GetHRFileSize ( size  ) 

convert size in bytes into Kb or Mb or Gb, depending on the value

Parameters:
size int - size in bytes
Returns:
string, like : 100Kb

GetLastUpdateVersion (  ) 

returns last update version (stored in DB, table dsite_version)

Returns:
return last update version
Remarks:
If the version from DB is lower, the updates will be applied

GetMeta (  ) 

Returns:
the text line of the meta-tags for the current section

GetPageByID ( id,
bcheckflag = false 
)

returns page file name by the page ID

Parameters:
id int - page id
bcheckflag bool - check flag bUsePages for this page, if not set, does not return any pages
Returns:
the full filepath of the page false on error or not found

GetRequestString ( bRequestURI = true  ) 

tries to re-create full path of browser request

Parameters:
bRequestURI bool - append request uri or not
Returns:
full request string

GetRevision ( revstr  ) 

retrieves revision info from string created by CVS

Parameters:
revstr string - string from CVS
Returns:
numbered revision

GetSavedVars ( vars,
add = '' 
)

retrieves variable value, saved by SaveCookiesVars

Parameters:
vars string - must be 'var1,var2 ...' variable names ',' delimited
add string - the addition to the cookie name (usually section id)
Returns:
always true
Remarks:
sets only if not empty, otherwise variable is leaved unchanged
See also:
SaveCookiesVars

GetSecFromButton ( nButtonID,
nPartID = false 
)

Returns:
Section ID by Button ID and Part ID

Parameters:
nButtonID int - button ID
nPartID int - part ID, if not specifed uses current Part ID
Remarks:
available only from version 3.17

GetSectionButtonName (  ) 

returns an active Section Button name (even when no button ID supplied)

Returns:
the currently selected Section Button Name

GetSectionId (  ) 

Returns:
the selected section id or the page id when usepages flag is on

GetSectionName (  ) 

returns an active Section name

Returns:
the currently selected Section Name

GetServerName ( optionalname = false  ) 

returns string containing server name

Parameters:
$optionalname string - the optional server name to be used instead of default
Remarks:
server name is the name of the server for which web script has been executed
Returns:
string in a form 'webmedia.ru' containing current server name
Remarks:
if this function is used on web output, provide DOMAIN macro to get valid server name

GetUpdateDefinesDBTbl ( dbhost,
db,
dbuser,
dbpwd,
&$  vars,
update = false,
silent = false,
tablename = 'dsite_config',
link = false,
prohibited_vars = array() 
)

the function uses specified table with format 'DESCR' 'NAME' 'VALUE' in order to do the following:
1) select from the specified database the values;
2) set defines [NAME] = [VALUE];
3) set global variables $fv_{NAME} = {VALUE} for forms post data;
4) if $update is set to true, update every record with values, stored in a forms variables with name $fv_{NAME}
5) close database

Remarks:
the function uses global user $gdbuser and password gdpass
Parameters:
dbhost string - host for the specified database
db string - database name
dbuser string -database user name
dbpwd string - database password
vars 2 dim array - the result variables : $vars[$i]['NAME'] - the name, $vars[$i]['VALUE] - the value $vars['DESCR'] contains the user-friendly description
update bool - update config table
silent bool - keep silence if true (no screen messages)
tablename string - the name of the table, by default dsite_config
link - a link to the database, if specified, ConnectDatabase is not called
prohibited_vars array - the array, contains the names of variables that are prohibited to update in this call
Returns:
true on success, false on error, printing an error information on the screen

GetWWWPath (  ) 

get current document www path correctly $PHP_SELF зависит от documentroot, который, в случае если установлен неправильно, может портить ссылки, поэтому оптимальнее взять $REQUEST_URI

Returns:
for /index.html?id=25&hhh=90 /index.html
See also:
urlencoderepl

hasPHP ( htmlsource  ) 

determines whether the page containg a PHP code

Returns:
true if PHP code exist, otherwise false

ImageUpload ( userfile,
filepath,
userfile_name,
bsilent = false,
boverwrite = false 
)

Image upload helper.

Parameters:
userfile string - variable (usually name of file-type input) that contains user file name
filepath string - the storage folder for the uploaded file
userfile_name string - the name of the uploaded file
bsilent bool - if true, does not write to output any information about file-upload (writes to log)
boverwrite bool - if true, exisiting file will be overwritten
Returns:
false on errors, true on success
Remarks:
usually use of this function:
   $userfile_name = $_FILES['userfile']['name'];
   $userfile = $_FILES['userfile']['tmp_name'];
   ImageUpload($userfile, $path, $userfile_name, false);
for a form:
  <FORM ACTION="#" enctype="multipart/form-data" METHOD="POST">
  <input class=cutebox name='userfile' type='file'>
  ...
  </form>

InsertBannerBlock ( blockid,
bannerType = 0,
target = '_blank' 
)

Banner block function.

Parameters:
$blockid - the id or the name of the block
$bannerType - the type of the banner to find
target string - the target, default '_blank'
Remarks:
Selects an image from a banners table randomly

InsertBlock ( blockid  ) 

Inserts specified block or an applicable banner if allowed.

Parameters:
$blockid - the id or the name of the block

InsertButtonImage ( buttonid = -1  ) 

obsolete, for backward compatibility only

InsertButtonText ( buttonid = -1  ) 

obsolete, for backward compatibility only

InsertButtonURL ( buttonid = -1  ) 

obsolete, for backward compatibility only

InsertContentBlock ( blockid  ) 

Inserts contents of the specified block into current place.

Parameters:
$blockid int - the id or the name of the block
Returns:
true if successfully inserted the block otherwise returns false.

IsActiveButton ( nButtonID,
nPartID = false 
)

determines whether the button with specified id is active or not

Parameters:
nButtonID int - the id of the button
nPartID int - the part for which the button id is specified, when false used the currently active part
Returns:
true if active

IsAdminMode (  ) 

returns whether calling script is in admin part of the system

Returns:
true if backend, false if frontent

IsButton ( nButtonID,
nPartID = false 
)

checks whether button with the specified id exists or not

Parameters:
nButtonID int - the id of the button
nPartID int - the part for which the button id is specified, when false used the currently active part
Returns:
true if exists, otherwise false

IsProhibitedServerFile ( filename  ) 

Parameters:
filename string - the file name to be checked

Returns:
true if this type of file(s) prohibited (executable or script)
Remarks:
the prohibited extensions are stored in DSITE_PROHIBITED_FILE_EXTENSIONS constant, that can be overriden in config.php file, if needed

IsSafe2Include ( strPath  ) 

in several cases you cannot use RequireSafe function, then you can use simple require but checking the validity of the path

Parameters:
strPath string - the path to be checked
Returns:
true if path is ok, otherwise false
Example of use
  if (IsSafe2Include($module)) include($module);

MailSafe ( strto,
strsubj,
strmessage,
strfrom = false,
content_type = "text/html; charset=windows-1251" 
)

Sends an HTML coded e-mail message, preventing spam exploits.

Parameters:
strto string - Receiver, or receivers of the mail (comma-separated)
strsubj string - message subject
strmessage string - message body
strfrom string - message sender, optional
$content_type string - optional parameter for setting content-type, by default text/html, charset Windows-1251
Returns:
true on success, and false on error
Remarks:
adds to log hacking attempts

MakeSafeRootPath ( folderPath  ) 

this function performes simple test for a folder name (to be viewed or created).

If the path is root-based (starts from '/' symbol), then it is checked for starting with SERVERROOT constant, which contains the root of web-site project on the server. If this paths not match, it will be corrected to a relative one. If the path is already relative, then it is not changed.

Parameters:
folderPath string - the path to be checked
Returns:
the name that is safe for the client project
Remarks:
if the path has been corrected, function writes to log

MakeURL ( url  ) 

this function returns URL, formatted by the following rules: if this is an URL - it is formatted like an url: http://www.dsite.ru, if this is e-mail - it is formatted like e-mail: mailto:info@webmedia.ru

Parameters:
url string - the url to make href for
Returns:
full href string

MoveUploadedFileSafe ( filename,
destination 
)

the safe version of php function move_uploaded_file

Parameters:
filename string - the name of uploaded file
destination string - the destination file, where uploaded file has to be written to
Returns:
result of move_uploaded_file PHP function
See also:
php help for details

IsProhibitedServerFile

mysql_time ( atime,
gmt = false 
)

returns the specified time in a mysql format as string

Parameters:
$atime - date time stamp value
$gmt bool - default false, use GMT time
Returns:
string with time, false on error
example
mysql_time(time());

ParseStaticURI ( bMakeGlobal = false  ) 

parses url in a form /param/value/param/value and gets some parameters from it

Remarks:
to make it work you have to set script to ErrorDocument
Parameters:
bMakeGlobal bool - if true makes variables global, otherwise only fills $_GET array, false by default

ParseURIAlias ( bMakeGlobal = false  ) 

parses url using aliases table for which object in the system you can define an alias: section, page, news etc.

in order to make it work you have to define alias for that object using aliases plugin or imbuild DSite functionality

Parameters:
bMakeGlobal bool - if true makes variables global, otherwise only fills $_GET array, false by default
Returns:
false if no Parse needed (not an alias), true if succeeded
Remarks:
There must be defined RewriteRules in .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

print_r_get ( arr  ) 

retrieves the array

Parameters:
$arr array - source array
Returns:
the print_r function result as string

PrintButtons ( printfunc  ) 

goes through the buttons and calls function, specified as a parameter

Parameters:
printfunc string - the name of the function, specified somewhere in template the function must be in the following form: function PrintAButton($buttontext, $buttonurl, $active, $sectionid), where $buttontext string - the text of the button, $buttonurl string - url which button references, $active bool - true, if this button is active $sectionid int - id of the section for this button
Returns:
nothing

PrintButtonsEx ( printfunc  ) 

goes through the buttons and calls function, specified as a parameter

Parameters:
printfunc string - the name of the function, specified somewhere in template the function must be in the following form: function PrintAButtonEx($buttoninfo, $buttonid), where $buttoninfo array in with the following keys:
['url'] - url which button references, ['text'] - text of the button ['section'] - section id of the button ['sectionname'] - section title of the button
Returns:
nothing

PrintError500 ( moreinfo = ''  ) 

returns WWW server error
used internally and called on fatal errors only

Parameters:
moreinfo string - more information - hidden from user, but visible to techican
Remarks:
also sends email and writes to log file
See also:
DSiteError, CheckSignatureFile, ConfirmMessage

RedirectMe ( urlto,
timed = false,
bnotdies = false 
)

this function performs redirection from one page to another

Parameters:
$urlto string - the url to redirect user to
timed int - optional parameter, determines the number of milliseconds to wait, before redirection.
if set Javascript/noscript only version is used
bnotdies bool - not dying after RedirectMe (since 26.04.07 )
Returns:
true

ReplaceSRCAttr2Full ( htmlsource  ) 

replaces SRC attributes to make them absolute from DOMAIN constant

Parameters:
$htmlsource - the source html
Returns:
the replaced html

ReplaceSRCAttr2Relative ( htmlsource  ) 

replaces SRC attributes to make them relative from DOMAIN constant

Parameters:
$htmlsource - the source html
Returns:
the replaced html

RequireSafe ( require_module  ) 

when you use require_once with variable parameter, use this function to avoid vulnarabilities

Parameters:
$require_module string - path to be required
Returns:
false on error or invalid path, otherwise true
See also:
IsSafe2Include

SaveCookiesVars ( vars,
add = '',
cookielife = '' 
)

this function will save in cookies all variables

Parameters:
vars string - must be 'var1,var2 ...' variable names ',' delimited
cookielife time - the life of these cookies, 1 day by default
add string - the addition to the cookie name (usually section id)
Returns:
always true
See also:
GetSavedVars
Remarks:
Within DSite pages system you can use the following global variable $gSaveCookies in order to save all your cookies, because index.php uses the following syntax:
if (isset($gSaveCookies))
{
SaveCookiesVars($gSaveCookies,$id,$gSaveCookiesLife);
}

SetCookies ( cookielife = false,
cookies = false,
busercookie = false 
)

this function sets all cookies that are need to be set, during page loading in order to use from a form, use the followin syntax:

   <input type=hidden name="gSetCookies" value="cookiename1=cookieval1;cookiename2=cookieval2...">
using `;` delimiter between cookies, and `=` between names and values
Use 3D symbol for method `GET`
Parameters:
cookielife - the life of cookie as time(), by default - 1 day
cookies - if not empty, uses this variable instead of gSetCookies
busercookie bool - if true uses current DSite user name to store cookie for
Remarks:
This function is called within the index.inc file (Adm part of DSite)

This function also sets all global variables with cookie names in order they can be used inside the program in real-time

See also:
index.inc

GetCookie

SetDSiteVersionToDB ( ver  ) 

store to DB current DSite global DB version

Parameters:
ver float - version number of DB that sets
Returns:
false on error

SetGlobalCookie ( strCookieName,
strValue 
)

sets global DSite admin system cookie

Remarks:
usually this function used interanlly

SQLProcessError ( errno,
tablename = 'news_cat' 
)

this function process MySQL error and reacts on it.


In several cases it can automatically fix an error.
In other cases it will terminate execution.

Parameters:
errno int - the error number returned by mysql_errno() function
tablename string - the table, for which to process an error, default news_cat
Returns:
true on success, or stops, false on error

SwapFields ( table,
idfieldname,
id1,
id2,
additionalsql = '' 
)

Swaps two `ID` fields.

Swaps two `ID` fields, without changing the contents.

Parameters:
$table - the name of the table;
$idfieldname - the name of the field that contains ID
$id1 - the first id to swap
$id2 - the id to swap with $id1
$additionalsql - additional sql that can be "where FIRSTID=0"
Returns:
zero on success

trans ( language_str  ) 

Parameters:
language_str string - the constant string, that identifies language line translates text into current language, if no available value, prints not found symbol.

optional additional arguments can be used like in "printf" function.

Returns:
string tranlated

urlencoderepl ( arg,
replacements = NULL,
qfrm = '?=&' 
)

encodes url, replacing additional values

Parameters:
$arg array - $_GET usually
$replacements array - array of replacing values
$qfrm string - optional delimiters for URL encoding, by default '?=&'
Returns:
the encoded url part
example
$href = $PHP_SELF.'?'.urlencoderepl( $_GET, array('myvar'=>'5') );

WriteLog ( str  ) 

writes the line with time stamp into the log file

Parameters:
$str the line to write
Returns:
true if write wass successfull
Remarks:
uses global variable $glog_file which specifies full path to the log file on server, if it is empty, no writing performed.
This variable usually filled the following way:
  • For frontend part of the site located in inc directory of SERVERROOT and can be viewed through DSite system - view log file Menus
  • For backend part located in inc directory where admin modules are stored and can be viewed by served administator (superuser) using Users Administration - View log file menus.

When error is specified, backtrace is done. It's also done when DEBUG constant is specified. The DEBUG constant can be defined in config.php file and can value from 0 to 4. It's not recommended to leave it defined on live web-sites, because there are too many log information can be generated.


Variable Documentation

global $gActiveSection

active section parameters array. contains the following parameters: SectionName,ButtonName,Keywords,Description

global $gBlockData

specific block data

$gDSiteVersion

Initial value:

 '
$Revision: 4.92 $
'
set DSite version by functions.inc revision

global $gDSiteVersion

global $gEditMode

edit mode on, section visualizer, contains admin path

$gFileVersion[__FILE__] = $gDSiteVersion

global $gFileVersion

contains file versions, array

$gHTMLBodyFound = false

global $gHTMLBodyFound

user internally for BODY found sign

global $glog_file

global Log file, most of cases used internally, externally defined by DSITELOGFILE value

global $gMenuButtons

all menu buttons array in a form $gMenuButtons[$button_id][$button_part]['section'], where last parameter can be one of the following: section (section id), text (button name), url (button url), sectionname (section name)

global $gPartID

global selected Part ID

global $gsql

global SQL holder - array of SQL strings in a form of $gsql['SQLQUERYNAME']

global $gUserCookieLives

defines how long registration cookie lives (not used from version 3.90)

global $id

global selected section id

$reggl = ini_get('register_globals')

set the default registration cookie life time (depricated) $gUserCookieLives = GetCookie('USER_COOKIELIVES');; //!< minutes cookie lives if (empty($gUserCookieLives)) { $gUserCookieLives = 20; }

global $theme

global selected theme name

Copyright © 2001-2007 Media Programming Group
Last generated 8 Jun 2011