PluginProbe
FeedWordPress / 2022.0203
FeedWordPress v2022.0203
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / feedwordpresslocalpost.class.php

feedwordpresslocalpost.class.php in FeedWordPress 2022.0203, at feedwordpresslocalpost.class.php

224 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class FeedWordPressLocalPost {
4 public $post;
5 public $link;
6
7 public function __construct ($p = NULL) {
8 global $post;
9
10 if (is_null($p)) :
11 $this->post = $post; // current post in loop
12 elseif (is_object($p)) :
13 $this->post = $p;
14 else :
15 $this->post = get_post($p);
16 endif;
17 }
18
19 public function id () {
20 if (is_null($this->post) or !is_object($this->post)) :
21 return NULL;
22 else :
23 return $this->post->ID;
24 endif;
25 } /* FeedWordPressLocalPost::id () */
26
27 public function meta ($what, $params = array()) {
28
29 // -=-=-= 1. INITIAL SETUP. =-=-=-
30 $params = wp_parse_args($params, array(
31 "single" => true,
32 "default" => NULL,
33 "global" => NULL,
34 "unproxied setting" => NULL,
35 "unproxy" => false,
36 ));
37
38 // If we got put through the_content without a current
39 // $post object set, then bail out immediately.
40 if (is_null($this->post) or !is_object($this->post)) :
41 return $params['default'];
42 endif;
43
44 // This is a little weird, just bear with me here.
45 $results = array();
46
47 // Has this been left up to the admin setting?
48 if (is_null($params['unproxy'])) :
49 $params['unproxy'] = FeedWordPress::use_aggregator_source_data();
50 endif;
51
52 // -=-=-= 2. GET DATA FROM THE PROXIMATE OR THE ULTIMATE SOURCE. =-=-=-
53
54 // Now if we are supposed to look for ultimate source data (e.g. from
55 // <atom:source> ... </atom:source> elements), do so here.
56 if ($params['unproxy']) :
57 if (!is_string($params['unproxied setting'])) :
58 // Default pattern for unproxied settings: {$name}_original
59 $params['unproxied setting'] = $what . '_original';
60 endif;
61
62 // Now see if there's anything in postmeta from our ultimate source.
63 // If so, then we can cut out the middle man here.
64 $results = get_post_meta($this->post->ID, /*key=*/ $params['unproxied setting'], /*single=*/ false);
65 endif;
66
67 // If we weren't looking for ultimate source data, or if there wasn't
68 // any recorded, then grab this from the data for the proximate source.
69 if (empty($results)) :
70 $results = get_post_meta($this->post->ID, /*key=*/ $what, /*single=*/ false);
71 endif;
72
73 // -=-=-= 3. DEAL WITH THE RESULTS, IF ANY, OR FALLBACK VALUES. =-=-=-
74
75 // If we have results now, cool. Just pass them back.
76 if (!empty($results)) :
77 $ret = ($params['single'] ? $results[0] : $results);
78
79 // If we got no results but we have a fallback global setting, cool. Use
80 // that. Jam it into a singleton array for queries expecting an array of
81 // results instead of a scalar result.
82 elseif (is_string($params['global']) and strlen($params['global']) > 0) :
83 $opt = get_option($params['global'], $params['default']);
84 $ret = ($params['single'] ? $opt : array($opt));
85
86 // If we got no results and we have no fallback global setting, pass
87 // back a default value for single-result queries, or an empty array for
88 // multiple-result queries.
89 else :
90 $ret = ($params['single'] ? $params['default'] : array());
91 endif;
92
93 return $ret;
94 }
95
96 public function is_syndicated () {
97 return (!is_null($this->feed_id(/*single=*/ false)));
98 }
99
100 public function syndication_permalink () {
101 return $this->meta('syndication_permalink');
102 }
103
104 public function feed () {
105 global $feedwordpress;
106 if (is_object($feedwordpress) and method_exists($feedwordpress, 'subscription')) :
107 $this->link = $feedwordpress->subscription($this->feed_id());
108 endif;
109 return $this->link;
110 }
111
112 public function feed_id () {
113 return $this->meta('syndication_feed_id');
114 }
115
116 public function syndication_feed ($original = NULL) {
117 return $this->meta('syndication_feed', array("unproxy" => $original));
118 }
119
120 public function syndication_feed_guid ($original = NULL) {
121 $ret = $this->meta('syndication_source_id', array("unproxy" => $original));
122
123 // If this is blank, fall back to the full URL of the feed
124 if (is_null($ret) or strlen(trim($ret))==0) :
125 $ret = get_syndication_feed();
126 endif;
127
128 return $ret;
129 }
130
131 public function syndication_source ($original = NULL) {
132 $ret = $this->meta('syndication_source', array("unproxy" => $original));
133
134 // If this is blank, fall back to a prettified URL for the blog.
135 if (is_null($ret) or strlen(trim($ret)) == 0) :
136 $ret = feedwordpress_display_url($this->syndication_source_link());
137 endif;
138
139 return $ret;
140 }
141
142 public function syndication_source_link ($original = NULL) {
143 return $this->meta('syndication_source_uri', array("unproxy" => $original));
144 }
145
146 public function is_exposed_to_formatting_filters () {
147
148 return (
149 !$this->is_syndicated()
150 or (
151 'yes' == $this->meta(
152 '_feedwordpress_formatting_filters',
153 array(
154 'global' => 'feedwordpress_formatting_filters',
155 'default' => 'no',
156 )
157 )
158 )
159 );
160
161 } /* FeedWordPressLocalPost::is_exposed_to_formatting_filters () */
162
163
164 public function content () {
165 if (is_null($this->post) or !is_object($this->post)) :
166 $post_content = NULL;
167 $post_id = NULL;
168 else :
169 $post_content = $this->post->post_content;
170 $post_id = $this->post->ID;
171 endif;
172 return apply_filters('the_content', $post_content, $post_id);
173 }
174
175 public function title () {
176 if (is_null($this->post) or !is_object($this->post)) :
177 $post_title = NULL;
178 $post_id = NULL;
179 else :
180 $post_title = $this->post->post_title;
181 $post_id = $this->post->ID;
182 endif;
183 return apply_filters('the_title', $post_title, $post_id);
184 }
185
186 public function guid () {
187 if (is_null($this->post) or !is_object($this->post)) :
188 $post_guid = NULL;
189 else :
190 $post_guid = $this->post->guid;
191 endif;
192 return apply_filters('get_the_guid', $post_guid);
193 }
194
195 public function get_categories () {
196 if (is_null($this->post) or !is_object($this->post)) :
197 return array();
198 endif;
199
200 $terms = wp_get_object_terms(
201 $this->post->ID,
202 get_taxonomies(array(
203 'public' => true,
204 ), 'names'),
205 'all'
206 );
207 $rootUrl = get_bloginfo('url');
208
209 $cats = array();
210 foreach ($terms as $term) :
211 $taxUrl = MyPHP::url($rootUrl, array("taxonomy" => $term->taxonomy));
212 //array("taxonomy" => $term->taxonomy ));
213 $cats[] = new SimplePie_Category(
214 /*term=*/ $term->slug,
215 /*scheme=*/ $taxUrl,
216 /*label=*/ $term->name
217 );
218 endforeach;
219 return $cats;
220 }
221
222 } /* class FeedWordPressLocalPost */
223
224