PHPクラスを長時間使用してSemantic UI threaded comments HTMLを生成しようとしましたが、残念ながらそれはできませんでした。ここで意味クラスを生成するPHPクラススレッド化されたコメントHTML
は正常に動作しませんでした私の現在のクラスです:
class SemanticUiThreadedComments {
function PrintComments($comments) {
/** Comment prepare start */
foreach ($comments as $k => &$v) {
if ($v['comment_parent'] != 0) {
$comments[ $v['comment_parent'] ]['children'][] =& $v;
}
}
unset($v);
foreach ($comments as $k => $v) {
if ($v['comment_parent'] != 0) {
unset($comments[ $k ]);
}
}
/** Comment prepare end */
$html = '';
$html .= '<div class="ui threaded comments">';
$html .= '<h3 class="ui dividing header">'.__('Comments','trusty').'</h3>';
ob_start();
$this->PrintSingleComments($comments);
$html .= ob_get_clean();
$html .= $this->reply_form();
$html .= '</div>';
return $html;
}
function indent($size) {
$string = '';
for ($i = 0; $i < $size; $i++) {
$string .= '</div>';
}
echo $string;
}
function PrintSingleComments($comments, $indent = 0) {
foreach ($comments as $comment) {
echo $this->comment($comment, 1);
if (! empty($comment['children'])) {
$this->PrintSingleComments($comment['children'], $indent + 1);
}
$div_num = $indent + 1;
$this->indent($div_num);
}
}
function comment($comment) {
ob_start();
echo '<div class="comment" id="'.$comment['comment_id'].'">';
echo $this->avatar();
echo $this->content();
echo (! empty($comment['children']))? '<div class="comments">':'</div>';
$html = ob_get_clean();
return $html;
}
function avatar() {
$html = '';
$html .= '<a class="avatar">';
$html .= '<img src="/images/avatar/small/matt.jpg">';
$html .= '</a>';
return $html;
}
function content() {
$html = '';
$html .= '<div class="content">';
$html .= '<a class="author">Matt</a>';
$html .= '<div class="metadata">';
$html .= '<span class="date">Today at 5:42PM</span>';
$html .= '</div>';
$html .= '<div class="text">';
$html .= 'How artistic!';
$html .= '</div>';
$html .= '<div class="actions">';
$html .= '<a class="reply">Reply</a>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
function reply_form() {
$html = '';
$html .= '<form class="ui reply form">';
$html .= '<div class="field">';
$html .= '<textarea></textarea>';
$html .= '</div>';
$html .= '<div class="ui primary submit labeled icon button">';
$html .= '<i class="icon edit"></i> Add Reply';
$html .= '</div>';
$html .= '</form>';
return $html;
}
}
$comments = array(
1 => array('comment_id' => 1, 'comment_parent' => 0, 'children' => array()),
2 => array('comment_id' => 2, 'comment_parent' => 0, 'children' => array()),
3 => array('comment_id' => 3, 'comment_parent' => 0, 'children' => array()),
5 => array('comment_id' => 5, 'comment_parent' => 0, 'children' => array()),
11 => array('comment_id' => 11, 'comment_parent' => 0, 'children' => array()),
17 => array('comment_id' => 17, 'comment_parent' => 0, 'children' => array()),
23 => array('comment_id' => 23, 'comment_parent' => 0, 'children' => array()),
28 => array('comment_id' => 28, 'comment_parent' => 0, 'children' => array()),
4 => array('comment_id' => 4, 'comment_parent' => 1, 'children' => array()),
6 => array('comment_id' => 6, 'comment_parent' => 1, 'children' => array()),
8 => array('comment_id' => 8, 'comment_parent' => 2, 'children' => array()),
9 => array('comment_id' => 9, 'comment_parent' => 2, 'children' => array()),
7 => array('comment_id' => 7, 'comment_parent' => 3, 'children' => array()),
12 => array('comment_id' => 12, 'comment_parent' => 7, 'children' => array()),
13 => array('comment_id' => 13, 'comment_parent' => 12, 'children' => array()),
);
$threaded_comments = new SemanticUiThreadedComments();
echo $threaded_comments->PrintComments($comments);
私は制限の任意の種類を望んでいない、例えば、コメントはネジ付きの10個のレベルを有することができます子供のコメント。
このクラスをどのように動作させるか、これを達成するためのよりよい方法については、何か提案をいただければ幸いです。