| @@ -1,9 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | require_once(dirname(__FILE__) . '/admin-ui.php'); |
| 3 | +require_once(dirname(__FILE__) . '/updatedpostscontrol.class.php'); | |
| 3 | 4 | |
| 4 | 5 | class FeedWordPressPostsPage extends FeedWordPressAdminPage { |
| 5 | 6 | var $link = NULL; |
| 7 | + var $updatedPosts = NULL; | |
| 6 | 8 | |
| 7 | 9 | /** |
| 8 | 10 | * Construct the posts page object. |
| 9 | 11 | * |
| @@ -12,10 +14,106 @@ | ||
| 12 | 14 | function FeedWordPressPostsPage ($link = NULL) { |
| 13 | 15 | FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresspostspage', $link); |
| 14 | 16 | $this->dispatch = 'feedwordpress_posts_settings'; |
| 15 | 17 | $this->filename = __FILE__; |
| 18 | + $this->updatedPosts = new UpdatedPostsControl($this); | |
| 16 | 19 | } /* FeedWordPressPostsPage constructor */ |
| 17 | 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 | + | |
| 18 | 116 | /** |
| 19 | 117 | * Outputs "Publication" settings box. |
| 20 | 118 | * |
| 21 | 119 | * @since 2009.0713 |
| @@ -44,8 +142,10 @@ | ||
| 44 | 142 | ); |
| 45 | 143 | if (SyndicatedPost::use_api('post_status_pending')) : |
| 46 | 144 | $setting['pending'] = array('label' => "Hold %s for review; mark as Pending", 'checked' => ''); |
| 47 | 145 | endif; |
| 146 | + | |
| 147 | + | |
| 48 | 148 | if ($page->for_feed_settings()) : |
| 49 | 149 | $href = $fwp_path.'/'.basename(__FILE__); |
| 50 | 150 | $currently = str_replace('%s', '', strtolower(strtok($setting[$post_status_global]['label'], ';'))); |
| 51 | 151 | $setting['site-default'] = array('label' => "Use <a href=\"admin.php?page=${href}\">site-wide setting</a>", 'checked' => ''); |
| @@ -79,9 +179,9 @@ | ||
| 79 | 179 | #syndicated-publication-form td { width: 73%; vertical-align: top; } |
| 80 | 180 | </style> |
| 81 | 181 | |
| 82 | 182 | <table id="syndicated-publication-form" class="form-table" cellspacing="2" cellpadding="5"> |
| 83 | - <tr><th scope="row">Status for new posts:</th> | |
| 183 | + <tr><th scope="row"><?php _e('New posts:'); ?></th> | |
| 84 | 184 | <td><ul class="options"> |
| 85 | 185 | <?php foreach ($selector as $code => $li) : ?> |
| 86 | 186 | <li><label><input type="radio" name="feed_post_status" |
| 87 | 187 | value="<?php print $code; ?>"<?php print $li['checked']; ?> /> |
| @@ -88,8 +188,10 @@ | ||
| 88 | 188 | <?php print str_replace('%s', $thesePosts, $li['label']); ?></label></li> |
| 89 | 189 | <?php endforeach; ?> |
| 90 | 190 | </ul></td> |
| 91 | 191 | </tr> |
| 192 | + | |
| 193 | + <?php $page->updatedPosts->display(); ?> | |
| 92 | 194 | </table> |
| 93 | 195 | |
| 94 | 196 | <?php |
| 95 | 197 | } /* FeedWordPressPostsPage::publication_box () */ |
| @@ -105,21 +207,59 @@ | ||
| 105 | 207 | * @uses fwp_option_box_opener() |
| 106 | 208 | * @uses fwp_option_box_closer() |
| 107 | 209 | */ |
| 108 | 210 | function formatting_box ($page, $box = NULL) { |
| 109 | - $formatting_filters = get_option('feedwordpress_formatting_filters'); | |
| 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; | |
| 110 | 228 | ?> |
| 111 | 229 | <table class="form-table" cellspacing="2" cellpadding="5"> |
| 112 | - <tr><th scope="row">Formatting filters:</th> | |
| 113 | - <td><select name="formatting_filters" size="1"> | |
| 114 | - <option value="no"<?php echo ($formatting_filters!='yes')?' selected="selected"':''; ?>>Protect syndicated posts from formatting filters</option> | |
| 115 | - <option value="yes"<?php echo ($formatting_filters=='yes')?' selected="selected"':''; ?>>Expose syndicated posts to formatting filters</option> | |
| 116 | - </select> | |
| 117 | - <p class="setting-description">If you have trouble getting plugins to work that are supposed to insert | |
| 118 | - elements after posts (like relevant links or a social networking | |
| 119 | - <q>Share This</q> button), try changing this option to see if it fixes your | |
| 120 | - problem.</p> | |
| 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> | |
| 121 | 260 | </td></tr> |
| 261 | + | |
| 122 | 262 | </table> |
| 123 | 263 | <?php |
| 124 | 264 | } /* FeedWordPressPostsPage::formatting_box() */ |
| 125 | 265 | |
| @@ -306,14 +446,16 @@ | ||
| 306 | 446 | } |
| 307 | 447 | |
| 308 | 448 | function fwp_posts_page () { |
| 309 | 449 | global $wpdb, $wp_db_version; |
| 310 | - | |
| 450 | + global $fwp_post; | |
| 451 | + | |
| 311 | 452 | if (FeedWordPress::needs_upgrade()) : |
| 312 | 453 | fwp_upgrade_page(); |
| 313 | 454 | return; |
| 314 | 455 | endif; |
| 315 | 456 | |
| 457 | + // If this is a POST, validate source and user credentials | |
| 316 | 458 | FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_posts_settings', /*capability=*/ 'manage_links'); |
| 317 | 459 | |
| 318 | 460 | $link = FeedWordPressAdminPage::submitted_link(); |
| 319 | 461 | $link_id = $link->id; |
| @@ -321,94 +463,18 @@ | ||
| 321 | 463 | |
| 322 | 464 | $mesg = null; |
| 323 | 465 | |
| 324 | 466 | //////////////////////////////////////////////// |
| 325 | - // Process POST request, if any ///////////////// | |
| 467 | + // Process POST request, if any //////////////// | |
| 326 | 468 | //////////////////////////////////////////////// |
| 327 | - if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['submit'])) : | |
| 328 | - // custom post settings | |
| 329 | - foreach ($GLOBALS['fwp_post']['notes'] as $mn) : | |
| 330 | - $mn['key0'] = trim($mn['key0']); | |
| 331 | - $mn['key1'] = trim($mn['key1']); | |
| 332 | - | |
| 333 | - if (strlen($mn['key0']) > 0) : | |
| 334 | - unset($custom_settings[$mn['key0']]); // out with the old | |
| 335 | - endif; | |
| 336 | - | |
| 337 | - if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) : | |
| 338 | - $custom_settings[$mn['key1']] = $mn['value']; // in with the new | |
| 339 | - endif; | |
| 340 | - endforeach; | |
| 341 | - | |
| 342 | - if (is_object($link) and $link->found()) : | |
| 343 | - $alter = array (); | |
| 344 | - | |
| 345 | - $link->settings['postmeta'] = serialize($custom_settings); | |
| 346 | - | |
| 347 | - // Post status, comment status, ping status | |
| 348 | - foreach (array('post', 'comment', 'ping') as $what) : | |
| 349 | - $sfield = "feed_{$what}_status"; | |
| 350 | - if (isset($GLOBALS['fwp_post'][$sfield])) : | |
| 351 | - if ($GLOBALS['fwp_post'][$sfield]=='site-default') : | |
| 352 | - unset($link->settings["{$what} status"]); | |
| 353 | - else : | |
| 354 | - $link->settings["{$what} status"] = $GLOBALS['fwp_post'][$sfield]; | |
| 355 | - endif; | |
| 356 | - endif; | |
| 357 | - endforeach; | |
| 358 | - | |
| 359 | - $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'"; | |
| 360 | - | |
| 361 | - $alter_set = implode(", ", $alter); | |
| 362 | - | |
| 363 | - // issue update query | |
| 364 | - $result = $wpdb->query(" | |
| 365 | - UPDATE $wpdb->links | |
| 366 | - SET $alter_set | |
| 367 | - WHERE link_id='$link_id' | |
| 368 | - "); | |
| 369 | - $updated_link = true; | |
| 370 | - | |
| 371 | - // reload link information from DB | |
| 372 | - if (function_exists('clean_bookmark_cache')) : | |
| 373 | - clean_bookmark_cache($link_id); | |
| 374 | - endif; | |
| 375 | - $link =& new SyndicatedLink($link_id); | |
| 376 | - else : | |
| 377 | - // update_option ... | |
| 378 | - if (isset($GLOBALS['fwp_post']['feed_post_status'])) : | |
| 379 | - update_option('feedwordpress_syndicated_post_status', $GLOBALS['fwp_post']['feed_post_status']); | |
| 380 | - endif; | |
| 381 | - | |
| 382 | - update_option('feedwordpress_custom_settings', serialize($custom_settings)); | |
| 383 | - | |
| 384 | - update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']); | |
| 385 | - update_option('feedwordpress_use_aggregator_source_data', $_REQUEST['use_aggregator_source_data']); | |
| 386 | - update_option('feedwordpress_formatting_filters', $_REQUEST['formatting_filters']); | |
| 387 | - | |
| 388 | - if (isset($_REQUEST['feed_comment_status']) and ($_REQUEST['feed_comment_status'] == 'open')) : | |
| 389 | - update_option('feedwordpress_syndicated_comment_status', 'open'); | |
| 390 | - else : | |
| 391 | - update_option('feedwordpress_syndicated_comment_status', 'closed'); | |
| 392 | - endif; | |
| 393 | - | |
| 394 | - if (isset($_REQUEST['feed_ping_status']) and ($_REQUEST['feed_ping_status'] == 'open')) : | |
| 395 | - update_option('feedwordpress_syndicated_ping_status', 'open'); | |
| 396 | - else : | |
| 397 | - update_option('feedwordpress_syndicated_ping_status', 'closed'); | |
| 398 | - endif; | |
| 399 | - | |
| 400 | - $updated_link = true; | |
| 401 | - endif; | |
| 402 | - | |
| 403 | - do_action('feedwordpress_admin_page_posts_save', $GLOBALS['fwp_post'], $postsPage); | |
| 404 | - else : | |
| 405 | - $updated_link = false; | |
| 469 | + if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') : | |
| 470 | + $postsPage->accept_POST($fwp_post); | |
| 471 | + do_action('feedwordpress_admin_page_posts_save', $fwp_post, $postsPage); | |
| 406 | 472 | endif; |
| 407 | 473 | |
| 408 | 474 | $postsPage->ajax_interface_js(); |
| 409 | 475 | |
| 410 | - if ($updated_link) : ?> | |
| 476 | + if ($postsPage->updated) : ?> | |
| 411 | 477 | <div class="updated"><p>Syndicated posts settings updated.</p></div> |
| 412 | 478 | <?php elseif (!is_null($mesg)) : ?> |
| 413 | 479 | <div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div> |
| 414 | 480 | <?php endif; ?> |
| @@ -424,11 +490,11 @@ | ||
| 424 | 490 | </style> |
| 425 | 491 | <div id="post-body"> |
| 426 | 492 | <?php |
| 427 | 493 | $boxes_by_methods = array( |
| 428 | - 'publication_box' => __('Publication'), | |
| 494 | + 'publication_box' => __('Syndicated Posts'), | |
| 495 | + 'links_box' => __('Links'), | |
| 429 | 496 | 'formatting_box' => __('Formatting'), |
| 430 | - 'links_box' => __('Links'), | |
| 431 | 497 | 'comments_and_pings_box' => __('Comments & Pings'), |
| 432 | 498 | 'custom_post_settings_box' => __('Custom Post Settings (to apply to each syndicated post)'), |
| 433 | 499 | ); |
| 434 | 500 | |
| @@ -433,9 +499,8 @@ | ||
| 433 | 499 | ); |
| 434 | 500 | |
| 435 | 501 | // Feed-level settings don't exist for these. |
| 436 | 502 | if ($postsPage->for_feed_settings()) : |
| 437 | - unset($boxes_by_methods['formatting_box']); | |
| 438 | 503 | unset($boxes_by_methods['links_box']); |
| 439 | 504 | endif; |
| 440 | 505 | |
| 441 | 506 | foreach ($boxes_by_methods as $method => $title) : |