Gossamer Forum
Quote Reply
Editor tag replacement
Note:
---------------------------------------------------------------------------------------------------Ok, my aim is NOT to repost threads, but I just want to isolate this one aspect from the suggested Editor Monitor Pluging, since this is essentially not monitor but a replacement/enhancement to the existing <%editors%> tag place on pages which have editors assigned to them.

See Editor Monitor Plugin at: http://www.gossamer-threads.com/...orum.cgi?post=195385
---------------------------------------------------------------------------------------------------

I think the way the editors are presented at the bottom of each page could be improved upon. Example from DMOZ:

Category editors: andylehrer, artson, dlugan, funk, inge, indianpipe, tania


I'd like to kick this one off, please feel free to join in and help if you are also interested in this (or you just want to helpWink).

The best thing I think, is just to make a new tag to replace the <%editors%> tag to produce the above output.

1. Finding which editor belongs to this category

I guess the tag needs to know somehow which category is being built at that instant... how I dont know. Lets say it is equal to $category_id. Just use SQL to search the editors table for all the editors where (CategoryID = $category_id) and add it to an array @editors. (push, pop I am not sure).

2. Hyperlinking

I keep my editors profiles in mysite.com/editors/profiles/editoralias.html so the hyperlink could automatically be produced: buildpath/editors/profiles/[Username].html. Just go through the array @editors and produce the hyperlink from this.

Simple??

Of course, the ultimate would be to have dynamically produced profile pages... but the above would be a great start. Maybe this could be my 2nd plugin attempt (with your helpWink), but I think the above could be solved with a simple global.



Code:


#I have a condition on <%editors%> at them moment, where if there are no editors
# I have a hyperlink "Become an Editor" which goes to my signup form.
# So i don't think this tag needs to take this into account


my $i;
my $output = "Editors: ";

for ($i = 0; $i< scaler @editors; $i++) {
if ($i>0) {$output .= qq~,~; } #add a comma
$output .= qq~<a href="$CFG->{build_root_url}"/editors/profiles/$editor.html">$editor</a>~;
}
Its a start.


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

sooke: May 16, 2002, 4:07 PM
Quote Reply
Re: [sooke] Editor tag replacement In reply to
This is what I have so far:

sub editorlinks {

# I have a condition on <%editors%> at them moment, where if there are no editors
# I have a hyperlink "Become an Editor" which goes to my signup form.
# So i don't think this tag needs to take this into account

my $tags = shift;
my $editor_db = $DB->table('Editors');

my @editors = $editor_db->select (['Username'], { CategoryID => $category_id })->fetchall_list;

my $i;
my $output = "Editors: ";

for ($i = 0; $i< scaler @editors; $i++) {
if ($i>0) {$output .= qq~,~; } #add a comma
$output .= qq~<a href="$CFG->{build_root_url}/editors/profiles/$editor.html">$editor</a>~;
}
return $output;
}




I am sure this is loaded with mistakes.... and I am not sure how to load the $category_id scaler with the correct category ID which is being built.... anyone??


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

sooke: May 16, 2002, 5:29 PM
Quote Reply
Re: [sooke] Editor tag replacement In reply to
Still having no luck.

When I place this tag <%editorlinks%> into my category.html I get a printed of the entire sub on the page! "sub {blah blah..}"

This is the code I have:

Code:


sub {

# I have a condition on <%editors%> at them moment, where if there are no editors
# I have a hyperlink "Become an Editor" which goes to my signup form.
# So i don't think this tag needs to take this into account

my $tags = shift;
my $editor_db = $DB->table('Editors');
my $category_id = $tags->('ID')

my @editors = $editor_db->select (['Username'], { CategoryID => $category_id })->fetchall_list;

my $i;
my $output = "Editors: ";

for ($i = 0; $i< scalar @editors; $i++) {
if ($i>0) {$output .= qq~,~; } #add a comma
$output .= qq~<a href="$CFG->{build_root_url}/editors/profiles/$editor.html">$editor</a>~;
}
return $output;
}


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [sooke] Editor tag replacement In reply to
Just a bug:
my $category_id = $tags->('ID');

Are you sure the tags are not hashref?
This case you have to use:
$tags->{'ID'} instead of $tags->('ID')

I did not check further. Just my 2 cents.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [sooke] Editor tag replacement In reply to
I believe that it is the first line. Try removing one of the spaces. For some reason there is a bug with the globals system. Putting sub { (i.e with 2 spaces) will cause it to just print...but with one space, it should work ok Wink

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy.] Editor tag replacement In reply to
Hey thanks both!

Webmaster, I beleive your right should be tags->{ }; Thanks for pointing this out. Still being new, I check over my code, and still find it difficult to spot errors, especially since it is not perlchecked when it is not part of a plugin.

