Contentserv PHP API

CS
in package

This class delivers the CONTENTSERV API for PHP based Applications

The CSApi is the central core access point for any PHP scripts that need access to the CONTENTSERV system.

All calls to the API are static PHP class method calls, e.g.

  CS:loadAPI("CSUser");
  echo "The current user is " . CSUser::getUserName();

The CS Api is available automatically in all CONTENTSERV html templates.

Tags
access

public

Table of Contents

INI_GROUP_AUTOMATION  = \CSIniUtils::INI_GROUP_AUTOMATION
Defines standard sections of the CS.ini file
INI_GROUP_BACKUP  = \CSIniUtils::INI_GROUP_BACKUP
INI_GROUP_LICENSE  = \CSIniUtils::INI_GROUP_LICENSE
INI_GROUP_OPTIONS  = \CSIniUtils::INI_GROUP_OPTIONS
INI_GROUP_PHP  = \CSIniUtils::INI_GROUP_PHP
INI_GROUP_RIGHTS  = \CSIniUtils::INI_GROUP_RIGHTS
INI_GROUP_VOLUMES  = \CSIniUtils::INI_GROUP_VOLUMES
activateUpdateMode()  : void
Activates the CS Update mode - reducing the CONTENTSERV caching for maximal update speed If multiple updates or inserts are scripted (e.g. for imports) this could be enabled to reduce update durations
checkStopEvent()  : bool
This method should be called regularly in large abortable scripts to detect, whether the process should be stopped If it returns true, the script should finish itself
createAjaxEvaluate()  : string
creates a unique id for the php code that can be used with the javascript CS.evaluate-method
deactivateItemCache()  : void
Deactivates the new item cache mode which has been introduced with CS12.1 If this mode is activated (standard) all getValue calls are forwarded to the getValues method This decreases the amount of object operations and required data to load as it only loads the required values from the database. On some systems the new way is faster, on some the old way.
disableCurlRequestForWorkflowActions()  : void
This method sets the public instance variable $bDisableCurlRequestForWorkflowActions of the Workflow class to true
disableRightCheck()  : void
This method can be used to disable all standard right checks for all objects.
freeMemory()  : void
Decreases the used memory by removing all internal cached objects from memory
getApiDocumentationUrl()  : string
Returns am API Documentation URL to CONTENTSERV Application.
getCredentialOption()  : string
Returns a credential value based on the Credentials API. This is required if the option that is requested stores its value in the credential context.
getDate()  : string
Format a local time/date
getDocumentationUrl()  : string
Returns general documentation URL to CONTENTSERV Application.
getFormValues()  : array<string|int, mixed>
Returns an array of request values found in the global $_POST array.
getIniValue()  : mixed
Returns the requested ini value if it exists.
getIniValues()  : array<string|int, mixed>
Returns all ini values from the specified group.
getLicensee()  : string
Retrieves the current licensee.
getLinkToResource()  : string
Returns a link to a CONTENTSERV project document or file resource, which can be absolute or relative to the project base directory.
getObjectRecord()  : ObjectDatabaseRecord
Loads a object database record with a given id.
getOption()  : string
Returns an Option from the administrations or custom settings
getProcessID()  : string
Returns the unique ID for the current process
getProjectName()  : string
Retrieves the current project name.
getRecord()  : Record
Loads a record with a given id. If the class has not been loaded, the corresponding module is loaded first
getRequestValues()  : array<string|int, mixed>
Returns an array of request values found in the global $_GET array.
getServerName()  : string
Returns the server name.
getTable()  : Table
Loads a table for a given record.
getTablePrefix()  : string
Retrieves a table prefix used by the current project.
getUrl()  : string
generates an url with the specified params including a security hash to make sure the url is not manipulated
getVersion()  : string
Returns the build number of the CS API
htmlentities()  : string
Entities encodes a string in the current charset. For details see for the build in PHP htmlentities method.
includeFile()  : mixed
Includes one file. The file is searched in the following directories: - [PROJECT]/$file - [admin.local]/$file - [admin]/$file - $file The first found file is included.
isAdmin()  : bool
Return whether the current call to this function is done within the administrative backend or from the published website
loadAPI()  : string
Loads the specified API
loadModule()  : CSModule
Loads a module
log()  : void
Adds an entry in the CS system log table
logProcess()  : void
Adds an entry in the CS system process log
mail()  : mixed
Sends a mail generated by an xml template file
query()  : mixed
Sends an sql query to the database
queryValue()  : mixed
Sends an sql query to the database
requireFile()  : mixed
Includes one file.
runScheduledAutomations()  : mixed
Starts the schedular to check whether automations should be done As this is done automatically since CS 4.3 this method call is internal
scheduleProcess()  : mixed
Schedules method calls in another process which is called after the original process has been finished.
setLocaleCharset()  : void
Sets the output charset for all translations
setLocaleLanguage()  : void
Sets the default locale language for all translations
setOption()  : mixed
Sets an Option at the administration or custom settings
setProjectName()  : mixed
Sets the current project name and reinitialize the database connection with that project
throwError()  : void
Throws an Exception
throwWarning()  : void
Throws an Exception with type E_WARNING
translate()  : string
Translates a word with the CONTENTSERV Dictionary It is possible to create dynamic translations. Therefore an array is allowed as $word, where the first value is the word to translate and the others are values which are automatically replaced.

