HTMLGenerator.pm 71 KB

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