-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
298 lines (262 loc) · 9.05 KB
/
index.php
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Jack Northrup" />
<title>GET URL</title>
<link rel="stylesheet" href="reset.css" />
<style>
p {
font-size: 1.5em;
color:#272928;
background:white;
}
</style>
</head>
<body style="all:initial;">
<div style="padding=8px;margin:8px;">
<div id="wrapper">
<h1 style="color:#272928; background:white;">Get_URL Project</h1>
<h2>Get URLs Convert to Static HTML Pages</h2>
<p>Description: The project is designed to capture webpages convert them into Base64 Data and store the data in a MySQL Database. After the pages are converted to base64 data and stored it may be retrieved by id and viewed as a decoded webpage. The webpages also may be converted to a static html page with your choice of name. Example: MyStoredPage.html</p>
<p>objective: I have an online notebook. The notes kept in the notebook are searchable. I wanted the pages / articles created to exist as a static html webpage. I also have some very productive search queries that would be nice to exist as a static webpage. This project will sucessfully accomplish that taskdo that.</p>
<p>Future Plans: Currently the project does not capture any CSS except for that that is inline. Since it is primarily designed to work with my notebook, that is not important because the pages all use to local CSS file and look good. Get-URL will also capture off-site or non-local domain webpages. The off-sites webpages have no CSS other than What was used inline. The project's use will expand tremendously if it can also capture the CSS of an off-site webpage.</p>
<div id="center-column">
<div id="post">
<hr>
<center>
<h2>To GET and Store a URL</h2>
<h4>Copy and Paste a URL and give it keywords</h4>
</center>
<br />
<center><form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
URL: <textarea style="width: 60%;height: 2.5em;"
cols="70" rows="1" name="origpage" value=""></textarea></span><br />
<br />
Keywords: <textarea style="width: 60%;height: 2.5em;"
cols="70" rows="1" name="origkeywords" value="text"></textarea></span><br />
<br /> <span style="float: right; margin-right: 50%; color: red;"><input
type="submit" name="submit" value="Enter" /></span><br />
<br /><br />
<hr>
<hr>
</form></center>
<br />
<center>
<h2>To Convert Stored Data to HTML</h2>
<h4>Enter ID number and a PageName (do not enter the extension)</h4>
</center>
<br />
<center><form action="" method="post">
Enter ID -:<input style="margin-right:20%;width: 10%;height: 2.5em;"type="text" name="data" />
<br /><br /> Save as PageName:
<textarea style="width: 60%;height: 2.5em;"cols="50" rows="2" name="pagename" value="text"></textarea>
<br />
<br /> <span color: red;"><input type="submit" name="makeit" value="Enter" /></span>
</form></center>
<br /><br /><br />
<hr>
<hr><br />
<center><h2>View a Stored Page by ID</h2>
<form action="" method="post">
View by Id:
<textarea style="width: 60%;height: 2.5em;"cols="50" rows="2" name="origid" value="text"></textarea>
<br />
<br /> <input type="submit" name="submit2" value="Enter" />
</form></center>
<br />
<hr>
<hr><br />
<center><h2>Delete a Stored Page by ID</h2>
<form action="" method="post">
Delete Sql by Id:
<textarea style="width: 60%;height: 2.5em;"cols="50" rows="2" name="delid" value="text"></textarea>
<br />
<br /> <input type="submit" name="deleteit" value="Enter" />
</form></center>
<br /><hr /><hr />
<center><h2>"CLICKABLE" List of html Generated Pages</h2><br />
<?php
settype($thelist, "string");
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && strtolower(substr($file, strrpos($file, '.') + 1)) == 'html')
{
$thelist .= '<li><a href="'.$file.'">'.$file.'</a></li>';
}
}
echo $thelist;
closedir($handle);
}
?></center><hr />
<center>
<h2>View and Delete Files</h2>
<h4>Select file to view then view or delete</h4>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<input type="file" name="filename" value="" />
<input type="submit" name="submit" value="VIEW" />
<input type="submit" name="delete" value="DELETE" style="color:red;" />
<br />
</form>
<?php
if (isset ( $_POST ['submit'] ) ) {
$view = file_get_contents ($_POST ['filename'] );
echo $view;
} ;
?>
<?php
if (isset ( $_POST ['delete'] ) && ! empty ($_POST ['filename'] )) {
$filename = $_POST ['filename'];
unlink($filename);
$filename = NULL;
}
?>
</center>
<br /><br />
<hr style="height:5px;background-color:gray;" >
<hr style="height:5px;background-color:gray;" >
<br /><br />
<?php
//connection to the database
$hostname = "localhost";
$username = "root";
$password = "";
$database = "geturl";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db($database,$dbhandle)
or die("Could not select geturl");
?>
executed an SQL query and return the last 3 records
<?php $result = mysql_query("SELECT * FROM `urls`" . "ORDER BY `ID` DESC LIMIT 3"); ?>
<div class="boxit">
<?php
// fetch the data from the database
while ( $row = mysql_fetch_array ( $result ) ) {
echo "ID -" . $row ['id'] . " Date:" . $row ['date'] . "<br />";
$page = base64_decode ( $row ['page'] ) . "<br />";
$keywords = $row ['keywords'];
// display the keywords and the WebPage
echo $keywords . "<br />";
echo $page . "<br /><br /><hr>";
}
?>
<?php
// executed the SQL query and return 1 record
if (isset ( $_POST ["submit2"] ) && ! empty ( $_POST ["origid"] )) {
?>
<?php
$id = $_POST ["origid"];
$result = mysql_query ( "SELECT * FROM urls WHERE id=" . ( int ) $id . " LIMIT 1" );
// fetch the data from the database
?>
<?php
while ( $row = mysql_fetch_array ( $result ) ) {
echo "ID -" . $row ['id'] . " Date:" . $row ['date'] . "<br />";
$page = base64_decode($row['page'])."<br />";
$keywords = $row['keywords'];
echo $keywords."<br />";
echo $page."<br /><br /><hr>";
echo "Here is your Page";
}
}
?>
</div>
<?php
if (isset ( $_POST ['submit'] )) {
header ( 'Content-Type: text/html; charset=UTF-8' );
$con = mysqli_connect ( "localhost", "root", "", "geturl" );
// Check connection
if (mysqli_connect_error ()) {
echo "Failed to connect to MySQL SERVER: " . mysqli_connect_error ();
}
$keywords = $_POST [origkeywords];
$page1 = file_get_contents ( $_POST [origpage] );
$page = base64_encode ( $page1 );
$sql = "INSERT INTO urls (keywords, page)
VALUES
('$keywords','$page')";
if (! mysqli_query ( $con, $sql )) {
die ( 'Error - Failed to post: ' . mysqli_error ( $con ) );
}
mysqli_close ( $con );
header ( "Location: index.php" );
?>
<?php
header ( 'Content-Type: text/html; charset=UTF-8' );
?>
<?php
// execute the SQL query and return 5 records
$result = mysql_query ( "SELECT * FROM `urls`" . " ORDER BY `ID` DESC LIMIT 5 " );
// fetch the data from the database
?>
<div class="boxit">
<?php
while ( $row = mysql_fetch_array ( $result ) ) {
echo "ID -" . $row ['id'] . " Date:" . $row ['date'] . "<br />";
$page = base64_decode ( $row ['page'] ) . "<br />";
$keywords = $row ['keywords'];
echo $keywords . "<br />";
echo $page . "<br /><br /><hr>";
}
}
?>
<?php
// execute the SQL query and return 1 record
if (isset ( $_POST ["makeit"] ) && ! empty ( $_POST ["pagename"] )) {
$data = $_POST ['data'];
$pagename = $_POST ['pagename'];
$min_length = 5;
if (strlen ( $pagename ) >= $min_length) {
$result = mysql_query ( "SELECT * FROM urls WHERE id= '$data'" );
// fetch the data from the database
?>
</div>
<div class="boxit">
<?php
while ( $row = mysql_fetch_array ( $result ) ) {
echo "ID -" . $row ['id'] . " Date:" . $row ['date'] . "<br />";
$page = base64_decode ( $row ['page'] ) . "<br />";
$keywords = $row ['keywords'];
echo $keywords . "<br />";
echo $page . "<br /><br /><hr>";
$file = $pagename . '.html';
file_put_contents ( $file, $page );
}
?>
<?php Echo "<h2>CLICK RED FILENAME TO VIEW HTML:<a style='color:red;' href=$file>$pagename</a></h2>"?>
<?php
}
}
?>
<?php
if(isset($_POST['deleteit']))
{
$con = mysql_connect($hostname, $username, $password);
if(! $con )
{
die('Could not connect: ' . mysql_error());
}
//$id = $_POST['id'];
$sql = "DELETE FROM urls WHERE ID={$_POST['delid']} LIMIT 1";
//$sql = "DELETE comments ".
// "WHERE id = $id" ;
mysql_select_db($database);
$retval = mysql_query( $sql, $con );
if(! $retval )
{
die('Could not delete data: ' . mysql_error());
}
echo "Deleted data successfully\n";
mysql_close($con);
}
?>
</div>
</div>
</div>
</div></div>
</body>
</html>