HTMLGenerator.pm 70 KB

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