Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

hmm... i'm stumped ;)

Quote Reply
hmm... i'm stumped ;)
hello.. i just installed links sql and now i am putting some mods in.. my version of something like links sql used much simpler terms for the SQL queries.. i was looking at nph-build.cgi and HTML_Templates.pm to figure out what to do to install subcategories like yahoo..

i got something simple.. but it sucks Wink i can't figure out how to get an array of subcategories in the subcategory that we are printing.. anyone? my first hour with links sql.. so.... hehe.. this is gonna take awhile to get isn't it?

to see what i did get..

http://www.pdamania.com/

just simple little thing..

all automatic..

jerry
Quote Reply
Re: hmm... i'm stumped ;) In reply to
Jerry,

Haven't looked at the answer to that, but _remember_ to think in terms of SQL QUERY not PERL Programming. If you can request the information in an SQL QUERY (or DO) then that's the way you should try it first.

I've cut 90% of the code out of some of my programs and have cut as much as 85 lines of code down to two calls to DBSQL.pm!! with improved efficiency!

The DBSQL.pm module is an interface or wrapper for the DBD Smile
Quote Reply
Re: hmm... i'm stumped ;) In reply to
yea.. i know mysql queries.. how else did i make review.cgi and category.cgi? Wink

and BTW.. mysql queries isn't much different than perl too.. it's not perl.. but it's just one sentence that is only like 5% perl.. (the regexp being used)..

otherwise it's just a bunch of perl.. like the $sth->execute() or blah; parts

hehe.. i was using $CATDB in HTML_Templates.pm but no matter what it returns with the errors..

jerry

[This message has been edited by widgetz (edited October 15, 1999).]
Quote Reply
Re: hmm... i'm stumped ;) In reply to
nevermind.. i figured it out using Alex's Mini Guide to making mods in the resource center Wink

i'm guessing it is made for people that arn't programmers.. which is very good.. but the thing i needed was:

Code:
my $CATDB = new Links: BSQL "$LINKS{admin_root_path}/defs/Category.def";

hehe.. the rest of it didn't help.. i am using a REGEXP to query out all the subcategories..

i think i should have my first links sql mod in a few minutes!

jerry
Quote Reply
Re: hmm... i'm stumped ;) In reply to
Well... share it Smile

We could use some discussion here.

The mini-guide answers a lot of the questions, doesn't it? Smile

Most of what I'm doing has nothing to do with Links. Alex is adding in things to the 1.2 release, so when that comes out we'll see what still needs to be done.

