agree-disagree.pl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright (C) 2005 Bayle Shanks http://purl.net/net/bshanks
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. our ($Now, @MyMacros, @MyRules, $DefaultStyleSheet, $q, $bol);
  18. AddModuleDescription('agree-disagree.pl', 'AgreeDisagreePlugin');
  19. push(@MyRules, \&AgreeDisagreeSupportRule);
  20. push(@MyMacros, sub{ s/\[\+\]/"[+:" . GetParam('username', T('Anonymous'))
  21. . ':' . TimeToText($Now) . "]"/eg });
  22. push(@MyMacros, sub{ s/\[\+(:[^]:]+)\]/"[+$1:" . TimeToText($Now) . "]"/eg });
  23. push(@MyMacros, sub{ s/\[\-\]/"[-:" . GetParam('username', T('Anonymous'))
  24. . ':' . TimeToText($Now) . "]"/eg });
  25. push(@MyMacros, sub{ s/\[\-(:[^]:]+)\]/"[-$1:" . TimeToText($Now) . "]"/eg });
  26. $DefaultStyleSheet .= <<'EOT' unless $DefaultStyleSheet =~ /div\.agree/; # mod_perl?
  27. div.agreeCount {
  28. float: left;
  29. clear: left;
  30. background-color: Green;
  31. padding-left: .5em;
  32. padding-right: .5em;
  33. padding-top: .5em;
  34. padding-bottom: .5em;
  35. }
  36. div.disagreeCount {
  37. float: left;
  38. clear: right;
  39. background-color: Red;
  40. padding-left: .5em;
  41. padding-right: .5em;
  42. padding-top: .5em;
  43. padding-bottom: .5em;
  44. }
  45. div.agreeNames {
  46. float: left;
  47. background-color: Green;
  48. font-size: xx-small;
  49. display: none;
  50. }
  51. div.disagreeNames {
  52. float: left;
  53. background-color: Red;
  54. font-size: xx-small;
  55. display: none;
  56. }
  57. EOT
  58. my %AgreePortraits = ();
  59. sub AgreeDisagreeSupportRule {
  60. if ($bol) {
  61. if ($bol && m/(\G(\s*\[\+(.*?)\]|\s*\[-(.*?)\])+)/cgs) {
  62. my $votes = $1;
  63. my @ayes = ();
  64. my @nayes = ();
  65. while ($votes =~ m/\G.*?\[\+(.*?)\]/cgs) {
  66. my ($ignore, $name, $time) = split(/:/, $1, 3);
  67. push(@ayes, $name);
  68. }
  69. my $votes2 = $votes;
  70. while ($votes2 =~ m/\G.*?\[-(.*?)\]/cgs) {
  71. my ($ignore, $name, $time) = split(/:/, $1, 3);
  72. push(@nayes, $name);
  73. }
  74. my $html = CloseHtmlEnvironments() ;
  75. $html .= $q->div({-class=>'agreeCount'}) . ($#ayes+1) . ' ' . '</div>' ;
  76. $html .= $q->div({-class=>'agreeNames'}) . printNames(@ayes) . '</div>' ;
  77. $html .= $q->div({-class=>'disagreeCount'}) . ' ' . ($#nayes+1) . '</div>' ;
  78. $html .= $q->div({-class=>'disagreeNames'}) . printNames(@nayes) . '</div>' ;
  79. return $html;
  80. }
  81. }
  82. return undef;
  83. }
  84. sub printNames {
  85. my @names = @_;
  86. my $html = '';
  87. foreach my $name (@names) {
  88. $html .= "$name<br>";
  89. }
  90. return $html;
  91. }