📄 class.tslib_pibase.php
字号:
<?php/**************************************************************** Copyright notice** (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)* All rights reserved** This script is part of the TYPO3 project. The TYPO3 project is* free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** The GNU General Public License can be found at* http://www.gnu.org/copyleft/gpl.html.* A copy is found in the textfile GPL.txt and important notices to the license* from the author is found in LICENSE.txt distributed with these scripts.*** This script is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** This copyright notice MUST APPEAR in all copies of the script!***************************************************************//** * This script contains the parent class, 'pibase', providing an API with the most basic methods for frontend plugins * * $Id: class.tslib_pibase.php 1930 2007-01-23 22:43:06Z mundaun $ * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj * XHTML compliant * * @author Kasper Skaarhoj <kasperYYYY@typo3.com> *//** * [CLASS/FUNCTION INDEX of SCRIPT] * * * * 132: class tslib_pibase * * SECTION: Init functions * 214: function tslib_pibase() * 240: function pi_setPiVarDefaults() * * SECTION: Link functions * 277: function pi_getPageLink($id,$target='',$urlParameters=array()) * 293: function pi_linkToPage($str,$id,$target='',$urlParameters=array()) * 308: function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0) * 331: function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) * 355: function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) * 373: function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0) * 401: function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1') * * SECTION: Functions for listing, browsing, searching etc. * 456: function pi_list_browseresults($showResultCount=1,$tableParams='',$wrapArr=array(), $pointerName = 'pointer', $hscText = TRUE) * 618: function pi_list_searchBox($tableParams='') * 649: function pi_list_modeSelector($items=array(),$tableParams='') * 687: function pi_list_makelist($res,$tableParams='') * 722: function pi_list_row($c) * 734: function pi_list_header() * * SECTION: Stylesheet, CSS * 765: function pi_getClassName($class) * 777: function pi_classParam($class) * 791: function pi_setClassStyle($class,$data,$selector='') * 802: function pi_wrapInBaseClass($str) * * SECTION: Frontend editing: Edit panel, edit icons * 858: function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) * 900: function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array()) * * SECTION: Localization, locallang functions * 947: function pi_getLL($key,$alt='',$hsc=FALSE) * 970: function pi_loadLL() * * SECTION: Database, queries * 1048: function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE) * 1140: function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='') * 1155: function pi_getRecord($table,$uid,$checkPage=0) * 1166: function pi_getPidList($pid_list,$recursive=0) * 1191: function pi_prependFieldsWithTable($table,$fieldList) * 1211: function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='') * * SECTION: Various * 1255: function pi_isOnlyFields($fList,$lowerThan=-1) * 1275: function pi_autoCache($inArray) * 1306: function pi_RTEcssText($str) * * SECTION: FlexForms related functions * 1328: function pi_initPIflexForm($field='pi_flexform') * 1346: function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF') * 1363: function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value) * * TOTAL FUNCTIONS: 35 * (This index is automatically created/updated by the extension "extdeveval") * *//** * Base class for frontend plugins * Most modern frontend plugins are extension classes of this one. * This class contains functions which assists these plugins in creating lists, searching, displaying menus, page-browsing (next/previous/1/2/3) and handling links. * Functions are all prefixed "pi_" which is reserved for this class. Those functions can of course be overridden in the extension classes (that is the point...) * * @author Kasper Skaarhoj <kasperYYYY@typo3.com> * @package TYPO3 * @subpackage tslib */class tslib_pibase { // Reserved variables: var $cObj; // The backReference to the mother cObj object set at call time var $prefixId; // Should be same as classname of the plugin, used for CSS classes, variables var $scriptRelPath; // Path to the plugin class script relative to extension directory, eg. 'pi1/class.tx_newfaq_pi1.php' var $extKey; // Extension key. var $piVars = Array ( // This is the 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[...]=... 'pointer' => '', // Used as a pointer for lists 'mode' => '', // List mode 'sword' => '', // Search word 'sort' => '', // [Sorting column]:[ASC=0/DESC=1] ); var $internal = Array( // Used internally for general storage of values between methods 'res_count' => 0, // Total query count 'results_at_a_time' => 20, // pi_list_browseresults(): Show number of results at a time 'maxPages' => 10, // pi_list_browseresults(): Max number of 'Page 1 - Page 2 - ...' in the list browser 'currentRow' => Array(), // Current result row 'currentTable' => '', // Current table ); var $LOCAL_LANG = Array(); // Local Language content var $LOCAL_LANG_charset = Array(); // Local Language content charset for individual labels (overriding) var $LOCAL_LANG_loaded = 0; // Flag that tells if the locallang file has been fetch (or tried to be fetched) already. var $LLkey='default'; // Pointer to the language to use. var $altLLkey=''; // Pointer to alternative fall-back language to use. 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. var $LLtestPrefixAlt=''; // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls var $pi_isOnlyFields = 'mode,pointer'; var $pi_alwaysPrev = 0; var $pi_lowerThan = 5; var $pi_moreParams=''; var $pi_listFields='*'; var $pi_autoCacheFields=array(); var $pi_autoCacheEn=0; 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!) 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!) /** * Should normally be set in the main function with the TypoScript content passed to the method. * * $conf[LOCAL_LANG][_key_] is reserved for Local Language overrides. * $conf[userFunc] / $conf[includeLibs] reserved for setting up the USER / USER_INT object. See TSref */ var $conf = Array(); // internal, don't mess with... var $pi_EPtemp_cObj; var $pi_tmpPageId=0; /*************************** * * Init functions * **************************/ /** * Class Constructor (true constructor) * Initializes $this->piVars if $this->prefixId is set to any value * Will also set $this->LLkey based on the config.language setting. * * @return void */ function tslib_pibase() { // Setting piVars: if ($this->prefixId) { $this->piVars = t3lib_div::GParrayMerged($this->prefixId); // cHash mode check // 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. // 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! if ($this->pi_checkCHash && count($this->piVars)) { $GLOBALS['TSFE']->reqCHash(); } } if ($GLOBALS['TSFE']->config['config']['language']) { $this->LLkey = $GLOBALS['TSFE']->config['config']['language']; if ($GLOBALS['TSFE']->config['config']['language_alt']) { $this->altLLkey = $GLOBALS['TSFE']->config['config']['language_alt']; } } } /** * If internal TypoScript property "_DEFAULT_PI_VARS." is set then it will merge the current $this->piVars array onto these default values. * * @return void */ function pi_setPiVarDefaults() { if (is_array($this->conf['_DEFAULT_PI_VARS.'])) { $this->piVars = t3lib_div::array_merge_recursive_overrule($this->conf['_DEFAULT_PI_VARS.'],is_array($this->piVars)?$this->piVars:array()); } } /*************************** * * Link functions * **************************/ /** * Get URL to some page. * Returns the URL to page $id with $target and an array of additional url-parameters, $urlParameters * Simple example: $this->pi_getPageLink(123) to get the URL for page-id 123. * * The function basically calls $this->cObj->getTypoLink_URL() * * @param integer Page id * @param string Target value to use. Affects the &type-value of the URL, defaults to current. * @param array Additional URL parameters to set (key/value pairs) * @return string The resulting URL * @see pi_linkToPage() */ function pi_getPageLink($id,$target='',$urlParameters=array()) { return $this->cObj->getTypoLink_URL($id,$urlParameters,$target); // ?$target:$GLOBALS['TSFE']->sPre } /** * Link a string to some page. * Like pi_getPageLink() but takes a string as first parameter which will in turn be wrapped with the URL including target attribute * Simple example: $this->pi_linkToPage('My link', 123) to get something like <a href="index.php?id=123&type=1">My link</a> (or <a href="123.1.html">My link</a> if simulateStaticDocuments is set) * * @param string The content string to wrap in <a> tags * @param integer Page id * @param string Target value to use. Affects the &type-value of the URL, defaults to current. * @param array Additional URL parameters to set (key/value pairs) * @return string The input string wrapped in <a> tags with the URL and target set. * @see pi_getPageLink(), tslib_cObj::getTypoLink() */ function pi_linkToPage($str,$id,$target='',$urlParameters=array()) { return $this->cObj->getTypoLink($str,$id,$urlParameters,$target); // ?$target:$GLOBALS['TSFE']->sPre } /** * Link string to the current page. * Returns the $str wrapped in <a>-tags with a link to the CURRENT page, but with $urlParameters set as extra parameters for the page. * * @param string The content string to wrap in <a> tags * @param array Array with URL parameters as key/value pairs. They will be "imploded" and added to the list of parameters defined in the plugins TypoScript property "parent.addParams" plus $this->pi_moreParams. * @param boolean If $cache is set (0/1), the page is asked to be cached by a &cHash value (unless the current plugin using this class is a USER_INT). Otherwise the no_cache-parameter will be a part of the link. * @param integer Alternative page ID for the link. (By default this function links to the SAME page!) * @return string The input string wrapped in <a> tags * @see pi_linkTP_keepPIvars(), tslib_cObj::typoLink() */ function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0) { $conf=array(); $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache; $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache; $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id); $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('',$urlParameters,'',1).$this->pi_moreParams; return $this->cObj->typoLink($str, $conf); } /** * Link a string to the current page while keeping currently set values in piVars. * Like pi_linkTP, but $urlParameters is by default set to $this->piVars with $overrulePIvars overlaid. * This means any current entries from this->piVars are passed on (except the key "DATA" which will be unset before!) and entries in $overrulePIvars will OVERRULE the current in the link. * * @param string The content string to wrap in <a> tags * @param array Array of values to override in the current piVars. Contrary to pi_linkTP the keys in this array must correspond to the real piVars array and therefore NOT be prefixed with the $this->prefixId string. Further, if a value is a blank string it means the piVar key will not be a part of the link (unset) * @param boolean If $cache is set, the page is asked to be cached by a &cHash value (unless the current plugin using this class is a USER_INT). Otherwise the no_cache-parameter will be a part of the link. * @param boolean If set, then the current values of piVars will NOT be preserved anyways... Practical if you want an easy way to set piVars without having to worry about the prefix, "tx_xxxxx[]" * @param integer Alternative page ID for the link. (By default this function links to the SAME page!) * @return string The input string wrapped in <a> tags * @see pi_linkTP() */ function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) { if (is_array($this->piVars) && is_array($overrulePIvars) && !$clearAnyway) { $piVars = $this->piVars; unset($piVars['DATA']); $overrulePIvars = t3lib_div::array_merge_recursive_overrule($piVars,$overrulePIvars); if ($this->pi_autoCacheEn) { $cache = $this->pi_autoCache($overrulePIvars); } } $res = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId); return $res; } /** * Get URL to the current page while keeping currently set values in piVars. * Same as pi_linkTP_keepPIvars but returns only the URL from the link. * * @param array See pi_linkTP_keepPIvars * @param boolean See pi_linkTP_keepPIvars * @param boolean See pi_linkTP_keepPIvars * @param integer See pi_linkTP_keepPIvars * @return string The URL ($this->cObj->lastTypoLinkUrl) * @see pi_linkTP_keepPIvars() */ function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) { $this->pi_linkTP_keepPIvars('|',$overrulePIvars,$cache,$clearAnyway,$altPageId); return $this->cObj->lastTypoLinkUrl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -