Skip to content

Commit

Permalink
Kommentarer
Browse files Browse the repository at this point in the history
Delningsknappar
  • Loading branch information
rickard2 committed Feb 5, 2012
1 parent 55fea6e commit 6eccd3a
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 27 deletions.
15 changes: 15 additions & 0 deletions comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<section class="comments-wrapper">

<h1>Kommentarer</h1>

<?php if ( have_comments() ) : ?>
<?php wp_list_comments(array('walker' => new Walker_Comment_HTML5())); ?>

<?php else : ?>

<p>Inga kommentarer.</p>

<?php endif ?>

<?php pp_comment_form(array('title_reply' => 'Lämna kommentar')) ?>
</section>
3 changes: 3 additions & 0 deletions entry-comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php if ( is_single() ) : ?>
<?php comments_template() ?>
<?php endif ?>
36 changes: 35 additions & 1 deletion entry-footer.php
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
<?php the_tags("", ", ", ""); ?>
<?php ob_start() ?>
<?php the_tags("", ", ", ""); ?>
<?php $tags = ob_get_contents(); ob_end_clean(); ?>

<?php if ( is_single() || is_page() ) : ?>
<div class="social">
<a class="FlattrButton"
title="<?php the_title() ?>"
data-flattr-uid="piratpartiet"
data-flattr-tags="<?php echo strip_tags($tags) ?>"
data-flattr-category="text"
href="<?php the_permalink() ?>">Flattr this</a>

<div class="fb-like" data-href="<?php the_permalink() ?>" data-send="false" data-layout="box_count" data-width="48" data-show-faces="false"></div>
<div class="g-plusone" data-size="tall"></div>
<div class="pusha-button">
<a href="http://www.pusha.se/posta?url=<?php echo urlencode(get_permalink()) ?>" target="_blank">
<img alt="Pusha" src="//static.pusha.se/176/i/push_arrow.png" title="Pusha denna nyhet" width=56 height=56 />
</a>
</div>
<div class="tweetmeme_button">
<a href="http://api.tweetmeme.com/share?url=<?php echo urlencode(get_permalink()) ?>">
<img src="http://api.tweetmeme.com/imagebutton.gif?url=<?php echo urlencode(get_permalink()) ?>" height="61" width="50" />
</a>
</div>
</div>
<?php
wp_enqueue_script('flattr');
wp_enqueue_script('facebook');
wp_enqueue_script('gplusone');
?>
<?php endif ?>

<?php echo $tags ?>
<div class="clearfix"></div>
2 changes: 1 addition & 1 deletion entry-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
</time>
</span> |
<?php comments_number( __('inga kommentarer', 'piratpartiet'), __('en kommentar', 'piratpartiet'), __('% kommentarer', 'piratpartiet') ) ?>
] </div>
] </div>
13 changes: 4 additions & 9 deletions footer.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<footer id="footer">
<div>
<?php dynamic_sidebar('footer-section-a') ?>
</div>
<div>
<?php dynamic_sidebar('footer-section-b') ?>
</div>
<div>
<?php dynamic_sidebar('footer-section-c') ?>
</div>
<?php dynamic_sidebar('footer-section-a') ?>
<?php dynamic_sidebar('footer-section-b') ?>
<?php dynamic_sidebar('footer-section-c') ?>
<div class="clearfix"></div>
</footer>
</div> <!-- #container -->
<?php wp_footer(); ?>
Expand Down
196 changes: 195 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ function init_assets() {
// Only enqueue files on the public part of the page
if ( !is_admin() ) {

$protocol = isset($_SERVER['HTTPS']) ? "https" : "http";

wp_enqueue_style($this->plugin_name . '-style', get_bloginfo( 'stylesheet_directory') . "/style.css");

wp_enqueue_script('modernizr', get_bloginfo("stylesheet_directory") . "/js/libs/modernizr-2.0.6.min.js");
wp_enqueue_script($this->plugin_name . '-plugins', get_bloginfo("stylesheet_directory") . "/js/plugins.js", array('jquery'), false, true);
wp_enqueue_script($this->plugin_name . '-script', get_bloginfo("stylesheet_directory") . "/js/script.js", array('jquery', $this->plugin_name . '-plugins'), false, true);

wp_register_script('flattr', $protocol . '://api.flattr.com/js/0.6/load.js?mode=auto&language=sv_SE&category=text', array(), false, true);
wp_register_script('facebook', $protocol . '://connect.facebook.net/sv_SE/all.js#xfbml=1', array(), false, true);
wp_register_script('gplusone', $protocol . '://apis.google.com/js/plusone.js', array(), false, true);
}
}
}
Expand All @@ -110,4 +116,192 @@ function month_sv($month) {

$m = array(null, "Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec");
return $m[ $month ];
}
}




