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->users_library_page = $configuration->users_library_page; $this->purchased_posts_list_placeholder=$configuration->purchased_posts_list_placeholder; $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_filter('the_content', array(&$this,'purchased_posts')); add_action('wp_head', array(&$this,'add_html_headers')); add_action( 'wp_footer', array(&$this,'put_my_url_to_footer')); $install = new Are_PayPal_Install(); register_activation_hook(__FILE__,array(&$install,'install')); $this->set_templates(); } function put_my_url_to_footer() { ?> set_templates(); } function show_login_button($url,$urltext){ $templateName=$this->prefix."_LoginButtonTemplate"; $result=stripslashes(get_option($templateName)); $explanation = get_option($this->prefix.'_TextToShowIfNotLogedIn'); $result=str_replace('%EXPLANATION%',$explanation,$result); $result=str_replace('%LOGINURL%',$url,$result); $result=str_replace('%LOGINURLTEXT%',$urltext,$result); return $result; } function purchased_posts($content){ global $wpdb; if (strpos($content,$this->purchased_posts_list_placeholder) === false){ if ( is_page($this->users_library_page)) { $content.= $this->purchased_posts_list_placeholder; } } if (!(strpos($content,$this->purchased_posts_list_placeholder) === false)){ global $current_user, $user_ID; $userID=$user_ID; if ($userID == 0) {$userID = $current_user->id;} $sql = "SELECT DISTINCT posts.post_title,posts.guid, items.post_id FROM $wpdb->posts posts INNER JOIN $this->paied_users_table items ON items.post_id=posts.id WHERE user_id ='$userID' AND $this->post_type_clause"; $purchased_posts = $wpdb->get_results($sql, OBJECT); if ($purchased_posts){ $purchasedPostsList=""; foreach ($purchased_posts as $post){ if ($this->IsPostPurchased($post->post_id,$userID)){ $purchasedPostsList.="

$post->post_title

"; } } } $content=str_replace($this->purchased_posts_list_placeholder,$purchasedPostsList,$content); } return $content; } 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 = $this->show_login_button(get_option ('siteurl')."/wp-login.php?redirect_to=$url",__("Log in")); $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,$item->expire); } $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,get_option($this->prefix.'_BlogExpire'));//-1 post id for whole site } 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'),'/wp-content/plugins/are-paypal/images/icon_paypal_2Ps_16x14.gif'); 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')); add_submenu_page(__FILE__, __($this->prefix.' Configuration 6'), __('Donate'), 10,$this->prefix.'_Donate' , array(&$this,'Donate')); } } function Main_Configuration_Page() { global $wpdb; check_admin_referer(); if ( isset($_POST['restoretemplatedefaults']) ) { delete_option($this->prefix.'_InstantPaymentTemplate'); delete_option($this->prefix.'_RecurentPaymentTemplate'); delete_option($this->prefix.'_LoginButtonTemplate'); $this->set_templates(); } if ( isset($_POST['submit']) ) { $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); $Value = $_POST['InstantPaymentTemplate']; update_option($this->prefix.'_InstantPaymentTemplate', $Value); $Value = $_POST['RecurentPaymentTemplate']; update_option($this->prefix.'_RecurentPaymentTemplate', $Value); $Value = $_POST['LoginButtonTemplate']; update_option($this->prefix.'_LoginButtonTemplate', $Value); $Value = $_POST['Suppress_Notification_Emails']; update_option($this->prefix.'_Suppress_Notification_Emails', $Value); $Value = $_POST['users_library_page']; update_option($this->prefix.'_Users_Library_Page', $Value); $LastAction = __("Updated successfully ..."); } ?>

'.$LastAction.'

'; } ?>

prefix.' Configuration'); ?>

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

prefix.'_test'); ?> />  

prefix.'_Suppress_Notification_Emails'); ?> />  

paypal_buy_now_form("Item Name","Item Number","1","EUR",0,0,0)); ?> paypal_buy_now_form("Item Name","Item Number","1","EUR",0,0,30));?> show_login_button("URL","URLTEXT"))?>

prefix.'_Users_Library_Page', $Value);?>

How to hide content and show paypal button?

How to add purchased posts list into any page/post?

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

