ADimeEveryTime", 1, 'a-dime-every-time/admin.php', 'bachbill_general_options', plugins_url('a-dime-every-time/img/dime_logo_15x15.png')); add_submenu_page('a-dime-every-time/admin.php', __('Settings', 'bachbill'), __('Settings', 'bachbill'), 1, 'a-dime-every-time/admin.php','bachbill_general_options'); add_submenu_page('a-dime-every-time/admin.php', __('Reporting', 'bachbill'), __('Reporting', 'bachbill'), 1, __('reporting', 'bachbill'), 'bachbill_reporting'); $accountSetup=get_option('bachbill_account_setup'); if ($accountSetup && $accountSetup=='ready'){ add_submenu_page('a-dime-every-time/admin.php', __('Payments', 'bachbill'), __('Payments', 'bachbill'), 1, __('Payments', 'bachbill'), 'bachbill_payments'); } } function rewriteLinks($post, $content){ $links=get_post_meta($post->ID, 'bachbill_protected_links', ''); if (!is_array($links)){ return; } $links=$links[0]; if ($links){ $root=getRootUrl(); foreach ($links as $link){ $index=strrpos($link, '.'); $name=md5($link); $ext=''; if ($index>0){ $ext=substr($link, $index); } $fName=$name.$ext; $fullName=$root.'/wp-content/plugins/a-dime-every-time/media.php?file='.$fName.'&postId='.$post->ID; update_option('bachbill_protected_'.$post->ID.'_'.$fName, $link); $content=str_replace($link, $fullName, $content); } } return $content; } function intercept($content){ global $post; $isChargeable=get_post_meta($post->ID, 'bachbill_chargeable', true); if (!$isChargeable){ // see if any category is chargeable $categories=wp_get_post_categories($post->ID); foreach ($categories as $cat){ $isChargeable=get_option('bachbill_cat_'.$cat.'_chargeable'); if ($isChargeable){ break; } } } if (!$isChargeable){ return $content; } $content=rewriteLinks($post, $content); $serviceId='s_'.$post->ID; $user=wp_get_current_user(); $role=$user->roles[0]; if (is_user_logged_in() && $role!='subscriber'){ return $content; } if ( !is_user_logged_in() ){ return $post->post_excerpt.'
'.__('You are not logged in to see this content', 'bachbill').'.
'.__('log in', 'bachbill').''; }else { if ($serviceId){ @session_start(); $userServices=$_SESSION['bachbill_userServices']; if (!isset($userServices)){ $userServices=array(); $_SESSION['bachbill_userServices']=$userServices; } $service=$userServices[$serviceId]; if ($service){ return $content; }else { // try to authorize the user // concurrence control. Some themes ask for the_content more than once and we don't want that @session_start(); //!!! disable $concurrenceTime=$_SESSION['bachbill_concurrence_thecontent']; //!!! disable $_SESSION['bachbill_concurrence_thecontent']=microtime(true); //!!! disable if ($concurrenceTime>0 && microtime(true)-$concurrenceTime<0.7){ //!!! disable return '';//.(microtime(true)-$concurrenceTime); //!!! disable } $nUsages=get_post_meta($post->ID, 'bachbill_n_usages', '1'); $nUsages=$nUsages?$nUsages:1; if (is_single() || is_page()){ $api=getBachbillApi(); $priceplanId=get_option('bachbill_priceplanId'); $endUserAreaId=get_option('bachbill_endUserAreaId'); $api->setMethod("get"); $res=$api->authorize($priceplanId, $endUserAreaId, getUserId(), $serviceId, $nUsages); if ($api->hasErrors()){ return $api->getErrorMessage(); } if (!$res){ return __('There was an error while trying to authorize the user to use the content', 'bachbill'); } if ($res['error']){ echo $res['error']['message']; }else { $res=$res['AuthorizeResponse']; $transaction=$res['transaction']; if ($res['code']==0){ if ($transaction){ if ($transaction['captureDate']){ // transaction is captured so user is authorized permanently. Otherwise it wouldn't be reported and only the subscription object would be there $service=new BachbillService($serviceId); $userServices[$serviceId]=$service; $_SESSION['bachbill_userServices']=$userServices; }else { // transaction is ongoing and not captured yet } return $content; } // if the subscription is credit based, show splash page $pendingAccesses=$res['subscriptions']['Subscription']['pendingAccesses']; if (!$_GET['confirmUsageSplash']=='true' && $pendingAccesses>0){ $finalUrl=get_permalink( $post->ID ); $position=strpos($finalUrl, '?'); if ($position){ $finalUrl.='&confirmUsageSplash=true'; }else{ $finalUrl.='?confirmUsageSplash=true'; } // $finalUrl=strpos($finalUrl, '?')>=0?($finalUrl+'&confirmUsageSplash'):($finalUrl+'?confirmUsageSplash'); return '

