HTMLGenerator.pm 82 KB

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