HTMLGenerator.pm 81 KB

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