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