Gossamer Forum
Home : Products : Links 2.0 : Customization :

Priority & Logo Mod + 1 to 10 priority sort

Quote Reply
Priority & Logo Mod + 1 to 10 priority sort
I've installed the Priority & Logo Mod but now I get a idea making custom sorting for the top 10 links in each category.
I've already make a new field in admin called PriorityNo with 1,2,3,4,5,6,7,8,9,10 to choose from, but now I don't know how to make new entries in db_utils.pl sub build_sorthit
Can anyone help me on this?

Thanks in advanced,

Nuno Duque
--------------------
Macau Search Engine
searchmacau.com
Quote Reply
Re: Priority & Logo Mod + 1 to 10 priority sort In reply to
No one can help me on this?
I just want a answer, possible or not.

Thank in advance,

Nuno Duque
--------------------
Macau Search Engine
searchmacau.com
Quote Reply
Re: Priority & Logo Mod + 1 to 10 priority sort In reply to
Is this any help?

Code:
sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort
# new links first, then cool links, then the rest alphabetically. By modifying
# the sort function below, you can sort the links however you like (by date,
# or random, etc.).
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %priorityno, %priority, %isnew, %iscool, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
$priorityno{$i} = $unsorted[$db_priorityno + ($i * ($#db_cols+1))];
($unsorted[$db_priority + ($i * ($#db_cols+1))] eq "Yes") and ($priority{$i} = 1);
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
}
foreach $hit (sort {
($priorityno{$b} and !$priorityno{$a}) and return 1;
($priorityno{$a} and !$priorityno{$b}) and return -1;
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($iscool{$b} and !$iscool{$a}) and return 1;
($iscool{$a} and !$iscool{$b}) and return -1;
($priorityno{$a} and $priorityno{$b}) and return $priorityno{$b} <=> $priorityno{$a};
($priority{$a} and $priority{$b}) and return $sortby{$b} <=> $sortby{$a};
($isnew{$a} and $isnew{$b}) and return $sortby{$b} <=> $sortby{$a};
($iscool{$a} and $iscool{$b}) and return $sortby{$b} <=> $sortby{$a};
$sortby{$b} <=> $sortby{$a};
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
http://www.humorlinks.com
Quote Reply
Re: Priority & Logo Mod + 1 to 10 priority sort In reply to
Thanks a lot, you're a genius, it's working now.
When you have some time can you take a look in my another question http://www.gossamer-threads.com/...=25&Old=allposts


Thanks,

Nuno Duque
--------------------
Macau Search Engine
searchmacau.com
Quote Reply
Re: Priority & Logo Mod + 1 to 10 priority sort In reply to
What does your links.def file code look like with this modification? Or, put another way, what mods had to be performed in the links.def file?

Thanks.

Mark G.
Mark

Quote Reply
Re: Priority & Logo Mod + 1 to 10 priority sort In reply to
Change the code to the following:

# Database Definition: LINKS
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, '', '^http|news|mailto|ftp'],
DateAdded => [3, 'date', 15, 15, 0, \&get_date, ''],
Date => [4, 'date', 15, 15, 1, \&get_date, ''],
Category => [5, 'alpha', 0, 150, 1, '', ''],
Description => [6, 'alpha', '40x3', 250, 0, '', ''],
Keywords => [7, 'alpha', '40x5', 450, 0, '', ''],
'Contact Name' => [8, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [9, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [10, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [11, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [12, 'alpha', 0, 5, 0, 'No', ''],
Rating => [13, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [14, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [15, 'alpha', 10, 10, 1, 'Yes', 'No|Yes'],
Logo => [16, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
Graphic => [17, 'alpha', 40, 100, 0, '', ''],
Gwidth => [18, 'alpha', 5, 5, 0, '', ''],
Gheight => [19, 'alpha', 5, 5, 0, '', ''],
Priority => [20, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
PriorityNo => [21, 'alpha', 0, 5, 1, '0', '0|1|2|3|4|5|6|7|8|9|10'],
IP => [22, 'alpha', 20, 20, 1, '', ''],
Host => [23, 'alpha', 40, 40, 1, '', ''],
Domain => [24, 'alpha', 20, 20, 1, '', ''],
ServerIP => [25, 'alpha', 20, 20, 1, '', ''],
Password => [26, 'alpha', 10, 10, 1, '', '']

);

# Database file to use -- defined in mse.cfg.
$db_file_name = $db_links_name;
# Counter file to use -- defined in mse.cfg.
$db_id_file_name = $db_links_id_file_name;
# The column name for the database key.
$db_key = 'ID';
# Database delimeter.
$db_delim = '|';
# Title used in admin output.
$html_title = 'Links Database';
$html_object = 'Link';

# Field Number of some important fields. The number is from %db_def above
# where the first field equals 0.
$db_title = 1; $db_url = 2; $db_dateadded = 3;
$db_modified = 4; $db_category = 5;
$db_contact_name = 8; $db_contact_email = 9; $db_hits = 10;
$db_isnew = 11; $db_ispop = 12; $db_rating = 13;
$db_votes = 14; $db_mail = 15; $db_logo = 16;
$db_priority = 20; $db_priorityno = 21; $db_ip = 22;
$db_host = 23; $db_domain = 24; $db_serverip = 25;
$db_password = 26;

# Field number to sort links by:
$db_sort_links = 1;

# Field names you want to allow visitors to search on:
@search_fields = (1,2,5,6,7);

# System defaults. When adding new links or modifying links, these fields
# can not be overwritten by a user.
%add_system_fields = (
isNew => 'No',
isPopular => 'No',
Hits => '0',
Priority => 'No',
PriorityNo => '0',
Rating => 0,
Votes => 0,
ReceiveMail => 'Yes',
Logo => 'No',
);

# Hash of column names to possible options. If you want to use a select form
# field, you can use &build_select_field in your HTML page. This routine will
# make a <SELECT> input tag using the following values:
%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No',
Logo => 'Yes,No',
Priority => 'Yes,No',
PriorityNo => '0,1,2,3,4,5,6,7,8,9,10'
);

Note: This is not the full file, just overwrite it with your existing values.

Regards,

Nuno Duque
--------------------
Macau Search Engine
inmacau.com
Quote Reply
Re: Priority & Logo Mod + 1 to 10 priority sort In reply to
Nuno,

Thank you very much!!

Mark G.

Quote Reply
Re: [humorlinks] Priority & Logo Mod + 1 to 10 priority sort In reply to
Hi,
I installed this mod and nothing happened.
No errors, no changes at links listings.

I was reviewing all the code and I have only found a little differences between mod code and mine.
do you think that could be the problem?
here is an example:

sub build_sorthit
-----posted mode code----
($iscool{$a} and !$iscool{$b}) and return -1; ($priorityno{$a} and $priorityno{$b}) and return $priorityno{$b} <=> $priorityno{$a}; ($priority{$a} and $priority{$b}) and return $sortby{$b} <=> $sortby{$a}; ($isnew{$a} and $isnew{$b}) and return $sortby{$b} <=> $sortby{$a};

----my code-----
($iscool{$a} and !$iscool{$b}) and return -1;
($priorityno{$a} and $priorityno{$b}) and return $priorityno{$b} <=> $priorityno{$a};
($priority{$a} and $priority{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});

note the lc

Last edited by:

polete: Nov 24, 2001, 6:24 PM
Quote Reply
Re: [polete] Priority & Logo Mod + 1 to 10 priority sort In reply to
In Reply To:
---
now I have changed my code to the exact mod's code and it seems to work upside down! Crazy
priorityNo #10 takes a link to position #1
thats ok?

-----
mmm...definitivelly dont work Unsure
I have added 3 links with different OriorityNo levels.
Say LinkA No 10, LinkB No5, LinkC No3

Firts were shown in the above order, thats why I though it was working upside down, but then I have changed LinkC from No3 to No8 and there were no change at all.
Any ideas? I'll really appreciate any help.
thank you

Last edited by:

polete: Nov 24, 2001, 9:12 PM
Quote Reply
Re: [polete] Priority & Logo Mod + 1 to 10 priority sort In reply to
Hi there,

I really need I little help on this...
the mod it is working but just sort new links in order,
for links already in DB just give priority and not the specific place.
Any ideas? thank you.
Quote Reply
Re: [polete] Priority & Logo Mod + 1 to 10 priority sort In reply to
Hello again.

I have amended the code, and it should work.

Try this: -

Code:
sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort
# new links first, then cool links, then the rest alphabetically. By modifying
# the sort function below, you can sort the links however you like (by date,
# or random, etc.).
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %priorityno, %priority, %isnew, %iscool, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
$priorityno{$i} = $unsorted[$db_priorityno + ($i * ($#db_cols+1))];
($unsorted[$db_priority + ($i * ($#db_cols+1))] eq "Yes") and ($priority{$i} = 1);
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
}
foreach $hit (sort {
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($isnew{$b} and !$isnew{$a} and !$priority{$a} and !$priority{$b}) and return 1;
($isnew{$a} and !$isnew{$b} and !$priority{$a} and !$priority{$b}) and return -1;
($iscool{$b} and !$iscool{$a} and !$priority{$a} and !$priority{$b}) and return 1;
($iscool{$a} and !$iscool{$b} and !$priority{$a} and !$priority{$b}) and return -1;
($priority{$a} and $priority{$b}) and return $priorityno{$b} <=> $priorityno{$a};
($isnew{$a} and $isnew{$b}) and return $sortby{$b} <=> $sortby{$a};
($iscool{$a} and $iscool{$b}) and return $sortby{$b} <=> $sortby{$a};
$sortby{$b} <=> $sortby{$a};
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}

Cheers,

Warwick Evans

http://www.humorlinks.com

Quote Reply
Re: [humorlinks] Priority & Logo Mod + 1 to 10 priority sort In reply to
Unimpressed Great mod but it does not display properly when using netscape 4.7

It displays rectangular box next to the links which do not have an image assigned to them.

This really Crazy me

IceWater
Quote Reply
Re: [IceWater] Priority & Logo Mod + 1 to 10 priority sort In reply to
I think you have replied to the wrong person.Pirate

My part of this just deals with the sorting routine - nothing to do with images or the display.Unimpressed

Hope this will avoid any confusion.

Cheers,

Warwick Evans

http://www.humorlinks.com

Quote Reply
Re: [humorlinks] Priority & Logo Mod + 1 to 10 priority sort In reply to
Has anyone ever managed to get this to work succesfully? If so, can you assist me further?