3 require_once(
'utils.php');
14 private $sac_root_out;
17 private $sac_file_out;
23 private $sac_filecount;
26 private $sac_entry_dctermsFields;
27 private $sac_entry_dctermsValues;
28 private $sac_entry_dctermsAttributes;
31 private $sac_entry_title;
34 private $sac_entry_id;
37 private $sac_entry_updated;
40 private $sac_entry_authors;
43 private $sac_entry_summary;
46 function __construct($sac_rootin, $sac_dirin, $sac_rootout, $sac_fileout) {
48 $this->sac_root_in = $sac_rootin;
49 $this->sac_dir_in = $sac_dirin;
50 $this->sac_root_out = $sac_rootout;
51 $this->sac_file_out = $sac_fileout;
53 $this->sac_files = array();
54 $this->sac_mimetypes = array();
55 $this->sac_filecount = 0;
57 $this->sac_entry_dctermsFields = array();
58 $this->sac_entry_dctermsValues = array();
59 $this->sac_entry_dctermsAttributes = array();
61 $this->sac_entry_authors = array();
65 $this->sac_entry_title = $this->
clean($sac_thetitle);
69 $this->sac_entry_id = $this->
clean($sac_theID);
73 $this->sac_entry_updated = $this->
clean($sac_theUpdated);
77 array_push($this->sac_entry_authors, $this->
clean($sac_theauthor));
81 $this->sac_entry_summary = $this->
clean($sac_theSummary);
84 function addMetadata($sac_theElement, $sac_theValue, $sac_theAttributes = array()) {
85 array_push($this->sac_entry_dctermsFields, $this->
clean($sac_theElement));
86 array_push($this->sac_entry_dctermsValues, $this->
clean($sac_theValue));
87 $sac_cleanAttributes = array();
88 foreach ($sac_theAttributes as $attrName => $attrValue) {
89 $sac_cleanAttributes[$this->
clean($attrName)] = $this->
clean($attrValue);
91 array_push($this->sac_entry_dctermsAttributes, $sac_cleanAttributes);
95 array_push($this->sac_files, $sac_thefile);
96 $this->sac_filecount++;
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");
136 $temp = $this->sac_root_out .
'/' . $this->sac_file_out;
137 $atom = file_get_contents($sac_atom);
138 $xml =
"\r\nMedia Post\r\n";
139 $xml .=
"--===============SWORDPARTS==\r\n";
140 $xml .=
"Content-Type: application/atom+xml\r\n";
141 $xml .=
"MIME-Version: 1.0\r\n";
142 $xml .=
"Content-Disposition: attachment; name=\"atom\"\r\n";
146 file_put_contents($temp, $xml);
149 for ($i = 0; $i < $this->sac_filecount; $i++) {
151 $sac_filename = $this->sac_files[$i];
152 $sac_fullfilename = $this->sac_root_in .
'/' . $this->sac_dir_in .
'/' . $sac_filename;
154 $xml .=
"--===============SWORDPARTS==\r\n";
155 $xml .=
"Content-Type: " . mime_content_type($sac_fullfilename) .
"\r\n";
156 $xml .=
"Content-MD5: " . md5_file($sac_fullfilename) .
"\r\n";
157 $xml .=
"MIME-Version: 1.0\r\n";
158 $xml .=
"Content-Disposition: attachment; name=\"payload\"; filename=\"" . $sac_filename .
"\"\r\n";
159 $xml .=
"Packaging: http://purl.org/net/sword/package/Binary\r\n";
160 $xml .=
"Content-Transfer-Encoding: base64\r\n\r\n";
161 file_put_contents($temp, $xml, FILE_APPEND);
162 base64chunk($sac_fullfilename, $temp);
165 $xml =
"--===============SWORDPARTS==--\r\n";
166 file_put_contents($temp, $xml, FILE_APPEND);
170 return str_replace(
''',
''', htmlspecialchars($data, ENT_QUOTES));