mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 09:37:26 +00:00
Adjust site to use PSR-2 coding standard
This commit is contained in:
parent
3acdae342e
commit
771b205d79
74 changed files with 3377 additions and 3739 deletions
27
autoload.php
27
autoload.php
|
@ -5,16 +5,14 @@ class Autoloader
|
||||||
|
|
||||||
public static function autoload($class)
|
public static function autoload($class)
|
||||||
{
|
{
|
||||||
if (class_exists($class, false) || interface_exists($class, false))
|
if (class_exists($class, false) || interface_exists($class, false)) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = strtolower($class);
|
$class = strtolower($class);
|
||||||
$path = static::$classes[$class] ?? false;
|
$path = static::$classes[$class] ?? false;
|
||||||
|
|
||||||
if ($path)
|
if ($path) {
|
||||||
{
|
|
||||||
require_once $path;
|
require_once $path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -25,11 +23,9 @@ class Autoloader
|
||||||
public static function reload($reload = false)
|
public static function reload($reload = false)
|
||||||
{
|
{
|
||||||
$key = 'lbry-classes-5';
|
$key = 'lbry-classes-5';
|
||||||
if (ini_get('apc.enabled') && !$reload)
|
if (ini_get('apc.enabled') && !$reload) {
|
||||||
{
|
|
||||||
$classes = apc_fetch($key, $success);
|
$classes = apc_fetch($key, $success);
|
||||||
if ($success)
|
if ($success) {
|
||||||
{
|
|
||||||
static::$classes = $classes;
|
static::$classes = $classes;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -40,16 +36,13 @@ class Autoloader
|
||||||
$dir = new RecursiveDirectoryIterator(ROOT_DIR, RecursiveDirectoryIterator::SKIP_DOTS);
|
$dir = new RecursiveDirectoryIterator(ROOT_DIR, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||||
$ite = new RecursiveIteratorIterator($dir);
|
$ite = new RecursiveIteratorIterator($dir);
|
||||||
$pathIterator = new RegexIterator($ite, '/.*\.php$/', RegexIterator::GET_MATCH);
|
$pathIterator = new RegexIterator($ite, '/.*\.php$/', RegexIterator::GET_MATCH);
|
||||||
foreach($pathIterator as $paths)
|
foreach ($pathIterator as $paths) {
|
||||||
{
|
foreach ($paths as $path) {
|
||||||
foreach($paths as $path)
|
|
||||||
{
|
|
||||||
static::$classes += static::parseFile($path);
|
static::$classes += static::parseFile($path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ini_get('apc.enabled'))
|
if (ini_get('apc.enabled')) {
|
||||||
{
|
|
||||||
apc_store($key, static::$classes);
|
apc_store($key, static::$classes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,15 +55,13 @@ class Autoloader
|
||||||
preg_match_all('~^\s*(?:namespace)\s+([^;]+)~mi', file_get_contents($path), $namespaces);
|
preg_match_all('~^\s*(?:namespace)\s+([^;]+)~mi', file_get_contents($path), $namespaces);
|
||||||
preg_match_all('~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi', file_get_contents($path), $classes);
|
preg_match_all('~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi', file_get_contents($path), $classes);
|
||||||
|
|
||||||
if (isset($namespaces[1]) && count($namespaces[1]) > 2)
|
if (isset($namespaces[1]) && count($namespaces[1]) > 2) {
|
||||||
{
|
|
||||||
throw new RuntimeException('Autoloader cannot handle 2 namespaces in the same file');
|
throw new RuntimeException('Autoloader cannot handle 2 namespaces in the same file');
|
||||||
}
|
}
|
||||||
|
|
||||||
$prefix = isset($namespaces[1]) && count($namespaces[1]) ? reset($namespaces[1]) . '\\' : '';
|
$prefix = isset($namespaces[1]) && count($namespaces[1]) ? reset($namespaces[1]) . '\\' : '';
|
||||||
|
|
||||||
foreach ($classes[1] as $class)
|
foreach ($classes[1] as $class) {
|
||||||
{
|
|
||||||
$mapping[strtolower($prefix . $class)] = $path;
|
$mapping[strtolower($prefix . $class)] = $path;
|
||||||
}
|
}
|
||||||
return $mapping;
|
return $mapping;
|
||||||
|
|
|
@ -8,30 +8,23 @@ class Controller
|
||||||
|
|
||||||
public static function dispatch($uri)
|
public static function dispatch($uri)
|
||||||
{
|
{
|
||||||
try
|
try {
|
||||||
{
|
if (IS_PRODUCTION && function_exists('newrelic_name_transaction')) {
|
||||||
if (IS_PRODUCTION && function_exists('newrelic_name_transaction'))
|
|
||||||
{
|
|
||||||
newrelic_name_transaction(Request::getMethod() . ' ' . strtolower($uri));
|
newrelic_name_transaction(Request::getMethod() . ' ' . strtolower($uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
$viewAndParams = static::execute(Request::getMethod(), $uri);
|
$viewAndParams = static::execute(Request::getMethod(), $uri);
|
||||||
$viewTemplate = $viewAndParams[0];
|
$viewTemplate = $viewAndParams[0];
|
||||||
$viewParameters = $viewAndParams[1] ?? [];
|
$viewParameters = $viewAndParams[1] ?? [];
|
||||||
if (!IS_PRODUCTION && isset($viewAndParams[2]))
|
if (!IS_PRODUCTION && isset($viewAndParams[2])) {
|
||||||
{
|
|
||||||
throw new Exception('use response::setheader instead of returning headers');
|
throw new Exception('use response::setheader instead of returning headers');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$viewTemplate)
|
if (!$viewTemplate) {
|
||||||
{
|
if ($viewTemplate !== null) {
|
||||||
if ($viewTemplate !== null)
|
|
||||||
{
|
|
||||||
throw new LogicException('All execute methods must return a template or NULL.');
|
throw new LogicException('All execute methods must return a template or NULL.');
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$layout = !(isset($viewParameters['_no_layout']) && $viewParameters['_no_layout']);
|
$layout = !(isset($viewParameters['_no_layout']) && $viewParameters['_no_layout']);
|
||||||
unset($viewParameters['_no_layout']);
|
unset($viewParameters['_no_layout']);
|
||||||
|
|
||||||
|
@ -44,16 +37,12 @@ class Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::setDefaultSecurityHeaders();
|
Response::setDefaultSecurityHeaders();
|
||||||
if (Request::isGzipAccepted())
|
if (Request::isGzipAccepted()) {
|
||||||
{
|
|
||||||
Response::gzipContentIfNotDisabled();
|
Response::gzipContentIfNotDisabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::send();
|
Response::send();
|
||||||
}
|
} catch (StopException $e) {
|
||||||
catch (StopException $e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,17 +50,12 @@ class Controller
|
||||||
{
|
{
|
||||||
$router = static::getRouterWithRoutes();
|
$router = static::getRouterWithRoutes();
|
||||||
static::performSubdomainRedirects();
|
static::performSubdomainRedirects();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$dispatcher = new Routing\Dispatcher($router->getData());
|
$dispatcher = new Routing\Dispatcher($router->getData());
|
||||||
return $dispatcher->dispatch($method, $uri);
|
return $dispatcher->dispatch($method, $uri);
|
||||||
}
|
} catch (\Routing\HttpRouteNotFoundException $e) {
|
||||||
catch (\Routing\HttpRouteNotFoundException $e)
|
|
||||||
{
|
|
||||||
return NavActions::execute404();
|
return NavActions::execute404();
|
||||||
}
|
} catch (\Routing\HttpMethodNotAllowedException $e) {
|
||||||
catch (\Routing\HttpMethodNotAllowedException $e)
|
|
||||||
{
|
|
||||||
Response::setStatus(405);
|
Response::setStatus(405);
|
||||||
Response::setHeader('Allow', implode(', ', $e->getAllowedMethods()));
|
Response::setHeader('Allow', implode(', ', $e->getAllowedMethods()));
|
||||||
return ['page/405'];
|
return ['page/405'];
|
||||||
|
@ -97,8 +81,7 @@ class Controller
|
||||||
|
|
||||||
$router->get(['/get', 'get'], 'DownloadActions::executeGet');
|
$router->get(['/get', 'get'], 'DownloadActions::executeGet');
|
||||||
$router->get(['/getrubin', 'getrubin'], 'DownloadActions::executeGet');
|
$router->get(['/getrubin', 'getrubin'], 'DownloadActions::executeGet');
|
||||||
foreach(array_keys(OS::getAll()) as $os)
|
foreach (array_keys(OS::getAll()) as $os) {
|
||||||
{
|
|
||||||
$router->get(['/' . $os, 'get-' . $os], 'DownloadActions::executeGet');
|
$router->get(['/' . $os, 'get-' . $os], 'DownloadActions::executeGet');
|
||||||
}
|
}
|
||||||
$router->get('/roadmap', 'ContentActions::executeRoadmap');
|
$router->get('/roadmap', 'ContentActions::executeRoadmap');
|
||||||
|
@ -139,11 +122,11 @@ class Controller
|
||||||
$permanentRedirects = SpyC::YAMLLoadString(file_get_contents($permanentRedirectsPath));
|
$permanentRedirects = SpyC::YAMLLoadString(file_get_contents($permanentRedirectsPath));
|
||||||
$tempRedirects = SpyC::YAMLLoadString(file_get_contents($tempRedirectsPath));
|
$tempRedirects = SpyC::YAMLLoadString(file_get_contents($tempRedirectsPath));
|
||||||
|
|
||||||
foreach ([307 => $tempRedirects, 301 => $permanentRedirects] as $code => $redirects)
|
foreach ([307 => $tempRedirects, 301 => $permanentRedirects] as $code => $redirects) {
|
||||||
{
|
foreach ($redirects as $src => $target) {
|
||||||
foreach ($redirects as $src => $target)
|
$router->any($src, function () use ($target, $code) {
|
||||||
{
|
return static::redirect($target, $code);
|
||||||
$router->any($src, function () use ($target, $code) { return static::redirect($target, $code); });
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,15 +142,11 @@ class Controller
|
||||||
$router->get(ContentActions::URL_CREDIT_REPORTS, 'ContentActions::executeCreditReports');
|
$router->get(ContentActions::URL_CREDIT_REPORTS, 'ContentActions::executeCreditReports');
|
||||||
$router->get([ContentActions::URL_CREDIT_REPORTS . '/{year:c}-q{quarter:c}', ContentActions::URL_CREDIT_REPORTS . '/{year:c}-Q{quarter:c}'], 'ContentActions::executeCreditReport');
|
$router->get([ContentActions::URL_CREDIT_REPORTS . '/{year:c}-q{quarter:c}', ContentActions::URL_CREDIT_REPORTS . '/{year:c}-Q{quarter:c}'], 'ContentActions::executeCreditReport');
|
||||||
|
|
||||||
$router->get('/{slug}', function (string $slug)
|
$router->get('/{slug}', function (string $slug) {
|
||||||
{
|
if (View::exists('page/' . $slug)) {
|
||||||
if (View::exists('page/' . $slug))
|
|
||||||
{
|
|
||||||
Response::enableHttpCache();
|
Response::enableHttpCache();
|
||||||
return ['page/' . $slug, []];
|
return ['page/' . $slug, []];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return NavActions::execute404();
|
return NavActions::execute404();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -177,8 +156,7 @@ class Controller
|
||||||
|
|
||||||
public static function redirect($url, $statusCode = 302)
|
public static function redirect($url, $statusCode = 302)
|
||||||
{
|
{
|
||||||
if (!$url)
|
if (!$url) {
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('Cannot redirect to an empty URL.');
|
throw new InvalidArgumentException('Cannot redirect to an empty URL.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,8 +164,7 @@ class Controller
|
||||||
|
|
||||||
Response::setStatus($statusCode);
|
Response::setStatus($statusCode);
|
||||||
|
|
||||||
if ($statusCode == 201 || ($statusCode >= 300 && $statusCode < 400))
|
if ($statusCode == 201 || ($statusCode >= 300 && $statusCode < 400)) {
|
||||||
{
|
|
||||||
Response::setHeader(Response::HEADER_LOCATION, $url);
|
Response::setHeader(Response::HEADER_LOCATION, $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,8 +178,7 @@ class Controller
|
||||||
|
|
||||||
public static function shutdown()
|
public static function shutdown()
|
||||||
{
|
{
|
||||||
while ($fn = array_shift(static::$queuedFunctions))
|
while ($fn = array_shift(static::$queuedFunctions)) {
|
||||||
{
|
|
||||||
call_user_func($fn);
|
call_user_func($fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,7 @@ class Request
|
||||||
|
|
||||||
public static function getMethod(): string
|
public static function getMethod(): string
|
||||||
{
|
{
|
||||||
if (!static::$method)
|
if (!static::$method) {
|
||||||
{
|
|
||||||
$method = static::getHeader('REQUEST_METHOD') ? strtoupper(static::getHeader('REQUEST_METHOD')) : null;
|
$method = static::getHeader('REQUEST_METHOD') ? strtoupper(static::getHeader('REQUEST_METHOD')) : null;
|
||||||
|
|
||||||
static::$method = in_array($method, [static::GET, static::POST, static::HEAD, static::OPTIONS]) ? $method : static::GET;
|
static::$method = in_array($method, [static::GET, static::POST, static::HEAD, static::OPTIONS]) ? $method : static::GET;
|
||||||
|
@ -77,8 +76,7 @@ class Request
|
||||||
public static function getRoutingUri()
|
public static function getRoutingUri()
|
||||||
{
|
{
|
||||||
$host = preg_replace('/^www\./', '', static::getHost());
|
$host = preg_replace('/^www\./', '', static::getHost());
|
||||||
switch($host)
|
switch ($host) {
|
||||||
{
|
|
||||||
case 'betteryoutube.com':
|
case 'betteryoutube.com':
|
||||||
case 'lbrycreators.com':
|
case 'lbrycreators.com':
|
||||||
return '/youtube';
|
return '/youtube';
|
||||||
|
@ -98,15 +96,13 @@ class Request
|
||||||
$domainParts = explode('.', $host);
|
$domainParts = explode('.', $host);
|
||||||
$domainPartCount = count($domainParts);
|
$domainPartCount = count($domainParts);
|
||||||
|
|
||||||
if (count($domainParts) < 1)
|
if (count($domainParts) < 1) {
|
||||||
{
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$isLocalhost = $domainParts[$domainPartCount - 1] === 'localhost';
|
$isLocalhost = $domainParts[$domainPartCount - 1] === 'localhost';
|
||||||
|
|
||||||
if (count($domainParts) < ($isLocalhost ? 2 : 3))
|
if (count($domainParts) < ($isLocalhost ? 2 : 3)) {
|
||||||
{
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +152,8 @@ class Request
|
||||||
return preg_match('/(' . join('|', $bots) . ')/i', static::getUserAgent());
|
return preg_match('/(' . join('|', $bots) . ')/i', static::getUserAgent());
|
||||||
}
|
}
|
||||||
//Method that encode html tags to special character
|
//Method that encode html tags to special character
|
||||||
public static function encodeStringFromUser($string){
|
public static function encodeStringFromUser($string)
|
||||||
|
{
|
||||||
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
|
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,13 @@ class Session
|
||||||
ini_set('session.cookie_httponly', true); // no js access to cookies
|
ini_set('session.cookie_httponly', true); // no js access to cookies
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
if (!static::get('secure_and_httponly_set'))
|
if (!static::get('secure_and_httponly_set')) {
|
||||||
{
|
|
||||||
session_regenerate_id(); // ensure that old cookies get new settings
|
session_regenerate_id(); // ensure that old cookies get new settings
|
||||||
}
|
}
|
||||||
static::set('secure_and_httponly_set', true);
|
static::set('secure_and_httponly_set', true);
|
||||||
|
|
||||||
// migrate existing session data into namespaced session
|
// migrate existing session data into namespaced session
|
||||||
if (!static::getNamespace(static::NAMESPACE_DEFAULT))
|
if (!static::getNamespace(static::NAMESPACE_DEFAULT)) {
|
||||||
{
|
|
||||||
$oldSession = deserialize(serialize($_SESSION)) ?: [];
|
$oldSession = deserialize(serialize($_SESSION)) ?: [];
|
||||||
session_unset();
|
session_unset();
|
||||||
static::setNamespace(static::NAMESPACE_DEFAULT, $oldSession);
|
static::setNamespace(static::NAMESPACE_DEFAULT, $oldSession);
|
||||||
|
@ -71,8 +69,7 @@ class Session
|
||||||
|
|
||||||
protected static function initFlashes()
|
protected static function initFlashes()
|
||||||
{
|
{
|
||||||
foreach(static::getNamespace(static::NAMESPACE_FLASH) as $key => $val)
|
foreach (static::getNamespace(static::NAMESPACE_FLASH) as $key => $val) {
|
||||||
{
|
|
||||||
static::set($key, true, static::NAMESPACE_FLASH_REMOVE);
|
static::set($key, true, static::NAMESPACE_FLASH_REMOVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +78,7 @@ class Session
|
||||||
|
|
||||||
public static function cleanupFlashes()
|
public static function cleanupFlashes()
|
||||||
{
|
{
|
||||||
foreach(array_keys(static::getNamespace(static::NAMESPACE_FLASH_REMOVE)) as $flashName)
|
foreach (array_keys(static::getNamespace(static::NAMESPACE_FLASH_REMOVE)) as $flashName) {
|
||||||
{
|
|
||||||
static::unsetKey($flashName, static::NAMESPACE_FLASH);
|
static::unsetKey($flashName, static::NAMESPACE_FLASH);
|
||||||
static::unsetKey($flashName, static::NAMESPACE_FLASH_REMOVE);
|
static::unsetKey($flashName, static::NAMESPACE_FLASH_REMOVE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,44 +69,39 @@ class AcquisitionActions extends Actions
|
||||||
|
|
||||||
public static function actionYoutubeToken(string $desired_lbry_channel_name)
|
public static function actionYoutubeToken(string $desired_lbry_channel_name)
|
||||||
{
|
{
|
||||||
|
|
||||||
$desired_lbry_channel_name_is_valid = static::lbry_channel_verification($desired_lbry_channel_name);
|
$desired_lbry_channel_name_is_valid = static::lbry_channel_verification($desired_lbry_channel_name);
|
||||||
|
|
||||||
if ($desired_lbry_channel_name_is_valid) {
|
if ($desired_lbry_channel_name_is_valid) {
|
||||||
$token = LBRY::connectYoutube($desired_lbry_channel_name);
|
$token = LBRY::connectYoutube($desired_lbry_channel_name);
|
||||||
if ($token['success'] == false) {
|
if ($token['success'] == false) {
|
||||||
Controller::redirect('/youtube?error=true&error_message=' . $token['error']);
|
Controller::redirect('/youtube?error=true&error_message=' . $token['error']);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Controller::redirect($token['data']);
|
Controller::redirect($token['data']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function actionYoutubeEdit($status_token, $channel_name, $email, $sync_consent)
|
public static function actionYoutubeEdit($status_token, $channel_name, $email, $sync_consent)
|
||||||
{
|
{
|
||||||
$current_value = LBRY::statusYoutube($status_token);
|
$current_value = LBRY::statusYoutube($status_token);
|
||||||
if($current_value['data']['email'] == $email)
|
if ($current_value['data']['email'] == $email) {
|
||||||
{
|
|
||||||
$status = LBRY::editYoutube($status_token, $channel_name, null, $sync_consent);
|
$status = LBRY::editYoutube($status_token, $channel_name, null, $sync_consent);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$status = LBRY::editYoutube($status_token, $channel_name, $email, $sync_consent);
|
$status = LBRY::editYoutube($status_token, $channel_name, $email, $sync_consent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($status['success'] == false) {
|
if ($status['success'] == false) {
|
||||||
Controller::redirect("/youtube/status/". $status_token . "?error=true&error_message=" . $status['error']);
|
Controller::redirect("/youtube/status/". $status_token . "?error=true&error_message=" . $status['error']);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
Controller::redirect("/youtube/status/" . $status_token);
|
Controller::redirect("/youtube/status/" . $status_token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function executeYoutubeEdit(){
|
public static function executeYoutubeEdit()
|
||||||
|
{
|
||||||
return ['acquisition/youtube_edit'];
|
return ['acquisition/youtube_edit'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function executeRedirectYoutube(){
|
public static function executeRedirectYoutube()
|
||||||
|
{
|
||||||
return ['acquisition/youtube_status_redirect'];
|
return ['acquisition/youtube_status_redirect'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,16 +36,15 @@ class ContentActions extends Actions
|
||||||
{
|
{
|
||||||
Response::enableHttpCache();
|
Response::enableHttpCache();
|
||||||
|
|
||||||
if (!$slug || $slug == static::SLUG_RSS)
|
if (!$slug || $slug == static::SLUG_RSS) {
|
||||||
{
|
|
||||||
$posts = array_filter(
|
$posts = array_filter(
|
||||||
Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC),
|
Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC),
|
||||||
function (Post $post) {
|
function (Post $post) {
|
||||||
return !$post->getDate() || $post->getDate()->format('U') <= date('U');
|
return !$post->getDate() || $post->getDate()->format('U') <= date('U');
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if ($slug == static::SLUG_RSS)
|
if ($slug == static::SLUG_RSS) {
|
||||||
{
|
|
||||||
Response::setHeader(Response::HEADER_CONTENT_TYPE, 'text/xml; charset=utf-8');
|
Response::setHeader(Response::HEADER_CONTENT_TYPE, 'text/xml; charset=utf-8');
|
||||||
return ['content/rss', [
|
return ['content/rss', [
|
||||||
'posts' => array_slice($posts, 0, 10),
|
'posts' => array_slice($posts, 0, 10),
|
||||||
|
@ -61,12 +60,9 @@ class ContentActions extends Actions
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$post = Post::load(static::SLUG_NEWS . '/' . ltrim($slug, '/'));
|
$post = Post::load(static::SLUG_NEWS . '/' . ltrim($slug, '/'));
|
||||||
}
|
} catch (PostNotFoundException $e) {
|
||||||
catch (PostNotFoundException $e)
|
|
||||||
{
|
|
||||||
return NavActions::execute404();
|
return NavActions::execute404();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +78,7 @@ class ContentActions extends Actions
|
||||||
{
|
{
|
||||||
Response::enableHttpCache();
|
Response::enableHttpCache();
|
||||||
|
|
||||||
if (!$slug)
|
if (!$slug) {
|
||||||
{
|
|
||||||
$allPosts = Post::find(static::VIEW_FOLDER_FAQ, Post::SORT_ORD_ASC);
|
$allPosts = Post::find(static::VIEW_FOLDER_FAQ, Post::SORT_ORD_ASC);
|
||||||
|
|
||||||
$allCategories = [
|
$allCategories = [
|
||||||
|
@ -109,8 +104,7 @@ class ContentActions extends Actions
|
||||||
|
|
||||||
$groups = array_fill_keys(array_keys($allCategories), []);
|
$groups = array_fill_keys(array_keys($allCategories), []);
|
||||||
|
|
||||||
foreach ($posts as $post)
|
foreach ($posts as $post) {
|
||||||
{
|
|
||||||
$groups[$post->getCategory()][] = $post;
|
$groups[$post->getCategory()][] = $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,12 +115,9 @@ class ContentActions extends Actions
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$post = Post::load(static::SLUG_FAQ . '/' . ltrim($slug, '/'));
|
$post = Post::load(static::SLUG_FAQ . '/' . ltrim($slug, '/'));
|
||||||
}
|
} catch (PostNotFoundException $e) {
|
||||||
catch (PostNotFoundException $e)
|
|
||||||
{
|
|
||||||
return Controller::redirect('/' . static::SLUG_FAQ);
|
return Controller::redirect('/' . static::SLUG_FAQ);
|
||||||
}
|
}
|
||||||
return ['content/faq-post', ['post' => $post]];
|
return ['content/faq-post', ['post' => $post]];
|
||||||
|
@ -146,15 +137,11 @@ class ContentActions extends Actions
|
||||||
|
|
||||||
public static function executeCreditReport(string $year = null, string $quarter = null): array
|
public static function executeCreditReport(string $year = null, string $quarter = null): array
|
||||||
{
|
{
|
||||||
|
|
||||||
Response::enableHttpCache();
|
Response::enableHttpCache();
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$post = Post::load(static::SLUG_CREDIT_REPORTS . '/' . $year . '-Q' . $quarter);
|
$post = Post::load(static::SLUG_CREDIT_REPORTS . '/' . $year . '-Q' . $quarter);
|
||||||
}
|
} catch (PostNotFoundException $e) {
|
||||||
catch (PostNotFoundException $e)
|
|
||||||
{
|
|
||||||
return Controller::redirect('/' . static::SLUG_CREDIT_REPORTS);
|
return Controller::redirect('/' . static::SLUG_CREDIT_REPORTS);
|
||||||
}
|
}
|
||||||
$metadata = $post->getMetadata();
|
$metadata = $post->getMetadata();
|
||||||
|
@ -167,12 +154,9 @@ class ContentActions extends Actions
|
||||||
public static function executePress(string $slug = null): array
|
public static function executePress(string $slug = null): array
|
||||||
{
|
{
|
||||||
Response::enableHttpCache();
|
Response::enableHttpCache();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$post = Post::load(static::SLUG_PRESS . '/' . ltrim($slug, '/'));
|
$post = Post::load(static::SLUG_PRESS . '/' . ltrim($slug, '/'));
|
||||||
}
|
} catch (PostNotFoundException $e) {
|
||||||
catch (PostNotFoundException $e)
|
|
||||||
{
|
|
||||||
return NavActions::execute404();
|
return NavActions::execute404();
|
||||||
}
|
}
|
||||||
return ['content/press-post', ['post' => $post]];
|
return ['content/press-post', ['post' => $post]];
|
||||||
|
@ -189,14 +173,12 @@ class ContentActions extends Actions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($slug)
|
if ($slug) {
|
||||||
{
|
|
||||||
list($metadata, $postHtml) = View::parseMarkdown(ContentActions::VIEW_FOLDER_BOUNTY . '/' . $slug . '.md');
|
list($metadata, $postHtml) = View::parseMarkdown(ContentActions::VIEW_FOLDER_BOUNTY . '/' . $slug . '.md');
|
||||||
|
|
||||||
$metadata['lbc_award'] = static::convertBountyAmount($metadata['award']);
|
$metadata['lbc_award'] = static::convertBountyAmount($metadata['award']);
|
||||||
|
|
||||||
if (!$postHtml)
|
if (!$postHtml) {
|
||||||
{
|
|
||||||
return NavActions::execute404();
|
return NavActions::execute404();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,8 +208,7 @@ class ContentActions extends Actions
|
||||||
$metadataB = $postB->getMetadata();
|
$metadataB = $postB->getMetadata();
|
||||||
$awardA = strpos('-', $metadataA['award']) !== false ? rtrim(explode('-', $metadataA['award'])[0], '+') : $metadataA['award'];
|
$awardA = strpos('-', $metadataA['award']) !== false ? rtrim(explode('-', $metadataA['award'])[0], '+') : $metadataA['award'];
|
||||||
$awardB = strpos('-', $metadataB['award']) !== false ? rtrim(explode('-', $metadataB['award'])[0], '+') : $metadataB['award'];
|
$awardB = strpos('-', $metadataB['award']) !== false ? rtrim(explode('-', $metadataB['award'])[0], '+') : $metadataB['award'];
|
||||||
if ($awardA != $awardB)
|
if ($awardA != $awardB) {
|
||||||
{
|
|
||||||
return $awardA > $awardB ? -1 : 1;
|
return $awardA > $awardB ? -1 : 1;
|
||||||
}
|
}
|
||||||
return $metadataA['title'] < $metadataB['title'] ? -1 : 1;
|
return $metadataA['title'] < $metadataB['title'] ? -1 : 1;
|
||||||
|
@ -252,14 +233,11 @@ class ContentActions extends Actions
|
||||||
$cache = !Request::getParam('nocache');
|
$cache = !Request::getParam('nocache');
|
||||||
$githubItems = Github::listRoadmapChangesets($cache);
|
$githubItems = Github::listRoadmapChangesets($cache);
|
||||||
$projectMaxVersions = [];
|
$projectMaxVersions = [];
|
||||||
foreach($githubItems as $group => $items)
|
foreach ($githubItems as $group => $items) {
|
||||||
{
|
if ($items) {
|
||||||
if ($items)
|
|
||||||
{
|
|
||||||
$firstItem = reset($items);
|
$firstItem = reset($items);
|
||||||
$project = $firstItem['project'];
|
$project = $firstItem['project'];
|
||||||
if (!isset($projectMaxVersions[$project]) || $firstItem['sort_key'] > $projectMaxVersions[$project])
|
if (!isset($projectMaxVersions[$project]) || $firstItem['sort_key'] > $projectMaxVersions[$project]) {
|
||||||
{
|
|
||||||
$projectMaxVersions[$project] = $firstItem['sort_key'];
|
$projectMaxVersions[$project] = $firstItem['sort_key'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,15 +275,13 @@ class ContentActions extends Actions
|
||||||
//
|
//
|
||||||
// $zip->addFromString('press.html', $html);
|
// $zip->addFromString('press.html', $html);
|
||||||
|
|
||||||
foreach (glob(ROOT_DIR . '/web/img/press/*') as $productImgPath)
|
foreach (glob(ROOT_DIR . '/web/img/press/*') as $productImgPath) {
|
||||||
{
|
|
||||||
$imgPathTokens = explode('/', $productImgPath);
|
$imgPathTokens = explode('/', $productImgPath);
|
||||||
$imgName = $imgPathTokens[count($imgPathTokens) - 1];
|
$imgName = $imgPathTokens[count($imgPathTokens) - 1];
|
||||||
$zip->addFile($productImgPath, '/logo_and_product/' . $imgName);
|
$zip->addFile($productImgPath, '/logo_and_product/' . $imgName);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (glob(ContentActions::CONTENT_DIR . '/bio/*.md') as $bioPath)
|
foreach (glob(ContentActions::CONTENT_DIR . '/bio/*.md') as $bioPath) {
|
||||||
{
|
|
||||||
list($metadata, $bioHtml) = View::parseMarkdown($bioPath);
|
list($metadata, $bioHtml) = View::parseMarkdown($bioPath);
|
||||||
$zip->addFile($bioPath, '/team_bios/' . $metadata['name'] . ' - ' . $metadata['role'] . '.txt');
|
$zip->addFile($bioPath, '/team_bios/' . $metadata['name'] . ' - ' . $metadata['role'] . '.txt');
|
||||||
}
|
}
|
||||||
|
@ -347,7 +323,6 @@ class ContentActions extends Actions
|
||||||
'bioHtml' => $bioHtml,
|
'bioHtml' => $bioHtml,
|
||||||
'orientation' => 'vertical'
|
'orientation' => 'vertical'
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function preparePostAuthorPartial(array $vars): array
|
public static function preparePostAuthorPartial(array $vars): array
|
||||||
|
@ -380,7 +355,8 @@ class ContentActions extends Actions
|
||||||
Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC),
|
Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC),
|
||||||
function (Post $post) use ($category) {
|
function (Post $post) use ($category) {
|
||||||
return (($post->getCategory() === $category) && (!$post->getDate() || $post->getDate()->format('U') <= date('U')));
|
return (($post->getCategory() === $category) && (!$post->getDate() || $post->getDate()->format('U') <= date('U')));
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -397,7 +373,9 @@ class ContentActions extends Actions
|
||||||
$jobs =
|
$jobs =
|
||||||
array_filter(
|
array_filter(
|
||||||
array_map('View::parseMarkdown', glob(static::VIEW_FOLDER_JOBS . '/*')),
|
array_map('View::parseMarkdown', glob(static::VIEW_FOLDER_JOBS . '/*')),
|
||||||
function($job) { return $job[0]['status'] !== 'closed'; }
|
function ($job) {
|
||||||
|
return $job[0]['status'] !== 'closed';
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
usort($jobs, function ($jobA, $jobB) {
|
usort($jobs, function ($jobA, $jobB) {
|
||||||
|
|
|
@ -21,10 +21,8 @@ class DeveloperActions extends Actions
|
||||||
'stepLabels' => $stepLabels
|
'stepLabels' => $stepLabels
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($currentStep !== 'all')
|
if ($currentStep !== 'all') {
|
||||||
{
|
if (!isset($stepLabels[$currentStep])) {
|
||||||
if (!isset($stepLabels[$currentStep]))
|
|
||||||
{
|
|
||||||
Controller::redirect('/quickstart');
|
Controller::redirect('/quickstart');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,13 +78,11 @@ class DeveloperActions extends Actions
|
||||||
Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, trim(Request::getPostParam('wallet_address')));
|
Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, trim(Request::getPostParam('wallet_address')));
|
||||||
Session::set(Session::KEY_DEVELOPER_LAST_FORM, Request::getPostParam('formName'));
|
Session::set(Session::KEY_DEVELOPER_LAST_FORM, Request::getPostParam('formName'));
|
||||||
|
|
||||||
if (Request::getPostParam('returnUrl'))
|
if (Request::getPostParam('returnUrl')) {
|
||||||
{
|
|
||||||
Session::set(Session::KEY_DEVELOPER_RETURN_URL_SUCCESS, Request::getPostParam('returnUrl'));
|
Session::set(Session::KEY_DEVELOPER_RETURN_URL_SUCCESS, Request::getPostParam('returnUrl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID))
|
if (!Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID)) {
|
||||||
{
|
|
||||||
throw new Exception('no github client id');
|
throw new Exception('no github client id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,12 +100,9 @@ class DeveloperActions extends Actions
|
||||||
{
|
{
|
||||||
$code = Request::getParam('code');
|
$code = Request::getParam('code');
|
||||||
|
|
||||||
if (!$code)
|
if (!$code) {
|
||||||
{
|
|
||||||
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.');
|
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.');
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$authResponseData = Curl::post('https://github.com/login/oauth/access_token', [
|
$authResponseData = Curl::post('https://github.com/login/oauth/access_token', [
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
'client_id' => Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID),
|
'client_id' => Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID),
|
||||||
|
@ -119,16 +112,11 @@ class DeveloperActions extends Actions
|
||||||
'json_response' => true
|
'json_response' => true
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!$authResponseData || !isset($authResponseData['access_token']))
|
if (!$authResponseData || !isset($authResponseData['access_token'])) {
|
||||||
{
|
|
||||||
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.');
|
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.');
|
||||||
}
|
} elseif (isset($authResponseData['error_description'])) {
|
||||||
elseif (isset($authResponseData['error_description']))
|
|
||||||
{
|
|
||||||
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']);
|
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Session::set(Session::KEY_GITHUB_ACCESS_TOKEN, $authResponseData['access_token']);
|
Session::set(Session::KEY_GITHUB_ACCESS_TOKEN, $authResponseData['access_token']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@ class DownloadActions extends Actions
|
||||||
$uri = null;
|
$uri = null;
|
||||||
$oses = Os::getAll();
|
$oses = Os::getAll();
|
||||||
|
|
||||||
if (isset($oses[$os]))
|
if (isset($oses[$os])) {
|
||||||
{
|
|
||||||
$uri = GitHub::getDaemonDownloadUrl($os);
|
$uri = GitHub::getDaemonDownloadUrl($os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +36,7 @@ class DownloadActions extends Actions
|
||||||
$asset = Github::getAppAsset($os);
|
$asset = Github::getAppAsset($os);
|
||||||
$param = ['osTitle' => $osTitle, 'osIcon' => $osIcon, 'os' => $os, 'downloadUrl' => $asset ? $asset['browser_download_url'] : null];
|
$param = ['osTitle' => $osTitle, 'osIcon' => $osIcon, 'os' => $os, 'downloadUrl' => $asset ? $asset['browser_download_url'] : null];
|
||||||
return ['download/get', $param];
|
return ['download/get', $param];
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
return ['download/get-no-os'];
|
return ['download/get-no-os'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,31 +53,25 @@ class DownloadActions extends Actions
|
||||||
{
|
{
|
||||||
//if exact OS is requested, use that
|
//if exact OS is requested, use that
|
||||||
$uri = Request::getRelativeUri();
|
$uri = Request::getRelativeUri();
|
||||||
foreach (OS::getAll() as $os => $osChoice)
|
foreach (OS::getAll() as $os => $osChoice) {
|
||||||
{
|
if ($osChoice[0] == $uri) {
|
||||||
if ($osChoice[0] == $uri)
|
|
||||||
{
|
|
||||||
return $os;
|
return $os;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Request::isRobot())
|
if (Request::isRobot()) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//otherwise guess from UA
|
//otherwise guess from UA
|
||||||
$ua = Request::getUserAgent();
|
$ua = Request::getUserAgent();
|
||||||
if (stripos($ua, 'OS X') !== false)
|
if (stripos($ua, 'OS X') !== false) {
|
||||||
{
|
|
||||||
return strpos($ua, 'iPhone') !== false || stripos($ua, 'iPad') !== false ? OS::OS_IOS : OS::OS_OSX;
|
return strpos($ua, 'iPhone') !== false || stripos($ua, 'iPad') !== false ? OS::OS_IOS : OS::OS_OSX;
|
||||||
}
|
}
|
||||||
if (stripos($ua, 'Linux') !== false || strpos($ua, 'X11') !== false)
|
if (stripos($ua, 'Linux') !== false || strpos($ua, 'X11') !== false) {
|
||||||
{
|
|
||||||
return strpos($ua, 'Android') !== false ? OS::OS_ANDROID : OS::OS_LINUX;
|
return strpos($ua, 'Android') !== false ? OS::OS_ANDROID : OS::OS_LINUX;
|
||||||
}
|
}
|
||||||
if (stripos($ua, 'Windows') !== false)
|
if (stripos($ua, 'Windows') !== false) {
|
||||||
{
|
|
||||||
return OS::OS_WINDOWS;
|
return OS::OS_WINDOWS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,14 +80,11 @@ class DownloadActions extends Actions
|
||||||
{
|
{
|
||||||
$email = Request::getParam('e');
|
$email = Request::getParam('e');
|
||||||
|
|
||||||
if (!$email)
|
if (!$email) {
|
||||||
{
|
|
||||||
$encoded = Request::getParam('ec');
|
$encoded = Request::getParam('ec');
|
||||||
if ($encoded)
|
if ($encoded) {
|
||||||
{
|
|
||||||
$email = Smaz::decode(Encoding::base64DecodeUrlsafe($encoded), Smaz::CODEBOOK_EMAIL);
|
$email = Smaz::decode(Encoding::base64DecodeUrlsafe($encoded), Smaz::CODEBOOK_EMAIL);
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
{
|
|
||||||
$email = null;
|
$email = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,22 +4,21 @@ class MailActions extends Actions
|
||||||
{
|
{
|
||||||
public static function executeSubscribe()
|
public static function executeSubscribe()
|
||||||
{
|
{
|
||||||
if (!Request::isPost())
|
if (!Request::isPost()) {
|
||||||
{
|
|
||||||
return ['mail/subscribe'];
|
return ['mail/subscribe'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$nextUrl = Request::getPostParam('returnUrl', '/');
|
$nextUrl = Request::getPostParam('returnUrl', '/');
|
||||||
if (!$nextUrl || $nextUrl[0] != '/' || !filter_var($nextUrl, FILTER_VALIDATE_URL))
|
if (!$nextUrl || $nextUrl[0] != '/' || !filter_var($nextUrl, FILTER_VALIDATE_URL)) {
|
||||||
{
|
|
||||||
$nextUrl = '/';
|
$nextUrl = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
$email = Request::getPostParam('email');
|
$email = Request::getPostParam('email');
|
||||||
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL))
|
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
{
|
Session::set(
|
||||||
Session::set(Session::KEY_LIST_SUB_ERROR,
|
Session::KEY_LIST_SUB_ERROR,
|
||||||
$email ? __('Please provide a valid email address.') : __('Please provide an email address.'));
|
$email ? __('Please provide a valid email address.') : __('Please provide an email address.')
|
||||||
|
);
|
||||||
|
|
||||||
return Controller::redirect(Request::getRelativeUri());
|
return Controller::redirect(Request::getRelativeUri());
|
||||||
}
|
}
|
||||||
|
@ -27,8 +26,7 @@ class MailActions extends Actions
|
||||||
$tag = Request::getPostParam('tag');
|
$tag = Request::getPostParam('tag');
|
||||||
|
|
||||||
$response = LBRY::subscribe($email, $tag);
|
$response = LBRY::subscribe($email, $tag);
|
||||||
if ($response['error'])
|
if ($response['error']) {
|
||||||
{
|
|
||||||
return ['mail/subscribe', ['error' => $response['error']]];
|
return ['mail/subscribe', ['error' => $response['error']]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +52,7 @@ class MailActions extends Actions
|
||||||
public static function executeUnsubscribe(string $email)
|
public static function executeUnsubscribe(string $email)
|
||||||
{
|
{
|
||||||
$decodedEmail = Encoding::base64DecodeUrlsafe(urldecode($email));
|
$decodedEmail = Encoding::base64DecodeUrlsafe(urldecode($email));
|
||||||
if (!$decodedEmail)
|
if (!$decodedEmail) {
|
||||||
{
|
|
||||||
return ['mail/unsubscribe', ['error' => 'Invalid unsubscribe link']];
|
return ['mail/unsubscribe', ['error' => 'Invalid unsubscribe link']];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,7 @@ class OpsActions extends Actions
|
||||||
{
|
{
|
||||||
public static function executeClearCache(): array
|
public static function executeClearCache(): array
|
||||||
{
|
{
|
||||||
if (!ini_get('apc.enabled') || !function_exists('apc_clear_cache'))
|
if (!ini_get('apc.enabled') || !function_exists('apc_clear_cache')) {
|
||||||
{
|
|
||||||
return View::renderJson(['success' => false, 'error' => 'Cache not enabled']);
|
return View::renderJson(['success' => false, 'error' => 'Cache not enabled']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,30 +18,25 @@ class OpsActions extends Actions
|
||||||
public static function executePostCommit(): array
|
public static function executePostCommit(): array
|
||||||
{
|
{
|
||||||
$payload = Request::getParam('payload');
|
$payload = Request::getParam('payload');
|
||||||
if (!$payload)
|
if (!$payload) {
|
||||||
{
|
|
||||||
return NavActions::execute400(['error' => 'No payload']);
|
return NavActions::execute400(['error' => 'No payload']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$payload = json_decode($payload, true);
|
$payload = json_decode($payload, true);
|
||||||
if ($payload['ref'] === 'refs/heads/master')
|
if ($payload['ref'] === 'refs/heads/master') {
|
||||||
{
|
|
||||||
$sig = Request::getHttpHeader('X-Hub-Signature');
|
$sig = Request::getHttpHeader('X-Hub-Signature');
|
||||||
if (!$sig)
|
if (!$sig) {
|
||||||
{
|
|
||||||
return NavActions::execute400(['error' => "HTTP header 'X-Hub-Signature' is missing."]);
|
return NavActions::execute400(['error' => "HTTP header 'X-Hub-Signature' is missing."]);
|
||||||
}
|
}
|
||||||
|
|
||||||
list($algo, $hash) = explode('=', Request::getHttpHeader('X-Hub-Signature'), 2) + ['', ''];
|
list($algo, $hash) = explode('=', Request::getHttpHeader('X-Hub-Signature'), 2) + ['', ''];
|
||||||
if (!in_array($algo, hash_algos(), true))
|
if (!in_array($algo, hash_algos(), true)) {
|
||||||
{
|
|
||||||
return NavActions::execute400(['error' => 'Invalid hash algorithm "' . htmlspecialchars($algo) . '"']);
|
return NavActions::execute400(['error' => 'Invalid hash algorithm "' . htmlspecialchars($algo) . '"']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rawPost = file_get_contents('php://input');
|
$rawPost = file_get_contents('php://input');
|
||||||
$secret = Config::get(Config::GITHUB_KEY);
|
$secret = Config::get(Config::GITHUB_KEY);
|
||||||
if ($hash !== hash_hmac($algo, $rawPost, $secret))
|
if ($hash !== hash_hmac($algo, $rawPost, $secret)) {
|
||||||
{
|
|
||||||
return NavActions::execute400(['error' => 'Hash does not match.']);
|
return NavActions::execute400(['error' => 'Hash does not match.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,42 +49,34 @@ class OpsActions extends Actions
|
||||||
public static function executeLogUpload(): array
|
public static function executeLogUpload(): array
|
||||||
{
|
{
|
||||||
$log = Request::getPostParam('log') ? urldecode(Request::getPostParam('log')) : null;
|
$log = Request::getPostParam('log') ? urldecode(Request::getPostParam('log')) : null;
|
||||||
if (Request::getPostParam('name'))
|
if (Request::getPostParam('name')) {
|
||||||
{
|
|
||||||
$name = substr(trim(urldecode(Request::getPostParam('name'))), 0, 50);
|
$name = substr(trim(urldecode(Request::getPostParam('name'))), 0, 50);
|
||||||
}
|
} elseif (Request::getPostParam('date')) {
|
||||||
elseif (Request::getPostParam('date'))
|
|
||||||
{
|
|
||||||
$name = substr(trim(urldecode(Request::getPostParam('date'))), 0, 20) . '_' .
|
$name = substr(trim(urldecode(Request::getPostParam('date'))), 0, 20) . '_' .
|
||||||
substr(trim(urldecode(Request::getPostParam('hash'))), 0, 20) . '_' .
|
substr(trim(urldecode(Request::getPostParam('hash'))), 0, 20) . '_' .
|
||||||
substr(trim(urldecode(Request::getPostParam('sys'))), 0, 50) . '_' .
|
substr(trim(urldecode(Request::getPostParam('sys'))), 0, 50) . '_' .
|
||||||
substr(trim(urldecode(Request::getPostParam('type'))), 0, 20);
|
substr(trim(urldecode(Request::getPostParam('type'))), 0, 20);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$name = null;
|
$name = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = preg_replace('/[^A-Za-z0-9_-]+/', '', $name);
|
$name = preg_replace('/[^A-Za-z0-9_-]+/', '', $name);
|
||||||
|
|
||||||
if (!$log || !$name)
|
if (!$log || !$name) {
|
||||||
{
|
|
||||||
return NavActions::execute400(['error' => "Required params: log, name"]);
|
return NavActions::execute400(['error' => "Required params: log, name"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$awsKey = Config::get(Config::AWS_LOG_ACCESS_KEY);
|
$awsKey = Config::get(Config::AWS_LOG_ACCESS_KEY);
|
||||||
$awsSecret = Config::get(Config::AWS_LOG_SECRET_KEY);
|
$awsSecret = Config::get(Config::AWS_LOG_SECRET_KEY);
|
||||||
|
|
||||||
if (!$log || !$name)
|
if (!$log || !$name) {
|
||||||
{
|
|
||||||
throw new RuntimeException('Missing AWS credentials');
|
throw new RuntimeException('Missing AWS credentials');
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmpFile = tempnam(sys_get_temp_dir(), 'lbryinstalllog');
|
$tmpFile = tempnam(sys_get_temp_dir(), 'lbryinstalllog');
|
||||||
file_put_contents($tmpFile, $log);
|
file_put_contents($tmpFile, $log);
|
||||||
|
|
||||||
if (filesize($tmpFile) > 1024 * 1024 * 2)
|
if (filesize($tmpFile) > 1024 * 1024 * 2) {
|
||||||
{
|
|
||||||
return NavActions::execute400(['error' => 'Log file is too large']);
|
return NavActions::execute400(['error' => 'Log file is too large']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,32 +5,26 @@ class ReportActions extends Actions
|
||||||
public static function executeDmca()
|
public static function executeDmca()
|
||||||
{
|
{
|
||||||
Response::setHeader(Response::HEADER_CROSS_ORIGIN, "*");
|
Response::setHeader(Response::HEADER_CROSS_ORIGIN, "*");
|
||||||
if (!Request::isPost())
|
if (!Request::isPost()) {
|
||||||
{
|
|
||||||
return ['report/dmca'];
|
return ['report/dmca'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = [];
|
$values = [];
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
foreach (['name', 'email', 'rightsholder', 'identifier'] as $field)
|
foreach (['name', 'email', 'rightsholder', 'identifier'] as $field) {
|
||||||
{
|
|
||||||
$value = Request::getPostParam($field);
|
$value = Request::getPostParam($field);
|
||||||
|
|
||||||
if (!$value)
|
if (!$value) {
|
||||||
{
|
|
||||||
$errors[$field] = __('form_error.required');
|
$errors[$field] = __('form_error.required');
|
||||||
}
|
} elseif ($field == 'email' && !filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||||
elseif($field == 'email' && !filter_var($value, FILTER_VALIDATE_EMAIL))
|
|
||||||
{
|
|
||||||
$errors[$field] = __('form_error.invalid');
|
$errors[$field] = __('form_error.invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
$values[$field] = $value;
|
$values[$field] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$errors)
|
if (!$errors) {
|
||||||
{
|
|
||||||
$values['report_id'] = Encoding::base58Encode(random_bytes(6));
|
$values['report_id'] = Encoding::base58Encode(random_bytes(6));
|
||||||
Mailgun::sendDmcaReport($values);
|
Mailgun::sendDmcaReport($values);
|
||||||
Session::setFlash('success', '<h3>Report Submitted</h3><p>We will respond shortly.</p><p>This ID for this report is <strong>' . $values['report_id'] . '</strong>. Please reference this ID when contacting us regarding this report.</p>');
|
Session::setFlash('success', '<h3>Report Submitted</h3><p>We will respond shortly.</p><p>This ID for this report is <strong>' . $values['report_id'] . '</strong>. Please reference this ID when contacting us regarding this report.</p>');
|
||||||
|
|
|
@ -7,17 +7,13 @@ class i18nActions extends Actions
|
||||||
$culture = Request::getPostParam('culture');
|
$culture = Request::getPostParam('culture');
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
if ($culture && !in_array($culture, i18n::getAllCultures()))
|
if ($culture && !in_array($culture, i18n::getAllCultures())) {
|
||||||
{
|
|
||||||
$culture = null;
|
$culture = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($culture)
|
if ($culture) {
|
||||||
{
|
|
||||||
Session::set(Session::KEY_USER_CULTURE, $culture);
|
Session::set(Session::KEY_USER_CULTURE, $culture);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Session::unsetKey(Session::KEY_USER_CULTURE);
|
Session::unsetKey(Session::KEY_USER_CULTURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,4 @@
|
||||||
|
|
||||||
class StopException extends Exception
|
class StopException extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,10 @@ function __($msg, $args = [])
|
||||||
|
|
||||||
class i18n
|
class i18n
|
||||||
{
|
{
|
||||||
protected static
|
protected static $language = null;
|
||||||
$language = null,
|
protected static $translations = [];
|
||||||
$translations = [],
|
protected static $country = null;
|
||||||
$country = null,
|
protected static $cultures = ['pt_PT', 'en_US'];
|
||||||
$cultures = ['pt_PT', 'en_US'];
|
|
||||||
|
|
||||||
public static function register() /*needed to trigger class include, presumably setup would happen here*/
|
public static function register() /*needed to trigger class include, presumably setup would happen here*/
|
||||||
{
|
{
|
||||||
|
@ -55,26 +54,20 @@ class i18n
|
||||||
public static function translate($token, $language = null)
|
public static function translate($token, $language = null)
|
||||||
{
|
{
|
||||||
$language = $language === null ? static::$language : $language;
|
$language = $language === null ? static::$language : $language;
|
||||||
if (!isset(static::$translations[$language]))
|
if (!isset(static::$translations[$language])) {
|
||||||
{
|
|
||||||
$path = ROOT_DIR . '/data/i18n/' . $language . '.yaml';
|
$path = ROOT_DIR . '/data/i18n/' . $language . '.yaml';
|
||||||
|
|
||||||
static::$translations[$language] = file_exists($path) ? Spyc::YAMLLoadString(file_get_contents($path)) : [];
|
static::$translations[$language] = file_exists($path) ? Spyc::YAMLLoadString(file_get_contents($path)) : [];
|
||||||
}
|
}
|
||||||
$scope = static::$translations[$language];
|
$scope = static::$translations[$language];
|
||||||
foreach (explode('.', $token) as $level)
|
foreach (explode('.', $token) as $level) {
|
||||||
{
|
if (isset($scope[$level])) {
|
||||||
if (isset($scope[$level]))
|
|
||||||
{
|
|
||||||
$scope = $scope[$level];
|
$scope = $scope[$level];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$scope = [];
|
$scope = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$scope && $language != 'en')
|
if (!$scope && $language != 'en') {
|
||||||
{
|
|
||||||
return static::translate($token, 'en');
|
return static::translate($token, 'en');
|
||||||
}
|
}
|
||||||
return $scope ?: $token;
|
return $scope ?: $token;
|
||||||
|
@ -87,8 +80,7 @@ class i18n
|
||||||
//url trumps everything
|
//url trumps everything
|
||||||
$urlTokens = Request::getHost() ? explode('.', Request::getHost()) : [];
|
$urlTokens = Request::getHost() ? explode('.', Request::getHost()) : [];
|
||||||
$code = $urlTokens ? reset($urlTokens) : null;
|
$code = $urlTokens ? reset($urlTokens) : null;
|
||||||
if ($code !== 'www')
|
if ($code !== 'www') {
|
||||||
{
|
|
||||||
$candidates[] = $code;
|
$candidates[] = $code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,21 +89,17 @@ class i18n
|
||||||
|
|
||||||
// then headers
|
// then headers
|
||||||
// http://www.thefutureoftheweb.com/blog/use-accept-language-header
|
// http://www.thefutureoftheweb.com/blog/use-accept-language-header
|
||||||
if (Request::getHttpHeader('Accept-Language'))
|
if (Request::getHttpHeader('Accept-Language')) {
|
||||||
{
|
|
||||||
// break up string into pieces (languages and q factors)
|
// break up string into pieces (languages and q factors)
|
||||||
preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', Request::getHttpHeader('Accept-Language'), $languages);
|
preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', Request::getHttpHeader('Accept-Language'), $languages);
|
||||||
|
|
||||||
if (isset($languages[1]) && count($languages[1]))
|
if (isset($languages[1]) && count($languages[1])) {
|
||||||
{
|
|
||||||
// create a list like "en" => 0.8
|
// create a list like "en" => 0.8
|
||||||
$langs = array_combine($languages[1], $languages[4]);
|
$langs = array_combine($languages[1], $languages[4]);
|
||||||
|
|
||||||
// set default to 1 for any without q factor
|
// set default to 1 for any without q factor
|
||||||
foreach ($langs as $lang => $val)
|
foreach ($langs as $lang => $val) {
|
||||||
{
|
if ($val === '') {
|
||||||
if ($val === '')
|
|
||||||
{
|
|
||||||
$langs[$lang] = 1;
|
$langs[$lang] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,12 +110,9 @@ class i18n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($candidates as $candidate)
|
foreach ($candidates as $candidate) {
|
||||||
{
|
foreach (static::getAllCultures() as $culture) {
|
||||||
foreach (static::getAllCultures() as $culture)
|
if ($candidate === $culture || substr($culture, 0, 2) === $candidate) {
|
||||||
{
|
|
||||||
if ($candidate === $culture || substr($culture, 0, 2) === $candidate)
|
|
||||||
{
|
|
||||||
return $culture;
|
return $culture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,6 @@
|
||||||
|
|
||||||
namespace Routing;
|
namespace Routing;
|
||||||
|
|
||||||
class RouterBadRouteException extends \LogicException {}
|
class RouterBadRouteException extends \LogicException
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ namespace Routing;
|
||||||
|
|
||||||
class Dispatcher
|
class Dispatcher
|
||||||
{
|
{
|
||||||
|
|
||||||
private $staticRouteMap;
|
private $staticRouteMap;
|
||||||
private $variableRouteData;
|
private $variableRouteData;
|
||||||
private $filters;
|
private $filters;
|
||||||
|
@ -25,12 +24,9 @@ class Dispatcher
|
||||||
|
|
||||||
$this->filters = $data->getFilters();
|
$this->filters = $data->getFilters();
|
||||||
|
|
||||||
if ($resolver === null)
|
if ($resolver === null) {
|
||||||
{
|
|
||||||
$this->handlerResolver = new HandlerResolver();
|
$this->handlerResolver = new HandlerResolver();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->handlerResolver = $resolver;
|
$this->handlerResolver = $resolver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +45,7 @@ class Dispatcher
|
||||||
|
|
||||||
list($beforeFilter, $afterFilter) = $this->parseFilters($filters);
|
list($beforeFilter, $afterFilter) = $this->parseFilters($filters);
|
||||||
|
|
||||||
if (($response = $this->dispatchFilters($beforeFilter)) !== null)
|
if (($response = $this->dispatchFilters($beforeFilter)) !== null) {
|
||||||
{
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,12 +66,10 @@ class Dispatcher
|
||||||
*/
|
*/
|
||||||
private function dispatchFilters($filters, $response = null)
|
private function dispatchFilters($filters, $response = null)
|
||||||
{
|
{
|
||||||
while ($filter = array_shift($filters))
|
while ($filter = array_shift($filters)) {
|
||||||
{
|
|
||||||
$handler = $this->handlerResolver->resolve($filter);
|
$handler = $this->handlerResolver->resolve($filter);
|
||||||
|
|
||||||
if (($filteredResponse = call_user_func($handler, $response)) !== null)
|
if (($filteredResponse = call_user_func($handler, $response)) !== null) {
|
||||||
{
|
|
||||||
return $filteredResponse;
|
return $filteredResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,13 +89,11 @@ class Dispatcher
|
||||||
$beforeFilter = [];
|
$beforeFilter = [];
|
||||||
$afterFilter = [];
|
$afterFilter = [];
|
||||||
|
|
||||||
if (isset($filters[Route::BEFORE]))
|
if (isset($filters[Route::BEFORE])) {
|
||||||
{
|
|
||||||
$beforeFilter = array_intersect_key($this->filters, array_flip((array)$filters[Route::BEFORE]));
|
$beforeFilter = array_intersect_key($this->filters, array_flip((array)$filters[Route::BEFORE]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($filters[Route::AFTER]))
|
if (isset($filters[Route::AFTER])) {
|
||||||
{
|
|
||||||
$afterFilter = array_intersect_key($this->filters, array_flip((array)$filters[Route::AFTER]));
|
$afterFilter = array_intersect_key($this->filters, array_flip((array)$filters[Route::AFTER]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,8 +110,7 @@ class Dispatcher
|
||||||
*/
|
*/
|
||||||
private function dispatchRoute($httpMethod, $uri)
|
private function dispatchRoute($httpMethod, $uri)
|
||||||
{
|
{
|
||||||
if (isset($this->staticRouteMap[$uri]))
|
if (isset($this->staticRouteMap[$uri])) {
|
||||||
{
|
|
||||||
return $this->dispatchStaticRoute($httpMethod, $uri);
|
return $this->dispatchStaticRoute($httpMethod, $uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +130,7 @@ class Dispatcher
|
||||||
{
|
{
|
||||||
$routes = $this->staticRouteMap[$uri];
|
$routes = $this->staticRouteMap[$uri];
|
||||||
|
|
||||||
if (!isset($routes[$httpMethod]))
|
if (!isset($routes[$httpMethod])) {
|
||||||
{
|
|
||||||
$httpMethod = $this->checkFallbacks($routes, $httpMethod);
|
$httpMethod = $this->checkFallbacks($routes, $httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,15 +149,12 @@ class Dispatcher
|
||||||
{
|
{
|
||||||
$additional = [Route::ANY];
|
$additional = [Route::ANY];
|
||||||
|
|
||||||
if ($httpMethod === Route::HEAD)
|
if ($httpMethod === Route::HEAD) {
|
||||||
{
|
|
||||||
$additional[] = Route::GET;
|
$additional[] = Route::GET;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($additional as $method)
|
foreach ($additional as $method) {
|
||||||
{
|
if (isset($routes[$method])) {
|
||||||
if (isset($routes[$method]))
|
|
||||||
{
|
|
||||||
return $method;
|
return $method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,35 +175,27 @@ class Dispatcher
|
||||||
*/
|
*/
|
||||||
private function dispatchVariableRoute($httpMethod, $uri)
|
private function dispatchVariableRoute($httpMethod, $uri)
|
||||||
{
|
{
|
||||||
foreach ($this->variableRouteData as $data)
|
foreach ($this->variableRouteData as $data) {
|
||||||
{
|
if (!preg_match($data['regex'], $uri, $matches)) {
|
||||||
if (!preg_match($data['regex'], $uri, $matches))
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = count($matches);
|
$count = count($matches);
|
||||||
|
|
||||||
while (!isset($data['routeMap'][$count++]))
|
while (!isset($data['routeMap'][$count++])) {
|
||||||
{
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
$routes = $data['routeMap'][$count - 1];
|
$routes = $data['routeMap'][$count - 1];
|
||||||
|
|
||||||
if (!isset($routes[$httpMethod]))
|
if (!isset($routes[$httpMethod])) {
|
||||||
{
|
|
||||||
$httpMethod = $this->checkFallbacks($routes, $httpMethod);
|
$httpMethod = $this->checkFallbacks($routes, $httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array_values($routes[$httpMethod][2]) as $i => $varName)
|
foreach (array_values($routes[$httpMethod][2]) as $i => $varName) {
|
||||||
{
|
if (!isset($matches[$i + 1]) || $matches[$i + 1] === '') {
|
||||||
if (!isset($matches[$i + 1]) || $matches[$i + 1] === '')
|
|
||||||
{
|
|
||||||
unset($routes[$httpMethod][2][$varName]);
|
unset($routes[$httpMethod][2][$varName]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$routes[$httpMethod][2][$varName] = $matches[$i + 1];
|
$routes[$httpMethod][2][$varName] = $matches[$i + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,7 @@ class HandlerResolver implements HandlerResolverInterface
|
||||||
{
|
{
|
||||||
public function resolve($handler)
|
public function resolve($handler)
|
||||||
{
|
{
|
||||||
if (is_array($handler) && is_string($handler[0]))
|
if (is_array($handler) && is_string($handler[0])) {
|
||||||
{
|
|
||||||
$handler[0] = new $handler[0];
|
$handler[0] = new $handler[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,6 @@
|
||||||
|
|
||||||
namespace Routing;
|
namespace Routing;
|
||||||
|
|
||||||
class HttpException extends \Exception {}
|
class HttpException extends \Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -2,5 +2,6 @@
|
||||||
|
|
||||||
namespace Routing;
|
namespace Routing;
|
||||||
|
|
||||||
class HttpRouteNotFoundException extends HttpException {}
|
class HttpRouteNotFoundException extends HttpException
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -23,4 +23,3 @@ class Route
|
||||||
const DELETE = 'DELETE';
|
const DELETE = 'DELETE';
|
||||||
const OPTIONS = 'OPTIONS';
|
const OPTIONS = 'OPTIONS';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,23 +57,16 @@ class RouteCollector
|
||||||
|
|
||||||
$variable = 0;
|
$variable = 0;
|
||||||
|
|
||||||
foreach ($this->reverse[$name] as $part)
|
foreach ($this->reverse[$name] as $part) {
|
||||||
{
|
if (!$part['variable']) {
|
||||||
if (!$part['variable'])
|
|
||||||
{
|
|
||||||
$url[] = $part['value'];
|
$url[] = $part['value'];
|
||||||
}
|
} elseif (isset($replacements[$variable])) {
|
||||||
elseif (isset($replacements[$variable]))
|
if ($part['optional']) {
|
||||||
{
|
|
||||||
if ($part['optional'])
|
|
||||||
{
|
|
||||||
$url[] = '/';
|
$url[] = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
$url[] = $replacements[$variable++];
|
$url[] = $replacements[$variable++];
|
||||||
}
|
} elseif (!$part['optional']) {
|
||||||
elseif (!$part['optional'])
|
|
||||||
{
|
|
||||||
throw new BadRouteException("Expecting route variable '{$part['name']}'");
|
throw new BadRouteException("Expecting route variable '{$part['name']}'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,9 +76,7 @@ class RouteCollector
|
||||||
|
|
||||||
public function addRoute(string $httpMethod, $route, $handler, array $filters = []): RouteCollector
|
public function addRoute(string $httpMethod, $route, $handler, array $filters = []): RouteCollector
|
||||||
{
|
{
|
||||||
|
if (is_array($route)) {
|
||||||
if (is_array($route))
|
|
||||||
{
|
|
||||||
list($route, $name) = $route;
|
list($route, $name) = $route;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,8 +84,7 @@ class RouteCollector
|
||||||
|
|
||||||
list($routeData, $reverseData) = $this->routeParser->parse($route);
|
list($routeData, $reverseData) = $this->routeParser->parse($route);
|
||||||
|
|
||||||
if (isset($name))
|
if (isset($name)) {
|
||||||
{
|
|
||||||
$this->reverse[$name] = $reverseData;
|
$this->reverse[$name] = $reverseData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,15 +101,12 @@ class RouteCollector
|
||||||
{
|
{
|
||||||
$routeStr = $routeData[0];
|
$routeStr = $routeData[0];
|
||||||
|
|
||||||
if (isset($this->staticRoutes[$routeStr][$httpMethod]))
|
if (isset($this->staticRoutes[$routeStr][$httpMethod])) {
|
||||||
{
|
|
||||||
throw new BadRouteException("Cannot register two routes matching '$routeStr' for method '$httpMethod'");
|
throw new BadRouteException("Cannot register two routes matching '$routeStr' for method '$httpMethod'");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->regexToRoutesMap as $regex => $routes)
|
foreach ($this->regexToRoutesMap as $regex => $routes) {
|
||||||
{
|
if (isset($routes[$httpMethod]) && preg_match('~^' . $regex . '$~', $routeStr)) {
|
||||||
if (isset($routes[$httpMethod]) && preg_match('~^' . $regex . '$~', $routeStr))
|
|
||||||
{
|
|
||||||
throw new BadRouteException("Static route '$routeStr' is shadowed by previously defined variable route '$regex' for method '$httpMethod'");
|
throw new BadRouteException("Static route '$routeStr' is shadowed by previously defined variable route '$regex' for method '$httpMethod'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,8 +118,7 @@ class RouteCollector
|
||||||
{
|
{
|
||||||
list($regex, $variables) = $routeData;
|
list($regex, $variables) = $routeData;
|
||||||
|
|
||||||
if (isset($this->regexToRoutesMap[$regex][$httpMethod]))
|
if (isset($this->regexToRoutesMap[$regex][$httpMethod])) {
|
||||||
{
|
|
||||||
throw new BadRouteException("Cannot register two routes matching '$regex' for method '$httpMethod'");
|
throw new BadRouteException("Cannot register two routes matching '$regex' for method '$httpMethod'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,18 +205,14 @@ class RouteCollector
|
||||||
|
|
||||||
$sep = $route === '/' ? '' : '/';
|
$sep = $route === '/' ? '' : '/';
|
||||||
|
|
||||||
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method)
|
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
|
||||||
{
|
foreach ($validMethods as $valid) {
|
||||||
foreach ($validMethods as $valid)
|
if (stripos($method->name, $valid) === 0) {
|
||||||
{
|
|
||||||
if (stripos($method->name, $valid) === 0)
|
|
||||||
{
|
|
||||||
$methodName = $this->camelCaseToDashed(substr($method->name, strlen($valid)));
|
$methodName = $this->camelCaseToDashed(substr($method->name, strlen($valid)));
|
||||||
|
|
||||||
$params = $this->buildControllerParameters($method);
|
$params = $this->buildControllerParameters($method);
|
||||||
|
|
||||||
if ($methodName === self::DEFAULT_CONTROLLER_ROUTE)
|
if ($methodName === self::DEFAULT_CONTROLLER_ROUTE) {
|
||||||
{
|
|
||||||
$this->addRoute($valid, $route . $params, [$classname, $method->name], $filters);
|
$this->addRoute($valid, $route . $params, [$classname, $method->name], $filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,8 +230,7 @@ class RouteCollector
|
||||||
{
|
{
|
||||||
$params = '';
|
$params = '';
|
||||||
|
|
||||||
foreach ($method->getParameters() as $param)
|
foreach ($method->getParameters() as $param) {
|
||||||
{
|
|
||||||
$params .= "/{" . $param->getName() . "}" . ($param->isOptional() ? '?' : '');
|
$params .= "/{" . $param->getName() . "}" . ($param->isOptional() ? '?' : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,16 +284,14 @@ class RouteCollector
|
||||||
$routeMap = [];
|
$routeMap = [];
|
||||||
$regexes = [];
|
$regexes = [];
|
||||||
$numGroups = 0;
|
$numGroups = 0;
|
||||||
foreach ($regexToRoutesMap as $regex => $routes)
|
foreach ($regexToRoutesMap as $regex => $routes) {
|
||||||
{
|
|
||||||
$firstRoute = reset($routes);
|
$firstRoute = reset($routes);
|
||||||
$numVariables = count($firstRoute[2]);
|
$numVariables = count($firstRoute[2]);
|
||||||
$numGroups = max($numGroups, $numVariables);
|
$numGroups = max($numGroups, $numVariables);
|
||||||
|
|
||||||
$regexes[] = $regex . str_repeat('()', $numGroups - $numVariables);
|
$regexes[] = $regex . str_repeat('()', $numGroups - $numVariables);
|
||||||
|
|
||||||
foreach ($routes as $httpMethod => $route)
|
foreach ($routes as $httpMethod => $route) {
|
||||||
{
|
|
||||||
$routeMap[$numGroups + 1][$httpMethod] = $route;
|
$routeMap[$numGroups + 1][$httpMethod] = $route;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,7 @@ class RouteParser
|
||||||
|
|
||||||
$route = strtr($route, $this->regexShortcuts);
|
$route = strtr($route, $this->regexShortcuts);
|
||||||
|
|
||||||
if (!$matches = $this->extractVariableRouteParts($route))
|
if (!$matches = $this->extractVariableRouteParts($route)) {
|
||||||
{
|
|
||||||
$reverse = [
|
$reverse = [
|
||||||
'variable' => false,
|
'variable' => false,
|
||||||
'value' => $route
|
'value' => $route
|
||||||
|
@ -80,9 +79,7 @@ class RouteParser
|
||||||
return [[$route], [$reverse]];
|
return [[$route], [$reverse]];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($matches as $set)
|
foreach ($matches as $set) {
|
||||||
{
|
|
||||||
|
|
||||||
$this->staticParts($route, $set[0][1]);
|
$this->staticParts($route, $set[0][1]);
|
||||||
|
|
||||||
$this->validateVariable($set[1][0]);
|
$this->validateVariable($set[1][0]);
|
||||||
|
@ -95,8 +92,7 @@ class RouteParser
|
||||||
|
|
||||||
$isOptional = substr($set[0][0], -1) === '?';
|
$isOptional = substr($set[0][0], -1) === '?';
|
||||||
|
|
||||||
if ($isOptional)
|
if ($isOptional) {
|
||||||
{
|
|
||||||
$match = $this->makeOptional($match);
|
$match = $this->makeOptional($match);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +135,7 @@ class RouteParser
|
||||||
*/
|
*/
|
||||||
private function extractVariableRouteParts($route)
|
private function extractVariableRouteParts($route)
|
||||||
{
|
{
|
||||||
if (preg_match_all(self::VARIABLE_REGEX, $route, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER))
|
if (preg_match_all(self::VARIABLE_REGEX, $route, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
|
||||||
{
|
|
||||||
return $matches;
|
return $matches;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,10 +148,8 @@ class RouteParser
|
||||||
{
|
{
|
||||||
$static = preg_split('~(/)~u', substr($route, $this->regexOffset, $nextOffset - $this->regexOffset), 0, PREG_SPLIT_DELIM_CAPTURE);
|
$static = preg_split('~(/)~u', substr($route, $this->regexOffset, $nextOffset - $this->regexOffset), 0, PREG_SPLIT_DELIM_CAPTURE);
|
||||||
|
|
||||||
foreach ($static as $staticPart)
|
foreach ($static as $staticPart) {
|
||||||
{
|
if ($staticPart) {
|
||||||
if ($staticPart)
|
|
||||||
{
|
|
||||||
$quotedPart = $this->quote($staticPart);
|
$quotedPart = $this->quote($staticPart);
|
||||||
|
|
||||||
$this->parts[$this->partsCounter] = $quotedPart;
|
$this->parts[$this->partsCounter] = $quotedPart;
|
||||||
|
@ -176,8 +169,7 @@ class RouteParser
|
||||||
*/
|
*/
|
||||||
private function validateVariable($varName)
|
private function validateVariable($varName)
|
||||||
{
|
{
|
||||||
if (isset($this->variables[$varName]))
|
if (isset($this->variables[$varName])) {
|
||||||
{
|
|
||||||
throw new BadRouteException("Cannot use the same placeholder '$varName' twice");
|
throw new BadRouteException("Cannot use the same placeholder '$varName' twice");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,8 +185,7 @@ class RouteParser
|
||||||
{
|
{
|
||||||
$previous = $this->partsCounter - 1;
|
$previous = $this->partsCounter - 1;
|
||||||
|
|
||||||
if (isset($this->parts[$previous]) && $this->parts[$previous] === '/')
|
if (isset($this->parts[$previous]) && $this->parts[$previous] === '/') {
|
||||||
{
|
|
||||||
$this->partsCounter--;
|
$this->partsCounter--;
|
||||||
$match = '(?:/' . $match . ')';
|
$match = '(?:/' . $match . ')';
|
||||||
}
|
}
|
||||||
|
|
21
lib/thirdparty/Asana.class.php
vendored
21
lib/thirdparty/Asana.class.php
vendored
|
@ -23,15 +23,13 @@ class Asana
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($allTasks as $task)
|
foreach ($allTasks as $task) {
|
||||||
{
|
|
||||||
$badge = "Planned";
|
$badge = "Planned";
|
||||||
if ($task['completed'])
|
if ($task['completed']) {
|
||||||
{
|
|
||||||
$badge = "Complete";
|
$badge = "Complete";
|
||||||
}
|
} elseif (in_array("In Progress", array_map(function ($tag) {
|
||||||
else if (in_array("In Progress", array_map(function($tag) { return $tag['name']; }, $task['tags'] ?? [])))
|
return $tag['name'];
|
||||||
{
|
}, $task['tags'] ?? []))) {
|
||||||
$badge = "In Progress";
|
$badge = "In Progress";
|
||||||
}
|
}
|
||||||
$taskDueTime = strtotime($task['due_on']);
|
$taskDueTime = strtotime($task['due_on']);
|
||||||
|
@ -45,12 +43,9 @@ class Asana
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($tasks as &$groupTasks)
|
foreach ($tasks as &$groupTasks) {
|
||||||
{
|
usort($groupTasks, function ($tA, $tB) {
|
||||||
usort($groupTasks, function ($tA, $tB)
|
if ($tA['date'] xor $tB['date']) {
|
||||||
{
|
|
||||||
if ($tA['date'] xor $tB['date'])
|
|
||||||
{
|
|
||||||
return $tA['date'] ? -1 : 1;
|
return $tA['date'] ? -1 : 1;
|
||||||
}
|
}
|
||||||
return $tA['date'] < $tB['date'] ? -1 : 1;
|
return $tA['date'] < $tB['date'] ? -1 : 1;
|
||||||
|
|
83
lib/thirdparty/Github.class.php
vendored
83
lib/thirdparty/Github.class.php
vendored
|
@ -4,13 +4,11 @@ class Github
|
||||||
{
|
{
|
||||||
protected static function findReleaseAssetForOs(array $release, string $os)
|
protected static function findReleaseAssetForOs(array $release, string $os)
|
||||||
{
|
{
|
||||||
if (!in_array($os, array_keys(OS::getAll())))
|
if (!in_array($os, array_keys(OS::getAll()))) {
|
||||||
{
|
|
||||||
throw new DomainException('Unknown OS');
|
throw new DomainException('Unknown OS');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($release['assets'] as $asset)
|
foreach ($release['assets'] as $asset) {
|
||||||
{
|
|
||||||
$ext = substr($asset['name'], -4);
|
$ext = substr($asset['name'], -4);
|
||||||
if (
|
if (
|
||||||
($os == OS::OS_LINUX &&
|
($os == OS::OS_LINUX &&
|
||||||
|
@ -18,8 +16,7 @@ class Github
|
||||||
($os == OS::OS_OSX &&
|
($os == OS::OS_OSX &&
|
||||||
($ext == '.dmg' || in_array($asset['content_type'], ['application/x-diskcopy', 'application/x-apple-diskimage']))) ||
|
($ext == '.dmg' || in_array($asset['content_type'], ['application/x-diskcopy', 'application/x-apple-diskimage']))) ||
|
||||||
($os == OS::OS_WINDOWS && $ext == '.exe')
|
($os == OS::OS_WINDOWS && $ext == '.exe')
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
return $asset;
|
return $asset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,12 +24,9 @@ class Github
|
||||||
|
|
||||||
public static function getAppRelease($cache = true)
|
public static function getAppRelease($cache = true)
|
||||||
{
|
{
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return static::get('/repos/lbryio/lbry-app/releases/latest', [], $cache);
|
return static::get('/repos/lbryio/lbry-app/releases/latest', [], $cache);
|
||||||
}
|
} catch (Exception $e) {
|
||||||
catch (Exception $e)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -53,17 +47,13 @@ class Github
|
||||||
|
|
||||||
public static function getAppPrereleaseDownloadUrl($os, $cache = true)
|
public static function getAppPrereleaseDownloadUrl($os, $cache = true)
|
||||||
{
|
{
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$releases = static::get('/repos/lbryio/lbry-app/releases', [], $cache);
|
$releases = static::get('/repos/lbryio/lbry-app/releases', [], $cache);
|
||||||
if (count($releases))
|
if (count($releases)) {
|
||||||
{
|
|
||||||
$asset = static::findReleaseAssetForOs($releases[0], $os);
|
$asset = static::findReleaseAssetForOs($releases[0], $os);
|
||||||
return $asset ? $asset['browser_download_url'] : null;
|
return $asset ? $asset['browser_download_url'] : null;
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception $e) {
|
||||||
catch (Exception $e)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -72,28 +62,22 @@ class Github
|
||||||
|
|
||||||
public static function getDaemonReleaseProperty($os, $property, $isAssetProperty = false, $cache = true)
|
public static function getDaemonReleaseProperty($os, $property, $isAssetProperty = false, $cache = true)
|
||||||
{
|
{
|
||||||
if (!in_array($os, array_keys(OS::getAll())))
|
if (!in_array($os, array_keys(OS::getAll()))) {
|
||||||
{
|
|
||||||
throw new DomainException('Unknown OS');
|
throw new DomainException('Unknown OS');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$releaseData = static::get('/repos/lbryio/lbry/releases/latest', [], $cache);
|
$releaseData = static::get('/repos/lbryio/lbry/releases/latest', [], $cache);
|
||||||
foreach ($releaseData['assets'] as $asset)
|
foreach ($releaseData['assets'] as $asset) {
|
||||||
{
|
|
||||||
if (
|
if (
|
||||||
($os == OS::OS_LINUX && stripos($asset['browser_download_url'], 'linux') !== false) ||
|
($os == OS::OS_LINUX && stripos($asset['browser_download_url'], 'linux') !== false) ||
|
||||||
($os == OS::OS_OSX && stripos($asset['browser_download_url'], 'macos') !== false) ||
|
($os == OS::OS_OSX && stripos($asset['browser_download_url'], 'macos') !== false) ||
|
||||||
($os == OS::OS_WINDOWS && strpos($asset['browser_download_url'], 'windows') !== false)
|
($os == OS::OS_WINDOWS && strpos($asset['browser_download_url'], 'windows') !== false)
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
return $isAssetProperty ? $asset[$property] : $releaseData[$property];
|
return $isAssetProperty ? $asset[$property] : $releaseData[$property];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception $e) {
|
||||||
catch (Exception $e)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -107,8 +91,11 @@ class Github
|
||||||
public static function get($endpoint, array $params = [], $cache = true)
|
public static function get($endpoint, array $params = [], $cache = true)
|
||||||
{
|
{
|
||||||
$twoHoursInSeconds = 7200;
|
$twoHoursInSeconds = 7200;
|
||||||
return CurlWithCache::get('https://api.github.com' . $endpoint . '?' . http_build_query($params), [],
|
return CurlWithCache::get(
|
||||||
['headers' => ['Accept: application/vnd.github.v3.html+json'],'user_agent' => 'LBRY', 'json_response' => true, 'cache' => $cache === true ? $twoHoursInSeconds : $cache]);
|
'https://api.github.com' . $endpoint . '?' . http_build_query($params),
|
||||||
|
[],
|
||||||
|
['headers' => ['Accept: application/vnd.github.v3.html+json'],'user_agent' => 'LBRY', 'json_response' => true, 'cache' => $cache === true ? $twoHoursInSeconds : $cache]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function listRoadmapChangesets($cache = true)
|
public static function listRoadmapChangesets($cache = true)
|
||||||
|
@ -118,18 +105,14 @@ class Github
|
||||||
|
|
||||||
$projects = ['lbry' => 'LBRY Protocol', 'lbry-app' => 'LBRY App'];
|
$projects = ['lbry' => 'LBRY Protocol', 'lbry-app' => 'LBRY App'];
|
||||||
|
|
||||||
foreach($projects as $project => $projectLabel)
|
foreach ($projects as $project => $projectLabel) {
|
||||||
{
|
|
||||||
$page = 1;
|
$page = 1;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
$releases = static::get('/repos/lbryio/' . $project . '/releases', ['page' => $page], $cache);
|
$releases = static::get('/repos/lbryio/' . $project . '/releases', ['page' => $page], $cache);
|
||||||
$page++;
|
$page++;
|
||||||
$allReleases = array_merge($allReleases, array_map(function ($release) use ($project, $projectLabel)
|
$allReleases = array_merge($allReleases, array_map(function ($release) use ($project, $projectLabel) {
|
||||||
{
|
|
||||||
return $release + ['project' => $projectLabel];
|
return $release + ['project' => $projectLabel];
|
||||||
}, array_filter($releases, function ($release)
|
}, array_filter($releases, function ($release) {
|
||||||
{
|
|
||||||
return isset($release['tag_name']) && isset($release['published_at']) && $release['published_at'];
|
return isset($release['tag_name']) && isset($release['published_at']) && $release['published_at'];
|
||||||
})));
|
})));
|
||||||
} while (count($releases) >= 30);
|
} while (count($releases) >= 30);
|
||||||
|
@ -140,16 +123,13 @@ class Github
|
||||||
* to strictly by time. - Jeremy
|
* to strictly by time. - Jeremy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
foreach ($allReleases as $release)
|
foreach ($allReleases as $release) {
|
||||||
{
|
|
||||||
$group = null;
|
$group = null;
|
||||||
$matches = null;
|
$matches = null;
|
||||||
if (preg_match('/^v(\d+)\.(\d+)\./', $release['tag_name'] ?? '', $matches))
|
if (preg_match('/^v(\d+)\.(\d+)\./', $release['tag_name'] ?? '', $matches)) {
|
||||||
{
|
|
||||||
$group = $release['project'] . ' v' . $matches[1] . '.' . $matches[2];
|
$group = $release['project'] . ' v' . $matches[1] . '.' . $matches[2];
|
||||||
}
|
}
|
||||||
if ($group)
|
if ($group) {
|
||||||
{
|
|
||||||
$sets[$group][] = array_intersect_key($release, [
|
$sets[$group][] = array_intersect_key($release, [
|
||||||
'prerelease' => null, 'tag_name' => null, 'published_at' => null, 'project' => null
|
'prerelease' => null, 'tag_name' => null, 'published_at' => null, 'project' => null
|
||||||
]) + [
|
]) + [
|
||||||
|
@ -168,18 +148,17 @@ class Github
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uasort($sets, function ($sA, $sB)
|
uasort($sets, function ($sA, $sB) {
|
||||||
{
|
if ($sA[0]['project'] != $sB[0]['project']) {
|
||||||
if ($sA[0]['project'] != $sB[0]['project'])
|
|
||||||
{
|
|
||||||
return $sA[0]['project'] < $sB[0]['project'] ? -1 : 1;
|
return $sA[0]['project'] < $sB[0]['project'] ? -1 : 1;
|
||||||
}
|
}
|
||||||
return $sB[0]['sort_key'] <=> $sA[0]['sort_key'];
|
return $sB[0]['sort_key'] <=> $sA[0]['sort_key'];
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach ($sets as $group => &$groupSet)
|
foreach ($sets as $group => &$groupSet) {
|
||||||
{
|
usort($groupSet, function ($rA, $rB) {
|
||||||
usort($groupSet, function ($rA, $rB) { return $rB['created_at'] <=> $rA['created_at']; });
|
return $rB['created_at'] <=> $rA['created_at'];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sets;
|
return $sets;
|
||||||
|
|
4
lib/thirdparty/LBRY.class.php
vendored
4
lib/thirdparty/LBRY.class.php
vendored
|
@ -51,9 +51,7 @@ class LBRY
|
||||||
{
|
{
|
||||||
if ($email == null) {
|
if ($email == null) {
|
||||||
return Curl::post(static::getApiUrl("/yt/update"), ['status_token' => $status_token, 'new_preferred_channel' => $channel_name, 'sync_consent' => $sync_consent], ['json_response' => true]);
|
return Curl::post(static::getApiUrl("/yt/update"), ['status_token' => $status_token, 'new_preferred_channel' => $channel_name, 'sync_consent' => $sync_consent], ['json_response' => true]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
|
|
||||||
return Curl::post(static::getApiUrl("/yt/update"), ['status_token' => $status_token, 'new_email' => $email, 'new_preferred_channel' => $channel_name, 'sync_consent' => $sync_consent], ['json_response' => true]);
|
return Curl::post(static::getApiUrl("/yt/update"), ['status_token' => $status_token, 'new_email' => $email, 'new_preferred_channel' => $channel_name, 'sync_consent' => $sync_consent], ['json_response' => true]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
lib/thirdparty/Salesforce.class.php
vendored
12
lib/thirdparty/Salesforce.class.php
vendored
|
@ -6,8 +6,7 @@ class Salesforce
|
||||||
API_URL = 'https://api.salesforceiq.com/v2/',
|
API_URL = 'https://api.salesforceiq.com/v2/',
|
||||||
DEFAULT_LIST_ID = '58387a94e4b0a1fea2c76f4a';
|
DEFAULT_LIST_ID = '58387a94e4b0a1fea2c76f4a';
|
||||||
|
|
||||||
protected static
|
protected static $curlOptions = [
|
||||||
$curlOptions = [
|
|
||||||
'headers' => ['Accept: application/json', 'Content-type: application/json'],
|
'headers' => ['Accept: application/json', 'Content-type: application/json'],
|
||||||
'json_response' => true,
|
'json_response' => true,
|
||||||
'json_data' => true,
|
'json_data' => true,
|
||||||
|
@ -27,10 +26,8 @@ class Salesforce
|
||||||
|
|
||||||
$contactId = static::post('contacts?_upsert=email', $contactData)['id'] ?? null;
|
$contactId = static::post('contacts?_upsert=email', $contactData)['id'] ?? null;
|
||||||
|
|
||||||
if ($initialListId)
|
if ($initialListId) {
|
||||||
{
|
if (!$contactId) {
|
||||||
if (!$contactId)
|
|
||||||
{
|
|
||||||
throw new SalesforceException('Failed to generate or update contact');
|
throw new SalesforceException('Failed to generate or update contact');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +43,7 @@ class Salesforce
|
||||||
protected static function getApiUserPassword()
|
protected static function getApiUserPassword()
|
||||||
{
|
{
|
||||||
$userpw = Config::get(Config::SALESFORCE_KEY) . ':' . Config::get(Config::SALESFORCE_SECRET);
|
$userpw = Config::get(Config::SALESFORCE_KEY) . ':' . Config::get(Config::SALESFORCE_SECRET);
|
||||||
if ($userpw[0] === ':' || substr($userpw, -1) === ':')
|
if ($userpw[0] === ':' || substr($userpw, -1) === ':') {
|
||||||
{
|
|
||||||
throw new SalesforceException('Salesforce key and/or secret not configured correctly');
|
throw new SalesforceException('Salesforce key and/or secret not configured correctly');
|
||||||
}
|
}
|
||||||
return $userpw;
|
return $userpw;
|
||||||
|
|
7
lib/thirdparty/Slack.class.php
vendored
7
lib/thirdparty/Slack.class.php
vendored
|
@ -2,17 +2,14 @@
|
||||||
|
|
||||||
class Slack
|
class Slack
|
||||||
{
|
{
|
||||||
|
|
||||||
public static function sendErrorIfProd($e, $alert = true)
|
public static function sendErrorIfProd($e, $alert = true)
|
||||||
{
|
{
|
||||||
if ($e instanceof Throwable)
|
if ($e instanceof Throwable) {
|
||||||
{
|
|
||||||
$e = Debug::exceptionToString($e);
|
$e = Debug::exceptionToString($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
$slackErrorNotificationUrl = Config::get(Config::SLACK_ERROR_NOTIFICATION_URL);
|
$slackErrorNotificationUrl = Config::get(Config::SLACK_ERROR_NOTIFICATION_URL);
|
||||||
if ($slackErrorNotificationUrl)
|
if ($slackErrorNotificationUrl) {
|
||||||
{
|
|
||||||
Curl::post($slackErrorNotificationUrl, ['text' => ($alert ? '<!channel> ' : '') . Request::getRelativeUri() . "\n" . $e], ['json_data' => true]);
|
Curl::post($slackErrorNotificationUrl, ['text' => ($alert ? '<!channel> ' : '') . Request::getRelativeUri() . "\n" . $e], ['json_data' => true]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,9 @@ class Config
|
||||||
|
|
||||||
protected static function load()
|
protected static function load()
|
||||||
{
|
{
|
||||||
if (!static::$loaded)
|
if (!static::$loaded) {
|
||||||
{
|
|
||||||
$dataFile = ROOT_DIR.'/data/config.php';
|
$dataFile = ROOT_DIR.'/data/config.php';
|
||||||
if (!is_readable($dataFile))
|
if (!is_readable($dataFile)) {
|
||||||
{
|
|
||||||
throw new RuntimeException('config file is missing or not readable');
|
throw new RuntimeException('config file is missing or not readable');
|
||||||
}
|
}
|
||||||
static::$data = require $dataFile;
|
static::$data = require $dataFile;
|
||||||
|
|
|
@ -50,20 +50,17 @@ class Curl
|
||||||
];
|
];
|
||||||
|
|
||||||
$invalid = array_diff_key($options, $defaults);
|
$invalid = array_diff_key($options, $defaults);
|
||||||
if ($invalid)
|
if ($invalid) {
|
||||||
{
|
|
||||||
throw new DomainException('Invalid curl options: ' . join(', ', array_keys($invalid)));
|
throw new DomainException('Invalid curl options: ' . join(', ', array_keys($invalid)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($method, [static::GET, static::POST, static::PUT]))
|
if (!in_array($method, [static::GET, static::POST, static::PUT])) {
|
||||||
{
|
|
||||||
throw new DomainException('Invalid method: ' . $method);
|
throw new DomainException('Invalid method: ' . $method);
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array_merge($defaults, $options);
|
$options = array_merge($defaults, $options);
|
||||||
|
|
||||||
if ($options['headers'] && $options['headers'] !== array_values($options['headers'])) // associative array
|
if ($options['headers'] && $options['headers'] !== array_values($options['headers'])) { // associative array
|
||||||
{
|
|
||||||
throw new DomainException('Headers must not be an associative array. Its a simple array with values of the form "Header: value"');
|
throw new DomainException('Headers must not be an associative array. Its a simple array with values of the form "Header: value"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,14 +69,12 @@ class Curl
|
||||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||||
curl_setopt($ch, CURLOPT_STDERR, fopen(sys_get_temp_dir().'/curl-debug-'.date('Ymd-His'), 'w+'));
|
curl_setopt($ch, CURLOPT_STDERR, fopen(sys_get_temp_dir().'/curl-debug-'.date('Ymd-His'), 'w+'));
|
||||||
|
|
||||||
if ($ch === false || $ch === null)
|
if ($ch === false || $ch === null) {
|
||||||
{
|
|
||||||
throw new LogicException('Unable to initialize cURL');
|
throw new LogicException('Unable to initialize cURL');
|
||||||
}
|
}
|
||||||
|
|
||||||
$urlWithParams = $url;
|
$urlWithParams = $url;
|
||||||
if ($method == static::GET && $params)
|
if ($method == static::GET && $params) {
|
||||||
{
|
|
||||||
$urlWithParams .= (strpos($urlWithParams, '?') === false ? '?' : '&') . http_build_query($params);
|
$urlWithParams .= (strpos($urlWithParams, '?') === false ? '?' : '&') . http_build_query($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,52 +91,39 @@ class Curl
|
||||||
CURLOPT_USERAGENT => $options['user_agent'],
|
CURLOPT_USERAGENT => $options['user_agent'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($method == static::POST)
|
if ($method == static::POST) {
|
||||||
{
|
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
}
|
} elseif ($method == static::PUT) {
|
||||||
elseif ($method == static::PUT)
|
|
||||||
{
|
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($method, [static::PUT, static::POST]))
|
if (in_array($method, [static::PUT, static::POST])) {
|
||||||
{
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $options['json_data'] ? json_encode($params) : http_build_query($params));
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $options['json_data'] ? json_encode($params) : http_build_query($params));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['proxy'])
|
if ($options['proxy']) {
|
||||||
{
|
|
||||||
curl_setopt($ch, CURLOPT_PROXY, $options['proxy']);
|
curl_setopt($ch, CURLOPT_PROXY, $options['proxy']);
|
||||||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
|
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['password'])
|
if ($options['password']) {
|
||||||
{
|
|
||||||
curl_setopt($ch, CURLOPT_USERPWD, $options['password']);
|
curl_setopt($ch, CURLOPT_USERPWD, $options['password']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['cookie'])
|
if ($options['cookie']) {
|
||||||
{
|
|
||||||
curl_setopt($ch, CURLOPT_COOKIE, $options['cookie']);
|
curl_setopt($ch, CURLOPT_COOKIE, $options['cookie']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$startingResponse = false;
|
$startingResponse = false;
|
||||||
$headers = [];
|
$headers = [];
|
||||||
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $h) use (&$headers, &$startingResponse)
|
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $h) use (&$headers, &$startingResponse) {
|
||||||
{
|
|
||||||
$value = trim($h);
|
$value = trim($h);
|
||||||
if ($value === '')
|
if ($value === '') {
|
||||||
{
|
|
||||||
$startingResponse = true;
|
$startingResponse = true;
|
||||||
}
|
} elseif ($startingResponse) {
|
||||||
elseif ($startingResponse)
|
|
||||||
{
|
|
||||||
$startingResponse = false;
|
$startingResponse = false;
|
||||||
$headers = [$value];
|
$headers = [$value];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$headers[] = $value;
|
$headers[] = $value;
|
||||||
}
|
}
|
||||||
return strlen($h);
|
return strlen($h);
|
||||||
|
@ -149,21 +131,16 @@ class Curl
|
||||||
|
|
||||||
$rawResponse = curl_exec($ch);
|
$rawResponse = curl_exec($ch);
|
||||||
|
|
||||||
if ($options['json_response'])
|
if ($options['json_response']) {
|
||||||
{
|
|
||||||
$responseContent = $rawResponse ? json_decode($rawResponse, true) : [];
|
$responseContent = $rawResponse ? json_decode($rawResponse, true) : [];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$responseContent = $rawResponse;
|
$responseContent = $rawResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
$statusCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$statusCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
|
||||||
if (curl_errno($ch))
|
if (curl_errno($ch)) {
|
||||||
{
|
if ($options['retry'] && is_numeric($options['retry']) && $options['retry'] > 0) {
|
||||||
if ($options['retry'] && is_numeric($options['retry']) && $options['retry'] > 0)
|
|
||||||
{
|
|
||||||
$options['retry'] -= 1;
|
$options['retry'] -= 1;
|
||||||
return static::doCurl($method, $url, $params, $options);
|
return static::doCurl($method, $url, $params, $options);
|
||||||
}
|
}
|
||||||
|
@ -178,7 +155,10 @@ class Curl
|
||||||
|
|
||||||
class CurlException extends Exception
|
class CurlException extends Exception
|
||||||
{
|
{
|
||||||
protected $errno, $error, $info, $handle;
|
protected $errno;
|
||||||
|
protected $error;
|
||||||
|
protected $info;
|
||||||
|
protected $handle;
|
||||||
|
|
||||||
public function __construct($curlHandle, Exception $previous = null)
|
public function __construct($curlHandle, Exception $previous = null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,25 +13,19 @@ class CurlWithCache extends Curl
|
||||||
unset($options['cache']);
|
unset($options['cache']);
|
||||||
|
|
||||||
$cacheKey = $cacheEnabled ? md5($url . $method . serialize($options) . serialize($params)) : null;
|
$cacheKey = $cacheEnabled ? md5($url . $method . serialize($options) . serialize($params)) : null;
|
||||||
if ($cacheAllowed && $cacheKey)
|
if ($cacheAllowed && $cacheKey) {
|
||||||
{
|
|
||||||
$cachedData = apc_fetch($cacheKey);
|
$cachedData = apc_fetch($cacheKey);
|
||||||
if ($cachedData)
|
if ($cachedData) {
|
||||||
{
|
|
||||||
return $cachedData;
|
return $cachedData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = parent::doCurl($method, $url, $params, $options);
|
$response = parent::doCurl($method, $url, $params, $options);
|
||||||
|
|
||||||
if ($cacheEnabled)
|
if ($cacheEnabled) {
|
||||||
{
|
if ($cacheAllowed) {
|
||||||
if ($cacheAllowed)
|
|
||||||
{
|
|
||||||
apc_store($cacheKey, $response, $cacheTimeout);
|
apc_store($cacheKey, $response, $cacheTimeout);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
apc_delete($cacheKey);
|
apc_delete($cacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,17 @@ class Debug
|
||||||
public static function getFullTrace(Throwable $exception)
|
public static function getFullTrace(Throwable $exception)
|
||||||
{
|
{
|
||||||
$rtn = '';
|
$rtn = '';
|
||||||
foreach ($exception->getTrace() as $count => $frame)
|
foreach ($exception->getTrace() as $count => $frame) {
|
||||||
{
|
|
||||||
$args = isset($frame['args']) ? static::exceptionFrameArgsToString($frame['args']) : '';
|
$args = isset($frame['args']) ? static::exceptionFrameArgsToString($frame['args']) : '';
|
||||||
|
|
||||||
$rtn .= sprintf("#%s %s(%s): %s(%s)\n",
|
$rtn .= sprintf(
|
||||||
|
"#%s %s(%s): %s(%s)\n",
|
||||||
$count,
|
$count,
|
||||||
$frame['file'] ?? 'unknown file',
|
$frame['file'] ?? 'unknown file',
|
||||||
$frame['line'] ?? 'unknown line',
|
$frame['line'] ?? 'unknown line',
|
||||||
isset($frame['class']) ? $frame['class'].$frame['type'].$frame['function'] : $frame['function'],
|
isset($frame['class']) ? $frame['class'].$frame['type'].$frame['function'] : $frame['function'],
|
||||||
$args);
|
$args
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return $rtn;
|
return $rtn;
|
||||||
}
|
}
|
||||||
|
@ -39,34 +40,20 @@ class Debug
|
||||||
public static function exceptionFrameArgsToString(array $args)
|
public static function exceptionFrameArgsToString(array $args)
|
||||||
{
|
{
|
||||||
$ret = [];
|
$ret = [];
|
||||||
foreach ($args as $arg)
|
foreach ($args as $arg) {
|
||||||
{
|
if (is_string($arg)) {
|
||||||
if (is_string($arg))
|
|
||||||
{
|
|
||||||
$ret[] = "'" . $arg . "'";
|
$ret[] = "'" . $arg . "'";
|
||||||
}
|
} elseif (is_array($arg)) {
|
||||||
elseif (is_array($arg))
|
|
||||||
{
|
|
||||||
$ret[] = 'Array(' . count($arg) . ')';
|
$ret[] = 'Array(' . count($arg) . ')';
|
||||||
}
|
} elseif (is_null($arg)) {
|
||||||
elseif (is_null($arg))
|
|
||||||
{
|
|
||||||
$ret[] = 'NULL';
|
$ret[] = 'NULL';
|
||||||
}
|
} elseif (is_bool($arg)) {
|
||||||
elseif (is_bool($arg))
|
|
||||||
{
|
|
||||||
$ret[] = ($arg) ? 'true' : 'false';
|
$ret[] = ($arg) ? 'true' : 'false';
|
||||||
}
|
} elseif (is_object($arg)) {
|
||||||
elseif (is_object($arg))
|
|
||||||
{
|
|
||||||
$ret[] = get_class($arg) . (!($arg instanceof Closure) && isset($arg->id) ? "({$arg->id})" : '');
|
$ret[] = get_class($arg) . (!($arg instanceof Closure) && isset($arg->id) ? "({$arg->id})" : '');
|
||||||
}
|
} elseif (is_resource($arg)) {
|
||||||
elseif (is_resource($arg))
|
|
||||||
{
|
|
||||||
$ret[] = get_resource_type($arg);
|
$ret[] = get_resource_type($arg);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$ret[] = $arg;
|
$ret[] = $arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,7 @@ class Encoding
|
||||||
|
|
||||||
protected static function convertBase($numberInput, $sourceAlphabet, $targetAlphabet)
|
protected static function convertBase($numberInput, $sourceAlphabet, $targetAlphabet)
|
||||||
{
|
{
|
||||||
if ($sourceAlphabet == $targetAlphabet)
|
if ($sourceAlphabet == $targetAlphabet) {
|
||||||
{
|
|
||||||
return $numberInput;
|
return $numberInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,11 +34,9 @@ class Encoding
|
||||||
$toLen = strlen($targetAlphabet);
|
$toLen = strlen($targetAlphabet);
|
||||||
$numberLen = strlen($numberInput);
|
$numberLen = strlen($numberInput);
|
||||||
|
|
||||||
if ($targetAlphabet == $decimalAlphabet)
|
if ($targetAlphabet == $decimalAlphabet) {
|
||||||
{
|
|
||||||
$decimal = 0;
|
$decimal = 0;
|
||||||
for ($i = 1; $i <= $numberLen; $i++)
|
for ($i = 1; $i <= $numberLen; $i++) {
|
||||||
{
|
|
||||||
$decimal = bcadd($decimal, bcmul(array_search($number[$i - 1], $fromBase), bcpow($fromLen, $numberLen - $i)));
|
$decimal = bcadd($decimal, bcmul(array_search($number[$i - 1], $fromBase), bcpow($fromLen, $numberLen - $i)));
|
||||||
}
|
}
|
||||||
return $decimal;
|
return $decimal;
|
||||||
|
@ -47,14 +44,12 @@ class Encoding
|
||||||
|
|
||||||
$base10 = $sourceAlphabet == $decimalAlphabet ? $numberInput : static::convertBase($numberInput, $sourceAlphabet, $decimalAlphabet);
|
$base10 = $sourceAlphabet == $decimalAlphabet ? $numberInput : static::convertBase($numberInput, $sourceAlphabet, $decimalAlphabet);
|
||||||
|
|
||||||
if ($base10 < strlen($targetAlphabet))
|
if ($base10 < strlen($targetAlphabet)) {
|
||||||
{
|
|
||||||
return $toBase[$base10];
|
return $toBase[$base10];
|
||||||
}
|
}
|
||||||
|
|
||||||
$retval = '';
|
$retval = '';
|
||||||
while ($base10 != '0')
|
while ($base10 != '0') {
|
||||||
{
|
|
||||||
$retval = $toBase[bcmod($base10, $toLen)] . $retval;
|
$retval = $toBase[bcmod($base10, $toLen)] . $retval;
|
||||||
$base10 = bcdiv($base10, $toLen, 0);
|
$base10 = bcdiv($base10, $toLen, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,23 +8,18 @@ class Gzip
|
||||||
$mode = 'wb' . $level;
|
$mode = 'wb' . $level;
|
||||||
|
|
||||||
$fpOut = gzopen($compressedPath, $mode);
|
$fpOut = gzopen($compressedPath, $mode);
|
||||||
if (!$fpOut)
|
if (!$fpOut) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fpIn = fopen($source, 'rb');
|
$fpIn = fopen($source, 'rb');
|
||||||
$error = false;
|
$error = false;
|
||||||
if ($fpIn)
|
if ($fpIn) {
|
||||||
{
|
while (!feof($fpIn)) {
|
||||||
while (!feof($fpIn))
|
|
||||||
{
|
|
||||||
gzwrite($fpOut, fread($fpIn, 1024 * 512));
|
gzwrite($fpOut, fread($fpIn, 1024 * 512));
|
||||||
}
|
}
|
||||||
fclose($fpIn);
|
fclose($fpIn);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error = true;
|
$error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,24 +25,20 @@ class Lock
|
||||||
*/
|
*/
|
||||||
public static function getLock($name, $blocking = false)
|
public static function getLock($name, $blocking = false)
|
||||||
{
|
{
|
||||||
if (!preg_match('/^[A-Za-z0-9\.\-_]+$/', $name))
|
if (!preg_match('/^[A-Za-z0-9\.\-_]+$/', $name)) {
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('Invalid lock name: "' . $name . '"');
|
throw new InvalidArgumentException('Invalid lock name: "' . $name . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = static::getLockDir() . '/' . $name;
|
$filename = static::getLockDir() . '/' . $name;
|
||||||
if (!preg_match('/\.lo?ck$/', $filename))
|
if (!preg_match('/\.lo?ck$/', $filename)) {
|
||||||
{
|
|
||||||
$filename .= '.lck';
|
$filename .= '.lck';
|
||||||
}
|
}
|
||||||
if (!file_exists($filename))
|
if (!file_exists($filename)) {
|
||||||
{
|
|
||||||
file_put_contents($filename, '');
|
file_put_contents($filename, '');
|
||||||
chmod($filename, 0666); // if the file cant be opened for writing later, getting the lock will fail
|
chmod($filename, 0666); // if the file cant be opened for writing later, getting the lock will fail
|
||||||
}
|
}
|
||||||
$lockFile = fopen($filename, 'w+');
|
$lockFile = fopen($filename, 'w+');
|
||||||
if (!flock($lockFile, $blocking ? LOCK_EX : LOCK_EX|LOCK_NB))
|
if (!flock($lockFile, $blocking ? LOCK_EX : LOCK_EX|LOCK_NB)) {
|
||||||
{
|
|
||||||
fclose($lockFile);
|
fclose($lockFile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -56,8 +52,7 @@ class Lock
|
||||||
*/
|
*/
|
||||||
public static function freeLock($lockFile)
|
public static function freeLock($lockFile)
|
||||||
{
|
{
|
||||||
if ($lockFile)
|
if ($lockFile) {
|
||||||
{
|
|
||||||
flock($lockFile, LOCK_UN);
|
flock($lockFile, LOCK_UN);
|
||||||
fclose($lockFile);
|
fclose($lockFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ class OS
|
||||||
|
|
||||||
public static function getOsForExtension($ext)
|
public static function getOsForExtension($ext)
|
||||||
{
|
{
|
||||||
switch ($ext)
|
switch ($ext) {
|
||||||
{
|
|
||||||
case 'deb':
|
case 'deb':
|
||||||
return OS::OS_LINUX;
|
return OS::OS_LINUX;
|
||||||
|
|
||||||
|
|
|
@ -35,13 +35,11 @@ class Shell
|
||||||
'live_callback' => null,
|
'live_callback' => null,
|
||||||
], $options);
|
], $options);
|
||||||
|
|
||||||
if ($options['echo_errors'] === null)
|
if ($options['echo_errors'] === null) {
|
||||||
{
|
|
||||||
$options['echo_errors'] = $options['echo'];
|
$options['echo_errors'] = $options['echo'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['live_callback'] && !is_callable($options['live_callback']))
|
if ($options['live_callback'] && !is_callable($options['live_callback'])) {
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('live_callback option must be a valid callback');
|
throw new InvalidArgumentException('live_callback option must be a valid callback');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +49,7 @@ class Shell
|
||||||
];
|
];
|
||||||
|
|
||||||
$process = proc_open($cmd, $descriptorSpec, $pipes);
|
$process = proc_open($cmd, $descriptorSpec, $pipes);
|
||||||
if (!is_resource($process))
|
if (!is_resource($process)) {
|
||||||
{
|
|
||||||
throw new RuntimeException('proc_open failed');
|
throw new RuntimeException('proc_open failed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,37 +59,27 @@ class Shell
|
||||||
$output = '';
|
$output = '';
|
||||||
$err = '';
|
$err = '';
|
||||||
|
|
||||||
while (!feof($pipes[1]) || !feof($pipes[2]))
|
while (!feof($pipes[1]) || !feof($pipes[2])) {
|
||||||
{
|
foreach ($pipes as $key => $pipe) {
|
||||||
foreach ($pipes as $key => $pipe)
|
|
||||||
{
|
|
||||||
$data = fread($pipe, 1024);
|
$data = fread($pipe, 1024);
|
||||||
if (!$data)
|
if (!$data) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (1 == $key)
|
if (1 == $key) {
|
||||||
{
|
|
||||||
$output .= $data;
|
$output .= $data;
|
||||||
if ($options['echo'])
|
if ($options['echo']) {
|
||||||
{
|
|
||||||
fprintf(STDOUT, "%s", $data);
|
fprintf(STDOUT, "%s", $data);
|
||||||
}
|
}
|
||||||
if ($options['live_callback'])
|
if ($options['live_callback']) {
|
||||||
{
|
|
||||||
call_user_func($options['live_callback'], $data, false);
|
call_user_func($options['live_callback'], $data, false);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$err .= $data;
|
$err .= $data;
|
||||||
if ($options['echo_errors'])
|
if ($options['echo_errors']) {
|
||||||
{
|
|
||||||
fprintf(STDERR, "%s", $data);
|
fprintf(STDERR, "%s", $data);
|
||||||
}
|
}
|
||||||
if ($options['live_callback'])
|
if ($options['live_callback']) {
|
||||||
{
|
|
||||||
call_user_func($options['live_callback'], $data, true);
|
call_user_func($options['live_callback'], $data, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,23 +112,17 @@ class Shell
|
||||||
{
|
{
|
||||||
$shellArgs = [];
|
$shellArgs = [];
|
||||||
|
|
||||||
foreach ($options as $key => $value)
|
foreach ($options as $key => $value) {
|
||||||
{
|
if ($value === false) {
|
||||||
if ($value === false)
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($key) === 1)
|
if (strlen($key) === 1) {
|
||||||
{
|
|
||||||
$shellArgs[] = '-'.$key;
|
$shellArgs[] = '-'.$key;
|
||||||
if ($value !== true)
|
if ($value !== true) {
|
||||||
{
|
|
||||||
$shellArgs[] = $value;
|
$shellArgs[] = $value;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$shellArgs[] = '--' . $key . ($value !== true ? '=' . $value : '');
|
$shellArgs[] = '--' . $key . ($value !== true ? '=' . $value : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,7 @@ class Smaz
|
||||||
|
|
||||||
protected static function getEncodeBook($codebook)
|
protected static function getEncodeBook($codebook)
|
||||||
{
|
{
|
||||||
if (!isset(static::$encodeBooks[$codebook]))
|
if (!isset(static::$encodeBooks[$codebook])) {
|
||||||
{
|
|
||||||
static::$encodeBooks[$codebook] = array_flip(static::getDecodeBook($codebook));
|
static::$encodeBooks[$codebook] = array_flip(static::getDecodeBook($codebook));
|
||||||
}
|
}
|
||||||
return static::$encodeBooks[$codebook];
|
return static::$encodeBooks[$codebook];
|
||||||
|
@ -78,12 +77,10 @@ class Smaz
|
||||||
|
|
||||||
protected static function getDecodeBook($codebook)
|
protected static function getDecodeBook($codebook)
|
||||||
{
|
{
|
||||||
if (!static::$decodeBooks[$codebook])
|
if (!static::$decodeBooks[$codebook]) {
|
||||||
{
|
|
||||||
throw new Exception('decodebook ' . $codebook . ' does not exist');
|
throw new Exception('decodebook ' . $codebook . ' does not exist');
|
||||||
}
|
}
|
||||||
if (count(static::$decodeBooks[$codebook]) > static::VERBATIM_CHAR)
|
if (count(static::$decodeBooks[$codebook]) > static::VERBATIM_CHAR) {
|
||||||
{
|
|
||||||
throw new Exception('decodebook ' . $codebook . ' must be at most ' . static::VERBATIM_CHAR . 'entries');
|
throw new Exception('decodebook ' . $codebook . ' must be at most ' . static::VERBATIM_CHAR . 'entries');
|
||||||
}
|
}
|
||||||
return static::$decodeBooks[$codebook];
|
return static::$decodeBooks[$codebook];
|
||||||
|
@ -106,18 +103,14 @@ class Smaz
|
||||||
$verbatim = '';
|
$verbatim = '';
|
||||||
$maxItemLen = max(array_map('strlen', array_keys($encodeBook)));
|
$maxItemLen = max(array_map('strlen', array_keys($encodeBook)));
|
||||||
|
|
||||||
while ($inIdx < $inLen)
|
while ($inIdx < $inLen) {
|
||||||
{
|
|
||||||
$encode = false;
|
$encode = false;
|
||||||
|
|
||||||
for ($j = min($maxItemLen, $inLen - $inIdx); $j > 0; $j--)
|
for ($j = min($maxItemLen, $inLen - $inIdx); $j > 0; $j--) {
|
||||||
{
|
|
||||||
$code = isset($encodeBook[substr($str, $inIdx, $j)]) ? $encodeBook[substr($str, $inIdx, $j)] : null;
|
$code = isset($encodeBook[substr($str, $inIdx, $j)]) ? $encodeBook[substr($str, $inIdx, $j)] : null;
|
||||||
if ($code !== null)
|
if ($code !== null) {
|
||||||
{
|
|
||||||
// echo substr($str, $inIdx, $j) . " = $code\n";
|
// echo substr($str, $inIdx, $j) . " = $code\n";
|
||||||
if (strlen($verbatim))
|
if (strlen($verbatim)) {
|
||||||
{
|
|
||||||
$output .= static::flushVerbatim($verbatim);
|
$output .= static::flushVerbatim($verbatim);
|
||||||
$verbatim = '';
|
$verbatim = '';
|
||||||
}
|
}
|
||||||
|
@ -128,21 +121,18 @@ class Smaz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$encode)
|
if (!$encode) {
|
||||||
{
|
|
||||||
// echo "VERBATIM\n";
|
// echo "VERBATIM\n";
|
||||||
$verbatim .= $str[$inIdx];
|
$verbatim .= $str[$inIdx];
|
||||||
$inIdx++;
|
$inIdx++;
|
||||||
if (strlen($verbatim) == 255) // any longer, and we can't represent the length as a single char
|
if (strlen($verbatim) == 255) { // any longer, and we can't represent the length as a single char
|
||||||
{
|
|
||||||
$output .= static::flushVerbatim($verbatim);
|
$output .= static::flushVerbatim($verbatim);
|
||||||
$verbatim = '';
|
$verbatim = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($verbatim))
|
if (strlen($verbatim)) {
|
||||||
{
|
|
||||||
$output .= static::flushVerbatim($verbatim);
|
$output .= static::flushVerbatim($verbatim);
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
|
@ -161,26 +151,18 @@ class Smaz
|
||||||
$output = '';
|
$output = '';
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
while ($i < strlen($str))
|
while ($i < strlen($str)) {
|
||||||
{
|
|
||||||
$code = ord($str[$i]);
|
$code = ord($str[$i]);
|
||||||
if ($code == static::VERBATIM_CHAR)
|
if ($code == static::VERBATIM_CHAR) {
|
||||||
{
|
|
||||||
$output .= $str[$i + 1];
|
$output .= $str[$i + 1];
|
||||||
$i += 2;
|
$i += 2;
|
||||||
}
|
} elseif ($code == static::VERBATIM_STR) {
|
||||||
elseif ($code == static::VERBATIM_STR)
|
|
||||||
{
|
|
||||||
$len = ord($str[$i + 1]);
|
$len = ord($str[$i + 1]);
|
||||||
$output .= substr($str, $i + 2, $len);
|
$output .= substr($str, $i + 2, $len);
|
||||||
$i += 2 + $len;
|
$i += 2 + $len;
|
||||||
}
|
} elseif (!isset($decodeBook[$code])) {
|
||||||
elseif (!isset($decodeBook[$code]))
|
|
||||||
{
|
|
||||||
return null; // decode error. throw exception?
|
return null; // decode error. throw exception?
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$output .= $decodeBook[$code];
|
$output .= $decodeBook[$code];
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
@ -191,18 +173,14 @@ class Smaz
|
||||||
protected static function flushVerbatim($verbatim)
|
protected static function flushVerbatim($verbatim)
|
||||||
{
|
{
|
||||||
$output = '';
|
$output = '';
|
||||||
if (!strlen($verbatim))
|
if (!strlen($verbatim)) {
|
||||||
{
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($verbatim) > 1)
|
if (strlen($verbatim) > 1) {
|
||||||
{
|
|
||||||
$output .= chr(static::VERBATIM_STR);
|
$output .= chr(static::VERBATIM_STR);
|
||||||
$output .= chr(strlen($verbatim));
|
$output .= chr(strlen($verbatim));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$output .= chr(static::VERBATIM_CHAR);
|
$output .= chr(static::VERBATIM_CHAR);
|
||||||
}
|
}
|
||||||
$output .= $verbatim;
|
$output .= $verbatim;
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class PostNotFoundException extends Exception {}
|
class PostNotFoundException extends Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
class PostMalformedException extends Exception {}
|
class PostMalformedException extends Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
class Post
|
class Post
|
||||||
{
|
{
|
||||||
|
@ -10,14 +14,24 @@ class Post
|
||||||
SORT_ORD_ASC = 'sort_ord_asc';
|
SORT_ORD_ASC = 'sort_ord_asc';
|
||||||
|
|
||||||
protected static $slugMap = [];
|
protected static $slugMap = [];
|
||||||
protected $path, $slug, $title, $metadata, $author, $date, $markdown, $contentText, $contentHtml, $cover, $postType, $category;
|
protected $path;
|
||||||
|
protected $slug;
|
||||||
|
protected $title;
|
||||||
|
protected $metadata;
|
||||||
|
protected $author;
|
||||||
|
protected $date;
|
||||||
|
protected $markdown;
|
||||||
|
protected $contentText;
|
||||||
|
protected $contentHtml;
|
||||||
|
protected $cover;
|
||||||
|
protected $postType;
|
||||||
|
protected $category;
|
||||||
protected $isCoverLight = false;
|
protected $isCoverLight = false;
|
||||||
|
|
||||||
public static function load($relativeOrAbsolutePath)
|
public static function load($relativeOrAbsolutePath)
|
||||||
{
|
{
|
||||||
$pathTokens = explode('/', $relativeOrAbsolutePath);
|
$pathTokens = explode('/', $relativeOrAbsolutePath);
|
||||||
if (count($pathTokens) <= 1)
|
if (count($pathTokens) <= 1) {
|
||||||
{
|
|
||||||
throw new LogicException('Cannot load a post without a path.');
|
throw new LogicException('Cannot load a post without a path.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,13 +43,10 @@ class Post
|
||||||
$relativeOrAbsolutePath .
|
$relativeOrAbsolutePath .
|
||||||
(substr($filename, -3) !== '.md' ? '.md' : '');
|
(substr($filename, -3) !== '.md' ? '.md' : '');
|
||||||
|
|
||||||
if (!file_exists($path) && $isRelative) //may have come in without a post number
|
if (!file_exists($path) && $isRelative) { //may have come in without a post number
|
||||||
{
|
if ($isRelative) {
|
||||||
if ($isRelative)
|
|
||||||
{
|
|
||||||
$slugMap = static::getSlugMap($postType);
|
$slugMap = static::getSlugMap($postType);
|
||||||
if (isset($slugMap[$slug]))
|
if (isset($slugMap[$slug])) {
|
||||||
{
|
|
||||||
return static::load($slugMap[$slug]);
|
return static::load($slugMap[$slug]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,8 +54,7 @@ class Post
|
||||||
}
|
}
|
||||||
|
|
||||||
list($ignored, $frontMatter, $content) = explode('---', file_get_contents($path), 3) + ['','',''];
|
list($ignored, $frontMatter, $content) = explode('---', file_get_contents($path), 3) + ['','',''];
|
||||||
if (!$frontMatter || !$content)
|
if (!$frontMatter || !$content) {
|
||||||
{
|
|
||||||
throw new PostMalformedException('Post "' . basename($path) . '" is missing front matter or content');
|
throw new PostMalformedException('Post "' . basename($path) . '" is missing front matter or content');
|
||||||
}
|
}
|
||||||
return new static($path, $postType, $slug, Spyc::YAMLLoadString(trim($frontMatter)), trim($content));
|
return new static($path, $postType, $slug, Spyc::YAMLLoadString(trim($frontMatter)), trim($content));
|
||||||
|
@ -68,15 +78,12 @@ class Post
|
||||||
public static function find($folder, $sort = null)
|
public static function find($folder, $sort = null)
|
||||||
{
|
{
|
||||||
$posts = [];
|
$posts = [];
|
||||||
foreach(glob(rtrim($folder, '/') . '/*.md') as $file)
|
foreach (glob(rtrim($folder, '/') . '/*.md') as $file) {
|
||||||
{
|
|
||||||
$posts[] = static::load($file);
|
$posts[] = static::load($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sort)
|
if ($sort) {
|
||||||
{
|
switch ($sort) {
|
||||||
switch ($sort)
|
|
||||||
{
|
|
||||||
case static::SORT_DATE_DESC:
|
case static::SORT_DATE_DESC:
|
||||||
usort($posts, function (Post $a, Post $b) {
|
usort($posts, function (Post $a, Post $b) {
|
||||||
return strcasecmp($b->getDate()->format('Y-m-d'), $a->getDate()->format('Y-m-d'));
|
return strcasecmp($b->getDate()->format('Y-m-d'), $a->getDate()->format('Y-m-d'));
|
||||||
|
@ -87,12 +94,10 @@ class Post
|
||||||
usort($posts, function (Post $a, Post $b) {
|
usort($posts, function (Post $a, Post $b) {
|
||||||
$aMeta = $a->getMetadata();
|
$aMeta = $a->getMetadata();
|
||||||
$bMeta = $b->getMetadata();
|
$bMeta = $b->getMetadata();
|
||||||
if (!isset($aMeta['order']) && !isset($bMeta['order']))
|
if (!isset($aMeta['order']) && !isset($bMeta['order'])) {
|
||||||
{
|
|
||||||
return $a->getTitle() < $b->getTitle() ? -1 : 1;
|
return $a->getTitle() < $b->getTitle() ? -1 : 1;
|
||||||
}
|
}
|
||||||
if (isset($aMeta['order']) && isset($bMeta['order']))
|
if (isset($aMeta['order']) && isset($bMeta['order'])) {
|
||||||
{
|
|
||||||
return $aMeta['order'] < $bMeta['order'] ? -1 : 1;
|
return $aMeta['order'] < $bMeta['order'] ? -1 : 1;
|
||||||
}
|
}
|
||||||
return isset($aMeta['order']) ? -1 : 1;
|
return isset($aMeta['order']) ? -1 : 1;
|
||||||
|
@ -107,13 +112,11 @@ class Post
|
||||||
{
|
{
|
||||||
return array_filter($posts, function (Post $post) use ($filters) {
|
return array_filter($posts, function (Post $post) use ($filters) {
|
||||||
$metadata = $post->getMetadata();
|
$metadata = $post->getMetadata();
|
||||||
foreach($filters as $filterAttr => $filterValue)
|
foreach ($filters as $filterAttr => $filterValue) {
|
||||||
{
|
|
||||||
if (!isset($metadata[$filterAttr]) || (
|
if (!isset($metadata[$filterAttr]) || (
|
||||||
($metadata[$filterAttr] != $filterValue) &&
|
($metadata[$filterAttr] != $filterValue) &&
|
||||||
(!is_array($metadata[$filterAttr]) || !in_array($filterValue, $metadata[$filterAttr]))
|
(!is_array($metadata[$filterAttr]) || !in_array($filterValue, $metadata[$filterAttr]))
|
||||||
))
|
)) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,8 +205,7 @@ public function getAuthorEmail()
|
||||||
|
|
||||||
public function getContentText($wordLimit = null, $appendEllipsis = false)
|
public function getContentText($wordLimit = null, $appendEllipsis = false)
|
||||||
{
|
{
|
||||||
if ($this->markdown && !$this->contentText)
|
if ($this->markdown && !$this->contentText) {
|
||||||
{
|
|
||||||
// $this->contentText = $this->markdownToText(trim($this->markdown));
|
// $this->contentText = $this->markdownToText(trim($this->markdown));
|
||||||
$this->contentText = html_entity_decode(str_replace(' ', ' ', strip_tags($this->getContentHtml())), ENT_COMPAT, 'utf-8');
|
$this->contentText = html_entity_decode(str_replace(' ', ' ', strip_tags($this->getContentHtml())), ENT_COMPAT, 'utf-8');
|
||||||
}
|
}
|
||||||
|
@ -213,8 +215,7 @@ public function getAuthorEmail()
|
||||||
|
|
||||||
public function getContentHtml()
|
public function getContentHtml()
|
||||||
{
|
{
|
||||||
if ($this->markdown && !$this->contentHtml)
|
if ($this->markdown && !$this->contentHtml) {
|
||||||
{
|
|
||||||
$this->contentHtml = ParsedownExtra::instance()->text(trim($this->markdown));
|
$this->contentHtml = ParsedownExtra::instance()->text(trim($this->markdown));
|
||||||
}
|
}
|
||||||
return $this->contentHtml;
|
return $this->contentHtml;
|
||||||
|
@ -261,7 +262,6 @@ public function getAuthorEmail()
|
||||||
$post = ContentActions::prepareBioPartial(['person' =>$this->author]);
|
$post = ContentActions::prepareBioPartial(['person' =>$this->author]);
|
||||||
|
|
||||||
return $post["email"];
|
return $post["email"];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAuthorPhoto()
|
public function getAuthorPhoto()
|
||||||
|
@ -288,16 +288,14 @@ public function getAuthorEmail()
|
||||||
$urls = [];
|
$urls = [];
|
||||||
|
|
||||||
$cover = $this->getCover();
|
$cover = $this->getCover();
|
||||||
if ($cover)
|
if ($cover) {
|
||||||
{
|
|
||||||
$urls[] = 'https://' . Request::getHost() . '/img/blog-covers/' . $cover;
|
$urls[] = 'https://' . Request::getHost() . '/img/blog-covers/' . $cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
$matches = [];
|
$matches = [];
|
||||||
preg_match_all('/!\[.*?\]\((.*?)\)/', $this->markdown, $matches);
|
preg_match_all('/!\[.*?\]\((.*?)\)/', $this->markdown, $matches);
|
||||||
|
|
||||||
if ($matches)
|
if ($matches) {
|
||||||
{
|
|
||||||
$urls = array_merge($urls, $matches[1]);
|
$urls = array_merge($urls, $matches[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,15 +336,13 @@ public function getAuthorEmail()
|
||||||
|
|
||||||
# TBB: if there are $wordLimit words or less, this check is necessary
|
# TBB: if there are $wordLimit words or less, this check is necessary
|
||||||
# to prevent the last word from being lost.
|
# to prevent the last word from being lost.
|
||||||
if ($numWords > $wordLimit)
|
if ($numWords > $wordLimit) {
|
||||||
{
|
|
||||||
array_pop($words);
|
array_pop($words);
|
||||||
}
|
}
|
||||||
|
|
||||||
$string = implode(' ', $words);
|
$string = implode(' ', $words);
|
||||||
|
|
||||||
if ($appendEllipsis && $numWords > $wordLimit)
|
if ($appendEllipsis && $numWords > $wordLimit) {
|
||||||
{
|
|
||||||
$ellipsis = '…';
|
$ellipsis = '…';
|
||||||
$string .= $ellipsis;
|
$string .= $ellipsis;
|
||||||
}
|
}
|
||||||
|
@ -371,13 +367,11 @@ public function getAuthorEmail()
|
||||||
|
|
||||||
public static function getSlugMap($postType)
|
public static function getSlugMap($postType)
|
||||||
{
|
{
|
||||||
if (!isset(static::$slugMap[$postType]))
|
if (!isset(static::$slugMap[$postType])) {
|
||||||
{
|
|
||||||
static::$slugMap[$postType] = [];
|
static::$slugMap[$postType] = [];
|
||||||
$files = glob(ContentActions::CONTENT_DIR . '/' . $postType . '/*.md');
|
$files = glob(ContentActions::CONTENT_DIR . '/' . $postType . '/*.md');
|
||||||
usort($files, 'strnatcasecmp');
|
usort($files, 'strnatcasecmp');
|
||||||
foreach($files as $file)
|
foreach ($files as $file) {
|
||||||
{
|
|
||||||
static::$slugMap[$postType][static::getSlugFromFilename($file)] = $file;
|
static::$slugMap[$postType][static::getSlugFromFilename($file)] = $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,7 @@ $options = getopt('f');
|
||||||
$force = isset($options['f']); // update even if no NEEDS_UPDATE file exists
|
$force = isset($options['f']); // update even if no NEEDS_UPDATE file exists
|
||||||
|
|
||||||
$needsUpdateFile = ROOT_DIR . '/data/writeable/NEEDS_UPDATE';
|
$needsUpdateFile = ROOT_DIR . '/data/writeable/NEEDS_UPDATE';
|
||||||
if (!$force && !file_exists($needsUpdateFile))
|
if (!$force && !file_exists($needsUpdateFile)) {
|
||||||
{
|
|
||||||
echo "No update necessary\n";
|
echo "No update necessary\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,25 +16,24 @@ class Response
|
||||||
const HEADER_CONTENT_ENCODING = 'Content-Encoding';
|
const HEADER_CONTENT_ENCODING = 'Content-Encoding';
|
||||||
const HEADER_CROSS_ORIGIN = 'Access-Control-Allow-Origin';
|
const HEADER_CROSS_ORIGIN = 'Access-Control-Allow-Origin';
|
||||||
|
|
||||||
protected static
|
protected static $metaDescription = '';
|
||||||
$metaDescription = '',
|
protected static $metaTitle = '';
|
||||||
$metaTitle = '',
|
protected static $jsCalls = [];
|
||||||
$jsCalls = [],
|
protected static $assets = [
|
||||||
$assets = [
|
|
||||||
'js' => [
|
'js' => [
|
||||||
'/js/jquery-3.3.1.min.js',
|
'/js/jquery-3.3.1.min.js',
|
||||||
'/js/global.js'
|
'/js/global.js'
|
||||||
],
|
],
|
||||||
'css' => ['/css/all.css']
|
'css' => ['/css/all.css']
|
||||||
],
|
];
|
||||||
$headers = [],
|
protected static $headers = [];
|
||||||
$headersSent = false,
|
protected static $headersSent = false;
|
||||||
$content = '',
|
protected static $content = '';
|
||||||
$contentSent = false,
|
protected static $contentSent = false;
|
||||||
$isHeadersOnly = false,
|
protected static $isHeadersOnly = false;
|
||||||
$gzipResponseContent = true,
|
protected static $gzipResponseContent = true;
|
||||||
$metaImages = [],
|
protected static $metaImages = [];
|
||||||
$facebookAnalyticsType = "PageView";
|
protected static $facebookAnalyticsType = "PageView";
|
||||||
|
|
||||||
public static function setMetaDescription($description)
|
public static function setMetaDescription($description)
|
||||||
{
|
{
|
||||||
|
@ -48,8 +47,7 @@ class Response
|
||||||
|
|
||||||
public static function addMetaImages(array $urls)
|
public static function addMetaImages(array $urls)
|
||||||
{
|
{
|
||||||
foreach ($urls as $url)
|
foreach ($urls as $url) {
|
||||||
{
|
|
||||||
static::addMetaImage($url);
|
static::addMetaImage($url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,13 +76,10 @@ class Response
|
||||||
{
|
{
|
||||||
$title = '';
|
$title = '';
|
||||||
preg_match_all('/<h(1|2)[^>]*>([^<]+)</', $content, $titleMatches);
|
preg_match_all('/<h(1|2)[^>]*>([^<]+)</', $content, $titleMatches);
|
||||||
foreach ($titleMatches[1] as $matchIndex => $headerValue)
|
foreach ($titleMatches[1] as $matchIndex => $headerValue) {
|
||||||
{
|
if ($headerValue == '1' || !$title) {
|
||||||
if ($headerValue == '1' || !$title)
|
|
||||||
{
|
|
||||||
$title = $titleMatches[2][$matchIndex];
|
$title = $titleMatches[2][$matchIndex];
|
||||||
if ($headerValue == '1')
|
if ($headerValue == '1') {
|
||||||
{
|
|
||||||
return $title;
|
return $title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +118,8 @@ class Response
|
||||||
return static::$assets['css'];
|
return static::$assets['css'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setCssAssets(array $assets = []){
|
public static function setCssAssets(array $assets = [])
|
||||||
|
{
|
||||||
static::$assets['css'] = $assets;
|
static::$assets['css'] = $assets;
|
||||||
}
|
}
|
||||||
public static function setGzipResponseContent($gzip = true)
|
public static function setGzipResponseContent($gzip = true)
|
||||||
|
@ -133,11 +129,9 @@ class Response
|
||||||
|
|
||||||
public static function gzipContentIfNotDisabled()
|
public static function gzipContentIfNotDisabled()
|
||||||
{
|
{
|
||||||
if (static::$gzipResponseContent)
|
if (static::$gzipResponseContent) {
|
||||||
{
|
|
||||||
$content = static::getContent();
|
$content = static::getContent();
|
||||||
if (strlen($content) > 256) // not worth it for really short content
|
if (strlen($content) > 256) { // not worth it for really short content
|
||||||
{
|
|
||||||
$compressed = gzencode($content, 1);
|
$compressed = gzencode($content, 1);
|
||||||
static::setContent($compressed);
|
static::setContent($compressed);
|
||||||
static::setHeader(static::HEADER_CONTENT_LENGTH, strlen($compressed));
|
static::setHeader(static::HEADER_CONTENT_LENGTH, strlen($compressed));
|
||||||
|
@ -164,13 +158,11 @@ class Response
|
||||||
|
|
||||||
public static function sendContent()
|
public static function sendContent()
|
||||||
{
|
{
|
||||||
if (static::$contentSent)
|
if (static::$contentSent) {
|
||||||
{
|
|
||||||
throw new LogicException('Content has already been sent. It cannot be sent twice');
|
throw new LogicException('Content has already been sent. It cannot be sent twice');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!static::$isHeadersOnly)
|
if (!static::$isHeadersOnly) {
|
||||||
{
|
|
||||||
echo static::$content;
|
echo static::$content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,10 +205,8 @@ class Response
|
||||||
{
|
{
|
||||||
$cacheControl = static::getHeader(static::HEADER_CACHE_CONTROL);
|
$cacheControl = static::getHeader(static::HEADER_CACHE_CONTROL);
|
||||||
$currentHeaders = [];
|
$currentHeaders = [];
|
||||||
if ($cacheControl)
|
if ($cacheControl) {
|
||||||
{
|
foreach (preg_split('/\s*,\s*/', $cacheControl) as $tmp) {
|
||||||
foreach (preg_split('/\s*,\s*/', $cacheControl) as $tmp)
|
|
||||||
{
|
|
||||||
$tmp = explode('=', $tmp);
|
$tmp = explode('=', $tmp);
|
||||||
$currentHeaders[$tmp[0]] = $tmp[1] ?? null;
|
$currentHeaders[$tmp[0]] = $tmp[1] ?? null;
|
||||||
}
|
}
|
||||||
|
@ -224,8 +214,7 @@ class Response
|
||||||
$currentHeaders[strtr(strtolower($name), '_', '-')] = $value;
|
$currentHeaders[strtr(strtolower($name), '_', '-')] = $value;
|
||||||
|
|
||||||
$headers = [];
|
$headers = [];
|
||||||
foreach ($currentHeaders as $key => $currentVal)
|
foreach ($currentHeaders as $key => $currentVal) {
|
||||||
{
|
|
||||||
$headers[] = $key . ($currentVal !== null ? '=' . $currentVal : '');
|
$headers[] = $key . ($currentVal !== null ? '=' . $currentVal : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,10 +228,8 @@ class Response
|
||||||
|
|
||||||
public static function setHeaders($headers, $overwrite = true)
|
public static function setHeaders($headers, $overwrite = true)
|
||||||
{
|
{
|
||||||
foreach ($headers as $name => $value)
|
foreach ($headers as $name => $value) {
|
||||||
{
|
if ($overwrite || !static::getHeader($name)) {
|
||||||
if ($overwrite || !static::getHeader($name))
|
|
||||||
{
|
|
||||||
static::setHeader($name, $value);
|
static::setHeader($name, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,8 +258,7 @@ class Response
|
||||||
'X-XSS-Protection' => '1',
|
'X-XSS-Protection' => '1',
|
||||||
];
|
];
|
||||||
|
|
||||||
if (IS_PRODUCTION)
|
if (IS_PRODUCTION) {
|
||||||
{
|
|
||||||
$defaultHeaders['Strict-Transport-Security'] = 'max-age=31536000';
|
$defaultHeaders['Strict-Transport-Security'] = 'max-age=31536000';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,33 +267,28 @@ class Response
|
||||||
|
|
||||||
public static function sendHeaders()
|
public static function sendHeaders()
|
||||||
{
|
{
|
||||||
if (static::$headersSent)
|
if (static::$headersSent) {
|
||||||
{
|
|
||||||
throw new LogicException('Headers have already been sent. They cannot be sent twice');
|
throw new LogicException('Headers have already been sent. They cannot be sent twice');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!static::getHeader(static::HEADER_CONTENT_TYPE))
|
if (!static::getHeader(static::HEADER_CONTENT_TYPE)) {
|
||||||
{
|
|
||||||
static::setHeader(static::HEADER_CONTENT_TYPE, 'text/html');
|
static::setHeader(static::HEADER_CONTENT_TYPE, 'text/html');
|
||||||
}
|
}
|
||||||
|
|
||||||
$headers = static::getHeaders();
|
$headers = static::getHeaders();
|
||||||
|
|
||||||
if (isset($headers[static::HEADER_STATUS]))
|
if (isset($headers[static::HEADER_STATUS])) {
|
||||||
{
|
|
||||||
$status = 'HTTP/1.0 ' . $headers[static::HEADER_STATUS] . ' ' . static::getStatusTextForCode($headers[static::HEADER_STATUS]);
|
$status = 'HTTP/1.0 ' . $headers[static::HEADER_STATUS] . ' ' . static::getStatusTextForCode($headers[static::HEADER_STATUS]);
|
||||||
header($status);
|
header($status);
|
||||||
|
|
||||||
if (substr(php_sapi_name(), 0, 3) == 'cgi')
|
if (substr(php_sapi_name(), 0, 3) == 'cgi') {
|
||||||
{
|
|
||||||
// fastcgi servers cannot send this status information because it was sent by them already due to the HTT/1.0 line
|
// fastcgi servers cannot send this status information because it was sent by them already due to the HTT/1.0 line
|
||||||
// so we can safely unset them. see ticket #3191
|
// so we can safely unset them. see ticket #3191
|
||||||
unset($headers[static::HEADER_STATUS]);
|
unset($headers[static::HEADER_STATUS]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($headers as $name => $value)
|
foreach ($headers as $name => $value) {
|
||||||
{
|
|
||||||
header($name . ': ' . $value);
|
header($name . ': ' . $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,11 +348,13 @@ class Response
|
||||||
return $statusTexts[$code] ?? null;
|
return $statusTexts[$code] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setFacebookPixelAnalyticsType($type){
|
public static function setFacebookPixelAnalyticsType($type)
|
||||||
|
{
|
||||||
static::$facebookAnalyticsType = $type;
|
static::$facebookAnalyticsType = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFacebookPixelAnalyticsType(){
|
public static function getFacebookPixelAnalyticsType()
|
||||||
|
{
|
||||||
return static::$facebookAnalyticsType;
|
return static::$facebookAnalyticsType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +362,9 @@ class Response
|
||||||
{
|
{
|
||||||
return preg_replace_callback(
|
return preg_replace_callback(
|
||||||
'/\-(.)/',
|
'/\-(.)/',
|
||||||
function ($matches) { return '-' . strtoupper($matches[1]); },
|
function ($matches) {
|
||||||
|
return '-' . strtoupper($matches[1]);
|
||||||
|
},
|
||||||
strtr(ucfirst(strtolower($name)), '_', '-')
|
strtr(ucfirst(strtolower($name)), '_', '-')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,11 @@ class View
|
||||||
|
|
||||||
public static function render($template, array $vars = []): string
|
public static function render($template, array $vars = []): string
|
||||||
{
|
{
|
||||||
if (static::isMarkdown($template))
|
if (static::isMarkdown($template)) {
|
||||||
{
|
|
||||||
return static::markdownToHtml(static::getFullPath($template));
|
return static::markdownToHtml(static::getFullPath($template));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!static::exists($template) || substr_count($template, '/') !== 1)
|
if (!static::exists($template) || substr_count($template, '/') !== 1) {
|
||||||
{
|
|
||||||
throw new InvalidArgumentException(sprintf('The template "%s" does not exist or is unreadable.', $template));
|
throw new InvalidArgumentException(sprintf('The template "%s" does not exist or is unreadable.', $template));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,13 +35,11 @@ class View
|
||||||
$actionClass = ucfirst($module) . 'Actions';
|
$actionClass = ucfirst($module) . 'Actions';
|
||||||
$method = 'prepare' . ucfirst(ltrim($view, '_')) . ($isPartial ? 'Partial' : '');
|
$method = 'prepare' . ucfirst(ltrim($view, '_')) . ($isPartial ? 'Partial' : '');
|
||||||
|
|
||||||
if (method_exists($actionClass, $method))
|
if (method_exists($actionClass, $method)) {
|
||||||
{
|
|
||||||
$vars = $actionClass::$method($vars);
|
$vars = $actionClass::$method($vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($vars === null)
|
if ($vars === null) {
|
||||||
{
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,13 +61,10 @@ class View
|
||||||
ob_start();
|
ob_start();
|
||||||
ob_implicit_flush(0);
|
ob_implicit_flush(0);
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
require(static::getFullPath($___template));
|
require(static::getFullPath($___template));
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
}
|
} catch (Throwable $e) {
|
||||||
catch (Throwable $e)
|
|
||||||
{
|
|
||||||
// need to end output buffering before throwing the exception
|
// need to end output buffering before throwing the exception
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -95,13 +88,11 @@ class View
|
||||||
|
|
||||||
protected static function getFullPath($template): string
|
protected static function getFullPath($template): string
|
||||||
{
|
{
|
||||||
if ($template && $template[0] == '/')
|
if ($template && $template[0] == '/') {
|
||||||
{
|
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (static::isMarkdown($template))
|
if (static::isMarkdown($template)) {
|
||||||
{
|
|
||||||
return ContentActions::CONTENT_DIR . '/' . $template;
|
return ContentActions::CONTENT_DIR . '/' . $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,12 +120,9 @@ class View
|
||||||
$scssCompiler->setImportPaths([self::SCSS_DIR]);
|
$scssCompiler->setImportPaths([self::SCSS_DIR]);
|
||||||
|
|
||||||
$compress = true;
|
$compress = true;
|
||||||
if ($compress)
|
if ($compress) {
|
||||||
{
|
|
||||||
$scssCompiler->setFormatter('Leafo\ScssPhp\Formatter\Crunched');
|
$scssCompiler->setFormatter('Leafo\ScssPhp\Formatter\Crunched');
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$scssCompiler->setFormatter('Leafo\ScssPhp\Formatter\Expanded');
|
$scssCompiler->setFormatter('Leafo\ScssPhp\Formatter\Expanded');
|
||||||
$scssCompiler->setLineNumberStyle(Leafo\ScssPhp\Compiler::LINE_COMMENTS);
|
$scssCompiler->setLineNumberStyle(Leafo\ScssPhp\Compiler::LINE_COMMENTS);
|
||||||
}
|
}
|
||||||
|
@ -148,10 +136,8 @@ class View
|
||||||
|
|
||||||
public static function gzipAssets()
|
public static function gzipAssets()
|
||||||
{
|
{
|
||||||
foreach ([self::CSS_DIR => 'css', self::JS_DIR => 'js'] as $dir => $ext)
|
foreach ([self::CSS_DIR => 'css', self::JS_DIR => 'js'] as $dir => $ext) {
|
||||||
{
|
foreach (glob("$dir/*.$ext") as $file) {
|
||||||
foreach (glob("$dir/*.$ext") as $file)
|
|
||||||
{
|
|
||||||
Gzip::compressFile($file);
|
Gzip::compressFile($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,8 +145,7 @@ class View
|
||||||
|
|
||||||
protected static function interpolateTokens($html): string
|
protected static function interpolateTokens($html): string
|
||||||
{
|
{
|
||||||
return preg_replace_callback('/{{[\w\.]+}}/is', function ($m)
|
return preg_replace_callback('/{{[\w\.]+}}/is', function ($m) {
|
||||||
{
|
|
||||||
return i18n::translate(trim($m[0], '}{'));
|
return i18n::translate(trim($m[0], '}{'));
|
||||||
}, $html);
|
}, $html);
|
||||||
}
|
}
|
||||||
|
@ -172,8 +157,7 @@ class View
|
||||||
|
|
||||||
protected static function attributesToHtml($attributes): string
|
protected static function attributesToHtml($attributes): string
|
||||||
{
|
{
|
||||||
return implode('', array_map(function ($k, $v)
|
return implode('', array_map(function ($k, $v) {
|
||||||
{
|
|
||||||
return $v === true ? " $k" : ($v === false || $v === null || ($v === '' && $k != 'value') ? '' : sprintf(' %s="%s"', $k, static::escapeOnce($v)));
|
return $v === true ? " $k" : ($v === false || $v === null || ($v === '' && $k != 'value') ? '' : sprintf(' %s="%s"', $k, static::escapeOnce($v)));
|
||||||
}, array_keys($attributes), array_values($attributes)));
|
}, array_keys($attributes), array_values($attributes)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,3 @@ if(!preg_match("/@[A-Za-z0-9_-]+$/", $desired_lbry_channel_name)){
|
||||||
}
|
}
|
||||||
|
|
||||||
AcquisitionActions::actionYoutubeToken($desired_lbry_channel_name);
|
AcquisitionActions::actionYoutubeToken($desired_lbry_channel_name);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<?php echo json_encode($json ?? [], JSON_PRETTY_PRINT) ?>
|
<?php echo json_encode($json ?? [], JSON_PRETTY_PRINT);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<?php echo file_get_contents($zipPath) ?>
|
<?php echo file_get_contents($zipPath);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
# Enable PHP dev cli-server
|
# Enable PHP dev cli-server
|
||||||
if (php_sapi_name() === 'cli-server' && is_file(__DIR__.preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI'])))
|
if (php_sapi_name() === 'cli-server' && is_file(__DIR__.preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']))) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,28 +14,22 @@ error_reporting(IS_PRODUCTION ? 0 : (E_ALL | E_STRICT));
|
||||||
|
|
||||||
register_shutdown_function('Controller::shutdown');
|
register_shutdown_function('Controller::shutdown');
|
||||||
|
|
||||||
if (!IS_PRODUCTION)
|
if (!IS_PRODUCTION) {
|
||||||
{
|
|
||||||
// make warnings into errors
|
// make warnings into errors
|
||||||
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
||||||
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
|
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
|
||||||
}, E_WARNING|E_CORE_WARNING|E_COMPILE_WARNING|E_USER_WARNING);
|
}, E_WARNING|E_CORE_WARNING|E_COMPILE_WARNING|E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
Session::init();
|
Session::init();
|
||||||
i18n::register();
|
i18n::register();
|
||||||
if (!IS_PRODUCTION)
|
if (!IS_PRODUCTION) {
|
||||||
{
|
|
||||||
View::compileCss();
|
View::compileCss();
|
||||||
}
|
}
|
||||||
Controller::dispatch(Request::getRoutingUri());
|
Controller::dispatch(Request::getRoutingUri());
|
||||||
}
|
} catch (Throwable $e) {
|
||||||
catch(Throwable $e)
|
if (IS_PRODUCTION) {
|
||||||
{
|
|
||||||
if (IS_PRODUCTION)
|
|
||||||
{
|
|
||||||
Slack::sendErrorIfProd($e);
|
Slack::sendErrorIfProd($e);
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue