[LON-CAPA-cvs] cvs: loncom /interface lonbulletin.pm lonsimplepage.pm lonsyllabus.pm lontemplate.pm
faziophi
faziophi@source.lon-capa.org
Sun, 31 Jan 2010 06:03:55 -0000
This is a MIME encoded message
--faziophi1264917835
Content-Type: text/plain
faziophi Sun Jan 31 06:03:55 2010 EDT
Modified files:
/loncom/interface lonsyllabus.pm lonsimplepage.pm lonbulletin.pm
lontemplate.pm
Log:
Refactors nearly-common code located in the templated pages,
into a new routine &print_template_fields() which controls printing
LC_Boxes for fields, and <textarea>s as necessary. Custom fields
(links to be included, for example), are processed using handler routines
in closures, which are passed in a hash to the routine.
Saves about 140 lines of code are so?
--faziophi1264917835
Content-Type: text/plain
Content-Disposition: attachment; filename="faziophi-20100131060355.txt"
Index: loncom/interface/lonsyllabus.pm
diff -u loncom/interface/lonsyllabus.pm:1.105 loncom/interface/lonsyllabus.pm:1.106
--- loncom/interface/lonsyllabus.pm:1.105 Thu Jan 28 17:22:34 2010
+++ loncom/interface/lonsyllabus.pm Sun Jan 31 06:03:55 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Syllabus
#
-# $Id: lonsyllabus.pm,v 1.105 2010/01/28 17:22:34 raeburn Exp $
+# $Id: lonsyllabus.pm,v 1.106 2010/01/31 06:03:55 faziophi Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -58,7 +58,7 @@
if ($homeserver eq 'no_host') {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
- &Apache::loncommon::simple_error_page($r,'No syllabus available',
+ &Apache::loncommon::simple_error_page($r,'No syllabus available',
'No syllabus available');
return OK;
}
@@ -383,83 +383,53 @@
'<input type="hidden" name="forceedit" value="edit" />');
}
my @htmlids=();
+ my $url_include_handler = sub {
+ my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed) = @_;
+ my %data = %{$data_ref};
+ my %fields = %{$fields_ref};
+ my $urls=$message;
+ $message='';
+ foreach my $filelink (split(/\n/,$urls)) {
+ my $output='';
+ # embed style?
+ my ($curfext)=($filelink=~/\.([^\.]+)$/);
+ my $embstyle=&Apache::loncommon::fileembstyle($curfext);
+ if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
+ $output=&Apache::lonnet::ssi_body($filelink);
+ } elsif ($embstyle eq 'img') {# embed as an image
+ $output='<img src="'.$filelink.'" />';
+ }
+ if ($output ne '') {
+ if ($target ne 'tex') {
+ $message.='<p>'.$output.'</p>';
+ } else {
+ $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
+ }
+ }
+ }
+ if ($allowed) {
+ &Apache::lonfeedback::newline_to_br(\$urls);
+ &Apache::lontemplate::print_start_template($r,$fields{$field}.
+ &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box');
+ $r->print($urls);
+ $r->print("<br /><div>");
+ &Apache::lontemplate::print_textarea_template($r, $data{$field},
+ $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
+ &Apache::lontemplate::print_saveall_template($r);
+ $r->print("</div>");
+ &Apache::lontemplate::print_end_template($r);
- foreach my $field (sort(keys(%syllabusfields))) {
- if (($syllabus{$field}=~/\w/) || ($allowed)) {
- my $message=$syllabus{$field};
- if ($field eq 'lll_includeurl') { # this is the "included" field
- my $urls=$message;
- $message='';
- foreach my $filelink (split(/\n/,$urls)) {
- my $output='';
- # embed style?
- my ($curfext)=($filelink=~/\.([^\.]+)$/);
- my $embstyle=&Apache::loncommon::fileembstyle($curfext);
- if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
- $output=&Apache::lonnet::ssi_body($filelink);
- } elsif ($embstyle eq 'img') {# embed as an image
- $output='<img src="'.$filelink.'" />';
- }
- if ($output ne '') {
- if ($target ne 'tex') {
- $message.='<p>'.$output.'</p>';
- } else {
- $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
- }
- }
- }
- if ($allowed) {
- &Apache::lonfeedback::newline_to_br(\$urls);
- &Apache::lontemplate::print_start_template($r,$syllabusfields{$field}.
- &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box');
- $r->print($urls);
- $r->print("<br /><div>");
- &Apache::lontemplate::print_textarea_template($r, $syllabus{$field},
- $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
- &Apache::lontemplate::print_saveall_template($r);
- $r->print("</div>");
- &Apache::lontemplate::print_end_template($r);
-
- } else {
- $r->print($message);
- }
- } else {
- if (!&Apache::lonfeedback::contains_block_html($message)) {
- &Apache::lonfeedback::newline_to_br(\$message);
- } else {
- $message = &Apache::lonfeedback::tidy_html($message);
- }
- $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
-
- if ($allowed) {
- $message=&Apache::lonspeller::markeduptext($message);
- }
- $message=&Apache::lontexconvert::msgtexconverted($message);
- if ($target ne 'tex') {
- #output of syllabusfields will be generated here.
- &Apache::lontemplate::print_start_template($r,$syllabusfields{$field},'LC_Box');
- $r->print($message);
- if ($allowed) {
- $r->print("<br /><div>");
- &Apache::lontemplate::print_textarea_template($r, $syllabus{$field},
- $field, Apache::lontemplate->RICH_TEXT_DETECT_HTML);
- &Apache::lontemplate::print_saveall_template($r);
- $r->print("</div>");
- }
- &Apache::lontemplate::print_end_template($r);
- } else {
- $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
- &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
- }
- push(@htmlids,$field);
- }
- }
- }
+ } else {
+ $r->print($message);
+ }
+ };
+ my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
+ @htmlids = &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
+ $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash);
if ($allowed) {
$r->print('</form>'.
&Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
}
- # if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
} else {
if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
$r->print(&mt('No syllabus information provided.'));
Index: loncom/interface/lonsimplepage.pm
diff -u loncom/interface/lonsimplepage.pm:1.92 loncom/interface/lonsimplepage.pm:1.93
--- loncom/interface/lonsimplepage.pm:1.92 Thu Jan 7 14:45:08 2010
+++ loncom/interface/lonsimplepage.pm Sun Jan 31 06:03:55 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Simple Page Editor
#
-# $Id: lonsimplepage.pm,v 1.92 2010/01/07 14:45:08 wenzelju Exp $
+# $Id: lonsimplepage.pm,v 1.93 2010/01/31 06:03:55 faziophi Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -361,59 +361,26 @@
else {
$r->print($image);
}
-
- foreach my $field (sort(keys(%syllabusfields))) {
- if (($syllabus{$field}) || ($allowed) ||
- ($field eq 'abb_links' && $group ne '')) {
- my $message=$syllabus{$field};
- if (!&Apache::lonfeedback::contains_block_html($message)) {
- &Apache::lonfeedback::newline_to_br(\$message);
- }
- $message=~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
- if ($allowed) {
- $message=&Apache::lonspeller::markeduptext($message);
- }
- if ($target ne 'tex') {
- $message=&Apache::lontexconvert::msgtexconverted($message);
- }
- if ($field eq 'abb_links' && $group ne '') {
- $r->print('<br /><input type="hidden" name="'.$field.
- '" value="'.$syllabus{$field}.'" />');
- &display_group_links($r,$target,$group,'edit',$refarg,
- %groupinfo);
- $r->print('<br />');
- } elsif ($field eq 'aaa_title') {
- next;
- } else {
- if ($target ne 'tex') {
- if ($allowed) {
- } else {
- &Apache::lontemplate::print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
- }
- } else {
- my $safeinit;
- $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$field}.'</h3>'));
- $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
- }
- if ($allowed) {
- if ($target ne 'tex') {
- #output of syllabusfields will be generated here.
- &Apache::lontemplate::print_start_template($r,$syllabusfields{$field},'LC_Box');
- $r->print($message);
- $r->print("<br /><div>");
- &Apache::lontemplate::print_textarea_template($r, $syllabus{$field},
- $field, Apache::lontemplate->RICH_TEXT_DETECT_HTML);
- &Apache::lontemplate::print_saveall_template($r);
- $r->print("</div>");
- &Apache::lontemplate::print_end_template($r);
- } else {
- my $safeinit;
- $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$field},$safeinit));
- }
- }
- }
- }
- }
+
+ my $links_handler = sub {
+ my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed) = @_;
+ if ($group ne '') {
+ my %data = %{$data_ref};
+ my %fields = %{$fields_ref};
+ $r->print('<br /><input type="hidden" name="'.$field.
+ '" value="'.$data{$field}.'" />');
+ &display_group_links($r, $target, $group, 'edit', $refarg, %groupinfo);
+ $r->print('<br />');
+ }
+ };
+ my $title_handler = sub {};
+ my %custom_handlers = (
+ 'abb_links' => $links_handler,
+ 'aaa_title' => $title_handler
+ );
+ &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
+ $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_handlers, $group);
+
if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
$r->print(&Apache::lonhtmlcommon::htmlareaselectactive
('bbb_content').'</form>');
Index: loncom/interface/lonbulletin.pm
diff -u loncom/interface/lonbulletin.pm:1.57 loncom/interface/lonbulletin.pm:1.58
--- loncom/interface/lonbulletin.pm:1.57 Tue Dec 22 06:32:04 2009
+++ loncom/interface/lonbulletin.pm Sun Jan 31 06:03:55 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Bulletin Board Handler
#
-# $Id: lonbulletin.pm,v 1.57 2009/12/22 06:32:04 faziophi Exp $
+# $Id: lonbulletin.pm,v 1.58 2010/01/31 06:03:55 faziophi Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -277,39 +277,10 @@
elsif($syllabus{'uploaded.photourl'} && $target ne 'tex'){
$r->print('<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>');
}
- foreach my $field (sort(keys(%syllabusfields))) {
- if (($syllabus{$field}) || ($allowed)) {
- my $message=$syllabus{$field};
- if (!&Apache::lonfeedback::contains_block_html($message)) {
- &Apache::lonfeedback::newline_to_br(\$message);
- } else {
- $message = &Apache::lonfeedback::tidy_html($message);
- }
- $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
- if ($allowed) {
- $message=&Apache::lonspeller::markeduptext($message);
- }
- $message=&Apache::lontexconvert::msgtexconverted($message);
- unless ($field eq 'aaa_title') {
- if ($target ne 'tex') {
- #output of syllabusfields will be generated here.
- &Apache::lontemplate::print_start_template($r,$syllabusfields{$field},'LC_Box');
- $r->print($message);
- if ($allowed) {
- $r->print("<br /><div>");
- &Apache::lontemplate::print_textarea_template($r, $syllabus{$field},
- $field, Apache::lontemplate->RICH_TEXT_DETECT_HTML);
- &Apache::lontemplate::print_saveall_template($r);
- $r->print("</div>");
- }
- &Apache::lontemplate::print_end_template($r);
- push(@htmlids,$field);
- } else {
- $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.&Apache::lonxml::xmlparse($r,'tex',$message));
- }
- }
- }
- }
+
+ my %custom_handlers = ( 'aaa_title' => sub {} );
+ @htmlids = &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
+ $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_handlers);
if ($allowed) {
$r->print('</form>'.
&Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
Index: loncom/interface/lontemplate.pm
diff -u loncom/interface/lontemplate.pm:1.42 loncom/interface/lontemplate.pm:1.43
--- loncom/interface/lontemplate.pm:1.42 Tue Dec 22 06:22:12 2009
+++ loncom/interface/lontemplate.pm Sun Jan 31 06:03:55 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# "Template" Functions to generate html output
#
-# $Id: lontemplate.pm,v 1.42 2009/12/22 06:22:12 faziophi Exp $
+# $Id: lontemplate.pm,v 1.43 2010/01/31 06:03:55 faziophi Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -144,4 +144,52 @@
$r->print('<input type="submit" name="storesyl" value="'.&mt('Save All').'" />');
}
+sub print_template_fields {
+ my ($r, $data_ref, $fields_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group) = @_;
+ my @html_ids = ();
+ my %data = %{$data_ref};
+ my %fields = %{$fields_ref};
+ my %custom_handlers = %{$custom_handlers_ref};
+
+ foreach my $field (sort(keys(%fields))) {
+ my $message = $data{$field} if (($data{$field}=~/\w/) || ($allowed));
+ if ((%custom_handlers) && ($custom_handlers{$field})) {
+ $custom_handlers{$field}->($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed);
+ } else {
+ if (($data{$field}=~/\w/) || ($allowed)) {
+ if (!&Apache::lonfeedback::contains_block_html($message)) {
+ &Apache::lonfeedback::newline_to_br(\$message);
+ } else {
+ $message = &Apache::lonfeedback::tidy_html($message);
+ }
+ $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
+ if ($allowed) {
+ $message=&Apache::lonspeller::markeduptext($message);
+ }
+ $message=&Apache::lontexconvert::msgtexconverted($message);
+ if ($target ne 'tex') {
+ #output of syllabusfields will be generated here.
+ &Apache::lontemplate::print_start_template($r,$fields{$field},'LC_Box');
+ $r->print($message);
+ if ($allowed) {
+ $r->print("<br /><div>");
+ &Apache::lontemplate::print_textarea_template($r, $data{$field},
+ $field, $default_rich_text);
+ &Apache::lontemplate::print_saveall_template($r);
+ $r->print("</div>");
+ }
+ &Apache::lontemplate::print_end_template($r);
+ } else {
+ my $safeinit;
+ $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$fields{$field}.'</h3>'));
+ $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
+ }
+ push(@html_ids,$field);
+ }
+ }
+ }
+
+ return @html_ids;
+}
+
1;
--faziophi1264917835--