function make_entry_xml() { global $row, $xml, $comment_arr, $count; $xml = new XMLFile(); $xml->create_root(); # necessary -- no root is created until requested $xml->roottag->name = 'PIVOTXML'; $xml->roottag->add_subtag('ENTRY', array()); $entrytag =& $xml->roottag->curtag; $entrytag->add_attribute('UID', $row['id']); $entrytag->add_attribute('CODE', $row['code']); $entrytag->add_subtag('TEMPLATE', array()); $entrytag->curtag->cdata = $row['template']; $entrytag->add_subtag('DATE', array()); $entrytag->curtag->cdata = $row['date']; $entrytag->add_subtag('USER', array()); $entrytag->curtag->cdata = $row['user']; $entrytag->add_subtag('TITLE', array()); $entrytag->curtag->cdata = html_entities($row['title']); $entrytag->add_subtag('SUBTITLE', array()); $entrytag->curtag->cdata = html_entities($row['subtitle']); $entrytag->add_subtag('INTRODUCTION', array()); $entrytag->curtag->cdata = html_entities($row['introduction'], 1); $entrytag->add_subtag('BODY', array()); $entrytag->curtag->cdata = html_entities($row['body']); $entrytag->add_subtag('MEDIA', array()); $entrytag->curtag->cdata = $row['media']; $entrytag->add_subtag('LINKS', array()); if (count($row['comments']) > 0) { foreach ($row['comments'] as $comment) { $entrytag->add_subtag('COMMENT', array()); $commtag =& $entrytag->curtag; // When we start using the Thread_code, use this.. //$commtag->add_attribute( 'THREAD_CODE', $comment['thread_code']); $commtag->add_attribute('THREAD_CODE', ""); $commtag->add_subtag('NAME', array()); $commtag->curtag->cdata = html_entities($comment['name']); $commtag->add_subtag('EMAIL', array()); $commtag->curtag->cdata = html_entities($comment['email']); $commtag->add_subtag('URL', array()); $commtag->curtag->cdata = html_entities($comment['url']); $commtag->add_subtag('IP', array()); $commtag->curtag->cdata = $comment['ip']; $commtag->add_subtag('DATE', array()); $commtag->curtag->cdata = $comment['date']; $commtag->add_subtag('COMMENT', array()); $commtag->curtag->cdata = html_entities($comment['comment'], 1); } // foreach } // if $filename = str_replace("blog-", "entry", add_code_padding($row['code']) . ".php"); $fh = fopen("db/" . $filename, 'w'); $xml->write_file_handle($fh); fclose($fh); $xml->cleanup(); debug("writexml - {$filename}"); }
function read_entry($filename, $updateindex = TRUE) { global $global_pref; $xml = new XMLFile(); if ($filename == "") { $filename = $this->entry['filename']; } //debug("read entry: $filename". ( ($updateindex) ? "(T)" : "(F)")); if ($this->entry['filename'] == "ROOT") { debug("root lezen"); $this->entry['template'] = "weblog.html"; return; } @($fh = fopen($filename, 'r')); if ($fh == false) { piv_error("File Does not Exist!", "One of the xml files needed ({$filename}) could not be found. <br /><br />This can normally be fixed by recreating the index-file. Click <a href='reindex.php'>reindex</a> to do so now, and then go <a href='javascript:history.go(-1)'>back</a> to the last page.", 0); } $xml->read_file_handle($fh); fclose($fh); $row_entrypoint =& $xml->roottag->tags[0]; $row =& $xml->roottag->tags[0]->make_array(); $this->entry['code'] = rem_code_padding($row_entrypoint->attributes['CODE']); $this->entry['id'] = $this->set_id(); @($this->entry['category'] = trim($row_entrypoint->attributes['CATEGORY'])); debug("leescat2: " . $this->entry['category']); $this->entry['template'] = $row['template']; $this->entry['date'] = $row['date']; $this->entry['user'] = $row['user']; $this->entry['title'] = rem_entities($row['title']); $this->entry['subtitle'] = rem_entities($row['subtitle']); $this->entry['introduction'] = rem_entities($row['introduction']); $this->entry['body'] = rem_entities($row['body']); $this->entry['media'] = $row['media']; $this->entry['links'] = $row['links']; $this->entry['url'] = $this['url']; $this->entry['filename'] = $filename; unset($commnames); if (isset($row['comment'])) { for ($i = 0; $i < count($row['comment']); $i++) { $row['comment'][$i]['name'] = substr(rem_entities($row['comment'][$i]['name']), 0, 30); $row['comment'][$i]['email'] = rem_entities($row['comment'][$i]['email']); $row['comment'][$i]['comment'] = rem_entities($row['comment'][$i]['comment']); $commnames[] = $row['comment'][$i]['name']; } $this->entry['comments'] = $row['comment']; $this->entry['commnames'] = implode(", ", array_unique($commnames)); $commcount = count($commnames); } else { unset($this->entry['comments']); $commcount = 0; } $this->entry['commcount'] = $commcount; if ($commcount == 0) { $commcount_str = $global_pref['commentsarr'][0]; $this->entry['commcount_str'] = str_replace("%num%", $global_pref['comments_numbersarr'][0], $commcount_str); } else { if ($commcount == 1) { $commcount_str = $global_pref['commentsarr'][1]; $this->entry['commcount_str'] = str_replace("%num%", $global_pref['comments_numbersarr'][1], $commcount_str); } else { if (isset($global_pref['comments_numbersarr'][$commcount])) { $num = $global_pref['comments_numbersarr'][$commcount]; } else { $num = $commcount; } $commcount_str = $global_pref['commentsarr'][2]; $this->entry['commcount_str'] = str_replace("%num%", $num, $commcount_str); } } if ($this->entry['media'] != "") { $media_lines = explode("#", $this->entry['media']); $i = 0; unset($this->entry['media']); foreach ($media_lines as $media_line) { @(list($file, $width, $height, $name) = explode("|", $media_line)); $i++; $this->entry['media'][] = array("file" => $file, "width" => $width, "height" => $height, "name" => $name); } } if ($this->entry['category'] == "") { $this->entry['category'] = "standard"; } $xml->cleanup(); $this->update_index(FALSE); // Sometimes the code is another number than the filename would suggest. If so, // this needs to be fixed, by renaming the file. if ($filename != $this->set_filename($this->entry['code'])) { debug("rename: " . $filename . " , ", $this->set_filename($this->entry['code'])); rename($filename, $this->set_filename($this->entry['code'])); } return TRUE; }