/**
  * The wp_cpl_shortcode_handler function
  * This function is responsible for converting shortcodes into dynamic contents
  * @package WordPress
  * @subpackage WordPress Category Post List plugin
  * @since 1.1.0
  * @param array $atts The attributes passed through the shortcode
  * @param string $content The string passed through the shortcode. Used for generating title
  * @return string The modified content
  */
 public function wp_cpl_shortcode_handler($atts, $content = null)
 {
     /** first extract the attributes */
     $op = shortcode_atts(array('cat_id' => 1, 'css_theme' => 0, 'is_thumb' => 'true', 'list_num' => 10, 'show_comments' => 'true', 'sort_using' => 1, 'sort_order' => 'asc', 'exclude_post' => '', 'sticky_post' => '', 'show_date' => 'true', 'show_author' => 'true', 'show_excerpt' => 'true', 'excerpt_length' => 150, 'optional_excerpt' => 'false', 'read_more' => __('Continue Reading', itgdb_wp_cpl_loader::$text_domain)), $atts);
     /** Sanitize some of the user datas */
     $cat_id = (int) $op['cat_id'];
     $i = 0;
     /** Done, now the main thing */
     include_once itgdb_wp_cpl_loader::$abs_path . '/includes/wp_cpl_output_gen.php';
     $output_gen = new itgdb_wp_cpl_output_gen();
     return $output_gen->shortcode_output_gen($op);
 }
Exemple #2
0
 /**
  * The main Widget
  * All the magic Happens here
  */
 function widget($args, $instance)
 {
     /** The translator */
     $wp_cat_list_itg_tans = 'wp-cat-list-itg';
     /** Extact default things */
     extract($args);
     /** Now lets start the main output */
     /**
      * We are using wp_cache_get, wp_cache_set and wp_cache_delete for better caching of the complex query results
      * Hat Tip: Most Commented Widget <http://plugins.trac.wordpress.org/browser/most-commented/trunk/most-commented.php?rev=248712#L56>
      */
     if (!($output = wp_cache_get($widget_id))) {
         /**
          * Initiate the output
          * and the post_output
          */
         $output = '';
         $post_output = '';
         /**
          * We get the category here
          * as of v1.1.0 we support current category
          * If current category is selected and this is home page then no widget is shown
          */
         if ($instance['cat_id'] == -1) {
             //We return if this is not a single post page. So, no widget for this
             if (!is_single() && !is_category()) {
                 return;
             }
             if (is_single()) {
                 $wp_cpl_cat = get_the_category();
                 //Although there wont be such case, but still for safety.
                 if (!$wp_cpl_cat[0]->cat_ID) {
                     return;
                 }
                 //This returns the widget function. So no widget is created
                 $cat_id = (int) $wp_cpl_cat[0]->cat_ID;
             } else {
                 $wp_cpl_cat = get_query_var('cat');
                 $cat_id = (int) $wp_cpl_cat;
             }
             unset($wp_cpl_cat);
         } else {
             $cat_id = (int) $instance['cat_id'];
         }
         /**
          * A new instance of the output class
          */
         $i = 0;
         include_once itgdb_wp_cpl_loader::$abs_path . '/includes/wp_cpl_output_gen.php';
         $out_class = new itgdb_wp_cpl_output_gen();
         $post_output = $out_class->widget_output_gen($instance, $cat_id, $i);
         /**
          * Done the Loop
          * Now add the main widget data to the output
          */
         /** The themes before widget */
         $output .= $before_widget;
         /** The title with parameters */
         //%widget_num%/%cat_count% of %cat_name%
         $wp_cpl_cat_info = get_category($cat_id);
         $title = str_ireplace(array('%widget_num%', '%cat_count%', '%cat_name%'), array($i, $wp_cpl_cat_info->count, $wp_cpl_cat_info->name), $instance['title']);
         $title = apply_filters('widget_title', $title);
         /** Add hyperlink to the title if active */
         if (true == $instance['title_hyper']) {
             $title = '<a href="' . get_category_link($instance['cat_id']) . '">' . $title . '</a>';
         }
         $output .= $before_title . $title . $after_title;
         /**
          * Set the USER made before, after widget
          */
         if (false == $instance['list_style']) {
             $before_main_widget = '' != $instance['before_main_widget'] ? $instance['before_main_widget'] : '<ul class="%widget_class%">';
             $after_main_widget = '' != $instance['after_main_widget'] ? $instance['after_main_widget'] : '</ul>';
         } else {
             $before_main_widget = '<ul class="%widget_class%">';
             $after_main_widget = '</ul>';
         }
         /**
          * Now apply the class to the widget
          */
         $wp_cpl_widget_class = '' != $instance['widget_class'] ? 'wp-cpl-widget ' . $instance['widget_class'] . ' wp-cpl-theme-' . $instance['css_theme'] : 'wp-cpl-widget' . ' wp-cpl-theme-' . $instance['css_theme'];
         $before_main_widget = str_ireplace('%widget_class%', $wp_cpl_widget_class, $before_main_widget);
         /**
          * Wrap the $post_output with the before and after user widget html
          * for the $output we have upto the title
          */
         $post_output = $before_main_widget . $post_output . $after_main_widget;
         /**
          * Add the teaser if present
          */
         if ('' != $instance['teaser']) {
             $teaser = str_ireplace(array('%widget_num%', '%cat_count%', '%cat_name%'), array((int) $i, (int) itgdb_wp_cpl_loader::wp_get_postcount($cat_id), $wp_cpl_cat_info->name), $instance['teaser']);
             $post_output .= '<p class="wp-cpl-teaser">' . $teaser . '</p>';
         }
         /**
          * Check to see if feed syndication is active
          * Now, user can put their custom html
          * @since v1.1.0
          */
         if (true == $instance['show_feed'] && '' != $instance['feed_html']) {
             $post_output .= '<p class="wp-cpl-feed-subs"><a href="' . get_category_feed_link($cat_id) . '">' . $instance['feed_html'] . '</a></p>';
         }
         /**
          * Add the read more thing
          * Here also user can select whether or not to show the link
          * and provide custom html
          * @since v1.1.0
          */
         if (true == $instance['show_read_more'] && '' != $instance['read_more_html']) {
             $post_output .= '<p class="wp-cpl-read-more"><a href="' . get_category_link($cat_id) . '" title="' . $wp_cpl_cat_info->description . '">' . $instance['read_more_html'] . '</a></p>';
         }
         /**
          * Done all the dynamic things
          * Now add the post_output to output and close the theme's widget
          */
         $output .= $post_output;
         $output .= $after_widget;
         /**
          * Final free up of memory
          */
         unset($post_output);
         unset($wp_cpl_cat_info);
         /**
          * Cache it for future use
          */
         wp_cache_set($widget_id, $output, '', 18);
     }
     echo $output;
 }