HTMLGenerator.pm 70 KB

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