HTMLGenerator.pm 69 KB

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