sh = $sh;
if (! function_exists('get_editable_roles')) {
require_once(ABSPATH . '/wp-admin/includes/user.php');
}
//Check the status of the RSS feed
$this->isRssEnabled();
// Generate a rss secret, if it does not exist
if (! get_option("simple_history_rss_secret")) {
$this->updateRssSecret();
}
add_action('init', array($this, 'checkForRssFeedRequest'));
// Add settings with prio 11 so it' added after the main Simple History settings
add_action('admin_menu', array($this, 'addSettings'), 11);
}
/**
* Add settings for the RSS feed
* + also regenerates the secret if requested
*/
public function addSettings()
{
//we register a setting to keep track of the RSS feed status (enabled/disabled)
register_setting(
SimpleHistory::SETTINGS_GENERAL_OPTION_GROUP,
'simple_history_enable_rss_feed',
array($this, 'public updateRssStatus'
)
);
/**
* Start new section for RSS feed
*/
$settings_section_rss_id = "simple_history_settings_section_rss";
add_settings_section(
$settings_section_rss_id,
_x("RSS feed", "rss settings headline", "simple-history"), // No title __("General", "simple-history"),
array($this, "settingsSectionOutput"),
SimpleHistory::SETTINGS_MENU_SLUG // same slug as for options menu page
);
// Enable/Disabled RSS feed
add_settings_field(
"simple_history_enable_rss_feed",
__("Enable", "simple-history"),
array($this, "settingsFieldRssEnable"),
SimpleHistory::SETTINGS_MENU_SLUG,
$settings_section_rss_id
);
//if RSS is activated we display other fields
if ($this->isRssEnabled()) {
// RSS address
add_settings_field(
"simple_history_rss_feed",
__("Address", "simple-history"),
array($this, "settingsFieldRss"),
SimpleHistory::SETTINGS_MENU_SLUG,
$settings_section_rss_id
);
// Regnerate address
add_settings_field(
"simple_history_rss_feed_regenerate_secret",
__("Regenerate", "simple-history"),
array($this, "settingsFieldRssRegenerate"),
SimpleHistory::SETTINGS_MENU_SLUG,
$settings_section_rss_id
);
}
// Create new RSS secret
$create_new_secret = false;
$create_secret_nonce_name = "simple_history_rss_secret_regenerate_nonce";
$createNonceOk = isset($_GET[$create_secret_nonce_name]) && wp_verify_nonce($_GET[$create_secret_nonce_name], 'simple_history_rss_update_secret');
if ($createNonceOk) {
$create_new_secret = true;
$this->updateRssSecret();
// Add updated-message and store in transient and then redirect
// This is the way options.php does it.
$msg = __("Created new secret RSS address", 'simple-history');
add_settings_error("simple_history_rss_feed_regenerate_secret", "simple_history_rss_feed_regenerate_secret", $msg, "updated");
set_transient('settings_errors', get_settings_errors(), 30);
$goback = esc_url_raw(add_query_arg('settings-updated', 'true', wp_get_referer()));
wp_redirect($goback);
exit;
}
} // settings
/**
* Check if RSS feed is enabled or disabled
*/
public function isRssEnabled()
{
// User has never used the plugin we disable RSS feed
if (get_option("simple_history_rss_secret") === false && get_option("simple_history_enable_rss_feed") === false) {
//We disable RSS by default, we use 0/1 to prevent fake disabled with bools from functions returning false for unset
update_option("simple_history_enable_rss_feed", "0");
} elseif (get_option("simple_history_enable_rss_feed") === false) {
// User was using the plugin before RSS feed became disabled by default
// We activate RSS to prevent a "breaking change"
update_option("simple_history_enable_rss_feed", "1");
return true;
} elseif (get_option("simple_history_enable_rss_feed") === "1") {
return true;
}
return false;
}
/**
* Output for settings field that show current RSS address
*/
public function settingsFieldRssEnable()
{
?>
isRssEnabled(), 1); ?> />
outputRss();
exit;
}
}
/**
* Modify capability check so all users reading rss feed (logged in or not) can read all loggers
*/
public function onCanReadSingleLogger($user_can_read_logger, $logger_instance, $user_id)
{
$user_can_read_logger = true;
return $user_can_read_logger;
}
/**
* Output RSS
*/
public function outputRss()
{
$rss_secret_option = get_option("simple_history_rss_secret");
$rss_secret_get = isset($_GET["rss_secret"]) ? $_GET["rss_secret"] : "";
if (empty($rss_secret_option) || empty($rss_secret_get)) {
die();
}
$rss_show = true;
$rss_show = apply_filters("simple_history/rss_feed_show", $rss_show);
if (! $rss_show || ! $this->isRssEnabled()) {
wp_die('Nothing here.');
}
header("Content-Type: text/xml; charset=utf-8");
echo '';
$self_link = $this->getRssAddress();
if ($rss_secret_option === $rss_secret_get) {
?>
"; _e("You can generate a new address for the RSS feed. This is useful if you think that the address has fallen into the wrong hands.", 'simple-history'); echo "
"; echo ""; printf( '%2$s', $update_link, // 1 __('Generate new address', "simple-history") // 2 ); echo "
"; } /** * Get the URL to the RSS feed * * @return string URL */ public function getRssAddress() { $rss_secret = get_option("simple_history_rss_secret"); $rss_address = add_query_arg( array("simple_history_get_rss" => "1", "rss_secret" => $rss_secret), get_bloginfo("url") . "/" ); $rss_address = esc_url($rss_address); // $rss_address = htmlspecialchars($rss_address, ENT_COMPAT, "UTF-8"); return $rss_address; } /** * Content for section intro. Leave it be, even if empty. * Called from add_sections_setting. */ public function settingsSectionOutput() { echo ""; _e("Simple History has a RSS feed which you can subscribe to and receive log updates. Make sure you only share the feed with people you trust, since it can contain sensitive or confidential information.", 'simple-history'); echo "
"; } } // end rss class