Add a list of last paste sent

This commit is contained in:
Némunaire 2012-01-20 18:41:56 +01:00
parent 75f83329af
commit 4649253774
4 changed files with 98 additions and 11 deletions

View File

@ -16,17 +16,10 @@ 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])))
{
require_once("../geshi/geshi.php");
$paste = new Paste($kout[1]);
$geshi = new GeSHi($paste->content, $paste->language);
if (!empty($kout[3]) && is_file(Paste::get_path($kout[3])))
$diff = new Paste($kout[3]);
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
?>
<div id="corps" style="text-align: center;">
<h1>
@ -42,7 +35,7 @@ foreach ($_GET as $k => $t)
if (isset($diff))
echo $paste->get_diff($diff);
else
echo $geshi->parse_code();
echo $paste->get_code();
?>
</div>
</div>
@ -120,6 +113,9 @@ else
<input type="submit" value="Envoyer">
</fieldset>
</form>
<?php
include("list.php");
?>
</div>
</body>
</html>

57
htdocs/list.php Normal file
View File

@ -0,0 +1,57 @@
<h1>Dernières publications</h1>
<?php
require_once("../common.php");
if ($dh = opendir(DESTINATION))
{
$list = array();
while (($file = readdir($dh)) !== false)
$list[] = array(filemtime(DESTINATION.$file), $file);
closedir($dh);
array_multisort($list, SORT_DESC);
?>
<ul id="list">
<?php
if (empty($_GET["s"]))
$_GET["s"] = 0;
$s = intval($_GET["s"]);
$i = 0;
foreach($list as $f)
{
if ($s > 0)
{
$s--;
continue;
}
if ($i++ > 10)
{
print '<li><a href="./?s='.(intval($_GET["s"])+10).'#list">Plus anciens ...</a></li>';
break;
}
if (preg_match("#^([a-zA-Z0-9]{".RGXP_NB."}).xml$#", $f[1], $fout))
{
$paste = new Paste($fout[1]);
if (empty($paste->title))
$title = "Sans titre";
else
$title = htmlentities($paste->title);
if (empty($paste->author))
$author = "<em>un anonyme</em>";
else
$author = htmlentities($paste->author);
print '<li><a href="./?'.$paste->fileref.'">'.$title."</a> par ".$author.", le ".date("d/m/Y H:i:s", $paste->date)."</li>";
}
}
?>
</ul>
<?php
}
?>

View File

@ -31,7 +31,7 @@ header h2
p,ul
{
margin: auto;
width: 400px;
text-align: left;
}
label {
@ -68,6 +68,7 @@ input.erreur:hover, select.erreur:hover {
h1 {
color: #75903b;
text-align: center;
}
h2 {
color: #7f9a48;
@ -83,7 +84,7 @@ form {
text-align: center;
}
fieldset, div#content {
fieldset, div#content, ul#list {
background: #e3e3e3;
border: none;
border-radius: 10px;
@ -93,6 +94,11 @@ fieldset, div#content {
width: 750px;
}
ul#list
{
padding: 10px 10px 10px 20px;
}
div#content {
padding: 5px;
text-align: left;

View File

@ -52,7 +52,10 @@ class Paste
else
$this->ref = NULL;
$this->ip = $doc->getElementsByTagName("ip")->item(0)->textContent;
$this->hash = $doc->getElementsByTagName("hash")->item(0)->textContent;
if ($doc->getElementsByTagName("hash")->length > 0)
$this->hash = $doc->getElementsByTagName("hash")->item(0)->textContent;
else
$this->hash = NULL;
//Check the lang exists
if (empty($this->language) || !is_file(GESHI_DIR.$this->language.".php"))
@ -143,6 +146,9 @@ class Paste
}
}
/**
* Set attributes from an dictionnary like _POST
*/
function create($dict)
{
$this->title = $dict["title"];
@ -155,6 +161,9 @@ class Paste
$this->content = $dict["content"];
}
/**
* Generate a subtitle
*/
function get_subtitle()
{
if (empty($this->author))
@ -166,6 +175,9 @@ class Paste
$this->date);
}
/**
* Get the ref HTML part of the paste
*/
function get_ref($is_diff)
{
if (!empty($this->ref))
@ -180,6 +192,22 @@ class Paste
return "";
}
/**
* Get the parsed code
*/
function get_code()
{
require_once("geshi/geshi.php");
$geshi = new GeSHi($this->content, $this->language);
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
return $geshi->parse_code();
}
/**
* Get the parsed code with diff
*/
function get_diff($diff)
{
require_once("geshi/geshi.php");