From 9f60540e54e4a6ce6c8b99b8af033d61769b5b7c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20=27banana=27=20Ke=C3=9Fler?= Date: Tue, 7 Jun 2011 15:48:00 +0200 Subject: [PATCH] tag suggest was not working correctly and pl scripts should be cgi scripts --- ChangeLog | 231 +++++++++--------- lib/Insipid/DBInstall.pm | 165 ++++++------- lib/Insipid/Database.pm | 299 ++++++++++++------------ lib/js/tagsSuggest.js | 2 +- lib/{tagsSuggest.pl => tagsSuggest.cgi} | 12 +- 5 files changed, 356 insertions(+), 353 deletions(-) rename lib/{tagsSuggest.pl => tagsSuggest.cgi} (84%) diff --git a/ChangeLog b/ChangeLog index 6169f5d..eeadd79 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,114 +1,117 @@ -Tue Jul 14 21:38 EST 2009 Luke Reeve - - * Fix the option "proxy_host" not being saved correctly. - -Sun Jul 12 11:00 EST 2009 Luke Reeves - - * Fixed the Perl 5.10 module reloading bug. - * Fixed snapshotting functionality - -Sat Jul 11 23:30 EST 2009 Luke Reeves - - * Dusted off the codebase, kicked the tires and finally - finished off the git migration. - -Mon Mar 27 18:59 EST 2006 Luke Reeves - - * Added an option for disabling mod_rewrite support - * Added a prefix option for database tables - -Tue Mar 21 19:34 EST 2006 Luke Reeves - - * Fix the export system - -Tue Feb 21 12:30 EST 2006 Luke Reeves - - * Fix up database connectivity for newer PostgreSQL - libraries - * Incorporate patch from Paul Boin that allows importing - of regular del.icio.us backups (as opposed to only - supporting exports as before) - -Mon Nov 21 12:41 EST 2005 Luke Reeves - - * Fixed some of the cleanup process for snapshot deletion - * Added a "Fetch Related" function, so that the snapshot - tool can grab related objects - * Work on the tag tools - delete and rename tags - -Fri Nov 04 09:00 EST 2005 Luke Reeves - - * Database fix (thanks to Jutta Horstmann) - * Remove export and import to server-side files, since the - standalone tools can easily accomplish that - -Fri Sep 23 07:35 EST 2005 Luke Reeves - - * Enable taint mode for all the modules/scripts. - -Thu Sep 22 12:15 EST 2005 Luke Reeves - - * Remove dependency on App::Config, since all it does is - read a simple text file. - * Remove dependency on CGI::Session in lieu of a built-in - session management system - * Fixed up database tables - -Mon Sep 19 20:37 EST 2005 Luke Reeves - - * Add the ability to drill-down into more details on cached - objects. - * Fix up the standalone import and export tools. - * Show the correct total size of snapshots in the snapshot - view. - -Fri Sep 16 21:02 EST 2005 Luke Reeves - - * Move tools to a separate directory - * Add a standalone export script. - * Fix bugs in the export concerning character encoding. - -Fri Sep 16 12:30 EST 2005 Luke Reeves - - * Fix a couple possible installation issues on PostgreSQL - systems. - -Mon Sep 05 22:28 EST 2005 Luke Reeves - - * Major code cleanup (splitting the main CGI file into multiple, - more maintainable ones inside of the lib/Insipid directory) - * Bugfix for adding duplicate items not being flagged as such - -Tue Aug 09 22:05 EST 2005 Luke Reeves - - * Added proxy support for fetching pages - * Fix blob size for MySQL tables - * Added a toggle to not redirect when a mark is added - * Added a toggle to snapshot a page when bookmarked - * Support passing the Referer header when snapshotting a page. - * Added support for If-Modified-Since requests to cached objects. - * Added a Last-Modified header for cache objects. - -Thu Jul 21 21:35 EST 2005 Luke Reeves - - * Fix a bunch of errors concerning PostgreSQL and the snapshots, - as well as other bug fixes. - -Sun Jul 17 15:19 EST 2005 Luke Reeves - - * Added the page cache feature, so a user can take snapshots of pages - that have been bookmarked. - -Tue Jul 05 21:58 EST 2005 Luke Reeves - - * Added addition of tags (like Documentation + Java) to get - intersections of bookmarks. - -Fri May 27 11:05 JST 2005 Luke Reeves - - * Added postgresql backend support (submitted by Stephen Patterson) - -Mon Apr 25 21:00 EST 2005 Luke Reeves - - * Add a search box, with the option of showing it to non-logged in - users. +06.2011 CEST jumpin.banana + * tag suggest was not working correctly. + +Tue Jul 14 21:38 EST 2009 Luke Reeve + + * Fix the option "proxy_host" not being saved correctly. + +Sun Jul 12 11:00 EST 2009 Luke Reeves + + * Fixed the Perl 5.10 module reloading bug. + * Fixed snapshotting functionality + +Sat Jul 11 23:30 EST 2009 Luke Reeves + + * Dusted off the codebase, kicked the tires and finally + finished off the git migration. + +Mon Mar 27 18:59 EST 2006 Luke Reeves + + * Added an option for disabling mod_rewrite support + * Added a prefix option for database tables + +Tue Mar 21 19:34 EST 2006 Luke Reeves + + * Fix the export system + +Tue Feb 21 12:30 EST 2006 Luke Reeves + + * Fix up database connectivity for newer PostgreSQL + libraries + * Incorporate patch from Paul Boin that allows importing + of regular del.icio.us backups (as opposed to only + supporting exports as before) + +Mon Nov 21 12:41 EST 2005 Luke Reeves + + * Fixed some of the cleanup process for snapshot deletion + * Added a "Fetch Related" function, so that the snapshot + tool can grab related objects + * Work on the tag tools - delete and rename tags + +Fri Nov 04 09:00 EST 2005 Luke Reeves + + * Database fix (thanks to Jutta Horstmann) + * Remove export and import to server-side files, since the + standalone tools can easily accomplish that + +Fri Sep 23 07:35 EST 2005 Luke Reeves + + * Enable taint mode for all the modules/scripts. + +Thu Sep 22 12:15 EST 2005 Luke Reeves + + * Remove dependency on App::Config, since all it does is + read a simple text file. + * Remove dependency on CGI::Session in lieu of a built-in + session management system + * Fixed up database tables + +Mon Sep 19 20:37 EST 2005 Luke Reeves + + * Add the ability to drill-down into more details on cached + objects. + * Fix up the standalone import and export tools. + * Show the correct total size of snapshots in the snapshot + view. + +Fri Sep 16 21:02 EST 2005 Luke Reeves + + * Move tools to a separate directory + * Add a standalone export script. + * Fix bugs in the export concerning character encoding. + +Fri Sep 16 12:30 EST 2005 Luke Reeves + + * Fix a couple possible installation issues on PostgreSQL + systems. + +Mon Sep 05 22:28 EST 2005 Luke Reeves + + * Major code cleanup (splitting the main CGI file into multiple, + more maintainable ones inside of the lib/Insipid directory) + * Bugfix for adding duplicate items not being flagged as such + +Tue Aug 09 22:05 EST 2005 Luke Reeves + + * Added proxy support for fetching pages + * Fix blob size for MySQL tables + * Added a toggle to not redirect when a mark is added + * Added a toggle to snapshot a page when bookmarked + * Support passing the Referer header when snapshotting a page. + * Added support for If-Modified-Since requests to cached objects. + * Added a Last-Modified header for cache objects. + +Thu Jul 21 21:35 EST 2005 Luke Reeves + + * Fix a bunch of errors concerning PostgreSQL and the snapshots, + as well as other bug fixes. + +Sun Jul 17 15:19 EST 2005 Luke Reeves + + * Added the page cache feature, so a user can take snapshots of pages + that have been bookmarked. + +Tue Jul 05 21:58 EST 2005 Luke Reeves + + * Added addition of tags (like Documentation + Java) to get + intersections of bookmarks. + +Fri May 27 11:05 JST 2005 Luke Reeves + + * Added postgresql backend support (submitted by Stephen Patterson) + +Mon Apr 25 21:00 EST 2005 Luke Reeves + + * Add a search box, with the option of showing it to non-logged in + users. diff --git a/lib/Insipid/DBInstall.pm b/lib/Insipid/DBInstall.pm index 1d726dc..f1b075a 100755 --- a/lib/Insipid/DBInstall.pm +++ b/lib/Insipid/DBInstall.pm @@ -1,82 +1,83 @@ -#!/usr/bin/perl -# -# Copyright (C) 2008 Luke Reeves -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA -# - -package Insipid::DBInstall; - -use strict; -use warnings; - -use Insipid::Config; -use Insipid::Schemas; - -use DBI qw/:sql_types/;; -use vars qw($version); - -use Exporter (); -our (@ISA, @EXPORT); - -@ISA = qw(Exporter); -@EXPORT = qw(install); - -sub install { - my ($sth, $dbname, $dbuser, $dbpass, $dbtype, $dsn, $dbh, @creates); - - $dbname = getconfig('dbname'); - $dbuser = getconfig('dbuser'); - $dbpass = getconfig('dbpass'); - - if(defined(getconfig('dbtype'))) { - $dbtype = getconfig('dbtype'); - } else { - $dbtype = 'mysql'; - } - - $dsn = "DBI:$dbtype:dbname=$dbname;host=localhost"; - $dbh = DBI->connect($dsn, $dbuser, $dbpass, { 'RaiseError' => 0}) or die $DBI::errstr; - - print "Content-Type: text/html\r\n\r\n"; - print "Insipid Installation"; - - print "

Creating tables..."; - - if($dbtype eq 'mysql') { - @creates = split(/\;/, $createMySQL); - } else { - @creates = split(/\;/, $createPostgres); - } - - foreach(@creates) { - my $sql = $_; - if(length($sql) > 2) { - $sth = $dbh->prepare($sql); - $sth->execute() or print "
Error executing \"$sql\" - $DBI::errstr
"; - } - } - print " done!

"; - - print "

Insipid's database has been installed. You can reload this " . - "page to start using Insipid.

"; - - print ""; - -} - -1; -__END__ +#!/usr/bin/perl +# +# Copyright (C) 2008 Luke Reeves +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA +# + +package Insipid::DBInstall; + +use strict; +use warnings; + +use Insipid::Config; +use Insipid::Schemas; + +use DBI qw/:sql_types/;; +use vars qw($version); + +use Exporter (); +our (@ISA, @EXPORT); + +@ISA = qw(Exporter); +@EXPORT = qw(install); + +sub install { + my ($sth, $dbname, $dbuser, $dbpass, $dbhost, $dbtype, $dsn, $dbh, @creates); + + $dbname = getconfig('dbname'); + $dbuser = getconfig('dbuser'); + $dbpass = getconfig('dbpass'); + $dbhost = getconfig('dbhost'); + + if(defined(getconfig('dbtype'))) { + $dbtype = getconfig('dbtype'); + } else { + $dbtype = 'mysql'; + } + + $dsn = "DBI:$dbtype:dbname=$dbname;host=$dbhost"; + $dbh = DBI->connect($dsn, $dbuser, $dbpass, { 'RaiseError' => 0}) or die $DBI::errstr; + + print "Content-Type: text/html\r\n\r\n"; + print "Insipid Installation"; + + print "

Creating tables..."; + + if($dbtype eq 'mysql') { + @creates = split(/\;/, $createMySQL); + } else { + @creates = split(/\;/, $createPostgres); + } + + foreach(@creates) { + my $sql = $_; + if(length($sql) > 2) { + $sth = $dbh->prepare($sql); + $sth->execute() or print "
Error executing \"$sql\" - $DBI::errstr
"; + } + } + print " done!

"; + + print "

Insipid's database has been installed. You can reload this " . + "page to start using Insipid.

"; + + print ""; + +} + +1; +__END__ diff --git a/lib/Insipid/Database.pm b/lib/Insipid/Database.pm index 11278da..f6463f3 100755 --- a/lib/Insipid/Database.pm +++ b/lib/Insipid/Database.pm @@ -1,149 +1,150 @@ -#!/usr/bin/perl -# -# Copyright (C) 2008 Luke Reeves -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA -# - -package Insipid::Database; - -use strict; -use warnings; - -use Insipid::Config; -use Insipid::Schemas; - -use DBI qw/:sql_types/;; -use vars qw($version); - -use Exporter (); -our (@ISA, @EXPORT); - -@ISA = qw(Exporter); -@EXPORT = qw($dbname $dbuser $dbpass $dsn $dbh $dbtype get_option - install $version $tag_url $feed_url $full_url $snapshot_url - export_options $dbprefix); - -our ($dsn, $dbh, $dbname, $dbuser, $dbpass, $snapshot_url, - $dbtype, $tag_url, $feed_url, $full_url, $dbprefix); - -$dbname = getconfig('dbname'); -$dbuser = getconfig('dbuser'); -$dbpass = getconfig('dbpass'); - -if(defined(getconfig('dbtype'))) { - $dbtype = getconfig('dbtype'); -} else { - $dbtype = 'mysql'; -} - -$dsn = "DBI:$dbtype:dbname=$dbname;host=localhost"; -$dbh = DBI->connect($dsn, $dbuser, $dbpass, { 'RaiseError' => 0}) or die $DBI::errstr; - -my %options; - -sub export_options { - my ($writer) = (@_); - my ($sth); - - $writer->startTag('options'); - $sth = $dbh->prepare("select name, value from $tbl_options"); - $sth->execute(); - while(my $row = $sth->fetchrow_hashref) { - if($row->{name} ne 'version') { - $writer->emptyTag('option', - 'name' => $row->{name}, - 'value' => $row->{value}); - } - } - - $writer->endTag('options'); -} - -sub dbupgrade { - my $sql = "update $tbl_options set value = ? where (name = ?)"; - my $sth = $dbh->prepare($sql); - $sth->execute($version, 'version'); - - $sql = "insert into $tbl_options(name, value, description) - values(?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute('version', $version, 'Internal Insipid version'); - $sth->execute('use_rewrite', 'yes', 'Use mod_rewrite - disable this if you do not want to use mod_rewrite.'); - - # Delete the old sessions table - $sql = 'drop table sessions'; - $sth = $dbh->prepare($sql); - $sth->execute(); - - # Create the new session table if it's not there. - $sql = "create table $tbl_authentication ( - session_id varchar(32), - create_time int, - primary key(session_id))"; - $sth = $dbh->prepare($sql); - $sth->execute(); - if($dbh->errstr) { - print STDERR $dbh->errstr; - } - - return; -} - -sub get_option { - my ($name) = (@_); - - if(keys (%options) == 0) { - reload_options(); - } - - # Determine if we need to upgrade the database - if($version ne $options{'version'}) { - print STDERR "Upgrading schema from $options{'version'} to $version.\n"; - dbupgrade(); - reload_options(); - } - - return $options{$name}; -} - -sub reload_options { - my $sql = "select name, value from $tbl_options"; - my $sth = $dbh->prepare($sql); - $sth->execute() or die $DBI::errstr; - - while(my $hr = $sth->fetchrow_hashref) { - $options{$hr->{'name'}} = $hr->{'value'}; - } -} - -# This configures the URLs in the application to support mod_rewrite or -# a webserver sans mod_rewrite. -if(get_option('use_rewrite') eq 'yes') { - $tag_url = $site_url . '/bookmarks/'; - $feed_url = $site_url . '/feeds/bookmarks'; - $full_url = $site_url . '/bookmarks'; - $snapshot_url = $site_url . '/snapshot/'; -} else { - $tag_url = 'insipid.cgi?tag='; - $feed_url = $site_url . '/insipid.cgi?op=rss&tag='; - $full_url = $site_url . '/insipid.cgi'; - $snapshot_url = 'insipid.cgi?op=viewsnapshot&md5='; -} - - -1; -__END__ +#!/usr/bin/perl +# +# Copyright (C) 2008 Luke Reeves +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA +# + +package Insipid::Database; + +use strict; +use warnings; + +use Insipid::Config; +use Insipid::Schemas; + +use DBI qw/:sql_types/;; +use vars qw($version); + +use Exporter (); +our (@ISA, @EXPORT); + +@ISA = qw(Exporter); +@EXPORT = qw($dbname $dbuser $dbpass $dsn $dbh $dbtype get_option + install $version $tag_url $feed_url $full_url $snapshot_url + export_options $dbprefix); + +our ($dsn, $dbh, $dbname, $dbuser, $dbpass, $dbhost, $snapshot_url, + $dbtype, $tag_url, $feed_url, $full_url, $dbprefix); + +$dbname = getconfig('dbname'); +$dbuser = getconfig('dbuser'); +$dbpass = getconfig('dbpass'); +$dbhost = getconfig('dbhost'); + +if(defined(getconfig('dbtype'))) { + $dbtype = getconfig('dbtype'); +} else { + $dbtype = 'mysql'; +} + +$dsn = "DBI:$dbtype:dbname=$dbname;host=$dbhost"; +$dbh = DBI->connect($dsn, $dbuser, $dbpass, { 'RaiseError' => 0}) or die $DBI::errstr; + +my %options; + +sub export_options { + my ($writer) = (@_); + my ($sth); + + $writer->startTag('options'); + $sth = $dbh->prepare("select name, value from $tbl_options"); + $sth->execute(); + while(my $row = $sth->fetchrow_hashref) { + if($row->{name} ne 'version') { + $writer->emptyTag('option', + 'name' => $row->{name}, + 'value' => $row->{value}); + } + } + + $writer->endTag('options'); +} + +sub dbupgrade { + my $sql = "update $tbl_options set value = ? where (name = ?)"; + my $sth = $dbh->prepare($sql); + $sth->execute($version, 'version'); + + $sql = "insert into $tbl_options(name, value, description) + values(?, ?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute('version', $version, 'Internal Insipid version'); + $sth->execute('use_rewrite', 'yes', 'Use mod_rewrite - disable this if you do not want to use mod_rewrite.'); + + # Delete the old sessions table + $sql = 'drop table sessions'; + $sth = $dbh->prepare($sql); + $sth->execute(); + + # Create the new session table if it's not there. + $sql = "create table $tbl_authentication ( + session_id varchar(32), + create_time int, + primary key(session_id))"; + $sth = $dbh->prepare($sql); + $sth->execute(); + if($dbh->errstr) { + print STDERR $dbh->errstr; + } + + return; +} + +sub get_option { + my ($name) = (@_); + + if(keys (%options) == 0) { + reload_options(); + } + + # Determine if we need to upgrade the database + if($version ne $options{'version'}) { + print STDERR "Upgrading schema from $options{'version'} to $version.\n"; + dbupgrade(); + reload_options(); + } + + return $options{$name}; +} + +sub reload_options { + my $sql = "select name, value from $tbl_options"; + my $sth = $dbh->prepare($sql); + $sth->execute() or die $DBI::errstr; + + while(my $hr = $sth->fetchrow_hashref) { + $options{$hr->{'name'}} = $hr->{'value'}; + } +} + +# This configures the URLs in the application to support mod_rewrite or +# a webserver sans mod_rewrite. +if(get_option('use_rewrite') eq 'yes') { + $tag_url = $site_url . '/bookmarks/'; + $feed_url = $site_url . '/feeds/bookmarks'; + $full_url = $site_url . '/bookmarks'; + $snapshot_url = $site_url . '/snapshot/'; +} else { + $tag_url = 'insipid.cgi?tag='; + $feed_url = $site_url . '/insipid.cgi?op=rss&tag='; + $full_url = $site_url . '/insipid.cgi'; + $snapshot_url = 'insipid.cgi?op=viewsnapshot&md5='; +} + + +1; +__END__ diff --git a/lib/js/tagsSuggest.js b/lib/js/tagsSuggest.js index e8f12ef..eee91ab 100644 --- a/lib/js/tagsSuggest.js +++ b/lib/js/tagsSuggest.js @@ -71,7 +71,7 @@ $(document).ready(function() if (w.length > 1 && stopSuggesting == false) { $.ajax({ - url: 'lib/tagsSuggest.pl?' + w, + url: 'lib/tagsSuggest.cgi?' + w, dataType: 'html', success: function(o) { if (o.length > 0) { diff --git a/lib/tagsSuggest.pl b/lib/tagsSuggest.cgi similarity index 84% rename from lib/tagsSuggest.pl rename to lib/tagsSuggest.cgi index f20eec4..4e8d18e 100755 --- a/lib/tagsSuggest.pl +++ b/lib/tagsSuggest.cgi @@ -19,24 +19,22 @@ print $cgi->header(-type => "text/html", -charset => "utf-8"); # @return $out:string - HTML-formatted list of tags. my ($in) = shift; -if ($in =~ /^[0-9a-z:_]+/i) -{ +if ($in =~ /^[0-9a-z:_]+/i) { my ($sql, $sth); # The user has typed in the first two letters, look for a match. # Order suggestions by popularity. - $sql = "select $tbl_tags.name,count(*) from $tbl_tags + $sql = "select $tbl_tags.name, count(*) from `$tbl_tags` inner join $tbl_bookmark_tags on ($tbl_tags.id = $tbl_bookmark_tags.tag_id) - where ($tbl_tags.name LIKE '$in%') + where ($tbl_tags.name LIKE ".$dbh->quote($in.'%').") group by $tbl_tags.name - order by count( * ) desc"; + order by count(*) desc"; $sth = $dbh->prepare($sql); $sth->execute(); # external wrappers div.suggestlist>ul> ... /ul/div - if($sth->rows ne 0) - { + if($sth->rows ne 0) { my $out = ""; #$out .= "Content-Type: text/html; charset=UTF-8\n\n"; while(my @r = $sth->fetchrow_array()) { -- 2.39.5