DUMMY.pm 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package Trog::Data::DUMMY;
  2. use strict;
  3. use warnings;
  4. no warnings 'experimental';
  5. use feature qw{signatures};
  6. =head1 QUERY FORMAT
  7. The $query_language and $query_help variables are presented to the user as to how to use the search box in the tCMS header.
  8. =cut
  9. our $query_language = 'Perl Regex in Quotemeta';
  10. our $query_help = 'https://perldoc.perl.org/functions/quotemeta.html';
  11. =head1 POST STRUCTURE
  12. Posts generally need to have the following:
  13. data: Brief description of content, or the content itself.
  14. content_type: What this content actually is. Used to filter into the appropriate pages.
  15. href: Primary link. This is the subject of a news post, or a link to the item itself. Can be local or remote.
  16. local_href: Backup link. Automatically created link to a static cache of the content.
  17. title: Title of the content. Used as link name for the 'href' attribute.
  18. user: User was banned for this post
  19. id: Internal identifier in datastore for the post.
  20. tags: array ref of appropriate tags.
  21. created: timestamp of creation of this version of the post
  22. version: revision # of this post.
  23. =cut
  24. my $example_posts = [
  25. {
  26. content_type => "text/html",
  27. data => "Here, caveman",
  28. href => '/',
  29. local_href => "/assets/today.html",
  30. title => 'Example Post',
  31. user => 'Nobody',
  32. id => 665,
  33. tags => ['news'],
  34. created => time(),
  35. version => 0,
  36. },
  37. {
  38. content_type => "text/html",
  39. data => "Is amazing",
  40. href => '/',
  41. local_href => "/assets/blog/Muh Blog.html",
  42. title => 'Muh Blog',
  43. user => 'Nobody',
  44. id => 666,
  45. tags => ['blog'],
  46. created => time(),
  47. version => 0,
  48. },
  49. {
  50. content_type => "text/html",
  51. data => "Vote for Nobody, nobody really cares!",
  52. href => '/',
  53. local_href => "/assets/about/Nobody.html",
  54. title => 'Nobody',
  55. user => 'Nobody',
  56. id => 669,
  57. tags => ['about', 'profile'],
  58. created => time(),
  59. version => 0,
  60. },
  61. {
  62. content_type => "image/gif",
  63. data => "Default avatar for new users",
  64. href => "/img/avatar/humm.gif",
  65. local_href => "/img/avatar/humm.gif",
  66. title => "humm.gif",
  67. user => 'Nobody',
  68. id => 420,
  69. tags => ['image', 'files', 'profile-image'],
  70. created => time(),
  71. version => 0,
  72. preview => '/img/avatar/humm.gif',
  73. },
  74. {
  75. content_type => "audio/mpeg",
  76. data => "Test recording for tCMS",
  77. href => "/assets/audio/test.mp3",
  78. local_href => "/assets/audio/test.mp3",
  79. title => "test.mp3",
  80. user => "Nobody",
  81. id => 111,
  82. tags => ["audio", "files"],
  83. created => time(),
  84. version => 0,
  85. preview => '/img/sys/testpattern.jpg',
  86. },
  87. {
  88. content_type => "video/ogg",
  89. data => "Test video for tCMS",
  90. href => "/assets/video/test.ogv",
  91. local_href => "/assets/video/test.ogv",
  92. title => "test.ogv",
  93. user => "Nobody",
  94. id => "222",
  95. tags => ["video", "files"],
  96. created => time(),
  97. version => 0,
  98. preview => '/img/sys/testpattern.jpg',
  99. },
  100. ];
  101. =head1 CONSTRUCTOR
  102. =head2 new(Config::Simple $config)
  103. Try not to do expensive things here.
  104. =cut
  105. sub new ($class, $config) {
  106. $config = $config->vars();
  107. $config->{lang} = $query_language;
  108. $config->{help} = $query_help;
  109. return bless($config,__PACKAGE__);
  110. }
  111. =head1 METHODS
  112. =cut
  113. # These have to be sorted as requested by the client
  114. sub get ($self, %request) {
  115. my @filtered = @$example_posts;
  116. @filtered = grep { my $tags = $_->{tags}; grep { my $t = $_; grep {$t eq $_ } @{$request{tags}} } @$tags } @filtered if @{$request{tags}};
  117. @filtered = grep { $_->{data} =~ m/\Q$request{like}\E/i } @filtered if $request{like};
  118. # Next, go ahead and build the "post type"
  119. @filtered = _add_post_type(@filtered);
  120. # Next, add the type of post this is
  121. @filtered = _add_media_type(@filtered);
  122. return \@filtered;
  123. }
  124. sub _add_post_type (@posts) {
  125. return map {
  126. my $post = $_;
  127. my $type = 'file';
  128. $type = 'blog' if grep { $_ eq 'blog' } @{$post->{tags}};
  129. $type = 'microblog' if grep { $_ eq 'news' } @{$post->{tags}};
  130. $post->{type} = $type;
  131. $post
  132. } @posts;
  133. }
  134. sub _add_media_type (@posts) {
  135. return map {
  136. my $post = $_;
  137. $post->{is_video} = 1 if $post->{content_type} =~ m/^video\//;
  138. $post->{is_audio} = 1 if $post->{content_type} =~ m/^audio\//;
  139. $post->{is_image} = 1 if $post->{content_type} =~ m/^image\//;
  140. $post
  141. } @posts;
  142. }
  143. sub add ($self, @posts) {
  144. return 1;
  145. }
  146. sub update($self, @posts) {
  147. return 1;
  148. }
  149. sub delete($self, @ids) {
  150. return 1;
  151. }
  152. 1;