'. __('This content costs', 'bachbill'). ' '.$nUsages.' '. __('credit', 'bachbill').($nUsages>1?'s':''). '

'. __('You have', 'bachbill'). ' '.$pendingAccesses.' '. __('credits left in your subscription.', 'bachbill'). '

'. __('Please hit', 'bachbill'). ' '. __('Continue', 'bachbill'). ''. ' '. __('to access the content and discount the credit from your balance.', 'bachbill'); }else { $subscriptionId=$res['subscriptions']['Subscription']['id']; $res=$api->usage($priceplanId, $endUserAreaId, getUserId(), $subscriptionId, $serviceId, $nUsages); $service=new BachbillService($serviceId); $userServices[$serviceId]=$service; $_SESSION['bachbill_userServices']=$userServices; return $content; } }else { if (!$res){ return __('There was an error while trying to authorize the user to use the content', 'bachbill'); } @session_start(); $_SESSION['bachbill_redirect_after_purchase']=get_permalink( $post->ID ); return $post->post_excerpt.'
'.renderPurchaseExperience($res['bundles']); } return 'Lets see...'; } }else { $glue=''; if ($post->post_excerpt){ $glue='

'; } $nUsages=get_post_meta($post->ID, 'bachbill_n_usages', '1'); $credits=$nUsages>1?(__('This items costs', 'bachbill').' '.$nUsages.' '.__('credits', 'bachbill').'
'):''; return $post->post_excerpt.$glue.$credits.__('Please press', 'bachbill').' '.__('here', 'bachbill').' '.__('to access the full content', 'bachbill').'

'; } } }else { return $content; } } } //!!! disable $content_intercepted=false; //!!! disable $thecontent=''; function content_interceptor($content){ //!!! disable if (!$content_intercepted){ $c=intercept($content); //!!! disable $thecontent=$c; //!!! disable $content_intercepted=true; //!!! disable }else{ //!!! disable $c=$thecontent; //!!! disable } return $c; } function bachbill_logout(){ @session_start(); $endUserSessionId=$_SESSION['endUserSessionId']; unset($_SESSION['endUserSessionId']); unset($_SESSION['bachbill_userServices']); $_SESSION['bachbill_userServices']=array(); @session_destroy(); if ($endUserSessionId){ $priceplanId=get_option('bachbill_priceplanId'); $api=getBachbillApi(); $ret= $api->endSession($priceplanId, $endUserSessionId); $ret=$ret['GetSessionResponse']; }else { // echo 'not logged in by bachbill..'; } } /** * BachbillWidget Class */ class BachbillWidget extends WP_Widget { /** constructor */ function BachbillWidget() { parent::WP_Widget(false, $name = 'A Dime Every Time'); } /** @see WP_Widget::widget */ function widget($args, $instance) { extract( $args ); $title = apply_filters('widget_title', $instance['title']); ?>

