Offsite hosted Image resizing in e107 forums (Resolved)

e107 CMS » Forums » e107 v1.x Support » Core Code Support << Previous thread | Next thread >>
Go to page  1 2 3 ... 9 10 11
marj
Oct 27 2006, 09:18AM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6161
oh dear, I thought it was closed
yes it is possible,
just a question before to give a try:
do you want it in the same window?
Go to top
boedy
Oct 27 2006, 09:33AM
Registered Member #20343
Joined: Aug 23 2005, 06:30AM
Location: Delft, The Netherlands
Posts: 159
i think it would be better if would open in a new window. what do you think? maby you can use like an javascript that its fits the image
[ Edited Oct 27 2006, 09:33AM ]
Go to top
Website
marj
Oct 27 2006, 09:54AM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6161
boedy wrote ...

i think it would be better if would open in a new window. what do you think? maby you can use like an javascript that its fits the image

lol, you're my nightmare

I prefer to begin "simple" try that code in place of the other one
global $pref;
if (preg_match("#\.php\?.*#",$code_text)){return "";}
global $IMAGES_DIRECTORY, $FILES_DIRECTORY, $e107;
$search = array('"', '{E_IMAGE}', '{E_FILE}');
$replace = array('&#039;', $e107->base_path.$IMAGES_DIRECTORY, $e107->base_path.$FILES_DIRECTORY);
$code_text = str_replace($search, $replace, $code_text);
unset($imgParms);
$imgParms['class']="bbcode";
$imgParms['alt']='';
$imgParms['style']="vertical-align:middle; border:0";

$code_text = $tp -> toAttribute($code_text);

if($parm) {
$parm = preg_replace('#onerror *=#i','',$parm);
$parm = str_replace("amp;", "&", $parm);
parse_str($parm,$tmp);
foreach($tmp as $p => $v) {
$imgParms[$p]=$v;
}
}
$parmStr="";

foreach($imgParms as $k => $v) {
$parmStr .= $tp -> toAttribute($k)."='".$tp -> toAttribute($v)."' ";
}


if(file_exists(e_IMAGE."newspost_images/".$code_text))
{
$code_text = e_IMAGE."newspost_images/".$code_text;
}
// add
$resizeme = resizeme ($code_text);
$resizeme_prefix ='';
$resizeme_postfix='';
if ($resizeme != false) {
$resizeme_prefix .= "<a href='$code_text' rel='external'>";
$parmStr .= $resizeme;
$resizeme_postfix .= "</a>";
}
function resizeme ($code_text) {
$size = getimagesize($code_text);
if ($size !== false) {
$w = $size[0];
$h = $size[1];
$maxW = 595 ; // edited 595 in place of 100
if ($w > $maxW) {
$h = intval($h / ($w/$maxW));
$w = $maxW;
$parmStr .= " width='$w' height='$h'";
return $parmStr;
}
}
return false;
}
// end add

if (!$postID) {
return $resizeme_prefix."<img src='".$code_text."' {$parmStr} />".$resizeme_postfix; //add
} else {
if(strstr($postID,'class:')) {
$uc = substr($postID,6);
}
if ($pref['image_post']) {
if($uc == '') {
if (!function_exists('e107_userGetuserclass')) {
require_once(e_HANDLER.'user_func.php');
}
$uc = e107_userGetuserclass($postID);
}
if (check_class($pref['image_post_class'],$uc)) {
return $resizeme_prefix."<img src='".$code_text."' {$parmStr} />".$resizeme_postfix; // add
}
else
{
return ($pref['image_post_disabled_method'] ? "[ image disabled ]" : "Image: $code_text");
}
}
else
{
if ($pref['image_post_disabled_method']) {
return '[ image disabled ]';
} else {
return "Image: $code_text";
}
}
}


it's then just a bit of javascript if you need more
[ Edited Oct 27 2006, 01:44PM ]
Go to top
boedy
Oct 27 2006, 09:58AM
Registered Member #20343
Joined: Aug 23 2005, 06:30AM
Location: Delft, The Netherlands
Posts: 159
it doesn't work for me i get the following error

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in D:\Program Files\xampp\htdocs\e107\e107_handlers\bbcode_handler.php(190) : eval()'d code on line 8


lol, you're my nightmare


i heard before that I was a pain in the neck
Go to top
Website
marj
Oct 27 2006, 10:08AM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6161
it works fine for me, version .7.5 and last CVS..

I see you're under windows xampp, try to save the file in ANSI format.
Go to top
C6Dave
Oct 27 2006, 11:01AM
  • e107 Site administrator
  • e107 Support Team Leader
Registered Member #9506
Joined: Jul 31 2004, 12:57AM
Location: North East UK
Posts: 12342
Does something similar for me

