mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
Adding yt api
This commit is contained in:
parent
af29ad39f9
commit
7693b834ca
21 changed files with 236 additions and 64 deletions
|
@ -121,8 +121,9 @@ class Controller
|
||||||
|
|
||||||
$router->any('/youtube/thanks', 'AcquisitionActions::executeThanks');
|
$router->any('/youtube/thanks', 'AcquisitionActions::executeThanks');
|
||||||
$router->any('/youtube/sub', 'AcquisitionActions::executeYouTubeSub');
|
$router->any('/youtube/sub', 'AcquisitionActions::executeYouTubeSub');
|
||||||
$router->any('/youtube/{campaignId:c}?', 'AcquisitionActions::executeYouTube');
|
$router->any('/youtube', 'AcquisitionActions::executeYT2');
|
||||||
$router->any('/yt2', 'AcquisitionActions::executeYT2');
|
$router->post('/youtube/token', 'AcquisitionActions::executeYoutubeToken');
|
||||||
|
$router->any('/youtube/status/{token}', 'AcquisitionActions::executeYoutubeStatus');
|
||||||
$router->get('/verify/{token}', 'AcquisitionActions::executeVerify');
|
$router->get('/verify/{token}', 'AcquisitionActions::executeVerify');
|
||||||
|
|
||||||
$router->get('/news/category/{category}', 'ContentActions::executePostCategoryFilter');
|
$router->get('/news/category/{category}', 'ContentActions::executePostCategoryFilter');
|
||||||
|
|
|
@ -9,15 +9,13 @@ class AcquisitionActions extends Actions
|
||||||
|
|
||||||
public static function executeYouTubeSub()
|
public static function executeYouTubeSub()
|
||||||
{
|
{
|
||||||
if (!Request::isPost())
|
if (!Request::isPost()) {
|
||||||
{
|
|
||||||
return Controller::redirect('/youtube');
|
return Controller::redirect('/youtube');
|
||||||
}
|
}
|
||||||
|
|
||||||
$email = Request::getPostParam('email');
|
$email = Request::getPostParam('email');
|
||||||
|
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
{
|
|
||||||
Session::setFlash('error', 'Please enter a valid email.');
|
Session::setFlash('error', 'Please enter a valid email.');
|
||||||
return Controller::redirect('/youtube');
|
return Controller::redirect('/youtube');
|
||||||
}
|
}
|
||||||
|
@ -33,8 +31,7 @@ class AcquisitionActions extends Actions
|
||||||
public static function executeYouTube(string $campaignId = '')
|
public static function executeYouTube(string $campaignId = '')
|
||||||
{
|
{
|
||||||
$template = 'acquisition/youtube' . ($campaignId ? '-' . $campaignId : '');
|
$template = 'acquisition/youtube' . ($campaignId ? '-' . $campaignId : '');
|
||||||
if (!View::exists($template))
|
if (!View::exists($template)) {
|
||||||
{
|
|
||||||
return NavActions::execute404();
|
return NavActions::execute404();
|
||||||
}
|
}
|
||||||
return [$template];
|
return [$template];
|
||||||
|
@ -42,7 +39,7 @@ class AcquisitionActions extends Actions
|
||||||
|
|
||||||
public static function executeYT2()
|
public static function executeYT2()
|
||||||
{
|
{
|
||||||
return ['acquisition/yt2', ['_no_layout' => true]];
|
return ['acquisition/yt2'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function executeVerify(string $token)
|
public static function executeVerify(string $token)
|
||||||
|
@ -50,5 +47,64 @@ class AcquisitionActions extends Actions
|
||||||
return ['acquisition/verify', ['token' => $token]];
|
return ['acquisition/verify', ['token' => $token]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function executeYoutubeToken()
|
||||||
|
{
|
||||||
|
return ['acquisition/youtube_token', ['_no_layout' => true]];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function executeYoutubeStatus(string $token)
|
||||||
|
{
|
||||||
|
return ['acquisition/youtube_status', ['token' => $token]];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function actionYoutubeToken(string $email, string $desired_lbry_channel_name, string $youtube_channel_id)
|
||||||
|
{
|
||||||
|
|
||||||
|
$email_is_valid = static::email_verification($email);
|
||||||
|
$desired_lbry_channel_name_is_valid = static::lbry_channel_verification($desired_lbry_channel_name);
|
||||||
|
$youtube_channel_id_is_valid = static::youtube_channel_verification($youtube_channel_id);
|
||||||
|
|
||||||
|
|
||||||
|
if ($email_is_valid && $desired_lbry_channel_name_is_valid && $youtube_channel_id_is_valid) {
|
||||||
|
$token = LBRY::newYoutube($email, $youtube_channel_id, $desired_lbry_channel_name);
|
||||||
|
|
||||||
|
if ($token['error'] === null) {
|
||||||
|
$url = "/youtube/status/" . $token['data']['status_token'];
|
||||||
|
Controller::redirect($url);
|
||||||
|
} else {
|
||||||
|
$url = "/yt2?error=true&error_message=" . $token['error'];
|
||||||
|
Controller::redirect($url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$url = "/yt2?error=true";
|
||||||
|
Controller::redirect($url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function email_verification($email)
|
||||||
|
{
|
||||||
|
if (preg_match('/\S+@\S+\.\S+/', $email)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function youtube_channel_verification($youtube_channel_id)
|
||||||
|
{
|
||||||
|
if (preg_match('/^UC[A-Za-z0-9_-]{22}$/', $youtube_channel_id)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function lbry_channel_verification($lbry_channel)
|
||||||
|
{
|
||||||
|
if (preg_match('/[1-z]+/', $lbry_channel)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
16
lib/thirdparty/LBRY.class.php
vendored
16
lib/thirdparty/LBRY.class.php
vendored
|
@ -29,4 +29,20 @@ class LBRY
|
||||||
{
|
{
|
||||||
return Curl::post(static::getApiUrl('/list/unsubscribe'), ['email' => $email], ['json_response' => true]);
|
return Curl::post(static::getApiUrl('/list/unsubscribe'), ['email' => $email], ['json_response' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register new youtube sync
|
||||||
|
public static function newYoutube($email, $channel_id, $channel_name)
|
||||||
|
{
|
||||||
|
return Curl::post(static::getApiUrl('/yt/new'), ['email' => $email, 'youtube_channel_id' => $channel_id,'desired_lbry_channel_name' => $channel_name], ['json_response' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the sync status
|
||||||
|
public static function statusYoutube($status_token)
|
||||||
|
{
|
||||||
|
return Curl::post(static::getApiUrl('/yt/status'), ['status_token' => $status_token], ['json_response' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function youtubeReward(){
|
||||||
|
return CurlWithCache::post(static::getApiUrl('/yt/rewards'),[], ['cache' => 3600, 'json_response' => true ]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Response
|
||||||
'/js/jquery-2.1.3.min.js',
|
'/js/jquery-2.1.3.min.js',
|
||||||
'/js/global.js'
|
'/js/global.js'
|
||||||
],
|
],
|
||||||
'css' => []
|
'css' => ['/css/all.css']
|
||||||
],
|
],
|
||||||
$headers = [],
|
$headers = [],
|
||||||
$headersSent = false,
|
$headersSent = false,
|
||||||
|
@ -106,11 +106,24 @@ class Response
|
||||||
static::$assets['js'][$src] = $src;
|
static::$assets['js'][$src] = $src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function addCssAsset($src)
|
||||||
|
{
|
||||||
|
static::$assets['css'][$src] = $src;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getJsAssets()
|
public static function getJsAssets()
|
||||||
{
|
{
|
||||||
return static::$assets['js'];
|
return static::$assets['js'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getCssAssets()
|
||||||
|
{
|
||||||
|
return static::$assets['css'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setCssAssets(array $assets = []){
|
||||||
|
static::$assets['css'] = $assets;
|
||||||
|
}
|
||||||
public static function setGzipResponseContent($gzip = true)
|
public static function setGzipResponseContent($gzip = true)
|
||||||
{
|
{
|
||||||
static::$gzipResponseContent = $gzip;
|
static::$gzipResponseContent = $gzip;
|
||||||
|
|
18
view/template/acquisition/youtube_status.php
Normal file
18
view/template/acquisition/youtube_status.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php Response::setMetaDescription('YouTuber? Take back control! LBRY allows publication on your terms. It\'s open-source, decentralized, and gives you 100% of the profit.') ?>
|
||||||
|
<?php Response::setMetaTitle(__('YouTubers! Take back control.')) ?>
|
||||||
|
<?php echo View::render('nav/_header', ['isDark' => false]) ?>
|
||||||
|
<main>
|
||||||
|
|
||||||
|
<?php $status = LBRY::statusYoutube($token);
|
||||||
|
?>
|
||||||
|
<center>
|
||||||
|
LBRY channel name: <?php echo $status['data']['lbry_channel_name'];?>
|
||||||
|
</center>
|
||||||
|
<center>
|
||||||
|
Youtube Sync status: <?php echo $status['data']['status'];?>
|
||||||
|
|
||||||
|
</center>
|
||||||
|
<center>
|
||||||
|
Expected Reward: <?php echo $status['data']['expected_reward'];?>
|
||||||
|
</center>
|
||||||
|
<main/>
|
3
view/template/acquisition/youtube_token.php
Normal file
3
view/template/acquisition/youtube_token.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
AcquisitionActions::actionYoutubeToken($_POST['email_address'], $_POST['desired_lbry_channel_name'], $_POST['youtube_channel_url']);
|
||||||
|
?>
|
|
@ -1,26 +1,12 @@
|
||||||
<!DOCTYPE html>
|
<?php
|
||||||
<html>
|
Response::setCssAssets(['/css/yt2.css']);
|
||||||
<head>
|
Response::addJsAsset('/js/yt2/TweenMax.min.js');
|
||||||
<meta charset="utf-8">
|
Response::addJsAsset('/js/yt2/ScrollToPlugin.min.js');
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
Response::addJsAsset('/js/yt2/app.js');
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
Response::addJsAsset('/js/yt2/FormValidation.js');
|
||||||
<title>LBRY for YouTubers</title>
|
$reward = LBRY::youtubeReward();
|
||||||
<meta name="description" content="">
|
?>
|
||||||
|
<main>
|
||||||
<meta property="og:type" content="website">
|
|
||||||
<meta property="og:locale" content="en">
|
|
||||||
<meta property="og:site_name" content="LBRY">
|
|
||||||
<meta property="og:title" content="LBRY for YouTubers">
|
|
||||||
<meta property="og:description" content="">
|
|
||||||
<meta property="og:url" content="https://lbry.io/youtube">
|
|
||||||
<meta property="og:image" content="">
|
|
||||||
<meta property="og:image:width" content="">
|
|
||||||
<meta property="og:image:height" content="">
|
|
||||||
|
|
||||||
<link href="/css/yt2.css" rel="stylesheet" type="text/css" />
|
|
||||||
<link rel="icon" href="images/favicon.ico">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<header class="header">
|
<header class="header">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
|
@ -66,20 +52,32 @@
|
||||||
</section>
|
</section>
|
||||||
<section class="claim section">
|
<section class="claim section">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
<?php
|
||||||
|
if (isset($_GET['error'])): echo "<div>" . "The following error occurred: ". $_GET['error_message'] . " For support please send an email to hello@lbry.io" . "</div>";
|
||||||
|
endif;?>
|
||||||
<div class="zigzag"></div>
|
<div class="zigzag"></div>
|
||||||
<h1>Own your identity. For real this time.</h1>
|
<h1>Own your identity. For real this time.</h1>
|
||||||
<form>
|
<form id="youtube_claim" method="post" action="/youtube/token">
|
||||||
<div class="form-inner">
|
<div class="form-inner" >
|
||||||
|
<div class="block" hidden id="lbry_error">LBRY channel name is not valid or blank</div>
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<input type="text" placeholder="yourchannel" />
|
<input id="lbry_channel_name" type="text" name="desired_lbry_channel_name" placeholder="Desired LBRY channel name" />
|
||||||
<label>@</label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="block">
|
<div class="block" hidden id="email_error">Email is not valid or blank</div>
|
||||||
<input type="submit" value="Claim now" />
|
<div class="block">
|
||||||
</div>
|
<input hidden id="email" type="text" name="email_address" placeholder="Your Email" />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="block" hidden id="youtube_url_error">Youtube id is not valid or blank</div>
|
||||||
|
<div class="block">
|
||||||
|
<input hidden id="youtube_url" type="text" name="youtube_channel_url" placeholder="Your Channel ID" />
|
||||||
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
<div class="block">
|
||||||
|
<input type="submit" value="Claim now" onClick="return submitDetailsForm()"/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
@ -171,22 +169,22 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="line">
|
<div class="line">
|
||||||
<p>1,000</p>
|
<p>1,000</p>
|
||||||
<p>250 <span></span></p>
|
<p><?php echo $reward['data']['1000']; ?><span></span></p>
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="line">
|
<div class="line">
|
||||||
<p>10,000</p>
|
<p>10,000</p>
|
||||||
<p>1,000 <span></span></p>
|
<p><?php echo $reward['data']['10000']; ?><span></span></p>
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="line">
|
<div class="line">
|
||||||
<p>100,000</p>
|
<p>100,000</p>
|
||||||
<p>2,500 <span></span></p>
|
<p><?php echo $reward['data']['100000']; ?> <span></span></p>
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="line">
|
<div class="line">
|
||||||
<p>1,000,000</p>
|
<p>1,000,000</p>
|
||||||
<p>7,000 <span></span></p>
|
<p><?php echo $reward['data']['1000000']; ?> <span></span></p>
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -210,8 +208,4 @@
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<div class="to-top"><span>to top</span></div>
|
<div class="to-top"><span>to top</span></div>
|
||||||
<script type="text/javascript" src="/js/yt2/TweenMax.min.js"></script>
|
</main>
|
||||||
<script type="text/javascript" src="/js/yt2/ScrollToPlugin.min.js"></script>
|
|
||||||
<script type="text/javascript" src="/js/yt2/app.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
<title><?php echo $title ?></title>
|
<title><?php echo $title ?></title>
|
||||||
|
|
||||||
<link href='https://fonts.googleapis.com/css?family=Raleway:500,500italic,700' rel='stylesheet' type='text/css'>
|
<link href='https://fonts.googleapis.com/css?family=Raleway:500,500italic,700' rel='stylesheet' type='text/css'>
|
||||||
<link href="/css/all.css" rel="stylesheet" type="text/css" />
|
<?php foreach(Response::getCssAssets() as $src): ?>
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $src?>">
|
||||||
|
<?php endforeach ?>
|
||||||
<link rel="apple-touch-icon" sizes="60x60" href="/img/fav/apple-touch-icon-60x60.png">
|
<link rel="apple-touch-icon" sizes="60x60" href="/img/fav/apple-touch-icon-60x60.png">
|
||||||
<link rel="apple-touch-icon" sizes="114x114" href="/img/fav/apple-touch-icon-114x114.png">
|
<link rel="apple-touch-icon" sizes="114x114" href="/img/fav/apple-touch-icon-114x114.png">
|
||||||
<link rel="apple-touch-icon" sizes="120x120" href="/img/fav/apple-touch-icon-120x120.png">
|
<link rel="apple-touch-icon" sizes="120x120" href="/img/fav/apple-touch-icon-120x120.png">
|
||||||
|
|
|
@ -315,6 +315,8 @@ header .right a.github {
|
||||||
.claim .block {
|
.claim .block {
|
||||||
position: relative;
|
position: relative;
|
||||||
float: left;
|
float: left;
|
||||||
|
margin-top: 10px;
|
||||||
|
|
||||||
}
|
}
|
||||||
.claim input {
|
.claim input {
|
||||||
float: left;
|
float: left;
|
||||||
|
@ -344,6 +346,11 @@ header .right a.github {
|
||||||
-moz-box-shadow: 0 0 10px 0 rgba(0,0,0,0.15);
|
-moz-box-shadow: 0 0 10px 0 rgba(0,0,0,0.15);
|
||||||
box-shadow: 0 0 10px 0 rgba(0,0,0,0.15);
|
box-shadow: 0 0 10px 0 rgba(0,0,0,0.15);
|
||||||
}
|
}
|
||||||
|
.error_form{
|
||||||
|
-webkit-box-shadow:inset 0px 0px 0px 2px red;
|
||||||
|
-moz-box-shadow:inset 0px 0px 0px 2px red;
|
||||||
|
box-shadow:inset 0px 0px 0px 2px red;
|
||||||
|
}
|
||||||
.claim label {
|
.claim label {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
|
62
web/js/yt2/FormValidation.js
Normal file
62
web/js/yt2/FormValidation.js
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
function submitDetailsForm() {
|
||||||
|
$("#youtube_claim").submit(function (event) {
|
||||||
|
|
||||||
|
// get value from id
|
||||||
|
var lbry_channel_name = $.trim($('#lbry_channel_name').val());
|
||||||
|
var email = $.trim($('#email').val());
|
||||||
|
var youtube_url = $.trim($('#youtube_url').val());
|
||||||
|
|
||||||
|
// Make sure that the error message are hidden before trying to validate value
|
||||||
|
$('#lbry_error').hide();
|
||||||
|
$('#email_error').hide();
|
||||||
|
$('#youtube_url_error').hide();
|
||||||
|
|
||||||
|
// If the lbry name is invalid or blank stop the post request
|
||||||
|
if(!validateLBRYName(lbry_channel_name) || lbry_channel_name === '') {
|
||||||
|
$('#lbry_channel_name').addClass('error_form');
|
||||||
|
$('#lbry_error').show();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
// Show the other field if the LBRY channel name field is validated once
|
||||||
|
else{
|
||||||
|
// Check only if the two fields
|
||||||
|
if ($('#email').is(":visible") && $('#youtube_url').is(":visible")) {
|
||||||
|
// If the email is invalid or blank stop the post request
|
||||||
|
if (!validateEmail(email) || email === '') {
|
||||||
|
$('#email').addClass('error_form');
|
||||||
|
$('#email_error').show();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the youtube url is invalid or blank stop the post request
|
||||||
|
if (!validateYoutubeChannelUrl(youtube_url) || youtube_url === '') {
|
||||||
|
$('#youtube_url').addClass('error_form');
|
||||||
|
$('#youtube_url_error').show();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
$('#youtube_url').show();
|
||||||
|
$('#email').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateEmail(email) {
|
||||||
|
var re = /\S+@\S+\.\S+/;
|
||||||
|
return re.test(email);
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateLBRYName(lbry_channel_name){
|
||||||
|
var re = /[1-z]+/;
|
||||||
|
return re.test(lbry_channel_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateYoutubeChannelUrl(youtube_channel_url){
|
||||||
|
var re = /^UC[A-Za-z0-9_-]{22}$/;
|
||||||
|
return re.test(youtube_channel_url)
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue