Plugin Directory

Changeset 433619


Ignore:
Timestamp:
09/05/2011 03:57:55 PM (15 years ago)
Author:
timhodson
Message:
  • Added: shortcode parameter to offset the first n posts in the query.
  • Added: and selectors fpr posts by an author.
  • Fixed: Bug where user templates were not being saved to the database.
  • Fixed: Bug where Entity encoded chars in a template were decoded then causing problems on save.
  • Fixed: Bug where excerpts were not shown.
Location:
blog-in-blog
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • blog-in-blog/tags/1.0.9/blog-in-blog.php

    r432139 r433619  
    7070                'tag_slug' => '',
    7171                'custom_post_type' => '',
     72                'author' => '',
     73                'author_name' => '',
     74//                'taxonomy' => '',
     75//                'tax_field' => '',
     76//                'tax_terms' => '',
     77//                'tax_operator' => '',
    7278                'num' => '10',
    7379                'order_by' => 'date',
     
    7783                'post_id' => '',
    7884                'custom_order_by' => '',
    79                 'thumbnail_size' => 'thumbnail'
     85                'thumbnail_size' => 'thumbnail',
     86                'hidefirst' => 0
    8087                    ), $atts));
    8188
     
    8592    $blog_in_blog_opts['tag_slug'] = $tag_slug;
    8693    $blog_in_blog_opts['custom_post_type'] = $custom_post_type;
     94//    $blog_in_blog_opts['taxonomy'] = $taxonomy;
     95//    $blog_in_blog_opts['tax_field'] = $tax_field;
     96//    $blog_in_blog_opts['tax_terms'] = $tax_terms;
     97//    $blog_in_blog_opts['tax_operator'] = $tax_operator;
    8798    $blog_in_blog_opts['num'] = $num;
    8899    $blog_in_blog_opts['post_order'] = bib_set_post_order($sort);
     
    92103    $blog_in_blog_opts['pagination'] = $pagination;
    93104    $blog_in_blog_opts['template'] = $template ;
     105    $blog_in_blog_opts['author'] = $author ;
     106    $blog_in_blog_opts['author_name'] = $author_name ;
     107    $blog_in_blog_opts['hidefirst'] = $hidefirst ;
    94108
    95109    if(isset ($wp_query->post->ID)){
     
    122136            // currently no default applied here...
    123137        }
    124         else if (file_exists(BIB_WP_UPLOADS_DIR . "/" . $template)) {
     138        if (file_exists(BIB_WP_UPLOADS_DIR . "/" . $template)) {
    125139            $blog_in_blog_opts['bib_post_template'] = BIB_WP_UPLOADS_DIR . "/" . $template;
    126             echo "<!-- blog-in-blog using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
     140            echo "<!-- BIB: using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
    127141            bib_write_debug(__FUNCTION__, "using template ".$blog_in_blog_opts['bib_post_template']);
     142           
    128143        } else if (file_exists(WP_CONTENT_DIR . '/uploads/' . $template)) {
    129144            $blog_in_blog_opts['bib_post_template'] = WP_CONTENT_DIR . '/uploads/' . $template;
    130             echo "<!-- blog-in-blog using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
     145            echo "<!-- BIB: using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
    131146            bib_write_debug(__FUNCTION__, "using template ".$blog_in_blog_opts['bib_post_template']);
     147           
    132148        } else if (file_exists(WP_PLUGIN_DIR . "/blog-in-blog/" . $template)) {
    133149            $blog_in_blog_opts['bib_post_template'] = WP_PLUGIN_DIR . "/blog-in-blog/" . $template;
    134             echo "<!-- blog-in-blog using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
     150            echo "<!-- BIB: using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
    135151            bib_write_debug(__FUNCTION__, "using template ".$blog_in_blog_opts['bib_post_template']);
     152           
    136153        }else{
    137154            $blog_in_blog_opts['bib_post_template'] = ''; // this will force using of bib_html option
     
    141158    } else {
    142159        $blog_in_blog_opts['bib_post_template'] = ''; // this will force using bib_html from database.
    143         echo "<!-- blog-in-blog using template from database -->" ;
     160        echo "<!-- BIB: using default template from database -->" ;
    144161        bib_write_debug(__FUNCTION__, "defaulting to database template.");
    145162    }
     
    148165
    149166    $out = ""; // reset output
     167
     168    // validate selections and give useful responses
     169    // TODO expand this properly into a separate function...
     170    if($blog_in_blog_opts['author'] != '' && !is_object(get_user_by('id',$blog_in_blog_opts['author']))){
     171        $out = "Error: Author with id '{$blog_in_blog_opts['author']}' is not an author in this site.";
     172        return $out;
     173    }
     174    if($blog_in_blog_opts['author_name'] != '' && !is_object(get_user_by('slug',$blog_in_blog_opts['author_name']))){
     175        $out = "Error: Author with slug '{$blog_in_blog_opts['author_name']}' is not an author in this site.";
     176        return $out;
     177    }
    150178
    151179    if (isset($wp_query->query['bib_page_offset'])) {
     
    159187    // get the posts
    160188    $postslist = bib_get_posts();
    161 
    162189    // now for each post, populate the data
    163190    if (is_array($postslist)){
     191
     192        if(count($postslist) <= 0){
     193            $out = "<strong>Blog in Blog:</strong> There are no posts that match the selection criteria.";
     194            return $out;
     195        }
     196
    164197        foreach ($postslist as $post) {
    165198
    166199            //var_dump($post);
    167200
     201            setup_postdata($post);
     202           
    168203            $data['post_id'] = $post->ID;
    169204
     
    188223            $data['post_content'] = wpautop(wptexturize($post->post_content));
    189224            $data['post_content'] = bib_process_gallery($data['post_content'], $post->ID);
    190             $data['post_excerpt'] = wpautop(wptexturize(bib_process_excerpt($post)));
     225            //$data['post_excerpt'] = wpautop(wptexturize(bib_process_excerpt($post)));
     226            $data['post_excerpt'] = wpautop(wptexturize(get_the_excerpt()));
    191227            $data['post_permalink'] = get_permalink($post);
    192228            $data['post_comments'] = bib_process_comments($post->comment_status, $post->comment_count, $data['post_permalink']);
     
    214250
    215251            $out .= bib_parse_template($data); // finally output the data in the template
     252
     253            wp_reset_postdata();
    216254        }
    217255    }
     
    275313            $params['order'] = $blog_in_blog_opts['post_order'];
    276314        }
     315//        if ($blog_in_blog_opts['taxonomy'] != ''){
     316//
     317//            if($blog_in_blog_opts['tax_operator'] != ''){
     318//                $operator = $blog_in_blog_opts['tax_operator'];
     319//            }
     320//            else
     321//            {
     322//                $operator = 'IN';
     323//            }
     324//
     325//            $params['tax_query'] = array(
     326//                    'taxonomy' => $blog_in_blog_opts['taxonomy'],
     327//                    'field' => $blog_in_blog_opts['tax_field'],
     328//                    'terms' => explode(',',$blog_in_blog_opts['tax_terms']),
     329//                    'operator' => $operator
     330//                );
     331//        }
    277332
    278333        // apply whatever the case:
    279334        $params['suppress_filters'] = false;
    280         $params['offset'] = $blog_in_blog_opts['offset'];
     335
     336        // adjust the offsett
     337        if($blog_in_blog_opts['hidefirst'] != '' ){
     338            $params['offset'] = intval($blog_in_blog_opts['hidefirst']) + intval($blog_in_blog_opts['offset']);
     339        }else{
     340            $params['offset'] = $blog_in_blog_opts['offset'];
     341        }
     342
    281343        $params['numberposts'] = $blog_in_blog_opts['num'];
    282344
     
    559621}
    560622
     623// this function possible needs deprecating
    561624function bib_process_excerpt($post) {
    562625
     
    569632    }
    570633
    571     #return apply_filters('get_the_excerpt', $output);
    572634    return $output;
    573635}
     
    900962       
    901963        // do something with the author_name
     964        if($blog_in_blog_opts['author'] != ''){
    902965        $querystr .= "
    903         AND $wpdb->posts.author = '".$blog_in_blog_opts['author']."'";
    904 
    905         $querystr .= "
    906         AND $wpdb->posts.author = '".$blog_in_blog_opts['author']."'";
     966        AND $wpdb->posts.post_author = '".$blog_in_blog_opts['author']."'";
     967        }
     968        if($blog_in_blog_opts['author_name'] != ''){
     969            $author = get_user_by('slug',$blog_in_blog_opts['author_name']);
     970            bib_write_debug(__FUNCTION__, print_r($author,true));
     971            $querystr .= "
     972        AND $wpdb->posts.post_author = '".$author->ID."'";
     973        }
    907974    }
    908975
  • blog-in-blog/tags/1.0.9/options.php

    r411897 r433619  
    362362
    363363function bib_templates_textarea() {
    364     // Style not selected
    365     $templates = get_option('bib_templates');
    366 
     364   
    367365    // templates = array(
    368366    //      array('template_name' => 'one' , 'template_html' => 'some HTML'),
    369367    //      array('template_name' => 'two' , 'template_html' => 'some HTML')
    370368    // )
    371 
    372     //print_r($templates);
     369    $templates = get_option('bib_templates');
    373370
    374371    if(is_array($templates) ){
    375372        foreach ($templates as $k => $v) {
    376373            if(is_array($v)){
    377                 echo '<hr><div>';
     374                echo '<hr><div class="usertemplate">';
    378375                echo '<input type="text" size="40" name="bib_templates['.$k.'][template_name]" value="'.$v['template_name'].'" /> template name <a href="javascript:void();" class="delete_user_template" id="bib_templates['.$k.']">Delete this template</a>';
    379                 echo '<textarea rows="20" cols="60" name="bib_templates['.$k.'][template_html]" >' . html_entity_decode($v['template_html']) . '</textarea>';
     376                echo '<textarea rows="20" cols="60" name="bib_templates['.$k.'][template_html]" >' . $v['template_html'] . '</textarea>';
    380377                echo '</div>' ;
    381378            }
     
    396393            existing = parent.html();
    397394
    398             template_count = parent.children("input").length ;
    399 
    400             html_before = '<hr><div>';
     395            template_count = parent.children("div.usertemplate").length ;
     396
     397            html_before = '<hr><div class="usertemplate">';
    401398            input = '<input type="text" size="40" name="bib_templates['+ template_count +'][template_name]" value="Your template name here" /> (not saved)';
    402399            textarea = '<textarea rows="20" cols="60" name="bib_templates['+ template_count +'][template_html]" >Your html here</textarea>';
  • blog-in-blog/tags/1.0.9/readme.txt

    r432139 r433619  
    8484* `custom_post_type=<post_type>` Posts with a custom post type that you want to show
    8585* `tag_slug=<tag_slug>` Posts of this tag slug will be shown. You can do OR (slug1,slug2,slug3) and AND (slug1+slug2+slug3)
    86 * `author`=<author id> Posts from this author, identified by a numeric author id.
    87 * `author_name`=<author user_nicename> Posts from this author, identified by their user nicename.
     86* `author=<author id>` Posts from this author, identified by a numeric author id.
     87* `author_name=<author user_nicename>` Posts from this author, identified by their user nicename.
    8888* `post_id=<a post id>` If specified only shows a single post. All other selection or sort parameters are ignored.
    8989
     
    193193== Changelog ==
    194194
     195= 1.0.9 =
     196
     197* Added: `hidefirst` shortcode parameter to offset the first n posts in the query.
     198* Added: `author` and `author_name` selectors fpr posts by an author.
     199* Fixed: Bug where user templates were not being saved to the database.
     200* Fixed: Bug where Entity encoded chars in a template were decoded then causing problems on save.
     201* Fixed: Bug where excerpts were not shown.
     202
    195203= 1.0.8 =
    196204
  • blog-in-blog/trunk/blog-in-blog.php

    r432139 r433619  
    7070                'tag_slug' => '',
    7171                'custom_post_type' => '',
     72                'author' => '',
     73                'author_name' => '',
     74//                'taxonomy' => '',
     75//                'tax_field' => '',
     76//                'tax_terms' => '',
     77//                'tax_operator' => '',
    7278                'num' => '10',
    7379                'order_by' => 'date',
     
    7783                'post_id' => '',
    7884                'custom_order_by' => '',
    79                 'thumbnail_size' => 'thumbnail'
     85                'thumbnail_size' => 'thumbnail',
     86                'hidefirst' => 0
    8087                    ), $atts));
    8188
     
    8592    $blog_in_blog_opts['tag_slug'] = $tag_slug;
    8693    $blog_in_blog_opts['custom_post_type'] = $custom_post_type;
     94//    $blog_in_blog_opts['taxonomy'] = $taxonomy;
     95//    $blog_in_blog_opts['tax_field'] = $tax_field;
     96//    $blog_in_blog_opts['tax_terms'] = $tax_terms;
     97//    $blog_in_blog_opts['tax_operator'] = $tax_operator;
    8798    $blog_in_blog_opts['num'] = $num;
    8899    $blog_in_blog_opts['post_order'] = bib_set_post_order($sort);
     
    92103    $blog_in_blog_opts['pagination'] = $pagination;
    93104    $blog_in_blog_opts['template'] = $template ;
     105    $blog_in_blog_opts['author'] = $author ;
     106    $blog_in_blog_opts['author_name'] = $author_name ;
     107    $blog_in_blog_opts['hidefirst'] = $hidefirst ;
    94108
    95109    if(isset ($wp_query->post->ID)){
     
    122136            // currently no default applied here...
    123137        }
    124         else if (file_exists(BIB_WP_UPLOADS_DIR . "/" . $template)) {
     138        if (file_exists(BIB_WP_UPLOADS_DIR . "/" . $template)) {
    125139            $blog_in_blog_opts['bib_post_template'] = BIB_WP_UPLOADS_DIR . "/" . $template;
    126             echo "<!-- blog-in-blog using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
     140            echo "<!-- BIB: using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
    127141            bib_write_debug(__FUNCTION__, "using template ".$blog_in_blog_opts['bib_post_template']);
     142           
    128143        } else if (file_exists(WP_CONTENT_DIR . '/uploads/' . $template)) {
    129144            $blog_in_blog_opts['bib_post_template'] = WP_CONTENT_DIR . '/uploads/' . $template;
    130             echo "<!-- blog-in-blog using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
     145            echo "<!-- BIB: using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
    131146            bib_write_debug(__FUNCTION__, "using template ".$blog_in_blog_opts['bib_post_template']);
     147           
    132148        } else if (file_exists(WP_PLUGIN_DIR . "/blog-in-blog/" . $template)) {
    133149            $blog_in_blog_opts['bib_post_template'] = WP_PLUGIN_DIR . "/blog-in-blog/" . $template;
    134             echo "<!-- blog-in-blog using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
     150            echo "<!-- BIB: using template: ".$blog_in_blog_opts['bib_post_template']." -->" ;
    135151            bib_write_debug(__FUNCTION__, "using template ".$blog_in_blog_opts['bib_post_template']);
     152           
    136153        }else{
    137154            $blog_in_blog_opts['bib_post_template'] = ''; // this will force using of bib_html option
     
    141158    } else {
    142159        $blog_in_blog_opts['bib_post_template'] = ''; // this will force using bib_html from database.
    143         echo "<!-- blog-in-blog using template from database -->" ;
     160        echo "<!-- BIB: using default template from database -->" ;
    144161        bib_write_debug(__FUNCTION__, "defaulting to database template.");
    145162    }
     
    148165
    149166    $out = ""; // reset output
     167
     168    // validate selections and give useful responses
     169    // TODO expand this properly into a separate function...
     170    if($blog_in_blog_opts['author'] != '' && !is_object(get_user_by('id',$blog_in_blog_opts['author']))){
     171        $out = "Error: Author with id '{$blog_in_blog_opts['author']}' is not an author in this site.";
     172        return $out;
     173    }
     174    if($blog_in_blog_opts['author_name'] != '' && !is_object(get_user_by('slug',$blog_in_blog_opts['author_name']))){
     175        $out = "Error: Author with slug '{$blog_in_blog_opts['author_name']}' is not an author in this site.";
     176        return $out;
     177    }
    150178
    151179    if (isset($wp_query->query['bib_page_offset'])) {
     
    159187    // get the posts
    160188    $postslist = bib_get_posts();
    161 
    162189    // now for each post, populate the data
    163190    if (is_array($postslist)){
     191
     192        if(count($postslist) <= 0){
     193            $out = "<strong>Blog in Blog:</strong> There are no posts that match the selection criteria.";
     194            return $out;
     195        }
     196
    164197        foreach ($postslist as $post) {
    165198
    166199            //var_dump($post);
    167200
     201            setup_postdata($post);
     202           
    168203            $data['post_id'] = $post->ID;
    169204
     
    188223            $data['post_content'] = wpautop(wptexturize($post->post_content));
    189224            $data['post_content'] = bib_process_gallery($data['post_content'], $post->ID);
    190             $data['post_excerpt'] = wpautop(wptexturize(bib_process_excerpt($post)));
     225            //$data['post_excerpt'] = wpautop(wptexturize(bib_process_excerpt($post)));
     226            $data['post_excerpt'] = wpautop(wptexturize(get_the_excerpt()));
    191227            $data['post_permalink'] = get_permalink($post);
    192228            $data['post_comments'] = bib_process_comments($post->comment_status, $post->comment_count, $data['post_permalink']);
     
    214250
    215251            $out .= bib_parse_template($data); // finally output the data in the template
     252
     253            wp_reset_postdata();
    216254        }
    217255    }
     
    275313            $params['order'] = $blog_in_blog_opts['post_order'];
    276314        }
     315//        if ($blog_in_blog_opts['taxonomy'] != ''){
     316//
     317//            if($blog_in_blog_opts['tax_operator'] != ''){
     318//                $operator = $blog_in_blog_opts['tax_operator'];
     319//            }
     320//            else
     321//            {
     322//                $operator = 'IN';
     323//            }
     324//
     325//            $params['tax_query'] = array(
     326//                    'taxonomy' => $blog_in_blog_opts['taxonomy'],
     327//                    'field' => $blog_in_blog_opts['tax_field'],
     328//                    'terms' => explode(',',$blog_in_blog_opts['tax_terms']),
     329//                    'operator' => $operator
     330//                );
     331//        }
    277332
    278333        // apply whatever the case:
    279334        $params['suppress_filters'] = false;
    280         $params['offset'] = $blog_in_blog_opts['offset'];
     335
     336        // adjust the offsett
     337        if($blog_in_blog_opts['hidefirst'] != '' ){
     338            $params['offset'] = intval($blog_in_blog_opts['hidefirst']) + intval($blog_in_blog_opts['offset']);
     339        }else{
     340            $params['offset'] = $blog_in_blog_opts['offset'];
     341        }
     342
    281343        $params['numberposts'] = $blog_in_blog_opts['num'];
    282344
     
    559621}
    560622
     623// this function possible needs deprecating
    561624function bib_process_excerpt($post) {
    562625
     
    569632    }
    570633
    571     #return apply_filters('get_the_excerpt', $output);
    572634    return $output;
    573635}
     
    900962       
    901963        // do something with the author_name
     964        if($blog_in_blog_opts['author'] != ''){
    902965        $querystr .= "
    903         AND $wpdb->posts.author = '".$blog_in_blog_opts['author']."'";
    904 
    905         $querystr .= "
    906         AND $wpdb->posts.author = '".$blog_in_blog_opts['author']."'";
     966        AND $wpdb->posts.post_author = '".$blog_in_blog_opts['author']."'";
     967        }
     968        if($blog_in_blog_opts['author_name'] != ''){
     969            $author = get_user_by('slug',$blog_in_blog_opts['author_name']);
     970            bib_write_debug(__FUNCTION__, print_r($author,true));
     971            $querystr .= "
     972        AND $wpdb->posts.post_author = '".$author->ID."'";
     973        }
    907974    }
    908975
  • blog-in-blog/trunk/options.php

    r411897 r433619  
    362362
    363363function bib_templates_textarea() {
    364     // Style not selected
    365     $templates = get_option('bib_templates');
    366 
     364   
    367365    // templates = array(
    368366    //      array('template_name' => 'one' , 'template_html' => 'some HTML'),
    369367    //      array('template_name' => 'two' , 'template_html' => 'some HTML')
    370368    // )
    371 
    372     //print_r($templates);
     369    $templates = get_option('bib_templates');
    373370
    374371    if(is_array($templates) ){
    375372        foreach ($templates as $k => $v) {
    376373            if(is_array($v)){
    377                 echo '<hr><div>';
     374                echo '<hr><div class="usertemplate">';
    378375                echo '<input type="text" size="40" name="bib_templates['.$k.'][template_name]" value="'.$v['template_name'].'" /> template name <a href="javascript:void();" class="delete_user_template" id="bib_templates['.$k.']">Delete this template</a>';
    379                 echo '<textarea rows="20" cols="60" name="bib_templates['.$k.'][template_html]" >' . html_entity_decode($v['template_html']) . '</textarea>';
     376                echo '<textarea rows="20" cols="60" name="bib_templates['.$k.'][template_html]" >' . $v['template_html'] . '</textarea>';
    380377                echo '</div>' ;
    381378            }
     
    396393            existing = parent.html();
    397394
    398             template_count = parent.children("input").length ;
    399 
    400             html_before = '<hr><div>';
     395            template_count = parent.children("div.usertemplate").length ;
     396
     397            html_before = '<hr><div class="usertemplate">';
    401398            input = '<input type="text" size="40" name="bib_templates['+ template_count +'][template_name]" value="Your template name here" /> (not saved)';
    402399            textarea = '<textarea rows="20" cols="60" name="bib_templates['+ template_count +'][template_html]" >Your html here</textarea>';
  • blog-in-blog/trunk/readme.txt

    r432139 r433619  
    8484* `custom_post_type=<post_type>` Posts with a custom post type that you want to show
    8585* `tag_slug=<tag_slug>` Posts of this tag slug will be shown. You can do OR (slug1,slug2,slug3) and AND (slug1+slug2+slug3)
    86 * `author`=<author id> Posts from this author, identified by a numeric author id.
    87 * `author_name`=<author user_nicename> Posts from this author, identified by their user nicename.
     86* `author=<author id>` Posts from this author, identified by a numeric author id.
     87* `author_name=<author user_nicename>` Posts from this author, identified by their user nicename.
    8888* `post_id=<a post id>` If specified only shows a single post. All other selection or sort parameters are ignored.
    8989
     
    193193== Changelog ==
    194194
     195= 1.0.9 =
     196
     197* Added: `hidefirst` shortcode parameter to offset the first n posts in the query.
     198* Added: `author` and `author_name` selectors fpr posts by an author.
     199* Fixed: Bug where user templates were not being saved to the database.
     200* Fixed: Bug where Entity encoded chars in a template were decoded then causing problems on save.
     201* Fixed: Bug where excerpts were not shown.
     202
    195203= 1.0.8 =
    196204
Note: See TracChangeset for help on using the changeset viewer.