PluginProbe
FeedWordPress / 2022.0204
FeedWordPress v2022.0204
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 2022.0204, at posts-page.php

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