[dw-free] Template Toolikt / Routing System
[commit: http://hg.dwscoalition.org/dw-free/rev/07180fbb157d]
http://bugs.dwscoalition.org/show_bug.cgi?id=2054
Remove HTML::Template from the ESN system. We should be using the
translation system for this sort of thing.
Patch by
mark.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2054
Remove HTML::Template from the ESN system. We should be using the
translation system for this sort of thing.
Patch by
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
Files modified:
- bin/checkconfig.pl
- cgi-bin/LJ/Comment.pm
- cgi-bin/LJ/Event.pm
- cgi-bin/LJ/Event/JournalNewComment.pm
- cgi-bin/LJ/HTML/Template.pm
-------------------------------------------------------------------------------- diff -r 8f4e3e7a0082 -r 07180fbb157d bin/checkconfig.pl --- a/bin/checkconfig.pl Sun Dec 13 09:57:28 2009 +0000 +++ b/bin/checkconfig.pl Sun Dec 13 10:04:06 2009 +0000 @@ -63,7 +63,6 @@ my %modules = ( "Class::Autouse" => { 'deb' => 'libclass-autouse-perl', }, "Digest::MD5" => { 'deb' => 'libmd5-perl', }, "Digest::SHA1" => { 'deb' => 'libdigest-sha1-perl', }, - "HTML::Template" => { 'deb' => 'libhtml-template-perl' }, "Image::Size" => { 'deb' => 'libimage-size-perl', }, "MIME::Lite" => { 'deb' => 'libmime-lite-perl', }, "MIME::Words" => { 'deb' => 'libmime-perl', }, diff -r 8f4e3e7a0082 -r 07180fbb157d cgi-bin/LJ/Comment.pm --- a/cgi-bin/LJ/Comment.pm Sun Dec 13 09:57:28 2009 +0000 +++ b/cgi-bin/LJ/Comment.pm Sun Dec 13 10:04:06 2009 +0000 @@ -1504,113 +1504,6 @@ sub format_html_mail { return _format_mail_both($self, $targetu, 1); } -# Collects common comment's props, -# and passes them into the given template -sub _format_template_mail { - my $self = shift; # comment - my $targetu = shift; # target user, who should be notified about the comment - my $t = shift; # LJ::HTML::Template object - template of the notification e-mail - croak "invalid targetu passed to format_template_mail" - unless LJ::isu($targetu); - - my $parent = $self->parent || $self->entry; - my $entry = $self->entry; - my $posteru = $self->poster; - - my $encoding = $targetu->mailencoding || 'UTF-8'; - my $can_unscreen = $self->is_screened && - LJ::Talk::can_unscreen($targetu, $entry->journal, $entry->poster, $posteru ? $posteru->username : undef); - - # set template vars - $t->param(encoding => $encoding); - - # comment data - $t->param(parent_userpic => ($parent->userpic) ? $parent->userpic->imgtag : ''); - $t->param(parent_profile_url => $parent->poster->profile_url); - $t->param(parent_username => $parent->poster->username); - $t->param(poster_userpic => ($self->userpic) ? $self->userpic->imgtag : '' ); - $t->param(poster_profile_url => $self->poster->profile_url); - $t->param(poster_username => $self->poster->username); - - # manage comment - $t->param(thread_url => $self->thread_url); - $t->param(entry_url => $self->entry->url); - $t->param(reply_url => $self->reply_url); - $t->param(unscreen_url => $self->unscreen_url) if $can_unscreen; - $t->param(delete_url => $self->delete_url) if $self->user_can_delete($targetu); - $t->param(want_form => ($self->is_active || $can_unscreen)); - $t->param(form_action => "$LJ::SITEROOT/talkpost_do"); - $t->param(hidden_fields => LJ::html_hidden - ( usertype => "user", - parenttalkid => $self->jtalkid, - itemid => $entry->ditemid, - journal => $entry->journal->username, - userpost => $targetu->username, - ecphash => LJ::Talk::ecphash($entry->jitemid, $self->jtalkid, $targetu->password) - ) . - ($encoding ne "UTF-8" ? - LJ::html_hidden(encoding => $encoding): - '' - ) - ); - - $t->param(jtalkid => $self->jtalkid); - $t->param(dtalkid => $self->dtalkid); - $t->param(ditemid => $entry->ditemid); - $t->param(journal_username => $entry->journal->username); - if ($self->parent) { - $t->param(parent_jtalkid => $self->parent->jtalkid); - $t->param(parent_dtalkid => $self->parent->dtalkid); - } - -} - -# Processes template for HTML e-mail notifications -# and returns the result of template processing. -sub format_template_html_mail { - my $self = shift; # comment - my $targetu = shift; # target user, who should be notified about the comment - my $t = shift; # LJ::HTML::Template object - template of the notification e-mail - - my $parent = $self->parent || $self->entry; - - $self->_format_template_mail($targetu, $t); - - # add specific for HTML params - $t->param(parent_text => LJ::Talk::Post::blockquote($parent->body_html)); - $t->param(poster_text => LJ::Talk::Post::blockquote($self->body_html)); - - my $email_subject = $self->subject_html; - $email_subject = "Re: $email_subject" if $email_subject and $email_subject !~ /^Re:/; - $t->param(email_subject => $email_subject); - - # parse template and return it - return $t->output; -} - -# Processes template for PLAIN-TEXT e-mail notifications -# and returns the result of template processing. -sub format_template_text_mail { - my $self = shift; # comment - my $targetu = shift; # target user, who should be notified about the comment - my $t = shift; # LJ::HTML::Template object - template of the notification e-mail - - my $parent = $self->parent || $self->entry; - - $self->_format_template_mail($targetu, $t); - - # add specific for PLAIN-TEXT params - $t->param(parent_text => $parent->body_raw); - $t->param(poster_text => $self->body_raw); - - my $email_subject = $self->subject_raw; - $email_subject = "Re: $email_subject" if $email_subject and $email_subject !~ /^Re:/; - $t->param(email_subject => $email_subject); - - # parse template and return it - return $t->output; -} - sub delete { my $self = shift; diff -r 8f4e3e7a0082 -r 07180fbb157d cgi-bin/LJ/Event.pm --- a/cgi-bin/LJ/Event.pm Sun Dec 13 09:57:28 2009 +0000 +++ b/cgi-bin/LJ/Event.pm Sun Dec 13 10:04:06 2009 +0000 @@ -442,40 +442,6 @@ sub all_classes { return $tm->all_classes; } -# Returns path to template file by event type for certain language, journal and e-mail section. -# -# @params: section = [subject | body_html | body_text] -# lang = [ en | ru | ... ] -# -# @returns: filename or undef if template could not be found. -# -sub template_file_for { - my $self = shift; - my %opts = @_; - - return unless LJ::is_enabled('template_files'); - - my $section = $opts{section}; - my $lang = $opts{lang} || 'default'; - my ($event_type) = (ref $self) =~ /\:([^:]+)$/; # - my $journal_name = $self->event_journal->user; - - # all ESN e-mail templates are located in: - # $LJHOME/templates/ESN/$event_type/$language/$journal_name - # - # go though file paths until found existing one - foreach my $file ( - "$event_type/$lang/$journal_name/$section.tmpl", - "$event_type/$lang/default/$section.tmpl", - "$event_type/default/$journal_name/$section.tmpl", - "$event_type/default/default/$section.tmpl", - ) { - $file = "$LJ::HOME/templates/ESN/$file"; # add common prefix - return $file if -e $file; - } - return undef; -} - sub format_options { my ($self, $is_html, $lang, $vars, $urls, $extra) = @_; diff -r 8f4e3e7a0082 -r 07180fbb157d cgi-bin/LJ/Event/JournalNewComment.pm --- a/cgi-bin/LJ/Event/JournalNewComment.pm Sun Dec 13 09:57:28 2009 +0000 +++ b/cgi-bin/LJ/Event/JournalNewComment.pm Sun Dec 13 10:04:06 2009 +0000 @@ -2,7 +2,6 @@ use strict; use strict; use Scalar::Util qw(blessed); use LJ::Comment; -use LJ::HTML::Template; use Carp qw(croak); use base 'LJ::Event'; @@ -91,14 +90,6 @@ sub as_email_subject { $entry_details = ' [ ' . $self->comment->journal->display_name . ' - ' . $self->comment->entry->ditemid . ' ]'; } - my $filename = $self->template_file_for(section => 'subject', lang => $lang); - if ($filename) { - # Load template file into template processor - my $t = LJ::HTML::Template->new(filename => $filename); - $t->param( subject => $self->comment->subject_html . $entry_details ); - return $t->output; - } - my $key = 'esn.mail_comments.subject.'; if ($self->comment->subject_orig) { return LJ::strip_html( $self->comment->subject_orig . $entry_details ); @@ -125,14 +116,6 @@ sub as_email_string { my ($self, $u) = @_; my $comment = $self->comment or return "(Invalid comment)"; - my $filename = $self->template_file_for(section => 'body_text', lang => $u->prop('browselang')); - if ($filename) { - # Load template file into template processor - my $t = LJ::HTML::Template->new(filename => $filename); - - return $comment->format_template_text_mail($u, $t) if $t; - } - return $comment->format_text_mail($u); } @@ -140,14 +123,6 @@ sub as_email_html { my ($self, $u) = @_; my $comment = $self->comment or return "(Invalid comment)"; - my $filename = $self->template_file_for(section => 'body_html', lang => $u->prop('browselang')); - if ($filename) { - # Load template file into template processor - my $t = LJ::HTML::Template->new(filename => $filename); - - return $comment->format_template_html_mail($u, $t) if $t; - } - return $comment->format_html_mail($u); } diff -r 8f4e3e7a0082 -r 07180fbb157d cgi-bin/LJ/HTML/Template.pm --- a/cgi-bin/LJ/HTML/Template.pm Sun Dec 13 09:57:28 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package LJ::HTML::Template; -use strict; -use HTML::Template; - - -# Returns a new HTML::Template object -# with some redefined default values. -sub new { - my $class = shift; - return - HTML::Template->new( - global_vars => 1, # normally variables declared outside a loop are not available inside - # a loop. This option makes <TMPL_VAR>s like global variables in Perl - # - they have unlimited scope. - # This option also affects <TMPL_IF> and <TMPL_UNLESS> - - die_on_bad_params => 0, # if set to 0 the module will let you call - # $template->param(param_name => 'value') even - # if 'param_name' doesn't exist in the template body. - # Defaults to 1. - @_ - ); -} - - -1; --------------------------------------------------------------------------------