LBRY for
-LBRY is
-diff --git a/controller/Controller.class.php b/controller/Controller.class.php index c6c8f3f6..aaf531a4 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -76,32 +76,40 @@ class Controller return static::redirect('https://github.com/lbryio/lbry/releases/download/v0.2.5/lbry_0.2.5_amd64.deb', 307); case '/art': return static::redirect('/what'); - default: - $newsPattern = '#^' . ContentActions::URL_NEWS . '(/|$)#'; - if (preg_match($newsPattern, $uri)) - { - $slug = preg_replace($newsPattern, '', $uri); - if ($slug == ContentActions::RSS_SLUG) - { - return ContentActions::executeRss(); - } - return $slug ? ContentActions::executePost($uri) : ContentActions::executeNews(); - } - $faqPattern = '#^' . ContentActions::URL_FAQ . '(/|$)#'; - if (preg_match($faqPattern, $uri)) - { - $slug = preg_replace($faqPattern, '', $uri); - return $slug ? ContentActions::executePost($uri) : ContentActions::executeFaq(); - } - $noSlashUri = ltrim($uri, '/'); - if (View::exists('page/' . $noSlashUri)) - { - return ['page/' . $noSlashUri, []]; - } - else - { - return ['page/404', [], [static::HEADER_STATUS => 404]]; - } + } + + $newsPattern = '#^' . ContentActions::URL_NEWS . '(/|$)#'; + if (preg_match($newsPattern, $uri)) + { + $slug = preg_replace($newsPattern, '', $uri); + if ($slug == ContentActions::RSS_SLUG) + { + return ContentActions::executeRss(); + } + return $slug ? ContentActions::executePost($uri) : ContentActions::executeNews(); + } + + $faqPattern = '#^' . ContentActions::URL_FAQ . '(/|$)#'; + if (preg_match($faqPattern, $uri)) + { + $slug = preg_replace($faqPattern, '', $uri); + return $slug ? ContentActions::executePost($uri) : ContentActions::executeFaq(); + } + $noSlashUri = ltrim($uri, '/'); + + $accessPattern = '#^/signup#'; + if (preg_match($accessPattern, $uri)) + { + return DownloadActions::executeSignup(); + } + + if (View::exists('page/' . $noSlashUri)) + { + return ['page/' . $noSlashUri, []]; + } + else + { + return ['page/404', [], [static::HEADER_STATUS => 404]]; } } @@ -139,7 +147,7 @@ class Controller unset($headers[static::HEADER_STATUS]); } } - + foreach($headers as $name => $value) { header($name . ': ' . $value); diff --git a/controller/Session.class.php b/controller/Session.class.php index a7d9a49c..a29e8d68 100644 --- a/controller/Session.class.php +++ b/controller/Session.class.php @@ -8,6 +8,9 @@ class Session { const KEY_MAILCHIMP_LIST_IDS = 'mailchimp_list_ids', + KEY_DOWNLOAD_ACCESS_ERROR = 'download_error', + KEY_DOWNLOAD_REFERRAL_CODE = 'beta_referral_code', + KEY_DOWNLOAD_ALLOWED = 'beta_download_allowed', KEY_LIST_SUB_ERROR = 'list_error', KEY_LIST_SUB_SIGNATURE = 'list_sub_sig', KEY_LIST_SUB_SUCCESS = 'list_success', diff --git a/controller/action/DownloadActions.class.php b/controller/action/DownloadActions.class.php index b1e9a319..f9425eb8 100644 --- a/controller/action/DownloadActions.class.php +++ b/controller/action/DownloadActions.class.php @@ -5,6 +5,9 @@ * * @author jeremy */ + +class PrefinerySubscribeException extends Exception {} + class DownloadActions extends Actions { const OS_ANDROID = 'android', @@ -25,6 +28,20 @@ class DownloadActions extends Actions } public static function executeGet() + { + if (Session::get(Session::KEY_DOWNLOAD_ALLOWED)) + { + return static::executeGetAccepted(); + } + + $os = static::guessOs(); + return ['download/get', [ + 'os' => $os + ]]; + } + + + public static function executeGetAccepted() { $osChoices = static::getOses(); $os = static::guessOs(); @@ -32,21 +49,67 @@ class DownloadActions extends Actions if ($os && isset($osChoices[$os])) { list($uri, $osTitle, $osIcon, $partial) = $osChoices[$os]; - return ['download/get', [ + $inviteCode = Session::get(Session::KEY_DOWNLOAD_REFERRAL_CODE); + return ['download/getAllowed', [ + 'inviteCode' => $inviteCode, 'os' => $os, 'osTitle' => $osTitle, 'osIcon' => $osIcon, - 'hasMatchingInvite' => isset($_POST['invite']) && preg_match('/^(pfa|pfb).*$/', $_POST['invite']), - 'hasInvite' => isset($_POST['invite']) && $_POST['invite'], 'downloadHtml' => View::exists('download/' . $partial) ? - View::render('download/' . $partial, ['downloadUrl' => static::getDownloadUrl($os)]) : - false + View::render('download/' . $partial, ['downloadUrl' => static::getDownloadUrl($os)]) : + false ]]; } - return ['download/get-no-os', [ - 'isSubscribed' => in_array(Mailchimp::LIST_GENERAL_ID, Session::get(Session::KEY_MAILCHIMP_LIST_IDS, [])) - ]]; + return ['download/get-no-os']; + } + + public static function executeSignup() + { + $email = isset($_GET['email']) ? $_GET['email'] : (isset($_POST['email']) ? $_POST['email'] : null); + $code = isset($_GET['code']) ? $_GET['code'] : (isset($_POST['code']) ? $_POST['code'] : null); + + if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) + { + Session::set(Session::KEY_DOWNLOAD_ACCESS_ERROR, 'Please provide a valid email. You provided: ' . $email); + } + elseif ($code) + { + try + { + static::subscribeToPrefinery($email, $code); + Session::set(Session::KEY_DOWNLOAD_ALLOWED, true); + } + catch (PrefinerySubscribeException $e) + { + Session::set(Session::KEY_DOWNLOAD_ACCESS_ERROR, 'Your code is not valid. If you believe this is an error, please contact ' . Config::HELP_CONTACT_EMAIL); + } + } + else + { + $referrerId = isset($_GET['referrer_id']) ? $_GET['referrer_id'] : (isset($_POST['referrer_id']) ? $_POST['referrer_id'] : null); + $failure = false; + try + { +// MailActions::subscribeToMailchimp($email, Mailchimp::LIST_GENERAL_ID); + static::subscribeToPrefinery($email, null, $referrerId); + } + catch (PrefinerySubscribeException $e) + { + $failure = true; + } + catch (MailchimpSubscribeException $e) + { + $failure = true; + } + if ($failure) + { + Session::set(Session::KEY_DOWNLOAD_ACCESS_ERROR, + 'We were unable to add you to the wait list due to a technical error. Please contact ' . Config::HELP_CONTACT_EMAIL . ' for bonus credits.'); + } + } + + return Controller::redirect('/get'); } public static function prepareListPartial(array $vars) @@ -57,6 +120,68 @@ class DownloadActions extends Actions ]; } + public static function subscribeToPrefinery($email, $inviteCode = null, $referrerId = null) + { + $apiKey = Config::get('prefinery_key'); + $options = [ + 'headers' => [ + 'Accept: application/json', + 'Content-type: application/json' + ], + 'json_post' => true + ]; + + $listUrl = 'https://lbry.prefinery.com/api/v2/betas/8679/testers.json?api_key=' . $apiKey; + + $body = Curl::get($listUrl, ['email' => $email], $options); + + if (!$body) + { + throw new PrefinerySubscribeException('Empty cURL response.'); + } + + $data = json_decode($body, true); + + if ($data && is_array($data) && count($data) && isset($data[0]['share_link'])) + { + $shareLink = $data[0]['share_link']; + } + else + { + $createUrl = 'https://lbry.prefinery.com/api/v2/betas/8679/testers.json?api_key=' . $apiKey; + + $params = [ + 'tester' => array_filter([ + 'email' => $email, + 'status' => $inviteCode ? 'invited' : 'applied', + 'invitation_code' => $inviteCode, + 'referrer_id' => $referrerId + ]) + ]; + + $body = Curl::post($createUrl, $params, $options); + + if (!$body) + { + throw new PrefinerySubscribeException('Empty cURL response.'); + } + + $data = json_decode($body, true); + + if (!$data || !isset($data['share_link'])) + { + throw new PrefinerySubscribeException('Missing share_link.'); + } + + $shareLink = $data['share_link']; + } + + preg_match('/\?r\=(\w+)/', $shareLink, $matches); + Session::set(Session::KEY_DOWNLOAD_REFERRAL_CODE, $matches[1] ?: 'unknown'); + + return true; + } + protected static function guessOs() { //if exact OS is requested, use that @@ -138,40 +263,4 @@ class DownloadActions extends Actions return null; } - -// protected static function validateDownloadAccess() -// { -// $seshionKey = 'has-get-access'; -// if (Session::get($seshionKey)) -// { -// return true; -// } -// -// if ($_SERVER['REQUEST_METHOD'] === 'POST') -// { -// $accessCodes = include ROOT_DIR . '/data/secret/access_list.php'; -// $today = date('Y-m-d H:i:s'); -// foreach($accessCodes as $code => $date) -// { -// if ($_POST['invite'] == $code && $today <= $date) -// { -// Session::set($seshionKey, true); -// Controller::redirect('/get', 302); -// } -// } -// -// if ($_POST['invite']) -// { -// Session::set('invite_error', 'Please provide a valid invite code.'); -// } -// else -// { -// Session::set('invite_error', 'Please provide an invite code.'); -// } -// -// Controller::redirect('/get', 401); -// } -// -// return false; -// } } diff --git a/controller/action/MailActions.class.php b/controller/action/MailActions.class.php index 9bd803d0..eafabcd7 100644 --- a/controller/action/MailActions.class.php +++ b/controller/action/MailActions.class.php @@ -29,11 +29,11 @@ class MailActions extends Actions } else { - $mcApi = new Mailchimp(); $mcListId = $_POST['listId']; $mergeFields = isset($_POST['mergeFields']) ? unserialize($_POST['mergeFields']) : []; - $success = $mcApi->listSubscribe($mcListId, $email, $mergeFields, 'html', false); - if ($success) + $errorOrSuccess = static::subscribeToMailchimp($email, $mcListId, $mergeFields); + + if ($errorOrSuccess === true) { Session::set(Session::KEY_MAILCHIMP_LIST_IDS, array_merge(Session::get(Session::KEY_MAILCHIMP_LIST_IDS, []), [$mcListId])); Session::set(Session::KEY_LIST_SUB_SUCCESS, true); @@ -41,14 +41,24 @@ class MailActions extends Actions } else { - $error = $mcApi->errorMessage ?: __('Something went wrong adding you to the list.'); - Session::set(Session::KEY_LIST_SUB_ERROR, $error); + Session::set(Session::KEY_LIST_SUB_ERROR, $errorOrSuccess); } } return Controller::redirect($nextUrl); } + public static function subscribeToMailchimp($email, $listId, array $mergeFields = []) + { + $mcApi = new Mailchimp(); + $success = $mcApi->listSubscribe($listId, $email, $mergeFields, 'html', false); + if (!$success) + { + throw new MailchimpSubscribeException($mcApi->errorMessage ?: __('Something went wrong adding you to the list.')); + } + return true; + } + public static function prepareJoinList(array $vars) { $vars['listSig'] = md5(serialize($vars)); diff --git a/lib/mailchimp/Mailchimp.class.php b/lib/mailchimp/Mailchimp.class.php index e3e489c3..12197b4a 100644 --- a/lib/mailchimp/Mailchimp.class.php +++ b/lib/mailchimp/Mailchimp.class.php @@ -1,5 +1,7 @@ - This is a pre-release, beta version of LBRY. - It may crash, work unreliably, or inadvertently put a curse on your family for generations (a common programming error). + This is still a beta. + While LBRY is now live, it may crash, work unreliably, or inadvertently put a curse on your family for generations (a common programming error). Use at your own risk. \ No newline at end of file diff --git a/view/template/download/_reward.php b/view/template/download/_reward.php index 689a11ca..e69de29b 100644 --- a/view/template/download/_reward.php +++ b/view/template/download/_reward.php @@ -1,30 +0,0 @@ - -
wonderfullife
. Continue to play as you desire.- In addition to , your feedback will be personally read by the developers and help signal - interest in LBRY to investors. -
- -wonderfullife
- In addition to , your feedback will be personally read by the developers and help signal - interest in LBRY to investors. -
- Provide Your Feedback -LBRY is coming out on your favorite platform soon. Join our list to know when.
-Can't wait? View the source and compile instructions on - GitHub. -
+LBRY is not yet out on your platform. You will receive an email as we expand LBRY to your preferred platform.
+ +Arrival is expected by July 5.
+ +Arrival is expected this month.
+ +LBRY is
-LBRY is currently in invite only mode. Enter your code below for access:
- - -Your code does not grant access until July 4th, 2016. Enter your email address below for a reminder.
- 'Go', - 'returnUrl' => '/get', - 'meta' => true, - 'btnClass' => 'btn-alt', - 'listId' => Mailchimp::LIST_GENERAL_ID, - 'mergeFields' => ['CLI' => 'No'], - ]) ?> +You are currently on the wait list. Move up the list and earn per referral by sharing this URL:
+ +LBRY is currently in invite only mode. Enter your email to join the waitlist, or your email and invite code for access.
+ + + (function(){ + var form = $('#signup-form'), + codeRadioInputs = form.find('input[name="code_select"]'); + codeRadioInputs.change(function() { + var selectedInput = codeRadioInputs.filter(':checked'), + choice = selectedInput.val(), + hasChoice = selectedInput.length, + hasCode = choice == 'yes'; + + form.find('.has-code')[hasChoice && hasCode ? 'show' : 'hide'](); + form.find('.no-code')[hasChoice && !hasCode ? 'show' : 'hide'](); + if (!hasCode) + { + form.find('input[name="code"]').val(''); + } + }).change(); + + form.show(); + })(); +Earn per referral by sharing this URL:
+ + $inviteCode + ]) ?> +