'', ); /** * PHP5 constructor */ function __construct() { // set option values $this->_set_options(); // add actions add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_actions' ) ); add_action( 'admin_init', array( $this, 'admin_init' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'archive_admin_js_scripts' ) ); add_action( 'wp_head', array( $this, 'plugin_head_inject' ) ); add_action( 'plugins_loaded', array( $this, 'annual_archive_load_textdomain' ) ); // add shortcode add_shortcode('archives', array($this, 'shortcode')); add_shortcode('arcpromat', array($this, 'shortcode')); // add filters add_filter( 'widget_text', 'do_shortcode' ); add_filter( 'query_vars', array($this, 'annual_archive_query_vars') ); add_filter( 'pre_get_posts', array($this, 'annual_archive_decade_filter') ); add_filter( 'get_the_archive_title', array($this, 'annual_archive_decade_title') ); } // load text domain for translations function annual_archive_load_textdomain() { load_plugin_textdomain( 'anual-archive' ); } // Add decade to the query args function annual_archive_query_vars($vars) { $vars[] = 'decade'; return $vars; } //check for decade query var function annual_archive_decade_filter( $query ) { if ( $query->is_main_query() && $query->is_archive() ){ $decade = get_query_var( 'decade' ); if( !empty($decade) ){ $start = $decade.'-01-01'; $end = ($decade+9).'-12-31'; $query->set('year', ''); $query->set( 'date_query', array ( 'after' => $start, 'before' => $end, 'inclusive' => true, ) ); } } } //modify the title function annual_archive_decade_title($title) { $decade = get_query_var( 'decade' ); if(!empty($decade)){ $title = __('The').' '.$decade.'\'s'; } return $title; } //plugin header inject function plugin_head_inject(){ // custom css if( !empty( $this->options['custom_css'] ) ){ echo "\n\n"; } } /** * Callback admin_menu */ function admin_menu() { if ( function_exists( 'add_options_page' ) AND current_user_can( 'manage_options' ) ) { // add options page $options_page = add_options_page($this->plugin_options_page_title, $this->plugin_options_menue_title, 'manage_options', $this->plugin_options_slug, array( $this, 'options_page' )); } } /** * Callback admin_init */ function admin_init() { // register settings register_setting( $this->domain, $this->options_name ); } //load scripts on the widget admin page function archive_admin_js_scripts($hook){ global $pagenow; if( $hook == 'widgets.php' && $pagenow != 'customize.php'){ $plugin_url = plugins_url() .'/'. dirname( plugin_basename(__FILE__) ); wp_register_script('archive-admin-script', $plugin_url.'/js/widget_form.js', array ('jquery'), '0.2', true); wp_enqueue_script('archive-admin-script'); } } /** * Advaned wp_get_archives * adds the ability to order alpha and postbypost Archives * adds archive by decade **/ static function wp_get_archives_advanced( $args = '' ) { global $wpdb, $wp_locale; $defaults = array( 'type' => 'yearly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC', 'alpha_order' => 'ASC', 'post_order' => 'DESC', 'post_type' => 'post', ); $r = wp_parse_args( $args, $defaults ); $post_type_object = get_post_type_object( $r['post_type'] ); if ( ! is_post_type_viewable( $post_type_object ) ) { return; } $r['post_type'] = $post_type_object->name; if ( '' == $r['type'] ) { $r['type'] = 'yearly'; } if ( ! empty( $r['limit'] ) ) { $r['limit'] = absint( $r['limit'] ); $r['limit'] = ' LIMIT ' . $r['limit']; } $order = strtoupper( $r['order'] ); if ( $order !== 'ASC' ) { $order = 'DESC'; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] ); /** * Filters the SQL WHERE clause for retrieving archives. * * @since 2.2.0 * * @param string $sql_where Portion of SQL query containing the WHERE clause. * @param array $r An array of default arguments. */ $where = apply_filters( 'getarchives_where', $sql_where, $r ); /** * Filters the SQL JOIN clause for retrieving archives. * * @since 2.2.0 * * @param string $sql_join Portion of SQL query containing JOIN clause. * @param array $r An array of default arguments. */ $join = apply_filters( 'getarchives_join', '', $r ); $output = ''; $last_changed = wp_cache_get_last_changed( 'posts' ); $limit = $r['limit']; if ( 'monthly' == $r['type'] ) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit"; $key = md5( $query ); $key = "wp_get_archives_advanced:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); } if ( $results ) { $after = $r['after']; foreach ( (array) $results as $result ) { $url = get_month_link( $result->year, $result->month ); if ( 'post' !== $r['post_type'] ) { $url = add_query_arg( 'post_type', $r['post_type'], $url ); } /* translators: 1: month name, 2: 4-digit year */ $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year ); if ( $r['show_post_count'] ) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); } } } elseif ( 'yearly' == $r['type'] ) { $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit"; $key = md5( $query ); $key = "wp_get_archives_advanced:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); } if ( $results ) { $after = $r['after']; foreach ( (array) $results as $result ) { $url = get_year_link( $result->year ); if ( 'post' !== $r['post_type'] ) { $url = add_query_arg( 'post_type', $r['post_type'], $url ); } $text = sprintf( '%d', $result->year ); if ( $r['show_post_count'] ) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); } } } elseif ( 'daily' == $r['type'] ) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit"; $key = md5( $query ); $key = "wp_get_archives_advanced:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); } if ( $results ) { $after = $r['after']; foreach ( (array) $results as $result ) { $url = get_day_link( $result->year, $result->month, $result->dayofmonth ); if ( 'post' !== $r['post_type'] ) { $url = add_query_arg( 'post_type', $r['post_type'], $url ); } $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth ); $text = mysql2date( get_option( 'date_format' ), $date ); if ( $r['show_post_count'] ) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); } } } elseif ( 'weekly' == $r['type'] ) { $week = _wp_mysql_week( '`post_date`' ); $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit"; $key = md5( $query ); $key = "wp_get_archives_advanced:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); } $arc_w_last = ''; if ( $results ) { $after = $r['after']; foreach ( (array) $results as $result ) { if ( $result->week != $arc_w_last ) { $arc_year = $result->yr; $arc_w_last = $result->week; $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) ); $arc_week_start = date_i18n( get_option( 'date_format' ), $arc_week['start'] ); $arc_week_end = date_i18n( get_option( 'date_format' ), $arc_week['end'] ); $url = add_query_arg( array( 'm' => $arc_year, 'w' => $result->week, ), home_url( '/' ) ); if ( 'post' !== $r['post_type'] ) { $url = add_query_arg( 'post_type', $r['post_type'], $url ); } $text = $arc_week_start . $archive_week_separator . $arc_week_end; if ( $r['show_post_count'] ) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); } } } } elseif ( 'decade' == $r['type'] ) { $query = "SELECT count(*), decade, decade + 9 FROM (SELECT FLOOR(YEAR(post_date) / 10) * 10 AS decade FROM $wpdb->posts $join $where) t GROUP BY decade $order $limit"; $key = md5( $query ); $key = "wp_get_archives_advanced:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); } if ( $results ) { $after = $r['after']; foreach ( (array) $results as $result ) { $url = get_year_link($result->decade).'?decade='.$result->decade; if ( 'post' !== $r['post_type'] ) { $url = add_query_arg( 'post_type', $r['post_type'], $url ); } $text = sprintf( '%d\'s', $result->decade ); if ( $r['show_post_count'] ) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); } } } elseif ( ( 'postbypost' == $r['type'] ) || ( 'alpha' == $r['type'] ) ) { $alpha_order = strtoupper( $r['alpha_order'] ); if ( $alpha_order !== 'ASC' ) { $alpha_order = 'DESC'; } $post_order = strtoupper( $r['post_order'] ); if ( $post_order !== 'DESC' ) { $post_order = 'ASC'; } $orderby = ( 'alpha' == $r['type'] ) ? 'post_title '.$alpha_order. ' ' : 'post_date '.$post_order.', ID DESC '; $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; $key = md5( $query ); $key = "wp_get_archives_advanced:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); } if ( $results ) { foreach ( (array) $results as $result ) { if ( $result->post_date != '0000-00-00 00:00:00' ) { $url = get_permalink( $result ); if ( $result->post_title ) { /** This filter is documented in wp-includes/post-template.php */ $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) ); } else { $text = $result->ID; } $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); } } } } if ( $r['echo'] ) { echo $output; } else { return $output; } } /** * Callback shortcode */ function shortcode($atts, $content = null){ extract(shortcode_atts(array( 'type' => 'yearly', 'limit' => '', 'format' => 'html', //html, option, link 'before' => '', 'after' => '', 'showcount' => '0', 'tag' => 'ul', 'order' => 'DESC', 'alpha_order' => 'ASC', 'post_order' => 'DESC', 'select_text' => '', 'post_type' => 'post', ), $atts)); if ($format == 'option') { if( !empty($select_text) ){ $dtitle = $select_text; } else{ $dtitle = __('Select Year', 'anual-archive'); if ($type == 'monthly'){ $dtitle = __('Select Month', 'anual-archive'); } else if($type == 'weekly'){ $dtitle = __('Select Week', 'anual-archive'); } else if($type == 'daily'){ $dtitle = __('Select Day', 'anual-archive'); } else if($type == 'postbypost' || $type == 'alpha'){ $dtitle = __('Select Post', 'anual-archive'); } } $arc = ''; } else { $arc = '<'.$tag.'>'; $arch_arr = array( 'type' => $type, 'limit' => $limit, 'format' => $format, 'before' => $before, 'after' => $after, 'show_post_count' => $showcount, 'post_type' => $post_type, 'order' => $order, 'alpha_order' => $alpha_order, 'post_order' => $post_order, 'echo' => 0 ); $arc .= WP_Plugin_Annual_Archive::wp_get_archives_advanced($arch_arr); $arc .= ''.$tag.'>'; } return $arc; } // Add link to options page from plugin list function plugin_actions($links) { $new_links = array(); $new_links[] = '' . __('Settings', 'anual-archive') . ''; return array_merge($new_links, $links); } /** * Admin options page */ function options_page() { $like_it_arr = array( __('really tied the room together', 'anual-archive'), __('made you feel all warm and fuzzy on the inside', 'anual-archive'), __('restored your faith in humanity... even if only for a fleeting second', 'anual-archive'), __('rocked your world', 'provided a positive vision of future living', 'anual-archive'), __('inspired you to commit a random act of kindness', 'anual-archive'), __('encouraged more regular flossing of the teeth', 'anual-archive'), __('helped organize your life in the small ways that matter', 'anual-archive'), __('saved your minutes--if not tens of minutes--writing your own solution', 'anual-archive'), __('brightened your day... or darkened if if you are trying to sleep in', 'anual-archive'), __('caused you to dance a little jig of joy and joyousness', 'anual-archive'), __('inspired you to tweet a little @twinpictues social love', 'anual-archive'), __('tasted great, while also being less filling', 'anual-archive'), __('caused you to shout: "everybody spread love, give me some mo!"', 'anual-archive'), __('helped you keep the funk alive', 'anual-archive'), __('soften hands while you do dishes', 'anual-archive'), __('helped that little old lady find the beef', 'anual-archive') ); $rand_key = array_rand($like_it_arr); $like_it = $like_it_arr[$rand_key]; ?>
> /> DESC /> ASC
> /> DESC /> ASC
> /> DESC /> ASC