1# Copyright (C) March, 19th 2002  Author FoxMaSk <odemah@phpfr.org>
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public License
5# as published by the Free Software Foundation; either version 2
6# of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
17#Requirement : get the file funcsummary.txt from the CVS of http://php.net
18use strict;
19use Irssi;
20use vars qw($VERSION %IRSSI);
21
22$VERSION = "0.0.6";
23%IRSSI = (
24    authors => 'Foxmask',
25    contact => 'odemah@phpfr.org ',
26    name => 'PhpDoc',
27    description => 'Display all functions of the famous language PHP which is used in the funcsummary.txt file in the CVS of http://php.net',
28    license => 'GNU GPL',
29    url => 'http://team.gcu-squad.org/~odemah/'
30);
31
32#PARMS
33
34#file name that contains all function list and definition
35my $doc_file       = "$ENV{HOME}/phpdoc/funcsummary.txt";
36my $cmd_php        = "!man";
37my @channel_php = ();
38$channel_php[0] = "#phpfr";
39$channel_php[1] = "#phpfrance";
40my $mirror_php     = "http://phpnet.phpfr.org/manual/fr/";
41#==========================END OF PARMS======================================
42
43#init array
44my @doc = ();
45my $x = 0;
46
47#The main function
48sub doc_find {
49    my ($server, $msg, $nick, $address, $target) = @_;
50
51    my $keyword="";
52    my $def="";
53    my $cmd="";
54
55    #split the *action* and the rest of the line
56    ($cmd,$keyword) = split / /,$msg,2;
57
58    #to query
59    if (lc($cmd) eq $cmd_php and (lc($target) eq $channel_php[0] or lc($target) eq $channel_php[1]) ) {
60        if ($keyword eq '') {
61            if ( $server->channel_find($target)->nick_find($nick)->{voice} or $server->channel_find($target)->nick_find($nick)->{op} ) {
62            $server->command("/msg -$server->{tag} $target $cmd_php: \002$cmd_php <function>\002 example $cmd_php mysql_connect");
63	    	} else {
64                $server->command("/msg $nick $cmd_php: \002$cmd_php <function>\002 example $cmd_php mysql_connect");
65    		}
66        }
67        else {
68         for ($x=0;$x < @doc;$x++) {
69          	#ignore comment
70                if ( $doc[$x] =~ /^(object|unknown|mixed|class|resource|void|bool|array|string|int) $keyword/)  {
71        	        $def = $doc[$x];
72            	    chomp($def);
73                    $def =~ s/\s+/ /g;
74    	            $keyword =~ s/_/-/g ;
75                    $def .= ". More Details on ".$mirror_php ."function.".$keyword.".php";
76                	last;
77                }
78            }
79
80            if ( $def ne '' ) {
81    	        $keyword =~ s/-/_/g ;
82                #if the user is voice or op ; display the description in the channel
83                if ( $server->channel_find($target)->nick_find($nick)->{voice} or $server->channel_find($target)->nick_find($nick)->{op} ) {
84                    $server->command("/msg -$server->{tag} $target $def");
85        		}
86                #else display it to the $nick only
87    	    	else {
88                    $server->command("/msg $nick \002$keyword\002=$def");
89        		}
90            }
91                #definition not found ; so we tell it to $nick
92            else {
93                $server->command("/msg $nick $keyword does not exist");
94                Irssi::signal_stop();
95            }
96        }
97    }
98}
99
100
101#load datas from funcsummary.txt file
102sub load_doc {
103    my $doc_line="";
104    if (-e $doc_file) {
105        @doc = ();
106        Irssi::print("Loading doc from $doc_file");
107        local *DOC;
108        open(DOC,"$doc_file");
109        local $/ = "\n";
110        while (<DOC>) {
111            chomp();
112            #ignore comment and get all lines beginning with ... :
113            if ( /^(object|unknown|mixed|class|resource|void|bool|array|string|int)/)  {
114        	    #getting the line description
115                $doc_line = $_;
116                chomp($doc_line);
117        	    #getting the line definition
118                $doc_line .= <DOC>;
119                chomp($doc_line);
120                push(@doc,$doc_line);
121            }
122        }
123        close DOC;
124		Irssi::print("Loaded " . scalar(@doc) . " record(s)");
125	} else {
126		Irssi::print("Cannot load $doc_file");
127	}
128}
129
130load_doc();
131
132Irssi::signal_add_last('message public', 'doc_find');
133Irssi::print("Php Doc Management $VERSION loaded!");
134
135