* Somehow this scenario is rarely going to happen. Yet, it is an inconsistency and I see now practical way to handle it - other than simply ignoring maintaining the index for workspace records. Or we can say that the index is precise for all Live elements while glitches might happen in an offline workspace?
* Anyway, I just wanted to document this finding - I don't think we can find a solution for it. And its very TemplaVoila specific.
*
- * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
* @package TYPO3
* @subpackage t3lib
*/
var $words_strings = array();
var $words = array();
- var $hashVersion = 1; // Number which we can increase if a change in the code means we will have to force a re-generation of the index.
-
+ // Number which we can increase if a change in the code means we will have to force a re-generation of the index.
+ var $hashVersion = 1;
/**
* Call this function to update the sys_refindex table for a record (even one just deleted)
* NOTICE: Currently, references updated for a deleted-flagged record will not include those from within flexform fields in some cases where the data structure is defined by another record since the resolving process ignores deleted records! This will also result in bad cleaning up in tcemain I think... Anyway, thats the story of flexforms; as long as the DS can change, lots of references can get lost in no time.
*
- * @param string Table name
- * @param integer UID of record
- * @param boolean If set, nothing will be written to the index but the result value will still report statistics on what is added, deleted and kept. Can be used for mere analysis.
- * @return array Array with statistics about how many index records were added, deleted and not altered plus the complete reference set for the record.
+ * @param string $table Table name
+ * @param integer $uid UID of record
+ * @param boolean $testOnly If set, nothing will be written to the index but the result value will still report statistics on what is added, deleted and kept. Can be used for mere analysis.
+ * @return array Array with statistics about how many index records were added, deleted and not altered plus the complete reference set for the record.
*/
function updateRefIndexTable($table, $uid, $testOnly = FALSE) {
* Returns array of arrays with an index of all references found in record from table/uid
* If the result is used to update the sys_refindex table then ->WSOL must NOT be TRUE (no workspace overlay anywhere!)
*
- * @param string Table name from $GLOBALS['TCA']
- * @param integer Record UID
- * @return array Index Rows
+ * @param string $table Table name from $GLOBALS['TCA']
+ * @param integer $uid Record UID
+ * @return array Index Rows
*/
function generateRefIndexData($table, $uid) {
if (isset($GLOBALS['TCA'][$table])) {
* Create array with field/value pairs ready to insert in database.
* The "hash" field is a fingerprint value across this table.
*
- * @param string Tablename of source record (where reference is located)
- * @param integer UID of source record (where reference is located)
- * @param string Fieldname of source record (where reference is located)
- * @param string Pointer to location inside flexform structure where reference is located in [field]
- * @param integer Whether record is deleted-flagged or not
- * @param string For database references; the tablename the reference points to. Special keyword "_FILE" indicates that "ref_string" is a file reference either absolute or relative to PATH_site. Special keyword "_STRING" indicates some special usage (typ. softreference) where "ref_string" is used for the value.
- * @param integer For database references; The UID of the record (zero "ref_table" is "_FILE" or "_STRING")
- * @param string For "_FILE" or "_STRING" references: The filepath (relative to PATH_site or absolute) or other string.
- * @param integer The sorting order of references if many (the "group" or "select" TCA types). -1 if no sorting order is specified.
- * @param string If the reference is a soft reference, this is the soft reference parser key. Otherwise empty.
- * @param string Soft reference ID for key. Might be useful for replace operations.
- * @return array Array record to insert into table.
+ * @param string $table Tablename of source record (where reference is located)
+ * @param integer $uid UID of source record (where reference is located)
+ * @param string $field Fieldname of source record (where reference is located)
+ * @param string $flexpointer Pointer to location inside flexform structure where reference is located in [field]
+ * @param integer $deleted Whether record is deleted-flagged or not
+ * @param string $ref_table For database references; the tablename the reference points to. Special keyword "_FILE" indicates that "ref_string" is a file reference either absolute or relative to PATH_site. Special keyword "_STRING" indicates some special usage (typ. softreference) where "ref_string" is used for the value.
+ * @param integer $ref_uid For database references; The UID of the record (zero "ref_table" is "_FILE" or "_STRING")
+ * @param string $ref_string For "_FILE" or "_STRING" references: The filepath (relative to PATH_site or absolute) or other string.
+ * @param integer $sort The sorting order of references if many (the "group" or "select" TCA types). -1 if no sorting order is specified.
+ * @param string $softref_key If the reference is a soft reference, this is the soft reference parser key. Otherwise empty.
+ * @param string $softref_id Soft reference ID for key. Might be useful for replace operations.
+ * @return array Array record to insert into table.
*/
function createEntryData($table, $uid, $field, $flexpointer, $deleted, $ref_table, $ref_uid, $ref_string = '', $sort = -1, $softref_key = '', $softref_id = '') {
return array(
/**
* Enter database references to ->relations array
*
- * @param string [See createEntryData, arg 1]
- * @param integer [See createEntryData, arg 2]
- * @param string [See createEntryData, arg 3]
- * @param string [See createEntryData, arg 4]
- * @param string [See createEntryData, arg 5]
- * @param array Data array with databaes relations (table/id)
- * @return void
+ * @param string $table Tablename of source record (where reference is located)
+ * @param integer $uid UID of source record (where reference is located)
+ * @param string $fieldname Fieldname of source record (where reference is located)
+ * @param string $flexpointer Pointer to location inside flexform structure where reference is located in [field]
+ * @param integer $deleted Whether record is deleted-flagged or not
+ * @param array $items Data array with databaes relations (table/id)
+ * @return void
*/
function createEntryData_dbRels($table, $uid, $fieldname, $flexpointer, $deleted, $items) {
foreach ($items as $sort => $i) {
/**
* Enter file references to ->relations array
*
- * @param string [See createEntryData, arg 1]
- * @param integer [See createEntryData, arg 2]
- * @param string [See createEntryData, arg 3]
- * @param string [See createEntryData, arg 4]
- * @param string [See createEntryData, arg 5]
- * @param array Data array with file relations
+ * @param string $table Tablename of source record (where reference is located)
+ * @param integer $uid UID of source record (where reference is located)
+ * @param string $fieldname Fieldname of source record (where reference is located)
+ * @param string $flexpointer Pointer to location inside flexform structure where reference is located in [field]
+ * @param integer $deleted Whether record is deleted-flagged or not
+ * @param array $items Data array with file relations
* @return void
*/
function createEntryData_fileRels($table, $uid, $fieldname, $flexpointer, $deleted, $items) {
/**
* Enter softref references to ->relations array
*
- * @param string [See createEntryData, arg 1]
- * @param integer [See createEntryData, arg 2]
- * @param string [See createEntryData, arg 3]
- * @param string [See createEntryData, arg 4]
- * @param string [See createEntryData, arg 5]
- * @param array Data array with soft reference keys
- * @return void
+ * @param string $table Tablename of source record (where reference is located)
+ * @param integer $uid UID of source record (where reference is located)
+ * @param string $fieldname Fieldname of source record (where reference is located)
+ * @param string $flexpointer Pointer to location inside flexform struc
+ * @param array $keys Data array with soft reference keys
+ * @return void
*/
function createEntryData_softreferences($table, $uid, $fieldname, $flexpointer, $deleted, $keys) {
if (is_array($keys)) {
}
}
-
/*******************************
*
* Get relations from table row
* Traverses all fields in input row which are configured in TCA/columns
* It looks for hard relations to files and records in the TCA types "select" and "group"
*
- * @param string Table name
- * @param array Row from table
- * @param string Specific field to fetch for.
- * @return array Array with information about relations
+ * @param string $table Table name
+ * @param array $row Row from table
+ * @param string $onlyField Specific field to fetch for.
+ * @return array Array with information about relations
* @see export_addRecord()
*/
function getRelations($table, $row, $onlyField = '') {
/**
* Callback function for traversing the FlexForm structure in relation to finding file and DB references!
*
- * @param array Data structure for the current value
- * @param mixed Current value
- * @param array Additional configuration used in calling function
- * @param string Path of value in DS structure
- * @param object Object reference to caller
- * @return void
+ * @param array $dsArr Data structure for the current value
+ * @param mixed $dataValue Current value
+ * @param array $PA Additional configuration used in calling function
+ * @param string $structurePath Path of value in DS structure
+ * @param object $pObj Object reference to caller
+ * @return void
* @see t3lib_TCEmain::checkValue_flex_procInData_travDS()
*/
function getRelations_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, $pObj) {
- $structurePath = substr($structurePath, 5) . '/'; // removing "data/" in the beginning of path (which points to location in data array)
+ // Removing "data/" in the beginning of path (which points to location in data array)
+ $structurePath = substr($structurePath, 5) . '/';
$dsConf = $dsArr['TCEforms']['config'];
/**
* Check field configuration if it is a file relation field and extract file relations if any
*
- * @param string Field value
- * @param array Field configuration array of type "TCA/columns"
- * @param integer Field uid
- * @return array If field type is OK it will return an array with the files inside. Else FALSE
+ * @param string $value Field value
+ * @param array $conf Field configuration array of type "TCA/columns"
+ * @param integer $uid Field uid
+ * @retur array If field type is OK it will return an array with the files inside. Else FALSE
*/
function getRelations_procFiles($value, $conf, $uid) {
if ($conf['type'] == 'group' && ($conf['internal_type'] == 'file' || $conf['internal_type'] == 'file_reference')) {
}
}
-
/*******************************
*
* Setting values
* Notice; If you want to remove multiple references from the same field, you MUST start with the one having the highest sorting number. If you don't the removal of a reference with a lower number will recreate an index in which the remaining references in that field has new hash-keys due to new sorting numbers - and you will get errors for the remaining operations which cannot find the hash you feed it!
* To ensure proper working only admin-BE_USERS in live workspace should use this function
*
- * @param string 32-byte hash string identifying the record from sys_refindex which you wish to change the value for
- * @param mixed Value you wish to set for reference. If NULL, the reference is removed (unless a soft-reference in which case it can only be set to a blank string). If you wish to set a database reference, use the format "[table]:[uid]". Any other case, the input value is set as-is
- * @param boolean Return $dataArray only, do not submit it to database.
- * @param boolean If set, it will bypass check for workspace-zero and admin user
- * @return string If a return string, that carries an error message, otherwise FALSE (=OK) (except if $returnDataArray is set!)
+ * @param string $hash 32-byte hash string identifying the record from sys_refindex which you wish to change the value for
+ * @param mixed $newValue Value you wish to set for reference. If NULL, the reference is removed (unless a soft-reference in which case it can only be set to a blank string). If you wish to set a database reference, use the format "[table]:[uid]". Any other case, the input value is set as-is
+ * @param boolean $returnDataArray Return $dataArray only, do not submit it to database.
+ * @param boolean $bypassWorkspaceAdminCheck If set, it will bypass check for workspace-zero and admin user
+ * @return string If a return string, that carries an error message, otherwise FALSE (=OK) (except if $returnDataArray is set!)
*/
function setReferenceValue($hash, $newValue, $returnDataArray = FALSE, $bypassWorkspaceAdminCheck = FALSE) {
$tce->dontProcessTransformations = TRUE;
$tce->bypassWorkspaceRestrictions = TRUE;
$tce->bypassFileHandling = TRUE;
- $tce->bypassAccessCheckForRecords = TRUE; // Otherwise this cannot update things in deleted records...
+ // Otherwise this cannot update things in deleted records...
+ $tce->bypassAccessCheckForRecords = TRUE;
- $tce->start($dataArray, array()); // check has been done previously that there is a backend user which is Admin and also in live workspace
+ // Check has been done previously that there is a backend user which is Admin and also in live workspace
+ $tce->start($dataArray, array());
$tce->process_datamap();
// Return errors if any:
/**
* Setting a value for a reference for a DB field:
*
- * @param array sys_refindex record
- * @param array Array of references from that field
- * @param string Value to substitute current value with (or NULL to unset it)
- * @param array data array in which the new value is set (passed by reference)
- * @param string Flexform pointer, if in a flex form field.
- * @return string Error message if any, otherwise FALSE = OK
+ * @param array $refRec sys_refindex record
+ * @param array $itemArray Array of references from that field
+ * @param string $newValue Value to substitute current value with (or NULL to unset it)
+ * @param array $dataArray Data array in which the new value is set (passed by reference)
+ * @param string $flexpointer Flexform pointer, if in a flex form field.
+ * @return string Error message if any, otherwise FALSE = OK
*/
function setReferenceValue_dbRels($refRec, $itemArray, $newValue, &$dataArray, $flexpointer = '') {
if (!strcmp($itemArray[$refRec['sorting']]['id'], $refRec['ref_uid']) && !strcmp($itemArray[$refRec['sorting']]['table'], $refRec['ref_table'])) {
// Setting or removing value:
- if ($newValue === NULL) { // Remove value:
+ // Remove value:
+ if ($newValue === NULL) {
unset($itemArray[$refRec['sorting']]);
} else {
list($itemArray[$refRec['sorting']]['table'], $itemArray[$refRec['sorting']]['id']) = explode(':', $newValue);
/**
* Setting a value for a reference for a FILE field:
*
- * @param array sys_refindex record
- * @param array Array of references from that field
- * @param string Value to substitute current value with (or NULL to unset it)
- * @param array data array in which the new value is set (passed by reference)
- * @param string Flexform pointer, if in a flex form field.
- * @return string Error message if any, otherwise FALSE = OK
+ * @param array $refRec sys_refindex record
+ * @param array $itemArray Array of references from that field
+ * @param string $newValue Value to substitute current value with (or NULL to unset it)
+ * @param array $dataArray Data array in which the new value is set (passed by reference)
+ * @param string $flexpointer Flexform pointer, if in a flex form field.
+ * @return string Error message if any, otherwise FALSE = OK
*/
function setReferenceValue_fileRels($refRec, $itemArray, $newValue, &$dataArray, $flexpointer = '') {
if (!strcmp(substr($itemArray[$refRec['sorting']]['ID_absFile'], strlen(PATH_site)), $refRec['ref_string']) && !strcmp('_FILE', $refRec['ref_table'])) {
// Setting or removing value:
- if ($newValue === NULL) { // Remove value:
+ // Remove value:
+ if ($newValue === NULL) {
unset($itemArray[$refRec['sorting']]);
} else {
$itemArray[$refRec['sorting']]['filename'] = $newValue;
/**
* Setting a value for a soft reference token
*
- * @param array sys_refindex record
- * @param array Array of soft reference occurencies
- * @param string Value to substitute current value with
- * @param array data array in which the new value is set (passed by reference)
- * @param string Flexform pointer, if in a flex form field.
- * @return string Error message if any, otherwise FALSE = OK
+ * @param array $refRec sys_refindex record
+ * @param array $softref Array of soft reference occurencies
+ * @param string $newValue Value to substitute current value with
+ * @param array $dataArray Data array in which the new value is set (passed by reference)
+ * @param string $flexpointer Flexform pointer, if in a flex form field.
+ * @return string Error message if any, otherwise FALSE = OK
*/
function setReferenceValue_softreferences($refRec, $softref, $newValue, &$dataArray, $flexpointer = '') {
if (is_array($softref['keys'][$refRec['softref_key']][$refRec['softref_id']])) {
}
}
-
/*******************************
*
* Helper functions
/**
* Returns TRUE if the TCA/columns field type is a DB reference field
*
- * @param array config array for TCA/columns field
- * @return boolean TRUE if DB reference field (group/db or select with foreign-table)
+ * @param array $conf Config array for TCA/columns field
+ * @return boolean TRUE if DB reference field (group/db or select with foreign-table)
*/
function isReferenceField($conf) {
return ($conf['type'] == 'group' && $conf['internal_type'] == 'db') || (($conf['type'] == 'select' || $conf['type'] == 'inline') && $conf['foreign_table'] && $conf['foreign_table'] !== 'sys_file_reference');
/**
* Returns destination path to an upload folder given by $folder
*
- * @param string Folder relative to PATH_site
- * @return string Input folder prefixed with PATH_site. No checking for existence is done. Output must be a folder without trailing slash.
+ * @param string $folder Folder relative to PATH_site
+ * @return string Input folder prefixed with PATH_site. No checking for existence is done. Output must be a folder without trailing slash.
*/
function destPathFromUploadFolder($folder) {
if (!$folder) {
/**
* Sets error message in the internal error log
*
- * @param string Error message
- * @return void
+ * @param string $msg Error message
+ * @return void
*/
function error($msg) {
$this->errorLog[] = $msg;
/**
* Updating Index (External API)
*
- * @param boolean If set, only a test
- * @param boolean If set, output CLI status
- * @return array Header and body status content
+ * @param boolean $testOnly If set, only a test
+ * @param boolean $cli_echo If set, output CLI status
+ * @return array Header and body status content
*/
function updateIndex($testOnly, $cli_echo = FALSE) {
$errors = array();
*
* Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
*
- * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
*/
-
/**
* EXAMPLE PROTOTYPE
*
* Parent class for 'ScriptClasses' in backend modules.
* See example comment above.
*
- * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
* @package TYPO3
* @subpackage t3lib
* @see t3lib_extobjbase
*/
var $perms_clause;
-
/**
* The module menu items array. Each key represents a key for which values can range between the items in the array of that key.
* @see init()
*/
var $extObj;
-
/**
* Initializes the backend module by setting internal variables, initializing the menu.
*
- * @return void
+ * @return void
* @see menuConfig()
*/
function init() {
- // name might be set from outside
+ // Name might be set from outside
if (!$this->MCONF['name']) {
$this->MCONF = $GLOBALS['MCONF'];
}
* Then MOD_SETTINGS array is cleaned up (see t3lib_BEfunc::getModuleData()) so it contains only valid values. It's also updated with any SET[] values submitted.
* Also loads the modTSconfig internal variable.
*
- * @return void
+ * @return void
* @see init(), $MOD_MENU, $MOD_SETTINGS, t3lib_BEfunc::getModuleData(), mergeExternalItems()
*/
function menuConfig() {
- // page/be_user TSconfig settings and blinding of menu-items
+ // Page/be_user TSconfig settings and blinding of menu-items
$this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']);
$this->MOD_MENU['function'] = $this->mergeExternalItems($this->MCONF['name'], 'function', $this->MOD_MENU['function']);
$this->MOD_MENU['function'] = t3lib_BEfunc::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function');
- #debug($this->MOD_MENU['function'],$this->MCONF['name']);
- #debug($this->modTSconfig['properties']);
-
$this->MOD_SETTINGS = t3lib_BEfunc::getModuleData(
$this->MOD_MENU,
t3lib_div::_GP('SET'),
/**
* Merges menu items from global array $TBE_MODULES_EXT
*
- * @param string Module name for which to find value
- * @param string Menu key, eg. 'function' for the function menu.
- * @param array The part of a MOD_MENU array to work on.
- * @return array Modified array part.
+ * @param string $modName Module name for which to find value
+ * @param string $menuKey Menu key, eg. 'function' for the function menu.
+ * @param array $menuArr The part of a MOD_MENU array to work on.
+ * @return array Modified array part.
* @access private
* @see t3lib_extMgm::insertModuleFunction(), menuConfig()
*/
* Loads $this->extClassConf with the configuration for the CURRENT function of the menu.
* If for this array the key 'path' is set then that is expected to be an absolute path to a file which should be included - so it is set in the internal array $this->include_once
*
- * @param string The key to MOD_MENU for which to fetch configuration. 'function' is default since it is first and foremost used to get information per "extension object" (I think that is what its called)
- * @param string The value-key to fetch from the config array. If NULL (default) MOD_SETTINGS[$MM_key] will be used. This is usefull if you want to force another function than the one defined in MOD_SETTINGS[function]. Call this in init() function of your Script Class: handleExternalFunctionValue('function', $forcedSubModKey)
- * @return void
+ * @param string $MM_key The key to MOD_MENU for which to fetch configuration. 'function' is default since it is first and foremost used to get information per "extension object" (I think that is what its called)
+ * @param string $MS_value The value-key to fetch from the config array. If NULL (default) MOD_SETTINGS[$MM_key] will be used. This is usefull if you want to force another function than the one defined in MOD_SETTINGS[function]. Call this in init() function of your Script Class: handleExternalFunctionValue('function', $forcedSubModKey)
+ * @return void
* @see getExternalItemConfig(), $include_once, init()
*/
function handleExternalFunctionValue($MM_key = 'function', $MS_value = NULL) {
* Returns configuration values from the global variable $TBE_MODULES_EXT for the module given.
* For example if the module is named "web_info" and the "function" key ($menuKey) of MOD_SETTINGS is "stat" ($value) then you will have the values of $TBE_MODULES_EXT['webinfo']['MOD_MENU']['function']['stat'] returned.
*
- * @param string Module name
- * @param string Menu key, eg. "function" for the function menu. See $this->MOD_MENU
- * @param string Optionally the value-key to fetch from the array that would otherwise have been returned if this value was not set. Look source...
- * @return mixed The value from the TBE_MODULES_EXT array.
+ * @param string $modName Module name
+ * @param string $menuKey Menu key, eg. "function" for the function menu. See $this->MOD_MENU
+ * @param string $value Optionally the value-key to fetch from the array that would otherwise have been returned if this value was not set. Look source...
+ * @return mixed The value from the TBE_MODULES_EXT array.
* @see handleExternalFunctionValue()
*/
function getExternalItemConfig($modName, $menuKey, $value = '') {
* (Should be) called from global scope right after inclusion of files from the ->include_once array.
* If an instance is created it is initiated with $this passed as value and $this->extClassConf as second argument. Further the $this->MOD_SETTING is cleaned up again after calling the init function.
*
- * @return void
+ * @return void
* @see handleExternalFunctionValue(), t3lib_extMgm::insertModuleFunction(), $extObj
*/
function checkExtObj() {
/**
* Calls the checkExtObj function in sub module if present.
*
- * @return void
+ * @return void
*/
function checkSubExtObj() {
if (is_object($this->extObj)) {
* example call in the header function:
* $this->pObj->doc->JScode = $this->pObj->doc->wrapScriptTags(' ...
*
- * @return void
+ * @return void
*/
function extObjHeader() {
if (is_callable(array($this->extObj, 'head'))) {
/**
* Calls the 'main' function inside the "Function menu module" if present
*
- * @return void
+ * @return void
*/
function extObjContent() {
$this->extObj->pObj = $this;
}
}
-?>
\ No newline at end of file
+?>
* which are default for most TYPO3 installations. Soft References can also be userdefined.
* The Soft Reference parsers are used by the system to find these references and process them accordingly in import/export actions and copy operations.
*
- * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
*/
-
/**
* Example of usage
* // Soft References:
* - 'email' : Email highlight
* - 'url' : URL highlights (with a scheme)
*
- * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
* @package TYPO3
* @subpackage t3lib
*/
class t3lib_softrefproc {
- // external configuration
+ // External configuration
var $fileAdminDir = 'fileadmin';
-
// Internal:
var $tokenID_basePrefix = '';
/**
* Main function through which all processing happens
*
- * @param string Database table name
- * @param string Field name for which processing occurs
- * @param integer UID of the record
- * @param string The content/value of the field
- * @param string The softlink parser key. This is only interesting if more than one parser is grouped in the same class. That is the case with this parser.
- * @param array Parameters of the softlink parser. Basically this is the content inside optional []-brackets after the softref keys. Parameters are exploded by ";"
- * @param string If running from inside a FlexForm structure, this is the path of the tag.
- * @return array Result array on positive matches, see description above. Otherwise FALSE
+ * @param string $table Database table name
+ * @param string $field Field name for which processing occurs
+ * @param integer $uid UID of the record
+ * @param string $content The content/value of the field
+ * @param string $spKey The softlink parser key. This is only interesting if more than one parser is grouped in the same class. That is the case with this parser.
+ * @param array $spParams Parameters of the softlink parser. Basically this is the content inside optional []-brackets after the softref keys. Parameters are exploded by ";"
+ * @param string $structurePath If running from inside a FlexForm structure, this is the path of the tag.
+ * @return array Result array on positive matches, see description above. Otherwise FALSE
*/
function findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath = '') {
* Will only return files in fileadmin/ and files in uploads/ folders which are prefixed with "RTEmagic[C|P]_" for substitution
* Any "clear.gif" images are ignored.
*
- * @param string The input content to analyse
- * @param array Parameters set for the softref parser key in TCA/columns
- * @return array Result array on positive matches, see description above. Otherwise FALSE
+ * @param string $content The input content to analyse
+ * @param array $spParams Parameters set for the softref parser key in TCA/columns
+ * @return array Result array on positive matches, see description above. Otherwise FALSE
*/
function findRef_images($content, $spParams) {
// If the image seems to be from fileadmin/ folder or an RTE image, then proceed to set up substitution token:
if (t3lib_div::isFirstPartOfStr($srcRef, $this->fileAdminDir . '/') || (t3lib_div::isFirstPartOfStr($srcRef, 'uploads/') && preg_match('/^RTEmagicC_/', basename($srcRef)))) {
// Token and substitute value:
- if (strstr($splitContent[$k], $attribs[0]['src'])) { // Make sure the value we work on is found and will get substituted in the content (Very important that the src-value is not DeHSC'ed)
- $splitContent[$k] = str_replace($attribs[0]['src'], '{softref:' . $tokenID . '}', $splitContent[$k]); // Substitute value with token (this is not be an exact method if the value is in there twice, but we assume it will not)
+ // Make sure the value we work on is found and will get substituted in the content (Very important that the src-value is not DeHSC'ed)
+ if (strstr($splitContent[$k], $attribs[0]['src'])) {
+ // Substitute value with token (this is not be an exact method if the value is in there twice, but we assume it will not)
+ $splitContent[$k] = str_replace($attribs[0]['src'], '{softref:' . $tokenID . '}', $splitContent[$k]);
$elements[$k]['subst'] = array(
'type' => 'file',
'relFileName' => $srcRef,
'tokenID' => $tokenID,
'tokenValue' => $attribs[0]['src'],
);
- if (!@is_file($absPath)) { // Finally, notice if the file does not exist.
+ // Finally, notice if the file does not exist.
+ if (!@is_file($absPath)) {
$elements[$k]['error'] = 'File does not exist!';
}
} else {
* TypoLink value processing.
* Will process input value as a TypoLink value.
*
- * @param string The input content to analyse
- * @param array Parameters set for the softref parser key in TCA/columns. value "linkList" will split the string by comma before processing.
- * @return array Result array on positive matches, see description above. Otherwise FALSE
+ * @param string $content The input content to analyse
+ * @param array $spParams Parameters set for the softref parser key in TCA/columns. value "linkList" will split the string by comma before processing.
+ * @return array Result array on positive matches, see description above. Otherwise FALSE
* @see tslib_content::typolink(), getTypoLinkParts()
*/
function findRef_typolink($content, $spParams) {
// First, split the input string by a comma if the "linkList" parameter is set.
// An example: the link field for images in content elements of type "textpic" or "image". This field CAN be configured to define a link per image, separated by comma.
if (is_array($spParams) && in_array('linkList', $spParams)) {
- $linkElement = explode(',', $content); // Preserving whitespace on purpose.
+ // Preserving whitespace on purpose.
+ $linkElement = explode(',', $content);
} else {
- $linkElement = array($content); // If only one element, just set in this array to make it easy below.
+ // If only one element, just set in this array to make it easy below.
+ $linkElement = array($content);
}
// Traverse the links now:
* TypoLink tag processing.
* Will search for <link ...> tags in the content string and process any found.
*
- * @param string The input content to analyse
- * @param array Parameters set for the softref parser key in TCA/columns
- * @return array Result array on positive matches, see description above. Otherwise FALSE
+ * @param string $content The input content to analyse
+ * @param array $spParams Parameters set for the softref parser key in TCA/columns
+ * @return array Result array on positive matches, see description above. Otherwise FALSE
* @see tslib_content::typolink(), getTypoLinkParts()
*/
function findRef_typolink_tag($content, $spParams) {
* Processing the content expected from a TypoScript template
* This content includes references to files in fileadmin/ folders and file references in HTML tags like <img src="">, <a href=""> and <form action="">
*
- * @param string The input content to analyse
- * @param array Parameters set for the softref parser key in TCA/columns
- * @return array Result array on positive matches, see description above. Otherwise FALSE
+ * @param string $content The input content to analyse
+ * @param array $spParams Parameters set for the softref parser key in TCA/columns
+ * @return array Result array on positive matches, see description above. Otherwise FALSE
*/
function findRef_TStemplate($content, $spParams) {
$elements = array();
if (t3lib_div::isFirstPartOfStr($srcRef, $this->fileAdminDir . '/') && !$pI['query'] && $absPath) {
// Token and substitute value:
- if (strstr($splitContent[$k], $attribs[0][$attributeName])) { // Very important that the src-value is not DeHSC'ed
+ // Very important that the src-value is not DeHSC'ed
+ if (strstr($splitContent[$k], $attribs[0][$attributeName])) {
$splitContent[$k] = str_replace($attribs[0][$attributeName], '{softref:' . $tokenID . '}', $splitContent[$k]);
$elements[$k]['subst'] = array(
'type' => 'file',
* Processes possible references inside of Page and User TSconfig fields.
* Currently this only includes file references to fileadmin/ but in fact there are currently no properties that supports such references.
*
- * @param string The input content to analyse
- * @param array Parameters set for the softref parser key in TCA/columns
- * @return array Result array on positive matches, see description above. Otherwise FALSE
+ * @param string $content The input content to analyse
+ * @param array $spParams Parameters set for the softref parser key in TCA/columns
+ * @return array Result array on positive matches, see description above. Otherwise FALSE
*/
function findRef_TSconfig($content, $spParams) {
$elements = array();
/**
* Finding email addresses in content and making them substitutable.
*
- * @param string The input content to analyse
- * @param array Parameters set for the softref parser key in TCA/columns
- * @return array Result array on positive matches, see description above. Otherwise FALSE
+ * @param string $content The input content to analyse
+ * @param array $spParams Parameters set for the softref parser key in TCA/columns
+ * @return array Result array on positive matches, see description above. Otherwise FALSE
*/
function findRef_email($content, $spParams) {
$resultArray = array();
- // email:
+ // Email:
$parts = preg_split("/([^[:alnum:]]+)([A-Za-z0-9\._-]+[@][A-Za-z0-9\._-]+[\.].[A-Za-z0-9]+)/", ' ' . $content . ' ', 10000, PREG_SPLIT_DELIM_CAPTURE);
foreach ($parts as $idx => $value) {
if ($idx % 3 == 2) {
/**
* Finding URLs in content
*
- * @param string The input content to analyse
- * @param array Parameters set for the softref parser key in TCA/columns
- * @return array Result array on positive matches, see description above. Otherwise FALSE
+ * @param string $content The input content to analyse
+ * @param array $spParams Parameters set for the softref parser key in TCA/columns
+ * @return array Result array on positive matches, see description above. Otherwise FALSE
*/
function findRef_url($content, $spParams) {
$resultArray = array();
/**
* Finding reference to files from extensions in content, but only to notify about their existence. No substitution
*
- * @param string The input content to analyse
- * @param array Parameters set for the softref parser key in TCA/columns
- * @return array Result array on positive matches, see description above. Otherwise FALSE
+ * @param string $content The input content to analyse
+ * @param array $spParams Parameters set for the softref parser key in TCA/columns
+ * @return array Result array on positive matches, see description above. Otherwise FALSE
*/
function findRef_extension_fileref($content, $spParams) {
$resultArray = array();
}
}
-
/*************************
*
* Helper functions
* Searches the content for a reference to a file in "fileadmin/".
* When a match is found it will get substituted with a token.
*
- * @param string Input content to analyse
- * @param array Element array to be modified with new entries. Passed by reference.
- * @return string Output content, possibly with tokens inserted.
+ * @param string $content Input content to analyse
+ * @param array $elements Element array to be modified with new entries. Passed by reference.
+ * @return string Output content, possibly with tokens inserted.
*/
function fileadminReferences($content, &$elements) {
* The syntax of the [typolink] part is: [typolink] = [page id or alias][,[type value]][#[anchor, if integer = tt_content uid]]
* The extraction is based on how tslib_content::typolink() behaves.
*
- * @param string TypoLink value.
- * @return array Array with the properties of the input link specified. The key "LINK_TYPE" will reveal the type. If that is blank it could not be determined.
+ * @param string $typolinkValue TypoLink value.
+ * @return array Array with the properties of the input link specified. The key "LINK_TYPE" will reveal the type. If that is blank it could not be determined.
* @see tslib_content::typolink(), setTypoLinkPartsElement()
*/
function getTypoLinkParts($typolinkValue) {
if (trim($rootFileDat) && !$containsSlash && (@is_file(PATH_site . $rootFileDat) || t3lib_div::inList('php,html,htm', strtolower($rFD_fI['extension'])))) {
$isLocalFile = 1;
} elseif ($containsSlash) {
- $isLocalFile = 2; // Adding this so realurl directories are linked right (non-existing).
+ // Adding this so realurl directories are linked right (non-existing).
+ $isLocalFile = 2;
}
- if ($pU['scheme'] || ($isLocalFile != 1 && $urlChar && (!$containsSlash || $urlChar < $fileChar))) { // url (external): If doubleSlash or if a '.' comes before a '/'.
+ // Url (external): If doubleSlash or if a '.' comes before a '/'.
+ if ($pU['scheme'] || ($isLocalFile != 1 && $urlChar && (!$containsSlash || $urlChar < $fileChar))) {
$finalTagParts['LINK_TYPE'] = 'url';
$finalTagParts['url'] = $link_param;
} elseif ($containsSlash || $isLocalFile) { // file (internal)
/**
* Recompile a TypoLink value from the array of properties made with getTypoLinkParts() into an elements array
*
- * @param array TypoLink properties
- * @param array Array of elements to be modified with substitution / information entries.
- * @param string The content to process.
- * @param integer Index value of the found element - user to make unique but stable tokenID
- * @return string The input content, possibly containing tokens now according to the added substitution entries in $elements
+ * @param array $tLP TypoLink properties
+ * @param array $elements Array of elements to be modified with substitution / information entries.
+ * @param string $content The content to process.
+ * @param integer $idx Index value of the found element - user to make unique but stable tokenID
+ * @return string The input content, possibly containing tokens now according to the added substitution entries in $elements
* @see getTypoLinkParts()
*/
function setTypoLinkPartsElement($tLP, &$elements, $content, $idx) {
case 'file':
// Process files found in fileadmin directory:
if (!$tLP['query']) { // We will not process files which has a query added to it. That will look like a script we don't want to move.
- if (t3lib_div::isFirstPartOfStr($tLP['filepath'], $this->fileAdminDir . '/')) { // File must be inside fileadmin/
+ // File must be inside fileadmin/
+ if (t3lib_div::isFirstPartOfStr($tLP['filepath'], $this->fileAdminDir . '/')) {
// Set up the basic token and token value for the relative file:
$elements[$tokenID . ':' . $idx]['subst'] = array(
// Add anchor if applicable
if (strlen($tLP['anchor'])) {
- if (t3lib_utility_Math::canBeInterpretedAsInteger($tLP['anchor'])) { // Anchor is assumed to point to a content elements:
+ // Anchor is assumed to point to a content elements:
+ if (t3lib_utility_Math::canBeInterpretedAsInteger($tLP['anchor'])) {
// Initialize a new entry because we have a new relation:
$newTokenID = $this->makeTokenID('setTypoLinkPartsElement:anchor:' . $idx);
$elements[$newTokenID . ':' . $idx] = array();
/**
* Look up and return page uid for alias
*
- * @param integer Page alias string value
- * @return integer Page uid corresponding to alias value.
+ * @param integer $link_param Page alias string value
+ * @return integer Page uid corresponding to alias value.
*/
function getPageIdFromAlias($link_param) {
$pRec = t3lib_BEfunc::getRecordsByField('pages', 'alias', $link_param);
/**
* Make Token ID for input index.
*
- * @param string suffix value.
- * @return string Token ID
+ * @param string $index Suffix value.
+ * @return string Token ID
*/
function makeTokenID($index = '') {
return md5($this->tokenID_basePrefix . ':' . $index);
/**
* TYPO3 SQL parser
*
- * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
*/
-
/**
* TYPO3 SQL parser class.
*
- * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
* @package TYPO3
* @subpackage t3lib
*/
class t3lib_sqlparser {
// Parser:
- var $parse_error = ''; // Parsing error string
- var $lastStopKeyWord = ''; // Last stop keyword used.
-
+ // Parsing error string
+ var $parse_error = '';
+ // Last stop keyword used.
+ var $lastStopKeyWord = '';
/*************************************
*
/**
* Parses any single SQL query
*
- * @param string SQL query
- * @return array Result array with all the parts in - or error message string
+ * @param string $parseString SQL query
+ * @return array Result array with all the parts in - or error message string
* @see compileSQL(), debug_testSQL()
*/
public function parseSQL($parseString) {
/**
* Parsing SELECT query
*
- * @param string SQL string with SELECT query to parse
- * @param array Array holding references to either named (:name) or question mark (?) parameters found
- * @return mixed Returns array with components of SELECT query on success, otherwise an error message string.
+ * @param string $parseString SQL string with SELECT query to parse
+ * @param array $parameterReferences Array holding references to either named (:name) or question mark (?) parameters found
+ * @return mixed Returns array with components of SELECT query on success, otherwise an error message string.
* @see compileSELECT()
*/
protected function parseSELECT($parseString, &$parameterReferences = NULL) {
/**
* Parsing UPDATE query
*
- * @param string SQL string with UPDATE query to parse
- * @return mixed Returns array with components of UPDATE query on success, otherwise an error message string.
+ * @param string $parseString SQL string with UPDATE query to parse
+ * @return mixed Returns array with components of UPDATE query on success, otherwise an error message string.
* @see compileUPDATE()
*/
protected function parseUPDATE($parseString) {
// Get field/value pairs:
while ($comma) {
if ($fieldName = $this->nextPart($parseString, '^([[:alnum:]_]+)[[:space:]]*=')) {
- $this->nextPart($parseString, '^(=)'); // Strip of "=" sign.
+ // Strip of "=" sign.
+ $this->nextPart($parseString, '^(=)');
$value = $this->getValue($parseString);
$result['FIELDS'][$fieldName] = $value;
} else {
/**
* Parsing INSERT query
*
- * @param string SQL string with INSERT query to parse
- * @return mixed Returns array with components of INSERT query on success, otherwise an error message string.
+ * @param string $parseString SQL string with INSERT query to parse
+ * @return mixed Returns array with components of INSERT query on success, otherwise an error message string.
* @see compileINSERT()
*/
protected function parseINSERT($parseString) {
if ($result['TABLE']) {
- if ($this->nextPart($parseString, '^(VALUES)([[:space:]]+|\()')) { // In this case there are no field names mentioned in the SQL!
+ // In this case there are no field names mentioned in the SQL!
+ if ($this->nextPart($parseString, '^(VALUES)([[:space:]]+|\()')) {
// Get values/fieldnames (depending...)
$result['VALUES_ONLY'] = $this->getValue($parseString, 'IN');
if ($this->parse_error) {
return $this->parse_error;
}
- if ($this->nextPart($parseString, '^(VALUES)([[:space:]]+|\()')) { // "VALUES" keyword binds the fieldnames to values:
+ // "VALUES" keyword binds the fieldnames to values:
+ if ($this->nextPart($parseString, '^(VALUES)([[:space:]]+|\()')) {
$result['FIELDS'] = array();
do {
- $values = $this->getValue($parseString, 'IN'); // Using the "getValue" function to get the field list...
+ // Using the "getValue" function to get the field list...
+ $values = $this->getValue($parseString, 'IN');
if ($this->parse_error) {
return $this->parse_error;
}
/**
* Parsing DELETE query
*
- * @param string SQL string with DELETE query to parse
- * @return mixed Returns array with components of DELETE query on success, otherwise an error message string.
+ * @param string $parseString SQL string with DELETE query to parse
+ * @return mixed Returns array with components of DELETE query on success, otherwise an error message string.
* @see compileDELETE()
*/
protected function parseDELETE($parseString) {
/**
* Parsing EXPLAIN query
*
- * @param string SQL string with EXPLAIN query to parse
- * @return mixed Returns array with components of EXPLAIN query on success, otherwise an error message string.
+ * @param string $parseString SQL string with EXPLAIN query to parse
+ * @return mixed Returns array with components of EXPLAIN query on success, otherwise an error message string.
* @see parseSELECT()
*/
protected function parseEXPLAIN($parseString) {
/**
* Parsing CREATE TABLE query
*
- * @param string SQL string starting with CREATE TABLE
- * @return mixed Returns array with components of CREATE TABLE query on success, otherwise an error message string.
+ * @param string $parseString SQL string starting with CREATE TABLE
+ * @return mixed Returns array with components of CREATE TABLE query on success, otherwise an error message string.
* @see compileCREATETABLE()
*/
protected function parseCREATETABLE($parseString) {
// While the parseString is not yet empty:
while (strlen($parseString) > 0) {
- if ($key = $this->nextPart($parseString, '^(KEY|PRIMARY KEY|UNIQUE KEY|UNIQUE)([[:space:]]+|\()')) { // Getting key
+ // Getting key
+ if ($key = $this->nextPart($parseString, '^(KEY|PRIMARY KEY|UNIQUE KEY|UNIQUE)([[:space:]]+|\()')) {
$key = strtoupper(str_replace(array(' ', TAB, CR, LF), '', $key));
switch ($key) {
/**
* Parsing ALTER TABLE query
*
- * @param string SQL string starting with ALTER TABLE
- * @return mixed Returns array with components of ALTER TABLE query on success, otherwise an error message string.
+ * @param string $parseString SQL string starting with ALTER TABLE
+ * @return mixed Returns array with components of ALTER TABLE query on success, otherwise an error message string.
* @see compileALTERTABLE()
*/
protected function parseALTERTABLE($parseString) {
/**
* Parsing DROP TABLE query
*
- * @param string SQL string starting with DROP TABLE
- * @return mixed Returns array with components of DROP TABLE query on success, otherwise an error message string.
+ * @param string $parseString SQL string starting with DROP TABLE
+ * @return mixed Returns array with components of DROP TABLE query on success, otherwise an error message string.
*/
protected function parseDROPTABLE($parseString) {
/**
* Parsing CREATE DATABASE query
*
- * @param string SQL string starting with CREATE DATABASE
- * @return mixed Returns array with components of CREATE DATABASE query on success, otherwise an error message string.
+ * @param string $parseString SQL string starting with CREATE DATABASE
+ * @return mixed Returns array with components of CREATE DATABASE query on success, otherwise an error message string.
*/
protected function parseCREATEDATABASE($parseString) {
/**
* Parsing TRUNCATE TABLE query
*
- * @param string SQL string starting with TRUNCATE TABLE
- * @return mixed Returns array with components of TRUNCATE TABLE query on success, otherwise an error message string.
+ * @param string $parseString SQL string starting with TRUNCATE TABLE
+ * @return mixed Returns array with components of TRUNCATE TABLE query on success, otherwise an error message string.
*/
protected function parseTRUNCATETABLE($parseString) {
}
}
-
/**************************************
*
* SQL Parsing, helper functions for parts of queries
* The output from this function can be compiled back into a field list with ->compileFieldList()
* Will detect the keywords "DESC" and "ASC" after the table name; thus is can be used for parsing the more simply ORDER BY and GROUP BY field lists as well!
*
- * @param string The string with fieldnames, eg. "title, uid AS myUid, max(tstamp), count(*)" etc. NOTICE: passed by reference!
- * @param string Regular expressing to STOP parsing, eg. '^(FROM)([[:space:]]*)'
- * @return array If successful parsing, returns an array, otherwise an error string.
+ * @param string $parseString The string with fieldnames, eg. "title, uid AS myUid, max(tstamp), count(*)" etc. NOTICE: passed by reference!
+ * @param string $stopRegex Regular expressing to STOP parsing, eg. '^(FROM)([[:space:]]*)'
+ * @return array If successful parsing, returns an array, otherwise an error string.
* @see compileFieldList()
*/
public function parseFieldList(&$parseString, $stopRegex = '') {
return $stack;
} // FIXME - should never happen, why does it?
- $pnt = 0; // Pointer to positions in $stack
- $level = 0; // Indicates the parenthesis level we are at.
- $loopExit = 0; // Recursivity brake.
+ // Pointer to positions in $stack
+ $pnt = 0;
+ // Indicates the parenthesis level we are at.
+ $level = 0;
+ // Recursivity brake.
+ $loopExit = 0;
// Prepare variables:
$parseString = $this->trimSQL($parseString);
while (strlen($parseString)) {
// Checking if we are inside / outside parenthesis (in case of a function like count(), max(), min() etc...):
- if ($level > 0) { // Inside parenthesis here (does NOT detect if values in quotes are used, the only token is ")" or "("):
+ // Inside parenthesis here (does NOT detect if values in quotes are used, the only token is ")" or "("):
+ if ($level > 0) {
// Accumulate function content until next () parenthesis:
$funcContent = $this->nextPart($parseString, '^([^()]*.)');
break;
case ')':
$level--;
- if (!$level) { // If this was the last parenthesis:
+ // If this was the last parenthesis:
+ if (!$level) {
$stack[$pnt]['func_content'] = substr($stack[$pnt]['func_content'], 0, -1);
- $parseString = ltrim($parseString); // Remove any whitespace after the parenthesis.
+ // Remove any whitespace after the parenthesis.
+ $parseString = ltrim($parseString);
}
break;
}
// Looking for a known function (only known functions supported)
$func = $this->nextPart($parseString, '^(count|max|min|floor|sum|avg)[[:space:]]*\(');
if ($func) {
- $parseString = trim(substr($parseString, 1)); // Strip of "("
+ // Strip of "("
+ $parseString = trim(substr($parseString, 1));
$stack[$pnt]['type'] = 'function';
$stack[$pnt]['function'] = $func;
- $level++; // increse parenthesis level counter.
+ // increse parenthesis level counter.
+ $level++;
} else {
$stack[$pnt]['distinct'] = $this->nextPart($parseString, '^(distinct[[:space:]]+)');
// Otherwise, look for regular fieldname:
* Parsing a CASE ... WHEN flow-control construct.
* The output from this function can be compiled back with ->compileCaseStatement()
*
- * @param string The string with the CASE ... WHEN construct, eg. "CASE field WHEN 1 THEN 0 ELSE ..." etc. NOTICE: passed by reference!
- * @return array If successful parsing, returns an array, otherwise an error string.
+ * @param string $parseString The string with the CASE ... WHEN construct, eg. "CASE field WHEN 1 THEN 0 ELSE ..." etc. NOTICE: passed by reference!
+ * @return array If successful parsing, returns an array, otherwise an error string.
* @see compileCaseConstruct()
*/
protected function parseCaseStatement(&$parseString) {
* Parsing the tablenames in the "FROM [$parseString] WHERE" part of a query into an array.
* The success of this parsing determines if that part of the query is supported by TYPO3.
*
- * @param string list of tables, eg. "pages, tt_content" or "pages A, pages B". NOTICE: passed by reference!
- * @param string Regular expressing to STOP parsing, eg. '^(WHERE)([[:space:]]*)'
- * @return array If successful parsing, returns an array, otherwise an error string.
+ * @param string $parseString List of tables, eg. "pages, tt_content" or "pages A, pages B". NOTICE: passed by reference!
+ * @param string $stopRegex Regular expressing to STOP parsing, eg. '^(WHERE)([[:space:]]*)'
+ * @return array If successful parsing, returns an array, otherwise an error string.
* @see compileFromTables()
*/
public function parseFromTables(&$parseString, $stopRegex = '') {
$this->lastStopKeyWord = '';
$this->parse_error = '';
- $stack = array(); // Contains the parsed content
- $pnt = 0; // Pointer to positions in $stack
- $loopExit = 0; // Recursivity brake.
+ // Contains the parsed content
+ $stack = array();
+ // Pointer to positions in $stack
+ $pnt = 0;
+ // Recursivity brake.
+ $loopExit = 0;
// $parseString is continously shortend by the process and we keep parsing it till it is zero:
while (strlen($parseString)) {
* Parsing the WHERE clause fields in the "WHERE [$parseString] ..." part of a query into a multidimensional array.
* The success of this parsing determines if that part of the query is supported by TYPO3.
*
- * @param string WHERE clause to parse. NOTICE: passed by reference!
- * @param string Regular expressing to STOP parsing, eg. '^(GROUP BY|ORDER BY|LIMIT)([[:space:]]*)'
- * @param array Array holding references to either named (:name) or question mark (?) parameters found
- * @return mixed If successful parsing, returns an array, otherwise an error string.
+ * @param string $parseString WHERE clause to parse. NOTICE: passed by reference!
+ * @param string $stopRegex Regular expressing to STOP parsing, eg. '^(GROUP BY|ORDER BY|LIMIT)([[:space:]]*)'
+ * @param array $parameterReferences Array holding references to either named (:name) or question mark (?) parameters found
+ * @return mixed If successful parsing, returns an array, otherwise an error string.
*/
public function parseWhereClause(&$parseString, $stopRegex = '', array &$parameterReferences = array()) {
$this->lastStopKeyWord = '';
$this->parse_error = '';
- $stack = array(0 => array()); // Contains the parsed content
- $pnt = array(0 => 0); // Pointer to positions in $stack
- $level = 0; // Determines parenthesis level
- $loopExit = 0; // Recursivity brake.
+ // Contains the parsed content
+ $stack = array(0 => array());
+ // Pointer to positions in $stack
+ $pnt = array(0 => 0);
+ // Determines parenthesis level
+ $level = 0;
+ // Recursivity brake.
+ $loopExit = 0;
// $parseString is continously shortend by the process and we keep parsing it till it is zero:
while (strlen($parseString)) {
// Look for next parenthesis level:
$newLevel = $this->nextPart($parseString, '^([(])');
- if ($newLevel == '(') { // If new level is started, manage stack/pointers:
- $level++; // Increase level
- $pnt[$level] = 0; // Reset pointer for this level
- $stack[$level] = array(); // Reset stack for this level
+ // If new level is started, manage stack/pointers:
+ if ($newLevel == '(') {
+ // Increase level
+ $level++;
+ // Reset pointer for this level
+ $pnt[$level] = 0;
+ // Reset stack for this level
+ $stack[$level] = array();
} else { // If no new level is started, just parse the current level:
// Find "modifier", eg. "NOT or !"
// See if condition is EXISTS with a subquery
if (preg_match('/^EXISTS[[:space:]]*[(]/i', $parseString)) {
$stack[$level][$pnt[$level]]['func']['type'] = $this->nextPart($parseString, '^(EXISTS)[[:space:]]*');
- $parseString = trim(substr($parseString, 1)); // Strip of "("
+ // Strip of "("
+ $parseString = trim(substr($parseString, 1));
$stack[$level][$pnt[$level]]['func']['subquery'] = $this->parseSELECT($parseString, $parameterReferences);
// Seek to new position in parseString after parsing of the subquery
$parseString = $stack[$level][$pnt[$level]]['func']['subquery']['parseString'];
// See if LOCATE function is found
if (preg_match('/^LOCATE[[:space:]]*[(]/i', $parseString)) {
$stack[$level][$pnt[$level]]['func']['type'] = $this->nextPart($parseString, '^(LOCATE)[[:space:]]*');
- $parseString = trim(substr($parseString, 1)); // Strip of "("
+ // Strip of "("
+ $parseString = trim(substr($parseString, 1));
$stack[$level][$pnt[$level]]['func']['substr'] = $this->getValue($parseString);
if (!$this->nextPart($parseString, '^(,)')) {
return $this->parseError('No comma found as expected in parseWhereClause()', $parseString);
}
} elseif (preg_match('/^FIND_IN_SET[[:space:]]*[(]/i', $parseString)) {
$stack[$level][$pnt[$level]]['func']['type'] = $this->nextPart($parseString, '^(FIND_IN_SET)[[:space:]]*');
- $parseString = trim(substr($parseString, 1)); // Strip of "("
+ // Strip of "("
+ $parseString = trim(substr($parseString, 1));
if ($str = $this->getValue($parseString)) {
$stack[$level][$pnt[$level]]['func']['str'] = $str;
if ($fieldName = $this->nextPart($parseString, '^,[[:space:]]*([[:alnum:]._]+)[[:space:]]*', TRUE)) {
// Checking if the current level is ended, in that case do stack management:
while ($this->nextPart($parseString, '^([)])')) {
$level--; // Decrease level:
- $stack[$level][$pnt[$level]]['sub'] = $stack[$level + 1]; // Copy stack
- $pnt[$level]++; // Increase pointer of the new level
+ // Copy stack
+ $stack[$level][$pnt[$level]]['sub'] = $stack[$level + 1];
+ // Increase pointer of the new level
+ $pnt[$level]++;
// Make recursivity check:
$loopExit++;
* Parsing the WHERE clause fields in the "WHERE [$parseString] ..." part of a query into a multidimensional array.
* The success of this parsing determines if that part of the query is supported by TYPO3.
*
- * @param string WHERE clause to parse. NOTICE: passed by reference!
- * @param string Regular expressing to STOP parsing, eg. '^(GROUP BY|ORDER BY|LIMIT)([[:space:]]*)'
- * @return mixed If successful parsing, returns an array, otherwise an error string.
+ * @param string $parseString WHERE clause to parse. NOTICE: passed by reference!
+ * @param string $stopRegex Regular expressing to STOP parsing, eg. '^(GROUP BY|ORDER BY|LIMIT)([[:space:]]*)'
+ * @return mixed If successful parsing, returns an array, otherwise an error string.
*/
public function parseFieldDef(&$parseString, $stopRegex = '') {
// Prepare variables:
return $result;
}
-
/************************************
*
* Parsing: Helper functions
* Strips off a part of the parseString and returns the matching part.
* Helper function for the parsing methods.
*
- * @param string Parse string; if $regex finds anything the value of the first () level will be stripped of the string in the beginning. Further $parseString is left-trimmed (on success). Notice; parsestring is passed by reference.
- * @param string Regex to find a matching part in the beginning of the string. Rules: You MUST start the regex with "^" (finding stuff in the beginning of string) and the result of the first parenthesis is what will be returned to you (and stripped of the string). Eg. '^(AND|OR|&&)[[:space:]]+' will return AND, OR or && if found and having one of more whitespaces after it, plus shorten $parseString with that match and any space after (by ltrim())
- * @param boolean If set the full match of the regex is stripped of the beginning of the string!
- * @return string The value of the first parenthesis level of the REGEX.
+ * @param string $parseString Parse string; if $regex finds anything the value of the first () level will be stripped of the string in the beginning. Further $parseString is left-trimmed (on success). Notice; parsestring is passed by reference.
+ * @param string $regex Regex to find a matching part in the beginning of the string. Rules: You MUST start the regex with "^" (finding stuff in the beginning of string) and the result of the first parenthesis is what will be returned to you (and stripped of the string). Eg. '^(AND|OR|&&)[[:space:]]+' will return AND, OR or && if found and having one of more whitespaces after it, plus shorten $parseString with that match and any space after (by ltrim())
+ * @param boolean $trimAll If set the full match of the regex is stripped of the beginning of the string!
+ * @return string The value of the first parenthesis level of the REGEX.
*/
protected function nextPart(&$parseString, $regex, $trimAll = FALSE) {
$reg = array();
- if (preg_match('/' . $regex . '/i', $parseString . ' ', $reg)) { // Adding space char because [[:space:]]+ is often a requirement in regex's
+ // Adding space char because [[:space:]]+ is often a requirement in regex's
+ if (preg_match('/' . $regex . '/i', $parseString . ' ', $reg)) {
$parseString = ltrim(substr($parseString, strlen($reg[$trimAll ? 0 : 1])));
return $reg[1];
}
/**
* Finds value in beginning of $parseString, returns result and strips it of parseString
*
- * @param string The parseString, eg. "(0,1,2,3) ..." or "('asdf','qwer') ..." or "1234 ..." or "'My string value here' ..."
- * @param string The comparator used before. If "NOT IN" or "IN" then the value is expected to be a list of values. Otherwise just an integer (un-quoted) or string (quoted)
- * @param string The mode, eg. "INDEX"
- * @return mixed The value (string/integer). Otherwise an array with error message in first key (0)
+ * @param string $parseString The parseString, eg. "(0,1,2,3) ..." or "('asdf','qwer') ..." or "1234 ..." or "'My string value here' ..."
+ * @param string $comparator The comparator used before. If "NOT IN" or "IN" then the value is expected to be a list of values. Otherwise just an integer (un-quoted) or string (quoted)
+ * @param string $mode The mode, eg. "INDEX"
+ * @return mixed The value (string/integer). Otherwise an array with error message in first key (0)
*/
protected function getValue(&$parseString, $comparator = '', $mode = '') {
$value = '';
* Get value in quotes from $parseString.
* NOTICE: If a query being parsed was prepared for another database than MySQL this function should probably be changed
*
- * @param string String from which to find value in quotes. Notice that $parseString is passed by reference and is shortend by the output of this function.
- * @param string The quote used; input either " or '
- * @return string The value, passed through stripslashes() !
+ * @param string $parseString String from which to find value in quotes. Notice that $parseString is passed by reference and is shortend by the output of this function.
+ * @param string $quote The quote used; input either " or '
+ * @return string The value, passed through stripslashes() !
*/
protected function getValueInQuotes(&$parseString, $quote) {
* Strip slashes function used for parsing
* NOTICE: If a query being parsed was prepared for another database than MySQL this function should probably be changed
*
- * @param string Input string
- * @return string Output string
+ * @param string $str Input string
+ * @return string Output string
*/
protected function parseStripslashes($str) {
$search = array('\\\\', '\\\'', '\\"', '\0', '\n', '\r', '\Z');
* Add slashes function used for compiling queries
* NOTICE: If a query being parsed was prepared for another database than MySQL this function should probably be changed
*
- * @param string Input string
- * @return string Output string
+ * @param string $str Input string
+ * @return string Output string
*/
protected function compileAddslashes($str) {
$search = array('\\', '\'', '"', "\x00", "\x0a", "\x0d", "\x1a");
/**
* Setting the internal error message value, $this->parse_error and returns that value.
*
- * @param string Input error message
- * @param string Remaining query to parse.
- * @return string Error message.
+ * @param string $msg Input error message
+ * @param string $restQuery Remaining query to parse.
+ * @return string Error message.
*/
protected function parseError($msg, $restQuery) {
$this->parse_error = 'SQL engine parse ERROR: ' . $msg . ': near "' . substr($restQuery, 0, 50) . '"';
* White space is trimmed away around the value
* A single space-char is added in the end
*
- * @param string Input string
- * @return string Output string
+ * @param string $str Input string
+ * @return string Output string
*/
protected function trimSQL($str) {
return trim(rtrim($str, "; \r\n\t")) . ' ';
}
-
/*************************
*
* Compiling queries
/**
* Compiles an SQL query from components
*
- * @param array Array of SQL query components
- * @return string SQL query
+ * @param array $components Array of SQL query components
+ * @return string SQL query
* @see parseSQL()
*/
public function compileSQL($components) {
/**
* Compiles a SELECT statement from components array
*
- * @param array Array of SQL query components
- * @return string SQL SELECT query
+ * @param array $components Array of SQL query components
+ * @return string SQL SELECT query
* @see parseSELECT()
*/
protected function compileSELECT($components) {
/**
* Compiles an UPDATE statement from components array
*
- * @param array Array of SQL query components
- * @return string SQL UPDATE query
+ * @param array $components Array of SQL query components
+ * @return string SQL UPDATE query
* @see parseUPDATE()
*/
protected function compileUPDATE($components) {
/**
* Compiles an INSERT statement from components array
*
- * @param array Array of SQL query components
- * @return string SQL INSERT query
+ * @param array $components Array of SQL query components
+ * @return string SQL INSERT query
* @see parseINSERT()
*/
protected function compileINSERT($components) {
/**
* Compiles an DELETE statement from components array
*
- * @param array Array of SQL query components
- * @return string SQL DELETE query
+ * @param array $components Array of SQL query components
+ * @return string SQL DELETE query
* @see parseDELETE()
*/
protected function compileDELETE($components) {
/**
* Compiles a CREATE TABLE statement from components array
*
- * @param array Array of SQL query components
- * @return string SQL CREATE TABLE query
+ * @param array $components Array of SQL query components
+ * @return string SQL CREATE TABLE query
* @see parseCREATETABLE()
*/
protected function compileCREATETABLE($components) {
/**
* Compiles an ALTER TABLE statement from components array
*
- * @param array Array of SQL query components
- * @return string SQL ALTER TABLE query
+ * @param array $components Array of SQL query components
+ * @return string SQL ALTER TABLE query
* @see parseALTERTABLE()
*/
protected function compileALTERTABLE($components) {
/**
* Compiles a TRUNCATE TABLE statement from components array
*
- * @param array Array of SQL query components
- * @return string SQL TRUNCATE TABLE query
+ * @param array $components Array of SQL query components
+ * @return string SQL TRUNCATE TABLE query
* @see parseTRUNCATETABLE()
*/
protected function compileTRUNCATETABLE(array $components) {
return $query;
}
-
/**************************************
*
* Compiling queries, helper functions for parts of queries
* Compiles a "SELECT [output] FROM..:" field list based on input array (made with ->parseFieldList())
* Can also compile field lists for ORDER BY and GROUP BY.
*
- * @param array Array of select fields, (made with ->parseFieldList())
- * @param boolean Whether comments should be compiled
- * @return string Select field string
+ * @param array $selectFields Array of select fields, (made with ->parseFieldList())
+ * @param boolean $compileComments Whether comments should be compiled
+ * @return string Select field string
* @see parseFieldList()
*/
public function compileFieldList($selectFields, $compileComments = TRUE) {
/**
* Compiles a CASE ... WHEN flow-control construct based on input array (made with ->parseCaseStatement())
*
- * @param array Array of case components, (made with ->parseCaseStatement())
- * @return string case when string
+ * @param array $components Array of case components, (made with ->parseCaseStatement())
+ * @return string Case when string
* @see parseCaseStatement()
*/
protected function compileCaseStatement(array $components) {
/**
* Compiles a "FROM [output] WHERE..:" table list based on input array (made with ->parseFromTables())
*
- * @param array Array of table names, (made with ->parseFromTables())
- * @return string Table name string
+ * @param array $tablesArray Array of table names, (made with ->parseFromTables())
+ * @return string Table name string
* @see parseFromTables()
*/
public function compileFromTables($tablesArray) {
/**
* Implodes an array of WHERE clause configuration into a WHERE clause.
*
- * @param array WHERE clause configuration
- * @return string WHERE clause as string.
+ * @param array $clauseArray WHERE clause configuration
+ * @return string WHERE clause as string.
* @see explodeWhereClause()
*/
public function compileWhereClause($clauseArray) {
/**
* Compile field definition
*
- * @param array Field definition parts
- * @return string Field definition string
+ * @param array $fieldCfg Field definition parts
+ * @return string Field definition string
*/
public function compileFieldCfg($fieldCfg) {
return $cfg;
}
-
/*************************
*
* Debugging
/**
* Check parsability of input SQL part string; Will parse and re-compile after which it is compared
*
- * @param string Part definition of string; "SELECT" = fieldlist (also ORDER BY and GROUP BY), "FROM" = table list, "WHERE" = Where clause.
- * @param string SQL string to verify parsability of
- * @return mixed Returns array with string 1 and 2 if error, otherwise FALSE
+ * @param string $part Part definition of string; "SELECT" = fieldlist (also ORDER BY and GROUP BY), "FROM" = table list, "WHERE" = Where clause.
+ * @param string $str SQL string to verify parsability of
+ * @return mixed Returns array with string 1 and 2 if error, otherwise FALSE
*/
public function debug_parseSQLpart($part, $str) {
$retVal = FALSE;
/**
* Compare two query strins by stripping away whitespace.
*
- * @param string SQL String 1
- * @param string SQL string 2
- * @param boolean If TRUE, the strings are compared insensitive to case
- * @return mixed Returns array with string 1 and 2 if error, otherwise FALSE
+ * @param string $str SQL String 1
+ * @param string $newStr SQL string 2
+ * @param boolean $caseInsensitive If TRUE, the strings are compared insensitive to case
+ * @return mixed Returns array with string 1 and 2 if error, otherwise FALSE
*/
public function debug_parseSQLpartCompare($str, $newStr, $caseInsensitive = FALSE) {
if ($caseInsensitive) {
$str1 = str_replace($search, $replace, $str1);
$str2 = str_replace($search, $replace, $str2);
- # Normally, commented out since they are needed only in tricky cases...
- # $str1 = stripslashes($str1);
- # $str2 = stripslashes($str2);
-
if (strcmp(str_replace(array(' ', TAB, CR, LF), '', $this->trimSQL($str1)), str_replace(array(' ', TAB, CR, LF), '', $this->trimSQL($str2)))) {
return array(
str_replace(array(' ', TAB, CR, LF), ' ', $str),
/**
* Performs the ultimate test of the parser: Direct a SQL query in; You will get it back (through the parsed and re-compiled) if no problems, otherwise the script will print the error and exit
*
- * @param string SQL query
- * @return string Query if all is well, otherwise exit.
+ * @param string $SQLquery SQL query
+ * @return string Query if all is well, otherwise exit.
*/
public function debug_testSQL($SQLquery) {