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