Plugin Directory

Changeset 428453


Ignore:
Timestamp:
08/25/2011 04:13:58 AM (15 years ago)
Author:
taehan
Message:

umrp 1.4.1

Location:
u-more-recent-posts
Files:
3 deleted
6 edited
8 copied

Legend:

Unmodified
Added
Removed
  • u-more-recent-posts/tags/1.4.1/inc/script.js

    r427425 r428453  
    11
    2 var UMRP_Widget = function(t, widget_type){
     2var UMRP_Widget = function(t){
    33    var $ = jQuery;
    4     var widget_id = t.id;
    5     var container = $(t).find('.umrp-container');
     4    var $t = $(t);
     5    var widget_id = t.id.replace('-container', '');
     6    var widget_type = $t.hasClass('widget-type') ? 'widget' : ($t.hasClass('shortcode-type') ? 'shortcode' : '');
    67    var list, progress, nav;
    7     var options = {}, current_postid, auto_paginate_t;
     8    var options = {}, current_postid = '', auto_paginate_t;
    89   
    910    var init = function(){
    1011        resign_elements();
    1112       
    12         if( container.hasClass('single') ){
    13             var match = /postid-(\d+)/.exec( container.attr('class') );
     13        if( $t.hasClass('single') ){
     14            var match = /postid-(\d+)/.exec( $t.attr('class') );
    1415            current_postid = match ? match[1] : '';
     16            $t.removeClass('single');
    1517        }else{
    1618            UMRP_Cookie.remove_cookie(widget_id);
     
    1820       
    1921        nav.find('a').live('click', function(){
    20             var match = /umrp-page=(\d+)/.exec(this.href);
    21             var paged = match ? match[1] : '';
     22            var paged = Number(this.hash.replace('#', ''));
    2223            disappear(paged);
    2324            UMRP_Cookie.add_cookie(widget_id, paged, options.cookiepath);
     
    2526        });
    2627       
    27         container.hover(
     28        $t.hover(
    2829            function(){
    2930                $(this).addClass('pause');
     
    4748                if( options.auto_paginate )
    4849                    next_page();
    49                
    5050            }, 'json');
    5151       
    5252        }else if( widget_type=='shortcode'){
    53             options = /<!--(.*)-->/.exec(container.html());
     53            options = /<!--(.*)-->/.exec($t.html());
    5454            options = $.parseJSON(options[1]);
    5555        }
     
    5959   
    6060    var resign_elements = function(){
    61         list = container.find('ul');
    62         progress = container.find('.umrp-progress');
    63         nav = container.find('.umrp-nav');
     61        list = $t.find('.umrp-list');
     62        progress = $t.find('.umrp-progress');
     63        nav = $t.find('.umrp-nav');
    6464       
    6565        var list_pos = list.position();
     
    7575            widget_id: widget_id,
    7676            paged: paged,
    77             current_postid: current_postid ? current_postid : ''
     77            current_postid: current_postid
    7878        }
    7979       
     
    8787       
    8888        $.post(umrp_vars.ajaxurl, data, function(html){
    89             container.html(html);
     89            $t.html(html);
    9090            resign_elements();
    9191            appear();
     
    9494   
    9595    var appear = function(){
    96         var w = $(t).width();
    9796        var h = list.height();
    9897        list.css({height: h});
     
    110109           
    111110            case 'slidein':
    112             wrap_for_slide();
    113             list.css({left: w}).animate({left:0}, dur);
     111            var wrap = wrap_for_slide();
     112            list.css({left: wrap.width()}).animate({left:0}, dur);
    114113            break;
    115114        };
     
    120119   
    121120    var disappear = function(paged){
    122         var w = $(t).width();
    123121        var h = list.height();
    124122        list.css({height: h});
     
    141139           
    142140            case 'slideout':
    143             wrap_for_slide();
    144             list.animate({left:-w}, dur, '', function(){
     141            var wrap = wrap_for_slide();
     142            list.animate({left:-(wrap.width())}, dur, '', function(){
    145143                get_list(paged);
    146144            });
     
    156154   
    157155    var wrap_for_slide = function(){
    158         var w = $(t).width();
     156        var w = $t.width();
    159157        var h = list.height();
    160         var wrap = container.find('div.umrp-slide');
     158        var margin = parseInt(list.css('margin-left'))
     159        margin += parseInt(list.css('padding-left'));
     160        list.width( w-margin );
     161       
     162        var wrap = $t.find('div.umrp-slide');
    161163        if( !wrap.length ){
    162164            wrap = $('<div class="umrp-slide"/>').css({width: w, height: h});
     
    181183   
    182184    var load_next_page = function(){
    183         if( container.hasClass('pause') ){
     185        if( $t.hasClass('pause') ){
    184186            next_page();
    185187        }else{
     
    188190        }
    189191    }
    190    
    191192   
    192193    init();
     
    230231
    231232jQuery(function(){
    232     jQuery('.widget_umrp').each(function(){
    233         new UMRP_Widget( this, 'widget' );
    234     });
    235     jQuery('.umrp-shortcode').each(function(){
    236         new UMRP_Widget( this, 'shortcode' );
     233    jQuery('.umrp-container').each(function(){
     234        new UMRP_Widget( this );
    237235    });
    238236});
  • u-more-recent-posts/tags/1.4.1/inc/style.css

    r427425 r428453  
    33    position: relative;
    44}
    5 .umrp-container ul {
     5.umrp-container .umrp-list {
    66    margin-top: 0 !important;
    77    margin-bottom: 0 !important;
    88}
    9 .umrp-container li {
     9.umrp-container .umrp-list li {
    1010    clear: both;
    1111}
     
    2222    min-width: none !important;
    2323}
    24 .umrp-progress {
     24.umrp-container .umrp-progress {
    2525    position: absolute;
    2626    top: 0;
     
    3232/* effect
    3333--------------------------------------------------------------------------------------- */
    34 .umrp-slide {
     34.umrp-container .umrp-slide {
    3535    position: relative;
    3636    overflow: hidden;
    3737}
    38 .umrp-slide ul {
     38.umrp-container .umrp-slide .umrp-list {
    3939    position: absolute;
    4040    top:0;
     
    7979    font-weight: normal !important;
    8080    color: #333;
     81    text-decoration: none;
    8182}
    8283.umrp-nav .current,
     
    99100    font-size: 12px;
    100101}
    101 
    102 
  • u-more-recent-posts/tags/1.4.1/readme.txt

    r427432 r428453  
    55Requires at least: 3.1
    66Tested up to: 3.2.1
    7 Stable tag: 1.4
     7Stable tag: 1.4.1
    88
    99This plugin make it possible to navigate more recent posts without refreshing screen.
     
    4141
    4242== Changelog ==
     43
     44= 1.4.1 =
     45*Changed: DOM Structure
     46*Fixed: Slide effect
    4347
    4448= 1.4 =
  • u-more-recent-posts/tags/1.4.1/u-more-recent-posts.php

    r427432 r428453  
    44Plugin URI: http://urlless.com/u-more-recent-posts/
    55Description: This plugin make it possible to navigate more recent posts without refreshing screen.
    6 Version: 1.4
     6Version: 1.4.1
    77Author: Taehan Lee
    88Author URI: http://urlless.com
     
    1212
    1313var $id = 'umrp';
    14 var $ver = '1.4';
     14var $ver = '1.4.1';
    1515var $url;
    1616
     
    5555}
    5656
    57 function the_list_for_widget( $widget_id, $paged='', $current_postid='' ){
    58     $opts = $this->get_widget_option($widget_id);
    59     echo $this->get_the_list($opts, $paged, $current_postid, 'wp-'.$widget_id.'-paged');
    60 }
    61 
    62 function the_list_for_shortcode( $list_id, $opts, $paged='', $current_postid='' ){
    63     echo $this->get_the_list($opts, $paged, $current_postid, 'wp-'.$list_id.'-paged' );
    64 }
    65 
    66 function get_the_list($opts, $paged='', $current_postid='', $cookie_key='' ){
    67     $defaults = $this->get_default_options();
    68     $opts = wp_parse_args($opts, $defaults);
     57function ajax() {
     58    check_ajax_referer( $this->id.'_nonce' );
     59   
     60    switch( $_POST['action_scope'] ):
     61       
     62        case 'get_widget_option':
     63        $opts = $this->get_widget_option( $_POST['widget_id'] );
     64        $opts['cookiepath'] = COOKIEPATH;
     65        echo json_encode( $opts );
     66        break;
     67       
     68        case 'the_list_for_widget':
     69        $args = array(
     70            'widget_id' => $_POST['widget_id'],
     71            'paged' => $_POST['paged'],
     72            'current_postid' => $_POST['current_postid'],
     73        );
     74        $this->the_list_for_widget( $args );
     75        break;
     76       
     77        case 'the_list_for_shortcode':
     78        $args = array(
     79            'widget_id' => $_POST['widget_id'],
     80            'paged' => $_POST['paged'],
     81            'current_postid' => $_POST['current_postid'],
     82            'options' => (array) $_POST['options'],
     83        );
     84        $this->the_list_for_shortcode( $args );
     85        break;
     86       
     87    endswitch; 
     88    die();
     89}
     90
     91function get_widget_option($widget_id){
     92    $all_opts = get_option('widget_'.$this->id);
     93    $index = (int) preg_replace('/'.$this->id.'-/', '', $widget_id);
     94    $opts = $all_opts[$index];
     95    return $opts;
     96}
     97
     98function the_list_for_widget( $args ){
     99    if( empty($args['widget_id']) )
     100        return false;
     101    $args['options'] = $this->get_widget_option( $args['widget_id'] );
     102    $args['cookie_key'] = 'wp-'.$args['widget_id'].'-paged';
     103    echo $this->get_the_list($args);
     104}
     105
     106function the_list_for_shortcode( $args ){
     107    if( empty($args['widget_id']) )
     108        return false;
     109    $args['cookie_key'] = 'wp-'.$args['widget_id'].'-paged';
     110    echo $this->get_the_list( $args );
     111}
     112
     113function get_the_list( $args ){
     114    $default_args = array(
     115        'options' => array(),
     116        'paged' => '',
     117        'current_postid' => '',
     118        'cookie_key' => '',
     119    );
     120    $args = wp_parse_args($args, $default_args);
     121    extract($args);
     122   
     123    $default_options = $this->get_default_options();
     124    $opts = wp_parse_args($options, $default_options);
    69125   
    70126    $paged = ( empty($paged) AND is_single() AND !empty($_COOKIE[$cookie_key]) ) ? $_COOKIE[$cookie_key] : $paged;
    71127    $paged = max(1, absint($paged));
    72128   
    73     $args = array(
    74         'posts_per_page' => !empty($opts['number']) ? $opts['number'] : 5,
     129    $query_args = array(
     130        'posts_per_page' => $opts['number'],
    75131        'paged' => $paged,
    76132        'post_status' => 'publish',
     
    79135   
    80136    if( !empty($opts['post_type']) ) {
    81         $args['post_type'] = $opts['post_type'];
     137        $query_args['post_type'] = $opts['post_type'];
    82138       
    83139        if( !empty($opts['tax_query']) AND isset($opts['tax_query'][$opts['post_type']]) ) {
     
    100156                    $_tax_query['operator'] = $operator;
    101157               
    102                 $args['tax_query'] = array($_tax_query);
     158                $query_args['tax_query'] = array($_tax_query);
    103159            }
    104160        }
     
    116172            $authors = join(',', $ex_authors);
    117173        }
    118         $args['author'] = $authors;
     174        $query_args['author'] = $authors;
    119175    }
    120176   
     
    124180    }
    125181   
    126     $args = apply_filters('umrp_query_parameters', $args);
    127    
    128     $q = new WP_Query($args);
     182    $query_args = apply_filters('umrp_query_parameters', $query_args);
     183   
     184    $q = new WP_Query($query_args);
    129185    if ( !$q->have_posts() )
    130186        return false;
    131187       
    132     $ret = '<ul>';
     188    $ret = '<ul class="umrp-list">';
    133189    while($q->have_posts()): $q->the_post();
    134190        $post_id = get_the_ID();
     
    174230    $total_page = $max_page>0 ? min($max_page, $q->max_num_pages) : $q->max_num_pages;
    175231    $page_args = array(
    176         'base' => add_query_arg( 'umrp-page', '%#%', home_url('/') ),
     232        'base' => '#%#%',
     233        'format' => '',
    177234        'total' => $total_page,
    178235        'current' => $paged,
     
    183240   
    184241    if( $page_links ){
    185         $page_links = $opts['navi_label'] . ' ' . $page_links;
    186         $page_links = '<div class="umrp-nav %s '.$opts['navi_align'].'">'.$page_links.'</div>';
     242        $page_links_label = $opts['navi_label'] ? '<span class="umrp-nav-label">'.$opts['navi_label'].'</span> ' : '';
     243        $page_links = '<div class="umrp-nav %s '.$opts['navi_align'].'">'.$page_links_label.$page_links.'</div>';
    187244        $page_links_top = sprintf($page_links, 'umrp-nav-top');
    188245        $page_links_bottom = sprintf($page_links, 'umrp-nav-bottom');
     
    209266function shortcode_display($atts){
    210267    global $post;
    211     $query_args = $this->get_default_options();
    212     foreach($query_args as $k=>$v){
     268   
     269    $default_atts = array(
     270        'id' => 'umrp-shortcode',
     271    );
     272    extract( shortcode_atts( $default_atts, $atts ) );
     273   
     274    $opts = $this->get_default_options();
     275    foreach($opts as $k=>$v){
    213276        if( isset($atts[$k]) )
    214             $query_args[$k] = $atts[$k];
     277            $opts[$k] = $atts[$k];
    215278    }
    216279    if( isset($atts['tax_query']) ){
    217         $tax_query = wp_parse_args(preg_replace('/&amp;/', '&', $atts['tax_query']));
    218         $query_args['tax_query'] = array($query_args['post_type'] => $tax_query);
    219     }
    220     $query_string = json_encode($query_args);
    221    
    222     $default_atts = array(
    223         'id' => '',
    224     );
    225     extract( shortcode_atts( $default_atts, $atts ) );
    226    
    227     $class = $current_postid = '';
     280        $opts['tax_query'] = array($opts['post_type'] => wp_parse_args(preg_replace('/&amp;/', '&', $atts['tax_query'])));
     281    }
     282   
     283    $container_class = 'shortcode-type';
     284    $current_postid = '';
    228285    if( is_single() ){
    229         $class = 'single postid-'.$post->ID;
     286        $container_class .= ' single postid-'.$post->ID;
    230287        $current_postid = $post->ID;
    231288    }
     289   
     290    $args = array(
     291        'widget_id' => $id,
     292        'current_postid' => $current_postid,
     293        'options' => $opts,
     294    );
    232295    ?>
    233296    <div class="umrp-shortcode" id="<?php echo $id?>">
    234         <?php if( $query_args['title'] ){ ?>
    235         <h3 class="umrp-title"><?php echo $query_args['title']?></h3>
     297        <?php if( $opts['title'] ){ ?>
     298        <h3 class="umrp-title"><?php echo $opts['title']?></h3>
    236299        <?php } ?>
    237         <div class="umrp-container <?php echo $class?>">
    238             <?php echo $this->get_the_list($query_args);?>
    239             <!--<?php echo $query_string?>-->
     300        <div id="<?php echo $id?>-container" class="umrp-container <?php echo $container_class?>">
     301            <?php echo $this->the_list_for_shortcode($args);?>
     302            <!--<?php echo json_encode($opts)?>-->
    240303        </div>
    241304    </div>
     
    243306}
    244307
    245 function ajax() {
    246     check_ajax_referer( $this->id.'_nonce' );
    247    
    248     switch( $_POST['action_scope'] ):
    249        
    250         case 'get_widget_option':
    251         $opts = $this->get_widget_option( $_POST['widget_id'] );
    252         $opts['cookiepath'] = COOKIEPATH;
    253         echo json_encode( $opts );
    254         break;
    255        
    256         case 'the_list_for_widget':
    257         $this->the_list_for_widget( $_POST['widget_id'], $_POST['paged'], $_POST['current_postid'] );
    258         break;
    259        
    260         case 'the_list_for_shortcode':
    261         $this->the_list_for_shortcode( $_POST['widget_id'], (array) $_POST['options'], $_POST['paged'], $_POST['current_postid'] );
    262         break;
    263        
    264     endswitch; 
    265     die();
    266 }
    267308
    268309function filter_where( $where = '' ) {
     
    272313}
    273314
    274 
    275 function get_widget_option($widget_id){
    276     $opts = get_option('widget_'.$this->id);
    277     $widget_id = (int) preg_replace('/'.$this->id.'-/', '', $widget_id);
    278     $opts = $opts[$widget_id];
    279     return $opts;
    280 }
    281315
    282316function get_post_thumbnail( $post_id, $w, $h ){
     
    353387   
    354388    extract($args);
     389   
    355390    $title = apply_filters('widget_title', $instance['title']);
     391    $id = (int) str_replace('umrp-', '', $widget_id);
     392   
     393    $container_class = 'widget-type';
     394    $current_postid = '';
     395    if( is_single() ){
     396        $container_class .= ' single postid-'.$post->ID;
     397        $current_postid = $post->ID;
     398    }
     399   
     400    if( !empty($instance['custom_css']) ){
     401        $custom_css = preg_replace('/%widget_id%/', '#'.$widget_id.'-container', $instance['custom_css']);
     402        $custom_css = preg_replace('/(\r|\n)/', '', $custom_css);
     403        $custom_css = '<style>'.$custom_css.'</style>';
     404    }
     405   
     406    $args = array(
     407        'widget_id' => $widget_id,
     408        'current_postid' => $current_postid,
     409    );
     410   
    356411    echo $before_widget;
    357     if( $title ) echo $before_title . $title . $after_title;
    358    
    359     $class = $current_postid = '';
    360     if( is_single() ){
    361         $class = 'single postid-'.$post->ID;
    362         $current_postid = $post->ID;
    363     }
     412    if( $title )
     413        echo $before_title.$title.$after_title;
    364414    ?>
    365     <div class="umrp-container <?php echo $class?>">
    366         <?php $umrp->the_list_for_widget( $widget_id, '', $current_postid );?>
     415   
     416    <div id="umrp-<?php echo $id?>-container" class="umrp-container <?php echo $container_class?>">
     417        <?php $umrp->the_list_for_widget( $args );?>
    367418    </div>
     419   
    368420    <?php
    369     if( !empty($instance['custom_css']) ){
    370         $css = $instance['custom_css'];
    371         $css = str_replace('%widget_id%', '#'.$args['widget_id'], $css);
    372         $css = preg_replace('/(\r|\n)/', '', $css);
    373         echo '<style>'.$css.'</style>';
    374     }
    375    
     421    echo $custom_css;
    376422    echo $after_widget;
    377423}
  • u-more-recent-posts/trunk/inc/script.js

    r427425 r428453  
    11
    2 var UMRP_Widget = function(t, widget_type){
     2var UMRP_Widget = function(t){
    33    var $ = jQuery;
    4     var widget_id = t.id;
    5     var container = $(t).find('.umrp-container');
     4    var $t = $(t);
     5    var widget_id = t.id.replace('-container', '');
     6    var widget_type = $t.hasClass('widget-type') ? 'widget' : ($t.hasClass('shortcode-type') ? 'shortcode' : '');
    67    var list, progress, nav;
    7     var options = {}, current_postid, auto_paginate_t;
     8    var options = {}, current_postid = '', auto_paginate_t;
    89   
    910    var init = function(){
    1011        resign_elements();
    1112       
    12         if( container.hasClass('single') ){
    13             var match = /postid-(\d+)/.exec( container.attr('class') );
     13        if( $t.hasClass('single') ){
     14            var match = /postid-(\d+)/.exec( $t.attr('class') );
    1415            current_postid = match ? match[1] : '';
     16            $t.removeClass('single');
    1517        }else{
    1618            UMRP_Cookie.remove_cookie(widget_id);
     
    1820       
    1921        nav.find('a').live('click', function(){
    20             var match = /umrp-page=(\d+)/.exec(this.href);
    21             var paged = match ? match[1] : '';
     22            var paged = Number(this.hash.replace('#', ''));
    2223            disappear(paged);
    2324            UMRP_Cookie.add_cookie(widget_id, paged, options.cookiepath);
     
    2526        });
    2627       
    27         container.hover(
     28        $t.hover(
    2829            function(){
    2930                $(this).addClass('pause');
     
    4748                if( options.auto_paginate )
    4849                    next_page();
    49                
    5050            }, 'json');
    5151       
    5252        }else if( widget_type=='shortcode'){
    53             options = /<!--(.*)-->/.exec(container.html());
     53            options = /<!--(.*)-->/.exec($t.html());
    5454            options = $.parseJSON(options[1]);
    5555        }
     
    5959   
    6060    var resign_elements = function(){
    61         list = container.find('ul');
    62         progress = container.find('.umrp-progress');
    63         nav = container.find('.umrp-nav');
     61        list = $t.find('.umrp-list');
     62        progress = $t.find('.umrp-progress');
     63        nav = $t.find('.umrp-nav');
    6464       
    6565        var list_pos = list.position();
     
    7575            widget_id: widget_id,
    7676            paged: paged,
    77             current_postid: current_postid ? current_postid : ''
     77            current_postid: current_postid
    7878        }
    7979       
     
    8787       
    8888        $.post(umrp_vars.ajaxurl, data, function(html){
    89             container.html(html);
     89            $t.html(html);
    9090            resign_elements();
    9191            appear();
     
    9494   
    9595    var appear = function(){
    96         var w = $(t).width();
    9796        var h = list.height();
    9897        list.css({height: h});
     
    110109           
    111110            case 'slidein':
    112             wrap_for_slide();
    113             list.css({left: w}).animate({left:0}, dur);
     111            var wrap = wrap_for_slide();
     112            list.css({left: wrap.width()}).animate({left:0}, dur);
    114113            break;
    115114        };
     
    120119   
    121120    var disappear = function(paged){
    122         var w = $(t).width();
    123121        var h = list.height();
    124122        list.css({height: h});
     
    141139           
    142140            case 'slideout':
    143             wrap_for_slide();
    144             list.animate({left:-w}, dur, '', function(){
     141            var wrap = wrap_for_slide();
     142            list.animate({left:-(wrap.width())}, dur, '', function(){
    145143                get_list(paged);
    146144            });
     
    156154   
    157155    var wrap_for_slide = function(){
    158         var w = $(t).width();
     156        var w = $t.width();
    159157        var h = list.height();
    160         var wrap = container.find('div.umrp-slide');
     158        var margin = parseInt(list.css('margin-left'))
     159        margin += parseInt(list.css('padding-left'));
     160        list.width( w-margin );
     161       
     162        var wrap = $t.find('div.umrp-slide');
    161163        if( !wrap.length ){
    162164            wrap = $('<div class="umrp-slide"/>').css({width: w, height: h});
     
    181183   
    182184    var load_next_page = function(){
    183         if( container.hasClass('pause') ){
     185        if( $t.hasClass('pause') ){
    184186            next_page();
    185187        }else{
     
    188190        }
    189191    }
    190    
    191192   
    192193    init();
     
    230231
    231232jQuery(function(){
    232     jQuery('.widget_umrp').each(function(){
    233         new UMRP_Widget( this, 'widget' );
    234     });
    235     jQuery('.umrp-shortcode').each(function(){
    236         new UMRP_Widget( this, 'shortcode' );
     233    jQuery('.umrp-container').each(function(){
     234        new UMRP_Widget( this );
    237235    });
    238236});
  • u-more-recent-posts/trunk/inc/style.css

    r427425 r428453  
    33    position: relative;
    44}
    5 .umrp-container ul {
     5.umrp-container .umrp-list {
    66    margin-top: 0 !important;
    77    margin-bottom: 0 !important;
    88}
    9 .umrp-container li {
     9.umrp-container .umrp-list li {
    1010    clear: both;
    1111}
     
    2222    min-width: none !important;
    2323}
    24 .umrp-progress {
     24.umrp-container .umrp-progress {
    2525    position: absolute;
    2626    top: 0;
     
    3232/* effect
    3333--------------------------------------------------------------------------------------- */
    34 .umrp-slide {
     34.umrp-container .umrp-slide {
    3535    position: relative;
    3636    overflow: hidden;
    3737}
    38 .umrp-slide ul {
     38.umrp-container .umrp-slide .umrp-list {
    3939    position: absolute;
    4040    top:0;
     
    7979    font-weight: normal !important;
    8080    color: #333;
     81    text-decoration: none;
    8182}
    8283.umrp-nav .current,
     
    99100    font-size: 12px;
    100101}
    101 
    102 
  • u-more-recent-posts/trunk/readme.txt

    r427432 r428453  
    55Requires at least: 3.1
    66Tested up to: 3.2.1
    7 Stable tag: 1.4
     7Stable tag: 1.4.1
    88
    99This plugin make it possible to navigate more recent posts without refreshing screen.
     
    4141
    4242== Changelog ==
     43
     44= 1.4.1 =
     45*Changed: DOM Structure
     46*Fixed: Slide effect
    4347
    4448= 1.4 =
  • u-more-recent-posts/trunk/u-more-recent-posts.php

    r427432 r428453  
    44Plugin URI: http://urlless.com/u-more-recent-posts/
    55Description: This plugin make it possible to navigate more recent posts without refreshing screen.
    6 Version: 1.4
     6Version: 1.4.1
    77Author: Taehan Lee
    88Author URI: http://urlless.com
     
    1212
    1313var $id = 'umrp';
    14 var $ver = '1.4';
     14var $ver = '1.4.1';
    1515var $url;
    1616
     
    5555}
    5656
    57 function the_list_for_widget( $widget_id, $paged='', $current_postid='' ){
    58     $opts = $this->get_widget_option($widget_id);
    59     echo $this->get_the_list($opts, $paged, $current_postid, 'wp-'.$widget_id.'-paged');
    60 }
    61 
    62 function the_list_for_shortcode( $list_id, $opts, $paged='', $current_postid='' ){
    63     echo $this->get_the_list($opts, $paged, $current_postid, 'wp-'.$list_id.'-paged' );
    64 }
    65 
    66 function get_the_list($opts, $paged='', $current_postid='', $cookie_key='' ){
    67     $defaults = $this->get_default_options();
    68     $opts = wp_parse_args($opts, $defaults);
     57function ajax() {
     58    check_ajax_referer( $this->id.'_nonce' );
     59   
     60    switch( $_POST['action_scope'] ):
     61       
     62        case 'get_widget_option':
     63        $opts = $this->get_widget_option( $_POST['widget_id'] );
     64        $opts['cookiepath'] = COOKIEPATH;
     65        echo json_encode( $opts );
     66        break;
     67       
     68        case 'the_list_for_widget':
     69        $args = array(
     70            'widget_id' => $_POST['widget_id'],
     71            'paged' => $_POST['paged'],
     72            'current_postid' => $_POST['current_postid'],
     73        );
     74        $this->the_list_for_widget( $args );
     75        break;
     76       
     77        case 'the_list_for_shortcode':
     78        $args = array(
     79            'widget_id' => $_POST['widget_id'],
     80            'paged' => $_POST['paged'],
     81            'current_postid' => $_POST['current_postid'],
     82            'options' => (array) $_POST['options'],
     83        );
     84        $this->the_list_for_shortcode( $args );
     85        break;
     86       
     87    endswitch; 
     88    die();
     89}
     90
     91function get_widget_option($widget_id){
     92    $all_opts = get_option('widget_'.$this->id);
     93    $index = (int) preg_replace('/'.$this->id.'-/', '', $widget_id);
     94    $opts = $all_opts[$index];
     95    return $opts;
     96}
     97
     98function the_list_for_widget( $args ){
     99    if( empty($args['widget_id']) )
     100        return false;
     101    $args['options'] = $this->get_widget_option( $args['widget_id'] );
     102    $args['cookie_key'] = 'wp-'.$args['widget_id'].'-paged';
     103    echo $this->get_the_list($args);
     104}
     105
     106function the_list_for_shortcode( $args ){
     107    if( empty($args['widget_id']) )
     108        return false;
     109    $args['cookie_key'] = 'wp-'.$args['widget_id'].'-paged';
     110    echo $this->get_the_list( $args );
     111}
     112
     113function get_the_list( $args ){
     114    $default_args = array(
     115        'options' => array(),
     116        'paged' => '',
     117        'current_postid' => '',
     118        'cookie_key' => '',
     119    );
     120    $args = wp_parse_args($args, $default_args);
     121    extract($args);
     122   
     123    $default_options = $this->get_default_options();
     124    $opts = wp_parse_args($options, $default_options);
    69125   
    70126    $paged = ( empty($paged) AND is_single() AND !empty($_COOKIE[$cookie_key]) ) ? $_COOKIE[$cookie_key] : $paged;
    71127    $paged = max(1, absint($paged));
    72128   
    73     $args = array(
    74         'posts_per_page' => !empty($opts['number']) ? $opts['number'] : 5,
     129    $query_args = array(
     130        'posts_per_page' => $opts['number'],
    75131        'paged' => $paged,
    76132        'post_status' => 'publish',
     
    79135   
    80136    if( !empty($opts['post_type']) ) {
    81         $args['post_type'] = $opts['post_type'];
     137        $query_args['post_type'] = $opts['post_type'];
    82138       
    83139        if( !empty($opts['tax_query']) AND isset($opts['tax_query'][$opts['post_type']]) ) {
     
    100156                    $_tax_query['operator'] = $operator;
    101157               
    102                 $args['tax_query'] = array($_tax_query);
     158                $query_args['tax_query'] = array($_tax_query);
    103159            }
    104160        }
     
    116172            $authors = join(',', $ex_authors);
    117173        }
    118         $args['author'] = $authors;
     174        $query_args['author'] = $authors;
    119175    }
    120176   
     
    124180    }
    125181   
    126     $args = apply_filters('umrp_query_parameters', $args);
    127    
    128     $q = new WP_Query($args);
     182    $query_args = apply_filters('umrp_query_parameters', $query_args);
     183   
     184    $q = new WP_Query($query_args);
    129185    if ( !$q->have_posts() )
    130186        return false;
    131187       
    132     $ret = '<ul>';
     188    $ret = '<ul class="umrp-list">';
    133189    while($q->have_posts()): $q->the_post();
    134190        $post_id = get_the_ID();
     
    174230    $total_page = $max_page>0 ? min($max_page, $q->max_num_pages) : $q->max_num_pages;
    175231    $page_args = array(
    176         'base' => add_query_arg( 'umrp-page', '%#%', home_url('/') ),
     232        'base' => '#%#%',
     233        'format' => '',
    177234        'total' => $total_page,
    178235        'current' => $paged,
     
    183240   
    184241    if( $page_links ){
    185         $page_links = $opts['navi_label'] . ' ' . $page_links;
    186         $page_links = '<div class="umrp-nav %s '.$opts['navi_align'].'">'.$page_links.'</div>';
     242        $page_links_label = $opts['navi_label'] ? '<span class="umrp-nav-label">'.$opts['navi_label'].'</span> ' : '';
     243        $page_links = '<div class="umrp-nav %s '.$opts['navi_align'].'">'.$page_links_label.$page_links.'</div>';
    187244        $page_links_top = sprintf($page_links, 'umrp-nav-top');
    188245        $page_links_bottom = sprintf($page_links, 'umrp-nav-bottom');
     
    209266function shortcode_display($atts){
    210267    global $post;
    211     $query_args = $this->get_default_options();
    212     foreach($query_args as $k=>$v){
     268   
     269    $default_atts = array(
     270        'id' => 'umrp-shortcode',
     271    );
     272    extract( shortcode_atts( $default_atts, $atts ) );
     273   
     274    $opts = $this->get_default_options();
     275    foreach($opts as $k=>$v){
    213276        if( isset($atts[$k]) )
    214             $query_args[$k] = $atts[$k];
     277            $opts[$k] = $atts[$k];
    215278    }
    216279    if( isset($atts['tax_query']) ){
    217         $tax_query = wp_parse_args(preg_replace('/&amp;/', '&', $atts['tax_query']));
    218         $query_args['tax_query'] = array($query_args['post_type'] => $tax_query);
    219     }
    220     $query_string = json_encode($query_args);
    221    
    222     $default_atts = array(
    223         'id' => '',
    224     );
    225     extract( shortcode_atts( $default_atts, $atts ) );
    226    
    227     $class = $current_postid = '';
     280        $opts['tax_query'] = array($opts['post_type'] => wp_parse_args(preg_replace('/&amp;/', '&', $atts['tax_query'])));
     281    }
     282   
     283    $container_class = 'shortcode-type';
     284    $current_postid = '';
    228285    if( is_single() ){
    229         $class = 'single postid-'.$post->ID;
     286        $container_class .= ' single postid-'.$post->ID;
    230287        $current_postid = $post->ID;
    231288    }
     289   
     290    $args = array(
     291        'widget_id' => $id,
     292        'current_postid' => $current_postid,
     293        'options' => $opts,
     294    );
    232295    ?>
    233296    <div class="umrp-shortcode" id="<?php echo $id?>">
    234         <?php if( $query_args['title'] ){ ?>
    235         <h3 class="umrp-title"><?php echo $query_args['title']?></h3>
     297        <?php if( $opts['title'] ){ ?>
     298        <h3 class="umrp-title"><?php echo $opts['title']?></h3>
    236299        <?php } ?>
    237         <div class="umrp-container <?php echo $class?>">
    238             <?php echo $this->get_the_list($query_args);?>
    239             <!--<?php echo $query_string?>-->
     300        <div id="<?php echo $id?>-container" class="umrp-container <?php echo $container_class?>">
     301            <?php echo $this->the_list_for_shortcode($args);?>
     302            <!--<?php echo json_encode($opts)?>-->
    240303        </div>
    241304    </div>
     
    243306}
    244307
    245 function ajax() {
    246     check_ajax_referer( $this->id.'_nonce' );
    247    
    248     switch( $_POST['action_scope'] ):
    249        
    250         case 'get_widget_option':
    251         $opts = $this->get_widget_option( $_POST['widget_id'] );
    252         $opts['cookiepath'] = COOKIEPATH;
    253         echo json_encode( $opts );
    254         break;
    255        
    256         case 'the_list_for_widget':
    257         $this->the_list_for_widget( $_POST['widget_id'], $_POST['paged'], $_POST['current_postid'] );
    258         break;
    259        
    260         case 'the_list_for_shortcode':
    261         $this->the_list_for_shortcode( $_POST['widget_id'], (array) $_POST['options'], $_POST['paged'], $_POST['current_postid'] );
    262         break;
    263        
    264     endswitch; 
    265     die();
    266 }
    267308
    268309function filter_where( $where = '' ) {
     
    272313}
    273314
    274 
    275 function get_widget_option($widget_id){
    276     $opts = get_option('widget_'.$this->id);
    277     $widget_id = (int) preg_replace('/'.$this->id.'-/', '', $widget_id);
    278     $opts = $opts[$widget_id];
    279     return $opts;
    280 }
    281315
    282316function get_post_thumbnail( $post_id, $w, $h ){
     
    353387   
    354388    extract($args);
     389   
    355390    $title = apply_filters('widget_title', $instance['title']);
     391    $id = (int) str_replace('umrp-', '', $widget_id);
     392   
     393    $container_class = 'widget-type';
     394    $current_postid = '';
     395    if( is_single() ){
     396        $container_class .= ' single postid-'.$post->ID;
     397        $current_postid = $post->ID;
     398    }
     399   
     400    if( !empty($instance['custom_css']) ){
     401        $custom_css = preg_replace('/%widget_id%/', '#'.$widget_id.'-container', $instance['custom_css']);
     402        $custom_css = preg_replace('/(\r|\n)/', '', $custom_css);
     403        $custom_css = '<style>'.$custom_css.'</style>';
     404    }
     405   
     406    $args = array(
     407        'widget_id' => $widget_id,
     408        'current_postid' => $current_postid,
     409    );
     410   
    356411    echo $before_widget;
    357     if( $title ) echo $before_title . $title . $after_title;
    358    
    359     $class = $current_postid = '';
    360     if( is_single() ){
    361         $class = 'single postid-'.$post->ID;
    362         $current_postid = $post->ID;
    363     }
     412    if( $title )
     413        echo $before_title.$title.$after_title;
    364414    ?>
    365     <div class="umrp-container <?php echo $class?>">
    366         <?php $umrp->the_list_for_widget( $widget_id, '', $current_postid );?>
     415   
     416    <div id="umrp-<?php echo $id?>-container" class="umrp-container <?php echo $container_class?>">
     417        <?php $umrp->the_list_for_widget( $args );?>
    367418    </div>
     419   
    368420    <?php
    369     if( !empty($instance['custom_css']) ){
    370         $css = $instance['custom_css'];
    371         $css = str_replace('%widget_id%', '#'.$args['widget_id'], $css);
    372         $css = preg_replace('/(\r|\n)/', '', $css);
    373         echo '<style>'.$css.'</style>';
    374     }
    375    
     421    echo $custom_css;
    376422    echo $after_widget;
    377423}
Note: See TracChangeset for help on using the changeset viewer.