--- loncom/interface/lonhtmlcommon.pm 2016/08/04 21:26:35 1.358.2.4 +++ loncom/interface/lonhtmlcommon.pm 2023/01/21 21:20:54 1.358.2.19.2.5 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.358.2.4 2016/08/04 21:26:35 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.358.2.19.2.5 2023/01/21 21:20:54 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -78,7 +78,11 @@ sub java_not_enabled { sub coursepreflink { my ($text,$category)=@_; if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) { - return '&"').'">'.$text.''; + my $target =' target="_top"'; + if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) { + $target = ''; + } + return '&"').'">'.$text.''; } else { return ''; } @@ -92,7 +96,7 @@ sub raw_href_to_link { sub entity_encode { my ($text)=@_; - return &HTML::Entities::encode($text, '<>&"'); + return &HTML::Entities::encode($text, '\'<>&"'); } sub direct_parm_link { @@ -101,7 +105,11 @@ sub direct_parm_link { $filter=&entity_encode($filter); $part=&entity_encode($part); if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) { - return "$linktext"; + my $target=' target="_top"'; + if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) { + $target = ''; + } + return "$linktext"; } else { return $linktext; } @@ -407,7 +415,7 @@ sub textbox { ############################################## ############################################## sub checkbox { - my ($name,$checked,$value) = @_; + my ($name,$checked,$value,$special) = @_; my $Str = ''; return $Str; } @@ -534,6 +542,8 @@ sub date_setter { if (! defined($state) || $state ne 'disabled') { $state = ''; + } else { + $state = 'disabled="disabled"'; } if (! defined($no_hh_mm_ss)) { $no_hh_mm_ss = 0; @@ -669,7 +679,7 @@ ENDJS my $minuteselector = qq{}; my $secondselector= qq{}; my $cal_link; - if (!$nolink) { + unless (($nolink) || ($state eq 'disabled')) { $cal_link = qq{}; } # @@ -694,7 +704,7 @@ ENDJS $hourselector,$minuteselector,$secondselector). $tzone; } - if (!$nolink) { + unless (($nolink) || ($state eq 'disabled')) { $result .= &mt('[_1]Select Date[_2]',$cal_link,''); } $result .= "\n\n"; @@ -846,13 +856,14 @@ parameter setting wizard. ############################################## sub pjump_javascript_definition { my $Str = <&"'); &Apache::loncommon::inhibit_menu_check(\$href_path); if ($form) { @@ -1257,9 +1277,9 @@ sub htmlareaheaders { ENDEDITOR } $s.=(< - - + + + @@ -1342,6 +1362,41 @@ sub htmlareaselectactive { } function startRichEditor(id) { + // fix character entities inside + // NOTE: this is not fixing characters inside + // NOTE: < and > inside should fix automatically because there should not be a letter after <. + var ta = document.getElementById(id); + var value = ta.value; + var in_m = false; // in the m element + var in_text = false; // in the text inside the m element + var im = -1; // position of + var it = -1; // position of the text inside + for (var i=0; i if found twice + in_m = true; + in_text = false; + im = i; + it = -1; + } else if (in_m) { + if (!in_text) { + if (value.charAt(i) == ">") { + in_text = true; + it = i+1; + } + } else if (value.substr(i, 4) == "") { + in_m = false; + var text = value.substr(it, i-it); + var l1 = text.length; + text = text.replace(//g, ">"); + var l2 = text.length; + value = value.substr(0, it) + text + "" + value.substr(i+4); + i = i + (l2-l1); + } + } + } + ta.value = value; CKEDITOR.replace(id, { customConfig: "/ckeditor/loncapaconfig.js", @@ -1353,6 +1408,68 @@ sub htmlareaselectactive { function destroyRichEditor(id) { CKEDITOR.instances[id].destroy(); + // replace character entities < and > in and + // and "&fctname(" by "&fctname(" + // and the quotes inside functions: "&fct(1, "a")" -> "&fct(1, "a")" + var ta = document.getElementById(id); + var value = ta.value; + var in_element = false; // in the m or chem element + var tagname = ""; // m or chem + var in_text = false; // in the text inside the element + var im = -1; // position of start tag + var it = -1; // position of the text inside + for (var i=0; i") { + in_text = true; + it = i+1; + } + } else if (value.substr(i, 3+tagname.length) == "") { + in_element = false; + var text = value.substr(it, i-it); + var l1 = text.length; + text = text.replace(/</g, "<"); + text = text.replace(/>/g, ">"); + var l2 = text.length; + value = value.substr(0, it) + text + value.substr(i); + i = i + (l2-l1); + } + } + } + // fix function names + value = value.replace(/&([a-zA-Z_]+)\(/g, "&$1("); + // fix quotes in functions + var pos_next_fct = value.search(/&[a-zA-Z_]+\(/); + var depth = 0; + for (var i=0; i 0) { + if (value.charAt(i) == ")") + depth--; + else if (value.substr(i, 6) == """) + value = value.substr(0, i) + "\"" + value.substr(i+6); + } + } + // replace the text value + ta.value = value; } function editorHandler(event) { @@ -1585,7 +1702,7 @@ sub show_return_link { (($env{'request.noversionuri'}=~/^\/adm\//) && ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) && ($env{'request.noversionuri'}!~ - m{^/adm/.*/(smppg|bulletinboard)($|\?)}) + m{^/adm/.*/(smppg|bulletinboard|ext\.tool)($|\?)}) )); } @@ -1672,6 +1789,7 @@ Inputs: $component (the text on the righ row, using loncommon::help_open_topic() to generate the link. $topic_help_text (text to include in the link in the optional help item on the right side of the breadcrumbs row. + $links_target optionally includes the target (_top, _parent or _self) Returns a string containing breadcrumbs for the current page. @@ -1700,7 +1818,7 @@ returns: nothing sub breadcrumbs { my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt, - $CourseBreadcrumbs,$topic_help,$topic_help_text) = @_; + $CourseBreadcrumbs,$topic_help,$topic_help_text,$links_target) = @_; # $css_class ||= 'LC_breadcrumbs'; @@ -1716,6 +1834,16 @@ returns: nothing # The first one should be the course or a menu link if (!defined($menulink)) { $menulink=1; } if ($menulink) { + if ($env{'request.course.id'}) { + my ($menucoll,$deeplinkmenu,$menuref) = &Apache::loncommon::menucoll_in_effect(); + if (($menucoll) && (ref($menuref) eq 'HASH')) { + if ($menuref->{'main'} eq 'n') { + undef($menulink); + } + } + } + } + if ($menulink) { my $description = 'Menu'; my $no_mt_descr = 0; if ((exists($env{'request.course.id'})) && @@ -1725,7 +1853,7 @@ returns: nothing $env{'course.'.$env{'request.course.id'}.'.description'}; $no_mt_descr = 1; if ($env{'request.noversionuri'} =~ - m{^/public/($match_domain)/($match_courseid)/syllabus$}) { + m{^/?public/($match_domain)/($match_courseid)/syllabus$}) { unless (($env{'course.'.$env{'request.course.id'}.'.domain'} eq $1) && ($env{'course.'.$env{'request.course.id'}.'.num'} eq $2)) { $description = 'Menu'; @@ -1733,9 +1861,15 @@ returns: nothing } } } + my $target = '_top'; + if ($links_target) { + $target = $links_target; + } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) { + $target = ''; + } $menulink = { href =>'/adm/menu', title =>'Go to main menu', - target =>'_top', + target =>$target, text =>$description, no_mt =>$no_mt_descr, }; if($last) { @@ -1753,8 +1887,8 @@ returns: nothing title => &mt('Back to most recent content resource'), class => 'LC_menubuttons_link', }; - if ($env{'request.noversionuri'} eq '/adm/searchcat') { - $hashref->{'target'} = '_top'; + if ($links_target) { + $hashref->{'target'} = $links_target; } $links=&htmltag( 'a',''.$alttext.'', $hashref); @@ -1805,11 +1939,12 @@ returns: nothing if ($faq ne '' || $component_help ne '' || $bug ne '') { $icons .= &Apache::loncommon::help_open_menu($component, $component_help, - $faq,$bug); + $faq,$bug,'','','','', + $links_target); } if ($topic_help && $topic_help_text) { $icons .= ' '.&Apache::loncommon::help_open_topic($topic_help,&mt($topic_help_text),'', - undef,600); + undef,600,'',$links_target); } # @@ -1926,6 +2061,16 @@ returns: nothing undef(%tools); } +=item ¤t_breadcrumb_tools() + +returns: a hash containing the current breadcrumb tools. + +=cut + + sub current_breadcrumb_tools { + return %tools; + } + =item &render_tools(\$breadcrumbs) Creates html for breadcrumb tools (categories navigation and tools) and inserts @@ -1977,7 +2122,7 @@ returns: nothing } # End of scope for @Crumbs sub docs_breadcrumbs { - my ($allowed,$crstype,$contenteditor,$title,$precleared)=@_; + my ($allowed,$crstype,$contenteditor,$title,$precleared,$checklinkprot)=@_; my ($folderpath,@folders,$supplementalflag); @folders = split('&',$env{'form.folderpath'}); if ($env{'form.folderpath'} =~ /^supplemental/) { @@ -1992,19 +2137,21 @@ sub docs_breadcrumbs { my $foldername=shift(@folders); if ($folderpath) {$folderpath.='&';} $folderpath.=$folder.'&'.$foldername; - my $url; + my $url = $env{'request.use_absolute'}; if ($allowed) { - $url = '/adm/coursedocs?folderpath='; + $url .= '/adm/coursedocs?folderpath='; } else { - $url = '/adm/supplemental?folderpath='; + $url .= '/adm/supplemental?folderpath='; } $url .= &escape($folderpath); my $name=&unescape($foldername); # each of randompick number, hidden, encrypted, random order, is_page # are appended with ":"s to the foldername $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)\:?(\d*)$//; - unless ($supplementalflag) { - if ($contenteditor) { + if ($contenteditor) { + if ($supplementalflag) { + if ($2) { $ishidden=1; } + } else { if ($1 ne '') { $randompick=$1; } else { @@ -2048,6 +2195,14 @@ sub docs_breadcrumbs { if (!$allowed && !$contenteditor) { $menulink = 1; } + if ($checklinkprot) { + if ($env{'request.deeplink.login'}) { + my $linkprotout = &Apache::lonmenu::linkprot_exit(); + if ($linkprotout) { + &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout); + } + } + } return (&breadcrumbs(undef,undef,$menulink,'nohelp',undef,undef, $contenteditor), $randompick,$ishidden,$isencrypted,$plain, @@ -2421,9 +2576,9 @@ sub course_custom_roles { sub resource_info_box { - my ($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp)=@_; + my ($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp,$divforres)=@_; my $return=''; - if ($stuvcurrent ne '') { + if (($stuvcurrent ne '') || ($divforres)) { $return = '
'; } if ($symb) { @@ -2452,7 +2607,7 @@ sub resource_info_box { } else { $return='

'.&mt('No context provided.').'

'; } - if ($stuvcurrent ne '') { + if (($stuvcurrent ne '') || ($divforres)) { $return .= '
'; } return $return; @@ -2467,9 +2622,9 @@ sub resource_info_box { # sub display_usage { - my ($current_disk_usage,$disk_quota) = @_; - my $usage = $current_disk_usage/1000; - my $quota = $disk_quota/1000; + my ($current_disk_usage,$disk_quota,$context) = @_; + my $usage = $current_disk_usage/1024; + my $quota = $disk_quota/1024; my $percent; if ($disk_quota == 0) { $percent = 100.0; @@ -2493,9 +2648,13 @@ sub display_usage { if ($prog_width > 100) { $prog_width = 100; } + my $display = 'block'; + if ($context eq 'authoring') { + $display = 'inline'; + } return ' -
'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB ('.$percent.'%)',$quota.' MB')."\n". -'
'."\n". +
'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB ('.$percent.'%)',$quota.' MB')."\n". +'
'."\n". '
'."\n". '
'."\n". '
'; @@ -3179,12 +3338,18 @@ PARAMSONE if (itemid != null) { itemh = itemid.offsetHeight; } - var primaryheight = document.getElementById('LC_nav_bar').offsetHeight; - var secondaryheight; + var primaryheight = 0; + if (document.getElementById('LC_nav_bar') != null) { + primaryheight = document.getElementById('LC_nav_bar').offsetHeight; + } + var secondaryheight = 0; if (document.getElementById('LC_secondary_menu') != null) { secondaryheight = document.getElementById('LC_secondary_menu').offsetHeight; } - var crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight; + var crumbsheight = 0; + if (document.getElementById('LC_breadcrumbs') != null) { + crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight; + } var dccidheight = 0; if (document.getElementById('dccid') != null) { dccidheight = document.getElementById('dccid').offsetHeight; @@ -3257,20 +3422,37 @@ THIRD sub javascript_jumpto_resource { my $confirm_switch = &mt("Editing requires switching to the resource's home server.")."\n". &mt('Switch server?'); + my $confirm_new_tab = &mt("Editing requires using the resource's home server.")."\n". + &mt('Open a new browser tab?'); &js_escape(\$confirm_switch); + &js_escape(\$confirm_new_tab); return (<&'); - if ($symb) { - $cfile .= '&symb='.&HTML::Entities::encode($symb,'"<>&'); + if ($shownsymb) { + $cfile .= '&symb='.&HTML::Entities::encode($shownsymb,'"<>&'); + if ($resedit) { + $cfile .= '&edit=1'; + } } elsif ($folderpath) { $cfile .= '&folderpath='.&HTML::Entities::encode($folderpath,'"<>&'); } @@ -3300,11 +3502,48 @@ sub jump_to_editres { if ($forcereg) { $cfile .= '&register=1'; } - $jscall = "need_switchserver('".&Apache::loncommon::escape_single($cfile)."');"; + $jscall = "need_switchserver('".&Apache::loncommon::escape_single($cfile)."','$target')"; } } else { unless ($cfile =~ m{^/priv/}) { + if ($cfile =~ m{^(/adm/wrapper/ext/([^#]+))(?:|#([^#]+))$}) { + $cfile = $1; + my $extlink = $2; + $anchor = $3; + $is_ext = 1; + if (($extlink !~ /^https:/) && ($ENV{'SERVER_PORT'} == 443)) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { + $usehttp = 1; + } + } elsif ($env{'request.use_absolute'}) { + if ($env{'request.use_absolute'} =~ m{^https://}) { + $usehttps = 1; + } + } + } elsif ($cfile =~ m{^/?public/($match_domain)/($match_courseid)/syllabus}) { + if ($ENV{'SERVER_PORT'} == 443) { + my ($cdom,$cnum) = ($1,$2); + if (($env{'request.course.id'}) && + ($env{'course.'.$env{'request.course.id'}.'.num'} eq $cnum) && + ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $cdom)) { + if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { + $usehttp = 1; + } + } + } + } elsif ($env{'request.use_absolute'}) { + if ($env{'request.use_absolute'} =~ m{^https://}) { + $usehttps = 1; + } + } + } if ($symb) { + if ($anchor ne '') { + if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) { + $symb = $1.&escape(&escape('#')).$anchor; + } + } $cfile .= (($cfile=~/\?/)?'&':'?')."symb=$symb"; } elsif ($folderpath) { $cfile .= (($cfile=~/\?/)?'&':'?'). @@ -3323,14 +3562,31 @@ sub jump_to_editres { } if ($forceedit) { $cfile .= (($cfile=~/\?/)?'&':'?').'forceedit=1'; + if ($usehttps) { + $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile; + } + } elsif ($usehttp) { + if ($hostname ne '') { + $cfile = 'http://'.$hostname.(($cfile =~ /^\//)? '':'/').$cfile; + } + $cfile .= (($cfile=~/\?/)?'&':'?').'usehttp=1'; + } elsif ($usehttps) { + $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile; } if ($forcereg) { $cfile .= (($cfile=~/\?/)?'&':'?').'register=1'; } if ($todocs) { - $cfile .= (($cfile=~/\?/)?'&':'?').'todocs=1'; + $cfile .= (($cfile=~/\?/)?'&':'?').'todocs=1'; + } + if ($suppanchor ne '') { + $cfile .= (($cfile=~/\?/)?'&':'?').'anchor='. + &HTML::Entities::encode($suppanchor,'"<>&'); } } + if ($anchor ne '') { + $cfile .= '#'.$anchor; + } $jscall = "go('".&Apache::loncommon::escape_single($cfile)."')"; } return $jscall; @@ -3342,15 +3598,18 @@ sub jump_to_editres { # javascript_valid_email # # Generates javascript to validate an e-mail address. -# Returns a javascript function which accetps a form field as argumnent, and +# Returns a javascript function which accepts a form field as argument, and # returns false if field.value does not satisfy two regular expression matches # for a valid e-mail address. Backwards compatible with old browsers without # support for javascript RegExp (just checks for @ in field.value in this case). sub javascript_valid_email { my $scripttag .= <<'END'; -function validmail(field) { +function validmail(field,suffix) { var str = field.value; + if (suffix != '' && suffix != undefined) { + str += suffix; + } if (window.RegExp) { var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)"; var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"