-
Notifications
You must be signed in to change notification settings - Fork 2
/
message.php
executable file
·139 lines (116 loc) · 4.1 KB
/
message.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
<?php
include ('lib/twitese.php');
$title = "私信";
include ('inc/header.php');
if (!isLogin()) header('location: login.php');
?>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/message.js"></script>
<?php
$isSentPage = isset($_GET['t'])? true : false;
?>
<div id="statuses">
<div id="subnav">
<?php if ($isSentPage) {?>
<span class="subnavLink"><a href="message.php">我收到的私信</a></span><span class="subnavNormal">我发出的私信</span>
<?php } else {?>
<span class="subnavNormal">我收到的私信</span><span class="subnavLink"><a href="message.php?t=sent">我发出的私信</a></span>
<?php } ?>
</div>
<?php
$t = getTwitter();
if ( isset($_POST['sent_id']) && isset($_POST['message']) ) {
$msg = '';
if (trim($_POST['message']) == '') {
echo "<div id=\"sentTip\">发送私信失败,消息不能为空</div>";
} else {
$result = $t->sendDirectMessage(trim($_POST['sent_id']), $_POST['message']);
if (!$result) {
echo "<div id=\"sentTip\">发送私信失败,请重试</div>";
} if ($result == 'nofollow') {
echo "<div id=\"sentTip\">对方没有加你为好友,无法发送私信</div>";
} else {
echo "<div id=\"sentTip\">发送私信成功</div>";
}
}
}
?>
<form action="message.php" method="post">
<?php if ( isset($_GET['id']) ) { ?>
<h2>给 <input type="text" name="sent_id" id="sent_id" value="<?php echo $_GET['id'] ?>"/> 发私信</h2>
<?php } else { ?>
<h2>给 <input type="text" name="sent_id" id="sent_id" /> 发私信</h2>
<?php } ?>
<span id="tip">还可以输入<b>140</b>个字</span>
<textarea name="message" id="textbox"></textarea>
<input type="submit" id="submit_btn" title="按ctrl+enter键发送" value="发送" />
</form>
<div class="clear"></div>
<?php
$t = getTwitter();
$p = 1;
if (isset($_GET['p'])) {
$p = (int) $_GET['p'];
if ($p <= 0) $p = 1;
}
if ($isSentPage) {
$messages = $t->sentDirectMessage($p);
} else {
$messages = $t->directMessages($p);
}
if ($messages === false) {
header('location: error.php');
}
$empty = count($messages) == 0? true: false;
$error = $messages->errors;
if ($error) {
echo "<div id=\"error\">应用权限不够,请访问<a href=\"https://dev.twitter.com/apps\">https://dev.twitter.com/apps</a>,将应用的权限设置为\"Read, Write and Direct Messages\"。</div>";
}else if ($empty) {
echo "<div id=\"empty\">此页无消息</div>";
} else {
$output = '<ol class="timeline" id="allTimeline">';
foreach ($messages as $message) {
$name = $message->sender_screen_name;
$imgurl = $message->sender->profile_image_url;
$date = formatDate($message->created_at);
$text = formatText($message->text);
$output .= "
<li>
<span class=\"status_author\">
<a href=\"user.php?id=$name\" target=\"_blank\"><img src=\"$imgurl\" title=\"$name\" /></a>
</span>
<span class=\"status_body\">
<span class=\"status_id\">$message->id </span>
<span class=\"status_word\"><a class=\"user_name\" href=\"user.php?id=$name\">$name </a> $text </span>
<span class=\"status_info\">
";
if (!$isSentPage) {
$output .= "<a class=\"msg_replie_btn\" href=\"message.php?id=$name\">回复</a>";
} else {
$output .= "<a class=\"delete_btn\" href=\"a_del.php?id=$message->id&t=m\">删除</a>";
}
$output .=" <span class=\"date\">$date</span>
</span>
</span>
</li>
";
}
$output .= "</ol><div id=\"pagination\">";
if ($isSentPage) {
if ($p >1) $output .= "<a href=\"message.php?t=sent&p=" . ($p-1) . "\">上一页</a>";
if (!$empty) $output .= "<a href=\"message.php?t=sent&p=" . ($p+1) . "\">下一页</a>";
} else {
if ($p >1) $output .= "<a href=\"message.php?p=" . ($p-1) . "\">上一页</a>";
if (!$empty) $output .= "<a href=\"message.php?p=" . ($p+1) . "\">下一页</a>";
}
$output .= "</div>";
echo $output;
}
?>
</div>
<?php
include ('inc/sidebar.php');
?>
<?php
include ('inc/footer.php');
?>