-
Notifications
You must be signed in to change notification settings - Fork 0
/
psArchive.phps
133 lines (116 loc) · 5.83 KB
/
psArchive.phps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
// Config
$show_header = true;
$show_footer = true;
// End config
// Source code disclaimer - always added
$ps_disclaimer = '<!--
PurpleSlurple Copyright 2002 by Matthew A. Schneider.
PurpleSlurple code is licensed under the Open Software License version 1.1.
This version was modified 12.12.2006 by
Hans Fredrik Nordhaug <[email protected]>:
- Made it work with register globals off (which is highly recommended).
- Added autodetecting of location of this script.
- Inserted header/disclaimer, style, base and footer without
creating invalid HTML/breaking existing package.
- Added config section, might not be very useful.
***************************************************************
* PurpleSlurple(TM) was created by Matthew A. Schneider *
* and was inspired by Purple, Augment, and others. *
* It was created ostensibly for the purpose of *
* facilitating my communication with Eric S. Raymond *
* regarding edits to his "How to Become a Hacker" document. *
* I\'m not kidding. You can\'t make this stuff up! *
***************************************************************
-->';
// Automatically detect the location of this file
if (isset($_SERVER['PATH_INFO']) && ($_SERVER['PATH_INFO'] !="") ) {
$file_location = $_SERVER['PATH_INFO'];
} else if (isset($_SERVER['PHP_SELF']) && ($_SERVER['PHP_SELF'] !="") ) {
$file_location = $_SERVER['PHP_SELF'];
} else {
$file_location = $_SERVER['SCRIPT_NAME'];
}
$file_location = "http://".$_SERVER['HTTP_HOST'].$file_location;
// Register globals is bad, bad, bad - setting $theurl explicitly
$theurl = $_GET['theurl'];
//if (!ereg('^[^./][^/]*$', $theurl))
// die('bad filename'); //die, do not process
// check for target URL, if none present PS form
if (!($theurl))
{
echo '
<title>PurpleSlurple</title>
<h2>Welcome to PurpleSlurple ™</h2>
<h3>Granular Addressability in HTML Documents - ON THE FLY</h3>
<p><b><q>Slurp up a Web page, spit back Purple numbers</q></b></p><hr>
<p>If you are not familiar with Purple numbers you may want to read Eugene Eric Kim\'s “
<a href="http://www.eekim.com/software/purple/purple.html">An Introduction to Purple</a>”.
See also Eric Armstrong\'s comments on <a href="'.$file_location.
'?theurl=http://www.treelight.com/software/collaboration/whatsWrongWithEmail.html#purp587">granular addressability</a></p>
<p>Want one-click Purple numbers? Right-click on this link,
<a href="javascript:location.href=\''.$file_location.
'?theurl=\'+document.location.href;">PurpleSlurple Bookmarklet</a>,
and bookmark it, or drag and drop this bookmark onto your browser\'s personal toolbar.
Now when you are viewing a page on which you would like Purple numbers just click the bookmarklet.
(Javascript must be enabled).</p><hr>
<p>Enter the URL of the page to which you would like to apply Purple numbers.</p>
<form method="get" action="ps.php"><input type="text" name="theurl" size="30">
(e.g., http://www.somedomain.com/somepage.html)<br><input type="submit" value="Submit"></form>
<hr><p><a href="http://www.purpleslurple.net/">PurpleSlurple</a> ™
was created by <a href="mailto:[email protected]">Matthew A. Schneider</a></p>';
exit;
}
// check for sloppy input - missing protocol
if (!ereg('://', $theurl))
$theurl = "http://".$theurl;
// check for http-based url (thanks Jonathan Cheyer)
if (!ereg('http://', $theurl))
die('PurpleSlurple only supports http-based urls'); //die, do not process
// Do not slurp self
if (strpos($theurl,$file_location) !== false)
die('PurpleSlurple won\'t slurp itself :-)'); //die, do not process
// PurpleSlurple header/disclaimer and expand / collapse link
$ps_header = '<p>This page was generated by <a href="'.$file_location.'">PurpleSlurple</a>™.
The original page can be found <a href="'.$theurl.'">here</a>.</p><hr>';
// The following isn't displayed since the collapse function really doesn't
// work as intended - as far as I can tell. (Hans Nordhaug, 12.05.2007.)
$ps_header_unused = '<br><a href="'.$file_location.'?collapse=no&theurl='.$theurl.'">expand</a> | 
<a href="'.$file_location.'?collapse=yes&theurl='.$theurl.'">collapse</a><p><hr>';
// PurpleSlurple footer
$ps_footer = '<br style="clear:both"><hr><p style="height: 700px">
<a href="http://www.purpleslurple.net/">PurpleSlurple</a>™ was created
by <a href="mailto:[email protected]">Matthew A. Schneider</a></p>';
// set base to ensure relative links work
// Thanks to http://marc.theaimsgroup.com/?l=php-general&m=95597547227951&w=2 Duh!
$ps_base = "<base href='$theurl'>";
// PurpleSlurple "Proxy" stuff goes here (or somewhere) someday
// collapse outline (hiding elements)
$ps_style = "<style type='text/css'>p {display:none}\nli {display:none}\n</style>\n";
// get the web page into an array, loop through array, find <h>, <p> and <li> tags, apply Purple numbers
$fcontents = file($theurl);
$theurl = urlencode($theurl);
$ps_contents = "";
while (list ($line_num, $line) = each($fcontents)) {
$pattern = "<p[^>]*>|<h[1-6][^>]*>|<li[^nk>]*>";
$replacement = "\\0(<a href='$file_location?theurl=$theurl#purp$line_num' name='purp$line_num'><font color='purple'>$line_num</font></a>) ";
$ps_contents .= eregi_replace($pattern, $replacement, $line);
}
// find head and body and insert disclaimer/header/footer/style/base
list($head,$body) = explode("</head>", $ps_contents);
if (isset($_GET['collapse']) && ($_GET['collapse'] == "yes")) {
$head = str_replace("<head>","<head>\n$ps_style", $head);;
}
if (!strpos("<base",$head)) {
$head = str_replace("<head>","<head>\n$ps_base", $head);;
}
$head = str_replace("<head>","<head>\n$ps_disclaimer", $head);
if ($show_header) {
$body = eregi_replace("<body[^>]*>","\\0\n$ps_header",$body);
}
if ($show_footer) {
$body = str_replace("</body>","$ps_footer\n</body>",$body);
}
// Sending result to browser
echo $head."</head>".$body;
?>