%POST_THUMBNAIL|50x50%
%DATE% by %AUTHOR%
Filed as: %CATEGORIES|, % '); define( 'PA_TEMPLATE_BEFORE_DEFAULT', ' ' ); define( 'PA_TEMPLATE_AFTER_DEFAULT', '
Thumb Title
' ); function archivist_options() { $template = get_option( 'archivist_template', PA_TEMPLATE_DEFAULT ); $css = get_option( 'archivist_css', PA_CSS_DEFAULT ); $template_before = get_option( 'archivist_template_before', PA_TEMPLATE_BEFORE_DEFAULT ); $template_after = get_option( 'archivist_template_after', PA_TEMPLATE_AFTER_DEFAULT ); ?>



%TITLE%
-
%PERMALINK%
-
%AUTHOR%
-
%CATEGORIES%
-
%CATEGORIES|...%
- %CATEGORIES|, %', 'archivist' ) ?>
%TAGS%
-
%TAGS|...%
- %TAGS|, %', 'archivist' ) ?>
%EXCERPT%
-
%POST_META|...%
- %POST_META|duration%', 'archivist' ) ?>
%DATE%
-
%DATE|...%
- %DATE|Y/m/d%', 'archivist' ) ?>
%POST_THUMBNAIL|...x...%
- %POST_THUMBNAIL|75x75%', 'archivist' ) ?>
%COMMENTS%
-

load_textdomain(); add_shortcode( 'archivist', array( $this, 'shortcode' ) ); add_action( 'admin_menu', array( $this, 'add_menu_entry' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); } public function shortcode( $atts ) { extract( shortcode_atts( array( 'query' => '', 'category' => '', 'tag' => '', ), $atts ) ); if ( $query !== '' ) { return $this->display_by_query( $query ); } elseif ( $category !== '' ) { return $this->display_by_category( $category ); } else { return $this->display_by_tag( $tag ); } } public function register_settings() { register_setting( 'archivist-option-group', 'archivist_template' ); register_setting( 'archivist-option-group', 'archivist_template_before' ); register_setting( 'archivist-option-group', 'archivist_template_after' ); register_setting( 'archivist-option-group', 'archivist_css' ); } public function add_menu_entry() { add_submenu_page( 'options-general.php', 'Archivist', 'Archivist', 'edit_post', 'archivist_options_handle', 'archivist_options' ); } function render_element( $post, $template ) { $template = str_replace( '%AUTHOR%', get_the_author(), $template ); $template = str_replace( '%CATEGORIES%', get_the_category_list(), $template ); $template = str_replace( '%TAGS%', get_the_tag_list(), $template ); $template = str_replace( '%DATE%', get_the_date(), $template ); $template = str_replace( '%TITLE%', get_the_title(), $template ); $template = str_replace( '%PERMALINK%', get_permalink(), $template ); $template = str_replace( '%EXCERPT%', get_the_excerpt(), $template ); $template = str_replace( '%COMMENTS%', get_comments_number(), $template ); // categories with custom separator $template = preg_replace_callback( '/%TAGS\|(.*)%/', create_function( '$matches', 'return get_the_tag_list( "", $matches[1], "" );' ), $template ); // categories with custom separator $template = preg_replace_callback( '/%CATEGORIES\|(.*)%/', create_function( '$matches', 'return get_the_category_list( $matches[1] );' ), $template ); // custom post meta $template = preg_replace_callback( '/%POST_META\|(.*)%/', create_function( '$matches', 'global $post; return get_post_meta( $post->ID, "$matches[1]", true );' ), $template ); // custom date format $template = preg_replace_callback( '/%DATE\|(.*)%/', create_function( '$matches', 'return get_the_date($matches[1]);' ), $template ); // custom post thumbnails $template = preg_replace_callback( '/%POST_THUMBNAIL\|(\d+)x(\d+)%/', create_function( '$matches', 'return get_the_post_thumbnail( $post->ID, array( $matches[1], $matches[2] ) );' ), $template ); return $template; } public function display_by_category( $category ) { $parameters = array( 'posts_per_page' => -1, 'category_name' => $category ); $loop = new WP_Query( $parameters ); return $this->display_by_loop( $loop ); } public function display_by_tag( $tag ) { $parameters = array( 'posts_per_page' => -1, 'tag' => $tag ); $loop = new WP_Query( $parameters ); return $this->display_by_loop( $loop ); } public function display_by_query( $query ) { $loop = new WP_Query( $query ); return $this->display_by_loop( $loop ); } private function display_by_loop( $loop ) { $template = get_option( 'archivist_template', PA_TEMPLATE_DEFAULT ); $template_before = get_option( 'archivist_template_before', PA_TEMPLATE_BEFORE_DEFAULT ); $template_after = get_option( 'archivist_template_after', PA_TEMPLATE_AFTER_DEFAULT ); $css = get_option( 'archivist_css', PA_CSS_DEFAULT ); ob_start(); ?>
have_posts() ) : ?> the_post(); ?> render_element( $post, $template ); ?>
textdomain; } public function load_textdomain() { $plugin_dir = basename(dirname(__FILE__)); load_plugin_textdomain( $this->get_textdomain(), FALSE, $plugin_dir . '/languages' ); } private function get_plugin_data( $value = 'Version' ) { $plugin_data = get_plugin_data( __FILE__ ); return $plugin_data[ $value ]; } static public function activation_hook() { global $wp_version; // Load Text-Domain $obj = archivist::get_object(); $obj->load_textdomain(); // check wp version if ( ! version_compare( $wp_version, '3.0', '>=' ) ) { deactivate_plugins( __FILE__ ); wp_die( wp_sprintf( '<strong>%s:</strong> ' . __( 'Sorry, This plugin requires WordPress 3.0+', $obj->get_textdomain() ), self::get_plugin_data( 'Name' ) ) ); } // check php version if ( ! version_compare( PHP_VERSION, '5.3.0', '>=' ) ) { deactivate_plugins( __FILE__ ); // Deactivate ourself wp_die( wp_sprintf( '<strong>%1s:</strong> ' . __( 'Sorry, This plugin has taken a bold step in requiring PHP 5.3.0+, Your server is currently running PHP %2s, Please bug your host to upgrade to a recent version of PHP which is less bug-prone. At last count, <strong>over 80%% of WordPress installs are using PHP 5.2+</strong>.', $obj->get_textdomain() ), self::get_plugin_data( 'Name' ), PHP_VERSION ) ); } } } }