HTMLGenerator.pm 70 KB

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