/[gentoo-src]/glep15/scripts.php
Gentoo

Contents of /glep15/scripts.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Sat Nov 22 15:40:37 2003 UTC (10 years, 8 months ago) by hythloday
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +119 -5 lines
Added skeleton upload and viewing capabilities.

1 <?php
2 /***************************************************************************
3 * scripts.php
4 *
5 * Fri Oct 17 17:13:43 2003
6 * Copyright 2003 lisa seelye - lisa@gentoo.org
7 * Copyright 2003 james harlow - hythloday@gentoo.org
8 * Copyright 2003 Gentoo Technologies, Inc. - http://www.gentoo.org/
9 *
10 * $Header: $
11 ***************************************************************************
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 **************************************************************************/
26
27 /*
28 [ ]: End-user area
29 [ ]: |-> Method for script uploading and storing
30 [ ]: |-> Method for downloading scripts
31 [ ]: |-> Method for leaving user-comments
32 [ ]: |-> Method for script ranking (0-10)
33 [ ]: |-> Method for searching for scripts (name, category, submitter,language)
34 [ ]: |-> "Search friendly" URLs
35 */
36
37 require_once("mysql.php");
38
39 function print_links () {
40 echo ("<a href = \"scripts?mode=browse\">Browse all scripts</a><br />\n");
41 echo ("<a href = \"scripts?mode=upload\">Upload a new script</a><br />\n");
42 echo ("<a href = \"scripts?mode=search\">Search all scripts</a><br />\n");
43 echo ("<hr />\n");
44 }
45
46 function print_error ( $error_string ) {
47 if ( isset ( $error_String ) ) {
48 echo ("$error_string<br /><hr />\n");
49 }
50 }
51
52 function print_options( $sid ) {
53 echo ("<a href = \"scripts?mode=download&sid=$sid\">Download this script</a><br />\n");
54 echo ("<a href = \"scripts?mode=comment&sid=$sid\">Comment on this script</a><br />\n");
55 echo ("<a href = \"scripts?mode=rate&sid=$sid\">Rate this script</a><br />\n");
56 // echo ("<a href = \"scripts?mode=sign&sid=$sid\">Digitally sign this script</a><br />\n");
57 echo ("<hr />\n");
58 }
59
60 function print_script_row( $script ) {
61 echo ("<tr><td><a href = \"scripts?mode=view&sid=$script->sid\">$script->name</a></td>");
62 echo ("<td>$script->category</td>");
63 echo ("<td>$script->rank/10</td><td>$script->descript</td></tr>\n");
64 }
65
66 function print_script_table( $scripts ) {
67 echo ("<table width=\"100%\" border=\"1\">\n");
68 echo ("<th>Name</th><th>Language</th><th>Rating</th><th>Description</th>\n");
69 array_walk ( $scripts, 'print_script_row' );
70 echo ("</table>\n");
71 }
72
73 function print_script_info ( $script ) {
74 echo ("\$name = $script->name<br />\n");
75 echo ("\$language = $script->category<br />\n");
76 echo ("\$rating = $script->rank<br />\n");
77 echo ("\$description = $script->descript<br />\n");
78 echo ("\$text = <pre>$script->script</pre><br />\n");
79 echo ("<hr />\n");
80 }
81
82 function print_file_upload_form() {
83 /* FIXME. */
84 echo ("<form enctype=\"multipart/form-data\" action=\"scripts?mode=upload\" method=\"POST\">\n");
85 echo ("<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"10000\">\n");
86 echo ("Send this file: <input name=\"script\" type=\"file\"><br />\n");
87 echo ("Description: <input name=\"description\" type=\"text\"><br />\n");
88 echo ("<input type=\"submit\" value=\"Send File\">\n");
89 echo ("</form>\n");
90 }
91
92 function print_script_upload_success() {
93 echo ("<p>script was sucessfully uploaded.</p>");
94 }
95
96 function handle_script_upload() {
97 if ( $_FILES['script']['error'] ) {
98 print_links();
99 print_error ( $_FILES['script']['error'] );
100 print_file_upload_form();
101 } else {
102 if ( security_check ( $_FILES['script']['tmp_name'] ) ) {
103 submit_script ( $_FILES['script']['name'],
104 $_POST['description'],
105 $_FILES['script']['tmp_name'] );
106 print_links();
107 print_script_upload_success ();
108 print_script_table( get_scripts( 10 ) );
109 } else {
110 /* probably put it in a holding pen, talk to kurt. */
111 echo "FIXME";
112 }
113 }
114 }
115
116 switch ($_GET['mode']) {
117 case "browse":
118 print_links();
119 print_script_table( get_scripts( 10 ) );
120 break;
121 case "view":
122 if ( isset ( $_GET['sid'] ) ) {
123 print_links();
124 print_options ( $_GET['sid'] );
125 print_script_info ( get_script_by_sid ( $_GET['sid'] ) );
126 }
127 break;
128 case "upload":
129 if (isset($_FILES['script'])) {
130 handle_script_upload();
131 } else {
132 print_links();
133 print_file_upload_form();
134 }
135 break;
136 case "search": break;
137 case "download": break;
138 case "comment": break;
139 case "rate": break;
140 default: header ("Location: ./scripts?mode=browse" );
141 }
142
143 /* examine the script to see what language it's written in. */
144 function get_language_from_script ( $script_text ) {
145 return "fixme";
146 }
147
148 /* look at the script for suspicious characteristics. return TRUE if it's OK. */
149 function security_check ( $filename ) {
150 return true;
151 }
152
153 ?>

  ViewVC Help
Powered by ViewVC 1.1.20