start_delimiter=$configuration->start_delimiter; $this->end_delimiter=$configuration->end_delimiter; $this->delimiter_tag_name=$configuration->delimiter_tag_name; $this->paied_users_table = $configuration->paied_users_table; $this->paied_items_table = $configuration->paied_items_table; $this->bonus_posts_table = $configuration->bonus_posts_table; $this->paypal_requests_table = $configuration->paypal_requests_table; $this->paypal_field_types_table = $configuration->paypal_field_types_table; $this->paypal_fields_table = $configuration->paypal_fields_table; $this->paypal_payment_info_table=$configuration->paypal_payment_info_table; $this->paypal_url=$configuration->paypal_url; $this->paypal_email = $configuration->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_html_headers')); $install = new Are_PayPal_Install(); register_activation_hook(__FILE__,array(&$install,'install')); } function post_filter($content){ $start_delimiter=$this->start_delimiter; $end_delimiter=$this->end_delimiter; 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;} $isPostPurchased=$this->IsPostPurchased($postID,$userID); $combination=((!$this->IsGooglebot())&&(($userID == 0) || (!$isPostPurchased))); echo(""); if ((!$this->IsGooglebot())&&(($userID == 0) || (!$isPostPurchased))){ $start = strpos($content, $start_delimiter); $end = strpos($content, $end_delimiter); $pre = substr($content,0,$start); $suf = substr($content,$end,strlen($content)); $delimiterRegex="/\\[$this->delimiter_tag_name\\].*?\\[\/$this->delimiter_tag_name\\]/is"; if (!(($start===FALSE) && ($end===FALSE))){ if ($userID == 0){ $domain = $_SERVER['HTTP_HOST']; $url = "http://" . $domain . $_SERVER['REQUEST_URI']; $LoginButton="".__("Login").""; $content = preg_replace($delimiterRegex,$LoginButton,$content); }else{ global $wpdb; $sql="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'"; $items = $wpdb->get_results($sql); 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; $item_expire=$this->native_expiration_message($item->expire); $postButton=$this->paypal_buy_now_form($item_name.":".$item_title." ".$item_expire,$item_number,$item_amount,$item_currency,$postID,$userID); } $blog_item_amount=get_option($this->prefix.'_BlogAmount'); if ($blog_item_amount){ $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'); $blog_item_expire=$this->native_expiration_message($blog_item_expire); $blogButton=$this->paypal_buy_now_form($blog_item_name.":".$blog_item_title." ".$blog_item_expire,$blog_item_number,$blog_item_amount,$blog_item_currency,-1,$userID);//-1 post id for whole site } echo(""); if ($blogButton || $postButton){ $content = preg_replace($delimiterRegex,$postButton.$blogButton,$content); } } } } $content= str_replace($start_delimiter,'',$content); $content= str_replace($end_delimiter,'',$content); return $content; } function native_expiration_message($item_expire){ if ($item_expire){ $item_expire=__(" Expires in ").$item_expire.__(" days"); }else{ $item_expire=""; } return $item_expire; } 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')); add_submenu_page(__FILE__, __($this->prefix.' Configuration 5'), __('How to use'), 10,$this->prefix.'_HowToUse' , array(&$this,'How_To_Use')); } } 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'); ?> />  

How to hide content and show paypal button?

How to configure paypal's Instant Payment Notification (IPN)?

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 ($_GET["PurchasersSubmit"]){ if ($_GET["PurchasersSubmit"]==">>"){ $item_purchaser=$_GET["available_users"]; $wpdb->query("INSERT INTO $this->paied_users_table(post_id,user_id) VALUES($post_id,$item_purchaser)"); $LastAction = __("Added successfully ..."); }else{ $item_purchaser=$_GET["paied_users"]; $wpdb->query("DELETE FROM $this->paied_users_table WHERE post_id=$post_id AND user_id=$item_purchaser"); $LastAction = __("Removed successfully ..."); } } if (($action=="delete")&&($post_id)){ $wpdb->query("DELETE FROM $this->paied_items_table WHERE post_id=$post_id"); $wpdb->query("DELETE FROM $this->paied_users_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_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); } if (($action=="purchasers")&&($post_id)){ if(!empty($LastAction)) { echo '

'.$LastAction.'

'; } $items = $wpdb->get_results("SELECT posts.ID,posts.post_title FROM $wpdb->posts posts WHERE posts.id='$post_id'"); if($items) { $item=$items[0]; $item_id=$item->ID; $item_title=$item->post_title; ?>

"/>
 

"/>

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' AND $this->post_type_clause"); 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; if(!empty($LastAction)) { echo '

'.$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 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 AND (ADDDATE(up.purchase_date, up.expire) > CURDATE() OR up.expire is null OR up.expire = 0)"); foreach($users as $user) { echo $user->user_login; echo "
"; } ?>

"/>

"/>

posts posts LEFT OUTER JOIN $this->paied_items_table items ON items.post_id=posts.id WHERE posts.post_content LIKE '%$this->start_delimiter%' AND $this->post_type_clause"; $items = $wpdb->get_results($sql); if(!empty($LastAction)) { echo '

'.$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 AND (ADDDATE(up.purchase_date, up.expire) > CURDATE() OR up.expire is null OR up.expire = 0)"); 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').'
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)"; $users = $wpdb->get_results($sql); if ($users){ return true; } $item_amount=get_option($this->prefix.'_BlogAmount'); if ($item_amount){ $sql="SELECT * FROM .$this->paypal_payment_info_table WHERE custom ='$post_id|$user_id' AND mc_gross=$item_amount"; $paypal_response=$wpdb->get_results($sql); 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) { $sql="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)"; $users = $wpdb->get_results($sql); 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; } 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' AND (ADDDATE(purchase_date, expire) > CURDATE() OR expire is null OR expire = 0)"); 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']; $textExplanation ="

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

"; $result="
".$textExplanation."

$item_name: $item_number

$item_price $item_currency

".$this->BonusPostsList($post_id)."

"; return $result; } function BonusPostsList($post_id){ global $wpdb; $post_id=mysql_escape_string($post_id); $sql="select posts.post_title,posts.id from $this->bonus_posts_table bonuses INNER JOIN $wpdb->posts posts ON posts.id=bonuses.post2_id WHERE bonuses.post1_id='$post_id'"; $bonuses=$wpdb->get_results($sql); $result=""; if ($bonuses){ $result.="

".__("Purchasing current content you will also get access for posts below")."

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