'The Feed Key you used is invalid. It is either incorrect or has been revoked. Please login to obtain a valid Feed Key',
'feedkey_missing' => 'You need to use a Feed Key to access feeds on this site. Please login to obtain yours.',
'feedkey_notgen' => 'Feed Key not found.',
'feedurl_notgen' => 'URL is available once a Feed Key has been generated'
);
//---------------------------------------------------------------------------
// Setup Default Settings
//---------------------------------------------------------------------------
function feedkey_setup_options()
{
global $feedkey_opt;
$feedkey_version = get_option('feedkey_version'); //Feed Key Version Number
$feedkey_this_version = '0.2';
// Check the version of Feed Key
if (empty($feedkey_version))
{
add_option('feedkey_version', $feedkey_this_version);
}
elseif ($feedkey_version != $feedkey_this_version)
{
update_option('feedkey_version', $feedkey_this_version);
}
// Setup Default Options Array
$optionarray_def = array(
'char_set' => 'alpha-numeric-mixed',
'key_length' => '32',
'salt' => 'username',
'hash_using' => 'md5',
'user_reset' => TRUE
);
if (empty($feedkey_opt)){ //If there aren't already options for Feed Key
add_option('feedkey_options', $optionarray_def, 'Feed Key Wordpress Plugin Options');
}
}
//Detect WordPress version to add compatibility with 2.3 or higher
$wpversion_full = get_bloginfo('version');
$wpversion = preg_replace('/([0-9].[0-9])(.*)/', '$1', $wpversion_full); //Boil down version number to X.X
//--------------------------------------------------------------------------
// Add Admin Page
//--------------------------------------------------------------------------
function feedkey_add_options_page()
{
if (function_exists('add_options_page'))
{
add_options_page('Feed Key', 'Feed Key', 8, basename(__FILE__), 'feedkey_options_page');
}
}
//---------------------------------------------------------------------------
// Add Feed Key to Profile Page
//---------------------------------------------------------------------------
function feedkey_display()
{
global $blogurl, $feedkey_opt, $profileuser, $current_user, $errormsg;
// Setup Feed Key Reset Options
$feedkey_reset_types = array(
'Feed Key Options...' => NULL,
'Reset Feed Key' => 'feedkey-reset',
'Remove Feed Key' => 'feedkey-remove'
);
foreach ($feedkey_reset_types as $option => $value) {
if ($value == $optionarray_def['login_redirect_to']) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
$feedkey_reset_options .= "\n\t";
}
$yourprofile = $profileuser->ID == $current_user->ID;
$feedkey = get_usermeta($profileuser->ID,'feed_key');
$permalink_structure = get_option(permalink_structure);
//Check if Permalinks are being used
empty($permalink_structure) ? $feedjoin = '?feed=rss2&feedkey=' : $feedjoin = '/feed/?feedkey=';
$feedurl = $blogurl.$feedjoin.$feedkey;
$feedurl = ''.$feedurl.'';
?>
user_login;
break;
case 'email':
$salt = $userdata->user_email;
break;
}
switch ($feedkey_opt['hash_using'])
{
case 'md5':
$hashedkey = md5($salt.$key);
break;
case 'sha1':
$hashedkey = sha1($salt.$key);
break;
case 'sha1_md5':
$hashedkey = sha1(md5($salt.$key));
break;
case 'md5_sha1':
$hashedkey = md5(sha1($salt.$key));
break;
}
return $hashedkey;
}
//----------------------------------------------------------------------------
// Reset Feed Key Function
//----------------------------------------------------------------------------
function feedkey_reset()
{
$id = $_POST['user_id'];
if ($_POST['feedkey-reset'] != NULL || $_POST['feedkey-generate'] != NULL || $_POST['feedkey-reset-admin'] == 'feedkey-reset') //If the reset or generate check box is checked
{
$feedkey = members_only_gen_feedkey();
update_usermeta($id, 'feed_key', $feedkey);
}
if ($_POST['feedkey-reset-admin'] == 'feedkey-remove')
{
$feedkey = NULL;
update_usermeta($id, 'feed_key', $feedkey);
}
}
//----------------------------------------------------------------------------
// Create RSS Feed Function
//----------------------------------------------------------------------------
function feedkey_create_feed($item_title, $item_description)
{
global $blogtitle, $blogurl;
$today = date('F j, Y G:i:s T');
$feed_content = '
'.$blogtitle.'
'.$blogurl.'
-
'.$item_title.'
'.$blogurl.'
'.$item_description.'
'.$today.'
';
return $feed_content;
}
//----------------------------------------------------------------------------
// Main Function
//----------------------------------------------------------------------------
function feedkey()
{
global $feedkey_valid, $errormsg;
if (is_feed()) //Check if URL is a Feed
{
if (empty($_GET['feedkey']))
{
$feed = feedkey_create_feed('No Feed Key Found', $errormsg['feedkey_missing']);
header("Content-Type: application/xml; charset=ISO-8859-1");
echo $feed;
exit;
}
elseif ($feedkey_valid == FALSE)
{
$feed = feedkey_create_feed('Feed Key is Invalid', $errormsg['feedkey_invalid']);
header("Content-Type: application/xml; charset=ISO-8859-1");
echo $feed;
exit;
}
elseif ($feedkey_valid == TRUE)
{
// Do Nothing
}
}
}
//----------------------------------------------------------------------------
// Init Function
//----------------------------------------------------------------------------
function feedkey_init()
{
global $userdata, $feedkey_valid, $errormsg, $feedkey_opt, $wpdb;
if (!empty($userdata->ID)) // If user is logged in
{
//Get User's Feed key
$users_feedkey = get_usermeta($userdata->ID,'feed_key');
//If there isn't one then generate one
if (empty($users_feedkey))
{
$feedkey = feedkey_gen();
update_usermeta($userdata->ID, 'feed_key', $feedkey);
}
}
$submitted_feedkey = $_GET['feedkey'];
if (!empty($submitted_feedkey))
{
// Check if Feed Key is in the Database
$find_feedkey = $wpdb->get_results("SELECT umeta_id FROM wp_usermeta WHERE meta_value = '$submitted_feedkey'");
if (!empty($find_feedkey)) //If Feed Key is found
{
$feedkey_valid = TRUE;
}
}
//WordPress Feed Files
switch (basename($_SERVER['PHP_SELF']))
{
case 'wp-rss.php':
case 'wp-rss2.php':
case 'wp-atom.php':
case 'wp-rdf.php':
case 'wp-commentsrss2.php':
case 'wp-feed.php':
if (empty($submitted_feedkey))
{
$feed = feedkey_create_feed('No Feed Key Found', $errormsg['feedkey_missing']);
header("Content-Type: application/xml; charset=ISO-8859-1");
echo $feed;
exit;
}
elseif ($feedkey_valid == FALSE)
{
$feed = feedkey_create_feed('Feed Key is Invalid', $errormsg['feedkey_invalid']);
header("Content-Type: application/xml; charset=ISO-8859-1");
echo $feed;
exit;
}
break;
}
//WordPress Feed Queries
switch ($_GET['feed'])
{
case 'rss':
case 'rss2':
case 'atom':
case 'rdf':
if (empty($submitted_feedkey))
{
$feed = feedkey_create_feed('No Feed Key Found', $errormsg['feedkey_missing']);
header("Content-Type: application/xml; charset=ISO-8859-1");
echo $feed;
exit;
}
elseif ($feedkey_valid == FALSE)
{
$feed = feedkey_create_feed('Feed Key is Invalid', $errormsg['feedkey_invalid']);
header("Content-Type: application/xml; charset=ISO-8859-1");
echo $feed;
exit;
}
break;
}
}
//----------------------------------------------------------------------------
// ADMIN OPTION PAGE FUNCTIONS
//----------------------------------------------------------------------------
function feedkey_options_page()
{
global $wpdb, $wpversion;
if (isset($_POST['submit']) ) {
// Options Array Update
$optionarray_update = array (
'char_set' => $_POST['char_set'],
'key_length' => $_POST['key_length'],
'salt' => $_POST['salt'],
'hash_using' => $_POST['hash_using'],
'user_reset' => $_POST['user_reset']
);
update_option('feedkey_options', $optionarray_update);
}
// Get Options
$optionarray_def = get_option('feedkey_options');
// Setup Character Set Options
$charset_types = array(
'Alpha-Numeric (Lowercase)' => 'alpha-numeric-lower',
'Alpha-Numeric (Uppercase)' => 'alpha-numeric-upper',
'Alpha-Numeric (Mixed Case)' => 'alpha-numeric-mixed',
'Alpha (Lowercase)' => 'alpha-lower',
'Alpha (Uppercase)' => 'alpha-upper',
'Alpha (Mixed)' => 'alpha-mixed',
'Numeric' => 'numeric'
);
foreach ($charset_types as $option => $value) {
if ($value == $optionarray_def['char_set']) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
$charset_options .= "\n\t";
}
// Setup Key Length Options
$keylength_types = array(
'8bit' => '8',
'16bit' => '16',
'32bit' => '32',
'64bit' => '64',
'128bit' => '128',
'256bit' => '256'
);
foreach ($keylength_types as $option => $value) {
if ($value == $optionarray_def['key_length']) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
$keylength_options .= "\n\t";
}
// Setup Salt Options
$salt_types = array(
'Username' => 'username',
"eMail" => 'email'
);
foreach ($salt_types as $option => $value) {
if ($value == $optionarray_def['salt']) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
$salt_options .= "\n\t";
}
// Setup Hash Options
$hash_types = array(
'md5' => 'md5',
'sha1' => 'sha1',
'sha1 then md5' => 'sha1_md5',
'md5 then sha1' => 'md5_sha1'
);
foreach ($hash_types as $option => $value) {
if ($value == $optionarray_def['hash_using']) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
$hash_options .= "\n\t";
}
?>