177 lines
6.7 KiB
PHP
177 lines
6.7 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../_v4/includes.php';
|
|
|
|
define('FWH_STYLE', FWH_2020);
|
|
|
|
$randomFeatured = isset($_GET['rf']);
|
|
|
|
$getProjects = $pdo->prepare('
|
|
SELECT `project_id`, `project_name`, COALESCE(`project_name_clean`, REPLACE(LOWER(`project_name`), \' \', \'-\')) AS `project_name_clean`, `project_summary`, `project_description`, `project_featured`, `project_order`, `project_homepage`, `project_repository`, `project_forum`, UNIX_TIMESTAMP(`project_archived`) AS `project_archived`, `project_type`, UNIX_TIMESTAMP(`project_created`) AS `project_created`, `project_colour`
|
|
FROM `fm_projects`
|
|
WHERE `project_deleted` IS NULL
|
|
'. ($randomFeatured ? ' AND `project_featured` <> 0 ORDER BY RAND()' : 'ORDER BY `project_order` DESC')
|
|
);
|
|
$getProjects->execute();
|
|
$projects = $getProjects->fetchAll(PDO::FETCH_OBJ);
|
|
|
|
$activeProjects = [];
|
|
$toolProjects = [];
|
|
$archivedProjects = [];
|
|
|
|
foreach($projects as $project) {
|
|
if(!empty($project->project_archived))
|
|
$archivedProjects[] = $project;
|
|
elseif($project->project_type === 'Tool')
|
|
$toolProjects[] = $project;
|
|
else
|
|
$activeProjects[] = $project;
|
|
}
|
|
|
|
$getLanguages = $pdo->prepare('
|
|
SELECT pl.`language_id`, pl.`language_name`, pl.`language_colour`
|
|
FROM `fm_proglangs` AS pl
|
|
LEFT JOIN `fm_projects_proglangs` AS ppl
|
|
ON ppl.`language_id` = pl.`language_id`
|
|
WHERE ppl.`project_id` = :project_id
|
|
ORDER BY ppl.`priority`
|
|
');
|
|
|
|
function fm_project_box(stdClass $project, array $languages): string {
|
|
$colour = html_colour(isset($languages[0]->language_colour) ? $languages[0]->language_colour : 0x212121);
|
|
|
|
$html = <<<HTML
|
|
<div class="project" style="box-shadow: 0 1px 2px {$colour}; background-color: {$colour};">
|
|
<div class="project-name">
|
|
<h2>{$project->project_name}</h2>
|
|
</div>
|
|
<div class="project-inner">
|
|
<p>{$project->project_summary}</p>
|
|
<div class="project-languages">\r\n
|
|
HTML;
|
|
|
|
$indent = ' ';
|
|
|
|
foreach($languages as $lang) {
|
|
$colour = html_colour($lang->language_colour);
|
|
$html .= "{$indent} <div class=\"project-language\" style=\"box-shadow: 0 1px 2px {$colour}; background-color: {$colour};\"><div>{$lang->language_name}</div></div>\r\n";
|
|
}
|
|
|
|
$html .= "{$indent}</div>\r\n";
|
|
|
|
$links = '';
|
|
|
|
if(!empty($project->project_homepage))
|
|
$links .= " <a href=\"{$project->project_homepage}\"><img src=\"". html_baseurl() ."/assets/icons/s-home.png\" alt=\"\" width=\"17\" height=\"17\" /> Homepage</a>\r\n";
|
|
if(!empty($project->project_repository))
|
|
$links .= " <a href=\"{$project->project_repository}\"><img src=\"". html_baseurl() ."/assets/icons/s-code.png\" alt=\"\" width=\"17\" height=\"17\" /> Source</a>\r\n";
|
|
if(!empty($project->project_forum))
|
|
$links .= " <a href=\"{$project->project_forum}\"><img src=\"". html_baseurl() ."/assets/icons/s-forum.png\" alt=\"\" width=\"17\" height=\"17\" /> Discussion</a>\r\n";
|
|
|
|
if(!empty($links)) {
|
|
$html .= "{$indent}<div class=\"project-links\">\r\n";
|
|
$html .= "{$indent}{$links}";
|
|
$html .= "{$indent}</div>\r\n";
|
|
}
|
|
|
|
$html .= <<<HTML
|
|
</div>
|
|
</div>\r\n
|
|
HTML;
|
|
|
|
return $html;
|
|
}
|
|
|
|
if(isset($_GET['dump_that_shit'])) {
|
|
$doConvert = !isset($_GET['noconvert']);
|
|
$meow = [];
|
|
$projects = array_merge($activeProjects, $toolProjects, $archivedProjects);
|
|
|
|
foreach($projects as $project) {
|
|
if($doConvert) {
|
|
$projKeys = array_keys((array)$project);
|
|
foreach($projKeys as $key) {
|
|
$project->{substr($key, 8)} = $project->{$key};
|
|
unset($project->{$key});
|
|
}
|
|
}
|
|
|
|
$getLanguages->bindValue('project_id', $project->id ?? $project->project_id);
|
|
$getLanguages->execute();
|
|
$project->languages = $getLanguages->fetchAll(PDO::FETCH_OBJ);
|
|
if($doConvert) {
|
|
$langKeys = array_keys((array)$project->languages[0]);
|
|
for($i = 0; $i < count($project->languages); ++$i)
|
|
foreach($langKeys as $key) {
|
|
if(!isset($project->colour))
|
|
$project->colour = $project->languages[$i]->language_colour;
|
|
$project->languages[$i]->{substr($key, 9)} = $project->languages[$i]->{$key};
|
|
unset($project->languages[$i]->{$key});
|
|
}
|
|
}
|
|
|
|
if($randomFeatured || !$doConvert)
|
|
$meow[] = $project;
|
|
else {
|
|
$key = $project->archived ? 'archive' : strtolower($project->type);
|
|
$meow[$key][] = $project;
|
|
}
|
|
}
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
echo json_encode($meow);
|
|
return;
|
|
}
|
|
|
|
echo html_doctype();
|
|
?>
|
|
<html lang="en">
|
|
<head>
|
|
<?=html_charset();?>
|
|
<title>Projects</title>
|
|
<?=html_stylesheet('2020.css');?>
|
|
<?=html_meta();?>
|
|
</head>
|
|
<body>
|
|
<div class="wrapper">
|
|
<?=html_sidebar();?>
|
|
<div class="projects">
|
|
<h1 id="projects">Active Projects</h1>
|
|
<div class="projects-list active">
|
|
<?php
|
|
foreach ($activeProjects as $project) {
|
|
$getLanguages->bindValue('project_id', $project->project_id);
|
|
$getLanguages->execute();
|
|
$languages = $getLanguages->fetchAll(PDO::FETCH_OBJ);
|
|
echo fm_project_box($project, $languages);
|
|
}
|
|
?>
|
|
</div>
|
|
<h1 id="tools">Tools</h1>
|
|
<div class="projects-list tools">
|
|
<?php
|
|
foreach ($toolProjects as $project) {
|
|
$getLanguages->bindValue('project_id', $project->project_id);
|
|
$getLanguages->execute();
|
|
$languages = $getLanguages->fetchAll(PDO::FETCH_OBJ);
|
|
echo fm_project_box($project, $languages);
|
|
}
|
|
?>
|
|
</div>
|
|
<h1 id="archived">Archived Projects</h1>
|
|
<div class="projects-list archived">
|
|
<?php
|
|
foreach ($archivedProjects as $project) {
|
|
$getLanguages->bindValue('project_id', $project->project_id);
|
|
$getLanguages->execute();
|
|
$languages = $getLanguages->fetchAll(PDO::FETCH_OBJ);
|
|
echo fm_project_box($project, $languages);
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php if(html_old_ie()) { ?>
|
|
<?=html_script('/assets/fixpng.js');?>
|
|
<?php } ?>
|
|
</body>
|
|
</html>
|