",$targetname);
}
Markup('adlform','directives','/\(:adl form (.*?):\)/e',"Keep(AdlFormMarkup(\$pagename,PSS('$1')))");
Markup('adlform2','
",$targetpagename);
}
else
{
return FmtPageName("$[Delete]",$targetpagename);
}
}
Markup('adldeleteline','directives','/\(:adl delete (\w+) (.*?):\)/e',"Keep(AdlDeleteMarkup(PSS('$1'),PSS('$2')))");
Markup('adldeletelink','directives','/\(:adl deletelink (\w+) (.*?):\)/e',"Keep(AdlDeleteMarkup(PSS('$1'),PSS('$2'), true))");
Markup('adldeleterange','directives','/\(:adl delrange (\w+) (.*?):\)/e',"Keep(AdlDeleteMarkup(PSS('$1'),PSS('$2')))");
Markup('adldeletedummy','directives','/\(:adl delete:\)/e','Keep(AdlDeleteMarkup())');
Markup('adldeleterangedummy','directives','/\(:adl delrange:\)/e','Keep(AdlDeleteMarkup())');
# Creates the HTML code for (:adl template:)
# $fieldname is the name of the hidden form field, that is created by this function
# $template is the page template
function AdlTemplateMarkup($fieldname,$template) {
return '';
}
Markup('adltemplate','[=','/\(:adl template "(.*)":\)/e',"Keep(AdlTemplateMarkup('adltemplate',PSS('$1')))");
# Creates the HTML code for (:adl templatepage:)
# $fieldname is the name of the hidden form field, that should be the result
# $pagename is the name of the current page
# $templatepage is the name of the template page
function AdlTemplatePageMarkup($fieldname, $pagename, $templatepage) {
$templatepage = MakeLink($pagename,$templatepage,NULL,'','$FullName');
$page = RetrieveAuthPage($templatepage,"read");
if (!$page) { Abort("?cannot read $templatepage"); }
return AdlTemplateMarkup($fieldname,$page['text']);
}
Markup('adltemplatepage', 'directives','/\\(:adl templatepage\\s+(\\S.*?):\\)/ei', # This line is a modified version of PMs (:redirect:)
"Keep(AdlTemplatePageMarkup('adltemplate',\$pagename, PSS('$1')))");
# (:adl version:)
Markup('adlversion','directives','/\(:adl version:\)/e',"Keep('$AdlVersion')");
# (:adl end:)
Markup('adlendform','directives','/\(:adl end:\)/',"");
# (:adl prepend:) and (:adl append:) just vanish because they are only used later in AdlHandleAddLine
Markup('adlprepend','directives','/\(:adl prepend (.*?):\)/e','');
Markup('adlappend','directives','/\(:adl append (.*?):\)/e','');
# Markup for the #adl begin# and #adl end# marks. These marks should vansih as early as possible in the markup processing
# in order to allow markup like "! Header" to be process (which needs the stand at the beginning of the line.
Markup('adlentrybegin','_begin','/#adl begin( \w+)?#/','');
Markup('adlentryend','_begin','/#adl end( \w+)?#/','');
# Posts the text to the current page (calls the edit handler)
function AdlPost($text) {
global $HandleActions, $pagename;
$_POST['text']=get_magic_quotes_gpc()?addslashes($text):$text;
$handle = $HandleActions['edit'];
$_POST['post']='Save ';
return $handle($pagename);
}
# Delete one line from the wiki page
$HandleActions['deleteline']='AdlHandleDeleteLine';
function AdlHandleDeleteLine($pagename) {
$page = RetrieveAuthPage($pagename,"read");
if (!$page) { Abort("?cannot edit $pagename"); }
if(isset($_POST['linekey'])) $key = stripmagic($_POST['linekey']); # Retrieve the line-key
else $key = stripmagic($_GET['linekey']);
$newtext = $page['text']."\n"; # Add a newline so the the following regexes also work for the last line.
# Remove the line containing the delete statement with the provided line-key (if it exists)
$newtext = preg_replace("/^.*\(:adl delete(link)? $key $pagename:\).*\\n/m","",$newtext);
# Remove the range containing the delrange statement with the provided line-key (if it exists)
$newtext = preg_replace('/#adl begin '.$key.'#.*?\(:adl delrange '.$key.' '.$pagename.':\).*?#adl end '.$key.'#\n/s',"",$newtext);
# Remove the added newline character: This is either the newline we inserted, or the newline in front of the
# line we removed. Or, if the text was only one line with no newline at all, it is now empty, which should not be a problem.
chop($newtext);
return AdlPost($newtext);
}
# Processes the $template and inserts the values of $fields[].
# $fields is an array that is filled into the template
# $template is the template
# $linekeyseed is an optional parameter that allows the caller to specify a seed for the linekey
# that is used to identify the range in the delete-action.
# $targetpagename an optional parameter that is name of the page, where the data is to be stored. This
# is mainly used in order to fill in the pagename into the (:adl del[ete|range]:) directives.
#
# The engine returns an array of entries each of which contains a string. If no markup of the form {name[]}
# is present in the template, the array will contain exactly one entry, where the usual text substitutions have
# been performed.
# If a {name[]} markup is present, $fields['name'] has to be an array. For each element of $fields['name'],
# one entry is found in the array, where all the other fields are replicated, but {name[]} is subsituted
# by each element of $fields['name'].
# If more than one markups {name[]} are present, the outcome is undefined...
#
function AdlTemplateEngine($fields, $template,$linekeyseed=NULL,$targetpagename=NULL) {
global $pagename;
if ($targetpagename == NULL) { $targetpagename = $pagename; }
$string = $template;
# create the data to be added, from template and variables
$string = preg_replace('/\\\\n/',"\n",$string); # replace \n by newlines
$string = preg_replace('/\{date\:(.*?)\}/e',"date(PSS('$1'))",$string); # replace {date:fmt}
$string = preg_replace('/\{strftime\:(.*?)\}/e',"strftime(PSS('$1'))",$string); # replace {strftime:fmt}
$string = preg_replace('/\{([^[]*?)\}/e',"stripmagic(\$fields[PSS('$1')])",$string); # replace {name} fields
if(preg_match('/\{(.*?)\[\]\}/', $string, $m)) {
list($x, $name) = $m;
$result = Array();
foreach((array)$_POST[$name] as $val) {
if ($val) {
$result[] = preg_replace("/\{$name\[\]\}/", $val, $string);
}
}
} else {
$result = Array($string);
}
# Create a unique linekeyseed, if necessary
if ($linekeyseed==NULL) {
$linekeyseed=time().'a'.rand(0,100000);
}
foreach ($result as $index => $entry) {
$linekey = $linekeyseed.'b'.$index;
$entry = str_replace('(:adl delete:)',"(:adl delete $linekey $targetpagename:)",$entry); # Add linekey to delete statements
$entry = str_replace('(:adl deletelink:)',"(:adl deletelink $linekey $targetpagename:)",$entry); # for link-delete
$entry = str_replace('(:adl delrange:)',"(:adl delrange $linekey $targetpagename:)",$entry); # Add linekey to delete statements
$entry = str_replace('#adl begin#',"#adl begin $linekey#",$entry); # Add line-key to delete statements
$entry = str_replace('#adl end#',"#adl end $linekey#",$entry); # Add line-key to delete statements
$result[$index] = $entry;
}
return $result;
}
# Insert text into the wiki page
$HandleActions['addline']='AdlHandleAddLine';
function AdlHandleAddLine($pagename) {
global $HandleActions,$action,$ScriptUrl;
$page = RetrieveAuthPage($pagename,"read");
if (!$page) { Abort("?cannot edit $pagename"); }
$newentries = AdlTemplateEngine($_POST,html_entity_decode(stripmagic($_POST['adltemplate']))); # Decode the template
$addstring = join("\n",$newentries);
# Handle the special names #top and #bottom
if ($_POST['adlname'] == '#top') {
return AdlPost($addstring."\n".$page['text']);
}
if ($_POST['adlname'] == '#bottom') {
return AdlPost($page['text']."\n".$addstring);
}
# Handle locations specified by 'adl prepend' and 'adl append'
$text = split("\n",$page['text']);
# Look for (:adl append:) statements and append the $
$appendcmd='(:adl append '.stripmagic($_POST['adlname']).':)';
foreach ($text as $nr => $line) {
if ($line==$appendcmd) {
$text[$nr]=$addstring."\n$line";
}
}
$prependcmd='(:adl prepend '.stripmagic($_POST['adlname']).':)';
foreach ($text as $nr => $line) {
if ($line==$prependcmd) {
$text[$nr] = "$line\n".$addstring;
}
}
return AdlPost(join("\n",$text));
}
# vi:shiftwidth=4:autoindent:softtabstop=4:expandtab:
?>