Nee, halt nur den entsprechenden Marker im Template
<?php
/***************************************************************
* Copyright notice
*
* (c) 2002 René Fritz (r.fritz@colorcube.de)
* All rights reserved
*
* This script is part of the Typo3 project. The Typo3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Plugin 'Random image' for the 'cc_random_image' extension.
*
* @author René Fritz <r.fritz@colorcube.de>
* @package TYPO3_EXT
* @subpackage cc_randomimage
*/
class tx_ccrandomimage_pi1 {
var $cObj;
/**
* Call it from a USER cObject with 'userFunc = tx_ccrandomimage_pi1->main'
*/
function main ($content,$conf) {
mt_srand((double)microtime()*1000000);
$overrideParms = trim($this->cObj->stdWrap($conf['overrideParms'],$conf['overrideParms.']));
if ($overrideParms) {
$parseObj = t3lib_div::makeInstance('t3lib_TSparser');
$parseObj->parse($overrideParms);
$overrideParms = $parseObj->setup;
}
$config['path'] = $overrideParms['path'] ? $overrideParms['path'] : trim($this->cObj->stdWrap($conf['path'],$conf['path.']));
$config['path'] = str_replace('//','/', $config['path'].'/');
$config['fileExt'] = $overrideParms['fileExt'] ? $overrideParms['fileExt'] : trim($this->cObj->stdWrap($conf['fileExt'],$conf['fileExt.']));
$config['excludePath'] = isset($overrideParms['excludePath']) ? $overrideParms['excludePath'] : trim($this->cObj->stdWrap($conf['excludePath'],$conf['excludePath.']));
// create file table and store it into global var
// to do it this way, we have to get all files only once per page rendering
$key = substr(md5($config['path'].$config['fileExt']),0,10);
if (!is_array($GLOBALS['tx_ccrandomimage_pi1'][$key])) {
$dataArray = array();
$GLOBALS['tx_ccrandomimage_pi1'][$key] = array();
$paths = explode (',',$config['path']);
$fileExt = explode (',',$config['fileExt']);
reset($paths);
while (list(, $path) = each($paths)) {
$GLOBALS['tx_ccrandomimage_pi1'][$key] = array_merge($GLOBALS['tx_ccrandomimage_pi1'][$key],$this->traverseDirectory(trim($path),$fileExt,&$dataArray,FALSE,10));
}
}
/* testing rand()
$numbers = array();
for ($i=0;$i<100000;$i++) {
$numbers[mt_rand(0,10)]++;
}
asort($numbers);
debug($numbers);
*/
// we need that to check for the markers
$markContentArray = Array();
$markContentArray['###FILE_PATH###'] = $config['path'];
$count = 0;
$found = false;
do {
$imageFile = '';
$count ++;
// if marker not found - let's stop searching for markers
$found = false;
// select one random image and remove it from the file table (the image will be selected once)
if($filesCount = count($GLOBALS['tx_ccrandomimage_pi1'][$key])) {
// search for markers in renderObj setup
if ($this->str_in_array('###FILE_'.$count."###", $conf['renderObj.'])) {
$found = true;
// get a random image from the global list
$select = min(mt_rand(0,$filesCount),$filesCount-1);
$randomImage = $GLOBALS['tx_ccrandomimage_pi1'][$key][$select];
// delete just selected image from the global list
if ( $select == $filesCount-1 ) {
unset($GLOBALS['tx_ccrandomimage_pi1'][$key][$select]);
} else {
$GLOBALS['tx_ccrandomimage_pi1'][$key][$select]=$GLOBALS['tx_ccrandomimage_pi1'][$key][$filesCount-1];
unset($GLOBALS['tx_ccrandomimage_pi1'][$key][$filesCount-1]);
$filesCount--;
}
// apply image to marker
$markContentArray['###FILE_'.$count.'###'] = ($config['excludePath']?'':$randomImage['path']).$randomImage['file'];
}
}
} while ($found AND $count<50 AND $filesCount);
$lConf = $conf['renderObj.'];
$this->cObj->substituteMarkerInObject (&$lConf, $markContentArray);
$content.=$this->cObj->cObjGetSingle($conf['renderObj'],$lConf);
return $content;
}
function traverseDirectory($searchPath,$fileExt,&$dataArray,$recursive,$maxinst,$aktinst = 0) {
$searchPath = str_replace ('//','/',$searchPath.'/');
//Load Directory Into Array
$handle=@opendir($searchPath);
while ($file = @readdir($handle)) {
$newDataArray[$searchPath.$file]['file'] = $file;
$newDataArray[$searchPath.$file]['path'] = $searchPath;
}
@closedir($handle);
if (is_array($newDataArray)) {
reset($newDataArray);
while (list($key, $file) = each($newDataArray)) {
// clean it
if (($file['file'] == '.') OR ($file['file'] == '..')) {
unset ($newDataArray[$key]);
// get dirs
} elseif (is_dir($key)) {
if ( $recursive && ($aktinst < $maxinst || $maxinst == 0) ) {
unset ($newDataArray[$key]);
traverseDirectory($key."/",$fileSetup,$dataArray,$recursive,$maxinst,$aktinst+1);
}
} else {
reset($fileExt);
while (list(, $ext) = each($fileExt)) {
if ($ext == substr($file['file'],(strlen($ext)*-1))) {
$dataArray[] = $file;
unset ($newDataArray[$key]);
}
}
}
}
} else {
$dataArray = array();
}
return $dataArray;
}
function str_in_array ($needle, $array) {
reset($array);
while(list($key,$val)=each($array)) {
if (is_array($val)) {
if ($this->str_in_array ($needle, $val)) {
return true;
}
} elseif (strstr($val, $needle)) {
return true;
}
}
return false;
}
}
if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/cc_random_image/pi1/class.tx_ccrandomimage_pi1.php"]) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/cc_random_image/pi1/class.tx_ccrandomimage_pi1.php"]);
}
?>