HTMLGenerator.pm 81 KB

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