Began parsing process for Spee.ch URL

This commit is contained in:
Paul Kirby 2018-09-13 19:34:11 -05:00
parent 94f6c6eca2
commit 18c26ab330
5 changed files with 35 additions and 14 deletions

View file

@ -185,7 +185,14 @@ class LBRY_Admin
// 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'])) {
LBRY()->notice->set_notice('error', 'Must supply both channel name and bid amount');
} else {
$new_channel = $_POST['new_channel'];
$bid_amount = $_POST['bid_amount'];
// TODO: Wrap in a try catch
LBRY()->daemon->channel_new($new_channel, $bid_amount);
LBRY()->notice->set_notice('success', 'Successfully added a new channel!', true);
}

View file

@ -58,8 +58,9 @@ class LBRY_Daemon
* https://lbryio.github.io/lbry/#channel_new
* @return array dictionary containing result of the request
*/
public function channel_new()
public function channel_new($channel_name, $bid_amount)
{
return null;
}
/**
@ -101,6 +102,8 @@ class LBRY_Daemon
{
$output_filename = "lbrydaemon";
// HACK: Shouldn't just directly download, need to know OS, etc
// TODO: Make sure we are only installing if not there or corrupted
$host = "http://build.lbry.io/daemon/build-6788_commit-5099e19_branch-lbryum-refactor/mac/lbrynet";
$fp = fopen(LBRY_URI . '/' . $output_filename, 'w+');
$ch = curl_init();

View file

@ -10,19 +10,25 @@
class LBRY_Speech
{
/**
* [__construct description]
* HTML Parser
* @var LBRY_Speech_Parser
*/
private $parser = null;
public function __construct()
{
$this->parser = new LBRY_Speech_Parser();
}
public function get_address()
/**
* Checks to see if we need to rewrite URLS, does if necessary
*/
public function maybe_rewrite_urls()
{
return get_option(LBRY_SPEECH);
// See if we have a Spee.ch URL and if we are on the front-end
$speech_url = get_option(LBRY_SETTINGS)[LBRY_SPEECH];
if ($speech_url != '' && !is_admin()) {
ob_start(array($this->parser, 'rewrite'));
}
public function set_address($address)
{
update_option(LBRY_SPEECH, $address);
}
}

View file

@ -7,10 +7,13 @@
class LBRY_Speech_Parser
{
/**
* [__construct description]
*/
public function __construct()
public function rewrite($html)
{
// TODO: Completely fix this, as its super slow. Looking at cdn_enabler for ideas
$speech_url = get_option(LBRY_SETTINGS)[LBRY_SPEECH];
$html = str_replace(site_url(), $speech_url, $html);
return $html;
}
}

View file

@ -137,6 +137,8 @@ class LBRYPress
// Admin request
if (is_admin()) {
$this->admin = new LBRY_Admin();
} else {
$this->speech->maybe_rewrite_urls();
}
}
@ -163,7 +165,7 @@ class LBRYPress
add_option(LBRY_SETTINGS, $option_defaults, false);
}
// TODO: decide if we need to check for missing or corrupt settings. May be unecessary.
// 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);
// $new_settings = $current_settings;