The only two LinkSQL mods I'm working on is a comments (review) and a rating mod that keeps track of the individual votes, since people can be real jerks.
Quote Reply
Re: hmm... i'm stumped ;) In reply to
Code:
$output .= qq|</dt><dd><span class="descript">|;
if ($description =~ m,^\(([^\)]+)\)(\d)$,) {
($description, $style) = ($1, $2);
my $subcat_length = 40;
my $CATDB = new Links: BSQL "$LINKS{admin_root_path}/defs/Category.def";
my $sth = $CATDB->prepare (qq! SELECT Name FROM Category WHERE Name REGEXP "^$cat/" !) or die $DBI::errstr;
$sth->execute() or die $DBI::errstr;
my $subcategories = ($sth->fetchall_arrayref)[0];
if ($#$subcategories >= 0) {
@subnames = split (/\|/, $description);
my ($length, $s) = 0;
foreach $category_name (@subnames) {
foreach (@$subcategories) {
($description eq "ALL" && $#subnames == 0) ?
($$_[0] =~ m,.*/([^/]+)$, and $category_name = &build_clean($1)) :
($$_[0] eq "$cat/$category_name" or next);
if ($style eq "1") {
$length += length($category_name);
($length > $subcat_length) and last;
}
if ($s > 0) {
$output .= qq~, ~ and $length += 2 if ($style == 1);
$output .= qq~<br>~ if ($style == 2);
}
elsif ($style == 1) { $output .= qq~&nbsp;&nbsp;~; }
$output .= qq~&nbsp;&nbsp;~ if ($style == 2);
$output .= qq~<a href="$category_url~.&build_clean_name($category_name).qq~/">$category_name</a>~;
$s++;
last if ($description ne "ALL" && $#subnames > 0);
}
}
if ($s < $#$subcategories) { $output .= qq~..~ if ($style == 1); }
}
}
else { $output .= qq|$description| if ($description !~ /^\s*$/sm); }
$output .= qq|</span></dd></dl>|;

version 2 for SQL of Subcategories Like Yahoo!..

umm.. just change this code in HTML_Templates.pm (sub site_html_print_cat):

Code:
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if ($description !~ /^\s*$/sm);
$output .= qq|</dl>|;

with the above code..

also to avoid strict errors...

in

Code:
my ($output, $category_name, $category_url, $id, $name, $new, $links, $description, $i, $cat, $half, @subnames);

change to:

Code:
my ($output, $category_name, $category_url, $id, $name, $new, $links, $description, $i, $cat, $half, @subnames, $style);

that's all!

to use.. it's pretty self explainatory.. well not really.. but.. ok here we go..

TO USE YAHOO STYLE..

in the categories description put:

(sub1|sub2|sub3)1

replacing each of the sub# with a subcategory.. you can put as many as you want.. or as few as you want..

you can also use:

(ALL)1

to make them list all in alphabetical order..

YAHOO STYLE USES

Code:
my $subcat_length = 40;

change the 40 to the maximum number of characters you want to appear on the subcategory line..

THE OTHER STYLE is simply an new space + an indent..

so it looks like

hello
hi
bye
buenos dias
adios

something like that..

just do

(sub1|sub2|sub3)2

or

(ALL)2

ahh... my first links sql mod.. (it was also my first links2 mod)

jerry
Quote Reply
Re: hmm... i'm stumped ;) In reply to
oh... the Wink

ok.. uh.. pugdog..

http://www.pdamania.com/sql/review.cgi?ID=2

it's for Links SQL.. hope you don't get an error this time.. since i yelled at my host last time about locking up my mysql server for 2 days.. i think they haven't been down since! Smile

jerry
Quote Reply
Re: hmm... i'm stumped ;) In reply to
Ok... I guess I don't have to continue with the mod... <G> I assume it would be easy to make rate 1-10 and to change the criteria it's judged on?

I'd still need to work on the 'review' part since I want to integrate it into the detailed page, as short 'comments' (like "add a caption").

Quote Reply
Re: hmm... i'm stumped ;) In reply to
Doesn't plug in that easily to the newer template-based category routine.

I guess you have the original update, not the 'beta' release.
Quote Reply
Re: hmm... i'm stumped ;) In reply to
template based eh?

no.. i have the older one.. i just got today.. i think i'll stay with it until a NON beta comes out.. at that time i'll post another one..

review.cgi sql can go into detailed pages on links sql.. that's a very big advantage over links 2 cause links 2 has that annoying require thing.. and links sql can open mutiple objects (def files) at the same time..

yes.. you can change to ten by change a code in it from 5 to 10..

Code:
my $bars = 5;

hehe.. i did 5 cause i like the number better.. means either it's good.. it's ok.. it's middle.. it's so so.. or it sucks Wink changing it to any number will make the graph work perfectly fine (all three.. image, image/html, and html).. just the rating images you have to edit yourself..

i am thinking about just making it with review.cgi.. but i'm not sure if that will put a larger load on your server.. it would be useful though.. "the all in one download" Smile

also.. the graph formats itself.. (image and image/html) [1st and 2nd] to fit with the width and height you set for it.. if you made it really big and you have like 5 bars.. it will have BIG FAT bars Wink

anyways.. just some things i've been playing with in the past week..

jerry

[This message has been edited by widgetz (edited October 15, 1999).]
Quote Reply
Re: hmm... i'm stumped ;) In reply to
Have you made the code available? I might have some suggestions for it based on what I've been working on for my needs.

The templates work really nice! I'm sure you can use the old non-template based one, but I haven't looked to see what other changes were made (out side of print_cat..).

Quote Reply
Re: hmm... i'm stumped ;) In reply to
what have you been doing?

the major change i made was the image graph.. i made it cause then the page won't pause when loading in netscape.. and i think it looks better..

all the color is chageable in this version too.. for the graph you use the HTML tags.. like #ffffff for background.. etc

i made this subroutine to change the ffffff,etc into it's RGB.. alot of learning there.. Wink i had difficulty trying to understand what the heck a,b,c,d,e,f stands for.. until i realized they were just the numbers 10,11,12,13,14,15.. then i had problems figuring out what each portion meant.. like "ff" and "ff" and "ff"

obvious it's in order RGB.. but ff mean 15 15.. which didn't make anything.. then i found out you had to multiply the first number by 16.. so you get 240.. then you add the second number and get 255.. so 255, 255, 255..

hehe... it works great.. [why did i have to make the rgb? cause then the html graphs could use the html code too]

jerry
Quote Reply
Re: hmm... i'm stumped ;) In reply to
I've been working on my own version, not using any of your code. I didn't know you had made any code for this available.

But, you are further along than I am, I hadn't even looked at using graphs, just a status bar.

What I needed most was a way to integrate it into Links' detailed pages, and then into my send scripts. The whole point was to give users more options, not just collect more data.

Quote Reply
Re: hmm... i'm stumped ;) In reply to
i guarantee you can put it into your detailed pages.. it's not hard.. you can even put the review.cgi image graph on the users page Wink

since it is an image..

right now i am working on getting the script to work with Links SQL.. there are a bunch of things i have to globalize.. i made it shorter and i am going to try and make the graph subroutine more cleaner.. as it has a whole bunch of numbers that are hardcoded.. and i should change it to be based on the height.. i am also going to make the font sizes editable..

anyways.. i think the mod will be out by the end of this week.. i have no clue if i want to support it for links2 though.. i was thinking maybe some links2 user will find out for themselves.. but idunno.. if i get enough feedback.. i will probably just do it..

jerry
Quote Reply
Re: hmm... i'm stumped ;) In reply to
Hi Jerry,

One of the things the building statistics does is create a table of category heiarchry information. From it, you can easily (and efficently) grab a list of subcategories without scanning the whole table.

Try:

Code:
$sth = $db->prepare ("
SELECT Category.Name
FROM Category, CategoryHeiarchy
WHERE CategoryHeiarchy.CategoryID = ? AND
CategoryHeiarchy.Depth = 1 AND
CategoryHeiarchy.SubCategoryID = Category.ID
");

This will get you a list of first level subcategories for any given category id. To run the query do:

$sth->execute('35');

to get subcats for id 35. You should put the prepare and the new outside of any loop to maximize performance.

Hope this helps,

Alex
Quote Reply
Re: hmm... i'm stumped ;) In reply to
Wow.... I knew there had to be a reason for doing the Heirarchy table like that! Cool beans!
Quote Reply
Re: hmm... i'm stumped ;) In reply to
Whats the code we replace with

$output .= qq|</dt>|; $output .= qq|<dd><span class="descript">$description </span></dd>| if ($description !~ /^\s*$/sm); $output .= qq|</dl>|;


Thanks
Quote Reply
Re: hmm... i'm stumped ;)<br> In reply to
I was wondering whether anybody had modified the code kindly provided by Jerry Su. You can't actually implement directly into the Links SQL version 1.11. The code that Jerry explains needs to be replaced can't be found in the site_html_print_cat subroutine in HTML_Templates.pm. It was obviously different in an earlier version. The coding is a bit too overwhelming for me to understand what needs to be changed.

Also I was wondering whether, with $description that does not seem to be defined in the newer version of LinksSQL, does it need to be replaced by another term ?

I am sorry if this seems to be a extremely silly query, but I'm fairly stuck on this and can't find my way out, so any help would be appreciated. Jag

Quote Reply
Re: hmm... i'm stumped ;)<br> In reply to
Hi Jag

if you tell me exactly what you want to achieve, I can adjust this mod for you.

regards, alexander

Quote Reply
Re: hmm... i'm stumped ;)<br> In reply to
I went over the above code, working out what it actually did and it seems quite complete in that it allows for different ways to actually display the subcategories. However part of the code seems to do what the subcategory.html template effectively does, ie. the code that deals with the display of the description :

$output .= qq|<dd><span class="descript">$description </span></dd>| if ($description !~ /^\s*$/sm);

seems to be in the subcategory.html template where $description is replaced with <%Description%>.

I tried putting the big chunk of code that is in the sixth message in this discussion, but this also uses a similar type of code to one above that needs to be replaced, hence it starts with :

$output .= qq|</dt><dd><span class="descript">|;
if ($description =~ m,^\(([^\)]+)\)(\d)$,)

From what I have understood, the place for this code to sit is in the site_html_print_cat subroutine in HTML_Templates.pm. I suspected that it should be after :

# If you are using the three level new, calculate the number of days old.

and before the end of table cell function, but even if it is actually placed correctly I don't see how it can work without getting rid of the "$output .= qq|<dd><span class="descript">..." part since it is redundant with what appears in the subcategory.html.

Finally from what I understood, in the subcategory.html file I need to put <%Description%> followed by (sub1|sub2|sub3)1 for example but this seems fairly weird to me. Should this be a value ?

Anyway, if you could help me Alexander to understand what I need to do and where to place it, I would be very greatfull.
PS : I hope I have explained the problems I have (and the mistakes I making) well enough.

Jag