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 ***************************************************************/
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 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[...]=...
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_charset = Array();      // Local Language content charset for individual labels (overriding)
00155         var $LOCAL_LANG_loaded = 0;             // Flag that tells if the locallang file has been fetch (or tried to be fetched) already.
00156         var $LLkey='default';                   // Pointer to the language to use.
00157         var $altLLkey='';                       // Pointer to alternative fall-back language to use.
00158         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.
00159         var $LLtestPrefixAlt='';                // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
00160 
00161         var $pi_isOnlyFields = 'mode,pointer';
00162         var $pi_alwaysPrev = 0;
00163         var $pi_lowerThan = 5;
00164         var $pi_moreParams='';
00165         var $pi_listFields='*';
00166 
00167         var $pi_autoCacheFields=array();
00168         var $pi_autoCacheEn=0;
00169 
00170         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!)
00171         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!)
00172 
00179         var $conf = Array();
00180 
00181         // internal, don't mess with...
00182         var $pi_EPtemp_cObj;
00183         var $pi_tmpPageId=0;
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201         /***************************
00202          *
00203          * Init functions
00204          *
00205          **************************/
00206 
00214         function tslib_pibase() {
00215 
00216                         // Setting piVars:
00217                 if ($this->prefixId)    {
00218                         $this->piVars = t3lib_div::GParrayMerged($this->prefixId);
00219 
00220                                 // cHash mode check
00221                                 // 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.
00222                                 // 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!
00223                         if ($this->pi_checkCHash && count($this->piVars))       {
00224                                 $GLOBALS['TSFE']->reqCHash();
00225                         }
00226                 }
00227                 if ($GLOBALS['TSFE']->config['config']['language'])     {
00228                         $this->LLkey = $GLOBALS['TSFE']->config['config']['language'];
00229                         if ($GLOBALS['TSFE']->config['config']['language_alt']) {
00230                                 $this->altLLkey = $GLOBALS['TSFE']->config['config']['language_alt'];
00231                         }
00232                 }
00233         }
00234 
00240         function pi_setPiVarDefaults()  {
00241                 if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
00242                         $this->piVars = t3lib_div::array_merge_recursive_overrule($this->conf['_DEFAULT_PI_VARS.'],is_array($this->piVars)?$this->piVars:array());
00243                 }
00244         }
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258         /***************************
00259          *
00260          * Link functions
00261          *
00262          **************************/
00263 
00277         function pi_getPageLink($id,$target='',$urlParameters=array())  {
00278                 return $this->cObj->getTypoLink_URL($id,$urlParameters,$target);        // ?$target:$GLOBALS['TSFE']->sPre
00279         }
00280 
00293         function pi_linkToPage($str,$id,$target='',$urlParameters=array())      {
00294                 return $this->cObj->getTypoLink($str,$id,$urlParameters,$target);       // ?$target:$GLOBALS['TSFE']->sPre
00295         }
00296 
00308         function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0)   {
00309                 $conf=array();
00310                 $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
00311                 $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
00312                 $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id);
00313                 $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('',$urlParameters,'',1).$this->pi_moreParams;
00314 
00315                 return $this->cObj->typoLink($str, $conf);
00316         }
00317 
00331         function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)        {
00332                 if (is_array($this->piVars) && is_array($overrulePIvars) && !$clearAnyway)      {
00333                         $piVars = $this->piVars;
00334                         unset($piVars['DATA']);
00335                         $overrulePIvars = t3lib_div::array_merge_recursive_overrule($piVars,$overrulePIvars);
00336                         if ($this->pi_autoCacheEn)      {
00337                                 $cache = $this->pi_autoCache($overrulePIvars);
00338                         }
00339                 }
00340                 $res = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
00341                 return $res;
00342         }
00343 
00355         function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) {
00356                 $this->pi_linkTP_keepPIvars('|',$overrulePIvars,$cache,$clearAnyway,$altPageId);
00357                 return $this->cObj->lastTypoLinkUrl;
00358         }
00359 
00373         function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0)       {
00374                 if ($this->prefixId)    {
00375                         if ($cache)     {
00376                                 $overrulePIvars=$uid?array('showUid'=>$uid):Array();
00377                                 $overrulePIvars=array_merge($overrulePIvars,(array)$mergeArr);
00378                                 $str = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
00379                         } else {
00380                                 $overrulePIvars=array('showUid'=>$uid?$uid:'');
00381                                 $overrulePIvars=array_merge($overrulePIvars,(array)$mergeArr);
00382                                 $str = $this->pi_linkTP_keepPIvars($str,$overrulePIvars,$cache,0,$altPageId);
00383                         }
00384 
00385                                 // If urlOnly flag, return only URL as it has recently be generated.
00386                         if ($urlOnly)   {
00387                                 $str = $this->cObj->lastTypoLinkUrl;
00388                         }
00389                 }
00390                 return $str;
00391         }
00392 
00401         function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')      {
00402                 if (eregi('(.*)(<a[^>]*>)(.*)',$str,$match))    {
00403                         $aTagContent = t3lib_div::get_tag_attributes($match[2]);
00404                         $match[2]='<a href="#" onclick="'.
00405                                 htmlspecialchars('vHWin=window.open(\''.$GLOBALS['TSFE']->baseUrlWrap($aTagContent['href']).'\',\''.($winName?$winName:md5($aTagContent['href'])).'\',\''.$winParams.'\');vHWin.focus();return false;').
00406                                 '">';
00407                         $str=$match[1].$match[2].$match[3];
00408                 }
00409                 return $str;
00410         }
00411 
00412 
00413 
00414 
00415 
00416 
00417 
00418 
00419 
00420 
00421 
00422 
00423 
00424 
00425         /***************************
00426          *
00427          * Functions for listing, browsing, searching etc.
00428          *
00429          **************************/
00430 
00456         function pi_list_browseresults($showResultCount=1,$tableParams='',$wrapArr=array(), $pointerName = 'pointer', $hscText = TRUE)  {
00457 
00458                 // example $wrapArr-array how it could be traversed from an extension
00459                 /* $wrapArr = array(
00460                         'browseBoxWrap' => '<div class="browseBoxWrap">|</div>',
00461                         'showResultsWrap' => '<div class="showResultsWrap">|</div>',
00462                         'browseLinksWrap' => '<div class="browseLinksWrap">|</div>',
00463                         'showResultsNumbersWrap' => '<span class="showResultsNumbersWrap">|</span>',
00464                         'disabledLinkWrap' => '<span class="disabledLinkWrap">|</span>',
00465                         'inactiveLinkWrap' => '<span class="inactiveLinkWrap">|</span>',
00466                         'activeLinkWrap' => '<span class="activeLinkWrap">|</span>'
00467                 ); */
00468 
00469                         // Initializing variables:
00470                 $pointer = intval($this->piVars[$pointerName]);
00471                 $count = intval($this->internal['res_count']);
00472                 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
00473                 $totalPages = ceil($count/$results_at_a_time);
00474                 $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
00475                 $pi_isOnlyFields = $this->pi_isOnlyFields($this->pi_isOnlyFields);
00476 
00477                         // $showResultCount determines how the results of the pagerowser will be shown.
00478                         // If set to 0: only the result-browser will be shown
00479                         //                       1: (default) the text "Displaying results..." and the result-browser will be shown.
00480                         //                       2: only the text "Displaying results..." will be shown
00481                 $showResultCount = intval($showResultCount);
00482 
00483                         // if this is set, two links named "<< First" and "LAST >>" will be shown and point to the very first or last page.
00484                 $showFirstLast = $this->internal['showFirstLast'];
00485 
00486                         // if this has a value the "previous" button is always visible (will be forced if "showFirstLast" is set)
00487                 $alwaysPrev = $showFirstLast?1:$this->pi_alwaysPrev;
00488 
00489                 if (isset($this->internal['pagefloat'])) {
00490                         if (strtoupper($this->internal['pagefloat']) == 'CENTER') {
00491                                 $pagefloat = ceil(($maxPages - 1)/2);
00492                         } else {
00493                                 // pagefloat set as integer. 0 = left, value >= $this->internal['maxPages'] = right
00494                                 $pagefloat = t3lib_div::intInRange($this->internal['pagefloat'],-1,$maxPages-1);
00495                         }
00496                 } else {
00497                         $pagefloat = -1; // pagefloat disabled
00498                 }
00499 
00500                         // default values for "traditional" wrapping with a table. Can be overwritten by vars from $wrapArr
00501                 $wrapper['disabledLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
00502                 $wrapper['inactiveLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
00503                 $wrapper['activeLinkWrap'] = '<td'.$this->pi_classParam('browsebox-SCell').' nowrap="nowrap"><p>|</p></td>';
00504                 $wrapper['browseLinksWrap'] = trim('<table '.$tableParams).'><tr>|</tr></table>';
00505                 $wrapper['showResultsWrap'] = '<p>|</p>';
00506                 $wrapper['browseBoxWrap'] = '
00507                 <!--
00508                         List browsing box:
00509                 -->
00510                 <div '.$this->pi_classParam('browsebox').'>
00511                         |
00512                 </div>';
00513 
00514                         // now overwrite all entries in $wrapper which are also in $wrapArr
00515                 $wrapper = array_merge($wrapper,$wrapArr);
00516 
00517                 if ($showResultCount != 2) { //show pagebrowser
00518                         if ($pagefloat > -1) {
00519                                 $lastPage = min($totalPages,max($pointer+1 + $pagefloat,$maxPages));
00520                                 $firstPage = max(0,$lastPage-$maxPages);
00521                         } else {
00522                                 $firstPage = 0;
00523                                 $lastPage = t3lib_div::intInRange($totalPages,1,$maxPages);
00524                         }
00525                         $links=array();
00526 
00527                                 // Make browse-table/links:
00528                         if ($showFirstLast) { // Link to first page
00529                                 if ($pointer>0) {
00530                                         $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),array($pointerName => null),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
00531                                 } else {
00532                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),$wrapper['disabledLinkWrap']);
00533                                 }
00534                         }
00535                         if ($alwaysPrev>=0)     { // Link to previous page
00536                                 if ($pointer>0) {
00537                                         $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']);
00538                                 } elseif ($alwaysPrev)  {
00539                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),$wrapper['disabledLinkWrap']);
00540                                 }
00541                         }
00542                         for($a=$firstPage;$a<$lastPage;$a++)    { // Links to pages
00543                                 if ($this->internal['showRange']) {
00544                                         $pageText = (($a*$results_at_a_time)+1).'-'.min($count,(($a+1)*$results_at_a_time));
00545                                 } else {
00546                                         $pageText = trim($this->pi_getLL('pi_list_browseresults_page','Page',$hscText).' '.($a+1));
00547                                 }
00548                                 if ($pointer == $a) { // current page
00549                                         if ($this->internal['dontLinkActivePage']) {
00550                                                 $links[] = $this->cObj->wrap($pageText,$wrapper['activeLinkWrap']);
00551                                         } else {
00552                                                 $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName  => ($a?$a:'')),$pi_isOnlyFields),$wrapper['activeLinkWrap']);
00553                                         }
00554                                 } else {
00555                                         $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
00556                                 }
00557                         }
00558                         if ($pointer<$totalPages-1 || $showFirstLast)   {
00559                                 if ($pointer==$totalPages-1) { // Link to next page
00560                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),$wrapper['disabledLinkWrap']);
00561                                 } else {
00562                                         $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']);
00563                                 }
00564                         }
00565                         if ($showFirstLast) { // Link to last page
00566                                 if ($pointer<$totalPages-1) {
00567                                         $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']);
00568                                 } else {
00569                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),$wrapper['disabledLinkWrap']);
00570                                 }
00571                         }
00572                         $theLinks = $this->cObj->wrap(implode(chr(10),$links),$wrapper['browseLinksWrap']);
00573                 } else {
00574                         $theLinks = '';
00575                 }
00576 
00577                 $pR1 = $pointer*$results_at_a_time+1;
00578                 $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
00579 
00580                 if ($showResultCount) {
00581                         if ($wrapper['showResultsNumbersWrap']) {
00582                                 // this will render the resultcount in a more flexible way using markers (new in TYPO3 3.8.0).
00583                                 // the formatting string is expected to hold template markers (see function header). Example: 'Displaying results ###FROM### to ###TO### out of ###OUT_OF###'
00584 
00585                                 $markerArray['###FROM###'] = $this->cObj->wrap($this->internal['res_count'] > 0 ? $pR1 : 0,$wrapper['showResultsNumbersWrap']);
00586                                 $markerArray['###TO###'] = $this->cObj->wrap(min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
00587                                 $markerArray['###OUT_OF###'] = $this->cObj->wrap($this->internal['res_count'],$wrapper['showResultsNumbersWrap']);
00588                                 $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']);
00589                                 $markerArray['###CURRENT_PAGE###'] = $this->cObj->wrap($pointer+1,$wrapper['showResultsNumbersWrap']);
00590                                 $markerArray['###TOTAL_PAGES###'] = $this->cObj->wrap($totalPages,$wrapper['showResultsNumbersWrap']);
00591                                 // substitute markers
00592                                 $resultCountMsg = $this->cObj->substituteMarkerArray($this->pi_getLL('pi_list_browseresults_displays','Displaying results ###FROM### to ###TO### out of ###OUT_OF###'),$markerArray);
00593                         } else {
00594                                 // render the resultcount in the "traditional" way using sprintf
00595                                 $resultCountMsg = sprintf(
00596                                         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>')),
00597                                         $count > 0 ? $pR1 : 0,
00598                                         min($count,$pR2),
00599                                         $count);
00600                         }
00601                         $resultCountMsg = $this->cObj->wrap($resultCountMsg,$wrapper['showResultsWrap']);
00602                 } else {
00603                         $resultCountMsg = '';
00604                 }
00605 
00606                 $sTables = $this->cObj->wrap($resultCountMsg.$theLinks,$wrapper['browseBoxWrap']);
00607 
00608                 return $sTables;
00609         }
00610 
00618         function pi_list_searchBox($tableParams='')     {
00619                         // Search box design:
00620                 $sTables = '
00621 
00622                 <!--
00623                         List search box:
00624                 -->
00625                 <div'.$this->pi_classParam('searchbox').'>
00626                         <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
00627                         <'.trim('table '.$tableParams).'>
00628                                 <tr>
00629                                         <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
00630                                         <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' />'.
00631                                                 '<input type="hidden" name="no_cache" value="1" />'.
00632                                                 '<input type="hidden" name="'.$this->prefixId.'[pointer]" value="" />'.
00633                                                 '</td>
00634                                 </tr>
00635                         </table>
00636                         </form>
00637                 </div>';
00638 
00639                 return $sTables;
00640         }
00641 
00649         function pi_list_modeSelector($items=array(),$tableParams='')   {
00650                 $cells=array();
00651                 reset($items);
00652                 while(list($k,$v)=each($items)) {
00653                         $cells[]='
00654                                         <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
00655                                 $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
00656                                 '</p></td>';
00657                 }
00658 
00659                 $sTables = '
00660 
00661                 <!--
00662                         Mode selector (menu for list):
00663                 -->
00664                 <div'.$this->pi_classParam('modeSelector').'>
00665                         <'.trim('table '.$tableParams).'>
00666                                 <tr>
00667                                         '.implode('',$cells).'
00668                                 </tr>
00669                         </table>
00670                 </div>';
00671 
00672                 return $sTables;
00673         }
00674 
00687         function pi_list_makelist($res,$tableParams='') {
00688                         // Make list table header:
00689                 $tRows=array();
00690                 $this->internal['currentRow']='';
00691                 $tRows[] = $this->pi_list_header();
00692 
00693                         // Make list table rows
00694                 $c=0;
00695                 while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00696                         $tRows[] = $this->pi_list_row($c);
00697                         $c++;
00698                 }
00699 
00700                 $out = '
00701 
00702                 <!--
00703                         Record list:
00704                 -->
00705                 <div'.$this->pi_classParam('listrow').'>
00706                         <'.trim('table '.$tableParams).'>
00707                                 '.implode('',$tRows).'
00708                         </table>
00709                 </div>';
00710 
00711                 return $out;
00712         }
00713 
00722         function pi_list_row($c)        {
00723                 // Dummy
00724                 return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
00725         }
00726 
00734         function pi_list_header()       {
00735                 return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
00736         }
00737 
00738 
00739 
00740 
00741 
00742 
00743 
00744 
00745 
00746 
00747 
00748 
00749 
00750 
00751 
00752         /***************************
00753          *
00754          * Stylesheet, CSS
00755          *
00756          **************************/
00757 
00758 
00765         function pi_getClassName($class)        {
00766                 return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
00767         }
00768 
00777         function pi_classParam($class)  {
00778                 return ' class="'.$this->pi_getClassName($class).'"';
00779         }
00780 
00791         function pi_setClassStyle($class,$data,$selector='')    {
00792                 $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
00793         }
00794 
00802         function pi_wrapInBaseClass($str)       {
00803                 $content = '<div class="'.str_replace('_','-',$this->prefixId).'">
00804                 '.$str.'
00805         </div>
00806         ';
00807 
00808                 if(!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
00809                         $content = '
00810 
00811 
00812         <!--
00813 
00814                 BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
00815 
00816         -->
00817         '.$content.'
00818         <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
00819 
00820         ';
00821                 }
00822 
00823                 return $content;
00824         }
00825 
00826 
00827 
00828 
00829 
00830 
00831 
00832 
00833 
00834 
00835 
00836 
00837 
00838 
00839 
00840 
00841 
00842         /***************************
00843          *
00844          * Frontend editing: Edit panel, edit icons
00845          *
00846          **************************/
00847 
00858         function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
00859                 $panel='';
00860                 if (!$row || !$tablename)       {
00861                         $row = $this->internal['currentRow'];
00862                         $tablename = $this->internal['currentTable'];
00863                 }
00864 
00865                 if ($GLOBALS['TSFE']->beUserLogin)      {
00866                                 // Create local cObj if not set:
00867                         if (!is_object($this->pi_EPtemp_cObj))  {
00868                                 $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
00869                                 $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
00870                         }
00871 
00872                                 // Initialize the cObj object with current row
00873                         $this->pi_EPtemp_cObj->start($row,$tablename);
00874 
00875                                 // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
00876                         $conf['allow'] = 'edit,new,delete,move,hide';
00877                         $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
00878                 }
00879 
00880                 if ($panel)     {
00881                         if ($label)     {
00882                                 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 -->';
00883                         } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
00884                 } else return $label;
00885         }
00886 
00900         function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array())        {
00901                 if ($GLOBALS['TSFE']->beUserLogin){
00902                         if (!$row || !$tablename)       {
00903                                 $row = $this->internal['currentRow'];
00904                                 $tablename = $this->internal['currentTable'];
00905                         }
00906                         $conf=array_merge(array(
00907                                 'beforeLastTag'=>1,
00908                                 'iconTitle' => $title
00909                         ),$oConf);
00910                         $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
00911                 }
00912                 return $content;
00913         }
00914 
00915 
00916 
00917 
00918 
00919 
00920 
00921 
00922 
00923 
00924 
00925 
00926 
00927 
00928 
00929 
00930 
00931         /***************************
00932          *
00933          * Localization, locallang functions
00934          *
00935          **************************/
00936 
00937 
00947         function pi_getLL($key,$alt='',$hsc=FALSE)      {
00948                 if (isset($this->LOCAL_LANG[$this->LLkey][$key]))       {
00949                         $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.
00950                 } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key]))   {
00951                         $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.
00952                 } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
00953                         $word = $this->LOCAL_LANG['default'][$key];     // No charset conversion because default is english and thereby ASCII
00954                 } else {
00955                         $word = $this->LLtestPrefixAlt.$alt;
00956                 }
00957 
00958                 $output = $this->LLtestPrefix.$word;
00959                 if ($hsc)       $output = htmlspecialchars($output);
00960 
00961                 return $output;
00962         }
00963 
00970         function pi_loadLL()    {
00971                 if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath)  {
00972                         $basePath = t3lib_extMgm::extPath($this->extKey).dirname($this->scriptRelPath).'/locallang.php';
00973 
00974                                 // php or xml as source: In any case the charset will be that of the system language.
00975                                 // 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)
00976                         $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey);
00977                         if ($this->altLLkey)    {
00978                                 $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
00979                                 $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
00980                         }
00981 
00982                                 // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
00983                         if (is_array($this->conf['_LOCAL_LANG.']))      {
00984                                 reset($this->conf['_LOCAL_LANG.']);
00985                                 while(list($k,$lA)=each($this->conf['_LOCAL_LANG.']))   {
00986                                         if (is_array($lA))      {
00987                                                 $k = substr($k,0,-1);
00988                                                 foreach($lA as $llK => $llV)    {
00989                                                         if (!is_array($llV))    {
00990                                                                 $this->LOCAL_LANG[$k][$llK] = $llV;
00991                                                                 if ($k != 'default')    {
00992                                                                         $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)
00993                                                                 }
00994                                                         }
00995                                                 }
00996                                         }
00997                                 }
00998                         }
00999                 }
01000                 $this->LOCAL_LANG_loaded = 1;
01001         }
01002 
01003 
01004 
01005 
01006 
01007 
01008 
01009 
01010 
01011 
01012 
01013 
01014 
01015 
01016 
01017 
01018 
01019 
01020 
01021 
01022 
01023 
01024 
01025         /***************************
01026          *
01027          * Database, queries
01028          *
01029          **************************/
01030 
01048         function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)       {
01049 
01050                         // Begin Query:
01051                 if (!$query)    {
01052                                 // Fetches the list of PIDs to select from.
01053                                 // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
01054                                 // 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.
01055                         $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
01056                         if (is_array($mm_cat))  {
01057                                 $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).
01058                                                 ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).
01059                                                 (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).
01060                                                 ' AND '.$table.'.pid IN ('.$pidList.')'.chr(10).
01061                                                 $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!
01062                         } else {
01063                                 $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10).
01064                                                 $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!
01065                         }
01066                 }
01067 
01068                         // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
01069                 list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
01070                 $TABLENAMES = trim(substr(trim($TABLENAMES),5));
01071                 $WHERE = trim($WHERE);
01072 
01073                         // Add '$addWhere'
01074                 if ($addWhere)  {$WHERE.=' '.$addWhere.chr(10);}
01075 
01076                         // Search word:
01077                 if ($this->piVars['sword'] && $this->internal['searchFieldList'])       {
01078                         $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);
01079                 }
01080 
01081                 if ($count) {
01082                         $queryParts = array(
01083                                 'SELECT' => 'count(*)',
01084                                 'FROM' => $TABLENAMES,
01085                                 'WHERE' => $WHERE,
01086                                 'GROUPBY' => '',
01087                                 'ORDERBY' => '',
01088                                 'LIMIT' => ''
01089                         );
01090                 } else {
01091                                 // Order by data:
01092                         if (!$orderBy && $this->internal['orderBy'])    {
01093                                 if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy']))       {
01094                                         $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
01095                                 }
01096                         }
01097 
01098                                 // Limit data:
01099                         $pointer = $this->piVars['pointer'];
01100                         $pointer = intval($pointer);
01101                         $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
01102                         $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
01103 
01104                                 // Add 'SELECT'
01105                         $queryParts = array(
01106                                 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
01107                                 'FROM' => $TABLENAMES,
01108                                 'WHERE' => $WHERE,
01109                                 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
01110                                 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
01111                                 'LIMIT' => $LIMIT
01112                         );
01113                 }
01114 
01115                 $query = $GLOBALS['TYPO3_DB']->SELECTquery (
01116                                         $queryParts['SELECT'],
01117                                         $queryParts['FROM'],
01118                                         $queryParts['WHERE'],
01119                                         $queryParts['GROUPBY'],
01120                                         $queryParts['ORDERBY'],
01121                                         $queryParts['LIMIT']
01122                                 );
01123                 return $returnQueryArray ? $queryParts : $query;
01124         }
01125 
01140         function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')       {
01141                 $queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);
01142 
01143                 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
01144         }
01145 
01155         function pi_getRecord($table,$uid,$checkPage=0) {
01156                 return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
01157         }
01158 
01166         function pi_getPidList($pid_list,$recursive=0)  {
01167                 if (!strcmp($pid_list,''))      $pid_list = $GLOBALS['TSFE']->id;
01168                 $recursive = t3lib_div::intInRange($recursive,0);
01169 
01170                 $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));
01171                 $pid_list = array();
01172 
01173                 foreach($pid_list_arr as $val)  {
01174                         $val = t3lib_div::intInRange($val,0);
01175                         if ($val)       {
01176                                 $_list = $this->cObj->getTreeList(-1*$val, $recursive);
01177                                 if ($_list)             $pid_list[] = $_list;
01178                         }
01179                 }
01180 
01181                 return implode(',', $pid_list);
01182         }
01183 
01191         function pi_prependFieldsWithTable($table,$fieldList)   {
01192                 $list=t3lib_div::trimExplode(',',$fieldList,1);
01193                 $return=array();
01194                 while(list(,$listItem)=each($list))     {
01195                         $return[]=$table.'.'.$listItem;
01196                 }
01197                 return implode(',',$return);
01198         }
01199 
01211         function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')     {
01212                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01213                                         '*',
01214                                         $table,
01215                                         'pid='.intval($pid).
01216                                                 $this->cObj->enableFields($table).' '.
01217                                                 $whereClause,   // whereClauseMightContainGroupOrderBy
01218                                         $groupBy,
01219                                         $orderBy,
01220                                         $limit
01221                                 );
01222                 $outArr = array();
01223                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
01224                         $outArr[$row['uid']] = $row;
01225                 }
01226                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01227                 return $outArr;
01228         }
01229 
01230 
01231 
01232 
01233 
01234 
01235 
01236 
01237 
01238 
01239 
01240 
01241         /***************************
01242          *
01243          * Various
01244          *
01245          **************************/
01246 
01255         function pi_isOnlyFields($fList,$lowerThan=-1)  {
01256                 $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;
01257 
01258                 $fList = t3lib_div::trimExplode(',',$fList,1);
01259                 $tempPiVars = $this->piVars;
01260                 while(list(,$k)=each($fList))   {
01261                         if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan)         unset($tempPiVars[$k]);
01262                 }
01263                 if (!count($tempPiVars))        return 1;
01264         }
01265 
01275         function pi_autoCache($inArray) {
01276                 if (is_array($inArray)) {
01277                         reset($inArray);
01278                         while(list($fN,$fV)=each($inArray))     {
01279                                 if (!strcmp($inArray[$fN],''))  {
01280                                         unset($inArray[$fN]);
01281                                 } elseif (is_array($this->pi_autoCacheFields[$fN]))     {
01282                                         if (is_array($this->pi_autoCacheFields[$fN]['range'])
01283                                                          && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])
01284                                                          && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1]))  {
01285                                                                 unset($inArray[$fN]);
01286                                         }
01287                                         if (is_array($this->pi_autoCacheFields[$fN]['list'])
01288                                                          && in_array($inArray[$fN],$this->pi_autoCacheFields[$fN]['list']))     {
01289                                                                 unset($inArray[$fN]);
01290                                         }
01291                                 }
01292                         }
01293                 }
01294                 if (!count($inArray))   return 1;
01295         }
01296 
01306         function pi_RTEcssText($str)    {
01307                 $parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];
01308                 if (is_array($parseFunc))       $str = $this->cObj->parseFunc($str, $parseFunc);
01309                 return $str;
01310         }
01311 
01312 
01313 
01314 
01315 
01316         /*******************************
01317          *
01318          * FlexForms related functions
01319          *
01320          *******************************/
01321 
01328         function pi_initPIflexForm($field='pi_flexform')        {
01329                         // Converting flexform data into array:
01330                 if (!is_array($this->cObj->data[$field]) && $this->cObj->data[$field])  {
01331                         $this->cObj->data[$field] = t3lib_div::xml2array($this->cObj->data[$field]);
01332                         if (!is_array($this->cObj->data[$field]))       $this->cObj->data[$field]=array();
01333                 }
01334         }
01335 
01346         function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')   {
01347                 $sheetArray = is_array($T3FlexForm_array) ? $T3FlexForm_array['data'][$sheet][$lang] : '';
01348                 if (is_array($sheetArray))      {
01349                         return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
01350                 }
01351         }
01352 
01363         function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)  {
01364 
01365                 $tempArr=$sheetArray;
01366                 foreach($fieldNameArr as $k => $v)      {
01367                         if (t3lib_div::testInt($v))     {
01368                                 if (is_array($tempArr)) {
01369                                         $c=0;
01370                                         foreach($tempArr as $values)    {
01371                                                 if ($c==$v)     {
01372                                                         #debug($values);
01373                                                         $tempArr=$values;
01374                                                         break;
01375                                                 }
01376                                                 $c++;
01377                                         }
01378                                 }
01379                         } else {
01380                                 $tempArr = $tempArr[$v];
01381                         }
01382                 }
01383                 return $tempArr[$value];
01384         }
01385 }
01386 
01387 // NO extension of class - does not make sense here.
01388 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6