*/ class Feedzy_Rss_Feeds_Util_SimplePie extends SimplePie { /** * The shortcode attributes. * * @access private * @var array $sc The shortcode attributes. */ private static $sc; /** * Whether custom sorting is enabled. * * @access private * @var bool $custom_sorting Whether custom sorting is enabled. */ private static $custom_sorting = false; /** * Initialize the class and set its properties. * * @access public * * @param array $sc The shortcode attributes. */ public function __construct( $sc ) { self::$sc = $sc; if ( array_key_exists( 'sort', self::$sc ) && ! empty( self::$sc['sort'] ) ) { if ( 'date_desc' === self::$sc['sort'] ) { $this->enable_order_by_date( true ); } else { self::$custom_sorting = true; } } parent::__construct(); } /** * Sorting callback for items * * @access public * @param SimplePie $a The SimplePieItem. * @param SimplePie $b The SimplePieItem. * @return boolean */ public static function sort_items( $a, $b ) { if ( self::$custom_sorting ) { switch ( self::$sc['sort'] ) { case 'title_desc': return $a->get_title() <= $b->get_title(); case 'title_asc': return $a->get_title() > $b->get_title(); case 'date_asc': return $a->get_date( 'U' ) > $b->get_date( 'U' ); } } return parent::sort_items( $a, $b ); } }