Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

FoxEdit

Summary: add edit links for editing page sections and PTVs with Fox
Version: 2014-02-21
Prerequisites: PmWiki 2.2.56 and Fox (compatible with PHP 5.5)
Status: stable
Maintainer: HansB
Download: Fox Downloads (external link)
Discussion: FoxEdit-Talk

Questions answered by this recipe

How can I add edit links which will open an edit form to edit a page section or PTVs?

Description

FoxEdit is an add-on for the Fox form processors by which you can add edit links. Special Fox edit forms can be called by such links, which need Fox for processing the submitted content. So FoxEdit does not do the editing, that is up to the Fox form processor!

Install in the usual manner by copying to cookbook/ or cookbook/fox/ folder and including in local config file.

This script adds a markup {[foxedit]} which creates an edit link to open a page section for editing with a special edit form. The following parameters can be used within the markup:

{[foxedit section label form=EditFormName]}

  • section is either a page section enclosed with page anchors, or a named page text variable.
    • for editing an anchored section use the # hash character in front of the anchor name, this will call the EditSectionForm.
    • for editing a PTV, use the PTV name, this will call the EditPTVForm.
    • for editing an anchor section as a PTV, use the anchor name without the # hash character, this will call the EditPTVForm with the content of the anchor section for editing.
  • label (as second parameter) can be an alternative to 'Edit' for the link label.
  • form=EditFormName can be used to specify a custom edit form, which the link will call.
  • tooltip='STRING' or title='STRING' adds link tooltip (HTML <a title='STRING'...).

There are two default edit forms, configurable with setting variables:

  • $FoxEditPTVSectionForm = '$SiteGroup.FoxEditForms#ptv';
  • $FoxEditPageSectionForm = '$SiteGroup.FoxEditForms#section';

Please make sure you have these forms installed, or set variables to custom forms you use!
For message editing in FoxForum use $SiteGroup.FoxEditForms#message and set in your local/Forum.php config file:

$FoxEditPTVSectionForm = '$SiteGroup.FoxEditForms#message';

Three page variables are defined which can be used in the edit form:

  • {$EditTarget} - page in which the section or ptv(s) will be updated, usually the calling page. Can be named in the edit link markup.
  • {$EditSection} - anchored section or ptv which will be loaded for editing, named in the edit link markup.
  • {$EditSource} - page which holds the section or ptv to be updated, usually the calling page, and same as the the target page. Can be named in the edit link markup.

