Page Index Toggle Pages: 1 2 [3] 4 5 
Topic Tools
Very Hot Topic (More than 25 Replies) Profile IM protocol names repeated, diff. icons (Read 18,611 times)
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
 
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 #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 #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 #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 #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
 
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
 
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 #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 #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 #40 - Jun 18th, 2009 at 10:28pm
Post Tools
LoneWebSurfer wrote on Jun 18th, 2009 at 8:58pm:
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.)

No, that was not the desired result.  If you put the code back to how it was before my changes, do the online/offline images show up even if they're not in the 2.1 image directory?

Edited:
Ah, I know why this is happening.  It's because the regexp isn't picking up the image URL, since it's buried within the AIM URL.  darn.  It's really not worth putting it into the regex because that specific URL format appears in exactly one place - the Profile page - and there's no need to slow the regex down with additional checks when we know it will appear only once.  Unless, of course, someone puts it in their signature or something.  darn!  But.....


OK, to cover this issue, if we don't want to add the aim_online and aim_offline images to each template directory, then the regexp can be modified as such:
Code
Select All
      if ($imagesdir ne $defaultimagesdir) {
            $output =~ s~(src|value|_url)\s*=\s*(['"]?)$imagesdir/([^'"&\s]+)\2~ "$1=$2" . &ImgLoc($3) . $2 ~eisg;
      } 


This modifies the regex by looking for an _url prefix in addition to src or value, it makes the quotation marks optional, and it disallows ampersands or whitespace in the image name (which should be fine, since technically neither of those are legal filename character within URLs anyway, and should always be url-encoded).

If we would rather keep the regexp "slimmer" as per the previous example, then I recommend putting the aim_*line.gif images into each template directory.  If we are OK using the slightly slower regexp above (it is still much faster than the 4 regexps used previously!), then we can omit the .gifs from the individual templates (unless someone wants to use different files in that template, of course).

Edited:
But, I don't think this is what we should do.  See below.
« Last Edit: Jun 19th, 2009 at 2:28am by cepheid »  
Back to top
WWW  
IP Logged
 
cepheid
Senior Member
****
Offline



Posts: 516
Re: Profile IM protocol names repeated, diff. icons
Reply #41 - Jun 18th, 2009 at 10:35pm
Post Tools
deti, I found a bug in the profile patch... in loading the AOL status image, I forgot to add the username to the URL.  I also omitted a $ from the URL.  D'oh!!

Edited:
Also, after thinking long and hard about this, I think the best solution is actually to enforce the AIM status icons to be only in $defaultimagesdir, and to not make them template-able.  The reason I say this is that the other status indicators (from ICQ, Skype, and Yahoo) are all served from external websites, and their style is hardcoded into Profile.pl ... there is no user preference to change the style, which means that it will show up just the same on every template.

Until/unless we implement a means for the other status indicators to be changeable by template, I think the AIM indicator should also be hardcoded.  This would not only be more consistent, it would keep the regex slimmer and faster, and would get rid of any question about where the images need to go.

Once we implement template-able styles for the Yahoo, ICQ, and Skype indicators, then the AIM indicator should be template-able, as well.


To that end, please make the following changes:
1) Please use the regexp as given in reply #35, i.e.
Code
Select All
      if ($imagesdir ne $defaultimagesdir) {
            $output =~ s~(src|value)\s*=\s*("|')$imagesdir/([^'"]+)\2~ "$1=$2" . &ImgLoc($3) . $2 ~eisg;
      } 



2) To fix the status indicator (both the bug and the directory issue), in Profile.pl, find:
Code
Select All
<a href="aim:goim?screenname=${$uid.$user}{'aim'}&amp;me
ssage=Hi,+are+you+there?"><img src="$imagesdir/aim.gif" alt="${$uid.$user}{'aim'
}" border="0" style="vertical-align: middle;" /> $aim_user <img src="http://big.
oscar.aol.com/?on_url=$imagesdir/aim_online.gif&amp;off_url=imagesdir/aim_offlin
e.gif" alt="${$uid.$user}{'aim'}" border="0" style="vertical-align: middle;" /><
/a> 



and replace with:
Code
Select All
<a href="aim:goim?screenname=${$uid.$user}{'aim'}&amp;me
ssage=Hi,+are+you+there?"><img src="$imagesdir/aim.gif" alt="${$uid.$user}{'aim'
}" border="0" style="vertical-align: middle;" /> $aim_user <img src="http://big.
oscar.aol.com/${$uid.$user}{'aim'}?on_url=$defaultimagesdir/aim_online.gif&amp;off_url=$defaultimagesdir/aim_offlin
e.gif" alt="${$uid.$user}{'aim'}" border="0" style="vertical-align: middle;" /><
/a> 

« Last Edit: Jun 19th, 2009 at 2:31am 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 #42 - Jun 19th, 2009 at 11:58am
Post Tools
@ cepheid
Thanks for your patches. I will test them tonight.
  

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 #43 - Jun 19th, 2009 at 8:34pm
Post Tools
deti wrote on Jun 19th, 2009 at 11:58am:
Thanks for your patches. I will test them tonight.

I presume you're using the latest ones that I mentioned above, right?  Plus the new ImgLoc code from before.  I do think those are the best way to go.  Let me know how it goes...
  
Back to top
WWW  
IP Logged
 
LoneWebSurfer
Past Team Members
Offline



Posts: 1,279
Re: Profile IM protocol names repeated, diff. icons
Reply #44 - Jun 19th, 2009 at 8:52pm
Post Tools
works for me on 2.1 template while images are in default image directory Smiley
I redid the aim_online/offline image to look more like the yim.. I think it looks nicer .. I included them here should you wish to use them.


  

Closed all my sites due to lack of Internet access
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1 2 [3] 4 5 
Topic Tools
 
  « Board Index ‹ Board  ^Top