]>
Commit | Line | Data |
---|---|---|
ca74886f V |
1 | <?php |
2 | /** | |
3 | * Populates a reference datastore to test LinkDB | |
4 | */ | |
5 | class ReferenceLinkDB | |
6 | { | |
c3dfd899 | 7 | public static $NB_LINKS_TOTAL = 8; |
89baf23d | 8 | |
07b6fa75 V |
9 | private $_links = array(); |
10 | private $_publicCount = 0; | |
11 | private $_privateCount = 0; | |
ca74886f V |
12 | |
13 | /** | |
14 | * Populates the test DB with reference data | |
15 | */ | |
735ed4a9 | 16 | public function __construct() |
ca74886f | 17 | { |
89baf23d | 18 | $this->addLink( |
c3dfd899 | 19 | 41, |
89baf23d A |
20 | 'Link title: @website', |
21 | '?WDWyig', | |
9ccca401 | 22 | 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag', |
89baf23d | 23 | 0, |
d592daea | 24 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), |
c3dfd899 A |
25 | 'sTuff', |
26 | null, | |
27 | 'WDWyig' | |
89baf23d A |
28 | ); |
29 | ||
ca74886f | 30 | $this->addLink( |
c3dfd899 A |
31 | 42, |
32 | 'Note: I have a big ID but an old date', | |
33 | '?WDWyig', | |
34 | 'Used to test links reordering.', | |
35 | 0, | |
d592daea | 36 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20100310_101010'), |
c3dfd899 A |
37 | 'ut' |
38 | ); | |
39 | ||
40 | $this->addLink( | |
41 | 8, | |
522b278b | 42 | 'Free as in Freedom 2.0 @website', |
ca74886f | 43 | 'https://static.fsf.org/nosvn/faif-2.0.pdf', |
9ccca401 | 44 | 'Richard Stallman and the Free Software Revolution. Read this. #hashtag', |
ca74886f | 45 | 0, |
d592daea | 46 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'), |
c6d876bb | 47 | 'free gnu software stallman -exclude stuff hashtag', |
d592daea | 48 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033') |
ca74886f V |
49 | ); |
50 | ||
51 | $this->addLink( | |
c3dfd899 | 52 | 7, |
ca74886f V |
53 | 'MediaGoblin', |
54 | 'http://mediagoblin.org/', | |
9ccca401 | 55 | 'A free software media publishing platform #hashtagOther', |
ca74886f | 56 | 0, |
d592daea | 57 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20130614_184135'), |
c3dfd899 A |
58 | 'gnu media web .hidden hashtag', |
59 | null, | |
60 | 'IuWvgA' | |
ca74886f V |
61 | ); |
62 | ||
63 | $this->addLink( | |
c3dfd899 | 64 | 6, |
ca74886f V |
65 | 'w3c-markup-validator', |
66 | 'https://dvcs.w3.org/hg/markup-validator/summary', | |
9ccca401 | 67 | 'Mercurial repository for the W3C Validator #private', |
ca74886f | 68 | 1, |
d592daea | 69 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20141125_084734'), |
ca74886f V |
70 | 'css html w3c web Mercurial' |
71 | ); | |
72 | ||
73 | $this->addLink( | |
c3dfd899 | 74 | 4, |
ca74886f V |
75 | 'UserFriendly - Web Designer', |
76 | 'http://ars.userfriendly.org/cartoons/?id=20121206', | |
9ccca401 | 77 | 'Naming conventions... #private', |
ca74886f | 78 | 0, |
d592daea | 79 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'), |
ca74886f V |
80 | 'dev cartoon web' |
81 | ); | |
82 | ||
83 | $this->addLink( | |
c3dfd899 | 84 | 1, |
ca74886f V |
85 | 'UserFriendly - Samba', |
86 | 'http://ars.userfriendly.org/cartoons/?id=20010306', | |
87 | 'Tropical printing', | |
88 | 0, | |
d592daea | 89 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'), |
ca74886f V |
90 | 'samba cartoon web' |
91 | ); | |
92 | ||
93 | $this->addLink( | |
c3dfd899 | 94 | 0, |
ca74886f V |
95 | 'Geek and Poke', |
96 | 'http://geek-and-poke.com/', | |
97 | '', | |
98 | 1, | |
d592daea | 99 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'), |
9866b408 | 100 | 'dev cartoon tag1 tag2 tag3 tag4 ' |
ca74886f V |
101 | ); |
102 | } | |
103 | ||
104 | /** | |
105 | * Adds a new link | |
106 | */ | |
c3dfd899 | 107 | protected function addLink($id, $title, $url, $description, $private, $date, $tags, $updated = '', $shorturl = '') |
ca74886f V |
108 | { |
109 | $link = array( | |
c3dfd899 | 110 | 'id' => $id, |
ca74886f V |
111 | 'title' => $title, |
112 | 'url' => $url, | |
113 | 'description' => $description, | |
114 | 'private' => $private, | |
ca74886f | 115 | 'tags' => $tags, |
c3dfd899 | 116 | 'created' => $date, |
c6d876bb | 117 | 'updated' => $updated, |
d592daea | 118 | 'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id), |
ca74886f | 119 | ); |
c3dfd899 | 120 | $this->_links[$id] = $link; |
ca74886f V |
121 | |
122 | if ($private) { | |
07b6fa75 | 123 | $this->_privateCount++; |
ca74886f V |
124 | return; |
125 | } | |
07b6fa75 | 126 | $this->_publicCount++; |
ca74886f V |
127 | } |
128 | ||
129 | /** | |
130 | * Writes data to the datastore | |
131 | */ | |
9c8752a2 | 132 | public function write($filename) |
ca74886f V |
133 | { |
134 | file_put_contents( | |
135 | $filename, | |
07b6fa75 | 136 | '<?php /* '.base64_encode(gzdeflate(serialize($this->_links))).' */ ?>' |
ca74886f V |
137 | ); |
138 | } | |
139 | ||
140 | /** | |
141 | * Returns the number of links in the reference data | |
142 | */ | |
143 | public function countLinks() | |
144 | { | |
07b6fa75 | 145 | return $this->_publicCount + $this->_privateCount; |
ca74886f V |
146 | } |
147 | ||
148 | /** | |
149 | * Returns the number of public links in the reference data | |
150 | */ | |
151 | public function countPublicLinks() | |
152 | { | |
07b6fa75 | 153 | return $this->_publicCount; |
ca74886f V |
154 | } |
155 | ||
156 | /** | |
157 | * Returns the number of private links in the reference data | |
158 | */ | |
159 | public function countPrivateLinks() | |
160 | { | |
07b6fa75 | 161 | return $this->_privateCount; |
ca74886f | 162 | } |
822bffce A |
163 | |
164 | public function getLinks() | |
165 | { | |
166 | return $this->_links; | |
167 | } | |
c3dfd899 A |
168 | |
169 | /** | |
170 | * Setter to override link creation. | |
171 | * | |
172 | * @param array $links List of links. | |
173 | */ | |
174 | public function setLinks($links) | |
175 | { | |
176 | $this->_links = $links; | |
177 | } | |
ca74886f | 178 | } |