-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitlytotweet.php
More file actions
110 lines (69 loc) · 2.49 KB
/
Copy pathbitlytotweet.php
File metadata and controls
110 lines (69 loc) · 2.49 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
<?php
// edit these settings
$source = 'kimondo';
// just your bit.ly username
$bitlyusername = 'username';
// generate your bit.ly app key here: https://bitly.com/a/your_api_key
$bitlyAPIkey = 'api key';
//
/* make a URL small */
function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1')
{
//create the URL
$bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format;
//get the url
//could also use cURL here
$response = file_get_contents($bitly);
//parse depending on desired format
if(strtolower($format) == 'json')
{
$json = @json_decode($response,true);
return $json['results'][$url]['shortUrl'];
}
else //xml
{
$xml = simplexml_load_string($response);
return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
}
}
// ------------------------------------------ post + filter data from the form ---------------------------------
// get the tweet text
$tweet = $_POST['tweet'];
$tweet = urlencode($tweet);
// include the source (see settings above)
$output = 'https://twitter.com/intent/tweet?text='.$tweet.'&source='.$source;
// generate the bit.ly link
$short = make_bitly_url($output,$bitlyusername,$bitlyAPIkey,'json');
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>bit.ly twitter link generator</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
</head>
<body>
<div id="container">
<div id="webtivistform">
<h1>Bit(.ly) to tweet link generator</h1>
<p>Here\'s your tweet link:</p>';
echo '<a href="'.$output.'">'.$output.'</a>';
echo '<p>Here\'s your bit.ly link:</p>';
echo '<a href="'.$short.'">'.$short.'</a>';
echo '<p>Here\'s your bit.ly tracking link:</p>';
echo '<a href="'.$short.'+">'.$short.'+</a>';
echo '<p>
<input type="submit" value="Generate another link"
onclick="return btntest_onclick()" />
<script language="javascript" type="text/javascript">
function btntest_onclick()
{
window.location.href = "index.html";
}
</script>
</p>
</div></div></body>
</html>';
?>