Try Arial first for NS4/Win
[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.11 2002/04/07 15:00:20 oes Exp $
12
13   $Log: step2.php,v $
14   Revision 1.11  2002/04/07 15:00:20  oes
15   Descand into framesets to harvest all image URLs
16
17   Revision 1.10  2002/04/06 15:19:35  oes
18   Cosmetics   Clean-up, smarter handling of unreachable URLs
19
20   Revision 1.9  2002/04/06 11:34:44  oes
21   Reactivating the scripts ,-)   Cosmetics
22
23   Revision 1.7  2002/04/03 19:36:04  swa
24   consistent look
25
26   Revision 1.6  2002/04/02 07:22:19  oes
27   Elimnating duplicate images; using relative link for step3
28
29   Revision 1.5  2002/04/02 06:14:47  oes
30   Follow redirects  
31
32   Revision 1.4  2002/04/01 19:13:47  oes (based on 1.2)
33   Extended, fixed bugs, beefed up design, made IE-safe
34
35   Revision 1.3  2002/03/30 20:44:46  swa
36   have consistent look and feel. part 2.
37   use correct urls. 
38
39   Revision 1.2  2002/03/30 19:49:34  swa
40   have consistent look and feel
41
42   Revision 1.1  2002/03/30 03:20:30  oes
43   Added Feedback mechanism for actions file
44
45
46   Copyright (C) 2002 the SourceForge Privoxy team.
47   http://www.privoxy.org/
48
49   Written by Andreas Oesterhelt
50
51   This program is free software; you can redistribute it
52   and/or modify it under the terms of the GNU General
53   Public License as published by the Free Software
54   Foundation; either version 2 of the License, or (at
55   your option) any later version.
56
57   This program is distributed in the hope that it will
58   be useful, but WITHOUT ANY WARRANTY; without even the
59   implied warranty of MERCHANTABILITY or FITNESS FOR A
60   PARTICULAR PURPOSE.  See the GNU General Public
61   License for more details.
62
63   The GNU General Public License should be included with
64   this file.  If not, you can view it at
65   http://www.gnu.org/copyleft/gpl.html
66   or write to the Free Software Foundation, Inc., 59
67   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
68
69  -->
70
71  <head>
72   <meta http-equiv="Content-Style-Type" content="text/css">
73   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
74   <link rel="stylesheet" type="text/css" href="../privoxy.css">
75   <link rel="stylesheet" type="text/css" href="../p_feedback.css">
76
77   <script language="javascript" type="text/javascript">
78   <!--
79    //
80    // Could be as easy as style="max-wdith: 300px; max-height..." inside the
81    // <img> tag, but IE doesn't understand that. Setting the values directly also
82    // screws IE for some weird reason. All praise MS.
83    //
84
85    function prettyscale(image)
86    {
87       newwidth = 0
88       newheight = 0
89
90       if (image.width > 300)
91       {
92          newwidth = 300
93       }
94
95       if (image.height > 50)
96       {
97          newheight = 50
98       }
99
100       if (image.width < 20)
101       {
102          newwidth = 20
103       }
104
105       if (image.height < 20)
106       {
107          newheight = 20
108       }
109
110       if (newwidth != 0)
111       {
112          image.width = newwidth
113       }
114
115       if (newheight != 0)
116       {
117          image.height = newheight
118       }
119    }
120   //-->
121   </script>
122
123 <?php
124
125 /*
126  * For testing: 
127  */
128 //phpinfo();
129 //error_reporting(E_ALL);
130 error_reporting(E_NONE);
131
132 /*
133  * Function: link_to_absolute
134  * Purpose:  Make $link from $base absolute
135  */
136 function link_to_absolute($base, $link)
137 {
138    /*
139     * If $link already is absolute, we're done:
140     */
141    if (!strncmp("http://", $link, 7) || !strncmp("https://", $link, 8))
142    {
143       return $link;
144    }
145
146    /*
147     * Cut the base to it's proto://host/ or to its proto://host/dir/,
148     * depending whether $link is host-relative or path-relative.
149     */
150    if ($link{0} == "/")
151    {
152       /*
153        * host-relative:
154        */
155        preg_match('|^(https?://[^/]+)|i', $base, $results);
156        $base = $results[1];
157    }
158    else
159    {
160       /*
161        * path-relative:
162        */
163       if (strpos($base, '/') != strlen($base))
164       {
165          preg_match('|(.*/)|i', $base, $results);
166          $base = $results[1];
167       }
168    }
169    return $base.$link;
170 }
171
172
173 /*
174  * Function: slurp_page
175  *
176  * Purpose:  Retrieve a URL with curl, and return the contents
177  *           or "FAILED" if it fails.
178  */
179
180 function slurp_page($url)
181 {
182    $ch = curl_init ($url);
183
184    curl_setopt ($ch, CURLOPT_HEADER, 0);
185    curl_setopt ($ch, CURLOPT_FAILONERROR, 1);
186    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
187    curl_setopt ($ch, CURLOPT_TIMEOUT, 20);            
188
189    ob_start();
190    $success = curl_exec ($ch);
191    $page = ob_get_contents();
192    ob_end_clean();
193
194    curl_close ($ch);
195
196    return $success ? $page : "FAILED";
197 }
198
199 /*
200  * Function: get_image_urls_sp
201  * 
202  * Purpose:  Return the image URLs from a single page
203  */
204 function get_image_urls_sp($page, $url)
205 {
206    preg_match_all('|<img\s+[^>]*?src=[\'"]?(.*?)[\'" >]|i', $page, $matches);
207    
208    foreach (array_unique($matches[1]) as $image_link)
209    {
210       $result[] = link_to_absolute($url, $image_link); 
211    }
212
213    return count($result) ? $result : 0;
214 }
215
216 /*
217  * Function: get_image_urls
218  * 
219  * Purpose:  If the page is a frameset, rerurn the image URLs from all
220  *           its frame SRCes, else from the page itself.
221  */
222 function get_image_urls($page, $url)
223 {
224
225    preg_match_all('|<frame\s+[^>]*?src=[\'"]?(.*?)[\'" >]|i', $page, $matches);
226
227    if (count($matches[1]))
228    {
229       foreach(array_unique($matches[1]) as $frame_link)
230       {
231          $framebuf = slurp_page(link_to_absolute($url, $frame_link));
232          $result = array_merge($result, get_image_urls_sp($framebuf, link_to_absolute($url, $frame_link)));
233       }
234    }
235    else
236    {
237       $result = get_image_urls_sp($page, $url);
238    }
239
240    return array_values(array_unique($result));
241 }
242
243
244 /*
245  * Function: error_abort
246  * Purpose:  Return an error page with $title and $message
247  */
248 function error_abort($title, $message)
249 {
250    if ($title == "invalid") /* shortcut */
251    {
252       $title = "Invalid Feedback Submission";
253    }
254
255    echo ("  <title>Privoxy: $title</title>
256            </head>
257            <body>
258             <div class=\"title\">
259              <h1>
260               <a href=\"http://www.privoxy.org/\">Privoxy</a>: $title
261               </h1>
262              </div>
263             <center>
264              <div class=\"warning\">
265               $message
266              </div>
267             </center>
268             <p>Valid <a href=\"http://validator.w3.org/\">HTML 4.01 Transitional</a></p>
269            </body>
270           </html>\n");
271    exit; 
272 }
273
274 /* 
275  * Cannot start with step 2:
276  */
277 if (!isset($referrer_url))
278 {
279    error_abort("invalid", "When submitting your feedback please start with
280                 <a href=\"index.php\">step 1</a>.");
281 }
282
283
284 /* 
285  * Cannot work on unknown problem:
286  */
287 if (!isset($problem) || $problem == "INVALID")
288 {
289    error_abort("invalid", "You need to select the nature of the problem in
290                 <a href=\"javascript:history.back();\">step 1</a>.");
291 }
292
293
294 /*
295  * If the protocol is missing from $referrer_url, prepend "http://"
296  */
297 if (strncmp("http://", $referrer_url, 7))
298 {
299    $referrer_url = "http://" . $referrer_url;
300 }
301
302
303 /*
304  * Check if URL really exists and buffer its contents:
305  */
306 if (($page = slurp_page($referrer_url)) == "FAILED")
307 {
308    $url_confirm = "
309      <dt>
310       <p><b>Confirm the URL:</b></p>
311      </dt>
312      <dd>
313       <p>
314        The URL that you entered could not be retrieved. Please make sure that
315       </p>
316       <p class=\"important\">
317        <a href=\"$referrer_url\">$referrer_url</a>
318       </p>
319       <p>
320        is correct and publicly accssible.
321       </p>
322       <p>
323        <input type=\"checkbox\" name=\"url_confirmed\" value=\"user\"> Yes, I'm sure.
324       </p>
325      </dd>";
326 }
327 else
328 {
329    $url_confirm = "<input type=\"hidden\" name=\"url_confirmed\" value=\"automatic\">";
330 }
331
332 /* 
333  * Create description from problem code:
334  */
335 switch($problem)
336 {
337    case "P1": $problem_description="an advertisment was not blocked"; break;
338    case "P2": $problem_description="an innocent image was blocked"; break;
339    case "P3": $problem_description="the whole page was erraneously blocked"; break;
340    case "P4": $problem_description="the page needs popups but they don't work"; break;
341    case "P5": $problem_description="a problem occured"; break;
342    default: $problem_description="AN UNPROCESSABLE PROBLEM OCCURED";
343 }
344
345 ?>
346
347   <title>Privoxy Action List Feedback - Step 2 of 2</title>
348  </head>
349  <body>
350
351   <div class="title">
352    <h1>
353      <a href="http://www.privoxy.org" target="_blank">Privoxy</a> Action List Feedback - Step 2 of 2
354    </h1>
355   </div>
356
357   <div class="box">
358    <b>You are about to report that <?php echo ($problem_description) ?> on
359    <a href="<?php echo ($referrer_url) ?>"><?php echo ($referrer_url) ?></a>.</b>
360   </div>
361
362   <div class="box">
363    <form action="step3.php" method="post">
364     <p>
365      <input type="hidden" name="problem" value="<?php echo ($problem) ?>">
366      <input type="hidden" name="referrer_url" value="<?php echo ($referrer_url) ?>">
367     </p>
368
369     <dl>
370
371 <?php
372
373 /*
374  * Include the confirmation for an unretrievable URL if
375  * necessary
376  */
377 echo ($url_confirm);
378
379 /*
380  * Create / suppress form elements depending on type of
381  * problem
382  */
383 if ($problem != "P1")
384 {
385    echo ("<!--");
386 }
387 else
388 {
389    $image_urls = get_image_urls($page, $referrer_url);
390    $count = count($image_urls);
391
392    if ($count > 0)
393    {
394       /*
395        * Open section in <dl>; Open table:
396        */
397       echo ("     <dt><b>Choose the images you want blocked from the following list:</b></dt>
398                   <dd>
399                    <p>
400                     <input type=\"hidden\" name=\"num_images\" value=\"$count\">
401                     <table border=\"0\" cellpadding=\"0\" cellspacing=\"4\">\n");
402       /*
403        * Print one table row for each image found:
404        */
405       for ($i=0; $i< $count; $i++)
406       {
407          $image_url = link_to_absolute($referrer_url, $image_urls[$i]);
408
409          /*
410           * Print the row(s):
411           */
412          echo ("       <tr>
413                         <td rowspan=\"2\">
414                          <input type=\"checkbox\" name=\"block_image[$i]\" value=\"off\">
415                         </td>
416                         <td>
417                          <a href=\"$image_url\">$image_url</a>:
418                         </td>
419                         <td>
420                          <input type=\"hidden\" name=\"image_url[$i]\" value=\"$image_url\">
421                         </td>
422                        </tr>
423                        <tr>
424                         <td>
425                          <img onload=\"prettyscale(this);\" src=\"$image_url\" alt=\"banner or not?\">
426                         </td>
427                        </tr>\n");
428       }
429       echo ("      </table>
430                   </dd>
431
432                   <dt>
433                    <b>If the banner that you saw is not listed above, enter the URL here</b>\n");
434    }
435    else
436    {
437       echo ("     <dt>
438                    <b>URL of the advertisment image:</b>\n");
439    }
440 }
441
442 ?>
443
444       <br><i>Hint: right-click the image, select "Copy image location" and paste the URL here.</i>
445      </dt>
446      <dd>
447       <p>
448        <input name="manual_image_url" type="text" size="45" maxlength="255">
449       </p>
450      </dd>
451
452 <?php if($problem != "P1") echo ("-->") ?>
453
454 <?php if($problem != "P2") echo ("<!--") ?>
455
456      <dt>
457       <p><b>URL of the innocent image:</b>
458        <br><i>Hint: right-click the image, select "Copy image location" and paste the URL here.
459        <br>This may not work if the image was blocked by size or if +image-blocker is set to redirect.</i>
460       </p>
461      </dt>
462      <dd>
463       <p>
464        <input name="image_url" value="unknown" type="text" size="45" maxlength="255">
465       </p>
466      </dd>
467
468 <?php if($problem != "P2") echo ("-->") ?>
469
470      <dt><b>Severity:</b></dt>
471      <dd>
472       <p>
473        <select name="severity">
474         <option value="3">drives me crazy</option>
475         <option selected value="2">normal</option>
476         <option value="1">cosmetic</option>
477        </select>
478       </p>
479      </dd>
480
481      <dt>
482       <b>Remarks:</b> <i>(optional)</i>
483      </dt>
484      <dd>
485       <p>
486        <textarea wrap="hard" style="font-size: 10px" name="remarks" cols="35" rows="3">None.</textarea>
487       </p>
488      </dd>
489
490      <dt>
491       <b>Your Name:</b> <i>(optional, public)</i>
492      </dt>
493      <dd>
494       <p>
495        <input name="name" size="45">
496       </p>
497      </dd>
498
499      <dt>&nbsp;</dt>
500      <dd>
501       <input type="submit" value="Submit">
502      </dd>
503
504     </dl>
505    </form>
506   </div>
507
508   <p>Valid <a href="http://validator.w3.org/">HTML 4.01 Transitional</a></p>
509
510  </body>
511 </html>