HTMLGenerator.pm 74 KB

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