Random image
Random image
Hello
I am trying to use the random image replacement tag for a background image of a table, is this at all possible, it would be most useful for me.....
Thanks in advance
I am trying to use the random image replacement tag for a background image of a table, is this at all possible, it would be most useful for me.....
Thanks in advance
Hi,
You can add this code and use the new tag
Open include/inc_front/front.func.inc.php
Find function html_parser($string) {
Find in the function sholud be at line 1205
Add after it
Then find in the same file (line 1336)
function get_random_image_tag($path) {
Replace function with
Then use the new tag RANDOM_IMG_FILE
Best Regards
Kiril
You can add this code and use the new tag
Open include/inc_front/front.func.inc.php
Find function html_parser($string) {
Find in the function sholud be at line 1205
Code: Select all
// random Image Tag
$search[15] = '/\{RANDOM:(.*?)\}/e';
$replace[15] = 'get_random_image_tag("$1");';
Code: Select all
// random Image Tag
$search[15] = '/\{RANDOM_IMG_FILE:(.*?)\}/e';
$replace[15] = 'get_random_image_file("$1");';
function get_random_image_tag($path) {
Replace function with
Code: Select all
// -------------------------------------------------------------
function get_random_image($path) {
// returns an random image from the give path
// it looks for image of following type:
// gif, jpg, jpeg, png
$imgArray = array();
$imgpath = str_replace("//", "/", PHPWCMS_ROOT."/".$path."/");
$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;
}
// -------------------------------------------------------------
function get_random_image_tag($path) {
// returns an random image tag from the give path
// it looks for image of following type:
// gif, jpg, jpeg, png
return (get_random_image($path)) ? "<img src=\"".$path."/".$imageinfo["imagename"].
"\" ".$imageinfo[3]." border=\"0\" alt=\"".
$imageinfo["imagename"]."\" />"
: "";
}
// -------------------------------------------------------------
function get_random_image_file($path) {
// returns an random image tag from the give path
// it looks for image of following type:
// gif, jpg, jpeg, png
return (get_random_image($path)) ? $path."/".$imageinfo["imagename"]: "";
}
Best Regards
Kiril
Thanks
Thanks so much for this - but I keep getting Parse error: parse error in /usr/local/psa/home/vhosts/holby.tv/httpdocs/db/include/inc_front/front.func.inc.php on line 2189
Fatal error: Call to undefined function: get_active_categories() in /usr/local/psa/home/vhosts/holby.tv/httpdocs/db/include/inc_front/content.func.inc.php on line 85
when I try and do it.
Any ideas? Thanks
Fatal error: Call to undefined function: get_active_categories() in /usr/local/psa/home/vhosts/holby.tv/httpdocs/db/include/inc_front/content.func.inc.php on line 85
when I try and do it.
Any ideas? Thanks
helloholbytv wrote:Still having trouble mate
The image doesn't come up... no errors though. Using this HTML...
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 height="144">
<TBODY>
<TR>
<TD height="207" background={RANDOM_IMG_FILE:db/img/front/pres}>
</TD></TR>
Thanks
never tryed this! but maybe the random path is wrong!?
Code: Select all
<TD height="207" background={RANDOM_IMG_FILE:db/img/front/pres/}
This modification can't possibly work as the variable $imageinfo is not defined in the functions that return the value, yet it is being used in the return statement. You can't possibly have tested this to work.
The correct modification would be:
I suggest to add a new search statement anyway so not to interfere with the existing {RANDOM..} tags. (Replace xx with the next number)
Hope this helps.
I came accross this post due to the fact that I also needed to have random images posted to the code without any accompanying html code, just the path and file.
regards,
Leone
The correct modification would be:
Code: Select all
// -------------------------------------------------------------
function get_random_image($path) {
// returns an random image from the give path
// it looks for image of following type:
// gif, jpg, jpeg, png
$imgArray = array();
$imgpath = str_replace("//", "/", PHPWCMS_ROOT."/".$path."/");
$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;
}
// -------------------------------------------------------------
function get_random_image_tag($path) {
// returns an random image tag from the give path
// it looks for image of following type:
// gif, jpg, jpeg, png
$imageinfo = get_random_image($path);
return ($imageinfo) ? "<img src=\"".$path."/".$imageinfo["imagename"].
"\" ".$imageinfo[3]." border=\"0\" alt=\"".
$imageinfo["imagename"]."\" />"
: "";
}
// -------------------------------------------------------------
function get_random_image_file($path) {
// returns an random image tag from the give path
// it looks for image of following type:
// gif, jpg, jpeg, png
$imageinfo = get_random_image($path);
return ($imageinfo) ? $path."/".$imageinfo["imagename"]: "";
}
Code: Select all
// random Image File Without tag.
$search[xx] = '/\{RANDIMG:(.*?)\}/e';
$replace[xx] = 'get_random_image_file("$1");';
Hope this helps.
I came accross this post due to the fact that I also needed to have random images posted to the code without any accompanying html code, just the path and file.
regards,
Leone