~canonical-website-editors/insights/plus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php // Do not delete these lines
	if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
		die ('Please do not load this page directly. Thanks!');

	if (!empty($post->post_password)) { // if there's a password
		if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie
			?>

			<p class="nocomments">This post is password protected. Enter the password to view comments.</p>

			<?php
			return;
		}
	}
	/* This variable is for alternating comment background */
	$oddcomment = ' comment-alt';
?>

<?php // start editing here. ?>
<div id="comments" class="">
<?php if ($comments) : ?>
	<h3 id="comment-count"><?php comments_number('No comments', 'One comment', '% comments' );?> </h3>

	<ul class="comment-list no-bullets">
	<?php foreach ($comments as $comment) : ?>
	<?php $comment_type = get_comment_type(); ?>
	<?php if($comment_type == 'comment') { ?>
    	<li class="clearfix twelve-col <?php echo $oddcomment; ?><?php if ($comment->comment_author_email == get_the_author_email()) { echo ' author-comment'; } ?>" id="comment-<?php comment_ID() ?>">
			<?php if ($comment->comment_approved == '0') : ?>
			<div class="alert">Thank you. Your comment is awaiting moderation.</div>
			<?php endif; ?>
			<div class="comment-meta three-col">
				<div>
					<?php echo get_avatar( $comment, 32 ); ?>
					<cite><?php comment_author_link() ?></cite>
					<time datetime="<?php the_time('Y-m-d') ?>"><a href="#comment-<?php comment_ID() ?>" title=""><?php the_time('j') ?><sup><?php the_time('S') ?></sup><?php the_time(' F Y') ?></a></time>
				</div>
			</div><!-- /.comment-meta -->
			<div class="comment-content five-col last-col">
				<div>
					<?php comment_text() ?>
				</div>
			</div><!-- /.comment-content -->
		</li>
	<?php
		/* Changes every other comment to a different class */
		$oddcomment = ( empty( $oddcomment ) ) ? ' comment-alt' : '';
	?>
	<?php } else { $trackback = true; } /* End of is_comment statement */ ?>
	<?php endforeach; /* end for each comment */ ?>
	</ul>
<?php if ($trackback == true) { ?>
	<div id="post-trackbacks" class="container<?php if (get_comments_number()==0) { echo ' no-comments'; } ?>">
		<h3>Trackbacks</h3>
			<ul class="no-bullets">
			<?php foreach ($comments as $comment) : ?>
				<?php $comment_type = get_comment_type(); ?>
				<?php if($comment_type != 'comment') { ?>
				<li><?php comment_author_link() ?></li>
				<?php } ?>
			<?php endforeach; ?>
			</ul>
	</div>
<?php } ?>
<?php endif; ?>

<?php

  $custom = get_post_custom();
  $options = get_option('discourse');
  $permalink = (string)$custom['discourse_permalink'][0];
  $discourse_url_name = preg_replace("(https?://)", "", $options['url'] );
  $discourse_info = json_decode($custom['discourse_comments_raw'][0]);
  $more_replies = $discourse_info->posts_count - count($discourse_info->posts) - 1;
  $show_fullname = $options['use-fullname-in-comments'] == 1;
  $comments_title = $options['custom-comments-title'];
  if(!$comments_title || strlen(trim($comments_title)) == 0) {
    $comments_title = 'Notable Replies';
  }
  $more = count($discourse_info->posts) == 0 ? "" : "more ";

  if($more_replies == 0) {
    $more_replies = "";
  } elseif($more_replies == 1) {
    $more_replies = "1 " . $more . "reply";
  } else {
    $more_replies = $more_replies . " " . $more . "replies";
  }

  $link_text = count($discourse_info->posts_count - 1) == 0 ? "Start the discussion" : "Continue the discussion";

  if($permalink != '') {

?>
<?php if(count($discourse_info->posts) > 0) { ?>
    <h2 id="comments-title"><?php echo $comments_title ?></h2>

		<ul class="commentlist no-bullet">

      <?php foreach($discourse_info->posts as &$post) { ?>
      <li class="comment">
				<div class="comment-author vcard">
          <img alt="" src="<?php Discourse::avatar($post->avatar_template,64) ?>" class="avatar avatar-64 photo avatar-default" height="64" width="64">
            <a href="<?php Discourse::homepage($options['url'],$post) ?>" rel="external" class="url"><?php echo ($show_fullname ? $post->name : $post->username) ?></a>
            <br/>
            <time pubdate="" datetime="<?php echo $post->created_at ?>"><?php echo mysql2date(get_option('date_format'), $post->created_at)?></time>
        </div>
        <div class="comment-content"><?php echo $post->cooked ?></div>
      </li>
      <?php } ?>

		</ul>

<?php } ?>

    <div class="respond">
        <h3 class="reply-title"><a href="<?php echo $permalink ?>"><?php echo $link_text ?></a> at <?php echo $discourse_url_name ?></h3>
        <?php if(count($discourse_info->posts) > 0 || $more_replies > 0) { ?>
        <p class='more-replies'><?php echo $more_replies ?></p>
        <p>
          <?php foreach($discourse_info->participants as &$participant) { ?>
            <img alt="" src="<?php Discourse::avatar($participant->avatar_template,25) ?>" class="avatar avatar-25 photo avatar-default" height="25" width="25">
          <?php } ?>
        </p>
        <?php } ?>
    </div><!-- #respond -->

    <?php
     }
    ?>

</div>