Gossamer Forum
Home : Products : Links 2.0 : Customization :

Search Engine Friendly Links II - Link Title instead of ID

(Page 2 of 2)
> >
Quote Reply
Re: [PerlFlunkie] Search Engine Friendly Links II - Link Title instead of ID In reply to
PerlFlunkie wrote:
One thing you can do to simplify your mod is to make common code snippets into a subroutine.

I did so.

Code for the subroutine in db_utils.pl:

Code:

sub cleanup {
#-----------------------------------------
# get rid of extra characters

my($input) = shift;

$input =~ s/ä/ae/g;
$input =~ s/Ä/Ae/g;
$input =~ s/ö/oe/g;
$input =~ s/Ö/Oe/g;
$input =~ s/ü/ue/g;
$input =~ s/Ü/Ue/g;
$input =~ s/ß/ss/g;

$input =~ s/\@/-at-/g; # @
$input =~ s/\//-/g; # /
$input =~ s/\&/\-und-/g; # &
$input =~ s/\%/\-Prozent-/g; # %
$input =~ s/ /\-/g; # Leerzeichen - empty space
$input =~ s/\(/\-/g; # (
$input =~ s/\)/\-/g; # )
$input =~ s/!/\-/g; # !
$input =~ s/_/-/g;
$input =~ s/\+/\-und-/g; # +
$input =~ s/,/\-/g; # ,
$input =~ s/\>/\-/g; # >
$input =~ s/\:/\-/g; # :
$input =~ s/®/\-/g; # ®
$input =~ s/©/\-/g; # ©
$input =~ s/º/\-/g; # Nº
$input =~ s/\«/\-/g; # «
$input =~ s/\»/\-/g; # »
$input =~ s/\*/\-/g; # *
$input =~ s/²/\-/g; # ²
$input =~ s/\?/\-/g; # ?
$input =~ s/\./\-/g; # .
$input =~ s/`/\-/g; # `
$input =~ s/´/\-/g; # ´
$input =~ s/\'/\-/g; # '
$input =~ s/’n/\-/g; # ’
$input =~ s/\{/\-/g; # {
$input =~ s/\}/\-/g; # }
$input =~ s/\[/\-/g; # [
$input =~ s/\]/\-/g; # ]

$esc =~ s/^\s-|\s-$//gs;
$esc =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$esc =~ s/([^a-zA-Z0-9_\-.()[]%ae!+,>%O9)/uc sprintf("%%%02x",ord($1))/eg;

$esc =~ s/\%20/\-/g; #
$esc =~ s/\%23/\-/g; #
$esc =~ s/\%09/\-/g; #
$esc =~ tr/--/-/s; # get rid of multiple - charakters

return $input;
}


Code for Einschub $ Echte URL in nph-build.cgi ( sub build_update_newpop ) :

Code:

####################### Einschub $ Echte URL ###################################
##### Variante 1 : Detailed Folder ####

my($esc) = $values[$db_title];
$esc = &cleanup($esc);

## Kategorie hinzufügen - Now let`s add the category:
my($esd) = $values[$db_category] ."-";
$esd =~ s/\//-/g;
$esd =~ s/_/-/g;

## <%ID%> hinzufügen - Now let`s add the $db_key
$esd = $values[$db_key] ."-" .$esd;

$esd = $esd .$esc;

$esd =~ tr/-/-/s; # replace character for subtraction
$esd =~ tr/--/-/s; # get rid of multiple - charakters
$esd =~ tr/[A-Z]/[a-z]/; # change all letters to lowercase

$values[$db_echteURL] = $esd;
$echteURL = $esd;

## <%echteURL%> = 3043-grafik-bildbearbeitung-speziell-fuer-soko

####################### Einschub $ Echte URL ###################################

It works fine - Smile

.


Andreas

Dr.Windows








Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
If you are using 3 Level of New Graphics modification :

In this case you must change site_html_templates.pl too :
( To avoid that all detailed.html`s in the folder Detailed will be marked as updated )

Find in sub site_html_detailed the following line(s) :

Code:


# If the link is not new, check to see if it has been updated.

elsif (&compare_dates($rec{'Datum'}, $rec{'Anmeldedatum'})) {

# Calculate age of link based on Date Modified, not Date Added.

$days_old = &days_old($rec{'Datum'});

if ($days_old <= $db_new_cutoff && $rec{'istUpdate'} ne "Nein") { $new_mod_img = qq~ $updated~; }

}


and change these lines to :

Code:


# If the link is not new, check to see if it has been updated.

elsif (&compare_dates($rec{'Datum'}, $rec{'Anmeldedatum'})) {

# Calculate age of link based on Date Modified, not Date Added.

$days_old = &days_old($rec{'Datum'});

if ($days_old <= $db_new_cutoff && $rec{'istUpdate'} ne "Nein") { $new_mod_img = qq~ $updated~; }
if ($days_old > $db_newupdate_cutoff ) { $new_mod_img = qq~ ~; }

}


Ignore : && $rec{'istUpdate'} ne "Nein" : because this is part of an other mod and not important for this mod.

.


Andreas

Dr.Windows








Last edited by:

SevenSpirits: May 16, 2007, 9:07 AM
Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
Final modification

Once again the complete modification .

My Version :
Gossamer Links V 2.01 - German translation by Nicky available at : http://www.nicky.net/

Instead of dynamic HTML Pages (generated by detail.cgi) only -
static HTML Pages will be generated by nph-build.cgi too.


What must be done?

1. Add new system fields in links.def

2. Edit links.cfg

3. Edit nph-build.cgi
3.1 Insert code of # Einschub EchteURL # into sub build_update_newpop
3.2 Insert code of # Einschub Delete $echteURLalt ---- nph-build.cgi # into sub build_update_newpop
3.3 Edit sub build_detailed_view

4. New subroutine in db_utils.pl
Add sub cleanup at the end of db_utils.pl

5. Edit detail.cgi
All entries like : http://.../cgi-bin/detail.cgi?ID=4964
will be redirected to their static html pages.


6. Edit site_html_templates.pl
If you are using 3 Level of New Graphics modification :
In this case you must edit sub site_html_detailed in site_html_templates.pl too :
( To avoid that all detailed.html`s in the folder Detailed will be marked as updated )


7. Edit aendern.cgi (aendern.cgi is used for updating entries in links.db )
Insert code of # Einschub Delete $echteURLalt -- aendern.cgi # into aendern.cgi


.
Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
1. Add new system fields in links.def


Insert into your links.def :

Code:

echteURL => [27, 'alpha', 40, 200, 0, '', ''],

echteURLalt => [28, 'alpha', 40, 200, 0, '', ''],

Code:

$db_echteURL = 27;

$db_echteURLalt = 28;


Explanation:

$db_echteURL contains the value of <%ID%>-<%Kategorie%>-<%Titel%>
<%Titel%> ist the name of an entry.

$db_echteURLalt contains the old value of $db_echteURL if <%Titel%> and/or <%Kategorie%> were changed by an update.

$db_echteURLalt will be used to delete old static html pages of an entry in links.db .


Attachment : links.def




2. Edit links.cfg

Find these lines in your links.cfg :

Code:
# Soll die Detailierte Ansicht fuer jeden Link erstellt werden ? (1 = ja, 0 = nein).
$build_detailed = 0;
$build_detail_path = "$build_root_path/Detailiert";
$build_detail_url = "$build_root_url/Detailiert";

and change the value of $build_detailed from 0 to 1 .

Now sub build_detailed_view in nph-build.cgi
does create static HTML Pages in the folder : links/Detailed/



.


Andreas

Dr.Windows








Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
3. Edit nph-build.cgi

3.1 Insert code of # Einschub EchteURL # into sub build_update_newpop
3.2 Insert code of # Einschub Delete $echteURLalt ---- nph-build.cgi # into sub build_update_newpop


Find these lines in sub build_update_newpop:

Code:
print DBTMP &join_encode (&array_to_hash(0, @values));
}
close DB;
close DBTMP;


