Page Index Toggle Pages: 1 2 [3] 4 5 
Topic Tools
 25 Profile IM protocol names repeated, diff. icons (Read 18,046 times)
LoneWebSurfer
Past Team Members
Offline



Posts: 1,279
Re: Profile IM protocol names repeated, diff. icons
Reply #39 - Jun 18th, 2009 at 8:58pm
Post Tools
ahh.. was using default.. but can fix that real quick lol.

Edited:
2.1 template the aim online/offline image shows.. but only if it is in the 2.1 image directory..( said that as im not sure if this was the desired result.)
« Last Edit: Jun 18th, 2009 at 9:08pm by LoneWebSurfer »  

Closed all my sites due to lack of Internet access
Back to top
WWW  
IP Logged
 
cepheid
Senior Member
****
Offline



Posts: 516
Re: Profile IM protocol names repeated, diff. icons
Reply #38 - Jun 18th, 2009 at 8:55pm
Post Tools
LoneWebSurfer wrote on Jun 18th, 2009 at 8:52pm:
all the IM images show up nicely

I presume you were using a non-default template, e.g. the yabb21 template, right?  The changes only affect non-default templates.

Thanks for checking! Smiley
  
Back to top
WWW  
IP Logged
 
LoneWebSurfer
Past Team Members
Offline



Posts: 1,279
Re: Profile IM protocol names repeated, diff. icons
Reply #37 - Jun 18th, 2009 at 8:52pm
Post Tools
I emplimented those changes Cepheid, while i dont have an accurate way of benchmarking speed on my shared host ( it varies with each load) all the IM images show up nicely.. yim and aim(only two i tested) show online offline as they should. cant really give any more feedback than that as i dont know perl... but it does work Smiley and it was fun figuring out where to put that  Grin Grin
  

Closed all my sites due to lack of Internet access
Back to top
WWW  
IP Logged
 
cepheid
Senior Member
****
Offline



Posts: 516
Re: Profile IM protocol names repeated, diff. icons
Reply #36 - Jun 18th, 2009 at 12:45am
Post Tools
Also, I've revised the ImgLoc code.  Instead of what you put earlier, I suggest the following:
Code
Select All
my %img_locs;
sub ImgLoc {
      if (exists $img_locs{$_[0]}) {
            return $img_locs{$_[0]};
      } elsif (-e "$imagesdir/$_[0]") {
            return $img_locs{$_[0]} = qq~$imagesdir/$_[0]~;
      } else {
            return $img_locs{$_[0]} = qq~$defaultimagesdir/$_[0]~;
      }
} 


The reasons I think this is better are:
1) Using a flag to check whether the file has been processed still requires us to reconstruct the location each time.  Instead, we can simply check if the location has been constructed (and hence if the field exists in the hash).

2) For speed optimization in if-else blocks, the most likely possibility should always be first, so that the match occurs as early as possible.  Since templated images are repeated very often throughout the page but are processed only once, you will get only one negative hit but many positive hits, so the positive outcome should be first.

3) The return statements should be there so that the routine exits as soon as possible, rather than having to process (albeit skip) the rest of the lines.  Formatting them in this way also allows us to store the image location and return all in one line.

This revised code should minimize the processor cycles used for determining image locations.
  
Back to top
WWW  
IP Logged
 
cepheid
Senior Member
****
Offline



Posts: 516
Re: Profile IM protocol names repeated, diff. icons
Reply #35 - Jun 18th, 2009 at 12:12am
Post Tools
deti, I've looked at the regexps and have condensed the 4 lines into just one.  The new code should function identically, but faster and more reliably.

Replace:
Code
Select All
      if ($imagesdir ne $defaultimagesdir) {
            $output =~ s~img src=("|')$imagesdir/(.+?)('|")~ "img src=$1" . &ImgLoc($2) . $3 ~eisg;
            $output =~ s~.src='$imagesdir/(.+?)'~ ".src='" . &ImgLoc($1) . "'" ~eisg; # For Javascript generated images
            $output =~ s~input type="image" src="$imagesdir/(.+?)"~ 'input type="image" src="' . &ImgLoc($1) . '"' ~eisg; # For input images
            $output =~ s~option value="$imagesdir/(.+?)"~ 'option value="' . &ImgLoc($1) . '"' ~eisg; # For the post page
      } 



