PluginProbe
FeedWordPress / 2015.0514
FeedWordPress v2015.0514
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 2015.0514, at feedwordpresslocalpost.class.php

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