PluginProbe
FeedWordPress / 2020.0118
FeedWordPress v2020.0118
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
← All changes | posts-page.php +504 -301 2010.01272020.0118 View file →
@@ -10,112 +10,146 @@
10 10 * Construct the posts page object.
11 11 *
12 12 * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings
13 13 */
14 - function FeedWordPressPostsPage ($link = NULL) {
15 - FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresspostspage', $link);
16 - $this->dispatch = 'feedwordpress_posts_settings';
14 + public function __construct( $link = -1 ) {
15 + if (is_numeric($link) and -1 == $link) :
16 + $link = $this->submitted_link();
17 + endif;
18 +
19 + parent::__construct('feedwordpresspostspage', $link);
20 + $this->dispatch = 'feedwordpress_admin_page_posts';
17 21 $this->filename = __FILE__;
18 22 $this->updatedPosts = new UpdatedPostsControl($this);
23 +
24 + $this->pagenames = array(
25 + 'default' => 'Posts',
26 + 'settings-update' => 'Syndicated posts',
27 + 'open-sheet' => 'Syndicated Posts & Links',
28 + );
19 29 } /* FeedWordPressPostsPage constructor */
20 30
21 - function accept_POST ($post) {
22 - global $wpdb;
23 -
24 - $link_id = $this->link->id;
31 + function save_settings ($post) {
32 + // custom post settings
33 + $custom_settings = $this->custom_post_settings();
25 34
26 - // User mashed a Save Changes button
27 - if (isset($post['save']) or isset($post['submit'])) :
28 - // custom post settings
29 - foreach ($post['notes'] as $mn) :
35 + foreach ($post['notes'] as $mn) :
36 + if (isset($mn['key0'])) :
30 37 $mn['key0'] = trim($mn['key0']);
31 - $mn['key1'] = trim($mn['key1']);
32 -
33 38 if (strlen($mn['key0']) > 0) :
34 39 unset($custom_settings[$mn['key0']]); // out with the old
35 40 endif;
41 + endif;
36 42
43 + if (isset($mn['key1'])) :
44 + $mn['key1'] = trim($mn['key1']);
45 +
37 46 if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
38 47 $custom_settings[$mn['key1']] = $mn['value']; // in with the new
39 48 endif;
49 + endif;
50 + endforeach;
51 +
52 + $this->updatedPosts->accept_POST($post);
53 + if ($this->for_feed_settings()) :
54 + $alter = array ();
55 +
56 + $this->link->settings['postmeta'] = serialize($custom_settings);
57 +
58 + if (isset($post['resolve_relative'])) :
59 + $this->link->settings['resolve relative'] = $post['resolve_relative'];
60 + endif;
61 + if (isset($post['munge_permalink'])) :
62 + $this->link->settings['munge permalink'] = $post['munge_permalink'];
63 + endif;
64 + if (isset($post['munge_comments_feed_links'])) :
65 + $this->link->settings['munge comments feed links'] = $post['munge_comments_feed_links'];
66 + endif;
67 +
68 + // Post status, comment status, ping status
69 + foreach (array('post', 'comment', 'ping') as $what) :
70 + $sfield = "feed_{$what}_status";
71 + if (isset($post[$sfield])) :
72 + if ($post[$sfield]=='site-default') :
73 + unset($this->link->settings["{$what} status"]);
74 + else :
75 + $this->link->settings["{$what} status"] = $post[$sfield];
76 + endif;
77 + endif;
40 78 endforeach;
41 -
42 - $this->updatedPosts->accept_POST($post);
43 - if ($this->for_feed_settings()) :
44 - $alter = array ();
45 -
46 - $this->link->settings['postmeta'] = serialize($custom_settings);
47 -
48 - if (isset($post['resolve_relative'])) :
49 - $this->link->settings['resolve relative'] = $post['resolve_relative'];
79 +
80 + if (isset($post['syndicated_post_type'])) :
81 + if ($post['syndicated_post_type']=='default') :
82 + unset($this->link->settings['syndicated post type']);
83 + else :
84 + $this->link->settings['syndicated post type'] = $post['syndicated_post_type'];
50 85 endif;
51 -
52 - // Post status, comment status, ping status
53 - foreach (array('post', 'comment', 'ping') as $what) :
54 - $sfield = "feed_{$what}_status";
55 - if (isset($post[$sfield])) :
56 - if ($post[$sfield]=='site-default') :
57 - unset($this->link->settings["{$what} status"]);
58 - else :
59 - $this->link->settings["{$what} status"] = $post[$sfield];
60 - endif;
86 + endif;
87 +
88 + else :
89 + // update_option ...
90 + if (isset($post['feed_post_status'])) :
91 + update_option('feedwordpress_syndicated_post_status', $post['feed_post_status']);
92 + endif;
93 +
94 + update_option('feedwordpress_custom_settings', serialize($custom_settings));
95 +
96 + update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']);
97 + update_option('feedwordpress_use_aggregator_source_data', $_REQUEST['use_aggregator_source_data']);
98 + update_option('feedwordpress_formatting_filters', $_REQUEST['formatting_filters']);
99 +
100 + if (isset($post['resolve_relative'])) :
101 + update_option('feedwordpress_resolve_relative', $post['resolve_relative']);
102 + endif;
103 + if (isset($post['munge_comments_feed_links'])) :
104 + update_option('feedwordpress_munge_comments_feed_links', $post['munge_comments_feed_links']);
105 + endif;
106 + if (isset($_REQUEST['feed_comment_status']) and ($_REQUEST['feed_comment_status'] == 'open')) :
107 + update_option('feedwordpress_syndicated_comment_status', 'open');
108 + else :
109 + update_option('feedwordpress_syndicated_comment_status', 'closed');
110 + endif;
111 +
112 + if (isset($_REQUEST['feed_ping_status']) and ($_REQUEST['feed_ping_status'] == 'open')) :
113 + update_option('feedwordpress_syndicated_ping_status', 'open');
114 + else :
115 + update_option('feedwordpress_syndicated_ping_status', 'closed');
116 + endif;
117 +
118 + if (isset($post['syndicated_post_type'])) :
119 + update_option('feedwordpress_syndicated_post_type', $post['syndicated_post_type']);
120 + endif;
121 + endif;
122 +
123 + if (isset($post['save']) or isset($post['submit'])) :
124 + if (isset($post['boilerplate'])) :
125 + foreach ($post['boilerplate'] as $index => $line) :
126 + if (0 == strlen(trim($line['template']))) :
127 + unset($post['boilerplate'][$index]);
61 128 endif;
62 129 endforeach;
63 130
64 - $alter[] = "link_notes = '".$wpdb->escape($this->link->settings_to_notes())."'";
65 - $alter_set = implode(", ", $alter);
66 -
67 - // issue update query
68 - $result = $wpdb->query("
69 - UPDATE $wpdb->links
70 - SET $alter_set
71 - WHERE link_id='$link_id'
72 - ");
73 - $this->updated = true;
74 -
75 - // reload link information from DB
76 - if (function_exists('clean_bookmark_cache')) :
77 - clean_bookmark_cache($link_id);
78 - endif;
79 - $link =& new SyndicatedLink($link_id);
80 - else :
81 - // update_option ...
82 - if (isset($post['feed_post_status'])) :
83 - update_option('feedwordpress_syndicated_post_status', $post['feed_post_status']);
84 - endif;
131 + // Convert indexes to 0..(N-1) to avoid possible collisions
132 + $post['boilerplate'] = array_values($post['boilerplate']);
85 133
86 - update_option('feedwordpress_custom_settings', serialize($custom_settings));
87 -
88 - update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']);
89 - update_option('feedwordpress_use_aggregator_source_data', $_REQUEST['use_aggregator_source_data']);
90 - update_option('feedwordpress_formatting_filters', $_REQUEST['formatting_filters']);
91 -
92 - if (isset($post['resolve_relative'])) :
93 - update_option('feedwordpress_resolve_relative', $post['resolve_relative']);
94 - endif;
95 - if (isset($_REQUEST['feed_comment_status']) and ($_REQUEST['feed_comment_status'] == 'open')) :
96 - update_option('feedwordpress_syndicated_comment_status', 'open');
134 + if ($this->for_feed_settings()) :
135 + $this->link->settings['boilerplate rules'] = serialize($post['boilerplate']);
136 + $this->link->save_settings(/*reload=*/ true);
97 137 else :
98 - update_option('feedwordpress_syndicated_comment_status', 'closed');
138 + update_option('feedwordpress_boilerplate', $post['boilerplate']);
99 139 endif;
100 -
101 - if (isset($_REQUEST['feed_ping_status']) and ($_REQUEST['feed_ping_status'] == 'open')) :
102 - update_option('feedwordpress_syndicated_ping_status', 'open');
103 - else :
104 - update_option('feedwordpress_syndicated_ping_status', 'closed');
105 - endif;
140 + endif;
106 141
107 - $this->updated = true;
142 + if (isset($post['boilerplate_hook_order'])) :
143 + $this->update_setting('boilerplate hook order', intval($post['boilerplate_hook_order']));
108 144 endif;
145 + endif;
109 146
110 - // Probably a "Go" button for the drop-down
111 - else :
112 - $this->updated = false;
113 - endif;
147 + parent::save_settings($post);
114 148 }
115 149
116 150 /**
117 - * Outputs "Publication" settings box.
151 + * publication_box: Outputs "Publication" settings box.
118 152 *
119 153 * @since 2009.0713
120 154 * @param object $page of class FeedWordPressPostsPage tells us whether this is
121 155 * a page for one feed's settings or for global defaults
@@ -123,73 +157,41 @@
123 157 *
124 158 * @uses FeedWordPressPostsPage::these_posts_phrase()
125 159 * @uses FeedWordPress::syndicated_status()
126 160 * @uses SyndicatedLink::syndicated_status()
127 - * @uses SyndicatedPost::use_api()
128 - * @uses fwp_option_box_opener()
129 - * @uses fwp_option_box_closer()
130 161 */
131 162 /*static*/ function publication_box ($page, $box = NULL) {
132 - global $fwp_path;
133 -
134 - $post_status_global = FeedWordPress::syndicated_status('post', /*default=*/ 'publish');
135 163 $thesePosts = $page->these_posts_phrase();
136 -
137 - // Set up array for selector
138 - $setting = array(
139 - 'publish' => array ('label' => "Publish %s immediately", 'checked' => ''),
140 - 'draft' => array('label' => "Save %s as drafts", 'checked' => ''),
141 - 'private' => array('label' => "Save %s as private posts", 'checked' => ''),
164 + $postSelector = array(
165 + 'publish' => "Publish %s immediately",
166 + 'pending' => "Hold %s for review; mark as Pending",
167 + 'draft' => "Save %s as drafts",
168 + 'private' => "Save %s as private posts",
142 169 );
143 - if (SyndicatedPost::use_api('post_status_pending')) :
144 - $setting['pending'] = array('label' => "Hold %s for review; mark as Pending", 'checked' => '');
145 - endif;
170 + $labels = array();
171 + foreach ($postSelector as $index => $value) :
172 + $postSelector[$index] = sprintf(__($value), $thesePosts);
173 + $labels[$index] = __(str_replace(' %s', '', strtolower(strtok($value, ';'))));
174 + endforeach;
175 +
176 + $params = array(
177 + 'input-name' => 'feed_post_status',
178 + 'setting-default' => NULL,
179 + 'global-setting-default' => 'publish',
180 + 'labels' => $labels,
181 + );
146 182
147 -
148 - if ($page->for_feed_settings()) :
149 - $href = $fwp_path.'/'.basename(__FILE__);
150 - $currently = str_replace('%s', '', strtolower(strtok($setting[$post_status_global]['label'], ';')));
151 - $setting['site-default'] = array('label' => "Use <a href=\"admin.php?page=${href}\">site-wide setting</a>", 'checked' => '');
152 - $setting['site-default']['label'] .= " (currently: <strong>${currently}</strong>)";
153 -
154 - $checked = $page->link->syndicated_status('post', 'site-default', /*fallback=*/ false);
155 - else :
156 - $checked = $post_status_global;
157 - endif;
158 -
159 - // Re-order appropriately
160 - $selector = array();
161 - $order = array(
162 - 'site-default',
163 - 'publish',
164 - 'pending',
165 - 'draft',
166 - 'private',
167 - );
168 - foreach ($order as $line) :
169 - if (isset($setting[$line])) :
170 - $selector[$line] = $setting[$line];
171 - endif;
172 - endforeach;
173 - $selector[$checked]['checked'] = ' checked="checked"';
174 -
175 183 // Hey ho, let's go...
176 184 ?>
177 - <style type="text/css">
178 - #syndicated-publication-form th { width: 27%; vertical-align: top; }
179 - #syndicated-publication-form td { width: 73%; vertical-align: top; }
180 - </style>
181 -
182 - <table id="syndicated-publication-form" class="form-table" cellspacing="2" cellpadding="5">
185 + <table id="syndicated-publication-form" class="edit-form narrow">
183 186 <tr><th scope="row"><?php _e('New posts:'); ?></th>
184 - <td><ul class="options">
185 - <?php foreach ($selector as $code => $li) : ?>
186 - <li><label><input type="radio" name="feed_post_status"
187 - value="<?php print $code; ?>"<?php print $li['checked']; ?> />
188 - <?php print str_replace('%s', $thesePosts, $li['label']); ?></label></li>
189 - <?php endforeach; ?>
190 - </ul></td>
191 - </tr>
187 + <td><?php
188 + $this->setting_radio_control(
189 + 'post status', 'syndicated_post_status',
190 + $postSelector, $params
191 + );
192 + ?>
193 + </td></tr>
192 194
193 195 <?php $page->updatedPosts->display(); ?>
194 196 </table>
195 197
@@ -203,31 +205,21 @@
203 205 * @param object $page of class FeedWordPressPostsPage tells us whether this is
204 206 * a page for one feed's settings or for global defaults
205 207 * @param array $box
206 208 *
207 - * @uses fwp_option_box_opener()
208 - * @uses fwp_option_box_closer()
209 209 */
210 210 function formatting_box ($page, $box = NULL) {
211 - global $fwp_path;
212 211 $thesePosts = $page->these_posts_phrase();
213 - $global_resolve_relative = get_option('feedwordpress_resolve_relative', 'yes');
212 +
214 213 if ($page->for_feed_settings()) :
215 214 $formatting_filters = null;
216 - $resolve_relative = $page->link->setting('resolve relative', NULL, 'default');
217 215 $url = preg_replace('|/+$|', '', $page->link->homepage());
218 - $setting = array(
219 - 'yes' => __('resolve relative URIs'),
220 - 'no' => __('leave relative URIs unresolved'),
221 - );
222 - $href = $fwp_path.'/'.basename(__FILE__);
223 216 else :
224 217 $formatting_filters = get_option('feedwordpress_formatting_filters', 'no');
225 - $resolve_relative = $global_resolve_relative;
226 218 $url = 'http://example.com';
227 219 endif;
228 220 ?>
229 - <table class="form-table" cellspacing="2" cellpadding="5">
221 + <table class="edit-form narrow">
230 222 <?php if (!is_null($formatting_filters)) : ?>
231 223
232 224 <tr><th scope="row">Formatting filters:</th>
233 225 <td><select name="formatting_filters" size="1">
@@ -242,22 +234,32 @@
242 234
243 235 <?php endif; ?>
244 236
245 237 <tr><th scope="row">Relative URIs:</th>
246 - <td>If link or image in a syndicated post from <code><?php print $url; ?></code>
238 + <td><p>If link or image in a syndicated post from <code><?php print $url; ?></code>
247 239 refers to a partial URI like <code>/about</code>, where should
248 240 the syndicated copy point to?</p>
249 241
250 - <ul>
251 - <?php if ($page->for_feed_settings()) : ?>
252 - <li><p><label><input type="radio" name="resolve_relative" value='default' <?php echo ($resolve_relative=='default')?' checked="checked"':''; ?>/> Use <a href="admin.php?page=<?php print $href; ?>">site-wide setting</a><br/>
253 - <small style="margin-left: 2.0em;">Currently: <strong><?php print $setting[$global_resolve_relative]; ?></strong></small></label></p></li>
254 - <?php endif; ?>
255 - <li><p><label><input type="radio" name="resolve_relative" value="yes"<?php echo ($resolve_relative!='no' and $resolve_relative!='default')?' checked="checked"':''; ?>/> Resolve the URI so it points to <code><?php print $url; ?></code><br/>
256 - <small style="margin-left: 2.0em;"><code>/contact</code> is rewritten as <code><?php print $url; ?>/contact</code></label></small></p></li>
257 - <li><p><label><input type="radio" name="resolve_relative" value="no"<?php echo ($resolve_relative=='no')?' checked="checked"':''; ?>/> Leave relative URIs unchanged, so they point to this site<br/>
258 - <small style="margin-left: 2.0em;"><code>/contact</code> is left as <code>/contact</code></small></label></li>
259 - </ul>
242 + <?php
243 + $options = array(
244 + 'yes' => 'Resolve the URI so it points to <code>'.$url.'</code><br/><small style="margin-left: 2.0em;"><code>/contact</code> is rewritten as <code>'.$url.'/contact</code></small>',
245 + 'no' => 'Leave relative URIs unchanged, so they point to this site<br/><small style="margin-left: 2.0em;"><code>/contact</code> is left as <code>/contact</code></small>',
246 + );
247 + $params = array(
248 + 'setting-default' => 'default',
249 + 'global-setting-default' => 'yes',
250 + 'labels' => array(
251 + 'yes' => __('resolve relative URIs'),
252 + 'no' => __('leave relative URIs unresolved'),
253 + ),
254 + 'default-input-value' => 'default',
255 + );
256 +
257 + $this->setting_radio_control(
258 + 'resolve relative', 'resolve_relative',
259 + $options, $params
260 + );
261 + ?>
260 262 </td></tr>
261 263
262 264 </table>
263 265 <?php
@@ -270,23 +272,39 @@
270 272 * @param object $page of class FeedWordPressPostsPage tells us whether this is
271 273 * a page for one feed's settings or for global defaults
272 274 * @param array $box
273 275 *
274 - * @uses fwp_option_box_opener()
275 - * @uses fwp_option_box_closer()
276 276 */
277 277 /*static*/ function links_box ($page, $box = NULL) {
278 - $munge_permalink = get_option('feedwordpress_munge_permalink');
279 - $use_aggregator_source_data = get_option('feedwordpress_use_aggregator_source_data');
278 + $setting = array(
279 + 'munge_permalink' => array(
280 + 'yes' => __('The copy on the original website'),
281 + 'no' => __('The local copy on this website'),
282 + ),
283 + );
284 +
285 + if (!$page->for_feed_settings()) :
286 + $use_aggregator_source_data = get_option('feedwordpress_use_aggregator_source_data');
287 + endif;
280 288 ?>
281 - <table class="form-table" cellspacing="2" cellpadding="5">
282 - <tr><th scope="row">Permalinks:</th>
283 - <td><select name="munge_permalink" size="1">
284 - <option value="yes"<?php echo ($munge_permalink=='yes')?' selected="selected"':''; ?>>point to the copy on the original website</option>
285 - <option value="no"<?php echo ($munge_permalink=='no')?' selected="selected"':''; ?>>point to the local copy on this website</option>
286 - </select></td>
287 - </tr>
289 + <table class="edit-form narrow">
290 + <tr><th scope="row">Permalinks point to:</th>
291 + <td><?php
288 292
293 + $params = array(
294 + 'setting-default' => 'default',
295 + 'global-setting-default' => 'yes',
296 + 'default-input-value' => 'default',
297 + );
298 + $this->setting_radio_control(
299 + 'munge permalink', 'munge_permalink',
300 + $setting['munge_permalink'], $params
301 + );
302 + ?>
303 +
304 + </td></tr>
305 +
306 + <?php if (!$page->for_feed_settings()) : ?>
289 307 <tr><th scope="row">Posts from aggregator feeds:</th>
290 308 <td><ul class="options">
291 309 <li><label><input type="radio" name="use_aggregator_source_data" value="no"<?php echo ($use_aggregator_source_data!="yes")?' checked="checked"':''; ?>> Give the aggregator itself as the source of posts from an aggregator feed.</label></li>
292 310 <li><label><input type="radio" name="use_aggregator_source_data" value="yes"<?php echo ($use_aggregator_source_data=="yes")?' checked="checked"':''; ?>> Give the original source of the post as the source, not the aggregator.</label></li>
@@ -294,8 +312,9 @@
294 312 <p class="setting-description">Some feeds (for example, those produced by FeedWordPress) aggregate content from several different sources, and include information about the original source of the post.
295 313 This setting controls what FeedWordPress will give as the source of posts from
296 314 such an aggregator feed.</p>
297 315 </td></tr>
316 + <?php endif; ?>
298 317 </table>
299 318
300 319 <?php
301 320 } /* FeedWordPressPostsPage::links_box() */
@@ -307,73 +326,102 @@
307 326 * @param object $page of class FeedWordPressPostsPage tells us whether this is
308 327 * a page for one feed's settings or for global defaults
309 328 * @param array $box
310 329 *
311 - * @uses fwp_option_box_opener()
312 - * @uses fwp_option_box_closer()
313 330 */
314 331 /*static*/ function comments_and_pings_box ($page, $box = NULL) {
315 - $setting = array();
316 - $selector = array();
317 -
318 332 $whatsits = array(
319 333 'comment' => array('label' => __('Comments'), 'accept' => 'Allow comments'),
320 334 'ping' => array('label' => __('Pings'), 'accept' => 'Accept pings'),
321 335 );
322 336 $onThesePosts = 'on '.$page->these_posts_phrase();
337 +
338 + $mcflSettings = array(
339 + "yes" => __('Point to comment feeds from the original website (when provided by the syndicated feed)'),
340 + "no" => __('Point to local comment feeds on this website'),
341 + );
342 + $mcflParams = array(
343 + 'setting-default' => 'default',
344 + 'global-setting-default' => 'yes',
345 + 'labels' => array(
346 + 'yes' => __('comment feeds from the original website'),
347 + 'no' => __('local comment feeds on this website')
348 + ),
349 + 'default-input-value' => 'default',
350 + );
323 351
352 + $settings = array(); $params = array();
324 353 foreach ($whatsits as $what => $how) :
325 354 $whatsits[$what]['default'] = FeedWordPress::syndicated_status($what, /*default=*/ 'closed');
326 355
327 356 // Set up array for selector
328 - $setting = array(
329 - 'open' => array ('label' => "{$how['accept']} %s", 'checked' => ''),
330 - 'closed' => array('label' => "Don't ".strtolower($how['accept'])." %s", 'checked' => ''),
357 + $settings[$what] = array(
358 + 'open' => sprintf(__("{$how['accept']} %s"), __($onThesePosts)),
359 + 'closed' => sprintf(__("Don't ".strtolower($how['accept'])." %s"), __($onThesePosts)),
331 360 );
332 - if ($page->for_feed_settings()) :
333 - $href = $fwp_path.'/'.basename(__FILE__);
334 - $currently = trim(str_replace('%s', '', strtolower(strtok($setting[$whatsits[$what]['default']]['label'], ';'))));
335 - $setting['site-default'] = array('label' => "Use <a href=\"admin.php?page=${href}\">site-wide setting</a>", 'checked' => '');
336 - $setting['site-default']['label'] .= " (currently: <strong>${currently}</strong>)";
337 -
338 - $checked = $page->link->syndicated_status($what, 'site-default', /*fallback=*/ false);
339 - else :
340 - $checked = $whatsits[$what]['default'];
341 - endif;
342 -
343 - // Re-order appropriately
344 - $selector[$what] = array();
345 - $order = array(
346 - 'site-default',
347 - 'open',
348 - 'closed',
361 + $params[$what] = array(
362 + 'input-name' => "feed_${what}_status",
363 + 'setting-default' => NULL,
364 + 'global-setting-default' => FeedWordPress::syndicated_status($what, /*default=*/ 'closed'),
365 + 'labels' => array(
366 + 'open' => strtolower(__($how['accept'])),
367 + 'closed' => strtolower(__("Don't ".$how['accept'])),
368 + ),
349 369 );
350 - foreach ($order as $line) :
351 - if (isset($setting[$line])) :
352 - $selector[$what][$line] = $setting[$line];
353 - endif;
354 - endforeach;
355 - $selector[$what][$checked]['checked'] = ' checked="checked"';
356 370 endforeach;
357 371
358 372 // Hey ho, let's go...
359 373 ?>
360 - <table class="form-table" cellspacing="2" cellpadding="5">
374 + <table class="edit-form narrow">
361 375 <?php foreach ($whatsits as $what => $how) : ?>
376 +
362 377 <tr><th scope="row"><?php print $how['label']; ?>:</th>
363 - <td><ul class="options">
364 - <?php foreach ($selector[$what] as $code => $li) : ?>
365 - <li><label><input type="radio" name="feed_<?php print $what; ?>_status"
366 - value="<?php print $code; ?>"<?php print $li['checked']; ?> />
367 - <?php print trim(str_replace('%s', $onThesePosts, $li['label'])); ?></label></li>
368 - <?php endforeach; ?>
369 - </ul></td></tr>
378 + <td><?php
379 + $this->setting_radio_control(
380 + "$what status", "syndicated_${what}_status",
381 + $settings[$what], $params[$what]
382 + );
383 + ?></td></tr>
384 +
370 385 <?php endforeach; ?>
386 +
387 + <tr><th scope="row"><?php _e('Comment feeds'); ?></th>
388 + <td><p>When WordPress feeds and templates link to comments
389 + feeds for <?php print $page->these_posts_phrase(); ?>, the
390 + URLs for the feeds should...</p>
391 + <?php
392 + $this->setting_radio_control(
393 + "munge comments feed links", "munge_comments_feed_links",
394 + $mcflSettings, $mcflParams
395 + );
396 + ?></td></tr>
371 397 </table>
372 398
373 399 <?php
374 400 } /* FeedWordPressPostsPage::comments_and_pings_box() */
375 401
402 + /*static*/ function custom_post_settings ($page = NULL) {
403 + if (is_null($page)) :
404 + $page = $this;
405 + endif;
406 +
407 + if ($page->for_feed_settings()) :
408 + $custom_settings = $page->link->setting("postmeta", NULL, array());
409 + else :
410 + $custom_settings = get_option('feedwordpress_custom_settings');
411 + endif;
412 +
413 + if ($custom_settings and !is_array($custom_settings)) :
414 + $custom_settings = unserialize($custom_settings);
415 + endif;
416 +
417 + if (!is_array($custom_settings)) :
418 + $custom_settings = array();
419 + endif;
420 +
421 + return $custom_settings;
422 + } /* FeedWordPressPostsPage::custom_post_settings() */
423 +
376 424 /**
377 425 * Output "Custom Post Settings" settings box
378 426 *
379 427 * @since 2009.0713
@@ -379,35 +427,14 @@
379 427 * @since 2009.0713
380 428 * @param object $page of class FeedWordPressPostsPage tells us whether this is
381 429 * a page for one feed's settings or for global defaults
382 430 * @param array $box
383 - *
384 - * @uses fwp_option_box_opener()
385 - * @uses fwp_option_box_closer()
386 431 */
387 432 /*static*/ function custom_post_settings_box ($page, $box = NULL) {
388 - if ($page->for_feed_settings()) :
389 - $custom_settings = $page->link->settings["postmeta"];
390 - if ($custom_settings and !is_array($custom_settings)) :
391 - $custom_settings = unserialize($custom_settings);
392 - endif;
393 -
394 - if (!is_array($custom_settings)) :
395 - $custom_settings = array();
396 - endif;
397 - else :
398 - $custom_settings = get_option('feedwordpress_custom_settings');
399 - if ($custom_settings and !is_array($custom_settings)) :
400 - $custom_settings = unserialize($custom_settings);
401 - endif;
402 -
403 - if (!is_array($custom_settings)) :
404 - $custom_settings = array();
405 - endif;
406 - endif;
407 -
433 + $custom_settings = FeedWordPressPostsPage::custom_post_settings($page);
408 434 ?>
409 435 <div id="postcustomstuff">
436 + <p>Custom fields can be used to add extra metadata to a post that you can <a href="http://codex.wordpress.org/Using_Custom_Fields">use in your theme</a>.</p>
410 437 <table id="meta-list" cellpadding="3">
411 438 <tr>
412 439 <th>Key</th>
413 440 <th>Value</th>
@@ -415,14 +442,18 @@
415 442 </tr>
416 443
417 444 <?php
418 445 $i = 0;
419 - foreach ($custom_settings as $key => $value) :
446 + $testerButton = '<br/><button id="xpath-test-%d"'
447 + .'class="xpath-test"'
448 + .'>test expression</button>';
449 + foreach ($custom_settings as $key => $value) :
420 450 ?>
421 451 <tr style="vertical-align:top">
422 - <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo wp_specialchars($key, 'both'); ?>" />
423 - <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo wp_specialchars($key, 'both'); ?>" /></th>
424 - <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo wp_specialchars($value, 'both'); ?></textarea></td>
452 + <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo esc_html($key); ?>" />
453 + <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo esc_html($key); ?>" /></th>
454 + <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo esc_html($value); ?></textarea>
455 + <?php print sprintf($testerButton, $i); ?></td>
425 456 <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
426 457 <option value="update">save changes</option>
427 458 <option value="delete">delete this setting</option>
428 459 </select></td>
@@ -432,11 +463,17 @@
432 463 $i++;
433 464 endforeach;
434 465 ?>
435 466
436 - <tr>
467 + <tr style="vertical-align: top">
437 468 <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th>
438 - <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea></td>
469 + <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea><?php print sprintf($testerButton, $i); ?>
470 + <p>Enter a text value, or a path to a data element from the syndicated item.<br/>
471 + For data elements, you can use an XPath-like syntax wrapped in <code>$( ... )</code>.<br/>
472 + <code>hello</code> = the text value <code><span style="background-color: #30FFA0;">hello</span></code><br/>
473 + <code>$(author/email)</code> = the contents of <code>&lt;author&gt;&lt;email&gt;<span style="background-color: #30FFA0">...</span>&lt;/email&gt;&lt;/author&gt;</code><br/>
474 + <code>$(media:content/@url)</code> = the contents of <code>&lt;media:content url="<span style="background-color: #30FFA0">...</span>"&gt;...&lt;/media:content&gt;</code></p>
475 + </td>
439 476 <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
440 477 </tr>
441 478 </table>
442 479 </div> <!-- id="postcustomstuff" -->
@@ -441,88 +478,254 @@
441 478 </table>
442 479 </div> <!-- id="postcustomstuff" -->
443 480
444 481 <?php
445 - } /* FeedWordPressPostsPage::custom_post_settings_box() */
446 -}
482 + } /* FeedWordPressPostsPage::custom_post_settings_box() */
447 483
448 -function fwp_posts_page () {
449 - global $wpdb, $wp_db_version;
450 - global $fwp_post;
484 + function custom_post_types_box ($page, $box = NULL) {
485 + global $fwp_path;
486 +
487 + // local: syndicated post type // default NULL
488 + // global: syndicated_post_type // default 'post'
489 + // default-input-value => 'default'
490 +
491 + // Get all custom post types
492 + $post_types = get_post_types(array(
493 + '_builtin' => false,
494 + ), 'objects');
451 495
452 - if (FeedWordPress::needs_upgrade()) :
453 - fwp_upgrade_page();
454 - return;
455 - endif;
496 + $ul = array();
497 + $ul['post'] = __('Normal WordPress posts');
498 + foreach ($post_types as $post_type) :
499 + $ul[$post_type->name] = __($post_type->labels->name);
500 + endforeach;
501 +
502 + $params = array(
503 + 'global-setting-default' => 'post',
504 + 'default-input-value' => 'default',
505 + );
506 +
507 + // Hey, ho, let's go...
508 + ?>
509 + <table class="edit-form narrow">
510 + <tbody>
511 + <tr><th><?php _e('Custom Post Types:'); ?></th>
512 + <td><p>Incoming syndicated posts should be stored in the
513 + posts database as...</p>
514 + <?php
515 + $this->setting_radio_control(
516 + 'syndicated post type', 'syndicated_post_type',
517 + $ul, $params
518 + );
519 + ?>
520 + </td></tr>
521 + </tbody>
522 + </table>
523 + <?php
524 + } /* FeedWordPressPostsPage::custom_post_types_box() */
525 +
526 + public function boilerplate_box ($page, $box = NULL) {
527 + if ($page->for_feed_settings()) :
528 + $attrib = unserialize($page->link->settings['boilerplate rules']);
529 + $syndicatedPosts = 'this feed\'s posts';
530 + else :
531 + $attrib = get_option('feedwordpress_boilerplate');
532 + $syndicatedPosts = 'syndicated posts';
533 + endif;
534 + $hookOrder = intval($page->setting('boilerplate hook order', FEEDWORDPRESS_BOILERPLATE_DEFAULT_HOOK_ORDER));
535 +?>
536 + <style type="text/css">
537 + .boilerplate-help-box {
538 + float: right;
539 + width: 300px;
540 + border: 1px dotted #777;
541 + margin: 3px;
542 + padding: 5px;
543 + background-color: #f7f7f7;
544 + }
545 + .boilerplate-help-box dt {
546 + font-weight: bold;
547 + font-size: 85%;
548 + }
549 + .boilerplate-help-box dd {
550 + font-size: 80%; line-height: 100%; font-style: italic;
551 + padding-left: 1.5em;
552 + }
553 + .boilerplate-help-box code {
554 + font-size: inherit;
555 + font-style: normal;
556 + background-color: inherit;
557 + }
456 558
457 - // If this is a POST, validate source and user credentials
458 - FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_posts_settings', /*capability=*/ 'manage_links');
559 + .boilerplate-li {
560 + padding-bottom: 5px;
561 + margin-bottom: 5px;
562 + border-bottom: 1px dotted black;
563 + }
564 +
565 + </style>
459 566
460 - $link = FeedWordPressAdminPage::submitted_link();
461 - $link_id = $link->id;
462 - $postsPage = new FeedWordPressPostsPage($link);
567 + <div class="boilerplate-help-box">
568 + <p style="border-bottom: 1px dotted #777;">To remove boilerplate, just blank out the text box and leave it empty.</p>
463 569
464 - $mesg = null;
570 + <p>Use shortcodes to include information about your source:</p>
571 + <dl>
572 + <dt><code>[source]</code></dt>
573 + <dd>A link to the source you syndicated the post from</dd>
465 574
466 - ////////////////////////////////////////////////
467 - // Process POST request, if any ////////////////
468 - ////////////////////////////////////////////////
469 - if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
470 - $postsPage->accept_POST($fwp_post);
471 - do_action('feedwordpress_admin_page_posts_save', $fwp_post, $postsPage);
472 - endif;
575 + <dt><code>[source-name]</code></dt>
576 + <dd>Name of the source you syndicated the post from</dd>
577 +
578 + <dt><code>[source-url]</code></dt>
579 + <dd>URL of the source you syndicated the post from</dd>
580 +
581 + <dt><code>[original-link]text[/original-link]</code></dt>
582 + <dd>A link to the <em>original post</em> back on the source website,
583 + using <code>text</code> as the link text.</dd>
473 584
474 - $postsPage->ajax_interface_js();
585 + <dt><code>[original-url]</code></dt>
586 + <dd>URL of the <em>original post</em> back on the source website</dd>
475 587
476 - if ($postsPage->updated) : ?>
477 -<div class="updated"><p>Syndicated posts settings updated.</p></div>
478 -<?php elseif (!is_null($mesg)) : ?>
479 -<div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div>
480 -<?php endif; ?>
588 + <dt><code>[author]</code></dt>
589 + <dd>A link with the name of the author who wrote the post, linking to other posts by the same author</dd>
481 590
591 + <dt><code>[author-name]</code></dt>
592 + <dd>Name of the author who wrote the post</dd>
593 +
594 + <dt><code>[feed-setting key="setting-name"]</code></dt>
595 + <dd>Value of a custom feed setting (named <code>setting-name</code>) for the feed</dd>
596 + </dl>
597 + </div>
598 +
482 599 <?php
483 - $links = FeedWordPress::syndicated_links();
484 - $postsPage->open_sheet('Syndicated Posts & Links');
600 + print "<ul>\n";
601 + if (!is_array($attrib)) : $attrib = array(); endif;
602 +
603 + print '<input type="hidden" id="next-boilerplate-rule-index" name="next_boilerplate_rule_index" value="'.count($attrib).'" />';
604 +
605 + // In AJAX environment, this is a dummy rule that stays hidden. In a
606 + // non-AJAX environment, this provides a blank rule that we can fill in.
607 + $attrib['new'] = array(
608 + 'class' => array('hide-if-js'),
609 + 'placement' => 'before',
610 + 'element' => 'post',
611 + 'template' => '',
612 + );
613 +
614 + foreach ($attrib as $index => $line) :
615 + if (isset($line['template'])) :
616 + $selected['before'] = (($line['placement']=='before') ? ' selected="selected"' : '');
617 + $selected['after'] = (($line['placement']=='after') ? ' selected="selected"' : '');
618 + $selected['title'] = (($line['element']=='title') ? ' selected="selected"' : '');
619 + $selected['post'] = (($line['element']=='post') ? ' selected="selected"' : '');
620 + $selected['excerpt'] = (($line['element']=='excerpt') ? ' selected="selected"' : '');
621 +
622 + if (!isset($line['class'])) : $line['class'] = array(); endif;
623 + $line['class'][] = 'boilerplate-li';
485 624 ?>
486 -<style type="text/css">
487 - table.edit-form th, table.form-table th { width: 27%; vertical-align: top; }
488 - table.edit-form td, table.form-table td { width: 73%; vertical-align: top; }
489 - ul.options { margin: 0; padding: 0; list-style: none; }
490 -</style>
491 -<div id="post-body">
625 +
626 +<li id="boilerplate-<?php print $index; ?>-li" class="<?php print implode(' ', $line['class']); ?>">&raquo; <strong>Add</strong> <select id="boilerplate-<?php print $index; ?>-placement" name="boilerplate[<?php print $index; ?>][placement]" style="width: 8.0em">
627 +<option value="before"<?php print $selected['before']; ?>>before</option>
628 +<option value="after"<?php print $selected['after']; ?>>after</option>
629 +</select> the <select style="width: 8.0em" id="boilerplate-<?php print $index; ?>-element" name="boilerplate[<?php print $index; ?>][element]">
630 +<option value="title"<?php print $selected['title']; ?>>title</option>
631 +<option value="post"<?php print $selected['post']; ?>>content</option>
632 +<option value="excerpt"<?php print $selected['excerpt']; ?>>excerpt</option>
633 +</select> of
634 +<?php print $syndicatedPosts; ?>: <textarea style="vertical-align: top; width: 40%;" rows="2" cols="30" class="boilerplate-template" id="boilerplate-<?php print $index; ?>-template" name="boilerplate[<?php print $index; ?>][template]"><?php print htmlspecialchars($line['template']); ?></textarea></li>
492 635 <?php
493 -$boxes_by_methods = array(
494 - 'publication_box' => __('Syndicated Posts'),
495 - 'links_box' => __('Links'),
496 - 'formatting_box' => __('Formatting'),
497 - 'comments_and_pings_box' => __('Comments & Pings'),
498 - 'custom_post_settings_box' => __('Custom Post Settings (to apply to each syndicated post)'),
499 -);
636 + endif;
637 + endforeach;
638 +?>
639 + </ul>
640 + <br style="clear: both" />
500 641
501 -// Feed-level settings don't exist for these.
502 -if ($postsPage->for_feed_settings()) :
503 - unset($boxes_by_methods['links_box']);
504 -endif;
642 + <script type="text/javascript">
643 + jQuery(document).ready( function($) {
644 + $('.boilerplate-template').blur( function() {
645 + if (this.value.length == 0) {
646 + var theLi = $('li:has(#'+this.id+")");
647 + theLi.hide('normal')
648 + }
649 + } );
505 650
506 - foreach ($boxes_by_methods as $method => $title) :
507 - fwp_add_meta_box(
508 - /*id=*/ 'feedwordpress_'.$method,
509 - /*title=*/ $title,
510 - /*callback=*/ array('FeedWordPressPostsPage', $method),
511 - /*page=*/ $postsPage->meta_box_context(),
512 - /*context=*/ $postsPage->meta_box_context()
513 - );
514 - endforeach;
515 - do_action('feedwordpress_admin_page_posts_meta_boxes', $postsPage);
516 -?>
517 - <div class="metabox-holder">
651 + var addRuleLi = document.createElement('li');
652 + addRuleLi.innerHTML = '<strong style="vertical-align: middle; font-size: 110%">[+]</strong> <a style="font-variant: small-caps" id="add-new-boilerplate-rule" href="#">Add new boilerplate</a> ….';
653 + $('#boilerplate-new-li').after(addRuleLi);
654 +
655 + $('#add-new-boilerplate-rule').click( function() {
656 + // Get index counter
657 + var nextIndex = parseInt($('#next-boilerplate-rule-index').val());
658 +
659 + var newIdPrefix = 'boilerplate-'+nextIndex;
660 + var newNamePrefix = 'boilerplate['+nextIndex+']';
661 +
662 + var dummy = {};
663 + dummy['li'] = {'el': $('#boilerplate-new-li') }
664 + dummy['placement'] = {'el': $('#boilerplate-new-placement') };
665 + dummy['element'] = {'el': $('#boilerplate-new-element') };
666 + dummy['template'] = {'el': $('#boilerplate-new-template') };
667 +
668 + for (var element in dummy) {
669 + dummy[element]['save'] = {
670 + 'id': dummy[element]['el'].attr('id'),
671 + 'name': dummy[element]['el'].attr('name')
672 + };
673 + dummy[element]['el'].attr('id', newIdPrefix+'-'+element);
674 + dummy[element]['el'].attr('name', newNamePrefix+'['+element+']');
675 + }
676 +
677 + var newLi = $('#'+newIdPrefix+'-li').clone(/*events=*/ true);
678 + //newLi.attr('id', null);
679 + newLi.removeClass('hide-if-js');
680 + newLi.addClass('boilerplate-li');
681 + newLi.css('display', 'none');
682 +
683 + // Switch back
684 + for (var element in dummy) {
685 + dummy[element]['el'].attr('id', dummy[element]['save']['id']);
686 + dummy[element]['el'].attr('name', dummy[element]['save']['name']);
687 + }
688 +
689 + $('#boilerplate-new-li').before(newLi);
690 + newLi.show('normal');
691 +
692 + $('#next-boilerplate-rule-index').val(nextIndex+1);
693 +
694 + return false;
695 + } )
696 + } );
697 + </script>
518 698 <?php
519 - fwp_do_meta_boxes($postsPage->meta_box_context(), $postsPage->meta_box_context(), $postsPage);
699 + if ($page->for_default_settings()) :
520 700 ?>
521 - </div> <!-- class="metabox-holder" -->
522 -</div> <!-- id="post-body" -->
701 + <h3>Advanced Settings</h3>
702 + <table class="edit-form narrow">
703 + <tbody>
704 + <tr><th scope="row"><?php _e("Hook Order:") ?></th>
705 + <td><input type="number" name="boilerplate_hook_order" value="<?php print esc_attr($hookOrder); ?>" /></td></tr>
706 + </tbody>
707 + </table>
523 708 <?php
524 - $postsPage->close_sheet();
525 -} /* function fwp_posts_page () */
709 + endif;
710 + } /* FeedWordPressPostsPage::boilerplate_box() */
526 711
527 - fwp_posts_page();
712 + function display () {
713 + $this->boxes_by_methods = array(
714 + 'publication_box' => __('Syndicated Posts'),
715 + 'links_box' => __('Links'),
716 + 'formatting_box' => __('Formatting'),
717 + 'boilerplate_box' => ('Boilerplate / Credits'),
718 + 'comments_and_pings_box' => __('Comments & Pings'),
719 + 'custom_post_settings_box' => __('Custom Post Settings (to apply to each syndicated post)'),
720 + 'custom_post_types_box' => ('Custom Post Types (advanced database settings)'),
721 + );
722 +
723 + parent::display();
724 + } /* FeedWordPressPostsPage::display () */
725 +
726 +
727 +}
728 +
729 + $postsPage = new FeedWordPressPostsPage;
730 + $postsPage->display();
528 731