Skip to content

Commit

Permalink
added adblock detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekliptor authored and Ekliptor committed Nov 11, 2019
1 parent 2a3101f commit 69e14a3
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 32 deletions.
4 changes: 2 additions & 2 deletions cashtippr.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: CashTippr: Bitcoin Cash instant tips & payments for your content
* Plugin URI: https://cashtippr.com/
* Description: Earn money for your content using instant Bitcoin Cash tips (0 conf).
* Version: 1.1.11
* Version: 1.1.13
* Author: Ekliptor
* Author URI: https://twitter.com/ekliptor
* License: GPLv3
Expand All @@ -18,7 +18,7 @@
exit ();
}

define ( 'CASHTIPPR_VERSION', '1.1.11' );
define ( 'CASHTIPPR_VERSION', '1.1.13' );
define ( 'CASHTIPPR__MINIMUM_WP_VERSION', '4.7' );
define ( 'CASHTIPPR__PLUGIN_DIR', plugin_dir_path ( __FILE__ ) );

Expand Down
20 changes: 17 additions & 3 deletions classes/Cashtippr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Cashtippr {
private static $cron_events_hourly = array(
'update_currency_rates'
);
/** @var \WC_Log_Handler_File */
protected static $logger = null;

/** @var CTIP_Settings */
protected $settings;
Expand All @@ -60,6 +62,8 @@ class Cashtippr {
protected $hiddenWords = 0;
/** @var bool */
protected $includedMoneybuttonScript = false;
/** @var bool */
protected $includedQrCodeTemplate = false;
/** @var string */
protected $qrcodeStatic;
/** @var string */
Expand All @@ -68,7 +72,7 @@ class Cashtippr {
protected $loadingImage;

private function __construct() {
$this->qrcodeStatic = plugins_url( 'img/qrcode.svg', CASHTIPPR__PLUGIN_DIR . 'cashtippr.php' );
$this->qrcodeStatic = plugins_url( 'img/qrstatic.png', CASHTIPPR__PLUGIN_DIR . 'cashtippr.php' );
$this->closeImage = plugins_url( 'img/close50.png', CASHTIPPR__PLUGIN_DIR . 'cashtippr.php' );
$this->loadingImage = plugins_url( 'img/loading.gif', CASHTIPPR__PLUGIN_DIR . 'cashtippr.php' );
}
Expand Down Expand Up @@ -338,7 +342,7 @@ public function generateQrCodeForAddress(string $txid, string $address, float $a
$qrHash = hash('sha512', $txid);
$fileName = sprintf('data/temp/qr/%s.png', $qrHash);
$fileLocal = CASHTIPPR__PLUGIN_DIR . $fileName;
$fileUrl = plugins_url( $fileName, CASHTIPPR__PLUGIN_DIR . 'slp-payments.php' );
$fileUrl = plugins_url( $fileName, CASHTIPPR__PLUGIN_DIR . 'cashtippr.php' );
if (file_exists($fileLocal) === true)
return $fileUrl; // use it from cache

Expand All @@ -359,7 +363,7 @@ public function generateQrCode(string $txid): string {
$qrHash = hash('sha512', $txid);
$fileName = sprintf('data/temp/qr/%s.png', $qrHash);
$fileLocal = CASHTIPPR__PLUGIN_DIR . $fileName;
$fileUrl = plugins_url( $fileName, CASHTIPPR__PLUGIN_DIR . 'slp-payments.php' );
$fileUrl = plugins_url( $fileName, CASHTIPPR__PLUGIN_DIR . 'cashtippr.php' );
if (file_exists($fileLocal) === true)
return $fileUrl; // use it from cache

Expand Down Expand Up @@ -426,6 +430,7 @@ public function showTipprButton($attrs, $content = null, $tag = "") {
$btnConf['addQrCode'] = $btnConf['isRestricted'] === false && $btnConf['tag'] === 'tippr_button' && $btnConf['unit'] === 'USD'; // TODO QR code support for more currencies
$btnConf['btnText'] = __('Send', 'ekliptor');
$includedMoneybuttonScript = $this->getIncludedMoneybuttonScript();
$includedQrCodeTemplate = $this->includedQrCodeTemplate;
ob_start();
switch ($tag) {
case "tippr_button":
Expand Down Expand Up @@ -480,6 +485,7 @@ public function showTipprButton($attrs, $content = null, $tag = "") {
ob_end_clean();
//$this->setIncludedMoneybuttonScript($includedMoneybuttonScript);
$this->setIncludedMoneybuttonScript(true);
$this->includedQrCodeTemplate = $includedQrCodeTemplate;
wp_enqueue_script( 'badger-wallet', Cashtippr::BADGER_WALLET_JS, array(), CASHTIPPR_VERSION, true );
return $docHtml;
}
Expand Down Expand Up @@ -729,6 +735,14 @@ public function notifyError($subject, $error, $data = null) {

public static function notifyErrorExt($subject, $error, $data = null) {
global $wpdb;
if (defined('WC_LOG_DIR') === true) {
if (static::$logger === null)
static::$logger = new \WC_Log_Handler_File();
$logMsg = $subject . "\r\n" . print_r($error, true);
if ($data !== null)
$logMsg .= "\r\n" . print_r($data, true);
static::$logger->handle(time(), 'error', $logMsg, array('source' => 'cashtippr'));
}
if (static::DEBUG === false)
return;
$table = static::getTableName("messages_system");
Expand Down
2 changes: 2 additions & 0 deletions classes/CashtipprAdmin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public function showAllSettings() {

public function initCurrentScreen(WP_Screen $screen) {
// id: [id] => toplevel_page_cashtippr or cashtippr_page_cashtippr_shout <- this is always the hook
if (strpos($screen->base, 'cashtippr') === false)
return;
$this->pageHook = $screen->base;

add_action( $this->pageHook . '_settings_page_boxes', array( $this, 'showAllSettings' ) );
Expand Down
29 changes: 18 additions & 11 deletions classes/DatabaseMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace Ekliptor\Cashtippr;

class DatabaseMigration {
/** @var string */
/** @var string Latest DB version. Only updated with plugin version if there are migrations. */
protected $lastVersion;
/** @var string */
protected $currentVersion;
Expand All @@ -11,23 +11,28 @@ class DatabaseMigration {

public function __construct(string $lastVersion, string $currentVersion) {
if (!$lastVersion)
$lastVersion = '1';
$lastVersion = '1'; // when we added migration. shouldn't be needed
$this->lastVersion = $lastVersion;
$this->currentVersion = $currentVersion;
}

public static function checkAndMigrate() {
add_action('plugins_loaded', function() {
$lastVersion = get_option('cashtippr_version');
if ($lastVersion === CASHTIPPR_VERSION)
return;
$lastVersion = get_option('cashtippr_version');
if ($lastVersion === CASHTIPPR_VERSION)
return;
add_action('plugins_loaded', function() use ($lastVersion) {
$migrate = new DatabaseMigration($lastVersion, CASHTIPPR_VERSION);
if ($migrate->ensureLatestVersion() === false) { // TODO can be switched to migrate() call just like in plugin_activcation()
\Cashtippr::notifyErrorExt("Error ensuring latest DB version on migration", $migrate->getLastError());
return;
try {
if ($migrate->migrate() === false) {
\Cashtippr::notifyErrorExt("Error ensuring latest DB version on migration", $migrate->getLastError());
return;
}
update_option( 'cashtippr_version', CASHTIPPR_VERSION ); // should already be done in main plugin class
}
catch (\Exception $e) {
\Cashtippr::notifyErrorExt("Exception during DB migration: " . get_class(), $e->getMessage());
}
update_option ( 'cashtippr_version', CASHTIPPR_VERSION );
});
}, 200); // load after other plugins
}

public function migrate(): bool {
Expand All @@ -52,6 +57,7 @@ public function migrate(): bool {
/**
* Fix function if migrate() didn't work on some instances previously.
*/
/*
public function ensureLatestVersion(): bool {
$table = \Cashtippr::getTableName('transactions');
if ($this->columnExists($table, 'amount') === false) {
Expand All @@ -60,6 +66,7 @@ public function ensureLatestVersion(): bool {
}
return true;
}
*/

public function getLastError(): array {
return $this->lastError;
Expand Down
3 changes: 0 additions & 3 deletions img/qrcode.svg

This file was deleted.

5 changes: 3 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: ekliptor
Tags: bitcoin, bch, ecommerce, e-commerce, blog, tipping, store, sales, sell, shop, bitcoin cash, btc
Donate link: https://cashtippr.com/
Requires at least: 4.7
Tested up to: 5.2
Tested up to: 5.3
Requires PHP: 7.1
Stable tag: 1.1.11
Stable tag: 1.1.13
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -20,6 +20,7 @@ Earn money for your content using instant Bitcoin Cash tips (0 conf).
* earn tips from your content
* add tip buttons for voluntary donations or
* hide parts of your posts to require users to tip
* AdBlock detection: show custom message to AdBlock users
* 0 coding skills required

Check the demo at [CashTippr.com](https://cashtippr.com/ "CashtTippr") and send me a tip to support development.
Expand Down
2 changes: 1 addition & 1 deletion tpl/admin/metaboxAds.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
),
$this->makeCheckbox(
'adblockDisable',
esc_html__( 'Disable page for AdBlock users', 'ekliptor' ) . ' ' . $adblockDisableInfo,
esc_html__( 'Disable page for AdBlock users with 0 tips', 'ekliptor' ) . ' ' . $adblockDisableInfo,
'',
false
),
Expand Down
7 changes: 7 additions & 0 deletions tpl/css/cashtippr.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
.ct-button-text {
font-weight: bold;
}
.ct-qrcode-img-wrap {
line-height: 1.0;
padding-right: 5px;
}
.ct-qr-btn-txt {
padding-left: 4px;
}

.money-button-iframe-wrapper {
}
Expand Down
2 changes: 1 addition & 1 deletion tpl/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tpl/js/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tpl/js/src/QrCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class QrCode extends AbstractModule {
// ###################### PRIVATE FUNCTIONS #######################

protected showQrDialog(target: Element) {
const paymentButtonWrapper = this.cashtippr.$(target).parent().parent().parent();
const paymentButtonWrapper = this.cashtippr.$(target).parent().parent().parent().parent();
const txid = this.cashtippr.getPluginPaymentID(paymentButtonWrapper);
const paymentCtrlWrapper = paymentButtonWrapper.parent();
let amount = 0.0;
Expand Down
12 changes: 10 additions & 2 deletions tpl/js/src/Woocommerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {AbstractModule} from "./AbstractModule";
* Class to interact with the Woocommerce store of a WordPress installation.
*/
export class Woocommerce extends AbstractModule {
protected fullyPaid: boolean = false;
protected checkServerPaymentTimerID: number = 0;

constructor(cashtippr: CashTippr, webHelpers: WebHelpers) {
super(cashtippr, webHelpers);
Expand Down Expand Up @@ -58,8 +60,10 @@ export class Woocommerce extends AbstractModule {
oid: config.orderID
}
this.webHelpers.getApi("/wp-json/cashtippr-wc/v1/order-status", params, (data) => {
if (config.checkPaymentIntervalSec > 0) // TODO abort checking after x minutes?
setTimeout(this.checkPaymentStatus.bind(this, true), config.checkPaymentIntervalSec*1000); // always repeat the check even if there was an error
if (repeat === true && config.checkPaymentIntervalSec > 0) { // TODO abort checking after x minutes?
clearTimeout(this.checkServerPaymentTimerID); // ensure we don't have multiple timers running
this.checkServerPaymentTimerID = setTimeout(this.checkPaymentStatus.bind(this, true), config.checkPaymentIntervalSec * 1000); // always repeat the check even if there was an error
}
if (data.error === true) {
this.cashtippr.window.console.error("Error checking BCH payment status: %s", data.errorMsg);
return;
Expand Down Expand Up @@ -94,6 +98,10 @@ export class Woocommerce extends AbstractModule {
}

protected showPaymentReceived() {
if (this.fullyPaid === true)
return; // already updated
this.fullyPaid = true;
clearTimeout(this.checkServerPaymentTimerID);
this.cashtippr.$("#ct-payment-status").text(this.cashtippr.getConfig().paidTxt);
this.cashtippr.$("#ct-payment-pending, #ct-pay-instructions, .ct-payment-option").fadeOut("slow");
}
Expand Down
1 change: 0 additions & 1 deletion tpl/js/src/admin/Tooltips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {AbstractModule} from "../AbstractModule";
import {WebHelpers} from "../WebHelpers";

export class Tooltips extends AbstractModule {
protected cashtippr: CashTippr;

constructor(cashtippr: CashTippr, webHelpers: WebHelpers) {
super(cashtippr, webHelpers);
Expand Down
11 changes: 7 additions & 4 deletions tpl/moneybuttonCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<?php if($btnConf['addQrCode'] === true && !isset($btnConf['noQrButton'])):?>
<div class="ct-qrcode-wrap">
<a class="ct-qrcode-btn" href="javascript:;">
<img src="<?php echo esc_attr($btnConf['qrcodeStatic']);?>" width="70" height="70" alt="<?php esc_attr_e('Tip with QR Code', 'ekliptor');?>" title="<?php esc_attr_e('Tip with QR Code', 'ekliptor');?>">
<div class="ct-qrcode-img-wrap">
<img src="<?php echo esc_attr($btnConf['qrcodeStatic']);?>" width="50" height="50" alt="<?php esc_attr_e('Click to tip with QR Code', 'ekliptor');?>" title="<?php esc_attr_e('Click to tip with QR Code', 'ekliptor');?>">
<div class="ct-qr-btn-txt"><?php esc_html_e('Click', 'ekliptor');?></div>
</div>
</a>
</div>
<?php endif;?>
Expand All @@ -19,10 +22,10 @@ class="ct-badger-button button"
><?php echo esc_html($btnConf['btnText']);?> <span class="ct-btn-display-amount"><?php echo $btnConf['amount'];?></span> <?php echo $btnConf['unit'];?></button>
</div>
</div>
<?php if($btnConf['addQrCode'] === true && $includedQrCodeTemplate === false): $includedQrCodeTemplate = true;?>
<?php include CASHTIPPR__PLUGIN_DIR . 'tpl/client/qrcode.php';?>
<?php endif;?>
<?php if ($includedMoneybuttonScript === false): $includedMoneybuttonScript = true;?>
<?php if($btnConf['addQrCode'] === true):?>
<?php include CASHTIPPR__PLUGIN_DIR . 'tpl/client/qrcode.php';?>
<?php endif;?>
<script type="text/javascript">
function onBadgerPaymentG_<?php echo $btnConf['txid'];?>(txid) {
window.onBadgerPayment({
Expand Down

0 comments on commit 69e14a3

Please sign in to comment.