WordPress.org

Plugin Directory

Changeset 335684 for organize-series


Ignore:
Timestamp:
01/22/11 05:18:04 (3 years ago)
Author:
nerrad
Message:

[fixes https://www.pivotaltracker.com/story/show/8799829]
[fixes https://www.pivotaltracker.com/story/show/8800251]
[fixes https://www.pivotaltracker.com/story/show/8691459]

  • Major update that adds new hooks and filters for more addons (specifically enabling Organize Series Multiples addon)
  • series_part custom field has been reworked so it's hidden from the edit_post screen (automatic imports take care of existing series_parts).
  • Some fixes and reworking of the Series Inline Edit capabilities within the inline-edit on edit.php?post-type=post page.
  • multiple minor bug fixes.
Location:
organize-series/trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • organize-series/trunk/js/inline-series.js

    r311984 r335684  
    11jQuery(document).ready(function($) { 
    22    $("label.inline-edit-tags").remove(":contains('Series')"); 
    3     $('a.editinline').bind( 'click.series', function() { 
     3    $('a.editinline').live( 'click.series', function() { 
    44        var id, type, editRowData, rowData, series_check, series_part, series_text; 
    55        var r_id = inlineEditPost.getId(this); 
     
    2626            $('.post_series_select', editRowData).append('<option value="'+series_check+'" selected="selected">'+series_text+'</option>'); 
    2727             
    28             $('.series_part', editRowData).val(series_part); 
    29             var test3 = $('.series_post_id', editRowData).val(r_id) 
     28            if ( series_check == -1 ) series_check = 0; 
    3029             
     30            $('.series_part', editRowData).attr('name', 'series_part['+series_check+']').val(series_part); 
     31             
     32                     
    3133        } 
     34         
     35        $('select.post_series_select', editRowData).bind('change',function() { 
     36                new_id = $(this).val(); 
     37                $('.series_part').attr('name', 'series_part['+new_id+']').val(''); 
     38        }); 
    3239         
    3340        $('label.inline-edit-series', editRowData).before('<div id="hidden_series_id" class="hidden">'+series_check+'</div>'); 
  • organize-series/trunk/js/series.js

    r327433 r335684  
    11jQuery( function($) { 
    22    var myConfirm = function() { return '' !== $('#newseries').val(); }; 
     3     
    34    $('#jaxseries').prepend('<span id="ajaxseries"><input type="text" name="newseries" id="newseries" size="16" autocomplete="off"/><input type="button" name="Button" class="add:serieschecklist:jaxseries" id="seriesadd" value="' + seriesL10n.add + '" /><input type="hidden"/><input type="hidden"/><span id="howto">' + seriesL10n.how + '</span></span><span id="series-ajax-response"></span>') 
     5     
    46    $('#serieschecklist').wpList( { alt: '', response: 'series-ajax-response', confirm: myConfirm } ); 
    57     
    6     $('#seriesadd').click(function() { 
     8     
     9    $('#seriesadd').click( function() { 
    710        $('input','#serieschecklist').removeAttr('checked'); 
    811    }); 
     12     
     13    $('#seriesadd').mouseup( function() { 
     14        setTimeout( function() { 
     15            var new_id = $('input:checked', '#serieschecklist').val(); 
     16            if ( new_id != null ) 
     17                $('#series_part').attr('name', 'series_part['+new_id+']') 
     18        }, 1000); 
     19    }); 
     20     
     21    $('input[name|="post_series"]').click(function() { 
     22        var ser_id = $(this).attr('id').replace('in-series-', ''); 
     23        $('#series_part').attr('name', 'series_part['+ser_id+']') 
     24    }); 
     25     
    926} ); 
  • organize-series/trunk/orgSeries-admin.php

    r327433 r335684  
    1818 
    1919##ADMIN-Write/Edit Post Script loader 
    20 add_action('admin_print_scripts','orgSeries_admin_script');  
     20//add_action('admin_print_scripts','orgSeries_admin_script');  
     21add_action('admin_print_scripts-post.php', 'orgSeries_post_script'); 
     22add_action('admin_print_scripts-post-new.php', 'orgSeries_post_script'); 
     23add_action('admin_print_scripts-edit-tags.php', 'orgSeries_manage_script'); 
    2124 
    2225//add ajax for on-the-fly series adds 
    2326add_action('wp_ajax_add-series', 'admin_ajax_series'); 
    24 add_action('wp_ajax_inline-series', 'admin_inline_series_ajax'); 
     27//add_action('wp_ajax_inline-series', 'admin_inline_series_ajax'); 
    2528 
    2629//hook into the quick-edit on edit.php 
     
    4750 
    4851//add_action filter for the manage_series page... 
     52 
     53function orgSeries_post_script() { 
     54    wp_enqueue_script('ajaxseries'); 
     55} 
    4956function orgSeries_admin_script() { 
    5057//load in the series.js script and set localization variables. 
     
    8592        'what' => 'series', 
    8693        'id' => $series_id, 
    87         'data' => "<li id='series-$series_id'><label for='in-series-$series_id' class='selectit'><input value='$series_id' type='radio' name='post_series' id='in-series-$series_id' checked /> $series_name</label></li>" 
     94        'data' => "<li id='series-$series_id'><label for='in-series-$series_id' class='selectit'><input value='$series_id' type='radio' name='post_series' id='in-series-$series_id' checked /> $series_name</label><span id='new_series_id' class='hidden'>$series_id</span></li>", 
     95        'position' => -1 
    8896    ) ); 
    8997    $x->send(); 
     
    93101function admin_inline_series_ajax() { 
    94102    check_ajax_referer ( 'inlineeditnonce', '_inline_edit' ); 
    95     $series_id = $_POST['post_series']; 
     103    $data[$seriesid] = $_POST['post_series']; 
     104    $data[$series_part] = $_POST['series_part']; 
     105    $data[$id] = $_POST['series_post_id']; 
     106    /*$series_id = $_POST['post_series']; 
    96107    $part = $_POST['series_part']; 
    97     $post_id = $_POST['series_post_id']; 
    98     orgseries_custom_column_action('series', $post_id); 
     108    $post_id = $_POST['series_post_id'];*/ 
     109    orgSeries_custom_column_action('series', $data[$id]); 
    99110    exit; 
    100111    break; 
     
    183194global $post, $postdata, $content, $orgseries; 
    184195    $id = isset($post) ? $post->ID : $postdata->ID; 
     196    $ser_id = wp_get_post_series( $id ); 
    185197    ?> 
    186198    <p id="jaxseries"></p> 
     
    189201                <?php get_series_to_select(); ?> 
    190202        </ul> 
    191         <span id="seriespart"><strong> <?php _e('Series Part:', $orgseries->org_domain); ?>   </strong><input type="text" name="series_part" id="series_part" size="5" value="<?php echo get_post_meta($id, SERIES_PART_KEY, true); ?>" /></span> 
     203        <span id="seriespart"><strong> <?php _e('Series Part:', $orgseries->org_domain); ?>   </strong><input type="text" name="series_part[<?php echo $ser_id[0]; ?>]" id="series_part" size="5" value="<?php echo get_post_meta($id, SERIES_PART_KEY, true); ?>" /></span> 
    192204            <p id="part-description"><?php _e('Note: that if you leave this blank or enter an invalid number the post will automatically be appended to the rest of the posts in the series', $orgseries->org_domain); ?></p> 
    193205    <?php 
     
    209221 
    210222function orgSeries_custom_column_action($column_name, $id) { 
    211     global $wpdb, $orgseries; 
     223    global $orgseries; 
    212224    $seriesid = null; 
    213225    $series_part = null; 
    214226    $series_name = null; 
     227     
    215228    if ($column_name == 'series') { 
    216         if ( $series = get_the_series($id) ) { 
     229        if ( $series = get_the_series($id, false) ) { 
    217230            $seriesid = $series[0]->term_id; 
    218231            $series_name = $series[0]->name; 
  • organize-series/trunk/orgSeries-manage.php

    r296330 r335684  
    3131    return $output; 
    3232} 
     33 
    3334function add_series_form_fields($taxonomy) { 
    3435    global $orgseries; 
  • organize-series/trunk/orgSeries-rss.php

    r309484 r335684  
    1313    //check for series_id and attempt to find it if possible 
    1414    if ( $series_id == '' ) { 
    15         $series = get_the_series(); 
    16         if (!empty($series) ) { 
    17             foreach ($series as $ser) { 
    18                 $series_id = $ser->term_id; 
    19             } 
    20         } 
     15        $series = get_query_var(SERIES_QUERYVAR); 
    2116    } 
    2217     
  • organize-series/trunk/orgSeries-setup.php

    r329963 r335684  
    1313 
    1414    var $settings; 
    15     var $version = '2.2.9'; 
     15    var $version = ORG_SERIES_VERSION; 
    1616    var $org_domain = 'organize-series'; 
    1717     
     
    8080            $old_version = $old_oldversion; 
    8181        } 
    82                  
    83         if ( !empty( $old_version ) ) { //register the current version of orgSeries 
     82         
     83        if ( !empty( $old_version ) ) { //register the current version of orgSeries and check if any updates. 
    8484            if ( $oldversion != $this->version ) { 
    8585                $this->update($oldversion); 
     
    109109    //function for all updates 
    110110    function update($version) { 
     111        global $wpdb; 
    111112        //upgrading from 2.2 
    112113        if ( $version == '2.2'  || $version < '2.2') { 
     
    127128            update_option('org_series_options', $settings); 
    128129        } 
     130         
     131        //upgrading for versions before 2.3. We're updating the series_part meta key to the new format for all posts that are a part of a series. 
     132        if ( $version < '2.3' ) { 
     133            $query = "SELECT p.ID, pm.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON p.ID = pm.post_id LEFT JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id LEFT JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id LEFT JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE pm.meta_key = 'series_part' AND tt.taxonomy = 'series'"; 
     134            $posts = $wpdb->get_results($query); 
     135             
     136            //let's cycle through the posts and update the meta_keys to the new format. 
     137            if ( empty($posts) ) return; //get out there's no posts to update. 
     138            foreach ($posts as $post) { 
     139                $meta_key = SERIES_PART_KEY; 
     140                $meta_value = $post->meta_value; 
     141                add_post_meta($post->ID, $meta_key, $meta_value); 
     142            } 
     143             
     144            //let's take this opportunity to do some database cleanup.  We need to delete any post that has the SERIES_PART_KEY meta_key including those that are actually not part of a series (from some legacy bugs). 
     145            $query = "SELECT p.ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON p.ID = pm.post_id LEFT JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id LEFT JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id LEFT JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE pm.meta_key = 'series_part'"; 
     146            $posts = $wpdb->get_results($query); 
     147             
     148            //now let's delete the meta_key/value combo from those posts 
     149            if ( empty($posts) ) return; //not posts, let's get out and save the environment (sic). 
     150            foreach ($posts as $post) { 
     151                $meta_key = 'series_part'; 
     152                delete_post_meta($post->ID, $meta_key); 
     153            } 
     154        } 
     155        return; 
    129156    } 
    130157     
    131158    function register_scripts() { 
    132         global $wp_rewrite; 
    133159        $url = WP_PLUGIN_URL.'/'.SERIES_DIR.'/js/'; 
    134160        wp_register_script('inline-edit-series',$url.'inline-series.js');   
     
    354380     
    355381    function sort_series_page_join($join) { 
    356         global $wpdb, $wp_query; 
     382        global $wp_query, $wpdb; 
    357383        if (!is_series() || ( is_series() && is_feed() ) || !empty($wp_query->request) ) return $join; 
    358         $join .= " LEFT JOIN $wpdb->postmeta orgmeta ON($wpdb->posts.ID = orgmeta.post_id) "; 
     384        $os_join = " LEFT JOIN $wpdb->postmeta orgmeta ON($wpdb->posts.ID = orgmeta.post_id) "; 
     385        $join .= apply_filters('orgseries_sort_series_page_join', $os_join); 
    359386        return $join; 
    360387    } 
    361388 
    362389    function sort_series_page_where($where) { 
    363         global $wpdb, $wp_query; 
     390        global $wp_query, $wpdb; 
    364391        if (!is_series() || ( is_series() && is_feed() ) || !empty($wp_query->request) ) return $where; 
    365392        $part_key = SERIES_PART_KEY; 
    366         $where .= " AND orgmeta.meta_key = '$part_key' "; 
     393        $os_where = " AND orgmeta.meta_key = '$part_key' "; 
     394        $where .= apply_filters('orgseries_sort_series_page_where', $os_where); 
    367395        return $where; 
    368396    } 
    369397 
    370398    function sort_series_page_orderby($ordering) { 
    371         global $wp_query; 
     399        global $wp_query, $wpdb; 
    372400        if (!is_series() || ( is_series() && is_feed() ) || !empty($wp_query->request) ) return $ordering; 
    373401        $settings = $this->settings; 
     
    379407        if (!isset($order)) $order = "DESC"; 
    380408        $ordering = " $orderby $order "; 
    381         return $ordering;    
     409        return apply_filters('orgseries_sort_series_page_orderby', $ordering) 
    382410    } 
    383411     
     
    432460    }    
    433461     
    434     //add series navigation strip to posts taht are part of a series (on single.php view) 
     462    //add series navigation strip to posts that are part of a series (on single.php view) 
    435463    function series_nav_filter($content) { 
    436464        if (is_single()) { 
  • organize-series/trunk/orgSeries-taxonomy.php

    r316150 r335684  
    88 * get_the_series() - calls up all the series info from the taxonomy tables (for a particular post). 
    99*/   
    10 function get_the_series( $id = false ) {  
     10function get_the_series( $id = false, $cache = true ) {  
    1111    global $post, $term_cache; 
    1212     
     
    1919        return false; 
    2020     
    21     $series = get_object_term_cache($id, 'series'); 
     21    $series = $cache ? get_object_term_cache($id, 'series') : false; 
    2222     
    2323    if (false === $series ) 
     
    7272 //will have to add the following function for deleting the series relationship when a post is deleted. 
    7373function delete_series_post_relationship($postid) { 
    74     wp_delete_object_term_relationships($postid, 'series'); 
    75 } 
    76  
    77 //call up series post is associated with -- needed for the post-edit panel specificaly. 
     74    $id = (int) $postid; 
     75    $series = get_the_series($id); 
     76     
     77    if ( !empty($series) ) {  //let's not waste any cycles 
     78        foreach ( $series as $ser ) { 
     79            wp_reset_series_order_meta_cache($id, $ser->term_id); 
     80        } 
     81        return wp_delete_object_term_relationships($id, array('series')); 
     82    } 
     83    return; 
     84} 
     85 
     86//call up series post is associated with -- needed for the post-edit panel specifically. 
    7887function wp_get_post_series( $post_id = 0, $args = array() ) { 
    7988    $post_id = (int) $post_id; 
     
    8998    $post_ids_in_series = get_objects_in_term($series_id, 'series'); 
    9099    $series_posts = array();  
    91     $series_posts = get_series_order($post_ids_in_series, $postid, true, false);  
     100    $series_posts = get_series_order($post_ids_in_series, $postid, $series_id, true, false);  
    92101    $total_posts = count($series_posts) + 1; 
    93102     
     
    144153                    }            
    145154             
    146             delete_post_meta($spostid, SERIES_PART_KEY);  
    147             add_post_meta($spostid, SERIES_PART_KEY, $newpart); 
     155            $series_part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $series_id); 
     156            delete_post_meta($spostid, $series_part_key);  
     157            add_post_meta($spostid, $series_part_key, $newpart); 
    148158            $ticker++; 
    149159            $oldpart = $newpart; 
     
    152162        } 
    153163    } 
    154     delete_post_meta($postid, SERIES_PART_KEY); 
    155     add_post_meta($postid, SERIES_PART_KEY, $series_part); 
     164    $series_part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $series_id); 
     165    delete_post_meta($postid, $series_part_key); 
     166    add_post_meta($postid, $series_part_key, $series_part); 
    156167    return true; 
    157168} 
    158169 
    159170function wp_reset_series_order_meta_cache ($post_id = 0, $series_id = 0, $reset = FALSE) { 
    160          
     171     
    161172    if ( 0 == $series_id ) return false; //post is not a part of a series so no need to waste cycles. 
    162173     
     
    165176    $addvalue = 1; 
    166177     
    167     $series_posts = get_series_order($post_ids_in_series, $post_id, true, false); 
     178    $series_posts = get_series_order($post_ids_in_series, $post_id, $series_id, true, false); 
     179    $series_part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $series_id); 
    168180     
    169181    if ($reset) { 
     
    174186            $spost_id = $spost; 
    175187            } 
    176             delete_post_meta($spost_id, SERIES_PART_KEY); 
     188 
     189            delete_post_meta($spost_id, $series_part_key); 
    177190        } 
    178191        return true; 
     
    181194    foreach ($series_posts as $spost) { 
    182195        $newpart = $addvalue; 
    183         delete_post_meta($spost['id'], SERIES_PART_KEY); 
    184         add_post_meta($spost['id'], SERIES_PART_KEY, $newpart); 
     196        delete_post_meta($spost['id'], $series_part_key); 
     197        add_post_meta($spost['id'], $series_part_key, $newpart); 
    185198        $addvalue++; 
    186199    } 
     
    298311    if ( empty($series) && ! $r['hide_if_empty'] && !empty($show_option_none) ) { 
    299312        $show_option_none = apply_filters( 'list_series', $show_option_none ); 
    300         $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n"; 
     313        $output .= "\t<option value='0' selected='selected'>$show_option_none</option>\n"; 
    301314    } 
    302315 
     
    369382} 
    370383     
    371 function wp_set_post_series( $post_ID = 0, $post, $series_id = 0) { 
     384function wp_set_post_series( $post_ID = 0, $post, $series_id = array() ) { 
    372385    $post_series = null; 
    373386    //fix for the revisions feature in WP 2.6+  && bulk-edit stuff. 
     
    375388        return; 
    376389    } 
    377  
    378390    //echo $post->post_status; 
    379391    /*if ( $post->post_status == 'draft' || $post->post_status == 'pending' || $post->post_status == 'future' ) 
     
    382394    $old_series = wp_get_post_series($post_ID); 
    383395     
    384     if ( $series_id === 0 ) {  
    385         if (isset($_POST['post_series'])) $post_series = (int) $_POST['post_series']; 
    386         if (isset($_GET['post_series'])) $post_series = (int) $_GET['post_series']; 
     396    if ( empty($series_id) ) {  
     397        if (isset($_POST['post_series'])) $post_series = is_array($_POST['post_series']) ? $_POST['post_series'] : array($_POST['post_series']); 
     398        if (isset($_GET['post_series'])) $post_series = is_array($_GET['post_series']) ? $_GET['post_series'] : array($_GET['post_series']); 
    387399     } else { 
    388         $post_series = (int) $series_id; 
    389     } 
    390      
    391     $s_part = (int) wp_series_part($post_ID); 
     400        $post_series = is_array($series_id) ? $series_id : array($series_id); 
     401    } 
     402     
     403    $post_series = os_strarr_to_intarr($post_series); 
     404    if ( empty($post_series) || (count($post_series) >= count($old_series)) ) { 
     405        $match = false;  
     406    } else { 
     407        $match = array_diff($old_series, $post_series); 
     408    } 
     409     
     410    /*var_dump($match); 
     411    exit;/**/ 
     412     
     413    if (empty($post_series) || ( count($post_series) == 1 && $post_series[0] == 0 ) ) $post_series = array(); 
     414     
     415    /*print_r($post_series); 
     416    print_r($old_series); 
     417    print_r($match); 
     418    exit;/**/ //for test of values in quick edit 
    392419     
    393420    if ( isset($_POST) || isset($_GET)) { 
    394         if ( isset($_POST['series_part']) ) $series_part = (int) $_POST['series_part']; 
    395         if ( isset($_GET['series_part']) ) $series_part = (int) $_GET['series_part']; 
     421        if ( isset($_POST['series_part']) ) $series_part = is_array($_POST['series_part']) ? $_POST['series_part'] : array($_POST['series_part']); 
     422        if ( isset($_GET['series_part']) ) $series_part = is_array($_GET['series_part']) ? $_GET['series_part'] : array($_GET['series_part']); 
    396423         
    397424        /*if ( $update_count_forward ) 
    398425            wp_update_term_count( $post_series, 'series', false);//*/ 
    399426             
    400         if ( (in_array($post_series, $old_series)) && $series_part == $s_part && $series_part != 0 && $post->post_status == 'publish') return; //get out of here if there's no change in series part!! 
     427    /*print_r($series_part); 
     428    exit;/**/ 
     429        //if we don't have any changes in the series or series part info then let's get out and save time. 
     430        $count = count($post_series); 
     431        $c_chk = 0; 
     432        foreach ( $post_series as $ser ) { 
     433            if (in_array($ser, $old_series) && $series_part[$ser] == wp_series_part($post_ID, $ser) ) { 
     434                $c_chk++; 
     435                continue; 
     436            } else { 
     437                $p_ser_edit[] = $ser; //these are the series we need to set the parts for (leave the rest alone when we get to this section). 
     438            } 
     439        } 
     440                 
     441        /*print_r($count); 
     442        print_r(' AND '); 
     443        print_r($c_chk); 
     444        exit; /**/ 
     445        if ( $c_chk == $count && !empty($post_series) && count($post_series) == count($old_series) ) return;  //there are no changes so let's just skip the rest 
     446         
     447    } 
    401448      
    402      } else { 
    403         if ( $s_part ) 
    404             $series_part = $s_part; 
    405         else 
    406             $series_part = 0; 
    407     } 
    408      
    409     if ( ( $old_series != '' || !empty($old_series) ) && ( $post_series == '' || 0 == $post_series  ) ) 
    410         return wp_delete_post_series_relationship($post_ID); 
    411      
    412      
    413     if ( $old_series != '' && ($post_series == '' || 0 == $post_series) ) $post_series = (int) $old_series[0]; //this takes care of future posts being published.  Need to set the $post_series variable - but ONLY if the post was associated with a series. 
    414      
    415     $match = in_array($post_series, $old_series); 
    416      
    417     if ( !$match && $old_series[0] != 0 ) { 
    418         $old_series = (int) $old_series[0]; 
    419         wp_reset_series_order_meta_cache($post_ID, $old_series); 
     449     
     450    if ( empty($post_series) ) { 
     451        foreach ( $old_series as $o_ser ) { 
     452            $part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $o_ser); 
     453            delete_post_meta( $post_ID, $part_key); 
     454        } 
     455    } 
     456     
     457    foreach ( $old_series as $os_id ) { 
     458        if ( !in_array($os_id, $post_series) ) { 
     459            /*print_r('made it here'); 
     460            print_r($os_id); 
     461            /**/ 
     462            wp_delete_post_series_relationship($post_ID, $os_id); 
     463            } 
     464    } 
     465     
     466         
     467    if ( !empty($match) && $match ) { 
     468        foreach ($match as $part_reset_id) { 
     469            wp_reset_series_order_meta_cache($post_ID, $part_reset_id); 
     470        } 
    420471    } 
    421472     
    422473    $success = wp_set_object_terms($post_ID, $post_series, 'series'); 
    423474     
     475    if ( empty($p_ser_edit) ) return; //let's get out we've done everything we need to do. 
     476         
    424477    if ( $success ) { 
    425     return set_series_order($post_ID, $series_part, $post_series); 
     478        foreach ( $p_ser_edit as $ser_id ) { 
     479            if ( empty($series_part[$ser_id]) ) { 
     480                $s_pt = wp_series_part($post_ID, $ser_id); 
     481                if ( !$series_part ) $series_part = 0; 
     482            } else { 
     483                $s_pt = $series_part[$ser_id]; 
     484            } 
     485            /*print_r($s_pt); 
     486            exit;/**/ 
     487            set_series_order($post_ID, $s_pt, $ser_id); 
     488        } 
     489         
     490        return; 
    426491    } else { 
    427     return FALSE; 
    428     } 
    429 } 
    430  
    431 function wp_delete_post_series_relationship( $id ) { 
    432     global $wpdb, $wp_rewrite; 
     492        return FALSE; 
     493    } 
     494} 
     495 
     496function wp_delete_post_series_relationship( $id, $ser_id = 0 ) { 
    433497    $postid = (int) $id; 
    434     $series = get_the_series( $postid ); 
    435      
    436     if (!empty($series) ) { 
    437         $seriesid = $series[0]->term_id; 
    438         delete_post_meta($postid, SERIES_PART_KEY); 
    439         wp_delete_object_term_relationships($postid, array('series')); 
    440         return wp_reset_series_order_meta_cache($postid, $seriesid); 
     498     
     499    if (!empty($ser_id) ) { 
     500        $series_part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $ser_id); 
     501        delete_post_meta($postid, $series_part_key); 
     502        delete_series_object_relationship($postid, $ser_id); 
     503        return wp_reset_series_order_meta_cache($postid, $ser_id); 
    441504    } 
    442505    return false; 
     
    451514} 
    452515 
     516function delete_series_object_relationship( $object_id, $terms ) { 
     517    global $wpdb; 
     518     
     519    $object_id = (int) $object_id; 
     520     
     521    if ( !is_array($terms) ) 
     522        $terms = array($terms); 
     523     
     524    foreach ( $terms as $term ) { 
     525        $t_obj = term_exists($term, 'series'); 
     526        $t_ids[] = $t_obj->term_taxonomy_id; 
     527    } 
     528     
     529    $in_tt_ids = "'" . implode("', '", $t_ids) . "'"; 
     530    $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id) ); 
     531    wp_update_term_count($t_ids, 'series'); 
     532} 
     533 
    453534function get_series_to_edit ( $id ) { 
    454535    $series = get_orgserial( $id, OBJECT, 'edit' ); 
     
    481562function wp_delete_series($series_ID, $taxonomy_id) { 
    482563    global $wpdb; 
    483              
    484564    seriesicons_delete($series_ID); 
    485565    wp_reset_series_order_meta_cache('',$series_ID,TRUE); 
     
    570650add_action('draft_to_publish', 'wp_set_post_series_draft_transition', 10, 1); 
    571651add_action('pending_to_publish', 'wp_set_post_series_draft_transition', 10, 1); 
    572 add_action('delete_post','wp_delete_post_series_relationship',1); 
     652add_action('delete_post','delete_series_post_relationship',1); 
    573653 
    574654//hooking into insert_term, update_term and delete_term  
    575655add_action('created_series', 'wp_insert_series',1, 2); 
    576656add_action('edited_series', 'wp_update_series',1, 2); 
    577 add_action('delete_series', 'wp_delete_series', 1, 2); 
     657add_action('delete_series', 'wp_delete_series', 10, 2); 
    578658?> 
  • organize-series/trunk/orgSeries-template-tags.php

    r322485 r335684  
    3737        return false; 
    3838         
    39     if ( !isset($ser_ID) || $ser_ID == '' ) { 
     39    if (!empty($ser_ID) ) $ser_ID = is_array($ser_ID) ? $ser_ID : array($ser_ID); 
     40     
     41    if ( !isset($ser_ID) || empty($ser_ID) ) { 
    4042        $serarray = get_the_series(); 
    4143        if (!empty($serarray) ) { 
    4244            foreach ($serarray as $series) { 
    43                 $ser_ID = $series->term_id; 
     45                $ser_ID[] = $series->term_id; 
    4446            } 
    4547        } 
    4648    } 
     49 
    4750    $series_post = array(); 
    4851    $posts_in_series = array(); 
    4952    $settings = $orgseries->settings; 
    50     $series_post = get_objects_in_term($ser_ID, 'series');  
    51     $posts_in_series = get_series_order($series_post, 0, FALSE); 
    5253    $result = ''; 
    53      
    54     foreach($posts_in_series as $seriespost) {  
    55         if ($cur_id == $seriespost['id']) { 
     54    foreach ( $ser_ID as $ser ) { 
     55        $series_post = get_objects_in_term($ser, 'series');  
     56        $posts_in_series = get_series_order($series_post, 0, $ser, FALSE); 
     57        if ( 'widget' == $referral ) { 
     58            $result .= '<h4>' . __('Other posts belonging to the Series: ', $orgseries->org_domain) . get_series_name($ser) . '</h4>'; 
     59            $result .= '<ul>'; 
     60        } 
     61         
     62        foreach($posts_in_series as $seriespost) {  
     63            if ($cur_id == $seriespost['id']) { 
     64                if ( 'widget' == $referral ) 
     65                    $result .= '<li class="serieslist-current-li">' . series_post_title($seriespost['id']) . '</li>'; 
     66                else 
     67                    $result .= token_replace(stripslashes($settings['series_post_list_currentpost_template']), 'other', $seriespost['id'], $ser_ID); 
     68                continue; 
     69            } 
     70             
    5671            if ( 'widget' == $referral ) 
    57                 $result .= '<li class="serieslist-current-li">' . series_post_title($seriespost['id']) . '</li>'; 
     72                $result .= '<li>' . series_post_title($seriespost['id']) . '</li>'; 
    5873            else 
    59                 $result .= token_replace(stripslashes($settings['series_post_list_currentpost_template']), 'other', $seriespost['id'], $ser_ID); 
    60             continue; 
    61         } 
    62         if ( 'widget' == $referral ) 
    63             $result .= '<li>' . series_post_title($seriespost['id']) . '</li>'; 
    64         else 
    65             $result .= token_replace(stripslashes($settings['series_post_list_post_template']), 'other', $seriespost['id'], $ser_ID); 
    66     } 
     74                $result .= token_replace(stripslashes($settings['series_post_list_post_template']), 'other', $seriespost['id'], $ser_ID); 
     75        } 
     76         
     77        if ( 'widget' == $referral ) { 
     78            $result .= '</ul>'; 
     79        } 
     80    } 
     81     
    6782     
    6883    if ( !$display )  
     
    90105    $settings = $orgseries->settings; 
    91106    $serarray = get_the_series(); 
     107    $postlist = ''; 
     108    $count = count($serarray); 
     109    $i = 1; 
     110    $trigger = false; 
     111     
    92112        if (!empty($serarray)) { 
    93113            foreach ($serarray as $series) { 
    94114                $serID = $series->term_id; 
     115                $postlist .= token_replace(stripslashes($settings['series_post_list_template']), 'post-list', $serID); 
     116                if ( $i != $count || $trigger ) { 
     117                    $pos = strpos($postlist, '%postcontent%'); 
     118                    if ( $pos == 0 ) $trigger = true; 
     119                    $postlist = str_replace('%postcontent%', '', $postlist); 
     120                } 
     121                $i++; 
    95122            } 
    96         } 
    97     if (isset($serID)) { 
    98         $postlist = token_replace(stripslashes($settings['series_post_list_template']), 'post-list', $serID); 
    99         return $postlist; 
    100     } 
    101      
     123             
     124            if ($trigger) $postlist = '%postcontent%'.$postlist; 
     125            return $postlist; 
     126        } 
     127         
    102128    return false; 
    103129} 
     
    142168 * @since 2.0 
    143169 * 
    144  * @uses get_the_series() - checks if a post is part of a series and if it is it returns an array containing series data. 
    145170 * @uses get_orgserial - returns the series information for a single series (using the supplied series_id) 
    146171 * 
    147  * @param bool|int $ser_id - defaults to false. Int is the series id.   
     172 * @param bool|int $ser_id - defaults to false. int is the series id.  REQUIRED 
    148173 * 
    149174 * @return int $postlist_count - The number of posts in a series. 
    150175*/ 
    151176function wp_postlist_count($ser_id = false) {   
    152     if (!$ser_id) { 
    153         $series = get_the_series(); 
    154         if (!empty($series)) { 
    155             $postlist_count = $series[0]->count; 
    156         } else { 
    157             $postlist_count = 0; 
    158         } 
     177    if (!$ser_id) return false; //need the $ser_id to caculate the number of posts in the series. 
     178    $series = get_orgserial($ser_id); 
     179    if (!empty($series)) { 
     180        $postlist_count = $series->count; 
    159181    } else { 
    160         $series = get_orgserial($ser_id); 
    161         if (!empty($series)) { 
    162             $postlist_count = $series->count; 
    163         } else { 
    164             $postlist_count = 0; 
    165         } 
    166     }    
    167          
     182        $postlist_count = 0; 
     183    } 
    168184    return $postlist_count; 
    169185} 
     
    178194 * 
    179195 * @param int $id - The Post ID (defaults to 0) 
     196 * @param int $ser_id = The id of the series the post belongs to - REQUIRED 
    180197 * 
    181198 * @return int $series_part - The part the post is in a series IF it is part of a series. 
    182199*/ 
    183 function wp_series_part( $id = 0 ) {  
     200function wp_series_part( $id = 0, $ser_id = 0 ) {  
    184201    global $post; 
     202    print_r($id, $ser_id); 
    185203    if ( $id == 0 ) { 
    186204        if ( isset($post) ) 
     
    188206    } 
    189207     
    190     if ( $id == 0 ) 
     208    if ( $id == 0 || $ser_id == 0 ) 
    191209        return false; 
    192210     
    193211    $ser_post_id = $id; 
    194     $part_key = SERIES_PART_KEY; 
     212    $part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $ser_id); 
    195213    $series_part = get_post_meta($ser_post_id, $part_key, true); 
    196214    return $series_part; 
     
    214232    $settings = $orgseries->settings; 
    215233    $serarray = get_the_series(); 
     234    $series_meta = ''; 
     235    $count = count($serarray); 
     236    $i = 1; 
     237    $trigger = false; 
    216238    if (!empty($serarray) ) { 
    217239        foreach ($serarray as $series) { 
    218240        $serID = $series->term_id;  
    219         } 
    220     } 
    221      
    222     if ( $excerpt && isset($serID) ) { 
    223         $series_meta = token_replace(stripslashes($settings['series_meta_excerpt_template']), 'other', $post->ID, $serID); 
     241            if ( $excerpt ) { 
     242                $series_meta .= token_replace(stripslashes($settings['series_meta_excerpt_template']), 'other', $post->ID, $serID); 
     243            } else { 
     244                $series_meta .= token_replace(stripslashes($settings['series_meta_template']), 'other', 0, $serID); 
     245            } 
     246             
     247            if ( $i != $count || $trigger ) { 
     248                $pos = strpos($series_meta, '%postcontent%'); 
     249                if ( $pos == 0 ) $trigger = true; 
     250                $series_meta = str_replace('%postcontent%', '', $series_meta); 
     251            } 
     252            $i++; 
     253        } 
     254         
     255        if ($trigger) $series_meta = '%postcontent%'.$series_meta; 
    224256        return $series_meta; 
    225257    } 
    226258     
    227     if (isset($serID)) {  
    228         $series_meta = token_replace(stripslashes($settings['series_meta_template']), 'other', 0, $serID); 
    229         return $series_meta; 
    230     } 
    231259    return false; 
    232260} 
     
    298326 * @uses get_post_meta() - will get the current series part for the displayed post. 
    299327 * @uses get_option() - will get the template for series nav. 
    300  * @uses get_the_series() - will get the series data for the current post if $series_ID is not set. 
    301328 * @uses get_objects_in_term() - will get all the posts that belongs to the series the current post belongs to. 
    302329 * @uses get_series_order() - will take the list of posts and sort them by their order in the series. 
     
    304331 * @uses get_permalink() - permalink of a post 
    305332 *  
    306  * @param int $series_ID  
     333 * @param int $series_ID REQUIRED 
    307334 * @param bool $next  if TRUE will output the next post in the series.  if FALSE will output the previous post in the series. 
    308335 * @param bool $customtext if TRUE will output the custom text selected on the series options page for next or previous post rather than the titles of the posts. 
     
    313340function wp_series_nav($series_ID, $next = TRUE, $customtext = FALSE, $display = FALSE) { 
    314341    global $post, $orgseries; 
     342    if (empty($series_ID)) return false; //we can't do anything without the series_ID; 
    315343    $cur_id = $post->ID; 
    316     $cur_part = get_post_meta($cur_id, SERIES_PART_KEY, true); 
    317344    $settings = $orgseries->settings; 
    318345    $custom_next = $settings['series_nextpost_nav_custom_text']; 
    319346    $custom_prev = $settings['series_prevpost_nav_custom_text']; 
    320      
    321     if (!isset($series_ID)) { 
    322         $series = get_the_series(); 
    323         if (!empty($series) ) { 
    324             foreach ($series as $ser) { 
    325                 $series_ID = $ser->term_id;   
    326             } 
    327         } 
    328     } 
    329      
     347    $series_part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $series_ID); 
     348    $cur_part = get_post_meta($cur_id, $series_part_key, true); 
    330349    $series_posts = get_objects_in_term($series_ID, 'series'); 
    331350    $posts_in_series = array(); 
    332     $posts_in_series = get_series_order($series_posts, $cur_id); 
     351    $posts_in_series = get_series_order($series_posts, $cur_id, $series_ID); 
    333352    $result = ''; 
    334353     
     
    373392    $settings = $orgseries->settings; 
    374393    $series = get_the_series(); 
     394    $nav = ''; 
     395    $count = count($series); 
     396    $i = 1; 
     397    $trigger = false; 
    375398        if (!empty($series)) { 
    376399            foreach ($series as $ser) { 
    377400                $series_id = $ser->term_id; 
    378401                $series_count = $ser->count; 
     402                if ( $series_count > 1 ) { 
     403                    $nav .= token_replace(stripslashes($settings['series_post_nav_template']), 'other', $series_id); 
     404                    if ( $i != $count || $trigger ) { 
     405                        $pos = strpos($nav, '%postcontent%'); 
     406                        if ( $pos == 0 ) $trigger = true; //%postcontent% is at the top in the template so we need to erase all %postcontent% to fix. 
     407                        $nav = str_replace('%postcontent%', '', $nav); 
     408                    } 
     409                     
     410                    $i++; 
     411                } 
    379412            } 
    380         } 
    381         if ( isset($series_id) && $series_count > 1 ) { 
    382             $nav = token_replace(stripslashes($settings['series_post_nav_template']), 'other', $series_id); 
     413            if ($trigger) $nav = '%postcontent%'.$nav; 
    383414            return $nav; 
    384415        } 
  • organize-series/trunk/orgSeries-utility.php

    r316150 r335684  
    2525//This function is used to create an array of posts in a series including the order the posts are in the series.  Then it will sort the array so it is keyed in the order the posts are in.  Will return the array. 
    2626 
    27 function get_series_order($posts, $postid = 0, $skip = TRUE, $only_published = TRUE) { 
     27function get_series_order($posts, $postid = 0, $series_id = 0, $skip = TRUE, $only_published = TRUE) { 
    2828    if (!isset($posts)) return false; //don't have the posts array so can't do anything. 
    2929     
     
    4747    } 
    4848     
    49     $args = 'post_status=any&include='.$postids.'&meta_key='.SERIES_PART_KEY; 
     49    $args = 'post_status=any&include='.$postids; 
    5050    $posts = get_posts($args); 
    51     $meta_key = SERIES_PART_KEY; 
     51    $meta_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $series_id); 
    5252     
    5353    foreach ($posts as $spost) { 
     
    8989         } 
    9090    if ( 'series-toc' == $referral  || 'latest_series' == $referral ) { 
    91         $replace = str_replace('%total_posts_in_series%', wp_postlist_count($id), $replace); 
     91        $replace = str_replace('%total_posts_in_series%', wp_postlist_count($ser_id), $replace); 
    9292    } else { 
    93         $replace = str_replace('%total_posts_in_series%', wp_postlist_count(), $replace); 
     93        $replace = str_replace('%total_posts_in_series%', wp_postlist_count($ser_id), $replace); 
    9494    } 
    9595         
     
    109109    $replace = str_replace('%post_title_linked%', series_post_title($id), $replace); 
    110110    if( stristr($replace, '%series_part%') )  
    111     $replace = str_replace('%series_part%', wp_series_part($p_id), $replace); 
     111    $replace = str_replace('%series_part%', wp_series_part($p_id, $ser_id), $replace); 
    112112    if( stristr($replace, '%series_description%') )  
    113113    $replace = str_replace('%series_description%', series_description($id), $replace); 
     
    193193    } 
    194194} 
     195 
     196function os_strarr_to_intarr($array) { 
     197    if ( empty($array) ) return; 
     198    function this_to_int(&$val, $key) { 
     199        $val = (int) $val; 
     200    } 
     201     
     202    array_walk($array, 'this_to_int'); 
     203     
     204    return $array; 
     205} 
    195206?> 
  • organize-series/trunk/orgSeries-widgets.php

    r298200 r335684  
    128128            if ( ( $wp_query->is_single ) && $showpostlist && $series = get_the_series() ) { 
    129129                if ( $showseriestoc ) $out .= '<br /><br />'; 
    130                 $out .= '<h4>' . __('Other posts belonging to this series', $orgseries->org_domain) . '</h3>'; 
    131                 $out .= '<ul>' . get_series_posts('','widget') . '</ul>';   } 
     130                $out .= get_series_posts('','widget');   
     131                } 
    132132        } 
    133133         
  • organize-series/trunk/orgSeries.php

    r329963 r335684  
    1313//  can be found at http://www.unfoldingneurons.com/neurotic-plugins/organize-series-wordpress-plugin/ 
    1414 
    15  
     15$os_version = '2.3'; 
    1616###################################### 
    1717 
     
    7373  * This sets the constants for orgSeries 
    7474*/ 
     75define('ORG_SERIES_VERSION', $os_version); //the current version of the plugin 
    7576define('SERIES_DIR' , $org_dir_name); //the name of the directory that orgSeries files are located. 
    7677define('SERIES_LOC', $org_series_loc); //the uri of the orgSeries files. 
     
    7980define('SERIES_URL', 'series'); //URL tag to use when querying series archive pages. 
    8081define('SERIES_SEARCHURL','search'); //local search URL (from mod_rewrite_rules) 
    81 define('SERIES_PART_KEY', 'series_part'); //the default key for the Custom Field that distinguishes what part a post is in the series it belongs to. 
     82define('SERIES_PART_KEY', '_series_part'); //the default key for the Custom Field that distinguishes what part a post is in the series it belongs to. The underscore makes this hidden on edit post/page screens. 
    8283define('SERIES_REWRITERULES','1'); //flag to determine if plugin can change WP rewrite rules.    
    8384 
  • organize-series/trunk/uninstall.php

    r294302 r335684  
    1515    } 
    1616     
    17     $meta_key = 'series_part'; 
    18     $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key) ); 
     17    $meta_key = "'%series_part%'"; 
     18    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE %s", $meta_key) ); 
    1919    $table_name = $wpdb->prefix . "orgSeriesIcons"; 
    2020    $drop_query = "DROP TABLE ". $table_name; 
Note: See TracChangeset for help on using the changeset viewer.