HTMLGenerator.pm 83 KB

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