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