Thanks for using 123LinkIt!
';
echo 'For new users - to add money-making affiliate links to your posts, click on the 123LinkIt tab and register for an account. ';
echo 'For existing users - our Settings tab has changed. Click here to login and then synchronize all your posts at once (even if they\'ve been synced before).
';
echo 'You must configure your settings and select your blog category before using the 123Linkit plugin!
';
echo 'Note: You only need to synchronize your posts once. Our plugin will automatically update new and edited posts.
';
echo '';
}
add_action('admin_notices','LinkITAlert');
function loadjQuery() {
wp_enqueue_script("jquery");
}
add_action('init','loadjQuery');
require_once("lib/proxy.php");
add_action('admin_menu', 'LinkITMenu');
add_action('publish_post', 'LinkITPublish');
add_filter('the_content', 'TheContent');
remove_filter('the_content', 'wptexturize');
remove_filter('the_content', 'convert_smilies');
remove_filter('the_content', 'convert_chars');
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'prepend_attachment');
function TheContent($content) {
$private_key = get_option("LinkITPrivateKey");
if ($private_key == "") return $content;
global $wpdb;
$poststable = $wpdb->prefix . "posts";
//make sure we have a table
LinkITCreateCacheTable();
$guid = get_the_guid(0);
$private_key = get_option("LinkITPrivateKey");
$params = array("guid" => $guid,
"private_key" => $private_key,
"blog_url" => get_bloginfo("url"));
$cached_content = LinkITGetCachedPost($guid);
if (strlen($cached_content) > strlen($content))
return $cached_content;
else {
$result = LinkITAPIDownload($params);
$result = json_decode($result['data']);
$new_content = $result->{"content"};
// if (strlen($new_content) < 5) $new_content = $content;
if (strlen($new_content) < strlen($content)) $new_content = $content;
$hash = md5($new_content);
$new_content = wptexturize($new_content);
$new_content = convert_smilies($new_content);
$new_content = convert_chars($new_content);
$new_content = wpautop($new_content);
$new_content = prepend_attachment($new_content);
LinkITDeleteCachedPost($guid);
LinkITAddCachedPost($guid, $new_content, $hash);
return $new_content;
}
}
function LinkITPublish($post_id) {
$private_key = get_option("LinkITPrivateKey");
if ($private_key == "") return 0;
global $wpdb;
$poststable = $wpdb->prefix . "posts";
$myrows = $wpdb->get_results("SELECT guid, post_title, post_content, post_type FROM $poststable WHERE id = '$post_id'");
$s = $myrows[0];
if ($s->{'post_type'} == 'post') {
$guid = $s->{'guid'};
$title = $s->{'post_title'};
$content = $s->{'post_content'};
$params = array("guid" => $guid,
"title" => $title,
"content" => $content,
"private_key" => $private_key,
"blog_url" => get_bloginfo("url"));
LinkITAPIUpload($params);
//make sure we have the table
LinkITCreateCacheTable();
LinkITDeleteCachedPost($guid);
}
}
function LinkITMenu() {
// add_management_page('123LinkIt', '123LinkIt', 'manage_options', 'LinkITPluginCentral', 'LinkITPluginCentral');
add_menu_page('123LinkIt', '123LinkIt', 'manage_options', 'LinkITPluginCentral', 'LinkITPluginCentral', 'http://www.123linkit.com/images/123linkit.favicon.gif', 3);
}
function LinkITRenderHeader() {
echo '";
}
function LinkITRenderLogin($errorMessage) {
?>
$private_key);
$result = LinkITApiGetStats($params);
$result = json_decode($result['data']);
update_option("LinkITNPosts", $result->{"nposts"});
update_option("LinkITNLinks", $result->{"nlinks"});
update_option("LinkITAvgLinks", $result->{"avglinks"});
update_option("LinkITNCommissions", $result->{"ncommissions"});
update_option("LinkITTotalSelf", $result->{"totalself"});
update_option("LinkITNReferrals", $result->{"nreferrals"});
update_option("LinkITTotalReferrals", $result->{"totalreferrals"});
update_option("LinkITReceivedMoney", $result->{"receivedmoney"});
update_option("LinkITRemainingBalance", $result->{"remainingbalance"});
}
function LinkITRestoreDefaultSettings() {
$private_key = get_option("LinkITPrivateKey");
$params = array("private_key" => $private_key);
$result = LinkITApiRestoreDefaultSettings($params);
}
function LinkITUpload() {
$title = $_POST['title'];
$guid = $_POST['guid'];
$content = $_POST['content'];
$private_key = get_option("LinkITPrivateKey");
$params = array("guid" => $guid,
"title" => $title,
"content" => $content,
"private_key" => $private_key,
"blog_url" => get_bloginfo("url"));
LinkITAPIUpload($params);
}
function LinkITDownload() {
global $wpdb;
$poststable = $wpdb->prefix . "posts";
$guid = $_POST['guid'];
$private_key = get_option("LinkITPrivateKey");
$params = array("guid" => $guid,
"private_key" => $private_key,
"blog_url" => get_bloginfo("url"));
$result = LinkITAPIDownload($params);
$result = json_decode($result['data']);
$new_content = mysql_real_escape_string($result->{"content"});
$wpdb->query("UPDATE $poststable SET post_content = '$new_content' WHERE post_status = 'publish' AND guid = '$guid'");
}
function LinkITShowPost($post) {
$link = $post->{"guid"};
echo "" . $post->{"post_title"} . " ";
echo "" . $post->{"post_modified"} . " ";
echo "Not Synchronized ";
echo "";
echo "";
echo "";
echo " ";
}
function LinkITShowPostNew($post) {
$title = $post->{"post_title"};
$content = $post->{"post_content"};
$guid = $post->{"guid"};
$date = $post->{"post_date"};
echo "$date $title ";
echo "";
echo "";
echo " ";
echo "";
echo " ";
}
function LinkITShowAllPosts() {
global $wpdb;
$poststable = $wpdb->prefix . "posts";
$myrows = $wpdb->get_results("SELECT * FROM $poststable WHERE post_status = 'publish'");
foreach($myrows as $row)
LinkITShowPostNew($row);
}
function LinkITHeader() {
echo '';
}
function LinkITDashBoard() {
echo '';
echo '
Get Started Using 123LinkIt';
echo "
";
echo "
";
echo '';
echo '
My Profile';
echo '
';
echo "
";
echo '';
echo '';
echo '';
echo '';
echo 'Number of Posts Analyzed ';
echo 'Total Links Added ';
echo 'Average number of links per post ';
echo '';
echo 'Number of referrals ';
echo 'Total amount of commissions from referrals ';
echo ' ';
echo ' ';
echo '';
echo '';
echo '';
echo ' ' . get_option("LinkITNPosts") . ' ';
echo ' ' . get_option("LinkITNLinks") . ' ';
echo ' ' . get_option("LinkITAvgLinks") . ' ';
echo '';
echo ' ' . get_option("LinkITNReferrals") . ' ';
echo ' ' . get_option("LinkITTotalReferrals") . ' ';
echo ' ';
echo "";
echo ' ';
echo ' ';
echo "
";
echo '
';
echo '
';
}
function LinkITUpdateOptions() {
if(!empty($_POST)) {
$cloaked = $_POST['options_cloaked'];
$nofollow = $_POST['options_nofollow'];
$newwindow = $_POST['options_new_window'];
$num_links = $_POST['options_num_links'];
$blog_category = $_POST['LinkITBlogCategory'];
$params = array("private_key" => get_option("LinkITPrivateKey"),
"cloak_links" => $cloaked,
"nofollow_tags" => $nofollow,
"links_new_window" => $newwindow,
"maximum_links" => $num_links);
update_option("LinkITConfig","done");
update_option("LinkITBlogCategory",$blog_category);
LinkITApiUpdateOptions($params);
LinkITAPISetCategory($blog_category);
}
}
function LinkITSyncpubl($guid, $title, $content) {
echo "Syncing $title
"; flush(); ob_flush();
$private_key = get_option("LinkITPrivateKey");
$params = array("guid" => $guid,
"title" => $title,
"content" => $content,
"private_key" => $private_key,
"blog_url" => get_bloginfo("url"));
$result = LinkITAPISync($params);
$result = json_decode($result['data']);
$new_content = mysql_real_escape_string(stripslashes($result->{"content"}));
global $wpdb;
$poststable = $wpdb->prefix . "posts";
$wpdb->query("UPDATE $poststable SET post_content = '$new_content' WHERE post_status = 'publish' AND guid = '$guid'");
echo "Blog post $title has been updated successfully!
"; flush(); ob_flush();
}
function LinkITSyncAll() {
global $wpdb;
$poststable = $wpdb->prefix . "posts";
add_option("last_sync","0");
$last_sync = get_option("last_sync");
if ($last_sync == "")
$last_sync = 0;
$datetime=date('Y-m-d H:i:s', $last_sync);
$myrows = $wpdb->get_results("SELECT post_modified, id, post_title FROM $poststable WHERE post_status = 'publish' AND post_type = 'post' AND post_modified > '$datetime'");
echo " ";
// make sure the option last_sync exists
if (!$myrows)
echo "All posts are synchronized";
else
foreach($myrows as $row) {
$title = $row->{"post_title"};
$modified = strtotime($row->{"post_modified"});
if ($modified >= get_option("last_sync"))
{
LinkItPublish($row->{"id"});
echo "" . $title . " - synchronizing"." "; flush(); ob_flush();
}
else
echo $title . " - allready synchronized "; flush(); ob_flush();
}
echo " ";
update_option("last_sync",time());
LinkITSyncProfile();
}
function LinkITChallenge() {
$results = LinkITApiGetRandomKeywords();
$results = json_decode($results['data']);
echo '';
echo '
The 123LinkIt Challenge';
echo '
';
echo 'Lacking ideas for your blog post? We challenge you to write one using the following random keywords:';
echo '
';
foreach($results as $value)
echo '' . $value;
echo ' ';
echo '
';
echo '
';
}
function LinkITOptions() {
LinkITUpdateOptions();
$params = array("private_key" => get_option("LinkITPrivateKey"));
$results = LinkITApiGetOptions($params);
$results = json_decode($results['data']);
$cloaked = $results->{"cloak_links"} == 1 ? "checked" : "";
$nofollow = $results->{"nofollow_tags"} == "1" ? "checked" : "";
$newwindow = $results->{"links_new_window"} == "1" ? "checked" : "";
if($results->{"maximum_links"} == "1") $maximumlinks = "checked";
else $onelink = "checked";
echo '';
echo '
Options';
echo '
';
echo '
';
}
function TryOptions() {
add_option("LinkITEmail", "0", false, true);
add_option("LinkITPrivateKey", "0", false, true);
add_option("LinkITPublicKey", "0", false, true);
add_option("LinkITNPosts", "0", false, true);
add_option("LinkITNLinks", "0", false, true);
add_option("LinkITAvgLinks", "N/A", false, true);
add_option("LinkITNCommissions", "0", false, true);
add_option("LinkITTotalSelf", "0 USD", false, true);
add_option("LinkITNReferrals", "0", false, true);
add_option("LinkITTotalReferrals", "0 USD", false, true);
add_option("LinkITReceivedMoney", "0 USD", false, true);
add_option("LinkITRemainingBalance", "0 USD", false, true);
}
function LinkITSetCategory(){
$blog_category = $_POST['LinkITBlogCategory'];
update_option("LinkITBlogCategory", $blog_category);
LinkITAPISetCategory($blog_category);
}
function LinkITGetCategory(){
$result = LinkITAPIGetCategory();
$result = json_decode($result['data']);
if ($result->{'error'} == "0") {
$blog_category = $result -> {'blog_category'};
update_option("LinkITBlogCategory", $blog_category);
}
}
function LinkITBugReport() {
$msg = $_POST['LinkITMsg'];
global $wpdb;
$table = $wpdb->prefix . "linkit_requests";
$rows = $wpdb->get_results("SELECT * FROM $table ORDER BY time DESC");
$data = "request | sent | recived | time ";;
foreach ($rows as $row) {
$request = $row -> {'request'};
$sent = $row -> {'data_sent'};
$recived = $row -> {'data_recived'};
$time = $row -> {'time'};
$data=$data . "$request | $sent | $recived | $time ";
}
LinkITAPIBugReport($msg,$data);
}
function LinkITRenderBugReport() {
?>
Select your blog's category:
Accessories Art/Photo/Music Automotive Beauty Books/Media Business Buying and Selling Careers Clothing/Apparel Computer & Electronics Department Stores/Malls Education Entertainment Family Financial Services Food & Drinks Games & Toys Gifts & Flowers Health and Wellness Home & Garden Legal Marketing Non-Profit Online Services Recreation & Leisure Seasonal Sports & Fitness Telecommunications Travel
prefix . "linkit_cached_posts";
$wpdb -> query("delete all from $table_name");
$datetime=date('Y-m-d H:i:s');
// $_REQUEST['step'] = '';
// LinkITRenderLogin($errorMessage);
}
function LinkITPluginCentral() {
/* if (strlen(get_option("LinkITEmail")) > 4)
LinkITGetCategory();*/
if (strlen(get_option("LinkITEmail")) <= 4)
{
update_option("LinkITEmail","");
update_option("LinkITPrivateKey", "");
update_option("LinkITPublicKey", "");
}
register_activation_hook('lib/proxy.php','LinkITCreateCacheTable');
echo ' ' . "\n";
TryOptions();
LinkITRenderHeader();
$errorMessage = "";
$step = $_GET['step'];
if ($step == "resetAll") {
LinkITResetAll();
$step = "";
}
if($step =='login') {
$userResult = LinkITLogin();
if($userResult->{'error'} != "0") {
$errorMessage = $userResult->{'error'};
} else {
update_option("LinkITEmail", $_REQUEST['LinkITEmail']);
update_option("LinkITPrivateKey", $userResult->{"private_key"});
update_option("LinkITPublicKey", $userResult->{"public_key"});
LinkITGetCategory();
}
$step = "";
} else if($step == 'logout') {
update_option("LinkITEmail", "");
update_option("LinkITPrivateKey", "");
update_option("LinkITPublicKey", "");
$step = "";
}
else if ($step == 'signup') {
LinkITRenderSignUp();
}
else if ($step == 'createuser') {
$userResult = LinkITCreateUser();
if ($userResult -> {'error'} != "0")
$errorMessage = $userResult -> {'error'};
else
{
$userResult = LinkITLogin();
update_option("LinkITEmail", $_REQUEST['LinkITEmail']);
update_option("LinkITPrivateKey", $userResult->{"private_key"});
update_option("LinkITPublicKey", $userResult->{"public_key"});
}
$step = "";
}
else if ($step == 'install') {
LinkITCreateCacheTable();
}
if(get_option("LinkITPublicKey") != "") {
LinkITHeader();
//report bug
if ($step == 'reportbug') {
$userResult = LinkITBugReport();
if ($userResult -> {'error'} != "0")
$errorMessage = $userResult -> {'error'};
}
// actions
if($step == 'syncAll') {
LinkITSyncAll();
} else if($step == 'syncProfile') {
LinkITSyncProfile();
} else if($step == 'restoreDefaultSettings') {
LinkITRestoreDefaultSettings();
$step = 'options';
}
// and pages
if($step == 'options') {
LinkITOptions();
} else if($step == 'challenge') {
LinkITChallenge();
} else if ($step == 'bugform')
LinkITRenderBugReport();
else
LinkITDashBoard();
}
// else if($step == "") LinkITRenderLogin($errorMessage);
if (strlen(get_option("LinkITEmail")) < 4)
LinkITRenderLogin($errorMessage);
if (get_option("LinkITConfig") == "done"){
?>