and insert the following code above print DBTMP &join_encode (&array_to_hash(0, @values)); :


Code:

####################### Einschub $ Echte URL ###################################
##### Variante 1 : Detailed Folder ####

my($esc) = $values[$db_title];
$esc = &cleanup($esc);

## Kategorie hinzufügen - Now let`s add the category:
my($esd) = $values[$db_category] ."-";
$esd =~ s/\//-/g;
$esd =~ s/_/-/g;

## <%ID%> hinzufügen - Now let`s add the $db_key
$esd = $values[$db_key] ."-" .$esd;

$esd = $esd .$esc;

$esd =~ tr/-/-/s;
$esd =~ tr/--/-/s; # get rid of multiple - charakters
$esd =~ tr/[A-Z]/[a-z]/; # change all letters to lowercase

$values[$db_echteURL] = $esd;
$echteURL = $esd;

## <%echteURL%> = 3043-grafik-bildbearbeitung-speziell-fuer-soko

####################### Einschub $ Echte URL ###################################

####################### Einschub Delete $echteURLalt --- nph-build.cgi ###################################
##### Delete updated entries if Titel or Kategorie had been changed ####

if ($values[$db_echteURLalt] ne "") {
unlink("$values[$db_echteURLalt]");
$values[$db_echteURLalt] = "";
}
####################### Einschub Delete $echteURLalt ######################################################