with:
Code
Select All
      if ($imagesdir ne $defaultimagesdir) {
            $output =~ s~(src|value)\s*=\s*("|')$imagesdir/([^'"]+)\2~ "$1=$2" . &ImgLoc($3) . $2 ~eisg;
      } 


That single regexp handles all 4 cases.  The improvements are as follows:
1) There is no reason to segregate the cases based on what precedes the "src" attribute.  If there is any HTML tag with a src=$imagesdir* attribute, it should be checked... since they all follow the same syntax, there's no reason to do them individually.

2) There's no reason to force the specific quotation types, when it's easy to check both (as was done in the first example).  It's also easy to ensure that the match stops only when using a matching close-quote (which was not done in the first example, and should have been; it is achieved here by using a backreference).

3) Since there is no reason that a quotation mark should ever appear in the URL (it should be URL-encoded if needed), it is faster to use a negated character class to match the image URL rather than using the lazy plus (+?) which forces the regexp engine to backtrack and hence process every URL character twice.

4) For proper matching in all cases, I inserted (\s*) around the = sign because it's still valid HTML and someone updating the code in the future may insert spaces around the = sign.  This doesn't improve speed, but does improve reliability.

Using the one-line regexp given above should provide exactly the same output but with significantly fewer CPU cycles, and improved reliability of matching.

My testing indicates that this should work, but if you could double-check on your end, that'd be great.
  
Back to top
WWW  
IP Logged
 
deti
Legacy Dev Team
Development Team
****
Offline



Posts: 2,650
Location: Prien am Chiemsee, Germany
Re: Profile IM protocol names repeated, diff. icons
Reply #34 - Jun 15th, 2009 at 8:07am
Post Tools
cepheid wrote on Jun 15th, 2009 at 2:40am:
That's certainly some savings.  But, did you forget the "return" statement?  I don't see it there.

Read this:
Quote:
- return EXPR
- return

Returns from a subroutine, eval, or do FILE with the value given in EXPR. Evaluation of EXPR may be in list, scalar, or void context, depending on how the return value will be used, and the context may vary from one execution to the next (see wantarray). If no EXPR is given, returns an empty list in list context, the undefined value in scalar context, and (of course) nothing at all in a void context.

(Note that in the absence of an explicit return, a subroutine, eval, or do FILE will automatically return the value of the last expression evaluated.)
Out of: http://perldoc.perl.org/functions/return.html


cepheid wrote on Jun 15th, 2009 at 2:40am:
I'll work on this later tonight.

Every help is appreciated!


cepheid wrote on Jun 15th, 2009 at 2:40am:
Finally, why are you using "$forumstylesdir/$useimages/" and "$forumstylesurl/default/" instead of just "$imagesdir" and "$defaultimagesdir" ?  IMHO it's confusing to use both when they should mean the same thing, no?

Tanks you are right. I just overtook it from what was there and didn't think more about it. Cheesy Smiley
  

Was immer Du tun kannst
oder erträumst tun zu können,
beginne es.
Kühnheit besitzt Genie,
Macht und magische Kraft.
Beginne es jetzt.
Whatever you can do
or dream you can,
begin it.
Boldness has genius,
power and magic in it.
Begin it now.
J. W. Goethe
Back to top
WWW  
IP Logged
 
cepheid
Senior Member
****
Offline



Posts: 516
Re: Profile IM protocol names repeated, diff. icons
Reply #33 - Jun 15th, 2009 at 2:40am
Post Tools
deti wrote on Jun 15th, 2009 at 2:13am:
So at least it has not to check each file multiple times with -e(...).

That's certainly some savings.  But, did you forget the "return" statement?  I don't see it there.

Looking at the replacement code, this can actually be condensed into only one or two passes instead of 4, because some of the regexps are more specific than they need to be and could really be consolidated.  I'll work on this later tonight.  Also, it might be done somewhat faster by using an 'if' statement with m/ instead of the current s/ operator.

Finally, why are you using "$forumstylesdir/$useimages/" and "$forumstylesurl/default/" instead of just "$imagesdir" and "$defaultimagesdir" ?  IMHO it's confusing to use both when they should mean the same thing, no?
  
