--- class.tslib_content.orig Sat May 23 17:37:22 2009 +++ class.tslib_content.php Sat May 30 20:17:13 2009 @@ -7066,73 +7066,129 @@ * @see CONTENT(), numRows() * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=318&cHash=a98cb4e7e6 */ - function getQuery($table, $conf, $returnQueryArray=FALSE) { - // Construct WHERE clause: - $conf['pidInList'] = trim($this->stdWrap($conf['pidInList'],$conf['pidInList.'])); + function getQuery($table, $conf, $returnQueryArray=FALSE) { + + // All Values of $conf can be parsed through stdWrap + // The Values ('pidInList','uidInList','recursive','languageField') are stdWrap_ped by + // default while real datatype is unimportant (string, integer) + // Most SQL-Devices may optionally stdWrap_ped too ('where','groupBy','orderBy','join','leftjoin','rightjoin') + // To avoid potentially misbehaviors all SQL-Parameters and "min" and "begin" explicitly have to be noted with keyword stdWrap + // min., and begin. are parsed through calc, which is incompatible to prioCalc of stdWrap + // but stdWrap can be choosen by max.stdWrap and accordingly begin.stdWrap + // Values which must not be stdWrap_ped: + // - andWhere is stdWrap_ped anyway in function getWhere() + // changing this extra-handling is only possible by flag because of backward-compatibility + // Due to new Configuration-Options it's in responsibility of the TypoScript-Author that results are correct + // and Automatism can be switched off or overriden a bit more + + $stdWrapAllowedValues = Array('pidInList','uidInList','recursive','languageField'); + $stdWrapOptionalValues = Array('begin','max','selectFields','where','groupBy','orderBy','join','leftjoin','rightjoin'); + $doNotstdWrap = Array('andWhere'); + $config = Array(); + foreach ($conf as $k => $v) { + + $r = ''; + preg_match('/(.*?)(\.)?$/',$k,$r); + + if (!in_array($r[1],$doNotstdWrap)) { + + // Avoiding that stdWrap options are written as values to $config + // strcmp returns 0 if true + if (strcmp($r[2],'') === 0 && !$conf[ $r[1].'.' ] || + strcmp($r[2],'.') === 0 && $conf[ $r[1].'.' ]) { + + // default stdWrap + if (in_array($r[1],$stdWrapAllowedValues)) { + $config[ $r[1] ] = trim($this->stdWrap($conf[ $r[1] ],$conf[ $k ])); + } + // optional stdWrap + elseif (in_array($r[1],$stdWrapOptionalValues)) { + // optional stdWrap WITH usage + if (is_array($conf[$k]) && array_key_exists('stdWrap',$conf[$k]) && strcmp($conf[$k]['stdWrap'],'') !== 0) { + $config[ $r[1] ] = trim($this->stdWrap($conf[ $r[1] ]['stdWrap.'],$conf[ $k ]['stdWrap'])); + } + // optional stdWrap WITHOUT usage + else { + $config[ $r[1] ] = trim($this->stdWrap($conf[ $r[1] ],$conf[ $k ])); + } + } + // unknown parameter + else { + $config[ $r[1] ] = $conf[ $k ]; + } + } + // Catching of unknown behavior + // doesn't seem to make any problems in loop + if (!isset($config[ $k ])) $config[ $k ] = $conf[ $k ]; + } + } // Handle recursive function for the pidInList - if (isset($conf['recursive'])) { - $conf['recursive'] = intval($conf['recursive']); - if ($conf['recursive'] > 0) { - foreach (explode(',', $conf['pidInList']) as $value) { - $pidList .= $value . ',' . $this->getTreeList($value, $conf['recursive']); + if (isset($config['recursive'])) { + $config['recursive'] = intval($config['recursive']); + if ($config['recursive'] > 0) { + foreach (explode(',', $config['pidInList']) as $value) { + $pidList .= $value . ',' . $this->getTreeList($value, $config['recursive']); } - $conf['pidInList'] = trim($pidList, ','); + $config['pidInList'] = trim($pidList, ','); } } - if (!strcmp($conf['pidInList'],'')) { - $conf['pidInList'] = 'this'; + // $conf['pidInList']['dontSetPid'] is set as new Option that avoids that + // an empty $conf['pidInList'] is filled with 'this' (= current pid) + if (!strcmp($config['pidInList'],'') && !$config['pidInList']['dontSetPid']) { + $config['pidInList'] = 'this'; } - $queryParts = $this->getWhere($table,$conf,TRUE); + $queryParts = $this->getWhere($table,$config,TRUE); // Fields: - $queryParts['SELECT'] = $conf['selectFields'] ? $conf['selectFields'] : '*'; + $queryParts['SELECT'] = $config['selectFields'] ? $config['selectFields'] : '*'; // Setting LIMIT: - if ($conf['max'] || $conf['begin']) { + if ($config['max'] || $config['begin']) { $error=0; // Finding the total number of records, if used: - if (strstr(strtolower($conf['begin'].$conf['max']),'total')) { + if (strstr(strtolower($config['begin'].$config['max']),'total')) { $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, $queryParts['WHERE'], $queryParts['GROUPBY']); if ($error = $GLOBALS['TYPO3_DB']->sql_error()) { $GLOBALS['TT']->setTSlogMessage($error); } else { $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res); - $conf['max'] = str_ireplace('total', $row[0], $conf['max']); - $conf['begin'] = str_ireplace('total', $row[0], $conf['begin']); + $config['max'] = str_ireplace('total', $row[0], $config['max']); + $config['begin'] = str_ireplace('total', $row[0], $config['begin']); } $GLOBALS['TYPO3_DB']->sql_free_result($res); } if (!$error) { - $conf['begin'] = t3lib_div::intInRange(ceil($this->calc($conf['begin'])),0); - $conf['max'] = t3lib_div::intInRange(ceil($this->calc($conf['max'])),0); - if ($conf['begin'] && !$conf['max']) { - $conf['max'] = 100000; + // If ..[stdWrap] calculation by calc has to be avoided because it's incompatible with stdWrap-option prioCalc + $config['begin'] = (!$config['begin']['stdWrap']) ? t3lib_div::intInRange(ceil($this->calc($config['begin'])),0) : $config['begin']; + $config['max'] = (!$config['max']['stdWrap']) ? t3lib_div::intInRange(ceil($this->calc($config['max'])),0) : $config['max']; + if ($config['begin'] && !$config['max']) { + $config['max'] = 100000; } - if ($conf['begin'] && $conf['max']) { - $queryParts['LIMIT'] = $conf['begin'].','.$conf['max']; - } elseif (!$conf['begin'] && $conf['max']) { - $queryParts['LIMIT'] = $conf['max']; + if ($config['begin'] && $config['max']) { + $queryParts['LIMIT'] = $config['begin'].','.$config['max']; + } elseif (!$config['begin'] && $config['max']) { + $queryParts['LIMIT'] = $config['max']; } } } - + if (!$error) { - + // Setting up tablejoins: $joinPart=''; - if ($conf['join']) { - $joinPart = 'JOIN ' .trim($conf['join']); - } elseif ($conf['leftjoin']) { - $joinPart = 'LEFT OUTER JOIN ' .trim($conf['leftjoin']); - } elseif ($conf['rightjoin']) { - $joinPart = 'RIGHT OUTER JOIN ' .trim($conf['rightjoin']); + if ($config['join']) { + $joinPart = 'JOIN ' .trim($config['join']); + } elseif ($config['leftjoin']) { + $joinPart = 'LEFT OUTER JOIN ' .trim($config['leftjoin']); + } elseif ($config['rightjoin']) { + $joinPart = 'RIGHT OUTER JOIN ' .trim($config['rightjoin']); } - + // Compile and return query: $queryParts['FROM'] = trim($table.' '.$joinPart); $query = $GLOBALS['TYPO3_DB']->SELECTquery( @@ -7143,6 +7199,7 @@ $queryParts['ORDERBY'], $queryParts['LIMIT'] ); + return $returnQueryArray ? $queryParts : $query; } } @@ -7213,8 +7270,11 @@ } $query.=' AND '.$conf['languageField'].' IN ('.$sys_language_content.')'; } - - $andWhere = trim($this->stdWrap($conf['andWhere'],$conf['andWhere.'])); + + if ($conf['andWhere'] && strtolower($conf['andWhere']['stdWrap']) != 'false') { + $andWhere = trim($this->stdWrap($conf['andWhere'],$conf['andWhere.'])); + } + else $andWhere = $conf['andWhere']; if ($andWhere) { $query.=' AND '.$andWhere; }