forked from ThinkUpLLC/ThinkUp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
143 lines (105 loc) · 4.7 KB
/
index.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
<?php
session_start();
if (!isset($_SESSION['user'])) {
require_once('public.php');
die();
} else {
// set up
require_once('config.webapp.inc.php');
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.$INCLUDE_PATH);
require_once("init.php");
$db = new Database($TWITALYTIC_CFG);
$conn = $db->getConnection();
$od = new OwnerDAO($db);
$owner = $od->getByEmail($_SESSION['user']);
$id = new InstanceDAO($db);
if ( isset($_REQUEST['u']) && $id->isUserConfigured($_REQUEST['u']) ){
$username = $_REQUEST['u'];
$oid = new OwnerInstanceDAO($db);
if ( !$oid->doesOwnerHaveAccess($owner, $username) ) {
echo 'Insufficient privileges. <a href="/">Back</a>.';
$db->closeConnection($conn);
die;
} else {
$i = $id->getByUsername($username);
}
} else {
$i = $id->getFreshestByOwnerId($owner->id);
if ( !isset($i) && $i == null ) {
echo 'You have no Twitter accounts configured. <a href="'.$TWITALYTIC_CFG['site_root_path'].'account/">Set up a Twitter account here</a>';
$db->closeConnection($conn);
die;
}
}
$s = new SmartyTwitalytic();
if(!$s->is_cached('index.tpl', $i->twitter_username."-".$_SESSION['user'])) {
$cfg = new Config($i->twitter_username, $i->twitter_user_id);
$u = new Utils();
// instantiate data access objects
$ud = new UserDAO($db);
$td = new TweetDAO($db);
$fd = new FollowDAO($db);
// pass data to smarty
$owner_stats = $ud->getDetails($cfg->twitter_user_id);
$s->assign('owner_stats', $owner_stats);
$s->assign('instance', $i);
$s->assign('instances', $id->getByOwner($owner));
$s->assign('cfg', $cfg);
$total_follows_with_errors = $fd->getTotalFollowsWithErrors($cfg->twitter_user_id);
$s->assign('total_follows_with_errors', $total_follows_with_errors);
$total_follows_with_full_details = $fd->getTotalFollowsWithFullDetails($cfg->twitter_user_id);
$s->assign('total_follows_with_full_details', $total_follows_with_full_details);
$total_follows_protected = $fd-> getTotalFollowsProtected($cfg->twitter_user_id);
$s->assign('total_follows_protected', $total_follows_protected);
//TODO: Get friends with full details and also friends with errors, same as with followers
$total_friends_loaded = $fd->getTotalFriends($cfg->twitter_user_id);
$s->assign('total_friends', $total_friends_loaded);
$total_friends_with_errors = $fd->getTotalFriendsWithErrors($cfg->twitter_user_id);
$s->assign('total_friends_with_errors', $total_friends_with_errors);
$total_friends_protected = $fd->getTotalFriendsProtected($cfg->twitter_user_id);
$s->assign('total_friends_protected', $total_friends_protected);
//Percentages
$percent_followers_loaded = $u->getPercentage($owner_stats['follower_count'], ($total_follows_with_full_details + $total_follows_with_errors));
$percent_followers_loaded = ($percent_followers_loaded > 100) ? 100 : $percent_followers_loaded;
$percent_tweets_loaded = $u->getPercentage($owner_stats['tweet_count'],$i->total_tweets_in_system );
$percent_tweets_loaded = ($percent_tweets_loaded > 100) ? 100 : $percent_tweets_loaded;
$percent_friends_loaded = $u->getPercentage($owner_stats['friend_count'], ($total_friends_loaded));
$percent_friends_loaded = ($percent_friends_loaded > 100) ? 100 : $percent_friends_loaded;
$percent_followers_suspended = round($u->getPercentage($total_follows_with_full_details, $total_follows_with_errors), 2);
$percent_followers_protected = round($u->getPercentage($total_follows_with_full_details, $total_follows_protected), 2);
$s->assign('percent_followers_loaded', $percent_followers_loaded);
$s->assign('percent_tweets_loaded', $percent_tweets_loaded);
$s->assign('percent_friends_loaded', $percent_friends_loaded);
$s->assign('percent_followers_suspended', $percent_followers_suspended);
$s->assign('percent_followers_protected', $percent_followers_protected);
}
# clean up
$db->closeConnection($conn);
$s->display('index.tpl', $i->twitter_username."-".$_SESSION['user']);
/* People you've gotten the most replies from in the last XXX months (use date of oldest reply)
select
author_username, count(author_user_id) as total_replies
from
reply
group by
author_user_id
order by
total_replies desc
limit 5;
People you reply to the most since (date of oldest tweet)
select
u.user_name, count(t.in_reply_to_user_id) as total_replies
from
tweet t
inner join
user u
on
u.user_id = t.in_reply_to_user_id
group by
in_reply_to_user_id
order by
total_replies desc
limit 10;
*/
}
?>