3 require_once(
'utils.php');
11 private $sac_root_out;
14 private $sac_file_out;
20 private $sac_filecount;
23 private $sac_entry_dctermsFields;
24 private $sac_entry_dctermsValues;
25 private $sac_entry_dctermsAttributes;
28 private $sac_entry_title;
31 private $sac_entry_id;
34 private $sac_entry_updated;
37 private $sac_entry_authors;
40 private $sac_entry_summary;
42 function __construct($sac_rootin, $sac_dirin, $sac_rootout, $sac_fileout) {
44 $this->sac_root_in = $sac_rootin;
45 $this->sac_dir_in = $sac_dirin;
46 $this->sac_root_out = $sac_rootout;
47 $this->sac_file_out = $sac_fileout;
49 $this->sac_files = array();
50 $this->sac_mimetypes = array();
51 $this->sac_filecount = 0;
53 $this->sac_entry_dctermsFields = array();
54 $this->sac_entry_dctermsValues = array();
55 $this->sac_entry_dctermsAttributes = array();
57 $this->sac_entry_authors = array();
61 $this->sac_entry_title = $this->
clean($sac_thetitle);
65 $this->sac_entry_id = $this->
clean($sac_theID);
69 $this->sac_entry_updated = $this->
clean($sac_theUpdated);
73 array_push($this->sac_entry_authors, $this->
clean($sac_theauthor));
77 $this->sac_entry_summary = $this->
clean($sac_theSummary);
80 function addMetadata($sac_theElement, $sac_theValue, $sac_theAttributes = array()) {
81 array_push($this->sac_entry_dctermsFields, $this->
clean($sac_theElement));
82 array_push($this->sac_entry_dctermsValues, $this->
clean($sac_theValue));
83 $sac_cleanAttributes = array();
84 foreach ($sac_theAttributes as $attrName => $attrValue) {
85 $sac_cleanAttributes[$this->
clean($attrName)] = $this->
clean($attrValue);
87 array_push($this->sac_entry_dctermsAttributes, $sac_cleanAttributes);
91 array_push($this->sac_files, $sac_thefile);
92 $this->sac_filecount++;
96 return $this->sac_files;
101 $sac_atom = $this->sac_root_in .
'/' . $this->sac_dir_in .
'/atom';
102 $fh = @fopen($sac_atom,
'w');
104 throw new Exception(
"Error writing atom entry manifest (" .
105 $this->sac_root_in .
'/' . $this->sac_dir_in .
'/atom)');
109 fwrite($fh,
"<?xml version=\"1.0\"?>\n");
110 fwrite($fh,
"<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:dcterms=\"http://purl.org/dc/terms/\">\n");
111 if (!empty($this->sac_entry_title)) fwrite($fh,
"\t<title>" . $this->sac_entry_title .
"</title>\n");
112 if (!empty($this->sac_entry_id)) fwrite($fh,
"\t<id>" . $this->sac_entry_id .
"</id>\n");
113 if (!empty($this->sac_entry_updated)) fwrite($fh,
"\t<updated>" . $this->sac_entry_updated .
"</updated>\n");
114 foreach ($this->sac_entry_authors as $sac_author) {
115 fwrite($fh,
"\t<author><name>" . $sac_author .
"</name></author>\n");
117 if (!empty($this->sac_entry_summary)) fwrite($fh,
"\t<summary>" . $this->sac_entry_summary .
"</summary>\n");
120 for ($i = 0; $i < count($this->sac_entry_dctermsFields); $i++) {
121 $dcElement =
"\t<dcterms:" . $this->sac_entry_dctermsFields[$i];
122 if (!empty($this->sac_entry_dctermsAttributes[$i])) {
123 foreach ($this->sac_entry_dctermsAttributes[$i] as $attrName => $attrValue) {
124 $dcElement .=
" $attrName=\"$attrValue\"";
127 $dcElement .=
">" . $this->sac_entry_dctermsValues[$i] .
"</dcterms:" . $this->sac_entry_dctermsFields[$i] .
">\n";
128 fwrite($fh, $dcElement);
132 fwrite($fh,
"</entry>\n");
137 return str_replace(
''',
''', htmlspecialchars($data, ENT_QUOTES));