Add a compilation link for LaTeX documents
This commit is contained in:
parent
3eea4df363
commit
9d8d0ce4e9
121
htdocs/gen.php
Normal file
121
htdocs/gen.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
require_once("../common.php");
|
||||
|
||||
function generate_latex($filein, $content)
|
||||
{
|
||||
$fileout = $filein.".pdf";
|
||||
$filein = $filein.".tex";
|
||||
|
||||
if (is_file($fileout))
|
||||
return $fileout;
|
||||
|
||||
if (!preg_match("#\\begin{document}#ui", $content))
|
||||
$content = "\documentclass[10pt]{report}
|
||||
|
||||
\usepackage[utf8x]{inputenc}
|
||||
\usepackage[frenchb]{babel}
|
||||
\usepackage{ucs}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amsfonts}
|
||||
\usepackage{amssymb}
|
||||
\usepackage{eurosym}
|
||||
\usepackage{enumerate}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{listings}
|
||||
\usepackage{color}
|
||||
|
||||
\definecolor{dkgreen}{rgb}{0,0.6,0}
|
||||
\definecolor{gray}{rgb}{0.5,0.5,0.5}
|
||||
\definecolor{mauve}{rgb}{0.58,0,0.82}
|
||||
|
||||
\lstset{language=C++,keywordstyle=\color{blue},stringstyle=\color{mauve}}
|
||||
|
||||
\begin{document}".$content."\end{document}";
|
||||
|
||||
file_put_contents($filein, $content);
|
||||
|
||||
print system("pdflatex -halt-on-error -output-directory ../gen ".$filein, $ret);
|
||||
if ($ret == 0)
|
||||
return "../gen/".basename(str_replace(".tex", "", $filein)).".pdf";
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
foreach ($_GET as $k => $t)
|
||||
{
|
||||
if (preg_match("#^([a-zA-Z0-9]{".RGXP_NB."})(:([a-zA-Z0-9]{".RGXP_NB."}))?$#", $k, $kout)
|
||||
&& is_file(Paste::get_path($kout[1])))
|
||||
{
|
||||
$paste = new Paste($kout[1]);
|
||||
|
||||
if (!empty($paste->crypt) && empty($_POST["passwd"]) && empty($t))
|
||||
{
|
||||
?>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>.: Pommultimédia - Paste :.</title>
|
||||
<link href="style.css" rel="stylesheet" type="text/css">
|
||||
<link href="favicon.ico" type="image/x-icon" rel="shortcut icon"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="corps" style="text-align: center;">
|
||||
<h1>
|
||||
<?php echo htmlentities($paste->title); ?>
|
||||
</h1>
|
||||
<h2><?php echo $paste->get_subtitle(); ?></h2>
|
||||
<div>
|
||||
<form method="post" action="?<?php echo $kout[1]; ?>">
|
||||
<fieldset class="paste_form">
|
||||
<label for="title">Mot de passe :</label>
|
||||
<input type="password" size="42" id="passwd" name="passwd">
|
||||
<br><br>
|
||||
<input type="submit" value="Voir le texte">
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!empty($paste->crypt))
|
||||
{
|
||||
if (!empty($_POST["passwd"]))
|
||||
$paste->crypt($_POST["passwd"]);
|
||||
else
|
||||
$paste->crypt($t);
|
||||
}
|
||||
|
||||
$filename = "../gen/".$paste->fileref;
|
||||
|
||||
ob_start();
|
||||
if (strtolower($paste->language) == "latex")
|
||||
$f = generate_latex($filename, $paste->content);
|
||||
else if (strtolower($paste->language) == "html")
|
||||
die ($paste->content);
|
||||
else
|
||||
print "Je ne sais pas compiler ce code source :(";
|
||||
$log = ob_get_clean();
|
||||
ob_end_clean();
|
||||
|
||||
if (isset($f) && is_file($f))
|
||||
{
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header("Content-Disposition: attachment; filename=\"".basename($paste->title).substr($f, count($f)-5, 4)."\"");
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($f));
|
||||
readfile($f);
|
||||
}
|
||||
else
|
||||
die(nl2br($log));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@ -55,6 +55,7 @@ foreach ($_GET as $k => $t)
|
||||
<div class="answer">
|
||||
<a href="/?a=<?php echo $kout[1]; ?>">Répondre</a>
|
||||
<?php echo $paste->get_ref(isset($diff)); ?>
|
||||
<?php echo $paste->get_gen(isset($diff)); ?>
|
||||
</div>
|
||||
<?php
|
||||
if (isset($diff))
|
||||
|
@ -247,6 +247,20 @@ class Paste
|
||||
return "";
|
||||
}
|
||||
|
||||
function get_gen()
|
||||
{
|
||||
if (!empty($_POST["passwd"]))
|
||||
$passwd = "=".$_POST["passwd"];
|
||||
else
|
||||
$passwd = "";
|
||||
$raw = '<a href="/raw.php?'.$this->fileref.$passwd.'">Raw</a> ';
|
||||
|
||||
if ($this->language == "latex")
|
||||
return $raw.'<a href="/gen.php?'.$this->fileref.$passwd.'">Générer le document</a> ';
|
||||
else
|
||||
return $raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parsed code
|
||||
*/
|
||||
@ -300,6 +314,11 @@ class Paste
|
||||
return $ret.'</ul></div>';
|
||||
}
|
||||
}
|
||||
|
||||
function export_to_file($fileto)
|
||||
{
|
||||
file_put_contents($fileto, $this->content);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user