HTMLGenerator.pm 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  1. package Pisg::HTMLGenerator;
  2. # Copyright and license, as well as documentation(POD) for this module is
  3. # found at the end of the file.
  4. use strict;
  5. $^W = 1;
  6. # test for Text::Iconv
  7. my $have_iconv = 1;
  8. eval 'use Text::Iconv';
  9. $have_iconv = 0 if $@;
  10. sub new
  11. {
  12. my $type = shift;
  13. my %args = @_;
  14. my $self = {
  15. cfg => $args{cfg},
  16. stats => $args{stats},
  17. users => $args{users},
  18. tmps => $args{tmps},
  19. topactive => {},
  20. };
  21. # Import common functions in Pisg::Common
  22. require Pisg::Common;
  23. Pisg::Common->import();
  24. my $lang_charset = $self->{tmps}->{lc($self->{cfg}->{lang})}{lang_charset};
  25. if($lang_charset and $lang_charset ne $self->{cfg}->{charset}) {
  26. if($have_iconv) {
  27. # convert from template charset to our
  28. $self->{iconv} = Text::Iconv->new($lang_charset, $self->{cfg}->{charset});
  29. } else {
  30. print "Text::Iconv is not installed, skipping charset conversion of language templates\n"
  31. unless ($self->{cfg}->{silent});
  32. }
  33. }
  34. bless($self, $type);
  35. return $self;
  36. }
  37. sub create_output
  38. {
  39. # This subroutine calls all the subroutines which create their
  40. # individual stats. The name of the functions is somewhat saying - if
  41. # you don't understand it, most subs have a better explanation in the
  42. # sub itself.
  43. my $self = shift;
  44. $self->_topactive();
  45. if($self->{cfg}->{bignumbersthreshold} =~ /^sqrt/) {
  46. $self->{cfg}->{bignumbersthreshold} = int(sqrt($self->{stats}->{topactive_lines}));
  47. }
  48. my $fname = $self->{cfg}->{outputfile};
  49. $fname =~ s/\%t/$self->{cfg}->{outputtag}/g;
  50. print "Now generating HTML in $fname...\n"
  51. unless ($self->{cfg}->{silent});
  52. open (OUTPUT, "> $fname") or
  53. die("$0: Unable to open outputfile($fname): $!\n");
  54. if ($self->{cfg}->{showtime}) {
  55. $self->{cfg}->{tablewidth} += 40;
  56. }
  57. if ($self->{cfg}->{showlinetime}) {
  58. $self->{cfg}->{tablewidth} += 100;
  59. }
  60. if ($self->{cfg}->{showwordtime}) {
  61. $self->{cfg}->{tablewidth} += 100;
  62. }
  63. if ($self->{cfg}->{showwords}) {
  64. $self->{cfg}->{tablewidth} += 40;
  65. }
  66. if ($self->{cfg}->{showwpl}) {
  67. $self->{cfg}->{tablewidth} += 40;
  68. }
  69. if ($self->{cfg}->{showcpl}) {
  70. $self->{cfg}->{tablewidth} += 40;
  71. }
  72. if ($self->{cfg}->{userpics}) {
  73. $self->{cfg}->{tablewidth} += $self->{cfg}->{userpics} * ($self->{cfg}->{picwidth} || 60);
  74. }
  75. $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
  76. $self->_htmlheader();
  77. $self->_pageheader()
  78. if ($self->{cfg}->{pagehead} ne 'none');
  79. if ($self->{cfg}->{dailyactivity}) {
  80. $self->_activedays();
  81. }
  82. if ($self->{cfg}->{showactivetimes}) {
  83. $self->_activetimes();
  84. }
  85. if ($self->{cfg}->{showactivenicks}) {
  86. $self->_activenicks();
  87. }
  88. if ($self->{cfg}->{showmostactivebyhour}) {
  89. $self->_mostactivebyhour();
  90. }
  91. if ($self->{cfg}->{showbignumbers}) {
  92. $self->_headline($self->_template_text('bignumtopic'));
  93. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  94. $self->_questions();
  95. $self->_shoutpeople();
  96. $self->_capspeople();
  97. $self->_violent();
  98. $self->_mostsmiles();
  99. $self->_mostsad();
  100. $self->_linelengths();
  101. $self->_mostwords();
  102. $self->_mostwordsperline();
  103. _html("</table>"); # Needed for sections
  104. }
  105. if ($self->{cfg}->{showmostnicks}) {
  106. $self->_mostnicks();
  107. }
  108. if ($self->{cfg}->{showmuw}) {
  109. $self->_mostusedword();
  110. }
  111. if ($self->{cfg}->{showmrn}) {
  112. $self->_mostreferencednicks();
  113. }
  114. if ($self->{cfg}->{showmru}) {
  115. $self->_mosturls();
  116. }
  117. if ($self->{cfg}->{showbignumbers}) {
  118. $self->_headline($self->_template_text('othernumtopic'));
  119. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  120. $self->_gotkicks();
  121. $self->_mostkicks();
  122. $self->_mostop() if $self->{cfg}->{showops};
  123. $self->_mosthalfop() if $self->{cfg}->{showhalfops};
  124. $self->_mostvoice() if $self->{cfg}->{showvoices};
  125. $self->_mostactions();
  126. $self->_mostmonologues();
  127. $self->_mostjoins();
  128. $self->_mostfoul();
  129. _html("</table>"); # Needed for sections
  130. }
  131. if ($self->{cfg}->{showtopics}) {
  132. $self->_headline($self->_template_text('latesttopic'));
  133. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  134. $self->_lasttopics();
  135. _html("</table>"); # Needed for sections
  136. }
  137. my %hash = ( lines => $self->{stats}->{parsedlines} );
  138. _html($self->_template_text('totallines', %hash) . "<br /><br />");
  139. $self->_pagefooter()
  140. if ($self->{cfg}->{pagefoot} ne 'none');
  141. $self->_htmlfooter();
  142. close(OUTPUT);
  143. }
  144. sub _htmlheader
  145. {
  146. my $self = shift;
  147. my %hash = (
  148. network => $self->{cfg}->{network},
  149. maintainer => $self->{cfg}->{maintainer},
  150. days => $self->{stats}->{days},
  151. nicks => scalar keys %{ $self->{stats}->{lines} }
  152. );
  153. my $CSS;
  154. if($self->{cfg}->{colorscheme} =~ /[^\w]/) { # use external CSS file
  155. $CSS = "<link rel=\"stylesheet\" type=\"text/css\" href=\"$self->{cfg}->{colorscheme}\">";
  156. } elsif($self->{cfg}->{colorscheme} ne "none") { # read the chosen CSS file
  157. my $css_file = $self->{cfg}->{cssdir} . $self->{cfg}->{colorscheme} . ".css";
  158. open(FILE, $css_file) or open (FILE, $self->{cfg}->{search_path} . "/$css_file") or die("$0: Unable to open stylesheet $css_file: $!\n");
  159. {
  160. local $/; # enable "slurp" mode
  161. $CSS = "<style type=\"text/css\">\n". <FILE>. "</style>";
  162. }
  163. close FILE;
  164. }
  165. my $title = $self->_template_text('pagetitle1', %hash);
  166. if($self->{cfg}->{colorscheme} ne "none") {
  167. print OUTPUT <<HTML;
  168. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  169. <html>
  170. <head>
  171. <meta http-equiv="Content-Type" content="text/html; charset=$self->{cfg}->{charset}" />
  172. <title>$title</title>
  173. $CSS
  174. </head>
  175. <body>
  176. <div align="center">
  177. HTML
  178. }
  179. _html("<span class=\"title\">$title</span><br />");
  180. _html("<br />");
  181. _html($self->_template_text('pagetitle2', %hash) . " " . $self->get_time());
  182. _html("<br />" . $self->_template_text('pagetitle3', %hash) . "<br /><br />");
  183. }
  184. sub get_time
  185. {
  186. my $self = shift;
  187. my ($tday, %hash);
  188. my $month = $self->_template_text('month', %hash);
  189. my $day = $self->_template_text('day', %hash);
  190. my @month = split(" ", $month);
  191. my @day = split(" ", $day);
  192. # Get the Date from the users computer
  193. my $timezone = $self->{cfg}->{timeoffset} * 3600;
  194. my ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+$timezone);
  195. $year += 1900; # Y2K Patch
  196. $min =~ s/^(.)$/0$1/; # Fixes the display of mins/secs below
  197. $sec =~ s/^(.)$/0$1/; # it displays 03 instead of 3
  198. if ($hour > '23') { # Checks to see if it Midnight
  199. $hour = 12; # Makes it display the hour 12
  200. $tday = "AM"; # Display AM
  201. } elsif($hour > '12') { # Get rid of the Military time and
  202. $hour -= 12; # put it into normal time
  203. $tday = "PM"; # If past Noon and before Midnight set
  204. } else {
  205. $tday = "AM"; # If it's past Midnight and before Noon
  206. } # set the time as AM
  207. # Use 24 hours pr. day
  208. if ($tday eq "PM" && $hour < '12') {
  209. $hour += 12;
  210. }
  211. return "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec";
  212. }
  213. sub _htmlfooter
  214. {
  215. my $self = shift;
  216. my %hash;
  217. my $pisg_hp = $self->_template_text('pisghomepage');
  218. $hash{pisg_url} = "<a href=\"http://pisg.sourceforge.net/\" title=\"$pisg_hp\" class=\"background\">pisg</a>";
  219. my $author_hp = $self->_template_text('authorhomepage');
  220. $hash{author_url} = "<a href=\"http://mbrix.dk/\" title=\"$author_hp\" class=\"background\">Morten Brix Pedersen</a>";
  221. $hash{version} = $self->{cfg}->{version};
  222. my $hours = $self->_template_text('hours');
  223. my $mins = $self->_template_text('minutes');
  224. my $secs = $self->_template_text('seconds');
  225. my $and = $self->_template_text('and');
  226. my $h = $self->{stats}->{processtime}{hours};
  227. my $m = $self->{stats}->{processtime}{mins};
  228. my $s = $self->{stats}->{processtime}{secs};
  229. $hash{time} = "$h $hours $m $mins $and $s $secs";
  230. my $stats_gen = $self->_template_text('stats_gen_by', %hash);
  231. my $author_text = $self->_template_text('author', %hash);
  232. my $stats_text = $self->_template_text('stats_gen_in', %hash);
  233. print OUTPUT <<HTML;
  234. <span class="small">
  235. $stats_gen<br />
  236. $author_text<br />
  237. $stats_text
  238. </span>
  239. HTML
  240. if($self->{cfg}->{colorscheme} ne "none") {
  241. print OUTPUT <<HTML;
  242. </div>
  243. </body>
  244. </html>
  245. HTML
  246. }
  247. }
  248. sub _headline
  249. {
  250. my $self = shift;
  251. my ($title) = (@_);
  252. print OUTPUT <<HTML;
  253. <br />
  254. <table width="$self->{cfg}->{headwidth}" cellpadding="1" cellspacing="0" border="0">
  255. <tr>
  256. <td class="headlinebg">
  257. <table width="100%" cellpadding="2" cellspacing="0" border="0">
  258. <tr>
  259. <td class="headtext">$title</td>
  260. </tr>
  261. </table>
  262. </td>
  263. </tr>
  264. </table>
  265. HTML
  266. }
  267. sub _pageheader
  268. {
  269. my $self = shift;
  270. open(PAGEHEAD, $self->{cfg}->{pagehead}) or die("$0: Unable to open $self->{cfg}->{pagehead} for reading: $!\n");
  271. while (<PAGEHEAD>) {
  272. _html($_);
  273. }
  274. close(PAGEHEAD);
  275. }
  276. sub _pagefooter
  277. {
  278. my $self = shift;
  279. open(PAGEFOOT, $self->{cfg}->{pagefoot}) or die("$0: Unable to open $self->{cfg}->{pagefoot} for reading: $!\n");
  280. while (<PAGEFOOT>) {
  281. _html($_);
  282. }
  283. close(PAGEFOOT);
  284. }
  285. sub _activedays
  286. {
  287. # The most actives times on the channel
  288. my $self = shift;
  289. my $days = $self->{stats}->{days};
  290. my $ndays = $self->{cfg}->{dailyactivity};
  291. my $image;
  292. my $time;
  293. my $day;
  294. my (%output, $class);
  295. my $highest_value = 1;
  296. for ($day = $days; $day > $days - $ndays ; $day--) {
  297. if (defined($self->{stats}->{day_lines}{$day})) {
  298. if ($self->{stats}->{day_lines}{$day} > $highest_value) {
  299. $highest_value=$self->{stats}->{day_lines}{$day};
  300. }
  301. } else {
  302. #there are only $days - $day days :)
  303. $ndays = $days - $day;
  304. }
  305. }
  306. my %hash = (
  307. n => $ndays
  308. );
  309. $self->_headline($self->_template_text('dailyactivitytopic', %hash));
  310. _html("<table border=\"0\"><tr>\n");
  311. for ($day = $days - $ndays +1; $day <= $days ; $day++) {
  312. my $lines = $self->{stats}->{day_lines}{$day};
  313. _html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">$lines<br />");
  314. for ($time = 4; $time >= 0; $time--) {
  315. if (defined($self->{stats}->{day_times}{$day}[$time])) {
  316. my $size = int(($self->{stats}->{day_times}{$day}[$time] / $highest_value) * 100);
  317. if ($size < 1) {
  318. # Opera doesn't understand '0.xxxx' in the height="xx" attr,
  319. # so we simply round up to 1 here.
  320. $size = 1;
  321. }
  322. $image = "pic_v_".$time*6;
  323. $image = $self->{cfg}->{$image};
  324. _html("<img src=\"$self->{cfg}->{piclocation}/$image\" width=\"15\" height=\"$size\" alt=\"$lines\" /><br />");
  325. }
  326. }
  327. _html("</td>\n");
  328. }
  329. _html("</tr><tr>");
  330. for ($b = $ndays-1; $b >= 0 ; $b--) {
  331. $class = 'rankc10center';
  332. _html("<td class=\"$class\" align=\"center\">$b</td>");
  333. }
  334. _html("</tr></table>");
  335. if($self->{cfg}->{showlegend} == 1) {
  336. $self->_legend();
  337. }
  338. }
  339. sub _activetimes
  340. {
  341. # The most actives times on the channel
  342. my $self = shift;
  343. my (%output, $class);
  344. $self->_headline($self->_template_text('activetimestopic'));
  345. my @toptime = sort { $self->{stats}->{times}{$b} <=> $self->{stats}->{times}{$a} } keys %{ $self->{stats}->{times} };
  346. my $highest_value = $self->{stats}->{times}{$toptime[0]};
  347. my @now = localtime($self->{cfg}->{timestamp});
  348. my $image;
  349. for my $hour (sort keys %{ $self->{stats}->{times} }) {
  350. my $size = int(($self->{stats}->{times}{$hour} / $highest_value) * 100);
  351. my $percent = ($self->{stats}->{times}{$hour} / $self->{stats}->{parsedlines}) * 100;
  352. my $lines_per_hour = $self->{stats}->{times}{$hour};
  353. $percent =~ s/(\.\d)\d+/$1/;
  354. if ($size < 1) {
  355. # Opera doesn't understand '0.xxxx' in the height="xx" attr,
  356. # so we simply round up to 1 here.
  357. $size = 1;
  358. }
  359. $image = "pic_v_".(int($hour/6)*6);
  360. $image = $self->{cfg}->{$image};
  361. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br /><img src=\"$self->{cfg}->{piclocation}/$image\" width=\"15\" height=\"$size\" alt=\"$lines_per_hour\" title=\"$lines_per_hour\"/></td>\n";
  362. }
  363. _html("<table border=\"0\"><tr>\n");
  364. for ($b = 0; $b < 24; $b++) {
  365. $a = sprintf("%02d", $b);
  366. if (!defined($output{$a}) || $output{$a} eq "") {
  367. _html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  368. } else {
  369. _html($output{$a});
  370. }
  371. }
  372. _html("</tr><tr>");
  373. # Remove leading zero
  374. $toptime[0] =~ s/0(\d)/$1/;
  375. for ($b = 0; $b < 24; $b++) {
  376. if ($toptime[0] == $b) {
  377. # Highlight the top time
  378. $class = 'hirankc10center';
  379. } else {
  380. $class = 'rankc10center';
  381. }
  382. _html("<td class=\"$class\" align=\"center\">$b</td>");
  383. }
  384. _html("</tr></table>");
  385. if($self->{cfg}->{showlegend} == 1) {
  386. $self->_legend();
  387. }
  388. }
  389. sub _activenicks
  390. {
  391. # The most active nicks (those who wrote most lines)
  392. my $self = shift;
  393. $self->_headline($self->_template_text('activenickstopic'));
  394. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  395. _html("<td>&nbsp;</td>"
  396. . "<td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>"
  397. . "<td class=\"tdtop\"><b>" . $self->_template_text('numberlines') . "</b></td>"
  398. . ($self->{cfg}->{showtime} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_time')."</b></td>" : "")
  399. . ($self->{cfg}->{showwords} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_words')."</b></td>" : "")
  400. . ($self->{cfg}->{showwpl} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_wpl')."</b></td>" : "")
  401. . ($self->{cfg}->{showcpl} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_cpl')."</b></td>" : "")
  402. . ($self->{cfg}->{showlastseen} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_lastseen')."</b></td>" : "")
  403. . ($self->{cfg}->{showrandquote} ? "<td class=\"tdtop\"><b>".$self->_template_text('randquote')."</b></td>" : "")
  404. );
  405. my @active;
  406. my $nicks;
  407. if ($self->{cfg}->{sortbywords}) {
  408. @active = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} } keys %{ $self->{stats}->{words} };
  409. $nicks = scalar keys %{ $self->{stats}->{words} };
  410. } else {
  411. @active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} } keys %{ $self->{stats}->{lines} };
  412. $nicks = scalar keys %{ $self->{stats}->{lines} };
  413. }
  414. if ($self->{cfg}->{activenicks} > $nicks) { $self->{cfg}->{activenicks} = $nicks; }
  415. for (my $c = 0; $c < $self->{cfg}->{activenicks}; $c++) {
  416. last unless $self->{cfg}->{userpics};
  417. my $nick = $active[$c];
  418. if ($self->{users}->{userpics}{$nick}) {
  419. _html("<td class=\"tdtop\"" .
  420. ($self->{cfg}->{userpics} > 1 ? " colspan=\"$self->{cfg}->{userpics}\"" : "") .
  421. "><b>" . $self->_template_text('userpic') ."</b></td>");
  422. last;
  423. }
  424. }
  425. _html("</tr>");
  426. for (my $i = 0; $i < $self->{cfg}->{activenicks}; $i++) {
  427. my $c = $i + 1;
  428. my $nick = $active[$i];
  429. my $visiblenick;
  430. my $randomline;
  431. if (not defined $self->{stats}->{sayings}{$nick}) {
  432. if ($self->{stats}->{actions}{$nick}) {
  433. $randomline = $self->{stats}->{actionlines}{$nick};
  434. } else {
  435. $randomline = "";
  436. }
  437. } else {
  438. $randomline = $self->{stats}->{sayings}{$nick};
  439. }
  440. if ($randomline) {
  441. $randomline = $self->_format_line($randomline);
  442. }
  443. # Add a link to the nick if there is any and quote nick
  444. if ($self->{users}->{userlinks}{$nick}) {
  445. $visiblenick = $self->_format_word($self->{users}->{userlinks}{$nick}, $nick);
  446. } else {
  447. $visiblenick = $self->_format_word($nick);
  448. }
  449. my $color = $self->generate_colors($c);
  450. my $class = 'rankc';
  451. if ($c == 1) {
  452. $class = 'hirankc';
  453. }
  454. my $lastseen;
  455. if ($self->{cfg}->{showlastseen}) {
  456. $lastseen = $self->{stats}->{days} - $self->{stats}->{lastvisited}{$nick};
  457. if ($lastseen == 0) {
  458. $lastseen = $self->_template_text('today');
  459. } elsif ($lastseen == 1) {
  460. $lastseen = "$lastseen " .$self->_template_text('lastseen1');
  461. } else {
  462. $lastseen = "$lastseen " .$self->_template_text('lastseen2');
  463. }
  464. }
  465. _html("<tr><td class=\"$class\" align=\"left\">$c</td>");
  466. my $line = $self->{stats}->{lines}{$nick};
  467. my $w = $self->{stats}->{words}{$nick} ? $self->{stats}->{words}{$nick} : 0;
  468. my $ch = $self->{stats}->{lengths}{$nick};
  469. my $sex = $self->{users}->{sex}{$nick};
  470. _html("<td style=\"background-color: $color\""
  471. . ($sex ? ($sex eq 'm' ? " class=\"male\">"
  472. : ($sex eq 'f' ? " class=\"female\">" : " class=\"bot\">")) : ">")
  473. ."$visiblenick</td>"
  474. . ($self->{cfg}->{showlinetime} ?
  475. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_linetimes($nick,$active[0])."</td>"
  476. : "<td style=\"background-color: $color\">$line</td>")
  477. . ($self->{cfg}->{showtime} ?
  478. "<td style=\"background-color: $color\">".$self->_user_times($nick)."</td>"
  479. : "")
  480. . ($self->{cfg}->{showwords} ?
  481. ($self->{cfg}->{showwordtime} ?
  482. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_wordtimes($nick,$active[0])."</td>"
  483. : "<td style=\"background-color: $color\">$w</td>")
  484. : "")
  485. . ($self->{cfg}->{showwpl} ?
  486. "<td style=\"background-color: $color\">".sprintf("%.1f",$w/$line)."</td>"
  487. : "")
  488. . ($self->{cfg}->{showcpl} ?
  489. "<td style=\"background-color: $color\">".sprintf("%.1f",$ch/$line)."</td>"
  490. : "")
  491. . ($self->{cfg}->{showlastseen} ?
  492. "<td style=\"background-color: $color\">$lastseen</td>"
  493. : "")
  494. . ($self->{cfg}->{showrandquote} ?
  495. "<td style=\"background-color: $color\">\"$randomline\"</td>"
  496. : "")
  497. );
  498. if ($self->{cfg}->{userpics} && $i % $self->{cfg}->{userpics} == 0) {
  499. for my $ii (0 .. $self->{cfg}->{userpics} - 1) {
  500. last if $i + $ii >= $self->{cfg}->{activenicks};
  501. $self->_user_pic($active[$i + $ii], $color);
  502. }
  503. }
  504. _html("</tr>");
  505. }
  506. _html("</table><br />");
  507. # Almost as active nicks ('These didn't make it to the top..')
  508. my $toshow = $self->{cfg}->{activenicks2} - $self->{cfg}->{activenicks};
  509. my $remain = $self->{cfg}->{activenicks} + $toshow;
  510. unless ($toshow > $nicks) {
  511. $remain = $self->{cfg}->{activenicks} + $self->{cfg}->{activenicks2};
  512. if ($remain > $nicks) {
  513. $remain = $nicks;
  514. }
  515. if ($self->{cfg}->{activenicks} < $remain) {
  516. _html("<br /><b><i>" . $self->_template_text('nottop') . "</i></b><table><tr>");
  517. for (my $i = $self->{cfg}->{activenicks}; $i < $remain; $i++) {
  518. unless ($i % 5) { if ($i != $self->{cfg}->{activenicks}) { _html("</tr><tr>"); } }
  519. my $items;
  520. if ($self->{cfg}->{sortbywords}) {
  521. $items = $self->{stats}->{words}{$active[$i]};
  522. } else {
  523. $items = $self->{stats}->{lines}{$active[$i]};
  524. }
  525. my $sex = $self->{users}->{sex}{$active[$i]};
  526. _html("<td class=\"rankc10\">"
  527. . ($sex ? ($sex eq 'm' ? "<span class=\"male\">"
  528. : ($sex eq 'f' ? "<span class=\"female\">" : "<span class=\"bot\">")) : "")
  529. ."$active[$i] ($items)"
  530. . ($sex ? "</span>" : "")
  531. ."</td>");
  532. }
  533. _html("</tr></table>");
  534. }
  535. }
  536. my %hash;
  537. $hash{totalnicks} = $nicks - $remain;
  538. if ($hash{totalnicks} > 0) {
  539. _html("<br /><b>" . $self->_template_text('totalnicks', %hash) . "</b><br />");
  540. }
  541. }
  542. sub generate_colors
  543. {
  544. my $self = shift;
  545. my $c = shift;
  546. my $h = $self->{cfg}->{hicell};
  547. $h =~ s/^#//;
  548. $h = hex $h;
  549. my $h2 = $self->{cfg}->{hicell2};
  550. $h2 =~ s/^#//;
  551. $h2 = hex $h2;
  552. my $f_b = $h & 0xff;
  553. my $f_g = ($h & 0xff00) >> 8;
  554. my $f_r = ($h & 0xff0000) >> 16;
  555. my $t_b = $h2 & 0xff;
  556. my $t_g = ($h2 & 0xff00) >> 8;
  557. my $t_r = ($h2 & 0xff0000) >> 16;
  558. my $blue = sprintf "%0.2x", abs int(((($t_b - $f_b) / $self->{cfg}->{activenicks}) * +$c) + $f_b);
  559. my $green = sprintf "%0.2x", abs int(((($t_g - $f_g) / $self->{cfg}->{activenicks}) * +$c) + $f_g);
  560. my $red = sprintf "%0.2x", abs int(((($t_r - $f_r) / $self->{cfg}->{activenicks}) * +$c) + $f_r);
  561. return "#$red$green$blue";
  562. }
  563. sub _html
  564. {
  565. my $html = shift;
  566. print OUTPUT "$html\n";
  567. }
  568. sub _questions
  569. {
  570. # Persons who asked the most questions
  571. my $self = shift;
  572. my %qpercent;
  573. foreach my $nick (sort keys %{ $self->{stats}->{questions} }) {
  574. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  575. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  576. $qpercent{$nick} = ($self->{stats}->{questions}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  577. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  578. }
  579. }
  580. }
  581. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  582. if (@question) {
  583. my %hash = (
  584. nick => $question[0],
  585. per => $qpercent{$question[0]}
  586. );
  587. my $text = $self->_template_text('question1', %hash);
  588. _html("<tr><td class=\"hicell\">$text");
  589. if (@question >= 2) {
  590. my %hash = (
  591. nick => $question[1],
  592. per => $qpercent{$question[1]}
  593. );
  594. my $text = $self->_template_text('question2', %hash);
  595. _html("<br /><span class=\"small\">$text</span>");
  596. }
  597. _html("</td></tr>");
  598. } else {
  599. _html("<tr><td class=\"hicell\">" . $self->_template_text('question3') . "</td></tr>");
  600. }
  601. }
  602. sub _shoutpeople
  603. {
  604. # The ones who speak with exclamation marks!
  605. my $self = shift;
  606. my %spercent;
  607. foreach my $nick (sort keys %{ $self->{stats}->{shouts} }) {
  608. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  609. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  610. $spercent{$nick} = ($self->{stats}->{shouts}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  611. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  612. }
  613. }
  614. }
  615. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  616. if (@shout) {
  617. my %hash = (
  618. nick => $shout[0],
  619. per => $spercent{$shout[0]}
  620. );
  621. my $text = $self->_template_text('shout1', %hash);
  622. _html("<tr><td class=\"hicell\">$text");
  623. if (@shout >= 2) {
  624. my %hash = (
  625. nick => $shout[1],
  626. per => $spercent{$shout[1]}
  627. );
  628. my $text = $self->_template_text('shout2', %hash);
  629. _html("<br /><span class=\"small\">$text</span>");
  630. }
  631. _html("</td></tr>");
  632. } else {
  633. my $text = $self->_template_text('shout3');
  634. _html("<tr><td class=\"hicell\">$text</td></tr>");
  635. }
  636. }
  637. sub _capspeople
  638. {
  639. # The ones who speak ALL CAPS.
  640. my $self = shift;
  641. my %cpercent;
  642. foreach my $nick (sort keys %{ $self->{stats}->{allcaps} }) {
  643. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  644. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  645. $cpercent{$nick} = $self->{stats}->{allcaps}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  646. $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
  647. }
  648. }
  649. }
  650. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  651. if (@caps) {
  652. my %hash = (
  653. nick => $caps[0],
  654. per => $cpercent{$caps[0]},
  655. line => $self->_format_line($self->{stats}->{allcaplines}{$caps[0]})
  656. );
  657. my $text = $self->_template_text('allcaps1', %hash);
  658. if($self->{cfg}->{showshoutline}) {
  659. my $exttext = $self->_template_text('allcapstext', %hash);
  660. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  661. } else {
  662. _html("<tr><td class=\"hicell\">$text");
  663. }
  664. if (@caps >= 2) {
  665. my %hash = (
  666. nick => $caps[1],
  667. per => $cpercent{$caps[1]}
  668. );
  669. my $text = $self->_template_text('allcaps2', %hash);
  670. _html("<br /><span class=\"small\">$text</span>");
  671. }
  672. _html("</td></tr>");
  673. } else {
  674. my $text = $self->_template_text('allcaps3');
  675. _html("<tr><td class=\"hicell\">$text</td></tr>");
  676. }
  677. }
  678. sub _violent
  679. {
  680. # They attacked others (words defined by $self->{cfg}->{violent})
  681. my $self = shift;
  682. my @aggressors = sort { $self->{stats}->{violence}{$b} <=> $self->{stats}->{violence}{$a} }
  683. keys %{ $self->{stats}->{violence} };
  684. @aggressors = $self->_istoponly(@aggressors);
  685. if(@aggressors) {
  686. my %hash = (
  687. nick => $aggressors[0],
  688. attacks => $self->{stats}->{violence}{$aggressors[0]},
  689. line => $self->_format_line($self->{stats}->{violencelines}{$aggressors[0]})
  690. );
  691. my $text = $self->_template_text('violent1', %hash);
  692. if($self->{cfg}->{showviolentlines}) {
  693. my $exttext = $self->_template_text('violenttext', %hash);
  694. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  695. } else {
  696. _html("<tr><td class=\"hicell\">$text");
  697. }
  698. if (@aggressors >= 2) {
  699. my %hash = (
  700. nick => $aggressors[1],
  701. attacks => $self->{stats}->{violence}{$aggressors[1]}
  702. );
  703. my $text = $self->_template_text('violent2', %hash);
  704. _html("<br /><span class=\"small\">$text</span>");
  705. }
  706. _html("</td></tr>");
  707. } else {
  708. my $text = $self->_template_text('violent3');
  709. _html("<tr><td class=\"hicell\">$text</td></tr>");
  710. }
  711. # They got attacked
  712. my @victims = sort { $self->{stats}->{attacked}{$b} <=> $self->{stats}->{attacked}{$a} }
  713. keys %{ $self->{stats}->{attacked} };
  714. @victims = $self->_istoponly(@victims);
  715. if(@victims) {
  716. my %hash = (
  717. nick => $victims[0],
  718. attacks => $self->{stats}->{attacked}{$victims[0]},
  719. line => $self->_format_line($self->{stats}->{attackedlines}{$victims[0]})
  720. );
  721. my $text = $self->_template_text('attacked1', %hash);
  722. if($self->{cfg}->{showviolentlines}) {
  723. my $exttext = $self->_template_text('attackedtext', %hash);
  724. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  725. } else {
  726. _html("<tr><td class=\"hicell\">$text");
  727. }
  728. if (@victims >= 2) {
  729. my %hash = (
  730. nick => $victims[1],
  731. attacks => $self->{stats}->{attacked}{$victims[1]}
  732. );
  733. my $text = $self->_template_text('attacked2', %hash);
  734. _html("<br /><span class=\"small\">$text</span>");
  735. }
  736. _html("</td></tr>");
  737. }
  738. }
  739. sub _gotkicks
  740. {
  741. # The persons who got kicked the most
  742. my $self = shift;
  743. my @gotkick = sort { $self->{stats}->{gotkicked}{$b} <=> $self->{stats}->{gotkicked}{$a} }
  744. keys %{ $self->{stats}->{gotkicked} };
  745. @gotkick = $self->_istoponly(@gotkick);
  746. if (@gotkick) {
  747. my %hash = (
  748. nick => $gotkick[0],
  749. kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
  750. line => $self->_format_line($self->{stats}->{kicklines}{$gotkick[0]})
  751. );
  752. my $text = $self->_template_text('gotkick1', %hash);
  753. if ($self->{cfg}->{showkickline}) {
  754. my $exttext = $self->_template_text('kicktext', %hash);
  755. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  756. } else {
  757. _html("<tr><td class=\"hicell\">$text");
  758. }
  759. if (@gotkick >= 2) {
  760. my %hash = (
  761. nick => $gotkick[1],
  762. kicks => $self->{stats}->{gotkicked}{$gotkick[1]}
  763. );
  764. my $text = $self->_template_text('gotkick2', %hash);
  765. _html("<br /><span class=\"small\">$text</span>");
  766. }
  767. _html("</td></tr>");
  768. }
  769. }
  770. sub _mostjoins
  771. {
  772. my $self = shift;
  773. my @joins = sort { $self->{stats}->{joins}{$b} <=> $self->{stats}->{joins}{$a} }
  774. keys %{ $self->{stats}->{joins} };
  775. @joins = $self->_istoponly(@joins);
  776. if (@joins) {
  777. my %hash = (
  778. nick => $joins[0],
  779. joins => $self->{stats}->{joins}{$joins[0]}
  780. );
  781. my $text = $self->_template_text('joins', %hash);
  782. _html("<tr><td class=\"hicell\">$text</td></tr>");
  783. }
  784. }
  785. sub _mostwords
  786. {
  787. # The person who got words the most
  788. my $self = shift;
  789. my @words = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  790. keys %{ $self->{stats}->{words} };
  791. @words = $self->_istoponly(@words);
  792. if (@words) {
  793. my %hash = (
  794. nick => $words[0],
  795. words => $self->{stats}->{words}{$words[0]}
  796. );
  797. my $text = $self->_template_text('words1', %hash);
  798. _html("<tr><td class=\"hicell\">$text");
  799. if (@words >= 2) {
  800. my %hash = (
  801. oldnick => $words[0],
  802. nick => $words[1],
  803. words => $self->{stats}->{words}{$words[1]}
  804. );
  805. my $text = $self->_template_text('words2', %hash);
  806. _html("<br /><span class=\"small\">$text</span>");
  807. }
  808. _html("</td></tr>");
  809. } else {
  810. my $text = $self->_template_text('kick3');
  811. _html("<tr><td class=\"hicell\">$text</td></tr>");
  812. }
  813. }
  814. sub _mostkicks
  815. {
  816. # The person who kicked the most
  817. my $self = shift;
  818. my @kicked = sort { $self->{stats}->{kicked}{$b} <=> $self->{stats}->{kicked}{$a} }
  819. keys %{ $self->{stats}->{kicked} };
  820. @kicked = $self->_istoponly(@kicked);
  821. if (@kicked) {
  822. my %hash = (
  823. nick => $kicked[0],
  824. kicked => $self->{stats}->{kicked}{$kicked[0]}
  825. );
  826. my $text = $self->_template_text('kick1', %hash);
  827. _html("<tr><td class=\"hicell\">$text");
  828. if (@kicked >= 2) {
  829. my %hash = (
  830. oldnick => $kicked[0],
  831. nick => $kicked[1],
  832. kicked => $self->{stats}->{kicked}{$kicked[1]}
  833. );
  834. my $text = $self->_template_text('kick2', %hash);
  835. _html("<br /><span class=\"small\">$text</span>");
  836. }
  837. _html("</td></tr>");
  838. } else {
  839. my $text = $self->_template_text('kick3');
  840. _html("<tr><td class=\"hicell\">$text</td></tr>");
  841. }
  842. }
  843. sub _mostmonologues
  844. {
  845. # The person who had the most monologues (speaking to himself)
  846. my $self = shift;
  847. my @monologue = sort { $self->{stats}->{monologues}{$b} <=> $self->{stats}->{monologues}{$a} }
  848. keys %{ $self->{stats}->{monologues} };
  849. @monologue = $self->_istoponly(@monologue);
  850. if (@monologue) {
  851. my %hash = (
  852. nick => $monologue[0],
  853. monos => $self->{stats}->{monologues}{$monologue[0]}
  854. );
  855. my $text = $self->_template_text('mono1', %hash);
  856. _html("<tr><td class=\"hicell\">$text");
  857. if (@monologue >= 2) {
  858. my %hash = (
  859. nick => $monologue[1],
  860. monos => $self->{stats}->{monologues}{$monologue[1]}
  861. );
  862. my $text = $self->_template_text('mono2', %hash);
  863. _html("<br /><span class=\"small\">$text</span>");
  864. }
  865. _html("</td></tr>");
  866. }
  867. }
  868. sub _linelengths
  869. {
  870. # The person(s) who wrote the longest lines
  871. my $self = shift;
  872. my %len;
  873. foreach my $nick (sort keys %{ $self->{stats}->{lengths} }) {
  874. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  875. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  876. $len{$nick} = $self->{stats}->{lengths}{$nick} / $self->{stats}->{lines}{$nick};
  877. $len{$nick} =~ s/(\.\d)\d+/$1/;
  878. }
  879. }
  880. }
  881. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  882. my $all_lines = 0;
  883. my $totallength;
  884. foreach my $nick (keys %{ $self->{stats}->{lines} }) {
  885. $all_lines += $self->{stats}->{lines}{$nick};
  886. $totallength += $self->{stats}->{lengths}{$nick};
  887. }
  888. my $totalaverage;
  889. if ($all_lines > 0) {
  890. $totalaverage = $totallength / $all_lines;
  891. $totalaverage =~ s/(\.\d)\d+/$1/;
  892. }
  893. if (@len) {
  894. my %hash = (
  895. nick => $len[0],
  896. letters => $len{$len[0]}
  897. );
  898. my $text = $self->_template_text('long1', %hash);
  899. _html("<tr><td class=\"hicell\">$text<br />");
  900. if (@len >= 2) {
  901. %hash = (
  902. avg => $totalaverage
  903. );
  904. $text = $self->_template_text('long2', %hash);
  905. _html("<span class=\"small\">$text</span></td></tr>");
  906. } else {
  907. _html("</td></tr>");
  908. }
  909. }
  910. # The person(s) who wrote the shortest lines
  911. if (@len) {
  912. my %hash = (
  913. nick => $len[$#len],
  914. letters => $len{$len[$#len]}
  915. );
  916. my $text = $self->_template_text('short1', %hash);
  917. _html("<tr><td class=\"hicell\">$text<br />");
  918. if (@len >= 2) {
  919. %hash = (
  920. nick => $len[$#len - 1],
  921. letters => $len{$len[$#len - 1]}
  922. );
  923. $text = $self->_template_text('short2', %hash);
  924. _html("<span class=\"small\">$text</span></td></tr>");
  925. } else {
  926. _html("</td></tr>");
  927. }
  928. }
  929. }
  930. sub _mostfoul
  931. {
  932. my $self = shift;
  933. my %spercent;
  934. foreach my $nick (sort keys %{ $self->{stats}->{foul} }) {
  935. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  936. if ($self->{stats}->{lines}{$nick} > 15) {
  937. $spercent{$nick} = $self->{stats}->{foul}{$nick} / $self->{stats}->{words}{$nick} * 100;
  938. my $dec = $self->{cfg}->{showfouldecimals};
  939. $dec = 1 if($dec < 0); # default to 1
  940. $spercent{$nick} =~ s/(\.\d{$dec})\d+/$1/;
  941. }
  942. }
  943. }
  944. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  945. if (@foul) {
  946. my %hash = (
  947. nick => $foul[0],
  948. per => $spercent{$foul[0]},
  949. line => $self->_format_line($self->{stats}{foullines}{$foul[0]}),
  950. );
  951. my $text = $self->_template_text('foul1', %hash);
  952. if($self->{cfg}->{showfoulline}) {
  953. my $exttext = $self->_template_text('foultext', %hash);
  954. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  955. } else {
  956. _html("<tr><td class=\"hicell\">$text");
  957. }
  958. if (@foul >= 2) {
  959. my %hash = (
  960. nick => $foul[1],
  961. per => $spercent{$foul[1]}
  962. );
  963. my $text = $self->_template_text('foul2', %hash);
  964. _html("<br /><span class=\"small\">$text</span>");
  965. }
  966. _html("</td></tr>");
  967. } else {
  968. my $text = $self->_template_text('foul3');
  969. _html("<tr><td class=\"hicell\">$text</td></tr>");
  970. }
  971. }
  972. sub _mostsad
  973. {
  974. my $self = shift;
  975. my %spercent;
  976. foreach my $nick (sort keys %{ $self->{stats}->{frowns} }) {
  977. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  978. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  979. $spercent{$nick} = $self->{stats}->{frowns}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  980. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  981. }
  982. }
  983. }
  984. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  985. if (@sadface) {
  986. my %hash = (
  987. nick => $sadface[0],
  988. per => $spercent{$sadface[0]}
  989. );
  990. my $text = $self->_template_text('sad1', %hash);
  991. _html("<tr><td class=\"hicell\">$text");
  992. if (@sadface >= 2) {
  993. my %hash = (
  994. nick => $sadface[1],
  995. per => $spercent{$sadface[1]}
  996. );
  997. my $text = $self->_template_text('sad2', %hash);
  998. _html("<br /><span class=\"small\">$text</span>");
  999. }
  1000. _html("</td></tr>");
  1001. } else {
  1002. my $text = $self->_template_text('sad3');
  1003. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1004. }
  1005. }
  1006. sub _mostop
  1007. {
  1008. my $self = shift;
  1009. my @ops = sort { $self->{stats}->{gaveops}{$b} <=> $self->{stats}->{gaveops}{$a} }
  1010. keys %{ $self->{stats}->{gaveops} };
  1011. @ops = $self->_istoponly(@ops);
  1012. my @deops = sort { $self->{stats}->{tookops}{$b} <=> $self->{stats}->{tookops}{$a} }
  1013. keys %{ $self->{stats}->{tookops} };
  1014. @deops = $self->_istoponly(@deops);
  1015. if (@ops) {
  1016. my %hash = (
  1017. nick => $ops[0],
  1018. ops => $self->{stats}->{gaveops}{$ops[0]}
  1019. );
  1020. my $text = $self->_template_text('mostop1', %hash);
  1021. _html("<tr><td class=\"hicell\">$text");
  1022. if (@ops >= 2) {
  1023. my %hash = (
  1024. nick => $ops[1],
  1025. ops => $self->{stats}->{gaveops}{$ops[1]}
  1026. );
  1027. my $text = $self->_template_text('mostop2', %hash);
  1028. _html("<br /><span class=\"small\">$text</span>");
  1029. }
  1030. _html("</td></tr>");
  1031. } else {
  1032. my $text = $self->_template_text('mostop3');
  1033. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1034. }
  1035. if (@deops) {
  1036. my %hash = (
  1037. nick => $deops[0],
  1038. deops => $self->{stats}->{tookops}{$deops[0]}
  1039. );
  1040. my $text = $self->_template_text('mostdeop1', %hash);
  1041. _html("<tr><td class=\"hicell\">$text");
  1042. if (@deops >= 2) {
  1043. my %hash = (
  1044. nick => $deops[1],
  1045. deops => $self->{stats}->{tookops}{$deops[1]}
  1046. );
  1047. my $text = $self->_template_text('mostdeop2', %hash);
  1048. _html("<br /><span class=\"small\">$text</span>");
  1049. }
  1050. _html("</td></tr>");
  1051. } else {
  1052. my $text = $self->_template_text('mostdeop3');
  1053. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1054. }
  1055. }
  1056. sub _mostvoice
  1057. {
  1058. my $self = shift;
  1059. my @voice = sort { $self->{stats}->{gavevoice}{$b} <=> $self->{stats}->{gavevoice}{$a} }
  1060. keys %{ $self->{stats}->{gavevoice} };
  1061. @voice = $self->_istoponly(@voice);
  1062. my @devoice = sort { $self->{stats}->{tookvoice}{$b} <=> $self->{stats}->{tookvoice}{$a} }
  1063. keys %{ $self->{stats}->{tookvoice} };
  1064. @devoice = $self->_istoponly(@devoice);
  1065. if (@voice) {
  1066. my %hash = (
  1067. nick => $voice[0],
  1068. voices => $self->{stats}->{gavevoice}{$voice[0]}
  1069. );
  1070. my $text = $self->_template_text('mostvoice1', %hash);
  1071. _html("<tr><td class=\"hicell\">$text");
  1072. if (@voice >= 2) {
  1073. my %hash = (
  1074. nick => $voice[1],
  1075. voices => $self->{stats}->{gavevoice}{$voice[1]}
  1076. );
  1077. my $text = $self->_template_text('mostvoice2', %hash);
  1078. _html("<br /><span class=\"small\">$text</span>");
  1079. }
  1080. _html("</td></tr>");
  1081. } else {
  1082. my $text = $self->_template_text('mostvoice3');
  1083. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1084. }
  1085. if (@devoice) {
  1086. my %hash = (
  1087. nick => $devoice[0],
  1088. devoices => $self->{stats}->{tookvoice}{$devoice[0]}
  1089. );
  1090. my $text = $self->_template_text('mostdevoice1', %hash);
  1091. _html("<tr><td class=\"hicell\">$text");
  1092. if (@devoice >= 2) {
  1093. my %hash = (
  1094. nick => $devoice[1],
  1095. devoices => $self->{stats}->{tookvoice}{$devoice[1]}
  1096. );
  1097. my $text = $self->_template_text('mostdevoice2', %hash);
  1098. _html("<br /><span class=\"small\">$text</span>");
  1099. }
  1100. _html("</td></tr>");
  1101. } else {
  1102. my $text = $self->_template_text('mostdevoice3');
  1103. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1104. }
  1105. }
  1106. sub _mosthalfop
  1107. {
  1108. my $self = shift;
  1109. my @halfops = sort { $self->{stats}->{gavehalfops}{$b} <=> $self->{stats}->{gavehalfops}{$a} }
  1110. keys %{ $self->{stats}->{gavehalfops} };
  1111. @halfops = $self->_istoponly(@halfops);
  1112. my @dehalfops = sort { $self->{stats}->{tookhalfops}{$b} <=> $self->{stats}->{tookhalfops}{$a} }
  1113. keys %{ $self->{stats}->{tookhalfops} };
  1114. @dehalfops = $self->_istoponly(@dehalfops);
  1115. if (@halfops) {
  1116. my %hash = (
  1117. nick => $halfops[0],
  1118. halfops => $self->{stats}->{gavehalfops}{$halfops[0]}
  1119. );
  1120. my $text = $self->_template_text('mosthalfop1', %hash);
  1121. _html("<tr><td class=\"hicell\">$text");
  1122. if (@halfops >= 2) {
  1123. my %hash = (
  1124. nick => $halfops[1],
  1125. halfops => $self->{stats}->{gavehalfops}{$halfops[1]}
  1126. );
  1127. my $text = $self->_template_text('mosthalfop2', %hash);
  1128. _html("<br /><span class=\"small\">$text</span>");
  1129. }
  1130. _html("</td></tr>");
  1131. } else {
  1132. my $text = $self->_template_text('mosthalfop3');
  1133. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1134. }
  1135. if (@dehalfops) {
  1136. my %hash = (
  1137. nick => $dehalfops[0],
  1138. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[0]}
  1139. );
  1140. my $text = $self->_template_text('mostdehalfop1', %hash);
  1141. _html("<tr><td class=\"hicell\">$text");
  1142. if (@dehalfops >= 2) {
  1143. my %hash = (
  1144. nick => $dehalfops[1],
  1145. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[1]}
  1146. );
  1147. my $text = $self->_template_text('mostdehalfop2', %hash);
  1148. _html("<br /><span class=\"small\">$text</span>");
  1149. }
  1150. _html("</td></tr>");
  1151. } else {
  1152. my $text = $self->_template_text('mostdehalfop3');
  1153. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1154. }
  1155. }
  1156. sub _mostactions
  1157. {
  1158. # The person who did the most /me's
  1159. my $self = shift;
  1160. my @actions = sort { $self->{stats}->{actions}{$b} <=> $self->{stats}->{actions}{$a} }
  1161. keys %{ $self->{stats}->{actions} };
  1162. @actions = $self->_istoponly(@actions);
  1163. if (@actions) {
  1164. my %linehash =
  1165. my %hash = (
  1166. nick => $actions[0],
  1167. actions => $self->{stats}->{actions}{$actions[0]},
  1168. line => $self->_format_line($self->{stats}->{actionlines}{$actions[0]})
  1169. );
  1170. my $text = $self->_template_text('action1', %hash);
  1171. if($self->{cfg}->{showactionline}) {
  1172. my $exttext = $self->_template_text('actiontext', %hash);
  1173. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  1174. } else {
  1175. _html("<tr><td class=\"hicell\">$text");
  1176. }
  1177. if (@actions >= 2) {
  1178. my %hash = (
  1179. nick => $actions[1],
  1180. actions => $self->{stats}->{actions}{$actions[1]}
  1181. );
  1182. my $text = $self->_template_text('action2', %hash);
  1183. _html("<br /><span class=\"small\">$text</span>");
  1184. }
  1185. _html("</td></tr>");
  1186. } else {
  1187. my $text = $self->_template_text('action3');
  1188. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1189. }
  1190. }
  1191. sub _mostsmiles
  1192. {
  1193. # The person(s) who smiled the most :-)
  1194. my $self = shift;
  1195. my %spercent;
  1196. foreach my $nick (sort keys %{ $self->{stats}->{smiles} }) {
  1197. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1198. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  1199. $spercent{$nick} = $self->{stats}->{smiles}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  1200. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1201. }
  1202. }
  1203. }
  1204. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1205. if (@smiles) {
  1206. my %hash = (
  1207. nick => $smiles[0],
  1208. per => $spercent{$smiles[0]}
  1209. );
  1210. my $text = $self->_template_text('smiles1', %hash);
  1211. _html("<tr><td class=\"hicell\">$text");
  1212. if (@smiles >= 2) {
  1213. my %hash = (
  1214. nick => $smiles[1],
  1215. per => $spercent{$smiles[1]}
  1216. );
  1217. my $text = $self->_template_text('smiles2', %hash);
  1218. _html("<br /><span class=\"small\">$text</span>");
  1219. }
  1220. _html("</td></tr>");
  1221. } else {
  1222. my $text = $self->_template_text('smiles3');
  1223. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1224. }
  1225. }
  1226. sub _lasttopics
  1227. {
  1228. my $self = shift;
  1229. if ($self->{stats}->{topics}) {
  1230. my %topic_seen;
  1231. my %hash = (
  1232. total => scalar @{ $self->{stats}->{topics} }
  1233. );
  1234. my $ltopic = $#{ $self->{stats}->{topics} };
  1235. my $tlimit = 0;
  1236. $self->{cfg}->{topichistory} -= 1;
  1237. if ($ltopic > $self->{cfg}->{topichistory}) {
  1238. $tlimit = $ltopic - $self->{cfg}->{topichistory};
  1239. }
  1240. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1241. my $topic = $self->{stats}->{topics}[$i]{topic};
  1242. # This code makes sure that we don't see the same topic twice
  1243. next if ($topic_seen{$topic});
  1244. $topic_seen{$topic} = 1;
  1245. # Strip off the quotes (')
  1246. $topic =~ s/^\'(.*)\'$/$1/;
  1247. my $nick = $self->{stats}->{topics}[$i]{nick};
  1248. my $hour = $self->{stats}->{topics}[$i]{hour};
  1249. my $min = $self->{stats}->{topics}[$i]{min};
  1250. $hash{nick} = $nick;
  1251. $hash{time} = "$hour:$min";
  1252. _html('<tr><td class="hicell"><i>' . $self->_format_line($topic) . '</i></td>');
  1253. _html('<td class="hicell"><b>' . $self->_template_text('bylinetopic', %hash) . '</b></td></tr>');
  1254. }
  1255. _html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . $self->_template_text('totaltopic', %hash) . "</td></tr>");
  1256. } else {
  1257. _html("<tr><td class=\"hicell\">" . $self->_template_text('notopic') ."</td></tr>");
  1258. }
  1259. }
  1260. sub _template_text
  1261. {
  1262. # This function is for the homemade template system. It receives a name
  1263. # of a template and a hash with the fields in the template to update to
  1264. # its corresponding value
  1265. my $self = shift;
  1266. my $template = shift;
  1267. my %hash = @_;
  1268. my $text;
  1269. unless ($text = $self->{tmps}->{lc($self->{cfg}->{lang})}{$template}) {
  1270. # Fall back to English if the language template doesn't exist
  1271. if ($text = $self->{tmps}->{en}{$template}) {
  1272. print "Note: No translation in '$self->{cfg}->{lang}' for '$template' - falling back to English..\n"
  1273. unless ($self->{cfg}->{silent});
  1274. } else {
  1275. die("No such template '$template' in language file.\n");
  1276. }
  1277. }
  1278. if($self->{iconv}) {
  1279. $text = $self->{iconv}->convert($text);
  1280. die("Could not convert charset for template '$template'.\n") unless $text;
  1281. }
  1282. $hash{channel} = $self->{cfg}->{channel};
  1283. # the nick is sanitized here, everything else outside of _template_text
  1284. $hash{nick} = $self->_format_word($hash{nick}) if $hash{nick};
  1285. foreach my $key (sort keys %hash) {
  1286. $text =~ s/\[:$key\]/$hash{$key}/;
  1287. }
  1288. if ($text =~ /\[:[^:]*?:[^:]*?:[^:]*?:\]/o) {
  1289. $text =~ s/\[:([^:]*?):([^:]*?):([^:]*?):\]/$self->_get_subst($1,$2,$3,\%hash)/geo;
  1290. }
  1291. if ($text =~ /\[:[^:]*?:[^:]*?:]/o) {
  1292. $text =~ s/\[:([^:]*?):([^:]*?):]/$self->_get_subst($1,$2,undef,\%hash)/geo;
  1293. }
  1294. return $text;
  1295. }
  1296. sub _format_word
  1297. {
  1298. # This function formats a word -- should ONLY be called on words used alone (EG: not whole line printed)
  1299. my ($self, $word, $nick) = @_; # nick is only defined for user links in top table
  1300. $word = htmlentities($word, $self->{cfg}->{charset});
  1301. $word = $self->_replace_links($word, $nick);
  1302. return $word;
  1303. }
  1304. sub _format_line
  1305. {
  1306. # This function formats a action/normal line to be more readable, and calls any other function
  1307. # that should be executed on every line.
  1308. my ($self, $line) = @_;
  1309. my $hashref;
  1310. if ($hashref = $self->{cfg}->{analyzer}->{parser}->normalline($line)) {
  1311. $line = '<' . $hashref->{nick} . '> ' . $hashref->{saying};
  1312. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->actionline($line)) {
  1313. $line = '* ' . $hashref->{nick} . ' ' . $hashref->{saying};
  1314. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->thirdline($line)) {
  1315. if (defined($hashref->{kicker})) {
  1316. $line = '*** ' . $hashref->{nick} . ' was kicked by ' . $hashref->{kicker};
  1317. $line .= ' (' . $hashref->{kicktext} . ')'
  1318. if (defined($hashref->{kicktext}));
  1319. } elsif (defined($hashref->{newtopic})) {
  1320. $line = '*** ' . $hashref->{nick} . ' changes topic to \'' . $hashref->{newtopic} . '\'';
  1321. } elsif (defined($hashref->{newmode})) {
  1322. $line = '*** ' . $hashref->{nick} . ' sets mode ' . $hashref->{newmode};
  1323. $line .= ' ' . $hashref->{modechanges}
  1324. if (defined($hashref->{kicktext}));
  1325. } elsif (defined($hashref->{newjoin})) {
  1326. $line = '*** Joins: ' . $hashref->{nick};
  1327. } elsif (defined($hashref->{newnick})) {
  1328. $line = '*** ' . $hashref->{nick} . ' is now known as ' . $hashref->{newnick};
  1329. } elsif (defined($hashref->{newtopic})) {
  1330. $line = '*** ' . $hashref->{nick} . ' changes topic to: ' . $hashref->{newtopic};
  1331. }
  1332. }
  1333. $line = htmlentities($line, $self->{cfg}->{charset});
  1334. $line = $self->_replace_links($line);
  1335. return $line;
  1336. }
  1337. sub _get_subst
  1338. {
  1339. # This function looks at the user definition and see if there is sex
  1340. # defined. If yes, return the appropriate value. If no, just return the
  1341. # default he/she value.
  1342. my $self = shift;
  1343. my ($m,$f,$d,$hash) = @_;
  1344. if ($hash->{nick} && $self->{users}->{sex}{$hash->{nick}}) {
  1345. if ($self->{users}->{sex}{$hash->{nick}} eq 'm') {
  1346. return $m;
  1347. } elsif ($self->{users}->{sex}{$hash->{nick}} eq 'f') {
  1348. return $f;
  1349. }
  1350. }
  1351. return defined($d) ? $d : "$m/$f";
  1352. }
  1353. sub _mostusedword
  1354. {
  1355. # Word usage statistics
  1356. my $self = shift;
  1357. my %usages;
  1358. foreach my $word (keys %{ $self->{stats}->{wordcounts} }) {
  1359. # Skip people's nicks.
  1360. next if is_nick($word);
  1361. next if (length($word) < $self->{cfg}->{wordlength});
  1362. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1363. }
  1364. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1365. if (@popular) {
  1366. $self->_headline($self->_template_text('mostwordstopic'));
  1367. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1368. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('word') . "</b></td>");
  1369. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1370. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1371. my $count = 0;
  1372. for(my $i = 0; $count < $self->{cfg}->{wordhistory}; $i++) {
  1373. last unless $i < $#popular;
  1374. # Skip nicks. It's far more efficient to do this here than when
  1375. # @popular is created.
  1376. next if is_ignored($popular[$i]);
  1377. my $a = $count + 1;
  1378. my $popular = $self->_format_word($popular[$i]);
  1379. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1380. my $lastused = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]});
  1381. my $class;
  1382. if ($a == 1) {
  1383. $class = 'hirankc';
  1384. } else {
  1385. $class = 'rankc';
  1386. }
  1387. _html("<tr><td class=\"$class\">$a</td>");
  1388. _html("<td class=\"hicell\">$popular</td>");
  1389. _html("<td class=\"hicell\">$wordcount</td>");
  1390. _html("<td class=\"hicell\">$lastused</td>");
  1391. _html("</tr>");
  1392. $count++;
  1393. }
  1394. _html("</table>");
  1395. }
  1396. }
  1397. sub _mostwordsperline
  1398. {
  1399. # The person who got the most words per line
  1400. my $self = shift;
  1401. my %wpl = ();
  1402. my $numlines = 0;
  1403. my ($avg, $numwords);
  1404. foreach my $nick (keys %{ $self->{stats}->{words} }) {
  1405. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1406. $wpl{$nick} = sprintf("%.2f", $self->{stats}->{words}{$nick}/$self->{stats}->{lines}{$nick});
  1407. $numlines += $self->{stats}->{lines}{$nick};
  1408. $numwords += $self->{stats}->{words}{$nick};
  1409. }
  1410. }
  1411. if ($numlines > 0) {
  1412. $avg = sprintf("%.2f", $numwords/$numlines);
  1413. }
  1414. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  1415. if (@wpl) {
  1416. my %hash = (
  1417. nick => $wpl[0],
  1418. wpl => $wpl{$wpl[0]}
  1419. );
  1420. my $text = $self->_template_text('wpl1', %hash);
  1421. _html("<tr><td class=\"hicell\">$text");
  1422. $hash{avg} = $avg;
  1423. $text = $self->_template_text('wpl2', %hash);
  1424. _html("<br /><span class=\"small\">$text</span>");
  1425. _html("</td></tr>");
  1426. }
  1427. }
  1428. sub _mostreferencednicks
  1429. {
  1430. # List showing the most referenced nicks
  1431. my $self = shift;
  1432. my %usages;
  1433. foreach my $word (sort keys %{ $self->{stats}->{wordcounts} }) {
  1434. next if !exists $self->{stats}->{lines}{$word};
  1435. next if is_ignored($word);
  1436. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1437. }
  1438. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1439. if (@popular) {
  1440. $self->_headline($self->_template_text('referencetopic'));
  1441. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1442. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>");
  1443. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1444. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1445. for(my $i = 0; $i < $self->{cfg}->{nickhistory}; $i++) {
  1446. last unless $i <= $#popular;
  1447. my $a = $i + 1;
  1448. my $popular = $self->_format_word($popular[$i]);
  1449. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1450. my $lastused = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]});
  1451. my $class;
  1452. if ($a == 1) {
  1453. $class = 'hirankc';
  1454. } else {
  1455. $class = 'rankc';
  1456. }
  1457. _html("<tr><td class=\"$class\">$a</td>");
  1458. _html("<td class=\"hicell\">$popular</td>");
  1459. _html("<td class=\"hicell\">$wordcount</td>");
  1460. _html("<td class=\"hicell\">$lastused</td>");
  1461. _html("</tr>");
  1462. }
  1463. _html("</table>");
  1464. }
  1465. }
  1466. sub _mosturls
  1467. {
  1468. # List showing the most referenced URLs
  1469. my $self = shift;
  1470. my @sorturls = sort { $self->{stats}->{urlcounts}{$b} <=> $self->{stats}->{urlcounts}{$a} }
  1471. keys %{ $self->{stats}->{urlcounts} };
  1472. if (@sorturls) {
  1473. $self->_headline($self->_template_text('urlstopic'));
  1474. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1475. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('url') . "</b></td>");
  1476. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1477. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1478. for(my $i = 0; $i < $self->{cfg}->{urlhistory}; $i++) {
  1479. last unless $i < @sorturls;
  1480. my $a = $i + 1;
  1481. my $urlcount = $self->{stats}->{urlcounts}{$sorturls[$i]};
  1482. my $lastused = $self->{stats}->{urlnicks}{$sorturls[$i]};
  1483. my $printurl = $sorturls[$i];
  1484. if (length($printurl) > 60) {
  1485. $printurl = substr($printurl, 0, 60);
  1486. }
  1487. $printurl = htmlentities($printurl, $self->{cfg}->{charset});
  1488. my $linkurl = urlencode($sorturls[$i]);
  1489. my $class;
  1490. if ($a == 1) {
  1491. $class = 'hirankc';
  1492. } else {
  1493. $class = 'rankc';
  1494. }
  1495. _html("<tr><td class=\"$class\">$a</td>");
  1496. _html("<td class=\"hicell\"><a href=\"$linkurl\">$printurl</a></td>");
  1497. _html("<td class=\"hicell\">$urlcount</td>");
  1498. _html("<td class=\"hicell\">$lastused</td>");
  1499. _html("</tr>");
  1500. }
  1501. _html("</table>");
  1502. }
  1503. }
  1504. sub _legend
  1505. {
  1506. # A legend showing the timebars and their associated time.
  1507. my $self = shift;
  1508. _html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  1509. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"0-5\" /> = 0-5</td>");
  1510. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"6-11\" /> = 6-11</td>");
  1511. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"12-17\" /> = 12-17</td>");
  1512. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"18-23\" /> = 18-23</td>");
  1513. _html("</tr></table>\n");
  1514. }
  1515. sub _replace_url # used internally by _replace_links
  1516. {
  1517. my ($self, $url, $www, $ftp, $text) = @_;
  1518. $url = "http://$url" if $www;
  1519. $url = "ftp://$url" if $ftp;
  1520. my $texturl = $self->_template_text("newwindow");
  1521. return "<a href=\"$url\" target=\"_blank\" title=\"$texturl $url\">" . $self->_split_long_text($text) . '</a>';
  1522. }
  1523. sub _replace_email # used internally by _replace_links
  1524. {
  1525. my ($self, $mailto, $user, $domain, $nick) = @_;
  1526. $mailto = '' if $nick or not $mailto;
  1527. $nick ||= "$user&#64;$domain"; # obfuscate mail address
  1528. my $textmail = $self->_template_text("mailto");
  1529. return "<a href=\"mailto:$user&#64;$domain\" title=\"$textmail $nick\">" . $self->_split_long_text($mailto . $nick) . "<\/a>";
  1530. }
  1531. sub _replace_links
  1532. {
  1533. # replace URLs and email addresses by links
  1534. my ($self, $str, $nick) = @_; # nick is only defined for user links in top table
  1535. # Regular expressions are taken from match_urls() and match_email() in
  1536. # Common.pm
  1537. my (@str) = split(/ /,$str);
  1538. foreach (@str) {
  1539. s/((?:(?:https?|ftp|telnet|news):\/\/|(?:(?:(www)|(ftp))[\w-]*\.))[-\w\/~\@:]+\.\S+[\w\/])/$self->_replace_url($1, $2, $3, $nick || $1)/egio
  1540. or s/(mailto:)?([-\w.]+)@([-\w]+\.[-\w.]+)/$self->_replace_email($1, $2, $3, $nick)/egio
  1541. or $_ = $self->_split_long_text($_);
  1542. }
  1543. return join(' ', @str);
  1544. }
  1545. sub _split_long_text
  1546. {
  1547. my ($self, $str) = @_;
  1548. $str =~ s/(\S{$self->{cfg}->{quotewidth}})(?!\s)/$1-<br \/>/og;
  1549. return($str);
  1550. }
  1551. sub _user_linetimes
  1552. {
  1553. my $self = shift;
  1554. my $nick = shift;
  1555. my $top = shift;
  1556. my $bar = "";
  1557. my $len = ($self->{stats}->{lines}{$nick} / $self->{stats}->{lines}{$top}) * 100;
  1558. for (my $i = 0; $i <= 3; $i++) {
  1559. next if not defined $self->{stats}->{line_times}{$nick}[$i];
  1560. my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * $len);
  1561. if ($w) {
  1562. my $pic = 'pic_h_'.(6*$i);
  1563. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"$self->{stats}->{line_times}{$nick}[$i]\" />";
  1564. }
  1565. }
  1566. return "$bar&nbsp;$self->{stats}->{lines}{$nick}";
  1567. }
  1568. sub _user_wordtimes
  1569. {
  1570. my $self = shift;
  1571. my $nick = shift;
  1572. my $top = shift;
  1573. $self->{stats}->{words}{$nick} ||= 0;
  1574. my $len = ($self->{stats}->{words}{$nick} / $self->{stats}->{words}{$top}) * 100;
  1575. my $bar = "";
  1576. for (my $i = 0; $i <= 3; $i++) {
  1577. next if not defined $self->{stats}->{word_times}{$nick}[$i];
  1578. my $w = int(($self->{stats}->{word_times}{$nick}[$i] / $self->{stats}->{words}{$nick}) * $len);
  1579. if ($w) {
  1580. my $pic = 'pic_h_'.(6*$i);
  1581. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1582. }
  1583. }
  1584. return "$bar&nbsp;$self->{stats}->{words}{$nick}";
  1585. }
  1586. sub _user_times
  1587. {
  1588. my $self = shift;
  1589. my ($nick) = @_;
  1590. my $bar = "";
  1591. my $itemstat = ($self->{cfg}->{sortbywords} ? 'words' : 'lines');
  1592. my $timestat = ($self->{cfg}->{sortbywords} ? 'word_times' : 'line_times');
  1593. for (my $i = 0; $i <= 3; $i++) {
  1594. next if not defined $self->{stats}->{$timestat}{$nick}[$i];
  1595. my $w = int(($self->{stats}->{$timestat}{$nick}[$i] / $self->{stats}->{$itemstat}{$nick}) * 40);
  1596. if ($w) {
  1597. my $pic = 'pic_h_'.(6*$i);
  1598. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\" />";
  1599. }
  1600. }
  1601. return $bar;
  1602. }
  1603. sub _user_pic
  1604. {
  1605. my $self = shift;
  1606. my $nick = shift;
  1607. my $color = shift;
  1608. return unless $self->{users}->{userpics}{$nick} or $self->{cfg}->{defaultpic};
  1609. my $rowspan = $self->{cfg}->{userpics} ? " rowspan=\"$self->{cfg}->{userpics}\"" : "";
  1610. my $output = "<td style=\"background-color: $color\" align=\"center\" valign=\"middle\"$rowspan>";
  1611. my $biguserpic = $self->{users}->{biguserpics}{$nick};
  1612. if ($biguserpic) {
  1613. $biguserpic = $self->{cfg}->{imagepath} .
  1614. randomglob($biguserpic, $self->{cfg}->{imageglobpath})
  1615. if $biguserpic !~ /^http:\/\//i;
  1616. $output .= "<a href=\"$biguserpic\">";
  1617. }
  1618. my $pic = $self->{users}->{userpics}{$nick} || $self->{cfg}->{defaultpic};
  1619. $pic = $self->{cfg}->{imagepath} . randomglob($pic, $self->{cfg}->{imageglobpath})
  1620. unless $pic =~ /^http:\/\//i;
  1621. my $height = $self->{cfg}->{picheight} ? " height=\"$self->{cfg}->{picheight}\"" : "";
  1622. my $width = $self->{cfg}->{picwidth} ? " width=\"$self->{cfg}->{picwidth}\"" : "";
  1623. my $alt = $self->{users}->{userpics}{$nick} ? " alt=\"$nick\" title=\"$nick\"" : "";
  1624. my $border = $biguserpic ? ' border="0"' : '';
  1625. $output .= "<img src=\"$pic\"$width$height$alt$border />";
  1626. $output .= "</a>" if $biguserpic;
  1627. _html("$output</td>");
  1628. }
  1629. sub _mostnicks
  1630. {
  1631. # List showing the user with most used nicks
  1632. my $self = shift;
  1633. my @sortnicks = sort { keys %{ $self->{stats}->{nicks}->{$b} } <=> keys %{ $self->{stats}->{nicks}->{$a} } }
  1634. keys %{ $self->{stats}->{nicks} };
  1635. if (keys %{ $self->{stats}->{nicks}->{$sortnicks[0]} } > 1) {
  1636. $self->_headline($self->_template_text('mostnickstopic'));
  1637. my $names1 = $self->_template_text('names1');
  1638. my $names2 = $self->_template_text('names2');
  1639. my $nick_txt = $self->_template_text('nick');
  1640. my $names_txt = $self->_template_text('names');
  1641. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1642. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>$nick_txt</b></td>");
  1643. _html("<td class=\"tdtop\"><b>$names_txt</b></td></tr>");
  1644. my $a = 0;
  1645. foreach my $nick (@sortnicks) {
  1646. next if is_ignored($nick);
  1647. my $nickcount = keys %{ $self->{stats}->{nicks}->{$nick} };
  1648. my $nickused = join(", ", values %{ $self->{stats}->{nicks}->{$nick} });
  1649. last unless ($nickcount > 1);
  1650. $a++;
  1651. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1652. my $n = $nickcount > 1 ? $names1 : $names2;
  1653. _html("<tr><td class=\"$class\">$a</td>");
  1654. if ($self->{cfg}->{mostnicksverbose}) {
  1655. _html("<td class=\"hicell\">$nick ($nickcount $n)</td>");
  1656. _html("<td class=\"hicell\" valign='top'>$nickused</td>");
  1657. } else {
  1658. _html("<td class=\"hicell\">$nick</td>");
  1659. _html("<td class=\"hicell\" valign='top'>$nickcount $n</td>");
  1660. }
  1661. _html("</tr>");
  1662. last if $a >= $self->{cfg}->{mostnickshistory};
  1663. }
  1664. _html("</table>");
  1665. }
  1666. }
  1667. sub _mostactivebyhour
  1668. {
  1669. # Charts for most active nicks by hour (0-5, 6-11, 12-17, 18-23)
  1670. my $self = shift;
  1671. my $sortnicks;
  1672. my $lastline=-1;
  1673. my $maxlines=0;
  1674. foreach my $period (0,1,2,3) {
  1675. my @sortnicks =
  1676. sort
  1677. {
  1678. (defined $self->{stats}->{line_times}{$b}[$period]?$self->{stats}->{line_times}{$b}[$period]:0)
  1679. <=>
  1680. (defined $self->{stats}->{line_times}{$a}[$period]?$self->{stats}->{line_times}{$a}[$period]:0)
  1681. }
  1682. keys %{ $self->{stats}->{line_times} } ;
  1683. for(my $i = 0; $i < $self->{cfg}->{activenicksbyhour}; $i++) {
  1684. next if ! $sortnicks[$i];
  1685. next if is_ignored($sortnicks[$i]);
  1686. last unless $i < @sortnicks;
  1687. my $nick=$sortnicks[$i];
  1688. my $count=$self->{stats}->{line_times}{$nick}[$period] || 0;
  1689. last unless $nick;
  1690. last unless $count;
  1691. $sortnicks->[$period][$i]=$nick;
  1692. if ($lastline<$i) {
  1693. $lastline=$i;
  1694. }
  1695. if ($maxlines<$count) {
  1696. $maxlines=$count;
  1697. }
  1698. }
  1699. }
  1700. if ($lastline>=0) {
  1701. $self->_headline($self->_template_text('activenickbyhourtopic'));
  1702. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1703. _html("<td>&nbsp;</td>");
  1704. _html("<td class=\"tdtop\"><b>0-5</b></td>");
  1705. _html("<td class=\"tdtop\"><b>6-11</b></td>");
  1706. _html("<td class=\"tdtop\"><b>12-17</b></td>");
  1707. _html("<td class=\"tdtop\"><b>18-23</b></td>");
  1708. _html("</tr>");
  1709. for(my $i = 0; $i <= $lastline; $i++) {
  1710. my $a = $i + 1;
  1711. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1712. _html("<tr><td class=\"$class\">$a</td>");
  1713. foreach my $period (0,1,2,3) {
  1714. my $nick=$sortnicks->[$period][$i];
  1715. if ($nick) {
  1716. my $count=$self->{stats}->{line_times}{$nick}[$period];
  1717. if ($count) {
  1718. _html("<td class=\"hicell\">");
  1719. if ($self->{cfg}->{showmostactivebyhourgraph}) {
  1720. my $pic = 'pic_h_'.(6*$period);
  1721. my $w = int(($count / $maxlines) * 100) || 1;
  1722. _html("<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />");
  1723. }
  1724. _html($self->_format_word($nick)." - ".$count);
  1725. _html("</td>");
  1726. } else {
  1727. _html("<td class=\"hicell\">&nbsp;</td>");
  1728. }
  1729. } else {
  1730. _html("<td class=\"hicell\">&nbsp;</td>");
  1731. }
  1732. }
  1733. _html("</tr>");
  1734. }
  1735. _html("</table>");
  1736. }
  1737. }
  1738. sub _topactive {
  1739. my $self = shift;
  1740. my @top_active;
  1741. my $top_nicks;
  1742. if ($self->{cfg}->{sortbywords}) {
  1743. @top_active = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  1744. keys %{ $self->{stats}->{words} };
  1745. $top_nicks = scalar keys %{ $self->{stats}->{words} };
  1746. } else {
  1747. @top_active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} }
  1748. keys %{ $self->{stats}->{lines} };
  1749. $top_nicks = scalar keys %{ $self->{stats}->{lines} };
  1750. }
  1751. if ($self->{cfg}->{activenicks} > $top_nicks) {
  1752. $self->{cfg}->{activenicks} = $top_nicks;
  1753. }
  1754. if (($self->{cfg}->{activenicks}+$self->{cfg}->{activenicks2}) > $top_nicks) {
  1755. $self->{cfg}->{activenicks2} = $top_nicks-$self->{cfg}->{activenicks};
  1756. }
  1757. (@top_active) = @top_active[0..($self->{cfg}->{activenicks}+$self->{cfg}->{activenicks2}-1)];
  1758. $self->{stats}->{topactive_lines} = @top_active ? $self->{stats}->{lines}{$top_active[0]} : 1;
  1759. foreach (@top_active) {
  1760. $self->{topactive}{$_} = 1;
  1761. }
  1762. }
  1763. sub _istoponly {
  1764. my $self = shift;
  1765. my (@nicks_tmp) = @_;
  1766. my @nicks;
  1767. my $cnt=0;
  1768. if ($self->{cfg}->{showonlytop}) {
  1769. foreach my $nick (@nicks_tmp) {
  1770. if ($self->{topactive}{$nick}) {
  1771. push(@nicks, $nick);
  1772. }
  1773. }
  1774. return(@nicks);
  1775. } else {
  1776. return(@nicks_tmp);
  1777. }
  1778. }
  1779. 1;
  1780. __END__
  1781. =head1 NAME
  1782. Pisg::HTMLGenerator - class to create a static HTML page out of data parsed
  1783. =head1 DESCRIPTION
  1784. C<Pisg::HTMLGenerator> uses the hash returned by Pisg::Parser::Logfile and turns it into a static HTML page.
  1785. =head1 SYNOPSIS
  1786. use Pisg::HTMLGenerator;
  1787. $generator = new Pisg::HTMLGenerator(
  1788. cfg => $cfg,
  1789. stats => $stats,
  1790. users => $users,
  1791. tmps => $tmps
  1792. );
  1793. =head1 CONSTRUCTOR
  1794. =over 4
  1795. =item new ( [ OPTIONS ] )
  1796. This is the constructor for a new Pisg::HTMLGenerator object. C<OPTIONS> are passed in a hash like fashion using key and value pairs.
  1797. Possible options are:
  1798. B<cfg> - hashref containing configuration variables, created by the Pisg module.
  1799. B<stats> - reference to the hash returned by Pisg::Parser::Logfile containing all stats.
  1800. B<users> - reference to a hash containg user information
  1801. B<tmps> - reference to a hash containing the language templates.
  1802. =back
  1803. =head1 AUTHOR
  1804. Morten Brix Pedersen <morten@wtf.dk>
  1805. =head1 COPYRIGHT
  1806. Copyright (C) 2001-2002 Morten Brix Pedersen. All rights reserved.
  1807. This program is free software; you can redistribute it and/or modify it
  1808. under the terms of the GPL, license is included with the distribution of
  1809. this file.
  1810. =cut