ReferenceLinkDB.php 3.6 KB

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