{IMAGE_SIZE} Define Image Size in RT

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
breitsch
Posts: 473
Joined: Sun 6. Mar 2005, 23:12
Location: bern switzerland

{IMAGE_SIZE} Define Image Size in RT

Post by breitsch »

Hi

I needed to define the size in my IMAGE replacement tags.
I did the following:

in the include/inc_front/front.func.inc.php

Code: Select all

find:
$replace[7]		= '<img src="picture/$1" border="0" alt="" />';

add after:	
// insert non db image sizable
$search[71]		= '/\{IMAGE_SIZE:(.*?):(.*?):(.*?)\}/';
$replace[71]		= '<img src="picture/$1" border="0" width="$2" height="$3" alt="" />';
that's all!

Use {IMAGE_SIZE:image/name:width:height}
Leave blank width or height will scale the image.

If you don't want to touch the core code:
Make a new file image_size.php in phpwcms_template/inc_script/frontend_render
Here the code would be:

Code: Select all

<?php
// insert non db image sizable
$replace = '<img src="picture/$1" border="0" width="$2" height="$3" alt="" />';
$content["all"] = preg_replace('/\{IMAGE_SIZE:(.*?):(.*?):(.*?)\}/', $replace, $content["all"]);
?>
------------------------------------------------------------------------------

The perfect one would be:
{IMAGE_FULL:image/name:border:width:height:alt}

Code: Select all

// insert non db image full control
$search[71]		= '/\{IMAGE_FULL:(.*?):(.*?):(.*?):(.*?):(.*?)\}/';
$replace[71]		= '<img src="picture/$1" border="$2" width="$3" height="$4" alt="$5" />';
there might be problems with border"" so you have to write the 0!
http://www.youtube.com/watch?v=jqxENMKaeCU
because it's important!
breitsch
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

I would be the first to encourage new {RT}'s but I would also be the first to encourage them being created in phpwcms_template/inc_script/frontend_render/*.inc.php too.

As a search/replace scanes the whole {CONTENT} the least times this is done the better so editing front.func.inc.php is the most efficient way of doing the job BUT with every new upgrade it is very likley you will be giving yourself far more work transfering them over to the new front.func.inc.php with the added possibility of error.

phpwcms_template/inc_script/frontend_render/ is the final pass {CONTENT} goes through before it is rendered.

By creating a my_tags.inc.php within the phpwcms_template/inc_script/frontend_render/ folder as a repository for all your new tags & unofficial tags from this forum too you will never worry about losing your tags again. you also have no chance of corrupting the core code and spending hours debugging a stray { or ; or some other error again :)

the default my_tags.inc.php would be...

Code: Select all

<?php
// My {RT}'s
// This is an altered version of a function found in include/inc_front/front.func.inc.php
	
	$content["all"] = (myTagParser ($content["all"]));// parse the whole webpage $content["all"] is the fully rendered webpage your site displays
	
	function myTagParser($string) {	// parse the $string and replace all possible instances of the following {RT}'s
		
	// Define new {RT}'s here....
	
	// The replacements are done here....
	$string = preg_replace($search, $replace, $string);
	$string = str_replace('\'', ''',$string);
	$string = str_replace('&quot;', '"',$string);
	return $string;// spit out the final webpage for display
	}
?>
The code with your new {RT}...

Code: Select all

<?php
// My {RT}'s
// This is an altered version of a function found in include/inc_front/front.func.inc.php
	
	$content["all"] = (myTagParser ($content["all"]));// parse the whole webpage $content["all"] is the fully rendered webpage your site displays
	
	function myTagParser($string) {	// parse the $string and replace all possible instances of the following {RT}'s
		
	// Define new {RT}'s here....
// place an image of given dimentions // usage: {IMAGE_SIZE:x,y}
	$search[0]      = '/\{IMAGE_SIZE:(.*?):(.*?):(.*?)\}/';
	$replace[0]      = '<img src="picture/$1" border="0" width="$2" height="$3" alt=""
	// Define new {RT}'s here....increase $search[n] & $replace[n] ;)

	// The replacements are done here....
	$string = preg_replace($search, $replace, $string);
	$string = str_replace('\'', ''',$string);
	$string = str_replace('&quot;', '"',$string);
	return $string;// spit out the final webpage for display
	}
?>
I am sure you understand the benefits of this method.
I am sure anyone hoping to create thier own {RT}'s would follow these hint's 'n' tips too.
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

I am sure you understand the benefits of this method.
I am sure anyone hoping to create thier own {RT}'s would follow these hint's 'n' tips too.
pSouper
would it be possible if you could add this info to the --...-- forum?

TriP
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hey pSouper,

very nice idea!!!
OG could put this in the next releases as a "feature" of phpwcms!
Instead of messing with the front.func.inc.

Very neat!! Love it

Thanks
Cheers
Post Reply