Constants

INI_GROUP_AUTOMATION

Defines standard sections of the CS.ini file

public mixed INI_GROUP_AUTOMATION = \CSIniUtils::INI_GROUP_AUTOMATION
Tags

INI_GROUP_BACKUP

public mixed INI_GROUP_BACKUP = \CSIniUtils::INI_GROUP_BACKUP
Tags

INI_GROUP_LICENSE

public mixed INI_GROUP_LICENSE = \CSIniUtils::INI_GROUP_LICENSE
Tags

INI_GROUP_OPTIONS

public mixed INI_GROUP_OPTIONS = \CSIniUtils::INI_GROUP_OPTIONS
Tags

INI_GROUP_PHP

public mixed INI_GROUP_PHP = \CSIniUtils::INI_GROUP_PHP
Tags

INI_GROUP_RIGHTS

public mixed INI_GROUP_RIGHTS = \CSIniUtils::INI_GROUP_RIGHTS
Tags

INI_GROUP_VOLUMES

public mixed INI_GROUP_VOLUMES = \CSIniUtils::INI_GROUP_VOLUMES
Tags

Methods

activateUpdateMode()

Activates the CS Update mode - reducing the CONTENTSERV caching for maximal update speed If multiple updates or inserts are scripted (e.g. for imports) this could be enabled to reduce update durations

public static activateUpdateMode([bool $activate = true ]) : void
Parameters
$activate : bool = true

whether the update mode should be enabled

Tags
Return values
void

checkStopEvent()

This method should be called regularly in large abortable scripts to detect, whether the process should be stopped If it returns true, the script should finish itself

public static checkStopEvent() : bool
Tags
access

public

Return values
bool

whether the script should be stopped

createAjaxEvaluate()

creates a unique id for the php code that can be used with the javascript CS.evaluate-method

public static createAjaxEvaluate(string $code[, bool $removeAfterExecution = false ]) : string
Parameters
$code : string

the php code that should be encrypted.

$removeAfterExecution : bool = false

whether the php code should be removed from session after execution

Tags
access

public

Return values
string

a unique id for the php code inside the session that should be used with the CS.evaluate-method

deactivateItemCache()

Deactivates the new item cache mode which has been introduced with CS12.1 If this mode is activated (standard) all getValue calls are forwarded to the getValues method This decreases the amount of object operations and required data to load as it only loads the required values from the database. On some systems the new way is faster, on some the old way.

public static deactivateItemCache([bool $bDeactivate = true ]) : void

If it is faster for the current project or in some scripts without the cache, it can be deactivated using this method.

Parameters
$bDeactivate : bool = true

whether the new caching mode should be deactivated

Tags
Return values
void

disableCurlRequestForWorkflowActions()

This method sets the public instance variable $bDisableCurlRequestForWorkflowActions of the Workflow class to true

