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