This is an old revision of the document!


Random Images

FIXME translate

Random Images alias based

Tag: {GET_RANDOM_ALIAS_IMG_URL:image-path}

E.g. {GET_RANDOM_ALIAS_IMG_URL:picture/images/test}

Forum: {GET_RANDOM_ALIAS_IMG_URL}

Authors: tinoo, pepe(starter), RCS robin c. sherwood (adapting and mixing up the code)
Last modified: 23.01.2006 created/mixed up

Filename: rt_get_random_alias_img_url.php

Folder: /template/inc_script/frontend_render/

Switch: $phpwcms['allow_ext_render'] = 1; (/config/phpwcms/conf.inc.php)



Location: /template/inc_script/frontend_render/rt_get_random_alias_img_url.php

{GET_RANDOM_ALIAS_IMG_URL:image-path}

<?php
/********************************************
titel:          {GET_RANDOM_ALIAS_IMG_URL} Replacement-Tag
description:    {GET_RANDOM_ALIAS_IMG_URL:image-path}
    This Replacement-Tag is based on {RANDOM} tag. It started as a mixup of
    tinoos adapted random code and pepes strip-prefix.php. It creates the
    path info of random pictures related to your point of view in a website
    (like "picture/Image/structure- aliasname/pic1.png".
    This tag can be used at places like table background where no <img>-tag is required.
---------------------------------------------
example:    {GET_RANDOM_ALIAS_IMG_URL:picture/Image} or
        <table style="background-image: url ({GET_RANDOM_ALIAS_IMG_URL:picture/Image});"
        or even <img src="{GET_RANDOM_ALIAS_IMG_URL:picture/Image}"> in an "HTML" contentpart.
        <a href="link-to-somewhere"><img src="{GET_RANDOM_ALIAS_IMG_URL:picture/Image}" border="0"></a>
---------------------------------------------
    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 based

This snippet can be used at places like background in css constructions where no <img>-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.



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/
Condition:/config/phpwcms/conf.inc.php

  • $phpwcms['allow_ext_init'] = 1;

Author: Knut Heermann (flip-flop) http://planmatrix.de
Last modified: 03.01.2010 created/mixed up


Code

Location: /template/inc_script/frontend_init/rt_get_random_level_img_url.php

rt_get_random_level_img_url.php

<?php
/*********************************************************************************************
This snippet can be used at places like background where no <img>-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 <img>-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']  = '  <style type="text/css" media="screen">' . LF . '  <!--' . LF;
//   $block['custom_htmlhead']['mycss'] .= '   #bg-image'.$content['cat_id'].' { ' . LF;
   $block['custom_htmlhead']['mycss'] .= '   .bg-image { ' . LF;
   $block['custom_htmlhead']['mycss'] .= '      background: transparent url('.get_random_image_tag("SRC:$_image_path").') no-repeat left top;' . LF;
 
   $block['custom_htmlhead']['mycss'] .= '   }';
   $block['custom_htmlhead']['mycss'] .= LF . '  //-->' . LF . '  </style>';
 
?>


Another Random Background Images Script

Forum: {CSS trick: random body background image}

Only images with the name “rand[0-25].jpg” are available (Folder: “images/skins/”).

<head>
 
<style type="text/css" media="screen">
.bg-image {
   background-image: url(images/skins/[PHP] echo ("skins".rand(0,25).".jpg")[/PHP]) ;
}
</style>
 
</head>
 
<body class="bg-image id-33">


Setup in config/phpwcms/conf.template_default.inc.php

$template_default['body']['class'] = 'bg-image id-';
english/phpwcms_replacer_rts/frontend_render/random_image.1262608241.txt.gz · Last modified: 2018/06/03 18:08 (external edit)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0