public static disableCurlRequestForWorkflowActions([bool $bDisable = true ]) : void
Parameters
$bDisable : bool = true

whether the Workflow Action should be executed via Curl, disabled = true or enabled = false

Tags
Return values
void

disableRightCheck()

This method can be used to disable all standard right checks for all objects.

public static disableRightCheck([bool $disable = true ]) : void

If you want to disable the right check on a specific record, you can also disable the right check on this object using other methods. Even, if a user doesn't have the right to edit the item, he can check out/in or store it.

Parameters
$disable : bool = true

whether the right check should be disabled = true or enabled = false

Tags
Return values
void

freeMemory()

Decreases the used memory by removing all internal cached objects from memory

public static freeMemory() : void
Tags
access

public

Return values
void

getApiDocumentationUrl()

Returns am API Documentation URL to CONTENTSERV Application.

public static getApiDocumentationUrl() : string
Tags
Return values
string

getCredentialOption()

Returns a credential value based on the Credentials API. This is required if the option that is requested stores its value in the credential context.

public static getCredentialOption(string $sOptionName[, string $sModuleName = 'custom' ][, mixed $mDefault = '' ]) : string
Parameters
$sOptionName : string

Name of the credential option

$sModuleName : string = 'custom'

Name of the module the credential option refers to, custom is default

$mDefault : mixed = ''

Default value to be used if the credential option is not available

Tags
access

public

Return values
string

The value of the credential option

getDate()

Format a local time/date

public static getDate([int $time = null ]) : string
Parameters
$time : int = null

[optional] The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

Tags
access

public

Return values
string

the current date and time

getDocumentationUrl()

Returns general documentation URL to CONTENTSERV Application.

public static getDocumentationUrl() : string
Tags
Return values
string

getFormValues()

Returns an array of request values found in the global $_POST array.

public static getFormValues() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

the request values

getIniValue()

Returns the requested ini value if it exists.

public static getIniValue(string $sName, string $sGroup[, array<string|int, mixed> $aContext = array() ]) : mixed
Parameters
$sName : string

The name of the ini value to return

$sGroup : string

The group in which this value is contained as one of the CSIniUtils::INI_GROUP_-constants

$aContext : array<string|int, mixed> = array()

An optional list of contexts. If the context is provided and a group with one of the contexts exists, the values overwrite the global values.

Tags
access

public

Return values
mixed

The value of the requested option. If the value is not found, null is returned.

getIniValues()

Returns all ini values from the specified group.

public static getIniValues(string $sGroup[, array<string|int, mixed> $aContext = array() ][, array<string|int, mixed> $aFilter = array() ]) : array<string|int, mixed>
Parameters
$sGroup : string

The group in which this value is contained as one of the CSIniUtils::INI_GROUP_-constants

$aContext : array<string|int, mixed> = array()

An optional list of contexts. If the context is provided and a group with one of the contexts exists, the values overwrite the global values.

$aFilter : array<string|int, mixed> = array()

An optional list of filters to be applied. The values in the list are compared type-safe with the values from the ini file. Only if they match they are contained in the final result set.

Tags
access

public

Return values
array<string|int, mixed>

The list of all matching values for the current group, context and filter.

getLicensee()

Retrieves the current licensee.

public static getLicensee() : string
Tags
access

public

Return values
string

the name of the licensee as defined in the installation & licensing area

getLinkToResource()

Returns a link to a CONTENTSERV project document or file resource, which can be absolute or relative to the project base directory.

public static getLinkToResource(string $link[, string $base = 'relative' ]) : string

The base can be relative, external or internal. External is the base from the browsers point of view, internal from the servers point of view. The provided link must be relative to the project base directory. The internal and external bases can be configured in the settings or are guessed otherwise.

Parameters
$link : string

Link to the resource relative to the project root.

$base : string = 'relative'

Base of the link can be one of the following values: relative (default), external, internal, realpath, absolute, request, cluster, absolute

Tags
access

public

Return values
string

The desired link to the resource.

getObjectRecord()

Loads a object database record with a given id.

public static getObjectRecord(string $sClassName[, string $sId = null ]) : ObjectDatabaseRecord

