]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | /** | |
3 | * Populates a reference datastore to test LinkDB | |
4 | */ | |
5 | class ReferenceLinkDB | |
6 | { | |
7 | private $_links = array(); | |
8 | private $_publicCount = 0; | |
9 | private $_privateCount = 0; | |
10 | ||
11 | /** | |
12 | * Populates the test DB with reference data | |
13 | */ | |
14 | function __construct() | |
15 | { | |
16 | $this->addLink( | |
17 | 'Free as in Freedom 2.0 @website', | |
18 | 'https://static.fsf.org/nosvn/faif-2.0.pdf', | |
19 | 'Richard Stallman and the Free Software Revolution. Read this.', | |
20 | 0, | |
21 | '20150310_114633', | |
22 | 'free gnu software stallman -exclude stuff' | |
23 | ); | |
24 | ||
25 | $this->addLink( | |
26 | 'Link title: @website', | |
27 | 'local', | |
28 | 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this.', | |
29 | 0, | |
30 | '20150310_114651', | |
31 | 'stuff' | |
32 | ); | |
33 | ||
34 | $this->addLink( | |
35 | 'MediaGoblin', | |
36 | 'http://mediagoblin.org/', | |
37 | 'A free software media publishing platform', | |
38 | 0, | |
39 | '20130614_184135', | |
40 | 'gnu media web .hidden' | |
41 | ); | |
42 | ||
43 | $this->addLink( | |
44 | 'w3c-markup-validator', | |
45 | 'https://dvcs.w3.org/hg/markup-validator/summary', | |
46 | 'Mercurial repository for the W3C Validator', | |
47 | 1, | |
48 | '20141125_084734', | |
49 | 'css html w3c web Mercurial' | |
50 | ); | |
51 | ||
52 | $this->addLink( | |
53 | 'UserFriendly - Web Designer', | |
54 | 'http://ars.userfriendly.org/cartoons/?id=20121206', | |
55 | 'Naming conventions...', | |
56 | 0, | |
57 | '20121206_142300', | |
58 | 'dev cartoon web' | |
59 | ); | |
60 | ||
61 | $this->addLink( | |
62 | 'UserFriendly - Samba', | |
63 | 'http://ars.userfriendly.org/cartoons/?id=20010306', | |
64 | 'Tropical printing', | |
65 | 0, | |
66 | '20121206_172539', | |
67 | 'samba cartoon web' | |
68 | ); | |
69 | ||
70 | $this->addLink( | |
71 | 'Geek and Poke', | |
72 | 'http://geek-and-poke.com/', | |
73 | '', | |
74 | 1, | |
75 | '20121206_182539', | |
76 | 'dev cartoon' | |
77 | ); | |
78 | } | |
79 | ||
80 | /** | |
81 | * Adds a new link | |
82 | */ | |
83 | protected function addLink($title, $url, $description, $private, $date, $tags) | |
84 | { | |
85 | $link = array( | |
86 | 'title' => $title, | |
87 | 'url' => $url, | |
88 | 'description' => $description, | |
89 | 'private' => $private, | |
90 | 'linkdate' => $date, | |
91 | 'tags' => $tags, | |
92 | ); | |
93 | $this->_links[$date] = $link; | |
94 | ||
95 | if ($private) { | |
96 | $this->_privateCount++; | |
97 | return; | |
98 | } | |
99 | $this->_publicCount++; | |
100 | } | |
101 | ||
102 | /** | |
103 | * Writes data to the datastore | |
104 | */ | |
105 | public function write($filename) | |
106 | { | |
107 | file_put_contents( | |
108 | $filename, | |
109 | '<?php /* '.base64_encode(gzdeflate(serialize($this->_links))).' */ ?>' | |
110 | ); | |
111 | } | |
112 | ||
113 | /** | |
114 | * Returns the number of links in the reference data | |
115 | */ | |
116 | public function countLinks() | |
117 | { | |
118 | return $this->_publicCount + $this->_privateCount; | |
119 | } | |
120 | ||
121 | /** | |
122 | * Returns the number of public links in the reference data | |
123 | */ | |
124 | public function countPublicLinks() | |
125 | { | |
126 | return $this->_publicCount; | |
127 | } | |
128 | ||
129 | /** | |
130 | * Returns the number of private links in the reference data | |
131 | */ | |
132 | public function countPrivateLinks() | |
133 | { | |
134 | return $this->_privateCount; | |
135 | } | |
136 | ||
137 | public function getLinks() | |
138 | { | |
139 | return $this->_links; | |
140 | } | |
141 | } |