PluginProbe
FeedWordPress / 2025.1211
FeedWordPress v2025.1211
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 / feedwordpressadminpage.class.php

feedwordpressadminpage.class.php in FeedWordPress 2025.1211, at feedwordpressadminpage.class.php

821 lines 24.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 define( 'FWP_BOLD_PREFIX_REGEX', '/^[*][*] ([^*]+) [*][*] \s+ (\S.*)$/x' );
3
4 /**
5 * class FeedWordPressAdminPage
6 *
7 * Handles a lot of the interface-code related jots and tittles for putting together
8 * admin / settings pages within FeedWordPress, like Syndication > Posts & Links,
9 * Syndication > Feeds & Updates, etc., whether for setting global defaults, or for
10 * settings on particular feeds.
11 *
12 */
13 class FeedWordPressAdminPage {
14 protected $context;
15 protected $updated = false;
16 protected $mesg = NULL;
17
18 /** @var SyndicatedLink|null An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings. */
19 var $link = NULL;
20 var $dispatch = NULL;
21 var $filename = NULL;
22 var $pagenames = array();
23 var $boxes_by_methods = array(); // did I delete this by mistake? (gwyneth 20230920)
24
25 /**
26 * Construct the admin page object.
27 *
28 * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings.
29 */
30 public function __construct( $page = 'feedwordpressadmin', $link = NULL ) {
31 $this->link = $link;
32
33 // Set meta-box context name
34 $this->context = $page;
35 if ( $this->for_feed_settings() ) :
36 $this->context .= 'forfeed';
37 endif;
38 } /* FeedWordPressAdminPage constructor */
39
40 public function pageslug () {
41 $slug = preg_replace('/FeedWordPress(.*)Page/', '$1', get_class($this));
42 return strtolower($slug);
43 }
44
45 public function pagename ($context = NULL) {
46 if (is_null($context)) :
47 $context = 'default';
48 endif;
49
50 if (isset($this->pagenames[$context])) :
51 $name = $this->pagenames[$context];
52 elseif (isset($this->pagenames['default'])) :
53 $name = $this->pagenames['default'];
54 else :
55 $name = $this->pageslug();
56 endif;
57 return __($name);
58 } /* FeedWordPressAdminPage::pagename () */
59
60 public function accept_POST () {
61 if ( $this->for_feed_settings() and $this->update_requested() ) :
62 $this->update_feed();
63 elseif ($this->save_requested()) : // User mashed Save Changes
64 $this->save_settings();
65 endif;
66 do_action($this->dispatch.'_post', null, $this);
67 }
68
69
70 public function update_feed() {
71 global $feedwordpress;
72
73 add_action('feedwordpress_check_feed', 'update_feeds_mention');
74 add_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
75
76 $link = $this->link;
77
78 print '<div class="updated">';
79 print "<ul>";
80 $uri = $this->link->uri();
81 $displayUrl = $uri;
82
83 // check for effects of an effective-url filter
84 $effectiveUrl = $link->uri(array('fetch' => true));
85 if ($uri != $effectiveUrl) : $displayUrl .= ' | ' . $effectiveUrl; endif;
86
87 $delta = $feedwordpress->update($uri);
88 print "</ul>";
89
90 if ( !is_null($delta)) :
91 echo "<p><strong>Update complete.</strong>".esc_html( fwp_update_set_results_message($delta) )."</p>";
92 echo "\n"; flush();
93 else :
94 $effectiveUrl = esc_html($effectiveUrl);
95 echo '<p><strong>Error:</strong> There was a problem updating <a href="' . esc_url( $effectiveUrl ) . '">' . esc_html( $displayUrl ) . '</a></p>' . "\n";
96 endif;
97 print "</div>\n";
98 remove_action('feedwordpress_check_feed', 'update_feeds_mention');
99 remove_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
100 }
101
102 public function save_settings () {
103 do_action($this->dispatch.'_save', null, $this);
104
105 if ($this->for_feed_settings()) :
106 // Save settings
107 $this->link->save_settings(/*reload=*/ true);
108 $this->updated = true;
109
110 // Reset, reload
111 $link_id = $this->link->id;
112 unset($this->link);
113 $this->link = new SyndicatedLink($link_id);
114 else :
115 $this->updated = true;
116 endif;
117 } /* FeedWordPressAdminPage::save_settings () */
118
119
120 public function for_feed_settings() {
121 return ( is_object( $this->link ) and method_exists( $this->link, 'found' ) and $this->link->found() );
122 } /* FeedWordPressAdminPage */
123
124 public function for_default_settings () {
125 return ! $this->for_feed_settings();
126 } /* FeedWordPressAdminPage */
127
128 /**
129 * Attempts to retrieve a setting for a feed.
130 *
131 * @param string|array $names Either a string with the name of the feed,
132 * or an associative array where the 'feed' parameter
133 * indicates the feed.
134 * @param string|null $fallback_value Fallback option value, if everything fails.
135 * @param Array $params List of attributes.
136 *
137 * @return mixed Retrieved option from settings.
138 */
139 public function setting( $names, $fallback_value = NULL, $params = array() ) {
140 if ( ! is_array( $params ) ) :
141 $params = array( 'default' => $params );
142 endif;
143 $params = shortcode_atts( array(
144 'default' => 'default',
145 'fallback' => true,
146 ),
147 $params );
148
149 if ( is_string( $names ) ) :
150 $feed_name = $names;
151 $global_name = 'feedwordpress_' . preg_replace( '![\s/]+!', '_', $names );
152 else :
153 $feed_name = $names['feed'];
154 $global_name = 'feedwordpress_' . $names['global'];
155 endif;
156
157 if ( $this->for_feed_settings() ) : // Check feed-specific setting first; fall back to global
158 if ( ! $params['fallback'] ) :
159 $global_name = NULL;
160 endif;
161 $ret = $this->link->setting( $feed_name, $global_name, $fallback_value, $params['default'] );
162 else : // Check global setting
163 $ret = get_option( $global_name, $fallback_value );
164 endif;
165 return $ret;
166 } /* FeedWordPressAdminPage::setting() */
167
168 /**
169 * Updates feed settings.
170 *
171 * @see setting()
172 *
173 * @param string|array $names Either a string with the name of the feed,
174 * or an associative array where the 'global' parameter
175 * indicates the feed.
176 * @param string|null $value Setting value to update.
177 * @param string $default Setting default option (defaults to 'default').
178 */
179 public function update_setting( $names, $value, $default = 'default' ) {
180 if ( is_string( $names ) ) :
181 $feed_name = $names;
182 $global_name = 'feedwordpress_' . preg_replace( '![\s/]+!', '_', $names );
183 else :
184 $feed_name = $names['feed'];
185 $global_name = 'feedwordpress_' . $names['global'];
186 endif;
187
188 if ( $this->for_feed_settings() ) : // Update feed-specific setting
189 $this->link->update_setting( $feed_name, $value, $default );
190 else : // Update global setting
191 update_option( $global_name, $value );
192 endif;
193 } /* FeedWordPressAdminPage::update_setting() */
194
195 public function save_requested() {
196 return ! ( is_null( MyPHP::post('save') ) && is_null( MyPHP::post('submit') ) );
197 }
198
199 public function update_requested() {
200 return ( strlen( MyPHP::post('update', '') ) > 0 );
201 }
202
203 public function submitted_link_id() {
204 // Presume global unless we get a specific link ID
205 $link_id = NULL;
206
207 $submit_buttons = array(
208 'save',
209 'submit',
210 'fix_mismatch',
211 'feedfinder',
212 );
213 foreach ($submit_buttons as $field) :
214 if ( ! is_null( MyPHP::request($field) ) ) :
215 $link_id = sanitize_text_field( MyPHP::request('save_link_id') );
216 endif;
217 endforeach;
218
219 if ( is_null($link_id) ) :
220 $link_id = sanitize_text_field( MyPHP::request( 'link_id' ) );
221 endif;
222
223 return $link_id;
224 } /* FeedWordPressAdminPage::submitted_link_id() */
225
226 public function submitted_link () {
227 $link_id = $this->submitted_link_id();
228 if (is_numeric($link_id) and $link_id) :
229 $link = new SyndicatedLink($link_id);
230 else :
231 $link = NULL;
232 endif;
233 return $link;
234 } /* FeedWordPressAdminPage::submitted_link () */
235
236 public function stamp_link_id ($field = null) {
237 if (is_null($field)) : $field = 'save_link_id'; endif;
238 ?>
239 <input type="hidden" name="<?php print esc_attr($field); ?>" value="<?php print esc_attr( ($this->for_feed_settings() ? $this->link->id : '*') ); ?>" />
240 <?php
241 } /* FeedWordPressAdminPage::stamp_link_id () */
242
243 /**
244 * Returns a short explanation of what posts we have here,
245 * either posts from this feed or syndicated posts.
246 *
247 * @return string True corresponds to posts from this feed,
248 * false to syndicated posts.
249 */
250 public function these_posts_phrase() {
251 if ( $this->for_feed_settings() ) :
252 $phrase = __( 'posts from this feed' );
253 else :
254 $phrase = __( 'syndicated posts' );
255 endif;
256 return $phrase;
257 } /* FeedWordPressAdminPage::these_posts_phrase() */
258
259 /**
260 * Provides a uniquely identifying name for the interface context for
261 * use with add_meta_box() and do_meta_boxes(),
262 *
263 * @return string the context name
264 *
265 * @see add_meta_box()
266 * @see do_meta_boxes()
267 */
268 public function meta_box_context() {
269 return $this->context;
270 } /* FeedWordPressAdminPage::meta_box_context () */
271
272 /**
273 * Outputs JavaScript to fix AJAX toggles settings.
274 *
275 * @uses FeedWordPressAdminPage::meta_box_context()
276 */
277 public function fix_toggles () {
278 FeedWordPressSettingsUI::fix_toggles_js($this->meta_box_context());
279 } /* FeedWordPressAdminPage::fix_toggles() */
280
281 public function ajax_interface_js () {
282 ?>
283 function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
284 if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
285
286 var rollup=document.getElementById(item);
287 if (rollup) {
288 if ((checkbox && rollup.checked) || ( !checkbox && value==rollup.value)) {
289 jQuery('#'+disappear).hide();
290 jQuery('#'+appear).show(600);
291 } else {
292 jQuery('#'+appear).hide();
293 jQuery('#'+disappear).show(600);
294 }
295 }
296 }
297 <?php
298 } /* FeedWordPressAdminPage::ajax_interface_js () */
299
300 public function admin_page_href ($page, $params = array(), $link = NULL) {
301 global $fwp_path;
302
303 // Merge in the page's filename
304 $params = array_merge($params, array('page' => $fwp_path.'/'.$page));
305
306 // If there is a link ID provided, then merge that in too.
307 if ( !is_null($link)) :
308 $link_id = NULL;
309 if (is_object($link)) :
310 if (method_exists($link, 'found')) :
311 // Is this a SyndicatedLink object?
312 if ($link->found()) :
313 $link_id = $link->link->link_id;
314 endif;
315 else :
316 // Is this a wp_links table record?
317 $link_id = $link->link_id;
318 endif;
319 else :
320 // Is this just a numeric ID?
321 $link_id = $link;
322 endif;
323
324 if ( !is_null($link_id)) :
325 $params = array_merge($params, array('link_id' => $link_id));
326 endif;
327 endif;
328
329 return MyPHP::url(admin_url('admin.php'), $params);
330 } /* FeedWordPressAdminPage::admin_page_href () */
331
332 public function display_feed_settings_page_links ($params = array()) {
333 $params = wp_parse_args($params, array(
334 'before' => '',
335 'between' => ' | ',
336 'after' => '',
337 'long' => false,
338 'subscription' => $this->link,
339 ));
340 $sub = $params['subscription'];
341
342 $links = array(
343 "Feed" => array('page' => 'feeds-page.php', 'long' => 'Feeds & Updates'),
344 "Posts" => array('page' => 'posts-page.php', 'long' => 'Posts & Links'),
345 "Authors" => array('page' => 'authors-page.php', 'long' => 'Authors'),
346 'Categories' => array('page' => 'categories-page.php', 'long' => 'Categories & Tags'),
347 );
348
349 $link_id = NULL;
350 if (is_object($sub)) :
351 if (method_exists($sub, 'found')) :
352 if ($sub->found()) :
353 $link_id = $sub->link->link_id;
354 endif;
355 else :
356 $link_id = $sub->link_id;
357 endif;
358 endif;
359
360 $out_html = $params['before']; $first = true;
361 foreach ($links as $label => $link) :
362 if ( ! $first) : $out_html .= $params['between']; endif;
363
364 if (isset($link['url'])) : MyPHP::url($link['url'], array("link_id" => $link_id));
365 else : $url = $this->admin_page_href($link['page'], array(), $sub);
366 endif;
367 $url = esc_html($url);
368
369 if ($link['page']==basename($this->filename)) :
370 $out_html .= "<strong>";
371 else :
372 $out_html .= sprintf( '<a href="%s">', esc_url( $url ) );
373 endif;
374
375 if ($params['long']) : $out_html .= esc_html(__($link['long']));
376 else : $out_html .= esc_html(__($label));
377 endif;
378
379 if ($link['page']==basename($this->filename)) :
380 $out_html .= "</strong>";
381 else :
382 $out_html .= "</a>";
383 endif;
384
385 $first = false;
386 endforeach;
387 $out_html .= $params['after'];
388
389 print wp_kses( $out_html, 'post' );
390 } /* FeedWordPressAdminPage::display_feed_settings_page_links */
391
392 public function display_feed_select_dropdown() {
393 $links = FeedWordPress::syndicated_links();
394
395 ?>
396 <div id="fwpfs-container"><ul class="subsubsub">
397 <li><select name="link_id" class="fwpfs" style="max-width: 20.0em;">
398 <option value="*"<?php if ($this->for_default_settings()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
399 <?php if ($links) : foreach ($links as $ddlink) : ?>
400 <option value="<?php print (int) $ddlink->link_id; ?>"<?php if ( !is_null($this->link) and ($this->link->id==$ddlink->link_id)) : ?> selected="selected"<?php endif; ?>><?php print esc_html($ddlink->link_name); ?></option>
401 <?php endforeach; endif; ?>
402 </select>
403 <input id="fwpfs-button" class="button" type="submit" name="go" value="<?php esc_attr_e('Go') ?> &raquo;" /></li>
404
405 <?php
406 $this->display_feed_settings_page_links(array(
407 'before' => '<li>',
408 'between' => "</li>\n<li>",
409 'after' => '</li>',
410 'subscription' => $this->link,
411 ));
412
413 if ($this->for_feed_settings()) :
414 ?>
415 <li><input class="button" type="submit" name="update" value="Update Now" /></li>
416 <?php
417 endif;
418 ?>
419 </ul>
420 </div>
421 <?php
422 } /* FeedWordPressAdminPage::display_feed_select_dropdown() */
423
424 /**
425 * Displays a header section throughout the FWP dashboard.
426 *
427 * @param string $pagename Page name for which this header is.
428 * @param bool $all False if it displays just the settings; true if it displays all.
429 */
430 public function display_sheet_header( $pagename = 'Syndication', $all = false ) {
431 /* changed to use a SVG instead, while keeping the correct size.
432 Note that these icons have been deprecated in 2013 or so:
433 @see https://core.trac.wordpress.org/ticket/26119 */
434 ?>
435 <div class="icon32"><img src="<?php print esc_attr( plugins_url( 'assets/images/icon.svg', __FILE__ ) ); ?>" alt="FeedWordPress Logo" /></div>
436 <h2><?php print esc_html( __( $pagename . ( $all ? '' : ' Settings' ) ) ); ?><?php if ( $this->for_feed_settings() ) : ?>: <?php echo esc_html( $this->link->name( /*from feed=*/ false ) ); ?><?php endif; ?></h2>
437 <?php
438 } /* FeedWordPressAdminPage::display_sheet_header() */
439
440 public function display_update_notice_if_updated( $pagename = 'Syndication', $mesg = NULL ) {
441 if ( ! is_null( $mesg ) ) :
442 $this->mesg = $mesg;
443 endif;
444
445 if ($this->updated) :
446 if ($this->updated === true) :
447 $this->mesg = $pagename . ' settings updated.';
448 else :
449 $this->mesg = $this->updated;
450 endif;
451 endif;
452
453 if ( !is_null($this->mesg)) :
454 ?>
455 <div class="updated">
456 <p><?php print esc_html($this->mesg); ?></p>
457 </div>
458 <?php
459 endif;
460 } /* FeedWordPressAdminPage::display_update_notice_if_updated() */
461
462 public function display_settings_scope_message () {
463 if ($this->for_feed_settings()) :
464 ?>
465 <p>These settings only affect posts syndicated from
466 <strong><?php echo esc_html($this->link->link->link_name); ?></strong>.</p>
467 <?php
468 else :
469 ?>
470 <p>These settings affect posts syndicated from any feed unless they are overridden
471 by settings for that specific feed.</p>
472 <?php
473 endif;
474 } /* FeedWordPressAdminPage::display_settings_scope_message () */
475
476 /*static*/ function has_link () { return true; }
477
478 public function form_action ($filename = NULL) {
479 if (is_null($filename)) :
480 $filename = basename($this->filename);
481 endif;
482 return $this->admin_page_href($filename);
483 } /* FeedWordPressAdminPage::form_action () */
484
485 public function update_message () {
486 return $this->mesg;
487 }
488
489 public function display () {
490
491 if (FeedWordPress::needs_upgrade()) :
492 fwp_upgrade_page();
493 return;
494 endif;
495
496 FeedWordPressCompatibility::validate_http_request(/*action=*/ $this->dispatch, /*capability=*/ 'manage_links');
497
498 ////////////////////////////////////////////////
499 // Process POST request, if any ////////////////
500 ////////////////////////////////////////////////
501 if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
502 $this->accept_POST();
503 else :
504 $this->updated = false;
505 endif;
506
507 ////////////////////////////////////////////////
508 // Prepare settings page ///////////////////////
509 ////////////////////////////////////////////////
510
511 $this->display_update_notice_if_updated(
512 $this->pagename('settings-update'),
513 $this->update_message()
514 );
515
516 $this->open_sheet($this->pagename('open-sheet'));
517 ?>
518 <div id="post-body">
519 <?php
520 foreach ($this->boxes_by_methods as $method => $row) :
521 if (is_array($row)) :
522 $id = $row['id'];
523 $title = $row['title'];
524 else :
525 $id = 'feedwordpress_'.$method;
526 $title = $row;
527 endif;
528
529 add_meta_box(
530 /*id=*/ $id,
531 /*title=*/ $title,
532 /*callback=*/ array($this, $method),
533 /*screen=*/ $this->meta_box_context(),
534 /*context=*/ $this->meta_box_context(),
535 );
536 endforeach;
537 do_action($this->dispatch.'_meta_boxes', $this);
538 ?>
539 <div class="metabox-holder">
540 <?php
541 do_meta_boxes( $this->meta_box_context(), $this->meta_box_context(), $this );
542 ?>
543 </div> <!-- class="metabox-holder" -->
544 </div> <!-- id="post-body" -->
545 <?php $this->close_sheet(); ?>
546 <?php
547 }
548
549 public function open_sheet ($header) {
550 // Set up prepatory AJAX stuff
551 ?>
552 <script type="text/javascript">
553 <?php
554 $this->ajax_interface_js();
555 ?>
556 </script>
557
558 <?php
559 add_action(
560 FeedWordPressCompatibility::bottom_script_hook($this->filename),
561 /*callback=*/ array($this, 'fix_toggles'),
562 /*priority=*/ 10000
563 );
564 FeedWordPressSettingsUI::ajax_nonce_fields();
565
566 ?>
567 <div class="wrap feedwordpress-admin" id="feedwordpress-admin-<?php print esc_attr( $this->pageslug() ); ?>">
568 <?php
569 if ( !is_null($header)) :
570 $this->display_sheet_header($header);
571 endif;
572
573 if ( !is_null( $this->dispatch ) ) :
574 ?>
575 <form action="<?php print esc_url( $this->form_action() ); ?>" method="post">
576 <div><?php
577 FeedWordPressCompatibility::stamp_nonce($this->dispatch);
578 $this->stamp_link_id();
579 ?></div>
580 <?php
581 endif;
582
583 if ($this->has_link()) :
584 $this->display_settings_scope_message();
585 endif;
586
587 ?><div class="tablenav"><?php
588 if ( !is_null($this->dispatch)) :
589 ?><div class="alignright"><?php
590 $this->save_button();
591 ?></div><?php
592 endif;
593
594 if ($this->has_link()) :
595 $this->display_feed_select_dropdown();
596 endif;
597 ?>
598 </div>
599
600 <div id="poststuff">
601 <?php
602 } /* FeedWordPressAdminPage::open_sheet () */
603
604 public function close_sheet () {
605 ?>
606
607 </div> <!-- id="poststuff" -->
608 <?php
609 if ( !is_null($this->dispatch)) :
610 $this->save_button();
611 print "</form>\n";
612 endif;
613 ?>
614 </div> <!-- class="wrap" -->
615
616 <?php
617 } /* FeedWordPressAdminPage::close_sheet () */
618
619 public function setting_radio_control ($localName, $globalName, $options, $params = array()) {
620 $params = wp_parse_args(
621 $params,
622 array(
623 'filename' => basename($this->filename),
624 'site-wide-url' => null,
625 'setting-default' => null,
626 'global-setting-default' => null,
627 'offer-site-wide' => null,
628 )
629 );
630
631 $filename = $params['filename'];
632 $href = $params['site-wide-url'];
633 if ( is_null( $href ) ) :
634 $href = $this->admin_page_href( $filename );
635 endif;
636
637 $settingDefault = $params['setting-default'];
638 $globalSettingDefault = $params['global-setting-default'];
639 if ( is_null( $globalSettingDefault ) ) :
640 $globalSettingDefault = $settingDefault;
641 endif;
642
643 $globalSetting = get_option('feedwordpress_'.$globalName, $globalSettingDefault);
644 if ( $this->for_feed_settings() ) :
645 $setting = $this->link->setting($localName, NULL, $settingDefault);
646 else :
647 $setting = $globalSetting;
648 endif;
649
650 $offerSiteWide = $params['offer-site-wide'];
651 if ( is_null( $offerSiteWide ) ) :
652 $offerSiteWide = $this->for_feed_settings();
653 endif;
654
655 // This allows us to provide an alternative set of human-readable
656 // labels for each potential value. For use in Currently: line.
657 if (isset($params['labels'])) : $labels = $params['labels'];
658 elseif (is_callable($options)) : $labels = NULL;
659 else : $labels = $options;
660 endif;
661
662 if (isset($params['input-name'])) : $inputName = $params['input-name'];
663 else : $inputName = $globalName;
664 endif;
665
666 if (isset($params['default-input-id'])) : $defaultInputId = $params['default-input-id'];
667 else : $defaultInputId = NULL;
668 endif;
669
670 if (isset($params['default-input-id-no'])) : $defaultInputIdNo = $params['default-input-id-no'];
671 elseif ( !is_null($defaultInputId)) : $defaultInputIdNo = $defaultInputId.'-no';
672 else : $defaultInputIdNo = NULL;
673 endif;
674
675 // This allows us to either include the site-default setting as
676 // one of the options within the radio box, or else as a simple
677 // yes/no toggle that controls whether or not to check another
678 // set of inputs.
679 if (isset($params['default-input-name'])) : $defaultInputName = $params['default-input-name'];
680 else : $defaultInputName = $inputName;
681 endif;
682
683 if ($defaultInputName != $inputName) :
684 $defaultInputValue = 'yes';
685 else :
686 $defaultInputValue = (
687 isset($params['default-input-value'])
688 ? $params['default-input-value']
689 : 'site-default'
690 );
691 endif;
692
693 $settingDefaulted = (is_null($setting) or ($settingDefault === $setting));
694
695 if ( !is_callable($options)) :
696 $checked = array();
697 if ($settingDefaulted) :
698 $checked[$defaultInputValue] = ' checked="checked"';
699 endif;
700
701 foreach ($options as $value => $label) :
702 if ($setting == $value) :
703 $checked[$value] = ' checked="checked"';
704 else :
705 $checked[$value] = '';
706 endif;
707 endforeach;
708 endif;
709
710 $defaulted = array();
711 if ($defaultInputName != $inputName) :
712 $defaulted['yes'] = ($settingDefaulted ? ' checked="checked"' : '');
713 $defaulted['no'] = ($settingDefaulted ? '' : ' checked="checked"');
714 else :
715 $defaulted['yes'] = (isset($checked[$defaultInputValue]) ? $checked[$defaultInputValue] : '');
716 endif;
717
718 if (isset($params['defaulted'])) :
719 $defaulted['yes'] = ($params['defaulted'] ? ' checked="checked"' : '');
720 $defaulted['no'] = ($params['defaulted'] ? '' : ' checked="checked"');
721 endif;
722
723 if ($offerSiteWide) :
724 ?>
725 <table class="twofer">
726 <tbody>
727 <tr><td class="equals first inactive">
728 <ul class="options">
729 <li><label><input type="radio"
730 name="<?php print esc_attr( $defaultInputName ); ?>"
731 value="<?php print esc_attr( $defaultInputValue ); ?>"
732 <?php if ( !is_null($defaultInputId)) : ?>id="<?php print esc_attr( $defaultInputId ); ?>" <?php endif; ?>
733 <?php fwp_checked_flag($defaulted, 'yes'); ?> />
734 Use the site-wide setting</label>
735 <span class="current-setting">Currently:
736 <strong><?php if (is_callable($labels)) :
737 print wp_kses( call_user_func( $labels, $globalSetting, $defaulted, $params ), 'post' );
738 elseif (is_null($labels)) :
739 print esc_html( $globalSetting );
740 else :
741 $label = $labels[ $globalSetting ];
742 if ( preg_match( FWP_BOLD_PREFIX_REGEX, $label, $ref ) ) :
743 $label = $ref[1] . ' ' . $ref[2];
744 endif;
745
746 print esc_html( $label );
747 endif; ?></strong> (<a href="<?php print esc_url( $href ); ?>">change</a>)</span></li>
748 </ul></td>
749
750 <td class="equals second inactive">
751 <?php if ($defaultInputName != $inputName) : ?>
752 <ul class="options">
753 <li><label><input type="radio"
754 name="<?php print esc_attr( $defaultInputName ); ?>"
755 value="no"
756 <?php if ( !is_null($defaultInputIdNo)) : ?>id="<?php print esc_attr( $defaultInputIdNo ); ?>" <?php endif; ?>
757 <?php fwp_checked_flag($defaulted, 'no'); ?> />
758 <?php esc_html_e('Do something different with this feed.'); ?></label>
759 <?php endif;
760 endif;
761
762 // Let's spit out the controls here.
763 if (is_callable($options)) :
764 // Method call to print out options list
765 call_user_func($options, $setting, $defaulted, $params);
766 else :
767 ?>
768 <ul class="options">
769 <?php
770 foreach ($options as $value => $label) :
771 if ( preg_match( FWP_BOLD_PREFIX_REGEX, $label, $ref ) ) :
772 $prefix = $ref[1];
773 $label = $ref[2];
774 else :
775 $prefix = null;
776 endif;
777 ?>
778 <li><label><input type="radio" name="<?php print esc_attr( $inputName ); ?>"
779 value="<?php print esc_attr( $value ); ?>"
780 <?php fwp_checked_flag($checked, $value); ?> />
781 <?php
782 if ( !is_null($prefix) ) :
783 printf( '<strong>%s</strong> ', esc_html( $prefix ) );
784 endif;
785 printf( '%s', esc_html( $label ) );
786 ?>
787 </label></li>
788 <?php endforeach; ?>
789 </ul> <!-- class="options" -->
790 <?php
791 endif;
792
793 if ($offerSiteWide) :
794 if ($defaultInputName != $inputName) :
795 // Close the <li> and <ul class="options"> we opened above
796 ?>
797 </li>
798 </ul> <!-- class="options" -->
799 <?php
800 endif;
801
802 // Close off the twofer table that we opened up above.
803 ?>
804 </td></tr>
805 </tbody>
806 </table>
807 <?php
808 endif;
809 } /* FeedWordPressAdminPage::setting_radio_control () */
810
811 public function save_button ($caption = NULL) {
812 if (is_null($caption)) : $caption = __('Save Changes'); endif;
813 ?>
814 <p class="submit">
815 <input class="button-primary" type="submit" name="save" value="<?php print esc_attr( $caption ); ?>" />
816 </p>
817 <?php
818 }
819 } /* class FeedWordPressAdminPage */
820
821