From: Boris Z. <bo...@am...> - 2002-07-01 08:36:24
|
Hi, this patch fix the error, that Gabriel Burca reported ( in great detail so fixing was fun thanks ). His report can be read on the pkit-devel list search for the subject "Edit.pm - add_component_edit_stubs" Changed files: Apache-PageKit/Changes Apache-PageKit/lib/Apache/PageKit/Edit.pm Apache-PageKit/lib/Apache/PageKit/View.pm Index: Apache-PageKit/Changes =================================================================== RCS file: /cvsroot/pagekit/Apache-PageKit/Changes,v retrieving revision 1.152 diff -u -r1.152 Changes --- Apache-PageKit/Changes 26 Jun 2002 15:11:50 -0000 1.152 +++ Apache-PageKit/Changes 26 Jun 2002 15:17:34 -0000 @@ -5,10 +5,11 @@ - Use parameters for Apache::PageKit->startup if we can not find PKIT_ROOT and or PKIT_SERVER for mod_perl >= 1.06 (Boris Zentner) - - Fix: bug, where path relative components are not listed as an edit component. + - Fix: bug, where path relative components are not listed as + an edit component. (Boris Zentner, Gabriel Burca) + - Fix a errormessage is fixed, that report file is out of + the root_dir even if the file is not found. (Boris Zentner, Gabriel Burca) - - Fix a errormessage is fixed, that report file is out of the root_dir even - if the file is not found. (Boris Zentner, Gabriel Burca) - Fix: write the session data and destroy the db connection even if an error transpires (Boris Zentner) - Fix: defer delivery of static pages if parameters are attached to Index: Apache-PageKit/lib/Apache/PageKit/Edit.pm =================================================================== RCS file: /cvsroot/pagekit/Apache-PageKit/lib/Apache/PageKit/Edit.pm,v retrieving revision 1.10 diff -u -r1.10 Edit.pm --- Apache-PageKit/lib/Apache/PageKit/Edit.pm 7 Jun 2002 22:30:11 -0000 1.10 +++ Apache-PageKit/lib/Apache/PageKit/Edit.pm 26 Jun 2002 15:17:35 -0000 @@ -121,22 +121,22 @@ } sub add_component_edit_stubs { - my ( $view, $component_id, $html_code_ref, $pkit_view ) = @_; + my ( $view, $page_id, $html_code_ref, $pkit_view ) = @_; # insert edit stubs (PKIT_EDIT_COMPONENT), before each PKIT_COMPONENT tag, # for online editing tools to use if ( $view->{relaxed_parser} eq 'yes' ) { $$html_code_ref =~ - s%<(!--)?\s*PKIT_COMPONENT($key_value_pattern+)\s*/?(?(1)--)?>(?:<(!--)?\s*/PKIT_COMPONENT\s*(?(1)--)>)?%_build_component_edit_stub($view, $pkit_view, $component_id, $2)%eig; + s%<(!--)?\s*PKIT_COMPONENT($key_value_pattern+)\s*/?(?(1)--)?>(?:<(!--)?\s*/PKIT_COMPONENT\s*(?(1)--)>)?%_build_component_edit_stub($view, $pkit_view, $page_id, $2)%eig; } else { $$html_code_ref =~ - s%<\s*PKIT_COMPONENT($key_value_pattern+)\s*/?>(<\s*/PKIT_COMPONENT\s*>)?%_build_component_edit_stub($view, $pkit_view, $component_id, $1)%eig; + s%<\s*PKIT_COMPONENT($key_value_pattern+)\s*/?>(<\s*/PKIT_COMPONENT\s*>)?%_build_component_edit_stub($view, $pkit_view, $page_id, $1)%eig; } ###$$html_code_ref =~ s!(<[^>]*)?(<PKIT_COMPONENT $key_value_pattern>)!<font size="-1"><a href="/pkit_edit/open_file?file=$3">(edit $3)</a></font><br>$2!sig; sub _build_component_edit_stub { - my ( $view, $pkit_view, $component_id, $params ) = @_; + my ( $view, $pkit_view, $page_id, $params ) = @_; my %params; while ( $params =~ m!$key_value_pattern!g ) { @@ -149,9 +149,23 @@ $params{NAME} = $2; } } + $params{NAME} =~ s!^/+!!; - my $template_file = $view->_find_template( $pkit_view, $component_id ) - || die "$component_id not found"; + + my $template_file; + my $component_id; + + # search relative to the page_id path + if ( ( $component_id = $page_id ) =~ s!/([^/]+)$!/$params{NAME}! ) { + $template_file = $view->_find_template( $pkit_view, $component_id ); + } + + # if the template_dile is not found search as abs path + unless ( $template_file ) { + $component_id = $params{NAME}; + $template_file = $view->_find_template( $pkit_view, $component_id ) || die "$component_id not found"; + } + my $pkit_root = Apache->request->dir_config('PKIT_ROOT'); die "Filename ($template_file) points outside PKIT_ROOT ($pkit_root)" unless ( $template_file =~ s!^$pkit_root/!! ); return qq{<PKIT_EDIT_COMPONENT NAME="$component_id"><PKIT_COMPONENT $params>}; Index: Apache-PageKit/lib/Apache/PageKit/View.pm =================================================================== RCS file: /cvsroot/pagekit/Apache-PageKit/lib/Apache/PageKit/View.pm,v retrieving revision 1.97 diff -u -r1.97 View.pm --- Apache-PageKit/lib/Apache/PageKit/View.pm 7 Jun 2002 22:30:11 -0000 1.97 +++ Apache-PageKit/lib/Apache/PageKit/View.pm 26 Jun 2002 15:17:39 -0000 @@ -28,8 +28,9 @@ # * filename - filename of template source # * include_mtimes - a hash ref with file names as keys and mtimes as values # (contains all of the files included by the <PKIT_COMPONENT> tags -# * component_ids - an array ref containing component_ids that have -# code associated with them +# * component_ids - an array ref containing an array ref of component_ids and a hash ref +# with the parameters for the compoent, that may have +# code associated with them # * has_form - 1 if contains <form> tag, 0 otherwise. used to # determine whether to apply HTML::FillInForm module # the objects themselves are keyed by page_id, pkit_view and lang @@ -332,7 +333,6 @@ $$html_code_ref = ${$h->data()}; } -# returns the component_ids included sub _include_components { my ($view, $page_id, $html_code_ref, $pkit_view) = @_; @@ -341,6 +341,7 @@ } else { $$html_code_ref =~ s%<\s*PKIT_COMPONENT($key_value_pattern+)\s*/?>(<\s*/PKIT_COMPONENT\s*>)?%&get_component($page_id,$1,$view,$pkit_view)%eig; } + sub get_component { my ($page_id, $params, $view, $pkit_view) = @_; my %params = (); @@ -358,13 +359,18 @@ while ($component_id =~ s![^/]*/\.\./!!) {}; } + my $cid_key = join '', $component_id, sort %params; + unless ( $view->{component_ids_hash}->{$cid_key}++ ) { + push @{ $view->{component_ids} }, [ $component_id , \%params ]; + } + # check for recursive pkit_components - $view->{component_ids_hash}->{$component_id}++; - if($view->{component_ids_hash}->{$component_id} > 100){ + if($view->{component_ids_hash}->{$cid_key} > 100){ die "Likely recursive PKIT_COMPONENTS for component_id $component_id and giving up."; } my $template_ref = $view->_load_component($page_id, $component_id, $pkit_view, \%params); + push @{ $view->{component_ids_arrayref_with_params} }, [ $component_id => \%params ]; $$template_ref =~ s!<\s*PKIT_MACRO$key_value_pattern\s*/?>!$params{uc($+)}!egi if (keys %params); return $$template_ref; } @@ -437,7 +443,7 @@ } if($view->{can_edit} eq 'yes'){ - Apache::PageKit::Edit::add_component_edit_stubs($view, $component_id, $template_ref, $pkit_view); + Apache::PageKit::Edit::add_component_edit_stubs($view, $page_id, $template_ref, $pkit_view); } $view->_include_components($page_id,$template_ref,$pkit_view); @@ -495,7 +501,7 @@ if ( $converter ) { $$filtered_html = $converter->convert($$filtered_html) || die "Can not convert page from UTF-8 to $default_output_charset" if $$filtered_html; } - + my $exclude_params_set = $view->_preparse_model_tags($filtered_html); $view->_html_clean($filtered_html); @@ -513,14 +519,13 @@ if($@){ die "Can't load template (MODEL TAGS) for $page_id: $@" } - my @component_ids = keys %{$view->{component_ids_hash}}; my $record = { exclude_params_set => $exclude_params_set, filename => $template_file, html_template => $tmpl, include_mtimes => $view->{include_mtimes}, - component_ids => \@component_ids, - has_form => $has_form + component_ids => $view->{component_ids}, + has_form => $has_form, }; # make directories, if approriate -- Boris |