paied_users_table = $wpdb->prefix . $this->prefix . "_users"; $this->paied_items_table = $wpdb->prefix . $this->prefix . "_items"; $this->bonus_posts_table = $wpdb->prefix . $this->prefix . "_bonus"; $this->paypal_payment_info_table=$wpdb->prefix . $this->prefix . "_payment_info"; $this->paypal_url="https://www.paypal.com/cgi-bin/webscr"; if (get_option($this->prefix.'_test')=='checked'){ $this->paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; } $this->paypal_email = get_option($this->prefix.'_PayPal_Email'); //Hook into wordpress add_action('admin_menu', array(&$this,'Are_PayPal_Configuration')); add_filter('the_content', array(&$this,'post_filter')); add_action('wp_head', array(&$this,'add_meta_tags_for_robots')); register_activation_hook(__FILE__,array(&$this,'install')); } function post_filter($content){ $start_delimiter="[".$this->prefix."_LoginPlease]"; $end_delimiter="[/".$this->prefix."_LoginPlease]"; global $current_user, $user_ID,$post_ID,$post,$id; $postID=$post_ID; $userID=$user_ID; if ($userID == 0) {$userID = $current_user->id;} if ($postID == 0) {$postID = $post->id;} if ($postID == 0) {$postID = $id;} if ((!$this->IsGooglebot())&&(($userID == 0) || (!$this->IsPostPurchased($postID,$userID)))){ $start = strpos($content, $start_delimiter); $end = strpos($content, $end_delimiter); $pre = substr($content,0,$start); $suf = substr($content,$end,strlen($content)); if (!(($start===FALSE) && ($end===FALSE))){ if ($userID == 0){ $domain = $_SERVER['HTTP_HOST']; $url = "http://" . $domain . $_SERVER['REQUEST_URI']; $LoginButton="".__("Login").""; $content= $pre."
".get_option($this->prefix.'_TextToShowIfNotLogedIn')."
".$LoginButton.$suf; }else{ global $wpdb; $items = $wpdb->get_results("SELECT posts.ID,posts.post_title, items.* FROM $wpdb->posts posts INNER JOIN $this->paied_items_table items ON items.post_id=posts.id WHERE posts.id='$postID'"); if($items) { $item=$items[0]; $item_id=$item->ID; $item_title=$item->post_title; $item_amount=$item->amount; $item_currency=$item->currency; $item_name=$item->name; $item_number=$item->number; $postButton=$this->paypal_buy_now_form($item_name.":".$item_title,$item_number,$item_amount,$item_currency,$postID,$userID); } $blog_item_name=get_option($this->prefix.'_BlogName'); if ($blog_item_name){ $blog_item_amount=get_option($this->prefix.'_BlogAmount'); $blog_item_currency=get_option($this->prefix.'_BlogCurrency'); $blog_item_name=get_option($this->prefix.'_BlogName'); $blog_item_number=get_option($this->prefix.'_BlogNumber'); $blog_item_expire=get_option($this->prefix.'_BlogExpire'); $blogButton=$this->paypal_buy_now_form($blog_item_name.":".$blog_item_title,$blog_item_number,$blog_item_amount,$blog_item_currency,-1,$userID);//-1 post id for whole site } if ($blogButton || $postButton){ $textExplanation ="

".get_option($this->prefix.'_TextToShowIfNotPurchased')."

