WordPress.org

Plugin Directory

Changeset 489412


Ignore:
Timestamp:
01/13/12 15:11:54 (2 years ago)
Author:
goldenapples
Message:

Version 0.3.3; bugfixes

Location:
recommended-links
Files:
4 added
2 deleted
22 edited
1 copied

Legend:

Unmodified
Added
Removed
  • recommended-links/tags/0.3.3/admin-functions.php

    r488255 r489412  
    8181            </tr> 
    8282        <tr> 
     83            <th scope="row"> 
     84                <label><?php _e( 'Comments:', 'gad_reclinks' ); ?></label> 
     85            </th> 
     86            <td> 
     87                <p> 
     88                    <input type="checkbox" name="vote-on-comments" <?php checked( $current_settings['vote-on-comments'] ); ?> /> 
     89                    <label for="vote-on-comments"><?php _e( 'Enable voting / points tally on comments?', 'gad_reclinks' ); ?></label> 
     90                </p> 
     91            </td> 
     92        </tr> 
     93        <tr> 
    8394            <th></th> 
    8495            <td> 
     
    106117            'tax' => ( isset( $_POST['tax'] ) ) ? $_POST['tax'] : array(), 
    107118            'allow-unregistered-vote' => (isset($_POST['allow-unregistered-vote']) && true == $_POST['allow-unregistered-vote']), 
    108             'allow-unregistered-post' => (isset($_POST['allow-unregistered-post']) &&true == $_POST['allow-unregistered-post']), 
     119            'allow-unregistered-post' => (isset($_POST['allow-unregistered-post']) && true == $_POST['allow-unregistered-post']), 
     120            'vote-on-comments' => (isset($_POST['vote-on-comments']) && true == $_POST['vote-on-comments']), 
    109121 
    110122            // no UI for this yet, but its gotta be in there 
  • recommended-links/tags/0.3.3/ajax-functions.php

    r486514 r489412  
    5555        'reclink_title' => sanitize_text_field( $_POST['reclink_title'] ), 
    5656        'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ), 
    57         'reclink_taxes' => $_POST['reclink_taxes'] 
     57        'reclink_taxes' => isset( $_POST['reclink_taxes'] ) ? $_POST['reclink_taxes'] : null 
    5858    ); 
    5959 
  • recommended-links/tags/0.3.3/display-filters.php

    r486514 r489412  
    138138 
    139139/** 
    140  * By default, filters comment_text to add the vote box above the comment text.  
     140 * By default, this function filters comment_text to add the vote box above the  
     141 * comment text IF the setting "Enable voting / points tally on comments" is on. 
    141142 * If you would like to add the vote box in a different location, you can remove  
    142143 * this filter and include the template tag reclinks_votebox() in your comment 
    143  * callback function 
    144  * 
     144 * callback function. 
     145 *  
    145146 */ 
    146147add_filter( 'comment_text', 'reclinks_comment_show_votelinks' ); 
    147148 
    148149function reclinks_comment_show_votelinks( $comment_text, $comment = null ) { 
     150    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     151 
     152    if ( false == $plugin_settings['vote-on-comments'] ) 
     153        return $comment_text; 
     154 
    149155    if ( is_admin() ) 
    150156        return $comment_text; 
     
    158164} 
    159165 
    160 /** 
    161  * @function    reclinks_votebox 
    162  * 
    163  * Returns or outputs the div with vote buttons and current points score. 
    164  * Called by default by the filters above on the_content and comment_text, 
    165  * but you can remove those filters and include this function in your themes. 
    166  * 
    167  * @param   bool    true: echoes votebox, false: returns it as text. 
    168  */ 
    169  
    170 function reclinks_votebox ( $echo = true ) { 
    171     global $post, $comment, $current_user, $wpdb; 
    172  
    173     if ( $post->post_type !== 'reclink' ) 
    174         return; 
    175  
    176     if ( !isset( $comment ) ) { 
    177  
    178         // votebox on recommended link itself 
    179         $current_score = get_post_meta( $post->ID, '_vote_score', true ); 
    180         $comments_number = get_comments_number(); 
    181         if ( $comments_number > 0 ) 
    182             $comments_text = _n( 'One comment', sprintf( '%s comments', get_comments_number() ) ,get_comments_number(), 'gad_reclinks' ); 
    183         else  
    184             $comments_text = __( 'No comments yet', 'gad_reclinks' ); 
    185          
    186         $comments_link_text = '- <a href="' . get_comments_link() . '" title="' . the_title_attribute( 'echo=0' ) . '">' . $comments_text . '</a>'; 
    187         $author_link = ( get_the_author() )  
    188             ?  '<a href="' . get_author_posts_url( $post->post_author ) . '">' . get_the_author() . '</a>'  
    189             : "Anonymous"; 
    190         $submit_time = '<a href="'.get_permalink( $post->ID ).'">'.human_time_diff( mysql2date( 'U', $post->post_date ) ) . ' ago</a>'; 
    191  
    192         $comment_ID = 0; 
    193  
    194     } else { 
    195  
    196         // fields relevant to comments 
    197         $current_score = $comment->comment_karma; 
    198         $comments_link_text = ''; 
    199         $author_link = get_comment_author_link(); 
    200         $submit_time = '<a href="'.get_comment_link( $comment ).'">'.human_time_diff( mysql2date( 'U', $comment->comment_date ) ) . ' ago</a>'; 
    201  
    202         $comment_ID = $comment->comment_ID; 
    203     } 
    204  
    205     $reclinks_options = get_option( 'reclinks_plugin_options' ); 
    206  
    207     get_currentuserinfo(); 
    208  
    209     if ( is_user_logged_in() ) { 
    210         $current_vote = $wpdb->get_var( " 
    211             SELECT vote FROM {$wpdb->reclinkvotes} 
    212             WHERE post_id = {$post->ID} AND comment_id = $comment_ID 
    213             AND voter_id = {$current_user->ID}" ); 
    214     } else { 
    215         $current_vote = $wpdb->get_var( " 
    216             SELECT vote FROM {$wpdb->reclinkvotes} 
    217             WHERE post_id = {$post->ID} AND comment_id = $comment_ID 
    218             AND voter_id = 0 AND voter_ip = '{$_SERVER['REMOTE_ADDR']}'" ); 
    219     } 
    220  
    221     $vote_options = "\r\n" . '<form class="reclinks_vote" method="post" action="'.add_query_arg( 'action', 'reclink-vote' ).'" style="display:inline;">'; 
    222     $vote_options .= '<input type="hidden" name="reclink" value="'.$post->ID.'" >'; 
    223  
    224     if ( isset( $comment ) ) 
    225         $vote_options .= '<input type="hidden" name="comment" value="'.$comment->comment_ID.'">'; 
    226  
    227     foreach( $reclinks_options['vote-values'] as $vote => $values ) { 
    228         $class = ( $current_vote === $values['value'] ) ? 'current_vote' : ''; 
    229         $vote_options .= '<button class="votelink '.$class.'" name="vote" value="'.$values['value'].'" data-vote="'.$values['value'].'">'; 
    230         $vote_options .= $values['text'] . '</button>'; 
    231     } 
    232  
    233  
    234     $votebox = <<<VOTEBOX 
    235 <div class="votebox">$vote_options | <span class="votescore">$current_score</span> points by $author_link $submit_time $comments_link_text</form></div> 
    236 VOTEBOX; 
    237  
    238     if ( $echo === true ) 
    239         echo $votebox; 
    240     else 
    241         return $votebox; 
    242 } 
    243166 
    244167 
     
    260183function reclink_domain( $echo = true ) { return reclinks_domain( $echo ); } // the price you pay for typos in documentation 
    261184 
    262 function reclinks_domain( $echo = true ) { 
     185function reclinks_domain( $echo = true, $before = '(', $after = ')' ) { 
    263186    global $post; 
    264187    if ( $href = get_post_meta( $post->ID, '_href', true ) ) 
    265188        $host = parse_url( $href, PHP_URL_HOST ); 
     189     
     190    if ( empty( $host ) ) return; 
     191 
    266192    if ( $echo ) 
    267         echo $host; 
     193        echo $before . $host . $after; 
    268194    else  
    269         return $host; 
     195        return $before . $host . $after; 
    270196} 
    271197 
  • recommended-links/tags/0.3.3/display-shortcodes.php

    r486518 r489412  
    3838} 
    3939 
     40 
     41/** 
     42 * @function    reclinks_votebox 
     43 * 
     44 * Returns or outputs the div with vote buttons and current points score. 
     45 * Called by default by the filters above on the_content and comment_text, 
     46 * but you can remove those filters and include this function in your themes. 
     47 * 
     48 * @param   bool    true: echoes votebox, false: returns it as text. 
     49 */ 
     50 
     51function reclinks_votebox ( $echo = true ) { 
     52    global $post, $comment, $current_user, $wpdb; 
     53 
     54    if ( $post->post_type !== 'reclink' ) 
     55        return; 
     56 
     57    if ( !isset( $comment ) ) { 
     58 
     59        // votebox on recommended link itself 
     60        $current_score = get_post_meta( $post->ID, '_vote_score', true ); 
     61        $comments_number = get_comments_number(); 
     62        if ( $comments_number > 0 ) 
     63            $comments_text = _n( 'One comment', sprintf( '%s comments', get_comments_number() ) ,get_comments_number(), 'gad_reclinks' ); 
     64        else  
     65            $comments_text = __( 'No comments yet', 'gad_reclinks' ); 
     66         
     67        $comments_link_text = '- <a href="' . get_comments_link() . '" title="' . the_title_attribute( 'echo=0' ) . '">' . $comments_text . '</a>'; 
     68        $author_link = ( get_the_author() )  
     69            ?  '<a href="' . get_author_posts_url( $post->post_author ) . '">' . get_the_author() . '</a>'  
     70            : "Anonymous"; 
     71        $submit_time = '<a href="'.get_permalink( $post->ID ).'">'.human_time_diff( mysql2date( 'U', $post->post_date ), current_time('timestamp') ) . ' ago</a>'; 
     72 
     73        $comment_ID = 0; 
     74 
     75    } else { 
     76 
     77        // fields relevant to comments 
     78        $current_score = $comment->comment_karma; 
     79        $comments_link_text = ''; 
     80        $author_link = get_comment_author_link(); 
     81        $submit_time = '<a href="'.get_comment_link( $comment ).'">'.human_time_diff( mysql2date( 'U', $comment->comment_date ) ) . ' ago</a>'; 
     82 
     83        $comment_ID = $comment->comment_ID; 
     84    } 
     85 
     86    $reclinks_options = get_option( 'reclinks_plugin_options' ); 
     87 
     88    get_currentuserinfo(); 
     89 
     90    if ( is_user_logged_in() ) { 
     91        $current_vote = $wpdb->get_var( " 
     92            SELECT vote FROM {$wpdb->reclinkvotes} 
     93            WHERE post_id = {$post->ID} AND comment_id = $comment_ID 
     94            AND voter_id = {$current_user->ID}" ); 
     95    } else { 
     96        $current_vote = $wpdb->get_var( " 
     97            SELECT vote FROM {$wpdb->reclinkvotes} 
     98            WHERE post_id = {$post->ID} AND comment_id = $comment_ID 
     99            AND voter_id = 0 AND voter_ip = '{$_SERVER['REMOTE_ADDR']}'" ); 
     100    } 
     101 
     102    $vote_options = "\r\n" . '<form class="reclinks_vote" method="post" action="'.add_query_arg( 'action', 'reclink-vote' ).'" style="display:inline;">'; 
     103    $vote_options .= '<input type="hidden" name="reclink" value="'.$post->ID.'" >'; 
     104 
     105    if ( isset( $comment ) ) 
     106        $vote_options .= '<input type="hidden" name="comment" value="'.$comment->comment_ID.'">'; 
     107 
     108    foreach( $reclinks_options['vote-values'] as $vote => $values ) { 
     109        $class = 'votelink-' . $vote; 
     110        if ( $current_vote == $values['value'] ) 
     111            $class .= ' current-vote'; 
     112        $vote_options .= '<button class="votelink '.$class.'" name="vote" value="'.$values['value'].'" data-vote="'.$values['value'].'">'; 
     113        $vote_options .= $values['text'] . '</button>'; 
     114    } 
     115 
     116 
     117    $votebox = <<<VOTEBOX 
     118<div class="votebox">$vote_options | <span class="votescore">$current_score</span> points by $author_link $submit_time $comments_link_text</form></div> 
     119VOTEBOX; 
     120 
     121    if ( $echo === true ) 
     122        echo $votebox; 
     123    else 
     124        return $votebox; 
     125} 
     126 
     127 
    40128/** 
    41129 * Display the terms (of any taxonomy) associated with a given link. 
  • recommended-links/tags/0.3.3/js/reclinks-scripts.coffee

    r486514 r489412  
    99                form.find 
    1010                form[0].reset() 
    11                 form.prepend("<div class='message'><strong>#{ reclinks.messages.linkSubmit }</strong></div>").fadeIn() 
     11                form.prepend("<div class='message'><strong>#{ reclinks.messages_linkSubmitted }</strong></div>").fadeIn() 
    1212        return false 
    1313    $('form.reclinks_vote button').bind 'click', (event) -> 
    1414        event.preventDefault 
     15        button = $(this) 
    1516        form = $(this).parent('form') 
     17        form.find('button').removeClass 'current-vote' 
    1618        vote = $(this).data('vote') 
    1719        $.ajax reclinks.ajaxUrl + '?action=vote_reclink', 
     
    2325                    window.location.href = reclinks.loginUrl + '&msg=reclinks-login' 
    2426                else 
     27                    button.addClass 'current-vote' 
    2528                    form.find('.votescore').text( response.newCount ); 
    2629        return false 
     
    3740                response = r.query.results 
    3841                unless response 
    39                     alert reclinks.messages.error404 
     42                    alert reclinks.messages_error404 
    4043                    return false 
    4144                title = response.result.match( /<\s*title\s*>([^<]*)<\/title>/ )[1] 
    4245                unless title 
    43                     alert reclinks.messages.errorNoTitle 
     46                    alert reclinks.messages_errorNoTitle 
    4447                    return false 
    4548                $('#reclink_title').val title unless $('#reclink_title').val() is not '' 
  • recommended-links/tags/0.3.3/js/reclinks-scripts.js

    r486514 r489412  
    1111          form.find; 
    1212          form[0].reset(); 
    13           return form.prepend("<div class='message'><strong>" + reclinks.messages.linkSubmit + "</strong></div>").fadeIn(); 
     13          return form.prepend("<div class='message'><strong>" + reclinks.messages_linkSubmitted + "</strong></div>").fadeIn(); 
    1414        } 
    1515      }); 
     
    1717    }); 
    1818    $('form.reclinks_vote button').bind('click', function(event) { 
    19       var form, vote; 
     19      var button, form, vote; 
    2020      event.preventDefault; 
     21      button = $(this); 
    2122      form = $(this).parent('form'); 
     23      form.find('button').removeClass('current-vote'); 
    2224      vote = $(this).data('vote'); 
    2325      $.ajax(reclinks.ajaxUrl + '?action=vote_reclink', { 
     
    3032            return window.location.href = reclinks.loginUrl + '&msg=reclinks-login'; 
    3133          } else { 
     34            button.addClass('current-vote'); 
    3235            return form.find('.votescore').text(response.newCount); 
    3336          } 
     
    5053          response = r.query.results; 
    5154          if (!response) { 
    52             alert(reclinks.messages.error404); 
     55            alert(reclinks.messages_error404); 
    5356            return false; 
    5457          } 
    5558          title = response.result.match(/<\s*title\s*>([^<]*)<\/title>/)[1]; 
    5659          if (!title) { 
    57             alert(reclinks.messages.errorNoTitle); 
     60            alert(reclinks.messages_errorNoTitle); 
    5861            return false; 
    5962          } 
  • recommended-links/tags/0.3.3/loop-reclinks.php

    r486518 r489412  
    2727            <?php reclink_terms(); ?> 
    2828            <strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong>  
    29             <small>(<?php reclink_domain(); ?>)<small> 
     29            <small><?php reclinks_domain(); ?><small> 
    3030            <br /><?php reclinks_votebox(); ?> 
    3131        </li> 
  • recommended-links/tags/0.3.3/plugin-activation.php

    r488255 r489412  
    5858function reclinks_db_option_upgrade( $from ) { 
    5959 
     60    if ( $from === 4 ) return; 
     61 
    6062    $old_settings = ( $from ) ? get_option( 'reclinks_plugin_options' ) : array(); 
    6163 
     64    /* DB version 4, reflects plugin version 0.4. Includes 'vote-on-comments' settings. */ 
    6265    /* DB version 3, reflects plugin version 0.3. Includes 'tax' string. */ 
    6366    $reclinks_plugin_defaults = array( 
     
    7073        'allow-unregistered-vote' => false, 
    7174        'allow-unregistered-post' => false, 
     75        'vote-on-comments' => true, 
    7276        'tax' => array() 
    7377    ); 
     
    7680 
    7781    update_option( 'reclinks_plugin_options', $options_to_set ); 
    78     update_option( 'reclinks_db_version', 3 ); 
     82    update_option( 'reclinks_db_version', 4 ); 
    7983 
    8084} 
  • recommended-links/tags/0.3.3/readme.txt

    r488255 r489412  
    55Requires at least: 3.2.1 
    66Tested up to: 3.3.1 
    7 Stable tag: 0.3.2 
     7Stable tag: 0.3.3 
    88 
    99A sort of "Reddit clone" that allows users to post links, up- or down-vote them, and comment on them. 
     
    6969== Changelog == 
    7070 
     71= 0.3.3 = 
     72 
     73Several bugfixes; added "vote on comments" option and styling for buttons. 
     74 
    7175= 0.3.2 = 
    7276 
     
    105109== Upgrade Notice == 
    106110 
     111= 0.3.3 =  
     112 
     113This update fixes several bugs that were pointed out (time zone setting, posts showing up as from "anonymous", update messages not defined), and adds an option to disable voting on comments. It also styles the +1/-1 buttons a bit - skins for the style will be selectable and overridable by version 0.4, but just for now I was tired of seeing the unstyled buttons. 
     114 
    107115= 0.3 = 
    108116 
  • recommended-links/tags/0.3.3/reclinks-styles.css

    r481240 r489412  
    88} 
    99 
    10 .votelink.current_vote { 
    11     background: #cff; 
     10button.votelink { 
     11    font-size: 0; 
     12    content: " "; 
     13    display: inline-block; 
     14    vertical-align: middle; 
     15    width: 14px; 
     16    height: 14px; 
     17    margin: 0 1px; 
     18    padding: 0; 
     19    cursor: pointer; 
     20    border: none; 
     21    background: url( 'images/minus-plus-small.png' ); 
    1222} 
     23 
     24.votelink.votelink-minus { background-position: 0 0; } 
     25.votelink.votelink-plus { background-position: -14px 0; } 
     26.votelink.votelink-minus.current-vote { background-position: 0 -14px; } 
     27.votelink.votelink-plus.current-vote { background-position: -14px -14px; } 
     28.votelink.votelink-minus:hover { background-position: -28px -14px; } 
     29.votelink.votelink-plus:hover { background-position: -42px -14px; } 
  • recommended-links/tags/0.3.3/recommended-links.php

    r488255 r489412  
    55Description: A "reddit clone" that runs in Wordpress. 
    66Author: Nathaniel Taintor 
    7 Version: 0.3.2 
     7Version: 0.3.3 
    88Author URI: http://goldenapplesdesign.com 
    99*/ 
     
    7878    register_post_type( 'reclink', $args ); 
    7979 
    80  
    8180} 
    8281 
     
    9190function gad_check_db_tables() { 
    9291    $v = get_option( 'reclinks_db_version' ); 
    93     if ( !$v || $v < 3 ) 
     92    if ( !$v || $v < 4 ) 
    9493        reclinks_db_option_upgrade( $v ); 
    9594} 
     
    107106            'ajaxUrl' => admin_url( 'admin-ajax.php' ),  
    108107            'loginUrl' => wp_login_url( ( !empty( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) .$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ), 
    109             'messages' => array( 
    110                 'linkSubmitted' => __( 'Link submitted successfully.', 'gad_reclinks' ), 
    111                 'error404'      => __( 'The submitted link could not be found.', 'gad_reclinks' ), 
    112                 'errorNoTitle'  => __( 'The document does not appear to have a title.', 'gad_reclinks' ) 
    113             ) 
    114         )  
    115     ); 
     108            'messages_linkSubmitted'    => __( 'Link submitted successfully.', 'gad_reclinks' ), 
     109            'messages_error404'         => __( 'The submitted link could not be found.', 'gad_reclinks' ), 
     110            'messages_errorNoTitle'     => __( 'The document does not appear to have a title.', 'gad_reclinks' ) 
     111            )  
     112        ); 
    116113    wp_enqueue_style( 'reclinks', RECLINKS_DIRECTORY . 'reclinks-styles.css' ); 
    117114} 
     
    134131function gad_add_reclink( $reclink ) { 
    135132    global $current_user; 
     133    get_current_userinfo(); 
    136134 
    137135    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     
    152150    $link_ID = wp_insert_post( array( 
    153151        'post_type'     => 'reclink', 
    154         'post_author'   => $current_user->user_id, 
     152        'post_author'   => $current_user->ID, 
    155153        'post_title'    => $reclink['reclink_title'], 
    156154        'post_content'  => $reclink['reclink_description'], 
  • recommended-links/trunk/admin-functions.php

    r488255 r489412  
    8181            </tr> 
    8282        <tr> 
     83            <th scope="row"> 
     84                <label><?php _e( 'Comments:', 'gad_reclinks' ); ?></label> 
     85            </th> 
     86            <td> 
     87                <p> 
     88                    <input type="checkbox" name="vote-on-comments" <?php checked( $current_settings['vote-on-comments'] ); ?> /> 
     89                    <label for="vote-on-comments"><?php _e( 'Enable voting / points tally on comments?', 'gad_reclinks' ); ?></label> 
     90                </p> 
     91            </td> 
     92        </tr> 
     93        <tr> 
    8394            <th></th> 
    8495            <td> 
     
    106117            'tax' => ( isset( $_POST['tax'] ) ) ? $_POST['tax'] : array(), 
    107118            'allow-unregistered-vote' => (isset($_POST['allow-unregistered-vote']) && true == $_POST['allow-unregistered-vote']), 
    108             'allow-unregistered-post' => (isset($_POST['allow-unregistered-post']) &&true == $_POST['allow-unregistered-post']), 
     119            'allow-unregistered-post' => (isset($_POST['allow-unregistered-post']) && true == $_POST['allow-unregistered-post']), 
     120            'vote-on-comments' => (isset($_POST['vote-on-comments']) && true == $_POST['vote-on-comments']), 
    109121 
    110122            // no UI for this yet, but its gotta be in there 
  • recommended-links/trunk/ajax-functions.php

    r486514 r489412  
    5555        'reclink_title' => sanitize_text_field( $_POST['reclink_title'] ), 
    5656        'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ), 
    57         'reclink_taxes' => $_POST['reclink_taxes'] 
     57        'reclink_taxes' => isset( $_POST['reclink_taxes'] ) ? $_POST['reclink_taxes'] : null 
    5858    ); 
    5959 
  • recommended-links/trunk/display-filters.php

    r486514 r489412  
    138138 
    139139/** 
    140  * By default, filters comment_text to add the vote box above the comment text.  
     140 * By default, this function filters comment_text to add the vote box above the  
     141 * comment text IF the setting "Enable voting / points tally on comments" is on. 
    141142 * If you would like to add the vote box in a different location, you can remove  
    142143 * this filter and include the template tag reclinks_votebox() in your comment 
    143  * callback function 
    144  * 
     144 * callback function. 
     145 *  
    145146 */ 
    146147add_filter( 'comment_text', 'reclinks_comment_show_votelinks' ); 
    147148 
    148149function reclinks_comment_show_votelinks( $comment_text, $comment = null ) { 
     150    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     151 
     152    if ( false == $plugin_settings['vote-on-comments'] ) 
     153        return $comment_text; 
     154 
    149155    if ( is_admin() ) 
    150156        return $comment_text; 
     
    158164} 
    159165 
    160 /** 
    161  * @function    reclinks_votebox 
    162  * 
    163  * Returns or outputs the div with vote buttons and current points score. 
    164  * Called by default by the filters above on the_content and comment_text, 
    165  * but you can remove those filters and include this function in your themes. 
    166  * 
    167  * @param   bool    true: echoes votebox, false: returns it as text. 
    168  */ 
    169  
    170 function reclinks_votebox ( $echo = true ) { 
    171     global $post, $comment, $current_user, $wpdb; 
    172  
    173     if ( $post->post_type !== 'reclink' ) 
    174         return; 
    175  
    176     if ( !isset( $comment ) ) { 
    177  
    178         // votebox on recommended link itself 
    179         $current_score = get_post_meta( $post->ID, '_vote_score', true ); 
    180         $comments_number = get_comments_number(); 
    181         if ( $comments_number > 0 ) 
    182             $comments_text = _n( 'One comment', sprintf( '%s comments', get_comments_number() ) ,get_comments_number(), 'gad_reclinks' ); 
    183         else  
    184             $comments_text = __( 'No comments yet', 'gad_reclinks' ); 
    185          
    186         $comments_link_text = '- <a href="' . get_comments_link() . '" title="' . the_title_attribute( 'echo=0' ) . '">' . $comments_text . '</a>'; 
    187         $author_link = ( get_the_author() )  
    188             ?  '<a href="' . get_author_posts_url( $post->post_author ) . '">' . get_the_author() . '</a>'  
    189             : "Anonymous"; 
    190         $submit_time = '<a href="'.get_permalink( $post->ID ).'">'.human_time_diff( mysql2date( 'U', $post->post_date ) ) . ' ago</a>'; 
    191  
    192         $comment_ID = 0; 
    193  
    194     } else { 
    195  
    196         // fields relevant to comments 
    197         $current_score = $comment->comment_karma; 
    198         $comments_link_text = ''; 
    199         $author_link = get_comment_author_link(); 
    200         $submit_time = '<a href="'.get_comment_link( $comment ).'">'.human_time_diff( mysql2date( 'U', $comment->comment_date ) ) . ' ago</a>'; 
    201  
    202         $comment_ID = $comment->comment_ID; 
    203     } 
    204  
    205     $reclinks_options = get_option( 'reclinks_plugin_options' ); 
    206  
    207     get_currentuserinfo(); 
    208  
    209     if ( is_user_logged_in() ) { 
    210         $current_vote = $wpdb->get_var( " 
    211             SELECT vote FROM {$wpdb->reclinkvotes} 
    212             WHERE post_id = {$post->ID} AND comment_id = $comment_ID 
    213             AND voter_id = {$current_user->ID}" ); 
    214     } else { 
    215         $current_vote = $wpdb->get_var( " 
    216             SELECT vote FROM {$wpdb->reclinkvotes} 
    217             WHERE post_id = {$post->ID} AND comment_id = $comment_ID 
    218             AND voter_id = 0 AND voter_ip = '{$_SERVER['REMOTE_ADDR']}'" ); 
    219     } 
    220  
    221     $vote_options = "\r\n" . '<form class="reclinks_vote" method="post" action="'.add_query_arg( 'action', 'reclink-vote' ).'" style="display:inline;">'; 
    222     $vote_options .= '<input type="hidden" name="reclink" value="'.$post->ID.'" >'; 
    223  
    224     if ( isset( $comment ) ) 
    225         $vote_options .= '<input type="hidden" name="comment" value="'.$comment->comment_ID.'">'; 
    226  
    227     foreach( $reclinks_options['vote-values'] as $vote => $values ) { 
    228         $class = ( $current_vote === $values['value'] ) ? 'current_vote' : ''; 
    229         $vote_options .= '<button class="votelink '.$class.'" name="vote" value="'.$values['value'].'" data-vote="'.$values['value'].'">'; 
    230         $vote_options .= $values['text'] . '</button>'; 
    231     } 
    232  
    233  
    234     $votebox = <<<VOTEBOX 
    235 <div class="votebox">$vote_options | <span class="votescore">$current_score</span> points by $author_link $submit_time $comments_link_text</form></div> 
    236 VOTEBOX; 
    237  
    238     if ( $echo === true ) 
    239         echo $votebox; 
    240     else 
    241         return $votebox; 
    242 } 
    243166 
    244167 
     
    260183function reclink_domain( $echo = true ) { return reclinks_domain( $echo ); } // the price you pay for typos in documentation 
    261184 
    262 function reclinks_domain( $echo = true ) { 
     185function reclinks_domain( $echo = true, $before = '(', $after = ')' ) { 
    263186    global $post; 
    264187    if ( $href = get_post_meta( $post->ID, '_href', true ) ) 
    265188        $host = parse_url( $href, PHP_URL_HOST ); 
     189     
     190    if ( empty( $host ) ) return; 
     191 
    266192    if ( $echo ) 
    267         echo $host; 
     193        echo $before . $host . $after; 
    268194    else  
    269         return $host; 
     195        return $before . $host . $after; 
    270196} 
    271197 
  • recommended-links/trunk/display-shortcodes.php

    r486518 r489412  
    3838} 
    3939 
     40 
     41/** 
     42 * @function    reclinks_votebox 
     43 * 
     44 * Returns or outputs the div with vote buttons and current points score. 
     45 * Called by default by the filters above on the_content and comment_text, 
     46 * but you can remove those filters and include this function in your themes. 
     47 * 
     48 * @param   bool    true: echoes votebox, false: returns it as text. 
     49 */ 
     50 
     51function reclinks_votebox ( $echo = true ) { 
     52    global $post, $comment, $current_user, $wpdb; 
     53 
     54    if ( $post->post_type !== 'reclink' ) 
     55        return; 
     56 
     57    if ( !isset( $comment ) ) { 
     58 
     59        // votebox on recommended link itself 
     60        $current_score = get_post_meta( $post->ID, '_vote_score', true ); 
     61        $comments_number = get_comments_number(); 
     62        if ( $comments_number > 0 ) 
     63            $comments_text = _n( 'One comment', sprintf( '%s comments', get_comments_number() ) ,get_comments_number(), 'gad_reclinks' ); 
     64        else  
     65            $comments_text = __( 'No comments yet', 'gad_reclinks' ); 
     66         
     67        $comments_link_text = '- <a href="' . get_comments_link() . '" title="' . the_title_attribute( 'echo=0' ) . '">' . $comments_text . '</a>'; 
     68        $author_link = ( get_the_author() )  
     69            ?  '<a href="' . get_author_posts_url( $post->post_author ) . '">' . get_the_author() . '</a>'  
     70            : "Anonymous"; 
     71        $submit_time = '<a href="'.get_permalink( $post->ID ).'">'.human_time_diff( mysql2date( 'U', $post->post_date ), current_time('timestamp') ) . ' ago</a>'; 
     72 
     73        $comment_ID = 0; 
     74 
     75    } else { 
     76 
     77        // fields relevant to comments 
     78        $current_score = $comment->comment_karma; 
     79        $comments_link_text = ''; 
     80        $author_link = get_comment_author_link(); 
     81        $submit_time = '<a href="'.get_comment_link( $comment ).'">'.human_time_diff( mysql2date( 'U', $comment->comment_date ) ) . ' ago</a>'; 
     82 
     83        $comment_ID = $comment->comment_ID; 
     84    } 
     85 
     86    $reclinks_options = get_option( 'reclinks_plugin_options' ); 
     87 
     88    get_currentuserinfo(); 
     89 
     90    if ( is_user_logged_in() ) { 
     91        $current_vote = $wpdb->get_var( " 
     92            SELECT vote FROM {$wpdb->reclinkvotes} 
     93            WHERE post_id = {$post->ID} AND comment_id = $comment_ID 
     94            AND voter_id = {$current_user->ID}" ); 
     95    } else { 
     96        $current_vote = $wpdb->get_var( " 
     97            SELECT vote FROM {$wpdb->reclinkvotes} 
     98            WHERE post_id = {$post->ID} AND comment_id = $comment_ID 
     99            AND voter_id = 0 AND voter_ip = '{$_SERVER['REMOTE_ADDR']}'" ); 
     100    } 
     101 
     102    $vote_options = "\r\n" . '<form class="reclinks_vote" method="post" action="'.add_query_arg( 'action', 'reclink-vote' ).'" style="display:inline;">'; 
     103    $vote_options .= '<input type="hidden" name="reclink" value="'.$post->ID.'" >'; 
     104 
     105    if ( isset( $comment ) ) 
     106        $vote_options .= '<input type="hidden" name="comment" value="'.$comment->comment_ID.'">'; 
     107 
     108    foreach( $reclinks_options['vote-values'] as $vote => $values ) { 
     109        $class = 'votelink-' . $vote; 
     110        if ( $current_vote == $values['value'] ) 
     111            $class .= ' current-vote'; 
     112        $vote_options .= '<button class="votelink '.$class.'" name="vote" value="'.$values['value'].'" data-vote="'.$values['value'].'">'; 
     113        $vote_options .= $values['text'] . '</button>'; 
     114    } 
     115 
     116 
     117    $votebox = <<<VOTEBOX 
     118<div class="votebox">$vote_options | <span class="votescore">$current_score</span> points by $author_link $submit_time $comments_link_text</form></div> 
     119VOTEBOX; 
     120 
     121    if ( $echo === true ) 
     122        echo $votebox; 
     123    else 
     124        return $votebox; 
     125} 
     126 
     127 
    40128/** 
    41129 * Display the terms (of any taxonomy) associated with a given link. 
  • recommended-links/trunk/js/reclinks-scripts.coffee

    r486514 r489412  
    99                form.find 
    1010                form[0].reset() 
    11                 form.prepend("<div class='message'><strong>#{ reclinks.messages.linkSubmit }</strong></div>").fadeIn() 
     11                form.prepend("<div class='message'><strong>#{ reclinks.messages_linkSubmitted }</strong></div>").fadeIn() 
    1212        return false 
    1313    $('form.reclinks_vote button').bind 'click', (event) -> 
    1414        event.preventDefault 
     15        button = $(this) 
    1516        form = $(this).parent('form') 
     17        form.find('button').removeClass 'current-vote' 
    1618        vote = $(this).data('vote') 
    1719        $.ajax reclinks.ajaxUrl + '?action=vote_reclink', 
     
    2325                    window.location.href = reclinks.loginUrl + '&msg=reclinks-login' 
    2426                else 
     27                    button.addClass 'current-vote' 
    2528                    form.find('.votescore').text( response.newCount ); 
    2629        return false 
     
    3740                response = r.query.results 
    3841                unless response 
    39                     alert reclinks.messages.error404 
     42                    alert reclinks.messages_error404 
    4043                    return false 
    4144                title = response.result.match( /<\s*title\s*>([^<]*)<\/title>/ )[1] 
    4245                unless title 
    43                     alert reclinks.messages.errorNoTitle 
     46                    alert reclinks.messages_errorNoTitle 
    4447                    return false 
    4548                $('#reclink_title').val title unless $('#reclink_title').val() is not '' 
  • recommended-links/trunk/js/reclinks-scripts.js

    r486514 r489412  
    1111          form.find; 
    1212          form[0].reset(); 
    13           return form.prepend("<div class='message'><strong>" + reclinks.messages.linkSubmit + "</strong></div>").fadeIn(); 
     13          return form.prepend("<div class='message'><strong>" + reclinks.messages_linkSubmitted + "</strong></div>").fadeIn(); 
    1414        } 
    1515      }); 
     
    1717    }); 
    1818    $('form.reclinks_vote button').bind('click', function(event) { 
    19       var form, vote; 
     19      var button, form, vote; 
    2020      event.preventDefault; 
     21      button = $(this); 
    2122      form = $(this).parent('form'); 
     23      form.find('button').removeClass('current-vote'); 
    2224      vote = $(this).data('vote'); 
    2325      $.ajax(reclinks.ajaxUrl + '?action=vote_reclink', { 
     
    3032            return window.location.href = reclinks.loginUrl + '&msg=reclinks-login'; 
    3133          } else { 
     34            button.addClass('current-vote'); 
    3235            return form.find('.votescore').text(response.newCount); 
    3336          } 
     
    5053          response = r.query.results; 
    5154          if (!response) { 
    52             alert(reclinks.messages.error404); 
     55            alert(reclinks.messages_error404); 
    5356            return false; 
    5457          } 
    5558          title = response.result.match(/<\s*title\s*>([^<]*)<\/title>/)[1]; 
    5659          if (!title) { 
    57             alert(reclinks.messages.errorNoTitle); 
     60            alert(reclinks.messages_errorNoTitle); 
    5861            return false; 
    5962          } 
  • recommended-links/trunk/loop-reclinks.php

    r486518 r489412  
    2727            <?php reclink_terms(); ?> 
    2828            <strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong>  
    29             <small>(<?php reclink_domain(); ?>)<small> 
     29            <small><?php reclinks_domain(); ?><small> 
    3030            <br /><?php reclinks_votebox(); ?> 
    3131        </li> 
  • recommended-links/trunk/plugin-activation.php

    r488255 r489412  
    5858function reclinks_db_option_upgrade( $from ) { 
    5959 
     60    if ( $from === 4 ) return; 
     61 
    6062    $old_settings = ( $from ) ? get_option( 'reclinks_plugin_options' ) : array(); 
    6163 
     64    /* DB version 4, reflects plugin version 0.4. Includes 'vote-on-comments' settings. */ 
    6265    /* DB version 3, reflects plugin version 0.3. Includes 'tax' string. */ 
    6366    $reclinks_plugin_defaults = array( 
     
    7073        'allow-unregistered-vote' => false, 
    7174        'allow-unregistered-post' => false, 
     75        'vote-on-comments' => true, 
    7276        'tax' => array() 
    7377    ); 
     
    7680 
    7781    update_option( 'reclinks_plugin_options', $options_to_set ); 
    78     update_option( 'reclinks_db_version', 3 ); 
     82    update_option( 'reclinks_db_version', 4 ); 
    7983 
    8084} 
  • recommended-links/trunk/readme.txt

    r488255 r489412  
    55Requires at least: 3.2.1 
    66Tested up to: 3.3.1 
    7 Stable tag: 0.3.2 
     7Stable tag: 0.3.3 
    88 
    99A sort of "Reddit clone" that allows users to post links, up- or down-vote them, and comment on them. 
     
    6969== Changelog == 
    7070 
     71= 0.3.3 = 
     72 
     73Several bugfixes; added "vote on comments" option and styling for buttons. 
     74 
    7175= 0.3.2 = 
    7276 
     
    105109== Upgrade Notice == 
    106110 
     111= 0.3.3 =  
     112 
     113This update fixes several bugs that were pointed out (time zone setting, posts showing up as from "anonymous", update messages not defined), and adds an option to disable voting on comments. It also styles the +1/-1 buttons a bit - skins for the style will be selectable and overridable by version 0.4, but just for now I was tired of seeing the unstyled buttons. 
     114 
    107115= 0.3 = 
    108116 
  • recommended-links/trunk/reclinks-styles.css

    r481240 r489412  
    88} 
    99 
    10 .votelink.current_vote { 
    11     background: #cff; 
     10button.votelink { 
     11    font-size: 0; 
     12    content: " "; 
     13    display: inline-block; 
     14    vertical-align: middle; 
     15    width: 14px; 
     16    height: 14px; 
     17    margin: 0 1px; 
     18    padding: 0; 
     19    cursor: pointer; 
     20    border: none; 
     21    background: url( 'images/minus-plus-small.png' ); 
    1222} 
     23 
     24.votelink.votelink-minus { background-position: 0 0; } 
     25.votelink.votelink-plus { background-position: -14px 0; } 
     26.votelink.votelink-minus.current-vote { background-position: 0 -14px; } 
     27.votelink.votelink-plus.current-vote { background-position: -14px -14px; } 
     28.votelink.votelink-minus:hover { background-position: -28px -14px; } 
     29.votelink.votelink-plus:hover { background-position: -42px -14px; } 
  • recommended-links/trunk/recommended-links.php

    r488255 r489412  
    55Description: A "reddit clone" that runs in Wordpress. 
    66Author: Nathaniel Taintor 
    7 Version: 0.3.2 
     7Version: 0.3.3 
    88Author URI: http://goldenapplesdesign.com 
    99*/ 
     
    7878    register_post_type( 'reclink', $args ); 
    7979 
    80  
    8180} 
    8281 
     
    9190function gad_check_db_tables() { 
    9291    $v = get_option( 'reclinks_db_version' ); 
    93     if ( !$v || $v < 3 ) 
     92    if ( !$v || $v < 4 ) 
    9493        reclinks_db_option_upgrade( $v ); 
    9594} 
     
    107106            'ajaxUrl' => admin_url( 'admin-ajax.php' ),  
    108107            'loginUrl' => wp_login_url( ( !empty( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) .$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ), 
    109             'messages' => array( 
    110                 'linkSubmitted' => __( 'Link submitted successfully.', 'gad_reclinks' ), 
    111                 'error404'      => __( 'The submitted link could not be found.', 'gad_reclinks' ), 
    112                 'errorNoTitle'  => __( 'The document does not appear to have a title.', 'gad_reclinks' ) 
    113             ) 
    114         )  
    115     ); 
     108            'messages_linkSubmitted'    => __( 'Link submitted successfully.', 'gad_reclinks' ), 
     109            'messages_error404'         => __( 'The submitted link could not be found.', 'gad_reclinks' ), 
     110            'messages_errorNoTitle'     => __( 'The document does not appear to have a title.', 'gad_reclinks' ) 
     111            )  
     112        ); 
    116113    wp_enqueue_style( 'reclinks', RECLINKS_DIRECTORY . 'reclinks-styles.css' ); 
    117114} 
     
    134131function gad_add_reclink( $reclink ) { 
    135132    global $current_user; 
     133    get_current_userinfo(); 
    136134 
    137135    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     
    152150    $link_ID = wp_insert_post( array( 
    153151        'post_type'     => 'reclink', 
    154         'post_author'   => $current_user->user_id, 
     152        'post_author'   => $current_user->ID, 
    155153        'post_title'    => $reclink['reclink_title'], 
    156154        'post_content'  => $reclink['reclink_description'], 
Note: See TracChangeset for help on using the changeset viewer.