Back to top
WWW  
IP Logged
 
deti
Legacy Dev Team
Development Team
****
Offline



Posts: 2,650
Location: Prien am Chiemsee, Germany
Re: Profile IM protocol names repeated, diff. icons
Reply #32 - Jun 15th, 2009 at 2:13am
Post Tools
cepheid wrote on Jun 15th, 2009 at 1:57am:
Of course, in the meantime, this means you can remove the aim_*.gif files from the yabb21 template.

Done.

cepheid wrote on Jun 15th, 2009 at 1:57am:
Yes, but you have only two alternatives:

For the moment I did it this way:
Code
Select All
my %img_check;
sub ImgLoc {
	unless (exists $img_check{$_[0]}) {
		if (-e "$forumstylesdir/$useimages/$_[0]") {
			$img_check{$_[0]} = 1;
			qq~$imagesdir/$_[0]~;
		} else {
			$img_check{$_[0]} = 0;
			qq~$forumstylesurl/default/$_[0]~;
		}
	} else {
		$img_check{$_[0]} == 1 ? qq~$imagesdir/$_[0]~ : qq~$forumstylesurl/default/$_[0]~;
	}
} 


So at least it has not to check each file multiple times with -e(...).
  

Was immer Du tun kannst
oder erträumst tun zu können,
beginne es.
Kühnheit besitzt Genie,
Macht und magische Kraft.
Beginne es jetzt.
Whatever you can do
or dream you can,
begin it.
Boldness has genius,
power and magic in it.
Begin it now.
J. W. Goethe
Back to top
WWW  
IP Logged
 
cepheid
Senior Member
****
Offline



Posts: 516
Re: Profile IM protocol names repeated, diff. icons
Reply #31 - Jun 15th, 2009 at 1:57am
Post Tools
deti wrote on Jun 15th, 2009 at 12:49am:
Isn't this a huge work on every page of a non default template, checking all output 4 times just in case the admin forgot to add the image in the folder???

Yes, but you have only two alternatives:

1) Don't do any checking, which means that any template-able image (that uses $imagesdir insteadof $defaultimagesdir) absolutely must be present in the image folder; this could lead to a lot of duplicated storage if the forum allows a lot of template-able images... or

2) Change the way that the substitution is done to operate on a list of known differences instead of checking each and every image load.  This would still require some substitution but it would hopefully be less.  The way to implement this would be to make every image start with $defaultimagesdir, then, if $imagesdir ne $defaultimagesdir, to get the filelist in $imagesdir, and then do a search-and-replace only for the files in $imagesdir.  That way every file in $imagesdir is represented and those not there already defaulted to $defaultimagesdir.

Option 2 would require more coding changes, but should reduce processing (not entirely, but somewhat).

Option #1 is by far the easiest and certainly reduces processing time, but could increase duplicated storage if there are a lot of template-able images, plus it's less "idiot-proof."

Not sure which way I'd prefer, really...

Of course, in the meantime, this means you can remove the aim_*.gif files from the yabb21 template. Wink
« Last Edit: Jun 15th, 2009 at 1:57am by cepheid »  
Back to top
WWW  
IP Logged
 
deti
Legacy Dev Team
Development Team
****
Offline



Posts: 2,650
Location: Prien am Chiemsee, Germany
Re: Profile IM protocol names repeated, diff. icons
Reply #30 - Jun 15th, 2009 at 12:49am
Post Tools
You are right YaBB looks for all images if they are present in the folder. If not, the URL is modified to 'default'
Code
Select All
	if ($imagesdir ne $defaultimagesdir) {
		$output =~ s~img src=("|')$imagesdir/(.+?)('|")~ "img src=$1" . &ImgLoc($2) . $3 ~eisg;
		$output =~ s~\.src='$imagesdir/(.+?)'~ ".src='" . &ImgLoc($1) . "'" ~eisg; # For Javascript generated images
		$output =~ s~input type="image" src="$imagesdir/(.+?)"~ 'input type="image" src="' . &ImgLoc($1) . '"' ~eisg; # For input images
		$output =~ s~option value="$imagesdir/(.+?)"~ 'option value="' . &ImgLoc($1) . '"' ~eisg; # For the post page
	}

...


