HTMLGenerator.pm 83 KB

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