Zum Inhalt springen

random-images marker wird nicht angesprochen

Erstellt am 20. August 2004 · 11 Antworten · letzte Antwort am 3. September 2004

Tags: Frage

simba ·

hi,

ich habe die extension "Random images" nach der anleitung bei http://typo3lab.colorcube.de/Random_images.59.0.html
gemacht. die bildwechselfunktion klappt wunderbar.leider aber nicht an der vorgesehen stelle der marker wird nicht angesprochen. hat jemand ne ahnung woran das liegen kann?

gruss

markus

ps: der code:

########
##RANDOM_IMGAES

includeLibs.randomImage = media/scripts/random_image.php

marks.RANDOM = USER
marks.RANDOM {
userFunc = user_randomImage->main_randomImage
path = fileadmin/images_random/
fileExt = jpg,jpeg,gif

image = IMAGE
image.file = fileadmin/images_random/
}

page.10 < marks.RANDOM

simba ·

mein fehler ist wahrscheinlich sehr einfach. der marker wird nicht angesprochen. das php-script funktioniert aber. kann mir jemand beim fehlersuchen helfen? danke schon im voraus!

herzlich markus 😉

########
##RANDOM_IMGAES

includeLibs.randomImage = media/scripts/random_image.php

marks.RANDOM = USER
marks.RANDOM {
userFunc = user_randomImage->main_randomImage
path = fileadmin/images_random/
fileExt = jpg,jpeg,gif

image = IMAGE
image.file = fileadmin/images_random/
}

page.10 < marks.RANDOM

simba ·

hi,

nun habe ich rausgekriegt, dass das tutorial das random-image immer in die linke spalte neben das menue platziert. ich möchte es aber im anstelle des markers RANDOM. krieg ich das hin, indem ich den ts-code abändere, oder muss ich an das php-script dran?
danke für antwort

gruss

markus

link phpscript: http://typo3lab.colorcube.de/fileadmin/t3lab/download/randomImage/random_image.php.txt

tscode:
########
##RANDOM_IMGAES

includeLibs.randomImage = media/scripts/random_image.php

marks.RANDOM = USER
marks.RANDOM {
userFunc = user_randomImage->main_randomImage
path = fileadmin/images_random/
fileExt = jpg,jpeg,gif

image = IMAGE
image.file = fileadmin/images_random/
}

page.10 < marks.RANDOM

Zinner ·
rImage = USER_INT
rImage {

  userFunc = tx_ccrandomimage_pi1->main
  path = fileadmin/template/random/
  fileExt = jpg,jpeg,gif,png

  renderObj = COA
  renderObj {
      10 = IMAGE
      10.file = ###FILE_1###
      }
}

page.10.marks.DEINMARKER < rImage

Versuche es mal hiermit..

simba ·

damit gehts leider gar nicht. bei wem läuft die extension richtig und kann mir helfen?

gruss

markus

simba ·

würdest du mir vielleicht mal die php-datei posten und hast du sonst nicht mehr wegen dem random images im setup stehen?

danke und gruss!!

markus

Zinner ·

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"]);
}

?>
simba ·

hi,

ich habe alles genauso gemacht, wie du empfohlen hast. leider kommt ne fehlermeldung:

----------------
Fatal error: Cannot redeclare class tx_ccrandomimage_pi1 in /home/evbgch/public_html/media/scripts/random_image.php on line 34
-----------------

ich habe deine php-datei übernommen. mein marker in der designvorlage ist: ###RANDOM###. trotzdem klappts nicht. hast du einen tipp, oder jemand anderes?

danke und gruss

markus

ts:
########
##RANDOM_IMGAES

includeLibs.randomImage = media/scripts/random_image.php

rImage = USER_INT
rImage {

userFunc = tx_ccrandomimage_pi1->main
path = fileadmin/images_random/
fileExt = jpg,jpeg,gif,png

renderObj = COA
renderObj {
10 = IMAGE
10.file = ###FILE_1###
}
}

page.10.marks.RANDOM < rImage

simba ·

hi,

ich habe schon alles probiert: ts gewechselt, abgeändert, phpscript gewechselt und ausgewechselt. das beste resultat erziele ich mit dem tutorial http://typo3lab.colorcube.de/Random_images.59.0.html
der bildwechsel klappt, nur nicht am durch einen marker vorgesehenen platz. das bild wird links unten neben meinem centrierten website dargestellt. der marker RANDOM wird nicht angesprochen. was mache ich falsch. kann mir jemand helfen? es wäre echt klasse!!

herzlich markus

ts:
########
##RANDOM_IMGAES

includeLibs.randomImage = media/scripts/random_image.php

marks.RANDOM = USER
marks.RANDOM {
userFunc = user_randomImage->main_randomImage
path = fileadmin/images_random/
fileExt = jpg,jpeg,gif

image = IMAGE
image.file = fileadmin/images_random/
}

page.10 < marks.RANDOM

php: http://typo3lab.colorcube.de/fileadmin/t3lab/download/randomImage/random_image.php.txt

typo3Anwender ·

Hallo,

1. Marker korrekt benennen:

ts:
########
##RANDOM_IMGAES

wenn Du den Marker wirklich so genannt hast, kann es nicht gehen. Nenne ihn so:

###RANDOM_IMAGES###

2.
Schreibe im Setup das hier:

includeLibs.randomImage = media/scripts/random_image.php

temp.RANDOM = USER
temp.RANDOM {
   userFunc = user_randomImage->main_randomImage
   path = fileadmin/images_random/
   fileExt = jpg,jpeg,gif
   image = IMAGE
   image.file = fileadmin/images_random/
} 

page.10.marks.RANDOM_IMAGES < temp.RANDOM

Du kannst es auch so machen, wie hier erklärt:
#14917
(im unteren Abschnitt).

Viel Spaß.

MfG
Stefan