Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

PageBuilder to generate users pages...

Quote Reply
PageBuilder to generate users pages...
Hi

I have created a page to generate a dynamic users pages with their owne header, footer, info, links....

The trouble I am having is coming up with a Global to generate a spanned list of all users onfile with there name linked to their profile..

Spanning the list is the tough part otherwise I will end up with a list of over 3000 users on one page.

Any ideas?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] PageBuilder to generate users pages... In reply to
This is the span global that I use:

sub {
# ---------------------------------------------------------------
# Display/calculate a span pages toolbar.
#
my $tags=shift;
my $nh=$tags->{nh};
my $page=$tags->{p};
my $maxhits = $tags->{maxhits}||100;
my $numhits = $tags->{numhits}||1000;
my ($next_url, $max_page, $next_hit, $prev_hit, $left, $right, $upper, $lower, $first, $url, $last, $i);

# Return if there shouldn't be a speedbar.
return unless ($numhits > $maxhits);

$next_hit = $nh + 1;
$prev_hit = $nh - 1;
$max_page = int ($numhits / $maxhits) + (($numhits % $maxhits) ? 1 : 0);

# First, set how many pages we have on the left and the right.
$left = $nh;
$right = int($numhits/$maxhits) - $nh;

# Then work out what page number we can go above and below.
($left > 7) ? ($lower = $left - 7) : ($lower = 1);
($right > 7) ? ($upper = $nh + 7) : ($upper = int($numhits/$maxhits) + 1);

# Finally, adjust those page numbers if we are near an endpoint.
(7 - $nh >= 0) and ($upper = $upper + (8 - $nh));
($nh > ($numhits/$maxhits - 7)) and ($lower = $lower - ($nh - int($numhits/$maxhits - 7) - 1));
$url = "";
# Then let's go through the pages and build the HTML.
($nh > 1) and ($url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page">[&lt;&lt;]</a> ~);
($nh > 1) and ($url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page&nh=$prev_hit">[&lt;]</a> ~);
for ($i = 1; $i <= int($numhits/$maxhits) + 1; $i++) {
if ($i < $lower) { $url .= " ... "; $i = ($lower-1); next; }
if ($i > $upper) { $url .= " ... "; last; }
($i == $nh) ? ($url .= qq~$i ~) : ($url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page&nh=$i">$i</a> ~);
if ($i * $maxhits == $numhits) { $nh == $i and $next_hit = $i; last; }
}
$url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page&nh=$next_hit">[&gt;]</a> ~ unless ($next_hit == $nh or ($nh * $maxhits > $numhits));
$url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page&nh=$max_page">[&gt;&gt;]</a> ~ unless ($next_hit == $nh or ($nh * $maxhits > $numhits));
return $url;
}
Quote Reply
Re: [afinlr] PageBuilder to generate users pages... In reply to
Tahnks Laura..

That does not seem to work with my users list..

I think it has to be integrated within the same global or something.
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] PageBuilder to generate users pages... In reply to
Yes, you'll need to modify the list global slightly.

For example, if you wanted to span the users list of links (I don't have the global you are using for the list of users pages but you should be able to see the relevant bits):

sub {
my $name = shift;

my $tags = shift;
my ($output,$sth,$link);
my $db = $DB->table ('Links');
my $nh = $tags->{nh}||1;
my $mh = $tags->{maxhits}||15;
my $offset = ($nh-1) * $mh;
$db->select_options ("ORDER BY LinkOwner DESC", "LIMIT $offset, $mh");
my $sth = $db->select ( { 'LinkOwner' => $name });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}

Edit: These globals should work dynamically - I use the span global for several pages on my site with different lists. However, I'm not sure how easy it is to use the nh tag with pagebuilder. Using these dynamically is easy because the nh tag is in the url. You may need to set the nh tag in the template using another global by parsing the url but I'm not sure about this.

Last edited by:

afinlr: Aug 10, 2003, 4:38 AM
Quote Reply
Re: [afinlr] PageBuilder to generate users pages... In reply to
*******
---AD---

This feature of spanning user list is included in my commercial plugin package with span list features and sorting options!
Quote Reply
Re: [afinlr] PageBuilder to generate users pages... In reply to
Hi Laura,

Could you please explain (step-by-step, globals, how to call them), how do you create span pages like:

http://www.theukhighstreet.com/perl/page.cgi?g=offers

Thanks for your time!
Quote Reply
Re: [Payooo] PageBuilder to generate users pages... In reply to
Hi,

The span global above is really for use with pages like

page.cgi?p=list

where you have a new template called list.html. (You can use it on other pages - just takes a bit of modification).

To get the span, copy the global and call it span_pages and then where you want the span in the template <%span_pages%>

Near the top of the page (above the span) you'll need

<%ifnot nh%><%set nh=1%><%endif%>


Optional tags:

<%set maxhits=10%> - or what ever number of links you want per page (you can just set this in the global - but this means you can use the span global for different lists with different numbers of records per page).

<%set numhits=100%> - again you can set this in the global. You may want to look up the exact number of records in the global rather than using a fixed number.


You should be able to use this straight away and get a span list with the correct number of pages - try it and see - if you don't let me know, I may have missed out something.

The next problem is to get the correct links/records on each page.

This is where you need another global which selects the links/records. In the global you need to make sure that you have these lines:

my $tags = shift;
my $db = $DB->table ('Links'); #or whichever table you are taking records from
my $nh = $tags->{nh}||1;
my $mh = $tags->{maxhits}||15; #Make sure this matches the value you're using in the span global
my $offset = ($nh-1) * $mh;
$db->select_options ("ORDER BY Fieldname DESC", "LIMIT $offset, $mh");

I hope that helps a bit.

Laura.
The UK High Street
Quote Reply
Re: [afinlr] PageBuilder to generate users pages... In reply to
Smile (Big, biiiiiiig smile)

Thank you Laura!
Quote Reply
Re: [afinlr] PageBuilder to generate users pages... In reply to
Hi


I have tried exactly what you explained..

The speed bar is visible but the page still has all the users listed..

- I created a users_list global:

sub {
# Displays all Users.
my $search_db= $DB->table('Users');
$search_db->select_options ('ORDER BY Username DESC');
my $sth = $search_db->select;
my $output;
while (my $user = $sth->fetchrow_hashref) {
$output .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?page=user&user=$user->{Username}">$user->{Username}</a><br /> ~;
}
return $output;
}



- Created the span_page globale

- created a new page in the default templates test..

in it I have:

<%ifnot nh%><%set nh=1%><%endif%>
<%set numhits=100%>
<%set maxhits=10%>
<%span_page%>
<%users_list%>



Any idea?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] PageBuilder to generate users pages... In reply to
Hi katabd,

If you've got the speed bar showing the correct number of pages then you're halfway there. You just need to add bits to your global to tell it which page to show. Something like:

sub {
# Displays all Users.

my $tags=shift;
my $search_db= $DB->table('Users');

my $nh = $tags->{nh};
my $mh = $tags->{maxhits};
my $offset = ($nh-1) * $mh;
$search_db->select_options ('ORDER BY Username DESC',"LIMIT $offset, $mh");
my $sth = $search_db->select;
my $output;
while (my $user = $sth->fetchrow_hashref) {
$output .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?page=user&user=$user->{Username}">$user->{Username}</a><br /> ~;
}
return $output;
}
Quote Reply
Re: [afinlr] PageBuilder to generate users pages... In reply to
Hi

Thanks so very much.

I have all those changed in the global..

** When My template reads:

<%ifnot nh%><%set nh=1%><%endif%>
<%set numhits=100%>
<%set maxhits=10%>
<%span_page%>
<%users_list%>

The speedbar will only have 10 pages with 10 names in each.

I tried playing around with the numhits and maxhits with no changes.. still 10 pages only..

Any idea?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] PageBuilder to generate users pages... In reply to
Well ... that seems about right?

Numhits is the total number of users, maxhits is the number of users per page. So if you have 100 users and 10 per page you will have 10 pages.

If you want to have the number of users set equal to the actual number of users in the database, either set it in the tag if it doesn't change or you'll need to look it up at the beginning of the global.
Quote Reply
Re: [afinlr] PageBuilder to generate users pages... In reply to
i want to use the span global you posted (Display/calculate a span pages toolbar)

and i have this global:

sub {
my $output;
my $tags = shift;
my $cat_id = $tags->{ID};
my $subcats = $DB->table('Category')->children($cat_id);
push @$subcats, $cat_id;
my $link_db = $DB->table('Links','CatLinks');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', $subcats);
my $sth = $link_db->select($condition);

while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}


global name is: subcategory_links
it is on the template category.html it show all the links from the subcategory on the mother category.
but i want to span the links in pages.


what do i have to modify or add to my global to makit work with your span_pages global?

thanks
Quote Reply
Re: [Essam] PageBuilder to generate users pages... In reply to
Unfortunately I don't think it is that simple to do on Category pages as they are special. I think that this may need a plugin.
Quote Reply
Re: [afinlr] PageBuilder to generate users pages... In reply to
Sorry to slightly move away from the subject, (Yogi seems to be incommunicado about this plug-in at the moment)...

Is this plug-in capable of generating pages for editors to present themselves to every visitor of the web site (i.e. to anybody) if the editors are provided with the appropriate fields in Gossamer Community ?

Thanks, John
Significant Media