-
Notifications
You must be signed in to change notification settings - Fork 0
/
importer.php
68 lines (50 loc) · 1.44 KB
/
importer.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
<?php
$ids = array();
$handle = @fopen("data.txt", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
if($result = parseData($buffer)) {
$ids[] = $result;
}
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
echo json_encode($ids);
function parseData($data) {
$url_parts = parse_url($data);
$path_parts = explode("/", $url_parts['path']);
if(count($path_parts) > 3) {
$number = trim(str_replace("_", "", $path_parts[3]));
if(is_numeric($number)) {
return getFacebookID($number);
} else {
// return "something is wrong: " . $path_parts[3] . "\n";
}
} else {
$name = trim(str_replace("_", "", $path_parts[1]));
return getFacebookID($name);
}
} //parseData
function getFacebookID($name) {
$response = file_get_contents_curl("https://graph.facebook.com/{$name}");
$result = json_decode($response);
$facebookID = trim($result->id);
if($facebookID !== "")
return $facebookID;
else
return; // return "Error getting Facebook ID for {$name}.\n";
}
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}