@@ -106,24 +106,26 @@ public function getPosts() {
106
106
107
107
$ this ->log ->info (" + Getting post details... " );
108
108
$ fdPosts = $ graphNode ->getField ('posts ' );
109
- $ timeLimit = $ this ->db ->getTimeLimit ($ this ->partyCode , 'fb ' , 'T ' , $ this ->scrapeFull );
110
109
111
110
$ pageCount = 0 ;
112
111
$ txtCount = 0 ;
113
112
$ vidCount = 0 ;
114
113
$ loopCount = 0 ;
115
114
$ temp = [];
116
115
116
+ $ timeLimit = $ this ->db ->getTimeLimit ($ this ->partyCode , 'fb ' , 'T ' , $ this ->scrapeFull );
117
+
117
118
do {
118
119
$ this ->log ->debug (" + Page " . $ pageCount );
119
120
120
121
foreach ($ fdPosts as $ key => $ post ) {
121
- if (in_array ($ post ->getField ('id ' ), $ temp , true )) {
122
+ $ id = $ post ->getField ('id ' );
123
+
124
+ if (in_array ($ id , $ temp , true )) {
122
125
// if post was already scraped this session
123
126
$ loopCount ++;
124
127
continue ;
125
128
}
126
- $ temp [] = $ post ->getField ('id ' );
127
129
128
130
$ type = $ post ->getField ('type ' );
129
131
// types = 'status', 'link', 'photo', 'video', 'event'
@@ -138,7 +140,7 @@ public function getPosts() {
138
140
$ txtCount ++;
139
141
}
140
142
141
- $ this ->getPostDetails ($ post , $ subType );
143
+ $ temp [ $ id ] = $ this ->getPostDetails ($ post , $ subType );
142
144
}
143
145
144
146
$ timeCheck = $ post ->getField ('created_time ' )->getTimestamp (); // check time of last scraped post
@@ -151,6 +153,8 @@ public function getPosts() {
151
153
$ this ->log ->warning (" - Facebook post scraping for " . $ this ->partyCode . " looped " . $ loopCount . " times " );
152
154
}
153
155
156
+ $ this ->db ->processSocialMedia ($ temp );
157
+
154
158
$ out ['posts ' ] = $ txtCount ;
155
159
$ out ['videos ' ] = $ vidCount ;
156
160
$ this ->log ->info (" + " . $ txtCount . " text posts and " . $ vidCount . " videos since " . date ('d/m/Y ' , $ timeCheck ) . " processed " );
@@ -194,19 +198,22 @@ public function getPostDetails($post, $subType) {
194
198
'shares ' => $ shareCount
195
199
];
196
200
197
- $ this ->db ->addSocial (
198
- $ this ->partyCode ,
199
- SocialMedia::TYPE_FACEBOOK ,
200
- $ subType ,
201
- $ post ->getField ('id ' ),
202
- $ post ->getField ('updated_time ' ), // DateTime
203
- $ text ,
204
- $ img ,
205
- $ reactionCount ,
206
- $ allData
207
- );
201
+ $ out = [
202
+ 'code ' => $ this ->partyCode ,
203
+ 'type ' => SocialMedia::TYPE_FACEBOOK ,
204
+ 'subtype ' => $ subType ,
205
+ 'id ' => $ post ->getField ('id ' ),
206
+ 'time ' => $ post ->getField ('updated_time ' ), // DateTime
207
+ 'text ' => $ text ,
208
+ 'img ' => $ img ,
209
+ 'likes ' => $ reactionCount ,
210
+ 'allData ' => $ allData
211
+ ];
212
+
213
+ return $ out ;
208
214
}
209
215
216
+
210
217
/**
211
218
* Processes images
212
219
* @param string $requestFields
@@ -223,13 +230,14 @@ public function getImages() {
223
230
224
231
$ this ->log ->info (" + Getting image details... " );
225
232
$ fdAlbums = $ graphNode ->getField ('albums ' );
226
- $ timeLimit = $ this ->db ->getTimeLimit ($ this ->partyCode , 'fb ' , 'I ' , $ this ->scrapeFull );
227
233
228
234
$ pageCount = 0 ;
229
235
$ imgCount = 0 ;
230
236
$ loopCount = 0 ;
231
237
$ temp = [];
232
238
239
+ $ timeLimit = $ this ->db ->getTimeLimit ($ this ->partyCode , 'fb ' , 'I ' , $ this ->scrapeFull );
240
+
233
241
foreach ($ fdAlbums as $ key => $ album ) {
234
242
$ photoCount [] = $ album ->getField ('photo_count ' );
235
243
$ fdPhotos = $ album ->getField ('photos ' );
@@ -240,15 +248,17 @@ public function getImages() {
240
248
241
249
do {
242
250
$ this ->log ->debug (" + Page " . $ pageCount );
251
+
243
252
foreach ($ fdPhotos as $ key => $ photo ) {
244
- if (in_array ($ photo ->getField ('picture ' ), $ temp , true )) {
253
+ $ id = $ photo ->getField ('picture ' );
254
+
255
+ if (in_array ($ id , $ temp , true )) {
245
256
// if image was already scraped this session
246
257
$ loopCount ++;
247
258
continue ;
248
259
}
249
- $ temp [] = $ photo ->getField ('picture ' );
250
260
251
- $ this ->getImageDetails ($ photo , $ album );
261
+ $ temp [ $ id ] = $ this ->getImageDetails ($ photo , $ album );
252
262
$ imgCount ++;
253
263
}
254
264
@@ -263,6 +273,8 @@ public function getImages() {
263
273
$ this ->log ->warning (" - Facebook image scraping for " . $ this ->partyCode . " looped " . $ loopCount . " times " );
264
274
}
265
275
276
+ $ this ->db ->processSocialMedia ($ temp );
277
+
266
278
$ out ['imageCount ' ] = array_sum ($ photoCount );
267
279
$ out ['images ' ] = $ imgCount ;
268
280
$ this ->log ->info (" + " . $ out ['imageCount ' ] . " images found, " . $ imgCount . " since " . date ('d/m/Y ' , $ timeCheck ) . " processed " );
@@ -305,17 +317,19 @@ public function getImageDetails($photo, $album) {
305
317
'shares ' => $ shareCount
306
318
];
307
319
308
- $ this ->db ->addSocial (
309
- $ this ->partyCode ,
310
- SocialMedia::TYPE_FACEBOOK ,
311
- SocialMedia::SUBTYPE_IMAGE ,
312
- $ photo ->getField ('id ' ),
313
- $ photo ->getField ('updated_time ' ), // DateTime
314
- $ photo ->getField ('name ' ),
315
- $ img ,
316
- $ reactionCount ,
317
- $ allData
318
- );
320
+ $ out = [
321
+ 'code ' => $ this ->partyCode ,
322
+ 'type ' => SocialMedia::TYPE_FACEBOOK ,
323
+ 'subtype ' => SocialMedia::SUBTYPE_IMAGE ,
324
+ 'id ' => $ photo ->getField ('id ' ),
325
+ 'time ' => $ photo ->getField ('updated_time ' ), // DateTime
326
+ 'text ' => $ photo ->getField ('name ' ),
327
+ 'img ' => $ img ,
328
+ 'likes ' => $ reactionCount ,
329
+ 'allData ' => $ allData
330
+ ];
331
+
332
+ return $ out ;
319
333
}
320
334
321
335
@@ -335,24 +349,27 @@ public function getEvents() {
335
349
336
350
$ this ->log ->info (" + Getting event details... " );
337
351
$ fdEvents = $ graphNode ->getField ('events ' );
338
- $ timeLimit = $ this ->db ->getTimeLimit ($ this ->partyCode , 'fb ' , 'E ' , $ this ->scrapeFull );
339
352
340
353
$ pageCount = 0 ;
341
354
$ eveCount = 0 ;
342
355
$ loopCount = 0 ;
343
356
$ temp = [];
344
357
358
+ $ timeLimit = $ this ->db ->getTimeLimit ($ this ->partyCode , 'fb ' , 'E ' , $ this ->scrapeFull );
359
+
345
360
do { // process current page of results
346
361
$ this ->log ->debug (" + Page " . $ pageCount );
362
+
347
363
foreach ($ fdEvents as $ key => $ event ) {
348
- if (in_array ($ event ->getField ('id ' ), $ temp , true )) {
364
+ $ id = $ event ->getField ('id ' );
365
+
366
+ if (in_array ($ id , $ temp , true )) {
349
367
// if event was already scraped this session
350
368
$ loopCount ++;
351
369
continue ;
352
370
}
353
- $ temp [] = $ event ->getField ('id ' );
354
371
355
- $ this ->getEventDetails ($ event );
372
+ $ temp [ $ id ] = $ this ->getEventDetails ($ event );
356
373
$ eveCount ++;
357
374
}
358
375
@@ -366,6 +383,8 @@ public function getEvents() {
366
383
$ this ->log ->warning (" - Facebook event scraping for " . $ this ->partyCode . " looped " . $ loopCount . " times " );
367
384
}
368
385
386
+ $ this ->db ->processSocialMedia ($ temp );
387
+
369
388
$ out ['eventCount ' ] = $ eveCount ;
370
389
$ out ['events ' ] = true ;
371
390
$ this ->log ->info (" + " . $ out ['eventCount ' ] . " events found and processed " );
@@ -421,17 +440,19 @@ public function getEventDetails($event) {
421
440
'comments ' => $ commentCount
422
441
];
423
442
424
- $ this ->db ->addSocial (
425
- $ this ->partyCode ,
426
- SocialMedia::TYPE_FACEBOOK ,
427
- SocialMedia::SUBTYPE_EVENT ,
428
- $ event ->getField ('id ' ),
429
- $ event ->getField ('updated_time ' ), // DateTime
430
- $ event ->getField ('name ' ),
431
- $ img ,
432
- $ event ->getField ('interested_count ' ),
433
- $ allData
434
- );
443
+ $ out = [
444
+ 'code ' => $ this ->partyCode ,
445
+ 'type ' => SocialMedia::TYPE_FACEBOOK ,
446
+ 'subtype ' => SocialMedia::SUBTYPE_EVENT ,
447
+ 'id ' => $ event ->getField ('id ' ),
448
+ 'time ' => $ event ->getField ('updated_time ' ), // DateTime
449
+ 'text ' => $ event ->getField ('name ' ),
450
+ 'img ' => $ img ,
451
+ 'likes ' => $ event ->getField ('interested_count ' ),
452
+ 'allData ' => $ allData
453
+ ];
454
+
455
+ return $ out ;
435
456
}
436
457
437
458
}
0 commit comments