From ceda88a945534a7e55151666b414d6fa1ab38109 Mon Sep 17 00:00:00 2001 From: Evgeny Gryaznov Date: Fri, 20 Mar 2009 02:01:36 +0000 Subject: [PATCH] initial: collect messages usages script git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@426 c66351dc-e62f-0410-b875-e3a5c0b9693f --- src/messenger/compute_resources.pl | 212 +++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100755 src/messenger/compute_resources.pl diff --git a/src/messenger/compute_resources.pl b/src/messenger/compute_resources.pl new file mode 100755 index 00000000..1eba1f07 --- /dev/null +++ b/src/messenger/compute_resources.pl @@ -0,0 +1,212 @@ +#!/usr/bin/perl + +@rules = ( + ["redirect(ed)?\\.tpl", 1], + ["\\.tpl", 0], + + ["view/preview.php", 2], + ["view/translate.php", 2], + ["view/translatelist.php", 2], + ["view/settings.php", 2], + ["view/updates.php", 2], + ["view/features.php", 2], + ["view/avatar.php", 2], + ["view/permissions.php", 2], + ["view/agent.php", 2], + ["view/agents.php", 2], + ["view/department.php", 2], + ["view/departments.php", 2], + ["view/gen_button.php", 2], + ["view/install_err.php", 2], + ["view/install_index.php", 2], + ["view/.*\\.php", 1], + + ["install/.*\\.php", 2], + + ["operator/preview.php", 2], + ["operator/translate.php", 2], + ["operator/settings.php", 2], + ["operator/updates.php", 2], + ["operator/features.php", 2], + ["operator/avatar.php", 2], + ["operator/permissions.php", 2], + ["operator/operator.php", 2], + ["operator/operators.php", 2], + ["operator/department.php", 2], + ["operator/departments.php", 2], + ["operator/getcode.php", 2], + ["operator/.*\\.php", 1], + + ["webim/client.php", 0], + ["webim/leavemessage.php", 0], + ["webim/mail.php", 0], + + ["webim/libs/chat.php", 0], + ["libs/pagination.php", 1], + ["libs/settings.php", 2], + ["libs/demothread.php", 2], + + ["webim/thread.php", 0], + ["webim/button.php", 0], + ["webim/index.php", 0], + + ["webim/libs/.*\\.php", 1], +); + +%messagekeys = ( + "localeid" => 0, + "output_charset" => 0, + "output_encoding" => 0, + "harderrors.header" => 0, + + "errors.required" => 0, + "errors.wrong_field" => 0, + "errors.file.move.error" => 2, + "errors.invalid.file.type" => 2, + "errors.file.size.exceeded" => 2, + + "permission.admin" => 1, + "permission.takeover" => 1, + "permission.viewthreads" => 1, + + "chat.thread.state_chatting_with_agent" => 1, + "chat.thread.state_closed" => 1, + "chat.thread.state_loading" => 1, + "chat.thread.state_wait" => 1, + "chat.thread.state_wait_for_another_agent" => 1, + + "clients.queue.chat" => 1, + "clients.queue.prio" => 1, + "clients.queue.wait" => 1, +); + + +$webimPath = "webim"; + +%urls = (); + +%usermessages = (); +%operatormessages = (); +$current_level = 0; + +sub usemsg($) { + my ($m) = @_; + $messagekeys{$m} = exists $messagekeys{$m} && $messagekeys{$m} < $current_level ? $messagekeys{$m} : $current_level; + if($current_level == -1) { + print " .. $m\n"; + } +} + +sub file_content($) { + my $input = $_[0]; + open( IN1, "< $input" ) or die "cannot find file $input"; + my $oldslash = $/; + $/ = EOI; + $content = ; + $content =~ s/\r//g; + close( IN1 ); + $/ = $oldslash; + return $content; +} + +sub process_tpl($) { + my ($filename) = @_; + my $m = file_content($filename); + while( $m =~ /\${msg:([\w\.]+)(,[\w\.]+)?}/g ) { + usemsg($1); + } + while( $m =~ /\${url:([\w\.]+)(,[\w\.]+)?}/g ) { + usemsg($1); + $urls{"%$1"} = 1; + } +} + +sub process_php($) { + my ($source) = @_; + my $content = file_content($source); + $content =~ s/<\?xml version=\\"1\.0\\" encoding=\\"UTF-8\\"\?>//; + + while( $content =~ s/<\?(?!xml)(.*?)\?>//s ) { + my $inner = $1; + while($inner =~ s/(getlocal|getstring|no_field)2?_?\((.*?)[,\)]//s) { + my $firstarg = $2; + if( $firstarg =~ /^["']([\w\.]+)['"]$/) { + usemsg($1); + } elsif($firstarg =~ /^\$\w+$/ || $firstarg eq '"$var.header"' || $firstarg eq '"permission.$permid"' || $firstarg eq '$threadstate_key[$thread[\'istate\']]') { + # skip + } else { + print "> unknown: $firstarg\n"; + } + } + } +} + +sub process_one($) { + my($source) = @_; + + if($source !~ /\.(php|tpl)$/) { + return; + } + + $current_level = -1; + + A: foreach $rule (@rules) { + my $key = $$rule[0]; + if($source =~ /$key/) { + $current_level = $$rule[1]; + last A; + } + } + if($current_level < 0 || $current_level > 2) { + print "not detected for: $source\n"; + $current_level = 0; + } + + if($source =~ /\.php$/) { + # print "$source ($current_level)\n"; + process_php($source); + } elsif($source =~ /\.tpl$/) { + process_tpl($source); + } else { + #print ". $source\n"; + } +} + +sub process_files($) { + my($from) = @_; + opendir(DIR, $from) || die "can't opendir $from: $!"; + my @content = readdir(DIR); + closedir DIR; + + for(grep { -f "$from/$_" && ($_ !~ /^\./ || $_ eq ".htaccess") } @content) { + process_one("$from/$_"); + } + for(grep { -d "$from/$_" && $_ !~ /^\./ } @content) { + process_files("$from/$_"); + } +} + +process_files($webimPath); + +# fix +$messagekeys{'page.analysis.userhistory.title'} = 1; +$messagekeys{'errors.failed.uploading.file'} = 2; + + +open( OUT, "> $webimPath/locales/names/level1") or die "cannot write file, $!"; +for $key(sort grep { $messagekeys{$_} == 0 } keys %messagekeys) { + print OUT "$key\n"; +} +close( OUT ); + +open( OUT, "> $webimPath/locales/names/level2") or die "cannot write file, $!"; +for $key(sort grep { $messagekeys{$_} == 1 } keys %messagekeys) { + print OUT "$key\n"; +} +close( OUT ); + +open( OUT, "> $webimPath/locales/names/all2.txt") or die "cannot write file, $!"; +for $key(sort keys %messagekeys) { + print OUT "$key\n"; +} +close( OUT );