PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/typo3/sysext/cms/tslib/class.tslib_pibase.php

https://bitbucket.org/linxpinx/mercurial
PHP | 1399 lines | 591 code | 242 blank | 566 comment | 107 complexity | 017f1f121d74bbad55ab638c80798afb MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
  6. * All rights reserved
  7. *
  8. * This script is part of the TYPO3 project. The TYPO3 project is
  9. * free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * The GNU General Public License can be found at
  15. * http://www.gnu.org/copyleft/gpl.html.
  16. * A copy is found in the textfile GPL.txt and important notices to the license
  17. * from the author is found in LICENSE.txt distributed with these scripts.
  18. *
  19. *
  20. * This script is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * This copyright notice MUST APPEAR in all copies of the script!
  26. ***************************************************************/
  27. /**
  28. * This script contains the parent class, 'pibase', providing an API with the most basic methods for frontend plugins
  29. *
  30. * $Id: class.tslib_pibase.php 7905 2010-06-13 14:42:33Z ohader $
  31. * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
  32. * XHTML compliant
  33. *
  34. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  35. */
  36. /**
  37. * [CLASS/FUNCTION INDEX of SCRIPT]
  38. *
  39. *
  40. *
  41. * 132: class tslib_pibase
  42. *
  43. * SECTION: Init functions
  44. * 214: function tslib_pibase()
  45. * 240: function pi_setPiVarDefaults()
  46. *
  47. * SECTION: Link functions
  48. * 277: function pi_getPageLink($id,$target='',$urlParameters=array())
  49. * 293: function pi_linkToPage($str,$id,$target='',$urlParameters=array())
  50. * 308: function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0)
  51. * 331: function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)
  52. * 355: function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)
  53. * 373: function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0)
  54. * 401: function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')
  55. *
  56. * SECTION: Functions for listing, browsing, searching etc.
  57. * 456: function pi_list_browseresults($showResultCount=1,$tableParams='',$wrapArr=array(), $pointerName = 'pointer', $hscText = TRUE)
  58. * 618: function pi_list_searchBox($tableParams='')
  59. * 649: function pi_list_modeSelector($items=array(),$tableParams='')
  60. * 687: function pi_list_makelist($res,$tableParams='')
  61. * 722: function pi_list_row($c)
  62. * 734: function pi_list_header()
  63. *
  64. * SECTION: Stylesheet, CSS
  65. * 765: function pi_getClassName($class)
  66. * 777: function pi_classParam($class)
  67. * 791: function pi_setClassStyle($class,$data,$selector='')
  68. * 802: function pi_wrapInBaseClass($str)
  69. *
  70. * SECTION: Frontend editing: Edit panel, edit icons
  71. * 858: function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array())
  72. * 900: function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array())
  73. *
  74. * SECTION: Localization, locallang functions
  75. * 947: function pi_getLL($key,$alt='',$hsc=FALSE)
  76. * 970: function pi_loadLL()
  77. *
  78. * SECTION: Database, queries
  79. * 1048: function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)
  80. * 1140: function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')
  81. * 1155: function pi_getRecord($table,$uid,$checkPage=0)
  82. * 1166: function pi_getPidList($pid_list,$recursive=0)
  83. * 1191: function pi_prependFieldsWithTable($table,$fieldList)
  84. * 1211: function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')
  85. *
  86. * SECTION: Various
  87. * 1255: function pi_isOnlyFields($fList,$lowerThan=-1)
  88. * 1275: function pi_autoCache($inArray)
  89. * 1306: function pi_RTEcssText($str)
  90. *
  91. * SECTION: FlexForms related functions
  92. * 1328: function pi_initPIflexForm($field='pi_flexform')
  93. * 1346: function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')
  94. * 1363: function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)
  95. *
  96. * TOTAL FUNCTIONS: 35
  97. * (This index is automatically created/updated by the extension "extdeveval")
  98. *
  99. */
  100. /**
  101. * Base class for frontend plugins
  102. * Most modern frontend plugins are extension classes of this one.
  103. * This class contains functions which assists these plugins in creating lists, searching, displaying menus, page-browsing (next/previous/1/2/3) and handling links.
  104. * 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...)
  105. *
  106. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  107. * @package TYPO3
  108. * @subpackage tslib
  109. */
  110. class tslib_pibase {
  111. // Reserved variables:
  112. /**
  113. * The backReference to the mother cObj object set at call time
  114. *
  115. * @var tslib_cObj
  116. */
  117. var $cObj;
  118. var $prefixId; // Should be same as classname of the plugin, used for CSS classes, variables
  119. var $scriptRelPath; // Path to the plugin class script relative to extension directory, eg. 'pi1/class.tx_newfaq_pi1.php'
  120. var $extKey; // Extension key.
  121. 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[...]=...
  122. 'pointer' => '', // Used as a pointer for lists
  123. 'mode' => '', // List mode
  124. 'sword' => '', // Search word
  125. 'sort' => '', // [Sorting column]:[ASC=0/DESC=1]
  126. );
  127. var $internal = Array( // Used internally for general storage of values between methods
  128. 'res_count' => 0, // Total query count
  129. 'results_at_a_time' => 20, // pi_list_browseresults(): Show number of results at a time
  130. 'maxPages' => 10, // pi_list_browseresults(): Max number of 'Page 1 - Page 2 - ...' in the list browser
  131. 'currentRow' => Array(), // Current result row
  132. 'currentTable' => '', // Current table
  133. );
  134. var $LOCAL_LANG = Array(); // Local Language content
  135. var $LOCAL_LANG_charset = Array(); // Local Language content charset for individual labels (overriding)
  136. var $LOCAL_LANG_loaded = 0; // Flag that tells if the locallang file has been fetch (or tried to be fetched) already.
  137. var $LLkey='default'; // Pointer to the language to use.
  138. var $altLLkey=''; // Pointer to alternative fall-back language to use.
  139. 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.
  140. var $LLtestPrefixAlt=''; // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
  141. var $pi_isOnlyFields = 'mode,pointer';
  142. var $pi_alwaysPrev = 0;
  143. var $pi_lowerThan = 5;
  144. var $pi_moreParams='';
  145. var $pi_listFields='*';
  146. var $pi_autoCacheFields=array();
  147. var $pi_autoCacheEn=0;
  148. 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!)
  149. 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!)
  150. /**
  151. * Should normally be set in the main function with the TypoScript content passed to the method.
  152. *
  153. * $conf[LOCAL_LANG][_key_] is reserved for Local Language overrides.
  154. * $conf[userFunc] / $conf[includeLibs] reserved for setting up the USER / USER_INT object. See TSref
  155. */
  156. var $conf = Array();
  157. // internal, don't mess with...
  158. var $pi_EPtemp_cObj;
  159. var $pi_tmpPageId=0;
  160. /***************************
  161. *
  162. * Init functions
  163. *
  164. **************************/
  165. /**
  166. * Class Constructor (true constructor)
  167. * Initializes $this->piVars if $this->prefixId is set to any value
  168. * Will also set $this->LLkey based on the config.language setting.
  169. *
  170. * @return void
  171. */
  172. function tslib_pibase() {
  173. // Setting piVars:
  174. if ($this->prefixId) {
  175. $this->piVars = t3lib_div::_GPmerged($this->prefixId);
  176. // cHash mode check
  177. // 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.
  178. // 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!
  179. if ($this->pi_checkCHash && count($this->piVars)) {
  180. $GLOBALS['TSFE']->reqCHash();
  181. }
  182. }
  183. if (!empty($GLOBALS['TSFE']->config['config']['language'])) {
  184. $this->LLkey = $GLOBALS['TSFE']->config['config']['language'];
  185. if (!empty($GLOBALS['TSFE']->config['config']['language_alt'])) {
  186. $this->altLLkey = $GLOBALS['TSFE']->config['config']['language_alt'];
  187. }
  188. }
  189. }
  190. /**
  191. * If internal TypoScript property "_DEFAULT_PI_VARS." is set then it will merge the current $this->piVars array onto these default values.
  192. *
  193. * @return void
  194. */
  195. function pi_setPiVarDefaults() {
  196. if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
  197. $this->piVars = t3lib_div::array_merge_recursive_overrule($this->conf['_DEFAULT_PI_VARS.'],is_array($this->piVars)?$this->piVars:array());
  198. }
  199. }
  200. /***************************
  201. *
  202. * Link functions
  203. *
  204. **************************/
  205. /**
  206. * Get URL to some page.
  207. * Returns the URL to page $id with $target and an array of additional url-parameters, $urlParameters
  208. * Simple example: $this->pi_getPageLink(123) to get the URL for page-id 123.
  209. *
  210. * The function basically calls $this->cObj->getTypoLink_URL()
  211. *
  212. * @param integer Page id
  213. * @param string Target value to use. Affects the &type-value of the URL, defaults to current.
  214. * @param array Additional URL parameters to set (key/value pairs)
  215. * @return string The resulting URL
  216. * @see pi_linkToPage()
  217. */
  218. function pi_getPageLink($id,$target='',$urlParameters=array()) {
  219. return $this->cObj->getTypoLink_URL($id,$urlParameters,$target); // ?$target:$GLOBALS['TSFE']->sPre
  220. }
  221. /**
  222. * Link a string to some page.
  223. * Like pi_getPageLink() but takes a string as first parameter which will in turn be wrapped with the URL including target attribute
  224. * 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)
  225. *
  226. * @param string The content string to wrap in <a> tags
  227. * @param integer Page id
  228. * @param string Target value to use. Affects the &type-value of the URL, defaults to current.
  229. * @param array Additional URL parameters to set (key/value pairs)
  230. * @return string The input string wrapped in <a> tags with the URL and target set.
  231. * @see pi_getPageLink(), tslib_cObj::getTypoLink()
  232. */
  233. function pi_linkToPage($str,$id,$target='',$urlParameters=array()) {
  234. return $this->cObj->getTypoLink($str,$id,$urlParameters,$target); // ?$target:$GLOBALS['TSFE']->sPre
  235. }
  236. /**
  237. * Link string to the current page.
  238. * Returns the $str wrapped in <a>-tags with a link to the CURRENT page, but with $urlParameters set as extra parameters for the page.
  239. *
  240. * @param string The content string to wrap in <a> tags
  241. * @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.
  242. * @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.
  243. * @param integer Alternative page ID for the link. (By default this function links to the SAME page!)
  244. * @return string The input string wrapped in <a> tags
  245. * @see pi_linkTP_keepPIvars(), tslib_cObj::typoLink()
  246. */
  247. function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0) {
  248. $conf=array();
  249. $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
  250. $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
  251. $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id);
  252. $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('', $urlParameters, '', true).$this->pi_moreParams;
  253. return $this->cObj->typoLink($str, $conf);
  254. }
  255. /**
  256. * Link a string to the current page while keeping currently set values in piVars.
  257. * Like pi_linkTP, but $urlParameters is by default set to $this->piVars with $overrulePIvars overlaid.
  258. * 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.
  259. *
  260. * @param string The content string to wrap in <a> tags
  261. * @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)
  262. * @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.
  263. * @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[]"
  264. * @param integer Alternative page ID for the link. (By default this function links to the SAME page!)
  265. * @return string The input string wrapped in <a> tags
  266. * @see pi_linkTP()
  267. */
  268. function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) {
  269. if (is_array($this->piVars) && is_array($overrulePIvars) && !$clearAnyway) {
  270. $piVars = $this->piVars;
  271. unset($piVars['DATA']);
  272. $overrulePIvars = t3lib_div::array_merge_recursive_overrule($piVars,$overrulePIvars);
  273. if ($this->pi_autoCacheEn) {
  274. $cache = $this->pi_autoCache($overrulePIvars);
  275. }
  276. }
  277. $res = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
  278. return $res;
  279. }
  280. /**
  281. * Get URL to the current page while keeping currently set values in piVars.
  282. * Same as pi_linkTP_keepPIvars but returns only the URL from the link.
  283. *
  284. * @param array See pi_linkTP_keepPIvars
  285. * @param boolean See pi_linkTP_keepPIvars
  286. * @param boolean See pi_linkTP_keepPIvars
  287. * @param integer See pi_linkTP_keepPIvars
  288. * @return string The URL ($this->cObj->lastTypoLinkUrl)
  289. * @see pi_linkTP_keepPIvars()
  290. */
  291. function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) {
  292. $this->pi_linkTP_keepPIvars('|',$overrulePIvars,$cache,$clearAnyway,$altPageId);
  293. return $this->cObj->lastTypoLinkUrl;
  294. }
  295. /**
  296. * Wraps the $str in a link to a single display of the record (using piVars[showUid])
  297. * Uses pi_linkTP for the linking
  298. *
  299. * @param string The content string to wrap in <a> tags
  300. * @param integer UID of the record for which to display details (basically this will become the value of [showUid]
  301. * @param boolean See pi_linkTP_keepPIvars
  302. * @param array Array of values to override in the current piVars. Same as $overrulePIvars in pi_linkTP_keepPIvars
  303. * @param boolean If true, only the URL is returned, not a full link
  304. * @param integer Alternative page ID for the link. (By default this function links to the SAME page!)
  305. * @return string The input string wrapped in <a> tags
  306. * @see pi_linkTP(), pi_linkTP_keepPIvars()
  307. */
  308. function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0) {
  309. if ($this->prefixId) {
  310. if ($cache) {
  311. $overrulePIvars=$uid?array('showUid'=>$uid):Array();
  312. $overrulePIvars=array_merge($overrulePIvars,(array)$mergeArr);
  313. $str = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
  314. } else {
  315. $overrulePIvars=array('showUid'=>$uid?$uid:'');
  316. $overrulePIvars=array_merge($overrulePIvars,(array)$mergeArr);
  317. $str = $this->pi_linkTP_keepPIvars($str,$overrulePIvars,$cache,0,$altPageId);
  318. }
  319. // If urlOnly flag, return only URL as it has recently be generated.
  320. if ($urlOnly) {
  321. $str = $this->cObj->lastTypoLinkUrl;
  322. }
  323. }
  324. return $str;
  325. }
  326. /**
  327. * Will change the href value from <a> in the input string and turn it into an onclick event that will open a new window with the URL
  328. *
  329. * @param string The string to process. This should be a string already wrapped/including a <a> tag which will be modified to contain an onclick handler. Only the attributes "href" and "onclick" will be left.
  330. * @param string Window name for the pop-up window
  331. * @param string Window parameters, see the default list for inspiration
  332. * @return string The processed input string, modified IF a <a> tag was found
  333. */
  334. function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1') {
  335. if (preg_match('/(.*)(<a[^>]*>)(.*)/i',$str,$match)) {
  336. $aTagContent = t3lib_div::get_tag_attributes($match[2]);
  337. $match[2]='<a href="#" onclick="'.
  338. htmlspecialchars('vHWin=window.open(\''.$GLOBALS['TSFE']->baseUrlWrap($aTagContent['href']).'\',\''.($winName?$winName:md5($aTagContent['href'])).'\',\''.$winParams.'\');vHWin.focus();return false;').
  339. '">';
  340. $str=$match[1].$match[2].$match[3];
  341. }
  342. return $str;
  343. }
  344. /***************************
  345. *
  346. * Functions for listing, browsing, searching etc.
  347. *
  348. **************************/
  349. /**
  350. * Returns a results browser. This means a bar of page numbers plus a "previous" and "next" link. For each entry in the bar the piVars "pointer" will be pointing to the "result page" to show.
  351. * Using $this->piVars['pointer'] as pointer to the page to display. Can be overwritten with another string ($pointerName) to make it possible to have more than one pagebrowser on a page)
  352. * Using $this->internal['res_count'], $this->internal['results_at_a_time'] and $this->internal['maxPages'] for count number, how many results to show and the max number of pages to include in the browse bar.
  353. * Using $this->internal['dontLinkActivePage'] as switch if the active (current) page should be displayed as pure text or as a link to itself
  354. * Using $this->internal['showFirstLast'] as switch if the two links named "<< First" and "LAST >>" will be shown and point to the first or last page.
  355. * Using $this->internal['pagefloat']: this defines were the current page is shown in the list of pages in the Pagebrowser. If this var is an integer it will be interpreted as position in the list of pages. If its value is the keyword "center" the current page will be shown in the middle of the pagelist.
  356. * Using $this->internal['showRange']: this var switches the display of the pagelinks from pagenumbers to ranges f.e.: 1-5 6-10 11-15... instead of 1 2 3...
  357. * Using $this->pi_isOnlyFields: this holds a comma-separated list of fieldnames which - if they are among the GETvars - will not disable caching for the page with pagebrowser.
  358. *
  359. * The third parameter is an array with several wraps for the parts of the pagebrowser. The following elements will be recognized:
  360. * disabledLinkWrap, inactiveLinkWrap, activeLinkWrap, browseLinksWrap, showResultsWrap, showResultsNumbersWrap, browseBoxWrap.
  361. *
  362. * If $wrapArr['showResultsNumbersWrap'] is set, the formatting string is expected to hold template markers (###FROM###, ###TO###, ###OUT_OF###, ###FROM_TO###, ###CURRENT_PAGE###, ###TOTAL_PAGES###)
  363. * otherwise the formatting string is expected to hold sprintf-markers (%s) for from, to, outof (in that sequence)
  364. *
  365. * @param integer determines how the results of the pagerowser will be shown. See description below
  366. * @param string Attributes for the table tag which is wrapped around the table cells containing the browse links
  367. * @param array Array with elements to overwrite the default $wrapper-array.
  368. * @param string varname for the pointer.
  369. * @param boolean enable htmlspecialchars() for the pi_getLL function (set this to FALSE if you want f.e use images instead of text for links like 'previous' and 'next').
  370. * @param boolean forces the output of the page browser if you set this option to "true" (otherwise it's only drawn if enough entries are available)
  371. * @return string Output HTML-Table, wrapped in <div>-tags with a class attribute (if $wrapArr is not passed,
  372. */
  373. function pi_list_browseresults($showResultCount=1, $tableParams='', $wrapArr=array(), $pointerName='pointer', $hscText=TRUE, $forceOutput=FALSE) {
  374. // example $wrapArr-array how it could be traversed from an extension
  375. /* $wrapArr = array(
  376. 'browseBoxWrap' => '<div class="browseBoxWrap">|</div>',
  377. 'showResultsWrap' => '<div class="showResultsWrap">|</div>',
  378. 'browseLinksWrap' => '<div class="browseLinksWrap">|</div>',
  379. 'showResultsNumbersWrap' => '<span class="showResultsNumbersWrap">|</span>',
  380. 'disabledLinkWrap' => '<span class="disabledLinkWrap">|</span>',
  381. 'inactiveLinkWrap' => '<span class="inactiveLinkWrap">|</span>',
  382. 'activeLinkWrap' => '<span class="activeLinkWrap">|</span>'
  383. ); */
  384. // Initializing variables:
  385. $pointer = intval($this->piVars[$pointerName]);
  386. $count = intval($this->internal['res_count']);
  387. $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
  388. $totalPages = ceil($count/$results_at_a_time);
  389. $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
  390. $pi_isOnlyFields = $this->pi_isOnlyFields($this->pi_isOnlyFields);
  391. if (!$forceOutput && $count <= $results_at_a_time) {
  392. return '';
  393. }
  394. // $showResultCount determines how the results of the pagerowser will be shown.
  395. // If set to 0: only the result-browser will be shown
  396. // 1: (default) the text "Displaying results..." and the result-browser will be shown.
  397. // 2: only the text "Displaying results..." will be shown
  398. $showResultCount = intval($showResultCount);
  399. // if this is set, two links named "<< First" and "LAST >>" will be shown and point to the very first or last page.
  400. $showFirstLast = $this->internal['showFirstLast'];
  401. // if this has a value the "previous" button is always visible (will be forced if "showFirstLast" is set)
  402. $alwaysPrev = $showFirstLast?1:$this->pi_alwaysPrev;
  403. if (isset($this->internal['pagefloat'])) {
  404. if (strtoupper($this->internal['pagefloat']) == 'CENTER') {
  405. $pagefloat = ceil(($maxPages - 1)/2);
  406. } else {
  407. // pagefloat set as integer. 0 = left, value >= $this->internal['maxPages'] = right
  408. $pagefloat = t3lib_div::intInRange($this->internal['pagefloat'],-1,$maxPages-1);
  409. }
  410. } else {
  411. $pagefloat = -1; // pagefloat disabled
  412. }
  413. // default values for "traditional" wrapping with a table. Can be overwritten by vars from $wrapArr
  414. $wrapper['disabledLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
  415. $wrapper['inactiveLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
  416. $wrapper['activeLinkWrap'] = '<td'.$this->pi_classParam('browsebox-SCell').' nowrap="nowrap"><p>|</p></td>';
  417. $wrapper['browseLinksWrap'] = trim('<table '.$tableParams).'><tr>|</tr></table>';
  418. $wrapper['showResultsWrap'] = '<p>|</p>';
  419. $wrapper['browseBoxWrap'] = '
  420. <!--
  421. List browsing box:
  422. -->
  423. <div '.$this->pi_classParam('browsebox').'>
  424. |
  425. </div>';
  426. // now overwrite all entries in $wrapper which are also in $wrapArr
  427. $wrapper = array_merge($wrapper,$wrapArr);
  428. if ($showResultCount != 2) { //show pagebrowser
  429. if ($pagefloat > -1) {
  430. $lastPage = min($totalPages,max($pointer+1 + $pagefloat,$maxPages));
  431. $firstPage = max(0,$lastPage-$maxPages);
  432. } else {
  433. $firstPage = 0;
  434. $lastPage = t3lib_div::intInRange($totalPages,1,$maxPages);
  435. }
  436. $links=array();
  437. // Make browse-table/links:
  438. if ($showFirstLast) { // Link to first page
  439. if ($pointer>0) {
  440. $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),array($pointerName => null),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
  441. } else {
  442. $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),$wrapper['disabledLinkWrap']);
  443. }
  444. }
  445. if ($alwaysPrev>=0) { // Link to previous page
  446. if ($pointer>0) {
  447. $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']);
  448. } elseif ($alwaysPrev) {
  449. $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),$wrapper['disabledLinkWrap']);
  450. }
  451. }
  452. for($a=$firstPage;$a<$lastPage;$a++) { // Links to pages
  453. if ($this->internal['showRange']) {
  454. $pageText = (($a*$results_at_a_time)+1).'-'.min($count,(($a+1)*$results_at_a_time));
  455. } else {
  456. $pageText = trim($this->pi_getLL('pi_list_browseresults_page','Page',$hscText).' '.($a+1));
  457. }
  458. if ($pointer == $a) { // current page
  459. if ($this->internal['dontLinkActivePage']) {
  460. $links[] = $this->cObj->wrap($pageText,$wrapper['activeLinkWrap']);
  461. } else {
  462. $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['activeLinkWrap']);
  463. }
  464. } else {
  465. $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
  466. }
  467. }
  468. if ($pointer<$totalPages-1 || $showFirstLast) {
  469. if ($pointer>=$totalPages-1) { // Link to next page
  470. $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),$wrapper['disabledLinkWrap']);
  471. } else {
  472. $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']);
  473. }
  474. }
  475. if ($showFirstLast) { // Link to last page
  476. if ($pointer<$totalPages-1) {
  477. $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']);
  478. } else {
  479. $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),$wrapper['disabledLinkWrap']);
  480. }
  481. }
  482. $theLinks = $this->cObj->wrap(implode(LF,$links),$wrapper['browseLinksWrap']);
  483. } else {
  484. $theLinks = '';
  485. }
  486. $pR1 = $pointer*$results_at_a_time+1;
  487. $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
  488. if ($showResultCount) {
  489. if ($wrapper['showResultsNumbersWrap']) {
  490. // this will render the resultcount in a more flexible way using markers (new in TYPO3 3.8.0).
  491. // the formatting string is expected to hold template markers (see function header). Example: 'Displaying results ###FROM### to ###TO### out of ###OUT_OF###'
  492. $markerArray['###FROM###'] = $this->cObj->wrap($this->internal['res_count'] > 0 ? $pR1 : 0,$wrapper['showResultsNumbersWrap']);
  493. $markerArray['###TO###'] = $this->cObj->wrap(min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
  494. $markerArray['###OUT_OF###'] = $this->cObj->wrap($this->internal['res_count'],$wrapper['showResultsNumbersWrap']);
  495. $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']);
  496. $markerArray['###CURRENT_PAGE###'] = $this->cObj->wrap($pointer+1,$wrapper['showResultsNumbersWrap']);
  497. $markerArray['###TOTAL_PAGES###'] = $this->cObj->wrap($totalPages,$wrapper['showResultsNumbersWrap']);
  498. // substitute markers
  499. $resultCountMsg = $this->cObj->substituteMarkerArray($this->pi_getLL('pi_list_browseresults_displays','Displaying results ###FROM### to ###TO### out of ###OUT_OF###'),$markerArray);
  500. } else {
  501. // render the resultcount in the "traditional" way using sprintf
  502. $resultCountMsg = sprintf(
  503. 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>')),
  504. $count > 0 ? $pR1 : 0,
  505. min($count,$pR2),
  506. $count);
  507. }
  508. $resultCountMsg = $this->cObj->wrap($resultCountMsg,$wrapper['showResultsWrap']);
  509. } else {
  510. $resultCountMsg = '';
  511. }
  512. $sTables = $this->cObj->wrap($resultCountMsg.$theLinks,$wrapper['browseBoxWrap']);
  513. return $sTables;
  514. }
  515. /**
  516. * Returns a Search box, sending search words to piVars "sword" and setting the "no_cache" parameter as well in the form.
  517. * Submits the search request to the current REQUEST_URI
  518. *
  519. * @param string Attributes for the table tag which is wrapped around the table cells containing the search box
  520. * @return string Output HTML, wrapped in <div>-tags with a class attribute
  521. */
  522. function pi_list_searchBox($tableParams='') {
  523. // Search box design:
  524. $sTables = '
  525. <!--
  526. List search box:
  527. -->
  528. <div'.$this->pi_classParam('searchbox').'>
  529. <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
  530. <'.trim('table '.$tableParams).'>
  531. <tr>
  532. <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
  533. <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' />'.
  534. '<input type="hidden" name="no_cache" value="1" />'.
  535. '<input type="hidden" name="'.$this->prefixId.'[pointer]" value="" />'.
  536. '</td>
  537. </tr>
  538. </table>
  539. </form>
  540. </div>';
  541. return $sTables;
  542. }
  543. /**
  544. * Returns a mode selector; a little menu in a table normally put in the top of the page/list.
  545. *
  546. * @param array Key/Value pairs for the menu; keys are the piVars[mode] values and the "values" are the labels for them.
  547. * @param string Attributes for the table tag which is wrapped around the table cells containing the menu
  548. * @return string Output HTML, wrapped in <div>-tags with a class attribute
  549. */
  550. function pi_list_modeSelector($items=array(),$tableParams='') {
  551. $cells=array();
  552. foreach ($items as $k => $v) {
  553. $cells[]='
  554. <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
  555. $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
  556. '</p></td>';
  557. }
  558. $sTables = '
  559. <!--
  560. Mode selector (menu for list):
  561. -->
  562. <div'.$this->pi_classParam('modeSelector').'>
  563. <'.trim('table '.$tableParams).'>
  564. <tr>
  565. '.implode('',$cells).'
  566. </tr>
  567. </table>
  568. </div>';
  569. return $sTables;
  570. }
  571. /**
  572. * Returns the list of items based on the input SQL result pointer
  573. * For each result row the internal var, $this->internal['currentRow'], is set with the row returned.
  574. * $this->pi_list_header() makes the header row for the list
  575. * $this->pi_list_row() is used for rendering each row
  576. * Notice that these two functions are typically ALWAYS defined in the extension class of the plugin since they are directly concerned with the specific layout for that plugins purpose.
  577. *
  578. * @param pointer Result pointer to a SQL result which can be traversed.
  579. * @param string Attributes for the table tag which is wrapped around the table rows containing the list
  580. * @return string Output HTML, wrapped in <div>-tags with a class attribute
  581. * @see pi_list_row(), pi_list_header()
  582. */
  583. function pi_list_makelist($res,$tableParams='') {
  584. // Make list table header:
  585. $tRows=array();
  586. $this->internal['currentRow']='';
  587. $tRows[] = $this->pi_list_header();
  588. // Make list table rows
  589. $c=0;
  590. while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  591. $tRows[] = $this->pi_list_row($c);
  592. $c++;
  593. }
  594. $out = '
  595. <!--
  596. Record list:
  597. -->
  598. <div'.$this->pi_classParam('listrow').'>
  599. <'.trim('table '.$tableParams).'>
  600. '.implode('',$tRows).'
  601. </table>
  602. </div>';
  603. return $out;
  604. }
  605. /**
  606. * Returns a list row. Get data from $this->internal['currentRow'];
  607. * (Dummy)
  608. * Notice: This function should ALWAYS be defined in the extension class of the plugin since it is directly concerned with the specific layout of the listing for your plugins purpose.
  609. *
  610. * @param integer Row counting. Starts at 0 (zero). Used for alternating class values in the output rows.
  611. * @return string HTML output, a table row with a class attribute set (alternative based on odd/even rows)
  612. */
  613. function pi_list_row($c) {
  614. // Dummy
  615. return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
  616. }
  617. /**
  618. * Returns a list header row.
  619. * (Dummy)
  620. * Notice: This function should ALWAYS be defined in the extension class of the plugin since it is directly concerned with the specific layout of the listing for your plugins purpose.
  621. *
  622. * @return string HTML output, a table row with a class attribute set
  623. */
  624. function pi_list_header() {
  625. return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
  626. }
  627. /***************************
  628. *
  629. * Stylesheet, CSS
  630. *
  631. **************************/
  632. /**
  633. * Returns a class-name prefixed with $this->prefixId and with all underscores substituted to dashes (-)
  634. *
  635. * @param string The class name (or the END of it since it will be prefixed by $this->prefixId.'-')
  636. * @return string The combined class name (with the correct prefix)
  637. */
  638. function pi_getClassName($class) {
  639. return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
  640. }
  641. /**
  642. * Returns the class-attribute with the correctly prefixed classname
  643. * Using pi_getClassName()
  644. *
  645. * @param string The class name(s) (suffix) - separate multiple classes with commas
  646. * @param string Additional class names which should not be prefixed - separate multiple classes with commas
  647. * @return string A "class" attribute with value and a single space char before it.
  648. * @see pi_getClassName()
  649. */
  650. function pi_classParam($class, $addClasses='') {
  651. $output = '';
  652. foreach (t3lib_div::trimExplode(',',$class) as $v) {
  653. $output.= ' '.$this->pi_getClassName($v);
  654. }
  655. foreach (t3lib_div::trimExplode(',',$addClasses) as $v) {
  656. $output.= ' '.$v;
  657. }
  658. return ' class="'.trim($output).'"';
  659. }
  660. /**
  661. * Sets CSS style-data for the $class-suffix (prefixed by pi_getClassName())
  662. *
  663. * @param string $class: Class suffix, see pi_getClassName
  664. * @param string $data: CSS data
  665. * @param string If $selector is set to any CSS selector, eg 'P' or 'H1' or 'TABLE' then the style $data will regard those HTML-elements only
  666. * @return void
  667. * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, I think this function should not be used (and probably isn't used anywhere). It was a part of a concept which was left behind quite quickly.
  668. * @obsolete
  669. * @private
  670. */
  671. function pi_setClassStyle($class,$data,$selector='') {
  672. t3lib_div::logDeprecatedFunction();
  673. $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
  674. }
  675. /**
  676. * Wraps the input string in a <div> tag with the class attribute set to the prefixId.
  677. * All content returned from your plugins should be returned through this function so all content from your plugin is encapsulated in a <div>-tag nicely identifying the content of your plugin.
  678. *
  679. * @param string HTML content to wrap in the div-tags with the "main class" of the plugin
  680. * @return string HTML content wrapped, ready to return to the parent object.
  681. */
  682. function pi_wrapInBaseClass($str) {
  683. $content = '<div class="'.str_replace('_','-',$this->prefixId).'">
  684. '.$str.'
  685. </div>
  686. ';
  687. if(!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
  688. $content = '
  689. <!--
  690. BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
  691. -->
  692. '.$content.'
  693. <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
  694. ';
  695. }
  696. return $content;
  697. }
  698. /***************************
  699. *
  700. * Frontend editing: Edit panel, edit icons
  701. *
  702. **************************/
  703. /**
  704. * Returns the Backend User edit panel for the $row from $tablename
  705. *
  706. * @param array Record array.
  707. * @param string Table name
  708. * @param string A label to show with the panel.
  709. * @param array TypoScript parameters to pass along to the EDITPANEL content Object that gets rendered. The property "allow" WILL get overridden/set though.
  710. * @return string Returns false/blank if no BE User login and of course if the panel is not shown for other reasons. Otherwise the HTML for the panel (a table).
  711. * @see tslib_cObj::EDITPANEL()
  712. */
  713. function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
  714. $panel='';
  715. if (!$row || !$tablename) {
  716. $row = $this->internal['currentRow'];
  717. $tablename = $this->internal['currentTable'];
  718. }
  719. if ($GLOBALS['TSFE']->beUserLogin) {
  720. // Create local cObj if not set:
  721. if (!is_object($this->pi_EPtemp_cObj)) {
  722. $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
  723. $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
  724. }
  725. // Initialize the cObj object with current row
  726. $this->pi_EPtemp_cObj->start($row,$tablename);
  727. // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
  728. $conf['allow'] = 'edit,new,delete,move,hide';
  729. $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
  730. }
  731. if ($panel) {
  732. if ($label) {
  733. 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 -->';
  734. } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
  735. } else return $label;
  736. }
  737. /**
  738. * Adds edit-icons to the input content.
  739. * tslib_cObj::editIcons used for rendering
  740. *
  741. * @param string HTML content to add icons to. The icons will be put right after the last content part in the string (that means before the ending series of HTML tags)
  742. * @param string The list of fields to edit when the icon is clicked.
  743. * @param string Title for the edit icon.
  744. * @param array Table record row
  745. * @param string Table name
  746. * @param array Conf array
  747. * @return string The processed content
  748. * @see tslib_cObj::editIcons()
  749. */
  750. function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array()) {
  751. if ($GLOBALS['TSFE']->beUserLogin){
  752. if (!$row || !$tablename) {
  753. $row = $this->internal['currentRow'];
  754. $tablename = $this->internal['currentTable'];
  755. }
  756. $conf=array_merge(array(
  757. 'beforeLastTag'=>1,
  758. 'iconTitle' => $title
  759. ),$oConf);
  760. $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
  761. }
  762. return $content;
  763. }
  764. /***************************
  765. *
  766. * Localization, locallang functions
  767. *
  768. **************************/
  769. /**
  770. * Returns the localized label of the LOCAL_LANG key, $key
  771. * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
  772. *
  773. * @param string The key from the LOCAL_LANG array for which to return the value.
  774. * @param string Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
  775. * @param boolean If true, the output label is passed through htmlspecialchars()
  776. * @return string The value from LOCAL_LANG.
  777. */
  778. function pi_getLL($key,$alt='',$hsc=FALSE) {
  779. // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
  780. if (isset($this->LOCAL_LANG[$this->LLkey][$key])) {
  781. $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key], $this->LOCAL_LANG_charset[$this->LLkey][$key]);
  782. } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key])) {
  783. $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->altLLkey][$key], $this->LOCAL_LANG_charset[$this->altLLkey][$key]);
  784. } elseif (isset($this->LOCAL_LANG['default'][$key])) {
  785. $word = $this->LOCAL_LANG['default'][$key]; // No charset conversion because default is english and thereby ASCII
  786. } else {
  787. $word = $this->LLtestPrefixAlt.$alt;
  788. }
  789. $output = $this->LLtestPrefix.$word;
  790. if ($hsc) $output = htmlspecialchars($output);
  791. return $output;
  792. }
  793. /**
  794. * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
  795. * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
  796. *
  797. * @return void
  798. */
  799. function pi_loadLL() {
  800. if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
  801. $basePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xml';
  802. // Read the strings in the required charset (since TYPO3 4.2)
  803. $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey,$GLOBALS['TSFE']->renderCharset);
  804. if ($this->altLLkey) {
  805. $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
  806. $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
  807. }
  808. // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
  809. $confLL = $this->conf['_LOCAL_LANG.'];
  810. if (is_array($confLL)) {
  811. foreach ($confLL as $k => $lA) {
  812. if (is_array($lA)) {
  813. $k = substr($k,0,-1);
  814. foreach($lA as $llK => $llV) {
  815. if (!is_array($llV)) {
  816. $this->LOCAL_LANG[$k][$llK] = $llV;
  817. // 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
  818. $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : $GLOBALS['TSFE']->csConvObj->charSetArray[$k];
  819. }
  820. }
  821. }
  822. }
  823. }
  824. }
  825. $this->LOCAL_LANG_loaded = 1;
  826. }
  827. /***************************
  828. *
  829. * Database, queries
  830. *
  831. **************************/
  832. /**
  833. * Makes a standard query for listing of records based on standard input vars from the 'browser' ($this->internal['results_at_a_time'] and $this->piVars['pointer']) and 'searchbox' ($this->piVars['sword'] and $this->internal['searchFieldList'])
  834. * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
  835. * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
  836. *
  837. * @param string See pi_exec_query()
  838. * @param boolean See pi_exec_query()
  839. * @param string See pi_exec_query()
  840. * @param mixed See pi_exec_query()
  841. * @param string See pi_exec_query()
  842. * @param string See pi_exec_query()
  843. * @param string See pi_exec_query()
  844. * @param boolean If set, the function will return the query not as a string but array with the various parts.
  845. * @return mixed The query build.
  846. * @access private
  847. * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use pi_exec_query() instead!
  848. */
  849. function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE) {
  850. // Begin Query:
  851. if (!$query) {
  852. // Fetches the list of PIDs to select from.
  853. // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
  854. // 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.
  855. $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
  856. if (is_array($mm_cat)) {
  857. $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].LF.
  858. ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.LF.
  859. (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').LF.
  860. ' AND '.$table.'.pid IN ('.$pidList.')'.LF.
  861. $this->cObj->enableFields($table).LF; // 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!
  862. } else {
  863. $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.LF.
  864. $this->cObj->enableFields($table).LF; // 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!
  865. }
  866. }
  867. // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
  868. list($TABLENAMES, $WHERE) = preg_split('/WHERE/i', trim($query), 2);
  869. $TABLENAMES = trim(substr(trim($TABLENAMES),5));
  870. $WHERE = trim($WHERE);
  871. // Add '$addWhere'
  872. if ($addWhere) {$WHERE.=' '.$addWhere.LF;}
  873. // Search word:
  874. if ($this->piVars['sword'] && $this->internal['searchFieldList']) {
  875. $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).LF;
  876. }
  877. if ($count) {
  878. $queryParts = array(
  879. 'SELECT' => 'count(*)',
  880. 'FROM' => $TABLENAMES,
  881. 'WHERE' => $WHERE,
  882. 'GROUPBY' => '',
  883. 'ORDERBY' => '',
  884. 'LIMIT' => ''
  885. );
  886. } else {
  887. // Order by data:
  888. if (!$orderBy && $this->internal['orderBy']) {
  889. if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy'])) {
  890. $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
  891. }
  892. }
  893. // Limit data:
  894. $pointer = $this->piVars['pointer'];
  895. $pointer = intval($pointer);
  896. $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
  897. $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
  898. // Add 'SELECT'
  899. $queryParts = array(
  900. 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
  901. 'FROM' => $TABLENAMES,
  902. 'WHERE' => $WHERE,
  903. 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
  904. 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
  905. 'LIMIT' => $LIMIT
  906. );
  907. }
  908. $query = $GLOBALS['TYPO3_DB']->SELECTquery (
  909. $queryParts['SELECT'],
  910. $queryParts['FROM'],
  911. $queryParts['WHERE'],
  912. $queryParts['GROUPBY'],
  913. $queryParts['ORDERBY'],
  914. $queryParts['LIMIT']
  915. );
  916. return $returnQueryArray ? $queryParts : $query;
  917. }
  918. /**
  919. * Executes a standard SELECT query for listing of records based on standard input vars from the 'browser' ($this->internal['results_at_a_time'] and $this->piVars['pointer']) and 'searchbox' ($this->piVars['sword'] and $this->internal['searchFieldList'])
  920. * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
  921. * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
  922. *
  923. * @param string The table name to make the query for.
  924. * @param boolean If set, you will get a "count(*)" query back instead of field selecting
  925. * @param string Additional WHERE clauses (should be starting with " AND ....")
  926. * @param mixed If an array, then it must contain the keys "table", "mmtable" and (optionally) "catUidList" defining a table to make a MM-relation to in the query (based on fields uid_local and uid_foreign). If not array, the query will be a plain query looking up data in only one table.
  927. * @param string If set, this is added as a " GROUP BY ...." part of the query.
  928. * @param string If set, this is added as a " ORDER BY ...." part of the query. The default is that an ORDER BY clause is made based on $this->internal['orderBy'] and $this->internal['descFlag'] where the orderBy field must be found in $this->internal['orderByList']
  929. * @param string If set, this is taken as the first part of the query instead of what is created internally. Basically this should be a query starting with "FROM [table] WHERE ... AND ...". The $addWhere clauses and all the other stuff is still added. Only the tables and PID selecting clauses are bypassed. May be deprecated in the future!
  930. * @return pointer SQL result pointer
  931. */
  932. function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy=

Large files files are truncated, but you can click here to view the full file