'.__( 'ADimeEveryTime Charging Options', 'bachbill' ), 'bachbill_edit_post_form2', 'post', 'advanced' ); } else { add_action('dbx_post_advanced', 'bachbill_edit_post_form2' ); } } function bachbill_edit_post_form2($post){ $accountSetup=get_option('bachbill_account_setup'); if ($accountSetup!='ready'){ ?> ID, 'bachbill_chargeable', true); if ($isChargeable){ $priceplanId=get_option('bachbill_priceplanId'); $api=getBachbillApi(); $res=$api->callOnIncomingUrlAction($priceplanId, '/quick_provision?obj=bundle&action=get&id=s_'.$post->ID); if ($api->getErrorCode()<>0){ showErrorWithAlert($api->getErrorMessage()); return; } $code=$res['QuickProvisionResponse']['code']; if ($code==-4){// not existing yet }else if ($code==0){ $pricepoints=$res['QuickProvisionResponse']['result']['pricepoints']; if ($pricepoints['Pricepoint'] && !$pricepoints['Pricepoint']['id']){ $pricepoints=$pricepoints['Pricepoint']; } } } bachbill_print_pricing_options('post', $isChargeable, $pricepoints); } function bachbill_save_post($post_id){ if ( !current_user_can('edit_post', $post_id) ){ return $post_id; } $currency=get_option('bachbill_currency'); if (sizeof($_POST)==0){ return $post_id; } $quickEdit=!$_POST['original_post_status'];// it's quick edit $nUsages=$_POST['nUsages']; if ($nUsages){ //add_post_meta($post_id, 'bachbill_n_usages', $nUsages) or update_post_meta($post_id, 'bachbill_n_usages', $nUsages); } $post=get_post($post_id); @session_start(); $wasChargeable=$_SESSION['wasChargeable']; unset($_SESSION['wasChargeable']); if ($post->post_status=='publish'){ $prevTitle=$_SESSION['prevTitle']; unset($_SESSION['prevTitle']); if ($_POST['postPricingChanges']=='true' || $prevTitle!=$post->post_title){ // the post name or pricing changed $isChargeable=$quickEdit?get_post_meta($post->ID, 'bachbill_chargeable', true):$_POST['isChargeable']; if (!$isChargeable && $wasChargeable){ $priceplanId=get_option('bachbill_priceplanId'); $api=getBachbillApi(); $api->setParam('id', 's_'.$post->ID); $api->setParam('obj', 'service'); $api->setParam('action', 'deprovision'); $res=$api->callOnIncomingUrlAction($priceplanId, '/quick_provision'); if ($api->getErrorCode()<>0){ showErrorWithAlert($api->getErrorMessage()); return; } } if (!$quickEdit){ add_post_meta($post_id, 'bachbill_chargeable', $isChargeable, true) or update_post_meta($post_id, 'bachbill_chargeable', $isChargeable); } if (!$quickEdit && $isChargeable){ // manage price $price=$_POST['price']; $priceplanId=get_option('bachbill_priceplanId'); $api=getBachbillApi(); $api->setParam('id', 's_'.$post->ID); $api->setParam('obj', 'service'); $api->setParam('action', 'provision'); $api->setParam('description', $post->post_title); $api->setParam('price', $price); $api->setParam('currency', $currency); $res=$api->callOnIncomingUrlAction($priceplanId, '/quick_provision'); if ($api->getErrorCode()<>0){ wp_redirect($_SERVER['HTTP_REFERER'].'&bErrorStr='.urlencode($api->getErrorMessage())); throw new Exception($api->getErrorMessage(), $api->getErrorCode()); } } } // manage protected links $links=$_POST['bachbill_links']; update_post_meta($post->ID, 'bachbill_protected_links', $links); // check if categories changed $categories=wp_get_post_categories($post_id); $previous_categories=$_SESSION['bachbill_previous_categories']; unset($_SESSION['bachbill_previous_categories']); if (!is_array($categories)){ $c=$categories; $categories=array(); array_push($categories, $c); } if (!is_array($previous_categories)){ $c=$previous_categories; $previous_categories=array(); array_push($previous_categories, $c); } $added=array(); $deleted=array(); // foreach ($categories as $cat){ // if ((''.array_search($cat, $previous_categories))===''){ // // not there previously // $catName=get_cat_name($cat); // $isChargeable=get_option('bachbill_cat_'.$cat.'_chargeable'); // if ($isChargeable){ // //bachbill_update_category($cat, false); // array_push($added, 'b_'.$cat); // } // } // } foreach ($categories as $cat){ // we will add ALL the existing categories, even if there wheren't before. This way, we avoid draft posts to have "orphan" categories that are not provisioned in bachbill $catName=get_cat_name($cat); $isChargeable=get_option('bachbill_cat_'.$cat.'_chargeable'); if ($isChargeable){ //bachbill_update_category($cat, false); array_push($added, 'b_'.$cat); } } foreach ($previous_categories as $cat){ if ((''.array_search($cat, $categories))===''){ // cat not there anymore $catName=get_cat_name($cat); $isChargeable=get_option('bachbill_cat_'.$cat.'_chargeable'); if ($isChargeable){ //bachbill_update_category($cat, false); array_push($deleted, 'b_'.$cat); } } } if (sizeof($added)+sizeof($deleted)>0){ if (!addEditServiceBundles('s_'.$post->ID, $post->post_title, $added, $deleted)){ throw new Exception('dd', -1); } } }else { // save previous categories //exec( 'echo "saving prev id '.$post->ID.'">>/tmp/php.log'); @session_start(); $parent_post_id=$post->post_parent; if ($parent_post_id>0){ $categories=wp_get_post_categories($parent_post_id); $_SESSION['bachbill_previous_categories']=$categories; $wasChargeable=get_post_meta($post->ID, 'bachbill_chargeable', true); $_SESSION['wasChargeable']=wasChargeable; } // save previous title $_SESSION['prevTitle']=$post->post_title; } return $post_id; } function fill_pricepoints($pricepoints){ $i=0; foreach ($pricepoints as $p){ ?> addPricepoint();

'.__( 'ADimeEveryTime Charging Options', 'bachbill' ).'


'; } ?>
   : .

/>
()


   :






:



If you want to use the ADimeEveryTime plugin pricing options please click term_id){ // if ($cat->term_id!=1){ $isChargeable=get_option('bachbill_cat_'.$cat->term_id.'_chargeable'); if ($isChargeable){ $priceplanId=get_option('bachbill_priceplanId'); $api=getBachbillApi(); $res=$api->callOnIncomingUrlAction($priceplanId, '/quick_provision?obj=bundle&action=get&id=b_'.$cat->term_id); //exec( 'echo "res '.$res.'">>/tmp/php.log'); if ($api->getErrorCode()<>0){ showErrorWithAlert($api->getErrorMessage()); return; } $code=$res['QuickProvisionResponse']['code']; if ($code==-4){// not existing yet }else if ($code==0){ $pricepoints=$res['QuickProvisionResponse']['result']['pricepoints']; if ($pricepoints['Pricepoint'] && !$pricepoints['Pricepoint']['id']){ $pricepoints=$pricepoints['Pricepoint']; } } } // } // if ($cat->term_id!=1){ bachbill_print_pricing_options('category', $isChargeable, $pricepoints); // } } } function hasService($bundle, $service){ foreach ($bundle->services as $s){ if ($service->id == $s->id){ return true; } } return false; } function bachbill_update_category($term_id, $managePricepoints){ $currency=get_option('bachbill_currency'); $bundle=provisionBundle($term_id); $posts=get_posts(array('category'=>$term_id, 'numberposts' => 10000)); $changed=false; $bundle->services=array(); foreach($posts as $post){ // make all posts chargeable and provision them $service=provisionService($post->ID); array_push($bundle->services, $service); $changed=true; } if ($managePricepoints){ // manage price $price=$_POST['price']; $nPricepoints=$_POST['bachbill_n_pricepoints']; $pricepoints=array(); for ($i=0; $i<$nPricepoints; $i++){ $bachbill_pricepoint_enabled=$_POST['bachbill_pricepoint_enabled_'.$i]=='true'; if ($bachbill_pricepoint_enabled){ $bachbill_type=$_POST['bachbill_type_'.$i]; if ($bachbill_type=='timerecurring'){ $price=$_POST['a_price_'.$i]; $expireDuration=$_POST['a_expireDuration_'.$i]; $expireDurationUnit=$_POST['a_expireDurationUnit_'.$i]; $pricepointId='a_timerecurring_'.$price.'_'.$currency.'_'.$expireDuration.'_'.$expireDurationUnit; $desc=$expireDuration.' '.$expireDurationUnit; $pricepoint=provisionPricepoint($pricepointId, $price, $currency, '-1', '', $expireDuration, $expireDurationUnit, true, $desc); if (!$pricepoint->extendedAttributes){ $pricepoint->extendedAttributes=array(); } array_push($pricepoints, $pricepoint); }else if ($bachbill_type=='uses'){ $accessDuration=$_POST['b_accessDuration_'.$i]; $price=$_POST['b_price_'.$i]; $pricepointId='b_uses_'.$price.'_'.$currency.'_'.$accessDuration.'_use'; $desc=$accessDuration.' use'; $pricepoint=provisionPricepoint($pricepointId, $price, $currency, $accessDuration, 'use', 0, '', false, $desc); if (!$pricepoint->extendedAttributes){ $pricepoint->extendedAttributes=array(); } array_push($pricepoints, $pricepoint); }else if ($bachbill_type=='time'){ $price=$_POST['c_price_'.$i]; $expireDuration=$_POST['c_expireDuration_'.$i]; $expireDurationUnit=$_POST['c_expireDurationUnit_'.$i]; $pricepointId='c_time_'.$price.'_'.$currency.'_'.$expireDuration.'_'.$expireDurationUnit; $desc=$expireDuration.' '.$expireDurationUnit; $pricepoint=provisionPricepoint($pricepointId, $price, $currency, '-1', '', $expireDuration, $expireDurationUnit, false, $desc); if (!$pricepoint->extendedAttributes){ $pricepoint->extendedAttributes=array(); } array_push($pricepoints, $pricepoint); }else if ($bachbill_type=='timeanduses'){ $price=$_POST['d_price_'.$i]; $accessDuration=$_POST['d_accessDuration_'.$i]; $expireDuration=$_POST['d_expireDuration_'.$i]; $expireDurationUnit=$_POST['d_expireDurationUnit_'.$i]; $pricepointId='d_timeanduses_'.$price.'_'.$currency.'_'.$accessDuration.'_use_'.$expireDuration.'_'.$expireDurationUnit; $desc=$expireDuration.' '.$expireDurationUnit; $pricepoint=provisionPricepoint($pricepointId, $price, $currency, $accessDuration, 'use', $expireDuration, $expireDurationUnit, false, $desc); if (!$pricepoint->extendedAttributes){ $pricepoint->extendedAttributes=array(); } array_push($pricepoints, $pricepoint); } } } $bundle->pricepoints=$pricepoints; } if (!saveBundle($bundle, $managePricepoints)){ throw new Exception('dd', -1); } } function bachbill_save_category($term_id){ $isChargeable=$_POST['isChargeable']; $wasChargeable=$_POST['wasChargeable']; if (!$isChargeable && $wasChargeable){ if (!deleteBundle('b_'.$term_id)){ throw new Exception('dd', -1); } } $nPricepoints=$_POST['bachbill_n_pricepoints']; // if not present means that it's quick edit if ($nPricepoints){ if ($isChargeable){ bachbill_update_category($term_id, true); // do it after updating, just in case update_option('bachbill_cat_'.$term_id.'_chargeable', $isChargeable); }else { update_option('bachbill_cat_'.$term_id.'_chargeable', $isChargeable); } } return $term_id; } function bachbill_init() { $plugin_dir = dirname( plugin_basename( __FILE__ ) ); load_plugin_textdomain( 'bachbill', false, $plugin_dir ); } /** * WP HOOKS **/ add_action('init', 'bachbill_init'); add_action('admin_menu', 'bachbill_admin_menu'); add_action('the_content', 'content_interceptor'); add_action('register_form','plugin_form'); add_action('login_footer','bachbill_login_footer'); add_action('wp_logout','bachbill_logout'); add_action('dbx_post_advanced', 'bachbill_edit_post_form' ); add_action('save_post', 'bachbill_save_post' ); //add_action('publish_post', array('hsdhb', 'hhhsd')); add_action('edit_category_form', 'bachbill_edit_category_form' ); add_action('edit_category', 'bachbill_save_category' ); /** * END WP HOOKS **/ function bachbill_login_footer(){ // $referer=$_SERVER['HTTP_REFERER']; // if (!empty($referer) && !strpos($referer, '/wp-login.php')){ // @session_start(); // $_SESSION['bachbill_redirect_after_login']=$referer; // }else { // unset($_SESSION['bachbill_redirect_after_login']); // } $socialNetworks=get_option('bachbill_social_networks'); $n=0; foreach ($socialNetworks as $key => $value){ if ($value){ $n++; } } ?>
0){ ?>
If you prefer to log in using your social network please choose below: