false, 'seriesSlug' => false, 'use-frame' => true ), $args ); $post = get_post(); $series = false; $framing = false; $seriesSlug = $fargs[ 'series-slug' ] or $seriesSlug = $fargs[ 'seriesSlug' ]; $frameWidth = AlsoInThisSeries::config( 'window-series-listing' ); if( $seriesSlug ) $series = get_term_by( 'slug', $seriesSlug, self::taxonomy ); else $post and $postseries = get_the_terms( $post->ID, self::taxonomy ) and $series = array_shift( $postseries ); if( ! $series ) return; $postsinseries = get_posts( array( 'tax_query' => array( array( 'taxonomy' => self::taxonomy, 'field' => 'id', 'terms' => (int) $series->term_id ) ), 'posts_per_page' => -1, 'order' => 'asc' ) ); if( $fargs[ 'use-frame' ] && $frameWidth && !$seriesSlug && is_single() ) { $framing = true; $pivot = 0; foreach( $postsinseries as $index => $seriespost ) { $pivot = $index; if( $seriespost->ID == $post->ID ) break; } $frame_left = max( 0, $pivot - floor( ( $frameWidth - 1 ) / 2 ) ); $frame_right = min( count( $postsinseries ) - 1, $pivot + floor( ( $frameWidth - 1 ) / 2 ) ); $ldiff = $frame_left - ( $pivot - floor( ( $frameWidth - 1 ) / 2 ) ); $rdiff = ( $pivot + floor( ( $frameWidth - 1 ) / 2 ) ) - $frame_right; if( $ldiff && ! $rdiff ) $frame_right = min( count( $postsinseries ) - 1, $frame_right + $ldiff ); elseif( $rdiff && ! $ldiff ) $frame_left = max( 0, $frame_left - $rdiff ); $postsinseries = array_slice( $postsinseries, $frame_left, 1 + $frame_right - $frame_left ); } ob_start(); include 'views/serieslisting.php'; $content = ob_get_contents(); ob_end_clean(); return $content; } static function plugins_loaded() { $defaults = array( 'insert-in-content' => 'append', 'window-series-listing' => false, 'archive-sort-order' => false ); self::$config = array_merge( $defaults, get_option( self::slug, $defaults ) ); load_plugin_textdomain( self::slug, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } static function init() { add_shortcode( 'alsointhisseries', array( __CLASS__, 'displaySeries' ) ); } static function pre_get_posts( $query ) { $sortOrder = self::config( 'archive-sort-order' ); if( isset( $query->query[ self::taxonomy ] ) && $sortOrder ) $query->query_vars[ 'order' ] = $sortOrder; return $query; } static function the_content( $content ) { $before = $after = ''; $alsointhisseries = self::displaySeries(); if( is_tax( self::taxonomy ) ) return $content; switch( self::config( 'insert-in-content' ) ) { case 'prepend' : $before = $alsointhisseries; break; case 'append' : $after = $alsointhisseries; break; default : } return $before . $content . $after; } static function activate() { flush_rewrite_rules( $hard = false ); } static function deactivate() { } static function uninstall() { delete_option( self::slug ); } } require_once 'plugin-taxonomies.php'; require_once 'plugin-widgets.php'; register_activation_hook( __FILE__, array( 'AlsoInThisSeries', 'activate' ) ); register_deactivation_hook( __FILE__, array( 'AlsoInThisSeries', 'deactivate' ) ); register_uninstall_hook( __FILE__, array( 'AlsoInThisSeries', 'uninstall' ) ); add_action( 'plugins_loaded', array( 'AlsoInThisSeries', 'plugins_loaded' ) ); add_action( 'init', array( 'AlsoInThisSeries', 'init' ) ); add_action( 'pre_get_posts', array( 'AlsoInThisSeries', 'pre_get_posts' ) ); add_action( 'the_content', array( 'AlsoInThisSeries', 'the_content' ), 1 ); if( is_admin() && ! defined( 'DOING_AJAX' ) ) include_once plugin_dir_path( __file__ ) . 'admin-plugin.php';