prefix.FAIRSHARE_POSTS;
$structure = "CREATE TABLE IF NOT EXISTS ". $table." (
id INT(9) NOT NULL AUTO_INCREMENT,
post_id VARCHAR(255) NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($structure);
$fairshareWidgetPosition = get_option(FAIRSHARE_WIDGET_POSITION);
update_option(FAIRSHARE_PLUGIN_ACTIVE, 'true');
if(empty($fairshareWidgetPosition)){
add_option(FAIRSHARE_WIDGET_POSITION,'top-left');
}
$fairShareAnalytics = new FairShareAnalytics();
$fairShareAnalytics->logFairSharePluginActivity(get_option(FAIRSHARE_ACCOUNT_ID), 0, 0);
}
catch(Exception $e){
}
}
/**
* Adds a FairShare section to the post page.
*/
function add_fairshare_section_to_posts()
{
$fairShareAccountId = get_option(FAIRSHARE_ACCOUNT_ID);
if( function_exists( 'add_meta_box' ) && !empty($fairShareAccountId)) {
add_meta_box('attributor', __('FairShare'), 'add_fairshare_section', 'page', 'advanced', 'core');
add_meta_box('attributor', __('FairShare'), 'add_fairshare_section', 'post', 'advanced', 'core');
}
}
/**
* Enable the 'FairShare' checkbox if FairShare was enabled for this post previously or for new posts.
*/
function add_fairshare_section($post) {
global $wpdb;
$page_id=$post->ID;
$table=$wpdb->prefix.FAIRSHARE_POSTS;
$structure = "SELECT * FROM ". $table." WHERE post_id=".$post->ID;
$myrows = $wpdb->get_results($structure);
$pageName = basename($_SERVER['SCRIPT_FILENAME']);
?>
0 || $pageName == "post-new.php") echo 'checked'; ?>/>
** Only include the FairShare widget on original content that you can claim as your own. More info
prefix.FAIRSHARE_POSTS;
$delete_structure = "delete from ". $table." where post_id=".$post_id;
$wpdb->query($delete_structure);
$postAction = $_POST['action'];
if(isset($_POST["enable-fairshare"]) || $postAction === "post-quickpress-publish"){
$insert_structure = "insert into ".$table."(post_id) values (".$post_id.")";
$wpdb->query($insert_structure);
}
//Now, fetch the data saved in the DB for this post and ingest it into the Attributor System.
$resultSet = $wpdb->get_row('select * from wp_posts where ID = '.$post_id, ARRAY_A);
if (!empty($resultSet)){
$fairShareAccountId = get_option(FAIRSHARE_ACCOUNT_ID);
$postUrl = $resultSet[POST_URL];
$postTitle = $resultSet[POST_TITLE];
$postContent = $resultSet[POST_CONTENT];
$fairShareApi = new FairShareAPI();
$response = $fairShareApi->ingestSource($fairShareAccountId, $postUrl, $postTitle, $postContent, 0);
if($response == false){
// Log the upload response error
$fairShareAnalytics = new FairShareAnalytics();
$fairShareAnalytics->logFairShareError($fairShareAccountId, 0, 3);
}
}
}
/**
* Deactivate the FairShare plugin.
* Sets the plugin active flag to false
*/
function deactivate_fairshare(){
// Log the deactivation of the fairshare widget.
$fairShareAnalytics = new FairShareAnalytics();
$fairShareAnalytics->logFairSharePluginActivity(get_option(FAIRSHARE_ACCOUNT_ID), 0, 1);
update_option(FAIRSHARE_PLUGIN_ACTIVE, 'false');
}
/**
* Display the FairShare widget into the post for which FairShare is enabled.
*/
function display_fairshare_widget($content)
{
$fairSharePluginActive = get_option(FAIRSHARE_PLUGIN_ACTIVE);
if($fairSharePluginActive == "false"){
return $content;
}
global $wpdb;
global $post;
$table = $wpdb->prefix.FAIRSHARE_POSTS;
$resultSetForFairSharePosts = $wpdb->get_row('select * from ' . $table . ' where post_id = '.$post->ID);
$resultSet = $wpdb->get_row('select * from wp_posts where ID = '.$post->ID, ARRAY_A);
if(!empty($resultSetForFairSharePosts) && !empty($resultSet)){
$pos = get_option(FAIRSHARE_WIDGET_POSITION);
$fairShareAccountId = get_option(FAIRSHARE_ACCOUNT_ID);
$articleId = $fairShareAccountId . "|" . $post->ID;
$result = "
'.$content;
break;
case 'top-center':
$result .= '
' . $fairShareWidgetCallScript .
'
'.$content;
break;
case 'bottom-left':
$result .= $content.'
' . $fairShareWidgetCallScript .
'
';
break;
case 'bottom-right':
$result .= $content.'
' . $fairShareWidgetCallScript .
'
';
break;
case 'bottom-center':
$result .= $content.'
' . $fairShareWidgetCallScript .
'
';
break;
}
$result .= "
";
}
else{
$result = $content;
}
return $result;
}
function add_fairshare_settings_page(){
if (function_exists ( "add_submenu_page" )) {
add_submenu_page('plugins.php','FairShare', 'FairShare','manage_options', __FILE__, 'fairshare_settings');
}
}
/**
* Displays the FairShare settings page.
*/
function fairshare_settings(){
?>
FairShare
getFairshareUserKey()]);
if(!empty($inputKey)){
$isValidUserKey = $fairShareApi->isValidUserKey($inputKey);
update_option ( $fairShareApi->getFairshareUserKey(), $inputKey);
$tempAccountId = $fairShareApi->getFairShareAccountId();
if (!empty($isValidUserKey) && $isValidUserKey == true && !empty($tempAccountId) && $fairShareApi->getFairShareAccountStatus() == 0) {
// Log the successful validation of the fairshare user key.
$fairShareAnalytics->logFairSharePluginActivity($fairShareApi->getFairShareAccountId(), 0, 2);
?>
logFairShareError($inputKey, 0, 0);
}
}
}
// Read the FairShare user key value from database
$fairShareUserKey = get_option ( $fairShareApi->getFairshareUserKey());
// If we have a user key..
if (!empty($fairShareUserKey)) {
$doesUserKeyExist = true;
// Check if it is a valid user key. If so, display the account id and the widget position settings section.
$isValidUserKey = $fairShareApi->isValidUserKey($fairShareUserKey);
$tempAccountId = $fairShareApi->getFairShareAccountId();
if (!empty($isValidUserKey) && $isValidUserKey == true && !empty($tempAccountId) && $fairShareApi->getFairShareAccountStatus() == 0) {
update_option(FAIRSHARE_ACCOUNT_ID, $fairShareApi->getFairShareAccountId());
$element = 'FairShare widget';
$pos = get_option(FAIRSHARE_WIDGET_POSITION);
$accountRevenue = $fairShareApi->getRevenueInformation($fairShareUserKey);
if($accountRevenue && $accountRevenue != -1){
$accountRevenue = "$" . $accountRevenue;
}
else{
$accountRevenue = "Not Available";
$fairShareAnalytics->logFairShareError($fairShareApi->getFairShareAccountId(), 0, 1);
}
?>
FairShare Account ID: getFairShareAccountId(); ?>
Your FairShare plugin is active. You are free to FairShare your posts with others!
Current Earnings:
Usage Guidelines
Please remember to put the FairShare widget on original work that you can claim as your own. FairSharing content that isn't yours may result in
suspension of your FairShare account.
Only put the FairShare widget on original posts that you can legitimately claim as your own work.
If you include quotes from others in your posts, be sure to enclose the entire excerpt in "quotation marks" or
<blockquote>excerpted content</blockquote>
tags. This tells FairShare to ignore these sections when assessing the originality of your content.
Don't put the FairShare widget on press releases or other public service announcements you republish.
Don't put the FairShare widget on public domain content such as government documents, transcripts of political speeches or content whose copyright has expired.