ManagePurchasers($action,$post_id); if ( isset($_POST['submit']) ) { $Value=$_POST["amount"]; update_option($this->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']) ) { 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 ..."); } if (!$action||$action=="edit"){ $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.'

'; } ?>

"/>

paypal_requests_table"; if ($_REQUEST["action"] == "details"){ $RequestID = $_REQUEST["RequestID"]; $sql .= " where RequestID='$RequestID'"; } $requests=$wpdb->get_results($sql); if(count($requests) > 0) { ?>

RequestID; $fields=$wpdb->get_results("select * from $this->paypal_fields_table where RequestID='$RequestID'"); if(count($fields) > 0) { foreach($fields as $field) { ?>Name=="custom"){ list($post_id,$user_id) = explode("|",$field->Value); $user_id=mysql_escape_string($user_id); $post_id=mysql_escape_string($post_id); $login=$wpdb->get_results("SELECT user_login FROM $wpdb->users where ID='$user_id'"); ?>get_results("SELECT post_title FROM $wpdb->posts where ID='$post_id'"); ?>RequestID; $fields=$wpdb->get_results("select * from $this->paypal_fields_table where RequestID='$RequestID'"); if(count($fields) > 0) { ?>%TYPE%"; foreach($fields as $field) { switch ($field->Name) { case "txn_type": $rowTemplate=str_replace('%TYPE%',$field->Value,$rowTemplate); break; case "payer_email": $rowTemplate=str_replace('%EMAIL%',$field->Value,$rowTemplate); break; case "mc_gross": $rowTemplate=str_replace('%AMOUNT%',$field->Value,$rowTemplate); break; case "mc_amount3": $rowTemplate=str_replace('%AMOUNT%',$field->Value,$rowTemplate); break; case "custom": list($post_id,$user_id) = explode("|",$field->Value); $user_id=mysql_escape_string($user_id); $post_id=mysql_escape_string($post_id); $login=$wpdb->get_results("SELECT user_login FROM $wpdb->users where ID='$user_id'"); $post=$wpdb->get_results("SELECT post_title FROM $wpdb->posts where ID='$post_id'"); $rowTemplate=str_replace('%LOGIN%',$login[0]->user_login,$rowTemplate); $rowTemplate=str_replace('%TITLE%',$post[0]->post_title,$rowTemplate); break; } } $rowTemplate=str_replace('%AMOUNT%','',$rowTemplate); echo($rowTemplate); ?>
Name;?>Value;?>
user_login;?>
post_title;?>
%EMAIL%%AMOUNT%%LOGIN%%TITLE%
>"){ $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=="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 || $post_id==-1) { if ($post_id==-1){ $item_id=-1; $item_title="Entire blog ..."; }else{ $item=$items[0]; $item_id=$item->ID; $item_title=$item->post_title; } ?>

"/>
 

"/>

>"){ $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"); $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)){ $this->ManagePurchasers($action,$post_id); } elseif (($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' 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').'
IsPostPurchasedSql("-1",$user_id)){return true;} if ($this->IsPostPurchasedSql($post_id,$user_id)){return true;} return false; } function IsPostPurchasedSql($post_id,$user_id){ global $wpdb; $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; } return false; } function paypal_buy_now_form($item_name,$item_number,$item_price,$item_currency,$post_id,$user_id,$item_expiration){ $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 =stripslashes(get_option($this->prefix.'_TextToShowIfNotPurchased')); $templateName=$this->prefix."_RecurentPaymentTemplate"; if (!$item_expiration) {$templateName=$this->prefix."_InstantPaymentTemplate";} $result=stripslashes(get_option($templateName)); $result=str_replace('%EXPLANATION%',$textExplanation,$result); $result=str_replace('%PAYPALURL%',$paypal_url,$result); $result=str_replace('%ITEMNAME%',$item_name,$result); $result=str_replace('%ITEMNUMBER%',$item_number,$result); $result=str_replace('%ITEMPRICE%',$item_price,$result); $result=str_replace('%ITEMCURRENCY%',$item_currency,$result); $result=str_replace('%BONUSLIST%',$this->BonusPostsList($post_id),$result); $result=str_replace('%PAYPALEMAIL%',$paypal_email,$result); $result=str_replace('%ITEMRETURN%',$item_return,$result); $result=str_replace('%ITEMCUSTOM%',$item_custom,$result); $result=str_replace('%EXPIRATIONINDAYS%',$item_expiration,$result); $result=str_replace('%BUTTONALT%','',$result); 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(); } ?>