PluginProbe
FeedWordPress / 2014.0805
FeedWordPress v2014.0805
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / posts-page.php

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

518 lines 17.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once(dirname(__FILE__) . '/admin-ui.php');
3 require_once(dirname(__FILE__) . '/updatedpostscontrol.class.php');
4
5 class FeedWordPressPostsPage extends FeedWordPressAdminPage {
6 var $link = NULL;
7 var $updatedPosts = NULL;
8
9 /**
10 * Construct the posts page object.
11 *
12 * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings
13 */
14 function FeedWordPressPostsPage ($link = -1) {
15 if (is_numeric($link) and -1 == $link) :
16 $link = FeedWordPressAdminPage::submitted_link();
17 endif;
18
19 FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresspostspage', $link);
20 $this->dispatch = 'feedwordpress_admin_page_posts';
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 );
29 } /* FeedWordPressPostsPage constructor */
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
125 /**
126 * Outputs "Publication" settings box.
127 *
128 * @since 2009.0713
129 * @param object $page of class FeedWordPressPostsPage tells us whether this is
130 * a page for one feed's settings or for global defaults
131 * @param array $box
132 *
133 * @uses FeedWordPressPostsPage::these_posts_phrase()
134 * @uses FeedWordPress::syndicated_status()
135 * @uses SyndicatedLink::syndicated_status()
136 */
137 /*static*/ function publication_box ($page, $box = NULL) {
138 $thesePosts = $page->these_posts_phrase();
139 $postSelector = array(
140 'publish' => "Publish %s immediately",
141 'pending' => "Hold %s for review; mark as Pending",
142 'draft' => "Save %s as drafts",
143 'private' => "Save %s as private posts",
144 );
145 $labels = array();
146 foreach ($postSelector as $index => $value) :
147 $postSelector[$index] = sprintf(__($value), $thesePosts);
148 $labels[$index] = __(str_replace(' %s', '', strtolower(strtok($value, ';'))));
149 endforeach;
150
151 $params = array(
152 'input-name' => 'feed_post_status',
153 'setting-default' => NULL,
154 'global-setting-default' => 'publish',
155 'labels' => $labels,
156 );
157
158 // Hey ho, let's go...
159 ?>
160 <table id="syndicated-publication-form" class="edit-form narrow">
161 <tr><th scope="row"><?php _e('New posts:'); ?></th>
162 <td><?php
163 $this->setting_radio_control(
164 'post status', 'syndicated_post_status',
165 $postSelector, $params
166 );
167 ?>
168 </td></tr>
169
170 <?php $page->updatedPosts->display(); ?>
171 </table>
172
173 <?php
174 } /* FeedWordPressPostsPage::publication_box () */
175
176 /**
177 * Outputs "Formatting" settings box
178 *
179 * @since 2009.0713
180 * @param object $page of class FeedWordPressPostsPage tells us whether this is
181 * a page for one feed's settings or for global defaults
182 * @param array $box
183 *
184 */
185 function formatting_box ($page, $box = NULL) {
186 $thesePosts = $page->these_posts_phrase();
187
188 if ($page->for_feed_settings()) :
189 $formatting_filters = null;
190 $url = preg_replace('|/+$|', '', $page->link->homepage());
191 else :
192 $formatting_filters = get_option('feedwordpress_formatting_filters', 'no');
193 $url = 'http://example.com';
194 endif;
195 ?>
196 <table class="edit-form narrow">
197 <?php if (!is_null($formatting_filters)) : ?>
198
199 <tr><th scope="row">Formatting filters:</th>
200 <td><select name="formatting_filters" size="1">
201 <option value="no"<?php echo ($formatting_filters!='yes')?' selected="selected"':''; ?>>Protect syndicated posts from formatting filters</option>
202 <option value="yes"<?php echo ($formatting_filters=='yes')?' selected="selected"':''; ?>>Expose syndicated posts to formatting filters</option>
203 </select>
204 <p class="setting-description">If you have trouble getting plugins to work that are supposed to insert
205 elements after posts (like relevant links or a social networking
206 <q>Share This</q> button), try changing this option to see if it fixes your
207 problem.</p>
208 </td></tr>
209
210 <?php endif; ?>
211
212 <tr><th scope="row">Relative URIs:</th>
213 <td><p>If link or image in a syndicated post from <code><?php print $url; ?></code>
214 refers to a partial URI like <code>/about</code>, where should
215 the syndicated copy point to?</p>
216
217 <?php
218 $options = array(
219 '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>',
220 '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>',
221 );
222 $params = array(
223 'setting-default' => 'default',
224 'global-setting-default' => 'yes',
225 'labels' => array(
226 'yes' => __('resolve relative URIs'),
227 'no' => __('leave relative URIs unresolved'),
228 ),
229 'default-input-value' => 'default',
230 );
231
232 $this->setting_radio_control(
233 'resolve relative', 'resolve_relative',
234 $options, $params
235 );
236 ?>
237 </td></tr>
238
239 </table>
240 <?php
241 } /* FeedWordPressPostsPage::formatting_box() */
242
243 /**
244 * Output "Links" settings box
245 *
246 * @since 2009.0713
247 * @param object $page of class FeedWordPressPostsPage tells us whether this is
248 * a page for one feed's settings or for global defaults
249 * @param array $box
250 *
251 */
252 /*static*/ function links_box ($page, $box = NULL) {
253 $setting = array(
254 'munge_permalink' => array(
255 'yes' => __('The copy on the original website'),
256 'no' => __('The local copy on this website'),
257 ),
258 );
259
260 if (!$page->for_feed_settings()) :
261 $use_aggregator_source_data = get_option('feedwordpress_use_aggregator_source_data');
262 endif;
263 ?>
264 <table class="edit-form narrow">
265 <tr><th scope="row">Permalinks point to:</th>
266 <td><?php
267
268 $params = array(
269 'setting-default' => 'default',
270 'global-setting-default' => 'yes',
271 'default-input-value' => 'default',
272 );
273 $this->setting_radio_control(
274 'munge permalink', 'munge_permalink',
275 $setting['munge_permalink'], $params
276 );
277 ?>
278
279 </td></tr>
280
281 <?php if (!$page->for_feed_settings()) : ?>
282 <tr><th scope="row">Posts from aggregator feeds:</th>
283 <td><ul class="options">
284 <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>
285 <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>
286 </ul>
287 <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.
288 This setting controls what FeedWordPress will give as the source of posts from
289 such an aggregator feed.</p>
290 </td></tr>
291 <?php endif; ?>
292 </table>
293
294 <?php
295 } /* FeedWordPressPostsPage::links_box() */
296
297 /**
298 * Output "Comments & Pings" settings box
299 *
300 * @since 2009.0713
301 * @param object $page of class FeedWordPressPostsPage tells us whether this is
302 * a page for one feed's settings or for global defaults
303 * @param array $box
304 *
305 */
306 /*static*/ function comments_and_pings_box ($page, $box = NULL) {
307 $whatsits = array(
308 'comment' => array('label' => __('Comments'), 'accept' => 'Allow comments'),
309 'ping' => array('label' => __('Pings'), 'accept' => 'Accept pings'),
310 );
311 $onThesePosts = 'on '.$page->these_posts_phrase();
312
313 $mcflSettings = array(
314 "yes" => __('Point to comment feeds from the original website (when provided by the syndicated feed)'),
315 "no" => __('Point to local comment feeds on this website'),
316 );
317 $mcflParams = array(
318 'setting-default' => 'default',
319 'global-setting-default' => 'yes',
320 'labels' => array(
321 'yes' => __('comment feeds from the original website'),
322 'no' => __('local comment feeds on this website')
323 ),
324 'default-input-value' => 'default',
325 );
326
327 $settings = array(); $params = array();
328 foreach ($whatsits as $what => $how) :
329 $whatsits[$what]['default'] = FeedWordPress::syndicated_status($what, /*default=*/ 'closed');
330
331 // Set up array for selector
332 $settings[$what] = array(
333 'open' => sprintf(__("{$how['accept']} %s"), __($onThesePosts)),
334 'closed' => sprintf(__("Don't ".strtolower($how['accept'])." %s"), __($onThesePosts)),
335 );
336 $params[$what] = array(
337 'input-name' => "feed_${what}_status",
338 'setting-default' => NULL,
339 'global-setting-default' => FeedWordPress::syndicated_status($what, /*default=*/ 'closed'),
340 'labels' => array(
341 'open' => strtolower(__($how['accept'])),
342 'closed' => strtolower(__("Don't ".$how['accept'])),
343 ),
344 );
345 endforeach;
346
347 // Hey ho, let's go...
348 ?>
349 <table class="edit-form narrow">
350 <?php foreach ($whatsits as $what => $how) : ?>
351
352 <tr><th scope="row"><?php print $how['label']; ?>:</th>
353 <td><?php
354 $this->setting_radio_control(
355 "$what status", "syndicated_${what}_status",
356 $settings[$what], $params[$what]
357 );
358 ?></td></tr>
359
360 <?php endforeach; ?>
361
362 <tr><th scope="row"><?php _e('Comment feeds'); ?></th>
363 <td><p>When WordPress feeds and templates link to comments
364 feeds for <?php print $page->these_posts_phrase(); ?>, the
365 URLs for the feeds should...</p>
366 <?php
367 $this->setting_radio_control(
368 "munge comments feed links", "munge_comments_feed_links",
369 $mcflSettings, $mcflParams
370 );
371 ?></td></tr>
372 </table>
373
374 <?php
375 } /* FeedWordPressPostsPage::comments_and_pings_box() */
376
377 /*static*/ function custom_post_settings ($page = NULL) {
378 if (is_null($page)) :
379 $page = $this;
380 endif;
381
382 if ($page->for_feed_settings()) :
383 $custom_settings = $page->link->setting("postmeta", NULL, array());
384 else :
385 $custom_settings = get_option('feedwordpress_custom_settings');
386 endif;
387
388 if ($custom_settings and !is_array($custom_settings)) :
389 $custom_settings = unserialize($custom_settings);
390 endif;
391
392 if (!is_array($custom_settings)) :
393 $custom_settings = array();
394 endif;
395
396 return $custom_settings;
397 } /* FeedWordPressPostsPage::custom_post_settings() */
398
399 /**
400 * Output "Custom Post Settings" settings box
401 *
402 * @since 2009.0713
403 * @param object $page of class FeedWordPressPostsPage tells us whether this is
404 * a page for one feed's settings or for global defaults
405 * @param array $box
406 */
407 /*static*/ function custom_post_settings_box ($page, $box = NULL) {
408 $custom_settings = FeedWordPressPostsPage::custom_post_settings($page);
409 ?>
410 <div id="postcustomstuff">
411 <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>
412 <table id="meta-list" cellpadding="3">
413 <tr>
414 <th>Key</th>
415 <th>Value</th>
416 <th>Action</th>
417 </tr>
418
419 <?php
420 $i = 0;
421 $testerButton = '<br/><button id="xpath-test-%d"'
422 .'class="xpath-test"'
423 .'>test expression</button>';
424 foreach ($custom_settings as $key => $value) :
425 ?>
426 <tr style="vertical-align:top">
427 <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo esc_html($key); ?>" />
428 <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo esc_html($key); ?>" /></th>
429 <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>
430 <?php print sprintf($testerButton, $i); ?></td>
431 <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
432 <option value="update">save changes</option>
433 <option value="delete">delete this setting</option>
434 </select></td>
435 </tr>
436
437 <?php
438 $i++;
439 endforeach;
440 ?>
441
442 <tr style="vertical-align: top">
443 <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th>
444 <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea><?php print sprintf($testerButton, $i); ?>
445 <p>Enter a text value, or a path to a data element from the syndicated item.<br/>
446 For data elements, you can use an XPath-like syntax wrapped in <code>$( ... )</code>.<br/>
447 <code>hello</code> = the text value <code><span style="background-color: #30FFA0;">hello</span></code><br/>
448 <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/>
449 <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>
450 </td>
451 <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
452 </tr>
453 </table>
454 </div> <!-- id="postcustomstuff" -->
455
456 <?php
457 } /* FeedWordPressPostsPage::custom_post_settings_box() */
458
459 function custom_post_types_box ($page, $box = NULL) {
460 global $fwp_path;
461
462 // local: syndicated post type // default NULL
463 // global: syndicated_post_type // default 'post'
464 // default-input-value => 'default'
465
466 // Get all custom post types
467 $post_types = get_post_types(array(
468 '_builtin' => false,
469 ), 'objects');
470
471 $ul = array();
472 $ul['post'] = __('Normal WordPress posts');
473 foreach ($post_types as $post_type) :
474 $ul[$post_type->name] = __($post_type->labels->name);
475 endforeach;
476
477 $params = array(
478 'global-setting-default' => 'post',
479 'default-input-value' => 'default',
480 );
481
482 // Hey, ho, let's go...
483 ?>
484 <table class="edit-form narrow">
485 <tbody>
486 <tr><th><?php _e('Custom Post Types:'); ?></th>
487 <td><p>Incoming syndicated posts should be stored in the
488 posts database as...</p>
489 <?php
490 $this->setting_radio_control(
491 'syndicated post type', 'syndicated_post_type',
492 $ul, $params
493 );
494 ?>
495 </td></tr>
496 </tbody>
497 </table>
498 <?php
499 } /* FeedWordPressPostsPage::custom_post_types_box() */
500
501 function display () {
502 $this->boxes_by_methods = array(
503 'publication_box' => __('Syndicated Posts'),
504 'links_box' => __('Links'),
505 'formatting_box' => __('Formatting'),
506 'comments_and_pings_box' => __('Comments & Pings'),
507 'custom_post_settings_box' => __('Custom Post Settings (to apply to each syndicated post)'),
508 'custom_post_types_box' => ('Custom Post Types (advanced database settings)'),
509 );
510
511 parent::display();
512 } /* FeedWordPressPostsPage::display () */
513 }
514
515 $postsPage = new FeedWordPressPostsPage;
516 $postsPage->display();
517
518