<?php
class PluginMethodFactory extends MethodFactory {
var $theme;
var $gui;
function PluginMethodFactory() {
$this->MethodFactory();
$this->getUserinfo();
}
// Pulls a topic for a story ID and returns its info.
function getUserinfo() {
global $userinfo;
global $dbh;
if (isset($userinfo)) {
$sql = "SELECT name, value FROM article_userinfo where uid= '$userinfo[id]'";
$result= $dbh->Execute($SQL);
while(list($name,$value) = $result->fields) {
$userinfo[article][$name] = $value;
$result->MoveNext();
}
}
}
function getTopics($id) {
global $dbh;
$topic = array();
$sql = <<<END_SQL
SELECT t.id, t.name, t.image, t.description
FROM article_topic t, article a
where a.id = $id and t.id = a.topic
END_SQL;
$result= $dbh->Execute($sql);
!$result ? die("SQL: $sql -- " . $dbh->ErrorMsg()) : '';
return $result->fields;
}
function layerComments($result) {
global $config;
global $userinfo;
global $dbh;
global $gui;
$result->MoveFirst();
$view_parent = $result->fields[parent];
while ($parent_data = $result->fields) {
$this->comment_level = 0;
$result->MoveNext();
$date = $this->formatDBTimestamp($parent_data[create_date]);
if (isset($parent_data[alias]) && $parent_data[alias] != '' ) {
$author = $parent_data[alias];
} elseif (isset($parent_data[alias]) && $parent_data[alias] != '' ) {
$author = $parent_data[name];
} else {
$author = "Anonymous";
}
$content = nl2br($parent_data[content]);
$out .= <<<END_HTML
<tr><td class=commentheader>
<div class=commenttitle>{$parent_data[subject]}</div>
<div class=commentauthor>by $author ($date)</div>
</td></tr>
<tr><td class=commentcontent>
$content
</td></tr>
<tr><td class=commentfunction align=right>
<p>[<a href="$config[site_url]/plugins/article/comment.php?operation=add&form_parent_id=$parent_data[id]&form_article_id=$parent_data[aid]">Reply to Comment</a>]
</td></tr>
<tr><td class=commentreplies>
END_HTML;
$out .= $this->getChildComments($parent_data, $view_parent);
$out .= "</td></tr>";
}
unset ($this->comment_level);
return $out;
}
function getChildComments($parent, $view_parent = 0) {
global $config;
global $userinfo;
global $dbh;
global $gui;
$parent_id = $parent[id];
if ($userinfo[article][max_comment_depth]) {
$max_comment_depth = $userinfo[article][max_comment_depth];
} elseif($config[article][max_comment_depth]) {
$max_comment_depth = $config[article][max_comment_depth];
} else {
$max_comment_depth = "2";
}
$this->comment_level++;
$sql = <<<END_SQL
select a.id, a.parent, u.name, u.alias, a.subject, a.create_date
from article_comment a, users u
where a.uid = u.id
and a.parent = $parent_id
order by a.create_date
END_SQL;
$result = $dbh->Execute($sql);
!$result ? die("SQL: $sql -- " . $dbh->ErrorMsg()) : '';
if ($this->comment_level >= $max_comment_depth && isset($result->fields[id])) {
$rec_count = $result->RecordCount();
$rec_count = ($rec_count < 0) ? "Unknown" : $rec_count;
$pl = ($rec_count != 1) ? 's':'';
$out = "<ul>...$rec_count comment$pl below current level.</ul>";
$this->comment_level--;
return $out;
}
$out = "<ul>";
while ($child_data = $result->fields) {
$result->MoveNext();
$out .= <<<END_HTML
<li><a href="$config[site_url]/plugins/article/search.php?operation=search&searchby=article&searchid={$gui->search[id]}&form_comment_id=$child_data[parent]&form_parent_id=0">$child_data[subject]</a> ($child_data[create_date])</li>
END_HTML;
$out .= $this->getChildComments($child_data);
}
$this->comment_level--;
$out .= "</ul>";
return $out;
}
function parseReplyContent($content = '') {
global $config;
if ($content == '') {
return;
}
$out = "---- Reply to comment ----\n";
// Make lines for the content (break at XX cols).
$lines = explode ("\n", wordwrap($content, $config[article][comment_reply_width]));
// Append '>' content reply marker.
while (list ($k,$v) = each($lines)) {
$out .= $config[article][comment_reply_marker] . "$v\n";
}
// Returned parsed content.
return $out;
}
}
?>