. **************************************************************************/ // Seems some themes bundle this plugin and then users install it, // resulting in double output. This should be avoided, so use a global. if ( !isset($cleanarchivesreloaded) ) $cleanarchivesreloaded = false; class CleanArchivesReloaded { # Configuration has been moved to the new options page at Settings -> Clean Archives. # You can also set the configuration via the shortcode tag. var $version = '3.2.0'; // Class initialization function CleanArchivesReloaded() { if ( !function_exists('add_shortcode') ) return; // Load up the localization file if we're using WordPress in a different language // Place it in this plugin's "languages" folder and name it "car-[value in wp-config].mo" load_plugin_textdomain( 'clean-archives-reloaded', false, '/clean-archives-reloaded/languages' ); // Make sure all the plugin options have defaults set if ( FALSE === get_option('car_usejs') ) add_option( 'car_usejs', 1 ); if ( FALSE === get_option('car_monthorder') ) add_option( 'car_monthorder', 'new' ); if ( FALSE === get_option('car_postorder') ) add_option( 'car_postorder', 'new' ); if ( FALSE === get_option('car_dynamicload') ) add_option( 'car_dynamicload', null ); // Register all the hooks add_action( 'admin_menu', array(&$this, 'AddAdminMenu') ); add_shortcode( 'cleanarchivesreloaded' , array(&$this, 'PostList') ); add_shortcode( 'cartotalposts' , array(&$this, 'PostCount') ); add_filter( 'widget_text', 'do_shortcode', 11 ); // For the text widget // Hook into wp_head early so we can potentially look for posts add_action( 'wp_head', array(&$this, 'MaybeEnqueueCSSJavascript'), 1 ); // For users with a persistent object caching plugin installed, we need to dump the cache in some cases add_action( 'save_post', array(&$this, 'DeleteCache') ); add_action( 'edit_post', array(&$this, 'DeleteCache') ); add_action( 'delete_post', array(&$this, 'DeleteCache') ); } // Register the admin menu function AddAdminMenu() { add_options_page( __('Clean Archives Reloaded', 'clean-archives-reloaded'), __('Clean Archives', 'clean-archives-reloaded'), 'manage_options', 'clean-archives-reloaded', array(&$this, 'OptionsPage') ); } // The options page for this plugin function OptionsPage() { ?>



posts) || empty($wp_query->posts) ) return; // Loop through each post looking for the shortcode foreach ( $wp_query->posts as $post ) { if ( false !== stripos( $post->post_content, '[cleanarchivesreloaded') || false !== stripos( $post->post_content, '[cartotalposts') ) { wp_enqueue_script( 'jquery' ); add_action( 'wp_head', array(&$this, 'OutputCSSJavascript') ); // Even though we're in wp_head right now, default of 10 is greater than 1 return; } } } // Else load regardless else { wp_enqueue_script( 'jquery' ); add_action( 'wp_head', array(&$this, 'OutputCSSJavascript') ); // Even though we're in wp_head right now, default of 10 is greater than 1 } } // Output a little helper CSS and the Javascript for the plugin // Based on code from http://www.learningjquery.com/2007/03/accordion-madness function OutputCSSJavascript() { global $cleanarchivesreloaded; if ( !empty($cleanarchivesreloaded) ) return; $cleanarchivesreloaded = true; ?> get_results( "SELECT ID, post_date, post_date_gmt, comment_status, comment_count FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND post_password = ''" ); // Loop through each post and sort it into a structured array foreach( $rawposts as $post ) { $posts[ mysql2date( 'Y.m', $post->post_date ) ][] = $post; } $rawposts = null; // More memory cleanup // Store the results into the WordPress cache wp_cache_set( 'posts', $posts, 'clean-archives-reloaded' ); return $posts; } // Generates the HTML output based on $atts array from the shortcode function PostList( $atts = array() ) { global $wp_locale; // Set any missing $atts items to the defaults $atts = shortcode_atts(array( 'usejs' => get_option('car_usejs'), 'monthorder' => get_option('car_monthorder'), 'postorder' => get_option('car_postorder'), 'postcount' => '1', 'commentcount' => '1', ), $atts); // Get the big array of all posts $posts = $this->GetPosts(); // Sort the months based on $atts ( 'new' == $atts['monthorder'] ) ? krsort( $posts ) : ksort( $posts ); // Sort the posts within each month based on $atts foreach( $posts as $key => $month ) { $sorter = array(); foreach ( $month as $post ) $sorter[] = $post->post_date_gmt; $sortorder = ( 'new' == $atts['postorder'] ) ? SORT_DESC : SORT_ASC; array_multisort( $sorter, $sortorder, $month ); $posts[$key] = $month; unset($month); } // Generate the HTML $html = '
'. "\n"; if ( 1 == $atts['usejs'] ) $html .= '' . __('Expand All', 'clean-archives-reloaded') . "\n\n"; $html .= '\n
\n"; return $html; } // Returns the total number of posts function PostCount() { $num_posts = wp_count_posts( 'post' ); return number_format_i18n( $num_posts->publish ); } // Deletes the cached filtered posts array for users using a persistent caching plugin function DeleteCache() { wp_cache_delete( 'posts', 'clean-archives-reloaded' ); } } // Start this plugin once all other plugins are fully loaded add_action( 'init', create_function( '', 'global $CleanArchivesReloaded; $CleanArchivesReloaded = new CleanArchivesReloaded();' ) ); // Some backwards compatibility wrapper functions function car_total_posts() { global $CleanArchivesReloaded; return $CleanArchivesReloaded->PostCount(); } function clean_archives_reloaded() { global $CleanArchivesReloaded; echo $CleanArchivesReloaded->PostList(); } function car_regenerate() { return FALSE; } ?>