|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package Admin Page Framework Loader |
|
4
|
|
|
* @copyright Copyright (c) 2013-2022, Michael Uno |
|
5
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
|
6
|
|
|
* @since 3.5.0 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Retrieves an array of RSS feed items. |
|
11
|
|
|
*/ |
|
12
|
|
|
class AdminPageFrameworkLoader_FeedList { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* A container array that stores fetched feed items. |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $_aFeedItems = array(); |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Stores the feed object. |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $_oFeed; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Stores the target URLs. |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $_aURLs = array(); |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Sets up properties. |
|
32
|
|
|
* |
|
33
|
|
|
* @param array|string $asURLs A url of string or urls of array. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct( $asURLs ) { |
|
36
|
|
|
|
|
37
|
|
|
$this->_aURLs = is_array( $asURLs ) |
|
38
|
|
|
? $asURLs |
|
39
|
|
|
: ( empty( $asURLs ) |
|
40
|
|
|
? array() |
|
41
|
|
|
: ( array ) $asURLs |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function get( $iItems=0 ) { |
|
51
|
|
|
|
|
52
|
|
|
$_aOutput = array(); |
|
53
|
|
|
$_aURLs = $this->_aURLs; |
|
54
|
|
|
|
|
55
|
|
|
if ( empty( $_aURLs ) ) { |
|
56
|
|
|
return $_aOutput; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$_oFeed = fetch_feed( $_aURLs ); |
|
60
|
|
|
if ( is_wp_error( $_oFeed ) ) { |
|
61
|
|
|
return $_aOutput; |
|
62
|
|
|
} |
|
63
|
|
|
foreach ( $_oFeed->get_items() as $_oItem ) { |
|
64
|
|
|
$_aOutput[ $_oItem->get_title() ] = array( |
|
65
|
|
|
'content' => $_oItem->get_content(), |
|
66
|
|
|
'description' => $_oItem->get_description(), |
|
67
|
|
|
'title' => $_oItem->get_title(), |
|
68
|
|
|
'date' => $_oItem->get_date( 'j F Y, g:i a' ), |
|
69
|
|
|
'author' => $_oItem->get_author(), |
|
70
|
|
|
'link' => $_oItem->get_permalink(), // get_link() may be used as well |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if ( $iItems ) { |
|
75
|
|
|
array_splice( $_aOutput, $iItems ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $_aOutput; |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|