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