A custom markup is included by which an anchored section of form [[#anchor]] .... [[#anchorend]] (note the closing anchor name with an 'end' added) can be treated as a PTV. But note that FoxEdit (version 2008-03-29) will use the section edit form now. This may be reviewed in future.

Site.FoxEditForms

copy and paste following text in green box to new page Site.FoxEditForms
and edit as required.

Fox Edit Forms

for use with Cookbook:FoxEdit and Cookbook:Fox

#ptv PTV Edit Form (for a single PTV section)

[[#ptv]]
(:foxmessages:)
(:if foxpreview:)
!!!$[Preview]: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %green%[-&ndash; $[Changes have not been saved] &ndash;-]
>>frame<<
(:foxdisplay:)
>><<
(:if:)
(:fox editform  ptvtarget={$EditTarget} ptvfields={$EditSection} redirect=1:)
(:foxpreviewtemplate "{$$ptv_{$EditSection}}":)
(:input hidden csum 'Section {$EditSection} edited':)
(:if foxpreview :)(:input default request=1:)(:else:)(:input default source={$EditSource} :)(:ifend:)
!!!$[Editing PTV]: &nbsp; %color=#009%{$EditSection}
||(:guibuttons:) ||
||(:input textarea id=text name=$:{$EditSection} cols=80 rows=12 class=inputtext:) ||
(:if enabled EnableAccessCode:)
||Enter value {$AccessCode} (:input text access size=3 class=inputtext:)(:input hidden accesscode {$AccessCode}:)  <- Have you entered the code number? ||
(:if enabled EnablePostCaptchaRequired:)
||Enter value {$Captcha} (:input captcha class=inputtext:) <- Have you entered the code number? ||
(:if:)
||Author: (:input text author value='{$Author}' size=30 class=inputtext:) &nbsp; (:input submit post '$[Save]':) &nbsp; (:input submit preview $[Preview]:) &nbsp; (:input submit cancel '$[Cancel]':) ||
(:foxend editform:)
(:if foxpreview:)
%green center%[+&ndash; $[Changes have not been saved] &ndash;+]

[[#ptvend]]

#section Section Edit Form

[[#section]]
(:foxmessages:)(:noheader:)(:noright:)
(:if foxpreview:)
!!!$[Preview]: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %green%[-&ndash; $[Changes have not been saved] &ndash;-]
>>frame<<
(:foxdisplay:)
>><<
(:if:)
(:fox editform foxaction=replace put=overwrite  target={$EditTarget}{$EditSection} redirect={$EditTarget}{$EditSection}:)
(:foxtemplate "{$$text}":)(:input default request=1:)
(:input hidden csum 'Section {$EditSection} edited':)
(:if equal {$EditSection} '':)!!!$[Editing page]: &nbsp; %color=#009%{$EditTarget}(:else:)!!!$[Editing section]: &nbsp; %color=#009%{$EditSection}(:if:)
|| ||(:guibuttons:)||
|| ||(:input textarea id=text name=text style='width:95pct' cols=120 rows=15 class=inputtext:) ||
(:input hidden access {$Accesscode}:)(:input hidden accesscode {$AccessCode}:) 
|| ||Author: (:input text author value='{$Author}' size=30 class=inputtext:) &nbsp; (:input submit post $[Save]:) &nbsp; (:input submit preview $[Preview]:)  &nbsp; (:input submit cancel $[Cancel]:) ||
(:foxend editform:)
(:if foxpreview:)
%green center%[+&ndash; $[Changes have not been saved] &ndash;+]
[[#sectionend]]

#popupsection Section Edit Form with Popup Preview

requires Cookbook:Toggle to be installed

[[#popupsection]]
(:nolinebreaks:)(:noheader:)(:noright:)(:notitle:)
%rfloat%(:if enabled Toggle:)(:toggle id=edithelp init=hide show='$[Show Help]' hide='$[Close Help]' button:)(:if:)
(:foxmessages:)
(:div id=wikiedit:)
(:fox editform foxaction=replace put=overwrite  target={$EditTarget}{$EditSection} redirect={$EditTarget}{$EditSection}:)
(:foxtemplate "{$$text}":)(:input default request=1:)
(:input hidden csum 'Section {$EditSection} edited':)
(:if equal {$EditSection} '':)!!!$[Editing page]: &nbsp; %color=#226BAF%{$EditTarget}(:else:)!!!$[Editing section]: [[{$EditTarget}]] &nbsp;  %color=#226BAF%{$EditSection}(:if:)
(:input submit post $[Save]:) &nbsp; (:input submit preview $[Preview]:)  &nbsp; (:input submit cancel $[Cancel]:) Author: (:input text author value='{$Author}' size=30 class=inputtext:)\\
(:e_guibuttons:)
(:input textarea id=text name=text style='width:95pct' cols=120 rows=20 class=inputtext:)
(:input hidden access {$Accesscode}:)(:input hidden accesscode {$AccessCode}:) 
(:input submit post $[Save]:) &nbsp; (:input submit preview $[Preview]:)  &nbsp; (:input submit cancel $[Cancel]:)
(:foxend editform:)
(:divend:)[[<<]]
(:if [ !enabled Toggle ]:)
(:include Site.EditQuickReference:)

(:if foxpreview:)
(:div1 id=editpreview:)
>>transparency<<
>><<
(:div2 id=previewbox:)
>>previewheader<<
->[++$[Preview]++]  &mdash; '''%red%$[Page is unsaved]%%''' &mdash; (:if [ foxpreview && enabled Toggle ]:)(:toggle id=editpreview init=show hide='$[Close Preview]' button:)
(:if foxpreview:)
>>previewcontent<<

(:foxdisplay:)

>>previewfooter<<
->'''$[End of preview] &mdash; %red%$[remember to save]%%''' &mdash; '''[[#top | $[Top] ]]'''  &mdash; (:if [  foxpreview && enabled Toggle ]:)(:toggle id=editpreview init=show hide='$[Close Preview]' button:)
>><<
(:if foxpreview:)
(:div2end:) 
(:div1end:)
(:if [ enabled Toggle ]:)
(:include Site.Popup-EditQuickRef:)
[[#popupsectionend]]

#message Message Edit Form

[[#message]]
%red%(:foxmessages:)(:if foxpreview:)
!!!$[Preview]: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %green%[-&ndash; $[Changes have not been saved] &ndash;-]
>>frame<<
(:foxdisplay:)
>><<(:ifend:)
(:fox editform  ptvtarget={$EditTarget} redirect=1 :)
(:input hidden csum 'Section {$EditSection} edited':)
(:foxpreviewtemplate "'''{$$ptv_subject{$EditSection}}''' \n----\n\n{$$ptv_message{$EditSection}}":)
(:if foxpreview:)(:input default request=1:)(:else:)(:input default source={$EditSource} :)(:ifend:)
!!!$[Edit Message]: %color=#009%{$EditSection}
|| Subject:||(:input text name=$:subject{$EditSection} size=70:) ||
|| ||(:guibuttons:)||
|| Message:||(:input textarea id=text name=$:message{$EditSection}  cols=80 rows=12 class=inputtext:) ||
(:if enabled EnableAccessCode:)
|| ||Enter value {$AccessCode} (:input text access size=3 class=inputtext:)(:input hidden accesscode {$AccessCode}:)  <- $[Have you entered the code number?]||
(:if enabled EnablePostCaptchaRequired:)
|| ||Enter value {$Captcha} (:input captcha class=inputtext:) <- $[Have you entered the code number?]||
(:if:)
|| Author:||(:input text author value='{$Author}' size=30 class=inputtext:) (:input submit post '$[Save]':) (:input submit preview '$[Preview]':)  (:input submit cancel '$[Cancel]':) ||
(:foxend editform:)
(:if foxpreview:)
%green center%[+&ndash; $[Changes have not been saved] &ndash;+]

[[#messageend]]

See FoxContacts for an application which uses a custom edit form to edit the fields of a contacts info page.

Notes

Edit Forms with Preview button

Make sure of the following:

  • The preview button is named preview, like (:input submit preview 'Preview':)

The form examples on this page have been updated to include Preview, and the FoxForum zip file contains page files in its templates.d folder for ready use.

  • If you are designing a form for editng PTVs, add this to the form, above any (:input:) markup, but below the (:fox formname ... :) markup:

(:if expr !foxpreview && !foxcheck:)(:input default source={$EditSource} :)(:ifend:)

  • If you are designing a form for editng PTVs, use a (:foxpreviewtemplate "..":) markup and prefix any PTV names for replacement variables with ptv_, like {$$ptv_name1} for a PTV name1. But in the input field use name=$:name1 like (:input text name=$:name1:). PmWiki adds a ptv_ prefix for internal use, but we have to add it for the preview template variables in order to catch the input for the preview.

Adding section edit links

Fox and FoxEdit can perform section edits, when anchors are added to the top of each section, and a FoxEdit link calling the id of the section. Links are constructed dynamically from anchor markup added above each editable section. Edit links will only be displayed if edit authorisation is given (not for visitors not logged in as editors). The anchor syntax is the standard PmWiki anchor syntax, but the name should consist of one or more letters followed by a minus sign followed by one or more digits.
Example: [[#section-123]]

You can turn this feature off by setting

$EnableFoxSectionEditLinks = false;

Adding edit links to FoxForum posts

  1. Install FoxEdit
  2. Edit FoxTemplates.FormTemplates and add inside the (:include ... :) markup
    of sections headed comment form and newtopic form
    editlink="{[foxedit {$$FoxCount}]}" (best before the deletelink= ).
  3. Edit FoxTemplates.DisplayTemplates and add in all sections before {$$deletelink} {$$editlink}
  4. set in your local/Forum.php config file:
$FoxEditPTVSectionForm = '$SiteGroup.FoxEditforms#message';

This will add edit links to new posts, but not to existing posts.
Existing posts need a manual addition of editlink="{[foxedit nnn]}",
nnn shall be the post (message) number.

Checking for simultaneous edits - Not ready, still working on this!

From version 2001-01-01 FoxEdit and Fox provide for checking of simultaneous edits. No modifications of foxedit forms should be necessary. On form submission Fox will compare the text being edited as it was when the edit form opened with the text as found in the page. If they are not the same, the page section being edited was updated in the meantime, and Fox will return the user to the edit form, but with the newly updated content, not with the content the user tried to enter. A warning that the content was modified will be displayed as well.

This check will only involve the actual page section being edited, other page sections can be edited simultaneously without triggering such warning. If one or several PTVs are edited, only the PTVs being edited will be checked. For this to work, the editform needs to contain the ptvfields= parameter, naming the PTVs being edited (this is the case with the standard edit forms).

An alternative checking could be made by checking the time of the last page modification again the time the edit form was opened. Such check will catch any edits on the page, not just edits concerning the section or PTVs being targeted. For this more general time check one needs to add to the fox edit form a hidden input field like this, which catches the time the edit form opens:

(:input hidden basetime {(ftime %s)}:)

Release Notes

  • 2011-08-10: Added dynamic section edit link capability. Changed defaults for edit form locations to form templates on page Site.FoxEditForms (needs to be created!)

*2010-01-02: Added simultaneous editing check (needs fox.php 2010-01-02 or later)

  • 2009-05-11: fixed bug preventing giving section name in error message.
  • 2008-07-14: Added hook for handling of (:foxcheck:) validation errors.
  • 2008-07-03: Added preview capability, when used with latest fox.php and foxedit forms with Preview button.
  • 2008-05-06: Added ability to open an empty page for editing. Foxedit can now open new pages in an edit form.
  • 2008-04-27: disabled modification of page variables by Qualify function.
  • 2008-04-21: modified the form check (it broke FoxContacts editing).
  • 2008-04-19: Added check for loading right type of edit form according to PTV name or #section supplied in foxedit link. Added tooltip option.
  • 2008-04-18: Tydied up edit form handling. Fixed bug with handling of html special characters.
  • 2008-03-29: Reworked code to make it more stable and suitable for general page edits. Change default edit form settings. Added hard-coded default forms in case default edit forms are not set.
  • 2008-01-17: Added error message if edit form does not exist.
  • 2007-11-19: Initial release.

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See Also

Contributors

Comments

See discussion at FoxEdit-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on February 23, 2014, at 05:08 AM