summaryrefslogtreecommitdiff
path: root/utils/links.php
blob: d9ed1d9118ac04ff00de368a1d32dacdbd2acd8b (plain)
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
127
128
<?php

class Link {
	public $title;
	public $href;
	public $icon;

	public function Link($title, $href, $icon) {
		$this->title = $title;
		$this->href = $href;
		$this->icon = $icon;
	}

	public function show()
	{
		echo "<div class=\"link\">\n";
		if($this->icon != "") {
			echo "  <a class=\"link_icon\" rel=\"external\" href=\"" . $this->href . "\">\n";
			echo "    <img alt=\"" . $this->title . "\" src=\"" . $this->icon . "\"/>\n";
			echo "   </a>\n";
		}
		echo "  <a class=\"link_title\" rel=\"external\" href=\"" . $this->href . "\">\n";
		echo "    " . htmlspecialchars_decode($this->title, ENT_QUOTES) . "\n";
		echo "  </a>\n";
		echo "</div>\n";
	}
}

class LinkGroup {
	public $title;
	public $id;
	private $links = array();

	public function LinkGroup($title, $id) {
		$this->title = $title;
		$this->id = $id;
	}

	public function add($link) {
		$key = $link->title;
		$this->links[$key] = $link;
	}

	public function show()
	{
		echo "<div class=\"linkgroup\">\n";
		echo "  <div class=\"linkgroup_title\">". htmlspecialchars_decode($this->title, ENT_QUOTES) . "</div>\n";
		foreach($this->links as $link) {
			$link->show();
		}
		echo "</div>\n";
	}
}

class Links {
	private $file;
	private $groups = array();

	public function add($group) {
		$key = $group->title;
		$this->groups[$key] = $group;
	}
	/*
	public function write()
	{
		$fp = fopen($this->file, "w");
		fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");

		fwrite($fp, "<links>\n");
		foreach($this->links as $link) {
			fwrite($fp, "  <link title=\"" .
						 htmlspecialchars($link->title, ENT_QUOTES, "UTF-8") . "\"\n");
			fwrite($fp, "        href=\"" .
						 htmlspecialchars($link->href, ENT_QUOTES, "UTF-8") . "\">\n");
			fwrite($fp, "        icon=\"" .
						 htmlspecialchars($link->icon, ENT_QUOTES, "UTF-8") . "\">\n");
			fwrite($fp, "  </link>\n");
		}
		fwrite($fp, "</links>\n");

		fclose($fp);
	}
	*/
	public function show($groupid)
	{
		foreach($this->groups as $group) {
			if($groupid == $group->id || $groupid == "all") $group->show();
		}
	}

	private function read()
	{

		$dom = new DomDocument;
		$dom->preserveWhiteSpace = FALSE;
		$dom->load($this->file);

		$xmlgroups = $dom->getElementsByTagName('group');

		foreach ($xmlgroups as $xmlgroup) {

			$group = new LinkGroup($xmlgroup->getAttribute('name'),
														 $xmlgroup->getAttribute('id'));
			$xmllinks = $xmlgroup->getElementsByTagName('link');

			foreach ($xmllinks as $xmllink) {
				$link = new Link($xmllink->getAttribute('title'),
												 $xmllink->getAttribute('href'),
												 $xmllink->getAttribute('icon'));

				$group->add($link);
			}
		
			$this->add($group);
		}
		
		// Key sort
		//		ksort($this->events);
	}

	public function Links($file)
	{
		$this->file = $file;
		if(file_exists($file)) $this->read();
	}
}

?>