--- class.tslib_pibase.php.org 2005-04-14 19:49:31.000000000 +0200 +++ class.tslib_pibase.php 2005-04-14 20:00:33.850633088 +0200 @@ -92,54 +92,34 @@ * 1187: function pi_initPIflexForm() * 1205: function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF') * 1222: function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value) * * TOTAL FUNCTIONS: 35 * (This index is automatically created/updated by the extension "extdeveval") * */ - - - - - - - - - - - - - - - - - - - - /** * Base class for frontend plugins * Most modern frontend plugins are extension classes of this one. * This class contains functions which assists these plugins in creating lists, searching, displaying menus, page-browsing (next/previous/1/2/3) and handling links. * Functions are all prefixed "pi_" which is reserved for this class. Those functions can of course be overridden in the extension classes (that is the point...) * * @author Kasper Skaarhoj * @package TYPO3 * @subpackage tslib */ class tslib_pibase { - // Reserved variables: - var $cObj; // The backReference to the mother cObj object set at call time + // Reserved variables: + var $cObj; // The backReference to the mother cObj object set at call time var $prefixId; // Should be same as classname of the plugin, used for CSS classes, variables var $scriptRelPath; // Path to the plugin class script relative to extension directory, eg. 'pi1/class.tx_newfaq_pi1.php' var $extKey; // Extension key. var $piVars = Array ( // This is the incomming array by name $this->prefixId merged between POST and GET, POST taking precedence. Eg. if the class name is 'tx_myext' then the content of this array will be whatever comes into &tx_myext[...]=... 'pointer' => '', // Used as a pointer for lists 'mode' => '', // List mode 'sword' => '', // Search word 'sort' => '', // [Sorting column]:[ASC=0/DESC=1] ); var $internal = Array( // Used internally for general storage of values between methods @@ -173,35 +153,20 @@ * $conf[LOCAL_LANG][_key_] is reserved for Local Language overrides. * $conf[userFunc] / $conf[includeLibs] reserved for setting up the USER / USER_INT object. See TSref */ var $conf = Array(); // internal, don't mess with... var $pi_EPtemp_cObj; var $pi_tmpPageId=0; - - - - - - - - - - - - - - - /*************************** * * Init functions * **************************/ /** * Class Constructor (true constructor) * Initializes $this->piVars if $this->prefixId is set to any value * Will also set $this->LLkey based on the config.language setting. @@ -222,33 +187,20 @@ * * @return void */ function pi_setPiVarDefaults() { if (is_array($this->conf['_DEFAULT_PI_VARS.'])) { $this->piVars = t3lib_div::array_merge_recursive_overrule($this->conf['_DEFAULT_PI_VARS.'],is_array($this->piVars)?$this->piVars:array()); } } - - - - - - - - - - - - - /*************************** * * Link functions * **************************/ /** * Get URL to some page. * Returns the URL to page $id with $target and an array of additional url-parameters, $urlParameters * Simple example: $this->pi_getPageLink(123) to get the URL for page-id 123. @@ -390,60 +342,46 @@ $aTagContent = t3lib_div::get_tag_attributes($match[2]); $match[2]=''; $str=$match[1].$match[2].$match[3]; } return $str; } - - - - - - - - - - - - - /*************************** * * Functions for listing, browsing, searching etc. * **************************/ /** * Returns a results browser. This means a bar of page numbers plus a "previous" and "next" link. For each entry in the bar the piVars "pointer" will be pointing to the "result page" to show. * Using $this->piVars['pointer'] as pointer to the page to display * Using $this->internal['res_count'], $this->internal['results_at_a_time'] and $this->internal['maxPages'] for count number, how many results to show and the max number of pages to include in the browse bar. * * @param boolean If set (default) the text "Displaying results..." will be show, otherwise not. * @param string Attributes for the table tag which is wrapped around the table cells containing the browse links * @return string Output HTML, wrapped in
-tags with a class attribute */ function pi_list_browseresults($showResultCount=1,$tableParams='') { - - // Initializing variables: + // Initializing variables: $pointer=$this->piVars['pointer']; $count=$this->internal['res_count']; $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000); $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100); $max = t3lib_div::intInRange(ceil($count/$results_at_a_time),1,$maxPages); $pointer=intval($pointer); $links=array(); - // Make browse-table/links: + // Make browse-table/links: if ($this->pi_alwaysPrev>=0) { if ($pointer>0) { $links[]='

'.$this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_prev','< Previous',TRUE),array('pointer'=>($pointer-1?$pointer-1:'')),0).'

'; } elseif ($this->pi_alwaysPrev) { $links[]='

'.$this->pi_getLL('pi_list_browseresults_prev','< Previous',TRUE).'