If the class has not been loaded, the corresponding module is loaded first

Parameters
$sClassName : string

Name of the objec database record to be loaded

$sId : string = null

The optional id of the record which should be loaded

Tags
access

public

Return values
ObjectDatabaseRecord

The requested object, if available or null, if no record with this name has been found.

getOption()

Returns an Option from the administrations or custom settings

public static getOption(string $sOptionName[, string $sModuleName = 'custom' ][, mixed $mDefault = '' ]) : string
Parameters
$sOptionName : string

Name of the option

$sModuleName : string = 'custom'

Name of the module the option refers to, custom is default

$mDefault : mixed = ''

Default value to be used if the option is not available

Tags
access

public

Return values
string

the value of the option

getProcessID()

Returns the unique ID for the current process

public static getProcessID() : string
Tags
access

public

Return values
string

the ID of the current process

getProjectName()

Retrieves the current project name.

public static getProjectName() : string
Tags
access

public

Return values
string

the name of the currently authenticated project

getRecord()

Loads a record with a given id. If the class has not been loaded, the corresponding module is loaded first

public static getRecord(string $sClassName[, string|int $iId = '' ]) : Record
Parameters
$sClassName : string

Name of the record to be loaded

$iId : string|int = ''

The optional id of the record which should be loaded

Tags
access

public

Return values
Record

The requested object, if available or null, if no record with this name has been found.

getRequestValues()

Returns an array of request values found in the global $_GET array.

public static getRequestValues() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

the request values

getServerName()

Returns the server name.

public static getServerName() : string
Tags
access

public

deprecated

Deprecated since CS23.0, use CSServerUtils::getExternalServerName() instead.

Return values
string

the name of the server

getTable()

Loads a table for a given record.

public static getTable(string $sClassName[, mixed $sFilter = '' ][, string $sSortOrder = '' ]) : Table
Parameters
$sClassName : string

Name of the record to be loaded

$sFilter : mixed = ''

SQL Filter condition that can be used in the WHERE part or an array of IDs

$sSortOrder : string = ''

SQL sort order that can be used in the ORDER BY part

Tags
access

public

Return values
Table
  • the table of the requested object.

getTablePrefix()

Retrieves a table prefix used by the current project.

public static getTablePrefix([string $sProjectName = '' ]) : string
Parameters
$sProjectName : string = ''

Optional Project Name for which the table prefix should be retrieved.

Tags
access

public

Return values
string

the table prefix of the project as defined in the license settings or the install.php

getUrl()

generates an url with the specified params including a security hash to make sure the url is not manipulated

public static getUrl(string $path[, array<string|int, mixed> $dynamicParams = array() ][, array<string|int, mixed> $fixedParams = array() ]) : string
Parameters
$path : string

the path the url should point to

$dynamicParams : array<string|int, mixed> = array()

key/value pairs of parameter names and value types. This parameter values may be changed later on but must match the data type specified. For possible data types see @CSSecurityUtils INPUT_DATATYPE_XXX

$fixedParams : array<string|int, mixed> = array()

key/value pairs of parameter names and values. This parameter values must not be changed later on.

Tags
access

public

Return values
string

the generated url

getVersion()

Returns the build number of the CS API

public static getVersion() : string
Tags
access

public

deprecated

Deprecated since 24.0, use CSSystemUtils::getServiceVersion() instead

Return values
string

the build number of the CS API

htmlentities()

Entities encodes a string in the current charset. For details see for the build in PHP htmlentities method.

public static htmlentities(string $string[, int $quoteStyle = ENT_QUOTES ][, string $charset = 'UTF-8' ][, bool $doubleEncode = false ]) : string
Parameters
$string : string

the string to encode

$quoteStyle : int = ENT_QUOTES

the quoting style. One of the PHP ENT_QUOTES, ENT_COMPAT, ...

$charset : string = 'UTF-8'

optional charset. If not set the current charset is used.

$doubleEncode : bool = false

whether html entitites should be encoded another time

Tags
access

public

Return values
string

the string

includeFile()

Includes one file. The file is searched in the following directories: - [PROJECT]/$file - [admin.local]/$file - [admin]/$file - $file The first found file is included.

