NAVIGATION
This shows you the differences between two versions of the page.
deutsch:ersetzer_rts:frontend_render:random_image [2011/06/19 16:38] Knut Heermann (flip-flop) |
deutsch:ersetzer_rts:frontend_render:random_image [2018/06/03 18:09] (current) |
||
---|---|---|---|
Line 2: | Line 2: | ||
====== Random Images ====== | ====== Random Images ====== | ||
- | ===== Random Images Alias basiert ===== | + | ====== Random Images Alias basiert ====== |
Line 8: | Line 8: | ||
<code php>E.g. {GET_RANDOM_ALIAS_IMG_URL:picture/images/test}</code> | <code php>E.g. {GET_RANDOM_ALIAS_IMG_URL:picture/images/test}</code> | ||
- | Forum: [[http://forum.phpwcms.org/viewtopic.php?p=57124#p57124|{GET_RANDOM_ALIAS_IMG_URL}]] | + | **Forum:** [[http://forum.phpwcms.org/viewtopic.php?p=57124#p57124|{GET_RANDOM_ALIAS_IMG_URL}]] |
- | Authors: tinoo, pepe(starter), RCS robin c. sherwood //(adapting and mixing up the code)// \\ | + | **Autoren:** tinoo, pepe(starter), RCS robin c. sherwood //(adapting and mixing up the code)// \\ |
- | Last modified: 23.01.2006 created/mixed up | + | **Letze Änderung:** 23.01.2006 created/mixed up |
- | Filename: rt_get_random_alias_img_url.php | + | **Dateiname:** rt_get_random_alias_img_url.php |
- | Folder: /template/inc_script/frontend_render/ | + | **Verzeichnis:** /template/inc_script/frontend_render/ |
- | Switch: $phpwcms['allow_ext_render'] = 1; (/config/phpwcms/conf.inc.php) | + | **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. \\ | ||
- | Hier fehlt noch eine etwas genauere Erklärung. | + | <file> |
- | FIXME | + | <table style="background-image: url ({GET_RANDOM_ALIAS_IMG_URL:picture/Image}) |
+ | <img src="{GET_RANDOM_ALIAS_IMG_URL:picture/Image}"> | ||
+ | <a href="link-to-somewhere"><img src="{GET_RANDOM_ALIAS_IMG_URL:picture/Image}" border="0"></a> | ||
+ | </file> | ||
+ | |||
+ | \\ | ||
+ | Datei: **/template/inc_script/frontend_render/rt_get_random_alias_img_url.php** | ||
- | Location: **/template/inc_script/frontend_render/rt_get_random_alias_img_url.php** | ||
<code php |h {GET_RANDOM_ALIAS_IMG_URL:image-path}|h > | <code php |h {GET_RANDOM_ALIAS_IMG_URL:image-path}|h > | ||
<?php | <?php | ||
Line 94: | Line 102: | ||
\\ | \\ | ||
- | ===== Random Images Level basiert ===== | + | ====== Random Images Level basiert ====== |
**Dieser Programmteil kann an Orten wie background in CSS-Konstrutionen verwendet werden, die kein <img>-tag erfordern.** | **Dieser Programmteil kann an Orten wie background in CSS-Konstrutionen verwendet werden, die kein <img>-tag erfordern.** | ||
Line 217: | Line 225: | ||
\\ | \\ | ||
- | ===== Ein anderes Random Background Images Script ===== | + | ====== 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}]] | Forum: [[http://forum.phpwcms.org/viewtopic.php?f=8&t=14342&p=121758#p121758|{CSS trick: random body background image}]] | ||
Line 245: | Line 253: | ||
\\ | \\ | ||
- | ===== Random Images aus Accountverzeichnis ===== | + | ====== Random Images aus Accountverzeichnis ====== |
{RANDOMX:%SRC-LB%:%path%:%WIDTH%x%HEIGHT%} | {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: | Wie {RANDOM:Pfad}, jedoch mit folgenden Eigenschaften: | ||
Line 258: | Line 269: | ||
* **{RANDOMX:SRC-LB:path:WIDTHxHEIGHT}** gibt den kompletten html-Anweisungssatz für die LightBox mit %%WIDTHxHEIGHT%% für die Thumbs zurück | * **{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 LightBox stellt die Bilder in der Originalgröße dar. | ||
- | * Die Thumbs werden lediglich verkleinert dargestellt, nicht neu gerechnet/abgelegt. | + | * Die Thumbs werden lediglich verkleinert dargestellt, nicht neu gerechnet/abgelegt oder beschnitten //(cropping)//. |
\\ | \\ | ||
Line 284: | Line 295: | ||
// {RANDOMX:SRC:path} will return absolute URI PHPWCMS_URL/path/rand_image | // {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-R:path} will return only relative path/rand_image | ||
- | // {RANDOMX:SRCX-LB:path:%WIDTH%x%HEIGHT%} will return a complete html set for LightBox with WIDTHxHEIGHT for the thumb | + | // {RANDOMX:SRC-LB:path:%WIDTH%x%HEIGHT%} will return a complete html set for LightBox with WIDTHxHEIGHT for the thumb |
Line 301: | Line 312: | ||
// complete html set for LightBox with WIDTHxHEIGHT for the thumb | // complete html set for LightBox with WIDTHxHEIGHT for the thumb | ||
- | } elseif (strtoupper(substr($path, 0, 8)) == 'SRCX-LB:') { // +KH | + | } elseif (strtoupper(substr($path, 0, 7)) == 'SRC-LB:') { // +KH |
// %WIDTH%x%HEIGHT fallback | // %WIDTH%x%HEIGHT fallback | ||
$width = 150; | $width = 150; | ||
Line 308: | Line 319: | ||
$tag = false; | $tag = false; | ||
$tagX = 2; | $tagX = 2; | ||
- | $path = trim(substr($path, 8)); | + | $path = trim(substr($path, 7)); |
$data = explode(':', $path); | $data = explode(':', $path); | ||
$path = $data[0]; | $path = $data[0]; | ||
Line 342: | Line 353: | ||
} else { | } else { | ||
- | if ($tagX === 2) { // SRCX-LB | + | if ($tagX === 2) { // SRC-LB |
initializeLightbox(); | initializeLightbox(); | ||
// $x = '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE; | // $x = '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE; | ||
Line 370: | Line 381: | ||
?> | ?> | ||
+ | </code> | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ===== 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 | ||
+ | |||
+ | <code php|h rt_randomX_img.php |h> | ||
+ | <?php | ||
+ | // KH 21.06.11 flip-flop: Random image from normal folder V1.1 | ||
+ | |||
+ | // ------------------------------------------------------------------------------------------- | ||
+ | // obligate check for phpwcms constants | ||
+ | if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");} | ||
+ | // ------------------------------------------------------------------------------------------- | ||
+ | |||
+ | |||
+ | function get_random_image_tagX($path) { | ||
+ | // returns an random image from the given path | ||
+ | // it looks for image of following type: gif, jpg, jpeg, png | ||
+ | // {RANDOMX:path} will return <img src="path/rand_image" /> | ||
+ | // {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 '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE; | ||
+ | } else { | ||
+ | |||
+ | // LightBox output | ||
+ | if ($tagX === 2 OR $tagX === 3) { // SRC-LB OR SRC-LBNP: | ||
+ | initializeLightbox(); | ||
+ | // $x = '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE; | ||
+ | |||
+ | // Type of image | ||
+ | $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 | ||
+ | |||
+ | // 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 = '<a href="image_resized.php?format='.$img_type.'&imgfile='.$path.'/'.urlencode($imageinfo['imagename']).'" rel="lightbox[NextPrev]" target="_blank">'; | ||
+ | $x .= '<img src="image_resized.php?format='.$img_type.'&imgfile='.$path.'/'.urlencode($imageinfo['imagename']).'" class="random-img" alt="'.html_specialchars($imageinfo["imagename"]).'" height="'.$height.'" width="'.$width.'"></a>'.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 .= '<a href="image_resized.php?format='.$img_type.'&imgfile='.$path.'/'.urlencode($value).'" rel="lightbox[NextPrev]" target="_blank"></a>'.LF; | ||
+ | // $x .= '<img src="image_resized.php?format=jpg&q=85&imgfile='.$path.'/'.urlencode($value).'" class="image_img" alt="'.html_specialchars($value).'" height="'.$height.'" width="'.$width.'"></a>'.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); | ||
+ | |||
+ | |||
+ | ?> | ||
</code> | </code> | ||
\\ | \\ | ||