sub ImgLoc {
	return (!-e "$forumstylesdir/$useimages/$_[0]" ? qq~$forumstylesurl/default/$_[0]~ : qq~$imagesdir/$_[0]~);
} 



Isn't this a huge work on every page of a non default template, checking all output 4 times just in case the admin forgot to add the image in the folder???
« Last Edit: Jun 15th, 2009 at 12:50am by deti »  

Was immer Du tun kannst
oder erträumst tun zu können,
beginne es.
Kühnheit besitzt Genie,
Macht und magische Kraft.
Beginne es jetzt.
Whatever you can do
or dream you can,
begin it.
Boldness has genius,
power and magic in it.
Begin it now.
J. W. Goethe
Back to top
WWW  
IP Logged
 
deti
Legacy Dev Team
Development Team
****
Offline



Posts: 2,650
Location: Prien am Chiemsee, Germany
Re: Profile IM protocol names repeated, diff. icons
Reply #29 - Jun 15th, 2009 at 12:33am
Post Tools
Hmmmm, wait a minute. I'm a bit confused because the images are displayed in yabb21 template mode, but they are not in that folder... Shocked
  

Was immer Du tun kannst
oder erträumst tun zu können,
beginne es.
Kühnheit besitzt Genie,
Macht und magische Kraft.
Beginne es jetzt.
Whatever you can do
or dream you can,
begin it.
Boldness has genius,
power and magic in it.
Begin it now.
J. W. Goethe
Back to top
WWW  
IP Logged
 
cepheid
Senior Member
****
Offline



Posts: 516
Re: Profile IM protocol names repeated, diff. icons
Reply #28 - Jun 15th, 2009 at 12:25am
Post Tools
deti wrote on Jun 15th, 2009 at 12:13am:
In cases you don't expect users using an individual template image you must use $defaultimagesdir.

Ohhhh.  In that case, I should submit another patch, because all of the static icons should be called from $defaultimagesdir - they are not present in the yabb21 template.  Look for that patch later tonight, unless you get around to doing it first.
  
Back to top
WWW  
IP Logged
 
deti
Legacy Dev Team
Development Team
****
Offline



Posts: 2,650
Location: Prien am Chiemsee, Germany
Re: Profile IM protocol names repeated, diff. icons
Reply #27 - Jun 15th, 2009 at 12:13am
Post Tools
cepheid wrote on Jun 15th, 2009 at 12:06am:
... and YaBB defaults to looking in the default directory when it can't find them in the regular dir, right?

No.
$imagesdir is always the chosen template dir. In cases you don't expect users using an individual template image you must use $defaultimagesdir.
  

Was immer Du tun kannst
oder erträumst tun zu können,
beginne es.
Kühnheit besitzt Genie,
Macht und magische Kraft.
Beginne es jetzt.
Whatever you can do
or dream you can,
begin it.
Boldness has genius,
power and magic in it.
Begin it now.
J. W. Goethe
Back to top
WWW  
IP Logged
 
cepheid
Senior Member
****
Offline



Posts: 516
Re: Profile IM protocol names repeated, diff. icons
Reply #26 - Jun 15th, 2009 at 12:06am
Post Tools
deti, I don't think the aim_online.gif and aim_offline.gif need to be in the yabb21 template directory... none of the other static icon files are there, and YaBB defaults to looking in the default directory when it can't find them in the regular dir, right?  So only images which are different between the two forums should be there, and it should be safe to remove the aim_*.gif files from the yabb21 dir, I think...
  
Back to top
WWW  
IP Logged
 
deti
Legacy Dev Team
Development Team
****
Offline



Posts: 2,650
Location: Prien am Chiemsee, Germany
Re: Profile IM protocol names repeated, diff. icons
Reply #25 - Jun 14th, 2009 at 11:51pm
Post Tools
Thank you!

Added to SVN.
  

Was immer Du tun kannst
oder erträumst tun zu können,
beginne es.
Kühnheit besitzt Genie,
Macht und magische Kraft.
Beginne es jetzt.
Whatever you can do
or dream you can,
begin it.
Boldness has genius,
power and magic in it.
Begin it now.
J. W. Goethe
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1 2 [3] 4 5 
Topic Tools
 
  « Board Index ‹ Board  ^Top