Compare commits
135 commits
daemon-ins
...
master
Author | SHA1 | Date | |
---|---|---|---|
5bcdec98db | |||
510d6426ee | |||
794ad6af21 | |||
d34e241432 | |||
12332c65b6 | |||
524147d0a9 | |||
6d39f496d2 | |||
899e38d80a | |||
b405d5a0c7 | |||
0af8b712eb | |||
c1071c2477 | |||
eb42cfe3aa | |||
5ef5d1f68f | |||
c6f28b18ac | |||
04ad7a8746 | |||
31c66404f9 | |||
f09d446af1 | |||
148fd047d3 | |||
66df2ee020 | |||
a335d25206 | |||
d73d60a38e | |||
caa3b2e420 | |||
9acd398393 | |||
6199f2eb04 | |||
9231ae882e | |||
83874b5331 | |||
9a0a8350ad | |||
1464afec1e | |||
ca13ce8ae5 | |||
28da08d8c6 | |||
a1c0ac76a3 | |||
12251aed05 | |||
1e2083334d | |||
f2207821c1 | |||
0e736ef344 | |||
152aad9b8a | |||
099cdc6fdf | |||
3626ce993c | |||
2df40bee5f | |||
8d18e00a49 | |||
1acd7bda01 | |||
7eda9d0a48 | |||
a151701745 | |||
9472f35587 | |||
bc23888458 | |||
623ff37c6e | |||
dc483771f1 | |||
42f57fc8b2 | |||
b9117fc749 | |||
c65c7bc9a5 | |||
e54b3034d2 | |||
dd25f7ea57 | |||
a5b158e0ef | |||
adeae2303e | |||
c11b7e293f | |||
ed0864e205 | |||
592c3f9193 | |||
57f36cc0bc | |||
5b7d6036b9 | |||
a00f979bf3 | |||
13ed54206b | |||
388e1fb894 | |||
5809f72823 | |||
9149310a61 | |||
cb61208b12 | |||
1a9b881e61 | |||
21762aeedc | |||
a5a3e8372d | |||
03a86e63ac | |||
55c230b8fc | |||
8efe65a43c | |||
c37736a88a | |||
8ac66f71ab | |||
d04668ee91 | |||
e4513558fd | |||
ee92d4859a | |||
a1dc6319e2 | |||
557dd888fa | |||
6a1daab7c8 | |||
2c9379394f | |||
d6c9c4a55e | |||
f2e0c54e5e | |||
992be8ca0f | |||
c94a276a76 | |||
3e68befdc1 | |||
e66bc60c0e | |||
d8a818557c | |||
233856b67d | |||
558cf08965 | |||
d8cc3ff96f | |||
cc6b82ac9f | |||
025106fcd6 | |||
1245d0d9fb | |||
3368ffdfd7 | |||
bf183aac5a | |||
43929ecd17 | |||
9d2f01a37b | |||
87a0c132fa | |||
f35484d13e | |||
06fed9faf9 | |||
7eabd266d6 | |||
07a060eeaa | |||
908fb4c0cc | |||
b026f27485 | |||
c743030156 | |||
3980f60704 | |||
3f8d7413b9 | |||
e49670732c | |||
1226273a11 | |||
33fb30ccc9 | |||
9b6e6bd7f1 | |||
6657c8281a | |||
e894c3b6fc | |||
c89405bbd4 | |||
39170a3262 | |||
1795b57a1f | |||
056ee42d62 | |||
4b0e17bcf4 | |||
3aed9ece2e | |||
04e600a12d | |||
cb2239e403 | |||
1858cae047 | |||
18ac6106ed | |||
a7bc19c4d6 | |||
4f5371662a | |||
cf45ad030f | |||
eb5673502a | |||
c8860493bf | |||
2baa9426c0 | |||
9d1e4e4b8c | |||
0407104d71 | |||
441534fe9e | |||
94d4ff85a3 | |||
597ba0d364 | |||
9e65cf1a06 |
1
.gitignore
vendored
|
@ -4,6 +4,7 @@
|
|||
!*.*
|
||||
|
||||
.DS_Store
|
||||
.vscode/*
|
||||
|
||||
tmp/*
|
||||
logs/*
|
||||
|
|
101
README.md
|
@ -1,3 +1,100 @@
|
|||
Wordpress plugin for LBRY - automated posting to markdown files including images.
|
||||
# LBRYPress - Publish from WordPress to LBRY automatically
|
||||
|
||||
This Readme needs love.
|
||||
This plugin and README are in early development. Thank you for your patience.
|
||||
|
||||
![](https://spee.ch/c/lbry-press-cover.jpg)
|
||||
|
||||
## How it works
|
||||
The LBRYPress plugin communicates with the LBRY network via a locally installed SDK. This allows you to create a channel and then mirror any published posts to it. If there are images or GIFs in your post, they will be uploaded to spee.ch (our blockchain-based image sharing service) automatically during the publishing process. If you update a post, it will also be updated on LBRY.
|
||||
|
||||
## Downloading and installing the WordPress plugin
|
||||
First, install the LBRYPress plugin on WordPress.
|
||||
|
||||
1) Download the [zip file for this repository](https://github.com/lbryio/lbrypress/archive/master.zip).
|
||||
1) In WordPress, upload and install the plugin zip file from the WordPress admin dashboard. After activating, errors will show until the next steps are completed.
|
||||
1) LBRYPress is not currently working correctly with the WordPress block editor, try a plugin that reactivates the classic WP Editor screen. LBRYPress may work in the future with Gutenberg block editor.
|
||||
|
||||
## Downloading and installing LBRY
|
||||
This will step you through downloading the LBRY SDK, installing it, and running as a system service.
|
||||
|
||||
1) Download the latest LBRY SDK from our [releases page for your OS](https://github.com/lbryio/lbry-sdk/releases): `wget https://github.com/lbryio/lbry-sdk/releases/download/v0.86.1/lbrynet-linux.zip`
|
||||
1) Make a new directory in /opt named lbry: `mkdir /opt/lbry`
|
||||
1) You may need to install Unzip: `sudo apt get install unzip`
|
||||
1) Unzip the file here: `unzip lbrynet-linux.zip -d /opt/lbry`
|
||||
1) To get started, you can run the SDK manually at first. Open a new terminal, `cd /opt/lbry` and run: `./lbrynet start`
|
||||
Once you do this, the SDK will startup in the current session and sync with the blockchain. Open a new terminal to issue further commands.
|
||||
|
||||
### Install LBRY as system service (can skip this step for now)
|
||||
1) Create a file called lbrynet.service and insert it into `/etc/systemd/system/`:
|
||||
```
|
||||
[Unit]
|
||||
Description="LBRYnet daemon"
|
||||
After=network.target
|
||||
[Service]
|
||||
ExecStart=/opt/lbry/lbrynet start
|
||||
User=YOURUSERNAME
|
||||
Group=YOURUSERGROUP
|
||||
Restart=on-failure
|
||||
KillMode=process
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
1) Run `sudo systemctl daemon-reload`
|
||||
1) Start it with: `sudo service lbrynet start`. If you are already running LBRY in the background, issue a `lbrynet stop` command first.
|
||||
|
||||
## Funding and preparing your wallet
|
||||
LBRY will require LBRY Credits (LBC) for the channel creation and publishing process. You can send LBC to this instance from your LBRY app / lbry.tv using the Wallet page > Send Credits. If you need LBC, sign up for a [lbry.tv account](https://lbry.tv) or [email us](mailto:hello@lbry.com). After you send credits, they will be split into smaller amounts to facilitate the publishing process. You can also use an existing LBRY Desktop wallet/ channel by copying the default_wallet file into `~/.local/shared/lbry/lbryum/wallets`.
|
||||
|
||||
1) Go to the LBRYPress plugin page and find your wallet address:
|
||||
|
||||
![](/admin/images/wallet-address.jpg)
|
||||
|
||||
1) Copy this address and send at least a few credits to it. From the Desktop app/lbry.tv, go to the Wallet page > Send Credits.
|
||||
1) We will take the amount you deposited and split it up by a factor of 10. So if you deposited 10 LBC, you'd split it into 100: The decimal point is important, it will throw back an error without the structure of "10.0"
|
||||
1) Go to the LBRYnet Directory `cd /opt/lbry/`
|
||||
1) Run the command: `./lbrynet account fund --amount=10.0 --outputs=100`
|
||||
|
||||
## Setting up publishing
|
||||
Experimental: republishing of images in blog to LBRY: If images or GIFs are used in your posts, they should be reposted to as thumbnails similar to the upload process in the LBRY apps. This feature may not work correctly at this time.
|
||||
|
||||
**Please note: spee.ch channel creation is no longer available and that step can be skiped.**
|
||||
|
||||
1) Select the channel you wish as a **Default Publish Channel**. Can change later on a per-post basis.
|
||||
1) Select the **Default Publish License** you wish to use as your default.
|
||||
1) Enter 0.001 for **LBC per Publish** (later you can add more as a support if needed).
|
||||
1) Click **Save Settings**.
|
||||
|
||||
![](/admin/images/settings-tab.jpg)
|
||||
|
||||
## Setting up your blog publishing channel
|
||||
If you don't already have a channel, this process will create a channel in your local wallet where your blog posts will be published to. Any available channels will be listed at the top of the **Your Publishable Channels** section on the **Channels** tab.
|
||||
|
||||
1) Enter the channel you wish to create and publish under in **New Channel Name**.
|
||||
Your channel will be created with a single @ prefix and all spaces and underscores are changed to a dash. Uppercase characters are allowed. Most special characters are removed.
|
||||
1) Enter an **Amount of LBC to Bid** of 0.001 (current minimum, you can increase the amount or use supports later).
|
||||
By adding as a support you push your content higher in the search but also keep your LBC fluid and easily moved without needing to abandon your claim.
|
||||
1) Click **Add New Channel**.
|
||||
|
||||
![](/admin/images/add-channel.jpg)
|
||||
|
||||
![](/admin/images/channel-create-success.jpg)
|
||||
|
||||
Wait a few minutes and do a page refresh, your new channel should now be in the list.
|
||||
|
||||
![](/admin/images/new-channel.jpg)
|
||||
|
||||
## Publishing blog posts
|
||||
When creating a new post (or editing an existing one), you can choose to publish it on LBRY as well. If you do this for an existing post, it will not retain the original date (known issue).
|
||||
|
||||
1) Create your post.
|
||||
1) At the bottom of the Document menu, find **LBRY Network**, and click **Sync this post on channel**.
|
||||
1) Select the channel you want to publish it on.
|
||||
1) Click Publish.
|
||||
1) The plugin will automatically add a link to content on LBRY.
|
||||
1) Give it a few minutes to publish and be confirmed on the network (there's currently no feedback for this). Check your content at: https://lbry.tv/@ChannelName.
|
||||
|
||||
If you edit a post, it will also create an update on the LBRY network.
|
||||
|
||||
## Need help?
|
||||
Email us at [hello@lbry.com](mailto:hello@lbry.com) if you need assistance setting up the LBRYPress plugin.
|
||||
|
|
2
admin/css/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
121
admin/css/lbry-admin.css
Normal file
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* Stylesheet for the admin pages LBRYPress uses
|
||||
* @package LBRYPress
|
||||
*/
|
||||
|
||||
.wallet-icon-lbc {
|
||||
height: 1.8em;
|
||||
margin-right: .5em;
|
||||
margin-bottom: -.5em;
|
||||
}
|
||||
|
||||
.bid-icon-lbc {
|
||||
height: 1.2em;
|
||||
margin-bottom: -.2em;
|
||||
}
|
||||
|
||||
.channel-bid-icon-lbc {
|
||||
height: 1.1em;
|
||||
margin-right: .1em;
|
||||
margin-bottom: -.2em;
|
||||
}
|
||||
|
||||
.lbry-pub-metabox {
|
||||
margin: 0 0 0 -.2em;
|
||||
padding: 0 .2em 0 0 ;
|
||||
}
|
||||
.meta-icon-lbry {
|
||||
height: 1.55em;
|
||||
margin-bottom: -.4em;
|
||||
padding: 0 .1em 0 0;
|
||||
}
|
||||
.lbry-meta-checkbox-wrapper {
|
||||
padding: .5em .8em .6em;
|
||||
}
|
||||
|
||||
.lbry-meta-wrapper-last {
|
||||
padding: 0em .8em 1.5em;
|
||||
}
|
||||
|
||||
.lbry-meta-label {
|
||||
padding: .3em .6em .6em .1em;
|
||||
/* padding-left: .3em;
|
||||
padding-right: .6em;
|
||||
padding-bottom: .5em; */
|
||||
}
|
||||
|
||||
.lbry-meta-bx-label {
|
||||
margin: .5em .8em .6em;
|
||||
}
|
||||
|
||||
.lbry-meta-bx-option {
|
||||
padding: .5em .8em .6em;
|
||||
}
|
||||
|
||||
.lbry-meta-bx-option-last {
|
||||
padding: .5em .8em 1.5em;
|
||||
}
|
||||
|
||||
.lbry-hr-meta {
|
||||
margin-left: 1em;
|
||||
margin-right: 1em;
|
||||
}
|
||||
.post-lbry-display-before {
|
||||
color: green;
|
||||
}
|
||||
.post-lbry-display {
|
||||
color: #135548;
|
||||
}
|
||||
|
||||
.lbry-pub-metabox {
|
||||
margin: 0;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.lbry-claim-id-metabox {
|
||||
margin: 0;
|
||||
padding-top: .3em;
|
||||
font-size: .85em;
|
||||
line-height: 1em;
|
||||
}
|
||||
|
||||
.lbry-meta-bx-content {
|
||||
padding: .2em .8em .6em .1em;
|
||||
}
|
||||
|
||||
.lbry-meta-bx-content-last {
|
||||
padding: .2em .8em 1em .1em;
|
||||
}
|
||||
/*---------------------
|
||||
Channels Table
|
||||
-------------------*/
|
||||
table.lbry-channel-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-family: Georgia;
|
||||
}
|
||||
.lbry-channel-table th, .lbry-channel-table td {
|
||||
padding: .4em 1.6em;
|
||||
border: 2px solid #fff;
|
||||
background: #97eb9d;
|
||||
font-size: 1em;
|
||||
}
|
||||
.lbry-channel-table thead th {
|
||||
padding: .5em 2em;
|
||||
background: #135548;
|
||||
text-align: left;
|
||||
font-weight: normal;
|
||||
font-size: 1.2em;
|
||||
color: #fff;
|
||||
}
|
||||
.lbry-channel-table tbody tr:nth-child(odd) td {
|
||||
background: #e1fafa;
|
||||
}
|
||||
.lbry-channel-table tfoot th {
|
||||
padding: .5em 1.8em;
|
||||
background: #175248;
|
||||
text-align: left;
|
||||
font-weight: normal;
|
||||
font-size: .9em;
|
||||
color: #fff;
|
||||
}
|
BIN
admin/images/add-channel.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
admin/images/channel-create-success.jpg
Normal file
After Width: | Height: | Size: 6.1 KiB |
2
admin/images/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
BIN
admin/images/lbc.png
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
admin/images/lbry-icon.png
Normal file
After Width: | Height: | Size: 654 B |
BIN
admin/images/lbry.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
admin/images/new-channel.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
admin/images/settings-tab.jpg
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
admin/images/speech-tab.jpg
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
admin/images/wallet-address.jpg
Normal file
After Width: | Height: | Size: 31 KiB |
2
admin/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
56
admin/js/admin-image-uploader.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
jQuery( document ).ready( function( $ ) {
|
||||
|
||||
// Uploading files
|
||||
var file_frame;
|
||||
var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
|
||||
var set_to_post_id = 10; // Set this
|
||||
|
||||
jQuery('#lbry_upload_thumbnail_button').on('click', function( event ){
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// If the media frame already exists, reopen it.
|
||||
if ( file_frame ) {
|
||||
// Set the post ID to what we want
|
||||
file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
|
||||
// Open frame
|
||||
file_frame.open();
|
||||
return;
|
||||
} else {
|
||||
// Set the wp.media post id so the uploader grabs the ID we want when initialised
|
||||
wp.media.model.settings.post.id = set_to_post_id;
|
||||
}
|
||||
|
||||
// Create the media frame.
|
||||
file_frame = wp.media.frames.file_frame = wp.media({
|
||||
title: jQuery( this ).data( 'uploader_title' ),
|
||||
button: {
|
||||
text: jQuery( this ).data( 'uploader_button_text' ),
|
||||
},
|
||||
multiple: true // Set to true to allow multiple files to be selected
|
||||
});
|
||||
|
||||
// When an image is selected, run a callback.
|
||||
file_frame.on( 'select', function() {
|
||||
// We set multiple to false so only get one image from the uploader
|
||||
attachment = file_frame.state().get('selection').first().toJSON();
|
||||
|
||||
// Do something with attachment.id and/or attachment.url here
|
||||
$( '#thumbnail-preview' ).attr( 'src', attachment.url ).css( 'width', 'auto' );
|
||||
$( '#lbry_thumbnail_attachment_id' ).val( attachment.id );
|
||||
$( '#lbry_upload_thumbnail_button' ).css( 'display', 'none' );
|
||||
$( '.channel-image-info' ).css( 'display', 'none' );
|
||||
|
||||
// Restore the main post ID
|
||||
wp.media.model.settings.post.id = wp_media_post_id;
|
||||
});
|
||||
|
||||
// Finally, open the modal
|
||||
file_frame.open();
|
||||
});
|
||||
|
||||
// Restore the main ID when the add media button is pressed
|
||||
jQuery('a.add_media').on('click', function() {
|
||||
wp.media.model.settings.post.id = wp_media_post_id;
|
||||
});
|
||||
});
|
2
admin/js/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
83
admin/js/table-sort.js
Normal file
|
@ -0,0 +1,83 @@
|
|||
jQuery(document).ready(function($) {
|
||||
var compare = {
|
||||
channel: function(a, b) {
|
||||
a = a.replace(/^@/i, '') && a.replace(/[-]/gi, '');
|
||||
b = b.replace(/^@/i, '') && b.replace(/[-]/gi, '');
|
||||
|
||||
if (a < b) {
|
||||
return -1;
|
||||
} else {
|
||||
return a > b ? 1 : 0;
|
||||
}
|
||||
},
|
||||
lbryurl: function(a, b) {
|
||||
a = a.replace(/^lbry:\/\/@/i, '') && a.replace(/#[a-zA-Z0-9]+/, '') && a.replace(/-/g, '');
|
||||
b = b.replace(/^lbry:\/\/@/i, '') && b.replace(/#[a-zA-Z0-9]+/, '') && b.replace(/-/g, '');
|
||||
|
||||
if (a < b) {
|
||||
return -1;
|
||||
} else {
|
||||
return a > b ? 1 : 0;
|
||||
}
|
||||
},
|
||||
claim: function(a, b) {
|
||||
if (a < b) {
|
||||
return -1;
|
||||
} else {
|
||||
return a > b ? 1 : 0;
|
||||
}
|
||||
},
|
||||
posts: function(a, b) {
|
||||
a = Number(a);
|
||||
b = Number(b);
|
||||
|
||||
return a - b;
|
||||
},
|
||||
support: function(a, b) {
|
||||
a = a.replace(/,/g, '');
|
||||
b = b.replace(/,/g, '');
|
||||
|
||||
a = Number(a);
|
||||
b = Number(b);
|
||||
|
||||
return a - b;
|
||||
},
|
||||
date: function(a, b) {
|
||||
a = new Date(a);
|
||||
b = new Date(b);
|
||||
|
||||
return a - b;
|
||||
}
|
||||
};
|
||||
$('.lbry-channel-table').each(function() {
|
||||
var $table = $(this);
|
||||
var $tbody = $table.find('tbody');
|
||||
var $controls = $table.find('th');
|
||||
var rows = $tbody.find('tr').toArray();
|
||||
|
||||
$controls.on('click', function() {
|
||||
var $header = $(this);
|
||||
var order = $header.data('sort');
|
||||
var column;
|
||||
|
||||
if ($header.is('.ascending') || $header.is('.descending')) {
|
||||
$header.toggleClass('ascending descending');
|
||||
$tbody.append(rows.reverse());
|
||||
} else {
|
||||
$header.addClass('ascending');
|
||||
$header.siblings().removeClass('ascending descending');
|
||||
if (compare.hasOwnProperty(order)) {
|
||||
column = $controls.index(this);
|
||||
|
||||
rows.sort(function(a, b) {
|
||||
a = $(a).find('td').eq(column).text();
|
||||
b = $(b).find('td').eq(column).text();
|
||||
return compare[order](a, b);
|
||||
});
|
||||
|
||||
$tbody.append(rows);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
2
bin/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRYPress
|
||||
{
|
||||
|
@ -107,11 +108,12 @@ class LBRYPress
|
|||
$this->define('LBRY_VERSION', $this->version);
|
||||
|
||||
// Library Options Names
|
||||
$this->define('LBRY_SETTINGS_GROUP', 'lbry_settings_group');
|
||||
//$this->define('LBRY_SETTINGS_GROUP', 'lbry_settings_group');
|
||||
$this->define('LBRY_SETTINGS', 'lbry_settings');
|
||||
$this->define('LBRY_SETTINGS_SECTION_GENERAL', 'lbry_settings_section_general');
|
||||
$this->define('LBRY_ADMIN_PAGE', 'lbrypress');
|
||||
$this->define('LBRY_WALLET', 'lbry_wallet'); // the wallet address
|
||||
$this->define('LBRY_SPEECH_SETTINGS', 'lbry_speech_settings');
|
||||
$this->define('LBRY_SPEECH', 'lbry_speech'); // the spee.ch address
|
||||
$this->define('LBRY_SPEECH_CHANNEL', 'lbry_speech_channel'); // The spee.ch channel
|
||||
$this->define('LBRY_SPEECH_PW', 'lbry_speech_pw'); // The password for the spee.ch channel
|
||||
|
@ -119,6 +121,8 @@ class LBRYPress
|
|||
$this->define('LBRY_LBC_PUBLISH', 'lbry_lbc_publish'); // amount of lbc to use per publish
|
||||
$this->define('LBRY_WILL_PUBLISH', '_lbry_will_publish'); // The meta key for if to publish to LBRY Network or not
|
||||
$this->define('LBRY_POST_CHANNEL', '_lbry_channel'); // The meta key for which channel to publish
|
||||
$this->define('LBRY_POST_PUB_CHANNEL', '_lbry_post_pub_channel'); // The meta key for which channel to publish on
|
||||
$this->define('LBRY_POST_PUB_LICENSE', '_lbry_post_pub_license'); // The meta key for which license to publish on
|
||||
$this->define('LBRY_CLAIM_ID', '_lbry_claim_id'); // The Claim ID for the post as it was published on LBRY
|
||||
$this->define('LBRY_CANONICAL_URL', '_lbry_canonical_url'); // The canonical url for the published lbry post
|
||||
$this->define('LBRY_SPEECH_ASSET_URL', 'speech_asset_url'); // The meta key for an asset's speech url
|
||||
|
@ -160,6 +164,7 @@ class LBRYPress
|
|||
{
|
||||
register_activation_hook( LBRY_PLUGIN_FILE, array( $this, 'activate' ) );
|
||||
register_deactivation_hook( LBRY_PLUGIN_FILE, array( $this, 'deactivate' ) );
|
||||
add_filter( 'kses_allowed_protocols' , array( $this, 'lbry_add_additional_protocols' ) );
|
||||
|
||||
// Banner output for published posts
|
||||
// NOTE: move this to its own class to reduce clutter?
|
||||
|
@ -182,14 +187,26 @@ class LBRYPress
|
|||
|
||||
//Default options
|
||||
$option_defaults = array(
|
||||
LBRY_SPEECH => null,
|
||||
LBRY_LICENSE => $this->licenses[0],
|
||||
LBRY_LBC_PUBLISH => 1
|
||||
LBRY_WALLET => '',
|
||||
'lbry_default_publish_setting' => '',
|
||||
'default_lbry_channel' => '',
|
||||
LBRY_LICENSE => '',
|
||||
LBRY_LBC_PUBLISH => 0.001,
|
||||
);
|
||||
|
||||
add_option( LBRY_SETTINGS, $option_defaults, false );
|
||||
}
|
||||
|
||||
if ( ! get_option( LBRY_SPEECH_SETTINGS ) ) {
|
||||
// Default Speech Settings
|
||||
$option_defaults = array(
|
||||
LBRY_SPEECH =>'',
|
||||
LBRY_SPEECH_CHANNEL => '',
|
||||
LBRY_SPEECH_PW => '',
|
||||
);
|
||||
add_option( LBRY_SPEECH_SETTINGS, $option_defaults, false );
|
||||
}
|
||||
|
||||
// COMBAK: decide if we need to check for missing or corrupt settings. May be unecessary.
|
||||
// Double check we have all settings, if not, update with default
|
||||
// $current_settings = get_option(LBRY_SETTINGS);
|
||||
|
@ -211,6 +228,19 @@ class LBRYPress
|
|||
error_log( 'Deactivated LBRYPress' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowing additional URL protocols to list of allowed protocols.
|
||||
*
|
||||
* @param array $protocols List of protocols allowed by (default WordPress.)
|
||||
*
|
||||
* @return array $protocols Updated list including additional protocols.
|
||||
*/
|
||||
public function lbry_add_additional_protocols( $protocols )
|
||||
{
|
||||
$protocols[] = 'lbry';
|
||||
return $protocols;
|
||||
}
|
||||
|
||||
public function published_on_lbry_banner($content)
|
||||
{
|
||||
if ( ! is_single() || ! in_the_loop() || ! is_main_query() ) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Admin
|
||||
{
|
||||
|
@ -18,6 +19,8 @@ class LBRY_Admin
|
|||
add_action('admin_init', array($this, 'page_init'));
|
||||
add_action('admin_init', array($this, 'wallet_balance_warning'));
|
||||
add_action('admin_post_lbry_add_channel', array($this, 'add_channel'));
|
||||
add_action('admin_post_lbry_add_supports', array($this, 'add_supports'));
|
||||
add_action('admin_post_lbry_edit_channel', array($this, 'edit_channel'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,14 +28,84 @@ class LBRY_Admin
|
|||
*/
|
||||
public function create_options_page()
|
||||
{
|
||||
|
||||
add_menu_page(
|
||||
__( 'LBRYPress Settings', 'lbrypress' ),
|
||||
__( 'LBRYPress', 'lbrypress' ),
|
||||
'manage_options',
|
||||
LBRY_ADMIN_PAGE,
|
||||
array( $this, 'options_page_html' ),
|
||||
plugin_dir_url(LBRY_PLUGIN_FILE) . '/admin/images/lbry-logo.svg'
|
||||
plugin_dir_url( LBRY_PLUGIN_FILE ) . '/admin/images/lbry-icon.png'
|
||||
);
|
||||
|
||||
// Admin stylesheet enqueue
|
||||
function load_admin_stylesheet( $hook ) {
|
||||
|
||||
if ( ( $hook == 'post.php' ) || ( $hook == 'post-new.php' ) || ( $_GET['page'] == 'lbrypress' ) ) {
|
||||
wp_enqueue_style(
|
||||
'lbry-admin',
|
||||
plugins_url( '/admin/css/lbry-admin.css', LBRY_PLUGIN_FILE ),
|
||||
array(),
|
||||
LBRY_VERSION,
|
||||
'all'
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_enqueue_scripts', 'load_admin_stylesheet' );
|
||||
|
||||
// Admin channel sort JS enqueue
|
||||
function load_channel_sort_script() {
|
||||
if ( ( $_GET['page'] == 'lbrypress') && ( $_GET['tab'] == 'channels' ) ) {
|
||||
wp_enqueue_script(
|
||||
'lbry-table-sort',
|
||||
plugins_url( '/admin/js/table-sort.js', LBRY_PLUGIN_FILE ),
|
||||
array('jquery'),
|
||||
LBRY_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_enqueue_scripts', 'load_channel_sort_script' );
|
||||
|
||||
// Admin Media Upload on Edit Channel tab
|
||||
function load_channel_edit_media_scripts() {
|
||||
if ( ( $_GET['page'] == 'lbrypress' ) && ( $_GET['tab'] == 'channel-edit' ) ) {
|
||||
wp_enqueue_media();
|
||||
wp_enqueue_script(
|
||||
'lbry-media-upload',
|
||||
plugins_url( '/admin/js/admin-image-uploader.js', LBRY_PLUGIN_FILE ),
|
||||
array( 'jquery' ),
|
||||
LBRY_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_enqueue_scripts', 'load_channel_edit_media_scripts' );
|
||||
|
||||
// Admin Error Notices
|
||||
function lbry_plugin_not_configured_notice() {
|
||||
echo "<div id='notice' class='updated fade'><p>LBRYPress plugin is not configured yet. Please do it now.</p></div>\n";
|
||||
}
|
||||
$lbry_wallet = get_option('lbry_wallet');
|
||||
if ( ! isset($lbry_wallet) ) {
|
||||
add_action( 'admin_notices', 'lbry_plugin_not_configured_notice' );
|
||||
}
|
||||
function admin_permission_check() {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Options Page HTML for the plugin
|
||||
*/
|
||||
public function options_page_html()
|
||||
{
|
||||
// Set class properties to be referenced in callbacks
|
||||
$this->options = get_option( LBRY_SETTINGS );
|
||||
$this->options_speech = get_option( LBRY_SPEECH_SETTINGS );
|
||||
require_once( LBRY_ABSPATH . 'templates/options-page.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,13 +114,17 @@ class LBRY_Admin
|
|||
public function page_init()
|
||||
{
|
||||
// Register the LBRY Setting array
|
||||
register_setting(LBRY_SETTINGS_GROUP, LBRY_SETTINGS, array('sanitize_callback' => array($this, 'sanitize')));
|
||||
register_setting(
|
||||
'lbry_general_settings',
|
||||
LBRY_SETTINGS,
|
||||
array( $this, 'sanitize_general_settings' )
|
||||
);
|
||||
|
||||
// Add Required Settings Sections
|
||||
add_settings_section(
|
||||
LBRY_SETTINGS_SECTION_GENERAL, // ID
|
||||
'General Settings', // Title
|
||||
array( $this, 'general_section_info' ), // Callback
|
||||
array( $this, 'general_section_callback' ), // Callback
|
||||
LBRY_ADMIN_PAGE // Page
|
||||
);
|
||||
|
||||
|
@ -61,25 +138,17 @@ class LBRY_Admin
|
|||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH,
|
||||
'Spee.ch URL',
|
||||
array( $this, 'speech_callback' ),
|
||||
'lbry_default_publish_setting',
|
||||
'Always Publish to LBRY',
|
||||
array( $this, 'lbry_always_pub_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_CHANNEL,
|
||||
'Spee.ch Channel',
|
||||
array( $this, 'speech_channel_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_PW,
|
||||
'Spee.ch Password',
|
||||
array( $this, 'speech_pw_callback' ),
|
||||
'default_lbry_channel',
|
||||
'Default Publish Channel',
|
||||
array( $this, 'default_channel_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
@ -95,55 +164,136 @@ class LBRY_Admin
|
|||
add_settings_field(
|
||||
LBRY_LBC_PUBLISH,
|
||||
'LBC Per Publish',
|
||||
array( $this, 'lbc_publish_callback' ),
|
||||
array( $this, 'lbc_per_publish_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Options Page HTML for the plugin
|
||||
* Channel Page Settings
|
||||
* We are using a custom page so that we can use the admin-post action and retrieve the $_POST
|
||||
* global variable to populate the cURL request to create_channel, not saving the inputs to
|
||||
* our database.
|
||||
*/
|
||||
public function options_page_html()
|
||||
{
|
||||
// Set class property to be referenced in callbacks
|
||||
$this->options = get_option(LBRY_SETTINGS);
|
||||
require_once(LBRY_ABSPATH . 'templates/options_page.php');
|
||||
|
||||
|
||||
/**
|
||||
* Speech Admin Page settings
|
||||
*/
|
||||
|
||||
register_setting(
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
array( $this, 'sanitize_speech_settings' )
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'lbry_settings_section_speech', // ID
|
||||
'Spee.ch Channel Settings', // Title
|
||||
array( $this, 'speech_section_callback' ), // Callback
|
||||
'lbrypress-speech' // Page
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH,
|
||||
'Spee.ch URL',
|
||||
array( $this, 'speech_callback' ),
|
||||
'lbrypress-speech',
|
||||
'lbry_settings_section_speech'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_CHANNEL,
|
||||
'Spee.ch Channel',
|
||||
array( $this, 'speech_channel_callback' ),
|
||||
'lbrypress-speech',
|
||||
'lbry_settings_section_speech'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_PW,
|
||||
'Spee.ch Password',
|
||||
array( $this, 'speech_pw_callback' ),
|
||||
'lbrypress-speech',
|
||||
'lbry_settings_section_speech'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes setting input
|
||||
* // COMBAK Potentially sanitize more
|
||||
*/
|
||||
public function sanitize($input)
|
||||
|
||||
public function sanitize_general_settings( $input )
|
||||
{
|
||||
if (!empty($input[LBRY_SPEECH_CHANNEL])) {
|
||||
$new_input = get_option( LBRY_SETTINGS ); // get saved data
|
||||
|
||||
if ( isset( $input[LBRY_WALLET] ) ) {
|
||||
$new_input[LBRY_WALLET] = sanitize_text_field( $input[LBRY_WALLET] );
|
||||
}
|
||||
$new_input['lbry_default_publish_setting'] = $input['lbry_default_publish_setting'];
|
||||
|
||||
if ( isset( $input['default_lbry_channel'] ) ) {
|
||||
$new_input['default_lbry_channel'] = sanitize_text_field( $input['default_lbry_channel'] );
|
||||
}
|
||||
$license_array = LBRY()->licenses;
|
||||
if ( isset( $input[LBRY_LICENSE] ) && ( in_array( $input[LBRY_LICENSE], $license_array ) ) ) {
|
||||
$new_input[LBRY_LICENSE] = sanitize_text_field( $input[LBRY_LICENSE] );
|
||||
}
|
||||
if ( isset( $input[LBRY_LBC_PUBLISH] ) ) {
|
||||
$new_input[LBRY_LBC_PUBLISH] = number_format( floatval( $input[LBRY_LBC_PUBLISH] ), 3, '.', '' );
|
||||
}
|
||||
return $new_input;
|
||||
}
|
||||
|
||||
public function sanitize_speech_settings( $input )
|
||||
{
|
||||
$new_input = get_option( LBRY_SPEECH_SETTINGS );
|
||||
if ( isset( $input[LBRY_SPEECH] ) ) {
|
||||
$new_input[LBRY_SPEECH] = sanitize_text_field( $input[LBRY_SPEECH] );
|
||||
}
|
||||
if ( isset( $input[LBRY_SPEECH_CHANNEL] ) ) {
|
||||
$channel = $input[LBRY_SPEECH_CHANNEL];
|
||||
$channel = str_replace( '@', '', $channel );
|
||||
$input[LBRY_SPEECH_CHANNEL] = $channel;
|
||||
$new_input[LBRY_SPEECH_CHANNEL] = sanitize_user( $channel );
|
||||
}
|
||||
|
||||
if (!empty($input[LBRY_SPEECH_PW])) {
|
||||
$encrypted = $this->encrypt($input['lbry_speech_pw']);
|
||||
$input[LBRY_SPEECH_PW] = $encrypted;
|
||||
if ( isset( $input[LBRY_SPEECH_PW] ) ) {
|
||||
$input[LBRY_SPEECH_PW] = sanitize_text_field( $input[LBRY_SPEECH_PW] );
|
||||
$encrypted = $this->encrypt( $input[LBRY_SPEECH_PW] );
|
||||
$new_input[LBRY_SPEECH_PW] = $encrypted;
|
||||
} else {
|
||||
// If we have a password and its empty, keep orginal password
|
||||
if (!empty(get_option(LBRY_SETTINGS)[LBRY_SPEECH_PW])) {
|
||||
$input[LBRY_SPEECH_PW] = get_option(LBRY_SETTINGS)[LBRY_SPEECH_PW];
|
||||
// If we have a password and it's empty, keep original password
|
||||
if ( empty( $input[LBRY_SPEECH_PW] ) )
|
||||
$new_input[LBRY_SPEECH_PW] = get_option( LBRY_SPEECH_SETTINGS[LBRY_SPEECH_PW] );
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
return $new_input;
|
||||
update_option( LBRY_SPEECH_SETTINGS, $new_input );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section info for the General Section
|
||||
*/
|
||||
public function general_section_info()
|
||||
public function general_section_callback()
|
||||
{
|
||||
print 'This is where you can configure how LBRYPress will distribute your content:';
|
||||
}
|
||||
|
||||
/**
|
||||
* Section info for the Available Channel(s) Section
|
||||
*/
|
||||
public function available_channels_callback()
|
||||
{
|
||||
// Moved to channels-page.php
|
||||
}
|
||||
|
||||
/**
|
||||
* Section info for the Speech Channel Section
|
||||
*/
|
||||
public function speech_section_callback()
|
||||
{
|
||||
print 'If you have a Spee.ch account, you can enter your account details here, if you don\'t already have a Spee.ch account, no need to enter anything here.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Wallet input
|
||||
*/
|
||||
|
@ -153,7 +303,7 @@ class LBRY_Admin
|
|||
$address = LBRY()->daemon->address_list();
|
||||
$address = is_array( $address ) && ! empty( $address ) ? $address[0]->address : '';
|
||||
printf(
|
||||
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" readonly />',
|
||||
'<input type="text" id="'. esc_attr('%1$s') .'" name="'. esc_attr('%2$s[%1$s]') .'" value="' . esc_attr('%3$s') . '" readonly />',
|
||||
LBRY_WALLET,
|
||||
LBRY_SETTINGS,
|
||||
$address
|
||||
|
@ -161,41 +311,50 @@ class LBRY_Admin
|
|||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch input
|
||||
* Checkbox to default to always allow publish on LBRY
|
||||
*/
|
||||
public function speech_callback()
|
||||
public function lbry_always_pub_callback()
|
||||
{
|
||||
$options = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'];
|
||||
if ( ! isset( $options ) ) {
|
||||
$options = 0;
|
||||
}
|
||||
$checked = checked( $options, 1, false );
|
||||
printf(
|
||||
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" placeholder="https://your-speech-address.com"/>',
|
||||
LBRY_SPEECH,
|
||||
'<input type="checkbox" id="lbry_default_publish_setting" name="' . esc_attr('%2$s[%1$s]') . '" value="1" ' . esc_attr( $checked ) . '><p>Set Default to always Publish to <strong>LBRY</strong>, this can be adjusted when publishing a New Post.</p>',
|
||||
'lbry_default_publish_setting',
|
||||
LBRY_SETTINGS,
|
||||
isset($this->options[LBRY_SPEECH]) ? esc_attr($this->options[LBRY_SPEECH]) : ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch channel input
|
||||
* Prints select to choose a default to publish to channel
|
||||
*/
|
||||
public function speech_channel_callback()
|
||||
public function default_channel_callback()
|
||||
{
|
||||
printf(
|
||||
'<span>@</span><input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" placeholder="your-channel"/>',
|
||||
LBRY_SPEECH_CHANNEL,
|
||||
LBRY_SETTINGS,
|
||||
isset($this->options[LBRY_SPEECH_CHANNEL]) ? esc_attr($this->options[LBRY_SPEECH_CHANNEL]) : ''
|
||||
);
|
||||
$options = '';
|
||||
$channel_list = LBRY()->daemon->channel_list();
|
||||
|
||||
if ( $channel_list ) {
|
||||
foreach ( $channel_list as $channel ) {
|
||||
$selected = $this->options['default_lbry_channel'] === $channel->claim_id;
|
||||
|
||||
$options .= '<option value="' . esc_attr( $channel->claim_id ) . '"';
|
||||
if ( $selected ) {
|
||||
$options .= ' selected';
|
||||
}
|
||||
$options .= '>' . esc_html( $channel->name ) . '</option>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch password input
|
||||
*/
|
||||
public function speech_pw_callback()
|
||||
{
|
||||
printf(
|
||||
'<input type="password" id="%1$s" name="%2$s[%1$s]" value="" placeholder="Leave empty for same password"',
|
||||
LBRY_SPEECH_PW,
|
||||
LBRY_SETTINGS
|
||||
'<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '">' . esc_html('%3$s') . '</select>',
|
||||
'default_lbry_channel',
|
||||
LBRY_SETTINGS,
|
||||
$options
|
||||
);
|
||||
} else { ?>
|
||||
<p>Looks like you haven't added any channels yet, you can do that now on the <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) ) ); ?>" class="">Channels Tab</a></p>
|
||||
<?php }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,7 +377,7 @@ class LBRY_Admin
|
|||
}
|
||||
|
||||
printf(
|
||||
'<select id="%1$s" name="%2$s[%1$s]">%3$s</select>',
|
||||
'<select id="'.esc_attr('%1$s').'" name="'. esc_attr('%2$s[%1$s]') .'">' . esc_html('%3$s') . '</select>',
|
||||
LBRY_LICENSE,
|
||||
LBRY_SETTINGS,
|
||||
$options
|
||||
|
@ -228,13 +387,60 @@ class LBRY_Admin
|
|||
/**
|
||||
* Prints LBC per publish input
|
||||
*/
|
||||
public function lbc_publish_callback()
|
||||
public function lbc_per_publish_callback()
|
||||
{
|
||||
printf(
|
||||
'<input type="number" id="%1$s" name="%2$s[%1$s]" value="%3$s" min="0.01" step="0.01"/>',
|
||||
'<input type="number" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '" value="' . esc_attr('%3$.3f') . '" min="0.001" step="0.001"><p>Current minimum bid <img src="' . esc_attr('%4$s ') . '" class="icon icon-lbc bid-icon-lbc"> 0.001</p>',
|
||||
LBRY_LBC_PUBLISH,
|
||||
LBRY_SETTINGS,
|
||||
$this->options[LBRY_LBC_PUBLISH]
|
||||
$this->options[LBRY_LBC_PUBLISH],
|
||||
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Channels Page
|
||||
* Channels page uses admin.php so we are able to use the admin-post action instead of options.php
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prints Spee.ch input
|
||||
*/
|
||||
public function speech_callback()
|
||||
{
|
||||
$options = get_option( LBRY_SPEECH_SETTINGS );
|
||||
printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '" value="' . esc_attr('%3$s') . '" placeholder="https://your-speech-address.com">',
|
||||
LBRY_SPEECH,
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
isset( $options[LBRY_SPEECH] ) ? $options[LBRY_SPEECH] : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch channel input
|
||||
*/
|
||||
public function speech_channel_callback()
|
||||
{
|
||||
$options = get_option( LBRY_SPEECH_SETTINGS );
|
||||
printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '" value="@' . esc_attr('%3$s') . '" placeholder="your-speech-channel">',
|
||||
LBRY_SPEECH_CHANNEL,
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
isset( $options[LBRY_SPEECH_CHANNEL] ) ? $options[LBRY_SPEECH_CHANNEL] : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch password input
|
||||
*/
|
||||
public function speech_pw_callback()
|
||||
{
|
||||
printf(
|
||||
'<input type="password" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '" placeholder="Leave empty for same password">',
|
||||
LBRY_SPEECH_PW,
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -243,26 +449,138 @@ class LBRY_Admin
|
|||
*/
|
||||
public function add_channel()
|
||||
{
|
||||
$redirect_url = admin_url('options-general.php?page=' . LBRY_ADMIN_PAGE);
|
||||
|
||||
$redirect_url = admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) );
|
||||
|
||||
// Check that nonce
|
||||
if (! isset($_POST['_lbrynonce']) || ! wp_verify_nonce($_POST['_lbrynonce'], 'lbry_add_channel')) {
|
||||
LBRY()->notice->set_notice('error');
|
||||
} elseif (! isset($_POST['new_channel']) || ! isset($_POST['bid_amount'])) {
|
||||
if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'add_channel_nonce' ) ) {
|
||||
if ( empty( $_POST['lbry_new_channel'] ) || empty( $_POST['lbry_channel_bid_amount'] ) ) {
|
||||
LBRY()->notice->set_notice( 'error', 'Must supply both channel name and bid amount' );
|
||||
} else {
|
||||
$new_channel = $_POST['new_channel'];
|
||||
$bid_amount = $_POST['bid_amount'];
|
||||
} elseif ( isset( $_POST['lbry_new_channel'] ) && isset( $_POST['lbry_channel_bid_amount'] ) ) {
|
||||
$channel = $_POST['lbry_new_channel']; // TODO: sanitize key() only allows for lowercase chars, dashes, and underscores. maybe remove to allow more characters? and use something else for better control?
|
||||
$channel = trim( $channel );
|
||||
$channel = str_replace( '@', '', $channel );
|
||||
$channel = str_replace( ' ', '-', $channel );
|
||||
$channel = str_replace( '_', '-', $channel );
|
||||
$channel_name = sanitize_user( $channel );
|
||||
|
||||
$bid = $_POST['lbry_channel_bid_amount'];
|
||||
$channel_bid = number_format( floatval( $bid ), 3, '.', '' );
|
||||
|
||||
// Try to add the new channel
|
||||
try {
|
||||
$result = LBRY()->daemon->channel_new($new_channel, $bid_amount);
|
||||
$result = LBRY()->daemon->channel_new( $channel_name, $channel_bid );
|
||||
// Tell the user it takes some time to go through
|
||||
LBRY()->notice->set_notice('success', 'Successfully added a new channel! Please wait a few minutes for the bid to process.', true);
|
||||
LBRY()->notice->set_notice(
|
||||
'success', 'Successfully added a new channel: @' . esc_html( $channel_name ) . '! Please allow a few minutes for the bid to process.', true );
|
||||
|
||||
} catch ( \Exception $e ) {
|
||||
LBRY()->notice->set_notice( 'error', $e->getMessage(), false );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LBRY()->notice->set_notice('error', 'Security check failed' );
|
||||
die( __( 'Security check failed', 'lbrypress' ) );
|
||||
}
|
||||
|
||||
wp_safe_redirect( $redirect_url );
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles adding supports form submission
|
||||
*/
|
||||
public function add_supports()
|
||||
{
|
||||
if ( ( $_POST['post_id'] ) && ( absint( $_POST['post_id'] ) ) ) {
|
||||
$redirect_url = admin_url( add_query_arg( array( 'post' => $_POST['post_id'], 'action' => 'edit' ), 'post.php') );
|
||||
} else {
|
||||
$redirect_url = admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) );
|
||||
}
|
||||
if ( ( $_POST['lbry_url'] ) ? $lbry_url = urldecode($_POST['lbry_url']) : $lbry_url = $_POST['lbry_supports_add_claim_id']);
|
||||
if ( ( $_POST['supporting_channel'] ) ? $supporting_channel = $_POST['supporting_channel'] : $supporting_channel = null );
|
||||
// Check that nonce
|
||||
if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'add_supports_nonce' ) ) {
|
||||
if ( isset( $_POST['lbry_supports_add_claim_id'] ) && isset( $_POST['lbry_supports_add_bid_amount'] ) ) {
|
||||
$claim_id = $_POST['lbry_supports_add_claim_id']; // TODO: sanitize key() only allows for lowercase chars, dashes, and underscores. maybe remove to allow more characters? and use something else for better control?
|
||||
|
||||
$claim_id = sanitize_text_field( $claim_id );
|
||||
$bid = $_POST['lbry_supports_add_bid_amount'];
|
||||
$supports_bid = number_format( floatval( $bid ), 3, '.', '' );
|
||||
|
||||
// Try to add support to the claim
|
||||
try {
|
||||
$result = LBRY()->daemon->supports_add( $claim_id, $supports_bid, $supporting_channel, $lbry_url );
|
||||
|
||||
} catch ( \Exception $e ) {
|
||||
LBRY()->notice->set_notice( 'error', $e->getMessage(), false );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LBRY()->notice->set_notice('error', 'Security check failed' );
|
||||
die( __( 'Security check failed', 'lbrypress' ) );
|
||||
}
|
||||
|
||||
wp_safe_redirect( $redirect_url );
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles editing an existing channel form submission
|
||||
*/
|
||||
public function edit_channel()
|
||||
{
|
||||
$redirect_url = admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) );
|
||||
|
||||
$claim = $_POST['claim_id'];
|
||||
$claim_id = sanitize_text_field( $claim );
|
||||
$bid = $_POST['lbry_supports_add_bid_amount'];
|
||||
$channel_bid = number_format( floatval( $bid ), 3, '.', '' );
|
||||
$title = $_POST['lbry_edit_channel_title'];
|
||||
$channel_title = sanitize_text_field( $title );
|
||||
$description = $_POST['lbry_edit_channel_description'];
|
||||
$channel_description = sanitize_text_field( $description );
|
||||
$tags = $_POST['lbry_edit_channel_tags'];
|
||||
$channel_tags = sanitize_text_field( $tags );
|
||||
$website = $_POST['lbry_new_channel_website'];
|
||||
$channel_website = sanitize_text_field( $website );
|
||||
$email = $_POST['lbry_new_channel_email'];
|
||||
$channel_email = sanitize_text_field( $email );
|
||||
// $language_array = LBRY()->languages;
|
||||
// $primlang = $_POST['lbry_new_channel_prim_lang'];
|
||||
// $primary_language = ( ($primlang) && in_array( $primlang, $language_array ) );
|
||||
// $seclang = $_POST['lbry_new_channel_sec_lang'];
|
||||
// $secondary_language = ( ($seclang) && in_array( $seclang, $language_array ) );
|
||||
// $thumbnail = $_POST[''];
|
||||
// $thumbnail_url = wp_get_attachment_url( get_option( 'lbry_media_selector_thumbnail_id' ) )
|
||||
// $header = $_POST[''];
|
||||
// $header_url = wp_get_attachment_url( get_option( 'lbry_media_selector_header_id' ) );
|
||||
|
||||
// Check that nonce
|
||||
if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'edit_channel_nonce' ) ) {
|
||||
$args = array(
|
||||
'claim_id' => $claim_id,
|
||||
'bid' => $channel_bid,
|
||||
'title' => $channel_title,
|
||||
'description' => $channel_description,
|
||||
'tags' => $channel_tags,
|
||||
'website_url' => $channel_website,
|
||||
'email' => $channel_email,
|
||||
//'languages' => array( $primary_language, $secondary_language ),
|
||||
//'thumbnail_url' => $thumbnail_url,
|
||||
//'cover_url' => $header_url,
|
||||
);
|
||||
// Try to add support to the claim
|
||||
try {
|
||||
$result = LBRY()->daemon->channel_edit( $args );
|
||||
|
||||
} catch ( \Exception $e ) {
|
||||
LBRY()->notice->set_notice( 'error', $e->getMessage(), false );
|
||||
}
|
||||
} else {
|
||||
LBRY()->notice->set_notice('error', 'Security check failed' );
|
||||
die( __( 'Security check failed', 'lbrypress' ) );
|
||||
}
|
||||
|
||||
wp_safe_redirect( $redirect_url );
|
||||
exit();
|
||||
|
@ -276,13 +594,15 @@ class LBRY_Admin
|
|||
{
|
||||
// See if we've checked in the past two hours
|
||||
if ( ! get_transient( 'lbry_wallet_check' ) ) {
|
||||
$balance = LBRY()->daemon->wallet_balance();
|
||||
$result = LBRY()->daemon->wallet_balance();
|
||||
$balance = $result->result->available;
|
||||
$site_url = get_site_url();
|
||||
if ( $balance < get_option( LBRY_SETTINGS )[LBRY_LBC_PUBLISH] * 20 ) {
|
||||
// If LBRY Balance is low, send email, but only once per day
|
||||
if ( ! get_transient( 'lbry_wallet_warning_email' ) ) {
|
||||
$email = get_option( 'admin_email' );
|
||||
$subject = 'Your LBRYPress Wallet Balance is Low!';
|
||||
$message = "You LBRY Wallet for your wordpress installation at " . site_url() . " is running very low.\r\n\r\nYou currently have " . $balance . ' LBC left in your wallet. In order to keep publishing to the LBRY network, please add some LBC to your account.';
|
||||
$message = 'Your LBRY Wallet for your WordPress installation at ' . esc_html_e( $site_url ) . ' is running very low.\r\n\r\nYou currently have ' . esc_html_e( $balance ) . ' LBC left in your wallet. In order to keep publishing to the LBRY network, please add some LBC to your account.';
|
||||
wp_mail( $email, $subject, $message );
|
||||
set_transient( 'lbry_wallet_warning_email', true, DAY_IN_SECONDS );
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Admin_Notice
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Daemon
|
||||
{
|
||||
|
@ -32,8 +33,7 @@ class LBRY_Daemon
|
|||
* https://lbry.tech/api/sdk#address_unused
|
||||
* @return string Unused wallet address in base58
|
||||
*/
|
||||
public function wallet_unused_address()
|
||||
{
|
||||
public function wallet_unused_address() {
|
||||
try {
|
||||
$result = $this->request( 'address_unused' );
|
||||
return $result->result;
|
||||
|
@ -50,8 +50,7 @@ class LBRY_Daemon
|
|||
* @param int $page Pagination page number
|
||||
* @return array Array of address lists linked to this account
|
||||
*/
|
||||
public function address_list($page = 1)
|
||||
{
|
||||
public function address_list( $page = 1 ) {
|
||||
// Get 20 per page
|
||||
$params = array(
|
||||
'page' => $page,
|
||||
|
@ -67,20 +66,45 @@ class LBRY_Daemon
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the info about a claim can get supports and initial bid amount when claim created among other information about a claim.
|
||||
* TODO Can be build out later to accept more params
|
||||
* @param string $claim_id
|
||||
* @return object $result
|
||||
*/
|
||||
public function claim_search( $claim_id )
|
||||
{
|
||||
$params = array(
|
||||
'claim_id' => $claim_id,
|
||||
// 'name' => $norm_name,
|
||||
// 'claim_type' => $claim_type,
|
||||
);
|
||||
try {
|
||||
$result = $this->request( 'claim_search', $params );
|
||||
$this->logger->log( 'Claim Search Results: ' . print_r( $result->result, true ) );
|
||||
return $result->result;
|
||||
} catch ( LBRYDaemonException $e ) {
|
||||
$this->logger->log( 'claim_search error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
LBRY()->notice->set_notice( 'error', 'Issue getting claim search info' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the available balance of a current LBRY account
|
||||
* https://lbry.tech/api/sdk#account_balance
|
||||
* https://lbry.tech/api/sdk#wallet_balance
|
||||
* @param string $address Wallet Address
|
||||
* @return float Wallet Balance
|
||||
* @return object $wallet_balance Wallet Balance
|
||||
*
|
||||
*/
|
||||
public function wallet_balance()
|
||||
{
|
||||
try {
|
||||
$result = $this->request('account_balance');
|
||||
return $result->result->available;
|
||||
try { // Convert JSON string to an object
|
||||
$result = $this->request( 'wallet_balance' );
|
||||
return $result;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('account_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
LBRY()->notice->set_notice('error', 'Issue getting account balance.');
|
||||
$this->logger->log('wallet_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
LBRY()->notice->set_notice('error', 'Issue getting wallet balance.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +137,8 @@ class LBRY_Daemon
|
|||
* https://lbry.tech/api/sdk#channel_create
|
||||
* @return array dictionary containing result of the request
|
||||
*/
|
||||
public function channel_new($channel_name, $bid_amount)
|
||||
|
||||
public function channel_new( $channel_name, $channel_bid )
|
||||
{
|
||||
// TODO: Sanitize channel name and bid
|
||||
// Make sure no @ sign, as we will add that
|
||||
|
@ -133,10 +158,13 @@ class LBRY_Daemon
|
|||
'channel_create',
|
||||
array(
|
||||
'name' => $channel_name,
|
||||
'bid' => number_format(floatval($bid_amount), 2, '.', '')
|
||||
'bid' => $channel_bid
|
||||
)
|
||||
);
|
||||
|
||||
$this->logger->log( 'channel_create success!', 'Successfully created channel with result: ' . print_r( $result->result, true ) );
|
||||
return $result->result;
|
||||
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log( 'channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
throw new \Exception( 'Issue creating new channel.', 1 );
|
||||
|
@ -144,6 +172,62 @@ class LBRY_Daemon
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an existing channel to add missing details
|
||||
* https://lbry.tech/api/sdk#channel_update
|
||||
* @return array dictionary containing result of the request
|
||||
*/
|
||||
|
||||
public function channel_edit( $args )
|
||||
{
|
||||
try {
|
||||
$result = $this->request(
|
||||
'channel_update',
|
||||
$args
|
||||
);
|
||||
|
||||
$this->logger->log( 'channel_update success!', 'Successfully updated channel with result: ' . print_r( $result->result, true ) );
|
||||
return $result->result;
|
||||
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log( 'channel_update error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
throw new \Exception( 'Issue updating channel.', 1 );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add supports to an existing claim
|
||||
* https://lbry.tech/api/sdk#
|
||||
* @return array dictionary containing result of the request
|
||||
*/
|
||||
|
||||
public function supports_add( $claim_id, $supports_bid, $supporting_channel = null, $lbry_url = null )
|
||||
{
|
||||
try {
|
||||
$result = $this->request(
|
||||
'support_create',
|
||||
array(
|
||||
'claim_id' => $claim_id,
|
||||
'channel_name' => $supporting_channel,
|
||||
'amount' => $supports_bid
|
||||
)
|
||||
);
|
||||
if ( $result ) {
|
||||
if ( ( ($lbry_url) && ($lbry_url !== null ) ) ? $lbry_url : $lbry_url = $claim_id );
|
||||
LBRY()->notice->set_notice(
|
||||
'success', 'Successfully added supports for claim id: ' . esc_html__( $lbry_url, 'lbrypress' ) . '! Please allow a few minutes for the support to process.', true );
|
||||
}
|
||||
$this->logger->log( 'support_create success!', 'Successfully added support with result: ' . print_r( $result->result, true ) );
|
||||
return $result->result;
|
||||
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log( 'support_create error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
throw new \Exception( 'Issue creating new support.', 1 );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the canonical URL for the supplied claim ID, null otherwise
|
||||
* @param string $claim_id
|
||||
|
@ -244,7 +328,7 @@ class LBRY_Daemon
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks for erros in decoded daemon response and throws an exception if it finds one
|
||||
* Checks for errors in decoded daemon response and throws an exception if it finds one
|
||||
* @param $response
|
||||
*/
|
||||
private function check_for_errors( $response )
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Daemon_Logger
|
||||
{
|
||||
|
||||
/**
|
||||
* The directory to log to
|
||||
* @var string
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Network
|
||||
{
|
||||
|
@ -34,25 +35,31 @@ class LBRY_Network
|
|||
private function post_meta_setup()
|
||||
{
|
||||
// Add the meta boxes
|
||||
add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
|
||||
add_action( 'add_meta_boxes', array( $this, 'lbry_meta_boxes' ) );
|
||||
|
||||
// Save the post meta on 'save_post' hook
|
||||
add_action( 'wp_insert_post', array( $this, 'save_post_meta' ), 11, 2 );
|
||||
|
||||
// Checkbox inside the WordPres meta box near "Publish" button
|
||||
add_action( 'post_submitbox_misc_actions', array( $this, 'publish_to_lbry_checkbox' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the meta boxes to the post editing backend
|
||||
*/
|
||||
public function add_meta_boxes()
|
||||
public function lbry_meta_boxes( $post )
|
||||
{
|
||||
// IDEA: Support post types based on user selection
|
||||
add_meta_box(
|
||||
'lbry-network-publishing', // Unique ID
|
||||
'LBRY Network', // Title
|
||||
__('LBRY Network', 'lbrypress'), // Title
|
||||
array($this, 'meta_box_html'), // Callback function
|
||||
'post', // Screen Options (or post type)
|
||||
'side', // Context
|
||||
'high' // Priority
|
||||
'high', // Priority
|
||||
array(
|
||||
'__block_editor_compatible_meta_box' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -65,37 +72,130 @@ class LBRY_Network
|
|||
public function save_post_meta( $post_id, $post )
|
||||
{
|
||||
if ( $post->post_type != 'post' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify the nonce before proceeding.
|
||||
if (!isset($_POST['_lbrynonce']) || !wp_verify_nonce($_POST['_lbrynonce'], 'lbry_publish_channels')) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
// Check if the current user has permission to edit the post.
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return $post_id;
|
||||
}
|
||||
// Verify the nonce before proceeding.
|
||||
if ( ! isset( $_POST['_lbrynonce'] ) || ! wp_verify_nonce( $_POST['_lbrynonce'], 'lbry_publish_post_nonce' ) ) {
|
||||
//LBRY()->notice->set_notice('error', 'Security check failed' );
|
||||
return $post_id;
|
||||
}
|
||||
$post_type = get_post_type_object( $post->post_type );
|
||||
if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
|
||||
return $post_id;
|
||||
}
|
||||
if ( ( $_POST[LBRY_WILL_PUBLISH] ) && $_POST[LBRY_WILL_PUBLISH] != get_post_meta( $post_id, LBRY_WILL_PUBLISH, true ) ) {
|
||||
update_post_meta( $post_id, LBRY_WILL_PUBLISH, $_POST[LBRY_WILL_PUBLISH] );
|
||||
} elseif ( ! isset( $_POST[LBRY_WILL_PUBLISH] ) ) {
|
||||
update_post_meta( $post_id, LBRY_WILL_PUBLISH, 0 );
|
||||
}
|
||||
|
||||
$will_publish = (isset($_POST[LBRY_WILL_PUBLISH]) ? $_POST[LBRY_WILL_PUBLISH] : false);
|
||||
$new_channel = (isset($_POST[LBRY_POST_CHANNEL]) ? $_POST[LBRY_POST_CHANNEL] : null);
|
||||
$cur_channel = get_post_meta($post_id, LBRY_POST_CHANNEL, true);
|
||||
$channel = $_POST[LBRY_POST_PUB_CHANNEL];
|
||||
$cur_channel = ( get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( $post_id, '_lbry_channel', true ) );
|
||||
$license = $_POST[LBRY_POST_PUB_LICENSE];
|
||||
$cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true );
|
||||
$will_publish = $_POST[LBRY_WILL_PUBLISH];
|
||||
|
||||
// Update meta acordingly
|
||||
if (!$will_publish) {
|
||||
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'false');
|
||||
} else {
|
||||
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'true');
|
||||
|
||||
if ( ( $channel ) && ( $channel !== $cur_channel ) && ( $channel != null || $channel != '' ) ) {
|
||||
update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $channel );
|
||||
delete_post_meta( $post_id, '_lbry_channel'); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion
|
||||
} elseif ( $channel === $cur_channel && ( $cur_channel === get_post_meta( $post_id, '_lbry_channel', true ) ) ) {
|
||||
update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $channel );
|
||||
delete_post_meta( $post_id, '_lbry_channel' ); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion
|
||||
}
|
||||
if ( ( $license ) && ( $license !== $cur_license ) && ( $license != null || $license != '' ) ) {
|
||||
update_post_meta( $post_id, LBRY_POST_PUB_LICENSE, $license );
|
||||
} elseif ( $license === $cur_license && ( $cur_license === get_post_meta( $post_id, 'lbry_license', true ) ) ) {
|
||||
update_post_meta( $post_id, LBRY_POST_PUB_LICENSE, $license );
|
||||
}
|
||||
$published = get_post_meta( $post_id, '_lbry_is_published', true );
|
||||
$will_pub = get_post_meta( $post_id, '_lbry_will_publish', true );
|
||||
if ( ( $will_pub == 0 ) && ( ! ( $published ) || ( $published ) == 0 ) ) {
|
||||
// If not publishing to LBRY we want to not save unused values in database
|
||||
delete_post_meta( $post_id, '_lbry_post_pub_channel' );
|
||||
delete_post_meta( $post_id, '_lbry_post_pub_license' );
|
||||
delete_post_meta( $post_id, '_lbry_canonical_url' );
|
||||
}
|
||||
$pub_channel = ( $channel ) ? $channel : $cur_channel;
|
||||
$pub_license = ( $license ) ? $license : $cur_license;
|
||||
if ( ( $will_publish ) && ( $will_publish == true ) && ( $post->post_status == 'publish' ) && ( $pub_channel ) && ( $pub_license ) && ( $pub_license != null ) ) {
|
||||
// Publish the post on the LBRY Network
|
||||
$this->publisher->publish( $post, $pub_channel, $pub_license );
|
||||
}
|
||||
if ($new_channel !== $cur_channel) {
|
||||
update_post_meta($post_id, LBRY_POST_CHANNEL, $new_channel);
|
||||
}
|
||||
|
||||
if ($will_publish && $post->post_status == 'publish') {
|
||||
// Publish the post on the LBRY Network
|
||||
$this->publisher->publish($post, get_post_meta($post_id, LBRY_POST_CHANNEL, true));
|
||||
/**
|
||||
* Creates a checkbox that changes the default setting to always publish to LBRY,
|
||||
* can be reverted individually to not publish on a per post basis. Saves to options table.
|
||||
*/
|
||||
|
||||
public function publish_to_lbry_checkbox( $post )
|
||||
{
|
||||
if ( get_post_type( $post_id ) != 'post' ) {
|
||||
return $post;
|
||||
}
|
||||
$post_id = $post->ID;
|
||||
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
|
||||
if ( $_GET['action'] === 'edit' ) {
|
||||
if ( get_post_meta( $post_id, '_lbry_canonical_url', true ) == null || empty( get_post_meta( $post_id, '_lbry_canonical_url', true ) ) ) {
|
||||
$canonical_url = LBRY()->daemon->canonical_url( $lbry_claim_id );
|
||||
if ( $canonical_url != null ) {
|
||||
update_post_meta( $post_id, '_lbry_canonical_url', $canonical_url );
|
||||
} elseif ( $canonical_url == null ) {
|
||||
delete_post_meta( $post_id, '_lbry_canonical_url' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$lbry_url = ( get_post_meta( $post_id, '_lbry_canonical_url', true ) );
|
||||
if ($lbry_url) {
|
||||
$open_url = str_replace('lbry://', 'open.lbry.com/', $lbry_url );
|
||||
}
|
||||
|
||||
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
|
||||
$will_publish = get_post_meta( $post_id, '_lbry_will_publish', true );
|
||||
$lbry_post_pub_channel = get_post_meta( $post_id, '_lbry_post_pub_channel', true );
|
||||
if ( ( $will_publish ) ? $will_publish : $will_publish = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'] );
|
||||
if ( ( $_GET['action'] === 'edit' ) ? $value = $lbry_published : $value = $will_publish );
|
||||
|
||||
$checked = checked( $value, true, false );
|
||||
|
||||
// nonce set on page meta-box.php
|
||||
if ( ( ( $will_publish == true ) && ( $lbry_post_pub_channel ) ) || ( ( ( $lbry_published ) || ( $lbry_claim_id ) ) && ( ( $lbry_url != null ) || ( $lbry_claim_id ) ) ) ) {
|
||||
printf(
|
||||
'<hr class="lbry-hr-meta">
|
||||
<div class="misc-pub-section lbry-meta-published-lbry-wrapper">
|
||||
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span> <span class="post-lbry-display-before">Published on:</span> <span class="post-lbry-display"><strong>LBRY</strong></span>
|
||||
</div>
|
||||
<div class="misc-pub-section lbry-url-meta-wrapper">
|
||||
<span class="lbry-meta-label"><strong> LBRY URL: </strong></span><a href="' . esc_url( '%2$s', 'lbrypress' ) . '" target="_blank">' . esc_html__( '%3$s', 'lbrypress' ) . '</a>
|
||||
</div>
|
||||
<div class="misc-pub-section lbry-claim-id-meta-wrapper">
|
||||
<span class="lbry-meta-label"><strong> LBRY claim ID: </strong></span><span class="lbry-pub-metabox"><p class="lbry-claim-id-metabox">' . esc_html__( '%4$s', 'lbrypress' ) . '</p></span>
|
||||
</div>
|
||||
<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last">
|
||||
<span class="lbry-meta-label"> Update Post on: <span class="post-lbry-display"><strong>LBRY</strong></span> <input type="checkbox" class="lbry-meta-checkbox" value="1" ' . esc_attr('%5$s') . ' name="' . esc_attr('%6$s') . '">
|
||||
</div>',
|
||||
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
|
||||
$open_url,
|
||||
$lbry_url,
|
||||
$lbry_claim_id,
|
||||
$checked,
|
||||
LBRY_WILL_PUBLISH
|
||||
);
|
||||
} else {
|
||||
printf (
|
||||
'<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last">
|
||||
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span><span class="lbry-meta-label">Publish to: <span class="post-lbry-display"> <strong>LBRY</strong></span> <input type="checkbox" class="lbry-meta-checkbox" value="1" ' . esc_attr('%2$s') . ' name="' . esc_attr('%3$s') . '">
|
||||
</div>',
|
||||
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
|
||||
$checked,
|
||||
LBRY_WILL_PUBLISH
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,6 +205,6 @@ class LBRY_Network
|
|||
*/
|
||||
public function meta_box_html( $post )
|
||||
{
|
||||
require_once(LBRY_ABSPATH . 'templates/meta_box.php');
|
||||
require_once( LBRY_ABSPATH . 'templates/meta-box.php' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use League\HTMLToMarkdown\HtmlConverter;
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Network_Parser
|
||||
{
|
||||
|
@ -18,7 +19,7 @@ class LBRY_Network_Parser
|
|||
// COMBAK: Composer is not safe in a wordpress environment. May have to write our own package.
|
||||
require_once LBRY_ABSPATH . 'vendor/autoload.php';
|
||||
$this->converter = new HtmlConverter(array(
|
||||
'strip_tags' => false
|
||||
'strip_tags' => true
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Network_Publisher
|
||||
{
|
||||
|
@ -13,8 +14,9 @@ class LBRY_Network_Publisher
|
|||
* @param string $channel The Claim ID of the channel we are posting to
|
||||
*/
|
||||
// NOTE: This is currently sitting at about 150ms, mostly the post parsing
|
||||
public function publish($post, $channel = null)
|
||||
{
|
||||
public function publish( $post, $channel = null, $license ) {
|
||||
|
||||
$post_id = $post->ID;
|
||||
// Get converted markdown into a file
|
||||
$filepath = LBRY_ABSPATH . 'tmp/' . $post->post_name . time() . '.md';
|
||||
$file = fopen( $filepath, 'w' );
|
||||
|
@ -30,11 +32,11 @@ class LBRY_Network_Publisher
|
|||
// If everything went well with the conversion, carry on
|
||||
$args = array(
|
||||
'name' => $post->post_name,
|
||||
'bid' => number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', ''),
|
||||
'bid' => number_format( floatval( get_option( LBRY_SETTINGS )[LBRY_LBC_PUBLISH] ), 3, '.', '' ),
|
||||
'file_path' => $filepath,
|
||||
'title' => $post->post_title,
|
||||
'languages' => array( substr( get_locale(), 0, 2 ) ),
|
||||
'license' => get_option(LBRY_SETTINGS)[LBRY_LICENSE]
|
||||
'license' => $license,
|
||||
);
|
||||
|
||||
// Setup channel
|
||||
|
@ -82,9 +84,24 @@ class LBRY_Network_Publisher
|
|||
// Set Claim ID
|
||||
update_post_meta( $post->ID, LBRY_CLAIM_ID, $claim_id );
|
||||
|
||||
// Set Channel Name Published under
|
||||
$published_channel = $output->signing_channel->name;
|
||||
$channel_claim_id = $output->signing_channel->claim_id;
|
||||
update_post_meta( $post->ID, '_lbry_post_published_channel', $published_channel );
|
||||
update_post_meta( $post->ID, '_lbry_post_pub_channel_claim_id', $channel_claim_id );
|
||||
|
||||
// Set License Published under
|
||||
$published_license = $output->value->license;
|
||||
if ( ( $published_license ) && ( $published_license !== null ) ) {
|
||||
update_post_meta( $post->ID, '_lbry_post_published_license', $published_license );
|
||||
}
|
||||
|
||||
// Set Canonical URL
|
||||
$canonical_url = LBRY()->daemon->canonical_url( $claim_id );
|
||||
update_post_meta( $post->ID, LBRY_CANONICAL_URL, $canonical_url );
|
||||
|
||||
// Set _lbry_is_published to true
|
||||
update_post_meta( $post->ID, '_lbry_is_published', true );
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log( 'Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage() );
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Notifier
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Speech
|
||||
{
|
||||
|
@ -43,7 +44,7 @@ class LBRY_Speech
|
|||
return false;
|
||||
}
|
||||
|
||||
$speech_url = get_option(LBRY_SETTINGS)[LBRY_SPEECH];
|
||||
$speech_url = get_option(LBRY_SPEECH_SETTINGS)[LBRY_SPEECH];
|
||||
|
||||
// Die if we don't have a spee.ch url
|
||||
if (!$speech_url || $speech_url === '') {
|
||||
|
@ -66,7 +67,7 @@ class LBRY_Speech
|
|||
);
|
||||
|
||||
// Pull Channel and Password from config file for now
|
||||
$speech_channel = get_option(LBRY_SETTINGS)[LBRY_SPEECH_CHANNEL];
|
||||
$speech_channel = get_option(LBRY_SPEECH_SETTINGS)[LBRY_SPEECH_CHANNEL];
|
||||
$speech_pw = LBRY()->admin->get_speech_pw();
|
||||
if (!empty($speech_channel) && !empty($speech_pw)) {
|
||||
$params['channelName'] = '@' . $speech_channel;
|
||||
|
@ -229,7 +230,7 @@ class LBRY_Speech
|
|||
*/
|
||||
private function build_request($method, $params = array())
|
||||
{
|
||||
$speech_url = get_option(LBRY_SETTINGS)[LBRY_SPEECH];
|
||||
$speech_url = get_option(LBRY_SPEECH_SETTINGS)[LBRY_SPEECH];
|
||||
|
||||
// Die if no URL
|
||||
if (!$speech_url) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Speech_Media
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Speech_Parser
|
||||
{
|
||||
|
|
2
classes/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
|
@ -5,6 +5,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Post_Handler
|
||||
{
|
||||
|
|
2
frontend/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
2
inc/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
201
templates/channel-edit-page.php
Normal file
|
@ -0,0 +1,201 @@
|
|||
<?php
|
||||
/**
|
||||
* ============================
|
||||
* CHANNELS EDIT ADMIN PAGE
|
||||
* Uses the post-admin action so we can use the $_POST global variable to build our cURL request and the settings are not saved to the datbase
|
||||
* @package LBRYPress
|
||||
* ============================
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
if ( current_user_can( 'manage_options' ) ) {
|
||||
|
||||
// Generate a custom nonce
|
||||
$lbrynonce = wp_create_nonce( 'edit_channel_nonce' );
|
||||
|
||||
$claim_id = $_GET['claim_id'];
|
||||
$claim_id = sanitize_text_field( $claim_id );
|
||||
$lbry_url = $_GET['lbry_url'];
|
||||
$lbry_url = urldecode($lbry_url);
|
||||
$init_bid = $_GET['init_bid'];
|
||||
$init_bid = number_format( floatval( $init_bid ), 3, '.', '' );
|
||||
$channel = $_GET['channel_name'];
|
||||
$channel = sanitize_user( $channel );
|
||||
$support_amount = $_GET['current_support'];
|
||||
$support_amount = number_format( floatval( $support_amount ), 3, '.', '' );
|
||||
|
||||
// Save attachment ID
|
||||
// if ( isset( $_POST['submit'] ) && isset( $_POST['lbry_header_attachment_id'] ) ) :
|
||||
// update_option( 'lbry_media_selector_header_id', absint( $_POST['lbry_header_attachment_id'] ) );
|
||||
// endif;
|
||||
if ( isset( $_POST['submit'] ) && isset( $_POST['lbry_thumbnail_attachment_id'] ) ) :
|
||||
update_option( 'lbry_media_selector_thumbnail_id', absint( $_POST['lbry_thumbnail_attachment_id'] ) );
|
||||
endif;
|
||||
|
||||
// Build the page
|
||||
?>
|
||||
<img src="">
|
||||
<img src="">
|
||||
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="lbry_edit_channel_form">
|
||||
|
||||
<input type="hidden" name="action" value="lbry_edit_channel">
|
||||
<input type="hidden" name="_lbrynonce" value="<?php echo $lbrynonce ?>">
|
||||
<input type="hidden" name="claim_id" value ="<?php echo $claim_id ?>">
|
||||
<!-- <input type='hidden' name='lbry_header_attachment_id' id='lbry_header_attachment_id' value='<?php //echo get_option( 'lbry_media_selector_header_id' ); ?>'> -->
|
||||
<input type='hidden' name='lbry_thumbnail_attachment_id' id='lbry_thumbnail_attachment_id' value='<?php echo get_option( 'lbry_media_selector_thumbnail_id' ); ?>'>
|
||||
<?php if ( $claim_id ) { ?>
|
||||
<h2><?php echo _e( 'Editing Channel: ' . esc_html__( $channel ), 'lbrypress' ); ?></h2>
|
||||
<?php printf(
|
||||
'<h3>' . esc_html__( '%1$s', 'lbrypress' ) . '</h3>
|
||||
<h4>Claim ID: <code>' . esc_html__( '%2$s', 'lbrypress' ) . '</code></h4>',
|
||||
$lbry_url,
|
||||
$claim_id,
|
||||
);
|
||||
} ?>
|
||||
<table class="form-table" role="presentation">
|
||||
<tbody>
|
||||
<!-- <tr>
|
||||
<th scope="row">Header Image</th>
|
||||
<td>
|
||||
<div class='image-preview-wrapper'>
|
||||
<img id='header-preview' src='<?php //echo wp_get_attachment_url( get_option( 'lbry_media_selector_header_id' ) ); ?>' height='100'>
|
||||
</div>
|
||||
<input id="lbry_upload_header_button" type="button" class="button" value="<?php //_e( 'Upload Header', 'lbrypress' ); ?>">
|
||||
<p class="header-image-info">6.25:1 ratio for best result</p>
|
||||
<td>
|
||||
</tr> -->
|
||||
<tr>
|
||||
<th scope="row">Thumbnail Image</th>
|
||||
<td>
|
||||
<div class='image-preview-wrapper'>
|
||||
<img id="thumbnail-preview" src="'<?php echo wp_get_attachment_url( get_option( 'lbry_media_selector_thumbnail_id' ) ); ?>'" height="100">
|
||||
</div>
|
||||
<input id="lbry_upload_thumbnail_button" type="button" class="button" value="<?php _e( 'Upload Thumbnail', 'lbrypress' ); ?>">
|
||||
<p class="channel-image-info">1:1 ratio for best result</p>
|
||||
<td>
|
||||
</tr>
|
||||
<?php if ( $channel ) { ?>
|
||||
<tr>
|
||||
<th scope="row">Channel Name</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$s') . '" required readonly>',
|
||||
'lbry_edit_channel_name',
|
||||
$channel,
|
||||
); ?>
|
||||
<p>If you want to edit another channel, use the link for the specific channel claim found on the <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ),'options.php' ) ) ); ?>">Channels tab</a>or to create a complete <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channel-edit' ), 'admin.php' ) ) ); ?>">Channel</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } else { ?>
|
||||
<tr>
|
||||
<th scope="row">Channel Name</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="@' . esc_attr('') . '" required>',
|
||||
'lbry_edit_channel_name',
|
||||
); ?>
|
||||
<p>No spaces or special characters in @ Channel Name</p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<th scope="row">Title</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
|
||||
'lbry_edit_channel_title',
|
||||
); ?>
|
||||
<p></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Description</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<textarea rows="8" cols="24" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '"></textarea>',
|
||||
'lbry_edit_channel_description',
|
||||
); ?>
|
||||
<p></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Tags</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" rows="10" cols="50" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
|
||||
'lbry_edit_channel_tags',
|
||||
); ?>
|
||||
<p>Add up to five tags (comma separated)</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Website</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
|
||||
'lbry_new_channel_website',
|
||||
); ?>
|
||||
<p>Default is LBRYPress site channel was created on</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Email</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
|
||||
'lbry_new_channel_email',
|
||||
); ?>
|
||||
<p>Default is WordPress admin email</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Language</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
|
||||
'lbry_new_channel_prim_lang',
|
||||
); ?>
|
||||
<p>Primary language of the channel</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Second Language</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
|
||||
'lbry_new_channel_sec_lang',
|
||||
); ?>
|
||||
<p>Secondary language channel uses (if any)</p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php if ( $channel ) { ?>
|
||||
<tr>
|
||||
<th scope="row">Add LBC as Support</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="number" step="0.001" min="0.01" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$.3f') . '" required>',
|
||||
'lbry_supports_add_bid_amount',
|
||||
$bid_amount,
|
||||
); ?>
|
||||
<p>Current minimum support bid <img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc"> 0.01</p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } else { ?>
|
||||
<tr>
|
||||
<th scope="row">LBC to Bid</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="number" step="0.001" min="0.001" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$.3f') . '" required>',
|
||||
'lbry_channel_add_bid_amount',
|
||||
$bid_amount,
|
||||
); ?>
|
||||
<p>Current minimum bid <img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc"> 0.001</p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Create New Channel"></p>
|
||||
</form>
|
||||
<?php
|
||||
}
|
129
templates/channels-page.php
Normal file
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
/**
|
||||
* ============================
|
||||
* CHANNELS SETTINGS ADMIN PAGE
|
||||
* Uses the post-admin action so we can use the $_POST global variable to build our cURL request and the settings are not saved to the datbase
|
||||
* @package LBRYPress
|
||||
* ============================
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
if ( current_user_can( 'manage_options' ) ) {
|
||||
|
||||
// Generate a custom nonce
|
||||
$lbrynonce = wp_create_nonce( 'add_channel_nonce' );
|
||||
|
||||
// Build the page
|
||||
?>
|
||||
|
||||
<h3><?php _e( 'Available Channels To Publish', 'lbrypress' ); ?></h3>
|
||||
<?php //LBRY()->admin->available_channels_callback(); ?>
|
||||
<?php
|
||||
if ( $_POST['lbry_new_channel'] ) {
|
||||
$channel = $_POST['lbry_new_channel'];
|
||||
$channel = str_replace( '@', '', $channel );
|
||||
$channel = str_replace( ' ', '-', $channel );
|
||||
$clean_input['lbry_new_channel'] = sanitize_user( $channel );
|
||||
}
|
||||
if ( $_POST['lbry_channel_bid_amount'] ) {
|
||||
$channel_bid = $_POST['lbry_channel_bid_amount'];
|
||||
$clean_input['lbry_channel_bid_amount'] = number_format( floatval( $channel_bid ), 3, '.', '' );
|
||||
}
|
||||
|
||||
$channel_list = LBRY()->daemon->channel_list();
|
||||
if ( $channel_list ) { ?>
|
||||
<table class="lbry-channel-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sort="channel">Channel</th>
|
||||
<th data-sort="lbryurl">LBRY URL</th>
|
||||
<th data-sort="claim">Claim ID</th>
|
||||
<th data-sort="date">~ Date Created</th>
|
||||
<th data-sort="posts">Posts</th>
|
||||
<th data-sort="support" colspan="2">Supports</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ( $channel_list as $channel ):
|
||||
$claim_id = $channel->claim_id;
|
||||
$results = LBRY()->daemon->claim_search( $claim_id );
|
||||
$lbry_url = $results->items[0]->canonical_url;
|
||||
if ( $lbry_url ) {
|
||||
$open_url = str_replace( 'lbry://', 'https://open.lbry.com/', $lbry_url );
|
||||
}
|
||||
$timestamp = $results->items[0]->meta->creation_timestamp;
|
||||
$created_date = date( 'm-d-y', $timestamp );
|
||||
$support_amount = $results->items[0]->meta->support_amount;
|
||||
$claims_published = $results->items[0]->meta->claims_in_channel;
|
||||
if ( ( $support_amount < 0.001 ) ) {
|
||||
( $support_amount = '0' );
|
||||
} elseif ( ( $support_amount < 0.01 ) && ( $support_amount >= 0.001 ) ) {
|
||||
( $support_amount = '<0.01' );
|
||||
} elseif ( ( $support_amount <= 0.099 ) && ( $support_amount >= 0.01) ) {
|
||||
( $support_amount = number_format( floatval( $support_amount ), 2, '.', '' ) );
|
||||
} elseif ( ( $support_amount <= 0.999 ) && ( $support_amount >= 0.1 ) ) {
|
||||
( $support_amount = number_format( floatval( $support_amount ), 1, '.', '' ) );
|
||||
} else {
|
||||
( $support_amount = number_format( intval( $support_amount ) ) );
|
||||
}
|
||||
$init_bid = $results->items[0]->amount; ?>
|
||||
<tr>
|
||||
<td><a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channel-edit', 'claim_id' => urlencode( esc_html__( $claim_id, 'lbrypress' ) ), 'channel_name' => urlencode( esc_html__($channel->name, 'lbrypress' ) ), 'current_support' => urlencode( floatval($support_amount) ), 'init_bid' => urlencode( floatval($init_bid) ), 'lbry_url' => urlencode( esc_url($lbry_url) ) ), 'admin.php' ) ) ); ?>"><?php esc_html_e( $channel->name, 'lbrypress' ); ?></a></td>
|
||||
<td><a href="<?php echo esc_url( $open_url, 'lbrypress' ); ?>"><?php esc_html_e( esc_url( $lbry_url ), 'lbrypress' ); ?></a></td>
|
||||
<td><?php esc_html_e( $claim_id, 'lbrypress' ); ?></td>
|
||||
<td><?php esc_html_e( $created_date, 'lbrypress' ); ?></td>
|
||||
<td><?php esc_html_e( $claims_published, 'lbrypress' ); ?></td>
|
||||
<td><span title="Initial Bid Amount: <?php esc_html_e( $init_bid, 'lbrypress' ); ?>"><img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc channel-bid-icon-lbc"><?php esc_html_e( $support_amount, 'lbrypress' ); ?></span></td>
|
||||
<td><a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'supports', 'claim_id' => urlencode( esc_html__( $claim_id, 'lbrypress' ) ), 'supporting_channel' => urlencode( esc_html__($channel->name, 'lbrypress' ) ), 'current_support' => urlencode( floatval($support_amount) ), 'init_bid' => urlencode( floatval($init_bid) ), 'lbry_url' => urlencode( esc_url($lbry_url) ) ), 'admin.php' ) ) ); ?>">Add</a></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr><th colspan="7">LBRYPress</th></tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<?php } else { ?>
|
||||
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
|
||||
<?php }
|
||||
?>
|
||||
|
||||
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="lbry_add_channel_form">
|
||||
|
||||
<input type="hidden" name="action" value="lbry_add_channel">
|
||||
<input type="hidden" name="_lbrynonce" value="<?php echo $lbrynonce ?>">
|
||||
<h3><?php echo _e( 'Quick Create a New Channel', 'lbrypress' ); ?></h3>
|
||||
<p>Create a Channel that can be edited later to add details or set-up a complete <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channel-edit' ), 'admin.php' ) ) ); ?>">Channel</a> now.</p>
|
||||
<table class="form-table" role="presentation">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">New Channel Name</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="@' . esc_attr('%2$s') . '" placeholder="your-new-channel" required>',
|
||||
'lbry_new_channel',
|
||||
$clean_input['lbry_new_channel'],
|
||||
); ?>
|
||||
<p>No Spaces in Channel Names</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Amount of LBC to Bid</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="number" step="0.001" min="0.001" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$.3f') . '" required>',
|
||||
'lbry_channel_bid_amount',
|
||||
$clean_input['lbry_channel_bid_amount'],
|
||||
); ?>
|
||||
<p>Current minimum bid <img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc"> 0.001</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Create New Channel"></p>
|
||||
</form>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<p> <?php __( "You are not authorized to perform this operation.", 'lbrypress' ) ?> </p>
|
||||
<?php
|
||||
}
|
2
templates/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
137
templates/meta-box.php
Normal file
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
/**
|
||||
* ============================
|
||||
* META BOX FOR POST PAGE
|
||||
* Prints the post meta box
|
||||
* @package LBRYPress
|
||||
* ============================
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
$unnatributed = (object) array(
|
||||
'name' => 'none (anonymous)',
|
||||
'claim_id' => 'null'
|
||||
);
|
||||
$post_id = $post->ID;
|
||||
// Generate a custom nonce
|
||||
$lbrynonce = wp_create_nonce( 'lbry_publish_post_nonce' );
|
||||
|
||||
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
|
||||
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
|
||||
$lbry_published_channel = get_post_meta( $post_id, '_lbry_post_published_channel', true );
|
||||
if ( ( $lbry_published == true ) && ( $lbry_claim_id ) && ( ! ( $lbry_published_channel ) ) ) {
|
||||
$result = LBRY()->daemon->claim_search( $lbry_claim_id );
|
||||
$name = $result->items[0]->signing_channel->name;
|
||||
update_post_meta( $post_id, '_lbry_post_published_channel', $name );
|
||||
}
|
||||
$lbry_channel_claim_id = get_post_meta( $post_id, '_lbry_post_pub_channel', true );
|
||||
$lbry_published_license = get_post_meta( $post_id, '_lbry_post_pub_license', true );
|
||||
if ( ( $lbry_published == true ) && ( ( $lbry_claim_id ) ) && ( ! ( $lbry_published_license ) ) ) {
|
||||
$result = LBRY()->daemon->claim_search( $lbry_claim_id );
|
||||
$license = $result->items[0]->value->license;
|
||||
update_post_meta( $post_id, '_lbry_post_pub_license', $license );
|
||||
}
|
||||
$lbry_canonical_url = get_post_meta( $post_id, '_lbry_canonical_url', true );
|
||||
if ( ! $lbry_canonical_url ) {
|
||||
$result = LBRY()->daemon->claim_search( $lbry_claim_id );
|
||||
$lbry_canonical_url = $result->items[0]->canonical_url;
|
||||
update_post_meta( $post_id, '_lbry_canonical_url', $lbry_canonical_url );
|
||||
}
|
||||
$lbry_url = $lbry_canonical_url;
|
||||
$cur_channel = ( get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( $post_id, '_lbry_channel', true ) );
|
||||
$default_channel = get_option( LBRY_SETTINGS )['default_lbry_channel'];
|
||||
$chan_open_url = ( 'open.lbry.com/'. $lbry_published_channel .'#' . $lbry_channel_claim_id . '');
|
||||
|
||||
?>
|
||||
<input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>"><?php
|
||||
|
||||
if ( ( ( $will_publish == true ) && ( $lbry_channel_claim_id ) ) || ( ( ( $lbry_published == true ) || ( $lbry_claim_id ) || ( $lbry_published_channel ) ) && ( $lbry_published_license != null ) ) ) {
|
||||
|
||||
$results = LBRY()->daemon->claim_search( $lbry_claim_id );
|
||||
$init_bid = $results->items[0]->amount;
|
||||
$support_amount = $results->items[0]->meta->support_amount;
|
||||
if ( ( $support_amount < 0.001 ) ) {
|
||||
( $support_amount = '0' );
|
||||
} elseif ( ( $support_amount < 0.01 ) && ( $support_amount >= 0.001 ) ) {
|
||||
( $support_amount = '<0.01' );
|
||||
} elseif ( ( $support_amount <= 0.099 ) && ( $support_amount >= 0.01) ) {
|
||||
( $support_amount = number_format( floatval( $support_amount ), 2, '.', '' ) );
|
||||
} elseif ( ( $support_amount <= 0.999 ) && ( $support_amount >= 0.1 ) ) {
|
||||
( $support_amount = number_format( floatval( $support_amount ), 1, '.', '' ) );
|
||||
} else {
|
||||
( $support_amount = number_format( intval( $support_amount ) ) );
|
||||
}
|
||||
printf(
|
||||
'<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'Initial bid amount:', 'lbrypress' ) . ' </strong>
|
||||
<span class="lbry-meta-bx-content lbry-meta-bx-channel"><img src="' . esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) ) . 'admin/images/lbc.png" class="icon icon-lbc bid-icon-lbc bid-icon-lbc"> ' . esc_html__( '%1$s', 'lbrypress' ) . '</span></div>',
|
||||
$init_bid
|
||||
);
|
||||
printf(
|
||||
'<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'Supports:', 'lbrypress' ) . ' </strong>
|
||||
<span class="lbry-meta-bx-content lbry-meta-bx-channel"><img src="' . esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) ) . 'admin/images/lbc.png" class="icon icon-lbc bid-icon-lbc bid-icon-lbc"> ' . esc_html__( '%1$s', 'lbrypress' ) . '</span><a href="' . esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'supports', 'post_id' => intval($post_id), 'claim_id' => esc_html__( '%2$s', 'lbrypress' ), 'lbry_url' => '%3$s', 'supporting_channel' => esc_html__( '%4$s', 'lbrypress' ), 'current_support' => '%5$.3f', 'init_bid' => '%6$.3f'), 'admin.php' ) ) ) . '">' . __( 'Add', 'lbrypress' ) . '</a></div>',
|
||||
$support_amount,
|
||||
urlencode( $lbry_claim_id ),
|
||||
urlencode( esc_url( $lbry_url ) ),
|
||||
urlencode( $lbry_published_channel ),
|
||||
urlencode( $support_amount ),
|
||||
urlencode( $init_bid )
|
||||
);
|
||||
printf(
|
||||
'<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'LBRY channel published to:', 'lbrypress' ) . '</strong></div>
|
||||
<div class="lbry-meta-bx-content lbry-meta-bx-channel"><a href="' . esc_url( '%1$s', 'lbrypress' ) . '">' . esc_html__( '%2$s', 'lbrypress' ) . '</a></div>',
|
||||
$chan_open_url,
|
||||
$lbry_published_channel,
|
||||
);
|
||||
printf(
|
||||
'<div class="lbry-meta-label lbry-meta-bx-license"><strong>' . __( 'License published under:', 'lbrypress' ) .'</strong> </div>
|
||||
<div class="lbry-meta-bx-content lbry-meta-bx-license lbry-meta-bx-content-last">' . esc_html__( '%1$s', 'lbrypress' ) . '</div>',
|
||||
$lbry_published_license,
|
||||
);
|
||||
} else {
|
||||
$channels = LBRY()->daemon->channel_list();
|
||||
$channels[] = $unnatributed;
|
||||
// Sort the channels in a natural way
|
||||
usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) ); ?>
|
||||
|
||||
<div><label for="LBRY_POST_PUB_CHANNEL" class="lbry-meta-bx-label lbry-meta-bx-channel"><?php
|
||||
|
||||
esc_html_e( 'Channel to Publish:', 'lbrypress' ); ?> </label></div><?php
|
||||
|
||||
$options = '';
|
||||
if ( $channels ) {
|
||||
foreach ( $channels as $index=>$channel ) {
|
||||
$options .= '<option class="lbry-meta-bx-option lbry-meta-option-channel" value="' . esc_attr( $channel->claim_id ) . '"';
|
||||
if ( ( $cur_channel ) ? $cur_channel : $cur_channel = $default_channel ) {
|
||||
$options .= selected( $cur_channel, $channel->claim_id, false );
|
||||
}
|
||||
$options .= '>' . esc_html__( $channel->name, 'lbrypress' ) . '</option>';
|
||||
}
|
||||
printf(
|
||||
'<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '">' . esc_html('%2$s') . '</select>',
|
||||
LBRY_POST_PUB_CHANNEL,
|
||||
$options
|
||||
);
|
||||
}
|
||||
?>
|
||||
<div><label for="LBRY_POST_PUB_LICENSE" class="lbry-meta-bx-label lbry-meta-bx-license"><?php esc_html_e( 'Publish License:', 'lbrypress' ); ?> </label></div><?php
|
||||
$licenses = LBRY()->licenses;
|
||||
$options = '';
|
||||
$default_license = get_option(LBRY_SETTINGS)[LBRY_LICENSE];
|
||||
$cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true );
|
||||
|
||||
// Create options list, select current license
|
||||
if ( $licenses ) {
|
||||
foreach ( $licenses as $value => $name ) {
|
||||
$options .= '<option class="lbry-meta-bx-option lbry-meta-bx-option-last lbry-meta-option-license" value="' . esc_attr( $value ) . '"';
|
||||
if ( ( $cur_license ) ? $cur_license : $cur_license = $default_license ) {
|
||||
$options .= selected( $cur_license, $value, false );
|
||||
}
|
||||
$options .= '>'. esc_html__( $name, 'lbrypress' ) . '</option>';
|
||||
}
|
||||
}
|
||||
printf(
|
||||
'<select class="" id="'.esc_attr('%1$s').'" name="'. esc_attr('%1$s') .'">' . esc_html('%2$s') . '</select>',
|
||||
LBRY_POST_PUB_LICENSE,
|
||||
$options
|
||||
);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
$unnatributed = (object) array(
|
||||
'name' => 'none (anonymous)',
|
||||
'claim_id' => 'null'
|
||||
);
|
||||
$channels = LBRY()->daemon->channel_list();
|
||||
$channels[] = $unnatributed;
|
||||
// Sort the channels in a natural way
|
||||
usort($channels, array('LBRYPress', 'channel_name_comp'));
|
||||
$cur_channel = get_post_meta($post->ID, LBRY_POST_CHANNEL, true);
|
||||
$will_publish = get_post_meta($post->ID, LBRY_WILL_PUBLISH, true);
|
||||
?>
|
||||
<?php wp_nonce_field('lbry_publish_channels', '_lbrynonce'); ?>
|
||||
<div class="lbry-meta-checkbox-wrapper">
|
||||
<label class="lbry-meta-label">
|
||||
<input type="checkbox" class="lbry-meta-checkbox" name="<?= LBRY_WILL_PUBLISH ?>" value="true"
|
||||
<?php
|
||||
if ($will_publish === 'true' || $will_publish === '') {
|
||||
echo 'checked';
|
||||
}
|
||||
?>
|
||||
>
|
||||
Sync this post on channel:
|
||||
</label>
|
||||
</div>
|
||||
<select class="lbry-meta-select" name="<?= LBRY_POST_CHANNEL ?>">
|
||||
<?php foreach ($channels as $index=>$channel): ?>
|
||||
<option value="<?= $channel->claim_id ?>"
|
||||
<?php
|
||||
if ($cur_channel) {
|
||||
if ($cur_channel === $channel->claim_id) {
|
||||
echo 'selected';
|
||||
}
|
||||
} elseif ($index === 0) {
|
||||
echo 'selected';
|
||||
}
|
||||
?>
|
||||
>
|
||||
<?= $channel->name ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
70
templates/options-page.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/**
|
||||
* The Options Page with tabs
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
$LBRY = LBRY();
|
||||
$wallet_balance = $LBRY->daemon->wallet_balance();
|
||||
$available_balance = $wallet_balance->result->available;
|
||||
$total_balance = $wallet_balance->result->total;
|
||||
$lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php esc_html_e( get_admin_page_title(), 'lbrypress' ); ?></h1>
|
||||
<h2><img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc wallet-icon-lbc" title="<?php echo esc_attr( number_format( $total_balance, 3, '.', ',' ) ); ?> Wallet Total Balance"><code title="<?php echo esc_attr( number_format( $total_balance, 3, '.', ',' ) ); ?> Wallet Total Balance"><?php esc_html_e( number_format( $available_balance, 3, '.', ',' ) ); ?></code> Wallet Available Balance</h2>
|
||||
<nav class="nav-tab-wrapper">
|
||||
<a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=general' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'general' || '' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Settings' ); ?></a>
|
||||
<a href="<?php echo esc_url( admin_url( 'admin.php?page=lbrypress&tab=channels' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'channels' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Channels' ); ?></a>
|
||||
<a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=speech' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'speech' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Spee.ch' ); ?></a>
|
||||
<?php
|
||||
if ( $lbry_active_tab == 'supports' ) {
|
||||
$admin_url = admin_url( 'admin.php?page=lbrypress&tab=supports' );
|
||||
printf(
|
||||
'<a href="' . esc_url( $admin_url ) . '" class="nav-tab nav-tab-active">' . esc_html__( 'Supports', 'lbrypress') . '</a>',
|
||||
$admin_url,
|
||||
);
|
||||
}
|
||||
if ( $lbry_active_tab == 'channel-edit' ) {
|
||||
$admin_url = admin_url( 'admin.php?page=lbrypress&tab=channel-edit' );
|
||||
printf(
|
||||
'<a href="' . esc_url( $admin_url ) . '" class="nav-tab nav-tab-active">' . esc_html__( 'Channel', 'lbrypress' ) . '</a>',
|
||||
$admin_url,
|
||||
);
|
||||
} ?>
|
||||
</nav>
|
||||
<?php if ( $lbry_active_tab == 'channels' ) {
|
||||
include_once( 'channels-page.php' );
|
||||
} elseif ( $lbry_active_tab == 'supports' ) {
|
||||
include_once( 'supports-add-form.php' );
|
||||
} elseif ( $lbry_active_tab == 'channel-edit' ) {
|
||||
include_once( 'channel-edit-page.php' );
|
||||
} else {
|
||||
?>
|
||||
<form class="form-table" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post">
|
||||
<?php // TODO: write this as a switch?
|
||||
}
|
||||
if ( $lbry_active_tab == 'general' ) {
|
||||
settings_fields( 'lbry_general_settings' );
|
||||
do_settings_sections( LBRY_ADMIN_PAGE );
|
||||
submit_button();
|
||||
} elseif ( $lbry_active_tab == 'channels' ) {
|
||||
//include_once( 'channels-page.php' );
|
||||
} elseif ( $lbry_active_tab == 'supports' ) {
|
||||
//include_once( 'supports-add-form.php' );
|
||||
} elseif ( $lbry_active_tab == 'channel-edit' ) {
|
||||
//include_once( 'supports-add-form.php' );
|
||||
} elseif ( $lbry_active_tab == 'speech' ) {
|
||||
settings_fields( LBRY_SPEECH_SETTINGS );
|
||||
do_settings_sections( 'lbrypress-speech' );
|
||||
submit_button();
|
||||
} else {
|
||||
settings_fields( 'lbry_general_settings' );
|
||||
do_settings_sections( LBRY_ADMIN_PAGE );
|
||||
submit_button();
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
</div><!-- wrap -->
|
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
$LBRY = LBRY();
|
||||
$wallet_balance = $LBRY->daemon->wallet_balance();
|
||||
$channel_list = $LBRY->daemon->channel_list();
|
||||
// TODO: Make this page look cleaner
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?= esc_html(get_admin_page_title()); ?></h1>
|
||||
<h2>Your wallet amount:</h2>
|
||||
<code><?= number_format($wallet_balance, 2, '.', ','); ?></code>
|
||||
<form action="options.php" method="post">
|
||||
<?php
|
||||
settings_fields(LBRY_SETTINGS_GROUP);
|
||||
do_settings_sections(LBRY_ADMIN_PAGE);
|
||||
submit_button('Save Settings');
|
||||
?>
|
||||
</form>
|
||||
<h2>Your Publishable Channels</h2>
|
||||
<?php if ($channel_list): ?>
|
||||
<ul class="lbry-channel-list">
|
||||
<?php foreach ($channel_list as $channel): ?>
|
||||
<li><?= $channel->name ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php else: ?>
|
||||
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
|
||||
<?php endif; ?>
|
||||
<h2>Add a new channel to publish to:</h2>
|
||||
<form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
|
||||
<?php wp_nonce_field('lbry_add_channel', '_lbrynonce'); ?>
|
||||
<input type="hidden" name="action" value="lbry_add_channel">
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">New Channel Name</th>
|
||||
<td>
|
||||
<span>@</span>
|
||||
<input type="text" name="new_channel" value="" placeholder="your-new-channel" required>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Amount of LBC to Bid</th>
|
||||
<td>
|
||||
<input type="number" step="0.1" min="0.1" name="bid_amount" value="10" required>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php submit_button('Add New Channel'); ?>
|
||||
</form>
|
||||
</div>
|
|
@ -1,26 +1,28 @@
|
|||
<?php
|
||||
$url = get_post_meta(get_the_id(), LBRY_CANONICAL_URL, true);
|
||||
if (!$url) {
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
$lbry_url = get_post_meta( get_the_id(), LBRY_CANONICAL_URL, true );
|
||||
if ( ! $lbry_url ) {
|
||||
// Get channel canonical for backwards compatibility
|
||||
$channel_id = get_post_meta(get_the_id(), LBRY_POST_CHANNEL, true);
|
||||
$url = LBRY()->daemon->canonical_url($channel_id);
|
||||
$channel_id = ( get_post_meta( get_the_id(), LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( get_the_id(), LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( get_the_id(), '_lbry_channel', true ) );
|
||||
$lbry_url = LBRY()->daemon->canonical_url( $channel_id );
|
||||
}
|
||||
|
||||
if ($url) {
|
||||
$url = str_replace('lbry://', 'lbry.tv/', $url);
|
||||
if ( $lbry_url ) {
|
||||
$open_url = str_replace( 'lbry://', 'open.lbry.com/', $lbry_url );
|
||||
}
|
||||
?>
|
||||
<div class="lbry-published-banner">
|
||||
<h5>Stored Safely on Blockchain</h5>
|
||||
<p>
|
||||
This post is published to <a href="https://lbry.io/get">LBRY</a> blockchain
|
||||
<?php if($url): ?>
|
||||
at <a href="https://<?= $url ?>"><?= $url ?></a>.
|
||||
This post is published to the <a href="https://lbry.com/get">LBRY</a> blockchain
|
||||
<?php if( $lbry_url ) : ?>
|
||||
at: <a href="<?php echo esc_url( $open_url ); ?>"><?php esc_html_e( $lbry_url, 'lbrypress' ); ?></a>.
|
||||
<?php else: ?>
|
||||
.
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://lbry.io/get" target="_blank">Try LBRY</a> to experience content freedom, earn crypto, and support The Anti-Media!
|
||||
<a href="https://lbry.com/get" target="_blank">Try LBRY</a> to experience content freedom, earn crypto, and support us directly!
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<?php
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
?>
|
||||
<div class="error">
|
||||
<p><?php echo LBRY_NAME; ?> error: Your environment doesn't meet all of the system requirements listed below.</p>
|
||||
|
||||
|
|
101
templates/supports-add-form.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/**
|
||||
* ============================
|
||||
* ADD SUPPORTS FORM ADMIN PAGE
|
||||
* Uses the post-admin action and the $_POST global variable to build our cURL request
|
||||
* @package LBRYPress
|
||||
* ============================
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
if ( current_user_can( 'manage_options' ) ) {
|
||||
|
||||
// Generate a custom nonce
|
||||
$lbrynonce = wp_create_nonce( 'add_supports_nonce' );
|
||||
|
||||
// TODO sanitize more
|
||||
$claim_id = $_GET['claim_id'];
|
||||
$claim_id = sanitize_text_field( $claim_id );
|
||||
$lbry_url = $_GET['lbry_url'];
|
||||
$lbry_url = urldecode($lbry_url);
|
||||
$lbry_url = sanitize_text_field($lbry_url);
|
||||
$init_bid = $_GET['init_bid'];
|
||||
$init_bid = number_format( floatval( $init_bid ), 3, '.', '' );
|
||||
$supporting_channel = $_GET['supporting_channel'];
|
||||
$supporting_channel = sanitize_user( $supporting_channel );
|
||||
$support_amount = $_GET['current_support'];
|
||||
$support_amount = number_format( floatval( $support_amount ), 3, '.', '' );
|
||||
$return_post = $_GET['post_id'];
|
||||
$return_post = intval( $return_post );
|
||||
|
||||
|
||||
// Build the page ?>
|
||||
|
||||
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="lbry_add_supports_form">
|
||||
|
||||
<input type="hidden" name="action" value="lbry_add_supports">
|
||||
<input type="hidden" name="_lbrynonce" value="<?php echo esc_attr($lbrynonce); ?>">
|
||||
<input type="hidden" name="post_id" value="<?php echo esc_attr($return_post); ?>">
|
||||
<input type="hidden" name="lbry_url" value="<?php echo esc_url($lbry_url); ?>">
|
||||
<input type="hidden" name="supporting_channel" value="<?php echo esc_attr($supporting_channel); ?>">
|
||||
|
||||
<h2><?php echo _e( 'Add Supports to Claim:', 'lbrypress' ); ?></h2>
|
||||
<?php printf(
|
||||
'<h3>' . esc_html__( '%1$s', 'lbrypress' ) . '</h3>
|
||||
<h4>Claim ID: <code>' . esc_html__( '%2$s', 'lbrypress' ) . '</code></h4><p>If you want to add supports to a different channel or post, use the channel or post link that corresponds with that specific claim to add supports.</p>',
|
||||
$lbry_url,
|
||||
$claim_id,
|
||||
); ?>
|
||||
<table class="form-table" role="presentation">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">Claim ID</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$s') . '" required readonly>',
|
||||
'lbry_supports_add_claim_id',
|
||||
$claim_id,
|
||||
); ?>
|
||||
<p>Claims can be for either Channels or Posts</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Add LBC as Support</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<input type="number" step="0.001" min="0.01" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$.3f') . '" required>',
|
||||
'lbry_supports_add_bid_amount',
|
||||
$bid_amount,
|
||||
); ?>
|
||||
<p>Current minimum support bid <img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc"> 0.01</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope=""row>Amount Used to Create Claim</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<p><img src="' . esc_attr( '%2$s', 'lbrypress' ) . '" class="icon icon-lbc bid-icon-lbc"> ' . esc_html__( '%1$.3f', 'lbrypress' ) . '</p><p>Initial bid that was used to publish the claim.</p>',
|
||||
$init_bid,
|
||||
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png',
|
||||
); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Current Supports</th>
|
||||
<td>
|
||||
<?php printf(
|
||||
'<p><img src="' . esc_attr( '%2$s', 'lbrypress' ) . '" class="icon icon-lbc bid-icon-lbc"> ' . esc_html__('%1$.3f', 'lbrypress' ) . '</p><p>May not include very recently added supports, please be patient as it may take a short while to update.</p>',
|
||||
$support_amount,
|
||||
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png',
|
||||
); ?>
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Add Supports"></p>
|
||||
</form>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<p> <?php __( "You are not authorized to perform this operation.", 'lbrypress' ); ?> </p>
|
||||
<?php
|
||||
}
|
2
tests/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
// if uninstall.php is not called by WordPress, die
|
||||
defined('WP_UNINSTALL_PLUGIN') || die();
|
||||
|
|
2
vendor/index.php
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|