HTMLGenerator.pm 71 KB

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