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

Modifying MyLinks_DB Plugin ?

Quote Reply
Modifying MyLinks_DB Plugin ?
Hi ...

We have just started evaluating the MyLinks_DB plugin. We like what we see, but there are a few issues we need to sort out before the the 3 day limit expires ...

1. Would it be easy to modify it so that it works with links that are in multiple categories? All our links are like that, so users' lists display up to six copies of the same link. Users who have saved the maximum 25 would actually have a list of more than 100 repeating items.

2. We would need to set 'No categories' as the default grouping, and thereafter disable Grouping as a user option.

3. We would also need to disable Favorites Font as a user option.

4. Could the columns that appear in the users' Order By option be set by admin? We would need to exclude Hits, isNew, isPopular, Rating, and Votes from the list (we don't use them at all), and add Contact_Name, plus a couple of our own custom fields.
Quote Reply
Re: [YoYoYoYo] Modifying MyLinks_DB Plugin ? In reply to
Hi,

1. To sort out the first problem follow the instructions in this post:

http://www.gossamer-threads.com/...i?post=188796#188796

2. You can remove the grouping option from the preferences template easily to stop anyone being able to change this.

3. Similarly for the fonts - just remove the form field from the template.

4. I haven't got time just now to look at how this is written in the plugin - you can definitely remove the fields you don't want by modifying the template - I'm just not sure about adding them - why not try it and see?

Hope that helps,

Laura.
The UK High Street
Quote Reply
Re: [YoYoYoYo] Modifying MyLinks_DB Plugin ? In reply to
You can pass in any valid column to sort by.
Quote Reply
Re: [afinlr] Modifying MyLinks_DB Plugin ? In reply to
In Reply To:
1. To sort out the first problem follow the instructions in this post:
http://www.gossamer-threads.com/...i?post=188796#188796
OK, that works in the sense that only one instance of each link is displayed, but it also messes up the count. For example, if MyLinks_Per_Page is 10, we don't see 10 links per page -- if Link A is in 6 categories and Link B is in 4 categories, then page 1 just shows one each of A and B -- and the count stops when it gets to the maximum, so most links don't show up anywhere in the list.


In Reply To:
2. You can remove the grouping option from the preferences template easily to stop anyone being able to change this.
Yes, we have done that, but the default is Grouped, so that is what users would be stuck with, which is unthinkable. It should be an Admin setting like some of the other options.


Two other problems found:

Preferences don't get saved correctly -- as soon as we move to another page, they revert to the defaults (though we found we could prevent that by removing all the Javascript from mylinks_preferences.html)

We can't use ASC and DESC as abbreviations for Ascending and Descending. We can change it in the preferences template, but we can't see what other changes have to be made for it to take effect.
Quote Reply
Re: [YoYoYoYo] Modifying MyLinks_DB Plugin ? In reply to
Sorry - I forgot about this - its a few months since I got this plugin working and I'd forgotten how many changes I'd madeWink

I also found this problem:

http://www.gossamer-threads.com/...i?post=193598#193598

Unfortunately I couldn't get Paul to replicate it but its nice to know it wasn't just me!

However, it is fixable because I have links in multiple categories and the plugin is working on my site.

In the pm file you'll need to change both the sub main and the sub user_favourites:

