From c3232bcce63cd3b78d4f615049181188532bc278 Mon Sep 17 00:00:00 2001 From: Vlado Bosnjak Date: Sat, 18 Feb 2023 16:21:45 +0700 Subject: [PATCH 1/6] Enable overriding template for unpaid button from theme folder --- composer.lock | 75 +++++++++++----------- includes/class-bln-publisher-paywall.php | 43 +++++++++++-- public/templates/paywall-button-unpaid.php | 30 +++++++++ 3 files changed, 105 insertions(+), 43 deletions(-) create mode 100644 public/templates/paywall-button-unpaid.php diff --git a/composer.lock b/composer.lock index d1efedb..cc6116a 100644 --- a/composer.lock +++ b/composer.lock @@ -106,12 +106,12 @@ "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9" + "reference": "fa1ec24f0ab1efe642671ec15c51a3ab879f59bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/3953f23262f2bff1919fc82183ad9acb13ff62c9", - "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9", + "url": "https://api.github.com/repos/composer/semver/zipball/fa1ec24f0ab1efe642671ec15c51a3ab879f59bf", + "reference": "fa1ec24f0ab1efe642671ec15c51a3ab879f59bf", "shasum": "" }, "require": { @@ -162,9 +162,9 @@ "versioning" ], "support": { - "irc": "irc://irc.freenode.org/composer", + "irc": "ircs://irc.libera.chat:6697/composer", "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/3.3.2" + "source": "https://github.com/composer/semver/tree/main" }, "funding": [ { @@ -180,28 +180,28 @@ "type": "tidelift" } ], - "time": "2022-04-01T19:23:25+00:00" + "time": "2023-01-13T15:47:53+00:00" }, { "name": "fgrosse/phpasn1", - "version": "v2.4.0", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/fgrosse/PHPASN1.git", - "reference": "eef488991d53e58e60c9554b09b1201ca5ba9296" + "reference": "42060ed45344789fb9f21f9f1864fc47b9e3507b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fgrosse/PHPASN1/zipball/eef488991d53e58e60c9554b09b1201ca5ba9296", - "reference": "eef488991d53e58e60c9554b09b1201ca5ba9296", + "url": "https://api.github.com/repos/fgrosse/PHPASN1/zipball/42060ed45344789fb9f21f9f1864fc47b9e3507b", + "reference": "42060ed45344789fb9f21f9f1864fc47b9e3507b", "shasum": "" }, "require": { - "php": "~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0" + "php": "^7.1 || ^8.0" }, "require-dev": { "php-coveralls/php-coveralls": "~2.0", - "phpunit/phpunit": "^6.3 || ^7.0 || ^8.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "suggest": { "ext-bcmath": "BCmath is the fallback extension for big integer calculations", @@ -253,9 +253,10 @@ ], "support": { "issues": "https://github.com/fgrosse/PHPASN1/issues", - "source": "https://github.com/fgrosse/PHPASN1/tree/v2.4.0" + "source": "https://github.com/fgrosse/PHPASN1/tree/v2.5.0" }, - "time": "2021-12-11T12:41:06+00:00" + "abandoned": true, + "time": "2022-12-19T11:08:26+00:00" }, { "name": "firebase/php-jwt", @@ -263,12 +264,12 @@ "source": { "type": "git", "url": "https://github.com/firebase/php-jwt.git", - "reference": "bad1b040d0c736bbf86814c6b5ae614f517cf7bd" + "reference": "3b454f90f147db65a615041dec6661f427d6cb00" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/firebase/php-jwt/zipball/bad1b040d0c736bbf86814c6b5ae614f517cf7bd", - "reference": "bad1b040d0c736bbf86814c6b5ae614f517cf7bd", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/3b454f90f147db65a615041dec6661f427d6cb00", + "reference": "3b454f90f147db65a615041dec6661f427d6cb00", "shasum": "" }, "require": { @@ -283,6 +284,7 @@ "psr/http-factory": "^1.0" }, "suggest": { + "ext-sodium": "Support EdDSA (Ed25519) signatures", "paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present" }, "default-branch": true, @@ -318,7 +320,7 @@ "issues": "https://github.com/firebase/php-jwt/issues", "source": "https://github.com/firebase/php-jwt/tree/main" }, - "time": "2022-11-01T21:24:10+00:00" + "time": "2023-02-13T12:51:14+00:00" }, { "name": "guzzlehttp/guzzle", @@ -540,12 +542,12 @@ "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "67c26b443f348a51926030c83481b85718457d3d" + "reference": "58d0734481de3fbc62f3d13da4d991e051521282" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/67c26b443f348a51926030c83481b85718457d3d", - "reference": "67c26b443f348a51926030c83481b85718457d3d", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/58d0734481de3fbc62f3d13da4d991e051521282", + "reference": "58d0734481de3fbc62f3d13da4d991e051521282", "shasum": "" }, "require": { @@ -636,7 +638,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.4.3" + "source": "https://github.com/guzzle/psr7/tree/master" }, "funding": [ { @@ -652,7 +654,7 @@ "type": "tidelift" } ], - "time": "2022-10-26T14:07:24+00:00" + "time": "2023-02-15T13:59:53+00:00" }, { "name": "jorijn/bitcoin-bolt11", @@ -1340,26 +1342,25 @@ }, { "name": "symfony/deprecation-contracts", - "version": "dev-main", + "version": "3.0.x-dev", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "4912000e79dc2d6df029d35d8755be1ed79b6691" + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/4912000e79dc2d6df029d35d8755be1ed79b6691", - "reference": "4912000e79dc2d6df029d35d8755be1ed79b6691", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", "shasum": "" }, "require": { - "php": ">=8.1" + "php": ">=8.0.2" }, - "default-branch": true, "type": "library", "extra": { "branch-alias": { - "dev-main": "3.2-dev" + "dev-main": "3.0-dev" }, "thanks": { "name": "symfony/contracts", @@ -1388,7 +1389,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/main" + "source": "https://github.com/symfony/deprecation-contracts/tree/3.0" }, "funding": [ { @@ -1404,7 +1405,7 @@ "type": "tidelift" } ], - "time": "2022-05-20T13:56:22+00:00" + "time": "2022-01-02T09:55:41+00:00" }, { "name": "tkijewski/php-lnurl", @@ -1412,12 +1413,12 @@ "source": { "type": "git", "url": "https://github.com/tkijewski/php-lnurl.git", - "reference": "c5b34d45235f1d244a0d48d071975390f7cf2244" + "reference": "7007e8e26b3b3527f19446feaae9d6e4b602f8f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tkijewski/php-lnurl/zipball/c5b34d45235f1d244a0d48d071975390f7cf2244", - "reference": "c5b34d45235f1d244a0d48d071975390f7cf2244", + "url": "https://api.github.com/repos/tkijewski/php-lnurl/zipball/7007e8e26b3b3527f19446feaae9d6e4b602f8f8", + "reference": "7007e8e26b3b3527f19446feaae9d6e4b602f8f8", "shasum": "" }, "require": { @@ -1457,7 +1458,7 @@ "source": "https://github.com/tkijewski/php-lnurl/tree/master", "issues": "https://github.com/tkijewski/php-lnurl/issues" }, - "time": "2022-08-05T00:02:39+00:00" + "time": "2023-01-13T17:14:49+00:00" } ], "packages-dev": [], @@ -1476,5 +1477,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.3.0" } diff --git a/includes/class-bln-publisher-paywall.php b/includes/class-bln-publisher-paywall.php index e2c5f6e..69af607 100644 --- a/includes/class-bln-publisher-paywall.php +++ b/includes/class-bln-publisher-paywall.php @@ -282,13 +282,44 @@ protected function format_paid() */ protected function format_unpaid() { - - $button = sprintf('', $this->format_label($this->options['button_text'])); - $description = ''; - if (!empty($this->options['description'])) { - $description = sprintf('

%s

', $this->format_label($this->options['description'])); + $template_default = BLN_PUBLISHER_ROOT_PATH . '/public/templates/paywall-button-unpaid.php'; + $template_override = get_stylesheet_directory() . '/lightning-publisher-wordpress/paywall-button-unpaid.php'; + + // Use template from theme folder + if ( file_exists($template_override) ) + { + $template = $template_override; + } + // Use default template from plugin folder + else + { + $template = $template_default; } - return sprintf('%s
%s%s
', $this->teaser, $this->post_id, $description, $button); + + + + /** + * Allow template override with the hook + * + * @param $template string Absolute path to template file + * @param $this object Plugin instance + */ + $template = apply_filters( 'bln_paywall_unpaid_button_template', $template, $this ); + + error_log( print_r( $template, true ) ); + //error_log( print_r( file_exists($template_override), true ) ); + + ob_start(); + + // Class instance with all plugin data + $plugin = $this; + + // Load template file + include_once $template; + + $return = ob_get_clean(); + + return $return; } /** diff --git a/public/templates/paywall-button-unpaid.php b/public/templates/paywall-button-unpaid.php new file mode 100644 index 0000000..0a8ffee --- /dev/null +++ b/public/templates/paywall-button-unpaid.php @@ -0,0 +1,30 @@ +%s', + $plugin->format_label($plugin->options['button_text']) +); + + +$description = ''; + +if (!empty($plugin->options['description'])) +{ + $description = sprintf( + '

%s

', + $plugin->format_label($plugin->options['description']) + ); +} + +printf( + '%s
%s%s
', + $plugin->teaser, + $plugin->post_id, + $description, + $button +); \ No newline at end of file From 6c25353b5a0e83c393f4184faab376079293ad3f Mon Sep 17 00:00:00 2001 From: Vlado Bosnjak Date: Sat, 6 May 2023 19:23:56 +0700 Subject: [PATCH 2/6] - filter fix, passing $plugin instance as argument doesn't work. - updated readme file with example how to override default template --- README.md | 169 +++++++++++++-------- includes/class-bln-publisher-paywall.php | 5 +- public/templates/paywall-button-unpaid.php | 2 - 3 files changed, 104 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index a9568bb..baeb18e 100755 --- a/README.md +++ b/README.md @@ -8,58 +8,58 @@ It allows you to monetize any digital content with instant microtransactions and The plugin is the easiest and most flexible plugin to sell your digital content and to receive donations or Value 4 Value payments. Using the Bitcoin Lightning Network you can create the best visitor experience with seamless one-click payments. - ### Features #### Paywall to sell content -Sell any digital content (pay-per-post, pay-per-view, pay-per-download, etc.) with a highly configurable paywall -* [WebLN enabled](https://www.webln.guide/) by default for easy on-click payments -* Add a paywall to posts and pages to easily charge for any published content -* Crowdfund option: make the content freely available after a certain amount is received -* Time-in option: keep the article freely available for a certain time and then enable the paywall after that -* Time-out option: make the article freely available after a certain time -* Configure the price in Satoshis, EUR, USD, or GBP (with real-time exchange rate) -* Configure the paywall with a shortcode (`[lnpaywall]`) -* Or configure the paywall with a Gutenberg Block -* Integrate with other tools and plugins like membership tools to control if the paywall should be enabled (see Paywall Hook section) +Sell any digital content (pay-per-post, pay-per-view, pay-per-download, etc.) with a highly configurable paywall +- [WebLN enabled](https://www.webln.guide/) by default for easy on-click payments +- Add a paywall to posts and pages to easily charge for any published content +- Crowdfund option: make the content freely available after a certain amount is received +- Time-in option: keep the article freely available for a certain time and then enable the paywall after that +- Time-out option: make the article freely available after a certain time +- Configure the price in Satoshis, EUR, USD, or GBP (with real-time exchange rate) +- Configure the paywall with a shortcode (`[lnpaywall]`) +- Or configure the paywall with a Gutenberg Block +- Integrate with other tools and plugins like membership tools to control if the paywall should be enabled (see Paywall Hook section) #### Donation/Value4Value payments -The plugin comes with various options to receive donations and [Value 4 Value payments](https://blog.getalby.com/the-case-for-value-4-value/). -* Gutenberg block for a donation widget -* Donation widget for themes -* Enable Value 4 Value tags for your website and feeds: -* Enable the [Lightning meta tag](https://github.com/BitcoinAndLightningLayerSpecs/rfc/issues/1) to allow users to send payments (Value 4 Value) -* Enable the [`podcast:value` tag](https://github.com/Podcastindex-org/podcast-namespace/blob/main/value/value.md) in your RSS feed to receive payments for your podcast +The plugin comes with various options to receive donations and [Value 4 Value payments](https://blog.getalby.com/the-case-for-value-4-value/). +- Gutenberg block for a donation widget +- Donation widget for themes +- Enable Value 4 Value tags for your website and feeds: +- Enable the [Lightning meta tag](https://github.com/BitcoinAndLightningLayerSpecs/rfc/issues/1) to allow users to send payments (Value 4 Value) +- Enable the [`podcast:value` tag](https://github.com/Podcastindex-org/podcast-namespace/blob/main/value/value.md) in your RSS feed to receive payments for your podcast ### Lightning Node connections -Connect to your existing Bitcoin Lightning node or simply create a new [Alby account](https://getalby.com/) to instantly receive Lightning payments. -* [Alby](https://getalby.com/) -* [LND](https://github.com/lightningnetwork/lnd/) -* [LNDHub](https://github.com/getalby/lndhub.go) (e.g. BlueWallet) -* [LNBits](https://lnbits.com/) -* [BTCPay Server](https://btcpayserver.org/) -* [Lightning Address](https://lightningaddress.com/) +Connect to your existing Bitcoin Lightning node or simply create a new [Alby account](https://getalby.com/) to instantly receive Lightning payments. +- [Alby](https://getalby.com/) +- [LND](https://github.com/lightningnetwork/lnd/) +- [LNDHub](https://github.com/getalby/lndhub.go) (e.g. BlueWallet) +- [LNBits](https://lnbits.com/) +- [BTCPay Server](https://btcpayserver.org/) +- [Lightning Address](https://lightningaddress.com/) ### REST-API for full advanced custom usage -For more advanced, custom Lightning integrations you can use the REST API to create and verify invoices. The API also provides a [LNURL-pay](https://github.com/fiatjaf/lnurl-rfc/blob/luds/06.md) endpoint. See the REST-API section for details. +For more advanced, custom Lightning integrations you can use the REST API to create and verify invoices. The API also provides a [LNURL-pay](https://github.com/fiatjaf/lnurl-rfc/blob/luds/06.md) endpoint. See the REST-API section for details. ## Requirements -* WordPress 5.6 or higher -* PHP 7.4 or higher (with [internationalization functions](https://www.php.net/manual/en/book.intl.php) +- WordPress 5.6 or higher +- PHP 7.4 or higher (with [internationalization functions](https://www.php.net/manual/en/book.intl.php) ## Demo Here quick Demo videos showing how to setup and use the plugin: -+ [Quck Start - setup + paywall setup](https://www.loom.com/share/095b49a87e444442ac7b297f9483dfa7) -+ [Admin Panel](https://www.loom.com/share/dbe501fe9d91445082a2c5c07a1a8ce8) + +- [Quck Start - setup + paywall setup](https://www.loom.com/share/095b49a87e444442ac7b297f9483dfa7) +- [Admin Panel](https://www.loom.com/share/dbe501fe9d91445082a2c5c07a1a8ce8) ## Installation @@ -74,14 +74,15 @@ git clone https://github.com/getAlby/lightning-publisher-wordpress.git cd lightning-publisher-wordpress composer install # (maybe you need to add `--ignore-platform-reqs` if it asks you to update PHP) ``` + To build a .zip file of the WordPress plugin run: + ```bash ./build.sh # this builds a `wordpress-lightning-publisher.zip` ``` Then upload and activate the plugin through the WordPress Plugin admin panel. - ## Paywall Hook to have custom logic when to enable/disable the paywall To integrate with other plugins or to write custom conditions on when the paywall should be enabled a hook can be used. This means you can use a custom PHP function to decide if content should be behind the paywall or not. @@ -129,18 +130,55 @@ function wp_bln_has_paid_for_post($show_full_content, $post_id) { ``` +## Overriding template for unpaid button + +**Warning**: Do not edit these files within the core plugin itself as they are overwritten during the upgrade process and any customizations will be lost. +Use variable `$plugin` to access plugin options inside of the template file. + +##### Option 1 + +Copy file `wp-content/plugins/lightning-publisher-wordpress/public/templates/paywall-button-unpaid.php` to `wp-content/themes/yourtheme/lightning-publisher-wordpress/paywall-button-unpaid.php` + +The copied file will now override the default template file. + +##### Option 2 + +If you would prefer to place template file in a custom location, then you can use filter: `bln_paywall_unpaid_button_template` + +1. Copy file `wp-content/plugins/lightning-publisher-wordpress/public/templates/paywall-button-unpaid.php` to custom location, eg `wp-content/themes/yourtheme/plugin-mods/paywall-button-unpaid.php` +2. Use filter `bln_paywall_unpaid_button_template` to override button template path. + You can e.g. in `functions.php` + +```php + +// your function receives 1 argument: +// $template_path string, absolute path to template file used to render the button template +// +// return HTML template +function update_bln_paywall_unpaid_button($template_path) { + // Absolute path to template file + $new_path = get_stylesheet_directory() . '/plugin-mods/paywall-button-unpaid.php'; + + return $new_path; +} + +// Check out the `add_filter` documentation for more information: https://developer.wordpress.org/reference/functions/add_filter/ +add_filter( 'bln_paywall_unpaid_button_template', 'update_bln_paywall_unpaid_button' ); + +``` + ## Shortcode If you do not use the Gutenberg editor you can use the `[lnpaywall]` shortcode. The content after the shortcode will be behind the paywall. The following configuration options are possible: -* amount -* currency -* description -* button_text -* total -* timeout -* timein +- amount +- currency +- description +- button_text +- total +- timeout +- timein #### Example @@ -152,12 +190,12 @@ The following configuration options are possible: Folder structure is based on https://github.com/DevinVinson/WordPress-Plugin-Boilerplate -- `bln-publisher.php` is the entrypoint of the plugin -- `includes` is where functionality shared between the admin area and the public-facing parts of the site reside -- `admin` is for all admin-specific functionality -- `public` is for all public-facing functionality -- `includes/class-bln-publisher.php` is the main plugin class which handles including all the related classes. -- `includes/class-bln-publisher-loader.php` is responsible for registering the action and filter hooks, and shortcodes. +- `bln-publisher.php` is the entrypoint of the plugin +- `includes` is where functionality shared between the admin area and the public-facing parts of the site reside +- `admin` is for all admin-specific functionality +- `public` is for all public-facing functionality +- `includes/class-bln-publisher.php` is the main plugin class which handles including all the related classes. +- `includes/class-bln-publisher-loader.php` is responsible for registering the action and filter hooks, and shortcodes. ## REST API @@ -165,10 +203,10 @@ The plugin also provides a set of REST API Endpoints for handling payments and d #### Initiate Payment for Paywall -- URL: `/lnp-alby/v1/paywall/pay` -- Method: `POST` -- Auth Required: No -- Data example +- URL: `/lnp-alby/v1/paywall/pay` +- Method: `POST` +- Auth Required: No +- Data example ``` { @@ -178,10 +216,10 @@ The plugin also provides a set of REST API Endpoints for handling payments and d #### Verify Payment for Paywall -- URL: `/lnp-alby/v1/paywall/verify` -- Method: `POST` -- Auth Required: No -- Data example +- URL: `/lnp-alby/v1/paywall/verify` +- Method: `POST` +- Auth Required: No +- Data example ``` { @@ -193,9 +231,9 @@ The plugin also provides a set of REST API Endpoints for handling payments and d #### LNURL-pay -- URL: `/lnp-alby/v1/lnurlp` -- Method: `GET` -- Auth Required: No +- URL: `/lnp-alby/v1/lnurlp` +- Method: `GET` +- Auth Required: No ``` { @@ -208,16 +246,16 @@ The plugin also provides a set of REST API Endpoints for handling payments and d } ``` -- URL: `/lnp-alby/v1/lnurlp/callback` -- Method: `GET` -- Auth Required: No +- URL: `/lnp-alby/v1/lnurlp/callback` +- Method: `GET` +- Auth Required: No #### Initiate a general payment to generate an invoice -- URL: `/lnp-alby/v1/invoices` -- Method: `POST` -- Auth Required: No -- Data example +- URL: `/lnp-alby/v1/invoices` +- Method: `POST` +- Auth Required: No +- Data example ``` { @@ -228,10 +266,10 @@ The plugin also provides a set of REST API Endpoints for handling payments and d #### Verify Payment for an invoice -- URL: `/lnp-alby/v1/invoices/verify` -- Method: `POST` -- Auth Required: No -- Data example +- URL: `/lnp-alby/v1/invoices/verify` +- Method: `POST` +- Auth Required: No +- Data example ``` { @@ -244,7 +282,6 @@ The plugin also provides a set of REST API Endpoints for handling payments and d Do you need help? Create an issue or reach out to us: support[at]getalby.com - ## About Alby This plugin is powered by [Alby](https://getalby.com/) - We create tools to rethink content monetization on the web. diff --git a/includes/class-bln-publisher-paywall.php b/includes/class-bln-publisher-paywall.php index 69af607..5064c87 100644 --- a/includes/class-bln-publisher-paywall.php +++ b/includes/class-bln-publisher-paywall.php @@ -304,10 +304,7 @@ protected function format_unpaid() * @param $template string Absolute path to template file * @param $this object Plugin instance */ - $template = apply_filters( 'bln_paywall_unpaid_button_template', $template, $this ); - - error_log( print_r( $template, true ) ); - //error_log( print_r( file_exists($template_override), true ) ); + $template = apply_filters( 'bln_paywall_unpaid_button_template', $template ); ob_start(); diff --git a/public/templates/paywall-button-unpaid.php b/public/templates/paywall-button-unpaid.php index 0a8ffee..9dedaad 100644 --- a/public/templates/paywall-button-unpaid.php +++ b/public/templates/paywall-button-unpaid.php @@ -3,8 +3,6 @@ // If this file is called directly, abort. defined('WPINC') || die; - - $button = sprintf( '', $plugin->format_label($plugin->options['button_text']) From cd82879762805f1df68b37c973ebba73399d8bd8 Mon Sep 17 00:00:00 2001 From: Vlado Bosnjak Date: Sat, 6 May 2023 19:55:46 +0700 Subject: [PATCH 3/6] - moved post_id from wrapper to localize_script - updated Js selector to look for css class .wp-lnp-btn --- README.md | 8 + public/class-bln-publisher-public.php | 3 +- public/js/bln-publisher-public.js | 228 ++++++++++----------- public/templates/paywall-button-unpaid.php | 3 +- 4 files changed, 115 insertions(+), 127 deletions(-) diff --git a/README.md b/README.md index baeb18e..c4a7120 100755 --- a/README.md +++ b/README.md @@ -135,6 +135,14 @@ function wp_bln_has_paid_for_post($show_full_content, $post_id) { **Warning**: Do not edit these files within the core plugin itself as they are overwritten during the upgrade process and any customizations will be lost. Use variable `$plugin` to access plugin options inside of the template file. +Required markup for custom button: + +```HTML +
+ +
+``` + ##### Option 1 Copy file `wp-content/plugins/lightning-publisher-wordpress/public/templates/paywall-button-unpaid.php` to `wp-content/themes/yourtheme/lightning-publisher-wordpress/paywall-button-unpaid.php` diff --git a/public/class-bln-publisher-public.php b/public/class-bln-publisher-public.php index b322152..fae9c3b 100644 --- a/public/class-bln-publisher-public.php +++ b/public/class-bln-publisher-public.php @@ -75,7 +75,8 @@ public function enqueue_scripts() wp_localize_script( $this->plugin->get_plugin_name(), 'LN_Paywall', array( - 'rest_base' => get_rest_url(null, '/lnp-alby/v1') + 'rest_base' => get_rest_url(null, '/lnp-alby/v1'), + 'post_id' => get_the_ID(), ) ); } diff --git a/public/js/bln-publisher-public.js b/public/js/bln-publisher-public.js index 53d7ec1..9e9bab1 100644 --- a/public/js/bln-publisher-public.js +++ b/public/js/bln-publisher-public.js @@ -1,61 +1,50 @@ -document.addEventListener("DOMContentLoaded", function(event) { +document.addEventListener('DOMContentLoaded', function (event) { (function () { var checkPaidInterval = null; var wp_rest_base_url = LN_Paywall.rest_base; var LN_Paywall_Spinner = - ''; - var LN_Paywall_Copy = ''; + ''; + var LN_Paywall_Copy = + ''; - function pay(invoice, options) - { + function pay(invoice, options) { if (!window.webln) { showQRCode(invoice, options); return startWatchingForPayment(invoice); } - return window.webln.enable() - .then( - function () { + return window.webln + .enable() + .then(function () { window.webln - .sendPayment(invoice.payment_request) - .then( - (response) => { + .sendPayment(invoice.payment_request) + .then((response) => { window.LNP_CURRENT_PREIMAGE = - response.preimage || response.payment_preimage; - } - ) - .catch( - function (e) { + response.preimage || response.payment_preimage; + }) + .catch(function (e) { console.error(e); showQRCode(invoice, options); - } - ); + }); return startWatchingForPayment(invoice); - } - ) - .catch( - function (err) { + }) + .catch(function (err) { console.error(err); showQRCode(invoice, options); return startWatchingForPayment(invoice); - } - ); + }); } - function startWatchingForPayment(invoice) - { + function startWatchingForPayment(invoice) { stopWatchingForPayment(); - return new Promise( - function (resolve, reject) { - checkPaidInterval = setInterval( - checkPaymentStatus(invoice, resolve), - 2500 - ); - } - ); + return new Promise(function (resolve, reject) { + checkPaidInterval = setInterval( + checkPaymentStatus(invoice, resolve), + 2500 + ); + }); } - function stopWatchingForPayment() - { + function stopWatchingForPayment() { window.LNP_CURRENT_PREIMAGE = null; if (checkPaidInterval) { clearTimeout(checkPaidInterval); @@ -63,121 +52,112 @@ document.addEventListener("DOMContentLoaded", function(event) { } } - function checkPaymentStatus(invoice, callback) - { + function checkPaymentStatus(invoice, callback) { if (!invoice || !invoice.token) { - console.log("Ligthning invoice missing"); + console.log('Ligthning invoice missing'); return; } return function () { let body = { token: invoice.token, preimage: window.LNP_CURRENT_PREIMAGE, - t: Date.now() + t: Date.now(), }; - fetch( - wp_rest_base_url+'/paywall/verify', { - method: "POST", - credentials: "same-origin", - cache: "no-cache", - body: JSON.stringify(body), - headers: { - "Content-Type": "application/json", - }, - } - ).then( - function (response) { - if (response.ok) { - response.json().then( - function (content) { - stopWatchingForPayment(); - callback(content, invoice); - } - ); - } + fetch(wp_rest_base_url + '/paywall/verify', { + method: 'POST', + credentials: 'same-origin', + cache: 'no-cache', + body: JSON.stringify(body), + headers: { + 'Content-Type': 'application/json', + }, + }).then(function (response) { + if (response.ok) { + response.json().then(function (content) { + stopWatchingForPayment(); + callback(content, invoice); + }); } - ); + }); }; } - function showQRCode(invoice, options) - { - var button = options.target.querySelector("button.wp-lnp-btn"); + function showQRCode(invoice, options) { + var button = options.target.querySelector('button.wp-lnp-btn'); button.outerHTML = ``; } - function requestPayment(params, options) - { - return fetch( - wp_rest_base_url+'/paywall/pay', { - method: "POST", - credentials: "same-origin", - cache: "no-cache", - body: JSON.stringify(params), - headers: { - "Content-Type": "application/json", - }, - } - ) - .then( - function (resp) { - return resp.json(); - } - ) - .then( - function (invoice) { - if (!invoice || !invoice.payment_request) { - console.error("Failed to generate lightning invoice", invoice); - throw new Error("Failed to generate lightning invoice " + JSON.stringify(invoice)); - } - return pay(invoice, options); + function requestPayment(params, options) { + return fetch(wp_rest_base_url + '/paywall/pay', { + method: 'POST', + credentials: 'same-origin', + cache: 'no-cache', + body: JSON.stringify(params), + headers: { + 'Content-Type': 'application/json', + }, + }) + .then(function (resp) { + return resp.json(); + }) + .then(function (invoice) { + if (!invoice || !invoice.payment_request) { + console.error( + 'Failed to generate lightning invoice', + invoice + ); + throw new Error( + 'Failed to generate lightning invoice ' + + JSON.stringify(invoice) + ); } - ); + return pay(invoice, options); + }); } - function initPostPaywalls() - { - var buttons = document.querySelectorAll( - "[data-lnp-postid] button.wp-lnp-btn" + function initPostPaywalls() { + var buttons = [].slice.call( + document.querySelectorAll('.wp-lnp-btn') ); if (buttons.length === 0) { return; } - buttons.forEach( - function (button) { - button.addEventListener( - "click", function (e) { - e.preventDefault(); - this.setAttribute("disabled", ""); + buttons.forEach(function (button) { + button.addEventListener('click', function (e) { + e.preventDefault(); + this.setAttribute('disabled', ''); - this.innerHTML = LN_Paywall_Spinner; - var wrapper = this.closest(".wp-lnp-wrapper"); + this.innerHTML = LN_Paywall_Spinner; + var wrapper = this.closest('.wp-lnp-wrapper'); - requestPayment( - { post_id: wrapper.dataset.lnpPostid }, - { target: wrapper } - ) - .then( - function (content, invoice) { - wrapper.outerHTML = content; - } - ) - .catch( - function (e) { - console.log(e); - alert("sorry, something went wrong."); - } - ); - } - ); - } - ); + requestPayment( + { post_id: parseInt(window.LN_Paywall.post_id) }, + { target: wrapper } + ) + .then(function (content, invoice) { + wrapper.outerHTML = content; + }) + .catch(function (e) { + console.log(e); + alert('sorry, something went wrong.'); + }); + }); + }); } initPostPaywalls(); diff --git a/public/templates/paywall-button-unpaid.php b/public/templates/paywall-button-unpaid.php index 9dedaad..d1f08a5 100644 --- a/public/templates/paywall-button-unpaid.php +++ b/public/templates/paywall-button-unpaid.php @@ -20,9 +20,8 @@ } printf( - '%s
%s%s
', + '%s
%s%s
', $plugin->teaser, - $plugin->post_id, $description, $button ); \ No newline at end of file From a4dc9b32584043c0a6ea5e1fdf4ce28f1962eec3 Mon Sep 17 00:00:00 2001 From: Vlado Bosnjak Date: Sat, 13 May 2023 13:44:58 +0700 Subject: [PATCH 4/6] ignore lock files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6bf7624..90d45a5 100755 --- a/.gitignore +++ b/.gitignore @@ -110,6 +110,8 @@ typings/ # Yarn Integrity file .yarn-integrity package-lock.json +yarn.lock +composer.lock # dotenv environment variables file .env From 8ea9a3e669f20abc4c7b1fc823468efacf3359bb Mon Sep 17 00:00:00 2001 From: Vlado Bosnjak Date: Sat, 13 May 2023 13:50:30 +0700 Subject: [PATCH 5/6] add back composer.lock file --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 90d45a5..6bf7624 100755 --- a/.gitignore +++ b/.gitignore @@ -110,8 +110,6 @@ typings/ # Yarn Integrity file .yarn-integrity package-lock.json -yarn.lock -composer.lock # dotenv environment variables file .env From d161b9a0b1ffd1478dfec478895993e9931505dd Mon Sep 17 00:00:00 2001 From: Vlado Bosnjak Date: Sat, 13 May 2023 13:51:36 +0700 Subject: [PATCH 6/6] composer update test --- composer.lock | 129 ++++++++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 68 deletions(-) diff --git a/composer.lock b/composer.lock index cc6116a..e8ce147 100644 --- a/composer.lock +++ b/composer.lock @@ -264,21 +264,21 @@ "source": { "type": "git", "url": "https://github.com/firebase/php-jwt.git", - "reference": "3b454f90f147db65a615041dec6661f427d6cb00" + "reference": "6c8f5e7c7ca5a584c23878bc180b6927191422fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/firebase/php-jwt/zipball/3b454f90f147db65a615041dec6661f427d6cb00", - "reference": "3b454f90f147db65a615041dec6661f427d6cb00", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/6c8f5e7c7ca5a584c23878bc180b6927191422fb", + "reference": "6c8f5e7c7ca5a584c23878bc180b6927191422fb", "shasum": "" }, "require": { - "php": "^7.1||^8.0" + "php": "^7.4||^8.0" }, "require-dev": { "guzzlehttp/guzzle": "^6.5||^7.4", - "phpspec/prophecy-phpunit": "^1.1", - "phpunit/phpunit": "^7.5||^9.5", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.5", "psr/cache": "^1.0||^2.0", "psr/http-client": "^1.0", "psr/http-factory": "^1.0" @@ -320,26 +320,26 @@ "issues": "https://github.com/firebase/php-jwt/issues", "source": "https://github.com/firebase/php-jwt/tree/main" }, - "time": "2023-02-13T12:51:14+00:00" + "time": "2023-05-12T18:16:34+00:00" }, { "name": "guzzlehttp/guzzle", - "version": "dev-master", + "version": "7.5.x-dev", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "8459341c16f96b9610dcdfe22bd3060d60c0da04" + "reference": "255d7157b463ee2d9b3cbf891eda2691baa43076" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/8459341c16f96b9610dcdfe22bd3060d60c0da04", - "reference": "8459341c16f96b9610dcdfe22bd3060d60c0da04", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/255d7157b463ee2d9b3cbf891eda2691baa43076", + "reference": "255d7157b463ee2d9b3cbf891eda2691baa43076", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.5", - "guzzlehttp/psr7": "^1.9 || ^2.4", + "guzzlehttp/psr7": "^1.9.1 || ^2.4.5", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0", "symfony/deprecation-contracts": "^2.2 || ^3.0" @@ -365,9 +365,6 @@ "bamarni-bin": { "bin-links": true, "forward-command": false - }, - "branch-alias": { - "dev-master": "7.5-dev" } }, "autoload": { @@ -433,7 +430,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/master" + "source": "https://github.com/guzzle/guzzle/tree/7.5" }, "funding": [ { @@ -449,7 +446,7 @@ "type": "tidelift" } ], - "time": "2022-08-29T11:03:19+00:00" + "time": "2023-04-18T08:37:42+00:00" }, { "name": "guzzlehttp/promises", @@ -538,22 +535,22 @@ }, { "name": "guzzlehttp/psr7", - "version": "dev-master", + "version": "2.6.x-dev", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "58d0734481de3fbc62f3d13da4d991e051521282" + "reference": "b635f279edd83fc275f822a1188157ffea568ff6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/58d0734481de3fbc62f3d13da4d991e051521282", - "reference": "58d0734481de3fbc62f3d13da4d991e051521282", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/b635f279edd83fc275f822a1188157ffea568ff6", + "reference": "b635f279edd83fc275f822a1188157ffea568ff6", "shasum": "" }, "require": { "php": "^7.2.5 || ^8.0", "psr/http-factory": "^1.0", - "psr/http-message": "^1.0", + "psr/http-message": "^1.1 || ^2.0", "ralouphie/getallheaders": "^3.0" }, "provide": { @@ -568,15 +565,11 @@ "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" }, - "default-branch": true, "type": "library", "extra": { "bamarni-bin": { "bin-links": true, "forward-command": false - }, - "branch-alias": { - "dev-master": "2.4-dev" } }, "autoload": { @@ -638,7 +631,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/master" + "source": "https://github.com/guzzle/psr7/tree/2.5.0" }, "funding": [ { @@ -654,7 +647,7 @@ "type": "tidelift" } ], - "time": "2023-02-15T13:59:53+00:00" + "time": "2023-04-17T16:11:26+00:00" }, { "name": "jorijn/bitcoin-bolt11", @@ -845,12 +838,12 @@ "source": { "type": "git", "url": "https://github.com/bumi/btcpay-php.git", - "reference": "991ac24b228f3647a67d136e3814d9cda0c3d0a3" + "reference": "5be4ba849310cbcbeda2547bb49640efaffe5464" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bumi/btcpay-php/zipball/991ac24b228f3647a67d136e3814d9cda0c3d0a3", - "reference": "991ac24b228f3647a67d136e3814d9cda0c3d0a3", + "url": "https://api.github.com/repos/bumi/btcpay-php/zipball/5be4ba849310cbcbeda2547bb49640efaffe5464", + "reference": "5be4ba849310cbcbeda2547bb49640efaffe5464", "shasum": "" }, "require": { @@ -884,7 +877,7 @@ "support": { "source": "https://github.com/bumi/btcpay-php/tree/main" }, - "time": "2022-11-05T10:30:47+00:00" + "time": "2023-04-03T10:26:42+00:00" }, { "name": "octan/lnbits", @@ -892,12 +885,12 @@ "source": { "type": "git", "url": "https://github.com/bumi/lnbits-php.git", - "reference": "7e1f8ea981bc74fb58e62cf8c27dbb3c44372fbf" + "reference": "349752dff9cd5393c8291bfe11dda5f03228902f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bumi/lnbits-php/zipball/7e1f8ea981bc74fb58e62cf8c27dbb3c44372fbf", - "reference": "7e1f8ea981bc74fb58e62cf8c27dbb3c44372fbf", + "url": "https://api.github.com/repos/bumi/lnbits-php/zipball/349752dff9cd5393c8291bfe11dda5f03228902f", + "reference": "349752dff9cd5393c8291bfe11dda5f03228902f", "shasum": "" }, "require": { @@ -929,7 +922,7 @@ "source": "https://github.com/bumi/lnbits-php/tree/master", "issues": "https://github.com/bumi/lnbits-php/issues" }, - "time": "2022-11-05T10:26:06+00:00" + "time": "2023-04-03T10:20:11+00:00" }, { "name": "octan/lnd-rest", @@ -937,12 +930,12 @@ "source": { "type": "git", "url": "https://github.com/bumi/lnd-php-rest.git", - "reference": "da49a5a24f5da8c357b4b6f03884e5a96b748fbb" + "reference": "fe4713325a45bd06b2095e04456d2ef0126d84fa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bumi/lnd-php-rest/zipball/da49a5a24f5da8c357b4b6f03884e5a96b748fbb", - "reference": "da49a5a24f5da8c357b4b6f03884e5a96b748fbb", + "url": "https://api.github.com/repos/bumi/lnd-php-rest/zipball/fe4713325a45bd06b2095e04456d2ef0126d84fa", + "reference": "fe4713325a45bd06b2095e04456d2ef0126d84fa", "shasum": "" }, "require": { @@ -974,7 +967,7 @@ "source": "https://github.com/bumi/lnd-php-rest/tree/master", "issues": "https://github.com/bumi/lnd-php-rest/issues" }, - "time": "2022-11-05T10:29:20+00:00" + "time": "2023-04-03T10:27:20+00:00" }, { "name": "octan/lndhub", @@ -982,12 +975,12 @@ "source": { "type": "git", "url": "https://github.com/bumi/lndhub-php.git", - "reference": "ef763abd58218ce4199ecbf86c6a31c8aa0d2630" + "reference": "a7033a13f36532c8ac02371d634b67bf0cd09a1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bumi/lndhub-php/zipball/ef763abd58218ce4199ecbf86c6a31c8aa0d2630", - "reference": "ef763abd58218ce4199ecbf86c6a31c8aa0d2630", + "url": "https://api.github.com/repos/bumi/lndhub-php/zipball/a7033a13f36532c8ac02371d634b67bf0cd09a1d", + "reference": "a7033a13f36532c8ac02371d634b67bf0cd09a1d", "shasum": "" }, "require": { @@ -1022,7 +1015,7 @@ "source": "https://github.com/bumi/lndhub-php/tree/main", "issues": "https://github.com/bumi/lndhub-php/issues" }, - "time": "2022-10-13T10:27:50+00:00" + "time": "2023-04-03T10:20:57+00:00" }, { "name": "pleonasm/merkle-tree", @@ -1139,17 +1132,17 @@ "source": { "type": "git", "url": "https://github.com/php-fig/http-client.git", - "reference": "22b2ef5687f43679481615605d7a15c557ce85b1" + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/22b2ef5687f43679481615605d7a15c557ce85b1", - "reference": "22b2ef5687f43679481615605d7a15c557ce85b1", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/0955afe48220520692d2d09f7ab7e0f93ffd6a31", + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31", "shasum": "" }, "require": { "php": "^7.0 || ^8.0", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0 || ^2.0" }, "default-branch": true, "type": "library", @@ -1182,9 +1175,9 @@ "psr-18" ], "support": { - "source": "https://github.com/php-fig/http-client/tree/master" + "source": "https://github.com/php-fig/http-client/tree/1.0.2" }, - "time": "2020-09-19T09:12:31+00:00" + "time": "2023-04-10T20:12:12+00:00" }, { "name": "psr/http-factory", @@ -1192,17 +1185,17 @@ "source": { "type": "git", "url": "https://github.com/php-fig/http-factory.git", - "reference": "5a4f141ac2e5bc35e615134f127e1833158d2944" + "reference": "e616d01114759c4c489f93b099585439f795fe35" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/5a4f141ac2e5bc35e615134f127e1833158d2944", - "reference": "5a4f141ac2e5bc35e615134f127e1833158d2944", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", + "reference": "e616d01114759c4c489f93b099585439f795fe35", "shasum": "" }, "require": { "php": ">=7.0.0", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0 || ^2.0" }, "default-branch": true, "type": "library", @@ -1238,9 +1231,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-factory/tree/master" + "source": "https://github.com/php-fig/http-factory/tree/1.0.2" }, - "time": "2022-07-14T07:21:53+00:00" + "time": "2023-04-10T20:10:41+00:00" }, { "name": "psr/http-message", @@ -1248,22 +1241,22 @@ "source": { "type": "git", "url": "https://github.com/php-fig/http-message.git", - "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4" + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", - "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": "^7.2 || ^8.0" }, "default-branch": true, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1278,7 +1271,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for HTTP messages", @@ -1292,9 +1285,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-message/tree/master" + "source": "https://github.com/php-fig/http-message/tree/2.0" }, - "time": "2019-08-29T13:16:46+00:00" + "time": "2023-04-04T09:54:51+00:00" }, { "name": "ralouphie/getallheaders", @@ -1346,12 +1339,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" + "reference": "c30dd04b9a303689a26d7986f7cffce04203a107" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", - "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/c30dd04b9a303689a26d7986f7cffce04203a107", + "reference": "c30dd04b9a303689a26d7986f7cffce04203a107", "shasum": "" }, "require": { @@ -1405,7 +1398,7 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:55:41+00:00" + "time": "2023-01-01T08:36:10+00:00" }, { "name": "tkijewski/php-lnurl",