agree-disagree.pl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 2 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, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA
  18. use strict;
  19. use v5.10;
  20. our ($Now, @MyMacros, @MyRules, $DefaultStyleSheet, $q, $bol);
  21. AddModuleDescription('agree-disagree.pl', 'AgreeDisagreePlugin');
  22. push(@MyRules, \&AgreeDisagreeSupportRule);
  23. push(@MyMacros, sub{ s/\[\+\]/"[+:" . GetParam('username', T('Anonymous'))
  24. . ':' . TimeToText($Now) . "]"/eg });
  25. push(@MyMacros, sub{ s/\[\+(:[^]:]+)\]/"[+$1:" . TimeToText($Now) . "]"/eg });
  26. push(@MyMacros, sub{ s/\[\-\]/"[-:" . GetParam('username', T('Anonymous'))
  27. . ':' . TimeToText($Now) . "]"/eg });
  28. push(@MyMacros, sub{ s/\[\-(:[^]:]+)\]/"[-$1:" . TimeToText($Now) . "]"/eg });
  29. $DefaultStyleSheet .= <<'EOT' unless $DefaultStyleSheet =~ /div\.agree/; # mod_perl?
  30. div.agreeCount {
  31. float: left;
  32. clear: left;
  33. background-color: Green;
  34. padding-left: .5em;
  35. padding-right: .5em;
  36. padding-top: .5em;
  37. padding-bottom: .5em;
  38. }
  39. div.disagreeCount {
  40. float: left;
  41. clear: right;
  42. background-color: Red;
  43. padding-left: .5em;
  44. padding-right: .5em;
  45. padding-top: .5em;
  46. padding-bottom: .5em;
  47. }
  48. div.agreeNames {
  49. float: left;
  50. background-color: Green;
  51. font-size: xx-small;
  52. display: none;
  53. }
  54. div.disagreeNames {
  55. float: left;
  56. background-color: Red;
  57. font-size: xx-small;
  58. display: none;
  59. }
  60. EOT
  61. my %AgreePortraits = ();
  62. sub AgreeDisagreeSupportRule {
  63. if ($bol) {
  64. if ($bol && m/(\G(\s*\[\+(.*?)\]|\s*\[-(.*?)\])+)/cgs) {
  65. my $votes = $1;
  66. my @ayes = ();
  67. my @nayes = ();
  68. while ($votes =~ m/\G.*?\[\+(.*?)\]/cgs) {
  69. my ($ignore, $name, $time) = split(/:/, $1, 3);
  70. push(@ayes, $name);
  71. }
  72. my $votes2 = $votes;
  73. while ($votes2 =~ m/\G.*?\[-(.*?)\]/cgs) {
  74. my ($ignore, $name, $time) = split(/:/, $1, 3);
  75. push(@nayes, $name);
  76. }
  77. my $html = CloseHtmlEnvironments() ;
  78. $html .= $q->div({-class=>'agreeCount'}) . ($#ayes+1) . ' ' . '</div>' ;
  79. $html .= $q->div({-class=>'agreeNames'}) . printNames(@ayes) . '</div>' ;
  80. $html .= $q->div({-class=>'disagreeCount'}) . ' ' . ($#nayes+1) . '</div>' ;
  81. $html .= $q->div({-class=>'disagreeNames'}) . printNames(@nayes) . '</div>' ;
  82. return $html;
  83. }
  84. }
  85. return undef;
  86. }
  87. sub printNames {
  88. my @names = @_;
  89. my $html = '';
  90. foreach my $name (@names) {
  91. $html .= "$name<br>";
  92. }
  93. return $html;
  94. }