{{indexmenu_n>620}} ====== Random Images ====== ====== Random Images Alias basiert ====== Tag: **{GET_RANDOM_ALIAS_IMG_URL:image-path}** E.g. {GET_RANDOM_ALIAS_IMG_URL:picture/images/test} **Forum:** [[http://forum.phpwcms.org/viewtopic.php?p=57124#p57124|{GET_RANDOM_ALIAS_IMG_URL}]] **Autoren:** tinoo, pepe(starter), RCS robin c. sherwood //(adapting and mixing up the code)// \\ **Letze Änderung:** 23.01.2006 created/mixed up **Dateiname:** rt_get_random_alias_img_url.php **Verzeichnis:** /template/inc_script/frontend_render/ **Schalter:** $phpwcms['allow_ext_render'] = 1; (/config/phpwcms/conf.inc.php) ---- ---- \\ Die Verwendung ist denkbar einfach. Für jeden Stukturalias, der mit per Zufall ausgesuchten Bildern bestückt werden soll, legst Du ein Verzeichnis an, z.B. /picture/Image/structure-aliasname/.. \\ Der Upload kann per FTP erfolgen. \\ \\ Datei: **/template/inc_script/frontend_render/rt_get_random_alias_img_url.php** -tag is required. --------------------------------------------- example: {GET_RANDOM_ALIAS_IMG_URL:picture/Image} or
in an "HTML" contentpart. --------------------------------------------- The directories "alias1" "alias2" ... are subdirectories of picture/Image (you have to create them according to your given aliases "alias1" "alias2"... in admin/site structure). The complete path to the random pictures is then: www.yourdomain.com/picture/Image/alias1/ www.yourdomain.com/picture/Image/alias2/ and so on. The advantage of defining the alias-dirs in "picture/Image" is that this dir is used by fckeditor and you then can upload pictures per FTP and/or per fckeditor. It will deliver the pictures of the appropriately defined dir according to where you are in the site. --------------------------------------------- notice: name this file get_random_alias_img_url.php and copy it to phpwcms_template/inc_script/frontend_render --------------------------------------------- authors: tinoo, pepe(starter), RCS robin c. sherwood (adapting and mixing up the code) last modified: 23.01.2006 created/mixed up ********************************************/ // ---------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ---------------------------------------------------------------- function get_random_image_url_based_on_alias($path) { // returns a random image url from the given path // it looks for image of following type: gif, jpg, jpeg, png $alias = $GLOBALS['content']['struct'][($GLOBALS['aktion'][0])]['acat_alias']; $mypath = ($path."/".$alias); $imgArray = array(); $imgpath = str_replace("//", "/", PHPWCMS_ROOT."/".$mypath."/"); $imageinfo = false; if(is_dir($imgpath)) { $handle = opendir( $imgpath ); while($file = readdir( $handle )) { if( $file != "." && $file != ".." ) { if( preg_match('/(\.jpg|\.jpeg|\.gif|\.png)$/', strtolower($file)) ) $imgArray[] = $file; } } closedir( $handle ); } if(sizeof($imgArray)) $imageinfo = is_random_image($imgArray, $imgpath); return ($imageinfo) ? "".$mypath."/".$imageinfo["imagename"]: ""; } $content["all"] = preg_replace('/\{GET_RANDOM_ALIAS_IMG_URL:(.*?)\}/ie', 'get_random_image_url_based_on_alias("$1");', $content["all"]); ?> \\ ====== Random Images Level basiert ====== **Dieser Programmteil kann an Orten wie background in CSS-Konstrutionen verwendet werden, die kein -tag erfordern.** **Beschreibung:** rt_get_random_level_img_url.php Dieser Programmteil verwendet die Funktion des {RANDOM} Tag. Es sucht nach bildern im Pfad der in $_image_path like angeben ist z.B. picture/random[XX]/pic1.png". \\ Wobei XX die ID der aktiven Kategorie aus der Seitenstruktur des vorgegebenen Levels ist. //(Setup in $_level_base)//. Wenn in $_level_base "false" gesetzt ist, dann ist $_image_path der Fallback Bilderpfad. Alle Bilder werden in diesem Ordner gesucht. \\ Wenn $_level_base z.B. auf "1" gesetzt ist und die aktive Kategorie ist eine Sub-Kategorie der Kategorie in Level 1 z.B.. "ID=43", dann wird der Bilderpfad nach "picture/random43/" konvertiert. \\ Von allen Bildern in "picture/random43/" wird eins zufällig ausgewählt. ---- \\ **Beispiel:** gegebene Struktur: home (id=0) level 0 - cat01 (id=01) level 1 - cat02 (id=22) level 1 --- cat02_01 (id=45) level 2 --- cat02_02 (id=46) level 2 - [aktive Kategorie] - cat03 (id=33) level 1 $_level_base = 1; $_image_path = picture/random; Dieser Programmteil wird ein Pfad wie "picture/random22/" generieren und prüft alle Bilder in diesem Pfad. \\ Wenn "picture/random22/" nicht existiert, dann werden die Bilder im Fallback-Pfad "picture/random/" gesucht. \\ Das Gleiche wenn $_level_base = false; \\ ---- \\ **Notiz:** Benenne die Datei **rt_get_random_level_img_url.php** und kopiere diese nach **phpwcms_template/inc_script/frontend_init/** \\ **Bedingung:** -> [[http://www.phpwcms-docu.de/confincphp_de.phtml|/config/phpwcms/conf.inc.php]] \\ * $phpwcms['allow_ext_init'] = 1; ---- **Autor:** Knut Heermann (flip-flop) http://planmatrix.de \\ **Letze Änderung:** 03.01.2010 created/mixed up ==== Code ==== Ort: **/template/inc_script/frontend_init/rt_get_random_level_img_url.php** -tag is required. description: rt_get_random_level_img_url.php This snippet is using the function of {RANDOM} tag. It search for pictures in the path you have setup in $_image_path like e.g. "picture/random[XX]/pic1.png". Where XX is the id of the active category in site structure of the given level ( setup in $_level_base). If you have setup $_level_base to "false", $_image_path is the fallback image path. All pictures will be searched in the folder. If you have setup $_level_base to e.g. "1" and your active category is a sub category of the category in level 1 e.g. "id=43", the image path is converted to "picture/random43/". From all the images in "picture/random43/" one becomes randomly selected. This tag can be used at places like table background where no -tag is required. --------------------------------------------------------------------- example: given structure: home (id=0) level 0 - cat01 (id=01) level 1 - cat02 (id=22) level 1 --- cat02_01 (id=45) level 2 --- cat02_02 (id=46) level 2 - [active category] - cat03 (id=33) level 1 $_level_base = 1; $_image_path = picture/random; The snippet will generate a path like picture/random22/ and checks for all images in this path. If "picture/random22/" does not exist, then the images will be searched in the fallback path "picture/random/" The same if $_level_base = false; --------------------------------------------------------------------- notice: name this file rt_get_random_level_img_url.php and copy it to phpwcms_template/inc_script/frontend_init --------------------------------------------------------------------- author: Knut Heermann (flip-flop) http://planmatrix.de last modified: 03.01.2010 created/mixed up **********************************************************************************************/ // ------------------------------------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ------------------------------------------------------------------------------------------- // ===== CUSTOM SETTINGS ===================================================================== $_image_path = 'picture/random'; // path where the default (and fallback) images are $_level_base = 1; // false = off | Level-No = on e.g. 1 = TopLevel // ===== CUSTOM SETTINGS END ================================================================= if ( ($_level_base !== false) AND (isset($LEVEL_ID[$_level_base])) AND (is_dir($_image_path.$LEVEL_ID[$_level_base] )) ) $_image_path .= $LEVEL_ID[$_level_base]; // e.g. picture/random24 is the image path for images in category ID=24 and their subcategories // $template_default['body']['id'] = 'bg-image'; // it will be produced always "bg-image[cat-id]" $template_default['body']['class'] = 'bg-image id-'; // it will be produced always "bg-image[cat-id]" // Hm I want to write some default CSS $block['custom_htmlhead']['mycss'] = ' '; ?> \\ ====== Ein anderes Random Background Images Script ====== Forum: [[http://forum.phpwcms.org/viewtopic.php?f=8&t=14342&p=121758#p121758|{CSS trick: random body background image}]] Es sind in diesem Beispiel nur bilder mit dem Namen "rand[0-25].jpg" verfügbar (Ordner "images/skins/"). \\ Setup in **config/phpwcms/conf.template_default.inc.php** $template_default['body']['class'] = 'bg-image id-'; \\ ====== Random Images aus Accountverzeichnis ====== {RANDOMX:%SRC-LB%:%path%:%WIDTH%x%HEIGHT%} Aus einem anzugebenden Verzeichnis des Accounts wird aus den dort abgelegten Bildern ein Bild zufällig ausgewählt und dargestellt. Dieser erweiterte TAG erlaubt die Größenvorgabe für Vorschaubilder //(Thumbs)// und den Aufruf der LighBox //(SlimBox)//. Wie {RANDOM:Pfad}, jedoch mit folgenden Eigenschaften: * Gibt ein zufälliges Bild aus dem angegebenen Pfad zurück * Schaut nach Bilder des folgendes Typs: gif, jpg, jpeg, png. * **{RANDOMX:path}** gibt mit %%"path=path/rand_image/"%% --> %%%% zurück. * **{RANDOMX:SRC:path}** gibt das Bild zurück mit der absoluten Adresse %%URI PHPWCMS_URL/path/rand_image/...%% * **{RANDOMX:SRC-R:path}** gibt das Bild zurück mit der relativen Adresse %%path/rand_image/...%%. * **{RANDOMX:SRC-LB:path:WIDTHxHEIGHT}** gibt den kompletten html-Anweisungssatz für die LightBox mit %%WIDTHxHEIGHT%% für die Thumbs zurück * Die LightBox stellt die Bilder in der Originalgröße dar. * Die Thumbs werden lediglich verkleinert dargestellt, nicht neu gerechnet/abgelegt oder beschnitten //(cropping)//. \\ **Beispiel:** ##%%{RANDOMX:SRC-LB:picture/upload/image/:200x150}%%## ==== PHP: ==== **Datei:** template/inc_Script/forntend_render/rt_randomX_img.php // {RANDOMX:SRC:path} will return absolute URI PHPWCMS_URL/path/rand_image // {RANDOMX:SRC-R:path} will return only relative path/rand_image // {RANDOMX:SRC-LB:path:%WIDTH%x%HEIGHT%} will return a complete html set for LightBox with WIDTHxHEIGHT for the thumb $imgArray = array(); $path = trim($path); $tagX = false; //+KH if(strtoupper(substr($path, 0, 4)) == 'SRC:') { $tag = false; $path = trim(substr($path, 4)); // relative path/rand_image } elseif (strtoupper(substr($path, 0, 6)) == 'SRC-R:') { // +KH $tag = false; $tagX = 1; $path = trim(substr($path, 6)); // complete html set for LightBox with WIDTHxHEIGHT for the thumb } elseif (strtoupper(substr($path, 0, 7)) == 'SRC-LB:') { // +KH // %WIDTH%x%HEIGHT fallback $width = 150; $height = 100; $tag = false; $tagX = 2; $path = trim(substr($path, 7)); $data = explode(':', $path); $path = $data[0]; if (isset($data[1])) { // find WIDTH x HEIGHT $data[1] = preg_replace('/[^0-9x]/', '', $data[1]); $attribute = explode('x', $data[1]); $width = intval($attribute[0]); $height = isset($attribute[1]) ? intval($attribute[1]) : 0; } } else { $tag = true; } $path = trim($path, '/'); $imgpath = PHPWCMS_ROOT . '/' . $path . '/'; $imageinfo = false; if(is_dir($imgpath)) { $handle = opendir( $imgpath ); while($file = readdir( $handle )) { if( $file{0} != '.' && preg_match('/(\.jpg|\.jpeg|\.gif|\.png)$/i', $file)) { $imgArray[] = $file; } } closedir( $handle ); } if(count($imgArray) && ($imageinfo = is_random_image($imgArray, $imgpath))) { if($tag) { // normal output return ''.html_specialchars($imageinfo['; $x .= ''.html_specialchars($imageinfo['; return $x; } elseif (($tagX === 1)) // SRC-R return $path . '/' . urlencode($imageinfo['imagename']); else return PHPWCMS_URL . $path . '/' . urlencode($imageinfo['imagename']); } } return ''; } // randomX Image Tag $search = '/\{RANDOMX:(.*?)\}/e'; $replace = 'get_random_image_tagX("$1");'; $content["all"] = preg_replace($search, $replace, $content["all"]); // $string = str_replace('\'', ''', $string); // $string = str_replace('&quot;', '"', $string); ?> \\ ===== V1.1 ===== Identisch mit der o.g. Version jedoch erweitert durch die Darstellung aller Bilder im angegebenen Verzeichnis mit Hilfe der LightBox //(Next/Prev)//. * **{RANDOMX:SRC-LBNP:path:WIDTHxHEIGHT}** gibt den kompletten html-Anweisungssatz für die LightBox mit %%WIDTHxHEIGHT%% für die Thumbs zurück und stellt alle Bilddateien aus dem angegebenen Pfad in der LightBox dar. * Die LightBox stellt die Bilder in der Originalgröße dar. * Das Thumb wird lediglich verkleinert dargestellt, nicht neu gerechnet/abgelegt oder beschnitten //(cropping)//. * Update 21.06.11: - Das Thumb wird proportional verkleinert entsprechend den Größenangaben dargestellt //(Identisches Verfahren wie in den Bilder CPs - Das größte Teilungsverhältnis ist der Richtwert für beide Seiten)//. - Korrektur beim Bildtyp. \\ **Beispiel:** ##%%{RANDOMX:SRC-LBNP:picture/upload/image/:200x150}%%## Das Zufallsvorschaubild //(Thumb)// wird mit einer maximalen Größe von 200x150px //(siehe oben "proportional")// dargestellt und verlinkt auf die LightBox, in der dann alle Bilder des Verzeichnisses in Originalgröße mit //(Next/Prev)// dargestellt werden können. \\ ==== PHP V1.1: ==== **Datei:** template/inc_Script/forntend_render/rt_randomX_img.php // {RANDOMX:SRC:path} will return absolute URI PHPWCMS_URL/path/rand_image // {RANDOMX:SRC-R:path} will return only relative path/rand_image // {RANDOMX:SRC-LB:path:%WIDTH%x%HEIGHT%} will return a complete html set for LightBox with proportional WIDTHxHEIGHT for the thumb // {RANDOMX:SRC-LBNP:path:%WIDTH%x%HEIGHT%} the same like SRC-LB with LightBox Next/Prev pictures from this folder $imgArray = array(); $path = trim($path); $tagX = false; //+KH if(strtoupper(substr($path, 0, 4)) == 'SRC:') { $tag = false; $path = trim(substr($path, 4)); // relative path/rand_image } elseif (strtoupper(substr($path, 0, 6)) == 'SRC-R:') { // +KH $tag = false; $tagX = 1; $path = trim(substr($path, 6)); // complete html set for LightBox with WIDTHxHEIGHT for the thumb } elseif (strtoupper(substr($path, 0, 6)) == 'SRC-LB') { // +KH // %WIDTH%x%HEIGHT fallback $width = 150; $height = 100; $tag = false; $tagX = 2; if (strtoupper(substr($path, 0, 9)) == 'SRC-LBNP:') { $path = trim(substr($path, 9)); $tagX = 3; } else $path = trim(substr($path, 7)); $data = explode(':', $path); $path = $data[0]; if (isset($data[1])) { // find WIDTH x HEIGHT $data[1] = preg_replace('/[^0-9x]/', '', $data[1]); $attribute = explode('x', $data[1]); $width = intval($attribute[0]); $height = isset($attribute[1]) ? intval($attribute[1]) : 0; } } else { $tag = true; } $path = trim($path, '/'); $imgpath = PHPWCMS_ROOT . '/' . $path . '/'; $imageinfo = false; if(is_dir($imgpath)) { $handle = opendir( $imgpath ); while($file = readdir( $handle )) { if( $file{0} != '.' && preg_match('/(\.jpg|\.jpeg|\.gif|\.png)$/i', $file)) { $imgArray[] = $file; } } closedir( $handle ); } // RANDOM if(count($imgArray) && ($imageinfo = is_random_image($imgArray, $imgpath))) { if($tag) { // normal output return ''.html_specialchars($imageinfo[ jpeg if ($imageinfo['2'] == 2) $img_type .= '&q=85'; // Only if jpg = type Nr 2 // Proportional image size $img_x = $imageinfo[0] / $width; // z.B. 800 / 200 = 4,00 $img_y = $imageinfo[1] / $height; // z.B. 532 / 100 = 5,32 if ($img_x < $img_y) $width = $imageinfo[0] / $img_y; else $height = $imageinfo[1] / $img_x; $x = ''; $x .= ''.html_specialchars($imageinfo['.LF; $random_image = $imageinfo['imagename']; // LightBox with Next/Prev: Read all available images in path if ($tagX === 3 ) { // SRC-LBNP: foreach ($imgArray as $key=>$value) { $imageinfo = @getimagesize($imgpath.$value); // is it an image? if ($imageinfo) { $img_type = substr($imageinfo['mime'], 6); // e.g. image/jpeg -> jpeg if ($imageinfo['2'] == 2) $img_type .= '&q=85'; // Only if jpg = type Nr 2 if ($random_image != $value) // No double image entry except the random image $x .= ''.LF; // $x .= ''.html_specialchars($value).''.LF; } } } return $x; } elseif (($tagX === 1)) // SRC-R return $path . '/' . urlencode($imageinfo['imagename']); else // SRC: return PHPWCMS_URL . $path . '/' . urlencode($imageinfo['imagename']); } } return ''; } // randomX Image Tag $search = '/\{RANDOMX:(.*?)\}/e'; $replace = 'get_random_image_tagX("$1");'; $content["all"] = preg_replace($search, $replace, $content["all"]); // $string = str_replace('\'', ''', $string); // $string = str_replace('&quot;', '"', $string); ?> \\