Reactivating the scripts ,-)
[privoxy.git] / doc / webserver / actions / step2.php
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3  <!--
4
5   File :  $Source: /cvsroot/ijbswa/current/doc/webserver/actions/step2.php,v $
6
7   Purpose  :  Submit form for actions file feedback (step 2)
8               This file belongs in
9               ijbswa.sourceforge.net:/home/groups/i/ij/ijbswa/htdocs/
10
11   $Id: step2.php,v 1.7 2002/04/03 19:36:04 swa Exp $
12
13   $Log: step2.php,v $
14   Revision 1.7  2002/04/03 19:36:04  swa
15   consistent look
16
17   Revision 1.6  2002/04/02 07:22:19  oes
18   Elimnating duplicate images; using relative link for step3
19
20   Revision 1.4  2002/04/01 19:13:47  oes
21   Extended, fixed bugs, beefed up design, made IE-safe
22
23   Revision 1.1  2002/03/30 03:20:30  oes
24   Added Feedback mechanism for actions file
25
26
27   Written by and Copyright (C) 2002 the SourceForge
28   Privoxy team. http://www.privoxy.org/
29
30   This program is free software; you can redistribute it
31   and/or modify it under the terms of the GNU General
32   Public License as published by the Free Software
33   Foundation; either version 2 of the License, or (at
34   your option) any later version.
35
36   This program is distributed in the hope that it will
37   be useful, but WITHOUT ANY WARRANTY; without even the
38   implied warranty of MERCHANTABILITY or FITNESS FOR A
39   PARTICULAR PURPOSE.  See the GNU General Public
40   License for more details.
41
42   The GNU General Public License should be included with
43   this file.  If not, you can view it at
44   http://www.gnu.org/copyleft/gpl.html
45   or write to the Free Software Foundation, Inc., 59
46   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
47
48  -->
49
50  <head>
51   <link rel="stylesheet" type="text/css" href="../p_feedback.css">
52
53   <script language="javascript">
54    //
55    // Could be as easy as style="max-wdith: 300px; max-height..." inside the
56    // <img> tag, but IE doesn't do that. Setting the values directly also
57    // screws IE for some weird reason. All praise MS.
58    //
59
60    function prettyscale(image)
61    {
62       newwidth = 0
63       newheight = 0
64
65       if (image.width > 300)
66       {
67          newwidth = 300
68       }
69
70       if (image.height > 50)
71       {
72          newheight = 50
73       }
74
75       if (image.width < 20)
76       {
77          newwidth = 20
78       }
79
80       if (image.height < 20)
81       {
82          newheight = 20
83       }
84
85       if (newwidth != 0)
86       {
87          image.width = newwidth
88       }
89
90       if (newheight != 0)
91       {
92          image.height = newheight
93       }
94    }
95   </script>
96
97
98 <?php
99
100 /*
101  * For testing: 
102  */
103 //phpinfo();
104 //error_reporting(E_ALL);
105 error_reporting(E_NONE);
106
107
108 /* 
109  * Cannot start with step 2:
110  */
111 if (!isset($referrer_url))
112 {
113    echo ("  <title>Invalid Feedback Submission</title>
114            </head>
115            <body>
116             <div class=\"title\">Invalid Feedback Submission</div>
117             <div align=\"center\">
118              <div class=\"errorbox\" align=\"left\">When submitting your feedback please start with
119               <a href=\"index.php\">step 1</a>.
120              </div>
121             </div>
122            </body>
123           </html>\n");
124    exit; 
125 }
126
127
128 /* 
129  * Cannot work on unknown problem:
130  */
131 if (!isset($problem) || $problem == "INVALID")
132 {
133    echo ("  <title>Invalid Feedback Submission</title>
134            </head>
135            <body>
136             <div class=\"title\">Invalid Feedback Submission</div>
137             <div align=\"center\">
138              <div class=\"errorbox\" align=\"left\">You need to select the nature of the problem in
139               <a href=\"javascript:history.back();\">step 1</a>.
140              </div>
141             </div>
142            </body>
143           </html>\n");
144    exit; 
145 }
146
147
148 /*
149  * Check if URL really exists and buffer its contents:
150  *
151  * FIXME: Curl is not installed on SF; Filed as Alexandria
152  *        Feature Request #537014. 
153  *        PHP's fopen() supports URLs, but it seems that
154  *        curls options for Timeouts and HTTP error handling
155  *        are not supported by fopen().
156  */
157 $ch = curl_init ($referrer_url);
158
159 curl_setopt ($ch, CURLOPT_HEADER, 0);
160 curl_setopt ($ch, CURLOPT_FAILONERROR, 1);
161 curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
162 curl_setopt ($ch, CURLOPT_TIMEOUT, 20);            
163
164 ob_start();
165 $success = curl_exec ($ch);
166 $page = ob_get_contents();
167 ob_end_clean();
168
169 curl_close ($ch);
170
171 if (!$success)
172 {
173    echo ("  <title>Invalid Feedback Submission</title>
174            </head>
175            <body>
176             <div class=\"title\">Invalid Feedback Submission</div>
177             <div align=\"center\">
178              <div class=\"errorbox\" align=\"left\">
179               <p>The URL that you entered (<a href=\"$referrer_url\">$referrer_url</a>)
180                <br>could not be retrieved.
181               </p>
182               <p>Make sure the URL is correct and publicly accessible.</p>
183               <p><a href=\"javascript:history.back();\">Back to step 1</a></p>
184              </div>
185             </div>
186            </body>
187           </html>\n");
188    exit; 
189 }
190
191
192 /* 
193  * Create description from problem code:
194  */
195 switch($problem)
196 {
197    case "P1": $problem_description="an advertisment was not blocked"; break;
198    case "P2": $problem_description="an innocent image was blocked"; break;
199    case "P3": $problem_description="the whole page was erraneously blocked"; break;
200    case "P4": $problem_description="the page needs popups but they don't work"; break;
201    case "P5": $problem_description="a problem occured"; break;
202    default: $problem_description="AN UNPROCESSABLE PROBLEM OCCURED";
203 }
204
205 ?>
206
207   <title>Privoxy Action List Feedback - Step 2 of 2</title>
208  </head>
209  <body>
210
211   <div class="title"><a href="http://www.privoxy.org" target="_blank">Privoxy</a> Action List Feedback - Step 2 of 2</div>
212
213   <div class="box">
214    <b>You are about to report that <?php echo ($problem_description) ?> on
215    <a href="<?php echo ($referrer_url) ?>"><?php echo ($referrer_url) ?></a>.</b>
216   </div>
217
218   <div class="box">
219    <form action="step3.php" method="post">
220     <p>
221      <input type="hidden" name="problem" value="<?php echo ($problem) ?>">
222      <input type="hidden" name="referrer_url" value="<?php echo ($referrer_url) ?>">
223     </p>
224
225     <dl>
226
227 <?php
228
229 /*
230  * Create / suppress for elements depending on type of
231  * problem
232  */
233 if ($problem != "P1")
234 {
235    echo ("<!--");
236 }
237 else
238 {
239    /*
240     * Extract all image links from page, make them
241     * absolute, and present them (scaled to reasonable size)
242     * in a table for the user to select
243     */
244    preg_match_all('|<img\s+[^>]*?src=[\'"]?(.*?)[\'" >]|i', $page, $matches);
245    $image_urls = array_values(array_unique($matches[1]));
246    $count = count($image_urls);
247
248    if ($count > 0)
249    {
250       /* 
251        * Base URL ends in slash: don't touch.
252        */
253       if (strpos(strrev($referrer_url), '/') == 0)
254       {
255          $referrer_base = $referrer_url;
256       }
257       /* 
258        * Else grab URL up to last slash as base.
259        */
260       else
261       {
262          $referrer_base = substr($referrer_url, 0, -strpos(strrev($referrer_url), '/'));
263       }
264
265       /* 
266        * Get the protocol + host info for relative links
267        * that start with slash. FIXME: Cut trailing slash off!
268        */
269       $referrer_host = "http://".strrev(strrchr(strrev(substr($referrer_url, 7)), "/"));
270
271       /*
272        * Open section in <dl>; Open table:
273        */
274       echo ("     <dt><b>Choose the images you want blocked from the following list:</b></dt>
275                   <dd>
276                    <p>
277                     <input type=\"hidden\" name=\"num_images\" value=\"$count\">
278                     <table border=\"0\" cellpadding=\"0\" cellspacing=\"4\">\n");
279       /*
280        * Print one table row for each image found:
281        */
282       for ($i=0; $i< $count; $i++)
283       {
284          $image_url = $image_urls[$i];
285  
286          /*
287           * Make image URLs absolute:
288           */
289          if (strncmp("http://", $image_url, 7))
290          {
291             if ($image_url{0} == "/")
292             {
293                $image_url = $referrer_host.$image_url;
294             }
295             else
296             {
297                $image_url = $referrer_base.$image_url;
298             }
299          }
300
301          /*
302           * Print the row(s):
303           */
304          echo ("       <tr>
305                         <td rowspan=2>
306                          <input type=\"checkbox\" name=\"block_image[$i]\" value=\"off\">
307                         </td>
308                         <td>
309                          <a href=\"$image_url\">$image_url</a>:
310                         </td>
311                         <td>
312                          <input type=\"hidden\" name=\"image_url[$i]\" value=\"$image_url\">
313                         </td>
314                        </tr>
315                        <tr>
316                         <td>
317                          <img onload=\"prettyscale(this);\" src=\"$image_url\" alt=\"banner or not?\">
318                         </td>
319                        </tr>\n");
320       }
321       echo ("      </table>
322                   </dd>
323
324                   <dt>
325                    <b>If the banner that you saw is not listed above, enter the URL here</b>\n");
326    }
327    else
328    {
329       echo ("     <dt>
330                    <b>URL of the advertisment image:</b>\n");
331    }
332 }
333
334 ?>
335
336       <br><i>Hint: right-click the image, select "Copy image location" and paste the URL here.</i>
337      </dt>
338      <dd>
339       <p>
340        <input name="manual_image_url" type="text" size="45" maxlength="255">
341       </p>
342      </dd>
343
344 <?php if($problem != "P1") echo ("-->") ?>
345
346 <?php if($problem != "P2") echo ("<!--") ?>
347
348      <dt>
349       <p><b>URL of the innocent image:</b>
350        <br><i>Hint: right-click the image, select "Copy image location" and paste the URL here.
351        <br>This may not work if the image was blocked by size or if +image-blocker is set to redirect.</i>
352       </p>
353      </dt>
354      <dd>
355       <p>
356        <input name="image_url" value="unknown" type="text" size="45" maxlength="255">
357       </p>
358      </dd>
359
360 <?php if($problem != "P2") echo ("-->") ?>
361
362      <dt><b>Severity:</b></dt>
363      <dd>
364       <p>
365        <select name="severity">
366         <option value="3">drives me crazy</option>
367         <option selected value="2">normal</option>
368         <option value="1">cosmetic</option>
369        </select>
370       </p>
371      </dd>
372
373      <dt>
374       <b>Remarks:</b> <i>(optional)</i>
375      </dt>
376      <dd>
377       <p>
378        <textarea wrap="hard" style="font-size: 10px" name="remarks" cols="35" rows="3">None.</textarea>
379       </p>
380      </dd>
381
382      <dt>
383       <b>Your Name:</b> <i>(optional)</i>
384      </dt>
385      <dd>
386       <p>
387        <input name="name" size="45">
388       </p>
389      </dd>
390
391      <dt>&nbsp;</dt>
392      <dd>
393       <input type=submit value="Submit">
394      </dd>
395
396     </dl>
397    </form>
398   </div>
399
400  </body>
401 </html>