Plugin Directory

Changeset 588972


Ignore:
Timestamp:
08/22/2012 07:15:40 PM (13 years ago)
Author:
jascott
Message:

More magic dust, related-post and post-term elements are now working

Location:
kickpress/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kickpress/trunk/elements/class-related-posts.php

    r583867 r588972  
    44    public function input( $params ) {
    55        extract( $params, EXTR_SKIP );
     6       
     7        $params['name'] = $name = sprintf(
     8            'data[%s][%d][rel_input][%s][]',
     9            $post_type,
     10            $post_id,
     11            $relationship
     12        );
    613       
    714        $rel = kickpress_get_relationship( $relationship );
     
    1118       
    1219        $posts = kickpress_get_related_posts( $post_id, $relationship );
    13        
    14         $params['name'] = $name = sprintf(
    15             'rel_post[%s][%d][%s][]',
    16             $post_type,
    17             $post_id,
    18             $relationship
    19         );
    2020       
    2121        $conf = esc_attr( __( 'Are you sure you want to remove this post?' ) );
     
    2929        ) );
    3030       
    31         $html .= '<ul id="' . $id . '_list" class="ajax_search_list">';
     31        $html .= self::_html_input( 'hidden', $name, '0' );
    3232       
    33         foreach ( $posts as $post ) {
    34             $input  = self::_html_input( 'hidden', $name, $post->ID );
    35             $input .= self::_html_label( $post->post_title );
    36             $input .= self::_html_tag( 'a', 'X', array(
    37                 'href' => '#',
    38                 'rel'  => $post->ID
     33        $html .= '<ul id="' . $relationship . '_list" class="ajax_search_list">';
     34       
     35        foreach ( (array) $posts as $post ) {
     36            $input  = self::_html_input( 'checkbox', $name, $post->ID, array(
     37                'id' => $relationship . '_list_' . $post->ID,
     38                'checked' => true
     39            ) ) . self::_html_label( $post->post_title, array(
     40                'for' => $relationship . '_list_' . $post->ID
    3941            ) );
    4042           
    41             $html .= self::_html_tag( 'li', $input, array(
    42                 'id' => $id . '-' . $post->ID
     43            $html .= self::_html_tag( 'li', $input );
     44        }
     45       
     46        if ( empty( $posts ) ) {
     47            $html .= self::_html_tag( 'li', 'none', array(
     48                'class' => 'empty'
    4349            ) );
    4450        }
     
    4753       
    4854        $html .= self::_html_input( 'text', null, null, array(
    49             'id'    => $id,
     55            'id'    => $relationship,
    5056            'class' => 'ajax_search_input'
    5157        ) );
     
    6268       
    6369        $search = self::_html_tag( 'div', '&nbsp;', array(
    64             'id'    => $id . '_result',
     70            'id'    => $relationship . '_result',
    6571            'class' => 'ajax_search_result'
    6672        ) );
    6773       
    6874        $html .= self::_html_tag( 'div', $cancel . $search, array(
    69             'id'    => $id . '_window',
     75            'id'    => $relationship . '_window',
    7076            'class' => 'ajax_search_window'
    7177        ) );
  • kickpress/trunk/includes/js/kickpress-ajax-search.js

    r583190 r588972  
    11jQuery(document).ready(function($) {
    22    $('.ajax_search_window')
    3     .css('position', 'absolute')
    4     .css('visibility', 'hidden');
     3        .css('position', 'absolute')
     4        .css('visibility', 'hidden');
    55   
    6     $('.ajax_search_input').keyup(function() {
     6    $('.ajax_search_input').on('keyup', function(e) {
    77        var search = $(this).val();
    88       
     
    2323    });
    2424   
    25     $('.ajax_search_list a').live('click', function() {
     25    $('.ajax_search_list a').on('click', function(e) {
    2626        var ajax_list = $(this).parents('.ajax_search_list');
    2727        var conf = ajax_list.siblings('.ajax_search_conf').val();
     
    3030            $(this).parent().remove();
    3131       
     32        e.preventDefault();
    3233        return false;
    3334    });
    3435   
    35     $('.ajax_search_window a').live('click', function() {
    36         var id = this.rel;
     36    $('.ajax_search_window a').live('click', function(e) {
     37        var ajax_window = $(this).parents('.ajax_search_window');
    3738       
    38         var ajax_window = $(this).parents('.ajax_search_window');
    39          
    40         if (0 < id) {
    41             var name = ajax_window.siblings('.ajax_search_name').val();
    42            
    43             ajax_window.siblings('.ajax_search_list').append(
    44                 $('<li>').append($('<input>', {
    45                     type: 'hidden',
    46                     name: name,
    47                     value: id
    48                 }))
    49                 .append($('<label>').text($(this).text()))
    50                 .append($('<a>', {
    51                     href: '#',
    52                     rel:  id
    53                 }).text('X'))
    54             );
     39        if ($(this).hasClass('ajax_search_cancel')) {
     40            ajax_window.css('visibility', 'hidden');
     41        } else {
     42            var post_id = this.rel;
     43             
     44            if (0 < post_id) {
     45                var ajax_list = ajax_window.siblings('.ajax_search_list');
     46       
     47                var input_id = ajax_list.attr('id') + '_' + post_id;
     48                var input_name = ajax_window.siblings('.ajax_search_name').val();
     49               
     50                ajax_list.append(
     51                    $('<li>').append($('<input>', {
     52                        'id':    input_id,
     53                        'type':  'checkbox',
     54                        'name':  input_name,
     55                        'value': post_id,
     56                        'checked' : 'checked'
     57                    })).append($('<label>', {
     58                        'for': input_id
     59                    }).text($(this).text()))
     60                ).children('.empty').remove();
     61            }
    5562        }
    5663       
    5764        ajax_window.css('visibility', 'hidden');
    5865       
     66        e.preventDefault();
    5967        return false;
    6068    });
  • kickpress/trunk/kickpress-api.php

    r587972 r588972  
    193193            'single'  => true,
    194194            'hidden'  => true
     195        ),
     196        'tax' => array(
     197            'label'   => 'Taxonomy',
     198            'slug'    => 'tax',
     199            'aliases' => array(),
     200            'order'   => 0,
     201            'single'  => true,
     202            'hidden'  => true
    195203        )
    196204    );
     
    205213
    206214        $this->params = array_merge($default_params, $params);
    207 
     215       
    208216        if ( isset($kickpress_post_types[$this->params['post_type']]['post_type_id']) ) {
    209217            $meta_type = get_post_meta($kickpress_post_types[$this->params['post_type']]['post_type_id'], '_meta_type', true);
     
    268276            require_once(WP_PLUGIN_DIR.'/kickpress/kickpress-validation.php');
    269277            $this->validation = new validation($this->params, $post_id);
     278        }
     279       
     280        $post_type = $this->params['post_type'];
     281        $taxonomies = get_object_taxonomies( $post_type, 'objects' );
     282       
     283        foreach ( $taxonomies as $taxonomy ) {
     284            if ( ! $taxonomy->_builtin ) {
     285                $this->add_view_alias( 'tax', $taxonomy->name );
     286            }
    270287        }
    271288    }
     
    548565                }
    549566
    550                 $this->params['terms'][] = (object)array(
     567                $this->params['terms'][] = (object) array(
    551568                    'name'=>'Category',
    552569                    'slug'=>'category'
     
    10041021                    $errorCount = 1;
    10051022
     1023                    echo '<pre>' . htmlspecialchars( print_r( $action_results, true ) ) . '</pre>';
     1024                   
    10061025                    // There might be multiple errors, so they are in an array.
    1007                     foreach ( $notes['error'] as $key=>$value ) {
     1026                    foreach ( $notes['error'] as $key => $value ) {
    10081027                        $formErrors .= sprintf('
    10091028                            <p class="form-error%3$s"><span class="error-number">%1$s.</span> %2$s</p>',
     
    11021121            }
    11031122        }
     1123    }
     1124   
     1125    public function add_view_alias( $view, $alias ) {
     1126        $view_slug  = $this->sanitize_slug( $view );
     1127        $alias_slug = $this->sanitize_slug( $alias );
     1128       
     1129        if ( isset( $this->_valid_views[$view_slug] ) )
     1130            $this->_valid_views[$view_slug]['aliases'][] = $alias_slug;
    11041131    }
    11051132   
     
    18151842            $tags = $this->tags_input_to_string($post_data['tags_input']);
    18161843
     1844        $terms = $post_data['tax_input'];
     1845
    18171846        $version_control = false;
    18181847
     
    18381867            'post_type'      => $post_type, // post, page, or attachment
    18391868            'post_category'  => $categories,
    1840             'tags_input'     => $tags
     1869            'tags_input'     => $tags,
     1870            'tax_input'      => $terms
    18411871        );
    18421872        //'post_date'      => $post_date,
     
    19051935        if ( $post = get_post( $post_id ) ) {
    19061936            kickpress_process_custom_fields( $post, $post_data );
    1907 
     1937           
     1938            if ( @is_array( $post_data['rel_input'] ) ) {
     1939                foreach ( $post_data['rel_input'] as $slug => $ids ) {
     1940                    $rel_posts = kickpress_get_related_posts( $post_id, $slug );
     1941                   
     1942                    $skip_ids = array();
     1943                   
     1944                    foreach ( $rel_posts as $rel_post ) {
     1945                        var_dump( $rel_post->ID );
     1946                        if ( in_array( $rel_post->ID, $ids ) )
     1947                            $skip_ids[] = $rel_post->ID;
     1948                        else
     1949                            kickpress_remove_related_post( $post_id, $slug, $rel_post );
     1950                    }
     1951                   
     1952                    foreach ( $ids as $rel_id ) {
     1953                        if ( ! in_array( $rel_id, $skip_ids ) )
     1954                            kickpress_add_related_post( $post_id, $slug, $rel_id );
     1955                    }
     1956                   
     1957                }
     1958            }
     1959           
    19081960            // Set the featured image, if specified
    19091961            //if ( ! is_admin() ) {
  • kickpress/trunk/kickpress-form-elements.php

    r587972 r588972  
    184184    protected static function _html_tag( $name, $body = null, $attr = array(), $auto_close = false ) {
    185185        foreach ( (array) $attr as $attr_name => $attr_value ) {
    186             if ( empty( $attr_value ) ) continue;
     186            // if ( empty( $attr_value ) ) continue;
    187187           
    188188            if ( true === $attr_value ) $attr_value = $attr_name;
     
    204204     */
    205205    protected static function _html_label( $text, $attr = array() ) {
    206         return self::_html_tag( 'label', $text, $attr );
     206        return self::_html_tag( 'label', $text, $attr, true );
    207207    }
    208208   
  • kickpress/trunk/kickpress-functions.php

    r587972 r588972  
    868868    }
    869869    */
     870}
     871
     872function kickpress_the_form_element( $element = 'text', $args = array(), $params = array() ) {
     873    $form_element = kickpress_get_form_element( $element, $args );
     874    echo $form_element->element( $params );
    870875}
    871876
  • kickpress/trunk/kickpress.php

    r586927 r588972  
    131131}
    132132
     133add_filter( 'the_posts', 'kickpress_the_posts', 99 );
     134
     135function kickpress_the_posts( $posts ) {
     136    if ( is_admin() || ! is_main_query() ) return $posts;
     137   
     138    global $kickpress_api;
     139   
     140    if ( 'tax' == $kickpress_api->params['view'] ) {
     141        $taxonomy = $kickpress_api->params['view_alias'];
     142       
     143        if ( $tax = get_taxonomy( $taxonomy ) ) {
     144            $page  = intval( get_query_var( 'paged' ) );
     145            $limit = intval( get_query_var( 'posts_per_page' ) );
     146           
     147            if ( 0 < $page ) $page--;
     148           
     149            $terms = get_terms( $taxonomy, array(
     150                'number' => $limit,
     151                'offset' => $limit * $page,
     152                'hide_empty' => false,
     153                'search' => $kickpress_api->params['search']
     154            ) );
     155           
     156            $fake_posts = array();
     157           
     158            foreach ( (array) $terms as $term ) {
     159                $fake_posts[] = (object) array(
     160                    'ID'           => $term->term_id,
     161                    'post_type'    => $term->taxonomy,
     162                    'post_name'    => $term->slug,
     163                    'post_title'   => $term->name,
     164                    'post_content' => $term->description
     165                );
     166            }
     167           
     168            return $fake_posts;
     169        }
     170    }
     171   
     172    return $posts;
     173}
     174
    133175function kickpress_activation() {
    134176
Note: See TracChangeset for help on using the changeset viewer.