Andy: The spaces thing explains a lot! Is this some kind of bug... I think it should be announced in the bug section perhaps... I would have never guessed this. Thanks!

I will try this again nowSmile


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [sooke] Editor tag replacement In reply to
Quote:
Andy: The spaces thing explains a lot! Is this some kind of bug... I think it should be announced in the bug section perhaps... I would have never guessed this. Thanks!

No prob. I'm not sure if it is a bug...but I think Alex knows about it.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy.] Editor tag replacement In reply to
Its working now!

I found a few more errors in my code. Amazing when you are fresh, and its not 2 am!! Not to mention the great help around here.

I am going to including this code into my editormonitor plugin now.


EDIT:

A NOTE ABOUT THIS GLOBAL
*****************************************************************************
This global will only show the editor as being assigned to the top level category they are assigned and not all of the sub-categories they own, due to the nature of the Editors table.

If anyone knows how to correct this, the please share this with me!!!!!!!!!!!!!*****************************************************************************




http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

sooke: May 20, 2002, 10:06 AM
Quote Reply
Re: [sooke] Editor tag replacement In reply to
Glad to hear...I see your really getting the hang of this plugin/global stuff now Smile Wish I only had more time to look into it all :(

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [sooke] Editor tag replacement In reply to
Maybe someone from GT staff (Alex) could give me a little insight on how the <%editors%> tag knows how to associate an editor with a category during a build? I currently just have the tag showing the top level the editor is assigned to, see above global (any errors I could find corrected since posting this).

Crazy


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [sooke] Editor tag replacement In reply to
I can see this would work if:

my @editors = $editor_db->select (['Username'], { CategoryID => $category_id })->fetchall_list;

actually said "if CategoryID => $category_id OR CategoryID is a subcategory of $category_id";

eeek... here we go again.

I have this:




Code:


sub issubcategory {

my $cat_db = $DB->table('Category');
my $currentcat = shift; #category to test
my $parentcat = shift; #parent category for test
my $tempcat1 = $currentcat; #temporary placeholder for category ID
my $tempcat2 = $parentcat;
my $count = 0;
my $outcome = 0; # 0-false 1-true
if ($currentcat == $parentcat) {
$outcome=0; #if they are the same then return false
}
else {
for ($count = 0; $count<1000 || $outcome=1 || $tempcat2 < 1; $count++) { #prevent endless looping with 1000
$tempcat2 = $cat_db->select(['FatherID'], { ID => $tempcat1 })->fetchrow_array;
if ($tempcat2 == $parentcat) { $outcome = 1; } #YES it is a subcategory
$tempcat1 = $tempcat2; #move up a level
}
}

return $outcome;

}



But can I have nested subs in a global? How can I integrate this into my SQL statement above, even if it worked?


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

sooke: May 20, 2002, 1:58 PM
Quote Reply
Re: [Ian] Editor tag replacement In reply to
Alex, or someone:

I found this in Utils.pm. Instead of re-inventing the wheel, is it possible to either tap into this code and change the formatting to suit my above posts, or create a seperate tag from a global or plugin<%editorlinks%> to replace this completely?



Code:


sub load_editors {
# -------------------------------------------------------------------
# You call this tag by placing <%Links::Utils::load_editors%> in your
# category.html template. It will then make available an <%editors%>
# tag that you can use in your template. For example:
# <%Links::Utils::load_editors%>
# <%if editors%>
# The following users are editors in this category: <%editors%>
# <%endif%>
#
my $tags = GT::Template->tags;
my $cat_id = $tags->{category_id} or return "No category_id tag found! This tag can only be used on category.html template";
my $cat_db = $DB->table('Category');
my $parents = $cat_db->parents($cat_id);
push @$parents, $cat_id;

my $ed_db = $DB->table('Editors', 'Users');
my $sth = $ed_db->select ( GT::SQL::Condition->new('CategoryID', 'IN', $parents) );
return {} unless ($sth->rows);

# Make any formatting changes you need here.
my $output = '<ul>';
my @editors;
my %seen;
while (my $user = $sth->fetchrow_hashref) {
next if ($seen{$user->{Username}}++);
$output .= qq~
<li>$user->{Username}
~;
push @editors, $user;
}
$output .= "</ul>";
return { editors => $output, editors_loop => \@editors };
}


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: May 20, 2002, 6:48 PM
Quote Reply
Re: [Ian] Editor tag replacement In reply to
Ok, I have this working in a Global now!!!

Just need to figure how to put this into my plugin.

Talking to myself here! oh well.Wink Just thought I would post in case someone was figuring this out.


http://www.iuni.com/...tware/web/index.html
Links Plugins