File: explaindir.pike

package info (click to toggle)
libroxen-explaindir 0.93-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 80 kB
  • sloc: makefile: 36; ansic: 5
file content (149 lines) | stat: -rwxr-xr-x 4,055 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
    Copyright (C) 1997-1999  Daniel W. Crompton <redhat@rphh.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

string cvs_version= "$Id: explaindir.pike,v 0.93 1999/10/07 04:11:45 redhat Exp $";

inherit "roxenlib";
inherit "http";
inherit "module";
#include <module.h>
#include <stdio.h>

array register_module()

{
//*** RETURN TAGS TYPE
return ({ MODULE_PARSER|MODULE_LOCATION, "Explain Directory v0.93",
	    "This module returns a directory listing from a mountpoint, using a file with and explination of content."+
	    "<BR>There aren't really any more instructions, however you can find all my other modules at\n<P>"+
	    "<font size=+1 color=blue>http://<A HREF=http://www.rphh.org/ target=fnuggle>www.rphh.org</A>/"+
	    "<A HREF=http://www.rphh.org/downloads/ target=fnuggle>downloads</A>/</font>"+
	    "<P>"+
	    "<I>Coming Soon:</I> <B><font color=red>Gutenberg extention</B></font>"});
}

void create()
{
  defvar("dir",
         "NONE/",
         "Directory",
          TYPE_DIR,
         ".");
  defvar("mnt",
         "/download/",
         "Mountpoint",
          TYPE_LOCATION,
         ".");
  defvar("file",
         "filename.txt",
         "Filename",
          TYPE_FILE,
         ".");
  defvar("body",
         "<title> Something $mnt</title>\n<body>\n$result",
         "Body HTML",
          TYPE_TEXT_FIELD,
         "(<I>$mnt = mountpoint & $result = results from Content</I>).");
  defvar("cont",
         "<A HREF=$file>$title</A> $discript<BR>",
         "Content",
          TYPE_TEXT_FIELD,
         "How do you wish to return content???\n<BR>(<I>$file = filename & $discript = discription & $title = title</I>)");
}

string query_location()
{
  return QUERY(mnt);
}

string query_name()
{
  return sprintf("Explain <i>%s</i> in <i>%s</i>",query("dir"),query("mnt"));
}

int hits;

string status()
{
  return
    (
     sprintf("<P>Page Views: <B>%d</B>\n",hits)
    );
}

string directory(string t)
{
  string line;
  string filename = "";
  string _filename;
  string Result = "";
  array dirres = get_dir(combine_path(query("dir"),t));
  string discript;
  string title;
  string filecontent = Stdio.read_bytes(combine_path(query("dir"),query("file")));
  
  foreach(filecontent/"\n",line)
  {
    _filename = filename;
    sscanf(line,"%s:%s:%s",filename, title, discript);

    if(search(dirres,filename)>=0)
    {
      if(filename==_filename) continue;
      Result += replace(query("cont"),({"$file","$discript","$title"}),
                                      ({filename,discript, title})) +"\n";
    }
  }

//  return Result;

  return parse_html(Result - "\r", ([]),
                    ([ "pike" : lambda(string s, mapping a, string c) { return c; } ])
		   );
}

mixed find_file(string t, object id)
{
    hits++;
    if(t!="")
    {
      string content;
      string err = catch( content = Stdio.read_bytes(combine_path(query("dir"),t)) );

      if(!err) return http_string_answer(content);
    }
    return http_string_answer(replace(query("body"),({"$mnt","$result"}),
                                                    ({query("mnt"),directory(t)})
                                     )
			     );
}

string tag_list(string t, mapping m, mixed id)
{
}

string tag_short(string t, mapping m, mixed id)
{
}

mapping query_tag_callers()
{
  return ([ "explain_list":tag_list,
	    "short_list":tag_short,
	  ]);
}