Random logo with custom header file Random logo with custom header file
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Random logo with custom header file

Started by Ludo, February 09, 2008, 03:04:10 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ludo

Here's a little hack to display a random logo from a specific folder in your theme's directory (applies only to themes where it exists and contains images).
It's based on custom header file: if you already have set one, probably you won't be able to use this hack.
Basic HTML and CSS knowledge required.
Demo on my site http://vanrokken.altervista.org/
Any comment or suggestion appreciated.

OPEN
themes/your_theme/template.html

FIND
logo image "src" HTML attribute or "background"/"background-image" CSS property of the element containing the logo, e.g. in Classic theme:
<a href="index.php"><img src="themes/classic/images/site_logo.png" border="0" alt="" /></a><br />
in Project VII:
<div style="background-image:url(themes/project_vii/images/top_panel_r1_c1.jpg);background-repeat:no-repeat">

If you can't find any, probably the "background"/"background-image" property of the element containing the logo is set in the element class/id declaration in themes/your_theme/style.css, like in Connections theme:
#header {
        background: #FFF url(themes/connections/images/top.jpg) no-repeat bottom;
height: 183px;
margin: 0 auto;
width:760px;
padding:0;
border:#fc9 0px solid;
}



REPLACE
logo image "src" attribute or "background"/"background-image" url path with {CUSTOM_HEADER}, e.g.
<img src="{CUSTOM_HEADER}" border="0" alt="" />
<div style="background-image:url({CUSTOM_HEADER});background-repeat:no-repeat">
If "background"/"background-image" url path is set in style.css, you will have to delete or comment that property in CSS file and add an inline style to the element containing the logo, e.g.
<div id="header" style="background: #FFF url({CUSTOM_HEADER}) no-repeat bottom;">

DELETE
any other occurrence of {CUSTOM_HEADER} in the file, including elements containing it

SAVE AND CLOSE

COPY AND PASTE THE FOLLOWING CODE IN A NEW FILE AND SAVE IT AS
include/custom_header.php
<?php
// Custom header file for Coppermine Picture Gallery 1.4.x
// Allows to show a random logo from a logos folder
// created in your theme's directory
// (c) 2008 Gian Luigi Rocca (Ludo)
// support: http://forum.coppermine-gallery.net/index.php?topic=50365.0

// Change $deflogo to match your default logo's name
$deflogo 'top.jpg';

// Set $use_session to true if you want the logo to change on every 
// session instead on every page visited.
// If you don't have 'session.auto_start' set to 1 in your PHP 
// settings, to enable sessions you will have to add a line
// 'session_start();' at the end of your include/config.inc.php
$use_session false;

$imgdir 'themes/'.$CONFIG['theme'].'/images/';
$logodir $imgdir."logos/";
$logo $imgdir.$deflogo
if (
$dir  = @opendir($logodir)) {        
    while (
false !== ($file = @readdir($dir))) {
        if (
is_file($logodir.$file)) {
            
$files[] = $file;
        }
    }
    if (isset(
$files)) {
        
$i rand(0count($files)-1);
        
$logo $logodir.$files[$i];      
    } 
}
if (!
$use_session) {
   echo 
$logo;
} else {
   if (!isset(
$_SESSION['logo'])) $_SESSION['logo'] = $logo;         
   echo 
$_SESSION['logo'];
}
?>


Notes:
1) Change $deflogo to match your default logo's name
2) By default, logo changes on every page visited. If you'd like it to change on every session (so that every visitor gets the same logo until he closes browser), set $use_session to true. If you don't have 'session.auto_start' set to 1 in your PHP configuration file (check it from Admin Tools > phpinfo), to enable sessions you'll have to add a line
session_start();
at the end of your include/config.inc.php (just before ?>)

CREATE
a subfolder named 'logos' in themes/your theme/images and fulfill it with your logos

ENTER
'include/custom_header.php' in 'Path to custom header include' field under Configuration > Theme settings

SAVE AND ENJOY!

Qayyom

Hi I like the nice Idea and want to use for my site.

But i have not enough knowledge to edit easily and implement.

I am using Oranje theme. please do the favor and edit the codes here, with necessary instructions