public static includeFile(string $file[, bool $once = true ]) : mixed
Parameters
$file : string

the path of a file which should be included

$once : bool = true

whether the file should be included only once

Tags
access

public

Return values
mixed

isAdmin()

Return whether the current call to this function is done within the administrative backend or from the published website

public static isAdmin() : bool
Tags
access

public

Return values
bool

loadAPI()

Loads the specified API

public static loadAPI(string $Api[, string $ns = 'CS' ][, bool $skipErrors = false ]) : string
Parameters
$Api : string

Name of the API to load, e.g. 'CSImage'

$ns : string = 'CS'

The namespace of the API (default CS)

$skipErrors : bool = false

Whether the error message that no API has been found should be skipped

Tags
access

public

Return values
string

the name of the found API

loadModule()

Loads a module

public static loadModule(string $module) : CSModule

All modules must be loaded explicitly by calls to this API function, e.g. with CS::loadModule('project'), CS::loadModule('pages') or CS::loadModule('user')

Parameters
$module : string

name of the module in lower case without the CSModule at the end

Tags
access

public

Return values
CSModule

the loaded module object

log()

Adds an entry in the CS system log table

public static log(string $title[, string $description = '' ][, string $module = 'Core' ][, int $type = CS_LOG_NOTE ][, bool $doFlush = false ][, string $sFile = '' ]) : void
Parameters
$title : string

subject of the event

$description : string = ''

optional description of the event

$module : string = 'Core'

optional module name the event refers to

$type : int = CS_LOG_NOTE

optional type of the event, possible values are CS_LOG_PROCESS, CS_LOG_NOTE, CS_LOG_WARNING, CS_LOG_ERROR, CS_LOG_TRIGGER, CS_LOG_MAIL

$doFlush : bool = false

whether the log should be directly (true) or automatically (false) flushed (written to the database).

$sFile : string = ''

optional file name of the event refers to

Tags
deprecated

Deprecated since 24.0, move to CSLog::logToFile() usage instead

access

public

Return values
void

logProcess()

Adds an entry in the CS system process log

public static logProcess(string $title[, string $module = 'Core' ]) : void
Parameters
$title : string

subject of the event

$module : string = 'Core'

optional module name the event refers to

Tags
deprecated

Deprecated since 24.0, move to CSLog::logToFile() usage instead

access

public

Return values
void

mail()

Sends a mail generated by an xml template file

public static mail(mixed $template, mixed $params) : mixed

The template is expected to be similar to the xml file admin/classes/utils/HtmlMailTemplateSample.xml. You may pass an array with parameters to replace occurrences of {param} by a value.

Parameters
$template : mixed
$params : mixed
Tags
access

public

Return values
mixed

query()

Sends an sql query to the database

public static query(string $query[, array<string|int, mixed> $data = array() ][, array<string|int, mixed> $types = array() ][, bool|true $clearCache = true ][, bool|true $showError = true ][, null $ctsWebsite = null ]) : mixed
Parameters
$query : string
$data : array<string|int, mixed> = array()
$types : array<string|int, mixed> = array()
$clearCache : bool|true = true
$showError : bool|true = true
$ctsWebsite : null = null
Tags
access

public

Return values
mixed

queryValue()

Sends an sql query to the database

public static queryValue(string $sSql[, string $sProject = null ][, array<string|int, mixed> $aUsedTables = array() ]) : mixed
Parameters
$sSql : string

The sql query respecting the complete table names including the table prefix

$sProject : string = null

The project to use for the database connection, the current project if null

$aUsedTables : array<string|int, mixed> = array()

The used tables for a more stable cache, if not provided a global cache key will be generated ending up more frequently cleaned.

Tags
access

public

Return values
mixed

variable, one dimensional array or two dimensional array, depending on the query

requireFile()

Includes one file.

public static requireFile(string $file[, bool $once = true ]) : mixed
Parameters
$file : string

the path of a file which should be included

$once : bool = true

whether the file should be included only once

Tags
access

public

Return values
mixed

runScheduledAutomations()

