spacing and formatting

This commit is contained in:
Alex Grintsvayg 2016-10-12 11:37:13 -04:00
parent ff49e3e1fd
commit f4cb4df64a
6 changed files with 65 additions and 57 deletions

View file

@ -115,9 +115,9 @@ class Controller
'/deck.pdf' => 'https://www.dropbox.com/s/0xj4vgucsbi8rtv/lbry-deck.pdf?dl=1',
'/pln.pdf' => 'https://www.dropbox.com/s/uevjrwnyr672clj/lbry-pln.pdf?dl=1',
'/plan.pdf' => 'https://www.dropbox.com/s/uevjrwnyr672clj/lbry-pln.pdf?dl=1',
'/get/lbry.dmg' => GitHub::getDownloadUrl(Os::OS_OSX) ?: '/get',
'/get/lbry.deb' => GitHub::getDownloadUrl(Os::OS_LINUX) ?: '/get',
'/get/lbry.msi' => GitHub::getDownloadUrl(Os::OS_WINDOWS) ?: '/get',
'/get/lbry.dmg' => GitHub::getDownloadUrl(OS::OS_OSX) ?: '/get',
'/get/lbry.deb' => GitHub::getDownloadUrl(OS::OS_LINUX) ?: '/get',
'/get/lbry.msi' => GitHub::getDownloadUrl(OS::OS_WINDOWS) ?: '/get',
];
foreach ([302 => $tempRedirects, 301 => $permanentRedirects] as $code => $redirects)

View file

@ -35,7 +35,7 @@ class DownloadActions extends Actions
return ['download/get'];
}
$osChoices = Os::getAll();
$osChoices = OS::getAll();
$os = static::guessOs();
if ($os && isset($osChoices[$os]))
@ -105,8 +105,8 @@ class DownloadActions extends Actions
public static function prepareListPartial(array $vars)
{
return $vars + ['osChoices' => isset($vars['excludeOs']) ?
array_diff_key(Os::getAll(), [$vars['excludeOs'] => null]) :
Os::getAll()
array_diff_key(OS::getAll(), [$vars['excludeOs'] => null]) :
OS::getAll()
];
}
@ -147,7 +147,7 @@ class DownloadActions extends Actions
{
//if exact OS is requested, use that
$uri = Request::getRelativeUri();
foreach (Os::getAll() as $os => $osChoice)
foreach (OS::getAll() as $os => $osChoice)
{
if ($osChoice[0] == $uri)
{
@ -164,15 +164,15 @@ class DownloadActions extends Actions
$ua = Request::getUserAgent();
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)
{
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)
{
return Os::OS_WINDOWS;
return OS::OS_WINDOWS;
}
}
}

View file

