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