Skip to content
Browse files

Added log-print in the end of the application.

Also implemented "optional" anonymization instead of permanent.
Added some more functions in the data-scraping.
  • Loading branch information...
1 parent 2854d71 commit 774c76925ee7bbff04e1c8eb47943a03a9956970 @Cromigon committed Oct 26, 2011
Showing with 175 additions and 97 deletions.
  1. +2 −0 .gitignore
  2. +2 −2 SETUP
  3. +3 −3 src/config.php
  4. +23 −10 src/functions/functions.php
  5. +85 −46 src/functions/output.php
  6. +13 −13 src/index.php
  7. +43 −21 src/mainApp/submitform.php
  8. +3 −1 src/mainApp/windows/form.php
  9. +1 −1 src/style/stylesheet.css
View
2 .gitignore
@@ -10,3 +10,5 @@ doc/*
nbproject/*
/nbproject
output/*
+log/*
+/src/nbproject
View
4 SETUP
@@ -21,8 +21,8 @@
6. copy everyting from FriendDataScraper/src to /var/www/fb/FriendDataAnalyzer
sudo cp -R /path/to/FriendDataScraper/src/* /var/www/fb/FriendDataAnalyzer
-7. Create and Give /var/www/fb/FriendDataAnalyzer/output permissions 777
- sudo mkdir /var/www/FriendDataAnalyzer/output && chmod 777 /var/www/fb/FriendDataAnalyzer/output
+7. Create and Give /var/www/fb/FriendDataAnalyzer/output and /var/www/fb/FrientDataAnalyzer/log permissions 777
+ sudo mkdir /var/www/fb/FriendDataAnalyzer/output && mkdir /var/www/fb/FriendDataAnalyzer/log && chmod 777 /var/www/fb/FriendDataAnalyzer/output && chmod 777 /var/www/fb/FriendDataAnalyzer/log
8. In the file /var/www/fb/FriendDataAnalyzer/config.php, replace YOUR_APP_ID_here and YOUR_APP_SECRET_HERE with your own appId and appSecret.
'appId' => 'YOUR_APP_ID_HERE',
View
6 src/config.php
@@ -1,12 +1,12 @@
<?php
require 'facebook-sdk/facebook.php';
-
$facebook = new Facebook(array(
- 'appId' => 'YOUR_APP_ID_HERE',
- 'secret' => 'YOUR_APP_SECRET_HERE',
+ 'appId' => 'YOUR_APPID_HERE',
+ 'secret' => 'YOUR_APPSECRET_HERE',
'cookie' => true,
'callback' => 'localhost/fb/FriendDataAnalyzer/',
));
+
?>
View
33 src/functions/functions.php
@@ -21,11 +21,7 @@ function getUserWall($result_array, $facebook, $fid, $key, $nrOfPosts) {
'method' => 'fql.query',
'query' => $fql,
));
-
- echo '<pre>';
- print_r($return_object);
- echo '</pre>';
-
+
foreach ($return_object as $index => $arrayindex) {
if ($return_object[$index]['message'] != "") {
@@ -50,7 +46,6 @@ function getUserWallSpec($result_array, $facebook, $fid, $key, $nrOfPosts, $sear
'query' => $fql,
));
-
foreach ($return_object as $index => $arrayindex) {
if ($return_object[$index]['message'] != "") {
@@ -63,7 +58,27 @@ function getUserWallSpec($result_array, $facebook, $fid, $key, $nrOfPosts, $sear
}
if (!isset($result_array[$key]['wallpostsCont'])) {
- $result_array[$key]['wallpostsCont'][0] = "No wallposts containting any text, no wallpost containing the specified text, or no access to the users Wall";
+ $result_array[$key]['wallpostsCont'][0] = "No wallposts containting any text, or no access to the users Wall";
+ }
+
+ return $result_array;
+}
+
+function getWallpostsShared($result_array, $facebook, $fid, $key, $nrOfPosts, $friends) {
+ $time = $_SERVER['REQUEST_TIME'];
+ $fql = "SELECT actor_id FROM stream WHERE source_id = " . $fid . " AND target_id !='' AND created_time < " . $time . " LIMIT " . $nrOfPosts;
+ $return_object = $facebook->api(array(
+ 'method' => 'fql.query',
+ 'query' => $fql,
+ ));
+
+ foreach ($return_object as $index => $arrayindex) {
+
+ if ($return_object[$index]['actor_id'] != "") {
+ if ($return_object[$index]['actor_id'] != $fid) {
+ $result_array[$key]['wallpostTarget'][$index] = $return_object[$index]['actor_id'];
+ }
+ }
}
return $result_array;
@@ -77,9 +92,7 @@ function getUserLikes($result_array, $facebook, $fid, $key) {
'query' => $fql,
));
- echo '<pre>';
- print_r($return_object);
- echo '</pre>';
+
foreach ($return_object as $index => $arrayindex) {
$result_array[$key]['likes'][$index] = $return_object[$index]['page_id'];
}
View
131 src/functions/output.php
@@ -1,6 +1,6 @@
<?php
-function writeToCVSFile($write_array) {
+function writeToCVSFile($write_array, $list_of_friends, $anonymization) {
if (isset($write_array[0]['wallposts'])) {
$wallposts = '../output/wallposts.csv';
@@ -19,15 +19,20 @@ function writeToCVSFile($write_array) {
$wallpostsCont_write = fopen($wallpostsCont, 'w') or die("can't open file");
$listwpc = array();
}
-
- if (isset($write_array[0]['towns'])) {
+
+ if (isset($write_array[0]['wallpostTarget'])) {
+ $wallpostsShare = '../output/wallpostsShared.csv';
+ $wallpostsShare_write = fopen($wallpostsShare, 'w') or die("can't open file");
+ $listwps = array();
+ }
+
+ if (isset($write_array[0]['towns'])) {
$towns = '../output/towns.csv';
$towns_write = fopen($towns, 'w') or die("can't open file");
$listtow = array();
}
-
foreach ($write_array as $key => $index) {
if (isset($write_array[$key]['wallposts'])) {
$listwp[$key] = array();
@@ -36,7 +41,11 @@ function writeToCVSFile($write_array) {
$arrayindexwp = str_replace('\n', " ", $arrayindexwp);
$listwp[$key][$messageindex] = utf8_decode($arrayindexwp);
}
- array_unshift($listwp[$key], $key);
+ if ($anonymization == 1) {
+ array_unshift($listwp[$key], $key);
+ } else {
+ array_unshift($listwp[$key], $list_of_friends[$key]);
+ }
}
if (isset($write_array[$key]['likes'])) {
@@ -47,7 +56,11 @@ function writeToCVSFile($write_array) {
$arrayindexlike = str_replace('\n', " ", $arrayindexlike);
$listlike[$key][$likeindex] = utf8_decode($arrayindexlike);
}
- array_unshift($listlike[$key], $key);
+ if ($anonymization == 1) {
+ array_unshift($listlike[$key], $key);
+ } else {
+ array_unshift($listlike[$key], $list_of_friends[$key]);
+ }
}
if (isset($write_array[$key]['wallpostsCont'])) {
@@ -58,56 +71,82 @@ function writeToCVSFile($write_array) {
$arrayindexwpc = str_replace('\n', " ", $arrayindexwpc);
$listwpc[$key][$messageindex] = utf8_decode($arrayindexwpc);
}
- array_unshift($listwpc[$key], $key);
- echo '<pre>';
- print_r($listwpc);
- echo '</pre>';
+ if ($anonymization == 1) {
+ array_unshift($listwpc[$key], $key);
+ } else {
+ array_unshift($listwpc[$key], $list_of_friends[$key]);
+ }
}
-
- if (isset($write_array[$key]['towns'])) {
- $listwpc[$key] = array();
- foreach ($write_array[$key]['towns'] as $townindex => $arrayindextow) {
- $arrayindextow = str_replace(',', " ", $arrayindextow);
- $arrayindextow = str_replace('\n', " ", $arrayindextow);
- $listtow[$key][$townindex] = utf8_decode($arrayindextow);
+ if (isset($write_array[$key]['wallpostTarget'])) {
+ $listwps[$key] = array();
+ foreach ($write_array[$key]['wallpostTarget'] as $targetindex => $arrayindexwps) {
+ $pos = array_search($arrayindexwps, $list_of_friends);
+ if ($anonymization == 1) {
+ if ($pos !== false) {
+ array_push($listwps[$key], $pos);
+ }
+ } else {
+ if ($pos !== false) {
+ array_push($listwps[$key], $list_of_friends[$pos]);
+ }
+ }
}
- array_unshift($listtow[$key], $key);
- echo '<pre>';
- print_r($listtow);
- echo '</pre>';
+ if ($anonymization == 1) {
+ array_unshift($listwps[$key], $key);
+ } else {
+ array_unshift($listwps[$key], $list_of_friends[$key]);
+ }
}
- }
-
-
+ if (isset($write_array[$key]['towns'])) {
+ $listwpc[$key] = array();
+
+ foreach ($write_array[$key]['towns'] as $townindex => $arrayindextow) {
+ $arrayindextow = str_replace(',', " ", $arrayindextow);
+ $arrayindextow = str_replace('\n', " ", $arrayindextow);
+ $listtow[$key][$townindex] = utf8_decode($arrayindextow);
+ }
+ if ($anonymization == 1) {
+ array_unshift($listtow[$key], $key);
+ } else {
+ array_unshift($listtow[$key], $list_of_friends[$key]);
+ }
+ }
+ }
- if (isset($write_array[0]['wallposts'])) {
- foreach ($listwp as $fieldswp) {
- fputcsv($wallposts_write, $fieldswp);
+ if (isset($write_array[0]['wallposts'])) {
+ foreach ($listwp as $fieldswp) {
+ fputcsv($wallposts_write, $fieldswp);
+ }
+ fclose($wallposts_write);
}
- fclose($wallposts_write);
- }
- if (isset($write_array[0]['likes'])) {
- foreach ($listlike as $fieldslike) {
- fputcsv($likes_write, $fieldslike);
+ if (isset($write_array[0]['likes'])) {
+ foreach ($listlike as $fieldslike) {
+ fputcsv($likes_write, $fieldslike);
+ }
+ fclose($likes_write);
}
- fclose($likes_write);
- }
- if (isset($write_array[0]['wallpostsCont'])) {
- foreach ($listwpc as $fieldswpc) {
- fputcsv($wallpostsCont_write, $fieldswpc);
+ if (isset($write_array[0]['wallpostsCont'])) {
+ foreach ($listwpc as $fieldswpc) {
+ fputcsv($wallpostsCont_write, $fieldswpc);
+ }
+ fclose($wallpostsCont_write);
}
- fclose($wallpostsCont_write);
- }
-
- if (isset($write_array[0]['towns'])) {
- foreach ($listtow as $fieldstow) {
- fputcsv($towns_write, $fieldstow);
+
+ if (isset($write_array[0]['wallpostTarget'])) {
+ foreach ($listwps as $fieldswps) {
+ fputcsv($wallpostsShare_write, $fieldswps);
+ }
+ fclose($wallpostsShare_write);
+ }
+
+ if (isset($write_array[0]['towns'])) {
+ foreach ($listtow as $fieldstow) {
+ fputcsv($towns_write, $fieldstow);
+ }
+ fclose($towns_write);
}
- fclose($towns_write);
}
-}
-
?>
View
26 src/index.php
@@ -5,13 +5,13 @@
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
- $friends = $facebook->api('/me/friends');
} catch (FacebookApiException $e) {
error_log($e);
}
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
+ $friends = $facebook->api('/me/friends');
} else {
$loginUrl = $facebook->getLoginUrl(
array('canvas' => 0,
@@ -35,19 +35,19 @@
</head>
<body>
<div id="wrapper">
- <?php
- if ($me):
- include('mainApp/index.php');
- ?>
- <a href="<?php echo $logoutUrl; ?>">
- <img src="http://www.mywindowsphone.net/images/facebookLogOutButton.png">
- </a>
+ <?php
+ if ($me):
+ include('mainApp/index.php');
+ ?>
+ <a href="<?php echo $logoutUrl; ?>">
+ <img src="http://www.mywindowsphone.net/images/facebookLogOutButton.png">
+ </a>
- <?php else: ?>
- <a href="<?php echo $loginUrl; ?>">
- <img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">
- </a>
- <?php endif ?>
+ <?php else: ?>
+ <a href="<?php echo $loginUrl; ?>">
+ <img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">
+ </a>
+ <?php endif ?>
</div>
</body>
</html>
View
64 src/mainApp/submitform.php
@@ -1,13 +1,10 @@
<?php
-
-echo '<pre>';
-print_r($_POST);
-echo '</pre>';
require('../config.php');
include('../functions/functions.php');
-
$result_array = array();
+$friendlist = $_POST['friends'];
+$anonymization = $_POST['anonymize'];
foreach ($_POST['friends'] as $key => $fid) {
set_time_limit(0);
@@ -17,35 +14,60 @@
if (isset($_POST['likes']) && $_POST['likes'] == 1) {
$result_array = getUserLikes($result_array, $facebook, $fid, $key);
}
-
- if(isset($_POST['posts']) && $_POST['posts'] == 1) {
+
+ if (isset($_POST['posts']) && $_POST['posts'] == 1) {
$nr = $_POST['post_numbers'];
$result_array = getUserWall($result_array, $facebook, $fid, $key, $nr);
}
-
- if(isset($_POST['posts_containing']) && $_POST['posts_containing'] == 1) {
+
+ if (isset($_POST['posts_containing']) && $_POST['posts_containing'] == 1) {
$nr = $_POST['post_numbers'];
$data = $_POST['post_data'];
$result_array = getUserWallSpec($result_array, $facebook, $fid, $key, $nr, $data);
}
+
+ if (isset($_POST['wallpost_share']) && $_POST['wallpost_share'] == 1) {
+ $nr = $_POST['post_numbers'];
+ $result_array = getWallpostsShared($result_array, $facebook, $fid, $key, $nr, $friendlist);
+ }
if(isset($_POST['city']) && $_POST['city'] == 1) {
$result_array = getHomeTown($result_array, $facebook, $fid, $key);
}
-
- // FQL queries return the results in an array, so we have
- // to get the user's name from the first element in the array.
- /* echo '<pre>';
- print_r($result_array);
- echo '</pre>';
- echo '<pre>Index: ' . $key . ', Name: ' . utf8_decode($result_array[0]['name']) . '</pre>'; */
}
-print("All done!");
-writeToCVSFile($result_array);
+$file = fopen("../log/frienddataanalyzer.log", 'a');
+fwrite($file, "Start Of Log " . strftime("%Y-%m-%d - %H:%M:%S") . "\n");
+foreach ($_POST as $value) {
+ if (is_array($value)) {
+ foreach ($value as $index) {
+ fwrite($file, $index . "\n");
+ }
+ }
+ fwrite($file, $value . "\n");
+}
-echo '<pre>';
-print_r($result_array);
-echo '</pre>';
+foreach ($result_array as $value) {
+ if (is_array($value)) {
+ foreach ($value as $index) {
+ if (is_array($index)) {
+ foreach ($index as $i) {
+ fwrite($file, $i . "\n");
+ }
+ } else {
+ fwrite($file, $index . "\n");
+ }
+ }
+ }
+ fwrite($file, $value . "\n");
+}
+fwrite($file, "End Of Log \n");
+fclose($file);
+print("All done!");
+echo '<br />';
+print("You can find the log in fb/FriendDataAnalyzer/log/frienddataanalyzer.log in your webroot.");
+echo '<br /><br />';
+echo '<a href="http://localhost/fb/FriendDataAnalyzer">Return to the application</a>';
+writeToCVSFile($result_array, $friendlist, $anonymization);
?>
View
4 src/mainApp/windows/form.php
@@ -2,11 +2,13 @@
$form = <<< EOD
<fieldset>
+ <Input type = 'Radio' Name ='anonymize' value= '1' checked='checked'>Anonymize
+ <Input type = 'Radio' Name ='anonymize' value= '0'>Don't Anonymize <br />
<input type="checkbox" name="likes" value="1" /> Likes<br />
<input type="checkbox" name="posts" value="1" /> Posts, Number of Posts: <input type="text" name="post_numbers" value="100" /><br />
<input type="checkbox" name="posts_containing" value="1" /> Posts Containing: <input type="text" name="post_data" value="Post data" /><br />
+ <input type="checkbox" name="wallpost_share" value="1" /> Wallposts shared<br />
<input type="checkbox" name="city" value="1" />Current City<br />
- <input type="checkbox" name="age" value="1" /> Age<br />
<input type="checkbox" name="birthyear" value="1" /> Birthyear<br /><br />
</fieldset>
View
2 src/style/stylesheet.css
@@ -84,4 +84,4 @@ div#profile {
border-top-style: solid;
margin-top: 25px;
padding: 5px;
-}
+}

0 comments on commit 774c769

Please sign in to comment.
Something went wrong with that request. Please try again.