From 37c63e6a5ff76cdd513ab70f5973bd08ddf224f3 Mon Sep 17 00:00:00 2001 From: Ben Liyanage Date: Thu, 25 Sep 2014 13:29:34 -0400 Subject: [PATCH] moved feed processing into separate function this will let it be unit tested independent of data retrieval, which will help me update this to the facebook 2.1 api version. In addition I moved some additional data sanitation into the function that uses the data. --- fbsync/fbsync.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 1c4a5d8c..e78f46b4 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -178,7 +178,8 @@ function fbsync_cron($a,$b) { fbsync_get_self($rr['uid']); logger('fbsync_cron: importing timeline from user '.$rr['uid']); - fbsync_fetchfeed($a, $rr['uid']); + $data = fbsync_fetchfeed($a, $rr['uid']); + fbsync_processfeed($data); } } @@ -646,6 +647,8 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl } function fbsync_createlike($a, $uid, $self_id, $self, $contacts, $like) { + //Sanitize data + $like->user_id = number_format($like->user_id, 0, '', ''); $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc("fb::".$like->post_id), @@ -1025,6 +1028,10 @@ function fbsync_fetchfeed($a, $uid) { return; } + return $data; +} + +function fbsync_processfeed($data){ $posts = array(); $comments = array(); $likes = array(); @@ -1061,12 +1068,14 @@ function fbsync_fetchfeed($a, $uid) { $post_data = array(); $comment_data = array(); + //These Indexes are Used for lookups in the next loop foreach ($avatars AS $avatar) { $avatar->id = number_format($avatar->id, 0, '', ''); $square_avatars[$avatar->id] = $avatar; } unset($avatars); + //These Indexes are used for lookups elsewhere foreach ($profiles AS $profile) { $profile->id = number_format($profile->id, 0, '', ''); @@ -1078,10 +1087,12 @@ function fbsync_fetchfeed($a, $uid) { unset($profiles); unset($square_avatars); - foreach ($applications AS $key = $application) { + //These Indexes are Used for lookups elsewhere + foreach ($applications AS $application) { $application->app_id = number_format($application->app_id, 0, '', ''); - $applications[$key] = $application; + $application_data[$application->app_id] = $application; } + unset($applications); foreach ($posts AS $post) { if ($post->updated_time > $last_updated) @@ -1095,8 +1106,6 @@ function fbsync_fetchfeed($a, $uid) { } foreach($likes AS $like) { - $like->user_id = number_format($like->user_id, 0, '', ''); - fbsync_createlike($a, $uid, $self_id, $self, $contacts, $like); }