}
}
function Arrange_dataInto_Lines($columnNames,$row,$number_of_rows,$current_row=0){
if ($number_of_rows>$current_row){
?>
$counter=0;
foreach($columnNames as $columnName) {
$counter++;
if ($counter % $number_of_rows==$current_row){
?>
_e($columnName)?>
}
}
?>
$counter=0;
foreach($columnNames as $columnName) {
$counter++;
if ($counter % $number_of_rows==$current_row){
?>
=$row[$columnName]?>
}
}
?>
$this->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;
?>
}
}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.'
'; } ?>
}
}else if (($action=="edit")&&($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;
?>
if(!empty($LastAction)) { echo '
'.$LastAction.'
'; } ?>
}
}else{
$sql="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.post_content LIKE '%$this->start_delimiter%' AND $this->post_type_clause";
$items = $wpdb->get_results($sql);
if(!empty($LastAction)) { echo '
";
$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 "
}
function IsGooglebot(){
// check if user agent contains googlebot
if(eregi("Googlebot",$_SERVER['HTTP_USER_AGENT'])){
$ip = $_SERVER['REMOTE_ADDR'];
//server name e.g. crawl-66-249-66-1.googlebot.com
$name = gethostbyaddr($ip);
//check if name ciontains googlebot
if(eregi("Googlebot",$name)){
//list of IP's
$hosts = gethostbynamel($name);
foreach($hosts as $host){
if ($host == $ip){
return true;
}
}
return false; // Pretender, take some action if needed
}else{
return false; // Pretender, take some action if needed
}
}else{
// Not googlebot, take some action if needed
}
return false;
}
function IsPostPurchased($post_id,$user_id){
$user_id=mysql_escape_string($user_id);
$post_id_tmp=$post_id;
$post_id="-1";
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;
}
$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 ="
";
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();
}
?>