"Facebook", "google"=>"Google", "twitter"=>"Twitter", "linkedin"=>"Linkedin", "yahoo"=>"Yahoo");
$SOCIAL_NETWORK_ICONS=array("facebook"=>"facebook.png", "google"=>"google.png", "twitter"=>"twitter.png", "linkedin"=>"linkedin.png", "yahoo"=>"yahoo.png");
function selfURL() {
$s = empty($_SERVER['HTTPS']) ? '' : ($_SERVER['HTTPS'] == 'on') ? 's' : '';
$protocol = 'http'.$s;
$port = ($_SERVER['SERVER_PORT'] == '80') ? '' : (':'.$_SERVER['SERVER_PORT']);
$uri=$_SERVER['REQUEST_URI'];
return $protocol.'://'.$_SERVER['SERVER_NAME'].$port.substr($uri, 0, strpos($uri, '?'));
}
function getRootUrl($ssl=false){
$url=get_bloginfo('url');
if ($ssl && strpos($url, 'http://')===0){
return 'https://'.substr($url, 7);
}
return $url;
}
class service {
public $creationDate; // dateTime
public $descriptionText; // string
public $extendedAttributes; // extendedAttribute
public $id; // string
public $invoiceText; // string
public $modificationDate; // dateTime
public $permanentRights; // boolean
public $pricepoints; // pricepoint
public $services; // service
public $status; // string
public $stock; // long
}
class bundle {
public $creationDate; // dateTime
public $descriptionText; // string
public $extendedAttributes; // extendedAttribute
public $id; // string
public $invoiceText; // string
public $modificationDate; // dateTime
public $permanentRights; // boolean
public $pricepoints; // pricepoint
public $services; // service
public $status; // string
public $stock; // long
}
class pricepoint {
public $accessDuration; // int
public $accessDurationUnit; // string
public $creationDate; // dateTime
public $currency; // string
public $descriptionText; // string
public $expireDuration; // int
public $expireDurationUnit; // string
public $extendedAttributes; // extendedAttribute
public $id; // string
public $modificationDate; // dateTime
public $price; // double
public $promotions; // promotion
public $recurring; // boolean
public $status; // string
}
function getBachbillApi(){
$adminAreaId=get_option('bachbill_adminAreaId');
$adminUserId=get_option('bachbill_adminUserId');
$adminUserPassword=get_option('bachbill_adminUserPassword');
global $API_URL;
$api=new BachbillApi($API_URL);
$api->setAdminAreaId($adminAreaId);
$api->setAdminUserId($adminUserId);
$api->setAdminUserPassword($adminUserPassword);
return $api;
}
function getUserId(){
$current_user=wp_get_current_user();
$endUserId=$current_user->user_login;
$pos=strpos($endUserId, '__user_');
if ($pos===0){
$endUserId=substr($endUserId, 7);
}
return $endUserId;
}
function renderPromotion($pricepoint, $pr, $purchaseUrl){
$res='';
$res=$res.'
';
$res=$res.$pr['name'].'. '.$pr['discount'].' % '.__('discount', 'bachbill').'. '.$pr['descriptionText'].'. ';
$promoUrl=$purchaseUrl.'&promotionId='.$pr['id'];
if ($pr['hasPromocode']=='true'){
$res=$res.' '.__('You need a promocode', 'bachbill').': ';
}
$res=$res.'
';
$res=$res.'
';
return $res;
}
function renderPricepoint($bundleDesc, $endUserAreaId, $budleId, $p){
$res='';
$accessDuration=$p['accessDuration'];
$expireDuration=$p['expireDuration'];
$hasAccesses=$accessDuration>0;
$hasExpiry=$expireDuration>0;
$accessDuration=$p['accessDuration'];
$expireDuration=$p['expireDuration'];
$accessDurationUnit=$p['accessDurationUnit'];
$expireDurationUnit=$p['expireDurationUnit'];
$recurring=$p['recurring']=='true';
$price=$p['price'];
$currency=$p['currency'];
if ($hasAccesses && $hasExpiry){
$res=$res.$accessDuration.' '.__('article', 'bachbill').($accessDuration>1?'s':'').' in '.$expireDuration.' '.__($expireDurationUnit, 'bachbill').($expireDuration>1?'s':'');
}else if ($hasAccesses){
$res=$res.$accessDuration.' '.__('article', 'bachbill').($accessDuration>1?'s':'');
}else if ($hasExpiry){
$res=$res.$expireDuration.' '.__($expireDurationUnit, 'bachbill').($expireDuration>1?'s':'');
}else {
$res=$res.__('No match...', 'bachbill');
}
$recStr=$recurring?' for '.$price.' '.$currency.' '.__('per', 'bachbill').' '.__($expireDurationUnit, 'bachbill'):'';
$purchaseDetail=$bundleDesc.' ('.$res.$recStr.')';
$res=$res.' '.__('for', 'bachbill').' '.$price.' '.$currency;
if ($recurring){
$res=$res.', '.__('recurring', 'bachbill').'';
}
$useSSL=get_option('bachbill_useSSL');
$freqText='';
if ($recurring){
if ($expireDuration==1){
$freqText=__($expireDurationUnit, 'bachbill');
}else if ($expireDuration>1){
$freqText=''.$expireDuration.' '.__($expireDurationUnit, 'bachbill').'s';
}
}
$purchaseUrl=getRootUrl($useSSL).'/wp-content/plugins/a-dime-every-time/pages/purchase.php?action=render&recurring='.($recurring?'true':'false').'&purchaseDetail='.$purchaseDetail.'&price='.$price.'¤cy='.$currency.'&bundleId='.$budleId.'&pricepointId='.$p['id'].'&endUserId='.$endUserAreaId.'/'.getUserId().'&freqText='.$freqText;
$res=$res.' '.__('Buy', 'bachbill').'';
$promotions=$p['promotions'];
if ($promotions){
if ($promotions['Promotion'] && !$promotions['Promotion']['id']){
echo __('yes', 'bachbill').' ';
$promotions=$promotions['Promotion'];
}
$res=$res.'
';
$res=$res.'
';
$res=$res.'
'.__('This option has a promotion', 'bachbill').'
';
$res=$res.'
';
foreach ($promotions as $pr){
$res=$res.renderPromotion($p, $pr, $purchaseUrl);
}
$res=$res.'
';
}
return $res;
}
function renderPurchaseExperience($bundles){
$endUserAreaId=get_option('bachbill_endUserAreaId');
$res='';
$res=$res.'
'.__('To see more you need to subscribe to this content', 'bachbill').':
';
if ($bundles['Bundle'] && !$bundles['Bundle']['id']){
$bundles=$bundles['Bundle'];
}
foreach ($bundles as $b){
$bundleId=$b['id'];
$id=substr($bundleId, 2);
$isService=false;
$icon='puzzle_bundle2.png';
$category=null;
$post=null;
if (strpos($bundleId, "s_")===0){
$icon='puzzle.png';
$isService=true;
$post=get_post($id);
$bundleDesc=$post->post_title;
}else {
$category=get_category($id);
if ($category){
$bundleDesc=$category->name;
}else {
//!!! could be a good point where to delete the bundle?
}
}
$pricepoints=$b['pricepoints'];
if ($pricepoints['Pricepoint'] && !$pricepoints['Pricepoint']['id']){
$pricepoints=$pricepoints['Pricepoint'];
}
if ($pricepoints && ($category || $post)){
$res=$res.'