. ****/ // LOCALISATION add_action('init', 'archivesCalendar_init'); function archivesCalendar_init() { load_plugin_textdomain('archives_calendar', false, dirname(plugin_basename(__FILE__))); } // ACTIVATION function archivesCalendar_activation($network_wide){ global $wpdb; if (isMU()){ //isMU verifyes id the site is in Multisite mode // check if it is a network activation - if so, run the activation function for each blog id if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) { $old_blog = $wpdb->blogid; // Get all blog ids $blogids = $wpdb->get_results("SELECT blog_id FROM $wpdb->blogs"); foreach ($blogids as $blogid) { $blog_id = $blogid->blog_id; switch_to_blog($blog_id); _archivesCalendar_activate(); } switch_to_blog($old_blog); return; } } _archivesCalendar_activate(); } function _archivesCalendar_activate(){ global $wpdb; if(!get_option( 'archivesCalendar' )) $options = array("css" => 1, "theme" => "default", "jquery" => 0, "js" => 1, "show_settings" => 1, "shortcode" => 0); else $options = get_option( 'archivesCalendar' ); if(isMU()) { update_blog_option($wpdb -> blogid, 'archivesCalendar', $options); add_blog_option($wpdb -> blogid, 'archivesCalendar', $options); } else { update_option('archivesCalendar', $options); add_option('archivesCalendar', $options); } } register_activation_hook(__FILE__, 'archivesCalendar_activation'); function archivesCalendar_new_blog($blog_id) { global $wpdb; if (is_plugin_active_for_network('archives-calendar/archives-calendar.php')) { $old_blog = $wpdb->blogid; switch_to_blog($blog_id); _archivesCalendar_activate(); switch_to_blog($old_blog); } } add_action( 'wpmu_new_blog', 'archivesCalendar_new_blog', 10, 6); // in case of creation of a new site in WPMU // UNINSTALL function archivesCalendar_uninstall(){ global $wpdb; if (isMU()) { $old_blog = $wpdb->blogid; $blogids = $wpdb->get_results("SELECT blog_id FROM $wpdb->blogs"); foreach ($blogids as $blogid) { $blog_id = $blogid->blog_id; switch_to_blog($blog_id); _archivesCalendar_uninstall(); } switch_to_blog($old_blog); return; } _archivesCalendar_uninstall(); } function _archivesCalendar_uninstall(){ global $wpdb; if (isMU()) delete_blog_option($wpdb->blogid, 'archivesCalendar'); else delete_option('archivesCalendar'); } register_uninstall_hook(__FILE__, 'archivesCalendar_uninstall'); // ADD Settings link in Plugins page when the plugin is activated if(!function_exists('plugin_settings_link')){ function plugin_settings_link($links) { $settings_link = ''.__( 'Settings' ).''; array_unshift($links, $settings_link); return $links; } } $acplugin = plugin_basename( __FILE__ ); add_filter( "plugin_action_links_$acplugin", 'plugin_settings_link' ); $archivesCalendar_options = get_option('archivesCalendar'); function archivesCalendar_jquery() { wp_enqueue_script('jquery'); } function calendar_archives_js() { ?> __( 'Show archives as calendar', 'archives_calendar' ), ) ); } public function widget( $args, $instance ) { extract( $args ); $title = apply_filters( 'widget_title', $instance['title'] ); echo $before_widget; if ( ! empty( $title ) ) echo $before_title . $title . $after_title; $instance['function'] = 'no'; echo archive_calendar($instance); echo $after_widget; } public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['prev_text'] = $new_instance['prev_text']; $instance['next_text'] = $new_instance['next_text']; $instance['post_count'] = $new_instance['post_count']; return $instance; } public function form( $instance ) { $defaults = array( 'title' => __( 'Archives' ), 'next_text' => '>', 'prev_text' => '<', 'post_count' => 1, ); $instance = wp_parse_args( (array) $instance, $defaults ); $title = $instance['title']; $prev = $instance['prev_text']; $next = $instance['next_text']; $count = $instance['post_count']; ?>

