Skip to content

Commit

Permalink
merged latest version with SLP plugin support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekliptor authored and Ekliptor committed Mar 17, 2020
1 parent 69e14a3 commit 7c5b19f
Show file tree
Hide file tree
Showing 28 changed files with 122,264 additions and 30 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.13
* Version: 1.1.17
* Author: Ekliptor
* Author URI: https://twitter.com/ekliptor
* License: GPLv3
Expand All @@ -18,7 +18,7 @@
exit ();
}

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

Expand Down
24 changes: 22 additions & 2 deletions classes/Cashtippr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,18 @@ public function setIncludedMoneybuttonScript(bool $included) {
$this->includedMoneybuttonScript = $included;
}

public function getIncludedQrCodeTemplate() {
return $this->includedQrCodeTemplate;
}

public function setIncludedQrCodeTemplate(bool $included) {
$this->includedQrCodeTemplate = $included;
}

public function getSessionID(): string {
return session_id(); // ID or empty string
}

/**
* Generate a QR code for the payment
* @param string $txid The internal MySQL transaction ID (not the on-chain TXID).
Expand Down Expand Up @@ -581,7 +593,7 @@ public function restrictPostText(string $content) {
}

public function addFooterCode() {
$cfg = array(
$cfg = $this->getPluginJsConfigData(array(
'cookieLifeDays' => ceil(static::SESSION_LIFETIME_SEC / DAY_IN_SECONDS),
'cookiePath' => $this->siteUrlParts['path'],
'siteUrl' => $this->getSiteUrl(),
Expand All @@ -599,7 +611,7 @@ public function addFooterCode() {
'tipAmount' => $this->getTipAmount(),
// TODO move localized strings into a separate .js file generated from PHP if we have more strings
'badgerLocked' => __('Your BadgerWallet is locked. Please open it in your browser toolbar and enter your password before sending money.', 'ekliptor'),
);
));
if ($this->settings->get('show_cookie_consent') === true && !isset($_COOKIE[static::CONSENT_COOKIE_NAME])) {
// TODO add option to only show this to specific countries
// from get_the_privacy_policy_link()
Expand All @@ -623,6 +635,14 @@ public function addPluginScripts() {
wp_enqueue_script( 'cashtippr-bundle', plugins_url( 'tpl/js/bundle.js', CASHTIPPR__PLUGIN_DIR . 'cashtippr.php' ), array(), CASHTIPPR_VERSION, true );
}

public function getPluginJsConfigData(array $existingConfig = array()): array {
return array_merge($existingConfig, array(
'cookieLifeDays' => ceil(static::SESSION_LIFETIME_SEC / DAY_IN_SECONDS),
'cookiePath' => $this->siteUrlParts['path'],
'siteUrl' => $this->getSiteUrl(),
));
}

public function getSettings(): CTIP_Settings {
return $this->settings;
}
Expand Down
11 changes: 10 additions & 1 deletion classes/CashtipprAdmin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function init() {
//add_action( 'admin_init', array( $this, 'loadAssets' ) ); // done after screen setup
add_action( 'admin_init', array( $this, 'displayAdminNotices' ) );
add_action( 'admin_init', array( $this, 'addPrivacyPolicyContent' ) );
add_action('admin_footer', array($this, 'addAdminJavascript'));

add_filter('removable_query_args', array($this, 'addRemovableAdminArgs'));
add_filter('cashtippr_settings_change_xPub', array($this, 'onUpdateXpub'), 10, 4);
Expand Down Expand Up @@ -133,6 +134,12 @@ public function loadAssets() {
add_action( "load-{$this->pageHook}", array( $this, 'addMetaboxScripts' ) );
}

public function addAdminJavascript() {
$cfg = $this->cashtippr->getPluginJsConfigData();
$cfg = apply_filters('cashtippr_admin_js_config', $cfg);
echo '<script type="text/javascript">var cashtipprAdminCfg = ' . json_encode($cfg) . ';</script>';
}

public function addMetaboxScripts() {
wp_enqueue_script( 'common' );
wp_enqueue_script( 'wp-lists' );
Expand Down Expand Up @@ -181,7 +188,9 @@ public function addMetaBoxes(string $post_type/*, WP_Post $post*/) {
$pluginBoxes = array(
'BlurryImage' => false,
'Shout' => false,
'Woocommerce' => false
'SlpPress' => false,
'Woocommerce' => false,
'SlpPayments' => defined('BCHSLP_PAYMENTS_VERSION') === true // faster than get_option('slp_payments_installed')
);
$pluginBoxes = apply_filters('cashtippr_admin_metaboxes', $pluginBoxes, $post_type); // allows plugins to add metaboxes
if ($this->pageHook === static::PAGE_HOOK && $this->allPluginsEnabled($pluginBoxes) === false) { // advertise our plugin addons
Expand Down
9 changes: 9 additions & 0 deletions classes/Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function sanitizeByType($defaultValue) {
case 'integer': return array($this, 'formatInteger');
case 'double': return array($this, 'formatFloat'); // float
case 'string': return array($this, 'formatString');
case 'array': return array($this, 'formatArray');
}
return array($this, 'formatUnknown'); // shouldn't be reached since array, object,... can not be passed in via HTML forms
}
Expand Down Expand Up @@ -81,6 +82,14 @@ public function formatUnknown($newValue, string $settingName) {
return sanitize_text_field($newValue);
}

public function formatArray($newValue, string $settingName) {
// cashtippr_settings[slp_press_pages][] becomes a numeric PHP array with values of select options
// we don't pass along if array values are supposed to be numbers or strings, so assume strings
for ($i = 0; $i < count($newValue); $i++)
$newValue[$i] = sanitize_text_field($newValue[$i]);
return $newValue;
}

/**
* Sanitize a user input of html via text/textarea input. This will also keep <script> tags.
* @param string $html
Expand Down
42 changes: 42 additions & 0 deletions classes/Settings.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ public function sanitize($settings) {
// meta parameter one level above the registered cashtippr_settings array
$allCheckboxes = isset($_POST['all_checkboxes']) ? explode(',', sanitize_text_field($_POST['all_checkboxes'])) : array();
$allCheckboxes = array_flip($allCheckboxes);
$allMultiselect = isset($_POST['all_multiselect']) ? explode(',', sanitize_text_field($_POST['all_multiselect'])) : array();
$allMultiselect = array_flip($allMultiselect);
// sanitize & add missing keys
foreach ($defaults as $key => $value) {
if (!isset($settings[$key])) {
if (isset($allCheckboxes[$key]))
$settings[$key] = false; // unchecked checkboxes are not present in html forms , so do this BEFORE falling back to prev setting
else if (isset($allMultiselect[$key]))
$settings[$key] = array();
else if (isset($allSettings[$key]))
$settings[$key] = $allSettings[$key]; // keep the previous value
else
Expand Down Expand Up @@ -537,6 +541,41 @@ protected function getDefaultSiteOptions($onUpdate = false) {
'shout_update_nonce' => Cashtippr::getRandomString(20),
'shout_last_update_check' => time(),

// SLP Press
// Wallet
'admin_wallet' => '',
'admin_bch_wallet' => '',
'passphrase' => '',
// Distribution
'token_reward_amount' => 10,
'min_read_time_sec' => 40,
'token_reward_interval_h' => 18,
'vip_reader_days' => 7,
'token_reward_amount_vip' => 20,
'enable_slp_press_on_woocommerce' => true,
'enable_specific_pages' => false,
'slp_press_pages' => array(), // numeric page IDs as values
'enable_specific_posts' => false,
'slp_press_posts' => array(), // numeric post IDs as values
'token_payout_interval_days' => 1,
'token_last_payout_time' => 0, // unix timestamp, set to current time on first install
'hash_user_ips' => true,
// Community
'show_token_amount_comments' => true,
//'send_token_users' => true, // TODO
// token config
'token_reward_id' => '',
'token_reward_ticker' => '',
'token_reward_name' => '',
'token_reward_icon' => '',
'token_reward_website' => '',
'slp_press_admin_token' => '',
'slp_distribute_nonce' => '',
// stats
'pending_payouts' => 0,
'slp_press_update_nonce' => Cashtippr::getRandomString(20),
'slp_press_last_update_check' => time(),

// Woocommerce
'blockchain_api' => 'BitcoinComRestApi',
'wait_confirmations' => 3,
Expand All @@ -548,6 +587,9 @@ protected function getDefaultSiteOptions($onUpdate = false) {
'skipUsedAddressCount' => 10,
'addressCount' => 0,
'lastAddress' => '', // used for debugging

// Addons
'lastOrderID' => 0,
);
$defaults = apply_filters('cashtippr_default_settings', $defaults);
if ($onUpdate === true) { // html form checkboxes are not present when false, so assume false for all on update
Expand Down
Loading

0 comments on commit 7c5b19f

Please sign in to comment.