<?php
	if('comments.php' == basename( $_SERVER[ 'SCRIPT_FILENAME' ] ) )
		die( 'Please do not load this page directly. Thanks!' );

	if( !empty( $post->post_password ) ) {
		if( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] != $post->post_password ) {
?>
			<h2>Ups...</h2>
			<p>This post has been password protected. Enter the password in order to view comments.</p>
<?php
		return;
		}
	}
	$oddcomment = '';
?>
<?php
	$aOptions = SofaiBloggr::initOptions( false );
	$plur_comments = ( strlen( $aOptions[ 'plur_comments' ] ) > 0 ) ? stripslashes( $aOptions[ 'plur_comments' ] ) : 'Comments';
	$leavecomment = ( strlen( $aOptions[ 'leavecomment' ] ) > 0 ) ? stripslashes( $aOptions[ 'leavecomment' ] ) : 'Leave a Comment';
	$commenttag = ( strlen( $aOptions[ 'commenttag' ] ) > 0 ) ? stripslashes( $aOptions[ 'commenttag' ] ) : 'Comment';
	$nametag = ( strlen( $aOptions[ 'nametag' ] ) > 0 ) ? stripslashes( $aOptions[ 'nametag' ] ) : 'Name';
	$emailtag = ( strlen( $aOptions[ 'emailtag' ] ) > 0 ) ? stripslashes( $aOptions[ 'emailtag' ] ) : 'E-mail';
	$webtag = ( strlen( $aOptions[ 'webtag' ] ) > 0 ) ? stripslashes( $aOptions[ 'webtag' ] ) : 'WEB site';
	$submittag = ( strlen( $aOptions[ 'submittag' ] ) > 0 ) ? stripslashes( $aOptions[ 'submittag' ] ) : 'Submit';
?>
            
			<!-- comments -->
            <div id="comments" class="section">
                <h2 class="sectionheader"><?php echo $plur_comments; ?> (<?php comments_number('0', '1', '%' );?>)</h2>
                
                <?php if( ( 'open' == $post->comment_status ) && ( 'open' == $post->ping_status ) ) { ?>
                            <p class="cinfo">
                            Track comments via <?php comments_rss_link('RSS 2.0'); ?> feed. 
                            Feel free to post the <a href="#respond" title="respond">comment</a>, 
                            or <a href="<?php trackback_url(); ?>" rel="trackback">trackback</a> 
                            from your web site.
                            </p>
                            <?php } else if( !( 'open' == $post->comment_status ) && ( 'open' == $post->ping_status ) ) { ?>
                            <p class="cinfo">
                            Comments are closed but you can 
                            <a href="<?php trackback_url(); ?>" rel="trackback">trackback</a> 
                            from your web site.
                            </p>
                            <?php } else if( ( 'open' == $post->comment_status ) && !( 'open' == $post->ping_status ) ) { ?>
                            <p class="cinfo">
                            Scroll to the <a href="#respond" title="respond">Post Form</a> 
                            and leave a comment. Pinging is disabled.
                            </p>
                            <?php } else if( !( 'open' == $post->comment_status ) && !( 'open' == $post->ping_status ) ) { ?>
                            <p class="cinfo">
                            Comments and pings are not allowed!
                            </p>
                            <?php 
							} 
							if( !$comments ) echo '<p class="cinfo">Currently there are no comments related to article "' . get_the_title() . '". You have a special honor to be the first commenter. Thanks!</p>';
							?>
               
            
               <?php
			   // start comments list 
			   if( $comments ) : 
			   ?>
               
               <ol class="comment-list">
               <?php foreach( $comments as $comment ) : ?>
	               <li id="comment-<?php comment_ID(); ?>">
                   
                   	<div class="comment-info">
                    	<span class="date"><?php comment_date('M j, Y'); ?></span> 
                        | 
                    	<span class="user"><?php comment_author_link(); ?><?php edit_comment_link( 'EDIT', ' | ', '' ); ?></span>
                   		<?php
						$author_email = $comment->comment_author_email;
						echo '<span class="gravatar">';
						echo get_avatar( $author_email, '45' );
						echo '</span>';
				   		?>
                    </div>
                    <div class="comment">
                        <?php comment_text(); ?>
                        <?php if( $comment->comment_approved == '0' ) : ?>
                        <p class="approval">This comment has not been approved yet. Pending an Admin approval...</p>
                        <?php endif; ?>
                    </div>
                    
	               </li>
               <?php endforeach; ?>
	           </ol>
               
			   <?php endif; ?>
           
           <!-- comment form -->
           <div id="feedback">
           		<h3><?php echo $leavecomment; ?></h3>
 
<?php if( 'open' == $post->comment_status ) : ?>
                
<?php if( get_option( 'comment_registration' ) && !$user_ID ) : ?>

                <p>You must be <a href="<?php echo get_option( 'siteurl' ); ?>/wp-login.php?redirect_to=<?php echo urlencode( get_permalink() ); ?>">logged in</a> to post the comment!</p>
				
<?php else : ?>
                
                <form id="commentform" method="post" action="<?php echo get_option( 'siteurl' ); ?>/wp-comments-post.php">
                 
<?php if( $user_ID ) : ?>
                
				<p>Logged in as <a href="<?php echo get_option( 'siteurl' ); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. Would you like to <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Log out of this account">logout</a>?</p>
				
<?php else : ?>
                 <div>
                 	<label for="author"><?php if( $req ) echo "* "; ?><?php echo $nametag; ?></label>
                 	<input class="input" type="text" tabindex="1" size="22" value="<?php echo $comment_author; ?>" id="author" name="author" />
                 </div>
                 <div>
                 	<label for="email"><?php if( $req ) echo "* "; ?><?php echo $emailtag; ?></label>
                 	<input class="input" type="text" tabindex="2" size="22" value="<?php echo $comment_author_email; ?>" id="email" name="email" />
                 </div>
                 <div>
                 	<label for="url"><?php echo $webtag; ?></label>
                 	<input class="input" type="text" tabindex="3" size="22" value="<?php echo $comment_author_url; ?>" id="url" name="url" />
                 </div>
                 <!--<p><span><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></span></p>-->
<?php endif; ?>

                <div>
                 	<label for="comment"><?php echo $commenttag; ?></label>
                 	<textarea tabindex="4" rows="8" cols="25" id="comment" name="comment" class="textarea"></textarea>
                 </div>
                 <div class="submitMe">
                 
                    <input type="hidden" value="<?php echo $id; ?>" name="comment_post_ID" />
                    <button type="submit"><?php echo $submittag; ?></button>
                 	<!-- <input type="hidden" value="0" id="comment_parent" name="comment_parent" /> -->
                    
                 </div>
                 
                <?php do_action( 'comment_form', $post->ID ); ?>
                </form>
                
<?php endif; ?>
          <?php else : ?>
           <p>Oooh sorry, no comments allowed!</p>
<?php endif; ?>

	</div>

</div>
<!-- comment form -->