ReferenceLinkDB.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. * Populates the test DB with reference data
  12. */
  13. function __construct()
  14. {
  15. $this->addLink(
  16. 'Free as in Freedom 2.0',
  17. 'https://static.fsf.org/nosvn/faif-2.0.pdf',
  18. 'Richard Stallman and the Free Software Revolution',
  19. 0,
  20. '20150310_114633',
  21. 'free gnu software stallman'
  22. );
  23. $this->addLink(
  24. 'MediaGoblin',
  25. 'http://mediagoblin.org/',
  26. 'A free software media publishing platform',
  27. 0,
  28. '20130614_184135',
  29. 'gnu media web'
  30. );
  31. $this->addLink(
  32. 'w3c-markup-validator',
  33. 'https://dvcs.w3.org/hg/markup-validator/summary',
  34. 'Mercurial repository for the W3C Validator',
  35. 1,
  36. '20141125_084734',
  37. 'css html w3c web Mercurial'
  38. );
  39. $this->addLink(
  40. 'UserFriendly - Web Designer',
  41. 'http://ars.userfriendly.org/cartoons/?id=20121206',
  42. 'Naming conventions...',
  43. 0,
  44. '20121206_142300',
  45. 'dev cartoon web'
  46. );
  47. $this->addLink(
  48. 'UserFriendly - Samba',
  49. 'http://ars.userfriendly.org/cartoons/?id=20010306',
  50. 'Tropical printing',
  51. 0,
  52. '20121206_172539',
  53. 'samba cartoon web'
  54. );
  55. $this->addLink(
  56. 'Geek and Poke',
  57. 'http://geek-and-poke.com/',
  58. '',
  59. 1,
  60. '20121206_182539',
  61. 'dev cartoon'
  62. );
  63. }
  64. /**
  65. * Adds a new link
  66. */
  67. protected function addLink($title, $url, $description, $private, $date, $tags)
  68. {
  69. $link = array(
  70. 'title' => $title,
  71. 'url' => $url,
  72. 'description' => $description,
  73. 'private' => $private,
  74. 'linkdate' => $date,
  75. 'tags' => $tags,
  76. );
  77. $this->links[$date] = $link;
  78. if ($private) {
  79. $this->privateCount++;
  80. return;
  81. }
  82. $this->publicCount++;
  83. }
  84. /**
  85. * Writes data to the datastore
  86. */
  87. public function write($filename, $prefix, $suffix)
  88. {
  89. file_put_contents(
  90. $filename,
  91. $prefix.base64_encode(gzdeflate(serialize($this->links))).$suffix
  92. );
  93. }
  94. /**
  95. * Returns the number of links in the reference data
  96. */
  97. public function countLinks()
  98. {
  99. return $this->publicCount + $this->privateCount;
  100. }
  101. /**
  102. * Returns the number of public links in the reference data
  103. */
  104. public function countPublicLinks()
  105. {
  106. return $this->publicCount;
  107. }
  108. /**
  109. * Returns the number of private links in the reference data
  110. */
  111. public function countPrivateLinks()
  112. {
  113. return $this->privateCount;
  114. }
  115. }
  116. ?>