-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewsFeed-1.1.php
275 lines (212 loc) · 8.97 KB
/
NewsFeed-1.1.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
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/Logger.php';
require_once __DIR__ . '/FacebookHelp.php';
class NewsFeed extends Logger
{
public function __construct()
{
parent::__construct1('NewsFeed-1.1/');
$fbHelp = new FacebookHelp();
$app_id = '1741599822726232';
$app_secret = 'MyAppSecret';
$graph_version = 'v2.5';
$access_token = 'MyAccessToken';
$session = $fbHelp->generateSession($app_id, $app_secret, $graph_version, $access_token);
$id = '/337336379785052';
$limitofposts = 3;
$message;
$ammountOfPosts = 0;
$amountOfAttachments = 0;
$linksForGalery;
$firstLinkForGalery;
$pictureLink;
// 337336379785052
// db login datas
$servername = 'localhost';
$username = 'www-data';
$password = 'MySecretPassword';
// time when the script is called
$timeStamp = time();
$date = date("d.m.Y", $timeStamp);
$time = date("H:i:s",$timeStamp);
// general information about the facebook page
if(!($personalinformation = $fbHelp->generateGraphUser($id, $session)))
die("Fehler bitte ins Log schauen!");
// request for the profile picture
if(!($profile_picture = $fbHelp->generateGraphPicture($id . "/picture?type=large&redirect=false", $session)))
die("Fehler bitte Log lesen!");
// request for the facebook posts
if(!($graphEdge = $fbHelp->generateGraphEdge($id . '/posts?limit=' . $limitofposts, $session)))
die("Fehler Bitte Log lesen!");
$currentPage = serialize($graphEdge);
file_put_contents("furtherNews/currentPage.graphedge", $currentPage);
// Before writing new data into the HTML-file it has to be cleared
parent::writehtml("NewsFeed-1.1.html", " " ,"w");
// The foreach loop parses through every post from the response array
foreach($graphEdge as $key => $value)
{
$ammountOfPosts++;
if(!($attachmentsNode = $fbHelp->generateGraphNode('/' . $value->getField('id') . '?fields=attachments', $session)))
echo "Fehler bitte Log lesen!";
$medias = $attachmentsNode->getField('attachments');
$medias1 = $medias->getField('subattachments');
if ($medias[0]->getField('subattachments') == true) // if the "medias" Array contains the child "subattachments", the post contains more pictures
{
$medias = $medias[0]->getField('subattachments');
echo "\n" . count($medias);
foreach ($medias as $key1 => $value1)
{
$pictureLink[$key1] = $value1->getField('media')->getField('image')->getField('src'); // contains all links to the pictures of the post
echo $pictureLink[0];
$facebookPictureURLs[$key1] = $value1->getField('target')->getField('url'); // contains all links to the Facebook page of the pictures
$amountOfAttachments++; // amount of pictures
}
}
else // if the "medias" Array doesn't contain subattachments the post only have one picture
{
$pictureLink[0] = $medias[0]->getField('media')->getField('image')->getField('src'); // contains the link to the picture
$facebookPictureURLs[0] = $medias[0]->getField('target')->getField('url'); // contains the link to the picture's related Facebook page
$amountOfAttachments = 1; // it's only one picture so the value must be one
}
$createdtime = $value->getField('created_time');
$message = $value->getField('story');
$message = str_replace($personalinformation->getName(), "", $message);
$imageDimension = getimagesize($pictureLink[0]);
echo "\n" . $imageDimension[0] . " " . $imageDimension[1] . "\n";
// creates links for the galery
if($imageDimension[0]/$imageDimension[1] > 1)
{
$firstLinkForGalery .= '
<ul class="post-picture-left-wide post-picture-left">
<li>
<a style="color: black;" href="' . $pictureLink[0] . '" data-lightbox="attachmentGalery' . $ammountOfPosts . '">
<img src="' . $pictureLink[0] . '" alt="">
</a>
</li>
</ul>';
$linksForGalery = '<ul class="post-picture-right-wide post-picture-right">';
for ($i = 1; $i<count($pictureLink); $i++)
{
if ($i > 3)
{
$linksForGalery .= '<li style="display: none;"><a style="color: black;" href="' . $pictureLink[$i] . '" data-lightbox="attachmentGalery' . $ammountOfPosts . '">
</a></li>';
}
else
{
$linksForGalery .= ' <li>
<a style="color: black;" href="' . $pictureLink[$i] . '" data-lightbox="attachmentGalery' . $ammountOfPosts . '">
<img src="' . $pictureLink[$i] . '" alt="">
</a>
</li> ';
$counter++;
}
}
/*$linksForGalery .= '<p class="li-count" style="display: none;">' . $counter . '</p></ul>';*/
$linksForGalery .= '</ul>';
}
else
{
$firstLinkForGalery .= '
<ul class="post-picture-left">
<li>
<a style="color: black;" href="' . $pictureLink[0] . '" data-lightbox="attachmentGalery' . $ammountOfPosts . '">
<img src="' . $pictureLink[0] . '" alt="">
</a>
</li>
</ul>';
$linksForGalery = '<ul class="post-picture-right">';
for ($i = 1; $i<count($pictureLink); $i++)
{
if ($i > 3)
{
$linksForGalery .= '<li style="display: none"><a style="color: black;" href="' . $pictureLink[$i] . '" data-lightbox="attachmentGalery' . $ammountOfPosts . '">
</a></li>';
}
else
{
$linksForGalery .= ' <li>
<a style="color: black;" href="' . $pictureLink[$i] . '" data-lightbox="attachmentGalery' . $ammountOfPosts . '">
<img src="' . $pictureLink[$i] . '" alt="">
</a>
</li> ';
}
}
$linksForGalery .= '</ul>';
}
echo $count = count($pictureLink) . "\n";
// this is the String for the HTML page which contains all the information for the feed
$meineHtmlSeite1 = '<figure>
<div class="newsblock" style="">
<div class="newsHeader" style="">
<div class="header-left" style="">
<a href=http://facebook.com/' . $personalinformation->getId() . ' target="_blank">
<img style="" src="' . $profile_picture->getUrl() . '" alt="">
</a>
</div>
<div class="header-right" style="">
<a style="" href="http://facebook.com/' . $personalinformation->getId() . '" target="_blank">
<div class="name" style="">
<strong>
'
. $personalinformation->getName() .
'
</strong>
</div>
</a>
<div class="story">
<p>'
. $message .
'</p>
</div>
</div>
<div style="clear: right;"></div>
<div class="created-time">
<p style="">'
. $createdtime->format("d. F") . ' um ' . $createdtime->format("H:i:s") . ' Uhr
</p>
</div>
<div style="clear: both;"></div>
</div>
<article style="position: relative;">
<p style="">' . $value->getField("message") . '</p>
</article>
<div class="post-picture" style="">
' . $firstLinkForGalery . '
' . $linksForGalery . '
<p>' . $value->getField("name") . '</p>
<p>' . $value->getField("description") . '</p>
</div>
</figure>';
// restore variables for next iteration
$linksForGalery = '';
$firstLinkForGalery = '';
unset($pictureLink);
unset($imageDimension);
parent::writehtml("NewsFeed-1.1.html", $meineHtmlSeite1, "a+");
}
/*$anzahlPosts = fopen("furtherNews/ammountOfPosts.txt", "a");
echo fwrite($anzahlPosts, $ammountOfPosts);
fclose($anzahlPosts);*/
try
{
$conn = new PDO("mysql:host=$servername;dbname=FURTHERNEWSUSERS", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$url = $profile_picture->getUrl();
echo $url;
$sql_update = "update Benutzer set amountOfPosts='" . $ammountOfPosts . "', currentPost=?, timeStamp='" . time() . "',facebook_id='" . $personalinformation->getId() . "', profilepicturelink='" . $url . "', facebook_name='" . $personalinformation->getName() . "' where session_id='master'";
$update = $conn->prepare($sql_update);
$update->execute(array($currentPage));
parent::writelog("Log.txt", "update success. query: " . $sql_update, "a+");
}
catch(PDOException $e)
{
parent::writelog("ErrorLog.txt", parent::getCurrentTimeStamp() . " Fehler bei Datenbankupdate in NewsFeed-1.1.php: " . $e->getMessage(), "a");
die();
}
parent::writelog("TimeStampFile.txt", "Die Facebook News wurden am " . parent::getCurrentTimeStamp() . " aktualisiert", "a+");
}
}
new NewsFeed();
?>