'; } } for($a=0;$a<$max;$a++) { @@ -560,21 +498,21 @@ * $this->pi_list_header() makes the header row for the list * $this->pi_list_row() is used for rendering each row * Notice that these two functions are typically ALWAYS defined in the extension class of the plugin since they are directly concerned with the specific layout for that plugins purpose. * * @param pointer Result pointer to a SQL result which can be traversed. * @param string Attributes for the table tag which is wrapped around the table rows containing the list * @return string Output HTML, wrapped in
-tags with a class attribute * @see pi_list_row(), pi_list_header() */ function pi_list_makelist($res,$tableParams='') { - // Make list table header: + // Make list table header: $tRows=array(); $this->internal['currentRow']=''; $tRows[] = $this->pi_list_header(); // Make list table rows $c=0; while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $tRows[] = $this->pi_list_row($c); $c++; } @@ -610,41 +548,27 @@ * Returns a list header row. * (Dummy) * Notice: This function should ALWAYS be defined in the extension class of the plugin since it is directly concerned with the specific layout of the listing for your plugins purpose. * * @return string HTML output, a table row with a class attribute set */ function pi_list_header() { return 'pi_classParam('listrow-header').'>

[dummy header row]

'; } - - - - - - - - - - - - - - + /*************************** * * Stylesheet, CSS * **************************/ - /** * Returns a class-name prefixed with $this->prefixId and with all underscores substituted to dashes (-) * * @param string The class name (or the END of it since it will be prefixed by $this->prefixId.'-') * @return string The combined class name (with the correct prefix) */ function pi_getClassName($class) { return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class; } @@ -692,35 +616,20 @@ -->
'.$str.'
'; } - - - - - - - - - - - - - - - /*************************** * * Frontend editing: Edit panel, edit icons * **************************/ /** * Returns the Backend User edit panel for the $row from $tablename * * @param array Record array. @@ -780,63 +689,48 @@ } $conf=array_merge(array( 'beforeLastTag'=>1, 'iconTitle' => $title ),$oConf); $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))); } return $content; } - - - - - - - - - - - - - - - - /*************************** * * Localization, locallang functions * **************************/ - /** * Returns the localized label of the LOCAL_LANG key, $key * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix * * @param string The key from the LOCAL_LANG array for which to return the value. * @param string Alternative string to return IF no value is found set for the key, neither for the local language nor the default. * @param boolean If true, the output label is passed through htmlspecialchars() * @return string The value from LOCAL_LANG. */ function pi_getLL($key,$alt='',$hsc=FALSE) { if (isset($this->LOCAL_LANG[$this->LLkey][$key])) { $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key]); } elseif (isset($this->LOCAL_LANG['default'][$key])) { $word = $this->LOCAL_LANG['default'][$key]; // No charset conversion because default is english and thereby ASCII } else { $word = $this->LLtestPrefixAlt.$alt; } $output = $this->LLtestPrefix.$word; - if ($hsc) $output = htmlspecialchars($output); + if ($hsc) { + $output = htmlspecialchars($output); + } return $output; } /** * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it. * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file. * * @return void */ @@ -853,42 +747,20 @@ $k = substr($k,0,-1); $this->LOCAL_LANG[$k] = t3lib_div::array_merge_recursive_overrule(is_array($this->LOCAL_LANG[$k])?$this->LOCAL_LANG[$k]:array(), $lA); } } } } } $this->LOCAL_LANG_loaded = 1; } - - - - - - - - - - - - - - - - - - - - - - /*************************** * * Database, queries * **************************/ /** * Makes a standard query for listing of records based on standard input vars from the 'browser' ($this->internal['results_at_a_time'] and $this->piVars['pointer']) and 'searchbox' ($this->piVars['sword'] and $this->internal['searchFieldList']) * Set $count to 1 if you wish to get a count(*) query for selecting the number of results. * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records. @@ -899,76 +771,77 @@ * @param mixed See pi_exec_query() * @param string See pi_exec_query() * @param string See pi_exec_query() * @param string See pi_exec_query() * @param boolean If set, the function will return the query not as a string but array with the various parts. * @return mixed The query build. * @access private * @depreciated Use pi_exec_query() instead! */ function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE) { - - // Begin Query: + // Begin Query: if (!$query) { - // Fetches the list of PIDs to select from. - // TypoScript property .pidList is a comma list of pids. If blank, current page id is used. - // TypoScript property .recursive is a int+ which determines how many levels down from the pids in the pid-list subpages should be included in the select. + // Fetches the list of PIDs to select from. + // TypoScript property .pidList is a comma list of pids. If blank, current page id is used. + // TypoScript property .recursive is a int+ which determines how many levels down from the pids in the pid-list subpages should be included in the select. $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']); if (is_array($mm_cat)) { $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10). ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10). (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10). ' AND '.$table.'.pid IN ('.$pidList.')'.chr(10). $this->cObj->enableFields($table).chr(10); // This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries! } else { $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10). $this->cObj->enableFields($table).chr(10); // This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries! } } - // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...: + // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...: list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2); $TABLENAMES = trim(substr(trim($TABLENAMES),5)); $WHERE = trim($WHERE); - // Add '$addWhere' - if ($addWhere) {$WHERE.=' '.$addWhere.chr(10);} + // Add '$addWhere' + if ($addWhere) { + $WHERE.=' '.$addWhere.chr(10); + } - // Search word: + // Search word: if ($this->piVars['sword'] && $this->internal['searchFieldList']) { $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10); } if ($count) { $queryParts = array( 'SELECT' => 'count(*)', 'FROM' => $TABLENAMES, 'WHERE' => $WHERE, 'GROUPBY' => '', 'ORDERBY' => '', 'LIMIT' => '' ); } else { - // Order by data: + // Order by data: if (!$orderBy && $this->internal['orderBy']) { if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy'])) { $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':''); } } - // Limit data: + // Limit data: $pointer = $this->piVars['pointer']; $pointer = intval($pointer); $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000); $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time; - // Add 'SELECT' + // Add 'SELECT' $queryParts = array( 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields), 'FROM' => $TABLENAMES, 'WHERE' => $WHERE, 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy), 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy), 'LIMIT' => $LIMIT ); } @@ -1017,21 +890,23 @@ } /** * Returns a commalist of page ids for a query (eg. 'WHERE pid IN (...)') * * @param string $pid_list is a comma list of page ids (if empty current page is used) * @param integer $recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list * @return string List of PID values (comma separated) */ function pi_getPidList($pid_list,$recursive=0) { - if (!strcmp($pid_list,'')) $pid_list = $GLOBALS['TSFE']->id; + if (!strcmp($pid_list,'')) { + $pid_list = $GLOBALS['TSFE']->id; + } $recursive = t3lib_div::intInRange($recursive,0); $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1)); $pid_list = array(); foreach($pid_list_arr as $val) { $val = t3lib_div::intInRange($val,0); if ($val) { $_list = $this->cObj->getTreeList(-1*$val, $recursive); if ($_list) $pid_list[] = $_list; @@ -1044,21 +919,21 @@ /** * Having a comma list of fields ($fieldList) this is prepended with the $table.'.' name * * @param string Table name to prepend * @param string List of fields where each element will be prepended with the table name given. * @return string List of fields processed. */ function pi_prependFieldsWithTable($table,$fieldList) { $list=t3lib_div::trimExplode(',',$fieldList,1); $return=array(); - while(list(,$listItem)=each($list)) { + while (list(,$listItem)=each($list)) { $return[]=$table.'.'.$listItem; } return implode(',',$return); } /** * Will select all records from the "category table", $table, and return them in an array. * * @param string The name of the category table to select from. * @param integer The page from where to select the category records. @@ -1081,50 +956,40 @@ ); $outArr = array(); while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $outArr[$row['uid']] = $row; } $GLOBALS['TYPO3_DB']->sql_free_result($res); return $outArr; } - - - - - - - - - - /*************************** * * Various * **************************/ /** * Returns true if the piVars array has ONLY those fields entered that is set in the $fList (commalist) AND if none of those fields value is greater than $lowerThan field if they are integers. * Notice that this function will only work as long as values are integers. * * @param string List of fields (keys from piVars) to evaluate on * @param integer Limit for the values. * @return boolean Returns true (1) if conditions are met. */ function pi_isOnlyFields($fList,$lowerThan=-1) { $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan; $fList = t3lib_div::trimExplode(',',$fList,1); $tempPiVars = $this->piVars; - while(list(,$k)=each($fList)) { + while (list(,$k)=each($fList)) { if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan) unset($tempPiVars[$k]); } if (!count($tempPiVars)) return 1; } /** * Returns true if the array $inArray contains only values allowed to be cached based on the configuration in $this->pi_autoCacheFields * Used by ->pi_linkTP_keepPIvars * This is an advanced form of evaluation of whether a URL should be cached or not. * @@ -1163,36 +1028,33 @@ * @return string The processed string * @see tslib_cObj::parseFunc() */ function pi_RTEcssText($str) { $parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.']; if (is_array($parseFunc)) $str = $this->cObj->parseFunc($str, $parseFunc); return $str; } - - - /******************************* * * FlexForms related functions * *******************************/ /** * Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array. * * @return void */ function pi_initPIflexForm() { - // Converting flexform data into array: + // Converting flexform data into array: if (!is_array($this->cObj->data['pi_flexform']) && $this->cObj->data['pi_flexform']) { $this->cObj->data['pi_flexform'] = t3lib_div::xml2array($this->cObj->data['pi_flexform']); if (!is_array($this->cObj->data['pi_flexform'])) $this->cObj->data['pi_flexform']=array(); } } /** * Return value from somewhere inside a FlexForm structure * * @param array FlexForm data @@ -1213,23 +1075,22 @@ * Returns part of $sheetArray pointed to by the keys in $fieldNameArray * * @param array Multidimensiona array, typically FlexForm contents * @param array Array where each value points to a key in the FlexForms content - the input array will have the value returned pointed to by these keys. All integer keys will not take their integer counterparts, but rather traverse the current position in the array an return element number X (whether this is right behavior is not settled yet...) * @param string Value for outermost key, typ. "vDEF" depending on language. * @return mixed The value, typ. string. * @access private * @see pi_getFFvalue() */ function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value) { - $tempArr=$sheetArray; - foreach($fieldNameArr as $k => $v) { + foreach ($fieldNameArr as $k => $v) { if (t3lib_div::testInt($v)) { if (is_array($tempArr)) { $c=0; foreach($tempArr as $values) { if ($c==$v) { #debug($values); $tempArr=$values; break; } $c++;