"; $content = preg_replace("/\\[Are_PayPal_LoginPlease\\].*?\\[\/Are_PayPal_LoginPlease\\]/i",$textExplanation.$postButton.$blogButton,$content); } } } } $content= str_replace($start_delimiter,'',$content); $content= str_replace($end_delimiter,'',$content); return $content; } function Are_PayPal_Configuration() { global $wpdb; if ( function_exists('add_submenu_page') ){ add_menu_page(__($this->prefix), __($this->prefix), 10, __FILE__, array(&$this,'Main_Configuration_Page')); add_submenu_page(__FILE__, __($this->prefix.' Configuration 2'), __('Post Prices'), 10,$this->prefix.'_PostSetup' , array(&$this,'Configure_Prices_For_Posts')); add_submenu_page(__FILE__, __($this->prefix.' Configuration 3'), __('Paypal data'), 10,$this->prefix.'_PaypalData' , array(&$this,'View_Payments')); add_submenu_page(__FILE__, __($this->prefix.' Configuration 4'), __('Blog Price'), 10,$this->prefix.'_BlogPrice' , array(&$this,'Blog_Price')); } } function install(){ global $wpdb; if($wpdb->get_var("SHOW TABLES LIKE '$this->paied_items_table'") != $this->paied_items_table) { $sql = "CREATE TABLE " . $this->paied_items_table . " ( `id` bigint(20) NOT NULL auto_increment, `post_id` bigint(20) NOT NULL, `name` varchar(255) NOT NULL, `number` varchar(255) default NULL, `amount` double NOT NULL, `currency` char(3) NOT NULL, UNIQUE KEY `id` (`id`) );"; $sql = $sql . "CREATE TABLE " . $this->paied_users_table . " ( `id` bigint(20) NOT NULL auto_increment, `post_id` bigint(20) NOT NULL, `user_id` bigint(20) NOT NULL, UNIQUE KEY `id` (`id`) );"; $sql=$sql." CREATE TABLE ".$this->paypal_payment_info_table." ( `FIRSTNAME` VARCHAR(100) NOT NULL DEFAULT '', `LASTNAME` VARCHAR(100) NOT NULL DEFAULT '', `BUYER_EMAIL` VARCHAR(100) NOT NULL DEFAULT '', `STREET` VARCHAR(100) NOT NULL DEFAULT '', `CITY` VARCHAR(50) NOT NULL DEFAULT '', `STATE` CHAR(3) NOT NULL DEFAULT '', `ZIPCODE` VARCHAR(11) NOT NULL DEFAULT '', `MEMO` VARCHAR(255) DEFAULT NULL, `ITEMNAME` VARCHAR(255) DEFAULT NULL, `ITEMNUMBER` VARCHAR(50) DEFAULT NULL, `OS0` VARCHAR(20) DEFAULT NULL, `ON0` VARCHAR(50) DEFAULT NULL, `OS1` VARCHAR(20) DEFAULT NULL, `ON1` VARCHAR(50) DEFAULT NULL, `QUANTITY` CHAR(3) DEFAULT NULL, `PAYMENTDATE` VARCHAR(50) NOT NULL DEFAULT '', `PAYMENTTYPE` VARCHAR(10) NOT NULL DEFAULT '', `TXNID` VARCHAR(30) NOT NULL DEFAULT '', `MC_GROSS` VARCHAR(6) NOT NULL DEFAULT '', `MC_FEE` VARCHAR(5) NOT NULL DEFAULT '', `PAYMENTSTATUS` VARCHAR(15) NOT NULL DEFAULT '', `PENDINGREASON` VARCHAR(10) DEFAULT NULL, `TXNTYPE` VARCHAR(10) NOT NULL DEFAULT '', `TAX` VARCHAR(10) DEFAULT NULL, `MC_CURRENCY` VARCHAR(5) NOT NULL DEFAULT '', `REASONCODE` VARCHAR(20) NOT NULL DEFAULT '', `CUSTOM` VARCHAR(255) NOT NULL DEFAULT '', `COUNTRY` VARCHAR(20) NOT NULL DEFAULT '', `DATECREATION` DATE NOT NULL DEFAULT '0000-00-00');"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); add_option($this->prefix."_db_version", "1.0"); } $version = get_option($this->prefix."_db_version"); if ($version=="1.0"){ $sql = "CREATE TABLE " . $this->paied_items_table . " ( `id` bigint(20) NOT NULL auto_increment, `post_id` bigint(20) NOT NULL, `name` varchar(255) NOT NULL, `number` varchar(255) default NULL, `amount` double NOT NULL, `currency` char(3) NOT NULL, `expire` bigint(20) NULL, UNIQUE KEY `id` (`id`) );"; $sql = $sql . "CREATE TABLE " . $this->paied_users_table . " ( `id` bigint(20) NOT NULL auto_increment, `post_id` bigint(20) NOT NULL, `user_id` bigint(20) NOT NULL, `expire` bigint(20) NULL, `purchase_date` timestamp NOT NULL, UNIQUE KEY `id` (`id`) );"; $sql = $sql . " CREATE TABLE $this->bonus_posts_table ( `post1_id` bigint(20) NOT NULL, `post2_id` bigint(20) NOT NULL, PRIMARY KEY (`post1_id`,`post2_id`) ); "; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); $wpdb->query($sql); update_option($this->prefix."_db_version", "2.0"); } } function Main_Configuration_Page() { if ( isset($_POST['submit']) ) { check_admin_referer(); $Value = $_POST['TextToShowIfNotLogedIn']; update_option($this->prefix.'_TextToShowIfNotLogedIn', $Value); $Value = $_POST['PayPal_Email']; update_option($this->prefix.'_PayPal_Email', $Value); $Value = $_POST['test']; update_option($this->prefix.'_test', $Value); $Value = $_POST['TextToShowIfNotPurchased']; update_option($this->prefix.'_TextToShowIfNotPurchased', $Value); $LastAction = __("Updated successfully ..."); } ?>