'>', 'prev_text' => '<', 'post_count' => true, ); $args = wp_parse_args( (array) $args, $defaults ); extract($args); $results = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month FROM $wpdb->posts WHERE post_type='post' AND post_status='publish' AND post_password='' ORDER BY year DESC, month DESC"); $years = array(); foreach ($results as $date) { if($post_count){ $postcount = $wpdb->get_results("SELECT COUNT(ID) AS count FROM $wpdb->posts WHERE post_type='post' AND post_status='publish' AND post_password='' AND YEAR(post_date) = $date->year AND MONTH(post_date) = $date->month"); $count = $postcount[0]->count; } else $count = 0; $years[$date->year][$date->month] = $count; } $totalyears = count($years); $yearNb = array(); foreach ($years as $year => $months){ $yearNb[] = $year; } if(is_archive()){ global $post; $archiveYear = date('Y', strtotime($post->post_date)); // year to be visible } else $archiveYear = $yearNb[0]; // if no current year -> show the more recent $nextyear = ($totalyears > 1) ? ''.$next_text.'' : ''; $prevyear = ($totalyears > 1) ? ''.$prev_text.'' : ''; $cal = "\n\n"; $cal.= '
'; $cal.= '
'.$prevyear.'
'; $cal .= ''.$archiveYear.''; $cal .= '
'; $i=0; foreach( $yearNb as $year ){ $current = ($archiveYear == $year) ? " current" : ""; $cal.= ''.$year.''; $i++; } $cal.= '
'; if ($totalyears > 1) $cal.= '
'; $cal.= '
'.$nextyear.'
'; $cal.= '
'; $i=0; foreach ($years as $year => $months){ $lastyear = ($i == $totalyears-1 ) ? " last" : ""; $current = ($archiveYear == $year) ? " current" : ""; $cal .= '
'; for ( $month = 1; $month <= 12; $month++ ) { $last = ( $month%4 == 0 ) ? ' last' : ''; if($post_count) { if(isset($months[$month])) $count = $months[$month]; else $count = 0; $posts_text = ($count == 1) ? __('Post', 'archives_calendar') : __('Posts', 'archives_calendar'); $postcount = ''.$count.' '.$posts_text.''; } else $postcount = ""; if(isset($months[$month])) $cal .= ''; else $cal .= '
'.$mnames[$month].''.$postcount.'
'; } $cal .= "
\n"; $i++; } $cal .= "
"; if($function == "no") return $cal; else echo $cal; } /***** SHORTCODE *****/ if($archivesCalendar_options['shortcode']){ add_filter( 'widget_text', 'shortcode_unautop'); add_filter('widget_text', 'do_shortcode'); } function archivesCalendar_shortcode( $atts ) { extract( shortcode_atts( array( 'next_text' => '>', 'prev_text' => '<', 'post_count' => true, ), $atts ) ); $post_count = ($post_count == "true") ? true : false; $defaults = array( 'next_text' => $next_text, 'prev_text' => $prev_text, 'post_count' => $post_count, 'function' => 'no', ); return archive_calendar($defaults); } add_shortcode( 'arcalendar', 'archivesCalendar_shortcode' ); /***** SETTINGS ******/ function archivesCalendar_admin_init(){ register_setting( 'archivesCalendar_options', 'archivesCalendar', 'archivesCalendar_options_validate' ); add_settings_section('archivesCalendar_main', '', 'archivesCalendar_options', 'archivesCalendar_plugin'); } add_action('admin_init', 'archivesCalendar_admin_init'); function ArchivesCalandarSettingsMenu() { global $archivesCalendar_options; if($archivesCalendar_options['show_settings'] == 1) $menu_name = 'Archives Calendar'; else $menu_name = ''; add_options_page('Archives Calendar Settings', $menu_name, 'manage_options', 'archives_calendar', 'archives_calendar_settings'); } function archivesCalendar_options_validate($args) { if(!isset($args['show_settings'])) $args['show_settings'] = 0; else $args['show_settings'] = 1; if(!isset($args['css'])) $args['css'] = 0; else $args['css'] = 1; if(!isset($args['theme'])) $args['theme'] = "default"; if(!isset($args['jquery'])) $args['jquery'] = 0; else $args['jquery'] = 1; if(!isset($args['js'])) $args['js'] = 0; else $args['js'] = 1; if(!isset($args['shortcode'])) $args['shortcode'] = 0; else $args['shortcode'] = 1; return $args; } function archives_calendar_settings(){?>

/>
It\'s recommended to copy the CSS code to your theme´s style.css and uncheck this option.', 'archives_calendar' ); ?>

:
NOTE: if you have modified any plugin's CSS file it will be restored on next plugin update.", 'archives_calendar' ); ?>

/>
jQuery library is required.', 'archives_calendar');?>

/>
Uncheck only if you copy this code into your default .js file.', 'archives_calendar'); ?>


/>

[arcalendar next_text=">" prev_text="<" post_count="true"]


/>


item; $count = count($items); } else $count = 0; if($count > 0): ?>

RSS feed

pubDate); echo '

'; echo ''; echo ''.$item->title.''; echo '

'; } $i++; } if($count > 3){ $cat_url = 'http://labs.alek.be/category/archives-calendar/'; echo '

'; echo ''. __('More') .' ...'; echo '

'; } if($count <= 0) _e( 'No posts', 'acategory' ); ?>

GitHub
WordPress Plugins
Labs by alek´

alek.be



support my work, buy me a beer or a coffee. Click Donate and specify your amount.', 'acategory');?>

Donate