This repository has been archived by the owner on Apr 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
tweets.php
145 lines (131 loc) · 6.15 KB
/
tweets.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
144
145
<?PHP
require 'includes/master.inc.php';
$Auth->requireAdmin('login.php');
$nav = 'tweets';
$applications = DBObject::glob('Application', 'SELECT * FROM shine_applications ORDER BY name');
if(isset($_GET['refresh']))
include 'tweet-cron.php';
if(isset($_GET['delete']))
{
$t = new Tweet($_GET['delete']);
$t->deleted = 1;
$t->new = 0;
$t->update();
}
if(isset($_GET['reply']))
{
$t = new Tweet($_GET['reply']);
$t->replied_to = 1;
$t->reply_date = dater();
$t->new = 0;
$t->update();
redirect("http://twitter.com/home?status=@{$t->username}%20&in_reply_to={$t->tweet_id}");
}
$sql = ''; $app_id = ''; $group = '';
if(isset($_GET['id']) && !empty($_GET['id']))
{
$sql = 'AND app_id = ' . intval($_GET['id']);
$app_id = intval($_GET['id']);
}
else
{
$group = ' GROUP BY tweet_id ';
}
if(isset($_GET['read']))
{
$db = Database::getDatabase();
$db->query("UPDATE shine_tweets SET new = 0 WHERE 1 = 1 $sql");
redirect("tweets.php?id=$app_id");
}
$tweets = DBObject::glob('Tweet', "SELECT * FROM shine_tweets WHERE deleted = 0 $sql $group ORDER BY dt DESC LIMIT 100");
$db = Database::getDatabase();
$available_apps = $db->getValues("SELECT id FROM shine_applications WHERE CHAR_LENGTH(tweet_terms) > 0");
$tweet_terms = $db->getValues("SELECT tweet_terms FROM shine_applications WHERE CHAR_LENGTH(tweet_terms) > 0");
function twitterfy($str)
{
// Via http://www.snipe.net/2009/09/php-twitter-clickable-links/
$str = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $str);
$str = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $str);
$str = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $str);
$str = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $str);
return $str;
}
?>
<?PHP include('inc/header.inc.php'); ?>
<div id="bd">
<div id="yui-main">
<div class="yui-b"><div class="yui-g">
<div class="block tabs spaces">
<div class="hd">
<h2>Orders</h2>
<ul>
<li class="<?PHP if(!isset($_GET['id'])) echo 'active'; ?>"><a href="tweets.php">All Apps</a></li>
<?PHP foreach($applications as $a) : ?>
<?PHP if(!in_array($a->id, $available_apps)) continue; ?>
<li class="<?PHP if(@$_GET['id'] == $a->id) echo 'active'; ?>"><a href="tweets.php?id=<?PHP echo $a->id; ?>"><?PHP echo $a->name; ?></a></li>
<?PHP endforeach; ?>
</ul>
<div class="clear"></div>
</div>
<div class="bd">
<table class="lines">
<tbody>
<?PHP foreach($tweets as $t) : ?>
<?PHP if($t->new) : ?>
<tr class="highlight">
<?PHP else : ?>
<tr>
<?PHP endif; ?>
<td><img src="<?PHP echo $t->profile_img; ?>" style="width:48px;height:48px;"></td>
<td>
<strong><a href="http://twitter.com/<?PHP echo $t->username; ?>"><?PHP echo $t->username; ?></a></strong>
<br>
<a style="font-size:80%;" href="http://twitter.com/<?PHP echo $t->username; ?>/status/<?PHP echo $t->tweet_id; ?>"><?PHP echo time2str($t->dt); ?></a>
</td>
<td>
<?PHP echo twitterfy($t->body); ?><br>
<span style="font-size:80%;">
<?PHP if($t->replied_to) : ?>
Replied to <?PHP echo time2str($t->reply_date); ?>
<?PHP else : ?>
<a href="tweets.php?id=<?PHP echo $app_id; ?>&reply=<?PHP echo $t->id; ?>">Reply</a>
<?PHP endif; ?>
</span>
</td>
<td><a href="tweets.php?id=<?PHP echo $app_id; ?>&delete=<?PHP echo $t->id; ?>">Delete</a></td>
</tr>
<?PHP endforeach; ?>
</tbody>
</table>
</div>
</div>
</div></div>
</div>
<div id="sidebar" class="yui-b">
<div class="block">
<div class="hd">
<h3>Summary</h3>
</div>
<div class="bd">
<p><?PHP echo count($tweets); ?> tweets</p>
<p><a href="tweets.php?id=<?PHP echo $app_id; ?>&read=1">Mark all as read</a></p>
<p><a href="tweets.php?id=<?PHP echo $app_id; ?>&refresh=1">Refresh All</a></p>
</div>
</div>
<div class="block">
<div class="hd">
<h3>Tweet Terms</h3>
</div>
<div class="bd">
<ul class="biglist">
<?PHP foreach($tweet_terms as $tt) : ?>
<?PHP foreach(explode(',', $tt) as $term) : ?>
<li><a href="http://search.twitter.com/search?q=<?PHP echo urlencode($term); ?>"><?PHP echo $term; ?></a></li>
<?PHP endforeach; ?>
<?PHP endforeach; ?>
</ul>
</div>
</div>
</div>
</div>
<?PHP include('inc/footer.inc.php'); ?>