WordPress.org

Plugin Directory

Changeset 1544833


Ignore:
Timestamp:
12/02/16 20:01:10 (7 months ago)
Author:
daggerhart
Message:

1.5.41 multiple bug fixes, json import/export, and contextual tokes in callback field params

Location:
query-wrangler/trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • query-wrangler/trunk/README.txt

    r1330840 r1544833  
    44Tags: query, pages, widget, admin, widgets, administration, manage, views, loop 
    55Requires at least: 4 
    6 Tested up to: 4.4.1 
     6Tested up to: 4.6.1 
    77Stable tag: trunk 
    88 
     
    7474 
    7575== Changelog == 
     76= 1.5.41 = 
     77 
     78* Feature: Contextual tokens allowed in callback text parameters 
     79* Change: Now using json for export & import to avoid eval. Warning, his will make existing saved exports useless. 
     80* Change: HTML span tag around file attachments for styling 
     81* Bug fix: Providing simple array polyfills for PHP5.2- 
     82* Bug fix: Some php notices on query creation & save 
     83* Bug fix: Query data doesn't appear to save. Unserialize method was sometimes failing when loading a query in the editor. 
     84* Bug fix: Allow nested limited terms in filters 
    7685 
    7786= 1.5.40 = 
     
    337346== Upgrade Notice == 
    338347 
    339 1.5.40 Fixes taxonomy exposed filter 
     3481.5.41 Contextual tokens in callback parameters, multiple bug fixes, new json export/import 
  • query-wrangler/trunk/admin/admin.php

    r1329785 r1544833  
    8686        'slug' => sanitize_title( $post['qw-name'] ), 
    8787        'type' => $post['qw-type'], 
    88         'path' => ( $post['page-path'] ) ? urlencode( $post['page-path'] ) : NULL, 
     88        'path' => isset( $post['page-path'] ) ? urlencode( $post['page-path'] ) : NULL, 
    8989        'data' => qw_serialize( qw_default_query_data() ), 
    9090    ); 
     
    141141 
    142142    // update for pages 
    143     if ( $options['display']['page']['path'] ) { 
     143    if ( isset( $options['display']['page']['path'] ) ) { 
    144144        $page_path = ( $options['display']['page']['path'] ) ? $options['display']['page']['path'] : ''; 
    145145 
     
    150150        } 
    151151 
    152         $sql = "UPDATE " . $table_name . " SET data = %s, path = %s WHERE id = %d LIMIT 1"; 
    153         $wpdb->query( $wpdb->prepare( $sql, 
     152        $wpdb->query( $wpdb->prepare( "UPDATE {$table_name} SET data = %s, path = %s WHERE id = %d LIMIT 1", 
    154153            $new_data, 
    155154            $page_path, 
     
    157156    } // update for widgets 
    158157    else { 
    159         $sql = "UPDATE " . $table_name . " SET data = %s WHERE id = %d LIMIT 1"; 
    160         $t   = $wpdb->prepare( $sql, $new_data, $query_id ); 
    161         $wpdb->query( $t ); 
     158        $wpdb->query( $wpdb->prepare( "UPDATE {$table_name} SET data = %s WHERE id = %d LIMIT 1",  
     159            $new_data,  
     160            $query_id ) ); 
    162161    } 
    163162} 
     
    189188    global $wpdb; 
    190189    $table_name = $wpdb->prefix . "query_wrangler"; 
    191     $sql        = "SELECT id,name,slug,type,path,data FROM " . $table_name . " WHERE id = " . $query_id; 
    192  
    193     $row = $wpdb->get_row( $sql, ARRAY_A ); 
     190 
     191    $row = $wpdb->get_row( $wpdb->prepare( "SELECT `id`,`name`,`slug`,`type`,`path`,`data` FROM {$table_name} WHERE `id` = %d", 
     192        $query_id ), 
     193        ARRAY_A ); 
     194 
    194195    unset( $row['id'] ); 
    195     // unserealize the stored data 
    196     $row['data'] = qw_unserialize( $row['data'] ); 
    197     $export      = var_export( $row, 1 ); 
    198  
    199     return "\$query = " . $export . ";"; 
     196    // unserialize the stored data 
     197    $row['data'] = unserialize( $row['data'] ); 
     198    $row['data'] = qw_query_escape_export( $row['data'] ); 
     199 
     200    $export = wp_json_encode( $row, JSON_PRETTY_PRINT ); 
     201    return $export; 
    200202} 
    201203 
     
    208210    $table = $wpdb->prefix . "query_wrangler"; 
    209211 
    210     eval( stripslashes( $post['import-query'] ) ); 
     212    $post['import-query'] = stripslashes( $post['import-query'] ); 
     213    $query = json_decode( $post['import-query'], TRUE ); 
     214    $query['data'] = qw_query_decode_import( $query['data'] ); 
    211215 
    212216    if ( $post['import-name'] ) { 
     
    218222 
    219223    return $wpdb->insert_id; 
     224} 
     225 
     226/** 
     227 * Helper to handle HTMl inside of json export 
     228 * 
     229 * @param $data 
     230 * 
     231 * @return mixed 
     232 */ 
     233function qw_query_escape_export( $data ){ 
     234    if ( isset( $data['display']['field_settings']['fields'] ) ) { 
     235        $fields = &$data['display']['field_settings']['fields']; 
     236 
     237        foreach( $fields as $field_name => $field ) { 
     238            $fields[ $field_name ]['custom_output'] = htmlspecialchars( $field['custom_output'], ENT_QUOTES, 'UTF-8', false ); 
     239            $fields[ $field_name ]['empty_field_content'] = htmlspecialchars( $field['empty_field_content'], ENT_QUOTES, 'UTF-8', false ); 
     240        } 
     241    } 
     242 
     243    return $data; 
     244} 
     245 
     246/** 
     247 * Helper to handle HTMl inside of json import 
     248 * 
     249 * @param $data 
     250 * 
     251 * @return mixed 
     252 */ 
     253function qw_query_decode_import( $data ){ 
     254    if ( isset( $data['display']['field_settings']['fields'] ) ) { 
     255        $fields = &$data['display']['field_settings']['fields']; 
     256 
     257        foreach( $fields as $field_name => $field ) { 
     258            $fields[ $field_name ]['custom_output'] = htmlspecialchars_decode( $field['custom_output'] ); 
     259            $fields[ $field_name ]['empty_field_content'] = htmlspecialchars_decode( $field['empty_field_content'] ); 
     260        } 
     261    } 
     262 
     263    return $data; 
    220264} 
    221265 
     
    361405        $meta_key = sanitize_text_field( $_POST['qw_meta_key_autocomplete'] ); 
    362406        global $wpdb; 
    363         $query   = $wpdb->prepare( "SELECT DISTINCT(`meta_key`) FROM {$wpdb->postmeta} WHERE `meta_key` LIKE '%s' LIMIT 15", 
    364             '%' . $meta_key . '%' ); 
    365         $results = $wpdb->get_col( $query ); 
    366  
    367  
     407 
     408        $results = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT(`meta_key`) FROM {$wpdb->postmeta} WHERE `meta_key` LIKE '%s' LIMIT 15", 
     409            '%' . $meta_key . '%' ) ); 
     410         
    368411        //foreach ($query) 
    369412        wp_send_json( array( 
     
    371414            'values'  => $results, 
    372415        ) ); 
    373  
    374         if ( $results ) { 
    375         } else { 
    376  
    377         } 
    378416    } 
    379417    exit; 
  • query-wrangler/trunk/includes/fields/callback_field.php

    r1254091 r1544833  
    4040                    unset( $callback_params[ $k ] ); 
    4141                } 
     42                else { 
     43                    $callback_params[ $k ] = qw_contextual_tokens_replace( $v ); 
     44                } 
    4245            } 
    4346 
     
    6972    $include_output_args = ( isset( $field['values']['include_output_arguments'] ) ) ? 'checked="checked"' : ''; 
    7073    $include_text_args   = ( isset( $field['values']['include_text_arguments'] ) ) ? 'checked="checked"' : ''; 
     74    $defaults = array( '', '', '', '', '' ); 
    7175 
    7276    if ( ! isset( $field['values']['parameters'] ) ) { 
    73         $field['values']['parameters'] = array( '', '', '' ); 
     77        $field['values']['parameters'] = $defaults; 
     78    } 
     79    else { 
     80        $field['values']['parameters'] = array_replace( $defaults, $field['values']['parameters'] ); 
    7481    } 
    7582 
     
    132139                   value="<?php print esc_attr( $field['values']['parameters'][2] ); ?>"/> 
    133140        </p> 
     141 
     142        <p> 
     143            <label class="qw-label">Parameter 4:</label> 
     144            <input class='qw-js-title' type="text" size=30 
     145                   name="<?php print $field['form_prefix']; ?>[parameters][3]" 
     146                   value="<?php print esc_attr( $field['values']['parameters'][3] ); ?>"/> 
     147        </p> 
     148 
     149        <p> 
     150            <label class="qw-label">Parameter 5:</label> 
     151            <input class='qw-js-title' type="text" size=30 
     152                   name="<?php print $field['form_prefix']; ?>[parameters][4]" 
     153                   value="<?php print esc_attr( $field['values']['parameters'][4] ); ?>"/> 
     154        </p> 
    134155    </div> 
    135156<?php 
  • query-wrangler/trunk/includes/fields/file_attachment.php

    r1254091 r1544833  
    8787    $files = qw_get_post_files( $post->ID ); 
    8888    if ( is_array( $files ) ) { 
    89         $output = ''; 
     89        $output = array(); 
    9090        $i      = 0; 
    9191        foreach ( $files as $file ) { 
     
    9696                switch ( $style ) { 
    9797                    case 'url': 
    98                         $output .= wp_get_attachment_url( $file->ID ); 
     98                        $output[] = wp_get_attachment_url( $file->ID ); 
    9999                        break; 
    100100 
     
    103103                        $file_name = explode( "/", $file->guid ); 
    104104                        $file_name = $file_name[ count( $file_name ) - 1 ]; 
    105                         $output .= '<a href="' . wp_get_attachment_url( $file->ID ) . '" class="query-file-link">' . $file_name . '</a>'; 
     105                        $output[] = '<a href="' . wp_get_attachment_url( $file->ID ) . '" class="query-file-link">' . $file_name . '</a>'; 
    106106                        break; 
    107107 
    108108                    case 'link_url': 
    109                         $output .= '<a href="' . wp_get_attachment_url( $file->ID ) . '" class="query-file-link">' . $file->guid . '</a>'; 
     109                        $output[] = '<a href="' . wp_get_attachment_url( $file->ID ) . '" class="query-file-link">' . $file->guid . '</a>'; 
    110110                        break; 
    111111                } 
     
    114114        } 
    115115 
    116         return $output; 
     116        return "<span class='qw-file-attachment'>".implode( "</span><span class='qw-file-attachment'>", $output ) ."</span>"; 
    117117    } 
    118118} 
  • query-wrangler/trunk/includes/filters/taxonomies.php

    r1330840 r1544833  
    192192    $terms = array(); 
    193193    $t = get_terms( $filter['taxonomy']->name, array( 'hide_empty' => FALSE ) ); 
     194    // handle limited options 
     195    $t = qw_filter_taxonomies_exposed_limit_values( $filter, $t ); 
    194196    qw_sort_terms_hierarchically( $t, $terms ); 
    195197 
     
    209211 */ 
    210212function qw_filter_taxonomies_exposed_form_terms_select( $filter, $terms ) { 
    211     // handle limited options 
    212     $terms = qw_filter_taxonomies_exposed_limit_values( $filter, $terms ); 
    213  
    214213    // handle submitted values 
    215214    if ( isset( $filter['values']['submitted'] ) ) { 
     
    227226        <select name="<?php print $filter['exposed_key']; ?>"> 
    228227            <?php 
    229             foreach ( $terms as $term ) { 
    230                 $term_selected = ( in_array( $term->term_id, $filter['values']['terms'] ) ) ? 'selected="selected"' : ''; 
    231                 ?> 
    232                 <option 
    233                     value="<?php print $term->term_id; ?>"<?php print $term_selected; ?> > 
    234                     <?php print $term->name; ?> 
    235                 </option> 
    236             <?php 
    237             } 
     228            qw_filter_taxonomies_exposed_form_terms_options($filter,$terms) 
    238229            ?> 
    239230        </select> 
    240231    </div> 
    241232<?php 
     233} 
     234 
     235/* 
     236 * Select box options recursion 
     237 */ 
     238function qw_filter_taxonomies_exposed_form_terms_options($filter,$terms,$level = 0){ 
     239    // handle submitted values 
     240    if ( isset( $filter['values']['submitted'] ) ) { 
     241        $filter['values']['terms'] = $filter['values']['submitted']; 
     242 
     243        // select boxes submit as single values 
     244        if ( !is_array( $filter['values']['terms'] ) ){ 
     245            $filter['values']['terms'] = array( $filter['values']['terms'] ); 
     246        } 
     247 
     248    } 
     249 
     250    foreach ( $terms as $term ) { 
     251        $term_selected = ( in_array( $term->term_id, $filter['values']['terms'] ) ) ? 'selected="selected"' : ''; 
     252        ?> 
     253        <option 
     254            value="<?php print $term->term_id; ?>"<?php print $term_selected; ?> > 
     255            <?php print $term->name; ?> 
     256        </option> 
     257    <?php 
     258        if ( ! empty( $term->children ) ) { 
     259            qw_filter_taxonomies_exposed_form_terms_options( $filter, $term->children, ($level + 1) ); 
     260        } 
     261    } 
    242262} 
    243263 
     
    250270    $wrapper_class = "" 
    251271) { 
    252     // handle limited options 
    253     $terms = qw_filter_taxonomies_exposed_limit_values( $filter, $terms ); 
    254272 
    255273    ?> 
     
    285303        foreach ( $terms as $k => $term ) { 
    286304            if ( isset( $filter['values']['terms'][ $term->term_id ] ) ) { 
    287                 $limited[ $k ] = $term; 
     305                $limited[ $term->term_id ] = $term; 
    288306            } 
    289307        } 
    290308    } 
    291309    else { 
    292         $limited = $terms; 
     310        foreach($terms as $k => $term){ 
     311            $limited[ $term->term_id ] = $term; 
     312        } 
    293313    } 
    294314 
     
    309329    $parentId = 0 
    310330) { 
     331    if(0 == $parentId){ 
     332        //used to limit the number of expensive loops for orphans 
     333        $cats_copy = $cats; 
     334    } 
     335 
    311336    foreach ( $cats as $i => $cat ) { 
    312337        if ( $cat->parent == $parentId ) { 
     
    320345        qw_sort_terms_hierarchically( $cats, $topCat->children, $topCat->term_id ); 
    321346    } 
    322 } 
     347 
     348    //handle terms that are orphans based on limited values 
     349    if(0 == $parentId && count($cats) > 0){ 
     350        while(count($cats) > 0){ 
     351            foreach($cats as $term_id => $cat){ 
     352                if(isset($cats_copy[$cat->parent])){ 
     353                    continue; 
     354                } 
     355 
     356                $cat->children = array(); 
     357                $into[$cat->term_id] = $cat; 
     358                unset($cats[$cat->term_id]); 
     359                qw_sort_terms_hierarchically( $cats, $cat->children, $cat->term_id ); 
     360            } 
     361        } 
     362    } 
     363} 
  • query-wrangler/trunk/includes/overrides/post_type_archive.php

    r1329785 r1544833  
    2828 */ 
    2929function qw_override_post_type_archive_pre_save( $options, $query_id ) { 
     30    if ( ! isset( $options['override'] ) ) { 
     31        return $options; 
     32    } 
     33 
    3034    if ( ! is_array( $options['override'] ) ){ 
    3135        return $options; 
  • query-wrangler/trunk/includes/query.php

    r1329785 r1544833  
    327327    switch ( $by ) { 
    328328        case 'id': 
    329             $where = 't.term_id = ' . $term; 
     329            $where = 't.term_id = %d'; 
    330330            break; 
    331331 
    332332        case 'slug': 
    333             $where = 't.slug = "' . $term . '"'; 
     333            $where = 't.slug = %s'; 
    334334            break; 
    335335    } 
     
    337337    $sql = "SELECT 
    338338            t.term_id,t.name,t.slug,t.term_group,tax.taxonomy,tax.description,tax.parent,tax.count 
    339           FROM " . $wpdb->prefix . "terms as t 
    340           LEFT JOIN " . $wpdb->prefix . "term_taxonomy as tax ON t.term_id = tax.term_id 
    341           WHERE " . $where; 
    342     $t   = $wpdb->get_row( $sql, $return_type ); 
    343  
    344     if ( $t->term_id ) { 
     339          FROM {$wpdb->terms} as t 
     340          LEFT JOIN {$wpdb->term_taxonomy} as tax ON t.term_id = tax.term_id 
     341          WHERE {$where}"; 
     342 
     343    $term = $wpdb->get_row( $wpdb->prepare($sql, $term), $return_type ); 
     344 
     345    if ( $term->term_id ) { 
    345346        // http://web.archiveorange.com/archive/v/XZYvyS8D7kDM3sQgrvJF 
    346         $t->link = get_term_link( (int) $t->term_id, $t->taxonomy ); 
     347        $term->link = get_term_link( (int) $term->term_id, $term->taxonomy ); 
    347348 
    348349        // return term if found 
    349         return $t; 
    350     } else { 
     350        return $term; 
     351    } 
     352    else { 
    351353        return FALSE; 
    352354    } 
     
    372374 */ 
    373375function qw_unserialize( $serial_str ) { 
    374     $array = array(); 
    375     // TODO preg_replace \e deprecated - use preg_replace_callback 
    376     $serial_str = @preg_replace( '!s:(\d+):"(.*?)";!se', 
    377         "'s:'.strlen('$2').':\"$2\";'", 
    378         $serial_str ); 
    379     $array      = unserialize( $serial_str ); 
     376    $array = maybe_unserialize( $serial_str ); 
     377 
    380378    if ( is_array( $array ) ) { 
    381379        // stripslashes twice for science 
  • query-wrangler/trunk/query-wrangler.php

    r1330840 r1544833  
    1010Author:            Jonathan Daggerhart 
    1111Author URI:        http://daggerhart.com 
    12 Version:           1.5.40 
     12Version:           1.5.41 
    1313 
    1414****************************************************************** 
     
    3131 
    3232// some useful definitions 
    33 define( 'QW_VERSION', 1.540 ); 
     33define( 'QW_VERSION', 1.541 ); 
    3434define( 'QW_PLUGIN_DIR', dirname( __FILE__ ) ); 
    3535define( 'QW_PLUGIN_URL', plugins_url( '', __FILE__ ) ); 
     
    4747function qw_init_frontend() { 
    4848    $settings = QW_Settings::get_instance(); 
     49 
     50    // some additional functions to support php 5.2- 
     51    include_once QW_PLUGIN_DIR . '/includes/php-polyfill.php'; 
    4952 
    5053    // include Template Wrangler 
     
    8386    include_once QW_PLUGIN_DIR . '/includes/fields/featured_image.php'; 
    8487    include_once QW_PLUGIN_DIR . '/includes/fields/callback_field.php'; 
     88    include_once QW_PLUGIN_DIR . '/includes/fields/taxonomy_terms.php'; 
    8589 
    8690    // meta value field as a setting 
Note: See TracChangeset for help on using the changeset viewer.