HTMLGenerator.pm 82 KB

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