/**
* HTML comment list class.
*
* @package WordPress
* @uses Walker
* @since 2.7.0
*/
class Walker_Comment_HTML5 extends Walker_Comment {

/**
* @see Walker::start_lvl()
* @since 2.7.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of comment.
* @param array $args Uses 'style' argument for type of HTML list.
*/
function start_lvl(&$output, $depth, $args) {
$GLOBALS['comment_depth'] = $depth + 1;
}

/**
* @see Walker::end_lvl()
* @since 2.7.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of comment.
* @param array $args Will only append content if style argument value is 'ol' or 'ul'.
*/
function end_lvl(&$output, $depth, $args) {
$GLOBALS['comment_depth'] = $depth + 1;
}


/**
* @see Walker::start_el()
* @since 2.7.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $comment Comment data object.
* @param int $depth Depth of comment in reference to parents.
* @param array $args
*/
function start_el(&$output, $comment, $depth, $args) {
$depth++;
$GLOBALS['comment_depth'] = $depth;

if ( !empty($args['callback']) ) {
call_user_func($args['callback'], $comment, $args, $depth);
return;
}

$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);

?>
<article <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">

<header>
<span class="comment-author vcard">
<?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<?php printf('<cite class="fn">%s</cite> <span class="says">skrev</span>', get_comment_author_link()) ?>
</span>

<span class="comment-meta commentmetadata">
<a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><time class="published updated" pubdate datetime="<?php echo date("c", strtotime( get_comment_date() . " " . get_comment_time() ) )?>"><?php printf('den %1$s kl. %2$s', get_comment_date("j/n Y"), get_comment_time()) ?></time></a>:
<?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','' ); ?>
</span>

<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
<br />
<?php endif; ?>


</header>

<?php comment_text() ?>

<footer>
<?php comment_reply_link(array_merge( $args, array('add_below' => 'comment', 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</footer>
<?php
}

/**
* @see Walker::end_el()
* @since 2.7.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $comment
* @param int $depth Depth of comment.
* @param array $args
*/
function end_el(&$output, $comment, $depth, $args) {
if ( !empty($args['end-callback']) ) {
call_user_func($args['end-callback'], $comment, $args, $depth);
return;
}
echo '</article>';
}
}

function pp_comment_form( $args = array(), $post_id = null ) {
global $id;

if ( null === $post_id )
$post_id = $id;
else
$id = $post_id;

$commenter = wp_get_current_commenter();
$user = wp_get_current_user();
$user_identity = ! empty( $user->ID ) ? $user->display_name : '';

$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$fields = array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ' '. ( $req ? '<span class="required">*</span>' : '' ) .'</label> ' .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ' ' . ( $req ? '<span class="required">*</span>' : '' ) . '</label> ' .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
);

$required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
$defaults = array(
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
'comment_notes_after' => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
'id_form' => 'commentform',
'id_submit' => 'submit',
'title_reply' => __( 'Leave a Reply' ),
'title_reply_to' => __( 'Leave a Reply to %s' ),
'cancel_reply_link' => __( 'Cancel reply' ),
'label_submit' => __( 'Post Comment' ),
);

$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );

?>
<?php if ( comments_open() ) : ?>
<?php do_action( 'comment_form_before' ); ?>
<div id="respond">
<h2 id="reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h2>
<?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
<?php echo $args['must_log_in']; ?>
<?php do_action( 'comment_form_must_log_in_after' ); ?>
<?php else : ?>
<form role="form" action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>">
<?php do_action( 'comment_form_top' ); ?>
<?php if ( is_user_logged_in() ) : ?>
<?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
<?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
<?php else : ?>
<?php echo $args['comment_notes_before']; ?>
<?php
do_action( 'comment_form_before_fields' );
foreach ( (array) $args['fields'] as $name => $field ) {
echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
}
do_action( 'comment_form_after_fields' );
?>
<?php endif; ?>
<?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
<?php echo $args['comment_notes_after']; ?>
<p class="form-submit">
<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
<?php comment_id_fields( $post_id ); ?>
</p>
<?php do_action( 'comment_form', $post_id ); ?>
</form>
<?php endif; ?>
</div><!-- #respond -->
<?php do_action( 'comment_form_after' ); ?>
<?php else : ?>
<?php do_action( 'comment_form_comments_closed' ); ?>
<?php endif; ?>
<?php
}
6 changes: 4 additions & 2 deletions loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
<footer>
<?php get_template_part( 'entry', 'footer' ) ?>
</footer>


<?php get_template_part( 'entry', 'comments' ) ?>

</article>

<?php endwhile; endif; ?>
Loading

0 comments on commit 6eccd3a

Please sign in to comment.