");
if ($EnableCommentFormCheck == 1) {
$CommentBoxCheckFmt = "
";
# add markup (:cboxcheck:) for use when commentbox is constucted with (:input:) markup
Markup('cboxcheck', '>block', '/\\(:cboxcheck:\\)/', "CommentBoxCheckMarkup");
function CommentBoxCheckMarkup() {
return Keep($GLOBALS['CommentBoxCheckFmt']);
}
}
SDV($DiaryBoxFmt,"
");
SDV($CommentBoxFmt,"
".
($EnableCommentFormCheck ? $CommentBoxCheckFmt : "")
);
# date and time formats
SDV($JournalDateFmt,'%d %B %Y');
SDV($JournalTimeFmt,'%H:%M');
# journal and diary patterns as part of page name
SDV($JournalPattern,'/Journal$/');
SDV($DiaryPattern,'/Diary$/');
# comment authentication
SDV($HandleAuth['comment'], 'read');
$HandleActions['comment'] = 'HandleCommentPost';
Markup('cbox',''.Keep(str_replace(array('$Chrono','$PostTo','$AccessCode','$CaptchaValue'),
array($m[1], $m[2], RandomAccess(), CaptchaValueRelay()),
FmtPageName($GLOBALS['CommentBoxFmt'], $pagename)));
}
Markup('dbox',''.str_replace('$AccessCode', RandomAccess(),
FmtPageName($GLOBALS['DiaryBoxFmt'], $pagename));
}
if (preg_match($JournalPattern,$pagename) ||
preg_match($DiaryPattern,$pagename)) {
$GroupHeaderFmt .= '(:if auth edit:)(:diarybox:)(:if:)(:nl:)';
if (!PageExists($pagename)) $DefaultPageTextFmt = '';
}
if ($action=='print' || $action=='publish')
Markup('cbox',' $CommentBoxPlusMaxLinkCount) ? false : true;
}
function HandleCommentPost($pagename, $auth) {
global $JournalPattern, $DiaryPattern,
$Author, $EnablePostCaptchaRequired, $IsPagePosted,
$EnableRedirectToCommentPage, $PostToCommentPageFmt,
$EnablePostToAnyPage, $EnablePostToGroupPage, $EnablePreventDirectives;
$req = CBRequestArgs();
$currpage = $pagename; // set current page
$currgroup = PageVar($pagename, '$Group');
if(auditJP($req) == false) {
CBMessage("ERROR: Too many links in comment");
HandleBrowse($currpage);
exit;
}
if($EnablePostCaptchaRequired AND !IsCaptcha()) Redirect($pagename);
if (!$req['post'] || $req['text']=='') Redirect($pagename);
if ($req['author'] == '') $Author = 'anonymous';
// handling of postto page
if (!$req['postto'] == '') {
$tgtpage = MakePageName($pagename, $req['postto']);
$tgtgroup = PageVar($tgtpage, '$Group');
$tgtname = PageVar($tgtpage, '$Name');
if($EnablePostToAnyPage==1) $pagename = $tgtpage;
if($EnablePostToGroupPage==1 AND $tgtgroup==$currgroup )
$pagename = $tgtpage;
else {
foreach($PostToCommentPageFmt as $n ) {
$n = FmtPageName($n, $pagename);
if($n==$tgtpage) {
$tgt = 1;
$pagename = $tgtpage;
continue;
}
}
if(!isset($tgt)) {
CBMessage("ERROR: No permission to post to $tgtpage");
HandleBrowse($currpage);
exit;
}
}
}
if ($EnablePreventDirectives==1) {
$req['text'] = preg_replace('/\\(:/', '(:', $req['text']);
$req['author'] = preg_replace('/\\(:/', '(:', $req['author']);
}
$page = RetrieveAuthPage($pagename, $auth, true);
$HandleCommentFunction = (preg_match($JournalPattern,$pagename)) ? 'Journal' :
((preg_match($DiaryPattern,$pagename)) ? 'Diary' : 'Message');
$HandleCommentFunction = 'Handle' . $HandleCommentFunction . 'Post';
$newpage = $page;
$newpage['text'] = $HandleCommentFunction($pagename, $req, $page['text']);
UpdatePage($pagename, $page, $newpage);
if($EnableRedirectToCommentPage==1) Redirect($pagename);
if ($IsPagePosted && $tgtpage)
CBMessage("Successful post to $tgtpage");
HandleBrowse($currpage);
exit;
}
function FormatDateHeading($txt,$datefmt,$fmt) {
return str_replace($txt,strftime($datefmt,time()),$fmt);
}
## Journal entry
function HandleJournalPost($pagename, $req, $pagetext) {
global $JournalDateFmt,$JournalTimeFmt,$JPItemStartFmt,$JPItemEndFmt,$JPDateFmt,$JPTimeFmt,
$Author;
SDV($JPDateFmt,'>>journaldate<<(:nl:)!!!!$Date');
SDV($JPTimeFmt,"\n>>journalhead<<\n!!!!!– \$Time –\n");
SDV($JPItemStartFmt,">>journalitem<<\n");
SDV($JPItemEndFmt,"");
$date = FormatDateHeading('$Date',$JournalDateFmt,$JPDateFmt);
$time = $date . FormatDateHeading('$Time',$JournalTimeFmt,$JPTimeFmt);
$entry = $time.$JPItemStartFmt.stripmagic($req['text']).$JPItemEndFmt;
$text = (strstr($pagetext, $date)) ?
str_replace($date, $entry, $pagetext) :
"$entry\n>><<\n\n" . $pagetext;
return $text;
}
## Diary entry
function HandleDiaryPost($pagename, $req, $pagetext) {
global $JournalDateFmt,$DPDateFmt,$DPItemStartFmt,$DPItemEndFmt,$DPItemFmt;
SDV($DPDateFmt,">>diaryhead<<\n!!!!\$Date ");
SDV($DPItemStartFmt,"\n>>diaryitem<<\n");
SDV($DPItemEndFmt,"");
$date = FormatDateHeading('$Date',$JournalDateFmt,$DPDateFmt);
$entry = $date.$DPItemStartFmt.stripmagic($req['text']).$DPItemEndFmt;
$text = (strstr($pagetext, $date)) ?
str_replace($date, $entry, $pagetext) :
"$entry\n>><<\n\n" . $pagetext;
return $text;
}
## Comment entry
function HandleMessagePost($pagename, $req, $pagetext) {
global $JournalDateFmt, $JournalTimeFmt, $MPDateFmt, $MPTimeFmt, $MPAuthorLink,
$MPItemFmt, $MPItemStartFmt, $MPItemEndFmt, $MPDateTimeFmt, $MPAnchorFmt, $MPAnchorChronoFmt,
$CommentboxMessageFmt, $MultipleItemsPerDay, $Author, $PageUrl, $PostsPerPage,
$EnablePostAuthorRequired, $EnableWebsiteField, $EnablePageBreaks;
if ($EnableWebsiteField==1) {
$website = $req['website'];
$weblink = '— [-[[(http://)'.$website.']]-]';
if($req['website']=='') $weblink = '';
}
else $weblink = '';
$id = StringCount($pagename,">>messagehead<<")+1;
if ($EnablePageBreaks==1) {
$r = fmod($id-1,$PostsPerPage);
if($r==0 && $id>1) SDV($MPItemEndFmt, "\n>><<\n\n(:comment breakpage:)");
else SDV($MPItemEndFmt, "\n>><<");
}
else SDV($MPItemEndFmt,"\n>><<");
SDV($MPDateFmt,'>>messagedate<<(:nl:)!!!!$Date');
SDV($MPTimeFmt,"(:nl:)>>messagehead<<\n!!!!!\$Author — [-at \$Time-] $weblink \n");
SDV($MPItemStartFmt,">>messageitem<<\n");
SDV($MPDateTimeFmt,"(:nl:)>>messagehead<<\n!!!!!\$Author — [-\$Date, \$Time-] $weblink \n");
SDV($MultipleItemsPerDay,0); # set to 1 to have date above for multiple entries per day
SDV($MPAuthorLink, 1); # set to 0 to disable author name as link
SDV($MPAnchorFmt,"(:commentbox:)");
SDV($MPAnchorChronoFmt,"(:commentboxchrono:)");
$name = $req['author'];
if ($req['author']=='') $req['author'] = 'anonymous';
# disable anonymous posts, but this looses also any message content:
# if($EnablePostAuthorRequired == 1 && $name=='') Redirect($pagename);
if($name=='') $name = 'anonymous';
else $name = ($MPAuthorLink==1) ? '[[~' . $name . ']]' : $name;
if ($MultipleItemsPerDay) {
$date = FormatDateHeading('$Date',$JournalDateFmt,$MPDateFmt);
$entry = '[[#comment'.$id.']]';
$entry .= str_replace('$Author',$name,
FormatDateHeading('$Time',$JournalTimeFmt,$MPTimeFmt));
} else {
$date = '';
$entry = '[[#comment'.$id.']]';
$entry .= FormatDateHeading('$Date',$JournalDateFmt,
str_replace('$Author',$name,
FormatDateHeading('$Time',$JournalTimeFmt,$MPDateTimeFmt)));
}
$entry.= $MPItemStartFmt.stripmagic($req['text']).$MPItemEndFmt;
$order= $req['order'];
if ($order=='') { # order is not chrono, latest top
if (strstr($pagetext,$MPAnchorFmt)) {
$pos = strpos($pagetext,$MPAnchorFmt);
$len = strlen($MPAnchorFmt);
$before = substr($pagetext,0,$pos+$len)."\n";
$after = substr($pagetext,$pos+$len);
}
else {
$before = '';
$after = $pagetext;
}
$entry = "$date$entry";
$after = ($MultipleItemsPerDay && strstr($after, $date)) ?
str_replace($date, $entry, $after) : "$entry$after";
}
else { # order is chrono, latest last
$entry .= "\n";
if (strstr($pagetext,$MPAnchorChronoFmt)) {
$pos = strpos($pagetext,$MPAnchorChronoFmt);
$before = substr($pagetext,0,$pos);
$after = substr($pagetext,$pos);
}
else {
$before = $pagetext;
if ($before[strlen($before)-1]!='\n') $before .="\n";
$after = '';
}
$before .= ($MultipleItemsPerDay && strstr($before, $date)) ?
substr($entry,1) : "$date$entry";
}
return "$before\n$after";
}
# add page variable {$PostCount},
# counts message items per page
$FmtPV['$PostCount'] = 'StringCount($pn,">>messagehead<<")';
function StringCount($pagename,$find) {
$page = ReadPage($pagename, READPAGE_CURRENT);
$n = substr_count($page['text'], $find);
if ($n==0) return ''; #suppressing 0
return $n;
}
## get arguments from POST or GET
function CBRequestArgs ($req = NULL) {
if (is_null($req)) $req = array_merge($_GET, $_POST);
foreach ($req as $key=>$val) {
if(is_array($val))
foreach($value as $k=>$v)
$req[$key][$k] = htmlspecialchars(stripmagic($v),ENT_NOQUOTES);
else $req[$key] = htmlspecialchars(stripmagic($val),ENT_NOQUOTES);
}
return $req;
}
## display message
function CBMessage($msg) {
global $MessagesFmt;
$MessagesFmt[] = "$[$msg]
";
}
//EOF