I get:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRIN G, expecting ')' in /home3/rfastquo/ public_html/c4owners/ handlers/ bbcode_handler.php(190) : eval()'d code on line 40

Server info is:

Apache/1.3.36 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.27 OpenSSL/0.9.7a
(host: [-link-]

PHP Version
4.4.2

MySQL
4.1.18-standard
Database: ********

Charset
utf-8

Using latest CVS as of today
Go to top
Website
boedy
Oct 27 2006, 11:07AM
Registered Member #20343
Joined: Aug 23 2005, 06:30AM
Location: Delft, The Netherlands
Posts: 159
i tried it on my web server as well. here take a look: [-link-]

it doesn't work. maby the forum brakes up the code wrong?
[ Edited Oct 27 2006, 11:19AM ]
Go to top
Website
C6Dave
Oct 27 2006, 11:23AM
  • e107 Site administrator
  • e107 Support Team Leader
Registered Member #9506
Joined: Jul 31 2004, 12:57AM
Location: North East UK
Posts: 12342
Interesting that we both have a similar problem in the forums but you get it on line 8 of bbcode handler and I get it on line 40 boedy

My site uses e107_handlers bbcode_handler | $Revision: 1.46 $
Go to top
Website
boedy
Oct 27 2006, 11:28AM
Registered Member #20343
Joined: Aug 23 2005, 06:30AM
Location: Delft, The Netherlands
Posts: 159
this is my info

Server
Apache/2.0.53 (Unix)
(host: e107.creativemapping.nl)

PHP Version
5.1.4

MySQL
4.1.11-Debian_4sarge2-log
Database: *******

Charset
utf-8


i use bbcode_handler $Revision: 1.44 $

i wonder witch version bbcode_handler "marj" has
[ Edited Oct 27 2006, 11:32AM ]
Go to top
Website
marj
Oct 27 2006, 11:44AM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6161
I tried with both $Revision 1.41 v0.7.5 and $Revision 1.46 last CVS
and both are working, under news and forum

I'm testing under windows on
Server
Apache/1.3.33 (Win32)
(host: localhost)

PHP Version
4.3.10

MySQL
4.1.9-max

has I said above, I had to save in ANSI. I can't figure it out right now??? windows, old stuff, both...

here is a bugfix against function redifinition to put between // add and // end add
// add
if (!function_exists('resizeme')) {
function resizeme ($code_text) {
$size = getimagesize($code_text);
if ($size !== false) {
$w = $size[0];
$h = $size[1];
$maxW = 595; // change max width here
if ($w > $maxW) {
$h = intval($h / ($w/$maxW));
$w = $maxW;
$parmStr .= " width='$w' height='$h'";
return $parmStr;
}
}
return false;
}
}
$resizeme = resizeme ($code_text);
$resizeme_prefix ="";
$resizeme_postfix="";
if ($resizeme != false) {
$resizeme_prefix .= "<a href='$code_text' rel='external'>";
$parmStr .= $resizeme;
$resizeme_postfix .= "</a>";
}
// end add
Go to top
marj
Oct 27 2006, 11:57AM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6161
ok, I think I've got the problem. e107 code parsing. trying with the code above give an error for me too
I put the all file to make it clear, but it wasn't the good idea

line 5 replace ' by &_#039; edit: without underscore
$replace = array('&_#039;', $e107->base_path.$IMAGES_DIRECTORY, $e107->base_path.$FILES_DIRECTORY);

in other words, keep what you had there before
[ Edited Oct 27 2006, 11:58AM ]
Go to top
boedy
Oct 27 2006, 12:11PM
Registered Member #20343
Joined: Aug 23 2005, 06:30AM
Location: Delft, The Netherlands
Posts: 159
IT WORKS!!!!! YES!!!

Sorry for the post. when i was typing the post you already post a new reply. Thank you so much. This is what a really needed. You should definitely put this in the .7.6 update.

one again thanks again for all you help
[ Edited Oct 27 2006, 12:17PM ]
Go to top
Website
C6Dave
Oct 27 2006, 12:15PM
  • e107 Site administrator
  • e107 Support Team Leader
Registered Member #9506
Joined: Jul 31 2004, 12:57AM
Location: North East UK
Posts: 12342
Right I made the amendement above and here [-link-] if you look at the image of the red car it's resized down - right clicking and 'viewing image' gets the full size version but I think boedy wanted it so you could simply click the image and it would enlarge (yeah he wants it all!)

I know there is a bit of javascript out there [-link-] that will achieve this but it might be hard to intergrate as you have to give specific sizes which defeats the object

Thanks very much for the input so far marj


EDIT: boedy - it doesn't click and enlarge but 'right click' and 'view image' enlarges it
[ Edited Oct 27 2006, 12:17PM ]
Go to top
Website
marj
Oct 27 2006, 12:19PM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6161
to late, it works
[ Edited Oct 27 2006, 12:23PM ]
Go to top
boedy
Oct 27 2006, 12:20PM
Registered Member #20343
Joined: Aug 23 2005, 06:30AM
Location: Delft, The Netherlands
Posts: 159
2 dopey it does work with click! look at my site for example: [-link-]

just fill in this code in your img.bb file and your done:


global $pref;
if (preg_match("#\.php\?.*#",$code_text)){return "";}
global $IMAGES_DIRECTORY, $FILES_DIRECTORY, $e107;
$search = array('"', '{E_IMAGE}', '{E_FILE}');
$replace = array(''', $e107->base_path.$IMAGES_DIRECTORY, $e107->base_path.$FILES_DIRECTORY);
$code_text = str_replace($search, $replace, $code_text);
unset($imgParms);
$imgParms['class']="bbcode";
$imgParms['alt']='';
$imgParms['style']="vertical-align:middle; border:0";

$code_text = $tp -> toAttribute($code_text);

if($parm) {
$parm = preg_replace('#onerror *=#i','',$parm);
$parm = str_replace("amp;", "&", $parm);
parse_str($parm,$tmp);
foreach($tmp as $p => $v) {
$imgParms[$p]=$v;
}
}
$parmStr="";

foreach($imgParms as $k => $v) {
$parmStr .= $tp -> toAttribute($k)."='".$tp -> toAttribute($v)."' ";
}


if(file_exists(e_IMAGE."newspost_images/".$code_text))
{
$code_text = e_IMAGE."newspost_images/".$code_text;
}
// add
$resizeme = resizeme ($code_text);
$resizeme_prefix ='';
$resizeme_postfix='';
if ($resizeme != false) {
$resizeme_prefix .= "<a href='$code_text' rel='external'>";
$parmStr .= $resizeme;
$resizeme_postfix .= "</a>";
}
function resizeme ($code_text) {
$size = getimagesize($code_text);
if ($size !== false) {
$w = $size[0];
$h = $size[1];
$maxW = 350 ; // edited 595 in place of 100
if ($w > $maxW) {
$h = intval($h / ($w/$maxW));
$w = $maxW;
$parmStr .= " width='$w' height='$h'";
return $parmStr;
}
}
return false;
}
// end add

if (!$postID) {
return $resizeme_prefix."<img src='".$code_text."' {$parmStr} />".$resizeme_postfix; //add
} else {
if(strstr($postID,'class:')) {
$uc = substr($postID,6);
}
if ($pref['image_post']) {
if($uc == '') {
if (!function_exists('e107_userGetuserclass')) {
require_once(e_HANDLER.'user_func.php');
}
$uc = e107_userGetuserclass($postID);
}
if (check_class($pref['image_post_class'],$uc)) {
return $resizeme_prefix."<img src='".$code_text."' {$parmStr} />".$resizeme_postfix; // add
}
else
{
return ($pref['image_post_disabled_method'] ? "[ image disabled ]" : "Image: $code_text");
}
}
else
{
if ($pref['image_post_disabled_method']) {
return '[ image disabled ]';
} else {
return "Image: $code_text";
}
}
}
[ Edited Oct 28 2006, 06:21AM ]
Go to top
Website
C6Dave
Oct 27 2006, 12:22PM
  • e107 Site administrator
  • e107 Support Team Leader
Registered Member #9506
Joined: Jul 31 2004, 12:57AM
Location: North East UK
Posts: 12342
For anybody else following this boedy only posted the revised code section - the full file is 179 lines long

If we get it finalised I'll post a link so you download the full modified file
Go to top
Website
marj
Oct 27 2006, 12:26PM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6161
boedy wrote ...

2 dopey it does work with click! look at my site for example: [-link-]

just fill in this code in your img.bb file and your done:


that's it. it has to be cleaned a bit, but it's the idea
Go to top
boedy
Oct 27 2006, 12:30PM
Registered Member #20343
Joined: Aug 23 2005, 06:30AM
Location: Delft, The Netherlands
Posts: 159
but this only works for new posted images. how about images that already were in the forum?
Go to top
Website
marj
Oct 27 2006, 12:36PM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6161
boedy wrote ...

but this only works for new posted images. how about images that already were in the forum?

it works for all images surrounded by img bbcode, before or after you modify this one.
it is so called the bbcode magic
Go to top
C6Dave
Oct 27 2006, 12:39PM
  • e107 Site administrator
  • e107 Support Team Leader
Registered Member #9506
Joined: Jul 31 2004, 12:57AM
Location: North East UK
Posts: 12342
It doesn't work for me in Firefox or IE7 - it does on boedy's site

I deleted the image - saved the forum post

edited again and added it back in and re saved with no joy

Even creating a new post didn't work

Weird.
Go to top
Website
Go to page  1 2 3 ... 9 10 11  

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System