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

150 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 return $GLOBALS['feedwordpress']->subscription($this->feed_id());
95 }
96
97 public function feed_id () {
98 return $this->meta('syndication_feed_id');
99 }
100
101 public function syndication_feed ($original = NULL) {
102 return $this->meta('syndication_feed', array("unproxy" => $original));
103 }
104
105 public function syndication_feed_guid ($original = NULL) {
106 $ret = $this->meta('syndication_source_id', array("unproxy" => $original));
107
108 // If this is blank, fall back to the full URL of the feed
109 if (is_null($ret) or strlen(trim($ret))==0) :
110 $ret = get_syndication_feed();
111 endif;
112
113 return $ret;
114 }
115
116 public function syndication_source ($original = NULL) {
117 $ret = $this->meta('syndication_source', array("unproxy" => $original));
118
119 // If this is blank, fall back to a prettified URL for the blog.
120 if (is_null($ret) or strlen(trim($ret)) == 0) :
121 $ret = feedwordpress_display_url($this->syndication_source_link());
122 endif;
123
124 return $ret;
125 }
126
127 public function syndication_source_link ($original = NULL) {
128 return $this->meta('syndication_source_uri', array("unproxy" => $original));
129 }
130
131 public function is_exposed_to_formatting_filters () {
132
133 return (
134 !$this->is_syndicated()
135 or (
136 'yes' == $this->meta(
137 '_feedwordpress_formatting_filters',
138 array(
139 'global' => 'feedwordpress_formatting_filters',
140 'default' => 'no',
141 )
142 )
143 )
144 );
145
146 } /* FeedWordPressLocalPost::is_exposed_to_formatting_filters () */
147
148 } /* class FeedWordPressLocalPost */
149
150