function getPaywall($name = null, $showDisabled = true) { $paywalls = $this->getPaywalls($showDisabled); foreach ($paywalls as $rid => $ps) { if ($rid == $name) { return $ps; } } $ps = new TPPaySettings(array()); $ps->setResourceId($name); $ps->setEnabled(true); $ps->setMode(TPPaySettings::MODE_PPV); return $ps; }
/** * Create offer from settings data * * @param TPPaySettings $ps * @return returns null or a valid TPOffer */ public static function create_offer(&$ps, $rid, $rname = null) { if ($ps == null) { return null; } if ($rname == '' || $rname == null) { $rname = $ps->getResourceName(); } $resource = new TPResource($rid, stripslashes($rname)); $pos = array(); for ($i = 1; $i <= $ps->getNumPrices(); $i++) { $priceString = $ps->getPrice($i); if ($ps->isRecurring($i)) { $priceString = '[' . $ps->getPrice($i) . '|' . $ps->getRecurring($i) . '| * ]'; } $po = new TPPriceOption($priceString); if ($ps->getAccess($i) != '') { $po->setAccessPeriod($ps->getAccess($i)); } if ($ps->getCaption($i) != '') { $po->setCaption(stripslashes($ps->getCaption($i))); } $pos[] = $po; } $offer = new TPOffer($resource, $pos); return $offer; }
public function validatePostSettings($form, &$errors) { $form = new NiceArray($form); $errors = array(); for ($i = 1; $i <= 3; $i++) { if ($form['po_en' . $i] == 0) { unset($form["po_en{$i}"]); unset($form["po_p{$i}"]); unset($form["po_ap{$i}"]); unset($form["po_ap_type{$i}"]); unset($form["po_cap{$i}"]); unset($form["po_st{$i}"]); unset($form["po_et{$i}"]); continue; } $p = $form['po_p' . $i]; if (!TPValidate::validatePrice($p)) { $errors["po_p{$i}"] = _(TPValidate::PRICE_FAILED_MSG); } $ap = $form['po_ap' . $i]; if (!TPValidate::validateAccessPeriod($ap)) { $errors["po_ap{$i}"] = _(TPValidate::ACCESS_PERIOD_FAILED_MSG); } } $ps = new TPPaySettings($form->toArray()); $ps->setMode(TPPaySettings::MODE_PPV); return $ps; }
function tinypass_display_card($rid, TPPaySettings $ps) { $tags = $ps->getPremiumTagsArray(); $all = array(); $count = 0; foreach ($tags as $name) { $td = get_term_by('name', $name, 'post_tag'); $count += $td->count; $td = get_term_by('name', $name, 'story_tag'); if ($td) { $count += $td->count; } } ?> <div class="paywall-card"> <div class="slider"> <form> <?php wp_nonce_field('enable_paywall', 'tinypass_nonce'); ?> <input type="hidden" name="tinypass[rid]" value="<?php echo $rid; ?> "> <?php echo tinypass_slider('tinypass[en]', array('Off' => '0', 'On' => '1'), $ps->getEnabled()); ?> </form> </div> <div class="type"> <?php echo "{$ps->getModeName()} ({$ps->getModeNameReal()}) "; ?> </div> <div class="title"> <?php echo $ps->getResourceName(); ?> </div> <div class="footer"> <div class="leftcol"> <div class="section"> <div class="label"><?php _e("Content"); ?> </div> <div class="value"><?php echo $count; ?> Items</div> </div> <div class="section"> <div class="label"><?php _e("Tags"); ?> </div> <div class="value"><?php _e($ps->getPremiumTags(',')); ?> </div> </div> <div class="section"> <div class="label"><?php _e("RID"); ?> </div> <div class="value"> <?php echo $ps->getResourceId(); ?> <a onclick="tinypass.showEditRIDPopup('<?php echo esc_js($ps->getResourceId()); ?> ');return false;"> <img class="edit-bundle"> </a> </div> </div> <div class="clear"></div> </div> <div class="action"> <a class="button" href="admin.php?page=TinyPassEditPaywall&rid=<?php echo $rid; ?> ">Edit</a> </div> <div class="clear"></div> </div> </div> <div id="tp-edit-rid-dialog" style="display:none"> <form method="post" action="" onsubmit="return false;"> <div class="info"> <p> This is the Resource ID (RID) to your paywall and all of its content. You can refer to it on your Tinypass publisher dashboard. </p> <p> <b>Warning:</b> Changing your ResourceID will result in paid users losing access to their content. </p> </div> <input type="hidden" id="rid" name="tinypass[rid]"> <input type="text" id="value" name="tinypass[value]"> <?php wp_nonce_field('update_rid', 'tinypass_nonce'); ?> <br> <br> <br> <div style="text-align: center"> <a class="button" onclick="tinypass.updateRID(this);return false;">Save</a> <a class="button" onclick="tinypass.closeEditRIDPopup();return false;">Cancel</a> </div> </form> </div> <?php }
/** * Display individual price option */ function __tinypass_price_option_display($opt, TPPaySettings $ps, $sub = true, $subWidth = 380) { $times = TPSiteSettings::$PERIOD_CHOICES; $enabled = 0; $default_price = ''; $default_access_period = ''; $default_access_period_type = ''; if ($opt == '1') { $default_price = '1'; $default_access_period = '1'; $default_access_period_type = 'day'; } $price = $ps->getPrice($opt, $default_price); $access_period = $ps->getAccessPeriod($opt, $default_access_period); $access_period_type = $ps->getAccessPeriodType($opt, $default_access_period_type); $caption = htmlspecialchars(stripslashes($ps->getCaption($opt))); $recur = "1 month" == $ps->getRecurring($opt); if ($opt == 1 || $ps->hasPriceConfig($opt)) { $enabled = 1; } $display = "display:none"; if ($opt == '1' || $enabled) { $display = ""; } ?> <table class="tinypass_price_options_form option_form option_form<?php echo $opt; ?> " style="<?php echo $display; ?> "> <tr> <td width="100"> <input type="hidden" id="<?php echo "po_en{$opt}"; ?> " name="tinypass[<?php echo "po_en{$opt}"; ?> ]" value="<?php echo $enabled; ?> "> <input type="text" size="8" maxlength="10" name="tinypass[<?php echo "po_p{$opt}"; ?> ]" value="<?php echo $price; ?> "> </td> <td width="<?php echo $subWidth; ?> "> <?php if ($sub) { ?> <input class="recurring-opts-off" opt="<?php echo $opt; ?> " type="radio" value="0" name="tinypass[po_recur<?php echo $opt; ?> ]" <?php echo checked($recur, false); ?> autocomplete="false"> <?php } ?> <input type="text" size="5" maxlength="5" name="tinypass[<?php echo "po_ap{$opt}"; ?> ]" value="<?php echo $access_period; ?> " class="po_ap_opts<?php echo $opt; ?> "> <?php echo __tinypass_dropdown("tinypass[po_ap_type{$opt}]", $times, $access_period_type, array('class' => "po_ap_opts{$opt}")); ?> <?php if ($sub) { ?> <span style="margin-left:30px"> </span> <input class="recurring-opts-on" id="<?php echo "po_recur{$opt}"; ?> " type="radio" name="tinypass[po_recur<?php echo $opt; ?> ]" value="1 month" <?php checked($recur); ?> opt="<?php echo $opt; ?> "> <label for="<?php echo "po_recur{$opt}"; ?> "><?php _e("Monthly Subscription"); ?> </label> <?php } ?> </td> <td width="270"> <input type="text" size="20" maxlength="20" name="tinypass[<?php echo "po_cap{$opt}"; ?> ]" value="<?php echo $caption; ?> "> </td> </tr> </table> <?php }
/** * Misc options display section */ function __tinypass_misc_display(TPPaySettings $ps) { ?> <div class="tp-section"> <div class="info"> <div class="heading">Customize</div> <div class="desc">Enable / disable these features of additional behavior</div> </div> <div class="body"> <div class="postbox"> <h3><?php echo _e(" "); ?> </h3> <div class="inside"> <input type="checkbox" id="cb_track_homepage" name="tinypass[mlite_track_homepage]" value="1" <?php echo checked($ps->isTrackHomePage()); ?> > <label for="cb_track_homepage"><?php echo _e("Track on home page visit - visiting your homepage will count as a view"); ?> </label> <br> <br> <input type="checkbox" id="cb_disabled_for_admins" name="tinypass[mlite_disabled_for_admins]" value="1" <?php echo checked($ps->isDisabledForPriviledgesUsers()); ?> > <label for="cb_disabled_for_admins"><?php echo _e("Disable Tinypass for privileges users - TinyPass will be skipped for all non Subscriber users"); ?> </label> </div> </div> </div> <div class="clear"></div> </div> <?php }
/** * This method performs nearly all of the TinyPass logic for when and how to protect content. * Based upon the TP configuration, the post, the tags this method will either permit access * to a post or it will truncate the content and show a 'purchase now' widget instead of the post content. * * Access is checked by retreiving an encrypted cookie that is stored after a successful purchase. * */ function tinypass_intercept_content($content) { global $tpstate; global $post; $tpstate->reset(); tinypass_include(); $ss = tinypass_load_settings(); //break out if Tinypass is disabled if ($ss->isEnabled() == false) { return $content; } $storage = new TPStorage(); $postOptions = $storage->getPostSettings($post->ID); $tagOptions = $storage->getPaywallByTag($ss, $post->ID); if ($tagOptions->isEnabled() == false) { $tagOptions = $storage->getPaywallSubRefID($ss, $post->ID); } TinyPass::$AID = $ss->getAID(); TinyPass::$PRIVATE_KEY = $ss->getSecretKey(); TinyPass::$SANDBOX = $ss->isSand(); //TinyPass::$API_ENDPOINT_DEV = 'http://tinydev.com:9000'; $store = new TPAccessTokenStore(); $store->loadTokensFromCookie($_COOKIE); //we want to dump the button on this page if ($tagOptions->getSubscriptionPageRef() == $post->ID) { $tagOffer = TPPaySettings::create_offer($tagOptions, $tagOptions->getResourceId()); $gotolink = get_page_link($tagOptions->getSubscriptionPageSuccessRef()); $req = new TPPurchaseRequest($tagOffer); $req->setCallback('tinypass_redirect'); $button1 = $req->generateTag(); $tpstate->add_scripts = true; if (preg_match('/\\[tinypass\\s+rid.*\\]/', $content)) { $content = preg_replace('/\\[tinypass\\srid+.*\\]/', $button1, $content); $button1 = ''; } else { $button1 = "<div id='tinypass_subscription_holder'>{$button1}</div>"; } return $content . $button1 . "<script>" . "var tp_goto = '{$gotolink}';" . "if(typeof tinypass_redirect != 'function') {\n\t\t\t\t\t\t\t\tfunction tinypass_redirect(status){\n\t\t\t\t\t\t\t\tif(status.state == 'granted'){\n\t\t\t\t\t\t\t\t\twindow.location = tp_goto;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(typeof tpOnPrepare != 'function') {\n\t\t\t\t\t\t\tfunction tpOnPrepare(status){\n\t\t\t\t\t\t\t\tif(status.state == 'granted'){\n\t\t\t\t\t\t\t\t\t//window.location = tp_goto;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}" . "</script>"; } //exit if everything is disabled if ($postOptions->isEnabled_20() == false && $tagOptions->isEnabled() == false) { return $content; } $tpstate->add_scripts = true; //When content is shown in list form, i.e. categories we still need to truncate content //At this point in the execution we know that TP is enabled so we have to protect if (is_singular() == false) { $c = get_extended_with_tpmore($content); if ($c['extended'] == '') { $content = tinypass_trim_excerpt($content); } else { $content = $c['main']; } return $content; } define('DONOTCACHEPAGE', true); define('DONOTCACHEDB', true); define('DONOTMINIFY', true); define('DONOTCDN', true); define('DONOTCACHCEOBJECT', true); $postOffer = null; $tagOffer = null; $postToken = null; $tagToken = null; if ($postOptions->isEnabled_20() && $ss->isPPPEnabled()) { $postOffer = TPPaySettings::create_offer($postOptions, "wp_post_" . strval($post->ID), $postOptions->getResourceName() == '' ? $post->post_title : $postOptions->getResourceName()); $postToken = $store->getAccessToken($postOffer->getResource()->getRID()); } $tagOfferTrialActive = FALSE; if ($tagOptions != null && $tagOptions->isEnabled()) { $tagOffer = TPPaySettings::create_offer($tagOptions, $tagOptions->getResourceId()); $tagToken = $store->findActiveToken('/' . $tagOptions->getResourceId() . '/'); } //For PPV mode if ($tagOptions->isMode(TPPaySettings::MODE_PPV) && $tagOptions->isEnabled()) { $rid = "wp_post_" . strval($post->ID); $tagOffer = TPPaySettings::create_offer($tagOptions, $rid, $post->post_title); //If a offer on the post is defined then use that one if ($postOffer != null) { $tagOffer = null; } $tagToken = $store->getAccessToken($rid); } else { if ($tagOptions->isMode(TPPaySettings::MODE_METERED) && $tagOptions->isEnabled()) { //Only check metered if the mode is metered and it is enabled $meter = null; if ($tagOptions->isMetered()) { $cookieName = "tr_" . substr(md5($tagOptions->getResourceId()), 0, 20); $meter = TPMeterHelper::loadMeterFromCookie($cookieName, $_COOKIE); $lockoutPeriod = $tagOptions->getMeterLockoutPeriodFull(); if ($meter == null) { $meter = TPMeterHelper::createViewBased($cookieName, $tagOptions->getMeterMaxAccessAttempts(), $lockoutPeriod); } $lockoutPeriodEndTime = time() + TPUtils::parseLoosePeriodInSecs($lockoutPeriod); $meter->increment(); setcookie($cookieName, TPMeterHelper::__generateLocalToken($cookieName, $meter), $lockoutPeriodEndTime, '/'); if ($meter->isTrialPeriodActive()) { $tagOfferTrialActive = TRUE; if ($tagOptions->isCounterEnabled() && $meter->getTrialViewCount() > $tagOptions->getCounterDelay(PHP_INT_MAX)) { $tpstate->show_counter = true; $onclick = 'onclick="return false"'; if ($tagOptions->isCounterOnClick(TPPaySettings::CT_ONCLICK_PAGE)) { $gotolink = get_page_link($tagOptions->getSubscriptionPageRef()); $onclick = 'href="' . $gotolink . '"'; } else { if ($tagOptions->isCounterOnClick(TPPaySettings::CT_ONCLICK_APPEAL)) { $onclick = 'onclick="tinypass.showAppeal(); return false"'; $tpstate->embed_appeal = __tinypass_create_appeal($tagOptions); } } $tpstate->counter = __tinypass_render_template(TINYPASS_COUNTER_TEMPLATE, array('count' => $meter->getTrialViewCount(), 'max' => $meter->getTrialViewLimit(), 'remaining' => $meter->getTrialViewLimit() - $meter->getTrialViewCount(), 'position' => 'position-' . $tagOptions->getCounterPosition(), 'onclick' => $onclick)); } if ($tagOptions->getAppealEnabled() && $meter != null) { $count = $meter->getTrialViewCount(); if ($count == $tagOptions->getAppealNumViews() || $count > $tagOptions->getAppealNumViews() && $count % $tagOptions->getAppealFrequency() == 0) { $tpstate->show_appeal = true; $tpstate->embed_appeal = __tinypass_create_appeal($tagOptions); } } return $content; } } } } if ($postOffer == null && $tagOffer == null) { return $content; } //If they already have access to the post if ($postToken != null && $postToken->isAccessGranted()) { return $content; } //If the tag level offer does not exist or access is already granted if ($tagToken != null && $tagToken->isAccessGranted() || $tagOfferTrialActive) { return $content; } $c = get_extended_with_tpmore($post->post_content); if ($c['extended'] == '') { //means there was no <!--more--> defined $content = tinypass_trim_excerpt($content); } else { $content = $c['main']; } if ($ss->isDisableCommentsWhenDenied()) { add_filter('comments_open', 'tinypass_close_comments', 1000); $post->comment_status = "closed"; add_filter('comments_template', 'tinypass_skip_comments'); } /* * Construct the offers for both the tag level offer and the post level offer if they exist */ $ticketoptions = array(); if ($postOffer) { $req = new TPPurchaseRequest($postOffer, $ticketoptions); $tpstate->post_req = array('req' => $req, 'message1' => $postOptions->getDeniedMessage1("") != "" ? $postOptions->getDeniedMessage1() : $ss->getDeniedMessage1(), 'sub1' => $postOptions->getDeniedSub1("") != "" ? $postOptions->getDeniedSub1() : $ss->getDeniedSub1()); $req->setCallback('tinypass_reloader'); } if ($tagOffer) { $req2 = new TPPurchaseRequest($tagOffer, $ticketoptions); $tpstate->tag_req = array('req' => $req2, 'message1' => $tagOptions->getDeniedMessage1(), 'sub1' => $tagOptions->getDeniedSub1()); $req2->setCallback('tinypass_reloader'); } //Switch the offer order if selected in the settings if ($tagOptions->isPostFirstInOrder() == false) { $temp = $tpstate->post_req; $tpstate->post_req = $tpstate->tag_req; $tpstate->tag_req = $temp; } return $content; }
public function removePaywall(TPPaySettings $ps) { $rid = $ps->getResourceId(); $pws = $this->data[self::PAYWALLS]; if ($pws) { foreach ($pws as $i => $value) { if ($value == $rid) { unset($pws[$i]); } } } $this->data[self::PAYWALLS] = $pws; }