📄 addform.pm
字号:
# $Id: AddForm.pm,v 1.45 2006/01/14 00:44:02 martin Exp $## Copyright 2005 Nature Publishing Group# 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.## The Bibliotech::Component::AddForm class provides an add form, an edit form,# and an add comment form.package Bibliotech::Component::AddForm;use strict;use base 'Bibliotech::Component';use Bibliotech::Const;use Bibliotech::Component::List;use constant LOOK_UP_LABEL => 'Look Up';sub last_updated_basis { ('NOW'); # temporarily fix POST bug #('DBI', 'LOGIN', shift->include_basis('/addwelcome'))}sub html_content { my ($self, $class, $verbose, $main, $action) = @_; my $bibliotech = $self->bibliotech; my $command = $bibliotech->command; my $popup = $command->is_popup; my $cgi = $bibliotech->cgi; my $location = $bibliotech->location; my ($add, $addcomment, $edit) = (0, 0, 0); if (!$action or $action eq 'add') { $action = 'add'; $add = 1; } elsif ($action eq 'addcomment') { $addcomment = 1; } elsif ($action eq 'edit') { $edit = 1; } my $user = $self->getlogin; unless ($user) { my $msg; if ($action eq 'add') { if ($popup) { $msg = 'to add a bookmark'; } else { $self->remember_current_uri if $cgi->param('uri'); # special welcome text instead return Bibliotech::Page::HTML_Content->simple($self->include('/addwelcome')); } } elsif ($action eq 'addcomment') { $msg = 'to add a comment'; } elsif ($action eq 'edit') { $msg = 'to edit a bookmark'; } else { $msg = 'to perform this action'; } return $self->saylogin($msg); } my $validationmsg; my $button = $cgi->param('button'); if ($button =~ /^Add/ or $button =~ /^Save/ or ($button ne LOOK_UP_LABEL and $cgi->param('uri') and $cgi->param('tags')) ) { my $uri = eval { $self->call_action_with_cgi_params($action, $user, $cgi)->bookmark->url; }; if ($@) { $validationmsg = $@; } else { my $continue = $cgi->param('continue') || 'library'; die "Location: $uri\n" if $continue eq 'return'; if ($continue =~ /^comments/) { my $hash = Bibliotech::Bookmark->new($uri)->hash; die "Location: $location$continue/uri/$hash\n"; } if ($continue eq 'close') { return Bibliotech::Page::HTML_Content->new({html_parts => {main => ''}, javascript_onload => 'window.close()'}); } if ($continue eq 'library') { my $username = $user->username; die "Location: ${location}recent/user/$username\n"; } my %confirmation = (add => 'Your '.URI_TERM.' has been added.', edit => 'Your changes have been saved.', addcomment => 'Your comment has been added.'); return Bibliotech::Page::HTML_Content->simple($cgi->p($confirmation{$action} || 'Done.'). $cgi->p({class => 'closebutton'}, $cgi->button(-value => 'Close', -class => 'buttonctl', -onclick => 'window.close()'))); } } my $uri = $cgi->param('uri'); $uri = undef unless $main; if ($uri and Bibliotech::Bookmark::is_hash_format($uri)) { my ($bookmark) = Bibliotech::Bookmark->search(hash => $uri) or die "Hash not found as a known URI.\n"; $cgi->param('uri', $uri = $bookmark->url); } my $title = $self->cleanparam($cgi->param('title')); #$cgi->param(usertitle => $title) if $title and !defined($cgi->param('usertitle')); my $bookmark; if ($uri) { ($bookmark) = Bibliotech::Bookmark->search(url => $uri); if (!$bookmark) { eval { $bookmark = $bibliotech->preadd(uri => $uri, title => $title); if ((my $new_uri = $bookmark->url) ne $uri) { $cgi->param(uri => ($uri = $new_uri)); } }; $validationmsg = $@ if $@; } if ($bookmark) { $title = $bookmark->title; $cgi->param(title => $title) unless $cgi->param('title'); my $usertitle = $title; if (my $citation = $bookmark->citation) { if (my $citation_title = $citation->title) { $usertitle = $citation_title; } } $cgi->param(usertitle => $usertitle) unless $cgi->param('usertitle'); $bookmark->adding(1); # temp column, suppresses copy link in html_output if (!$button) { my ($user_bookmark) = Bibliotech::User_Bookmark->search(user => $user, bookmark => $bookmark); if ($user_bookmark) { $bookmark->for_user_bookmark($user_bookmark); if ($add and $main) { # trying to add an already added bookmark my $editlink = 'edit'.($popup ? 'popup' : ''); my $hash = $bookmark->hash; die "Location: $location$editlink?note=alreadyknown&uri=$hash\n"; } if ($edit) { $cgi->param(usertitle => $user_bookmark->title); $cgi->param(description => $user_bookmark->description); $cgi->param(tags => join(' ', map(/ / ? "\"$_\"" : $_, map($_->name, $user_bookmark->tags)))); my $lastcomment = $user_bookmark->last_comment; if ($lastcomment) { my $entry = $lastcomment->entry; $entry =~ s| *<br ?/?>|\n|g; $cgi->param(lastcomment => $entry); } $cgi->param(private => $user_bookmark->private); if (my $private_gang = $user_bookmark->private_gang) { $cgi->param(group => $private_gang->name); $cgi->param(private => 2); # for radio group } if (my $private_until = $user_bookmark->private_until) { if ($private_until->has_been_reached) { $cgi->param(private => 0); # for radio group } else { $cgi->param(embargo => $private_until->utc->ymdhm); } } $cgi->param(mywork => $user_bookmark->user_is_author); } } else { if (!$add and $main) { # trying to edit or addcomment for a non-copied bookmark my $add = 'add'.($popup ? 'popup' : ''); my $hash = $bookmark->hash; die "Location: $location$add?uri=$hash\n"; } } if ($add) { if (my $from = $cgi->param('from')) { if (my $from_user = Bibliotech::User->normalize_option({user => $from})) { my ($user_bookmark) = Bibliotech::User_Bookmark->search(user => $from_user, bookmark => $bookmark); $bookmark->for_user_bookmark($user_bookmark) if $user_bookmark; } } } } } } # parameter cleaning - need this to keep utf-8 output from messing up on an update reload foreach (qw/usertitle description tags comment/) { my $value = $self->cleanparam($cgi->param($_)); $cgi->param($_ => $value) if $value; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -