Documentation TYPO3 par Ameos

class.tslib_pibase.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00132 class tslib_pibase {
00133 
00134                 // Reserved variables:
00135         var $cObj;                      // The backReference to the mother cObj object set at call time
00136         var $prefixId;          // Should be same as classname of the plugin, used for CSS classes, variables
00137         var $scriptRelPath;     // Path to the plugin class script relative to extension directory, eg. 'pi1/class.tx_newfaq_pi1.php'
00138         var $extKey;            // Extension key.
00139         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[...]=...
00140                 'pointer' => '',                        // Used as a pointer for lists
00141                 'mode' => '',                           // List mode
00142                 'sword' => '',                          // Search word
00143                 'sort' => '',                           // [Sorting column]:[ASC=0/DESC=1]
00144         );
00145         var $internal = Array(  // Used internally for general storage of values between methods
00146                 'res_count' => 0,                       // Total query count
00147                 'results_at_a_time' => 20,      // pi_list_browseresults(): Show number of results at a time
00148                 'maxPages' => 10,                       // pi_list_browseresults(): Max number of 'Page 1 - Page 2 - ...' in the list browser
00149                 'currentRow' => Array(),        // Current result row
00150                 'currentTable' => '',           // Current table
00151         );
00152 
00153         var $LOCAL_LANG = Array();      // Local Language content
00154         var $LOCAL_LANG_loaded = 0;     // Flag that tells if the locallang file has been fetch (or tried to be fetched) already.
00155         var $LLkey='default';           // Pointer to the language to use.
00156         var $LLtestPrefix='';           // You can set this during development to some value that makes it easy for you to spot all labels that ARe delivered by the getLL function.
00157         var $LLtestPrefixAlt='';        // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
00158 
00159         var $pi_isOnlyFields = 'mode,pointer';
00160         var $pi_alwaysPrev = 0;
00161         var $pi_lowerThan = 5;
00162         var $pi_moreParams='';
00163         var $pi_listFields='*';
00164 
00165         var $pi_autoCacheFields=array();
00166         var $pi_autoCacheEn=0;
00167 
00168         var $pi_USER_INT_obj = 0;       // If set, then links are 1) not using cHash and 2) allowing pages to be cached.
00169 
00176         var $conf = Array();
00177 
00178         // internal, don't mess with...
00179         var $pi_EPtemp_cObj;
00180         var $pi_tmpPageId=0;
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198         /***************************
00199          *
00200          * Init functions
00201          *
00202          **************************/
00203 
00211         function tslib_pibase() {
00212                 if ($this->prefixId)    {
00213                         $this->piVars = t3lib_div::GParrayMerged($this->prefixId);
00214                 }
00215                 if ($GLOBALS['TSFE']->config['config']['language'])     {
00216                         $this->LLkey = $GLOBALS['TSFE']->config['config']['language'];
00217                 }
00218         }
00219 
00225         function pi_setPiVarDefaults()  {
00226                 if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
00227                         $this->piVars = t3lib_div::array_merge_recursive_overrule($this->conf['_DEFAULT_PI_VARS.'],is_array($this->piVars)?$this->piVars:array());
00228                 }
00229         }
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245         /***************************
00246          *
00247          * Link functions
00248          *
00249          **************************/
00250 
00264         function pi_getPageLink($id,$target='',$urlParameters=array())  {
00265                 return $this->cObj->getTypoLink_URL($id,$urlParameters,$target);        // ?$target:$GLOBALS['TSFE']->sPre
00266         }
00267 
00280         function pi_linkToPage($str,$id,$target='',$urlParameters=array())      {
00281                 return $this->cObj->getTypoLink($str,$id,$urlParameters,$target);       // ?$target:$GLOBALS['TSFE']->sPre
00282         }
00283 
00295         function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0)   {
00296                 $conf=array();
00297                 $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
00298                 $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
00299                 $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id);
00300                 $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('',$urlParameters,'',1).$this->pi_moreParams;
00301 
00302                 return $this->cObj->typoLink($str, $conf);
00303         }
00304 
00318         function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)        {
00319                 if (is_array($this->piVars) && is_array($overrulePIvars) && !$clearAnyway)      {
00320                         $piVars = $this->piVars;
00321                         unset($piVars['DATA']);
00322                         $overrulePIvars = t3lib_div::array_merge_recursive_overrule($piVars,$overrulePIvars);
00323                         if ($this->pi_autoCacheEn)      {
00324                                 $cache = $this->pi_autoCache($overrulePIvars);
00325                         }
00326                 }
00327                 $res = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
00328                 return $res;
00329         }
00330 
00342         function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) {
00343                 $this->pi_linkTP_keepPIvars('|',$overrulePIvars,$cache,$clearAnyway,$altPageId);
00344                 return $this->cObj->lastTypoLinkUrl;
00345         }
00346 
00360         function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0)       {
00361                 if ($this->prefixId)    {
00362                         if ($cache)     {
00363                                 $overrulePIvars=$uid?array('showUid'=>$uid):Array();
00364                                 $overrulePIvars=array_merge($overrulePIvars,$mergeArr);
00365                                 $str = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
00366                         } else {
00367                                 $overrulePIvars=array('showUid'=>$uid?$uid:'');
00368                                 $overrulePIvars=array_merge($overrulePIvars,$mergeArr);
00369                                 $str = $this->pi_linkTP_keepPIvars($str,$overrulePIvars,$cache,0,$altPageId);
00370                         }
00371 
00372                                 // If urlOnly flag, return only URL as it has recently be generated.
00373                         if ($urlOnly)   {
00374                                 $str = $this->cObj->lastTypoLinkUrl;
00375                         }
00376                 }
00377                 return $str;
00378         }
00379 
00388         function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')      {
00389                 if (eregi('(.*)(<a[^>]*>)(.*)',$str,$match))    {
00390                         $aTagContent = t3lib_div::get_tag_attributes($match[2]);
00391                         $match[2]='<a href="#" onclick="'.
00392                                 htmlspecialchars('vHWin=window.open(\''.$GLOBALS['TSFE']->baseUrlWrap($aTagContent['href']).'\',\''.($winName?$winName:md5($aTagContent['href'])).'\',\''.$winParams.'\');vHWin.focus();return false;').
00393                                 '">';
00394                         $str=$match[1].$match[2].$match[3];
00395                 }
00396                 return $str;
00397         }
00398 
00399 
00400 
00401 
00402 
00403 
00404 
00405 
00406 
00407 
00408 
00409 
00410 
00411 
00412 
00413         /***************************
00414          *
00415          * Functions for listing, browsing, searching etc.
00416          *
00417          **************************/
00418 
00428         function pi_list_browseresults($showResultCount=1,$tableParams='')      {
00429 
00430                         // Initializing variables:
00431                 $pointer=$this->piVars['pointer'];
00432                 $count=$this->internal['res_count'];
00433                 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
00434                 $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
00435                 $max = t3lib_div::intInRange(ceil($count/$results_at_a_time),1,$maxPages);
00436                 $pointer=intval($pointer);
00437                 $links=array();
00438 
00439                         // Make browse-table/links:
00440                 if ($this->pi_alwaysPrev>=0)    {
00441                         if ($pointer>0) {
00442                                 $links[]='
00443                                         <td nowrap="nowrap"><p>'.$this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_prev','< Previous',TRUE),array('pointer'=>($pointer-1?$pointer-1:'')),0).'</p></td>';
00444                         } elseif ($this->pi_alwaysPrev) {
00445                                 $links[]='
00446                                         <td nowrap="nowrap"><p>'.$this->pi_getLL('pi_list_browseresults_prev','< Previous',TRUE).'</p></td>';
00447                         }
00448                 }
00449                 for($a=0;$a<$max;$a++)  {
00450                         $links[]='
00451                                         <td'.($pointer==$a?$this->pi_classParam('browsebox-SCell'):'').' nowrap="nowrap"><p>'.
00452                                 $this->pi_linkTP_keepPIvars(trim($this->pi_getLL('pi_list_browseresults_page','Page',TRUE).' '.($a+1)),array('pointer'=>($a?$a:'')),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
00453                                 '</p></td>';
00454                 }
00455                 if ($pointer<ceil($count/$results_at_a_time)-1) {
00456                         $links[]='
00457                                         <td nowrap="nowrap"><p>'.
00458                                 $this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_next','Next >',TRUE),array('pointer'=>$pointer+1)).
00459                                 '</p></td>';
00460                 }
00461 
00462                 $pR1 = $pointer*$results_at_a_time+1;
00463                 $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
00464                 $sTables = '
00465 
00466                 <!--
00467                         List browsing box:
00468                 -->
00469                 <div'.$this->pi_classParam('browsebox').'>'.
00470                         ($showResultCount ? '
00471                         <p>'.
00472                                 ($this->internal['res_count'] ?
00473                         sprintf(
00474                                         str_replace('###SPAN_BEGIN###','<span'.$this->pi_classParam('browsebox-strong').'>',$this->pi_getLL('pi_list_browseresults_displays','Displaying results ###SPAN_BEGIN###%s to %s</span> out of ###SPAN_BEGIN###%s</span>')),
00475                                         $this->internal['res_count'] > 0 ? $pR1 : 0,
00476                                         min(array($this->internal['res_count'],$pR2)),
00477                                         $this->internal['res_count']
00478                                 ) :
00479                                 $this->pi_getLL('pi_list_browseresults_noResults','Sorry, no items were found.')).'</p>':''
00480                         ).
00481                 '
00482 
00483                         <'.trim('table '.$tableParams).'>
00484                                 <tr>
00485                                         '.implode('',$links).'
00486                                 </tr>
00487                         </table>
00488                 </div>';
00489 
00490                 return $sTables;
00491         }
00492 
00500         function pi_list_searchBox($tableParams='')     {
00501                         // Search box design:
00502                 $sTables = '
00503 
00504                 <!--
00505                         List search box:
00506                 -->
00507                 <div'.$this->pi_classParam('searchbox').'>
00508                         <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
00509                         <'.trim('table '.$tableParams).'>
00510                                 <tr>
00511                                         <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
00512                                         <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' />'.
00513                                                 '<input type="hidden" name="no_cache" value="1" />'.
00514                                                 '<input type="hidden" name="'.$this->prefixId.'[pointer]" value="" />'.
00515                                                 '</td>
00516                                 </tr>
00517                         </table>
00518                         </form>
00519                 </div>';
00520 
00521                 return $sTables;
00522         }
00523 
00531         function pi_list_modeSelector($items=array(),$tableParams='')   {
00532                 $cells=array();
00533                 reset($items);
00534                 while(list($k,$v)=each($items)) {
00535                         $cells[]='
00536                                         <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
00537                                 $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
00538                                 '</p></td>';
00539                 }
00540 
00541                 $sTables = '
00542 
00543                 <!--
00544                         Mode selector (menu for list):
00545                 -->
00546                 <div'.$this->pi_classParam('modeSelector').'>
00547                         <'.trim('table '.$tableParams).'>
00548                                 <tr>
00549                                         '.implode('',$cells).'
00550                                 </tr>
00551                         </table>
00552                 </div>';
00553 
00554                 return $sTables;
00555         }
00556 
00569         function pi_list_makelist($res,$tableParams='') {
00570                         // Make list table header:
00571                 $tRows=array();
00572                 $this->internal['currentRow']='';
00573                 $tRows[] = $this->pi_list_header();
00574 
00575                         // Make list table rows
00576                 $c=0;
00577                 while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00578                         $tRows[] = $this->pi_list_row($c);
00579                         $c++;
00580                 }
00581 
00582                 $out = '
00583 
00584                 <!--
00585                         Record list:
00586                 -->
00587                 <div'.$this->pi_classParam('listrow').'>
00588                         <'.trim('table '.$tableParams).'>
00589                                 '.implode('',$tRows).'
00590                         </table>
00591                 </div>';
00592 
00593                 return $out;
00594         }
00595 
00604         function pi_list_row($c)        {
00605                 // Dummy
00606                 return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
00607         }
00608 
00616         function pi_list_header()       {
00617                 return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
00618         }
00619 
00620 
00621 
00622 
00623 
00624 
00625 
00626 
00627 
00628 
00629 
00630 
00631 
00632 
00633 
00634         /***************************
00635          *
00636          * Stylesheet, CSS
00637          *
00638          **************************/
00639 
00640 
00647         function pi_getClassName($class)        {
00648                 return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
00649         }
00650 
00659         function pi_classParam($class)  {
00660                 return ' class="'.$this->pi_getClassName($class).'"';
00661         }
00662 
00673         function pi_setClassStyle($class,$data,$selector='')    {
00674                 $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
00675         }
00676 
00684         function pi_wrapInBaseClass($str)       {
00685                 return '
00686 
00687 
00688         <!--
00689 
00690                 BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
00691 
00692         -->
00693         <div class="'.str_replace('_','-',$this->prefixId).'">
00694                 '.$str.'
00695         </div>
00696         <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
00697 
00698         ';
00699         }
00700 
00701 
00702 
00703 
00704 
00705 
00706 
00707 
00708 
00709 
00710 
00711 
00712 
00713 
00714 
00715 
00716 
00717         /***************************
00718          *
00719          * Frontend editing: Edit panel, edit icons
00720          *
00721          **************************/
00722 
00733         function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
00734                 $panel='';
00735                 if (!$row || !$tablename)       {
00736                         $row = $this->internal['currentRow'];
00737                         $tablename = $this->internal['currentTable'];
00738                 }
00739 
00740                 if ($GLOBALS['TSFE']->beUserLogin)      {
00741                                 // Create local cObj if not set:
00742                         if (!is_object($this->pi_EPtemp_cObj))  {
00743                                 $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
00744                                 $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
00745                         }
00746 
00747                                 // Initialize the cObj object with current row
00748                         $this->pi_EPtemp_cObj->start($row,$tablename);
00749 
00750                                 // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
00751                         $conf['allow'] = 'edit,new,delete,move,hide';
00752                         $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
00753                 }
00754 
00755                 if ($panel)     {
00756                         if ($label)     {
00757                                 return '<!-- BEGIN: EDIT PANEL --><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td valign="top">'.$label.'</td><td valign="top" align="right">'.$panel.'</td></tr></table><!-- END: EDIT PANEL -->';
00758                         } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
00759                 } else return $label;
00760         }
00761 
00775         function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array())        {
00776                 if ($GLOBALS['TSFE']->beUserLogin){
00777                         if (!$row || !$tablename)       {
00778                                 $row = $this->internal['currentRow'];
00779                                 $tablename = $this->internal['currentTable'];
00780                         }
00781                         $conf=array_merge(array(
00782                                 'beforeLastTag'=>1,
00783                                 'iconTitle' => $title
00784                         ),$oConf);
00785                         $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
00786                 }
00787                 return $content;
00788         }
00789 
00790 
00791 
00792 
00793 
00794 
00795 
00796 
00797 
00798 
00799 
00800 
00801 
00802 
00803 
00804 
00805 
00806         /***************************
00807          *
00808          * Localization, locallang functions
00809          *
00810          **************************/
00811 
00812 
00822         function pi_getLL($key,$alt='',$hsc=FALSE)      {
00823                 if (isset($this->LOCAL_LANG[$this->LLkey][$key]))       {
00824                         $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key]);
00825                 } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
00826                         $word = $this->LOCAL_LANG['default'][$key];
00827                 } else {
00828                         $word = $this->LLtestPrefixAlt.$alt;
00829                 }
00830 
00831                 $output = $this->LLtestPrefix.$word;
00832                 if ($hsc)       $output = htmlspecialchars($output);
00833 
00834                 return $output;
00835         }
00836 
00843         function pi_loadLL()    {
00844                 if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath)  {
00845                         $basePath = t3lib_extMgm::siteRelPath($this->extKey).dirname($this->scriptRelPath).'/locallang.php';
00846                         if (@is_file($basePath))        {
00847                                 include('./'.$basePath);
00848                                 $this->LOCAL_LANG = $LOCAL_LANG;
00849                                 if (is_array($this->conf['_LOCAL_LANG.']))      {
00850                                         reset($this->conf['_LOCAL_LANG.']);
00851                                         while(list($k,$lA)=each($this->conf['_LOCAL_LANG.']))   {
00852                                                 if (is_array($lA))      {
00853                                                         $k = substr($k,0,-1);
00854                                                         $this->LOCAL_LANG[$k] = t3lib_div::array_merge_recursive_overrule(is_array($this->LOCAL_LANG[$k])?$this->LOCAL_LANG[$k]:array(), $lA);
00855                                                 }
00856                                         }
00857                                 }
00858                         }
00859                 }
00860                 $this->LOCAL_LANG_loaded = 1;
00861         }
00862 
00863 
00864 
00865 
00866 
00867 
00868 
00869 
00870 
00871 
00872 
00873 
00874 
00875 
00876 
00877 
00878 
00879 
00880 
00881 
00882 
00883 
00884 
00885         /***************************
00886          *
00887          * Database, queries
00888          *
00889          **************************/
00890 
00908         function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)       {
00909 
00910                         // Begin Query:
00911                 if (!$query)    {
00912                                 // Fetches the list of PIDs to select from.
00913                                 // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
00914                                 // 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.
00915                         $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
00916                         if (is_array($mm_cat))  {
00917                                 $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).
00918                                                 ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).
00919                                                 (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).
00920                                                 ' AND '.$table.'.pid IN ('.$pidList.')'.chr(10).
00921                                                 $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!
00922                         } else {
00923                                 $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10).
00924                                                 $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!
00925                         }
00926                 }
00927 
00928                         // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
00929                 list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
00930                 $TABLENAMES = trim(substr(trim($TABLENAMES),5));
00931                 $WHERE = trim($WHERE);
00932 
00933                         // Add '$addWhere'
00934                 if ($addWhere)  {$WHERE.=' '.$addWhere.chr(10);}
00935 
00936                         // Search word:
00937                 if ($this->piVars['sword'] && $this->internal['searchFieldList'])       {
00938                         $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);
00939                 }
00940 
00941                 if ($count) {
00942                         $queryParts = array(
00943                                 'SELECT' => 'count(*)',
00944                                 'FROM' => $TABLENAMES,
00945                                 'WHERE' => $WHERE,
00946                                 'GROUPBY' => '',
00947                                 'ORDERBY' => '',
00948                                 'LIMIT' => ''
00949                         );
00950                 } else {
00951                                 // Order by data:
00952                         if (!$orderBy)  {
00953                                 if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy']))       {
00954                                         $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
00955                                 }
00956                         }
00957 
00958                                 // Limit data:
00959                         $pointer = $this->piVars['pointer'];
00960                         $pointer = intval($pointer);
00961                         $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
00962                         $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
00963 
00964                                 // Add 'SELECT'
00965                         $queryParts = array(
00966                                 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
00967                                 'FROM' => $TABLENAMES,
00968                                 'WHERE' => $WHERE,
00969                                 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
00970                                 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
00971                                 'LIMIT' => $LIMIT
00972                         );
00973                 }
00974 
00975                 $query = $GLOBALS['TYPO3_DB']->SELECTquery (
00976                                         $queryParts['SELECT'],
00977                                         $queryParts['FROM'],
00978                                         $queryParts['WHERE'],
00979                                         $queryParts['GROUPBY'],
00980                                         $queryParts['ORDERBY'],
00981                                         $queryParts['LIMIT']
00982                                 );
00983                 return $returnQueryArray ? $queryParts : $query;
00984         }
00985 
01000         function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')       {
01001                 $queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);
01002 
01003                 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
01004         }
01005 
01015         function pi_getRecord($table,$uid,$checkPage=0) {
01016                 return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
01017         }
01018 
01026         function pi_getPidList($pid_list,$recursive=0)  {
01027                 if (!strcmp($pid_list,''))      $pid_list = $GLOBALS['TSFE']->id;
01028                 $recursive = t3lib_div::intInRange($recursive,0);
01029 
01030                 $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));
01031                 $pid_list = array();
01032 
01033                 foreach($pid_list_arr as $val)  {
01034                         $val = t3lib_div::intInRange($val,0);
01035                         if ($val)       {
01036                                 $_list = $this->cObj->getTreeList(-1*$val, $recursive);
01037                                 if ($_list)             $pid_list[] = $_list;
01038                         }
01039                 }
01040 
01041                 return implode(',', $pid_list);
01042         }
01043 
01051         function pi_prependFieldsWithTable($table,$fieldList)   {
01052                 $list=t3lib_div::trimExplode(',',$fieldList,1);
01053                 $return=array();
01054                 while(list(,$listItem)=each($list))     {
01055                         $return[]=$table.'.'.$listItem;
01056                 }
01057                 return implode(',',$return);
01058         }
01059 
01071         function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')     {
01072                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01073                                         '*',
01074                                         $table,
01075                                         'pid='.intval($pid).
01076                                                 $this->cObj->enableFields($table).' '.
01077                                                 $whereClause,   // whereClauseMightContainGroupOrderBy
01078                                         $groupBy,
01079                                         $orderBy,
01080                                         $limit
01081                                 );
01082                 $outArr = array();
01083                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
01084                         $outArr[$row['uid']] = $row;
01085                 }
01086                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01087                 return $outArr;
01088         }
01089 
01090 
01091 
01092 
01093 
01094 
01095 
01096 
01097 
01098 
01099 
01100 
01101         /***************************
01102          *
01103          * Various
01104          *
01105          **************************/
01106 
01115         function pi_isOnlyFields($fList,$lowerThan=-1)  {
01116                 $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;
01117 
01118                 $fList = t3lib_div::trimExplode(',',$fList,1);
01119                 $tempPiVars = $this->piVars;
01120                 while(list(,$k)=each($fList))   {
01121                         if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan)         unset($tempPiVars[$k]);
01122                 }
01123                 if (!count($tempPiVars))        return 1;
01124         }
01125 
01135         function pi_autoCache($inArray) {
01136                 if (is_array($inArray)) {
01137                         reset($inArray);
01138                         while(list($fN,$fV)=each($inArray))     {
01139                                 if (!strcmp($inArray[$fN],''))  {
01140                                         unset($inArray[$fN]);
01141                                 } elseif (is_array($this->pi_autoCacheFields[$fN]))     {
01142                                         if (is_array($this->pi_autoCacheFields[$fN]['range'])
01143                                                          && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])
01144                                                          && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1]))  {
01145                                                                 unset($inArray[$fN]);
01146                                         }
01147                                         if (is_array($this->pi_autoCacheFields[$fN]['list'])
01148                                                          && in_array($inArray[$fN],$this->pi_autoCacheFields[$fN]['list']))     {
01149                                                                 unset($inArray[$fN]);
01150                                         }
01151                                 }
01152                         }
01153                 }
01154                 if (!count($inArray))   return 1;
01155         }
01156 
01166         function pi_RTEcssText($str)    {
01167                 $parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];
01168                 if (is_array($parseFunc))       $str = $this->cObj->parseFunc($str, $parseFunc);
01169                 return $str;
01170         }
01171 
01172 
01173 
01174 
01175 
01176         /*******************************
01177          *
01178          * FlexForms related functions
01179          *
01180          *******************************/
01181 
01187         function pi_initPIflexForm()    {
01188                         // Converting flexform data into array:
01189                 if (!is_array($this->cObj->data['pi_flexform']) && $this->cObj->data['pi_flexform'])    {
01190                         $this->cObj->data['pi_flexform'] = t3lib_div::xml2array($this->cObj->data['pi_flexform']);
01191                         if (!is_array($this->cObj->data['pi_flexform']))        $this->cObj->data['pi_flexform']=array();
01192                 }
01193         }
01194 
01205         function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')   {
01206                 $sheetArray = $T3FlexForm_array['data'][$sheet][$lang];
01207                 if (is_array($sheetArray))      {
01208                         return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
01209                 }
01210         }
01211 
01222         function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)  {
01223 
01224                 $tempArr=$sheetArray;
01225                 foreach($fieldNameArr as $k => $v)      {
01226                         if (t3lib_div::testInt($v))     {
01227                                 if (is_array($tempArr)) {
01228                                         $c=0;
01229                                         foreach($tempArr as $values)    {
01230                                                 if ($c==$v)     {
01231                                                         #debug($values);
01232                                                         $tempArr=$values;
01233                                                         break;
01234                                                 }
01235                                                 $c++;
01236                                         }
01237                                 }
01238                         } else {
01239                                 $tempArr = $tempArr[$v];
01240                         }
01241                 }
01242                 return $tempArr[$value];
01243         }
01244 }
01245 
01246 // NO extension of class - does not make sense here.
01247 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6