\\[\\[#([A-Za-z]+\\-\\d+[-.:\\w]*))\\]\\]/e', "FoxEditAnchor(\$pagename, '$1')"); function FoxEditAnchor($pagename, $x) { global $HTMLStylesFmt; if (TrackAnchors($x)) return ''; $out = ''; if (CondAuth($pagename, 'edit')) { $HTMLStylesFmt['foxsectionedit'] = " .foxsectionedit { font-size:12px; font-style:normal; font-weight:400;} "; $out .= "".FoxEditLinkMarkup($pagename, 'section=#'.$x.' label=(edit) tooltip=\'edit '.$x.'\'').""; } $out .= ""; return Keep($out); } # ROS Pattern for preserving one empty line before each line with foxedit anchor $ROSPatterns['/(?.*?\\[\\[#([A-Za-z]+\\-\\d+[-.:\\w]*))\\]\\])/'] = "\n\n$1"; } # make it possible to treat [[#section]] .... [[#sectionend]] as a PTV of name 'section' $PageTextVarPatterns['[[#anchor]]'] = "/(\\[\\[#(\\w[-\\w]*)\\]\\](?: *\n)?)(.*?)(\\[\\[#\\2end\\]\\])/s"; //Handle section edit by setting page vars and loading edit form $HandleActions['foxedit'] = 'FoxHandleEdit'; function FoxHandleEdit($pagename) { global $FoxAuth, $EditSource, $EditTarget, $EditSection, $InputValues, $FmtV, $FmtPV, $FoxMsgFmt, $FoxEditPTVSectionForm, $FoxEditPageSectionForm, $PageStartFmt, $PageEndFmt, $FoxPageEditFmt, $EnableFoxEditFormCheck, $QualifyPatterns, $FoxCheckError, $FoxEditForm; //check if function is called by Fox preview if ($_POST['preview'] || $FoxCheckError==1) $args = $_SESSION['foxedit'][$pagename]; //fetch arguments from url of first foxedit call else { $args = RequestArgs(); //fetch GET or POST arguments FoxURLArgs($pagename); //set url arguments for use with preview } #echo "
\$args "; print_r($args); echo "
"; //DEBUG $EditSource = (isset($args['source'])) ? $args['source'] : $pagename; $target = (isset($args['target'])) ? $args['target'] : $EditSource; $prefix = (isset($args['prefix']) ? $args['prefix'] : ''); $section = (isset($args['section']) ? urldecode($args['section']) : ''); //open targetpage, get section, set InputValues for 'text' control $fulltarget = $target.$section; $EditTarget = MakePagename($pagename, $target); $page = RetrieveAuthPage($EditTarget, $FoxAuth, true); if (!$page) Abort( "?cannot read $page"); $text = $page['text']; //check if we got fullpage edit if ($section=='') { $mode = 'section'; $formpage = $FoxEditPageSectionForm; //default can open whole page for editing } //check if we got anchored section, else section is ptv else { if (strstr($section,'#')) { $mode = 'section'; $text = TextSection($page['text'], $fulltarget, array('anchors' => 1)); if (empty($text)) FoxAbort($pagename,"$[Error: cannot find section] '$EditSection'"); $formpage = $FoxEditPageSectionForm; } else { $mode = 'ptv'; $QualifyPatterns = NULL; //prevent substitutions by Qualify function $text = PageTextVar($EditSource, $section); $formpage = $FoxEditPTVSectionForm; } } //check if we should use a specified form if (isset($args['form'])) { $formpage = $args['form']; if ($section=='') $mode = ''; //no $mode since it could be whole page edit or ptv edit } //get text for insertion in editform textarea if ($InputValues['text']) $EditText = $InputValues['text']; else $EditText = $InputValues['text'] = str_replace('$','$',htmlspecialchars($text,ENT_NOQUOTES)); //set global $EditSection $EditSection = $prefix.$section; //retrieve edit form from page or page section $formpage = FmtPageName($formpage, $pagename); if ($formpage) { $formname = MakePageName($pagename, $formpage); if (PageExists($formname)) { $eform = RetrieveAuthSection($formname, $formpage); if ($eform=='') $FoxMsgFmt[] = "$[Warning: cannot find edit form] '''$formpage'''. Using basic edit form instead."; if (IsEnabled($EnableFoxEditFormCheck, 1)) { //check if edit form is the right type if (preg_match("/\\(:input\\s+([^\\)]+)\\s*name\\=\\$:/",$eform)) { if ($mode=='section') Abort( "Error: wrong PTV name in foxedit link or edit form not suitable for PTV editing!"); } else if ($mode=='ptv') Abort("Error: wrong section name in foxedit link or edit form not suitable for section editing!"); } } } //if no form, use hardcoded basic form, either for ptv or section edit if (!$formpage || empty($eform)) { $eform = "%red%(:foxmessages:)\n"; if ($mode=='ptv') $eform .= "(:fox eform ptvtarget=$target template=0 redirect=1:)"; else $eform .= "(:fox eform foxaction=replace put=overwrite target=$fulltarget :)" ."\n(:foxtemplate \"{\$\$text}\":)"; $eform .= "\n(:input hidden csum 'Section edited':)" ."\n'''Editing $target section $section'''" ."(:input defaults source={$EditSource}:)"; if ($mode=='ptv') $eform .= Keep("

"); else $eform .= Keep("

"); $eform .= "\n(:input submit post '$[Save]':)   (:input submit cancel '$[Cancel]':)" ."\n(:foxend eform:)"; } $FmtV['$FoxEditFrm'] = MarkupToHTML($pagename, $eform); $FoxPageEditFmt = '$FoxEditFrm'; $HandleEditFmt = array(&$PageStartFmt, &$FoxPageEditFmt, &$PageEndFmt); PrintFmt($pagename, $HandleEditFmt); exit; } //}}} Markup('foxeditlink','directives','/\\{\\[foxedit\\s*(.*?)\\s*\\]\\}/e', "FoxEditLinkMarkup(\$pagename, PSS('$1'))"); // make {[foxedit...]} link HTML function FoxEditLinkMarkup ($pagename, $args) { $PageUrl = PageVar($pagename, '$PageUrl'); $args = ParseArgs($args); $args[''] = (array)@$args['']; $section = (isset($args['section'])) ? $args['section'] : array_shift($args['']); $section = urlencode($section); $form = isset($args['form']) ? urlencode($args['form']) : ''; $label = (isset($args['label'])) ? $args['label'] : array_shift($args['']); $target = (isset($args['target'])) ? MakePageName($pagename,$args['target']) : ''; $source = (isset($args['source'])) ? MakePageName($pagename,$args['source']) : ''; if(!$label) $label = XL('Edit'); $url = "{$PageUrl}?action=foxedit". ($source ? "&source={$source}" : ""). ($target ? "&target={$target}" : ""). ($form ? "&form={$form}" : ""). (isset($args['prefix']) ? "&prefix={$args['prefix']}" : ""). ($section ? "&section={$section}" : ""); $out = "{$label}"; return Keep($out); } //}}} //make argument array out of url parameters function FoxURLArgs($pn) { @session_start(); $_SESSION['foxedit'][$pn] = array(); //get url if ($_SERVER["HTTPS"] == "on") $pageURL .= "https://"; else $pageURL .= "http://"; if ($_SERVER["SERVER_PORT"] != "80") $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; else $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; //use only argument string (form first ?), process it $args = strstr(strip_tags(urldecode($pageURL)),'?'); $args = str_replace('?',' ',$args); $args = str_replace('&',' ',$args); $args = htmlentities($args); //just to be safe... //make into array $args = ParseArgs($args); unset($args['#']); //save as SESSION var $_SESSION['foxedit'][$pn] = $args; return $args; } //}}}