Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to enable/disable comments per post #816

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lang/en_US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,6 @@ msg_error_field_req_feedurl = "You need to specify the feed url."
rss_feeds_description_select = "RSS Description"
rss_description_body = "Post Body"
rss_description_meta = "Post Meta Description"
comment_state = "Comments Status"
comments_enabled = "Enabled"
comments_disabled = "Disabled"
22 changes: 16 additions & 6 deletions system/admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function remove_accent($str)
}

// Add content
function add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description = null, $media = null, $dateTime = null, $autoSave = null)
function add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $comments, $description = null, $media = null, $dateTime = null, $autoSave = null)
{
if (!is_null($autoSave)) {
$draft = 'draft';
Expand Down Expand Up @@ -213,12 +213,17 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty
} else {
$tagmd = "";
}
if ($media!== null) {
$post_media = "\n<!--" .$type. " " . preg_replace('/\s\s+/', ' ', strip_tags($media)) . " " .$type. "-->";
if ($media !== null) {
$post_media = "\n<!--" . $type . " " . preg_replace('/\s\s+/', ' ', strip_tags($media)) . " " . $type . "-->";
} else {
$post_media = "";
}
$post_content = "<!--t " . $post_title . " t-->" . $post_description . $tagmd . $post_media . "\n\n" . $content;
if ($comments == "false") {
$comment = "\n<!--no-comments-->";
} else {
$comment = "";
}
$post_content = "<!--t " . $post_title . " t-->" . $post_description . $tagmd . $comment . $post_media . "\n\n" . $content;

if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) {

Expand Down Expand Up @@ -273,7 +278,7 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty
}

// Edit content
function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination = null, $description = null, $date = null, $media = null, $autoSave = null)
function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $comments, $destination = null, $description = null, $date = null, $media = null, $autoSave = null)
{
$tag = explode(',', preg_replace("/\s*,\s*/", ",", rtrim($tag, ',')));
$tag = array_filter(array_unique($tag));
Expand Down Expand Up @@ -363,7 +368,12 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
} else {
$post_media = "";
}
$post_content = "<!--t " . $post_title . " t-->" . $post_description . $tagmd . $post_media . "\n\n" . $content;
if ($comments == "false") {
$comment = "\n<!--no-comments-->";
} else {
$comment = "";
}
$post_content = "<!--t " . $post_title . " t-->" . $post_description . $tagmd . $comment . $post_media . "\n\n" . $content;

$dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type . '/';
$dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/';
Expand Down
6 changes: 6 additions & 0 deletions system/admin/views/add-content.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ function extractLast( term ) {
<label for="pMeta"><?php echo i18n('Meta_description');?> (<?php echo i18n('optional');?>)</label>
<textarea id="pMeta" class="form-control" name="description" rows="3" cols="20" placeholder="<?php echo i18n('If_left_empty_we_will_excerpt_it_from_the_content_below');?>"><?php if (isset($p->description)) { echo $p->description;} ?></textarea>
<br>
<label for="pComments"><?php echo i18n('Comment_State');?></label>
<select id="pComments" class="form-control" name="comments">
<option value="true" selected><?php echo i18n('Comments_enabled');?></option>
<option value="false"><?php echo i18n('Comments_disabled');?></option>
</select>
<br>
</div>

<div class="col-sm-6">
Expand Down
7 changes: 7 additions & 0 deletions system/admin/views/edit-content.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$oldtitle = get_content_tag('t', $content, 'Untitled');
$olddescription = get_content_tag('d', $content);
$oldtag = get_content_tag('tag', $content);
$oldcomment = check_comments_state($content);
$oldcontent = remove_html_comments($content);

$oldimage = get_content_tag('image', $content);
Expand Down Expand Up @@ -155,6 +156,12 @@ function extractLast( term ) {
<label for="pMeta"><?php echo i18n('Meta_description');?> (<?php echo i18n('optional');?>)</label>
<textarea id="pMeta" class="form-control" name="description" rows="3" cols="20" placeholder="<?php echo i18n('If_left_empty_we_will_excerpt_it_from_the_content_below');?>"><?php if (isset($p->description)) { echo $p->description; } else { echo $olddescription;} ?></textarea>
<br>
<label for="pComments"><?php echo i18n('Comment_State');?></label>
<select id="pComments" class="form-control" name="comments">
<option value="true" <?php if($oldcomment == "true") { echo 'selected="selected"';} ?>><?php echo i18n('Comments_enabled');?></option>
<option value="false" <?php if($oldcomment == "false") { echo 'selected="selected"';} ?>><?php echo i18n('Comments_disabled');?></option>
</select>
<br>
</div>

<div class="col-sm-6">
Expand Down
47 changes: 27 additions & 20 deletions system/htmly.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@
$category = from($_REQUEST, 'category');
$date = from($_REQUEST, 'date');
$time = from($_REQUEST, 'time');
$comments = from($_REQUEST, 'comments');
$dateTime = null;
if ($date !== null && $time !== null) {
$dateTime = $date . ' ' . $time;
Expand All @@ -736,17 +737,17 @@
}

if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime);
add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime, $comments);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime);
add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime, $comments);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime);
add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime, $comments);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime);
add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime, $comments);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime);
add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime, $comments);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime);
add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime, $comments);
} else {
$message['error'] = '';
if (empty($title)) {
Expand Down Expand Up @@ -799,6 +800,7 @@
'postAudio' => $audio,
'postTag' => $tag,
'postUrl' => $url,
'postComments' => $comments,
'postContent' => $content,
'type' => $type,
'is_admin' => true,
Expand Down Expand Up @@ -914,6 +916,7 @@
$addEdit = $_REQUEST['addEdit'];
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
$comments = $_REQUEST['comments'];

if (empty($url)) {
$url = $title;
Expand Down Expand Up @@ -971,11 +974,11 @@

if (!empty($title) && !empty($tag) && !empty($content)) {
if ($addEdit == 'add') {
$response = add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description, $media, $dateTime, $autoSave);
$response = add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description, $media, $dateTime, $autoSave, $comments);
} else {
$arr = explode('/', $oldfile);
if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
$response = edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination, $description, $dateTime, $media, $autoSave);
$response = edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination, $description, $dateTime, $media, $autoSave, $comments);
}
}
}
Expand Down Expand Up @@ -3706,6 +3709,7 @@
$description = from($_REQUEST, 'description');
$date = from($_REQUEST, 'date');
$time = from($_REQUEST, 'time');
$comments = from($_REQUEST, 'comments');
$dateTime = null;
$revertPost = from($_REQUEST, 'revertpost');
$publishDraft = from($_REQUEST, 'publishdraft');
Expand Down Expand Up @@ -3738,27 +3742,27 @@
if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $comments, $destination, $description, $dateTime, $image);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $comments, $destination, $description, $dateTime, $video);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $comments, $destination, $description, $dateTime, $link);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $comments, $destination, $description, $dateTime, $quote);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $comments, $destination, $description, $dateTime, $audio);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $comments, $destination, $description, $dateTime, null);

} else {
$message['error'] = '';
Expand Down Expand Up @@ -3816,6 +3820,7 @@
'postUrl' => $url,
'type' => $type,
'is_admin' => true,
'postComments' => $comments,
'postContent' => $content,
'bodyclass' => 'edit-post',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit_content')
Expand Down Expand Up @@ -4889,6 +4894,7 @@
$description = from($_REQUEST, 'description');
$date = from($_REQUEST, 'date');
$time = from($_REQUEST, 'time');
$comments = $_REQUEST['comments'];
$dateTime = null;
$revertPost = from($_REQUEST, 'revertpost');
$publishDraft = from($_REQUEST, 'publishdraft');
Expand Down Expand Up @@ -4922,27 +4928,27 @@

if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $comments, $destination, $description, $dateTime, $image);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $comments, $destination, $description, $dateTime, $video);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $comments, $destination, $description, $dateTime, $link);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $comments, $destination, $description, $dateTime, $quote);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $comments, $destination, $description, $dateTime, $audio);

} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {

edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null);
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $comments, $destination, $description, $dateTime, null);

} else {
$message['error'] = '';
Expand Down Expand Up @@ -5000,6 +5006,7 @@
'postUrl' => $url,
'type' => $type,
'postContent' => $content,
'postComments' => $comments,
'is_admin' => true,
'bodyclass' => 'edit-post',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $title
Expand Down
9 changes: 8 additions & 1 deletion system/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3720,10 +3720,17 @@ function get_content_tag($tag, $string, $alt = null)
return $alt;
}

// Check if comments are disabled inside the markdown files (true = disabled)
function check_comments_state($content)
{
$tag = '<!--no-comments-->';
return strpos($content, $tag) !== false ? "false" : "true";
}

// Strip html comment
function remove_html_comments($content)
{
$patterns = array('/(\s|)<!--t(.*)t-->(\s|)/', '/(\s|)<!--d(.*)d-->(\s|)/', '/(\s|)<!--tag(.*)tag-->(\s|)/', '/(\s|)<!--image(.*)image-->(\s|)/', '/(\s|)<!--video(.*)video-->(\s|)/', '/(\s|)<!--audio(.*)audio-->(\s|)/', '/(\s|)<!--link(.*)link-->(\s|)/', '/(\s|)<!--quote(.*)quote-->(\s|)/', '/(\s|)<!--post(.*)post-->(\s|)/');
$patterns = array('/(\s|)<!--t(.*)t-->(\s|)/', '/(\s|)<!--d(.*)d-->(\s|)/', '/(\s|)<!--tag(.*)tag-->(\s|)/', '/(\s|)<!--image(.*)image-->(\s|)/', '/(\s|)<!--video(.*)video-->(\s|)/', '/(\s|)<!--audio(.*)audio-->(\s|)/', '/(\s|)<!--link(.*)link-->(\s|)/', '/(\s|)<!--quote(.*)quote-->(\s|)/', '/(\s|)<!--post(.*)post-->(\s|)/', '/(\s|)<!--no-comments-->(\s|)/');
return preg_replace($patterns, '', $content);
}

Expand Down
1 change: 0 additions & 1 deletion themes/doks/post.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
</div>

</article>

<?php if (disqus()): ?>
<?php echo disqus($post->title, $post->url) ?>
<?php endif; ?>
Expand Down
3 changes: 1 addition & 2 deletions themes/twentysixteen/post.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
</footer><!-- .entry-footer -->

</article><!-- #post-## -->

<?php if (disqus()): ?>
<?php echo disqus($p->title, $p->url) ?>
<?php endif; ?>
Expand All @@ -93,7 +92,7 @@
<?php endif; ?>

</div>
<?php endif; ?>
<?php endif; ?>

<nav role="navigation" class="navigation post-navigation">
<h2 class="screen-reader-text">Post navigation</h2>
Expand Down