Commit ce899f0e authored by Carl Schwan's avatar Carl Schwan 🚴
Browse files

Add legacy redirecter

parent c2a317b8
......@@ -57,15 +57,23 @@ class MainController extends AbstractController
*/
public function category(Request $request, string $_locale, string $category): Response
{
print_r($this->getParameter('app.locales'));
if ($request->query->get('site_locale')) {
return $this->redirectToRoute('app_main_category_intl', ['_locale' => $request->query->get('site_locale'), 'category' => $category]);
}
$applicationsProvider = new ApplicationsProviderFile("index.json");
$categoryObject = $applicationsProvider->getApplicationsByCategory(ucfirst($category));
return $this->render('main/category.html.twig', [
'category' => $applicationsProvider->getApplicationsByCategory(ucfirst($category)),
'locale' => $_locale
if ($categoryObject) {
return $this->render('main/category.html.twig', [
'category' => $categoryObject,
'locale' => $_locale
]);
}
$applicationObj = AppData::fromBinary($category);
return $this->redirectToRoute('app_main_application_intl', [
'_locale' => $_locale,
'category' => strtolower($applicationObj->getPrimaryCategory()),
'application' => $applicationObj->getId(),
]);
}
......
......@@ -112,6 +112,54 @@ class AppData
return null;
}
public static function fromBinary($applicationBinary): ?AppData
{
$files = scandir('./appdata/');
$filePath = NULL;
foreach ($files as $file) {
if (strpos($file, $applicationBinary)) {
$filePath = './appdata/' . $file;
}
}
if (!$filePath) {
return NULL;
}
// Make sure to resolve symlinks to their actual name. Specifically
// symlinks may be used for backwards compatibility of old names, but
// data resolution should happen on the current name.
set_error_handler(function() { /* ignore errors */ });
$link = readlink($filePath);
restore_error_handler();
if ($link) {
$filePath = $link;
$name = basename($filePath, '.json');
}
if (!file_exists($filePath)) {
return null;
}
$data = json_decode(file_get_contents($filePath), true);
$extensionFile = '../appdata-extensions/' . $name. '.json';
if (file_exists($extensionFile)) {
$data = array_merge_recursive($data, json_decode(file_get_contents($extensionFile), true));
}
if ($data['Type'] === 'desktop-application') {
return new AppData($name, $data, AppDataType::Application);
} else if ($data['Type'] === 'addon') {
return new AppData($name, $data, AppDataType::Addon);
} else if ($data['Type'] === 'console-application') {
return new AppData($name, $data, AppDataType::Console);
}
return null;
}
public function getType()
{
return $this->type;
......
......@@ -44,8 +44,11 @@ class ApplicationsProviderFile
* @param string $category
* @return Category
*/
public function getApplicationsByCategory(string $category): Category
public function getApplicationsByCategory(string $category): ?Category
{
return new Category($category, $this->raw[$category]);
if ($this->raw[$category]) {
return new Category($category, $this->raw[$category]);
}
return null;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment