PluginProbe
FeedWordPress / 2017.1020
FeedWordPress v2017.1020
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 2017.1020, at feedwordpresslocalpost.class.php

191 lines 5.2 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 if (is_object($feedwordpress) and method_exists($feedwordpress, 'subscription')) :
97 $this->link = $feedwordpress->subscription($this->feed_id());
98 endif;
99 return $this->link;
100 }
101
102 public function feed_id () {
103 return $this->meta('syndication_feed_id');
104 }
105
106 public function syndication_feed ($original = NULL) {
107 return $this->meta('syndication_feed', array("unproxy" => $original));
108 }
109
110 public function syndication_feed_guid ($original = NULL) {
111 $ret = $this->meta('syndication_source_id', array("unproxy" => $original));
112
113 // If this is blank, fall back to the full URL of the feed
114 if (is_null($ret) or strlen(trim($ret))==0) :
115 $ret = get_syndication_feed();
116 endif;
117
118 return $ret;
119 }
120
121 public function syndication_source ($original = NULL) {
122 $ret = $this->meta('syndication_source', array("unproxy" => $original));
123
124 // If this is blank, fall back to a prettified URL for the blog.
125 if (is_null($ret) or strlen(trim($ret)) == 0) :
126 $ret = feedwordpress_display_url($this->syndication_source_link());
127 endif;
128
129 return $ret;
130 }
131
132 public function syndication_source_link ($original = NULL) {
133 return $this->meta('syndication_source_uri', array("unproxy" => $original));
134 }
135
136 public function is_exposed_to_formatting_filters () {
137
138 return (
139 !$this->is_syndicated()
140 or (
141 'yes' == $this->meta(
142 '_feedwordpress_formatting_filters',
143 array(
144 'global' => 'feedwordpress_formatting_filters',
145 'default' => 'no',
146 )
147 )
148 )
149 );
150
151 } /* FeedWordPressLocalPost::is_exposed_to_formatting_filters () */
152
153
154 public function content () {
155 return apply_filters('the_content', $this->post->post_content, $this->post->ID);
156 }
157
158 public function title () {
159 return apply_filters('the_title', $this->post->post_title, $this->post->ID);
160 }
161
162 public function guid () {
163 return apply_filters('get_the_guid', $this->post->guid);
164 }
165
166 public function get_categories () {
167 $terms = wp_get_object_terms(
168 $this->post->ID,
169 get_taxonomies(array(
170 'public' => true,
171 ), 'names'),
172 'all'
173 );
174 $rootUrl = get_bloginfo('url');
175
176 $cats = array();
177 foreach ($terms as $term) :
178 $taxUrl = MyPHP::url($rootUrl, array("taxonomy" => $term->taxonomy));
179 //array("taxonomy" => $term->taxonomy ));
180 $cats[] = new SimplePie_Category(
181 /*term=*/ $term->slug,
182 /*scheme=*/ $taxUrl,
183 /*label=*/ $term->name
184 );
185 endforeach;
186 return $cats;
187 }
188
189 } /* class FeedWordPressLocalPost */
190
191