1
BradM
auto-replace block title with graphic
  • 2003/12/29 3:27

  • BradM

  • Just popping in

  • Posts: 78

  • Since: 2003/8/14


I've just been working on this hack tonight, and it seems to be working fine, so I thought I'd pass it along for others to try (and hopefully make it better!).

This hack, as I have it implemented, automatically replaces all of the titles in the center/center blocks with a corresponding graphic. If the graphic does not exist, it just prints out the block title in text format (ie. no broken image to worry about). All this really means is you can add fancy graphic titles to all of your center/center blocks without too much hassle.

For this to work, you need to modify header.php and theme_blockcenter_c.html.

header.php
Around line 185 you'll see this code:
case XOOPS_CENTERBLOCK_CENTER:

A few lines down from it, you'll see this:
$xoopsTpl->append('xoops_ccblocks', array('title' => $block_arr[$i]->getVar('title'), 'content' => $bcontent));


Just before the $xoopsTpl line, add this code:
// title hack
$imgttl $block_arr[$i]->getVar('title');
// replace spaces with underscores
$imgttl str_replace(" ""_"$imgttl);
// remove non-alphanumeric characters
$imgttl preg_replace("(W)"""$imgttl);
// convert to lower case
$imgttl mb_convert_case($imgttlMB_CASE_LOWER"UTF-8");
// append image format
$imgttl $imgttl.".gif";
// build paths
$imgpath XOOPS_ROOT_PATH.'/images/'.$imgttl;
$imgurl XOOPS_URL.'/images/'.$imgttl;
// check for file
if (file_exists($imgpath)) {
    
$ttl_img $imgurl;
}
else { 
$ttl_img ""; }


Next, change the $xoopsTpl line to this:
$xoopsTpl->append('xoops_ccblocks', array('title' => $block_arr[$i]->getVar('title'), 'content' => $bcontent'ttl_img' => $ttl_img));


theme_blockcenter_c.html
Change this code:
<{$block.title}>

To this:
<{if $block.ttl_img}>
<
img src="<{$block.ttl_img}>" alt="<{$block.title}>" title="<{$block.title}>">
<{else}>
<{
$block.title}>
<{/if}>


After making these changes, you shouldn't see any difference in your center/center blocks unless you upload graphics into your XOOPS "/images" folder.

Make sure you change $imgttl = $imgttl.".gif"; to match the extension of the images you will be uploading (eg: .png or .jpg).

The graphic names should all be lower case, and have spaces replaced with underscores. Examples:

Block Title: What's New
Corresponding Graphic: whats_new.gif

Block Title: Recent Discussions
Corresponding Graphic: recent_discussions.gif

Block Title: News!!!!
Corresponding Graphic: news.gif

Block Title: tHe gNU PrOjeCT
Corresponding Graphic: the_gnu_project.gif


Brad

2
CBlue
Re: auto-replace block title with graphic

Cool! Thanks Brad!

3
BradM
Re: auto-replace block title with graphic
  • 2003/12/29 4:31

  • BradM

  • Just popping in

  • Posts: 78

  • Since: 2003/8/14


Here's a quick example of a guest-only block that lists the benefits of membership. The "Join Today!" block title has been replaced by the "join_today.gif" graphic file.

Resized Image



Brad

4
Bazus
Re: auto-replace block title with graphic
  • 2004/1/6 4:30

  • Bazus

  • Not too shy to talk

  • Posts: 144

  • Since: 2002/9/23


does n1 knows a place to find 'block graphics' (gif,jpg) for this hack?

that would be of great help

5
shivaji
Re: auto-replace block title with graphic
  • 2004/1/6 8:21

  • shivaji

  • Friend of XOOPS

  • Posts: 179

  • Since: 2003/9/18


Ya It's working perfectly. I use this code for left and right block also.

Thank you Brad for your support.

6
WarDick
Re: auto-replace block title with graphic
  • 2004/1/7 7:21

  • WarDick

  • Just can't stay away

  • Posts: 890

  • Since: 2003/9/13


I need some help with this hack.

This line causes a blank screen.
$imgttl = mb_convert_case($imgttl, MB_CASE_LOWER, "UTF-8");

Any ideas?

7
BradM
Re: auto-replace block title with graphic
  • 2004/1/8 6:06

  • BradM

  • Just popping in

  • Posts: 78

  • Since: 2003/8/14


Quote:
This line causes a blank screen.
$imgttl = mb_convert_case($imgttl, MB_CASE_LOWER, "UTF-8");


Yikes I wish I knew. I'm really new to php coding, so I was basically following some code examples I found at php.net.

Does that line of code appear all on one line? Sometimes if there's a line break it can mess things up.

Also, the website does mention that the command mb_convert_case requires PHP v4.3.0 or greater. Maybe you aren't running this version?

I'm not sure if you can check your php version via Xoops, however if you are running the IPB Forum module, it tells you the php version on the main page (for example, I'm running 4.3.3).


Brad


8
BradM
Re: auto-replace block title with graphic
  • 2004/1/8 6:27

  • BradM

  • Just popping in

  • Posts: 78

  • Since: 2003/8/14


Quote:
does n1 knows a place to find 'block graphics' (gif,jpg) for this hack?


I could swear that about a year or so ago I came across a site that generated instant title graphics. All you had to do was enter the text, pick a font, and it created a button or something (I think).

Of course, no matter what I tried in Google, nothing came up, so I'm afraid I'm not being very helpful here.


Brad

9
BradM
Re: auto-replace block title with graphic
  • 2004/1/10 2:21

  • BradM

  • Just popping in

  • Posts: 78

  • Since: 2003/8/14


I'm trying to figure out a way to make these titles theme-specific. I'm not sure how <{$xoops_imageurl}> (usually embedded in HTML) can translate into something usable in PHP code.

Also, is there a path equivalent to $xoops_imageurl?


Brad

10
CBlue
Re: auto-replace block title with graphic

There are two sites that I know of where you can create text gifs.http://www.gifworks.com andhttp://www.flamingtext.com. I use both of these to create cool looking text graphics.

Login

Who's Online

130 user(s) are online (102 user(s) are browsing Support Forums)


Members: 0


Guests: 130


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits