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