here is my template.html file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html dir="{LANG_DIR}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset={CHARSET}" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Pragma" content="no-cache" />
<title>{TITLE}</title>
{META}
<link rel="stylesheet" href="themes/oranje/style.css" type="text/css" />
<script type="text/javascript" src="scripts.js"></script>
</head>
<body style="bodybody">
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0" style="background-image:url(themes/oranje/images/bg.gif);">
<tr>
<td width="760" valign="top" align="center">
{CUSTOM_HEADER}
</td>
</tr>
<tr><td height="1" align="center"><img src="themes/oranje/images/black_spacer.gif" width="758" height="1" border="0" alt="" /></td></tr>
<tr>
    <td width="760" valign="top" align="center"  style="padding-right:10px; background-repeat: no-repeat; background-position: center left; background-image:url(themes/oranje/images/logo.jpg);">
        <table cellpadding="0" cellspacing="3" border="0" width="100%"><tr>
<td align="right">
<h1><font color="#FFFFFF">{GAL_NAME}</font></h1>
<font color="#FFFFFF">{GAL_DESCRIPTION}</font><p>
<font color="#FFFFFF"><br />
</font>
</td></tr></table>
      </td>
  </tr>
<tr><td height="1" align="center"><img src="themes/oranje/images/black_spacer.gif" width="758" height="1" border="0" alt="" /></td></tr>

  <tr>
        <td width="760" valign="top" align="left">
            <table width="756" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
            <td valign="top" align="left" width="640">

{GALLERY}

  </td>
            <td valign="top" align="left" width="116" style="padding-top:15px;">
<div id="sidebar">

{SYS_MENU}<br/><br/> {SUB_MENU}<br/><br/>  {ADMIN_MENU}
<br /><br />{THEME_SELECT_LIST}<br /><br />
{LANGUAGE_SELECT_LIST}

</div>
</td>
              </tr>
            </table>
          <br />
    </td>
  </tr>
<tr><td height="1" align="center"><img src="themes/oranje/images/black_spacer.gif" width="758" height="1" border="0" alt="" /></td></tr>
  <tr>
    <td valign="bottom">
<div align="center">{LANGUAGE_SELECT_FLAGS}</div>
{CUSTOM_FOOTER}
{VANITY}
  </td>
  </tr>
<tr><td height="1" align="center"><img src="themes/oranje/images/black_spacer.gif" width="758" height="1" border="0" alt="" /></td></tr>
</table>
</body>
</html>


and here is [i think] only header related codes in style.css file, instead of complete file

#header {
padding: 0;
margin: 0 auto;
height: 200px;
width: 100%;
background-color: #73a0c5;
}

#headerimg {
margin: 0;
height: 200px;
width: 100%;
}


I'll be grateful for the help
Qayyom Ashraf .:|:. Karachi-PK
*Image Removed*

Ludo

In template.html:

FIND AND DELETE:
<tr>
<td width="760" valign="top" align="center">
{CUSTOM_HEADER}
</td>
</tr>


FIND:
    <td width="760" valign="top" align="center"  style="padding-right:10px; background-repeat: no-repeat; background-position: center left; background-image:url(themes/oranje/images/logo.jpg);">

REPLACE WITH:
    <td width="760" valign="top" align="center"  style="padding-right:10px; background-repeat: no-repeat; background-position: center left; background-image:url({CUSTOM_HEADER});">

SAVE AND CLOSE

That's it! ;)

Qayyom

Qayyom Ashraf .:|:. Karachi-PK
*Image Removed*

Jittery Jim

#4
Great mod, just what I was looking for. It's working with the Briarpatch theme, except for one problem. At the top of each page, right above the image, it lists the path and image name for which ever logo it is showing:

http://img.photobucket.com/albums/v158/jenloe_watches/z_pmwf/CoppermineError.jpg [Edit GauGau] Replaced hotlinked image with attachment as per Board rules / Forum policies: Add Attachments [/Edit]

It shows up whether logged in or not. I've checked all my edits and they match the instructions provided above.

Site url is http://watches.jitteryjim.com

Any suggestions or help would be appreciated.

Ludo

It seems like you didn't delete (all the) old occurrences of {CUSTOM_HEADER} token in your template.html

Jittery Jim

Quote from: Ludo on November 10, 2008, 06:57:51 PM
It seems like you didn't delete (all the) old occurrences of {CUSTOM_HEADER} token in your template.html

I knew it had to be something simple. Thanks, that fixed the problem!

Deus

