%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' ) ); add_action( 'activate_archivist-custom-archive-templates/archivist.php', array( 'archivist', 'activation_hook' ) ); } class archivist { static private $classobj = NULL; // current template settings static $settings = NULL; public function __construct() { $this->load_textdomain(); add_shortcode( 'archivist', array( $this, 'shortcode' ) ); add_action( 'admin_menu', array( $this, 'add_menu_entry' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ) ); add_action( 'wp_ajax_archivist_paginate', array( $this, 'ajax_page') ); add_action( 'wp_ajax_nopriv_archivist_paginate', array( $this, 'ajax_page') ); add_action('wp_enqueue_scripts', function () { wp_register_script( 'archivist-pagination', plugins_url('js/archivist.js', __FILE__), ['jquery'] ); }); // only run update hooks if the plugin is already active $active_plugins = get_option( 'active_plugins' ); if ( in_array( 'archivist-custom-archive-templates/archivist.php', $active_plugins ) ) { $this->keep_backwards_compatibility(); } } public function load_scripts() { if (filter_input(INPUT_GET, 'page') === 'archivist_options_handle') { wp_enqueue_script( 'archivist-ace', plugins_url('vendor/ace/ace.js', __FILE__) ); } } static 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+', 'archivist' ), self::get_plugin_data( 'Name' ) ) ); } // check php version if ( ! version_compare( PHP_VERSION, '5.2.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>.', 'archivist' ), self::get_plugin_data( 'Name' ), PHP_VERSION ) ); } // set default template name add_option( 'archivist_default_template_name', 'default' ); // create default template $obj->create_default_template(); } static function get_default_template_name() { $name = get_option( 'archivist_default_template_name' ); return ( strlen( $name ) > 0 ) ? $name : 'default'; } public function create_default_template() { $default_name = self::get_default_template_name(); $settings = $this->get_template_options(); if ( ! isset( $settings[ $default_name ] ) ) { // TODO: refactor model archivist_settings::new // TODO: refactor model archivist_settings::new_with_defaults $settings[ $default_name ] = array( 'name' => $default_name, '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 ); } } private function do_plugin_update( $old_version, $current_version ) { // all updates before introduction of version number if ( ! $old_version ) { $this->update_from_zero(); } // if ( $old_version == 20 ) ... // if ( $old_version < 30 && $current_version == 40 ) ... // ... } private function update_from_zero() { // 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 $default_name = self::get_default_template_name(); $option = get_option( 'archivist_template' ); if ( $option ) { $settings = array(); $settings[ $default_name ] = array( 'name' => $default_name, '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' ); } // v1.2.3 -> 1.3.0 // default template name is now an option in the database // if it's not set, it should be 'default' like in the prior versions add_option( 'archivist_default_template_name', 'default' ); // 1.3.x revalidate all settings $settings = $this->get_template_options(); $new_settings = array(); foreach ( $settings as $template_name => $template ) { if ( $template_name != $template[ 'name' ] ) { die($template_name . $template_name['name']); continue; // skip this setting } // now fix missing template parts if ( ! isset( $template[ 'css' ] ) ) { $template[ 'css' ] = PA_CSS_DEFAULT; } if ( ! isset( $template[ 'template' ] ) ) { $template[ 'template' ] = PA_TEMPLATE_DEFAULT; } if ( ! isset( $template[ 'default_thumb' ] ) ) { $template[ 'default_thumb' ] = PA_THUMB_DEFAULT; } if ( ! isset( $template[ 'template_after' ] ) ) { $template[ 'template_after' ] = PA_TEMPLATE_AFTER_DEFAULT; } if ( ! isset( $template[ 'template_before' ] ) ) { $template[ 'template_before' ] = PA_TEMPLATE_BEFORE_DEFAULT; } // adopt template $new_settings[ $template[ 'name' ] ] = $template; } update_option( 'archivist', $new_settings ); // check if default template still exists $default_template = get_option( 'archivist_default_template_name' ); if ( ! isset( $new_settings[ $default_template ] ) ) { $first_template_name = array_shift( array_keys( $new_settings ) ); update_option( 'archivist_default_template_name', $first_template_name ); } // strip slashes in front of quotes for ( $i = 0; $i < 5; $i ++ ) { $new_settings = array_map( 'stripslashes_deep' , $new_settings ); } update_option( 'archivist', $new_settings ); } private function get_template_options() { $settings = get_option( 'archivist' ); if ( ! is_array( $settings) ) { $settings = array(); } return array_map( 'stripslashes_deep', $settings ); } private function keep_backwards_compatibility() { if ( ! defined( 'ARCHIVIST_VERSION' ) ) { return; } $current_version = (int) ARCHIVIST_VERSION; $old_version = (int) get_option( __CLASS__ . '_version' ); // if versions are equal, there is nothing to do if ( $current_version === $old_version ) { return; } // do the updates based on old and current version $this->do_plugin_update( $old_version, $current_version ); // update internal version update_option( __CLASS__ . '_version', $current_version ); } function ajax_page() { $shortcode_attributes = isset($_GET['shortcode_attributes']) ? $_GET['shortcode_attributes'] : null; if (is_null($shortcode_attributes) || empty($shortcode_attributes)) die(); $html = $this->shortcode($shortcode_attributes); echo $html; die(); } public function shortcode( $atts ) { $this->shortcode_attributes = shortcode_atts( array( 'query' => '', 'category' => '', 'tag' => '', 'template' => self::get_default_template_name(), 'pagination' => false, 'controls' => 'both' // controls for pagination: top / bottom / both ), $atts ); extract( $this->shortcode_attributes ); $this->pagination = (int) $pagination; if ($this->pagination < 1) { $this->pagination = false; } $this->controls = $controls; 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', 'manage_options', 'archivist_options_handle', array( $this, 'settings_page' ) ); } function render_element( $post, $template ) { require_once dirname( __FILE__ ) . '/parser.php'; $parser = new Archivist_Parser( $post, $template ); return $parser->render(); } public function get_current_page_number() { return isset($_GET['archivist_page']) && $_GET['archivist_page'] ? (int) $_GET['archivist_page'] : 1; } public function add_pagination_parameters($parameters) { if (!$this->pagination) { return $parameters; } $parameters['posts_per_page'] = $this->pagination; $parameters['paged'] = $this->get_current_page_number(); return $parameters; } public function set_post_status_parameters($parameters, $template) { $parameters['post_status'] = apply_filters('archivist_post_status', array('publish'), $template); return $parameters; } public function display_by_category( $category, $template = false ) { $parameters = array( 'posts_per_page' => -1, 'category_name' => $category ); $parameters = $this->add_pagination_parameters($parameters); $parameters = $this->set_post_status_parameters($parameters, $template); return $this->display_by_query_parameters($parameters, $template); } public function display_by_tag( $tag, $template = false ) { $parameters = array( 'posts_per_page' => -1, 'tag' => $tag ); $parameters = $this->add_pagination_parameters($parameters); $parameters = $this->set_post_status_parameters($parameters, $template); return $this->display_by_query_parameters($parameters, $template); } public function display_by_query( $query, $template = false ) { // sometimes WordPress does stupid stuff with ampersands $query = str_replace( "&", "&", $query ); $query = str_replace( "#038;", "&", $query ); $query = str_replace( "&&", "&", $query ); if ( ! stristr( $query, "posts_per_page" ) ) { $query .= "&posts_per_page=-1"; } // turn query string into parameter array parse_str($query, $parameters); $parameters = $this->add_pagination_parameters($parameters); $parameters = $this->set_post_status_parameters($parameters, $template); return $this->display_by_query_parameters($parameters, $template); } function display_pagination_controls($loop) { global $wp; $total_items = (int) $loop->found_posts; $items_per_page = (int) $this->pagination; if (!$items_per_page || !$total_items) return; $total_pages = ceil($total_items / $items_per_page); $current_page = $this->get_current_page_number(); $current_url = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}/{$_SERVER['REQUEST_URI']}"; ?> display_by_loop( $loop, $template ); } private function display_by_loop( $loop, $template = false ) { global $post; $all_settings = $this->get_template_options(); if ( ! $template ) { $template = self::get_default_template_name(); } $settings = $all_settings[ $template ]; archivist::$settings = $settings; if ( ! $settings ) { return '
' . wp_sprintf( __( 'Archivist Error: Unknown template "%1s"', 'archivist' ), $template ) . '
'; } if ($this->pagination) { wp_enqueue_script('archivist-pagination'); } ob_start(); ?>
pagination && in_array($this->controls, array('top', 'both'))): ?> display_pagination_controls($loop); ?> have_posts() ) : ?> the_post(); ?> render_element( $post, $settings[ 'template' ] ); ?> pagination && in_array($this->controls, array('bottom', 'both'))): ?> display_pagination_controls($loop); ?>
' . $content . ''; } public static function get_object() { if ( NULL === self::$classobj ) { self::$classobj = new self; } return self::$classobj; } public function load_textdomain() { $plugin_dir = basename(dirname(__FILE__)); load_plugin_textdomain( 'archivist', FALSE, $plugin_dir . '/languages' ); } private function get_plugin_data( $value = 'Version' ) { $plugin_data = get_plugin_data( __FILE__ ); return $plugin_data[ $value ]; } public function settings_page() { $tab = ( isset($_REQUEST[ 'tab' ]) && $_REQUEST[ 'tab' ] == 'add' ) ? 'add' : 'edit'; $current_template = $this->get_current_template_name(); $settings = $this->get_template_options(); if ( get_magic_quotes_gpc() ) { // strip slashes so HTML won't be escaped $_POST = array_map( 'stripslashes_deep', $_POST ); $_GET = array_map( 'stripslashes_deep', $_GET ); $_REQUEST = array_map( 'stripslashes_deep', $_REQUEST ); } // CHANGE DEFAULT action if ( isset( $_POST[ 'change_default' ] ) && strlen( $_POST[ 'choose_template_name' ] ) > 0 ) { update_option( 'archivist_default_template_name', $_POST[ 'choose_template_name' ] ); ?>

