%POST_THUMBNAIL|50x50%
%DATE% by %AUTHOR%
Filed as: %CATEGORIES|, % '); define( 'PA_TEMPLATE_BEFORE_DEFAULT', ' ' ); define( 'PA_TEMPLATE_AFTER_DEFAULT', '
Thumb Title
' ); define( 'PA_THUMB_DEFAULT', '' ); if ( ! class_exists( 'archivist' ) ) { if ( function_exists( 'add_action' ) && function_exists( 'register_activation_hook' ) ) { add_action( 'plugins_loaded', array( 'archivist', 'get_object' ) ); register_activation_hook( __FILE__, array( 'archivist', 'activation_hook' ) ); } class archivist { static private $classobj = NULL; public $textdomain = 'archivist'; public function __construct() { $this->load_textdomain(); add_shortcode( 'archivist', array( $this, 'shortcode' ) ); add_action( 'admin_menu', array( $this, 'add_menu_entry' ) ); $this->keep_backwards_compatibility(); } private function keep_backwards_compatibility() { // v1.1.0 -> v1.2.0 // move from single template to multiple templates // if single template stuff exists, create a 'default' // template entry based on those values. // When finished, delete the old data $option = get_option( 'archivist_template' ); if ( $option ) { $settings = array(); $settings[ 'default' ] = array( 'name' => 'default', 'css' => get_option( 'archivist_css', PA_CSS_DEFAULT ), 'template' => get_option( 'archivist_template', PA_TEMPLATE_DEFAULT ), 'default_thumb' => get_option( 'archivist_default_thumb', PA_THUMB_DEFAULT ), 'template_after' => get_option( 'archivist_template_after', PA_TEMPLATE_AFTER_DEFAULT ), 'template_before' => get_option( 'archivist_template_before', PA_TEMPLATE_BEFORE_DEFAULT ) ); update_option( 'archivist', $settings); delete_option( 'archivist_css' ); delete_option( 'archivist_template' ); delete_option( 'archivist_default_thumb' ); delete_option( 'archivist_template_after' ); delete_option( 'archivist_template_before' ); } } public function shortcode( $atts ) { extract( shortcode_atts( array( 'query' => '', 'category' => '', 'tag' => '', 'template' => 'default' ), $atts ) ); if ( $query !== '' ) { return $this->display_by_query( $query, $template ); } elseif ( $category !== '' ) { return $this->display_by_category( $category, $template ); } else { return $this->display_by_tag( $tag, $template ); } } public function add_menu_entry() { add_submenu_page( 'options-general.php', 'Archivist', 'Archivist', 'edit_post', 'archivist_options_handle', array( $this, 'settings_page' ) ); } function render_element( $post, $template ) { $template = str_replace( '%DATE%', get_the_date(), $template ); $template = str_replace( '%TITLE%', get_the_title(), $template ); $template = str_replace( '%AUTHOR%', get_the_author(), $template ); $template = str_replace( '%TAGS%', get_the_tag_list(), $template ); $template = str_replace( '%PERMALINK%', get_permalink(), $template ); $template = str_replace( '%EXCERPT%', get_the_excerpt(), $template ); $template = str_replace( '%COMMENTS%', get_comments_number(), $template ); $template = str_replace( '%CATEGORIES%', get_the_category_list(), $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', ' $thumb = get_the_post_thumbnail( $post->ID, array( $matches[ 1 ], $matches[ 2 ] ) ); if ( ! $thumb ) { $default_thumb = get_option( "archivist_default_thumb", PA_THUMB_DEFAULT ); if ( $default_thumb ) { $thumb = "\"Archive"; } } return $thumb;' ), $template ); return $template; } public function display_by_category( $category, $template = 'default' ) { $parameters = array( 'posts_per_page' => -1, 'category_name' => $category ); $loop = new WP_Query( $parameters ); return $this->display_by_loop( $loop, $template ); } public function display_by_tag( $tag, $template = 'default' ) { $parameters = array( 'posts_per_page' => -1, 'tag' => $tag ); $loop = new WP_Query( $parameters ); return $this->display_by_loop( $loop, $template ); } public function display_by_query( $query, $template = 'default' ) { $loop = new WP_Query( $query ); return $this->display_by_loop( $loop, $template ); } private function display_by_loop( $loop, $template = 'default' ) { $all_settings = get_option( 'archivist' ); $settings = $all_settings[ $template ]; if ( ! $settings ) { return '
' . wp_sprintf( __( 'Archivist Error: Unknown template "%1s"' ), $template ) . '
'; } ob_start(); ?>
have_posts() ) : ?> the_post(); ?> render_element( $post, $settings[ '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( '%s: ' . __( '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( '%1s: ' . __( '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 ) ); } // create default template $this->create_default_template(); } private function create_default_template() { $settings = get_option( 'archivist' ); if ( ! isset( $settings[ 'default' ] ) ) { // TODO: refactor model archivist_settings::new // TODO: refactor model archivist_settings::new_with_defaults $settings[ 'default' ] = array( 'name' => 'default', 'css' => PA_CSS_DEFAULT, 'default_thumb' => PA_THUMB_DEFAULT, 'template' => PA_TEMPLATE_DEFAULT, 'template_after' => PA_TEMPLATE_AFTER_DEFAULT, 'template_before' => PA_TEMPLATE_BEFORE_DEFAULT ); update_option( 'archivist', $settings); } } public function settings_page() { $tab = ( $_REQUEST[ 'tab' ] == 'add' ) ? 'add' : 'edit'; $current_template = $this->get_current_template_name(); // DELETE action if ( isset( $_POST[ 'delete' ] ) && strlen( $_POST[ 'delete' ] ) > 0 ) { $settings = get_option( 'archivist' ); unset( $settings[ $current_template ] ); update_option( 'archivist', $settings ); ?>

$value ) { $settings[ $key ] = $value; } update_option( 'archivist', $settings); } // CREATE action elseif ( isset( $_POST[ 'archivist_new_template_name' ] ) ) { $settings = get_option( 'archivist' ); if ( isset( $settings[ $_POST[ 'archivist_new_template_name' ] ] ) ) { $success = false; } else { $settings[ $_POST[ 'archivist_new_template_name' ] ] = array( 'name' => $_POST[ 'archivist_new_template_name' ], // FIXME: do I have to safeify this or does WP take care? 'css' => PA_CSS_DEFAULT, 'default_thumb' => PA_THUMB_DEFAULT, 'template' => PA_TEMPLATE_DEFAULT, 'template_after' => PA_TEMPLATE_AFTER_DEFAULT, 'template_before' => PA_TEMPLATE_BEFORE_DEFAULT ); update_option( 'archivist', $settings); $success = true; } if ( $success ) { $tab = 'edit'; // display edit-template-form for this template ?>

settings_page_sidebar(); if ( $tab == 'edit' ) { $this->settings_page_edit(); } else { $this->settings_page_add(); } ?>

If you like it, consider to flattr me a beer.', archivist::get_textdomain() ); ?>

Homepage, follow me on Twitter or look at my projects on GitHub.', archivist::get_textdomain() ), 'http://www.FarBeyondProgramming.com/', 'http://www.twitter.com/ericteubert', 'https://github.com/eteubert' ) ?>

get_current_template_name(); if ( $name == 'default' ) { $template_part = ' '; } else { $template_part = ' template="' . $name . '" '; } ?>

WordPress Codex' ), archivist::get_textdomain() ) ?>

%TITLE%



%PERMALINK%



%AUTHOR%



%CATEGORIES%



%CATEGORIES|...%

%CATEGORIES|, %', archivist::get_textdomain() ) ?>

%TAGS%



%TAGS|...%

%TAGS|, %', archivist::get_textdomain() ) ?>

%EXCERPT%



%POST_META|...%

%POST_META|duration%', archivist::get_textdomain() ) ?>

%DATE%



%DATE|...%

%DATE|Y/m/d%', archivist::get_textdomain() ) ?>

%POST_THUMBNAIL|...x...%

%POST_THUMBNAIL|75x75%', archivist::get_textdomain() ) ?>

%COMMENTS%


Example: If you name the template "rockstar", then you can use it with a shortcode like [archivist template="rockstar" category="..."]', archivist::get_textdomain() ) ?>


get_current_template_name(); $field_name = 'archivist[' . $name . ']'; $all_template_settings = get_option( 'archivist' ); $settings = $all_template_settings[ $name ]; ?>
1 ): ?>


%POST_THUMBNAIL|...x...% placeholder and the post has no thumbnail, then this image will be used.', archivist::get_textdomain() ) ?>