Since I'm not allowing the grouped option at all, I've commented out the whole 'if ($grp == 1)' statement and just left the bit in the 'else' bit (you'll need to comment out 'else {' and the closing '}'). Then I changed the line

my $table = $DB->table('Links,Catlinks');

to

my $table = $DB->table('Links');

I hope this makes sense - get back to me if not and I'll have another go.

Obviously this also remove the second problem as the links can now never be displayed as grouped.

As far as I can remember, the problem with the preferences was just typing errors in the template. For example, the options for MyLinks_Font suddenly revert to MyLinks_Grouping - just check the html.

For the ASC and DESC, just change the bit after the option tag to whatever you want:

<option <%if MyLinks_Order eq 'ASC'%>selected<%endif%>>Ascending

Laura.
The UK High Street
Quote Reply
Re: [afinlr] Modifying MyLinks_DB Plugin ? In reply to
In Reply To:
Since I'm not allowing the grouped option at all, I've commented out the whole 'if ($grp == 1)' statement and just left the bit in the 'else' bit (you'll need to comment out 'else {' and the closing '}').

Ok, we had already done that ... but not this ...
In Reply To:
Then I changed the line
my $table = $DB->table('Links,Catlinks');
to
my $table = $DB->table('Links');
... which produces a rather strange effect: The number of pages is correct, but now there is just one link per page!


In Reply To:
For the ASC and DESC, just change the bit after the option tag to whatever you want:
<option <%if MyLinks_Order eq 'ASC'%>selected<%endif%>>Ascending
... and also modify the MyLinks_Order column in the Users table.

But a better solution is to set it to form type RADIO (means it can retain the abbreviations). MyLinks_Per_Page and MyLinks_Ordering are also more user-friendly as radio buttons.
Quote Reply
Re: [YoYoYoYo] Modifying MyLinks_DB Plugin ? In reply to
I think that I would need to see your file and compare it to mine - it was such a long time ago that I can't remember exactly what I did - but it really is working on my site Wink

In Reply To:


... and also modify the MyLinks_Order column in the Users table.

But a better solution is to set it to form type RADIO (means it can retain the abbreviations). MyLinks_Per_Page and MyLinks_Ordering are also more user-friendly as radio buttons.
I'm sorry but I don't understand this. I wasn't sure in the first place why you couldn't use the ASC abreviation but the line I gave you does not need any changes to the Users table. The only change I have made as far as I am aware is the display of the option on the page. But if you've managed to fix your problem that's fine.
The UK High Street
Quote Reply
Re: [YoYoYoYo] Modifying MyLinks_DB Plugin ? In reply to
Try this (I just did a quick compare of the original and my version of the file):

In the main sub, replace

# If param nh is greater than one then we need to work out our start position.
if ($nh > 1) {
$low = ($nh - 1) * ($tmp->{MyLinks_Per_Page} || $mh);
}


with

# If param nh is greater than one then we need to work out our start position.
$low = ($nh - 1) * ($mh);

Hope that fixes it.

Laura.
The UK High Street
Quote Reply
Re: [afinlr] Modifying MyLinks_DB Plugin ? In reply to
In Reply To:
I'm sorry but I don't understand this. I wasn't sure in the first place why you couldn't use the ASC abreviation but the line I gave you does not need any changes to the Users table. The only change I have made as far as I am aware is the display of the option on the page. But if you've managed to fix your problem that's fine.

You are right -- I didn't need to change the Users table. Maybe I'm not thinking 100% straight because I'm in too much of a hurry to fix this.
Quote Reply
Re: [afinlr] Modifying MyLinks_DB Plugin ? In reply to
In Reply To:
$low = ($nh - 1) * ($mh);
Hope that fixes it.
Sadly ... no, it doesn't ...


Here is what the critical part of sub main looks like now ...
Code:
if ($tags->{total}) {
my $tab = $DB->table('MyLinks');
my @list = $tab->select( { UserID => $USER->{Username} } )->fetchall_list;
my $table = $DB->table('Links');
$table->select_options("ORDER BY $ord $way", "LIMIT $low,$mh");
my $sth = $table->select( { ID => \@list } );

my %match;
while (my $rec = $sth->fetchrow_hashref) {
unless (exists $match{$rec->{LinkID}}) {
$tags->{saved_links} .= Links::SiteHTML::display('mylinks_link', { %$rec, MyLinks_Font => $tmp->{MyLinks_Font} } );
$match{$rec->{LinkID}}++;
}
}
}
... following the modification suggested in http://gossamer-threads.com/..._reply;so=ASC;mh=50;

However, I feel I have reached the end of the line with this one.
Thanks afinir and everybody else for your generous time and thoughtfulness.
Time to move on now, there is another plugin waiting ...
Quote Reply
Re: [YoYoYoYo] Modifying MyLinks_DB Plugin ? In reply to
Just in case you're still willing to give it a go, you don't need the match bit any more.

my $tab = $DB->table('MyLinks');
my @list = $tab->select( { UserID => $USER->{Username} } )->fetchall_list;
my $table = $DB->table('Links');
$table->select_options("ORDER BY $ord $way", "LIMIT $low,$mh");
my $sth = $table->select( { ID => \@list } );
while (my $rec = $sth->fetchrow_hashref) {
$tags->{saved_links} .= Links::SiteHTML::display('mylinks_link', { %$rec, MyLinks_Font => $tmp->{MyLinks_Font} } );

}
The UK High Street
Quote Reply
Epilogue In reply to
That's right. As soon as I stopped thinking about it, the answer came to me immediately. The previous solution was actually the problem!
After which, it took me all of five seconds to change the code to this ...
Code:
if ($tags->{total}) {
my $tab = $DB->table('MyLinks');
my @list = $tab->select( { UserID => $USER->{Username} } )->fetchall_list;
my $table = $DB->table('Links');
$table->select_options("ORDER BY $ord", "LIMIT $low,$mh");
my $sth = $table->select( { ID => \@list } );
while (my $rec = $sth->fetchrow_hashref) {
$tags->{saved_links} .= Links::SiteHTML::display('mylinks_link', { %$rec } );
}
}
Now it works perfectly ... so far.
Quote Reply
Re: [YoYoYoYo] Epilogue In reply to
Great, I'm glad you managed to get it working - I think its great plugin.
The UK High Street
Quote Reply
Re: [afinlr] Epilogue In reply to
In Reply To:
Great, I'm glad you managed to get it working - I think its great plugin.
Yes, we agree with that -- and so do our hyper-critical testers, who have thought up several possible extensions.