forked from sergeychernyshev/showslow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.php
61 lines (49 loc) · 1.07 KB
/
import.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
<?php
require_once(dirname(__FILE__).'/global.php');
$sites = file('php://stdin');
$user_id = 1;
$pairs = '';
$first = true;
foreach ($sites as $site) {
if ($first) {
$first = false;
} else {
$pairs .= ', ';
}
$site = trim($site);
$url = filter_var($site, FILTER_VALIDATE_URL);
# let's try to beautify the URL by appending http://www.
if ($url === false) {
if (substr($site, 0, 3) == 'www') {
$url = filter_var('http://'.$site.'/', FILTER_VALIDATE_URL);
}
else
{
$url = filter_var('http://www.'.$site.'/', FILTER_VALIDATE_URL);
}
}
else
{
# skipping non-http URLs
if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://') {
echo "Skipping non-http URL: $url\n";
continue;
}
}
echo "Importing URL: $url ...";
if ($url === false) {
echo "Bad data ($site)\n";
continue;
}
else
{
echo " OK\n";
}
$url_id = getUrlId($url);
$pairs .= '('.$user_id.','.$url_id.')';
}
$query = "INSERT IGNORE INTO user_urls (user_id, url_id) VALUES $pairs";
$result = mysql_query($query);
if (!$result) {
error_log(mysql_error());
}