Open Journal Systems  3.3.0
packager_atom_twostep.php
1 <?php
2 
3 require_once('utils.php');
4 
6 
7  // The location of the files (without final directory)
8  private $sac_root_in;
9 
10  // The location to write the package out to
11  private $sac_root_out;
12 
13  // The filename to save the package as
14  private $sac_file_out;
15 
16  // File names
17  private $sac_files;
18 
19  // Number of files added
20  private $sac_filecount;
21 
22  // The dcterms metadata
23  private $sac_entry_dctermsFields;
24  private $sac_entry_dctermsValues;
25  private $sac_entry_dctermsAttributes;
26 
27  // The entry title
28  private $sac_entry_title;
29 
30  // The entry id
31  private $sac_entry_id;
32 
33  // The entry updated date / time stamp
34  private $sac_entry_updated;
35 
36  // The entry author names
37  private $sac_entry_authors;
38 
39  // The entry summary text
40  private $sac_entry_summary;
41 
42  function __construct($sac_rootin, $sac_dirin, $sac_rootout, $sac_fileout) {
43  // Store the values
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;
48 
49  $this->sac_files = array();
50  $this->sac_mimetypes = array();
51  $this->sac_filecount = 0;
52 
53  $this->sac_entry_dctermsFields = array();
54  $this->sac_entry_dctermsValues = array();
55  $this->sac_entry_dctermsAttributes = array();
56 
57  $this->sac_entry_authors = array();
58  }
59 
60  function setTitle($sac_thetitle) {
61  $this->sac_entry_title = $this->clean($sac_thetitle);
62  }
63 
64  function setIdentifier($sac_theID) {
65  $this->sac_entry_id = $this->clean($sac_theID);
66  }
67 
68  function setUpdated($sac_theUpdated) {
69  $this->sac_entry_updated = $this->clean($sac_theUpdated);
70  }
71 
72  function addEntryAuthor($sac_theauthor) {
73  array_push($this->sac_entry_authors, $this->clean($sac_theauthor));
74  }
75 
76  function setSummary($sac_theSummary) {
77  $this->sac_entry_summary = $this->clean($sac_theSummary);
78  }
79 
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);
86  }
87  array_push($this->sac_entry_dctermsAttributes, $sac_cleanAttributes);
88  }
89 
90  function addFile($sac_thefile) {
91  array_push($this->sac_files, $sac_thefile);
92  $this->sac_filecount++;
93  }
94 
95  function getFiles() {
96  return $this->sac_files;
97  }
98 
99  function create() {
100  // Write the atom entry manifest
101  $sac_atom = $this->sac_root_in . '/' . $this->sac_dir_in . '/atom';
102  $fh = @fopen($sac_atom, 'w');
103  if (!$fh) {
104  throw new Exception("Error writing atom entry manifest (" .
105  $this->sac_root_in . '/' . $this->sac_dir_in . '/atom)');
106  }
107 
108  // Write the atom entry header
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");
116  }
117  if (!empty($this->sac_entry_summary)) fwrite($fh, "\t<summary>" . $this->sac_entry_summary . "</summary>\n");
118 
119  // Write the dcterms metadata
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\"";
125  }
126  }
127  $dcElement .= ">" . $this->sac_entry_dctermsValues[$i] . "</dcterms:" . $this->sac_entry_dctermsFields[$i] . ">\n";
128  fwrite($fh, $dcElement);
129  }
130 
131  // Close the file
132  fwrite($fh, "</entry>\n");
133  fclose($fh);
134  }
135 
136  function clean($data) {
137  return str_replace('&#039;', '&apos;', htmlspecialchars($data, ENT_QUOTES));
138  }
139 }
140 ?>
PackagerAtomTwoStep\setIdentifier
setIdentifier($sac_theID)
Definition: packager_atom_twostep.php:64
PackagerAtomTwoStep\create
create()
Definition: packager_atom_twostep.php:99
PackagerAtomTwoStep\addMetadata
addMetadata($sac_theElement, $sac_theValue, $sac_theAttributes=array())
Definition: packager_atom_twostep.php:80
PackagerAtomTwoStep\addEntryAuthor
addEntryAuthor($sac_theauthor)
Definition: packager_atom_twostep.php:72
PackagerAtomTwoStep\setSummary
setSummary($sac_theSummary)
Definition: packager_atom_twostep.php:76
PackagerAtomTwoStep\clean
clean($data)
Definition: packager_atom_twostep.php:136
PackagerAtomTwoStep
Definition: packager_atom_twostep.php:5
PackagerAtomTwoStep\addFile
addFile($sac_thefile)
Definition: packager_atom_twostep.php:90
PackagerAtomTwoStep\getFiles
getFiles()
Definition: packager_atom_twostep.php:95
PackagerAtomTwoStep\setTitle
setTitle($sac_thetitle)
Definition: packager_atom_twostep.php:60
PackagerAtomTwoStep\setUpdated
setUpdated($sac_theUpdated)
Definition: packager_atom_twostep.php:68
PackagerAtomTwoStep\__construct
__construct($sac_rootin, $sac_dirin, $sac_rootout, $sac_fileout)
Definition: packager_atom_twostep.php:42