'.$LastAction.'

'; } ?>

prefix.' Configuration'); ?>

Aurimas Norkevicius for help with the plugin.')); ?>

prefix.'_test'); ?> />  

prefix.'_BlogAmount', $Value); $Value=$_POST["currency"]; update_option($this->prefix.'_BlogCurrency', $Value); $Value=$_POST["name"]; update_option($this->prefix.'_BlogName', $Value); $Value=$_POST["number"]; update_option($this->prefix.'_BlogNumber', $Value); $Value=$_POST["expire"]; update_option($this->prefix.'_BlogExpire', $Value); $LastAction = __(" Updated successfully ..."); } if ( isset($_POST['clear']) ) { check_admin_referer(); delete_option($this->prefix.'_BlogAmount'); delete_option($this->prefix.'_BlogCurrency'); delete_option($this->prefix.'_BlogName'); delete_option($this->prefix.'_BlogNumber'); delete_option($this->prefix.'_BlogExpire'); $LastAction = __(" Deleted successfully ..."); } $item_amount=get_option($this->prefix.'_BlogAmount'); $item_currency=get_option($this->prefix.'_BlogCurrency'); $item_name=get_option($this->prefix.'_BlogName'); $item_number=get_option($this->prefix.'_BlogNumber'); $item_expire=get_option($this->prefix.'_BlogExpire'); ?>

'.$LastAction.'

'; } ?>

"/>

