SharedObjectHeaderFile.php
2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* @class SharedObjectHeaderFile
* @version
*
*/
class SharedObjectHeaderFile {
private $doc = null;
private $filePath = "";
function __construct($filePath) {
if (!file_exists($filePath))
$this->createFile($filePath);
$this->loadFile($filePath);
$this->filePath = $filePath;
}
public function getInfo() {
return array(
"name" => $this->getName(),
"description" => $this->getDescription(),
"sharedBy" => $this->getSharedBy(),
"sharedDate" => $this->getSharedDate()
);
}
public function getName() {
return $this->getOneInfo("name");
}
public function setName($name) {
$this->setOneInfo("name", $name);
}
public function getDescription() {
return $this->getOneInfo("description");
}
public function setDescription($description) {
$this->setOneInfo("description", $description);
}
public function getSharedBy() {
return $this->getOneInfo("sharedBy");
}
public function setSharedBy($sharedBy) {
$this->setOneInfo("sharedBy", $sharedBy);
}
public function getSharedDate() {
return $this->getOneInfo("sharedDate");
}
public function setSharedDate($sharedDate) {
$this->setOneInfo("sharedDate", $sharedDate);
}
private function createFile($filePath) {
$this->doc = new DOMDocument("1.0", "UTF-8");
$this->doc->preserveWhiteSpace = false;
$this->doc->formatOutput = true;
$rootNode = $this->doc->createElement("shared-header");
$this->doc->appendChild($rootNode);
$nameNode = $this->doc->createElement("name");
$rootNode->appendChild($nameNode);
$descriptionNode = $this->doc->createElement("description");
$rootNode->appendChild($descriptionNode);
$sharedByNode = $this->doc->createElement("sharedBy");
$rootNode->appendChild($sharedByNode);
$sharedDateNode = $this->doc->createElement("sharedDate");
$rootNode->appendChild($sharedDateNode);
$this->doc->save($filePath);
chgrp($filePath, APACHE_USER);
chmod($filePath, 0775);
}
private function loadFile($filePath) {
$this->doc = new DOMDocument("1.0", "UTF-8");
$this->doc->preserveWhiteSpace = false;
$this->doc->formatOutput = true;
$this->doc->load($filePath);
}
private function getOneInfo($infoName) {
if (!isset($this->doc))
return "";
$rootNode = $this->doc->documentElement;
if (!isset($rootNode))
return "";
$infoNodes = $rootNode->getElementsByTagName($infoName);
if (count($infoNodes) == 0)
return "";
return $infoNodes->item(0)->nodeValue;
}
private function setOneInfo($infoName, $infoValue) {
if (!isset($this->doc))
return;
$rootNode = $this->doc->documentElement;
if (!isset($rootNode))
return "";
$infoNodes = $rootNode->getElementsByTagName($infoName);
if (count($infoNodes) == 0)
return "";
$infoNodes->item(0)->textContent = $infoValue;
$this->doc->save($this->filePath);
}
}
?>