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