PluginProbe
FeedWordPress / 2010.0127
FeedWordPress v2010.0127
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 / posts-page.php

posts-page.php in FeedWordPress 2010.0127, at posts-page.php

529 lines 19.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once(dirname(__FILE__) . '/admin-ui.php');
3 require_once(dirname(__FILE__) . '/updatedpostscontrol.class.php');
4
5 class FeedWordPressPostsPage extends FeedWordPressAdminPage {
6 var $link = NULL;
7 var $updatedPosts = NULL;
8
9 /**
10 * Construct the posts page object.
11 *
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 */
14 function FeedWordPressPostsPage ($link = NULL) {
15 FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresspostspage', $link);
16 $this->dispatch = 'feedwordpress_posts_settings';
17 $this->filename = __FILE__;
18 $this->updatedPosts = new UpdatedPostsControl($this);
19 } /* FeedWordPressPostsPage constructor */
20
21 function accept_POST ($post) {
22 global $wpdb;
23
24 $link_id = $this->link->id;
25
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) :
30 $mn['key0'] = trim($mn['key0']);
31 $mn['key1'] = trim($mn['key1']);
32
33 if (strlen($mn['key0']) > 0) :
34 unset($custom_settings[$mn['key0']]); // out with the old
35 endif;
36
37 if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
38 $custom_settings[$mn['key1']] = $mn['value']; // in with the new
39 endif;
40 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'];
50 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;
61 endif;
62 endforeach;
63
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;
85
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');
97 else :
98 update_option('feedwordpress_syndicated_comment_status', 'closed');
99 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;
106
107 $this->updated = true;
108 endif;
109
110 // Probably a "Go" button for the drop-down
111 else :
112 $this->updated = false;
113 endif;
114 }
115
116 /**
117 * Outputs "Publication" settings box.
118 *
119 * @since 2009.0713
120 * @param object $page of class FeedWordPressPostsPage tells us whether this is
121 * a page for one feed's settings or for global defaults
122 * @param array $box
123 *
124 * @uses FeedWordPressPostsPage::these_posts_phrase()
125 * @uses FeedWordPress::syndicated_status()
126 * @uses SyndicatedLink::syndicated_status()
127 * @uses SyndicatedPost::use_api()
128 * @uses fwp_option_box_opener()
129 * @uses fwp_option_box_closer()
130 */
131 /*static*/ function publication_box ($page, $box = NULL) {
132 global $fwp_path;
133
134 $post_status_global = FeedWordPress::syndicated_status('post', /*default=*/ 'publish');
135 $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' => ''),
142 );
143 if (SyndicatedPost::use_api('post_status_pending')) :
144 $setting['pending'] = array('label' => "Hold %s for review; mark as Pending", 'checked' => '');
145 endif;
146
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 // Hey ho, let's go...
176 ?>
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">
183 <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>
192
193 <?php $page->updatedPosts->display(); ?>
194 </table>
195
196 <?php
197 } /* FeedWordPressPostsPage::publication_box () */
198
199 /**
200 * Outputs "Formatting" settings box
201 *
202 * @since 2009.0713
203 * @param object $page of class FeedWordPressPostsPage tells us whether this is
204 * a page for one feed's settings or for global defaults
205 * @param array $box
206 *
207 * @uses fwp_option_box_opener()
208 * @uses fwp_option_box_closer()
209 */
210 function formatting_box ($page, $box = NULL) {
211 global $fwp_path;
212 $thesePosts = $page->these_posts_phrase();
213 $global_resolve_relative = get_option('feedwordpress_resolve_relative', 'yes');
214 if ($page->for_feed_settings()) :
215 $formatting_filters = null;
216 $resolve_relative = $page->link->setting('resolve relative', NULL, 'default');
217 $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 else :
224 $formatting_filters = get_option('feedwordpress_formatting_filters', 'no');
225 $resolve_relative = $global_resolve_relative;
226 $url = 'http://example.com';
227 endif;
228 ?>
229 <table class="form-table" cellspacing="2" cellpadding="5">
230 <?php if (!is_null($formatting_filters)) : ?>
231
232 <tr><th scope="row">Formatting filters:</th>
233 <td><select name="formatting_filters" size="1">
234 <option value="no"<?php echo ($formatting_filters!='yes')?' selected="selected"':''; ?>>Protect syndicated posts from formatting filters</option>
235 <option value="yes"<?php echo ($formatting_filters=='yes')?' selected="selected"':''; ?>>Expose syndicated posts to formatting filters</option>
236 </select>
237 <p class="setting-description">If you have trouble getting plugins to work that are supposed to insert
238 elements after posts (like relevant links or a social networking
239 <q>Share This</q> button), try changing this option to see if it fixes your
240 problem.</p>
241 </td></tr>
242
243 <?php endif; ?>
244
245 <tr><th scope="row">Relative URIs:</th>
246 <td>If link or image in a syndicated post from <code><?php print $url; ?></code>
247 refers to a partial URI like <code>/about</code>, where should
248 the syndicated copy point to?</p>
249
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>
260 </td></tr>
261
262 </table>
263 <?php
264 } /* FeedWordPressPostsPage::formatting_box() */
265
266 /**
267 * Output "Links" settings box
268 *
269 * @since 2009.0713
270 * @param object $page of class FeedWordPressPostsPage tells us whether this is
271 * a page for one feed's settings or for global defaults
272 * @param array $box
273 *
274 * @uses fwp_option_box_opener()
275 * @uses fwp_option_box_closer()
276 */
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');
280 ?>
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>
288
289 <tr><th scope="row">Posts from aggregator feeds:</th>
290 <td><ul class="options">
291 <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 <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>
293 </ul>
294 <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 This setting controls what FeedWordPress will give as the source of posts from
296 such an aggregator feed.</p>
297 </td></tr>
298 </table>
299
300 <?php
301 } /* FeedWordPressPostsPage::links_box() */
302
303 /**
304 * Output "Comments & Pings" settings box
305 *
306 * @since 2009.0713
307 * @param object $page of class FeedWordPressPostsPage tells us whether this is
308 * a page for one feed's settings or for global defaults
309 * @param array $box
310 *
311 * @uses fwp_option_box_opener()
312 * @uses fwp_option_box_closer()
313 */
314 /*static*/ function comments_and_pings_box ($page, $box = NULL) {
315 $setting = array();
316 $selector = array();
317
318 $whatsits = array(
319 'comment' => array('label' => __('Comments'), 'accept' => 'Allow comments'),
320 'ping' => array('label' => __('Pings'), 'accept' => 'Accept pings'),
321 );
322 $onThesePosts = 'on '.$page->these_posts_phrase();
323
324 foreach ($whatsits as $what => $how) :
325 $whatsits[$what]['default'] = FeedWordPress::syndicated_status($what, /*default=*/ 'closed');
326
327 // 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' => ''),
331 );
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',
349 );
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 endforeach;
357
358 // Hey ho, let's go...
359 ?>
360 <table class="form-table" cellspacing="2" cellpadding="5">
361 <?php foreach ($whatsits as $what => $how) : ?>
362 <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>
370 <?php endforeach; ?>
371 </table>
372
373 <?php
374 } /* FeedWordPressPostsPage::comments_and_pings_box() */
375
376 /**
377 * Output "Custom Post Settings" settings box
378 *
379 * @since 2009.0713
380 * @param object $page of class FeedWordPressPostsPage tells us whether this is
381 * a page for one feed's settings or for global defaults
382 * @param array $box
383 *
384 * @uses fwp_option_box_opener()
385 * @uses fwp_option_box_closer()
386 */
387 /*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
408 ?>
409 <div id="postcustomstuff">
410 <table id="meta-list" cellpadding="3">
411 <tr>
412 <th>Key</th>
413 <th>Value</th>
414 <th>Action</th>
415 </tr>
416
417 <?php
418 $i = 0;
419 foreach ($custom_settings as $key => $value) :
420 ?>
421 <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>
425 <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
426 <option value="update">save changes</option>
427 <option value="delete">delete this setting</option>
428 </select></td>
429 </tr>
430
431 <?php
432 $i++;
433 endforeach;
434 ?>
435
436 <tr>
437 <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>
439 <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
440 </tr>
441 </table>
442 </div> <!-- id="postcustomstuff" -->
443
444 <?php
445 } /* FeedWordPressPostsPage::custom_post_settings_box() */
446 }
447
448 function fwp_posts_page () {
449 global $wpdb, $wp_db_version;
450 global $fwp_post;
451
452 if (FeedWordPress::needs_upgrade()) :
453 fwp_upgrade_page();
454 return;
455 endif;
456
457 // If this is a POST, validate source and user credentials
458 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_posts_settings', /*capability=*/ 'manage_links');
459
460 $link = FeedWordPressAdminPage::submitted_link();
461 $link_id = $link->id;
462 $postsPage = new FeedWordPressPostsPage($link);
463
464 $mesg = null;
465
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;
473
474 $postsPage->ajax_interface_js();
475
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; ?>
481
482 <?php
483 $links = FeedWordPress::syndicated_links();
484 $postsPage->open_sheet('Syndicated Posts & Links');
485 ?>
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">
492 <?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 );
500
501 // Feed-level settings don't exist for these.
502 if ($postsPage->for_feed_settings()) :
503 unset($boxes_by_methods['links_box']);
504 endif;
505
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">
518 <?php
519 fwp_do_meta_boxes($postsPage->meta_box_context(), $postsPage->meta_box_context(), $postsPage);
520 ?>
521 </div> <!-- class="metabox-holder" -->
522 </div> <!-- id="post-body" -->
523 <?php
524 $postsPage->close_sheet();
525 } /* function fwp_posts_page () */
526
527 fwp_posts_page();
528
529