Plugin Directory

Changeset 610483


Ignore:
Timestamp:
10/10/2012 07:41:08 PM (13 years ago)
Author:
jascott
Message:

Revised related post controls, API URL filter for post_format

Location:
kickpress/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kickpress/trunk/kickpress-functions.php

    r610458 r610483  
    231231    $defaults = @array_intersect_key( $kickpress_api->params, array(
    232232        'post_type'      => get_post_type(),
    233         'post_types'     => array(),
     233        'post_format'    => null,
    234234        'page'           => 0,
     235        'posts_per_page' => 10,
    235236        'action'         => '',
    236237        'action_key'     => null,
    237238        'view'           => '',
    238         'post_format'    => null,
    239         'posts_per_page' => 10,
    240239        'first_letter'   => '',
    241240        'search'         => is_search() ? $_GET['s'] : '',
     
    248247        'extra_pairs'    => array(),
    249248        'extra_slugs'    => array(),
     249       
     250        // What are these for?
     251        'post_types'     => array(),
    250252        'target'         => null
    251253    ) );
     
    342344        $api_slugs[] = $view;
    343345    }
     346   
     347    if ( ! empty( $post_format ) ) {
     348        $api_slugs[] = 'post_format';
     349        $api_slugs[] = $post_format;
     350    }
    344351
    345352    if ( ! empty( $posts_per_page ) ) {
     
    481488    if ( $log = @fopen( $file, 'a' ) ) {
    482489        $line = sprintf(
    483             "%s\t%s\t%s",
    484             date( 'c' ),
     490            "%s.%3d %s\t%s\t%s",
     491            date( 'Y-m-d H:i:s' ),
     492            fmod( microtime( true ), 1 ) * 1000,
     493            date( 'P' ),
    485494            KICKPRESS_DEBUG_TOKEN,
    486495            $data
  • kickpress/trunk/kickpress-query-filters.php

    r610150 r610483  
    197197                    );
    198198                }
    199             }
     199               
     200                if ( isset( $kickpress_api->params['post_format'] ) ) {
     201                    $post_format = $kickpress_api->params['post_format'];
     202                   
     203                    $tax_query[] = array(
     204                        'taxonomy' => 'post_format',
     205                        'operator' => 'in',
     206                        'field'    => 'slug',
     207                        'terms'    => explode( ',', $post_format )
     208                    );
     209                }
     210            }
     211           
     212            $query->query_vars['tax_query'] = $tax_query;
     213            $query->is_archive = true;
     214        } elseif ( isset( $kickpress_api->params['post_format'] ) ) {
     215            $post_format = $kickpress_api->params['post_format'];
     216           
     217            $tax_query = array( 'relation' => 'AND' );
     218           
     219            $tax_query[] = array(
     220                'taxonomy' => 'post_format',
     221                'operator' => 'in',
     222                'field'    => 'slug',
     223                'terms'    => explode( ',', $post_format )
     224            );
    200225           
    201226            $query->query_vars['tax_query'] = $tax_query;
  • kickpress/trunk/kickpress-relationships.php

    r610458 r610483  
    214214    $ids = $wpdb->get_col( $sql );
    215215   
    216     $posts = get_posts( array(
     216    if ( empty( $ids ) )
     217        return array();
     218   
     219    return get_posts( array(
    217220        'post__in'  => $ids,
    218221        'post_type' => $object_type
    219222    ) );
    220    
    221     /* $meta_key = '_kickpress_rel[' . $rel->slug . ']';
    222    
    223     $is_source = $post->post_type == $rel->source_type;
    224    
    225     $posts = array();
    226    
    227     if ( $is_source ) {
    228         $posts = get_posts( array(
    229             'post_type'  => $rel->target_type,
    230             'meta_key'   => $meta_key,
    231             'meta_value' => $post->ID
    232         ) );
    233     } else {
    234         $meta = array_unique( get_post_meta( $post->ID, $meta_key, false ) );
    235        
    236         foreach ( $meta as $rel_post_id ) {
    237             $rel_post = get_post( $rel_post_id );
    238            
    239             if ( $rel->source_type != $rel_post->post_type ) continue;
    240             // if ( 'publish' != $rel_post->post_status ) continue;
    241            
    242             $posts[] = $rel_post;
    243         }
    244     } */
    245    
    246     return $posts;
    247223}
    248224
     
    286262    $rel = kickpress_get_relationship( $rel_name );
    287263   
    288     $meta_key = '_kickpress_rel[' . $rel->slug . ']';
    289    
    290264    if ( $rel->source_type == $post->post_type && $rel->target_type == $rel_post->post_type ) {
    291265        $src_post = $post;
     
    297271   
    298272    $wpdb->delete( $wpdb->prefix . 'kp_post_relationships', array(
    299         'source_id' => $src_post->ID,
    300         'target_id' => $tgt_post->ID,
     273        'source_id'    => $src_post->ID,
     274        'target_id'    => $tgt_post->ID,
    301275        'relationship' => $rel_name
    302276    ) );
    303    
    304     // delete_post_meta( $tgt_post->ID, $meta_key, $src_post->ID );
    305277}
    306278
     
    313285   
    314286    $object_type = get_post_type();
     287
     288    header( 'Content-type: text/plain' );
    315289
    316290    foreach ( $kickpress_relationships as $rel ) {
     
    322296           
    323297            foreach ( (array) $old_posts as $old_post ) {
    324                 // if ( ! in_array( $old_post->ID, $new_posts ) )
    325                 kickpress_remove_related_post( $post_id, $rel->name, $old_post );
     298                if ( ! in_array( $old_post->ID, $new_posts ) )
     299                    kickpress_remove_related_post( $post_id,
     300                        $rel->name, $old_post );
    326301            }
    327302           
    328303            foreach ( (array) $new_posts as $new_post ) {
    329                 kickpress_add_related_post( $post_id, $rel->name, $new_post );
     304                if ( 0 < intval( $new_post ) )
     305                    kickpress_add_related_post( $post_id,
     306                        $rel->name, intval( $new_post ) );
    330307            }
    331308        }
     
    372349?>
    373350<style type="text/css">
    374     /* .rel-post-search {
    375         position: relative;
    376     }
    377    
    378     .ajax-post-search {
     351    .rel-post-search {
     352        margin: 1em 0em;
     353    }
     354   
     355    /* .ajax-post-search {
    379356        position: absolute;
    380357        z-index: 100;
     
    413390</style>
    414391<script type="text/javascript">
     392    var is_rel_search = false;
     393   
    415394    jQuery(document).ready(function($) {
     395        $('#post').bind('submit', function(event) {
     396            if (is_rel_search) {
     397                $('#' + is_rel_search).siblings('.button').click();
     398               
     399                $('#publish').removeClass('button-primary-disabled');
     400                $('#ajax-loading').css('visibility', 'hidden');
     401               
     402                return false;
     403            }
     404        });
     405       
     406        $('.rel-post-title').each(function(index, item) {
     407            $(item).bind('focus', function(event) {
     408                is_rel_search = $(item).attr('id');
     409            });
     410           
     411            $(item).bind('blur', function(event) {
     412                is_rel_search = false;
     413            });
     414        });
     415       
    416416        $('div.relationship a.hide-if-no-js').each(function(index, item) {
    417417            $(item).click(function(event) {
    418418                $(this).hide();
    419                 $(this).parents('.relationship').children('.related-posts').hide('blind', null, 'fast');
     419                //$(this).parents('.relationship').children('.related-posts').hide('blind', null, 'fast');
    420420               
    421421                var div = $(this.href.match(/#[a-z\-]+/)[0]);
    422422               
    423423                div.show('blind', null, 'fast');
     424               
     425                div.children('.rel-post-title').focus();
    424426               
    425427                return false;
     
    442444                var resbox = $(this).siblings('.ajax-post-search').first();
    443445               
     446                resbox.html('<ul><li style="font-style: italic;">Loading...</li></ul>');
     447               
    444448                jQuery.post(ajaxurl, args, function(response) {
    445449                    resbox.html(response);
     
    457461               
    458462                $(this).parents('.relationship').children('a.hide-if-no-js').show();
     463                $(this).parents('.rel-post-search').children('.rel-post-title').val('');
    459464                $(this).parents('.rel-post-search').children('.ajax-post-search').empty();
    460465               
     
    492497            }).append(input).append(label));
    493498           
    494             form.hide('blind', null, 'fast');
    495             list.show('blind', null, 'fast');
    496            
    497             $(this).parents('.relationship').children('a.hide-if-no-js').show();
    498             $(this).parents('.rel-post-search').children('.ajax-post-search').empty();
     499            $(this).parents('li').first().remove();
    499500           
    500501            return false;
     
    550551?>
    551552<div class="relationship">
    552     <a href="#rel-post-search-<?php echo $name; ?>" class="hide-if-no-js" style="float: right;">Edit</a>
    553     <h4><?php echo $rel->label; ?></h4>
     553    <a href="#rel-post-search-<?php echo $name; ?>" class="hide-if-no-js" style="float: right;">Search</a>
     554    <h4><?php echo $rel->label; ?><br><small><?php echo $rel->object_type; ?></small></h4>
    554555    <div id="rel-post-search-<?php echo $name; ?>"  class="rel-post-search hide-if-js">
    555556        <label><?php echo $type->labels->search_items; ?>:</label><br>
    556         <input type="text" name="rel_post_title[<?php echo $name; ?>]" class="rel-post-title" style="display: block; width: 95%;">
     557        <input type="text" name="rel_post_title[<?php echo $name; ?>]" id="rel-post-title-<?php echo $name; ?>" class="rel-post-title" style="display: block; width: 95%;">
    557558        <input type="hidden" name="rel_post_type[<?php echo $name; ?>]" value="<?php echo $rel->object_type; ?>" class="rel-post-type">
    558559        <input type="hidden" name="rel_post_qty[<?php echo $name; ?>]" value="<?php echo $rel->object_qty; ?>" class="rel-post-qty">
    559560        <input type="button" value="Search" class="button">
    560         <a href="#" class="cancel">Cancel</a>
     561        <a href="#" class="cancel">Close</a>
    561562        <div id="ajax-post-search-<?php echo $name; ?>" class="ajax-post-search"></div>
    562563    </div>
    563564    <div id="related-posts-<?php echo $name; ?>" class="related-posts">
     565        <input type="hidden" name="rel_posts[<?php echo $name; ?>][]">
    564566        <?php if ( ! empty( $rel_posts ) ) : ?>
    565567        <?php if ( 'multiple' == $rel->object_qty ) : foreach ( $rel_posts as $rel_post ) :
     
    583585        <?php else : ?>
    584586        <span class="empty">none</span>
    585     <?php endif; ?>
     587        <?php endif; ?>
    586588    </div>
    587589</div>
     
    617619<ul>
    618620    <?php while ( have_posts() ) : the_post(); ?>
    619     <li><a rel="<?php the_ID(); ?>" href="#" class="rel-post-search-result <?php echo $_REQUEST['post_qty']; ?>"><?php the_title(); ?></a></li>
     621    <li>+ <a rel="<?php the_ID(); ?>" href="#" class="rel-post-search-result <?php echo $_REQUEST['post_qty']; ?>"><?php the_title(); ?></a></li>
    620622    <?php endwhile; ?>
    621623</ul>
Note: See TracChangeset for help on using the changeset viewer.