My personal blog. https://blog.airikr.me
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

244 lines
7.4 KiB

<?php
require_once 'site-header.php';
$is_unique = false;
if(isvalid_md5(strip_tags(htmlspecialchars($_GET['ide'])))) {
$is_unique = true;
$identity = strip_tags(htmlspecialchars($_GET['ide']));
$author = sql("SELECT visitor_name
FROM comments
WHERE comment_identity = :_identity
LIMIT 1
", Array(
'_identity' => $identity
), 'fetch');
$get_comments = sql("SELECT *,
c.id AS id_c,
p.id AS id_p
FROM comments AS c
JOIN posts AS p
ON c.id_post = p.id
WHERE c.comment_identity = :_identity
AND p.is_inenglish ".($viewing_in_english == true ? "IS NOT" : "IS")." NULL
ORDER BY c.timestamp_published DESC
", Array(
'_identity' => $identity
));
$c_comments = sql("SELECT COUNT(visitor_name)
FROM comments AS c
JOIN posts AS p
ON c.id_post = p.id
WHERE c.comment_identity = :_identity
AND p.is_inenglish ".($viewing_in_english == true ? "IS NOT" : "IS")." NULL
", Array(
'_identity' => $identity
), 'count');
$p_mostcommented = sql("SELECT p.id_unique, p.subject, COUNT(visitor_name) AS c_comments
FROM posts AS p
JOIN comments AS c
ON p.id = c.id_post
WHERE c.comment_identity = :_identity
AND p.is_inenglish ".($viewing_in_english == true ? "IS NOT" : "IS")." NULL
GROUP BY p.id, p.subject
ORDER BY c_comments DESC, p.subject ASC
LIMIT 1
", Array(
'_identity' => $identity
), 'fetch');
} else {
$name = strip_tags(htmlspecialchars(ucwords(str_replace('-', ' ', $_GET['ide']))));
$author = sql("SELECT visitor_name
FROM comments
WHERE visitor_name LIKE :_name
LIMIT 1
", Array(
'_name' => '%'.$name.'%'
), 'fetch');
$get_comments = sql("SELECT *,
c.id AS id_c,
p.id AS id_p
FROM comments AS c
JOIN posts AS p
ON c.id_post = p.id
WHERE c.visitor_name LIKE :_name
AND p.is_inenglish ".($viewing_in_english == true ? "IS NOT" : "IS")." NULL
ORDER BY c.timestamp_published DESC
", Array(
'_name' => '%'.$name.'%'
));
$c_comments = sql("SELECT COUNT(visitor_name)
FROM comments AS c
JOIN posts AS p
ON c.id_post = p.id
WHERE c.visitor_name LIKE :_name
AND p.is_inenglish ".($viewing_in_english == true ? "IS NOT" : "IS")." NULL
", Array(
'_name' => '%'.$name.'%'
), 'count');
$p_mostcommented = sql("SELECT p.id_unique, p.subject, COUNT(visitor_name) AS c_comments
FROM posts AS p
JOIN comments AS c
ON p.id = c.id_post
WHERE c.visitor_name LIKE :_name
AND p.is_inenglish ".($viewing_in_english == true ? "IS NOT" : "IS")." NULL
GROUP BY p.id, p.subject
ORDER BY c_comments DESC, p.subject ASC
LIMIT 1
", Array(
'_name' => '%'.$name.'%'
), 'fetch');
}
echo '<section id="comment-author">';
echo '<h1>'.($viewing_in_english == false ? 'Kommentarer från' : 'Comments from').' '.$author['visitor_name'].'</h1>';
if($c_comments == 0) {
echo '<div class="message">';
echo ($viewing_in_english == false ? 'Kunde inte hitta några kommentarer' : 'Couldn\'t find any comments');
echo '</div>';
} else {
if($is_unique == false) {
echo '<div class="not-unique small-text">';
if($viewing_in_english == false) {
echo '<p>Kommentarerna nedan kanske inte är från en och samma person. Om du har skickat någon kommentar som visas här och vill äga den, klicka på kommentarens id-nummer och välj sen "Hantera". Ange sen din e-postadress i formuläret.</p>';
} else {
echo '<p>The comments below might not be from the same person. If you have written one of the comments and wants to own it, hit the comment\'s ID and then hit "Manage". After that, enter your email address in the form.</p>';
}
echo '</div>';
}
echo '<div>';
echo '<div class="list">';
foreach($get_comments AS $comment) {
$url = (empty($comment['visitor_url']) ? null : parse_url($comment['visitor_url']));
$post = sql("SELECT *
FROM posts
WHERE id = :_idpost
", Array(
'_idpost' => (int)$comment['id_p']
), 'fetch');
if($comment['visitor_email'] != null) {
$comment_identity = MD5($comment['visitor_name'] . $comment['visitor_email'] . (empty($comment['visitor_url']) ? '' : $comment['visitor_url']));
} else {
$comment_identity = strtolower(str_replace(' ', '-', trim($comment['visitor_name'])));
}
echo '<div class="item">';
echo '<div class="post">';
echo '<a href="'.url('read:'.$post['id_unique']).'">';
echo $post['subject'];
echo '</a>';
echo '</div>';
echo '<div class="top">';
echo '<div class="avatar" style="background-image: url('.url('avatar:'.str_replace(' ', '-', trim($comment['visitor_name'])) . ($comment['visitor_url'] == null ? '' : $comment['visitor_url']), true).');"></div>';
echo '<div class="information" id="'.(int)$comment['id'].'">';
echo '<div>';
echo '<div class="id">';
echo '<a href="'.url('read:'.$post['id_unique'].'#'.(int)$comment['id_c']).'">';
echo '#'.(int)$comment['id_c'];
echo '</a>';
echo '</div>';
echo '<div class="name">';
echo '<a href="'.url('comment-author:'.$comment_identity).'" title="Se alla kommentarer från '.trim($comment['visitor_name']).'">';
echo trim($comment['visitor_name']);
echo '</a>';
echo '</div>';
if($url != null) {
echo '<div class="url">';
echo link_($url['host'] . (isset($url['path']) ? '<span class="path">'.$url['path'].'</span>' : ''), $comment['visitor_url']);
echo '</div>';
}
echo '</div>';
echo '<div>';
echo '<div class="published small-text">';
echo date_($comment['timestamp_published'], 'full');
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="comment">';
echo preg_replace('/(?<!\S)#([0-9a-zA-Z]+)/', '<a href="javascript:void(0)" class="link-id" data-idcomment="$1">#$1</a>', $Parsedown->text(emoji_convert($comment['visitor_comment'])));
echo '</div>';
echo '</div>';
}
echo '</div>';
echo '<div class="statistics small-text">';
echo '<h2>'.($viewing_in_english == false ? 'Statistik' : 'Statistics').'</h2>';
echo '<div class="item">';
echo '<div class="label">';
echo ($viewing_in_english == false ? 'Antalet kommentarer' : 'Number of comments');
echo '</div>';
echo '<div class="value">';
echo format_number($c_comments, 0);
echo '</div>';
echo '</div>';
echo '<div class="item">';
echo '<div class="label">';
echo ($viewing_in_english == false ? 'Mest kommenterade inlägget' : 'Most commented post');
echo '</div>';
echo '<div class="value">';
echo '<a href="'.url('read:'.$p_mostcommented['id_unique']).'">';
echo $p_mostcommented['subject'];
echo '</a>';
echo ' ('.$p_mostcommented['c_comments'].')';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
}
echo '</section>';
require_once 'site-footer.php';
?>