86 lines
2.1 KiB
PHP
86 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* The class that contains a custom implementation of SimplePie.
|
||
|
|
*
|
||
|
|
* @link http://themeisle.com
|
||
|
|
*
|
||
|
|
* @package feedzy-rss-feeds
|
||
|
|
* @subpackage feedzy-rss-feeds/includes/util
|
||
|
|
*/
|
||
|
|
|
||
|
|
if ( ! class_exists( 'SimplePie' ) ) {
|
||
|
|
require_once( ABSPATH . WPINC . '/class-simplepie.php' );
|
||
|
|
require_once( ABSPATH . WPINC . '/class-wp-feed-cache.php' );
|
||
|
|
require_once( ABSPATH . WPINC . '/class-wp-feed-cache-transient.php' );
|
||
|
|
require_once( ABSPATH . WPINC . '/class-wp-simplepie-file.php' );
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The class that contains a custom implementation of SimplePie.
|
||
|
|
*
|
||
|
|
* Class that contains a custom implementation of SimplePie.
|
||
|
|
*
|
||
|
|
* @package feedzy-rss-feeds
|
||
|
|
* @subpackage feedzy-rss-feeds/includes/util
|
||
|
|
* @author Themeisle <friends@themeisle.com>
|
||
|
|
*/
|
||
|
|
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 );
|
||
|
|
}
|
||
|
|
}
|