/** * Save the current paste */ function save($filename = NULL) { $this->hash = base64_encode(sha1($this->content, true)); if (empty($filename)) { $i = 0; do { $filename = substr(str_replace("+", "", str_replace("/", "", $this->hash)), $i++, NB_CHAR); } while (is_file(Paste::get_path($filename)) && Paste::speed_cmp(Paste::get_path($filename), $this->hash)); } $this->filename = $filename; $xml = new DOMDocument('1.0', 'UTF-8'); $xml->formatOutput = true; $xml_paste = $xml->createElement("paste"); $xml_paste->appendChild($xml->createElement("title", $this->title)); $xml_paste->appendChild($xml->createElement("author", $this->author)); $xml_paste->appendChild($xml->createElement("language", $this->language)); $xml_paste->appendChild($xml->createElement("date", $this->date)); $xml_paste->appendChild($xml->createElement("ip", $this->ip)); $cnt = $xml->createElement("content"); $cnt->appendChild($xml->createCDATASection($this->content)); $xml_paste->appendChild($cnt); if (!empty($this->crypt)) { $xml_paste->appendChild($xml->createElement("crypt", base64_encode($this->crypt))); } 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)); if ($this->is_private()) { $xml_paste->appendChild($xml->createElement("private")); } $xml->appendChild($xml_paste); if ($xml->save(Paste::get_path($this->filename))) { return $this->filename; } else { die("Sorry, an error occured while saving the file. Please try again later."); return FALSE; } }