WordPress.org

Plugin Directory

Changeset 486514


Ignore:
Timestamp:
01/08/12 13:59:20 (2 years ago)
Author:
goldenapples
Message:

Version 0.3

Location:
recommended-links
Files:
8 edited
13 copied

Legend:

Unmodified
Added
Removed
  • recommended-links/tags/0.3/ajax-functions.php

    r481651 r486514  
    2020        return; 
    2121 
    22     if ( 'reclink-add' === $_GET['action'] ) { 
     22    if ( 'reclink-add' === $_GET['action'] && !empty( $_POST['reclink_URL'] ) ) { 
    2323        $reclink = array( 
    2424            'reclink_url' => esc_url( $_POST['reclink_URL'] ), 
    2525            'reclink_title' => sanitize_text_field( $_POST['reclink_title'] ), 
    26             'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ) 
     26            'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ), 
     27            'reclink_taxes' => ( isset( $_POST['reclink_taxes'] ) ) ? $_POST['reclink_taxes'] : null 
    2728        ); 
    2829        gad_add_reclink( $reclink ); 
    2930    }  
    3031 
    31     if ( 'reclink-vote' === $_GET['action'] ) {      
     32    if ( 'reclink-vote' === $_GET['action'] && !empty( $_POST['reclink'] ) ) {       
    3233        global $current_user; 
    3334        get_currentuserinfo(); 
     
    4546 
    4647function gad_reclinks_ajax_add() { 
    47     if ( !current_user_can( 'add_reclink' ) ) 
     48    $plugin_settings = get_option( 'reclinks_plugin_settings' ); 
     49 
     50    if ( !$plugin_settings['allow-unregistered-post'] && !current_user_can( 'add_reclink' ) ) 
    4851        die( json_encode( array( 'exception' => 'Current user is not authorized to add links' ) ) ); 
     52 
    4953    $reclink = array( 
    5054        'reclink_url' => esc_url( $_POST['reclink_URL'] ), 
    5155        'reclink_title' => sanitize_text_field( $_POST['reclink_title'] ), 
    52         'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ) 
     56        'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ), 
     57        'reclink_taxes' => $_POST['reclink_taxes'] 
    5358    ); 
     59 
    5460    $link = gad_add_reclink( $reclink ); 
    5561    echo json_encode( get_post( $link ) ); 
     
    6268 
    6369function gad_reclinks_ajax_vote() { 
     70    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     71 
    6472    global $current_user; 
    6573    get_currentuserinfo(); 
    6674 
    67     if ( !current_user_can( 'vote_reclink' ) ) 
     75    if ( !$plugin_settings['allow-unregistered-vote'] && !current_user_can( 'vote_reclink' ) ) 
    6876        die( json_encode( array( 'exception' => 'Current user is not authorized to add links' ) ) ); 
    6977 
     
    7785} 
    7886 
     87add_action( 'wp_ajax_check_reclink_title', 'gad_reclinks_check_link_title' ); 
     88add_action( 'wp_ajax_nopriv_check_reclink_title', 'gad_reclinks_check_link_title' ); 
     89 
     90function gad_reclinks_check_link_title() { 
     91    $link = esc_url( $_POST['url'] ); 
     92    if ( !$link ) { 
     93        $return['exception'] = 'Invalid URL'; 
     94    } 
     95    $response = wp_remote_get( $link ); 
     96    if ( $response ) { 
     97        $doc = new DOMDocument(); 
     98        $doc->strictErrorChecking = FALSE; 
     99        $doc->loadHTML( $response['body'] ); 
     100        $xml = simplexml_import_dom($doc); 
     101        $title = $xml->head->title; 
     102        $return['title'] = (string)$title; 
     103    } 
     104    die( json_encode( $return ) ); 
     105 
     106 
     107} 
  • recommended-links/tags/0.3/display-filters.php

    r481905 r486514  
    11<?php 
    22 
    3 // Query filters for reclinks 
     3/** 
     4 * Query filters for reclinks 
     5 *  
     6 * 
     7 */ 
     8 
     9 
     10add_filter('query_vars', 'gad_reclinks_add_query_vars'); 
     11 
     12function gad_reclinks_add_query_vars( $query_vars ) { 
     13    $query_vars[] = "reclinks_sort"; 
     14    return $query_vars; 
     15} 
     16 
    417 
    518add_filter( 'pre_get_posts', 'gad_reclinks_sortby' ); 
    619 
    720function gad_reclinks_sortby( $query ) { 
     21    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
    822 
    923    global $wp_the_query; 
    1024 
    11     if ( !is_post_type_archive('reclink') || ( $query !== $wp_the_query ) ) 
     25    if ( !isset( $query->query_vars['post_type'] ) || $query->query_vars['post_type'] !== 'reclink') 
    1226        return $query; 
    13  
    14     $query->set( 'posts_per_page', 25 ); 
    15  
    16     $sortby = 'current'; // default sort 
     27     
     28    if ( $query === $wp_the_query ) { 
     29        $posts_per_page = ( isset( $plugin_settings['posts_per_page'] ) ) ? $plugin_settings['posts_per_page'] : 25; 
     30        $query->set( 'posts_per_page', $posts_per_page ); 
     31    } 
     32 
     33    $sort_order = ( isset( $plugin_settings['sort_order'] ) ) ? $plugin_settings['sort_order'] : 'current'; 
    1734 
    1835    if ( isset( $_GET['sort'] ) && in_array( 
    1936            $_GET['sort'],  
    2037            array( 'newest', 'hot', 'current', 'score' ) ) ) 
    21         $sortby = $_GET['sort']; 
    22  
    23     switch ( $sortby ) : 
     38        $sort_order = $_GET['sort']; 
     39 
     40    if ( isset( $query->query_vars['reclinks_sort'] ) && in_array( 
     41            $query->query_vars['reclinks_sort'],  
     42            array( 'newest', 'hot', 'current', 'score' ) ) ) 
     43        $sort_order = $query->query_vars['reclinks_sort']; 
     44 
     45    switch ( $sort_order ) : 
    2446        case 'score': 
    2547            // default: order by vote total 
     
    92114} 
    93115 
     116 
     117/** 
     118 * By default, filters the_content to add the vote box above the content  
     119 * (the link description). If you would like to add the vote box in a different  
     120 * location, you can remove this filter and include the template tag 
     121 * reclinks_votebox() in your theme files. 
     122 * 
     123 */ 
    94124add_filter( 'the_content', 'gad_reclinks_show_votelinks' ); 
    95125 
    96126function gad_reclinks_show_votelinks( $content ) { 
     127    if ( is_admin() ) 
     128        return $content; 
     129 
    97130    global $post; 
    98131    if ( $post->post_type !== 'reclink' ) 
     
    103136} 
    104137 
     138 
     139/** 
     140 * By default, filters comment_text to add the vote box above the comment text.  
     141 * If you would like to add the vote box in a different location, you can remove  
     142 * this filter and include the template tag reclinks_votebox() in your comment 
     143 * callback function 
     144 * 
     145 */ 
    105146add_filter( 'comment_text', 'reclinks_comment_show_votelinks' ); 
    106147 
    107148function reclinks_comment_show_votelinks( $comment_text, $comment = null ) { 
     149    if ( is_admin() ) 
     150        return $comment_text; 
     151     
    108152    global $post; 
    109153    if ( $post->post_type !== 'reclink' ) 
     
    131175 
    132176    if ( !isset( $comment ) ) { 
     177 
    133178        // votebox on recommended link itself 
    134179        $current_score = get_post_meta( $post->ID, '_vote_score', true ); 
     
    148193 
    149194    } else { 
     195 
    150196        // fields relevant to comments 
    151197        $current_score = $comment->comment_karma; 
     
    196242} 
    197243 
     244 
     245/** 
     246 * For recommended links, the_permalink is filtered to echo the link submitted, 
     247 * not the permalink of the comments page on your site. To get the discussion page 
     248 * permalink instead, use get_permalink() or another similar function. 
     249 * 
     250 */ 
    198251add_filter( 'the_permalink', 'gad_reclinks_permalink' ); 
    199252 
     
    205258} 
    206259 
    207 // the price you pay for typos in documentation 
    208 function reclink_domain( $echo = true ) { return reclinks_domain( $echo ); } 
     260function reclink_domain( $echo = true ) { return reclinks_domain( $echo ); } // the price you pay for typos in documentation 
    209261 
    210262function reclinks_domain( $echo = true ) { 
     
    218270} 
    219271 
     272 
     273/** 
     274 * A "pseudo-loop" for the page designated as "Page for Recommended Links Archive" 
     275 * 
     276 * Uses the WP_Query object to retrieve posts, the loop-reclinks.php template to display 
     277 * them, and the WordPress functions get_previous_posts_page and get_next_posts_page. 
     278 * In short, it basically functions just like a regular archive page, except for the  
     279 * template and the WordPress conditional tags, (ie. `is_archive()` will return false). 
     280 */ 
     281add_filter( 'the_content', 'gad_reclinks_page' ); 
     282 
     283function gad_reclinks_page( $content ) { 
     284    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     285 
     286    if ( !$plugin_settings['page_for_reclinks'] || !is_page( $plugin_settings['page_for_reclinks'] ) ) 
     287        return $content;     
     288 
     289    global $wp_query; 
     290 
     291    $links_paged = ( isset( $wp_query->query_vars['paged'] ) ) ? $wp_query->query_vars['paged'] : 1; 
     292    $posts_per_page = ( isset( $plugin_settings['posts_per_page'] ) ) ? $plugin_settings['posts_per_page'] : 25; 
     293 
     294    $old_query = $wp_query; 
     295    $wp_query = new WP_Query( array( 
     296        'post_type' => 'reclink', 
     297        'reclinks_sort' => $plugin_settings['sort_order'], 
     298        'posts_per_page' => $posts_per_page, 
     299        'paged' => $links_paged 
     300    ) ); 
     301 
     302 
     303    /* 
     304     * Basic structure for prev/next links, 
     305     * should be built out a little more in future releases. 
     306     */ 
     307    $found_posts = $wp_query->found_posts; 
     308 
     309    $links_navigation = '<div class="links-navigation">' ; 
     310 
     311    if ( $links_paged > 1 )  
     312        $links_navigation .= '<div class="nav-previous">' . get_previous_posts_link() . '</div>'; 
     313     
     314    if ( $found_posts > $posts_per_page * $links_paged ) 
     315        $links_navigation .= '<div class="nav-next">' . get_next_posts_link() . '</div>'; 
     316 
     317    $links_navigation .= '</div>'; 
     318 
     319    ob_start(); 
     320    if ( '' === locate_template( 'loop-reclinks.php', true, false ) ) 
     321        include( 'loop-reclinks.php' ); 
     322    $links_archive = ob_get_clean(); 
     323 
     324    $wp_query = $old_query; 
     325    return $content . $links_archive . $links_navigation; 
     326 
     327} 
  • recommended-links/tags/0.3/js/reclinks-scripts.coffee

    r481764 r486514  
    22    $('form.reclinks_addlink').bind 'submit', (event) -> 
    33        event.preventDefault 
    4         alert 'submitting' 
    5         $.ajax 
     4        form = $(this).fadeOut() 
     5        $.ajax reclinks.ajaxUrl + '?action=add_reclink', 
    66            type: 'post' 
    7             url: reclinks.ajaxUrl + '?action=add_reclink' 
    8             data: $(this).serialize() 
     7            data: form.serialize() 
    98            complete: () -> 
    10                 alert 'Link Submitted!' 
     9                form.find 
     10                form[0].reset() 
     11                form.prepend("<div class='message'><strong>#{ reclinks.messages.linkSubmit }</strong></div>").fadeIn() 
    1112        return false 
    1213    $('form.reclinks_vote button').bind 'click', (event) -> 
     
    1415        form = $(this).parent('form') 
    1516        vote = $(this).data('vote') 
    16         $.ajax 
     17        $.ajax reclinks.ajaxUrl + '?action=vote_reclink', 
    1718            type: 'post' 
    18             url: reclinks.ajaxUrl + '?action=vote_reclink' 
    1919            data: form.serialize() + '&vote=' + vote 
    2020            complete: (r) -> 
     
    2525                    form.find('.votescore').text( response.newCount ); 
    2626        return false 
     27    $('#reclink_URL').bind 'change', (event) -> 
     28        linkUrl = $(this).val() 
     29        $.ajax 'http://query.yahooapis.com/v1/public/yql', 
     30            type: 'get', 
     31            data: { 
     32                q: "use 'http://www.datatables.org/data/htmlstring.xml' as htmlstring; select * from htmlstring where url='#{ linkUrl }'", 
     33                format: 'json' 
     34                }, 
     35            dataType: 'json', 
     36            success: (r) -> 
     37                response = r.query.results 
     38                unless response 
     39                    alert reclinks.messages.error404 
     40                    return false 
     41                title = response.result.match( /<\s*title\s*>([^<]*)<\/title>/ )[1] 
     42                unless title 
     43                    alert reclinks.messages.errorNoTitle 
     44                    return false 
     45                $('#reclink_title').val title unless $('#reclink_title').val() is not '' 
     46        null 
    2747    null 
  • recommended-links/tags/0.3/js/reclinks-scripts.js

    r481764 r486514  
    22  jQuery(function($) { 
    33    $('form.reclinks_addlink').bind('submit', function(event) { 
     4      var form; 
    45      event.preventDefault; 
    5       alert('submitting'); 
    6       $.ajax({ 
     6      form = $(this).fadeOut(); 
     7      $.ajax(reclinks.ajaxUrl + '?action=add_reclink', { 
    78        type: 'post', 
    8         url: reclinks.ajaxUrl + '?action=add_reclink', 
    9         data: $(this).serialize(), 
     9        data: form.serialize(), 
    1010        complete: function() { 
    11           return alert('Link Submitted!'); 
     11          form.find; 
     12          form[0].reset(); 
     13          return form.prepend("<div class='message'><strong>" + reclinks.messages.linkSubmit + "</strong></div>").fadeIn(); 
    1214        } 
    1315      }); 
     
    1921      form = $(this).parent('form'); 
    2022      vote = $(this).data('vote'); 
    21       $.ajax({ 
     23      $.ajax(reclinks.ajaxUrl + '?action=vote_reclink', { 
    2224        type: 'post', 
    23         url: reclinks.ajaxUrl + '?action=vote_reclink', 
    2425        data: form.serialize() + '&vote=' + vote, 
    2526        complete: function(r) { 
     
    3536      return false; 
    3637    }); 
     38    $('#reclink_URL').bind('change', function(event) { 
     39      var linkUrl; 
     40      linkUrl = $(this).val(); 
     41      $.ajax('http://query.yahooapis.com/v1/public/yql', { 
     42        type: 'get', 
     43        data: { 
     44          q: "use 'http://www.datatables.org/data/htmlstring.xml' as htmlstring; select * from htmlstring where url='" + linkUrl + "'", 
     45          format: 'json' 
     46        }, 
     47        dataType: 'json', 
     48        success: function(r) { 
     49          var response, title; 
     50          response = r.query.results; 
     51          if (!response) { 
     52            alert(reclinks.messages.error404); 
     53            return false; 
     54          } 
     55          title = response.result.match(/<\s*title\s*>([^<]*)<\/title>/)[1]; 
     56          if (!title) { 
     57            alert(reclinks.messages.errorNoTitle); 
     58            return false; 
     59          } 
     60          if ($('#reclink_title').val() !== !'') { 
     61            return $('#reclink_title').val(title); 
     62          } 
     63        } 
     64      }); 
     65      return null; 
     66    }); 
    3767    return null; 
    3868  }); 
  • recommended-links/tags/0.3/plugin-activation.php

    r481651 r486514  
    4040    } 
    4141 
    42     if (!get_option('reclinks_plugin_options')) { 
    43     // Mockups of options. TODO: make these actual user-editable settings. 
     42    // Create default options in database settings 
     43    $v = get_option( 'reclinks_db_version' ); 
     44    reclinks_db_option_upgrade( $v ); 
     45 
     46} 
     47 
     48 
     49/** 
     50 * Create default options settings. 
     51 * 
     52 * Handles creating new options when upgrading from one version of the plugin to the next. 
     53 * 
     54 * @param   int     the db version being upgraded from 
     55 *                  // ie get_option( 'reclinks_db_version' ) 
     56 * 
     57 **/ 
     58function reclinks_db_option_upgrade( $from ) { 
     59 
     60    /* DB version 2, reflects plugin version 0.4. First user-editable settings. */ 
     61    if ( !$from || $from < 2 ) { 
    4462        $reclinks_plugin_defaults = array( 
    4563            'vote-values' => array( 
    4664                'minus' => array( 'value' => -1, 'text' => '-' ), 
    4765                'plus' => array( 'value' => 1, 'text' => '+' ) 
    48             ) 
     66            ), 
     67            'page-for-reclinks' => false, 
     68            'sort-order' => 'current', 
     69            'allow-unregistered-vote' => false, 
     70            'allow-unregistered-post' => false 
    4971        ); 
    50         update_option('reclinks_plugin_options',$reclinks_plugin_defaults); 
    5172    } 
     73 
     74    update_option( 'reclinks_plugin_options', $reclinks_plugin_defaults ); 
     75    update_option( 'reclinks_db_version', 2 ); 
     76 
    5277} 
     78 
    5379 
    5480/** 
  • recommended-links/tags/0.3/readme.txt

    r482847 r486514  
    44Tags: social bookmarking, sharing, voting, reddit, digg 
    55Requires at least: 3.2.1 
    6 Tested up to: 3.3 
    7 Stable tag: 0.2.3 
     6Tested up to: 3.3.1 
     7Stable tag: 0.3 
    88 
    99A sort of "Reddit clone" that allows users to post links, up- or down-vote them, and comment on them. 
     
    1111== Description == 
    1212 
    13 This is the beginnings of a much more ambitious project. At the moment, there is no admin options screen and functionality is a bit limited. However, if you want to try this out, please give me feedback. 
     13This is the beginning of what I hope will be a much more ambitious project. If you want to try this out, please give me feedback. 
    1414 
    1515I will guarantee backwards compatibility with all data saved by the plugin, so it should be safe to install and activate, and as I add features, your existing posts and links will work with them just fine. 
     
    1717== Installation == 
    1818 
    19 1. Upload the entire `recommended-links/` folder to the `/wp-content/plugins/` directory 
    20 1. Activate the plugin through the 'Plugins' menu in WordPress 
    21 1. Include the 'Reclinks Add Link Form' widget in a sidebar (or anywhere). 
    22 1. Any links added through this widget show up in the archive for the custom post type "Recommended Links".  
    23 1. If you have permalinks enabled, the archive will be displayed at `http://yoursite.tld/reclinks`; otherwise it will be at `http://yoursite.tld?post_type=reclink`. __(Note: on first activating the plugin, you may have to "flush your rewrite rules" to make these permalinks work - this can be done by visiting the Settings &raquo; Permalinks page in your WordPress admin once.)__ 
     191. Upload the entire `recommended-links/` folder to the `/wp-content/plugins/` directory. 
     201. Activate the plugin through the 'Plugins' menu in WordPress. 
     211. A plugin options page is included under the "Recommended Links" admin menu, where you can select some basic settings. 
     221. Include the 'Reclinks Add Link Form' widget in a sidebar (or anywhere). Alternately, you can use the shortcode `[reclinks_addlinkform]` in any page or post. 
     231. Any links added through this widget show up in the archive for the custom post type "Recommended Links". You can also create a new page and set that page to show your links on the plugin options page. 
     241. If you have permalinks enabled, the archive will be displayed at `http://yoursite.tld/reclinks`; otherwise it will be at `http://yoursite.tld?post_type=reclink`.  
    24251. The plugin tries to intelligently filter markup so that it can work with most themes out of the box. If the archive or single link display doesn't work in your theme, you may have to create an `archive-reclink.php` or `single-reclink.php` template file. _(See the FAQ for examples of markup for these template files)_. 
     261. See the "Frequently Asked Questions for questions on customizing the output or styling the plugin. 
    2527 
    2628== Frequently Asked Questions == 
     29 
     30= How can I customize the markup of the list of "Recommended Links"? = 
     31 
     32__If you are using the default post type archive__, WordPress will search in your theme directory for a file called `archive-reclinks.php`. If thats not found, it will fall back along the usual WordPress [template hierarchy](http://codex.wordpress.org/Template_Hierarchy). The easiest way to begin customizing your output is to copy your existing `archive.php` or `index.php` to a file called `archive-reclinks.php` and begin making changes to it. 
     33 
     34__If you have selected an existing page to hold your archive__, WordPress will use the template assigned to that page for the page layout, and the loop defined in the `loop_reclinks.php` file in the plugin directory to mark up the list of recommended links. To make changes to the `loop-reclinks.php` (which also affects the output of the recommended links list widget), copy it to your theme directory and edit it there. 
     35 
     36__Individual recommended link posts__ are handled by WordPress's normal template hierarchy in your theme. If you want to change their markup and layout, create a file in your theme directory called `single-reclink.php` (or copy your `single.php` file and rename it to `single-reclink.php`) and begin editing. 
    2737 
    2838= What sorting options are there? = 
     
    3747So for example, with permalinks enabled, the URL `yoursite.tld/reclinks/?sort=hot` would display a page of the 25 links with the highest vote score over the past day. 
    3848 
    39 At this point, implementing these sorting options is fully up to you - a user cookie would make sense here, or a drop down at the top of the archive page would work. I will provide a template tag and a widget to change sorting once I flesh out these options some more. 
     49You can also set a default sort order from the plugin settings page. The query string argument, if present, overrides the default value. So if your default sorting is **current**, you can still give your users a chance to view top voted links of all time by giving them a link to `yoursite.tld/reclinks/?sort=score`. 
    4050 
    4151= What markup does the plugin offer? = 
     
    5363* `reclink_domain()` echoes the host of the link submitted - give people a chance to know what they're getting themselves into before they follow a link.  
    5464* `reclink_votebox()` echoes a div with +/- vote buttons, the current score, author, and human time diff'd post date 
     65* `author_karma( $user )` returns a user's total karma score 
    5566 
    56 = Sample markup = 
    57  
    58 Sample markup for the loop on an `archive-reclinks.php` template. This will output a list very similar to [Hacker News](http://news.ycombinator.com)'s frontpage: 
    59  
    60     <?php if ( have_posts() ) : ?> 
    61     <ol> 
    62     <?php while ( have_posts() ) : the_post(); ?> 
    63         <li><strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong> <small><?php reclink_domain(); ?><small> 
    64             <br /><?php reclinks_votebox(); ?> 
    65         </li> 
    66     <?php endwhile; ?> 
    67     </ol> 
    68     <?php endif; ?> 
    69  
    70 That's all there is to it! 
    7167 
    7268 
    7369== Changelog == 
     70 
     71= 0.3 = 
     72 
     73Added multiple new features: 
     74 
     75* Plugin settings page 
     76* Link title now auto-populates from the link URL, so users don't have to enter it by hand 
     77* Shortcode for link add form 
     78* Allows you to set an existing page as the archive, rather than use the WP archive page 
     79* Option to allow unregistered users to vote (tracks votes by IP address) 
     80* User karma functions - not in UI yet; but roughed out. Use function `author_karma( $user )` to get a user's score. 
     81 
     82Also, fixed a couple bugs and roughed out the plugin to prepare for a number of other features in the works. 
    7483 
    7584= 0.2.2 = 
     
    8897== Upgrade Notice == 
    8998 
     99= 0.3 = 
     100 
     101This version includes a plugin settings page, as well as multiple new features: 
     102 
     103* Link title now auto-populates from the link URL, so users don't have to enter it by hand 
     104* Shortcode for link add form 
     105* Allows you to set an existing page as the archive, rather than use the WP archive page 
     106* Option to allow unregistered users to vote (tracks votes by IP address) 
     107* User karma functions - not in UI yet; but roughed out. 
     108 
    90109= 0.2.2 = 
    91110Added a widget to display the most recently posted links in the sidebar. Also, fixed some minor javascript and css errors. 
  • recommended-links/tags/0.3/recommended-links.php

    r482847 r486514  
    1010 
    1111// Variable definitions first 
    12 $reclinks_theme_options = get_option('reclinks_plugin_options'); 
     12$reclinks_options = get_option('reclinks_plugin_options'); 
    1313 
    1414// Register reclinks_votes table so it can be used with $wpdb class 
     
    2424 
    2525// Required files 
     26require_once( plugin_dir_path( __FILE__ ) . '/admin-functions.php' ); 
    2627require_once( plugin_dir_path( __FILE__ ) . '/user-functions.php' ); 
    2728require_once( plugin_dir_path( __FILE__ ) . '/widgets.php' ); 
    2829require_once( plugin_dir_path( __FILE__ ) . '/ajax-functions.php' ); 
    2930require_once( plugin_dir_path( __FILE__ ) . '/display-filters.php' ); 
     31require_once( plugin_dir_path( __FILE__ ) . '/display-shortcodes.php' ); 
    3032 
    3133// Register custom post type required for this work 
     
    3335 
    3436function register_cpt_reclink() { 
     37 
     38    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
    3539 
    3640    // Code generated by: http://themergency.com/generators/wordpress-custom-post-types/ 
     
    5458        'hierarchical' => false, 
    5559        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'custom-fields', 'comments' ), 
    56         'taxonomies' => array( 'category' ), 
     60        'taxonomies' => array_keys( $plugin_settings['tax'] ), 
    5761        'public' => true, 
    5862        'show_ui' => true, 
     
    8084register_deactivation_hook( __FILE__, 'reclinks_uninstall'); 
    8185 
     86 
     87add_action( 'admin_init', 'gad_check_db_tables' ); 
     88 
     89function gad_check_db_tables() { 
     90    $v = get_option( 'reclinks_db_version' ); 
     91    if ( !$v || $v < 2 ) 
     92        reclinks_db_option_upgrade( $v ); 
     93} 
     94 
     95 
    8296// Enqueue javascript and CSS on front end 
    8397add_action( 'wp_enqueue_scripts', 'gad_reclinks_enqueues' ); 
     
    90104        array(  
    91105            'ajaxUrl' => admin_url( 'admin-ajax.php' ),  
    92             'loginUrl' => wp_login_url( ( !empty( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) .$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] )  
     106            'loginUrl' => wp_login_url( ( !empty( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) .$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ), 
     107            'messages' => array( 
     108                'linkSubmitted' => __( 'Link submitted successfully.', 'gad_reclinks' ), 
     109                'error404'      => __( 'The submitted link could not be found.', 'gad_reclinks' ), 
     110                'errorNoTitle'  => __( 'The document does not appear to have a title.', 'gad_reclinks' ) 
     111            ) 
    93112        )  
    94113    ); 
    95114    wp_enqueue_style( 'reclinks', RECLINKS_DIRECTORY . 'reclinks-styles.css' ); 
    96115} 
     116 
    97117 
    98118/** 
     
    111131 
    112132function gad_add_reclink( $reclink ) { 
     133    global $current_user; 
     134 
     135    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     136 
    113137    // Check to see that user is authorized to add link 
    114     if ( !current_user_can( 'add_reclink' ) ) 
     138    if ( !$plugin_settings['allow-unregistered-post'] && !current_user_can( 'add_reclink' ) ) 
    115139        return false; 
    116140 
     
    129153        'post_title'    => $reclink['reclink_title'], 
    130154        'post_content'  => $reclink['reclink_description'], 
    131         'post_status'   => 'publish' 
     155        'post_status'   => 'publish', 
     156        'tax_input'     => $reclink['reclink_taxes'] 
    132157    ) ); 
     158 
    133159    update_post_meta( $link_ID, '_href', $reclink['reclink_url'] ); 
    134160    update_post_meta( $link_ID, '_vote_score', 1 ); 
     
    136162    return $link_ID; 
    137163} 
     164 
    138165 
    139166/** 
  • recommended-links/tags/0.3/widgets.php

    r481764 r486514  
    3131            if ( !empty( $title ) )  
    3232                echo $before_title . $title . $after_title; 
    33         ?> 
    34             <form class="reclinks_addlink" action="<?php echo add_query_arg( 'action', 'reclink-add' ); ?>" method="POST"> 
    35                 <label for="reclink_URL"><?php _e('Link URL', 'gad_reclinks'); ?></label> 
    36                 <input type="text" name="reclink_URL" /> 
    37                 <label for="reclink_title"><?php _e('Link Title', 'gad_reclinks'); ?></label> 
    38                 <input type="text" name="reclink_title" /> 
    39                 <label for="reclink_description"><?php _e('Link Description', 'gad_reclinks'); ?></label> 
    40                 <textarea id="reclink_description" name="reclink_description" rows="10" cols="30"></textarea> 
    41                 <button type="submit" id="reclink_submit"><?php _e( 'Submit Link', 'gad_reclinks' ); ?></button> 
    42             </form> 
    43         <?php    
     33 
     34            echo output_addlink_form(); 
     35 
    4436            echo $after_widget; 
    4537        } 
     
    9385                echo $before_title . $title . $after_title; 
    9486 
    95             $links = new WP_Query( array( 
     87 
     88            global $wp_query; 
     89            $old_query = $wp_query; 
     90 
     91            $wp_query = new WP_Query( array( 
    9692                'post_type' => 'reclink', 
    97                 'posts_per_page' => intval( $instance['number'] ) 
     93                'posts_per_page' => intval( $instance['number'] ), 
     94                'reclinks_sort' => 'current' 
    9895            ) ); 
    9996 
    100             if ( $links->have_posts() ) : 
    101                 echo '<ul>'; 
    102                 while ( $links->have_posts() ) : $links->the_post(); 
    103                     echo '<li><a href="'; the_permalink(); echo '" title="'.the_title_attribute().'" >'.get_the_title().'</a> '; 
    104                     if ( $instance['domain'] ) 
    105                         echo '<small>(' . reclinks_domain( false ) . ')</small>'; 
    106                     echo '<br / >' . reclinks_votebox( false ) . '</li>'; 
    107                 endwhile; 
     97            if ( '' === locate_template( 'loop-reclinks.php', true, false ) ) 
     98                include( 'loop-reclinks.php' ); 
    10899 
    109                 echo '</ul>'; 
    110             endif; 
     100            $wp_query = $old_query; 
    111101 
    112102            if ( $instance['links'] !== 'none' ): 
  • recommended-links/trunk/ajax-functions.php

    r481240 r486514  
    2020        return; 
    2121 
    22     if ( 'reclink-add' === $_GET['action'] ) { 
     22    if ( 'reclink-add' === $_GET['action'] && !empty( $_POST['reclink_URL'] ) ) { 
    2323        $reclink = array( 
    2424            'reclink_url' => esc_url( $_POST['reclink_URL'] ), 
    2525            'reclink_title' => sanitize_text_field( $_POST['reclink_title'] ), 
    26             'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ) 
     26            'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ), 
     27            'reclink_taxes' => ( isset( $_POST['reclink_taxes'] ) ) ? $_POST['reclink_taxes'] : null 
    2728        ); 
    2829        gad_add_reclink( $reclink ); 
    2930    }  
    3031 
    31     if ( 'reclink-vote' === $_GET['action'] ) {      
     32    if ( 'reclink-vote' === $_GET['action'] && !empty( $_POST['reclink'] ) ) {       
    3233        global $current_user; 
    3334        get_currentuserinfo(); 
     
    4546 
    4647function gad_reclinks_ajax_add() { 
    47     if ( !current_user_can( 'add_reclink' ) ) 
     48    $plugin_settings = get_option( 'reclinks_plugin_settings' ); 
     49 
     50    if ( !$plugin_settings['allow-unregistered-post'] && !current_user_can( 'add_reclink' ) ) 
    4851        die( json_encode( array( 'exception' => 'Current user is not authorized to add links' ) ) ); 
     52 
    4953    $reclink = array( 
    5054        'reclink_url' => esc_url( $_POST['reclink_URL'] ), 
    5155        'reclink_title' => sanitize_text_field( $_POST['reclink_title'] ), 
    52         'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ) 
     56        'reclink_description' => wp_filter_post_kses( $_POST['reclink_description'] ), 
     57        'reclink_taxes' => $_POST['reclink_taxes'] 
    5358    ); 
     59 
    5460    $link = gad_add_reclink( $reclink ); 
    5561    echo json_encode( get_post( $link ) ); 
     
    6268 
    6369function gad_reclinks_ajax_vote() { 
     70    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     71 
    6472    global $current_user; 
    6573    get_currentuserinfo(); 
    6674 
    67     if ( !current_user_can( 'vote_reclink' ) ) 
     75    if ( !$plugin_settings['allow-unregistered-vote'] && !current_user_can( 'vote_reclink' ) ) 
    6876        die( json_encode( array( 'exception' => 'Current user is not authorized to add links' ) ) ); 
    6977 
     
    7785} 
    7886 
     87add_action( 'wp_ajax_check_reclink_title', 'gad_reclinks_check_link_title' ); 
     88add_action( 'wp_ajax_nopriv_check_reclink_title', 'gad_reclinks_check_link_title' ); 
     89 
     90function gad_reclinks_check_link_title() { 
     91    $link = esc_url( $_POST['url'] ); 
     92    if ( !$link ) { 
     93        $return['exception'] = 'Invalid URL'; 
     94    } 
     95    $response = wp_remote_get( $link ); 
     96    if ( $response ) { 
     97        $doc = new DOMDocument(); 
     98        $doc->strictErrorChecking = FALSE; 
     99        $doc->loadHTML( $response['body'] ); 
     100        $xml = simplexml_import_dom($doc); 
     101        $title = $xml->head->title; 
     102        $return['title'] = (string)$title; 
     103    } 
     104    die( json_encode( $return ) ); 
     105 
     106 
     107} 
  • recommended-links/trunk/display-filters.php

    r481905 r486514  
    11<?php 
    22 
    3 // Query filters for reclinks 
     3/** 
     4 * Query filters for reclinks 
     5 *  
     6 * 
     7 */ 
     8 
     9 
     10add_filter('query_vars', 'gad_reclinks_add_query_vars'); 
     11 
     12function gad_reclinks_add_query_vars( $query_vars ) { 
     13    $query_vars[] = "reclinks_sort"; 
     14    return $query_vars; 
     15} 
     16 
    417 
    518add_filter( 'pre_get_posts', 'gad_reclinks_sortby' ); 
    619 
    720function gad_reclinks_sortby( $query ) { 
     21    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
    822 
    923    global $wp_the_query; 
    1024 
    11     if ( !is_post_type_archive('reclink') || ( $query !== $wp_the_query ) ) 
     25    if ( !isset( $query->query_vars['post_type'] ) || $query->query_vars['post_type'] !== 'reclink') 
    1226        return $query; 
    13  
    14     $query->set( 'posts_per_page', 25 ); 
    15  
    16     $sortby = 'current'; // default sort 
     27     
     28    if ( $query === $wp_the_query ) { 
     29        $posts_per_page = ( isset( $plugin_settings['posts_per_page'] ) ) ? $plugin_settings['posts_per_page'] : 25; 
     30        $query->set( 'posts_per_page', $posts_per_page ); 
     31    } 
     32 
     33    $sort_order = ( isset( $plugin_settings['sort_order'] ) ) ? $plugin_settings['sort_order'] : 'current'; 
    1734 
    1835    if ( isset( $_GET['sort'] ) && in_array( 
    1936            $_GET['sort'],  
    2037            array( 'newest', 'hot', 'current', 'score' ) ) ) 
    21         $sortby = $_GET['sort']; 
    22  
    23     switch ( $sortby ) : 
     38        $sort_order = $_GET['sort']; 
     39 
     40    if ( isset( $query->query_vars['reclinks_sort'] ) && in_array( 
     41            $query->query_vars['reclinks_sort'],  
     42            array( 'newest', 'hot', 'current', 'score' ) ) ) 
     43        $sort_order = $query->query_vars['reclinks_sort']; 
     44 
     45    switch ( $sort_order ) : 
    2446        case 'score': 
    2547            // default: order by vote total 
     
    92114} 
    93115 
     116 
     117/** 
     118 * By default, filters the_content to add the vote box above the content  
     119 * (the link description). If you would like to add the vote box in a different  
     120 * location, you can remove this filter and include the template tag 
     121 * reclinks_votebox() in your theme files. 
     122 * 
     123 */ 
    94124add_filter( 'the_content', 'gad_reclinks_show_votelinks' ); 
    95125 
    96126function gad_reclinks_show_votelinks( $content ) { 
     127    if ( is_admin() ) 
     128        return $content; 
     129 
    97130    global $post; 
    98131    if ( $post->post_type !== 'reclink' ) 
     
    103136} 
    104137 
     138 
     139/** 
     140 * By default, filters comment_text to add the vote box above the comment text.  
     141 * If you would like to add the vote box in a different location, you can remove  
     142 * this filter and include the template tag reclinks_votebox() in your comment 
     143 * callback function 
     144 * 
     145 */ 
    105146add_filter( 'comment_text', 'reclinks_comment_show_votelinks' ); 
    106147 
    107148function reclinks_comment_show_votelinks( $comment_text, $comment = null ) { 
     149    if ( is_admin() ) 
     150        return $comment_text; 
     151     
    108152    global $post; 
    109153    if ( $post->post_type !== 'reclink' ) 
     
    131175 
    132176    if ( !isset( $comment ) ) { 
     177 
    133178        // votebox on recommended link itself 
    134179        $current_score = get_post_meta( $post->ID, '_vote_score', true ); 
     
    148193 
    149194    } else { 
     195 
    150196        // fields relevant to comments 
    151197        $current_score = $comment->comment_karma; 
     
    196242} 
    197243 
     244 
     245/** 
     246 * For recommended links, the_permalink is filtered to echo the link submitted, 
     247 * not the permalink of the comments page on your site. To get the discussion page 
     248 * permalink instead, use get_permalink() or another similar function. 
     249 * 
     250 */ 
    198251add_filter( 'the_permalink', 'gad_reclinks_permalink' ); 
    199252 
     
    205258} 
    206259 
    207 // the price you pay for typos in documentation 
    208 function reclink_domain( $echo = true ) { return reclinks_domain( $echo ); } 
     260function reclink_domain( $echo = true ) { return reclinks_domain( $echo ); } // the price you pay for typos in documentation 
    209261 
    210262function reclinks_domain( $echo = true ) { 
     
    218270} 
    219271 
     272 
     273/** 
     274 * A "pseudo-loop" for the page designated as "Page for Recommended Links Archive" 
     275 * 
     276 * Uses the WP_Query object to retrieve posts, the loop-reclinks.php template to display 
     277 * them, and the WordPress functions get_previous_posts_page and get_next_posts_page. 
     278 * In short, it basically functions just like a regular archive page, except for the  
     279 * template and the WordPress conditional tags, (ie. `is_archive()` will return false). 
     280 */ 
     281add_filter( 'the_content', 'gad_reclinks_page' ); 
     282 
     283function gad_reclinks_page( $content ) { 
     284    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     285 
     286    if ( !$plugin_settings['page_for_reclinks'] || !is_page( $plugin_settings['page_for_reclinks'] ) ) 
     287        return $content;     
     288 
     289    global $wp_query; 
     290 
     291    $links_paged = ( isset( $wp_query->query_vars['paged'] ) ) ? $wp_query->query_vars['paged'] : 1; 
     292    $posts_per_page = ( isset( $plugin_settings['posts_per_page'] ) ) ? $plugin_settings['posts_per_page'] : 25; 
     293 
     294    $old_query = $wp_query; 
     295    $wp_query = new WP_Query( array( 
     296        'post_type' => 'reclink', 
     297        'reclinks_sort' => $plugin_settings['sort_order'], 
     298        'posts_per_page' => $posts_per_page, 
     299        'paged' => $links_paged 
     300    ) ); 
     301 
     302 
     303    /* 
     304     * Basic structure for prev/next links, 
     305     * should be built out a little more in future releases. 
     306     */ 
     307    $found_posts = $wp_query->found_posts; 
     308 
     309    $links_navigation = '<div class="links-navigation">' ; 
     310 
     311    if ( $links_paged > 1 )  
     312        $links_navigation .= '<div class="nav-previous">' . get_previous_posts_link() . '</div>'; 
     313     
     314    if ( $found_posts > $posts_per_page * $links_paged ) 
     315        $links_navigation .= '<div class="nav-next">' . get_next_posts_link() . '</div>'; 
     316 
     317    $links_navigation .= '</div>'; 
     318 
     319    ob_start(); 
     320    if ( '' === locate_template( 'loop-reclinks.php', true, false ) ) 
     321        include( 'loop-reclinks.php' ); 
     322    $links_archive = ob_get_clean(); 
     323 
     324    $wp_query = $old_query; 
     325    return $content . $links_archive . $links_navigation; 
     326 
     327} 
  • recommended-links/trunk/js/reclinks-scripts.coffee

    r481764 r486514  
    22    $('form.reclinks_addlink').bind 'submit', (event) -> 
    33        event.preventDefault 
    4         alert 'submitting' 
    5         $.ajax 
     4        form = $(this).fadeOut() 
     5        $.ajax reclinks.ajaxUrl + '?action=add_reclink', 
    66            type: 'post' 
    7             url: reclinks.ajaxUrl + '?action=add_reclink' 
    8             data: $(this).serialize() 
     7            data: form.serialize() 
    98            complete: () -> 
    10                 alert 'Link Submitted!' 
     9                form.find 
     10                form[0].reset() 
     11                form.prepend("<div class='message'><strong>#{ reclinks.messages.linkSubmit }</strong></div>").fadeIn() 
    1112        return false 
    1213    $('form.reclinks_vote button').bind 'click', (event) -> 
     
    1415        form = $(this).parent('form') 
    1516        vote = $(this).data('vote') 
    16         $.ajax 
     17        $.ajax reclinks.ajaxUrl + '?action=vote_reclink', 
    1718            type: 'post' 
    18             url: reclinks.ajaxUrl + '?action=vote_reclink' 
    1919            data: form.serialize() + '&vote=' + vote 
    2020            complete: (r) -> 
     
    2525                    form.find('.votescore').text( response.newCount ); 
    2626        return false 
     27    $('#reclink_URL').bind 'change', (event) -> 
     28        linkUrl = $(this).val() 
     29        $.ajax 'http://query.yahooapis.com/v1/public/yql', 
     30            type: 'get', 
     31            data: { 
     32                q: "use 'http://www.datatables.org/data/htmlstring.xml' as htmlstring; select * from htmlstring where url='#{ linkUrl }'", 
     33                format: 'json' 
     34                }, 
     35            dataType: 'json', 
     36            success: (r) -> 
     37                response = r.query.results 
     38                unless response 
     39                    alert reclinks.messages.error404 
     40                    return false 
     41                title = response.result.match( /<\s*title\s*>([^<]*)<\/title>/ )[1] 
     42                unless title 
     43                    alert reclinks.messages.errorNoTitle 
     44                    return false 
     45                $('#reclink_title').val title unless $('#reclink_title').val() is not '' 
     46        null 
    2747    null 
  • recommended-links/trunk/js/reclinks-scripts.js

    r481764 r486514  
    22  jQuery(function($) { 
    33    $('form.reclinks_addlink').bind('submit', function(event) { 
     4      var form; 
    45      event.preventDefault; 
    5       alert('submitting'); 
    6       $.ajax({ 
     6      form = $(this).fadeOut(); 
     7      $.ajax(reclinks.ajaxUrl + '?action=add_reclink', { 
    78        type: 'post', 
    8         url: reclinks.ajaxUrl + '?action=add_reclink', 
    9         data: $(this).serialize(), 
     9        data: form.serialize(), 
    1010        complete: function() { 
    11           return alert('Link Submitted!'); 
     11          form.find; 
     12          form[0].reset(); 
     13          return form.prepend("<div class='message'><strong>" + reclinks.messages.linkSubmit + "</strong></div>").fadeIn(); 
    1214        } 
    1315      }); 
     
    1921      form = $(this).parent('form'); 
    2022      vote = $(this).data('vote'); 
    21       $.ajax({ 
     23      $.ajax(reclinks.ajaxUrl + '?action=vote_reclink', { 
    2224        type: 'post', 
    23         url: reclinks.ajaxUrl + '?action=vote_reclink', 
    2425        data: form.serialize() + '&vote=' + vote, 
    2526        complete: function(r) { 
     
    3536      return false; 
    3637    }); 
     38    $('#reclink_URL').bind('change', function(event) { 
     39      var linkUrl; 
     40      linkUrl = $(this).val(); 
     41      $.ajax('http://query.yahooapis.com/v1/public/yql', { 
     42        type: 'get', 
     43        data: { 
     44          q: "use 'http://www.datatables.org/data/htmlstring.xml' as htmlstring; select * from htmlstring where url='" + linkUrl + "'", 
     45          format: 'json' 
     46        }, 
     47        dataType: 'json', 
     48        success: function(r) { 
     49          var response, title; 
     50          response = r.query.results; 
     51          if (!response) { 
     52            alert(reclinks.messages.error404); 
     53            return false; 
     54          } 
     55          title = response.result.match(/<\s*title\s*>([^<]*)<\/title>/)[1]; 
     56          if (!title) { 
     57            alert(reclinks.messages.errorNoTitle); 
     58            return false; 
     59          } 
     60          if ($('#reclink_title').val() !== !'') { 
     61            return $('#reclink_title').val(title); 
     62          } 
     63        } 
     64      }); 
     65      return null; 
     66    }); 
    3767    return null; 
    3868  }); 
  • recommended-links/trunk/plugin-activation.php

    r481240 r486514  
    4040    } 
    4141 
    42     if (!get_option('reclinks_plugin_options')) { 
    43     // Mockups of options. TODO: make these actual user-editable settings. 
     42    // Create default options in database settings 
     43    $v = get_option( 'reclinks_db_version' ); 
     44    reclinks_db_option_upgrade( $v ); 
     45 
     46} 
     47 
     48 
     49/** 
     50 * Create default options settings. 
     51 * 
     52 * Handles creating new options when upgrading from one version of the plugin to the next. 
     53 * 
     54 * @param   int     the db version being upgraded from 
     55 *                  // ie get_option( 'reclinks_db_version' ) 
     56 * 
     57 **/ 
     58function reclinks_db_option_upgrade( $from ) { 
     59 
     60    /* DB version 2, reflects plugin version 0.4. First user-editable settings. */ 
     61    if ( !$from || $from < 2 ) { 
    4462        $reclinks_plugin_defaults = array( 
    4563            'vote-values' => array( 
    4664                'minus' => array( 'value' => -1, 'text' => '-' ), 
    4765                'plus' => array( 'value' => 1, 'text' => '+' ) 
    48             ) 
     66            ), 
     67            'page-for-reclinks' => false, 
     68            'sort-order' => 'current', 
     69            'allow-unregistered-vote' => false, 
     70            'allow-unregistered-post' => false 
    4971        ); 
    50         update_option('reclinks_plugin_options',$reclinks_plugin_defaults); 
    5172    } 
     73 
     74    update_option( 'reclinks_plugin_options', $reclinks_plugin_defaults ); 
     75    update_option( 'reclinks_db_version', 2 ); 
     76 
    5277} 
     78 
    5379 
    5480/** 
  • recommended-links/trunk/readme.txt

    r482847 r486514  
    44Tags: social bookmarking, sharing, voting, reddit, digg 
    55Requires at least: 3.2.1 
    6 Tested up to: 3.3 
    7 Stable tag: 0.2.3 
     6Tested up to: 3.3.1 
     7Stable tag: 0.3 
    88 
    99A sort of "Reddit clone" that allows users to post links, up- or down-vote them, and comment on them. 
     
    1111== Description == 
    1212 
    13 This is the beginnings of a much more ambitious project. At the moment, there is no admin options screen and functionality is a bit limited. However, if you want to try this out, please give me feedback. 
     13This is the beginning of what I hope will be a much more ambitious project. If you want to try this out, please give me feedback. 
    1414 
    1515I will guarantee backwards compatibility with all data saved by the plugin, so it should be safe to install and activate, and as I add features, your existing posts and links will work with them just fine. 
     
    1717== Installation == 
    1818 
    19 1. Upload the entire `recommended-links/` folder to the `/wp-content/plugins/` directory 
    20 1. Activate the plugin through the 'Plugins' menu in WordPress 
    21 1. Include the 'Reclinks Add Link Form' widget in a sidebar (or anywhere). 
    22 1. Any links added through this widget show up in the archive for the custom post type "Recommended Links".  
    23 1. If you have permalinks enabled, the archive will be displayed at `http://yoursite.tld/reclinks`; otherwise it will be at `http://yoursite.tld?post_type=reclink`. __(Note: on first activating the plugin, you may have to "flush your rewrite rules" to make these permalinks work - this can be done by visiting the Settings &raquo; Permalinks page in your WordPress admin once.)__ 
     191. Upload the entire `recommended-links/` folder to the `/wp-content/plugins/` directory. 
     201. Activate the plugin through the 'Plugins' menu in WordPress. 
     211. A plugin options page is included under the "Recommended Links" admin menu, where you can select some basic settings. 
     221. Include the 'Reclinks Add Link Form' widget in a sidebar (or anywhere). Alternately, you can use the shortcode `[reclinks_addlinkform]` in any page or post. 
     231. Any links added through this widget show up in the archive for the custom post type "Recommended Links". You can also create a new page and set that page to show your links on the plugin options page. 
     241. If you have permalinks enabled, the archive will be displayed at `http://yoursite.tld/reclinks`; otherwise it will be at `http://yoursite.tld?post_type=reclink`.  
    24251. The plugin tries to intelligently filter markup so that it can work with most themes out of the box. If the archive or single link display doesn't work in your theme, you may have to create an `archive-reclink.php` or `single-reclink.php` template file. _(See the FAQ for examples of markup for these template files)_. 
     261. See the "Frequently Asked Questions for questions on customizing the output or styling the plugin. 
    2527 
    2628== Frequently Asked Questions == 
     29 
     30= How can I customize the markup of the list of "Recommended Links"? = 
     31 
     32__If you are using the default post type archive__, WordPress will search in your theme directory for a file called `archive-reclinks.php`. If thats not found, it will fall back along the usual WordPress [template hierarchy](http://codex.wordpress.org/Template_Hierarchy). The easiest way to begin customizing your output is to copy your existing `archive.php` or `index.php` to a file called `archive-reclinks.php` and begin making changes to it. 
     33 
     34__If you have selected an existing page to hold your archive__, WordPress will use the template assigned to that page for the page layout, and the loop defined in the `loop_reclinks.php` file in the plugin directory to mark up the list of recommended links. To make changes to the `loop-reclinks.php` (which also affects the output of the recommended links list widget), copy it to your theme directory and edit it there. 
     35 
     36__Individual recommended link posts__ are handled by WordPress's normal template hierarchy in your theme. If you want to change their markup and layout, create a file in your theme directory called `single-reclink.php` (or copy your `single.php` file and rename it to `single-reclink.php`) and begin editing. 
    2737 
    2838= What sorting options are there? = 
     
    3747So for example, with permalinks enabled, the URL `yoursite.tld/reclinks/?sort=hot` would display a page of the 25 links with the highest vote score over the past day. 
    3848 
    39 At this point, implementing these sorting options is fully up to you - a user cookie would make sense here, or a drop down at the top of the archive page would work. I will provide a template tag and a widget to change sorting once I flesh out these options some more. 
     49You can also set a default sort order from the plugin settings page. The query string argument, if present, overrides the default value. So if your default sorting is **current**, you can still give your users a chance to view top voted links of all time by giving them a link to `yoursite.tld/reclinks/?sort=score`. 
    4050 
    4151= What markup does the plugin offer? = 
     
    5363* `reclink_domain()` echoes the host of the link submitted - give people a chance to know what they're getting themselves into before they follow a link.  
    5464* `reclink_votebox()` echoes a div with +/- vote buttons, the current score, author, and human time diff'd post date 
     65* `author_karma( $user )` returns a user's total karma score 
    5566 
    56 = Sample markup = 
    57  
    58 Sample markup for the loop on an `archive-reclinks.php` template. This will output a list very similar to [Hacker News](http://news.ycombinator.com)'s frontpage: 
    59  
    60     <?php if ( have_posts() ) : ?> 
    61     <ol> 
    62     <?php while ( have_posts() ) : the_post(); ?> 
    63         <li><strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong> <small><?php reclink_domain(); ?><small> 
    64             <br /><?php reclinks_votebox(); ?> 
    65         </li> 
    66     <?php endwhile; ?> 
    67     </ol> 
    68     <?php endif; ?> 
    69  
    70 That's all there is to it! 
    7167 
    7268 
    7369== Changelog == 
     70 
     71= 0.3 = 
     72 
     73Added multiple new features: 
     74 
     75* Plugin settings page 
     76* Link title now auto-populates from the link URL, so users don't have to enter it by hand 
     77* Shortcode for link add form 
     78* Allows you to set an existing page as the archive, rather than use the WP archive page 
     79* Option to allow unregistered users to vote (tracks votes by IP address) 
     80* User karma functions - not in UI yet; but roughed out. Use function `author_karma( $user )` to get a user's score. 
     81 
     82Also, fixed a couple bugs and roughed out the plugin to prepare for a number of other features in the works. 
    7483 
    7584= 0.2.2 = 
     
    8897== Upgrade Notice == 
    8998 
     99= 0.3 = 
     100 
     101This version includes a plugin settings page, as well as multiple new features: 
     102 
     103* Link title now auto-populates from the link URL, so users don't have to enter it by hand 
     104* Shortcode for link add form 
     105* Allows you to set an existing page as the archive, rather than use the WP archive page 
     106* Option to allow unregistered users to vote (tracks votes by IP address) 
     107* User karma functions - not in UI yet; but roughed out. 
     108 
    90109= 0.2.2 = 
    91110Added a widget to display the most recently posted links in the sidebar. Also, fixed some minor javascript and css errors. 
  • recommended-links/trunk/recommended-links.php

    r482847 r486514  
    1010 
    1111// Variable definitions first 
    12 $reclinks_theme_options = get_option('reclinks_plugin_options'); 
     12$reclinks_options = get_option('reclinks_plugin_options'); 
    1313 
    1414// Register reclinks_votes table so it can be used with $wpdb class 
     
    2424 
    2525// Required files 
     26require_once( plugin_dir_path( __FILE__ ) . '/admin-functions.php' ); 
    2627require_once( plugin_dir_path( __FILE__ ) . '/user-functions.php' ); 
    2728require_once( plugin_dir_path( __FILE__ ) . '/widgets.php' ); 
    2829require_once( plugin_dir_path( __FILE__ ) . '/ajax-functions.php' ); 
    2930require_once( plugin_dir_path( __FILE__ ) . '/display-filters.php' ); 
     31require_once( plugin_dir_path( __FILE__ ) . '/display-shortcodes.php' ); 
    3032 
    3133// Register custom post type required for this work 
     
    3335 
    3436function register_cpt_reclink() { 
     37 
     38    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
    3539 
    3640    // Code generated by: http://themergency.com/generators/wordpress-custom-post-types/ 
     
    5458        'hierarchical' => false, 
    5559        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'custom-fields', 'comments' ), 
    56         'taxonomies' => array( 'category' ), 
     60        'taxonomies' => array_keys( $plugin_settings['tax'] ), 
    5761        'public' => true, 
    5862        'show_ui' => true, 
     
    8084register_deactivation_hook( __FILE__, 'reclinks_uninstall'); 
    8185 
     86 
     87add_action( 'admin_init', 'gad_check_db_tables' ); 
     88 
     89function gad_check_db_tables() { 
     90    $v = get_option( 'reclinks_db_version' ); 
     91    if ( !$v || $v < 2 ) 
     92        reclinks_db_option_upgrade( $v ); 
     93} 
     94 
     95 
    8296// Enqueue javascript and CSS on front end 
    8397add_action( 'wp_enqueue_scripts', 'gad_reclinks_enqueues' ); 
     
    90104        array(  
    91105            'ajaxUrl' => admin_url( 'admin-ajax.php' ),  
    92             'loginUrl' => wp_login_url( ( !empty( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) .$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] )  
     106            'loginUrl' => wp_login_url( ( !empty( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) .$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ), 
     107            'messages' => array( 
     108                'linkSubmitted' => __( 'Link submitted successfully.', 'gad_reclinks' ), 
     109                'error404'      => __( 'The submitted link could not be found.', 'gad_reclinks' ), 
     110                'errorNoTitle'  => __( 'The document does not appear to have a title.', 'gad_reclinks' ) 
     111            ) 
    93112        )  
    94113    ); 
    95114    wp_enqueue_style( 'reclinks', RECLINKS_DIRECTORY . 'reclinks-styles.css' ); 
    96115} 
     116 
    97117 
    98118/** 
     
    111131 
    112132function gad_add_reclink( $reclink ) { 
     133    global $current_user; 
     134 
     135    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     136 
    113137    // Check to see that user is authorized to add link 
    114     if ( !current_user_can( 'add_reclink' ) ) 
     138    if ( !$plugin_settings['allow-unregistered-post'] && !current_user_can( 'add_reclink' ) ) 
    115139        return false; 
    116140 
     
    129153        'post_title'    => $reclink['reclink_title'], 
    130154        'post_content'  => $reclink['reclink_description'], 
    131         'post_status'   => 'publish' 
     155        'post_status'   => 'publish', 
     156        'tax_input'     => $reclink['reclink_taxes'] 
    132157    ) ); 
     158 
    133159    update_post_meta( $link_ID, '_href', $reclink['reclink_url'] ); 
    134160    update_post_meta( $link_ID, '_vote_score', 1 ); 
     
    136162    return $link_ID; 
    137163} 
     164 
    138165 
    139166/** 
  • recommended-links/trunk/widgets.php

    r481764 r486514  
    3131            if ( !empty( $title ) )  
    3232                echo $before_title . $title . $after_title; 
    33         ?> 
    34             <form class="reclinks_addlink" action="<?php echo add_query_arg( 'action', 'reclink-add' ); ?>" method="POST"> 
    35                 <label for="reclink_URL"><?php _e('Link URL', 'gad_reclinks'); ?></label> 
    36                 <input type="text" name="reclink_URL" /> 
    37                 <label for="reclink_title"><?php _e('Link Title', 'gad_reclinks'); ?></label> 
    38                 <input type="text" name="reclink_title" /> 
    39                 <label for="reclink_description"><?php _e('Link Description', 'gad_reclinks'); ?></label> 
    40                 <textarea id="reclink_description" name="reclink_description" rows="10" cols="30"></textarea> 
    41                 <button type="submit" id="reclink_submit"><?php _e( 'Submit Link', 'gad_reclinks' ); ?></button> 
    42             </form> 
    43         <?php    
     33 
     34            echo output_addlink_form(); 
     35 
    4436            echo $after_widget; 
    4537        } 
     
    9385                echo $before_title . $title . $after_title; 
    9486 
    95             $links = new WP_Query( array( 
     87 
     88            global $wp_query; 
     89            $old_query = $wp_query; 
     90 
     91            $wp_query = new WP_Query( array( 
    9692                'post_type' => 'reclink', 
    97                 'posts_per_page' => intval( $instance['number'] ) 
     93                'posts_per_page' => intval( $instance['number'] ), 
     94                'reclinks_sort' => 'current' 
    9895            ) ); 
    9996 
    100             if ( $links->have_posts() ) : 
    101                 echo '<ul>'; 
    102                 while ( $links->have_posts() ) : $links->the_post(); 
    103                     echo '<li><a href="'; the_permalink(); echo '" title="'.the_title_attribute().'" >'.get_the_title().'</a> '; 
    104                     if ( $instance['domain'] ) 
    105                         echo '<small>(' . reclinks_domain( false ) . ')</small>'; 
    106                     echo '<br / >' . reclinks_votebox( false ) . '</li>'; 
    107                 endwhile; 
     97            if ( '' === locate_template( 'loop-reclinks.php', true, false ) ) 
     98                include( 'loop-reclinks.php' ); 
    10899 
    109                 echo '</ul>'; 
    110             endif; 
     100            $wp_query = $old_query; 
    111101 
    112102            if ( $instance['links'] !== 'none' ): 
Note: See TracChangeset for help on using the changeset viewer.