/
tweet.php
96 lines (79 loc) · 2.33 KB
/
tweet.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
<?php
/**
* @author Vinit Shahdeo
* @copyright miTweet | 2017
*/
//for removing extra spaces
function test_input($data) {
$data = trim($data);
$data = preg_replace('/\s{2,}/',' ', $data);
$data = str_replace("\0","", $data);
return $data;
}
$msg=''; //variable used for storing the textbox input i.e. tweet
//tweet now
if (isset($_POST['tweetnow'])) {
if(empty($_POST['msg']))
{
$developer='&via=Vinit_Shahdeo';
$hashtags='&hashtags=miTweet';
$msg='Hello there! You can create links for your tweets!';
$msg.=' Made with love! ';
$msg.=$developer;
$msg.=$hashtags;
@header("location:https://twitter.com/intent/tweet?text=$msg");
}
else
{
$msg = test_input($_POST['msg']);
file_put_contents("tweets.txt", date("Y-m-d h:i:sa").PHP_EOL,FILE_APPEND);
file_put_contents("tweets.txt", $msg. PHP_EOL.PHP_EOL,FILE_APPEND);
$hashtags='&hashtags=miTweet';
if(strlen($msg)<132)
{
$msg.=$hashtags;
}
$msg=htmlspecialchars($msg);
@header("location:https://twitter.com/intent/tweet?text=$msg")
or die("Use only required characters. Please don't include hashtags here!");
}
}
//link generator
if(isset($_POST['link']))
{
if(!empty($_POST['msg']))
{
function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1')
{
$bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format;
$response = file_get_contents($bitly);
if(strtolower($format) == 'json')
{
$json = @json_decode($response,true);
return $json['results'][$url]['shortUrl'];
}
else
{
$xml = simplexml_load_string($response);
return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
}
}
$msg = test_input($_POST['msg']);
$hashtags='&hashtags=miTweet';
file_put_contents("tweets.txt", date("Y-m-d h:i:sa").PHP_EOL,FILE_APPEND);
file_put_contents("tweets.txt", $msg. PHP_EOL,FILE_APPEND);
if(strlen($msg)<132)
{
$msg.=$hashtags;
}
$url='https://twitter.com/intent/tweet?text='.$msg;
$short = make_bitly_url($url,'mitweet','R_ff691c7d55584c13b8a3af003459dc48','json');
file_put_contents("tweets.txt", $short. PHP_EOL.PHP_EOL,FILE_APPEND);
@header("location:./link.php?q=$short");
}
else
{
@header("location:./result.php");
}
}
?>