<?php

/*
@package Nextpage
@since 1.0.0
@source @https://gist.github.com/bgallagh3r/8546465
*/

class Nextpage_Excerpt {

    // Default length (by WordPress)
    public static $length = 55;

    // So you can call: my_excerpt('short');
    public static $types = array(
      'short' => 25,
      'regular' => 55,
      'long' => 100,
      'promo'=>15
    );

    public static $more = true;

    /**
    * Sets the length for the excerpt,
    * then it adds the WP filter
    * And automatically calls the_excerpt();
    *
    * @param string $new_length
    * @return void
    * @author Baylor Rae'
    */
    public static function length($new_length = 55, $more = true) {
	    Nextpage_Excerpt::$length = $new_length;
	    Nextpage_Excerpt::$more = $more;

        add_filter( 'excerpt_more', 'Nextpage_Excerpt::auto_excerpt_more' );

        add_filter('excerpt_length', 'Nextpage_Excerpt::new_length');

	    Nextpage_Excerpt::output();
    }

    // Tells WP the new length
    public static function new_length() {
        if( isset(Nextpage_Excerpt::$types[Nextpage_Excerpt::$length]) )
            return Nextpage_Excerpt::$types[Nextpage_Excerpt::$length];
        else
            return Nextpage_Excerpt::$length;
    }

    // Echoes out the excerpt
    public static function output() {
        the_excerpt();
    }

    public static function continue_reading_link() {

        return '<p class="nextpage-read-more"><a href="'.esc_url( get_permalink() ).'" class="qry-blog-post__tranq">'.esc_html__("  Read More",'nextpage').'</a></p>';
    }

    public static function auto_excerpt_more( ) {

            return ' &hellip;';
    }

}

// An alias to the class
function nextpage_excerpt($length = 55, $more=true) {
	Nextpage_Excerpt::length($length, $more);
}