PluginProbe
FeedWordPress / 2013.0504
FeedWordPress v2013.0504
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 2013.0504, at feedwordpresslocalpost.class.php

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