forked from radgeek/feedwordpress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeedwordpresslocalpost.class.php
149 lines (115 loc) · 4.27 KB
/
feedwordpresslocalpost.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
class FeedWordPressLocalPost {
private $post;
public function __construct ($p = NULL) {
global $post;
if (is_null($p)) :
$this->post = $post; // current post in loop
elseif (is_object($p)) :
$this->post = $p;
else :
$this->post = get_post($p);
endif;
}
public function id () {
return $this->post->ID;
}
public function meta ($what, $params = array()) {
// -=-=-= 1. INITIAL SETUP. =-=-=-
$params = wp_parse_args($params, array(
"single" => true,
"default" => NULL,
"global" => NULL,
"unproxied setting" => NULL,
"unproxy" => false,
));
// This is a little weird, just bear with me here.
$results = array();
// Has this been left up to the admin setting?
if (is_null($params['unproxy'])) :
$params['unproxy'] = FeedWordPress::use_aggregator_source_data();
endif;
// -=-=-= 2. GET DATA FROM THE PROXIMATE OR THE ULTIMATE SOURCE. =-=-=-
// Now if we are supposed to look for ultimate source data (e.g. from
// <atom:source> ... </atom:source> elements), do so here.
if ($params['unproxy']) :
if (!is_string($params['unproxied setting'])) :
// Default pattern for unproxied settings: {$name}_original
$params['unproxied setting'] = $what . '_original';
endif;
// Now see if there's anything in postmeta from our ultimate source.
// If so, then we can cut out the middle man here.
$results = get_post_meta($this->post->ID, /*key=*/ $params['unproxied setting'], /*single=*/ false);
endif;
// If we weren't looking for ultimate source data, or if there wasn't
// any recorded, then grab this from the data for the proximate source.
if (empty($results)) :
$results = get_post_meta($this->post->ID, /*key=*/ $what, /*single=*/ false);
endif;
// -=-=-= 3. DEAL WITH THE RESULTS, IF ANY, OR FALLBACK VALUES. =-=-=-
// If we have results now, cool. Just pass them back.
if (!empty($results)) :
$ret = ($params['single'] ? $results[0] : $results);
// If we got no results but we have a fallback global setting, cool. Use
// that. Jam it into a singleton array for queries expecting an array of
// results instead of a scalar result.
elseif (is_string($params['global']) and strlen($params['global']) > 0) :
$opt = get_option($params['global'], $params['default']);
$ret = ($params['single'] ? $opt : array($opt));
// If we got no results and we have no fallback global setting, pass
// back a default value for single-result queries, or an empty array for
// multiple-result queries.
else :
$ret = ($params['single'] ? $params['default'] : array());
endif;
return $ret;
}
public function is_syndicated () {
return (!is_null($this->feed_id(/*single=*/ false)));
}
public function syndication_permalink () {
return $this->meta('syndication_permalink');
}
public function feed () {
return $GLOBALS['feedwordpress']->subscription($this->feed_id());
}
public function feed_id () {
return $this->meta('syndication_feed_id');
}
public function syndication_feed ($original = NULL) {
return $this->meta('syndication_feed', array("unproxy" => $original));
}
public function syndication_feed_guid ($original = NULL) {
$ret = $this->meta('syndication_source_id', array("unproxy" => $original));
// If this is blank, fall back to the full URL of the feed
if (is_null($ret) or strlen(trim($ret))==0) :
$ret = get_syndication_feed();
endif;
return $ret;
}
public function syndication_source ($original = NULL) {
$ret = $this->meta('syndication_source', array("unproxy" => $original));
// If this is blank, fall back to a prettified URL for the blog.
if (is_null($ret) or strlen(trim($ret)) == 0) :
$ret = feedwordpress_display_url($this->syndication_source_link());
endif;
return $ret;
}
public function syndication_source_link ($original = NULL) {
return $this->meta('syndication_source_uri', array("unproxy" => $original));
}
public function is_exposed_to_formatting_filters () {
return (
!$this->is_syndicated()
or (
'yes' == $this->meta(
'_feedwordpress_formatting_filters',
array(
'global' => 'feedwordpress_formatting_filters',
'default' => 'no',
)
)
)
);
} /* FeedWordPressLocalPost::is_exposed_to_formatting_filters () */
} /* class FeedWordPressLocalPost */