get_results("select * from $this->paypal_payment_info_table",ARRAY_A); if(count($payments) > 0) { $firstRow=$payments[0]; $columnNames=array_keys($firstRow); ?>

Arrange_dataInto_Lines($columnNames,$row,4); ?>
$current_row){ ?> Arrange_dataInto_Lines($columnNames,$row,$number_of_rows,$current_row+1); } } function Configure_Prices_For_Posts() { global $wpdb; ### Get The Posts $action = mysql_escape_string($_GET["action"]); $post_id = mysql_escape_string($_GET["post_id"]); if ($_GET["BonusSubmit"]){ if ($_GET["BonusSubmit"]==">>"){ $post2_id=$_GET["post_to_package"]; $wpdb->query("INSERT INTO $this->bonus_posts_table VALUES($post_id,$post2_id)"); $wpdb->query("INSERT INTO $this->bonus_posts_table VALUES($post2_id,$post_id)"); $LastAction = __("Added successfully ..."); }else{ $post2_id=$_GET["post_in_package"]; $wpdb->query("DELETE FROM $this->bonus_posts_table WHERE post1_id=$post_id AND post2_id=$post2_id"); $wpdb->query("DELETE FROM $this->bonus_posts_table WHERE post1_id=$post2_id AND post2_id=$post_id"); $LastAction = __("Removed successfully ..."); } } if (($action=="delete")&&($post_id)){ $wpdb->query("DELETE FROM $this->paied_items_table WHERE post_id=$post_id"); $LastAction = __("Deleted successfully ..."); } if (($action=="write")&&($post_id)){ $items = $wpdb->get_results("SELECT posts.ID,posts.post_title, items.* FROM $wpdb->posts posts LEFT OUTER JOIN $this->paied_items_table items ON items.post_id=posts.id WHERE posts.id='$post_id'"); $item=$items[0]; $item_id=$item->ID; $item_amount=mysql_escape_string($_GET["amount"]); $item_currency=mysql_escape_string($_GET["currency"]); $item_name=mysql_escape_string($_GET["name"]); $item_number=mysql_escape_string($_GET["number"]); $item_purchasers=$_GET["purchasers"]; $item_expire=$_GET["expire"]; if ($item->post_id){ //UPDATE $sql="UPDATE $this->paied_items_table SET name='$item_name',number='$item_number',amount='$item_amount',currency='$item_currency',expire='$item_expire' WHERE post_id=$item_id"; $LastAction = __("Updated successfully ..."); }else{ //INSERT $sql="INSERT INTO $this->paied_items_table (name,number,amount,currency, post_id,expire) VALUES('$item_name','$item_number','$item_amount','$item_currency','$item_id','$item_expire')"; $LastAction = __("Inserted successfully ..."); } $wpdb->query($sql); $wpdb->query("DELETE FROM $this->paied_users_table WHERE post_id=$item_id"); if ($item_purchasers){ foreach ($item_purchasers as $item_purchaser){ $item_purchaser=mysql_escape_string($item_purchaser); $wpdb->query("INSERT INTO $this->paied_users_table(post_id,user_id) VALUES($item_id,$item_purchaser)"); } } } if (($action=="bonus")&&($post_id)){ $items = $wpdb->get_results("SELECT posts.ID,posts.post_title, items.* FROM $wpdb->posts posts LEFT OUTER JOIN $this->paied_items_table items ON items.post_id=posts.id WHERE posts.id='$post_id'"); if($items) { $item=$items[0]; $item_id=$item->ID; $item_title=$item->post_title; $item_amount=$item->amount; $item_currency=$item->currency; $item_expire=$item->expire; $item_name=$item->name; $item_number=$item->number; ?>

'.$LastAction.'

'; } ?>

"/>
 

"/>

get_results("SELECT posts.ID,posts.post_title, items.* FROM $wpdb->posts posts LEFT OUTER JOIN $this->paied_items_table items ON items.post_id=posts.id WHERE posts.id='$post_id'"); if($items) { $item=$items[0]; $item_id=$item->ID; $item_title=$item->post_title; $item_amount=$item->amount; $item_currency=$item->currency; $item_expire=$item->expire; $item_name=$item->name; $item_number=$item->number; ?>

'.$LastAction.'

'; } ?>

"/>

"/>

"/>

get_results("SELECT posts.ID,posts.post_title, items.* FROM $wpdb->posts posts LEFT OUTER JOIN $this->paied_items_table items ON items.post_id=posts.id"); ?>

'.$LastAction.'

'; } ?>

ID; $item_title=$item->post_title; $item_amount=$item->amount; $item_currency=$item->currency; $item_expire=$item->expire; $item_name=$item->name; $item_number=$item->number; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; ?> '; $i++; } } else { echo ''; } ?>
 
$item_id$item_title"; $users = $wpdb->get_results("SELECT user_login FROM $wpdb->users u INNER JOIN $this->paied_users_table up ON up.user_id=u.id and up.post_id=$item_id"); foreach($users as $user) { echo $user->user_login; echo "
"; } echo "
$item_name$item_number$item_amount$item_currency$item_expire post_id){ ?> | |
'.__('No Posts Found').'
get_results("SELECT users.* FROM . $this->paied_users_table users WHERE (users.post_id='$post_id') AND users.user_id='$user_id' AND (ADDDATE(purchase_date, expire) > CURDATE() OR expire is null OR expire = 0)"); if ($users){ return true; } $item_amount=get_option($this->prefix.'_BlogAmount'); if ($item_amount){ $paypal_response=$wpdb->get_results("SELECT * FROM .$this->paypal_payment_info_table WHERE custom ='$post_id|$user_id' AND mc_gross=$item_amount"); if ($paypal_response){ //Grant access(This is needed to prevent misfunction on price change) $this->PayForItem($post_id,$user_id); $wpdb->query("UPDATE $this->paypal_payment_info_table SET custom='[processed]$post_id|$user_id' WHERE custom ='$post_id|$user_id' AND mc_gross=$item_amount"); return true; } } $post_id=mysql_escape_string($post_id_tmp); $sql = "SELECT items.* FROM $this->paied_items_table items WHERE items.post_id='$post_id'"; $items = $wpdb->get_results($sql); if($items) { $users = $wpdb->get_results("SELECT users.* FROM . $this->paied_users_table users WHERE (users.post_id='$post_id') AND users.user_id='$user_id' AND (ADDDATE(purchase_date, expire) > CURDATE() OR expire is null OR expire = 0)"); if ($users){ return true; } $item_amount=$items[0]->amount; if ($item_amount){ $paypal_response=$wpdb->get_results("SELECT * FROM .$this->paypal_payment_info_table WHERE custom ='$post_id|$user_id' AND mc_gross=$item_amount"); if ($paypal_response){ //Grant access(This is needed to prevent misfunction on price change) $this->PayForItem($post_id,$user_id); $wpdb->query("UPDATE $this->paypal_payment_info_table SET custom='[processed]$post_id|$user_id' WHERE custom ='$post_id|$user_id' AND mc_gross=$item_amount"); return true; } } } $item_amount=get_option($this->prefix.'_BlogAmount'); if ($item_amount){ return false; } } // Create User administration screen function PayForItem($post_id,$user_id){ global $wpdb; $post_id=mysql_escape_string($post_id); $items = $wpdb->get_results("SELECT * FROM . $this->paied_items_table WHERE post_id='$post_id'"); $expire=''; if ($items){ $expire=$items[0]->expire; } if ($post_id=="-1"){ $expire=get_option($this->prefix.'_BlogExpire'); } $user_id=mysql_escape_string($user_id); $users = $wpdb->get_results("SELECT users.* FROM . $this->paied_users_table users WHERE users.post_id='$post_id' AND users.user_id='$user_id'"); if (!$users){ $wpdb->query("INSERT INTO $this->paied_users_table(post_id,user_id,expire) VALUES('$post_id','$user_id','$expire')"); $bonuses = $wpdb->get_results("SELECT post2_id FROM . $this->bonus_posts_table WHERE post1_id='$post_id'"); foreach($bonuses as $bonus) { $this->PayForItem($bonus->post2_id,$user_id); } } } function paypal_buy_now_form($item_name,$item_number,$item_price,$item_currency,$post_id,$user_id){ $paypal_url=$this->paypal_url; $paypal_email = $this->paypal_email; $item_custom = $post_id."|".$user_id; $domain = $_SERVER['HTTP_HOST']; $item_return = "http://" . $domain . $_SERVER['REQUEST_URI']; $result="
$item_price $item_currency

"; return $result; } function add_meta_tags_for_robots(){ echo(''); } } } //instantiate the class if (class_exists('Are_PayPal')) { $Are_PayPal = new Are_PayPal(); } ?>