-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.php
133 lines (128 loc) · 5.49 KB
/
display.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
<?php
//just in case we want line numbers, uncomment below
$count = 0;
//put your fbid here
$fbid = "something";
// load the file into memory
$readjson = file_get_contents('facebook-'.$fbid.'/posts/your_posts_1.json');
// decode the file in memory to json
$json_object = json_decode($readjson, true);
// go through the json file and make each section an entry
foreach ($json_object as $json_entry) {
//flush
$timestamp = "";
$updated_time = "";
$title = "";
$tags = "";
$tagged = "";
$post = "";
$data = "";
$attachments = "";
$media = "";
$link = "";
//look for the timestamp
if (isset($json_entry['timestamp'])) {
$timestamp = date('m-d-Y H:i',$json_entry['timestamp']);
} else {
//strange, they all should have one
$timestamp = "***NO TIMESTAMP***";
}
//look for a title
if (isset($json_entry['title'])) {
$title = $json_entry['title'];
} else {
//fb is messy
$title = "";
}
//check for tags
if (isset($json_entry['tags'])) {
//look for tagged people
$tags = "(tagged:";
foreach(($json_entry['tags']) as $tagged) {
$tags = $tags.$tagged." ";
}
$tags = $tags.")";
} else {
//nobody tagged cleanup
$tags = "";
}
//check for data on the main array
if (isset($json_entry['data'])) {
//found data
foreach ($json_entry['data'] as $data) {
//look at the data
//print_r($data);
//check to see if the timestamp had been updated
if (isset($data['update_timestamp'])) {
$updated_time = date('m-d-Y H:i',$data['update_timestamp']);
if ($updated_time == $timestamp) {
//echo "same"
} else {
$timestamp = $timestamp." updated: ".$updated_time;
}
}
//see if ther was a post
if (isset($data['post'])) {
$post = $data['post'];
}
//need more work here
}
} else {
$data = "***NO DATA***";
}
//check for attachments
if (isset($json_entry['attachments']) && (!empty($json_entry['attachments']))) {
foreach ($json_entry['attachments'] as $attachments) {
if (isset($attachments['data']) && (!empty($attachments['data']))) {
foreach ($attachments['data'] as $attach_data) {
if (isset($attach_data['media']['uri']) && (!empty($attach_data['media']['uri']))) {
// print_r($attach_data['media']['uri']);
$nextmedia = "<img src=\"./facebook-".$fbid."/".$attach_data['media']['uri']."\" width=\"100\">";
$media = $nextmedia." ".$media;
} else {
//-- no media
}
if (isset($attach_data['external_context']['url']) && (!empty($attach_data['external_context']['url']))) {
// print_r($attach_data['external_context']['url']);
$tubeid = getYoutube($attach_data['external_context']['url']);
if ($tubeid !== "") {
$thumbURL = 'http://img.youtube.com/vi/'.$tubeid.'/0.jpg';
$link = "<a href=\"".$attach_data['external_context']['url']."\"><img src=\"".$thumbURL."\"width=\"100\"></a>";
} else {
//not youtube print normal
$link = "<a href=\"".$attach_data['external_context']['url']."\">".$attach_data['external_context']['url']."</a>";
}
} else {
//-- no external
}
}
} else {
//- no data
}
}
} else {
//no attachement
}
//echo $count." ";
echo $timestamp." ";
if ($title) echo "<b>".$title."</b><br>";
if ($tags) echo $tags."<br>";
echo $post."<br>";
if ($link) echo $link."<br>";
if ($media) echo $media."<br>";
//go to the next item in the object
$count++;
}
function getYoutube($url) {
$youtube_id = "";
$shortUrlRegex = '/youtu.be\/([a-zA-Z0-9_-]+)\??/i';
$longUrlRegex = '/youtube.com\/((?:embed)|(?:watch))((?:\?v\=)|(?:\/))([a-zA-Z0-9_-]+)/i';
if (preg_match($longUrlRegex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}
if (preg_match($shortUrlRegex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}
return $youtube_id;
}
?>