-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.php
94 lines (86 loc) · 2.36 KB
/
process.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
<?php
/**
*
* The Main Processing Happens here!
* @author: Vignesh Rajagopalan (@Aarvay)
*
**/
error_reporting (E_ALL ^ E_NOTICE);
global $rankings;
$rankings = array();
function fetchWords($uid) {
global $facebook;
$feeds = $facebook->api('/'.$uid.'/feed?access_token={$token}&limit=10');
$feeds = $feeds['data'];
$words = "random content..";
foreach($feeds as $feed){
if($feed['from']['id'] == $uid){
$words = $words." ".$feed['message'];
}
}
return $words;
}
function parsify($data, $uid, $key) {
global $rankings;
$index = array();
$find = array('/\r/', '/\n/', '/\s\s+/');
$replace = array(' ', ' ', ' ');
$data = file_get_contents($data);
$data = preg_replace('/[>][<]/', '> <', $data);
$data = strip_tags($data);
$data = strtolower($data);
$data = preg_replace($find, $replace, $data);
$data = trim($data);
$data = explode(' ', $data);
natcasesort($data);
$i = 0;
foreach($data as $word) {
$word = trim($word);
$junk = preg_match('/[^a-zA-Z]/', $word);
if($junk == 1) {
$word = '';
}
if( (!empty($word)) && ($word != '') ) {
if(!isset($index[$i]['word'])) { // notset => new index
$index[$i]['word'] = $word;
$index[$i]['count'] = 1;
}
elseif( $index[$i]['word'] == $word ) { // count repeats
$index[$i]['count'] += 1;
}
else { // else this is a different word, increment $i and create an entry
$i++;
$index[$i]['word'] = $word;
$index[$i]['count'] = 1;
}
}
}
//print_r($index);
$rank = count($index);
$rankings[$key]['id'] = $uid;
$rankings[$key]['rank'] = $rank;
}
function computeRankings() {
global $user;
global $rankings;
global $facebook;
$friends = null;
$friends = $facebook->api('me/friends');
$friends = $friends['data'];
$key=0;
//print_r($friends);
foreach($friends as $friend) {
$postData = fetchWords($friend['id']);
$file = 'data/'.$user['id'].'.txt';
$fp = fopen($file, 'w');
fwrite($fp, $postData);
fclose($fp);
parsify($file, $friend['id'], $key);
$key++;
}
$file = 'data/'.$user['id'].'_rank.txt';
$fp = fopen($file, 'w');
fwrite($fp, $postData);
fclose($fp);
}
?>