gl-website-deployer/publications.php
2024-11-19 08:02:04 +01:00

99 lines
2.5 KiB
PHP

<?php
require dirname(__FILE__).'/common.php';
$m = setup_mustache();
$query_builder = $db_conn->createQueryBuilder();
$sort_citation = 0;
$sort_year = $_GET['sort_year'] ?? -1;
if (isset($_GET['sort'])) {
$sort_citation = intval($_GET['sort']);
$sort_year = 0;
if ($sort_citation == null) {
$sort_citation = 0;
}
}
$output = 'publications_html';
$ctype = 'text/html';
$filename = null;
$decode = false;
if (isset($_GET['latex'])) {
$output = 'publications_latex';
$ctype = 'application/x-latex';
$filename = 'Content-Disposition: attachment; filename="publications.tex"';
$decode = true;
}
header("Content-Type: {$ctype}");
if ($filename != null) {
header($filename);
}
$tpl = $m->loadTemplate($output);
$query = $query_builder
->select('id,title,authors,journal,page,volume,year,arxiv,citation_count,doi')
->from('publications')
->where('owned=true');
if ($sort_citation > 0) {
$query = $query->orderBy('citation_count', 'ASC');
}
if ($sort_citation < 0) {
$query = $query->orderBy('citation_count', 'DESC');
}
if ($sort_year > 0) {
$query = $query->orderBy('year', 'ASC');
} else if ($sort_year < 0) {
$query = $query->orderBy('year', 'DESC');
}
$stmt = $query->executeQuery();
$data = array();
$count = 0;
$all_data = $stmt->fetchAllAssociative();
foreach ($all_data as $row) {
$title = $row['title'];
if ($decode) {
$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
}
$authors_merged = implode(';', json_decode($row['authors']));
$data[$count] = ["ads"=>$row['id'], "title"=>$title, "authors"=>json_decode($row['authors']),
"authors_merged"=>$authors_merged,
"arxiv" => $row['arxiv'],
"citation_count" => $row['citation_count'],
"year" => $row['year'],
"doi" => $row['doi'],
"journal" => $row['journal'],
"page" => $row['page'],
"volume" => $row['volume']
];
$count+=1;
}
echo $tpl->render(
array(
'ROOT_URL' => $iap_root,
'sort_year'=>$sort_year == 0 ? 1 : ($sort_year < 0 ? 1 : -1),
'sort_citation'=>$sort_citation == 0 ? 1 : ($sort_citation < 0 ? 1 : -1),
'title'=>'Guilhem Lavaux\'s publications',
'publi'=>$data,
'configure_script'=>[
'MathJax = {
tex: {
inlineMath: [[\'$\', \'$\'], [\'\\\\(\', \'\\\\)\']]
}
};
'
],
'external_scripts'=>[
'src="https://polyfill.io/v3/polyfill.min.js?features=es6"',
'id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"'
],
'bar' => 'baz'));