Modified some AND/OR statements to use common operators instead
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_extmgm.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2006 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 * Contains a class with Extension Management functions
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 114: class t3lib_extMgm
41 *
42 * SECTION: PATHS and other evaluation
43 * 131: function isLoaded($key,$exitOnError=0)
44 * 147: function extPath($key,$script='')
45 * 165: function extRelPath($key)
46 * 182: function siteRelPath($key)
47 * 194: function getCN($key)
48 *
49 * SECTION: Adding BACKEND features
50 * 227: function addTCAcolumns($table,$columnArray,$addTofeInterface=0)
51 * 251: function addToAllTCAtypes($table,$str,$specificTypesList='',$position='')
52 * 309: function allowTableOnStandardPages($table)
53 * 326: function addModule($main,$sub='',$position='',$path='')
54 * 389: function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='')
55 * 408: function addPageTSConfig($content)
56 * 422: function addUserTSConfig($content)
57 * 437: function addLLrefForTCAdescr($tca_descr_key,$file_ref)
58 *
59 * SECTION: Adding SERVICES features
60 * 479: function addService($extKey, $serviceType, $serviceKey, $info)
61 * 547: function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array())
62 * 618: function deactivateService($serviceType, $serviceKey)
63 *
64 * SECTION: Adding FRONTEND features
65 * 657: function addPlugin($itemArray,$type='list_type')
66 * 682: function addPiFlexFormValue($piKeyToMatch,$value)
67 * 702: function addToInsertRecords($table,$content_table='tt_content',$content_field='records')
68 * 733: function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)
69 * 808: function addStaticFile($extKey,$path,$title)
70 * 827: function addTypoScriptSetup($content)
71 * 841: function addTypoScriptConstants($content)
72 * 858: function addTypoScript($key,$type,$content,$afterStaticUid=0)
73 *
74 * SECTION: INTERNAL EXTENSION MANAGEMENT:
75 * 921: function typo3_loadExtensions()
76 * 998: function _makeIncludeHeader($key,$file)
77 * 1019: function isCacheFilesAvailable($cacheFilePrefix)
78 * 1032: function isLocalconfWritable()
79 * 1045: function cannotCacheFilesWritable($cacheFilePrefix)
80 * 1069: function currentCacheFiles()
81 * 1092: function writeCacheFiles($extensions,$cacheFilePrefix)
82 * 1130: function removeCacheFiles()
83 *
84 * TOTAL FUNCTIONS: 32
85 * (This index is automatically created/updated by the extension "extdeveval")
86 *
87 */
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 /**
105 * Extension Management functions
106 *
107 * This class is never instantiated, rather the methods inside is called as functions like
108 * t3lib_extMgm::isLoaded('my_extension');
109 *
110 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
111 * @package TYPO3
112 * @subpackage t3lib
113 */
114 class t3lib_extMgm {
115
116
117 /**************************************
118 *
119 * PATHS and other evaluation
120 *
121 ***************************************/
122
123 /**
124 * Returns true if the extension with extension key $key is loaded.
125 * Usage: 109
126 *
127 * @param string Extension key to test
128 * @param boolean If $exitOnError is true and the extension is not loaded the function will die with an error message
129 * @return boolean
130 */
131 function isLoaded($key,$exitOnError=0) {
132 global $TYPO3_LOADED_EXT;
133 if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key])) die('Fatal Error: Extension "'.$key.'" was not loaded.');
134 return isset($TYPO3_LOADED_EXT[$key]);
135 }
136
137 /**
138 * Returns the absolute path to the extension with extension key $key
139 * If the extension is not loaded the function will die with an error message
140 * Useful for internal fileoperations
141 * Usage: 136
142 *
143 * @param string Extension key
144 * @param string $script is appended to the output if set.
145 * @return string
146 */
147 function extPath($key,$script='') {
148 global $TYPO3_LOADED_EXT;
149 if (!isset($TYPO3_LOADED_EXT[$key])) {
150 #debug(array(debug_backtrace()));
151 die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extPath)');
152 }
153 return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
154 }
155
156 /**
157 * Returns the relative path to the extension as measured from from the TYPO3_mainDir
158 * If the extension is not loaded the function will die with an error message
159 * Useful for images and links from backend
160 * Usage: 54
161 *
162 * @param string Extension key
163 * @return string
164 */
165 function extRelPath($key) {
166 global $TYPO3_LOADED_EXT;
167 if (!isset($TYPO3_LOADED_EXT[$key])) {
168 die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extRelPath)');
169 }
170 return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
171 }
172
173 /**
174 * Returns the relative path to the extension as measured from the PATH_site (frontend)
175 * If the extension is not loaded the function will die with an error message
176 * Useful for images and links from the frontend
177 * Usage: 6
178 *
179 * @param string Extension key
180 * @return string
181 */
182 function siteRelPath($key) {
183 return substr(t3lib_extMgm::extPath($key),strlen(PATH_site));
184 }
185
186 /**
187 * Returns the correct class name prefix for the extension key $key
188 * Usage: 3
189 *
190 * @param string Extension key
191 * @return string
192 * @internal
193 */
194 function getCN($key) {
195 return substr($key,0,5)=='user_' ? 'user_'.str_replace('_','',substr($key,5)) : 'tx_'.str_replace('_','',$key);
196 }
197
198
199
200
201
202
203
204
205
206
207 /**************************************
208 *
209 * Adding BACKEND features
210 * (related to core features)
211 *
212 ***************************************/
213
214 /**
215 * Adding fields to an existing table definition in $TCA
216 * Adds an array with $TCA column-configuration to the $TCA-entry for that table.
217 * This function adds the configuration needed for rendering of the field in TCEFORMS - but it does NOT add the field names to the types lists!
218 * So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list.
219 * FOR USE IN ext_tables.php FILES
220 * Usage: 4
221 *
222 * @param string $table is the table name of a table already present in $TCA with a columns section
223 * @param array $columnArray is the array with the additional columns (typical some fields an extension wants to add)
224 * @param boolean If $addTofeInterface is true the list of fields are also added to the fe_admin_fieldList.
225 * @return void
226 */
227 function addTCAcolumns($table,$columnArray,$addTofeInterface=0) {
228 global $TCA;
229 t3lib_div::loadTCA($table);
230 if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns'])) {
231 $TCA[$table]['columns'] = array_merge($TCA[$table]['columns'],$columnArray); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
232 if ($addTofeInterface) $TCA[$table]['feInterface']['fe_admin_fieldList'].=','.implode(',',array_keys($columnArray));
233 }
234 }
235
236 /**
237 * Makes fields visible in the TCEforms, adding them to the end of (all) "types"-configurations
238 *
239 * Adds a string $str (comma list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $specificTypesList)
240 * This is needed to have new fields shown automatically in the TCEFORMS of a record from $table.
241 * Typically this function is called after having added new columns (database fields) with the addTCAcolumns function
242 * FOR USE IN ext_tables.php FILES
243 * Usage: 1
244 *
245 * @param string Table name
246 * @param string Field list to add.
247 * @param string List of specific types to add the field list to. (If empty, all type entries are affected)
248 * @param string Insert fields before (default) or after one of this fields (commalist with "before:" or "after:" commands). Example: "before:keywords,--palette--;;4,after:description". Palettes must be passed like in the example no matter how the palette definition looks like in TCA.
249 * @return void
250 */
251 function addToAllTCAtypes($table,$str,$specificTypesList='',$position='') {
252 global $TCA;
253
254 $positionArr=t3lib_div::trimExplode(',',$position,1);
255 $insert=count($position);
256
257 t3lib_div::loadTCA($table);
258 if (trim($str) && is_array($TCA[$table]) && is_array($TCA[$table]['types'])) {
259 foreach($TCA[$table]['types'] as $k => $v) {
260 if (!$specificTypesList || t3lib_div::inList($specificTypesList,$k)) {
261 if ($insert) {
262 $append=true;
263 $showItem = t3lib_div::trimExplode(',',$TCA[$table]['types'][$k]['showitem'],1);
264 foreach($showItem as $key => $fieldInfo) {
265
266 $parts = explode(';',$fieldInfo);
267 $theField = trim($parts[0]);
268 $palette = trim($parts[0]).';;'.trim($parts[2]);
269
270 // insert before: find exact field name or palette with number
271 if (in_array($theField, $positionArr) || in_array($palette, $positionArr) || in_array('before:'.$theField, $positionArr) || in_array('before:'.$palette, $positionArr)) {
272 $showItem[$key]=trim($str).', '.$fieldInfo;
273 $append=false;
274 break;
275 }
276 // insert after
277 if (in_array('after:'.$theField, $positionArr) || in_array('after:'.$palette, $positionArr)) {
278 $showItem[$key]=$fieldInfo.', '.trim($str);
279 $append=false;
280 break;
281 }
282 }
283
284 // Not found? Then append.
285 if($append) {
286 $showItem[]=trim($str);
287 }
288
289 $TCA[$table]['types'][$k]['showitem']=implode(', ', $showItem);
290
291 } else {
292 $TCA[$table]['types'][$k]['showitem'].=', '.trim($str);
293 }
294 }
295 }
296 }
297 }
298
299
300 /**
301 * Add tablename to default list of allowed tables on pages (in $PAGES_TYPES)
302 * Will add the $table to the list of tables allowed by default on pages as setup by $PAGES_TYPES['default']['allowedTables']
303 * FOR USE IN ext_tables.php FILES
304 * Usage: 11
305 *
306 * @param string Table name
307 * @return void
308 */
309 function allowTableOnStandardPages($table) {
310 global $PAGES_TYPES;
311
312 $PAGES_TYPES['default']['allowedTables'].=','.$table;
313 }
314
315 /**
316 * Adds a module (main or sub) to the backend interface
317 * FOR USE IN ext_tables.php FILES
318 * Usage: 18
319 *
320 * @param string $main is the main module key, $sub is the submodule key. So $main would be an index in the $TBE_MODULES array and $sub could be an element in the lists there.
321 * @param string $sub is the submodule key. If $sub is not set a blank $main module is created.
322 * @param string $position can be used to set the position of the $sub module within the list of existing submodules for the main module. $position has this syntax: [cmd]:[submodule-key]. cmd can be "after", "before" or "top" (or blank which is default). If "after"/"before" then submodule will be inserted after/before the existing submodule with [submodule-key] if found. If not found, the bottom of list. If "top" the module is inserted in the top of the submodule list.
323 * @param string $path is the absolute path to the module. If this value is defined the path is added as an entry in $TBE_MODULES['_PATHS'][ main_sub ]=$path; and thereby tells the backend where the newly added modules is found in the system.
324 * @return void
325 */
326 function addModule($main,$sub='',$position='',$path='') {
327 global $TBE_MODULES;
328
329 if (isset($TBE_MODULES[$main]) && $sub) { // If there is already a main module by this name:
330
331 // Adding the submodule to the correct position:
332 list($place,$modRef)=t3lib_div::trimExplode(':',$position,1);
333 $mods = t3lib_div::trimExplode(',',$TBE_MODULES[$main],1);
334 if (!in_array($sub,$mods)) {
335 switch(strtolower($place)) {
336 case 'after':
337 case 'before':
338 $pointer=0;
339 reset($mods);
340 while(list($k,$m)=each($mods)) {
341 if (!strcmp($m,$modRef)) {
342 $pointer=strtolower($place)=='after'?$k+1:$k;
343 }
344 }
345 array_splice(
346 $mods, // The modules array
347 $pointer, // To insert one position from the end of the list
348 0, // Don't remove any items, just insert
349 $sub // Module to insert
350 );
351 break;
352 default:
353 if (strtolower($place)=='top') {
354 array_unshift($mods,$sub);
355 } else {
356 array_push($mods,$sub);
357 }
358 break;
359 }
360 }
361 // Re-inserting the submodule list:
362 $TBE_MODULES[$main]=implode(',',$mods);
363 } else { // Create new main modules with only one submodule, $sub (or none if $sub is blank)
364 $TBE_MODULES[$main]=$sub;
365 }
366
367 // Adding path:
368 if ($path) {
369 $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')]=$path;
370 }
371 }
372
373 /**
374 * Adds a module path to TBE_MODULES for used with the module dispatcher, mod.php
375 * Used only for modules that are not placed in the main/sub menu hierarchy by the traditional mechanism of addModule()
376 * Examples for this is context menu functionality (like import/export) which runs as an independent module through mod.php
377 * FOR USE IN ext_tables.php FILES
378 * Example: t3lib_extMgm::addModulePath('xMOD_tximpexp',t3lib_extMgm::extPath($_EXTKEY).'app/');
379 *
380 * @param string $name is the name of the module, refer to conf.php of the module.
381 * @param string $path is the absolute path to the module directory inside of which "index.php" and "conf.php" is found.
382 * @return void
383 */
384 function addModulePath($name,$path) {
385 global $TBE_MODULES;
386
387 $TBE_MODULES['_PATHS'][$name] = $path;
388 }
389
390 /**
391 * Adding an application for the top menu. These are regular modules but is required to respond with Ajax content in case of certain parameters sent to them.
392 *
393 * @param string $name is the name of the module, refer to conf.php of the module.
394 * @param string $path is the absolute path to the module directory inside of which "index.php" and "conf.php" is found.
395 * @param boolean If set, the application is placed in the shortcut bar below the menu bar.
396 * @param array Options
397 * @return void
398 */
399 function addTopApp($name,$path,$iconPane=FALSE,$options=array()) {
400 global $TBE_MODULES,$TYPO3_CONF_VARS;
401
402 $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['topApps'][$iconPane?'icons':'menu'][$name] = $options;
403
404 // Set path for TBE-modules:
405 $TBE_MODULES['_PATHS'][$name] = $path;
406 }
407
408 /**
409 * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
410 * The arguments values are generally determined by which function menu this is supposed to interact with
411 * See Inside TYPO3 for information on how to use this function.
412 * FOR USE IN ext_tables.php FILES
413 * Usage: 26
414 *
415 * @param string Module name
416 * @param string Class name
417 * @param string Class path
418 * @param string Title of module
419 * @param string Menu array key - default is "function"
420 * @param string Workspace conditions. Blank means all workspaces, any other string can be a comma list of "online", "offline" and "custom"
421 * @return void
422 * @see t3lib_SCbase::mergeExternalItems()
423 */
424 function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='') {
425 global $TBE_MODULES_EXT;
426 $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className]=array(
427 'name' => $className,
428 'path' => $classPath,
429 'title' => $title,
430 'ws' => $WS
431 );
432 }
433
434 /**
435 * Adds $content to the default Page TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultPageTSconfig']
436 * Prefixed with a [GLOBAL] line
437 * FOR USE IN ext_tables.php/ext_locallang.php FILES
438 * Usage: 5
439 *
440 * @param string Page TSconfig content
441 * @return void
442 */
443 function addPageTSConfig($content) {
444 global $TYPO3_CONF_VARS;
445 $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
446 }
447
448 /**
449 * Adds $content to the default User TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultUserTSconfig']
450 * Prefixed with a [GLOBAL] line
451 * FOR USE IN ext_tables.php/ext_locallang.php FILES
452 * Usage: 3
453 *
454 * @param string User TSconfig content
455 * @return void
456 */
457 function addUserTSConfig($content) {
458 global $TYPO3_CONF_VARS;
459 $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
460 }
461
462 /**
463 * Adds a reference to a locallang file with TCA_DESCR labels
464 * FOR USE IN ext_tables.php FILES
465 * eg. t3lib_extMgm::addLLrefForTCAdescr('pages','EXT:lang/locallang_csh_pages.xml'); for the pages table or t3lib_extMgm::addLLrefForTCAdescr('_MOD_web_layout','EXT:cms/locallang_csh_weblayout.php'); for the Web > Page module.
466 * Usage: 31
467 *
468 * @param string Description key. Typically a database table (like "pages") but for applications can be other strings, but prefixed with "_MOD_")
469 * @param string File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php" (or ".xml")
470 * @return void
471 */
472 function addLLrefForTCAdescr($tca_descr_key,$file_ref) {
473 global $TCA_DESCR;
474 if ($tca_descr_key) {
475 if (!is_array($TCA_DESCR[$tca_descr_key])) {
476 $TCA_DESCR[$tca_descr_key]=array();
477 }
478 if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
479 $TCA_DESCR[$tca_descr_key]['refs']=array();
480 }
481 $TCA_DESCR[$tca_descr_key]['refs'][]=$file_ref;
482 }
483 }
484
485
486
487
488
489
490
491
492
493
494
495
496 /**************************************
497 *
498 * Adding SERVICES features
499 *
500 * @author René Fritz <r.fritz@colorcube.de>
501 *
502 ***************************************/
503
504 /**
505 * Adds a service to the global services array
506 *
507 * @param string Extension key
508 * @param string Service type, cannot be prefixed "tx_"
509 * @param string Service key, must be prefixed "tx_" or "user_"
510 * @param array Service description array
511 * @return void
512 * @author René Fritz <r.fritz@colorcube.de>
513 */
514 function addService($extKey, $serviceType, $serviceKey, $info) {
515 global $T3_SERVICES,$TYPO3_CONF_VARS;
516
517 // even not available services will be included to make it possible to give the admin a feedback of non-available services.
518 // but maybe it's better to move non-available services to a different array??
519
520 if ($serviceType &&
521 !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') &&
522 (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') || t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) &&
523 is_array($info)) {
524
525 $info['priority'] = max(0,min(100,$info['priority']));
526
527 $T3_SERVICES[$serviceType][$serviceKey]=$info;
528
529 $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
530 $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
531 $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
532
533
534 // mapping a service key to a service type
535 // all service keys begin with tx_ - service types don't
536 // this way a selection of a special service key as service type is easy
537 $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
538
539
540 // change the priority (and other values) from TYPO3_CONF_VARS
541 // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority']
542 // even the activation is possible (a unix service might be possible on windows for some reasons)
543 if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
544
545 // no check is done here - there might be configuration values only the service type knows about, so we pass everything
546 $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey],$TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
547 }
548
549
550 // OS check
551 // empty $os means 'not limited to one OS', therefore a check is not needed
552 if ($T3_SERVICES[$serviceType][$serviceKey]['available'] && $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
553
554 // TYPO3_OS is not yet defined
555 $os_type = stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX';
556
557 $os = t3lib_div::trimExplode(',',strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
558
559 if (!in_array($os_type,$os)) {
560 t3lib_extMgm::deactivateService($serviceType, $serviceKey);
561 }
562 }
563
564 // convert subtype list to array for quicker access
565 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
566 $serviceSubTypes = t3lib_div::trimExplode(',',$info['subtype']);
567 foreach ($serviceSubTypes as $subtype) {
568 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
569 }
570 }
571 }
572
573 /**
574 * Find the available service with highest priority
575 *
576 * @param string Service type
577 * @param string Service sub type
578 * @param mixed Service keys that should be excluded in the search for a service. Array or comma list.
579 * @return mixed Service info array if a service was found, FLASE otherwise
580 * @author René Fritz <r.fritz@colorcube.de>
581 */
582 function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) {
583 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
584
585 $serviceKey = FALSE;
586 $serviceInfo = FALSE;
587 $priority = 0;
588 $quality = 0;
589
590 if (!is_array($excludeServiceKeys) ) {
591 $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
592 }
593
594 if (is_array($T3_SERVICES[$serviceType])) {
595 foreach($T3_SERVICES[$serviceType] as $key => $info) {
596
597 if (in_array($key, $excludeServiceKeys)) {
598 continue;
599 }
600
601 // select a subtype randomly
602 // usefull to start a service by service key without knowing his subtypes - for testing purposes
603 if ($serviceSubType=='*') {
604 $serviceSubType = key($info['serviceSubTypes']);
605 }
606
607 // this matches empty subtype too
608 if ($info['available'] && ($info['subtype']==$serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority']>=$priority ) {
609
610 // has a lower quality than the already found, therefore we skip this service
611 if($info['priority']==$priority && $info['quality']<$quality) {
612 continue;
613 }
614
615 // service depends on external programs - check if they exists
616 if(trim($info['exec'])) {
617 require_once(PATH_t3lib.'class.t3lib_exec.php');
618
619 $executables = t3lib_div::trimExplode(',', $info['exec'],1);
620 foreach($executables as $executable) {
621 if(!t3lib_exec::checkCommand($executable)) {
622 t3lib_extMgm::deactivateService($serviceType, $key);
623 $info['available']=FALSE;
624 break;
625 }
626 }
627 }
628
629 // still available after exec check?
630 if($info['available']) {
631 $serviceKey = $key;
632 $priority = $info['priority'];
633 $quality = $info['quality'];
634 }
635 }
636 }
637 }
638
639 if ($serviceKey) {
640 $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
641 }
642 return $serviceInfo;
643 }
644
645 /**
646 * Deactivate a service
647 *
648 * @param string Service type
649 * @param string Service key
650 * @return void
651 * @author René Fritz <r.fritz@colorcube.de>
652 */
653 function deactivateService($serviceType, $serviceKey) {
654 global $T3_SERVICES;
655
656 // ... maybe it's better to move non-available services to a different array??
657 $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
658 }
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673 /**************************************
674 *
675 * Adding FRONTEND features
676 * (related specifically to "cms" extension)
677 *
678 ***************************************/
679
680 /**
681 * Adds an entry to the list of plugins in content elements of type "Insert plugin"
682 * Takes the $itemArray (label,value[,icon]) and adds to the items-array of $TCA[tt_content] elements with CType "listtype" (or another field if $type points to another fieldname)
683 * If the value (array pos. 1) is already found in that items-array, the entry is substituted, otherwise the input array is added to the bottom.
684 * Use this function to add a frontend plugin to this list of plugin-types - or more generally use this function to add an entry to any selectorbox/radio-button set in the TCEFORMS
685 * FOR USE IN ext_tables.php FILES
686 * Usage: 13
687 *
688 * @param array Item Array
689 * @param string Type (eg. "list_type") - basically a field from "tt_content" table
690 * @return void
691 */
692 function addPlugin($itemArray,$type='list_type') {
693 global $TCA;
694 t3lib_div::loadTCA('tt_content');
695 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
696 reset($TCA['tt_content']['columns'][$type]['config']['items']);
697 while(list($k,$v)=each($TCA['tt_content']['columns'][$type]['config']['items'])) {
698 if (!strcmp($v[1],$itemArray[1])) {
699 $TCA['tt_content']['columns'][$type]['config']['items'][$k]=$itemArray;
700 return;
701 }
702 }
703 $TCA['tt_content']['columns'][$type]['config']['items'][]=$itemArray;
704 }
705 }
706
707 /**
708 * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
709 * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin.
710 * Usage: 0
711 *
712 * @param string The same value as the key for the plugin
713 * @param string Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
714 * @return void
715 * @see addPlugin()
716 */
717 function addPiFlexFormValue($piKeyToMatch,$value) {
718 global $TCA;
719 t3lib_div::loadTCA('tt_content');
720
721 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) {
722 $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch] = $value;
723 }
724 }
725
726 /**
727 * Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records"
728 * By using $content_table and $content_field you can also use the function for other tables.
729 * FOR USE IN ext_tables.php FILES
730 * Usage: 9
731 *
732 * @param string Table name to allow for "insert record"
733 * @param string Table name TO WHICH the $table name is applied. See $content_field as well.
734 * @param string Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
735 * @return void
736 */
737 function addToInsertRecords($table,$content_table='tt_content',$content_field='records') {
738 global $TCA;
739 t3lib_div::loadTCA($content_table);
740 if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) {
741 $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
742 }
743 }
744
745 /**
746 * Add PlugIn to Static Template #43
747 *
748 * When adding a frontend plugin you will have to add both an entry to the TCA definition of tt_content table AND to the TypoScript template which must initiate the rendering.
749 * Since the static template with uid 43 is the "content.default" and practically always used for rendering the content elements it's very useful to have this function automatically adding the necessary TypoScript for calling your plugin. It will also work for the extension "css_styled_content"
750 * $type determines the type of frontend plugin:
751 * "list_type" (default) - the good old "Insert plugin" entry
752 * "menu_type" - a "Menu/Sitemap" entry
753 * "splash_layout" - a "Textbox" entry
754 * "CType" - a new content element type
755 * "header_layout" - an additional header type (added to the selection of layout1-5)
756 * "includeLib" - just includes the library for manual use somewhere in TypoScript.
757 * (Remember that your $type definition should correspond to the column/items array in $TCA[tt_content] where you added the selector item for the element! See addPlugin() function)
758 * FOR USE IN ext_locallang.php FILES
759 * Usage: 2
760 *
761 * @param string $key is the extension key
762 * @param string $classFile is the PHP-class filename relative to the extension root directory. If set to blank a default value is chosen according to convensions.
763 * @param string $prefix is used as a - yes, suffix - of the class name (fx. "_pi1")
764 * @param string $type, see description above
765 * @param boolean If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
766 * @return void
767 */
768 function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0) {
769 global $TYPO3_LOADED_EXT;
770 $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_','',$key).$prefix.'.php';
771 $cN = t3lib_extMgm::getCN($key);
772
773 // General plugin:
774 if ($cached) {
775 $pluginContent = trim('
776 includeLibs.'.$cN.$prefix.' = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
777 plugin.'.$cN.$prefix.' = USER
778 plugin.'.$cN.$prefix.' {
779 userFunc = '.$cN.$prefix.'->main
780 }');
781 } else {
782 $pluginContent = trim('
783 plugin.'.$cN.$prefix.' = USER_INT
784 plugin.'.$cN.$prefix.' {
785 includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
786 userFunc = '.$cN.$prefix.'->main
787 }');
788 }
789 t3lib_extMgm::addTypoScript($key,'setup','
790 # Setting '.$key.' plugin TypoScript
791 '.$pluginContent);
792
793 // After ST43:
794 switch($type) {
795 case 'list_type':
796 $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
797 break;
798 case 'menu_type':
799 $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
800 break;
801 case 'splash_layout':
802 $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
803 break;
804 case 'CType':
805 $addLine = trim('
806 tt_content.'.$key.$prefix.' = COA
807 tt_content.'.$key.$prefix.' {
808 10 = < lib.stdheader
809 20 = < plugin.'.$cN.$prefix.'
810 }
811 ');
812 break;
813 case 'header_layout':
814 $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
815 break;
816 case 'includeLib':
817 $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
818 break;
819 default:
820 $addLine = '';
821 break;
822 }
823 if ($addLine) {
824 t3lib_extMgm::addTypoScript($key,'setup','
825 # Setting '.$key.' plugin TypoScript
826 '.$addLine.'
827 ',43);
828 }
829 }
830
831 /**
832 * Call this method to add an entry in the static template list found in sys_templates
833 * "static template files" are the modern equalent (provided from extensions) to the traditional records in "static_templates"
834 * FOR USE IN ext_locallang.php FILES
835 * Usage: 3
836 *
837 * @param string $extKey is of course the extension key
838 * @param string $path is the path where the template files (fixed names) include_static.txt (integer list of uids from the table "static_templates"), constants.txt, setup.txt, editorcfg.txt, and include_static_file.txt is found (relative to extPath, eg. 'static/'). The file include_static_file.txt, allows you to include other static templates defined in files, from your static template, and thus corresponds to the field 'include_static_file' in the sys_template table. The syntax for this is a commaseperated list of static templates to include, like: EXT:css_styled_content/static/,EXT:da_newsletter_subscription/static/,EXT:cc_random_image/pi2/static/
839 * @param string $title is the title in the selector box.
840 * @return void
841 * @see addTypoScript()
842 */
843 function addStaticFile($extKey,$path,$title) {
844 global $TCA;
845 t3lib_div::loadTCA('sys_template');
846 if ($extKey && $path && is_array($TCA['sys_template']['columns'])) {
847 $value = str_replace(',','','EXT:'.$extKey.'/'.$path);
848 $itemArray=array(trim($title.' ('.$extKey.')'),$value);
849 $TCA['sys_template']['columns']['include_static_file']['config']['items'][]=$itemArray;
850 }
851 }
852
853 /**
854 * Adds $content to the default TypoScript setup code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_setup']
855 * Prefixed with a [GLOBAL] line
856 * FOR USE IN ext_locallang.php FILES
857 * Usage: 6
858 *
859 * @param string TypoScript Setup string
860 * @return void
861 */
862 function addTypoScriptSetup($content) {
863 global $TYPO3_CONF_VARS;
864 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
865 }
866
867 /**
868 * Adds $content to the default TypoScript constants code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_constants']
869 * Prefixed with a [GLOBAL] line
870 * FOR USE IN ext_locallang.php FILES
871 * Usage: 0
872 *
873 * @param string TypoScript Constants string
874 * @return void
875 */
876 function addTypoScriptConstants($content) {
877 global $TYPO3_CONF_VARS;
878 $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
879 }
880
881 /**
882 * Adds $content to the default TypoScript code for either setup, constants or editorcfg as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_*']
883 * (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!)
884 * FOR USE IN ext_locallang.php FILES
885 * Usage: 7
886 *
887 * @param string $key is the extension key (informative only).
888 * @param string $type is either "setup", "constants" or "editorcfg" and obviously determines which kind of TypoScript code we are adding.
889 * @param string $content is the TS content, prefixed with a [GLOBAL] line and a comment-header.
890 * @param string $afterStaticUid is either an integer pointing to a uid of a static_template or a string pointing to the "key" of a static_file template ([reduced extension_key]/[local path]). The points is that the TypoScript you add is included only IF that static template is included (and in that case, right after). So effectively the TypoScript you set can specifically overrule settings from those static templates.
891 * @return void
892 */
893 function addTypoScript($key,$type,$content,$afterStaticUid=0) {
894 global $TYPO3_CONF_VARS;
895
896 if ($type=='setup' || $type=='editorcfg' || $type=='constants') {
897 $content = '
898
899 [GLOBAL]
900 #############################################
901 ## TypoScript added by extension "'.$key.'"
902 #############################################
903
904 '.$content;
905 if ($afterStaticUid) {
906 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
907 if ($afterStaticUid==43) { // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
908 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.']['cssstyledcontent/static/'].=$content;
909 }
910 } else {
911 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
912 }
913 }
914 }
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933 /**************************************
934 *
935 * INTERNAL EXTENSION MANAGEMENT:
936 *
937 ***************************************/
938
939 /**
940 * Loading extensions configured in $TYPO3_CONF_VARS['EXT']['extList']
941 *
942 * CACHING ON: ($TYPO3_CONF_VARS['EXT']['extCache'] = 1 or 2)
943 * If caching is enabled (and possible), the output will be $extensions['_CACHEFILE'] set to the cacheFilePrefix. Subsequently the cache files must be included then since those will eventually set up the extensions.
944 * If cachefiles are not found they will be generated
945 * CACHING OFF: ($TYPO3_CONF_VARS['EXT']['extCache'] = 0)
946 * The returned value will be an array where each key is an extension key and the value is an array with filepaths for the extension.
947 * This array will later be set in the global var $TYPO3_LOADED_EXT
948 *
949 * Usages of this function can be seen in config_default.php
950 * Extensions are always detected in the order local - global - system.
951 * Usage: 1
952 *
953 * @return array Extension Array
954 * @internal
955 */
956 function typo3_loadExtensions() {
957 global $TYPO3_CONF_VARS;
958
959 // Full list of extensions includes both required and extList:
960 $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'].','.$TYPO3_CONF_VARS['EXT']['extList'];
961
962 // Empty array as a start.
963 $extensions = array();
964
965 //
966 if ($rawExtList) {
967 // The cached File prefix.
968 $cacheFilePrefix = 'temp_CACHED';
969 // Setting the name for the cache files:
970 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1) $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']),0,4);
971 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2) $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
972
973 // If cache files available, set cache file prefix and return:
974 if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix)) {
975 // Return cache file prefix:
976 $extensions['_CACHEFILE'] = $cacheFilePrefix;
977 } else { // ... but if not, configure...
978
979 // Prepare reserved filenames:
980 $files = t3lib_div::trimExplode(',','ext_localconf.php,ext_tables.php,ext_tables.sql,ext_tables_static+adt.sql,ext_typoscript_constants.txt,ext_typoscript_editorcfg.txt,ext_typoscript_setup.txt',1);
981
982 // Traverse extensions and check their existence:
983 clearstatcache(); // Clear file state cache to make sure we get good results from is_dir()
984 $temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1));
985 foreach($temp_extensions as $temp_extKey) {
986 // Check local, global and system locations:
987 if (@is_dir(PATH_typo3conf.'ext/'.$temp_extKey.'/')) {
988 $extensions[$temp_extKey] = array('type'=>'L', 'siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/', 'typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
989 } elseif (@is_dir(PATH_typo3.'ext/'.$temp_extKey.'/')) {
990 $extensions[$temp_extKey] = array('type'=>'G', 'siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/', 'typo3RelPath'=>'ext/'.$temp_extKey.'/');
991 } elseif (@is_dir(PATH_typo3.'sysext/'.$temp_extKey.'/')) {
992 $extensions[$temp_extKey] = array('type'=>'S', 'siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/', 'typo3RelPath'=>'sysext/'.$temp_extKey.'/');
993 }
994
995 // If extension was found, check for reserved filenames:
996 if (isset($extensions[$temp_extKey])) {
997 foreach($files as $fName) {
998 $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
999 if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) {
1000 $extensions[$temp_extKey][$fName] = $temp_filename;
1001 }
1002 }
1003 }
1004 }
1005 unset($extensions['_CACHEFILE']);
1006
1007 // write cache?
1008 if ($TYPO3_CONF_VARS['EXT']['extCache'] &&
1009 @is_dir(PATH_typo3.'sysext/') &&
1010 @is_dir(PATH_typo3.'ext/')) { // Must also find global and system extension directories to exist, otherwise caching cannot be allowed (since it is most likely a temporary server problem). This might fix a rare, unrepeatable bug where global/system extensions are not loaded resulting in fatal errors if that is cached!
1011 $wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix);
1012 if ($wrError) {
1013 $TYPO3_CONF_VARS['EXT']['extCache']=0;
1014 } else {
1015 // Write cache files:
1016 $extensions = t3lib_extMgm::writeCacheFiles($extensions,$cacheFilePrefix);
1017 }
1018 }
1019 }
1020 }
1021
1022 return $extensions;
1023 }
1024
1025 /**
1026 * Returns the section headers for the compiled cache-files.
1027 *
1028 * @param string $key is the extension key
1029 * @param string $file is the filename (only informative for comment)
1030 * @return string
1031 * @internal
1032 */
1033 function _makeIncludeHeader($key,$file) {
1034 return '<?php
1035 ###########################
1036 ## EXTENSION: '.$key.'
1037 ## FILE: '.$file.'
1038 ###########################
1039
1040 $_EXTKEY = \''.$key.'\';
1041 $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY];
1042
1043 ?>';
1044 }
1045
1046 /**
1047 * Returns true if both the localconf and tables cache file exists (with $cacheFilePrefix)
1048 * Usage: 2
1049 *
1050 * @param string Prefix of the cache file to check
1051 * @return boolean
1052 * @internal
1053 */
1054 function isCacheFilesAvailable($cacheFilePrefix) {
1055 return
1056 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
1057 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php');
1058 }
1059
1060 /**
1061 * Returns true if the "localconf.php" file in "typo3conf/" is writable
1062 * Usage: 1
1063 *
1064 * @return boolean
1065 * @internal
1066 */
1067 function isLocalconfWritable() {
1068 return @is_writable(PATH_typo3conf) && @is_writable(PATH_typo3conf.'localconf.php');
1069 }
1070
1071 /**
1072 * Returns an error string if typo3conf/ or cache-files with $cacheFilePrefix are NOT writable
1073 * Returns false if no problem.
1074 * Usage: 1
1075 *
1076 * @param string Prefix of the cache file to check
1077 * @return string
1078 * @internal
1079 */
1080 function cannotCacheFilesWritable($cacheFilePrefix) {
1081 $error=array();
1082 if (!@is_writable(PATH_typo3conf)) {
1083 $error[]=PATH_typo3conf;
1084 }
1085 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
1086 !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php')) {
1087 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
1088 }
1089 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') &&
1090 !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php')) {
1091 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
1092 }
1093 return implode(', ',$error);
1094 }
1095
1096 /**
1097 * Returns an array with the two cache-files (0=>localconf, 1=>tables) from typo3conf/ if they (both) exist. Otherwise false.
1098 * Evaluation relies on $TYPO3_LOADED_EXT['_CACHEFILE']
1099 * Usage: 2
1100 *
1101 * @return array
1102 * @internal
1103 */
1104 function currentCacheFiles() {
1105 global $TYPO3_LOADED_EXT;
1106
1107 if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
1108 if (t3lib_extMgm::isCacheFilesAvailable($TYPO3_LOADED_EXT['_CACHEFILE'])) {
1109 return array(
1110 PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php',
1111 PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php'
1112 );
1113 }
1114 }
1115 }
1116
1117 /**
1118 * Compiles/Creates the two cache-files in typo3conf/ based on $cacheFilePrefix
1119 * Returns a array with the key "_CACHEFILE" set to the $cacheFilePrefix value
1120 * Usage: 1
1121 *
1122 * @param array Extension information array
1123 * @param string Prefix for the cache files
1124 * @return array
1125 * @internal
1126 */
1127 function writeCacheFiles($extensions,$cacheFilePrefix) {
1128 // Making cache files:
1129 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1130 $cFiles=array();
1131 $cFiles['ext_localconf'].='<?php
1132
1133 $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extensions)).'\'));
1134
1135 ?>';
1136
1137 reset($extensions);
1138 while(list($key,$conf)=each($extensions)) {
1139 if (is_array($conf)) {
1140 if ($conf['ext_localconf.php']) {
1141 $cFiles['ext_localconf'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_localconf.php']);
1142 $cFiles['ext_localconf'].=trim(t3lib_div::getUrl($conf['ext_localconf.php']));
1143 }
1144 if ($conf['ext_tables.php']) {
1145 $cFiles['ext_tables'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_tables.php']);
1146 $cFiles['ext_tables'].=trim(t3lib_div::getUrl($conf['ext_tables.php']));
1147 }
1148 }
1149 }
1150
1151 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php',$cFiles['ext_localconf']);
1152 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php',$cFiles['ext_tables']);
1153
1154 $extensions=array();
1155 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1156
1157 return $extensions;
1158 }
1159
1160 /**
1161 * Unlink (delete) cache files
1162 *
1163 * @return integer Number of deleted files.
1164 */
1165 function removeCacheFiles() {
1166 $cacheFiles = t3lib_extMgm::currentCacheFiles();
1167 $out = 0;
1168 if (is_array($cacheFiles)) {
1169 reset($cacheFiles);
1170 foreach($cacheFiles as $cfile) {
1171 @unlink($cfile);
1172 clearstatcache();
1173 $out++;
1174 }
1175 }
1176 return $out;
1177 }
1178 }
1179
1180 ?>