0 ) { unset( $settings[ $current_template ] ); update_option( 'archivist', $settings ); // if default template is deleted, make another one default if ( $current_template == self::get_default_template_name() && count( $settings ) > 0 ) { $first_template_name = array_shift(array_keys($settings)); update_option( 'archivist_default_template_name', $first_template_name ); } ?>

$value ) { $template_name = $key; // update name if ( $value[ 'name' ] != $template_name ) { $template_name = $value[ 'name' ]; // remove old settings enry unset( $settings[ $key ] ); // update default_template_name setting update_option( 'archivist_default_template_name', $template_name ); } // update all options $settings[ $template_name ] = $value; } update_option( 'archivist', $settings); } // CREATE action elseif ( isset( $_POST[ 'archivist_new_template_name' ] ) ) { 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); // if it is the only template setting, that means the default has been deleted // so we make the newly created one the new default if ( count( $settings ) === 1 ) { update_option( 'archivist_default_template_name', $_POST[ 'archivist_new_template_name' ] ); } $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' ); ?>

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

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

WordPress Codex' ), 'archivist' ) ?>

%TITLE%



%PERMALINK%



%AUTHOR%



%CATEGORIES%



%CATEGORIES|...%

%CATEGORIES|, %', 'archivist' ) ?>

%TAGS%



%TAGS|...%

%TAGS|, %', 'archivist' ) ?>

%EXCERPT%



%POST_META|...%

%POST_META|duration%', 'archivist' ) ?>

%POST_META|...|...%

%POST_META|guest|<br>%', 'archivist' ) ?>

%DATE%



%DATE|...%

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

%POST_THUMBNAIL|...x...%

%POST_THUMBNAIL|75x75%', 'archivist' ) ?>

%COMMENTS%



%ACF|field_name%

ACF', '
get_field()
' ); ?>

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


get_template_options();; $settings = $all_settings[ $name ]; // if the setting does not exist, take the first you can get if ( ! $settings ) { $name = array_shift(array_keys($all_settings)); } return $name; } private function settings_page_edit() { $name = $this->get_current_template_name(); $field_name = 'archivist[' . $name . ']'; $all_template_settings = $settings = $this->get_template_options();; $settings = $all_template_settings[ $name ]; $default_template = get_option( 'archivist_default_template_name' ); ?>
1 ): ?>


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

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