3.3 Edit sub build_detailed_view

Code:

sub build_detailed_view {
# --------------------------------------------------------

my (@values, $id, %rec, $count, $days_old);


if ($build_detail_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}
print "\t";
open (DB, "<$db_file_name") or &cgierr("Kann die Datei bzw. Verzeichnis nicht öffnen: $db_file_name. Grund: $!");
LINE: while (<DB>) {
/^#/ and next LINE;
/^\s*$/ and next LINE;
chomp;
@values = &split_decode ($_);
$days_old = &days_old($rec{'Datum'});
$id = $values[$db_key_pos];
%rec = &array_to_hash (0, @values);

$echteURL = $rec{'echteURL'};

$title_unlinked = "Supernature Forum Testinstallation" ." : " .&build_unlinked_title ("$rec{'Kategorie'}/$rec{'Titel'}");
$title_linked = &build_linked_title ("$rec{'Kategorie'}/$rec{'Titel'}");
$category_clean = &build_clean ("$rec{'Kategorie'}");
$thiscat = ("$rec{'Kategorie'}");
open (DETAIL, ">$build_detail_path/$echteURL$build_extension") or &cgierr ("Kann die Detailierten Seiten nicht erstellen: $build_detail_path/$echteURL$build_extension. Grund: $!");

print DETAIL &site_html_detailed (%rec);
close DETAIL;
$use_html ?
print qq~<a href="$build_detail_url/$echteURL$build_extension" target="_blank">$echteURL</a> ~ :
print qq~$echteURL ~;
(++$count % 10) or print "\n\t";
}
close DB;
print "\n";
}



.


Andreas

Dr.Windows








Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
4. New subroutine in db_utils.pl

Add this new sub at the end of db_utils.pl :

Code:

sub cleanup {
#-----------------------------------------
# get rid of extra characters

my($input) = shift;

$input =~ s/ä/ae/g;
$input =~ s/Ä/Ae/g;
$input =~ s/ö/oe/g;
$input =~ s/Ö/Oe/g;
$input =~ s/ü/ue/g;
$input =~ s/Ü/Ue/g;
$input =~ s/ß/ss/g;

$input =~ s/\@/-at-/g; # @
$input =~ s/\//-/g; # /
$input =~ s/\&/\-und-/g; # &
$input =~ s/\%/\-Prozent-/g; # %
$input =~ s/ /\-/g; # Leerzeichen - empty space
$input =~ s/\(/\-/g; # (
$input =~ s/\)/\-/g; # )
$input =~ s/!/\-/g; # !
$input =~ s/_/-/g;
$input =~ s/\+/\-und-/g; # +
$input =~ s/,/\-/g; # ,
$input =~ s/\>/\-/g; # >
$input =~ s/\:/\-/g; # :
$input =~ s/®/\-/g; # ®
$input =~ s/©/\-/g; # ©
$input =~ s/º/\-/g; # Nº
$input =~ s/\«/\-/g; # «
$input =~ s/\»/\-/g; # »
$input =~ s/\*/\-/g; # *
$input =~ s/²/\-/g; # ²
$input =~ s/\?/\-/g; # ?
$input =~ s/\./\-/g; # .
$input =~ s/`/\-/g; # `
$input =~ s/´/\-/g; # ´
$input =~ s/\'/\-/g; # '
$input =~ s/’n/\-/g; # ’
$input =~ s/\{/\-/g; # {
$input =~ s/\}/\-/g; # }
$input =~ s/\[/\-/g; # [
$input =~ s/\]/\-/g; # ]

$esc =~ s/^\s-|\s-$//gs;
$esc =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$esc =~ s/([^a-zA-Z0-9_\-.()[]%ae!+,>%O9)/uc sprintf("%%%02x",ord($1))/eg;

$esc =~ s/\%20/\-/g; #
$esc =~ s/\%23/\-/g; #
$esc =~ s/\%09/\-/g; #
$esc =~ tr/--/-/s; # get rid of multiple - charakters

return $input;
}

.


Andreas

Dr.Windows








Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
5. Edit detail.cgi

Open detail.cgi and edit sub main :


Code:

sub main {
# --------------------------------------------------------
%in = &parse_form();

my (%rec) = &get_record ($in{'ID'});

unless ($in{'ID'}) {
&html_print_headers;
print &site_html_detailed_error ("Kein Link angegeben."); #future versions will load a form instead of an error
}

#### Leitet altes URL Format auf neues HTML Format um:
elsif ($rec{$db_key} eq $in{'ID'}) {

my ($esd) = "http://.../links/Detailiert/" .$rec{'echteURL'} .".html";
print "Location: $esd\n\n";
}


# Original Code:
# elsif ($rec{$db_key} eq $in{'ID'}) {
# $title_unlinked = &build_unlinked_title ("$rec{'Kategorie'}/$rec{'Titel'}");
# $title_linked = &build_linked_title ("$rec{'Kategorie'}/$rec{'Titel'}");
# $thiscat = $rec{'Kategorie'};
# &html_print_headers;
# print &site_html_detailed (%rec);
# }
else {
&html_print_headers;
print &site_html_detailed_error ("Link $in{'ID'} nicht gefunden.");
}
}

###
# Can't require nph-build -- have to copy this stuff :-)
###


Explanation:

The result is that old search engine entries are still valid and you dont even have to change entries in your html templates.

All entries like : http://.../cgi-bin/detail.cgi?ID=4964
will be redirected to their static html pages.

.


Andreas

Dr.Windows








Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
6. Edit site_html_templates.pl

Find the following lines in sub site_html_detailed :

Code:
# If the link is not new, check to see if it has been updated.

elsif (&compare_dates($rec{'Datum'}, $rec{'Anmeldedatum'})) {

# Calculate age of link based on Date Modified, not Date Added.

$days_old = &days_old($rec{'Datum'});

if ($days_old <= $db_new_cutoff && $rec{'istUpdate'} ne "Nein") { $new_mod_img = qq~ $updated~; }

}

and change them to :

Code:

# If the link is not new, check to see if it has been updated.

elsif (&compare_dates($rec{'Datum'}, $rec{'Anmeldedatum'})) {

# Calculate age of link based on Date Modified, not Date Added.

$days_old = &days_old($rec{'Datum'});

if ($days_old <= $db_new_cutoff && $rec{'istUpdate'} ne "Nein") { $new_mod_img = qq~ $updated~; }
if ($days_old > $db_newupdate_cutoff ) { $new_mod_img = qq~ ~; }

}


Ignore :
&& $rec{'istUpdate'} ne "Nein" : because this is part of an other mod and not important for this mod.


Add:
echteURL => $echteURL,

.


Andreas

Dr.Windows








Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
7. Edit aendern.cgi (aendern.cgi is used for updating entries in links.db )

Insert in sub process-form :

Code:

####################### Einschub Delete $echteURLalt --- aendern.cgi ###################################
##### Delete updated entries if Titel or Kategorie had been changed ####

my($esc)= $original{'Titel'};
$esc = &cleanup($esc);

## Kategorie hinzufügen - Now let`s add the category:
my($esd) = $original{'Kategorie'} ."-";
$esd =~ s/\//-/g;
$esd =~ s/_/-/g;

## <%ID%> hinzufügen - Now let`s add the $db_key
$esd = $original{'ID'} ."-" .$esd;

$esd = $esd .$esc;

$esd =~ tr/-/-/s;
$esd =~ tr/--/-/s; # get rid of multiple - charakters
$esd =~ tr/[A-Z]/[a-z]/; # change all letters to lowercase


$in{$db_cols[$db_echteURLalt]} = $build_detail_path ."/" .$esd .$build_extension;

# $values[$db_echteURLalt] = $esd;

####################### Einschub Delete $echteURLalt #####################################################

Example:

Code:
sub process_form {
# --------------------------------------------------------
my ($key, $status, @values, $found, $esc, $esd, $del);
local (%original);
local (%proof);

!$in{'Current URL'} and &site_html_modify_failure ("Du hast keine URL eingetragen !") and return;


open (DB, "<$db_file_name") or &cgierr("Fehler. Kann die Datei bzw. Verzeichnis nicht öffnen: $db_file_name. Grund: $!");
$found = 0;
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);

if ($data[$db_key] eq $in{'Current URL'}) {

$in{$db_key} = $data[0];
$found = 1;
%original = &array_to_hash (0, @data);
last LINE;
}
}
close DB;
!$found and &site_html_modify_failure ("Diese URL wurde in der Datenbank nicht gefunden.") and return;


