Add a list of answers for each answered message

This commit is contained in:
Némunaire 2012-01-20 20:04:04 +01:00
parent 4649253774
commit aad5915892
4 changed files with 59 additions and 5 deletions

View File

@ -11,6 +11,7 @@
<?php
require_once("../common.php");
$view = 0;
foreach ($_GET as $k => $t)
{
if (preg_match("#^([a-zA-Z0-9]{".RGXP_NB."})(:([a-zA-Z0-9]{".RGXP_NB."}))?$#", $k, $kout)
@ -36,13 +37,14 @@ foreach ($_GET as $k => $t)
echo $paste->get_diff($diff);
else
echo $paste->get_code();
echo $paste->show_answers();
?>
</div>
</div>
</body>
</html>
<?php
$view = true;
$view++;
}
}

View File

@ -1,4 +1,3 @@
<h1>Dernières publications</h1>
<?php
require_once("../common.php");
@ -12,6 +11,7 @@ if ($dh = opendir(DESTINATION))
array_multisort($list, SORT_DESC);
?>
<h1>Dernières publications</h1>
<ul id="list">
<?php
if (empty($_GET["s"]))

View File

@ -34,6 +34,15 @@ p,ul
text-align: left;
}
#res {
font-size: 80%;
text-align: right;
}
#res ul, #res ul li {
display: inline;
padding-right: 10px;
}
label {
color: #e9802c;
font-weight: bold;

View File

@ -14,6 +14,7 @@ class Paste
var $ip;
var $ref = NULL;
var $hash;
var $answers = array();
/**
* Create a new paste or open a existing file
@ -57,6 +58,9 @@ class Paste
else
$this->hash = NULL;
for ($i = 0; $i < $doc->getElementsByTagName("answer")->length; $i++)
$this->answers[] = $doc->getElementsByTagName("answer")->item($i)->textContent;
//Check the lang exists
if (empty($this->language) || !is_file(GESHI_DIR.$this->language.".php"))
$this->language = "text";
@ -90,9 +94,7 @@ class Paste
*/
function save($filename=NULL)
{
$this->date = time();
$this->hash = base64_encode(sha1($this->content, true));
$this->ip = $_SERVER["REMOTE_ADDR"];
if (empty($filename))
{
@ -129,9 +131,25 @@ class Paste
$xml->createElement("content", $this->content));
if (!empty($this->ref))
{
//Also indicate in the parent file
$parent = new Paste($this->ref);
//Does the parent exist?
if ($parent->load())
{
$xml_paste->appendChild(
$xml->createElement("ref", $this->ref));
if ($parent->add_answer($this->filename))
$parent->save();
}
}
foreach ($this->answers as $a)
$xml_paste->appendChild(
$xml->createElement("answer", $a));
$xml_paste->appendChild(
$xml->createElement("hash", $this->hash));
@ -154,6 +172,8 @@ class Paste
$this->title = $dict["title"];
$this->author = $dict["author"];
$this->language = $dict["lang"];
$this->date = time();
$this->ip = $_SERVER["REMOTE_ADDR"];
if (isset($dict["ref"]))
$this->ref = $dict["ref"];
@ -222,6 +242,29 @@ class Paste
str_replace("&lt;/del&gt;", "</del>",
$geshi->parse_code()))));
}
function add_answer($ref)
{
if (!in_array($ref, $this->answers))
{
$this->answers[] = $ref;
return true;
}
else
return false;
}
function show_answers()
{
$nb = count($this->answers);
if ($nb > 0)
{
$ret = '<div id="res">Des réponses à ce paste ont été publiées : <ul>';
foreach($this->answers as $a)
$ret .= '<li><a href="?'.$a.'">'.$a.'</a></li>';
return $ret.'</ul></div>';
}
}
}
?>