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 incomming array by name $this->prefixId merged between POST and GET, POST taking precedence. Eg. if the class name is 'tx_myext' then the content of this array will be whatever comes into &tx_myext[...]=...
00140                 'pointer' => '',                        // Used as a pointer for lists
00141                 'mode' => '',                           // List mode
00142                 'sword' => '',                          // Search word
00143                 'sort' => '',                           // [Sorting column]:[ASC=0/DESC=1]
00144         );
00145         var $internal = Array(  // Used internally for general storage of values between methods
00146                 'res_count' => 0,                       // Total query count
00147                 'results_at_a_time' => 20,      // pi_list_browseresults(): Show number of results at a time
00148                 'maxPages' => 10,                       // pi_list_browseresults(): Max number of 'Page 1 - Page 2 - ...' in the list browser
00149                 'currentRow' => Array(),        // Current result row
00150                 'currentTable' => '',           // Current table
00151         );
00152 
00153         var $LOCAL_LANG = Array();      // Local Language content
00154         var $LOCAL_LANG_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) 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,$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,$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 
00455         function pi_list_browseresults($showResultCount=1,$tableParams='',$wrapArr=array(), $pointerName = 'pointer', $hscText = TRUE)  {
00456 
00457                 // example $wrapArr-array how it could be traversed from an extension
00458                 /* $wrapArr = array(
00459                         'browseBoxWrap' => '<div class="browseBoxWrap">|</div>',
00460                         'showResultsWrap' => '<div class="showResultsWrap">|</div>',
00461                         'browseLinksWrap' => '<div class="browseLinksWrap">|</div>',
00462                         'showResultsNumbersWrap' => '<span class="showResultsNumbersWrap">|</span>',
00463                         'disabledLinkWrap' => '<span class="disabledLinkWrap">|</span>',
00464                         'inactiveLinkWrap' => '<span class="inactiveLinkWrap">|</span>',
00465                         'activeLinkWrap' => '<span class="activeLinkWrap">|</span>'
00466                 ); */
00467 
00468                         // Initializing variables:
00469                 $pointer = intval($this->piVars[$pointerName]);
00470                 $count = intval($this->internal['res_count']);
00471                 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
00472                 $totalPages = ceil($count/$results_at_a_time);
00473                 $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
00474                 $pi_isOnlyFields = $this->pi_isOnlyFields($this->pi_isOnlyFields);
00475 
00476                         // $showResultCount determines how the results of the pagerowser will be shown.
00477                         // If set to 0: only the result-browser will be shown
00478                         //                       1: (default) the text "Displaying results..." and the result-browser will be shown.
00479                         //                       2: only the text "Displaying results..." will be shown
00480                 $showResultCount = intval($showResultCount);
00481 
00482                         // if this is set, two links named "<< First" and "LAST >>" will be shown and point to the very first or last page.
00483                 $showFirstLast = $this->internal['showFirstLast'];
00484 
00485                         // if this has a value the "previous" button is always visible (will be forced if "showFirstLast" is set)
00486                 $alwaysPrev = $showFirstLast?1:$this->pi_alwaysPrev;
00487 
00488                 if (isset($this->internal['pagefloat'])) {
00489                         if (strtoupper($this->internal['pagefloat']) == 'CENTER') {
00490                                 $pagefloat = ceil(($maxPages - 1)/2);
00491                         } else {
00492                                 // pagefloat set as integer. 0 = left, value >= $this->internal['maxPages'] = right
00493                                 $pagefloat = t3lib_div::intInRange($this->internal['pagefloat'],-1,$maxPages-1);
00494                         }
00495                 } else {
00496                         $pagefloat = -1; // pagefloat disabled
00497                 }
00498 
00499                         // default values for "traditional" wrapping with a table. Can be overwritten by vars from $wrapArr
00500                 $wrapper['disabledLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
00501                 $wrapper['inactiveLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
00502                 $wrapper['activeLinkWrap'] = '<td'.$this->pi_classParam('browsebox-SCell').' nowrap="nowrap"><p>|</p></td>';
00503                 $wrapper['browseLinksWrap'] = trim('<table '.$tableParams).'><tr>|</tr></table>';
00504                 $wrapper['showResultsWrap'] = '<p>|</p>';
00505                 $wrapper['browseBoxWrap'] = '
00506                 <!--
00507                         List browsing box:
00508                 -->
00509                 <div '.$this->pi_classParam('browsebox').'>
00510                         |
00511                 </div>';
00512 
00513                         // now overwrite all entries in $wrapper which are also in $wrapArr
00514                 $wrapper = array_merge($wrapper,$wrapArr);
00515 
00516                 if ($showResultCount != 2) { //show pagebrowser
00517                         if ($pagefloat > -1) {
00518                                 $lastPage = min($totalPages,max($pointer+1 + $pagefloat,$maxPages));
00519                                 $firstPage = max(0,$lastPage-$maxPages);
00520                         } else {
00521                                 $firstPage = 0;
00522                                 $lastPage = t3lib_div::intInRange($totalPages,1,$maxPages);
00523                         }
00524                         $links=array();
00525 
00526                                 // Make browse-table/links:
00527                         if ($showFirstLast) { // Link to first page
00528                                 if ($pointer>0) {
00529                                         $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),array($pointerName => null),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
00530                                 } else {
00531                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),$wrapper['disabledLinkWrap']);
00532                                 }
00533                         }
00534                         if ($alwaysPrev>=0)     { // Link to previous page
00535                                 if ($pointer>0) {
00536                                         $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']);
00537                                 } elseif ($alwaysPrev)  {
00538                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),$wrapper['disabledLinkWrap']);
00539                                 }
00540                         }
00541                         for($a=$firstPage;$a<$lastPage;$a++)    { // Links to pages
00542                                 if ($this->internal['showRange']) {
00543                                         $pageText = (($a*$results_at_a_time)+1).'-'.min($count,(($a+1)*$results_at_a_time));
00544                                 } else {
00545                                         $pageText = trim($this->pi_getLL('pi_list_browseresults_page','Page',$hscText).' '.($a+1));
00546                                 }
00547                                 if ($pointer == $a) { // current page
00548                                         if ($this->internal['dontLinkActivePage']) {
00549                                                 $links[] = $this->cObj->wrap($pageText,$wrapper['activeLinkWrap']);
00550                                         } else {
00551                                                 $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName  => ($a?$a:'')),$pi_isOnlyFields),$wrapper['activeLinkWrap']);
00552                                         }
00553                                 } else {
00554                                         $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
00555                                 }
00556                         }
00557                         if ($pointer<$totalPages-1 || $showFirstLast)   {
00558                                 if ($pointer==$totalPages-1) { // Link to next page
00559                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),$wrapper['disabledLinkWrap']);
00560                                 } else {
00561                                         $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']);
00562                                 }
00563                         }
00564                         if ($showFirstLast) { // Link to last page
00565                                 if ($pointer<$totalPages-1) {
00566                                         $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']);
00567                                 } else {
00568                                         $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),$wrapper['disabledLinkWrap']);
00569                                 }
00570                         }
00571                         $theLinks = $this->cObj->wrap(implode(chr(10),$links),$wrapper['browseLinksWrap']);
00572                 } else {
00573                         $theLinks = '';
00574                 }
00575 
00576                 $pR1 = $pointer*$results_at_a_time+1;
00577                 $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
00578 
00579                 if ($showResultCount) {
00580                         if ($wrapper['showResultsNumbersWrap']) {
00581                                 // this will render the resultcount in a more flexible way using markers (new in TYPO3 3.8.0).
00582                                 // the formatting string is expected to hold template markers (see function header). Example: 'Displaying results ###FROM### to ###TO### out of ###OUT_OF###'
00583 
00584                                 $markerArray['###FROM###'] = $this->cObj->wrap($this->internal['res_count'] > 0 ? $pR1 : 0,$wrapper['showResultsNumbersWrap']);
00585                                 $markerArray['###TO###'] = $this->cObj->wrap(min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
00586                                 $markerArray['###OUT_OF###'] = $this->cObj->wrap($this->internal['res_count'],$wrapper['showResultsNumbersWrap']);
00587                                 $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']);
00588                                 $markerArray['###CURRENT_PAGE###'] = $this->cObj->wrap($pointer+1,$wrapper['showResultsNumbersWrap']);
00589                                 $markerArray['###TOTAL_PAGES###'] = $this->cObj->wrap($totalPages,$wrapper['showResultsNumbersWrap']);
00590                                 // substitute markers
00591                                 $resultCountMsg = $this->cObj->substituteMarkerArray($this->pi_getLL('pi_list_browseresults_displays','Displaying results ###FROM### to ###TO### out of ###OUT_OF###'),$markerArray);
00592                         } else {
00593                                 // render the resultcount in the "traditional" way using sprintf
00594                                 $resultCountMsg = sprintf(
00595                                         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>')),
00596                                         $count > 0 ? $pR1 : 0,
00597                                         min($count,$pR2),
00598                                         $count);
00599                         }
00600                         $resultCountMsg = $this->cObj->wrap($resultCountMsg,$wrapper['showResultsWrap']);
00601                 } else {
00602                         $resultCountMsg = '';
00603                 }
00604 
00605                 $sTables = $this->cObj->wrap($resultCountMsg.$theLinks,$wrapper['browseBoxWrap']);
00606 
00607                 return $sTables;
00608         }
00609 
00617         function pi_list_searchBox($tableParams='')     {
00618                         // Search box design:
00619                 $sTables = '
00620 
00621                 <!--
00622                         List search box:
00623                 -->
00624                 <div'.$this->pi_classParam('searchbox').'>
00625                         <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
00626                         <'.trim('table '.$tableParams).'>
00627                                 <tr>
00628                                         <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
00629                                         <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' />'.
00630                                                 '<input type="hidden" name="no_cache" value="1" />'.
00631                                                 '<input type="hidden" name="'.$this->prefixId.'[pointer]" value="" />'.
00632                                                 '</td>
00633                                 </tr>
00634                         </table>
00635                         </form>
00636                 </div>';
00637 
00638                 return $sTables;
00639         }
00640 
00648         function pi_list_modeSelector($items=array(),$tableParams='')   {
00649                 $cells=array();
00650                 reset($items);
00651                 while(list($k,$v)=each($items)) {
00652                         $cells[]='
00653                                         <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
00654                                 $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
00655                                 '</p></td>';
00656                 }
00657 
00658                 $sTables = '
00659 
00660                 <!--
00661                         Mode selector (menu for list):
00662                 -->
00663                 <div'.$this->pi_classParam('modeSelector').'>
00664                         <'.trim('table '.$tableParams).'>
00665                                 <tr>
00666                                         '.implode('',$cells).'
00667                                 </tr>
00668                         </table>
00669                 </div>';
00670 
00671                 return $sTables;
00672         }
00673 
00686         function pi_list_makelist($res,$tableParams='') {
00687                         // Make list table header:
00688                 $tRows=array();
00689                 $this->internal['currentRow']='';
00690                 $tRows[] = $this->pi_list_header();
00691 
00692                         // Make list table rows
00693                 $c=0;
00694                 while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00695                         $tRows[] = $this->pi_list_row($c);
00696                         $c++;
00697                 }
00698 
00699                 $out = '
00700 
00701                 <!--
00702                         Record list:
00703                 -->
00704                 <div'.$this->pi_classParam('listrow').'>
00705                         <'.trim('table '.$tableParams).'>
00706                                 '.implode('',$tRows).'
00707                         </table>
00708                 </div>';
00709 
00710                 return $out;
00711         }
00712 
00721         function pi_list_row($c)        {
00722                 // Dummy
00723                 return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
00724         }
00725 
00733         function pi_list_header()       {
00734                 return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
00735         }
00736 
00737 
00738 
00739 
00740 
00741 
00742 
00743 
00744 
00745 
00746 
00747 
00748 
00749 
00750 
00751         /***************************
00752          *
00753          * Stylesheet, CSS
00754          *
00755          **************************/
00756 
00757 
00764         function pi_getClassName($class)        {
00765                 return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
00766         }
00767 
00776         function pi_classParam($class)  {
00777                 return ' class="'.$this->pi_getClassName($class).'"';
00778         }
00779 
00790         function pi_setClassStyle($class,$data,$selector='')    {
00791                 $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
00792         }
00793 
00801         function pi_wrapInBaseClass($str)       {
00802                 return '
00803 
00804 
00805         <!--
00806 
00807                 BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
00808 
00809         -->
00810         <div class="'.str_replace('_','-',$this->prefixId).'">
00811                 '.$str.'
00812         </div>
00813         <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
00814 
00815         ';
00816         }
00817 
00818 
00819 
00820 
00821 
00822 
00823 
00824 
00825 
00826 
00827 
00828 
00829 
00830 
00831 
00832 
00833 
00834         /***************************
00835          *
00836          * Frontend editing: Edit panel, edit icons
00837          *
00838          **************************/
00839 
00850         function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
00851                 $panel='';
00852                 if (!$row || !$tablename)       {
00853                         $row = $this->internal['currentRow'];
00854                         $tablename = $this->internal['currentTable'];
00855                 }
00856 
00857                 if ($GLOBALS['TSFE']->beUserLogin)      {
00858                                 // Create local cObj if not set:
00859                         if (!is_object($this->pi_EPtemp_cObj))  {
00860                                 $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
00861                                 $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
00862                         }
00863 
00864                                 // Initialize the cObj object with current row
00865                         $this->pi_EPtemp_cObj->start($row,$tablename);
00866 
00867                                 // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
00868                         $conf['allow'] = 'edit,new,delete,move,hide';
00869                         $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
00870                 }
00871 
00872                 if ($panel)     {
00873                         if ($label)     {
00874                                 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 -->';
00875                         } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
00876                 } else return $label;
00877         }
00878 
00892         function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array())        {
00893                 if ($GLOBALS['TSFE']->beUserLogin){
00894                         if (!$row || !$tablename)       {
00895                                 $row = $this->internal['currentRow'];
00896                                 $tablename = $this->internal['currentTable'];
00897                         }
00898                         $conf=array_merge(array(
00899                                 'beforeLastTag'=>1,
00900                                 'iconTitle' => $title
00901                         ),$oConf);
00902                         $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
00903                 }
00904                 return $content;
00905         }
00906 
00907 
00908 
00909 
00910 
00911 
00912 
00913 
00914 
00915 
00916 
00917 
00918 
00919 
00920 
00921 
00922 
00923         /***************************
00924          *
00925          * Localization, locallang functions
00926          *
00927          **************************/
00928 
00929 
00939         function pi_getLL($key,$alt='',$hsc=FALSE)      {
00940                 if (isset($this->LOCAL_LANG[$this->LLkey][$key]))       {
00941                         $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.
00942                 } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key]))   {
00943                         $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.
00944                 } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
00945                         $word = $this->LOCAL_LANG['default'][$key];     // No charset conversion because default is english and thereby ASCII
00946                 } else {
00947                         $word = $this->LLtestPrefixAlt.$alt;
00948                 }
00949 
00950                 $output = $this->LLtestPrefix.$word;
00951                 if ($hsc)       $output = htmlspecialchars($output);
00952 
00953                 return $output;
00954         }
00955 
00962         function pi_loadLL()    {
00963                 if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath)  {
00964                         $basePath = t3lib_extMgm::extPath($this->extKey).dirname($this->scriptRelPath).'/locallang.php';
00965 
00966                                 // php or xml as source: In any case the charset will be that of the system language.
00967                                 // 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)
00968                         $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey);
00969                         if ($this->altLLkey)    {
00970                                 $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
00971                                 $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
00972                         }
00973 
00974                                 // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
00975                         if (is_array($this->conf['_LOCAL_LANG.']))      {
00976                                 reset($this->conf['_LOCAL_LANG.']);
00977                                 while(list($k,$lA)=each($this->conf['_LOCAL_LANG.']))   {
00978                                         if (is_array($lA))      {
00979                                                 $k = substr($k,0,-1);
00980                                                 foreach($lA as $llK => $llV)    {
00981                                                         if (!is_array($llV))    {
00982                                                                 $this->LOCAL_LANG[$k][$llK] = $llV;
00983                                                                 if ($k != 'default')    {
00984                                                                         $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)
00985                                                                 }
00986                                                         }
00987                                                 }
00988                                         }
00989                                 }
00990                         }
00991                 }
00992                 $this->LOCAL_LANG_loaded = 1;
00993         }
00994 
00995 
00996 
00997 
00998 
00999 
01000 
01001 
01002 
01003 
01004 
01005 
01006 
01007 
01008 
01009 
01010 
01011 
01012 
01013 
01014 
01015 
01016 
01017         /***************************
01018          *
01019          * Database, queries
01020          *
01021          **************************/
01022 
01040         function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)       {
01041 
01042                         // Begin Query:
01043                 if (!$query)    {
01044                                 // Fetches the list of PIDs to select from.
01045                                 // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
01046                                 // 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.
01047                         $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
01048                         if (is_array($mm_cat))  {
01049                                 $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).
01050                                                 ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).
01051                                                 (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).
01052                                                 ' AND '.$table.'.pid IN ('.$pidList.')'.chr(10).
01053                                                 $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!
01054                         } else {
01055                                 $query='FROM '.$table.' WHERE 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                         }
01058                 }
01059 
01060                         // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
01061                 list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
01062                 $TABLENAMES = trim(substr(trim($TABLENAMES),5));
01063                 $WHERE = trim($WHERE);
01064 
01065                         // Add '$addWhere'
01066                 if ($addWhere)  {$WHERE.=' '.$addWhere.chr(10);}
01067 
01068                         // Search word:
01069                 if ($this->piVars['sword'] && $this->internal['searchFieldList'])       {
01070                         $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);
01071                 }
01072 
01073                 if ($count) {
01074                         $queryParts = array(
01075                                 'SELECT' => 'count(*)',
01076                                 'FROM' => $TABLENAMES,
01077                                 'WHERE' => $WHERE,
01078                                 'GROUPBY' => '',
01079                                 'ORDERBY' => '',
01080                                 'LIMIT' => ''
01081                         );
01082                 } else {
01083                                 // Order by data:
01084                         if (!$orderBy && $this->internal['orderBy'])    {
01085                                 if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy']))       {
01086                                         $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
01087                                 }
01088                         }
01089 
01090                                 // Limit data:
01091                         $pointer = $this->piVars['pointer'];
01092                         $pointer = intval($pointer);
01093                         $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
01094                         $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
01095 
01096                                 // Add 'SELECT'
01097                         $queryParts = array(
01098                                 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
01099                                 'FROM' => $TABLENAMES,
01100                                 'WHERE' => $WHERE,
01101                                 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
01102                                 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
01103                                 'LIMIT' => $LIMIT
01104                         );
01105                 }
01106 
01107                 $query = $GLOBALS['TYPO3_DB']->SELECTquery (
01108                                         $queryParts['SELECT'],
01109                                         $queryParts['FROM'],
01110                                         $queryParts['WHERE'],
01111                                         $queryParts['GROUPBY'],
01112                                         $queryParts['ORDERBY'],
01113                                         $queryParts['LIMIT']
01114                                 );
01115                 return $returnQueryArray ? $queryParts : $query;
01116         }
01117 
01132         function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')       {
01133                 $queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);
01134 
01135                 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
01136         }
01137 
01147         function pi_getRecord($table,$uid,$checkPage=0) {
01148                 return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
01149         }
01150 
01158         function pi_getPidList($pid_list,$recursive=0)  {
01159                 if (!strcmp($pid_list,''))      $pid_list = $GLOBALS['TSFE']->id;
01160                 $recursive = t3lib_div::intInRange($recursive,0);
01161 
01162                 $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));
01163                 $pid_list = array();
01164 
01165                 foreach($pid_list_arr as $val)  {
01166                         $val = t3lib_div::intInRange($val,0);
01167                         if ($val)       {
01168                                 $_list = $this->cObj->getTreeList(-1*$val, $recursive);
01169                                 if ($_list)             $pid_list[] = $_list;
01170                         }
01171                 }
01172 
01173                 return implode(',', $pid_list);
01174         }
01175 
01183         function pi_prependFieldsWithTable($table,$fieldList)   {
01184                 $list=t3lib_div::trimExplode(',',$fieldList,1);
01185                 $return=array();
01186                 while(list(,$listItem)=each($list))     {
01187                         $return[]=$table.'.'.$listItem;
01188                 }
01189                 return implode(',',$return);
01190         }
01191 
01203         function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')     {
01204                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01205                                         '*',
01206                                         $table,
01207                                         'pid='.intval($pid).
01208                                                 $this->cObj->enableFields($table).' '.
01209                                                 $whereClause,   // whereClauseMightContainGroupOrderBy
01210                                         $groupBy,
01211                                         $orderBy,
01212                                         $limit
01213                                 );
01214                 $outArr = array();
01215                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
01216                         $outArr[$row['uid']] = $row;
01217                 }
01218                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01219                 return $outArr;
01220         }
01221 
01222 
01223 
01224 
01225 
01226 
01227 
01228 
01229 
01230 
01231 
01232 
01233         /***************************
01234          *
01235          * Various
01236          *
01237          **************************/
01238 
01247         function pi_isOnlyFields($fList,$lowerThan=-1)  {
01248                 $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;
01249 
01250                 $fList = t3lib_div::trimExplode(',',$fList,1);
01251                 $tempPiVars = $this->piVars;
01252                 while(list(,$k)=each($fList))   {
01253                         if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan)         unset($tempPiVars[$k]);
01254                 }
01255                 if (!count($tempPiVars))        return 1;
01256         }
01257 
01267         function pi_autoCache($inArray) {
01268                 if (is_array($inArray)) {
01269                         reset($inArray);
01270                         while(list($fN,$fV)=each($inArray))     {
01271                                 if (!strcmp($inArray[$fN],''))  {
01272                                         unset($inArray[$fN]);
01273                                 } elseif (is_array($this->pi_autoCacheFields[$fN]))     {
01274                                         if (is_array($this->pi_autoCacheFields[$fN]['range'])
01275                                                          && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])
01276                                                          && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1]))  {
01277                                                                 unset($inArray[$fN]);
01278                                         }
01279                                         if (is_array($this->pi_autoCacheFields[$fN]['list'])
01280                                                          && in_array($inArray[$fN],$this->pi_autoCacheFields[$fN]['list']))     {
01281                                                                 unset($inArray[$fN]);
01282                                         }
01283                                 }
01284                         }
01285                 }
01286                 if (!count($inArray))   return 1;
01287         }
01288 
01298         function pi_RTEcssText($str)    {
01299                 $parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];
01300                 if (is_array($parseFunc))       $str = $this->cObj->parseFunc($str, $parseFunc);
01301                 return $str;
01302         }
01303 
01304 
01305 
01306 
01307 
01308         /*******************************
01309          *
01310          * FlexForms related functions
01311          *
01312          *******************************/
01313 
01319         function pi_initPIflexForm()    {
01320                         // Converting flexform data into array:
01321                 if (!is_array($this->cObj->data['pi_flexform']) && $this->cObj->data['pi_flexform'])    {
01322                         $this->cObj->data['pi_flexform'] = t3lib_div::xml2array($this->cObj->data['pi_flexform']);
01323                         if (!is_array($this->cObj->data['pi_flexform']))        $this->cObj->data['pi_flexform']=array();
01324                 }
01325         }
01326 
01337         function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')   {
01338                 $sheetArray = is_array($T3FlexForm_array) ? $T3FlexForm_array['data'][$sheet][$lang] : '';
01339                 if (is_array($sheetArray))      {
01340                         return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
01341                 }
01342         }
01343 
01354         function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)  {
01355 
01356                 $tempArr=$sheetArray;
01357                 foreach($fieldNameArr as $k => $v)      {
01358                         if (t3lib_div::testInt($v))     {
01359                                 if (is_array($tempArr)) {
01360                                         $c=0;
01361                                         foreach($tempArr as $values)    {
01362                                                 if ($c==$v)     {
01363                                                         #debug($values);
01364                                                         $tempArr=$values;
01365                                                         break;
01366                                                 }
01367                                                 $c++;
01368                                         }
01369                                 }
01370                         } else {
01371                                 $tempArr = $tempArr[$v];
01372                         }
01373                 }
01374                 return $tempArr[$value];
01375         }
01376 }
01377 
01378 // NO extension of class - does not make sense here.
01379 ?>


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