@ -2,22 +2,22 @@
class Github
{
public static function getDownloadUrl($os, $useCache = true)
public static function getDownloadUrl($os, $cache = true)
{
if (!in_array($os, array_keys(Os::getAll())))
if (!in_array($os, array_keys(OS::getAll())))
{
throw new DomainException('Unknown OS');
}
try
{
$releaseData = static::get('/repos/lbryio/lbry/releases/latest');
$releaseData = static::get('/repos/lbryio/lbry/releases/latest', $cache);
foreach ($releaseData['assets'] as $asset)
{
if (
($os == Os::OS_LINUX && in_array($asset['content_type'], ['application/x-debian-package', 'application/x-deb'])) ||
($os == Os::OS_OSX && in_array($asset['content_type'], ['application/x-diskcopy', 'application/x-apple-diskimage'])) ||
($os == Os::OS_WINDOWS && substr($asset['name'], -4) == '.msi')
($os == OS::OS_LINUX && in_array($asset['content_type'], ['application/x-debian-package', 'application/x-deb'])) ||
($os == OS::OS_OSX && in_array($asset['content_type'], ['application/x-diskcopy', 'application/x-apple-diskimage'])) ||
($os == OS::OS_WINDOWS && substr($asset['name'], -4) == '.msi')
)
{
return $asset['browser_download_url'];
@ -33,7 +33,8 @@ class Github
public static function get($endpoint, $cache = true)
{
return CurlWithCache::get('https://api.github.com' . $endpoint, [], ['user_agent' => 'LBRY', 'json_response' => true, 'cache' => $cache]);
return CurlWithCache::get('https://api.github.com' . $endpoint, [],
['user_agent' => 'LBRY', 'json_response' => true, 'cache' => $cache]);
}
public static function listRoadmapChangesets($cache = true)
@ -52,10 +53,13 @@ class Github
{
$releases = static::get('/repos/lbryio/' . $project . '/releases?page=' . $page, $cache);
$page++;
$allReleases = array_merge($allReleases, array_map(function($release) use($label, $project) {
$allReleases = array_merge($allReleases, array_map(function ($release) use ($label, $project)
{
return $release + ['project_label' => $label, 'project' => $project];
}, array_filter($releases, function ($release) {
return isset($release['tag_name']) && isset($release['published_at']) && $release['published_at'] && $release['tag_name'] != 'v0.4.0';
}, array_filter($releases, function ($release)
{
return isset($release['tag_name']) && isset($release['published_at']) && $release['published_at'] &&
$release['tag_name'] != 'v0.4.0';
})));
} while (count($releases) >= 30);
}
@ -70,8 +74,11 @@ class Github
}
if ($group)
{
$sets[$group][] = array_intersect_key($release, ['prerelease' => null, 'tag_name' => null, 'published_at' => null, 'project' => null, 'project_label' => null]) + [
'date' => date('Y-m-d', strtotime($release['created_at'])), //I thought published_at, but GitHub displays created_at and published_at is out of sync sometimes (0.3.2, 0.3.3)
$sets[$group][] = array_intersect_key($release, [
'prerelease' => null, 'tag_name' => null, 'published_at' => null, 'project' => null, 'project_label' => null
]) + [
'date' => date('Y-m-d', strtotime($release['created_at'])),
//I thought published_at, but GitHub displays created_at and published_at is out of sync sometimes (0.3.2, 0.3.3)
'name' => $release['name'] ?: $release['tag_name'],
'github_url' => $release['url'],
'major_version' => $matches[1],
@ -83,7 +90,8 @@ class Github
}
}
uasort($sets, function($sA, $sB) {
uasort($sets, function ($sA, $sB)
{
if ($sA[0]['project'] != $sB[0]['project'])
{
return $sA[0]['project'] < $sB[0]['project'] ? -1 : 1;

23
lib/tools/OS.class.php Normal file
View file

@ -0,0 +1,23 @@
<?php
class OS
{
const OS_ANDROID = 'android',
OS_IOS = 'ios',
OS_LINUX = 'linux',
OS_OSX = 'osx',
OS_WINDOWS = 'windows';
public static function getAll()
{
//url, English name, icon class, partial name
//yes, this is probably a bad pattern
return [
OS::OS_WINDOWS => ['/windows', 'Windows', 'icon-windows', '_windows'],
OS::OS_OSX => ['/osx', 'OS X', 'icon-apple', '_osx'],
OS::OS_LINUX => ['/linux', 'Linux', 'icon-linux', '_linux'],
OS::OS_ANDROID => ['/android', 'Android', 'icon-android', '_android'],
OS::OS_IOS => ['/ios', 'iOS', 'icon-mobile', '_ios']
];
}
}

View file

@ -1,23 +0,0 @@
<?php
class Os
{
const OS_ANDROID = 'android',
OS_IOS = 'ios',
OS_LINUX = 'linux',
OS_OSX = 'osx',
OS_WINDOWS = 'windows';
public static function getAll()
{
//url, English name, icon class, partial name
//yes, this is probably a bad pattern
return [
Os::OS_WINDOWS => ['/windows', 'Windows', 'icon-windows', '_windows'],
Os::OS_OSX => ['/osx', 'OS X', 'icon-apple', '_osx'],
Os::OS_LINUX => ['/linux', 'Linux', 'icon-linux', '_linux'],
Os::OS_ANDROID => ['/android', 'Android', 'icon-android', '_android'],
Os::OS_IOS => ['/ios', 'iOS', 'icon-mobile', '_ios']
];
}
}