| @@ -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 | * |
| @@ -8,14 +10,119 @@ | ||
| 8 | 10 | * Construct the posts page object. |
| 9 | 11 | * |
| 10 | 12 | * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings |
| 11 | 13 | */ |
| 12 | - function FeedWordPressPostsPage ($link = NULL) { | |
| 14 | + function FeedWordPressPostsPage ($link = -1) { | |
| 15 | + if (is_numeric($link) and -1 == $link) : | |
| 16 | + $link = FeedWordPressAdminPage::submitted_link(); | |
| 17 | + endif; | |
| 18 | + | |
| 13 | 19 | FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresspostspage', $link); |
| 14 | - $this->dispatch = 'feedwordpress_posts_settings'; | |
| 20 | + $this->dispatch = 'feedwordpress_admin_page_posts'; | |
| 15 | 21 | $this->filename = __FILE__; |
| 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 | + ); | |
| 16 | 29 | } /* FeedWordPressPostsPage constructor */ |
| 17 | 30 | |
| 31 | + function save_settings ($post) { | |
| 32 | + // custom post settings | |
| 33 | + $custom_settings = $this->custom_post_settings(); | |
| 34 | + | |
| 35 | + foreach ($post['notes'] as $mn) : | |
| 36 | + if (isset($mn['key0'])) : | |
| 37 | + $mn['key0'] = trim($mn['key0']); | |
| 38 | + if (strlen($mn['key0']) > 0) : | |
| 39 | + unset($custom_settings[$mn['key0']]); // out with the old | |
| 40 | + endif; | |
| 41 | + endif; | |
| 42 | + | |
| 43 | + if (isset($mn['key1'])) : | |
| 44 | + $mn['key1'] = trim($mn['key1']); | |
| 45 | + | |
| 46 | + if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) : | |
| 47 | + $custom_settings[$mn['key1']] = $mn['value']; // in with the new | |
| 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; | |
| 78 | + endforeach; | |
| 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']; | |
| 85 | + 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 | + parent::save_settings($post); | |
| 123 | + } | |
| 124 | + | |
| 18 | 125 | /** |
| 19 | 126 | * Outputs "Publication" settings box. |
| 20 | 127 | * |
| 21 | 128 | * @since 2009.0713 |
| @@ -26,70 +133,43 @@ | ||
| 26 | 133 | * @uses FeedWordPressPostsPage::these_posts_phrase() |
| 27 | 134 | * @uses FeedWordPress::syndicated_status() |
| 28 | 135 | * @uses SyndicatedLink::syndicated_status() |
| 29 | 136 | * @uses SyndicatedPost::use_api() |
| 30 | - * @uses fwp_option_box_opener() | |
| 31 | - * @uses fwp_option_box_closer() | |
| 32 | 137 | */ |
| 33 | 138 | /*static*/ function publication_box ($page, $box = NULL) { |
| 34 | - global $fwp_path; | |
| 35 | - | |
| 36 | - $post_status_global = FeedWordPress::syndicated_status('post', /*default=*/ 'publish'); | |
| 37 | 139 | $thesePosts = $page->these_posts_phrase(); |
| 38 | - | |
| 39 | - // Set up array for selector | |
| 40 | - $setting = array( | |
| 41 | - 'publish' => array ('label' => "Publish %s immediately", 'checked' => ''), | |
| 42 | - 'draft' => array('label' => "Save %s as drafts", 'checked' => ''), | |
| 43 | - 'private' => array('label' => "Save %s as private posts", 'checked' => ''), | |
| 140 | + $postSelector = array( | |
| 141 | + 'publish' => "Publish %s immediately", | |
| 142 | + 'pending' => "Hold %s for review; mark as Pending", | |
| 143 | + 'draft' => "Save %s as drafts", | |
| 144 | + 'private' => "Save %s as private posts", | |
| 44 | 145 | ); |
| 45 | - if (SyndicatedPost::use_api('post_status_pending')) : | |
| 46 | - $setting['pending'] = array('label' => "Hold %s for review; mark as Pending", 'checked' => ''); | |
| 47 | - endif; | |
| 48 | - if ($page->for_feed_settings()) : | |
| 49 | - $href = $fwp_path.'/'.basename(__FILE__); | |
| 50 | - $currently = str_replace('%s', '', strtolower(strtok($setting[$post_status_global]['label'], ';'))); | |
| 51 | - $setting['site-default'] = array('label' => "Use <a href=\"admin.php?page=${href}\">site-wide setting</a>", 'checked' => ''); | |
| 52 | - $setting['site-default']['label'] .= " (currently: <strong>${currently}</strong>)"; | |
| 53 | - | |
| 54 | - $checked = $page->link->syndicated_status('post', 'site-default', /*fallback=*/ false); | |
| 55 | - else : | |
| 56 | - $checked = $post_status_global; | |
| 57 | - endif; | |
| 58 | - | |
| 59 | - // Re-order appropriately | |
| 60 | - $selector = array(); | |
| 61 | - $order = array( | |
| 62 | - 'site-default', | |
| 63 | - 'publish', | |
| 64 | - 'pending', | |
| 65 | - 'draft', | |
| 66 | - 'private', | |
| 146 | + $labels = array(); | |
| 147 | + foreach ($postSelector as $index => $value) : | |
| 148 | + $postSelector[$index] = sprintf(__($value), $thesePosts); | |
| 149 | + $labels[$index] = __(str_replace(' %s', '', strtolower(strtok($value, ';')))); | |
| 150 | + endforeach; | |
| 151 | + | |
| 152 | + $params = array( | |
| 153 | + 'input-name' => 'feed_post_status', | |
| 154 | + 'setting-default' => NULL, | |
| 155 | + 'global-setting-default' => 'publish', | |
| 156 | + 'labels' => $labels, | |
| 67 | 157 | ); |
| 68 | - foreach ($order as $line) : | |
| 69 | - if (isset($setting[$line])) : | |
| 70 | - $selector[$line] = $setting[$line]; | |
| 71 | - endif; | |
| 72 | - endforeach; | |
| 73 | - $selector[$checked]['checked'] = ' checked="checked"'; | |
| 74 | - | |
| 158 | + | |
| 75 | 159 | // Hey ho, let's go... |
| 76 | 160 | ?> |
| 77 | - <style type="text/css"> | |
| 78 | - #syndicated-publication-form th { width: 27%; vertical-align: top; } | |
| 79 | - #syndicated-publication-form td { width: 73%; vertical-align: top; } | |
| 80 | - </style> | |
| 81 | - | |
| 82 | - <table id="syndicated-publication-form" class="form-table" cellspacing="2" cellpadding="5"> | |
| 83 | - <tr><th scope="row">Status for new posts:</th> | |
| 84 | - <td><ul class="options"> | |
| 85 | - <?php foreach ($selector as $code => $li) : ?> | |
| 86 | - <li><label><input type="radio" name="feed_post_status" | |
| 87 | - value="<?php print $code; ?>"<?php print $li['checked']; ?> /> | |
| 88 | - <?php print str_replace('%s', $thesePosts, $li['label']); ?></label></li> | |
| 89 | - <?php endforeach; ?> | |
| 90 | - </ul></td> | |
| 91 | - </tr> | |
| 161 | + <table id="syndicated-publication-form" class="edit-form narrow"> | |
| 162 | + <tr><th scope="row"><?php _e('New posts:'); ?></th> | |
| 163 | + <td><?php | |
| 164 | + $this->setting_radio_control( | |
| 165 | + 'post status', 'syndicated_post_status', | |
| 166 | + $postSelector, $params | |
| 167 | + ); | |
| 168 | + ?> | |
| 169 | + </td></tr> | |
| 170 | + | |
| 171 | + <?php $page->updatedPosts->display(); ?> | |
| 92 | 172 | </table> |
| 93 | 173 | |
| 94 | 174 | <?php |
| 95 | 175 | } /* FeedWordPressPostsPage::publication_box () */ |
| @@ -101,25 +181,63 @@ | ||
| 101 | 181 | * @param object $page of class FeedWordPressPostsPage tells us whether this is |
| 102 | 182 | * a page for one feed's settings or for global defaults |
| 103 | 183 | * @param array $box |
| 104 | 184 | * |
| 105 | - * @uses fwp_option_box_opener() | |
| 106 | - * @uses fwp_option_box_closer() | |
| 107 | 185 | */ |
| 108 | 186 | function formatting_box ($page, $box = NULL) { |
| 109 | - $formatting_filters = get_option('feedwordpress_formatting_filters'); | |
| 187 | + $thesePosts = $page->these_posts_phrase(); | |
| 188 | + | |
| 189 | + if ($page->for_feed_settings()) : | |
| 190 | + $formatting_filters = null; | |
| 191 | + $url = preg_replace('|/+$|', '', $page->link->homepage()); | |
| 192 | + else : | |
| 193 | + $formatting_filters = get_option('feedwordpress_formatting_filters', 'no'); | |
| 194 | + $url = 'http://example.com'; | |
| 195 | + endif; | |
| 110 | 196 | ?> |
| 111 | - <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> | |
| 197 | + <table class="edit-form narrow"> | |
| 198 | + <?php if (!is_null($formatting_filters)) : ?> | |
| 199 | + | |
| 200 | + <tr><th scope="row">Formatting filters:</th> | |
| 201 | + <td><select name="formatting_filters" size="1"> | |
| 202 | + <option value="no"<?php echo ($formatting_filters!='yes')?' selected="selected"':''; ?>>Protect syndicated posts from formatting filters</option> | |
| 203 | + <option value="yes"<?php echo ($formatting_filters=='yes')?' selected="selected"':''; ?>>Expose syndicated posts to formatting filters</option> | |
| 204 | + </select> | |
| 205 | + <p class="setting-description">If you have trouble getting plugins to work that are supposed to insert | |
| 206 | + elements after posts (like relevant links or a social networking | |
| 207 | + <q>Share This</q> button), try changing this option to see if it fixes your | |
| 208 | + problem.</p> | |
| 209 | + </td></tr> | |
| 210 | + | |
| 211 | + <?php endif; ?> | |
| 212 | + | |
| 213 | + <tr><th scope="row">Relative URIs:</th> | |
| 214 | + <td><p>If link or image in a syndicated post from <code><?php print $url; ?></code> | |
| 215 | + refers to a partial URI like <code>/about</code>, where should | |
| 216 | + the syndicated copy point to?</p> | |
| 217 | + | |
| 218 | + <?php | |
| 219 | + $options = array( | |
| 220 | + '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>', | |
| 221 | + '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>', | |
| 222 | + ); | |
| 223 | + $params = array( | |
| 224 | + 'setting-default' => 'default', | |
| 225 | + 'global-setting-default' => 'yes', | |
| 226 | + 'labels' => array( | |
| 227 | + 'yes' => __('resolve relative URIs'), | |
| 228 | + 'no' => __('leave relative URIs unresolved'), | |
| 229 | + ), | |
| 230 | + 'default-input-value' => 'default', | |
| 231 | + ); | |
| 232 | + | |
| 233 | + $this->setting_radio_control( | |
| 234 | + 'resolve relative', 'resolve_relative', | |
| 235 | + $options, $params | |
| 236 | + ); | |
| 237 | + ?> | |
| 121 | 238 | </td></tr> |
| 239 | + | |
| 122 | 240 | </table> |
| 123 | 241 | <?php |
| 124 | 242 | } /* FeedWordPressPostsPage::formatting_box() */ |
| 125 | 243 | |
| @@ -130,23 +248,39 @@ | ||
| 130 | 248 | * @param object $page of class FeedWordPressPostsPage tells us whether this is |
| 131 | 249 | * a page for one feed's settings or for global defaults |
| 132 | 250 | * @param array $box |
| 133 | 251 | * |
| 134 | - * @uses fwp_option_box_opener() | |
| 135 | - * @uses fwp_option_box_closer() | |
| 136 | 252 | */ |
| 137 | 253 | /*static*/ function links_box ($page, $box = NULL) { |
| 138 | - $munge_permalink = get_option('feedwordpress_munge_permalink'); | |
| 139 | - $use_aggregator_source_data = get_option('feedwordpress_use_aggregator_source_data'); | |
| 254 | + $setting = array( | |
| 255 | + 'munge_permalink' => array( | |
| 256 | + 'yes' => __('The copy on the original website'), | |
| 257 | + 'no' => __('The local copy on this website'), | |
| 258 | + ), | |
| 259 | + ); | |
| 260 | + | |
| 261 | + if (!$page->for_feed_settings()) : | |
| 262 | + $use_aggregator_source_data = get_option('feedwordpress_use_aggregator_source_data'); | |
| 263 | + endif; | |
| 140 | 264 | ?> |
| 141 | - <table class="form-table" cellspacing="2" cellpadding="5"> | |
| 142 | - <tr><th scope="row">Permalinks:</th> | |
| 143 | - <td><select name="munge_permalink" size="1"> | |
| 144 | - <option value="yes"<?php echo ($munge_permalink=='yes')?' selected="selected"':''; ?>>point to the copy on the original website</option> | |
| 145 | - <option value="no"<?php echo ($munge_permalink=='no')?' selected="selected"':''; ?>>point to the local copy on this website</option> | |
| 146 | - </select></td> | |
| 147 | - </tr> | |
| 265 | + <table class="edit-form narrow"> | |
| 266 | + <tr><th scope="row">Permalinks point to:</th> | |
| 267 | + <td><?php | |
| 148 | 268 | |
| 269 | + $params = array( | |
| 270 | + 'setting-default' => 'default', | |
| 271 | + 'global-setting-default' => 'yes', | |
| 272 | + 'default-input-value' => 'default', | |
| 273 | + ); | |
| 274 | + $this->setting_radio_control( | |
| 275 | + 'munge permalink', 'munge_permalink', | |
| 276 | + $setting['munge_permalink'], $params | |
| 277 | + ); | |
| 278 | + ?> | |
| 279 | + | |
| 280 | + </td></tr> | |
| 281 | + | |
| 282 | + <?php if (!$page->for_feed_settings()) : ?> | |
| 149 | 283 | <tr><th scope="row">Posts from aggregator feeds:</th> |
| 150 | 284 | <td><ul class="options"> |
| 151 | 285 | <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> |
| 152 | 286 | <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> |
| @@ -154,8 +288,9 @@ | ||
| 154 | 288 | <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. |
| 155 | 289 | This setting controls what FeedWordPress will give as the source of posts from |
| 156 | 290 | such an aggregator feed.</p> |
| 157 | 291 | </td></tr> |
| 292 | + <?php endif; ?> | |
| 158 | 293 | </table> |
| 159 | 294 | |
| 160 | 295 | <?php |
| 161 | 296 | } /* FeedWordPressPostsPage::links_box() */ |
| @@ -167,73 +302,102 @@ | ||
| 167 | 302 | * @param object $page of class FeedWordPressPostsPage tells us whether this is |
| 168 | 303 | * a page for one feed's settings or for global defaults |
| 169 | 304 | * @param array $box |
| 170 | 305 | * |
| 171 | - * @uses fwp_option_box_opener() | |
| 172 | - * @uses fwp_option_box_closer() | |
| 173 | 306 | */ |
| 174 | 307 | /*static*/ function comments_and_pings_box ($page, $box = NULL) { |
| 175 | - $setting = array(); | |
| 176 | - $selector = array(); | |
| 177 | - | |
| 178 | 308 | $whatsits = array( |
| 179 | 309 | 'comment' => array('label' => __('Comments'), 'accept' => 'Allow comments'), |
| 180 | 310 | 'ping' => array('label' => __('Pings'), 'accept' => 'Accept pings'), |
| 181 | 311 | ); |
| 182 | 312 | $onThesePosts = 'on '.$page->these_posts_phrase(); |
| 313 | + | |
| 314 | + $mcflSettings = array( | |
| 315 | + "yes" => __('Point to comment feeds from the original website (when provided by the syndicated feed)'), | |
| 316 | + "no" => __('Point to local comment feeds on this website'), | |
| 317 | + ); | |
| 318 | + $mcflParams = array( | |
| 319 | + 'setting-default' => 'default', | |
| 320 | + 'global-setting-default' => 'yes', | |
| 321 | + 'labels' => array( | |
| 322 | + 'yes' => __('comment feeds from the original website'), | |
| 323 | + 'no' => __('local comment feeds on this website') | |
| 324 | + ), | |
| 325 | + 'default-input-value' => 'default', | |
| 326 | + ); | |
| 183 | 327 | |
| 328 | + $settings = array(); $params = array(); | |
| 184 | 329 | foreach ($whatsits as $what => $how) : |
| 185 | 330 | $whatsits[$what]['default'] = FeedWordPress::syndicated_status($what, /*default=*/ 'closed'); |
| 186 | 331 | |
| 187 | 332 | // Set up array for selector |
| 188 | - $setting = array( | |
| 189 | - 'open' => array ('label' => "{$how['accept']} %s", 'checked' => ''), | |
| 190 | - 'closed' => array('label' => "Don't ".strtolower($how['accept'])." %s", 'checked' => ''), | |
| 333 | + $settings[$what] = array( | |
| 334 | + 'open' => sprintf(__("{$how['accept']} %s"), __($onThesePosts)), | |
| 335 | + 'closed' => sprintf(__("Don't ".strtolower($how['accept'])." %s"), __($onThesePosts)), | |
| 191 | 336 | ); |
| 192 | - if ($page->for_feed_settings()) : | |
| 193 | - $href = $fwp_path.'/'.basename(__FILE__); | |
| 194 | - $currently = trim(str_replace('%s', '', strtolower(strtok($setting[$whatsits[$what]['default']]['label'], ';')))); | |
| 195 | - $setting['site-default'] = array('label' => "Use <a href=\"admin.php?page=${href}\">site-wide setting</a>", 'checked' => ''); | |
| 196 | - $setting['site-default']['label'] .= " (currently: <strong>${currently}</strong>)"; | |
| 197 | - | |
| 198 | - $checked = $page->link->syndicated_status($what, 'site-default', /*fallback=*/ false); | |
| 199 | - else : | |
| 200 | - $checked = $whatsits[$what]['default']; | |
| 201 | - endif; | |
| 202 | - | |
| 203 | - // Re-order appropriately | |
| 204 | - $selector[$what] = array(); | |
| 205 | - $order = array( | |
| 206 | - 'site-default', | |
| 207 | - 'open', | |
| 208 | - 'closed', | |
| 337 | + $params[$what] = array( | |
| 338 | + 'input-name' => "feed_${what}_status", | |
| 339 | + 'setting-default' => NULL, | |
| 340 | + 'global-setting-default' => FeedWordPress::syndicated_status($what, /*default=*/ 'closed'), | |
| 341 | + 'labels' => array( | |
| 342 | + 'open' => strtolower(__($how['accept'])), | |
| 343 | + 'closed' => strtolower(__("Don't ".$how['accept'])), | |
| 344 | + ), | |
| 209 | 345 | ); |
| 210 | - foreach ($order as $line) : | |
| 211 | - if (isset($setting[$line])) : | |
| 212 | - $selector[$what][$line] = $setting[$line]; | |
| 213 | - endif; | |
| 214 | - endforeach; | |
| 215 | - $selector[$what][$checked]['checked'] = ' checked="checked"'; | |
| 216 | 346 | endforeach; |
| 217 | 347 | |
| 218 | 348 | // Hey ho, let's go... |
| 219 | 349 | ?> |
| 220 | - <table class="form-table" cellspacing="2" cellpadding="5"> | |
| 350 | + <table class="edit-form narrow"> | |
| 221 | 351 | <?php foreach ($whatsits as $what => $how) : ?> |
| 352 | + | |
| 222 | 353 | <tr><th scope="row"><?php print $how['label']; ?>:</th> |
| 223 | - <td><ul class="options"> | |
| 224 | - <?php foreach ($selector[$what] as $code => $li) : ?> | |
| 225 | - <li><label><input type="radio" name="feed_<?php print $what; ?>_status" | |
| 226 | - value="<?php print $code; ?>"<?php print $li['checked']; ?> /> | |
| 227 | - <?php print trim(str_replace('%s', $onThesePosts, $li['label'])); ?></label></li> | |
| 228 | - <?php endforeach; ?> | |
| 229 | - </ul></td></tr> | |
| 354 | + <td><?php | |
| 355 | + $this->setting_radio_control( | |
| 356 | + "$what status", "syndicated_${what}_status", | |
| 357 | + $settings[$what], $params[$what] | |
| 358 | + ); | |
| 359 | + ?></td></tr> | |
| 360 | + | |
| 230 | 361 | <?php endforeach; ?> |
| 362 | + | |
| 363 | + <tr><th scope="row"><?php _e('Comment feeds'); ?></th> | |
| 364 | + <td><p>When WordPress feeds and templates link to comments | |
| 365 | + feeds for <?php print $page->these_posts_phrase(); ?>, the | |
| 366 | + URLs for the feeds should...</p> | |
| 367 | + <?php | |
| 368 | + $this->setting_radio_control( | |
| 369 | + "munge comments feed links", "munge_comments_feed_links", | |
| 370 | + $mcflSettings, $mcflParams | |
| 371 | + ); | |
| 372 | + ?></td></tr> | |
| 231 | 373 | </table> |
| 232 | 374 | |
| 233 | 375 | <?php |
| 234 | 376 | } /* FeedWordPressPostsPage::comments_and_pings_box() */ |
| 235 | 377 | |
| 378 | + /*static*/ function custom_post_settings ($page = NULL) { | |
| 379 | + if (is_null($page)) : | |
| 380 | + $page = $this; | |
| 381 | + endif; | |
| 382 | + | |
| 383 | + if ($page->for_feed_settings()) : | |
| 384 | + $custom_settings = $page->link->setting("postmeta", NULL, array()); | |
| 385 | + else : | |
| 386 | + $custom_settings = get_option('feedwordpress_custom_settings'); | |
| 387 | + endif; | |
| 388 | + | |
| 389 | + if ($custom_settings and !is_array($custom_settings)) : | |
| 390 | + $custom_settings = unserialize($custom_settings); | |
| 391 | + endif; | |
| 392 | + | |
| 393 | + if (!is_array($custom_settings)) : | |
| 394 | + $custom_settings = array(); | |
| 395 | + endif; | |
| 396 | + | |
| 397 | + return $custom_settings; | |
| 398 | + } /* FeedWordPressPostsPage::custom_post_settings() */ | |
| 399 | + | |
| 236 | 400 | /** |
| 237 | 401 | * Output "Custom Post Settings" settings box |
| 238 | 402 | * |
| 239 | 403 | * @since 2009.0713 |
| @@ -239,35 +403,14 @@ | ||
| 239 | 403 | * @since 2009.0713 |
| 240 | 404 | * @param object $page of class FeedWordPressPostsPage tells us whether this is |
| 241 | 405 | * a page for one feed's settings or for global defaults |
| 242 | 406 | * @param array $box |
| 243 | - * | |
| 244 | - * @uses fwp_option_box_opener() | |
| 245 | - * @uses fwp_option_box_closer() | |
| 246 | 407 | */ |
| 247 | 408 | /*static*/ function custom_post_settings_box ($page, $box = NULL) { |
| 248 | - if ($page->for_feed_settings()) : | |
| 249 | - $custom_settings = $page->link->settings["postmeta"]; | |
| 250 | - if ($custom_settings and !is_array($custom_settings)) : | |
| 251 | - $custom_settings = unserialize($custom_settings); | |
| 252 | - endif; | |
| 253 | - | |
| 254 | - if (!is_array($custom_settings)) : | |
| 255 | - $custom_settings = array(); | |
| 256 | - endif; | |
| 257 | - else : | |
| 258 | - $custom_settings = get_option('feedwordpress_custom_settings'); | |
| 259 | - if ($custom_settings and !is_array($custom_settings)) : | |
| 260 | - $custom_settings = unserialize($custom_settings); | |
| 261 | - endif; | |
| 262 | - | |
| 263 | - if (!is_array($custom_settings)) : | |
| 264 | - $custom_settings = array(); | |
| 265 | - endif; | |
| 266 | - endif; | |
| 267 | - | |
| 409 | + $custom_settings = FeedWordPressPostsPage::custom_post_settings($page); | |
| 268 | 410 | ?> |
| 269 | 411 | <div id="postcustomstuff"> |
| 412 | + <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> | |
| 270 | 413 | <table id="meta-list" cellpadding="3"> |
| 271 | 414 | <tr> |
| 272 | 415 | <th>Key</th> |
| 273 | 416 | <th>Value</th> |
| @@ -278,11 +421,11 @@ | ||
| 278 | 421 | $i = 0; |
| 279 | 422 | foreach ($custom_settings as $key => $value) : |
| 280 | 423 | ?> |
| 281 | 424 | <tr style="vertical-align:top"> |
| 282 | - <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo wp_specialchars($key, 'both'); ?>" /> | |
| 283 | - <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo wp_specialchars($key, 'both'); ?>" /></th> | |
| 284 | - <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 | + <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo esc_html($key); ?>" /> | |
| 426 | + <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo esc_html($key); ?>" /></th> | |
| 427 | + <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></td> | |
| 285 | 428 | <td width="10%"><select name="notes[<?php echo $i; ?>][action]"> |
| 286 | 429 | <option value="update">save changes</option> |
| 287 | 430 | <option value="delete">delete this setting</option> |
| 288 | 431 | </select></td> |
| @@ -292,11 +435,17 @@ | ||
| 292 | 435 | $i++; |
| 293 | 436 | endforeach; |
| 294 | 437 | ?> |
| 295 | 438 | |
| 296 | - <tr> | |
| 439 | + <tr style="vertical-align: top"> | |
| 297 | 440 | <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th> |
| 298 | - <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea></td> | |
| 441 | + <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea> | |
| 442 | + <p>Enter a text value, or a path to a data element from the syndicated item.<br/> | |
| 443 | + For data elements, you can use an XPath-like syntax wrapped in <code>$( ... )</code>.<br/> | |
| 444 | + <code>hello</code> = the text value <code><span style="background-color: #30FFA0;">hello</span></code><br/> | |
| 445 | + <code>$(author/email)</code> = the contents of <code><author><email><span style="background-color: #30FFA0">...</span></email></author></code><br/> | |
| 446 | + <code>$(media:content/@url)</code> = the contents of <code><media:content url="<span style="background-color: #30FFA0">...</span>">...</media:content></code></p> | |
| 447 | + </td> | |
| 299 | 448 | <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td> |
| 300 | 449 | </tr> |
| 301 | 450 | </table> |
| 302 | 451 | </div> <!-- id="postcustomstuff" --> |
| @@ -301,163 +450,65 @@ | ||
| 301 | 450 | </table> |
| 302 | 451 | </div> <!-- id="postcustomstuff" --> |
| 303 | 452 | |
| 304 | 453 | <?php |
| 305 | - } /* FeedWordPressPostsPage::custom_post_settings_box() */ | |
| 306 | -} | |
| 454 | + } /* FeedWordPressPostsPage::custom_post_settings_box() */ | |
| 307 | 455 | |
| 308 | -function fwp_posts_page () { | |
| 309 | - global $wpdb, $wp_db_version; | |
| 310 | - | |
| 311 | - if (FeedWordPress::needs_upgrade()) : | |
| 312 | - fwp_upgrade_page(); | |
| 313 | - return; | |
| 314 | - endif; | |
| 456 | + function custom_post_types_box ($page, $box = NULL) { | |
| 457 | + global $fwp_path; | |
| 458 | + | |
| 459 | + // local: syndicated post type // default NULL | |
| 460 | + // global: syndicated_post_type // default 'post' | |
| 461 | + // default-input-value => 'default' | |
| 462 | + | |
| 463 | + // Get all custom post types | |
| 464 | + $post_types = get_post_types(array( | |
| 465 | + '_builtin' => false, | |
| 466 | + ), 'objects'); | |
| 315 | 467 | |
| 316 | - FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_posts_settings', /*capability=*/ 'manage_links'); | |
| 317 | - | |
| 318 | - $link = FeedWordPressAdminPage::submitted_link(); | |
| 319 | - $link_id = $link->id; | |
| 320 | - $postsPage = new FeedWordPressPostsPage($link); | |
| 321 | - | |
| 322 | - $mesg = null; | |
| 323 | - | |
| 324 | - //////////////////////////////////////////////// | |
| 325 | - // Process POST request, if any ///////////////// | |
| 326 | - //////////////////////////////////////////////// | |
| 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; | |
| 468 | + $ul = array(); | |
| 469 | + $ul['post'] = __('Normal WordPress posts'); | |
| 470 | + foreach ($post_types as $post_type) : | |
| 471 | + $ul[$post_type->name] = __($post_type->labels->name); | |
| 340 | 472 | 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 | 473 | |
| 403 | - do_action('feedwordpress_admin_page_posts_save', $GLOBALS['fwp_post'], $postsPage); | |
| 404 | - else : | |
| 405 | - $updated_link = false; | |
| 406 | - endif; | |
| 474 | + $params = array( | |
| 475 | + 'global-setting-default' => 'post', | |
| 476 | + 'default-input-value' => 'default', | |
| 477 | + ); | |
| 478 | + | |
| 479 | + // Hey, ho, let's go... | |
| 480 | + ?> | |
| 481 | + <table class="edit-form narrow"> | |
| 482 | + <tbody> | |
| 483 | + <tr><th><?php _e('Custom Post Types:'); ?></th> | |
| 484 | + <td><p>Incoming syndicated posts should be stored in the | |
| 485 | + posts database as...</p> | |
| 486 | + <?php | |
| 487 | + $this->setting_radio_control( | |
| 488 | + 'syndicated post type', 'syndicated_post_type', | |
| 489 | + $ul, $params | |
| 490 | + ); | |
| 491 | + ?> | |
| 492 | + </td></tr> | |
| 493 | + </tbody> | |
| 494 | + </table> | |
| 495 | + <?php | |
| 496 | + } /* FeedWordPressPostsPage::custom_post_types_box() */ | |
| 407 | 497 | |
| 408 | - $postsPage->ajax_interface_js(); | |
| 409 | - | |
| 410 | - if ($updated_link) : ?> | |
| 411 | -<div class="updated"><p>Syndicated posts settings updated.</p></div> | |
| 412 | -<?php elseif (!is_null($mesg)) : ?> | |
| 413 | -<div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div> | |
| 414 | -<?php endif; ?> | |
| 415 | - | |
| 416 | -<?php | |
| 417 | - $links = FeedWordPress::syndicated_links(); | |
| 418 | - $postsPage->open_sheet('Syndicated Posts & Links'); | |
| 419 | -?> | |
| 420 | -<style type="text/css"> | |
| 421 | - table.edit-form th, table.form-table th { width: 27%; vertical-align: top; } | |
| 422 | - table.edit-form td, table.form-table td { width: 73%; vertical-align: top; } | |
| 423 | - ul.options { margin: 0; padding: 0; list-style: none; } | |
| 424 | -</style> | |
| 425 | -<div id="post-body"> | |
| 426 | -<?php | |
| 427 | -$boxes_by_methods = array( | |
| 428 | - 'publication_box' => __('Publication'), | |
| 429 | - 'formatting_box' => __('Formatting'), | |
| 430 | - 'links_box' => __('Links'), | |
| 431 | - 'comments_and_pings_box' => __('Comments & Pings'), | |
| 432 | - 'custom_post_settings_box' => __('Custom Post Settings (to apply to each syndicated post)'), | |
| 433 | -); | |
| 434 | - | |
| 435 | -// Feed-level settings don't exist for these. | |
| 436 | -if ($postsPage->for_feed_settings()) : | |
| 437 | - unset($boxes_by_methods['formatting_box']); | |
| 438 | - unset($boxes_by_methods['links_box']); | |
| 439 | -endif; | |
| 440 | - | |
| 441 | - foreach ($boxes_by_methods as $method => $title) : | |
| 442 | - fwp_add_meta_box( | |
| 443 | - /*id=*/ 'feedwordpress_'.$method, | |
| 444 | - /*title=*/ $title, | |
| 445 | - /*callback=*/ array('FeedWordPressPostsPage', $method), | |
| 446 | - /*page=*/ $postsPage->meta_box_context(), | |
| 447 | - /*context=*/ $postsPage->meta_box_context() | |
| 498 | + function display () { | |
| 499 | + $this->boxes_by_methods = array( | |
| 500 | + 'publication_box' => __('Syndicated Posts'), | |
| 501 | + 'links_box' => __('Links'), | |
| 502 | + 'formatting_box' => __('Formatting'), | |
| 503 | + 'comments_and_pings_box' => __('Comments & Pings'), | |
| 504 | + 'custom_post_settings_box' => __('Custom Post Settings (to apply to each syndicated post)'), | |
| 505 | + 'custom_post_types_box' => ('Custom Post Types (advanced database settings)'), | |
| 448 | 506 | ); |
| 449 | - endforeach; | |
| 450 | - do_action('feedwordpress_admin_page_posts_meta_boxes', $postsPage); | |
| 451 | -?> | |
| 452 | - <div class="metabox-holder"> | |
| 453 | -<?php | |
| 454 | - fwp_do_meta_boxes($postsPage->meta_box_context(), $postsPage->meta_box_context(), $postsPage); | |
| 455 | -?> | |
| 456 | - </div> <!-- class="metabox-holder" --> | |
| 457 | -</div> <!-- id="post-body" --> | |
| 458 | -<?php | |
| 459 | - $postsPage->close_sheet(); | |
| 460 | -} /* function fwp_posts_page () */ | |
| 507 | + | |
| 508 | + parent::display(); | |
| 509 | + } /* FeedWordPressPostsPage::display () */ | |
| 510 | +} | |
| 461 | 511 | |
| 462 | - fwp_posts_page(); | |
| 512 | + $postsPage = new FeedWordPressPostsPage; | |
| 513 | + $postsPage->display(); | |
| 463 | 514 | |