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