Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 22.64 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /*
  3. Plugin Name: Advanced Most Recent Posts Mod
  4. Plugin URI: http://trepmal.com/plugins/advanced-most-recent-posts-mod/
  5. Description: Display most recent posts from selected categories or current category or all posts with thumbnail images (optional).
  6. Version: 1.6.4
  7. Author: Kailey Lampert
  8. Author URI: http://kaileylampert.com
  9. */
  10.  
  11. namespace a\b\c;
  12. class yg_recent_posts extends \WP_Widget {
  13.  
  14.         function __construct() {
  15.                 parent::__construct('advancedrecentposts', __( 'Advanced Recent Posts', 'adv-recent-posts' ));
  16.         }
  17.         function yg_recent_posts() {
  18.                 //Load Language
  19.                 load_plugin_textdomain( 'adv-recent-posts', null, dirname( plugin_basename( __FILE__ ) ) .  '/lang' );
  20.                 $widget_ops = array( 'description' => __( 'Shows most recent posts. You can customize it easily.', 'adv-recent-posts' ) );
  21.                 //Create widget
  22.                 $this->WP_Widget( 'advancedrecentposts', __( 'Advanced Recent Posts', 'adv-recent-posts' ), $widget_ops );
  23.         }
  24.  
  25.         function widget( $args, $instance ) {
  26.  
  27.                 extract( $args, EXTR_SKIP );
  28.                 echo $before_widget;
  29.                 $title = empty( $instance[ 'title' ] ) ? __( 'Recent Posts', 'adv-recent-posts' ) : apply_filters( 'widget_title', $instance[ 'title' ] );
  30.                 $link = empty( $instance[ 'link' ]) ? '' : $instance[ 'link' ];
  31.                 $parameters = array(
  32.                                 'title'         => $title,
  33.                                 'link'          => $instance[ 'link' ],
  34.                                 'hideposttitle' => $instance[ 'hideposttitle' ],
  35.                                 'separator' => $instance[ 'separator' ],
  36.                                 'afterexcerpt' => $instance[ 'afterexcerpt' ],
  37.                                 'afterexcerptlink' => $instance[ 'afterexcerptlink' ],
  38.                                 'show_type' => $instance[ 'show_type' ],
  39.                                 'show_status' => $instance[ 'show_status' ],
  40.                                 'shownum'       => (int) $instance[ 'shownum' ],
  41.                                 'postoffset' => (int) $instance[ 'postoffset' ],
  42.                                 'reverseorder' => (int) $instance[ 'reverseorder' ],
  43.                                 'excerpt'       => (int) $instance[ 'excerpt' ],
  44.                                 'excerptlengthwords' => (int) $instance[ 'excerptlengthwords' ],
  45.                                 'actcat'        => (bool) $instance[ 'actcat' ],
  46.                                 'cats'          => esc_attr( $instance[ 'cats' ] ),
  47.                                 'cusfield'      => esc_attr( $instance[ 'cusfield' ] ),
  48.                                 'w'             => (int) $instance[ 'width' ],
  49.                                 'h'             => (int) $instance[ 'height' ],
  50.                                 'firstimage' => (bool) $instance[ 'firstimage' ],
  51.                                 'atimage'       =>(bool) $instance[ 'atimage' ],
  52.                                 'defimage'      => esc_url( $instance[ 'defimage' ] ),
  53.                                 'showauthor' => (bool) $instance[ 'showauthor' ],
  54.                                 'showtime'      => (bool) $instance[ 'showtime' ],
  55.                                 'format'        => esc_attr( $instance[ 'format' ] ),
  56.                                 'spot'          => esc_attr( $instance[ 'spot' ] ),
  57.                         );
  58.  
  59.                 if ( !empty( $title ) &&  !empty( $link ) ) {
  60.                                 echo $before_title . '<a href="' . $link . '">' . $title . '</a>' . $after_title;
  61.                 }
  62.                 else if ( !empty( $title ) ) {
  63.                          echo $before_title . $title . $after_title;
  64.                 }
  65.         //print recent posts
  66.                 yg_recentposts($parameters);
  67.                 echo $after_widget;
  68.  
  69.   } //end of widget()
  70.        
  71.         //Update widget options
  72.   function update($new_instance, $old_instance) {
  73.  
  74.                 $instance = $old_instance;
  75.                 //get old variables
  76.                 $instance['title'] = esc_attr($new_instance['title']);
  77.                 $instance['link'] = esc_attr($new_instance['link']);
  78.                 $instance['hideposttitle'] = $new_instance['hideposttitle'] ? 1 : 0;
  79.                 $instance['separator'] = $new_instance['separator'];
  80.                 $instance['afterexcerpt'] = $new_instance['afterexcerpt'];
  81.                 $instance['afterexcerptlink'] = $new_instance['afterexcerptlink'] ? 1 : 0;
  82.                 $instance['show_type'] = $new_instance['show_type'];
  83.                 $instance['show_status'] = $new_instance['show_status'];
  84.                 $instance['show_status'] = $new_instance['show_status'];
  85.  
  86.                 $instance['shownum'] = isset($new_instance['show-num']) ? (int) abs($new_instance['show-num']) : (int) abs($new_instance['shownum']);
  87.         //      if ($instance['shownum'] > 20) $instance['shownum'] = 20;
  88.                 unset($instance['show-num']);
  89.  
  90.                 $instance['postoffset'] = (int) abs($new_instance['postoffset']);
  91.                 $instance['reverseorder'] = $new_instance['reverseorder'] ? 1 : 0;
  92.  
  93.                 $instance['excerpt'] = isset($new_instance['excerpt-length']) ? (int) abs($new_instance['excerpt-length']) : (int) abs($new_instance['excerpt']);
  94.                 unset($instance['excerpt-length']);
  95.  
  96.                 $instance['excerptlengthwords'] = (int) abs($new_instance['excerptlengthwords']);
  97.  
  98.                 $instance['cats'] = esc_attr($new_instance['cats']);
  99.                 $instance['actcat'] = $new_instance['actcat'] ? 1 : 0;
  100.  
  101.                 $instance['cusfield'] = isset($new_instance['cus-field']) ? esc_attr($new_instance['cus-field']) : esc_attr($new_instance['cusfield']);
  102.                 unset($instance['cus-field']);
  103.  
  104.                 $instance['width'] = esc_attr($new_instance['width']);
  105.                 $instance['height'] = esc_attr($new_instance['height']);
  106.                 $instance['firstimage'] = $new_instance['first-image'] ? 1 : 0;
  107.                 $instance['atimage'] = $new_instance['atimage'] ? 1 : 0;
  108.                 $instance['defimage'] = esc_url($new_instance['def-image']);
  109.                 $instance['showauthor'] = $new_instance['showauthor'] ? 1 : 0;
  110.                 $instance['showtime'] = $new_instance['showtime'] ? 1 : 0;
  111.                 $instance['format'] = esc_attr($new_instance['format']);
  112.                 $instance['spot'] = esc_attr($new_instance['spot']);
  113.                 unset($instance['spot1']);
  114.                 unset($instance['spot2']);
  115.                 unset($instance['spot3']);
  116. //die($new_instance['spot']);
  117.                 return $instance;
  118.  
  119.         } //end of update()
  120.        
  121.         //Widget options form
  122.   function form($instance) {
  123.  
  124.                 if (isset($instance['spot1'])) $instance['spot'] = $instance['spot1'];
  125.                 if (isset($instance['show-num'])) $instance['shownum'] = $instance['show-num'];
  126.                 if (isset($instance['excerpt-length'])) $instance['excerpt'] = $instance['excerpt-length'];
  127.                 if (isset($instance['cus-field'])) $instance['cusfield'] = $instance['cus-field'];
  128.  
  129.                 $instance = wp_parse_args( (array) $instance, yg_recentposts_defaults() );
  130.                
  131.                 $title          = esc_attr($instance['title']);
  132.                 $link           = esc_attr($instance['link']);
  133.                 $hideposttitle = $instance['hideposttitle'];
  134.                 $separator      = $instance['separator'];
  135.                 $afterexcerpt = $instance['afterexcerpt'];
  136.                 $afterexcerptlink = $instance['afterexcerptlink'];
  137.                 $show_type      = $instance['show_type'];
  138.                 $show_status    = $instance['show_status'];
  139.                 $shownum        = (int) $instance['shownum'];
  140.                 $postoffset     = (int) $instance['postoffset'];
  141.                 $reverseorder = $instance['reverseorder'];
  142.                 $excerpt = (int) $instance['excerpt'];
  143.                 $excerptlengthwords = (int) $instance['excerptlengthwords'];
  144.                 $cats           = esc_attr($instance['cats']);
  145.                 $actcat         = (bool) $instance['actcat'];
  146.                 $cus_field      = esc_attr($instance['cusfield']);
  147.                 $width          = esc_attr($instance['width']);
  148.                 $height         = esc_attr($instance['height']);
  149.                 $firstimage     = (bool) $instance['firstimage'];
  150.                 $atimage        = (bool) $instance['atimage'];
  151.                 $defimage       = esc_url($instance['defimage']);
  152.                 $showauthor     = (bool) $instance['showauthor'];
  153.                 $showtime       = (bool) $instance['showtime'];
  154.                 $format         = esc_attr($instance['format']);
  155.                 $spot           = esc_attr($instance['spot']);
  156.                 ?>
  157.                 <p>
  158.                         <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' );?>
  159.                                 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
  160.                         </label>
  161.                 </p>
  162.                 <p>
  163.                         <label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Title Link:');?>
  164.                                 <input class="widefat" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" type="text" value="<?php echo $link; ?>" />
  165.                         </label>
  166.                 </p>
  167.                 <p>
  168.                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hideposttitle'); ?>" name="<?php echo $this->get_field_name('hideposttitle'); ?>"<?php checked( $hideposttitle ); ?> />
  169.                         <label for="<?php echo $this->get_field_id('hideposttitle'); ?>"><?php _e('Hide post title?', 'adv-recent-posts');?></label>
  170.                 </p>
  171.                 <p>
  172.                         <label for="<?php echo $this->get_field_id('separator'); ?>"><?php _e('Separator:');?>
  173.                                 <input class="widefat" id="<?php echo $this->get_field_id('separator'); ?>" name="<?php echo $this->get_field_name('separator'); ?>" type="text" value="<?php echo $separator; ?>" />
  174.                         </label>
  175.                 </p>
  176.                 <p>
  177.                         <label for="<?php echo $this->get_field_id('afterexcerpt'); ?>"><?php _e('After Excerpt:');?>
  178.                                 <input class="widefat" id="<?php echo $this->get_field_id('afterexcerpt'); ?>" name="<?php echo $this->get_field_name('afterexcerpt'); ?>" type="text" value="<?php echo $afterexcerpt; ?>" />
  179.                         </label>
  180.                 </p>
  181.                 <p>
  182.                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('afterexcerptlink'); ?>" name="<?php echo $this->get_field_name('afterexcerptlink'); ?>"<?php checked( $afterexcerptlink ); ?> />
  183.                         <label for="<?php echo $this->get_field_id('afterexcerptlink'); ?>"><?php _e('Link \'After Expcerpt\' to post?', 'adv-recent-posts');?></label>
  184.                 </p>
  185.                 <p>
  186.                         <label for="<?php echo $this->get_field_id('show_type'); ?>"><?php _e('Show:');?>
  187.                                 <select class="widefat" id="<?php echo $this->get_field_id('show_type'); ?>" name="<?php echo $this->get_field_name('show_type'); ?>">
  188.                                 <?php
  189.                                         global $wp_post_types;
  190.                                         foreach($wp_post_types as $k=>$pt) {
  191.                                                 if($pt->exclude_from_search) continue;
  192.                                                 echo '<option value="' . $k . '"' . selected($k,$show_type,true) . '>' . $pt->labels->name . '</option>';
  193.                                         }
  194.                                 ?>
  195.                                 </select>
  196.                         </label>
  197.                 </p>
  198.                 <p>
  199.                         <label for="<?php echo $this->get_field_id('show_status'); ?>"><?php _e('Status:');?>
  200.                                 <input class="widefat" id="<?php echo $this->get_field_id('show_status'); ?>" name="<?php echo $this->get_field_name('show_status'); ?>" type="text" value="<?php echo $show_status; ?>" />
  201.                         </label>
  202.                        
  203.                 </p>
  204.                 <p>
  205.                         <label for="<?php echo $this->get_field_id('shownum'); ?>"><?php _e('Number of posts to show:');?>
  206.                                 <input id="<?php echo $this->get_field_id('shownum'); ?>" name="<?php echo $this->get_field_name('shownum'); ?>" type="text" value="<?php echo $shownum; ?>" size ="3" /><br />
  207.                                 <small><?php _e('(at most 20)','adv-recent-posts'); ?></small>
  208.                         </label>
  209.                 </p>
  210.                 <p>
  211.                         <label for="<?php echo $this->get_field_id('postoffset'); ?>"><?php _e('Number of Posts to skip:');?>
  212.                                 <input id="<?php echo $this->get_field_id('postoffset'); ?>" name="<?php echo $this->get_field_name('postoffset'); ?>" type="text" value="<?php echo $postoffset; ?>" size ="3" /><br />
  213.                                 <small><?php _e('(e.g. "1" will skip the most recent post)','adv-recent-posts'); ?></small>
  214.                         </label>
  215.                 </p>
  216.                 <p>
  217.                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('reverseorder'); ?>" name="<?php echo $this->get_field_name('reverseorder'); ?>"<?php checked( $reverseorder ); ?> />
  218.                         <label for="<?php echo $this->get_field_id('reverseorder'); ?>"><?php _e('Show posts in reverse order?', 'adv-recent-posts');?></label>
  219.                 </p>
  220.                 <p>
  221.                         <label for="<?php echo $this->get_field_id('excerpt-length'); ?>"><?php _e('Excerpt length (letters):', 'adv-recent-posts');?>
  222.                                 <input id="<?php echo $this->get_field_id('excerpt-length'); ?>" name="<?php echo $this->get_field_name('excerpt-length'); ?>" type="text" value="<?php echo $excerpt; ?>" size ="3" /><br />
  223.                                 <small>(<?php _e('0 - Don\'t show excerpt', 'adv-recent-posts');?>)</small>
  224.                         </label>
  225.                 </p>
  226.                 <p>
  227.                         <label for="<?php echo $this->get_field_id('excerptlengthwords'); ?>"><?php _e('Excerpt length (words):', 'adv-recent-posts');?>
  228.                                 <input id="<?php echo $this->get_field_id('excerptlengthwords'); ?>" name="<?php echo $this->get_field_name('excerptlengthwords'); ?>" type="text" value="<?php echo $excerptlengthwords; ?>" size ="3" /><br />
  229.                                 <small>(<?php _e('0 - Use letter-excerpt', 'adv-recent-posts');?>)</small>
  230.                         </label>
  231.                 </p>
  232.                 <p>
  233.                         <label for="<?php echo $this->get_field_id('cus-field'); ?>"><?php _e('Thumbnail Custom Field Name:', 'adv-recent-posts');?>
  234.                                 <input id="<?php echo $this->get_field_id('cus-field'); ?>" name="<?php echo $this->get_field_name('cus-field'); ?>" type="text" value="<?php echo $cus_field; ?>" size ="20" />
  235.                         </label><br />
  236.                         <label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:', 'adv-recent-posts');?> <input id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" type="text" value="<?php echo $width; ?>" size ="3" /></label>px<br />
  237.                         <label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:', 'adv-recent-posts');?> <input id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="text" value="<?php echo $height; ?>" size ="3" /></label>px
  238.                 </p>
  239.                 <p>
  240.                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('first-image'); ?>" name="<?php echo $this->get_field_name('first-image'); ?>"<?php checked( $firstimage ); ?> />
  241.                         <label for="<?php echo $this->get_field_id('first-image'); ?>"><?php _e('Get first image of post', 'adv-recent-posts');?></label>
  242.                 </p>
  243.                 <p>
  244.                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('atimage'); ?>" name="<?php echo $this->get_field_name('atimage'); ?>"<?php checked( $atimage ); ?> />
  245.                         <label for="<?php echo $this->get_field_id('atimage'); ?>"><?php _e('Get first attached image of post', 'adv-recent-posts');?></label>
  246.                 </p>
  247.                 <p>
  248.                         <label for="<?php echo $this->get_field_id('def-image'); ?>"><?php _e('Default image:', 'adv-recent-posts');?>
  249.                                 <input class="widefat" id="<?php echo $this->get_field_id('def-image'); ?>" name="<?php echo $this->get_field_name('def-image'); ?>" type="text" value="<?php echo $defimage; ?>" /><br />
  250.                                 <small>(<?php _e('if there is no thumbnail, use this', 'adv-recent-posts');?></small>
  251.                         </label>
  252.                 </p>   
  253.                 <p>
  254.                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('showauthor'); ?>" name="<?php echo $this->get_field_name('showauthor'); ?>"<?php checked( $showauthor ); ?> />
  255.                         <label for="<?php echo $this->get_field_id('showauthor'); ?>"><?php _e('Show Author', 'adv-recent-posts');?></label>
  256.                 </p>
  257.                 <p>
  258.                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('showtime'); ?>" name="<?php echo $this->get_field_name('showtime'); ?>"<?php checked( $showtime ); ?> />
  259.                         <label for="<?php echo $this->get_field_id('showtime'); ?>"><?php _e('Show Post Timestamp', 'adv-recent-posts');?></label>
  260.                 </p>
  261.                 <p>
  262.                         <label for="<?php echo $this->get_field_id('format'); ?>"><?php _e('Time format:', 'adv-recent-posts');?>
  263.                                 <input class="widefat" id="<?php echo $this->get_field_id('format'); ?>" name="<?php echo $this->get_field_name('format'); ?>" type="text" value="<?php echo $format; ?>" /><br />
  264.                                 <small>(<?php _e('<a href="http://www.php.net/manual/en/function.date.php">PHP style</a> - leave as default unless you know what you\'re doing.', 'adv-recent-posts');?>)</small>
  265.                         </label>
  266.                 </p>
  267.                 <p>
  268.                         <label>Put time</label><br />
  269.                                 <select class="widefat" id="<?php echo $this->get_field_id('spot'); ?>" name="<?php echo $this->get_field_name('spot'); ?>">
  270.                                 <?php
  271.                                         $spots = array( 'spot1' => 'Before Title', 'spot2' => 'After Title', 'spot3' => 'After Separator' );
  272.                                         foreach($spots as $s => $l) {
  273.                                                 echo '<option value="' . $s . '"' . selected( $s, $spot, true ) . '>' . $l . '</option>';
  274.                                         }
  275.                                 ?>
  276.                                 </select>
  277.                 </p>
  278.                 <p>
  279.                         <label for="<?php echo $this->get_field_id('cats'); ?>"><?php _e('Categories:', 'adv-recent-posts');?>
  280.                                 <input class="widefat" id="<?php echo $this->get_field_id('cats'); ?>" name="<?php echo $this->get_field_name('cats'); ?>" type="text" value="<?php echo $cats; ?>" /><br />
  281.                                 <small>(<?php _e('Category IDs, separated by commas.', 'adv-recent-posts');?>)</small>
  282.                         </label>
  283.                 </p>
  284.                 <p>
  285.                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('actcat'); ?>" name="<?php echo $this->get_field_name('actcat'); ?>"<?php checked( $actcat ); ?> />
  286.                         <label for="<?php echo $this->get_field_id('actcat'); ?>"> <?php _e('Get posts from current category', 'adv-recent-posts');?></label>
  287.                 </p>
  288.                 <?php
  289.         } //end of form
  290. }
  291.  
  292. add_action( 'widgets_init', create_function('', 'return register_widget("a\b\c\yg_recent_posts");') );
  293. //Register Widget
  294.  
  295. // Show recent posts function
  296. function yg_recentposts_defaults() {
  297. $defaults = array(      'title' => __( 'Recent Posts', 'adv-recent-posts' ),
  298.                                         'link' => get_bloginfo( 'url' ) . '/blog/',
  299.                                         'hideposttitle' => 0,
  300.                                         'separator' => ': ',
  301.                                         'afterexcerpt' => '...',
  302.                                         'afterexcerptlink' => 0,
  303.                                         'show_type' => 'post',
  304.                                         'show_status' => 'publish',
  305.                                         'postoffset' => 0,
  306.                                         'limit' => 10,
  307.                                         'shownum' => 10,
  308.                                         'reverseorder' => 0,
  309.                                         'excerpt' => 0,
  310.                                         'excerptlengthwords' => 0,
  311.                                         'actcat' => 0,
  312.                                         'cats' => '',
  313.                                         'cusfield' => '',
  314.                                         'width' => '',
  315.                                         'height' => '',
  316.                                         'w' => '',
  317.                                         'h' => '',
  318.                                         'firstimage' => 0,
  319.                                         'showauthor' => 0,
  320.                                         'showtime' => 0,
  321.                                         'atimage' => 0,
  322.                                         'defimage' => '',
  323.                                         'format' => 'm/d/Y',
  324.                                         'spot' => 'spot1' );
  325.         return $defaults;
  326. }
  327. add_shortcode( 'amrp' , 'yg_recentposts_sc');
  328. function yg_recentposts_sc( $atts ) {
  329.  
  330.         $defaults = yg_recentposts_defaults();
  331. //      $defaults['limit'] = $defaults['shownum'];
  332. //      unset($shownum);
  333.         $args = shortcode_atts($defaults, $atts);
  334.         return yg_recentposts( $args, false );
  335.        
  336. }
  337. function yg_wordexcerpt() {
  338. }
  339.  
  340.  
  341.  
  342. function yg_recentposts($args = '', $echo = true) {
  343.         global $wpdb;
  344.         $defaults = yg_recentposts_defaults();
  345.         //$defaults = array('separator' => ': ','show_type' => 'post', 'limit' => 10, 'excerpt' => 0, 'actcat' => 0, 'cats'=>'', 'cusfield' =>'', 'w' => 48, 'h' => 48, 'firstimage' => 0, 'showauthor' => 0, 'showtime' => 0, 'atimage' => 0, 'defimage' => '', 'format' => 'm/d/Y', 'spot' => 'spot1');
  346.        
  347.         $args = wp_parse_args( $args, $defaults );
  348.         extract($args);
  349.        
  350.         $hideposttitle = (bool) $hideposttitle;
  351.         $separator = $separator;
  352.         $afterexcerpt = $afterexcerpt;
  353.         $afterexcerptlink = (bool) $afterexcerptlink;
  354.         $show_type = $show_type;
  355.         $show_status = $show_status;
  356.  
  357.         $shownum = (int) abs($shownum);
  358.         if(isset($limit) && $shownum == 10) $shownum = (int) $limit;
  359.         $postoffset = (int) abs($postoffset);
  360.         $reverseorder = (int) abs($reverseorder);
  361.         $firstimage = (bool) $firstimage;
  362.         $showauthor = (bool) $showauthor;
  363.         $showtime = (bool) $showtime;
  364.  
  365.         $spot = esc_attr($spot);
  366.  
  367.         $atimage = (bool) $atimage;
  368.         $defimage = esc_url($defimage);
  369.         $format = esc_attr($format);
  370.         $time = '';
  371.         $width = (int) $width;
  372.         $height = (int) $height;
  373.         $w = (int) $w;
  374.         $h = (int) $h;
  375.         if ($width > $w) {
  376.                 $width = $width; $height = $height;
  377.         } else {
  378.                 $width = $w; $height = $h;     
  379.         }
  380.        
  381.         $excerptlength = (int) abs($excerpt);
  382.         $excerptlengthwords = (int) abs($excerptlengthwords);
  383.         $excerpt = '';
  384.         $cats = str_replace(" ", "", esc_attr($cats));
  385.         if (($shownum < 1 ) || ($shownum > 20)) $shownum = 10;
  386.        
  387.         /*$postlist = wp_cache_get('yg_recent_posts'); //Not yet
  388.         if ( false === $postlist ) {
  389.         */
  390.                 if (($actcat) && (is_category())) {
  391.                         $cats = get_query_var('cat');
  392.                 }
  393.                 if (($actcat) && (is_single())) {
  394.                         $cats = '';
  395.                         foreach (get_the_category() as $catt) {
  396.                                 $cats .= $catt->cat_ID.' ';
  397.                         }
  398.                         $cats = str_replace(" ", ",", trim($cats));
  399.                 }
  400.                
  401.                 if (!intval($cats)) $cats='';
  402.                 //group by is needed to avoid that a single post belonging to k>1
  403.                 //categories is displayed k times
  404.                 $querystr = "
  405.                         SELECT wposts.*
  406.                         FROM $wpdb->posts wposts, $wpdb->term_relationships rel
  407.                         WHERE wposts.post_type = '$show_type'
  408.                                 AND wposts.post_status = '$show_status'
  409.                                 AND rel.object_id = wposts.ID
  410.                                 AND rel.term_taxonomy_id IN ($cats)
  411.                         GROUP BY wposts.ID
  412.                         ORDER BY wposts.post_date DESC
  413.                         LIMIT $shownum OFFSET $postoffset
  414.                         ";
  415.                 $posts = $wpdb->get_results($querystr, OBJECT);
  416.                 if ($reverseorder) $posts = array_reverse($posts);
  417.                 $postlist = '';
  418.                 $height = $height ? ' height: ' . $height .'px;' : '';
  419.                 $width = $width ? ' width: ' . $width . 'px;' : '';
  420.                 $hw = (!empty($height) || !empty($width)) ? 'style="'.$width.$height.'"' : '';
  421.          
  422.                 foreach ($posts as $post) {
  423.                         if ($showtime) { $time = ' '. date($format,strtotime($post->post_date)); }
  424.                         $post_title = stripslashes($post->post_title);
  425.                         if ($excerptlength) {
  426.                                 $excerpt = $post->post_excerpt;
  427.                                 $text = $post->post_content;
  428.                                 $text = strip_shortcodes( $text );
  429.                                 $text = str_replace(']]>', ']]&gt;', $text);
  430.                                 $text = strip_tags($text);
  431.                                 $excerpt_length = 100;
  432.                                 $words = explode(' ', $text, $excerpt_length + 1);
  433.                                 if ( '' == $excerpt ) {
  434.                                         if (count($words) > $excerpt_length) {
  435.                                                 array_pop($words);
  436.                                                 $text = implode(' ', $words);
  437.                                         }
  438.                                         $excerpt = $text;
  439.                                 }
  440.                                 $afterexcerpt_html = '';
  441.                                 if ($afterexcerptlink) $afterexcerpt_html = '<a href="' . get_permalink($post->ID) . '">' . $afterexcerpt . '</a>';
  442.                                 if ($excerptlengthwords > 0 ) {
  443.                                         $words = array_splice($words, 0, $excerptlengthwords);
  444.                                         $excerpt = implode(' ', $words);
  445.                                 }elseif(strlen($excerpt) > $excerptlength) {
  446.                                         $excerpt = mb_substr($excerpt, 0, $excerptlength);
  447.                                 }
  448.                                 $excerpt = $separator . ($spot == 'spot3' ? '<span class="date">'.$time.'</span> ' : '') . $excerpt . $afterexcerpt_html;
  449.                         }
  450.                         $image = '';
  451.                         $img = '';
  452.                         if ($cusfield) {
  453.                                 $cusfield = esc_attr($cusfield);
  454.                                 $img = get_post_meta($post->ID, $cusfield, true);
  455.                         }
  456.        
  457.                         if (!$img && $firstimage) {
  458.                                 $match_count = preg_match_all("/<img[^']*?src=\"([^']*?)\"[^']*?>/", $post->post_content, $match_array, PREG_PATTERN_ORDER);           
  459.                                 $img = count($match_array['1']) > 0 ? $match_array[1][0] : false;
  460.                         }
  461.                         if (!$img && $atimage) {
  462.                                 $p = array(
  463.                                         'post_type' => 'attachment',
  464.                                         'post_mime_type' => 'image',
  465.                                         'numberposts' => 1,
  466.                                         'order' => 'ASC',
  467.                                         'orderby' => 'menu_order ID',
  468.                                         'post_status' => null,
  469.                                         'post_parent' => $post->ID
  470.                                  );
  471.                                 $attachments = get_posts($p);
  472.                                 if ($attachments) {
  473.                                         $imgsrc = wp_get_attachment_image_src($attachments[0]->ID, 'thumbnail');
  474.                                         $img = $imgsrc[0];
  475.                                 }                        
  476.                          }
  477.                                  
  478.                         if (!$img && $defimage)
  479.                                 $img = $defimage;
  480.                                  
  481.                         if ($img)
  482.                                 $image = '<a href="' . get_permalink($post->ID) . '" title="'. $post_title .'" ><img src="' . $img . '" title="' . $post_title . '" class="recent-posts-thumb" ' . $hw . ' /></a>';
  483.          
  484.                         $postlist .=  '<li>'.($spot == 'spot1' ? '<span class="date">'.$time.'</span> ' : '');
  485.                         $postlist .= $image;
  486.                         if (!$hideposttitle) $postlist .= '<a href="' . get_permalink($post->ID) . '" title="'. $post_title .'" >' . $post_title .'</a>';
  487.                                 $author_data = get_userdata($post->post_author);
  488.                         $postlist .= ($showauthor ? ' by '.$author_data->display_name : '') . ($spot == 'spot2' ? ' <span class="date">'.$time.'</span>' : '') . $excerpt . "</li>";
  489.                 }// end foreach()
  490.                
  491.                 /*
  492.                 wp_cache_set('yg_recent_posts', $postlist);
  493.         }*/
  494.  
  495.         if ($echo)
  496.                 echo '<ul class="advanced-recent-posts">' . $postlist . '</ul>';
  497.         else
  498.                 return '<ul class="advanced-recent-posts">' . $postlist . '</ul>';
  499. }
  500. ?>