Starts the schedular to check whether automations should be done As this is done automatically since CS 4.3 this method call is internal

public static runScheduledAutomations() : mixed
Tags
access

public

Return values
mixed

scheduleProcess()

Schedules method calls in another process which is called after the original process has been finished.

public static scheduleProcess(string $evalCode[, array<string|int, mixed> $parameters = array() ][, bool $executeInNewThread = true ]) : mixed

As passing parameters to the process is not so easy there is the possibility to pass required parameters using the second parameter. The serialization is done internally and the parameters are available in the evalCode, e.g. CS::scheduleProcess('CS::log("Scheduled process from user ".$paramA);', array('paramA', CSUser::getName()) would log the current userName in the new process. As php serialization is used it is recommended to use just simple attributes and no objects, as their classes may not be available in the process.

Parameters
$evalCode : string

the code which should be evaluated in the new process, where it must contain the complete script inclusive required includes

$parameters : array<string|int, mixed> = array()

optional parameters which are available in the request.

$executeInNewThread : bool = true

optional parameters whether the process should be scheduled in a new thread.

Tags
access

public

Return values
mixed

setLocaleCharset()

Sets the output charset for all translations

public static setLocaleCharset([mixed $charset = 'UTF-8' ]) : void
Parameters
$charset : mixed = 'UTF-8'
Tags
access

public

Return values
void

setLocaleLanguage()

Sets the default locale language for all translations

public static setLocaleLanguage([mixed $language = '' ]) : void
Parameters
$language : mixed = ''
Tags
access

public

Return values
void

setOption()

Sets an Option at the administration or custom settings

public static setOption(string $mOptionValue, string $sOptionName[, string $sModule = 'custom' ][, bool $bPermanent = false ]) : mixed
Parameters
$mOptionValue : string

New value of the option

$sOptionName : string

Name of the option

$sModule : string = 'custom'

Name of the module the option refers to, custom is default

$bPermanent : bool = false

Whether to modify the option permanently in the database, false is default

Tags
access

public

Return values
mixed

setProjectName()

Sets the current project name and reinitialize the database connection with that project

public static setProjectName(string $sProjectName) : mixed
Parameters
$sProjectName : string
Tags
access

public

Return values
mixed

throwError()

Throws an Exception

public static throwError(mixed $message, int $code[, bool $forceAlert = false ]) : void
Parameters
$message : mixed

the error message as string or a CSException object to throw

$code : int

the optional exception code, if a string message is passed

$forceAlert : bool = false

whether a alert should be displayed, if no error handler has caught the exception. This alert is even displayed if normally no error messages are displayed. If deactivated a standard error window will be shown, if errors are displayed.

Tags
throws
CSException
access

public

Return values
void

throwWarning()

Throws an Exception with type E_WARNING

public static throwWarning(mixed $message, int $code[, bool $forceAlert = false ]) : void
Parameters
$message : mixed

the warning message as string or a CSException object to throw

$code : int

the optional exception code, if a string message is passed

$forceAlert : bool = false

whether a alert should be displayed, if no error handler has caught the exception. This alert is even displayed if normally no error messages are displayed. If deactivated a standard error window will be shown, if errors are displayed.

Tags
throws
CSException
access

public

Return values
void

translate()

Translates a word with the CONTENTSERV Dictionary It is possible to create dynamic translations. Therefore an array is allowed as $word, where the first value is the word to translate and the others are values which are automatically replaced.

public static translate(mixed $word[, string $module = '' ][, string $language = '' ][, array<string|int, mixed> $alternatives = array() ][, bool $ignoreInheritance = false ]) : string

Those values are replaced in the translation for the expressions XXX, YYY, ZZZ, AAA, BBB, CCC, DDD, EEE .

Parameters
$word : mixed
$module : string = ''

optional module to use for the translation

$language : string = ''

optional language to use for the translation

$alternatives : array<string|int, mixed> = array()

optional alternative words which are tried, if the first word failed. If no alternative matches, the key of the last alternative is returned.

$ignoreInheritance : bool = false

optional ignore flag to ignore the language inheritance

Tags
access

public

Return values
string

the translated word


        

Search results