Changeset 2732965
- Timestamp:
- 05/28/2022 01:22:19 AM (4 years ago)
- Location:
- wp-lightning-comments/trunk
- Files:
-
- 1 added
- 5 edited
-
README.md (modified) (2 diffs)
-
lightningcomments.css (modified) (1 diff)
-
lightningcomments.js (modified) (2 diffs)
-
lightningcomments.php (modified) (5 diffs)
-
qrious.min.js (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-lightning-comments/trunk/README.md
r1893155 r2732965 1 1 # Pay to Comment with Lightning 2 - Requires the user to send a small payment before being able to comment. 3 - Disables the comment form until a user has sent a bitcoin micropayment over Lightning Network. 4 - Remembers if a user paid to comment on a certain page. 5 - Supports multiple providers with simple configuration. 2 6 3 Require the user to send a small payment before being able to comment. 4 5 This plugin disables the comment form until a user has sent a bitcoin micropayment over Lightning Network. 6 7 The plugin is made for Wordpress, but the JavaScript component can easily be implemented into other CMS systems as well. 7 ## Supported Lightning Backends 8 * [LNBits](https://lnbits.com) 9 * [BTCPayServer](https://btcpayserver.org) 8 10 9 11 ## Usage … … 12 14 1. Upload it to your plugins-folder 13 15 1. Enable the plugin in your wordpress backend 14 1. Select if you want testnet or mainnet in the post admin interface15 1. Start using it!16 1. Configure provider url and invoice key in the plugin settings screen. 17 1. Enjoy spam-free comment section! -
wp-lightning-comments/trunk/lightningcomments.css
r1893155 r2732965 31 31 } 32 32 33 #lncomments_checkbox_field_0 {33 /* #lncomments_checkbox_field_0 { 34 34 visibility: hidden; 35 } 35 } */ -
wp-lightning-comments/trunk/lightningcomments.js
r1893155 r2732965 45 45 }; 46 46 47 var buildQuiz = function(quizNode){47 var buildQuiz = async function(quizNode){ 48 48 var formNode = quizNode.nextElementSibling; 49 49 var errorText = quizNode.getAttribute('data-' + LightningComments + '-error'); … … 81 81 }); 82 82 83 //testnet / mainnet 84 var mainnet = document.getElementsByName("lncomments_settings[lncomments_checkbox_field_0]")[0].checked; 85 var iframe = document.createElement('iframe'); 86 iframe.style.height = '150px'; 87 iframe.style.width = '100%'; 88 iframe.style.transition = 'height 1s'; 89 if(mainnet) { 90 iframe.src = "https://api.yunik.co:8113"; 91 } else { 92 iframe.src = "https://api.yunik.co:8112"; 83 //testnet / mainnet - remove testnet it's not 2018 anymore! 84 // var testnet = document.getElementsByName("lncomments_settings[lncomments_checkbox_field_0]")[0].checked; 85 // var iframe = document.createElement('iframe'); 86 87 let invoice; 88 const invoiceCheckInterval = 20000; 89 90 var invoiceDiv = document.createElement('div'); 91 // invoiceDiv.style.height = '550px'; 92 invoiceDiv.style.width = '100%'; 93 invoiceDiv.style.transition = 'height 1s'; 94 const invoiceAmount = document.getElementsByName("lncomments_settings[lncomments_text_field_3]")[0].value 95 const lnbitsUrl = document.getElementsByName("lncomments_settings[lncomments_text_field_1]")[0].value 96 const lnbitsKey = document.getElementsByName("lncomments_settings[lncomments_text_field_2]")[0].value 97 const btcpayserverUrl = document.getElementsByName("lncomments_settings[lncomments_text_field_4]")[0].value 98 const btcpayserverStoreId = document.getElementsByName("lncomments_settings[lncomments_text_field_5]")[0].value 99 const btcpayserverToken = document.getElementsByName("lncomments_settings[lncomments_text_field_6]")[0].value 100 101 try { 102 if(lnbitsUrl && lnbitsKey) { 103 // fetch invoice from lnbits 104 const invoiceResponse = await fetch(`${lnbitsUrl}/api/v1/payments`, 105 { 106 headers: { 107 'Accept': 'application/json', 108 'Content-Type': 'application/json', 109 'X-Api-Key': lnbitsKey 110 }, 111 method: "POST", 112 body: JSON.stringify({"out": false, "amount": parseInt(invoiceAmount), "memo": "Pay to comment on " + window.location.host}) 113 }) 114 invoice = await invoiceResponse.json() 115 console.log('invoice: ', invoice) 116 117 if(invoice?.payment_request) { 118 // check if invoice is paid 119 const interval = setInterval(async() => { 120 const paidResponse = await fetch(`${lnbitsUrl}/api/v1/payments/${invoice.payment_hash}`, 121 { 122 headers: { 123 'Accept': 'application/json', 124 'Content-Type': 'application/json', 125 'X-Api-Key': lnbitsKey 126 }, 127 }) 128 const paid = await paidResponse.json() 129 if(paid?.paid) { 130 localStorage.setItem(correctId, correctId); 131 setTimeout(removeQuizDelay, 2500, quizNode, formNode); 132 clearInterval(interval) 133 } 134 }, invoiceCheckInterval) 135 } 136 } else if(btcpayserverUrl && btcpayserverStoreId && btcpayserverToken) { 137 // fetch invoice from lnbits 138 const invoiceResponse = await fetch(`${btcpayserverUrl}/api/v1/stores/${btcpayserverStoreId}/invoices`, 139 { 140 headers: { 141 'Accept': 'application/json', 142 'Content-Type': 'application/json', 143 'Authorization': `token ${btcpayserverToken}`, 144 }, 145 method: "POST", 146 body: JSON.stringify({"amount": parseInt(invoiceAmount), "currency": "SATS"}) 147 }) 148 invoice = await invoiceResponse.json() 149 console.log('notinvoice ', invoice) 150 const actualInvoiceResponse = await fetch(`${btcpayserverUrl}/api/v1/stores/${btcpayserverStoreId}/invoices/${invoice.id}/payment-methods`, 151 { 152 headers: { 153 'Accept': 'application/json', 154 'Content-Type': 'application/json', 155 'Authorization': `token ${btcpayserverToken}`, 156 }, 157 }) 158 actualInvoice = (await actualInvoiceResponse.json())[0].destination 159 console.log('invoice: ', actualInvoice) 160 invoice.payment_request = actualInvoice 161 162 if(actualInvoice) { 163 // check if invoice is paid 164 const interval = setInterval(async() => { 165 const paidResponse = await fetch(`${btcpayserverUrl}/api/v1/stores/${btcpayserverStoreId}/invoices/${invoice.id}`, 166 { 167 headers: { 168 'Accept': 'application/json', 169 'Content-Type': 'application/json', 170 'Authorization': `token ${btcpayserverToken}`, 171 }, 172 }) 173 const paid = await paidResponse.json() 174 if(paid?.status === 'Settled') { 175 localStorage.setItem(correctId, correctId); 176 setTimeout(removeQuizDelay, 2500, quizNode, formNode); 177 clearInterval(interval) 178 } 179 }, invoiceCheckInterval) 180 } 181 } 182 183 var p1 = document.createElement('p') 184 p1.style.textAlign = 'center' 185 p1.innerHTML = 'Scan/Tap/Copy to Pay' 186 var p2 = document.createElement('p') 187 p2.style.wordBreak = 'break-all' 188 p2.innerHTML = invoice?.payment_request 189 var anchor = document.createElement('a') 190 anchor.target = '_blank' 191 var qrcode = document.createElement('canvas'); 192 qrcode.setAttribute("id","qr") 193 qrcode.style.margin = 'auto' 194 qrcode.style.display = 'block' 195 anchor.append(qrcode) 196 anchor.href = 'lightning:' + invoice?.payment_request?.toUpperCase() 197 invoiceDiv.append(p1) 198 invoiceDiv.append(anchor) 199 invoiceDiv.append(p2) 200 201 quizNode.appendChild(invoiceDiv); 202 203 //add the qrcode after append 204 new QRious({ 205 element: document.getElementById('qr'), 206 value: invoice?.payment_request, 207 padding: '4', 208 size: 300, 209 }); 210 211 } catch (error) { 212 console.log('failed to create Lightning invoice: ', error.message) 93 213 } 94 214 95 quizNode.appendChild(iframe); 96 215 // instead of cross-origin events - lets check if invoice was paid with interval 97 216 // Listen to message from child window 98 bindEvent(window, 'message', function (e) {99 // results.innerHTML = e.data;100 // console.log("fromiframe: " + e.data);101 if(e.data == "fromclientjs") {102 // console.log("payment received!");103 correct = true;104 localStorage.setItem(correctId, correctId);105 // removeQuiz(quizNode, formNode);106 setTimeout(removeQuizDelay, 2500, quizNode, formNode);107 108 var fool = document.getElementById("pmg_comment_titlez");109 fool.value = "youreok";110 111 } else if(e.data == "buyclicked") {112 iframe.style.height = "650px";113 } else {114 // console.log("received something else from iframe");115 }116 });217 // bindEvent(window, 'message', function (e) { 218 // // results.innerHTML = e.data; 219 // // console.log("fromiframe: " + e.data); 220 // if(e.data == "fromclientjs") { 221 // // console.log("payment received!"); 222 // correct = true; 223 // localStorage.setItem(correctId, correctId); 224 // // removeQuiz(quizNode, formNode); 225 // setTimeout(removeQuizDelay, 2500, quizNode, formNode); 226 227 // var fool = document.getElementById("pmg_comment_titlez"); 228 // fool.value = "youreok"; 229 230 // } else if(e.data == "buyclicked") { 231 // iframe.style.height = "650px"; 232 // } else { 233 // // console.log("received something else from iframe"); 234 // } 235 // }); 117 236 118 237 }; -
wp-lightning-comments/trunk/lightningcomments.php
r1893155 r2732965 2 2 /* 3 3 Plugin Name: Pay to Comment with Lightning 4 Version: 0. 1.04 Version: 0.2.0 5 5 Plugin URI: https://wordpress.org/plugins/wp-lightning-comments/ 6 6 Author: @citlayik 7 Author URI: https:// blog.kriptode.com/lightning-comments-for-wordpress/7 Author URI: https://kriptode.com 8 8 Description: Require the user to send a bitcoin payment to be able to post comments. 9 9 */ … … 13 13 14 14 add_action('wp_enqueue_scripts', function(){ 15 wp_enqueue_script('qrious', plugins_url('qrious.min.js', __FILE__)); 15 16 wp_enqueue_script(LightningComments, plugins_url('lightningcomments.js', __FILE__)); 16 17 wp_enqueue_style(LightningComments, plugins_url('lightningcomments.css', __FILE__)); … … 23 24 data-<?php echo LightningComments; ?>-error="<?php echo esc_attr(__('You have not sent the payment correctly. Try again.', LightningComments)); ?>"> 24 25 <!-- Would you like to comment? --> 25 <h2>Please send a small payment via Lightning to enable comments.</h2> 26 <?php lncomments_checkbox_field_0_render(); ?> 26 <h5 style="text-align: center;">Please send a small Bitcoin payment via Lightning to enable comments.</h5> 27 <div id="lncomments-settings" style="display:none;"> 28 <?php lncomments_text_field_1_render(); ?> 29 <?php lncomments_text_field_2_render(); ?> 30 <?php lncomments_text_field_3_render(); ?> 31 <?php lncomments_text_field_4_render(); ?> 32 <?php lncomments_text_field_5_render(); ?> 33 <?php lncomments_text_field_6_render(); ?> 34 </div> 27 35 <!-- <p> 28 36 We love comments & hate spam. … … 158 166 ); 159 167 160 add_settings_field( 161 'lncomments_checkbox_field_0', 162 __( 'Mainnet if checked', 'wordpress' ), 163 'lncomments_checkbox_field_0_render', 164 'pluginPage', 165 'lncomments_pluginPage_section' 166 ); 167 168 // add_settings_field( 169 // 'lncomments_checkbox_field_0', 170 // __( 'Testnet if checked', 'wordpress' ), 171 // 'lncomments_checkbox_field_0_render', 172 // 'pluginPage', 173 // 'lncomments_pluginPage_section' 174 // ); 175 176 177 add_settings_field( 178 'lncomments_text_field_3', 179 __( 'Comment Amount (sats)', 'wordpress' ), 180 'lncomments_text_field_3_render', 181 'pluginPage', 182 'lncomments_pluginPage_section' 183 ); 168 184 add_settings_field( 169 185 'lncomments_text_field_1', 170 __( ' Your Bitcoin Wallet Address', 'wordpress' ),186 __( 'LNBits URL (e.g. https://legend.lnbits.com)', 'wordpress' ), 171 187 'lncomments_text_field_1_render', 172 188 'pluginPage', 173 189 'lncomments_pluginPage_section' 174 190 ); 191 add_settings_field( 192 'lncomments_text_field_2', 193 __( 'LNBits Invoice/Read Key', 'wordpress' ), 194 'lncomments_text_field_2_render', 195 'pluginPage', 196 'lncomments_pluginPage_section' 197 ); 198 add_settings_field( 199 'lncomments_text_field_4', 200 __( 'BTCPayServer URL (e.g. https://mainnet.demo.btcpayserver.org)', 'wordpress' ), 201 'lncomments_text_field_4_render', 202 'pluginPage', 203 'lncomments_pluginPage_section' 204 ); 205 add_settings_field( 206 'lncomments_text_field_5', 207 __( 'BTCPayServer Store ID', 'wordpress' ), 208 'lncomments_text_field_5_render', 209 'pluginPage', 210 'lncomments_pluginPage_section' 211 ); 212 add_settings_field( 213 'lncomments_text_field_6', 214 __( 'BTCPayServer Greenfield Api Key (permissions: canviewinvoices & cancreateinvoice)', 'wordpress' ), 215 'lncomments_text_field_6_render', 216 'pluginPage', 217 'lncomments_pluginPage_section' 218 ); 219 // btcpay.store.cancreateinvoice 175 220 176 221 } … … 188 233 189 234 function lncomments_text_field_1_render( ) { 190 191 $options = get_option( 'lncomments_settings' ); 192 ?> 193 <input type='text' name='lncomments_settings[lncomments_text_field_1]' value='<?php echo $options['lncomments_text_field_1']; ?>'> 194 <?php 195 196 } 197 235 $options = get_option( 'lncomments_settings' ); 236 ?> 237 <input type='text' style='min-width: 300px;' name='lncomments_settings[lncomments_text_field_1]' value='<?php echo $options['lncomments_text_field_1']; ?>'> 238 <?php 239 } 240 241 function lncomments_text_field_2_render( ) { 242 $options = get_option( 'lncomments_settings' ); 243 ?> 244 <input type='text' style='min-width: 300px;' name='lncomments_settings[lncomments_text_field_2]' value='<?php echo $options['lncomments_text_field_2']; ?>'> 245 <?php 246 } 247 248 function lncomments_text_field_3_render( ) { 249 $options = get_option( 'lncomments_settings' ); 250 ?> 251 <input type='text' style='min-width: 300px;' name='lncomments_settings[lncomments_text_field_3]' value='<?php echo $options['lncomments_text_field_3']; ?>'> 252 <?php 253 } 254 255 function lncomments_text_field_4_render( ) { 256 $options = get_option( 'lncomments_settings' ); 257 ?> 258 <input type='text' style='min-width: 300px;' name='lncomments_settings[lncomments_text_field_4]' value='<?php echo $options['lncomments_text_field_4']; ?>'> 259 <?php 260 } 261 function lncomments_text_field_5_render( ) { 262 $options = get_option( 'lncomments_settings' ); 263 ?> 264 <input type='text' style='min-width: 300px;' name='lncomments_settings[lncomments_text_field_5]' value='<?php echo $options['lncomments_text_field_5']; ?>'> 265 <?php 266 } 267 function lncomments_text_field_6_render( ) { 268 $options = get_option( 'lncomments_settings' ); 269 ?> 270 <input type='text' style='min-width: 300px;' name='lncomments_settings[lncomments_text_field_6]' value='<?php echo $options['lncomments_text_field_6']; ?>'> 271 <?php 272 } 198 273 199 274 function lncomments_settings_section_callback( ) { 200 275 201 echo __( ' No information is saved or tracked. Currently payouts are disabled.', 'wordpress' );276 echo __( 'Populate URL and invoice key for your preferred provider', 'wordpress' ); 202 277 203 278 } -
wp-lightning-comments/trunk/readme.txt
r1893334 r2732965 1 1 === Pay to Comment with Lightning === 2 2 Contributors: pseudozach 3 Tags: comments, bitcoin, lightning, micropayment, spam blocker3 Tags: comments, bitcoin, lightning, micropayment, spam, captcha 4 4 Requires at least: 4.6 5 Tested up to: 4.9.65 Tested up to: 6.0 6 6 Stable tag: trunk 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html 9 Donate link: https://blog.kriptode.com/donations/9 Donate link: [email protected] 10 10 11 11 Require the user to send a small payment before being able to comment on a wordpress blog. … … 19 19 1. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly. 20 20 1. Activate the plugin through the 'Plugins' screen in WordPress 21 1. Select if you want to accept payments on testnet or mainnetunder Settings > Pay to Comment with Lightning section22 1. Start using it!21 1. Configure provider url and invoice key under Settings > Pay to Comment with Lightning section 22 1. Enjoy a spam-free comment section! 23 23 24 24 == Frequently Asked Questions == 25 25 26 Noone asked anything yet. 26 Q: Which Lightning payment processors are supported? 27 A: LNBits and BTCPayServer 28 29 Q: Which Lightning Network implementations are supported? 30 A: Both LNBits and BTCPayServer support almost all implementations (CLN, Eclair, LND)
Note: See TracChangeset
for help on using the changeset viewer.