summaryrefslogtreecommitdiff
path: root/forum/utils
diff options
context:
space:
mode:
Diffstat (limited to 'forum/utils')
-rw-r--r--forum/utils/contacts.php139
1 files changed, 139 insertions, 0 deletions
diff --git a/forum/utils/contacts.php b/forum/utils/contacts.php
new file mode 100644
index 0000000..cec6bd7
--- /dev/null
+++ b/forum/utils/contacts.php
@@ -0,0 +1,139 @@
+<?php
+
+include_once($UTIL_DIR . "/convert.php");
+
+class Contact {
+ public $cid;
+ public $name;
+ public $address;
+ public $phone;
+ public $phone2;
+ public $email;
+ public $url;
+
+ public function write($fp) {
+ fwrite($fp, " <contact cid=\"" . htmlspecialchars($this->cid, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " name=\"" . htmlspecialchars($this->name, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " address=\"" . htmlspecialchars($this->address, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " phone=\"" . htmlspecialchars($this->phone, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " phone2=\"" . htmlspecialchars($this->phone2, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " email=\"" . htmlspecialchars($this->email, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " url=\"" . htmlspecialchars($this->url, ENT_QUOTES, "UTF-8") . "\">\n");
+ fwrite($fp, " </contact>\n");
+ }
+
+ public function show()
+ {
+ echo "<p>\n";
+ echo "\tcid: " . $this->cid . "<br/>";
+ echo "\tname: " . $this->name . "<br/>";
+ echo "\taddress: " . $this->address . "<br/>";
+ echo "\tphone: " . $this->phone . "<br/>";
+ if($this->phone2) echo "\tphone2: " . $this->phone2 . "<br/>";
+ echo "\temail: <a href=\"mailto:" . $this->email . "\">" . $this->email . "</a><br/>";
+ echo "\turl: <a href=\"" . $this->url . "\">" . $this->url . "</a><br/>";
+ echo "</p>\n";
+ }
+
+ public function showshort()
+ {
+ echo "<div class\"contact\"><a href=\"?mode=addressbook&amp;cid=" . $this->cid . "\">" . $this->name . "</a></div>";
+ }
+
+ function Contact($cid,
+ $name,
+ $address,
+ $phone,
+ $phone2,
+ $email,
+ $url)
+ {
+ $this->cid = $cid;
+ $this->name = $name;
+ $this->address = $address;
+ $this->phone = $phone;
+ $this->phone2 = $phone2;
+ $this->email = $email;
+ $this->url = $url;
+ }
+}
+
+class Contacts {
+
+ private $file;
+ private $contacts = array();
+
+ public function show()
+ {
+ echo "<div class=\"contactlist\">\n";
+ foreach($this->contacts as $contact) {
+ $contact->showshort();
+ }
+ echo "</div>\n";
+ }
+
+ public function getNextCID()
+ {
+ $nextcid = 1;
+ foreach($this->contacts as $contact) {
+ if($nextcid < $contact->cid) $nextcid = $contact->cid;
+ }
+ return $nextcid;
+ }
+
+ public function getContact($cid)
+ {
+ return $this->contacts[$cid];
+ }
+
+ public function add($contact) {
+ $key = $contact->cid;
+ $this->contacts[$key] = $contact;
+ }
+
+ public function write()
+ {
+ $fp = fopen($this->file, "w");
+
+ $block = TRUE;
+ flock($fp, LOCK_EX, $block); // do an exclusive lock
+
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<contacts>\n");
+ foreach($this->contacts as $contact) {
+ $contact->write($fp);
+ }
+ fwrite($fp, "</contacts>\n");
+
+ fclose($fp);
+ }
+
+ private function read()
+ {
+
+ $dom = new DomDocument;
+ $dom->preserveWhiteSpace = FALSE;
+ $dom->load($this->file);
+ $params = $dom->getElementsByTagName('contact');
+
+ foreach ($params as $param) {
+ $contact = new Contact($param->getAttribute('cid'),
+ $param->getAttribute('name'),
+ $param->getAttribute('address'),
+ $param->getAttribute('phone'),
+ $param->getAttribute('phone2'),
+ $param->getAttribute('email'),
+ $param->getAttribute('url'));
+ $this->add($contact);
+ }
+ }
+
+ public function Contacts($file)
+ {
+ $this->file = $file;
+ if(file_exists($file)) $this->read();
+ }
+
+}
+?> \ No newline at end of file