-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwesta.php
More file actions
executable file
·158 lines (132 loc) · 4.22 KB
/
twesta.php
File metadata and controls
executable file
·158 lines (132 loc) · 4.22 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/** Module created by Mathew Taylor,
http://mathewtaylor.co.uk - 14/08/2010 **/
require_once('../modules/twesta/twitter.php');
class Twesta extends Module{
public function __construct()
{
$this->name = 'twesta';
$this->tab = 'Tools';
$this->version = 0.1;
parent::__construct();
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Twesta');
$this->description = $this->l('Allows you to push an update to Twitter,
storing the message in the database to be
displayed in a block.');
}
public function install()
{
if (parent::install() == False)
return False;
return Db::getInstance()->Execute('CREATE TABLE `'._DB_PREFIX_.'twesta`(
`oauth_token` char(50),
`oauth_token_secret` char(50),
`consumer_key` char(50),
`consumer_secret` char(50),
`message` char(140)
)');
}
public function uninstall()
{
if(parent::uninstall() == False)
return False;
$query = '
DROP TABLE `'._DB_PREFIX_.'twesta`
';
return Db::getInstance()->Execute($query);
}
public function getContent()
{
$twitter = TwitterAbrahamWrapper::get_instance();
if(isset($_GET['operation'])){
$operation = $_GET['operation'];
$error = $twitter->handle_connect($operation);
if(is_string($error)){
$this->_display_connect_form();
$this->_html .= $error;
}else{
$this->_display_tweet_form();
}
}else{
/* display the module name */
$this->_html = '<h2'.$this->displayName.'</h2>';
$errors = '';
if(isset($_POST['connect']) && isset($_POST['consumer_key'])
&& isset($_POST['consumer_secret'])){
$consumer_key = $_POST['consumer_key'];
$consumer_secret = $_POST['consumer_secret'];
$twitter->save_app_keys($consumer_key, $consumer_secret);
//save the above two in the database and begin connect.
$twitter->handle_connect('connect');
}
if(isset($_POST['tweet'])){
if(isset($_POST['message'])){
$message = $_POST['message'];
$twitter->tweet($message);
}else{
$error = "Please specify a message";
}
}
if($twitter->error){
echo $twitter->error;
}
if($twitter->connected){
$this->_display_tweet_form();
}else{
$this->_display_connect_form();
}
return $this->_html;
}
}
private function _display_connect_form()
{
$this->_html .= '
<form method="post" action="'.$_SERVER['REQUEST_URI'].'" enctype="multipart/form-data">
<fieldset style="width: 900px;">
<legend><img src="'.$this->_path.'logo.gif" alt="" title="" /> '.$this->displayName.'</legend>
<label>'.$this->l('App Consumer Key').'</label>
<div class="margin-form">
<input type="text" name="consumer_key"/>
</div>
<label>'.$this->l('App Consumer Secret').'</label>
<div class-"margin-form">
<input type="text" name="consumer_secret"/>
</div>
<div class="clear pspace"></div>
<div class="margin-form clear"><input type="submit" name="connect" value="'.$this->l('Connect').'" class="button" /></div>
</fieldset>
</form>';
}
private function _display_tweet_form()
{
$this->_html .= '
<form method="post" action="'.$_SERVER['REQUEST_URI'].'" enctype="multipart/form-data">
<fieldset style="width: 900px;">
<legend><img src="'.$this->_path.'logo.gif" alt="" title="" /> '.$this->displayName.'</legend>
<label>'.$this->l('Message').'<label>
<div class="margin-form">
<input type="text" name="message"/>
</div>
<div class="clear pspace"></div>
<div class="margin-form clear">
<a href="'. $_SERVER['REQUEST_URI'] .'&operation=disconnect">Disconnect</a>
<input type="submit" name="tweet" value="'.$this->l('Tweet').'" class="button" />
</div>
</fieldset>
</form>';
}
public function tweet($message){
$twitter = new Twitter();
if($twitter->connect()){
if($twitter->tweet($message)){
echo "tweeted successfully";
}else{
echo "an error occurred tweeting";
}
}else{
echo "Error creating twitter connection";
}
}
}
?>