foreach $key (keys %add_system_fields) {
$in{$key} = $original{$key};
}


$in{$db_cols[$db_dateadded]} = $original{'Anmeldedatum'};
$in{$db_cols[$db_modified]} = &get_date;


####################### Einschub Delete $echteURLalt --- aendern.cgi ###################################
##### Delete updated entries if Titel or Kategorie had been changed ####

my($esc)= $original{'Titel'};
$esc = &cleanup($esc);

## Kategorie hinzufügen - Now let`s add the category:
my($esd) = $original{'Kategorie'} ."-";
$esd =~ s/\//-/g;
$esd =~ s/_/-/g;

## <%ID%> hinzufügen - Now let`s add the $db_key
$esd = $original{'ID'} ."-" .$esd;

$esd = $esd .$esc;

$esd =~ tr/-/-/s;
$esd =~ tr/--/-/s; # get rid of multiple - charakters
$esd =~ tr/[A-Z]/[a-z]/; # change all letters to lowercase


$in{$db_cols[$db_echteURLalt]} = $build_detail_path ."/" .$esd .$build_extension;

# $values[$db_echteURLalt] = $esd;

####################### Einschub Delete $echteURLalt #####################################################




$in{$db_cols[$db_isnewupdate]} = "Ja";
$in{$db_cols[$db_isnew]} = "Nein";

&check_exclude($in{'Kategorie'});
$status = &validate_record(%in);
if ($status eq "ok") {

open (MOD, "<$db_modified_name") or &cgierr ("Fehler. Kann die Datei bzw. Verzeichnis nicht öffnen: $db_modified_name. Grund: $!");
while (<MOD>) {
chomp;
@values = split /\|/;
if ($values[0] eq $in{$db_key}) {
close MOD;
&site_html_modify_failure("Dein Antrag auf die Linkänderung wurde bereits abgeschickt.");
return;
}
}
close MOD;


open (MOD, ">>$db_modified_name") or &cgierr("Fehler. Kann die Datei bzw. Verzeichnis nicht öffnen: $db_modified_name. Grund: $!");
flock(MOD, $LOCK_EX) unless (!$db_use_flock);
print MOD &join_encode(%in);
close MOD;


&send_email;

&site_html_modify_success;
}
else {

&site_html_modify_failure($status);
}
}


.


Andreas

Dr.Windows








Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
Attachment : links.def --- Post #29


Andreas

Dr.Windows








Quote Reply
Re: [SevenSpirits] Search Engine Friendly Links II - Link Title instead of ID In reply to
We built in this mod into our public Download Section : http://downloads.supernature-forum.de/links/

As you can see we changed the mod a littlebit :
Instead of <%ID%>-<%Category%>-<%Title%> we only use <%ID%>-<%Title%>.
(The link becomes smaller this way)


Feel free to visit our site and to try out the functions there.



.


Andreas

Dr.Windows








> >