'F', 'show_count' => 'Y', 'delimiter' => '' ); // Set the default options public function action_plugin_activation( $file ) { if ( realpath( $file ) == __FILE__ ) { $this->class_name = strtolower( get_class( $this ) ); $this->cache_name = Site::get_url( 'host' ) . ':' . $this->class_name; foreach ( $this->default_options as $name => $value ) { $current_value = Options::get( $this->class_name . '__' . $name ); if ( !isset( $current_value) ) { Options::set( $this->class_name . '__' . $name, $value ); } } } } public function action_plugin_deactivation( $file ) { if ( realpath( $file ) == __FILE__ ) { Cache::expire( $this->cache_name ); } } public function action_init() { $this->class_name = strtolower( get_class( $this ) ); $this->cache_name = Site::get_url( 'host' ) . ':' . $this->class_name; foreach ( $this->default_options as $name => $unused ) { $this->config[$name] = Options::get( $this->class_name . '__' . $name ); } } public function filter_plugin_config( $actions, $plugin_id ) { if ( $plugin_id == $this->plugin_id() ) { $actions[] = _t( 'Configure' ); $actions[] = _t( 'Clear Cache' ); } return $actions; } public function action_plugin_ui( $plugin_id, $action ) { if ( $plugin_id == $this->plugin_id() ) { switch ( $action ) { case _t( 'Configure' ): $ui = new FormUI( $this->class_name ); $display_month = $ui->append( 'select', 'display_month', 'option:' . $this->class_name . '__display_month', _t( 'Month displayed as' ) ); $display_month->options = array( '' => '', 'F' => 'Full name', 'A' => 'Abbreviation', 'N' => 'Number' ); $show_count = $ui->append( 'select', 'show_count', 'option:' . $this->class_name . '__show_count', _t( 'Show Monthly Entries Count?' ) ); $show_count->options = array( '' => '', 'Y' => 'Yes', 'N' => 'No' ); $show_count->add_validator( 'validate_required' ); $delimiter = $ui->append( 'text', 'delimiter', 'option:' . $this->class_name . '__delimiter', _t( 'Delimiter to separate day and post title in detail view (optional)' ) ); $ui->append( 'submit', 'save', _t( 'Save' ) ); $ui->set_option( 'success_message', _t( 'Configuration saved' ) ); $ui->on_success( array( $this, 'updated_config' ) ); $ui->out(); break; case _t( 'Clear Cache' ): Cache::expire( $this->cache_name ); echo '

' . _t( 'Cache has been cleared.' ) . '

'; break; } } } public function updated_config( $ui ) { $ui->save(); Cache::expire( $this->cache_name ); return false; } public function theme_monthly_archives( $theme, $num_month = 0, $detail_view = 'Y' ) { if ( array_key_exists( $num_month, $this->cache ) ) { if ( Cache::has( $this->cache[$num_month] ) ) { $monthly_archives = Cache::get( $this->cache[$num_month] ); } else { $monthly_archives = $this->get_monthly_archives( $num_month, $detail_view ); Cache::set( $this->cache[$num_month], $monthly_archives ); } } else { $monthly_archives = $this->get_monthly_archives( $num_month, $detail_view ); $this->cache[$num_month] = Site::get_url( 'host' ) . ':' . $this->class_name . ':' . $num_month; Cache::set( $this->cache[$num_month], $monthly_archives ); } return $monthly_archives; } public function action_post_update_status( $post, $old_value, $new_value ) { if ( ( Post::status_name( $old_value ) == 'published' && Post::status_name( $new_value ) != 'published' ) || ( Post::status_name( $old_value ) != 'published' && Post::status_name( $new_value ) == 'published' ) ) { Cache::expire( $this->cache_name ); } } public function action_post_update_slug( $post, $old_value, $new_value ) { if ( Post::status_name( $post->status ) == 'published' ) { Cache::expire( $this->cache_name ); } } public function action_post_update_title( $post, $old_value, $new_value ) { if ( Post::status_name( $post->status ) == 'published' ) { Cache::expire( $this->cache_name ); } } public function action_post_delete_after( $post ) { if ( Post::status_name( $post->status ) == 'published' ) { Cache::expire( $this->cache_name ); } } private function get_monthly_archives( $num_month, $detail_view ) { $post_type = Post::type( 'entry' ); $post_status = Post::status( 'published' ); $monthly_archives = ''; $limit = ( empty( $num_month ) ? '' : "LIMIT {$num_month}" ); $sql = " SELECT YEAR(FROM_UNIXTIME(pubdate)) AS year, MONTH(FROM_UNIXTIME(pubdate)) AS month, COUNT(p.id) AS cnt FROM {posts} p WHERE p.content_type = {$post_type} AND p.status = {$post_status} GROUP BY year, month ORDER BY year DESC, month DESC {$limit}"; $yr_mths = DB::get_results( $sql ); $monthly_archives.= "\n"; return $monthly_archives; } } ?>