Documentation TYPO3 par Ameos

class.tslib_pibase.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 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 ***************************************************************/
00121 class tslib_pibase {
00122 
00123                 // Reserved variables:
00124         var $cObj;              // The backReference to the mother cObj object set at call time
00125         var $prefixId;          // Should be same as classname of the plugin, used for CSS classes, variables
00126         var $scriptRelPath;     // Path to the plugin class script relative to extension directory, eg. 'pi1/class.tx_newfaq_pi1.php'
00127         var $extKey;            // Extension key.
00128         var $piVars = Array (   // This is the incoming 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[...]=...
00129                 'pointer' => '',                // Used as a pointer for lists
00130                 'mode' => '',                   // List mode
00131                 'sword' => '',                  // Search word
00132                 'sort' => '',                   // [Sorting column]:[ASC=0/DESC=1]
00133         );
00134         var $internal = Array(  // Used internally for general storage of values between methods
00135                 'res_count' => 0,               // Total query count
00136                 'results_at_a_time' => 20,      // pi_list_browseresults(): Show number of results at a time
00137                 'maxPages' => 10,               // pi_list_browseresults(): Max number of 'Page 1 - Page 2 - ...' in the list browser
00138                 'currentRow' => Array(),        // Current result row
00139                 'currentTable' => '',           // Current table
00140         );
00141 
00142         var $LOCAL_LANG = Array();              // Local Language content
00143         var $LOCAL_LANG_charset = Array();      // Local Language content charset for individual labels (overriding)
00144         var $LOCAL_LANG_loaded = 0;             // Flag that tells if the locallang file has been fetch (or tried to be fetched) already.
00145         var $LLkey='default';                   // Pointer to the language to use.
00146         var $altLLkey='';                       // Pointer to alternative fall-back language to use.
00147         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.
00148         var $LLtestPrefixAlt='';                // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
00149 
00150         var $pi_isOnlyFields = 'mode,pointer';
00151         var $pi_alwaysPrev = 0;
00152         var $pi_lowerThan = 5;
00153         var $pi_moreParams='';
00154         var $pi_listFields='*';
00155 
00156         var $pi_autoCacheFields=array();
00157         var $pi_autoCacheEn=0;
00158 
00159         var $pi_USER_INT_obj = FALSE;           // If set, then links are 1) not using cHash and 2) not allowing pages to be cached. (Set this for all USER_INT plugins!)
00160         var $pi_checkCHash = FALSE;             // If set, then caching is disabled if piVars are incoming while no cHash was set (Set this for all USER plugins!)
00161 
00168         var $conf = Array();
00169 
00170         // internal, don't mess with...
00171         var $pi_EPtemp_cObj;
00172         var $pi_tmpPageId=0;
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190         /***************************
00191          *
00192          * Init functions
00193          *
00194          **************************/
00195 
00203         function tslib_pibase() {
00204 
00205                         // Setting piVars:
00206                 if ($this->prefixId)    {
00207                         $this->piVars = t3lib_div::GParrayMerged($this->prefixId);
00208 
00209                                 // cHash mode check
00210                                 // IMPORTANT FOR CACHED PLUGINS (USER cObject): As soon as you generate cached plugin output which depends on parameters (eg. seeing the details of a news item) you MUST check if a cHash value is set.
00211                                 // Background: The function call will check if a cHash parameter was sent with the URL because only if it was the page may be cached. If no cHash was found the function will simply disable caching to avoid unpredictable caching behaviour. In any case your plugin can generate the expected output and the only risk is that the content may not be cached. A missing cHash value is considered a mistake in the URL resulting from either URL manipulation, "realurl" "grayzones" etc. The problem is rare (more frequent with "realurl") but when it occurs it is very puzzling!
00212                         if ($this->pi_checkCHash && count($this->piVars))       {
00213                                 $GLOBALS['TSFE']->reqCHash();
00214                         }
00215                 }
00216                 if ($GLOBALS['TSFE']->config['config']['language'])     {
00217                         $this->LLkey = $GLOBALS['TSFE']->config['config']['language'];
00218                         if ($GLOBALS['TSFE']->config['config']['language_alt']) {
00219                                 $this->altLLkey = $GLOBALS['TSFE']->config['config']['language_alt'];
00220                         }
00221                 }
00222         }
00223 
00229         function pi_setPiVarDefaults()  {
00230                 if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
00231                         $this->piVars = t3lib_div::array_merge_recursive_overrule($this->conf['_DEFAULT_PI_VARS.'],is_array($this->piVars)?$this->piVars:array());
00232                 }
00233         }
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247         /***************************
00248          *
00249          * Link functions
00250          *
00251          **************************/
00252 
00266         function pi_getPageLink($id,$target='',$urlParameters=array())  {
00267                 return $this->cObj->getTypoLink_URL($id,$urlParameters,$target);        // ?$target:$GLOBALS['TSFE']->sPre
00268         }
00269 
00282         function pi_linkToPage($str,$id,$target='',$urlParameters=array())      {
00283                 return $this->cObj->getTypoLink($str,$id,$urlParameters,$target);       // ?$target:$GLOBALS['TSFE']->sPre
00284         }
00285 
00297         function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0)   {
00298                 $conf=array();
00299                 $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
00300                 $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
00301                 $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id);
00302                 $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('',$urlParameters,'',1).$this->pi_moreParams;
00303 
00304                 return $this->cObj->typoLink($str, $conf);
00305         }
00306 
00320         function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)        {
00321                 if (is_array($this->piVars) && is_array($overrulePIvars) && !$clearAnyway)      {
00322                         $piVars = $this->piVars;
00323                         unset($piVars['DATA']);
00324                         $overrulePIvars = t3lib_div::array_merge_recursive_overrule($piVars,$overrulePIvars);
00325                         if ($this->pi_autoCacheEn)      {
00326                                 $cache = $this->pi_autoCache($overrulePIvars);
00327                         }
00328                 }
00329                 $res = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
00330                 return $res;
00331         }
00332 
00344         function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) {
00345                 $this->pi_linkTP_keepPIvars('|',$overrulePIvars,$cache,$clearAnyway,$altPageId);
00346                 return $this->cObj->lastTypoLinkUrl;
00347         }
00348 
00362         function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0)       {
00363                 if ($this->prefixId)    {
00364                         if ($cache)     {
00365                                 $overrulePIvars=$uid?array('showUid'=>$uid):Array();
00366                                 $overrulePIvars=array_merge($overrulePIvars,(array)$mergeArr);
00367                                 $str = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
00368                         } else {
00369                                 $overrulePIvars=array('showUid'=>$uid?$uid:'');
00370                                 $overrulePIvars=array_merge($overrulePIvars,(array)$mergeArr);
00371                                 $str = $this->pi_linkTP_keepPIvars($str,$overrulePIvars,$cache,0,$altPageId);
00372                         }
00373 
00374                                 // If urlOnly flag, return only URL as it has recently be generated.
00375                         if ($urlOnly)   {
00376                                 $str = $this->cObj->lastTypoLinkUrl;
00377                         }
00378                 }
00379                 return $str;
00380         }
00381 
00390         function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')      {
00391                 if (eregi('(.*)(<a[^>]*>)(.*)',$str,$match))    {
00392                         $aTagContent = t3lib_div::get_tag_attributes($match[2]);
00393                         $match[2]='<a href="#" onclick="'.
00394                                 htmlspecialchars('vHWin=window.open(\''.$GLOBALS['TSFE']->baseUrlWrap($aTagContent['href']).'\',\''.($winName?$winName:md5($aTagContent['href'])).'\',\''.$winParams.'\');vHWin.focus();return false;').
00395                                 '">';
00396                         $str=$match[1].$match[2].$match[3];
00397                 }
00398                 return $str;
00399         }
00400 
00401 
00402 
00403 
00404 
00405 
00406 
00407 
00408 
00409 
00410 
00411 
00412 
00413 
00414         /***************************
00415          *
00416          * Functions for listing, browsing, searching etc.
00417          *
00418          **************************/
00419 
00443         function pi_list_browseresults($showResultCount=1, $tableParams='', $wrapArr=array(), $pointerName='pointer', $hscText=TRUE)    {
00444 
00445                 // example $wrapArr-array how it could be traversed from an extension
00446                 /* $wrapArr = array(
00447                         'browseBoxWrap' => '<div class="browseBoxWrap">|</div>',
00448                         'showResultsWrap' => '<div class="showResultsWrap">|</div>',
00449                         'browseLinksWrap' => '<div class="browseLinksWrap">|</div>',
00450                         'showResultsNumbersWrap' => '<span class="showResultsNumbersWrap">|</span>',
00451                         'disabledLinkWrap' => '<span class="disabledLinkWrap">|</span>',
00452                         'inactiveLinkWrap' => '<span class="inactiveLinkWrap">|</span>',
00453                         'activeLinkWrap' => '<span class="activeLinkWrap">|</span>'
00454                 ); */
00455 
00456                         // Initializing variables:
00457                 $pointer = intval($this->piVars[$pointerName]);
00458                 $count = intval($this->internal['res_count']);
00459                 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
00460                 $totalPages = ceil($count/$results_at_a_time);
00461                 $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
00462                 $pi_isOnlyFields = $this->pi_isOnlyFields($this->pi_isOnlyFields);
00463 
00464                         // $showResultCount determines how the results of the pagerowser will be shown.
00465                         // If set to 0: only the result-browser will be shown
00466                         //                       1: (default) the text "Displaying results..." and the result-browser will be shown.
00467                         //                       2: only the text "Displaying results..." will be shown
00468                 $showResultCount = intval($showResultCount);
00469 
00470                         // if this is set, two links named "<< First" and "LAST >>" will be shown and point to the very first or last page.
00471                 $showFirstLast = $this->internal['showFirstLast'];
00472 
00473                         // if this has a value the "previous" button is always visible (will be forced if "showFirstLast" is set)
00474                 $alwaysPrev = $showFirstLast?1:$this->pi_alwaysPrev;
00475 
00476                 if (isset($this->internal['pagefloat'])) {
00477                         if (strtoupper($this->internal['pagefloat']) == 'CENTER') {
00478                                 $pagefloat = ceil(($maxPages - 1)/2);
00479                         } else {
00480                                 // pagefloat set as integer. 0 = left, value >= $this->internal['maxPages'] = right
00481                                 $pagefloat = t3lib_div::intInRange($this->internal['pagefloat'],-1,$maxPages-1);
00482                         }
00483                 } else {
00484                         $pagefloat = -1; // pagefloat disabled
00485                 }
00486 
00487                         // default values for "traditional" wrapping with a table. Can be overwritten by vars from $wrapArr
00488                 $wrapper['disabledLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
00489                 $wrapper['inactiveLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
00490                 $wrapper['activeLinkWrap'] = '<td'.$this->pi_classParam('browsebox-SCell').' nowrap="nowrap"><p>|</p></td>';
00491                 $wrapper['browseLinksWrap'] = trim('<table '.$tableParams).'><tr>|</tr></table>';
00492                 $wrapper['showResultsWrap'] = '<p>|</p>';
00493                 $wrapper['browseBoxWrap'] = '
00494                 <!--
00495                         List browsing box:
00496                 -->
00497                 <div '.$this->pi_classParam('browsebox').'>
00498                         |
00499                 </div>';
00500 
00501                         // now overwrite all entries in $wrapper which are also in $wrapArr
00502                 $wrapper = array_merge($wrapper,$wrapArr);
00503 
00504                 if ($showResultCount != 2) { //show pagebrowser
00505                         if ($pagefloat > -1) {
00506                                 $lastPage = min($totalPages,max($pointer+1 + $pagefloat,$maxPages));
00507                                 $firstPage = max(0,$lastPage-$maxPages);
00508                         } else {
00509                                 $firstPage = 0;
00510                                 $lastPage = t3lib_div::intInRange($totalPages,1,$maxPages);
00511                         }
00512                         $links=array();
00513 
00514                                 // Make browse-table/links:
00515                         if ($showFirstLast) { // Link to first page
00516                                 if ($pointer>0) {
00517                                         $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),array($pointerName => null),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
00518                                 } else {
00519                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),$wrapper['disabledLinkWrap']);
00520                                 }
00521                         }
00522                         if ($alwaysPrev>=0)     { // Link to previous page
00523                                 if ($pointer>0) {
00524                                         $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),array($pointerName => ($pointer-1?$pointer-1:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
00525                                 } elseif ($alwaysPrev)  {
00526                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),$wrapper['disabledLinkWrap']);
00527                                 }
00528                         }
00529                         for($a=$firstPage;$a<$lastPage;$a++)    { // Links to pages
00530                                 if ($this->internal['showRange']) {
00531                                         $pageText = (($a*$results_at_a_time)+1).'-'.min($count,(($a+1)*$results_at_a_time));
00532                                 } else {
00533                                         $pageText = trim($this->pi_getLL('pi_list_browseresults_page','Page',$hscText).' '.($a+1));
00534                                 }
00535                                 if ($pointer == $a) { // current page
00536                                         if ($this->internal['dontLinkActivePage']) {
00537                                                 $links[] = $this->cObj->wrap($pageText,$wrapper['activeLinkWrap']);
00538                                         } else {
00539                                                 $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName  => ($a?$a:'')),$pi_isOnlyFields),$wrapper['activeLinkWrap']);
00540                                         }
00541                                 } else {
00542                                         $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
00543                                 }
00544                         }
00545                         if ($pointer<$totalPages-1 || $showFirstLast)   {
00546                                 if ($pointer==$totalPages-1) { // Link to next page
00547                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),$wrapper['disabledLinkWrap']);
00548                                 } else {
00549                                         $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),array($pointerName => $pointer+1),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
00550                                 }
00551                         }
00552                         if ($showFirstLast) { // Link to last page
00553                                 if ($pointer<$totalPages-1) {
00554                                         $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),array($pointerName => $totalPages-1),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
00555                                 } else {
00556                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),$wrapper['disabledLinkWrap']);
00557                                 }
00558                         }
00559                         $theLinks = $this->cObj->wrap(implode(chr(10),$links),$wrapper['browseLinksWrap']);
00560                 } else {
00561                         $theLinks = '';
00562                 }
00563 
00564                 $pR1 = $pointer*$results_at_a_time+1;
00565                 $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
00566 
00567                 if ($showResultCount) {
00568                         if ($wrapper['showResultsNumbersWrap']) {
00569                                 // this will render the resultcount in a more flexible way using markers (new in TYPO3 3.8.0).
00570                                 // the formatting string is expected to hold template markers (see function header). Example: 'Displaying results ###FROM### to ###TO### out of ###OUT_OF###'
00571 
00572                                 $markerArray['###FROM###'] = $this->cObj->wrap($this->internal['res_count'] > 0 ? $pR1 : 0,$wrapper['showResultsNumbersWrap']);
00573                                 $markerArray['###TO###'] = $this->cObj->wrap(min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
00574                                 $markerArray['###OUT_OF###'] = $this->cObj->wrap($this->internal['res_count'],$wrapper['showResultsNumbersWrap']);
00575                                 $markerArray['###FROM_TO###'] = $this->cObj->wrap(($this->internal['res_count'] > 0 ? $pR1 : 0).' '.$this->pi_getLL('pi_list_browseresults_to','to').' '.min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
00576                                 $markerArray['###CURRENT_PAGE###'] = $this->cObj->wrap($pointer+1,$wrapper['showResultsNumbersWrap']);
00577                                 $markerArray['###TOTAL_PAGES###'] = $this->cObj->wrap($totalPages,$wrapper['showResultsNumbersWrap']);
00578                                 // substitute markers
00579                                 $resultCountMsg = $this->cObj->substituteMarkerArray($this->pi_getLL('pi_list_browseresults_displays','Displaying results ###FROM### to ###TO### out of ###OUT_OF###'),$markerArray);
00580                         } else {
00581                                 // render the resultcount in the "traditional" way using sprintf
00582                                 $resultCountMsg = sprintf(
00583                                         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>')),
00584                                         $count > 0 ? $pR1 : 0,
00585                                         min($count,$pR2),
00586                                         $count);
00587                         }
00588                         $resultCountMsg = $this->cObj->wrap($resultCountMsg,$wrapper['showResultsWrap']);
00589                 } else {
00590                         $resultCountMsg = '';
00591                 }
00592 
00593                 $sTables = $this->cObj->wrap($resultCountMsg.$theLinks,$wrapper['browseBoxWrap']);
00594 
00595                 return $sTables;
00596         }
00597 
00605         function pi_list_searchBox($tableParams='')     {
00606                         // Search box design:
00607                 $sTables = '
00608 
00609                 <!--
00610                         List search box:
00611                 -->
00612                 <div'.$this->pi_classParam('searchbox').'>
00613                         <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
00614                         <'.trim('table '.$tableParams).'>
00615                                 <tr>
00616                                         <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
00617                                         <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' />'.
00618                                                 '<input type="hidden" name="no_cache" value="1" />'.
00619                                                 '<input type="hidden" name="'.$this->prefixId.'[pointer]" value="" />'.
00620                                                 '</td>
00621                                 </tr>
00622                         </table>
00623                         </form>
00624                 </div>';
00625 
00626                 return $sTables;
00627         }
00628 
00636         function pi_list_modeSelector($items=array(),$tableParams='')   {
00637                 $cells=array();
00638                 reset($items);
00639                 while(list($k,$v)=each($items)) {
00640                         $cells[]='
00641                                         <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
00642                                 $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
00643                                 '</p></td>';
00644                 }
00645 
00646                 $sTables = '
00647 
00648                 <!--
00649                         Mode selector (menu for list):
00650                 -->
00651                 <div'.$this->pi_classParam('modeSelector').'>
00652                         <'.trim('table '.$tableParams).'>
00653                                 <tr>
00654                                         '.implode('',$cells).'
00655                                 </tr>
00656                         </table>
00657                 </div>';
00658 
00659                 return $sTables;
00660         }
00661 
00674         function pi_list_makelist($res,$tableParams='') {
00675                         // Make list table header:
00676                 $tRows=array();
00677                 $this->internal['currentRow']='';
00678                 $tRows[] = $this->pi_list_header();
00679 
00680                         // Make list table rows
00681                 $c=0;
00682                 while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00683                         $tRows[] = $this->pi_list_row($c);
00684                         $c++;
00685                 }
00686 
00687                 $out = '
00688 
00689                 <!--
00690                         Record list:
00691                 -->
00692                 <div'.$this->pi_classParam('listrow').'>
00693                         <'.trim('table '.$tableParams).'>
00694                                 '.implode('',$tRows).'
00695                         </table>
00696                 </div>';
00697 
00698                 return $out;
00699         }
00700 
00709         function pi_list_row($c)        {
00710                 // Dummy
00711                 return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
00712         }
00713 
00721         function pi_list_header()       {
00722                 return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
00723         }
00724 
00725 
00726 
00727 
00728 
00729 
00730 
00731 
00732 
00733 
00734 
00735 
00736 
00737 
00738 
00739         /***************************
00740          *
00741          * Stylesheet, CSS
00742          *
00743          **************************/
00744 
00745 
00752         function pi_getClassName($class)        {
00753                 return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
00754         }
00755 
00765         function pi_classParam($class, $addClasses='')  {
00766                 $output = '';
00767                 foreach (t3lib_div::trimExplode(',',$class) as $v)      {
00768                         $output.= ' '.$this->pi_getClassName($v);
00769                 }
00770                 foreach (t3lib_div::trimExplode(',',$addClasses) as $v) {
00771                         $output.= ' '.$v;
00772                 }
00773                 return ' class="'.trim($output).'"';
00774         }
00775 
00786         function pi_setClassStyle($class,$data,$selector='')    {
00787                 $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
00788         }
00789 
00797         function pi_wrapInBaseClass($str)       {
00798                 $content = '<div class="'.str_replace('_','-',$this->prefixId).'">
00799                 '.$str.'
00800         </div>
00801         ';
00802 
00803                 if(!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
00804                         $content = '
00805 
00806 
00807         <!--
00808 
00809                 BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
00810 
00811         -->
00812         '.$content.'
00813         <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
00814 
00815         ';
00816                 }
00817 
00818                 return $content;
00819         }
00820 
00821 
00822 
00823 
00824 
00825 
00826 
00827 
00828 
00829 
00830 
00831 
00832 
00833 
00834 
00835 
00836 
00837         /***************************
00838          *
00839          * Frontend editing: Edit panel, edit icons
00840          *
00841          **************************/
00842 
00853         function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
00854                 $panel='';
00855                 if (!$row || !$tablename)       {
00856                         $row = $this->internal['currentRow'];
00857                         $tablename = $this->internal['currentTable'];
00858                 }
00859 
00860                 if ($GLOBALS['TSFE']->beUserLogin)      {
00861                                 // Create local cObj if not set:
00862                         if (!is_object($this->pi_EPtemp_cObj))  {
00863                                 $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
00864                                 $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
00865                         }
00866 
00867                                 // Initialize the cObj object with current row
00868                         $this->pi_EPtemp_cObj->start($row,$tablename);
00869 
00870                                 // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
00871                         $conf['allow'] = 'edit,new,delete,move,hide';
00872                         $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
00873                 }
00874 
00875                 if ($panel)     {
00876                         if ($label)     {
00877                                 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 -->';
00878                         } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
00879                 } else return $label;
00880         }
00881 
00895         function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array())        {
00896                 if ($GLOBALS['TSFE']->beUserLogin){
00897                         if (!$row || !$tablename)       {
00898                                 $row = $this->internal['currentRow'];
00899                                 $tablename = $this->internal['currentTable'];
00900                         }
00901                         $conf=array_merge(array(
00902                                 'beforeLastTag'=>1,
00903                                 'iconTitle' => $title
00904                         ),$oConf);
00905                         $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
00906                 }
00907                 return $content;
00908         }
00909 
00910 
00911 
00912 
00913 
00914 
00915 
00916 
00917 
00918 
00919 
00920 
00921 
00922 
00923 
00924 
00925 
00926         /***************************
00927          *
00928          * Localization, locallang functions
00929          *
00930          **************************/
00931 
00932 
00942         function pi_getLL($key,$alt='',$hsc=FALSE)      {
00943                 if (isset($this->LOCAL_LANG[$this->LLkey][$key]))       {
00944                         $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key], $this->LOCAL_LANG_charset[$this->LLkey][$key]); // The "from" charset is normally empty and thus it will convert from the charset of the system language, but if it is set (see ->pi_loadLL()) it will be used.
00945                 } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key]))   {
00946                         $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->altLLkey][$key], $this->LOCAL_LANG_charset[$this->altLLkey][$key]);   // The "from" charset is normally empty and thus it will convert from the charset of the system language, but if it is set (see ->pi_loadLL()) it will be used.
00947                 } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
00948                         $word = $this->LOCAL_LANG['default'][$key];     // No charset conversion because default is english and thereby ASCII
00949                 } else {
00950                         $word = $this->LLtestPrefixAlt.$alt;
00951                 }
00952 
00953                 $output = $this->LLtestPrefix.$word;
00954                 if ($hsc)       $output = htmlspecialchars($output);
00955 
00956                 return $output;
00957         }
00958 
00965         function pi_loadLL()    {
00966                 if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath)  {
00967                         $basePath = t3lib_extMgm::extPath($this->extKey).dirname($this->scriptRelPath).'/locallang.php';
00968 
00969                                 // php or xml as source: In any case the charset will be that of the system language.
00970                                 // However, this function guarantees only return output for default language plus the specified language (which is different from how 3.7.0 dealt with it)
00971                         $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey);
00972                         if ($this->altLLkey)    {
00973                                 $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
00974                                 $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
00975                         }
00976 
00977                                 // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
00978                         if (is_array($this->conf['_LOCAL_LANG.']))      {
00979                                 reset($this->conf['_LOCAL_LANG.']);
00980                                 while(list($k,$lA)=each($this->conf['_LOCAL_LANG.']))   {
00981                                         if (is_array($lA))      {
00982                                                 $k = substr($k,0,-1);
00983                                                 foreach($lA as $llK => $llV)    {
00984                                                         if (!is_array($llV))    {
00985                                                                 $this->LOCAL_LANG[$k][$llK] = $llV;
00986                                                                 if ($k != 'default')    {
00987                                                                         $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];        // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset" and if that is not set, assumed to be that of the individual system languages (thus no conversion)
00988                                                                 }
00989                                                         }
00990                                                 }
00991                                         }
00992                                 }
00993                         }
00994                 }
00995                 $this->LOCAL_LANG_loaded = 1;
00996         }
00997 
00998 
00999 
01000 
01001 
01002 
01003 
01004 
01005 
01006 
01007 
01008 
01009 
01010 
01011 
01012 
01013 
01014 
01015 
01016 
01017 
01018 
01019 
01020         /***************************
01021          *
01022          * Database, queries
01023          *
01024          **************************/
01025 
01043         function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)       {
01044 
01045                         // Begin Query:
01046                 if (!$query)    {
01047                                 // Fetches the list of PIDs to select from.
01048                                 // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
01049                                 // 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.
01050                         $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
01051                         if (is_array($mm_cat))  {
01052                                 $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).
01053                                                 ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).
01054                                                 (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).
01055                                                 ' AND '.$table.'.pid IN ('.$pidList.')'.chr(10).
01056                                                 $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!
01057                         } else {
01058                                 $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10).
01059                                                 $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!
01060                         }
01061                 }
01062 
01063                         // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
01064                 list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
01065                 $TABLENAMES = trim(substr(trim($TABLENAMES),5));
01066                 $WHERE = trim($WHERE);
01067 
01068                         // Add '$addWhere'
01069                 if ($addWhere)  {$WHERE.=' '.$addWhere.chr(10);}
01070 
01071                         // Search word:
01072                 if ($this->piVars['sword'] && $this->internal['searchFieldList'])       {
01073                         $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);
01074                 }
01075 
01076                 if ($count) {
01077                         $queryParts = array(
01078                                 'SELECT' => 'count(*)',
01079                                 'FROM' => $TABLENAMES,
01080                                 'WHERE' => $WHERE,
01081                                 'GROUPBY' => '',
01082                                 'ORDERBY' => '',
01083                                 'LIMIT' => ''
01084                         );
01085                 } else {
01086                                 // Order by data:
01087                         if (!$orderBy && $this->internal['orderBy'])    {
01088                                 if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy']))       {
01089                                         $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
01090                                 }
01091                         }
01092 
01093                                 // Limit data:
01094                         $pointer = $this->piVars['pointer'];
01095                         $pointer = intval($pointer);
01096                         $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
01097                         $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
01098 
01099                                 // Add 'SELECT'
01100                         $queryParts = array(
01101                                 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
01102                                 'FROM' => $TABLENAMES,
01103                                 'WHERE' => $WHERE,
01104                                 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
01105                                 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
01106                                 'LIMIT' => $LIMIT
01107                         );
01108                 }
01109 
01110                 $query = $GLOBALS['TYPO3_DB']->SELECTquery (
01111                                         $queryParts['SELECT'],
01112                                         $queryParts['FROM'],
01113                                         $queryParts['WHERE'],
01114                                         $queryParts['GROUPBY'],
01115                                         $queryParts['ORDERBY'],
01116                                         $queryParts['LIMIT']
01117                                 );
01118                 return $returnQueryArray ? $queryParts : $query;
01119         }
01120 
01135         function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')       {
01136                 $queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);
01137 
01138                 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
01139         }
01140 
01150         function pi_getRecord($table,$uid,$checkPage=0) {
01151                 return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
01152         }
01153 
01161         function pi_getPidList($pid_list,$recursive=0)  {
01162                 if (!strcmp($pid_list,''))      $pid_list = $GLOBALS['TSFE']->id;
01163                 $recursive = t3lib_div::intInRange($recursive,0);
01164 
01165                 $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));
01166                 $pid_list = array();
01167 
01168                 foreach($pid_list_arr as $val)  {
01169                         $val = t3lib_div::intInRange($val,0);
01170                         if ($val)       {
01171                                 $_list = $this->cObj->getTreeList(-1*$val, $recursive);
01172                                 if ($_list)             $pid_list[] = $_list;
01173                         }
01174                 }
01175 
01176                 return implode(',', $pid_list);
01177         }
01178 
01186         function pi_prependFieldsWithTable($table,$fieldList)   {
01187                 $list=t3lib_div::trimExplode(',',$fieldList,1);
01188                 $return=array();
01189                 while(list(,$listItem)=each($list))     {
01190                         $return[]=$table.'.'.$listItem;
01191                 }
01192                 return implode(',',$return);
01193         }
01194 
01206         function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')     {
01207                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01208                                         '*',
01209                                         $table,
01210                                         'pid='.intval($pid).
01211                                                 $this->cObj->enableFields($table).' '.
01212                                                 $whereClause,   // whereClauseMightContainGroupOrderBy
01213                                         $groupBy,
01214                                         $orderBy,
01215                                         $limit
01216                                 );
01217                 $outArr = array();
01218                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
01219                         $outArr[$row['uid']] = $row;
01220                 }
01221                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01222                 return $outArr;
01223         }
01224 
01225 
01226 
01227 
01228 
01229 
01230 
01231 
01232 
01233 
01234 
01235 
01236         /***************************
01237          *
01238          * Various
01239          *
01240          **************************/
01241 
01250         function pi_isOnlyFields($fList,$lowerThan=-1)  {
01251                 $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;
01252 
01253                 $fList = t3lib_div::trimExplode(',',$fList,1);
01254                 $tempPiVars = $this->piVars;
01255                 while(list(,$k)=each($fList))   {
01256                         if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan)         unset($tempPiVars[$k]);
01257                 }
01258                 if (!count($tempPiVars))        return 1;
01259         }
01260 
01270         function pi_autoCache($inArray) {
01271                 if (is_array($inArray)) {
01272                         reset($inArray);
01273                         while(list($fN,$fV)=each($inArray))     {
01274                                 if (!strcmp($inArray[$fN],''))  {
01275                                         unset($inArray[$fN]);
01276                                 } elseif (is_array($this->pi_autoCacheFields[$fN]))     {
01277                                         if (is_array($this->pi_autoCacheFields[$fN]['range'])
01278                                                          && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])
01279                                                          && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1]))  {
01280                                                                 unset($inArray[$fN]);
01281                                         }
01282                                         if (is_array($this->pi_autoCacheFields[$fN]['list'])
01283                                                          && in_array($inArray[$fN],$this->pi_autoCacheFields[$fN]['list']))     {
01284                                                                 unset($inArray[$fN]);
01285                                         }
01286                                 }
01287                         }
01288                 }
01289                 if (!count($inArray))   return 1;
01290         }
01291 
01301         function pi_RTEcssText($str)    {
01302                 $parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];
01303                 if (is_array($parseFunc))       $str = $this->cObj->parseFunc($str, $parseFunc);
01304                 return $str;
01305         }
01306 
01307 
01308 
01309 
01310 
01311         /*******************************
01312          *
01313          * FlexForms related functions
01314          *
01315          *******************************/
01316 
01323         function pi_initPIflexForm($field='pi_flexform')        {
01324                         // Converting flexform data into array:
01325                 if (!is_array($this->cObj->data[$field]) && $this->cObj->data[$field])  {
01326                         $this->cObj->data[$field] = t3lib_div::xml2array($this->cObj->data[$field]);
01327                         if (!is_array($this->cObj->data[$field]))       $this->cObj->data[$field]=array();
01328                 }
01329         }
01330 
01341         function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')   {
01342                 $sheetArray = is_array($T3FlexForm_array) ? $T3FlexForm_array['data'][$sheet][$lang] : '';
01343                 if (is_array($sheetArray))      {
01344                         return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
01345                 }
01346         }
01347 
01358         function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)  {
01359 
01360                 $tempArr=$sheetArray;
01361                 foreach($fieldNameArr as $k => $v)      {
01362                         if (t3lib_div::testInt($v))     {
01363                                 if (is_array($tempArr)) {
01364                                         $c=0;
01365                                         foreach($tempArr as $values)    {
01366                                                 if ($c==$v)     {
01367                                                         #debug($values);
01368                                                         $tempArr=$values;
01369                                                         break;
01370                                                 }
01371                                                 $c++;
01372                                         }
01373                                 }
01374                         } else {
01375                                 $tempArr = $tempArr[$v];
01376                         }
01377                 }
01378                 return $tempArr[$value];
01379         }
01380 }
01381 
01382 // NO extension of class - does not make sense here.
01383 ?>


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