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
| --- twitter_updater.php_orig 2008-08-04 20:42:26.000000000 +0200
+++ twitter_updater.php 2008-10-09 06:32:18.000000000 +0200
@@ -3,8 +3,8 @@
Plugin Name: Twitter updater
Plugin URI: http://www.ingoal.info/archives/2008/07/08/twitter-updater/
Description: Updates Twitter when you create a new blog or publish one
-Version: 2.06
-Author: Ingo "Ingoal" Hildebrandt
+Version: 2.06.1
+Author: Ingo "Ingoal" Hildebrandt and Andreas Ebbert-Karroum
Author URI: http://www.ingoal.info/archives/2008/07/08/twitter-updater/
Based on Version 1.0
@@ -45,6 +45,15 @@
Edited by
Ingo "Ingoal" Hildebrandt (v2.06)
Edit: - added cascading short-url generation (if zz.gd is down, it'll cascade to tinyurl.com)
+
+Edited by
+Andreas Ebbert-Karroum (v2.06.1)
+Edit: - hook to wp_insert_post instead of save_post
+ - retrieve post title with get_the_title
+ - shorten text if it grows over 140 characters
+ - urlencode text
+ - add option to use zz.gd or tinyurl (tinyurl keeps trailing slash)
+ - if qtranslate is present, set language to 'en'
*/
@@ -66,7 +75,7 @@
fputs($fp, "Authorization: Basic ".$thisLoginDetails."\r\n");
fputs($fp, "User-Agent: ".$agent."\n");
fputs($fp, "Host: $host\n");
- fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
+ fputs($fp, "Content-type: application/x-www-form-urlencoded; charset=utf8\n");
fputs($fp, "Content-length: ".strlen($twit)."\n");
fputs($fp, "Connection: close\n\n");
fputs($fp, $twit);
@@ -83,9 +92,12 @@
function vc_twit($post_ID) {
$twitterURI = "/statuses/update.xml?source=ingoalstwitterupdate";
$thisposttitle = "";
- $thisposttitle = $_POST['post_title'];
+ global $q_config;
+ if (isset($q_config)) {
+ $q_config['language']='en'; // 135) {
+ $thisposttitle = substr( $thisposttitle, 0, 140-strlen($tinyurl)-strlen('... ( )')-strlen($sentence)+strlen('#title#')) . '...';
}
$thisposttitle = $thisposttitle . ' ( ' . $tinyurl . ' )';
}
$sentence = str_replace ( '#title#', $thisposttitle, $sentence);
}
- }
}else if ($_POST['prev_status'] == 'publish') {
// is old post
if(get_option('oldpost-edited-update') == '1') {
@@ -130,23 +132,16 @@
if (strlen(trim($thisposttitle)) == 0) {
$post = get_post($post_ID);
if ($post) {
- $thisposttitle = $post->post_title;
+ // use get_the_title, because this is filtered by qTranslate
+ $thisposttitle = get_the_title($post_ID);
}
}
if(get_option('oldpost-edited-showlink') == '1') {
- if(get_option('short-method') == '1') {
- $tinyurl = file_get_contents_curl("http://zz.gd/api-create.php?url=".$thispostlink);
- if ($tinyurl == '') {
- $tinyurl = file_get_contents_curl("http://tinyurl.com/create.php?url=".$thispostlink);
- }
- }
- else {
- $tinyurl = file_get_contents("http://zz.gd/api-create.php?url=".$thispostlink);
- if ($tinyurl == '') {
- $tinyurl = file_get_contents("http://tinyurl.com/create.php?url=".$thispostlink);
- }
- }
+ $tinyurl = get_short_URL($thispostlink);
+ if (strlen($thisposttitle)+strlen($tinyurl)>135) {
+ $thisposttitle = substr( $thisposttitle, 0, 140-strlen($tinyurl)-strlen('... ( )')-strlen($sentence)+strlen('#title#')) . '...';
+ }
$thisposttitle = $thisposttitle . ' ( ' . $tinyurl . ' )';
}
$sentence = str_replace ( '#title#', $thisposttitle, $sentence);
@@ -158,13 +153,28 @@
if($sentence != ""){
- $urlstatus = 'status='.$sentence;
+ $urlstatus = 'status='.urlencode($sentence);
$status = utf8_encode($urlstatus);
$sendToTwitter = vc_doTwitterAPIPost($status, $twitterURI);
}
return $post_ID;
}
+function get_short_URL($url) {
+ if(get_option('short-method') == '1') {
+ if (get_option('use-zz-gd') == '1') {
+ return file_get_contents_curl("http://zz.gd/api-create.php?url=".$url);
+ } else {
+ return file_get_contents_curl("http://tinyurl.com/api-create.php?url=".$url);
+ }
+ } else {
+ if (get_option('use-zz-gd') == '1') {
+ return file_get_contents("http://zz.gd/api-create.php?url=".$url);
+ } else {
+ return file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
+ }
+ }
+}
function file_get_contents_curl($url) {
$ch = curl_init();
@@ -192,7 +202,7 @@
//HOOKIES
-add_action ( 'save_post', 'vc_twit');
+add_action ('wp_insert_post', 'vc_twit');
add_action('admin_menu', 'vc_addTwitterAdminPages');
?> |