Aritcles and white papers
function RecursiveDelete($num) {
global $commentstbl;
$query = "SELECT num FROM $commentstbl WHERE ancestor='$num'";
$result = DoQuery($query, __LINE__);
if($result->num_rows == 0)
return; /* end of recursive call */
while($line = $result->fetch_assoc()) {
$n = $line['num'];
$query = "DELETE FROM comments WHERE num=$n";
$newresult = DoQuery($query, __LINE__);
RecursiveDelete($n);
}
}
function GetTimeStr($hour, $min, $sec, $month, $day, $year) {
global $timeoffset;
$time = mktime($hour, $min, $sec, $month, $day, $year, 0);
$time += ($timeoffset * 3600); /* add time offset in seconds */
$str = date("d/m/Y H:i:s", $time);
return $str;
}
/*
| AddLinks:
| Replace URL's in string with links
*/
function AddLinks($string) {
$string = preg_replace("/(^|[^=\"\/])\b((\w+:\/\/|www\.)[^\s<]+)".
"((\W+|\b)([\s<]|$))/i", "$1
$2$4",
$string);
return preg_replace("/href=\"www/i", "href=\"http://www", $string);
// $txt = preg_replace( "/(?\s]+)/i", "
\\0", $txt );
// "
}
/*
| Replace special codes in messages
*/
function SpecialCodes($str) {
$str = stripslashes($str);
$str = str_replace('<', '<', $str);
$str = str_replace('|code|', '
', $str);
$str = str_replace('|CODE|', '', $str);
$str = str_replace('|ECODE|', '
', $str);
$str = str_replace('|ecode|', '
', $str);
$str = str_replace('|b|', '
', $str);
$str = str_replace('|B|', '', $str);
$str = str_replace('|eb|', '', $str);
$str = str_replace('|EB|', '', $str);
$str = str_replace('|u|', '
', $str);
$str = str_replace('|U|', '', $str);
$str = str_replace('|eu|', '', $str);
$str = str_replace('|EU|', '', $str);
$str = str_replace("\n", "
", $str);
$str = AddLinks($str);
return $str;
}
/*
| DisplayContents:
| Show a string of section body, parsing dot commands
| currently only one command is supported
| .C that will start or stop code section
*/
function DisplayContents($contents) {
$incode = 0;
$contents = SpecialCodes($contents);
$a = explode('
', $contents);
foreach($a as $val) {
if($val[0] == '.') { /* this is a command */
if($val[1] == 'C') {
if(!$incode) {
print "
\n";
$incode++;
}
else {
print "
\n";
$incode--;
}
}
}
else {
$val = AddLinks($val);
print "$val
\n";
}
}
if($incode) {
while($incode) {
print "
\n";
$incode--;
}
}
}
/*
| DispComments:
| Recursive function to display comments for specific article
*/
function DispComments($id, $ancestor, $level, $delprivilege) {
global $commentstbl, $abspath, $l10n;
global $dir, $lang;
global $base;
// print "dir: $dir
\n";
$query = "SELECT * FROM $commentstbl WHERE article='$id' AND ancestor='$ancestor' ORDER BY time DESC";
// print "Query: $query
\n";
$result = DoQuery($query, __LINE__);
if($result->num_rows == 0)
return; /* end of recursive call */
if($level == 0)
print "
\n"; /* spacer between two threades */
while($line = $result->fetch_assoc()) {
$msgnum = $line['num'];
$title = SpecialCodes($line['title']);
if(empty($title))
$title = _("No title");
$msguser = $line['name'];
$email = $line['email'];
$website = $line['website'];
$comment = $line['comment'];
$time = $line['time'];
$i = $level * 10;
if($dir == 'rtl')
$style = "margin-right:${i}px";
else
$style = "margin-left:${i}px";
print "
\n";
print "
$title \n";
if($website)
print "
$msguser ";
else
print "$msguser \n";
list($year, $month, $day, $hour, $min, $sec) = sscanf($time, "%d-%d-%d %d:%d:%d");
$timestr = GetTimeStr($hour, $min, $sec, $month, $day, $year);
print "$timestr\n";
/* Put message contents as DIV that will be displayed when clicking on message */
print "
\n";
DisplayContents($comment);
/* show link to add response */
$id1 = urlencode($id);
$url = "${base}articlemsg.php?id=$id1&ancestor=$msgnum&lang=$lang";
$url = urlencode($url);
print "
";
print _("Add comment");
print " \n";
if($delprivilege == 1) {
$l = _("Delete comment");
$url = "?action=delcomment&id=$id1&num=$msgnum";
print "
$l\n";
print "
$email\n";
}
print "
\n";
print "
\n";
print "
\n";
DispComments($id, $msgnum, $level+1, $delprivilege, $dir);
}
}
if($action == 'delcomment') {
$num = $_GET['num'];
$query = "DELETE FROM $commentstbl WHERE num='$num'";
$result = DoQuery($query, __LINE__);
RecursiveDelete($num);
$url = urldecode($id);
print "
\n";
return;
}
$commenturl1 = urlencode($commenturl);
$url = "${base}articlemsg.php?id=$commenturl1&ancestor=0&lang=$lang";
$url = urlencode($url);
print "