New idea, I have edited my last posting:
-
-
+ $block['custom_htmlhead']['mycss'] .= ' #bg-image'.$content['cat_id'].' { ' . LF;
Code: Select all
$template_default['body']['id'] = 'thisISit blah_fkID';
$template_default['body']['class'] = 'take_that blahClass_fkID';
Tat's de trutJensensen wrote:index.php needs some hack
Code: Select all
{RAND_IMG_FROM_FOLDER:ID of PHPWCMS Folder:CSS_CLASS or HTML tag:WxHxCROPxQUALITY ALT-Text}
Code: Select all
<?php
/* ===========================================================================================
random image from folder V1.0 22.03.10 breitsch http://www.webrealisierung.ch
-> {RAND_IMG_FROM_FOLDER:ID of PHPWCMS Folder:CSS_CLASS or HTML tag:WxHxCROPxQUALITY ALT-Text}
The original script in /include/inc_front/ext.func.inc.php programmed by (c) Oliver Georgi
22.03.10 patched and swaped out to /frontend_render/* by breitsch partially copied from
imgx V1.0 03.01.09 by K.Heermann (flip-flop)
Tag:
{RAND_IMG_FROM_FOLDER:ID of PHPWCMS Folder:CSS_CLASS or HTML tag:WxHxCROPxQUALITY ALT-Text}
ID of PHPWCMS Folder = the ID number of the Folder in the phpwcms file browser - required
CSS_CLASS or HTML tag = the CSS class or the HTML tag you want to add a random background image from the above folder
only the css property 'background-image' is rendered to the head section of the site, the
rest of the definitions should be done in the frontend css
if empty it renders the image in an image tag (<img src= ... />) for use wherever you want
WxHxCROPxQUALITY ALT-Text = Dimensions and alt text of the image (alt text only when not used as background image)
if empty and css background image it takes the original dimensions of the image
if empty and not css background image it takes the preview dimensions for the images
============================================================================================= */
// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
die("You Cannot Access This Script Directly, Have a Nice Day."); }
// ----------------------------------------------------------------
if( strpos($content['all'], '{RAND_IMG_FROM_FOLDER:') !== FALSE ) {
function parse_imagesfromfolder($matches) {
// $matches[0] = {RAND_IMG_FROM_FOLDER:ID of Folder:CSS_CLASS:WxHxCROPxQUALITY ALT-Text}
// $matches[1] = ID of Folder
// $matches[2] = CSS_CLASS
// $matches[3] = WxHxCROPxQUALITY ALT-Text
if(isset($matches[1])) {
// Folder ID
$folder_id = intval($matches[1]);
// check for Alt-Text
$alt = explode(' ', $matches[3], 2); // WxHxCROPxQUALITY ALT-Text
// $alt[0] = WxHxCROPxQUALITY
// $alt[1] = ALT-Text
$value = explode('x', trim(strtolower($alt[0])));
$alttext = isset($alt[1]) ? trim($alt[1]) : '';
$alt = isset($alt[0]) ? html_specialchars(trim($alt[0])) : ''; // WxHxCROPxQUALITY
$width = isset($value[ 0 ]) ? intval($value[ 0 ]) : 0;
$height = isset($value[ 1 ]) ? intval($value[ 1 ]) : 0;
$crop = isset($value[ 2 ]) && intval($value[ 2 ]) === 1 ? 1 : 0;
$quality = isset($value[ 3 ]) ? intval($value[ 3 ]) : 0;
$sql = 'SELECT * FROM '.DB_PREPEND.'phpwcms_file WHERE f_aktiv=1 AND f_public=1 AND f_trash=0 AND f_pid='.$folder_id.' AND f_ext IN ("jpg", "png", "gif")';
$result = mysql_query($sql);
$i=0;
while($folderfile = mysql_fetch_array($result)) {
$folderfiles[$i] = $folderfile;
$i++;
}
$random = array_rand($folderfiles, 1);
$folderfile = $folderfiles[$random];
if(isset($folderfile['f_id']) ) {
// $thumb_info = @getimagesize(PHPWCMS_URL.PHPWCMS_FILES.$folderfile["f_hash"] . '.' . $folderfile["f_ext"]);
$thumb_info = @getimagesize(PHPWCMS_FILES.$folderfile["f_hash"] . '.' . $folderfile["f_ext"]);
(isset ($value[ 0 ])) ? $thumb_info[0] = $value[0] : $thumb_info[0] = $thumb_info[0];
(isset ($value[ 1 ])) ? $thumb_info[1] = $value[1] : $thumb_info[1] = $thumb_info[1];
$zoominfo = get_cached_image(
array( "target_ext" => $folderfile["f_ext"],
"image_name" => $folderfile["f_hash"] . '.' . $folderfile["f_ext"],
"max_width" => $thumb_info[0],
"max_height" => $thumb_info[1],
"thumb_name" => md5( $folderfile["f_hash"].$thumb_info[0].
$thumb_info[1].$GLOBALS['phpwcms']["sharpen_level"].$crop),
'crop_image' => $crop
)
);
$folderfile_path = PHPWCMS_IMAGES.$zoominfo[0];
} else {
$folderfile_path = '';
}
$folderfile_output = '';
if (isset ($matches[2]) && $matches[2] !== "") {
$folderfile_output .= '<style type="text/css">
<!--
'.$matches[2].' {
background-image: url(\''.$folderfile_path.'\');
}
//-->
</style>'.LF;
$GLOBALS['block']['custom_htmlhead']['randomimagefoldercss'] = $folderfile_output;
return;
} else {
$image = '<img src="'.PHPWCMS_URL.'img/cmsimage.php/'.$width.'x'.$height.'x'.$crop;
if($quality <= 100 && $quality >= 10) {
$image .= 'x'.$quality;
}
$image .= '/'.$folderfile['f_id'].'.'.$folderfile["f_ext"].'" alt="'.$alttext.'" border="0"';
/*
if(isset($matches[3])) {
$title = html_specialchars( preg_replace('/\s+/', ' ', clean_slweg( xss_clean( $matches[3] ) ) ) );
if($title !== '') {
$image .= ' title="'.$title.'"';
}
}*/
$image .= ' />';
$folderfile_output .= $image;
return $folderfile_output;
}
}
return '<img src="'.PHPWCMS_URL.'img/leer.gif" alt="" border="0" />';
}
$content["all"] = preg_replace_callback( '/\{RAND_IMG_FROM_FOLDER:(\d+):(.*?):(.*?)\}/i', 'parse_imagesfromfolder', $content["all"]);
} // end if
?>
wiki: Random Image from folderflip flop - feel free to add this to the wiki
Code: Select all
{RAND_IMG_FROM_FOLDER:ID of PHPWCMS Folder:CSS_CLASS or HTML tag:WxHxCROPxQUALITY ALT-Text}
Code: Select all
<?php
function parse_rt_test1($matches) { return dumpVar($matches); }
$content["all"] = preg_replace_callback( '/\{RT_TEST1:(\d+):(.*?)\}/i', 'parse_rt_test1', $content["all"]);
$content["all"] = preg_replace( '/\{RT_TEST2:(\d+):(.*?)\}/is', 'Erster Wert:$1 - zweiter Wert:$2', $content["all"]);
?>
Code: Select all
{RT_TEST1:23:Tolle Sache}
{RT_TEST2:23:Tolle Sache}
Code: Select all
Array
(
[0] => {RT_TEST1:23:Tolle Sache}
[1] => 23
[2] => Tolle Sache
)
Code: Select all
Erster Wert:23 - zweiter Wert:Tolle Sache