Many thanks Ludo, works brilliantly.
I use mac_ox_x theme and it looks poor, so I tried to use it in an anycontent.php file without success.
I'm wondering what I need to do to make it work this way.

<center>
<img src="{CUSTOM_HEADER}" border="0" alt="" /><center>

I've also tried:
<center>
<img src="/include/{CUSTOM_HEADER}" border="0" alt="" /><center>

without any luck.
I'm not sure whats going wrong, I've moved the logos folder to the root of coppermine and the root of themes.
Thanks for any help I can get.
https://daz-stuff.uk
DJ tutorials, E-Bikes, Movies and videogames.
(https://daz-stuff.uk/daz/signature.png)

Ludo

logos folder must be in themes/mac_ox_x/images

To get this mod working with mac_ox_x theme follow these steps:

OPEN
themes/mac_ox_x/template.html (the original version)

FIND AND DELETE
<div id="CUSTOM_HEADER">
  {CUSTOM_HEADER}
</div>


FIND
<div class="top_panel">
  <div class="top_panel_r">


REPLACE WITH
<div class="top_panel" style="background-image: url({CUSTOM_HEADER})">
  <div class="top_panel_r" style="background-image: url({CUSTOM_HEADER})">



OPEN
themes/mac_ox_x/style.css

FIND AND DELETE OR COMMENT OUT
background-image: url(images/top_panel_r1_c1b.gif);

FIND AND DELETE OR COMMENT OUT
background-image: url(images/top_panel_r1_c2.jpg);


SAVE AND CLOSE ALL FILES

(Let me know if it works, I didn' test it ;) )

Deus

Thanks Ludo, I'll give it a go soon, and let you know.
Darron
https://daz-stuff.uk
DJ tutorials, E-Bikes, Movies and videogames.
(https://daz-stuff.uk/daz/signature.png)

Deus

themes/mac_ox_x/style.css

FIND AND DELETE OR COMMENT OUT
Code:

background-image: url(images/top_panel_r1_c1b.gif);


FIND AND DELETE OR COMMENT OUT
Code:

background-image: url(images/top_panel_r1_c2.jpg);



SAVE AND CLOSE ALL FILES

From what you are asking me to remove, I can see you are trying to get this working with OX_X theme.
I am trying to get it working in an anycontent block.
Also, I cannot delete those lines from the CSS as they dont exist.
What I'm tring to do it get a random image to replace Motorstom Pacific rift logo from here... my gallery
at the top of the page.
https://daz-stuff.uk
DJ tutorials, E-Bikes, Movies and videogames.
(https://daz-stuff.uk/daz/signature.png)

Ludo

Quote from: Deus on January 05, 2009, 07:47:30 PM
I am trying to get it working in an anycontent block.
This mod can't work in anycontent.php, because tokens get replaced in evaluating template file!

QuoteAlso, I cannot delete those lines from the CSS as they dont exist.
Lines 145 and 152.

Deus

I needed it to work in anycontent.
Thankyou for your time and patience Ludo, I shall find some html code that can work in there.
https://daz-stuff.uk
DJ tutorials, E-Bikes, Movies and videogames.
(https://daz-stuff.uk/daz/signature.png)

Ludo

#13
You can save my custom_header.php code above as your anycontent.php, adding this line
$logo = "<img src=\"$logo\" alt=\"logo\" />";

before
if (!$use_session) {

This will show a random image from the specified folder. Obviously you can add other code, or put the echoes wherever you want in the code itself.
If all images to show in anycontent.php have the same size, you'd better specify width and height attributes of <img> tag.

Deus

I'm loosing track of what edits are needed Ludo.
Any chance you could tell me whats needed for anycontent please.
https://daz-stuff.uk
DJ tutorials, E-Bikes, Movies and videogames.
(https://daz-stuff.uk/daz/signature.png)

Ludo

#15
Just save this code as your anycontent.php:
<?php
// Custom anycontent.php file for Coppermine Picture Gallery 1.4.x
// Allows to show a random image from a specified folder
// created in your theme's directory
// (c) 2009 Gian Luigi Rocca (Ludo)
// support: http://forum.coppermine-gallery.net/index.php?topic=50365.0

// Change $defany to match your default image name
$defany 'top.jpg';

// By default, images to show in anycontent.php are stored in themes/your_theme/images/anycontent
// If you have them stored elsewhere, change $imgdir and $anydir accordingly
$imgdir 'themes/'.$CONFIG['theme'].'/images/';
$anydir $imgdir."anycontent/";

$any $imgdir.$defany
if (
$dir  = @opendir($anydir)) {        
    while (
false !== ($file = @readdir($dir))) {
        if (
is_file($anydir.$file)) {
            
$files[] = $file;
        }
    }
    if (isset(
$files)) {
        
$i rand(0count($files)-1);
        
$any $anydir.$files[$i];      
    } 
}
$any "<img src=\"$any\" alt=\"image\" />";

// Your anycontent.php code
// By echoing $any you display a random image, e.g. 
// echo $any;

?>

Change $defany to your default image file name, and $anydir to the path where you have stored images to show, if different than default.
To display the random image anywhere you want in your anycontent.php code you just have to print $any variable.

Deus

#16
Thank you so much Ludo, it works brilliantly.
http://www.mess-hall.co.uk/gallery
It's the table just under friends.
I just need to get busy now with more logo's.


And now we have a random image in anycontent.php too.

Edit:
If I want to have a clickable link for each logo, taking you to the devolpers website, can I use a
$define or $link and logo=http://www.logo.com
$define or $link and logo=http://www.logo1.com
$define or $link and logo=http://www.logo2.com
$define or $link and logo=http://www.logo3.com

then output the link <a href='$link';

I'm not asking you to do this for me Ludo, just a pointer. I'm not sure about the define and output.

it's probably not the best place to ask, it's a coppermine forum after all and not a php forum.
https://daz-stuff.uk
DJ tutorials, E-Bikes, Movies and videogames.
(https://daz-stuff.uk/daz/signature.png)

Ludo

I'm not sure I've understood exactly what you mean, but the only way to place a link for each random image without storing it in the database is to put the url in the name of each image file, e.g.
www.logo1.com_img1.jpg
logo2.altervista.org_img2.jpg
and then get it using explode("_", $file) while scanning $anydir

Deus

forget I asked Ludo, I thought it might be a nice idea, but on reality, it's not necessary.
Some idea's seem good at the time, but this one is silly.
I thought it might be a good idea to place a link to a game developers site within each game logo, but if a user can't google it, why bother.

Edit:
At least no, as I said before, we have random logo header and random logo anycontent.


Many, Many thanks.
Darron
https://daz-stuff.uk
DJ tutorials, E-Bikes, Movies and videogames.
(https://daz-stuff.uk/daz/signature.png)

Deus

I'm sorry to pester you further Ludo, but how can I get this code to follow the theme rules?
It's not displaying correctly, ie, there's no definition for tableb so it's not displaying a white background or the black borders around the table.
I've added starttable("100%", " "); so it looks like the rest of the page, but it shows an off white background and not a white one.
I searched and tried everything I can to fix it myself. I either get T_String errors or parse errors if I format using HTML.
So how do I either 1, Get a white background, or 2, get it formatted to tableb as all the other anycontent files are?
??? ??? ??? :'(



<?php
// Custom anycontent.php file for Coppermine Picture Gallery 1.4.x
// Allows to show a random image from a specified folder
// created in your theme's directory
// (c) 2009 Gian Luigi Rocca (Ludo)
// support: http://forum.coppermine-gallery.net/index.php?topic=50365.0

// Change $defany to match your default image name
$defany 'logo.png';
if (!
defined('IN_COPPERMINE')) die('Not in Coppermine...');
starttable("100%"" ");

// By default, images to show in anycontent.php are stored in themes/your_theme/images/anycontent
// If you have them stored elsewhere, change $imgdir and $anydir accordingly
$imgdir 'themes/'.$CONFIG['theme'].'/images/';
$anydir $imgdir."logos/";

$any $imgdir.$defany
if (
$dir  = @opendir($anydir)) {        
    while (
false !== ($file = @readdir($dir))) {
        if (
is_file($anydir.$file)) {
            
$files[] = $file;
        }
    }
    if (isset(
$files)) {
        
$i rand(0count($files)-1);
        
$any $anydir.$files[$i];      
    } 
}
$any "<center><img src=\"$any\" alt=\"Lots of Logo's\" /></center>";

// Your anycontent.php code
// By echoing $any you display a random image, e.g. 
echo $any;
endtable();
?>



https://daz-stuff.uk
DJ tutorials, E-Bikes, Movies and videogames.
(https://daz-stuff.uk/daz/signature.png)