WP to Twitter - Version 1.2.0

Version Description

Download this release

Release Info

Developer joedolson
Plugin Icon 128x128 WP to Twitter
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.0.0 to 1.2.0

images/cligs.png DELETED
Binary file
images/twitter.png DELETED
Binary file
readme.txt CHANGED
@@ -1,50 +1,76 @@
1
- === Plugin Name ===
2
- Contributors: joedolson
3
- Donate link: http://www.joedolson.com/donate/
4
- Tags: twitter, microblogging, cligs, redirect, shortener
5
- Requires at least: 2.3
6
- Tested up to: 2.6
7
- Stable tag: 1.0
8
-
9
- Posts a Twitter status update when you update your blog, using the Cli.gs URL shortening service.
10
-
11
- == Description ==
12
-
13
- The WP-to-Twitter plugin posts a Twitter status update from your blog using the Cli.gs URL shortening service to
14
- provide a link back to your post from Twitter.
15
-
16
- If you have a Cli.gs API key, the shortened URL will also be filed in your Cli.gs account so that you can track
17
- statistics for the shortened URL.
18
-
19
- The plugin can send a default message for updating or editing posts or pages, but also allows you to write a custom
20
- Tweet for your post which says whatever you want. By default, the shortened URL from Cli.gs is appended to the end
21
- of your message, so you should keep that in mind when writing your custom Tweet.
22
-
23
- Any status update you write which is longer than the available space will automatically be truncated by the plugin. This applies to both the default messages and to your custom messages.
24
-
25
- This plugin was based on the Twitter Updater plugin by Jonathan Dingman (http://www.firesidemedia.net/dev/), which he adapted from a plugin by Victoria Chan.
26
-
27
- == Installation ==
28
-
29
- 1. Upload the `wp-to-twitter` folder to your `/wp-content/plugins/` directory
30
- 2. Activate the plugin using the `Plugins` menu in WordPress
31
- 3. Go to Settings > WP->Twitter
32
- 4. Adjust the WP->Twitter Options as you prefer them.
33
- 5. Supply your Twitter username and login.
34
- 6. **Optional**: Provide your Cli.gs API key ([available free from Cli.gs](http://cli.gs)), if you want to have statistics available for your URL.
35
- 7. That's it! You're all set.
36
-
37
- == Frequently Asked Questions ==
38
-
39
- = Do I have to have a Twitter.com account to use this plugin? =
40
-
41
- Yes, you need an account to use this plugin.
42
-
43
- = Do I have to have a Cli.gs account to use this plugin? =
44
-
45
- No, the Cli.gs account is entirely optional. Without a Cli.gs API, a "public" Clig will be generated. The redirect will work just fine, but you won't be able to access statistics on your Clig.
46
-
47
- == Screenshots ==
48
-
49
- 1. WP to Twitter custom Tweet box
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  2. WP to Twitter options page
1
+ === Plugin Name ===
2
+ Contributors: joedolson
3
+ Donate link: http://www.joedolson.com/donate.php
4
+ Tags: twitter, microblogging, cligs, redirect, shortener
5
+ Requires at least: 2.5
6
+ Tested up to: 2.6.3
7
+ Stable tag: trunk
8
+
9
+ Posts a Twitter status update when you update your blog or post to your blogroll, using the Cligs URL shortening service.
10
+
11
+ == Description ==
12
+
13
+ The WP-to-Twitter plugin posts a Twitter status update from your blog using the Cli.gs URL shortening service to
14
+ provide a link back to your post from Twitter.
15
+
16
+ New in version 1.2.0:
17
+ - option to post your new blogroll links to Twitter, using the description field as your status update text.
18
+ - option to decide on a post level whether or not that blog post should be posted to Twitter
19
+
20
+ If you have a Cli.gs API key, the shortened URL will also be filed in your Cli.gs account so that you can track
21
+ statistics for the shortened URL.
22
+
23
+ The plugin can send a default message for updating or editing posts or pages, but also allows you to write a custom
24
+ Tweet for your post which says whatever you want. By default, the shortened URL from Cli.gs is appended to the end
25
+ of your message, so you should keep that in mind when writing your custom Tweet.
26
+
27
+ Any status update you write which is longer than the available space will automatically be truncated by the plugin. This applies to both the default messages and to your custom messages.
28
+
29
+ This plugin is based loosely on the Twitter Updater plugin by Jonathan Dingman (http://www.firesidemedia.net/dev/), which he adapted from a plugin by Victoria Chan. Other contributions by Thor Erik (http://www.thorerik.net)
30
+
31
+ (As a side note, this plugin more or less works with WordPress 2.3. It's not fully tested, however. Make a request at http://www.joedolson.com/articles/wp-to-twitter/ if this is something you need!)
32
+
33
+ == Installation ==
34
+
35
+ 1. Upload the `wp-to-twitter` folder to your `/wp-content/plugins/` directory
36
+ 2. Activate the plugin using the `Plugins` menu in WordPress
37
+ 3. Go to Settings > WP->Twitter
38
+ 4. Adjust the WP->Twitter Options as you prefer them.
39
+ 5. Supply your Twitter username and login.
40
+ 6. **Optional**: Provide your Cli.gs API key ([available free from Cli.gs](http://cli.gs)), if you want to have statistics available for your URL.
41
+ 7. That's it! You're all set.
42
+
43
+ == Frequently Asked Questions ==
44
+
45
+ = Do I have to have a Twitter.com account to use this plugin? =
46
+
47
+ Yes, you need an account to use this plugin.
48
+
49
+ = Do I have to have a Cli.gs account to use this plugin? =
50
+
51
+ No, the Cli.gs account is entirely optional. Without a Cli.gs API, a "public" Clig will be generated. The redirect will work just fine, but you won't be able to access statistics on your Clig.
52
+
53
+ = Twitter goes down a lot. What happens if it's not available? =
54
+
55
+ If Twitter isn't available, you'll get a message telling you that there's been an error with your Twitter status update. The Tweet you were going to send will be saved in your post meta fields, so you can grab it and post it manually if you wish.
56
+
57
+ = What if Cli.gs isn't available when I make my post? =
58
+
59
+ If Cli.gs isn't available, your tweet will be sent using it's normal post permalink. You'll also get an error message letting you know that there was a problem contacting Cli.gs.
60
+
61
+ = What if my server doesn't support the methods you use to contact these other sites? =
62
+
63
+ Well, there isn't much I can do about that - but the plugin will check and see whether or not the needed methods work. If they don't, you will find a warning message on your settings page.
64
+
65
+ = If I mark a blogroll link as private, will it be posted to Twitter? =
66
+
67
+ No. Private.
68
+
69
+ = What are the changes between version 1.1 and 1.2? =
70
+
71
+ There are several additional functions available in version 1.2. First, you can now post links you add to your blogroll to Twitter. Second, you can configure whether or not you want to Tweet posts on an individual basis. Third, you can globally set whether you'd rather have posts default to be Tweeted or NOT to be Tweeted, depending on whether you're more likely to want to Tweet most posts but not all or Tweet only the occasional post.
72
+
73
+ == Screenshots ==
74
+
75
+ 1. WP to Twitter custom Tweet box
76
  2. WP to Twitter options page
images/wp-to-twitter-custom.png → screenshot-1.png RENAMED
File without changes
images/wp-to-twitter-options.png → screenshot-2.png RENAMED
Binary file
wp-to-twitter-manager.php CHANGED
@@ -2,48 +2,89 @@
2
 
3
  $wp_to_twitter_directory = get_bloginfo( 'wpurl' ) . '/' . PLUGINDIR . '/' . dirname( plugin_basename(__FILE__) );
4
 
5
- //update_option('twitterInitialised', '0');
6
  //SETS DEFAULT OPTIONS
7
- if(get_option('twitterInitialised') != '1'){
8
- update_option('newpost-published-update', '1');
9
- update_option('newpost-published-text', 'Published a new post: #title#');
10
- update_option('newpost-published-showlink', '1');
11
-
12
- update_option('oldpost-edited-update', '1');
13
- update_option('oldpost-edited-text', 'Blog post just edited: #title#');
14
- update_option('oldpost-edited-showlink', '1');
15
-
16
- update_option('twitterInitialised', '1');
17
- update_option('cligsapi','0');
18
- update_option('jd_twit_pages','0');
 
 
 
 
 
 
 
 
 
 
 
19
  $message = "Set your Twitter login information and Cli.gs API to use this plugin!";
20
  }
21
-
22
 
23
- if($_POST['submit-type'] == 'options'){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  //UPDATE OPTIONS
25
- update_option('newpost-published-update', $_POST['newpost-published-update']);
26
- update_option('newpost-published-text', $_POST['newpost-published-text']);
27
- update_option('newpost-published-showlink', $_POST['newpost-published-showlink']);
28
-
29
- update_option('oldpost-edited-update', $_POST['oldpost-edited-update']);
30
- update_option('oldpost-edited-text', $_POST['oldpost-edited-text']);
31
- update_option('oldpost-edited-showlink', $_POST['oldpost-edited-showlink']);
32
- update_option('jd_twit_pages',$_POST['jd_twit_pages']);
 
 
 
 
 
 
 
 
 
 
 
 
33
  $message = "WP to Twitter Options Updated";
34
 
35
- }else if ($_POST['submit-type'] == 'login'){
36
  //UPDATE LOGIN
37
- if(($_POST['twitterlogin'] != '') AND ($_POST['twitterpw'] != '')){
38
- update_option('twitterlogin', $_POST['twitterlogin']);
39
- update_option('twitterlogin_encrypted', base64_encode($_POST['twitterlogin'].':'.$_POST['twitterpw']));
40
  $message = "Twitter login and password updated.";
41
  } else {
42
  $message = "You need to provide your twitter login and password!";
43
  }
44
- } else if ($_POST['submit-type'] == 'cligsapi') {
45
- if($_POST['cligsapi'] != '') {
46
- update_option('cligsapi',$_POST['cligsapi']);
47
  $message = "Cligs API Key Updated";
48
  } else {
49
  $message = "Cli.gs API Key not added - <a href='http://cli.gs/user/api/'>get one here</a>!";
@@ -51,11 +92,28 @@ $wp_to_twitter_directory = get_bloginfo( 'wpurl' ) . '/' . PLUGINDIR . '/' . dir
51
  }
52
 
53
  // FUNCTION to see if checkboxes should be checked
54
- function jd_checkCheckbox($theFieldname){
55
- if( get_option($theFieldname) == '1'){
56
- echo('checked="true"');
57
  }
58
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  ?>
60
  <style type="text/css">
61
  <!--
@@ -70,6 +128,10 @@ padding: 10px 5px;
70
  margin: 4px 0;
71
  border: 1px solid #eee;
72
  }
 
 
 
 
73
  .floatright {
74
  float: right;
75
  }
@@ -83,27 +145,57 @@ padding: 2px!important;
83
  }
84
  -->
85
  </style>
 
 
 
 
 
 
 
86
  <?php if ($message) : ?>
87
  <div id="message" class="updated fade"><p><?php echo $message; ?></p></div>
88
  <?php endif; ?>
89
  <div id="dropmessage" class="updated" style="display:none;"></div>
90
 
91
  <div class="wrap" id="wp-to-twitter">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  <h2>WP to Twitter Options</h2>
93
  <p>
94
  For any update field, you can use the codes <code>#title#</code> for the title of your blog post or <code>#blog#</code> for the title of your blog! Given the character limit for Twitter, you may not want to include your blog title.
95
  </p>
96
- <form method="post">
 
97
  <div>
98
  <fieldset>
99
  <legend>Wordpress to Twitter Publishing Options</legend>
100
  <p>
101
  <input type="checkbox" name="jd_twit_pages" id="jd_twit_pages" value="1" <?php jd_checkCheckbox('jd_twit_pages')?> />
102
- <label for="jd_twit_pages">Update Twitter when new Wordpress Pages are published</label>
103
  </p>
104
  <p>
105
  <input type="checkbox" name="newpost-published-update" id="newpost-published-update" value="1" <?php jd_checkCheckbox('newpost-published-update')?> />
106
- <label for="newpost-published-update">Update Twitter when the new post is published</label>
107
  </p>
108
  <p>
109
  <label for="newpost-published-text">Text for this Twitter update</label><br />
@@ -115,7 +207,7 @@ For any update field, you can use the codes <code>#title#</code> for the title o
115
 
116
  <p>
117
  <input type="checkbox" name="oldpost-edited-update" id="oldpost-edited-update" value="1" <?php jd_checkCheckbox('oldpost-edited-update')?> />
118
- <label for="oldpost-edited-update">Update Twitter when the an old post has been edited</label>
119
  </p>
120
  <p>
121
  <label for="oldpost-edited-text">Text for this Twitter update</label><br />
@@ -124,6 +216,26 @@ For any update field, you can use the codes <code>#title#</code> for the title o
124
  <input type="checkbox" name="oldpost-edited-showlink" id="oldpost-edited-showlink" value="1" <?php jd_checkCheckbox('oldpost-edited-showlink')?> />
125
  <label for="oldpost-edited-showlink">Provide link to blog?</label>
126
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  <div>
128
  <input type="hidden" name="submit-type" value="options" />
129
  </div>
@@ -135,7 +247,7 @@ For any update field, you can use the codes <code>#title#</code> for the title o
135
 
136
  <h2 class="twitter">Your Twitter account details</h2>
137
 
138
- <form method="post" >
139
  <div>
140
  <p>
141
  <label for="twitterlogin">Your Twitter username:</label>
@@ -145,23 +257,23 @@ For any update field, you can use the codes <code>#title#</code> for the title o
145
  <label for="twitterpw">Your Twitter password:</label>
146
  <input type="password" name="twitterpw" id="twitterpw" value="" />
147
  </p>
148
- <input type="hidden" name="submit-type" value="login">
149
  <p><input type="submit" name="submit" value="Save Twitter Login Info" /> &raquo; <small>Don't have a Twitter account? <a href="http://www.twitter.com">Get one for free here</a></small></p>
150
  </div>
151
  </form>
152
 
153
  <h2 class="cligs">Your Cli.gs account details</h2>
154
 
155
- <form method="post">
156
  <div>
157
  <p>
158
  <label for="cligsapi">Your Cli.gs API Key:</label>
159
  <input type="text" name="cligsapi" id="cligsapi" size="40" value="<?php echo(get_option('cligsapi')) ?>" />
160
  </p>
161
  <div>
162
- <input type="hidden" name="submit-type" value="cligsapi">
163
  </div>
164
- <p><input type="submit" name="submit" value="Save Cli.gs API Key" /> &raquo; <small>Don't have a Cli.gs account or Cligs API key? <a href="http://cli.gs">Get one free here</a>! You'll need an API key in order to associate the Cligs you create with your Cligs account.</small></p>
165
  </div>
166
  <div>
167
 
2
 
3
  $wp_to_twitter_directory = get_bloginfo( 'wpurl' ) . '/' . PLUGINDIR . '/' . dirname( plugin_basename(__FILE__) );
4
 
5
+ //update_option( 'twitterInitialised', '0' );
6
  //SETS DEFAULT OPTIONS
7
+ if( get_option( 'twitterInitialised') != '1' ) {
8
+ update_option( 'newpost-published-update', '1' );
9
+ update_option( 'newpost-published-text', 'Published a new post: #title#' );
10
+ update_option( 'newpost-published-showlink', '1' );
11
+
12
+ update_option( 'oldpost-edited-update', '1' );
13
+ update_option( 'oldpost-edited-text', 'Blog post just edited: #title#' );
14
+ update_option( 'oldpost-edited-showlink', '1' );
15
+
16
+ update_option( 'cligsapi','' );
17
+ update_option( 'jd_twit_pages','0' );
18
+ update_option( 'jd_functions_checked','0' );
19
+ update_option( 'wp_twitter_failure','0' );
20
+ update_option( 'wp_cligs_failure','0' );
21
+ // Blogroll options
22
+ update_option ('jd-use-link-title','0' );
23
+ update_option( 'jd-use-link-description','1' );
24
+ update_option( 'newlink-published-text', 'New link posted: ' );
25
+ update_option( 'jd_twit_blogroll', '1');
26
+
27
+ update_option( 'jd_tweet_default', '0' );
28
+ update_option( 'twitterInitialised', '1' );
29
+
30
  $message = "Set your Twitter login information and Cli.gs API to use this plugin!";
31
  }
 
32
 
33
+ if ( $_POST['submit-type'] == 'clear-error' ) {
34
+ update_option( 'wp_twitter_failure','0' );
35
+ update_option( 'wp_cligs_failure','0' );
36
+ $message = "WP to Twitter Errors Cleared";
37
+ }
38
+ if ( get_option( 'wp_twitter_failure' ) == '1' || get_option( 'wp_cligs_failure' ) == '1' ) {
39
+ if ( get_option( 'wp_cligs_failure' ) == '1' ) {
40
+ $wp_to_twitter_failure .= "<div class='error'><p>Cli.gs request failed! We couldn't shrink that URL, so we attached the normal URL to your Tweet.</p></div>";
41
+ }
42
+ if ( get_option( 'wp_twitter_failure' ) == '1' ) {
43
+ $wp_to_twitter_failure .= "<div class='error'><p>Sorry! I couldn't get in touch with the Twitter servers. Your tweet has been stored in a custom field attached to your post, so you can Tweet it manually if you wish!</p></div>";
44
+ } else if ( get_option( 'wp_twitter_failure' ) == '2') {
45
+ $wp_to_twitter_failure .= "<div class='error'><p>Sorry! I couldn't get in touch with the Twitter servers to post your new link! You'll have to post it manually, I'm afraid.</p></div>";
46
+ }
47
+ } else {
48
+ $wp_to_twitter_failure = '';
49
+ }
50
+
51
+
52
+ if ( $_POST['submit-type'] == 'options' ) {
53
  //UPDATE OPTIONS
54
+ update_option( 'newpost-published-update', $_POST['newpost-published-update'] );
55
+ update_option( 'newpost-published-text', $_POST['newpost-published-text'] );
56
+ update_option( 'newpost-published-showlink', $_POST['newpost-published-showlink'] );
57
+ update_option( 'jd_tweet_default', $_POST['jd_tweet_default'] );
58
+ update_option( 'oldpost-edited-update', $_POST['oldpost-edited-update'] );
59
+ update_option( 'oldpost-edited-text', $_POST['oldpost-edited-text'] );
60
+ update_option( 'oldpost-edited-showlink', $_POST['oldpost-edited-showlink'] );
61
+ update_option( 'jd_twit_pages',$_POST['jd_twit_pages'] );
62
+
63
+ if ( $_POST['jd-use-link-field'] == '2' ) {
64
+ update_option( 'jd-use-link-description', '1' );
65
+ update_option( 'jd-use-link-title', '0' );
66
+
67
+ } else if ( $_POST['jd-use-link-field'] == '1' ) {
68
+ update_option( 'jd-use-link-title', '1' );
69
+ update_option( 'jd-use-link-description', '0' );
70
+ }
71
+ update_option( 'newlink-published-text', $_POST['newlink-published-text'] );
72
+ update_option( 'jd_twit_blogroll',$_POST['jd_twit_blogroll'] );
73
+
74
  $message = "WP to Twitter Options Updated";
75
 
76
+ }else if ( $_POST['submit-type'] == 'login' ){
77
  //UPDATE LOGIN
78
+ if( ( $_POST['twitterlogin'] != '' ) AND ( $_POST['twitterpw'] != '' ) ) {
79
+ update_option( 'twitterlogin', $_POST['twitterlogin'] );
80
+ update_option( 'twitterlogin_encrypted', base64_encode( $_POST['twitterlogin'].':'.$_POST['twitterpw'] ) );
81
  $message = "Twitter login and password updated.";
82
  } else {
83
  $message = "You need to provide your twitter login and password!";
84
  }
85
+ } else if ( $_POST['submit-type'] == 'cligsapi' ) {
86
+ if ( $_POST['cligsapi'] != '' ) {
87
+ update_option( 'cligsapi',$_POST['cligsapi'] );
88
  $message = "Cligs API Key Updated";
89
  } else {
90
  $message = "Cli.gs API Key not added - <a href='http://cli.gs/user/api/'>get one here</a>!";
92
  }
93
 
94
  // FUNCTION to see if checkboxes should be checked
95
+ function jd_checkCheckbox( $theFieldname ){
96
+ if( get_option( $theFieldname ) == '1'){
97
+ echo 'checked="checked"';
98
  }
99
  }
100
+ // Check whether the server has supported for needed functions.
101
+ if ( get_option('jd-functions-checked') == '0') {
102
+ $wp_twitter_error = FALSE;
103
+ if ( !function_exists( 'fputs' ) ) {
104
+ $wp_twitter_error = TRUE;
105
+ $message = "Your server does not support <code>fputs</code>, the function used to send information to Twitter.";
106
+ }
107
+ if ( !function_exists( 'curl_init' ) && ( file_get_contents ( "http://www.joedolson.com/scripts/wp-to-twitter-check.txt" ) != 1 ) ) {
108
+ $wp_twitter_error = TRUE;
109
+ $message .= "Your server does not support the <code>file_get_contents</code> or <code>cURL</code> functions which this plugin uses to send information to Cli.gs. At least one of the above is required for this plugin to work.";
110
+ }
111
+ // If everything's OK, there's no reason to do this again.
112
+ if ($wp_twitter_error == FALSE) {
113
+ update_option( 'jd-functions-checked','1' );
114
+ }
115
+ }
116
+
117
  ?>
118
  <style type="text/css">
119
  <!--
128
  margin: 4px 0;
129
  border: 1px solid #eee;
130
  }
131
+ #wp-to-twitter form .error p {
132
+ background: none;
133
+ border: none;
134
+ }
135
  .floatright {
136
  float: right;
137
  }
145
  }
146
  -->
147
  </style>
148
+ <?php if ($wp_twitter_error == TRUE) {
149
+ echo "<div class='error'><p>This plugin will not work in your server environment.</p></div>";
150
+ }
151
+ if ( get_option( 'wp_twitter_failure' ) == '1' || get_option( 'wp_cligs_failure' ) == '1' ) {
152
+ echo $wp_to_twitter_failure;
153
+ }
154
+ ?>
155
  <?php if ($message) : ?>
156
  <div id="message" class="updated fade"><p><?php echo $message; ?></p></div>
157
  <?php endif; ?>
158
  <div id="dropmessage" class="updated" style="display:none;"></div>
159
 
160
  <div class="wrap" id="wp-to-twitter">
161
+ <?php if ( get_option( 'wp_twitter_failure' ) == '1' || get_option( 'wp_cligs_failure' ) == '1' ) { ?>
162
+ <form method="post" action="">
163
+ <div class="error">
164
+ <div>
165
+ <input type="hidden" name="submit-type" value="clear-error">
166
+ </div>
167
+ <p><input type="submit" name="submit" value="Clear 'WP to Twitter' Error" /> <strong>Why are you seeing this field?</strong><br />
168
+ <?php if ( get_option( 'wp_twitter_failure' ) == '1' ) {
169
+ echo "One or more of your last posts has failed to send it's status update to Twitter. Your Tweet has been saved in the custom meta data for your post, and you can re-Tweet it at your leisure.";
170
+ }
171
+ if ( get_option( 'wp_cligs_failure' ) == '1' ) {
172
+ echo "The query to the Cli.gs API failed, and your URL was not shrunk. The normal post URL was attached to your Tweet.";
173
+ }
174
+ ?>
175
+ If you see these errors frequently, please <a href="http://www.joedolson.com/articles/wp-to-twitter/">notify the developer</a>.
176
+ </p>
177
+ </div>
178
+ </form>
179
+ <?php
180
+ }
181
+ ?>
182
+
183
  <h2>WP to Twitter Options</h2>
184
  <p>
185
  For any update field, you can use the codes <code>#title#</code> for the title of your blog post or <code>#blog#</code> for the title of your blog! Given the character limit for Twitter, you may not want to include your blog title.
186
  </p>
187
+
188
+ <form method="post" action="">
189
  <div>
190
  <fieldset>
191
  <legend>Wordpress to Twitter Publishing Options</legend>
192
  <p>
193
  <input type="checkbox" name="jd_twit_pages" id="jd_twit_pages" value="1" <?php jd_checkCheckbox('jd_twit_pages')?> />
194
+ <label for="jd_twit_pages"><strong>Update Twitter when new Wordpress Pages are published</strong></label>
195
  </p>
196
  <p>
197
  <input type="checkbox" name="newpost-published-update" id="newpost-published-update" value="1" <?php jd_checkCheckbox('newpost-published-update')?> />
198
+ <label for="newpost-published-update"><strong>Update Twitter when the new post is published</strong></label>
199
  </p>
200
  <p>
201
  <label for="newpost-published-text">Text for this Twitter update</label><br />
207
 
208
  <p>
209
  <input type="checkbox" name="oldpost-edited-update" id="oldpost-edited-update" value="1" <?php jd_checkCheckbox('oldpost-edited-update')?> />
210
+ <label for="oldpost-edited-update"><strong>Update Twitter when an old post has been edited</strong></label>
211
  </p>
212
  <p>
213
  <label for="oldpost-edited-text">Text for this Twitter update</label><br />
216
  <input type="checkbox" name="oldpost-edited-showlink" id="oldpost-edited-showlink" value="1" <?php jd_checkCheckbox('oldpost-edited-showlink')?> />
217
  <label for="oldpost-edited-showlink">Provide link to blog?</label>
218
  </p>
219
+
220
+ <p>
221
+ <input type="checkbox" name="jd_twit_blogroll" id="jd_twit_blogroll" value="1" <?php jd_checkCheckbox('jd_twit_blogroll')?> />
222
+ <label for="oldpost-edited-update"><strong>Update Twitter when you post a Blogroll link</strong></label>
223
+ </p>
224
+ <p>
225
+ <input type="radio" name="jd-use-link-field" id="jd-use-link-title" value="1" <?php jd_checkCheckbox('jd-use-link-title')?> /> <label for="jd-use-link-title">Use <strong>link title</strong> for Twitter updates</label> <input type="radio" name="jd-use-link-field" id="jd-use-link-description" value="2" <?php jd_checkCheckbox('jd-use-link-description')?> /> <label for="jd-use-link-description">Use <strong>link description</strong> for Twitter updates</label>
226
+ </p>
227
+
228
+ <p>
229
+ <label for="newlink-published-text">Text for this Twitter update (used if above choice isn't available.)</label><br />
230
+ <input type="text" name="newlink-published-text" id="newlink-published-text" size="60" maxlength="146" value="<?php echo(get_option('newlink-published-text')) ?>" />
231
+ </p>
232
+
233
+ <p>
234
+ <input type="checkbox" name="jd_tweet_default" id="jd_tweet_default" value="1" <?php jd_checkCheckbox('jd_tweet_default')?> />
235
+ <label for="jd_tweet_default">Set default Tweet status to 'No.'</label><br />
236
+ <strong>Twitter updates can be set on a post by post basis. By default, posts WILL be posted to Twitter. Check this to change the default to NO.</strong>
237
+ </p>
238
+
239
  <div>
240
  <input type="hidden" name="submit-type" value="options" />
241
  </div>
247
 
248
  <h2 class="twitter">Your Twitter account details</h2>
249
 
250
+ <form method="post" action="" >
251
  <div>
252
  <p>
253
  <label for="twitterlogin">Your Twitter username:</label>
257
  <label for="twitterpw">Your Twitter password:</label>
258
  <input type="password" name="twitterpw" id="twitterpw" value="" />
259
  </p>
260
+ <input type="hidden" name="submit-type" value="login" />
261
  <p><input type="submit" name="submit" value="Save Twitter Login Info" /> &raquo; <small>Don't have a Twitter account? <a href="http://www.twitter.com">Get one for free here</a></small></p>
262
  </div>
263
  </form>
264
 
265
  <h2 class="cligs">Your Cli.gs account details</h2>
266
 
267
+ <form method="post" action="">
268
  <div>
269
  <p>
270
  <label for="cligsapi">Your Cli.gs API Key:</label>
271
  <input type="text" name="cligsapi" id="cligsapi" size="40" value="<?php echo(get_option('cligsapi')) ?>" />
272
  </p>
273
  <div>
274
+ <input type="hidden" name="submit-type" value="cligsapi" />
275
  </div>
276
+ <p><input type="submit" name="submit" value="Save Cli.gs API Key" /> &raquo; <small>Don't have a Cli.gs account or Cligs API key? <a href='http://cli.gs/user/api/'>Get one free here</a>! You'll need an API key in order to associate the Cligs you create with your Cligs account.</small></p>
277
  </div>
278
  <div>
279
 
wp-to-twitter.php CHANGED
@@ -1,235 +1,351 @@
1
- <?php
2
- /*
3
- Plugin Name: WP to Twitter
4
- Plugin URI: http://www.joedolson.com/wp-to-twitter/
5
- Description: Updates Twitter when you create a new blog post using Cli.gs. With a Cli.gs API key, creates a clig in your Cli.gs account with the name of your post as the title.
6
- Version: 1.0beta
7
- Author: Joseph Dolson, with a nod to Victoria Chan & Jonathan Dingman
8
- Author URI: http://www.joedolson.com/
9
- */
10
-
11
- /* Copyright 2008 Joseph C Dolson (email : wp-to-twitter@joedolson.com)
12
-
13
- This program is free software; you can redistribute it and/or modify
14
- it under the terms of the GNU General Public License as published by
15
- the Free Software Foundation; either version 2 of the License, or
16
- (at your option) any later version.
17
-
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- GNU General Public License for more details.
22
-
23
- You should have received a copy of the GNU General Public License
24
- along with this program; if not, write to the Free Software
25
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
- */
27
-
28
- $jd_plugin_url = "http://www.joedolson.com/wp-to-twitter/";
29
- // This function performs the API post to Twitter
30
- function jd_doTwitterAPIPost( $twit, $twitterURI ) {
31
- $host = 'twitter.com';
32
- $port = 80;
33
- $fp = @fsockopen($host, $port, $err_num, $err_msg, 10);
34
-
35
- //check if user login details have been entered on admin page
36
- $thisLoginDetails = get_option( 'twitterlogin_encrypted' );
37
-
38
- if ( $thisLoginDetails != '' ) {
39
- if ( !$fp ) {
40
- #echo "$err_msg ($err_num)<br>\n"; // Fail Silently
41
- } else {
42
- fputs( $fp, "POST $twitterURI HTTP/1.1\r\n" );
43
- fputs( $fp, "Authorization: Basic ".$thisLoginDetails."\r\n" );
44
- fputs( $fp, "User-Agent: ".$agent."\n" );
45
- fputs( $fp, "Host: $host\n" );
46
- fputs( $fp, "Content-type: application/x-www-form-urlencoded\n" );
47
- fputs( $fp, "Content-length: ".strlen( $twit)."\n" );
48
- fputs( $fp, "Connection: close\n\n" );
49
- fputs( $fp, $twit );
50
- for ( $i = 1; $i < 10; $i++ ) {
51
- $reply = fgets( $fp, 256 );
52
- }
53
- fclose( $fp );
54
- }
55
- return $response;
56
- } else {
57
- // no username/password: return an empty string
58
- return '';
59
- }
60
- }
61
-
62
-
63
- function jd_twit( $post_ID ) {
64
- $twitterURI = "/statuses/update.xml";
65
- $thisposttitle = urlencode( stripcslashes( $_POST['post_title'] ) );
66
- $thispostlink = get_permalink( $post_ID );
67
- $thisblogtitle = urlencode( get_bloginfo( 'name' ) );
68
- $cligsapi = get_option( 'cligsapi' );
69
- $sentence = '';
70
- $customTweet = stripcslashes( $_POST['jd_twitter'] );
71
-
72
- if ( $_POST['publish'] == 'Publish' ){
73
- // publish new post
74
- if ( get_option( 'newpost-published-update' ) == '1' ) {
75
- $sentence = get_option( 'newpost-published-text' );
76
- if ( get_option( 'newpost-published-showlink') == '1' ) {
77
- // Generate and grab the clig using the Cli.gs API
78
- $shrink = file_get_contents( "http://cli.gs/api/v1/cligs/create?url=".$thispostlink."&title=".$thisposttitle."&key=".$cligsapi."&appid=WP-to-Twitter" );
79
- $sentence = $sentence . " " . $shrink;
80
-
81
- if ( $customTweet != "" ) {
82
- // Get the custom Tweet message if it's been supplied. Truncate it to fit if necessary.
83
- if ( get_option( 'newpost-published-showlink') == '1' ) {
84
- if ( ( strlen( $customTweet ) + 21) > 140 ) {
85
- $customTweet = substr( $customTweet, 0, 119 );
86
- }
87
- } else {
88
- if ( strlen( $customTweet ) > 140 ) {
89
- $customTweet = substr( $customTweet, 0, 140 );
90
- }
91
- }
92
- if ( get_option( 'newpost-published-showlink') == '1' ) {
93
- $sentence = $customTweet . " " . $shrink;
94
- } else {
95
- $sentence = $customTweet;
96
- }
97
- } else {
98
- // Check the length of the tweet and truncate parts as necessary.
99
- $twit_length = strlen( $sentence );
100
- $title_length = strlen( $thisposttitle );
101
- $blog_length = strlen( $thisblogtitle );
102
- if ( ( ( $twit_length + $title_length ) - 7 ) < 140 ) {
103
- $sentence = str_replace( '#title#', $thisposttitle, $sentence );
104
- $twit_length = strlen( $sentence );
105
- } else {
106
- $thisposttitle = substr( $thisposttitle, 0, ( 140- ( $twit_length-3 ) ) ) . "...";
107
- $sentence = str_replace ( '#title#', $thisposttitle, $sentence );
108
- $twit_length = strlen( $sentence );
109
- }
110
- if ( ( ( $twit_length + $blog_length ) - 6 ) < 140 ) {
111
- $thisblogtitle = substr( $thisblogtitle, 0, ( 140-( $twit_length-3 ) ) ) . "...";
112
- $sentence = str_replace ( '#blog#',$thisblogtitle,$sentence );
113
- }
114
- }
115
- /* This is for testing. Creates a post meta field containing the Cli.gs API request string
116
- //add_post_meta($post_ID, 'post_cligs_text',"http://cli.gs/api/v1/cligs/create?url=".$thispostlink."&title=".$thisposttitle."&key=".$cligsapi."&appid=WP-to-Twitter"); */
117
- }
118
- }
119
- } else if ( ( $_POST['originalaction'] == "editpost" ) && ( $_POST['prev_status'] == 'publish' ) ) {
120
- // if this is an old post and editing updates are enabled
121
- if ( get_option( 'oldpost-edited-update') == '1' ) {
122
- $sentence = get_option( 'oldpost-edited-text' );
123
- if ( get_option( 'oldpost-edited-showlink') == '1') {
124
- $thisposttitle = $thisposttitle . ' ( ' . $thispostlink . ' )';
125
- }
126
- $sentence = str_replace( '#title#', $thisposttitle, $sentence );
127
- $sentence = str_replace( '#blog#',$thisblogtitle,$sentence );
128
-
129
- }
130
- }
131
-
132
- if ( $sentence != '' ) {
133
- $sendToTwitter = jd_doTwitterAPIPost( 'status='.$sentence, $twitterURI );
134
- }
135
-
136
- return $post_ID;
137
- }
138
- // Add custom Tweet field on Post & Page write/edit forms
139
- function jd_add_twitter_textinput() {
140
- global $post;
141
- $post_id = $post;
142
- if (is_object($post_id)) {
143
- $post_id = $post_id->ID;
144
- }
145
- $jd_twitter = htmlspecialchars(stripcslashes(get_post_meta($post_id, 'jd_twitter', true)));
146
- ?>
147
- <script type="text/javascript">
148
- <!-- Begin
149
- function countChars(field,cntfield) {
150
- cntfield.value = field.value.length;
151
- }
152
- // End -->
153
- </script>
154
- <?php /* Compatibility with version 2.3 and below (needs to be tested.) */ ?>
155
- <?php if (substr(get_bloginfo('version'), 0, 3) >= '2.5') { ?>
156
- <div id="wp-to-twitter" class="postbox closed">
157
- <h3><?php _e('WP to Twitter', 'wp-to-twitter') ?></h3>
158
- <div class="inside">
159
- <div id="jd-twitter">
160
- <?php } else { ?>
161
- <div class="dbx-b-ox-wrapper">
162
- <fieldset id="twitdiv" class="dbx-box">
163
- <div class="dbx-h-andle-wrapper">
164
- <h3 class="dbx-handle"><?php _e('WP to Twitter', 'wp-to-twitter') ?></h3>
165
- </div>
166
- <div class="dbx-c-ontent-wrapper">
167
- <div class="dbx-content">
168
- <?php } ?>
169
-
170
- <input value="jd_twit_edit" type="hidden" name="jd_twit_edit" />
171
-
172
- <label for="jd_twitter"><?php _e('Twitter Post', 'wp-to-twitter') ?></label><br /><textarea name="jd_twitter" id="jd_twitter" rows="2" cols="60"
173
- onKeyDown="countChars(document.post.jd_twitter,document.post.twitlength)"
174
- onKeyUp="countChars(document.post.jd_twitter,document.post.twitlength)"><?php echo $jd_twitter ?></textarea>
175
- <p><input readonly type="text" name="twitlength" size="3" maxlength="3" value="<?php echo strlen( $description); ?>" />
176
- <?php _e(' characters. Twitter posts are a maximum of 140 characters; if your Cli.gs URL is appended to the end of your document, you have 119 characters available.', 'wp-to-twitter') ?> <a target="__blank" href="<?php echo $jd_plugin_url; ?>"><?php _e('Get Support', 'wp-to-twitter') ?></a> &raquo;
177
- </p>
178
- <?php if (substr(get_bloginfo('version'), 0, 3) >= '2.5') { ?>
179
- </div></div></div>
180
- <?php } else { ?>
181
- </div>
182
- </fieldset>
183
- </div>
184
- <?php } ?>
185
-
186
- <?php
187
- }
188
- // Post the Custom Tweet into the post meta table
189
- function post_jd_twitter( $id ) {
190
- $jd_twit_edit = $_POST["jd_twit_edit"];
191
- if (isset($jd_twit_edit) && !empty($jd_twit_edit)) {
192
- $jd_twitter = $_POST["jd_twitter"];
193
- delete_post_meta( $id, 'jd_twitter' );
194
- if (isset($jd_twitter) && !empty($jd_twitter)) {
195
- add_post_meta( $id, 'jd_twitter', $jd_twitter );
196
- }
197
- }
198
- }
199
-
200
- // Add the administrative settings to the "Settings" menu.
201
- function jd_addTwitterAdminPages() {
202
- if ( function_exists( 'add_submenu_page' ) ) {
203
- add_options_page( 'WP -> Twitter', 'WP -> Twitter', 8, __FILE__, 'jd_wp_Twitter_manage_page' );
204
- }
205
- }
206
- // Include the Manager page
207
- function jd_wp_Twitter_manage_page() {
208
- include(dirname(__FILE__).'/wp-to-twitter-manager.php' );
209
- }
210
-
211
-
212
- //Add Plugin Actions to WordPress
213
- if ( substr( get_bloginfo( 'version' ), 0, 3 ) >= '2.5' ) {
214
- add_action( 'edit_form_advanced','jd_add_twitter_textinput' );
215
- if ( get_option( 'jd_twit_pages')=='1') {
216
- add_action( 'edit_page_form','jd_add_twitter_textinput' );
217
- }
218
- } else {
219
- add_action( 'dbx_post_advanced','jd_add_twitter_textinput' );
220
- if (get_option( 'jd_twit_pages')=='1') {
221
- add_action( 'dbx_page_advanced','jd_add_twitter_textinput' );
222
- }
223
- }
224
-
225
-
226
- if ( get_option( 'jd_twit_pages')=='1') {
227
- add_action( 'publish_page', 'jd_twit' );
228
- add_action( 'edit_page','post_jd_twitter' );
229
- add_action( 'publish_page','post_jd_twitter' );
230
- }
231
- add_action( 'publish_post', 'jd_twit' );
232
- add_action( 'admin_menu', 'jd_addTwitterAdminPages' );
233
- add_action( 'edit_post','post_jd_twitter' );
234
- add_action( 'publish_post','post_jd_twitter' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  ?>
1
+ <?php
2
+ /*
3
+ Plugin Name: WP to Twitter
4
+ Plugin URI: http://www.joedolson.com/articles/wp-to-twitter/
5
+ Description: Updates Twitter when you create a new blog post or add to your blogroll using Cli.gs. With a Cli.gs API key, creates a clig in your Cli.gs account with the name of your post as the title.
6
+ Version: 1.2.0
7
+ Author: Joseph Dolson
8
+ Author URI: http://www.joedolson.com/
9
+ */
10
+ /* Copyright 2008 Joseph C Dolson (email : wp-to-twitter@joedolson.com)
11
+
12
+ This program is free software; you can redistribute it and/or modify
13
+ it under the terms of the GNU General Public License as published by
14
+ the Free Software Foundation; either version 2 of the License, or
15
+ (at your option) any later version.
16
+
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
+
22
+ You should have received a copy of the GNU General Public License
23
+ along with this program; if not, write to the Free Software
24
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
+ */
26
+ $version = "1.2.0";
27
+ $jd_plugin_url = "http://www.joedolson.com/articles/wp-to-twitter/";
28
+ // This function performs the API post to Twitter
29
+ function jd_doTwitterAPIPost( $twit, $twitterURI ) {
30
+ $host = 'twitter.com';
31
+ $port = 80;
32
+ $fp = @fsockopen($host, $port, $err_num, $err_msg, 10);
33
+
34
+ //check if user login details have been entered on admin page
35
+ $thisLoginDetails = get_option( 'twitterlogin_encrypted' );
36
+
37
+ if ( $thisLoginDetails != '' ) {
38
+ if ( !is_resource($fp) ) {
39
+ #echo "$err_msg ($err_num)<br>\n"; // Fail Silently, but you could turn these back on...
40
+ return FALSE;
41
+ } else {
42
+ $response = TRUE;
43
+ if (!fputs( $fp, "POST $twitterURI HTTP/1.1\r\n" )) {
44
+ return FALSE;
45
+ }
46
+ fputs( $fp, "Authorization: Basic ".$thisLoginDetails."\r\n" );
47
+ fputs( $fp, "User-Agent: ".$agent."\n" );
48
+ fputs( $fp, "Host: $host\n" );
49
+ fputs( $fp, "Content-type: application/x-www-form-urlencoded\n" );
50
+ fputs( $fp, "Content-length: ".strlen( $twit )."\n" );
51
+ fputs( $fp, "Connection: close\n\n" );
52
+ fputs( $fp, $twit );
53
+ for ( $i = 1; $i < 10; $i++ ) {
54
+ $reply = fgets( $fp, 256 );
55
+ }
56
+ fclose( $fp );
57
+ return $response;
58
+ }
59
+ } else {
60
+ // no username/password: return an empty string
61
+ return FALSE;
62
+ }
63
+ }
64
+
65
+ // cURL query contributed by Thor Erik (http://thorerik.net)
66
+ function getfilefromurl($url) {
67
+ $ch = curl_init();
68
+ curl_setopt( $ch, CURLOPT_HEADER, 0 );
69
+ curl_setopt( $ch, CURLOPT_VERBOSE, 0 );
70
+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
71
+ curl_setopt( $ch, CURLOPT_URL, $url );
72
+ $output = curl_exec( $ch );
73
+ curl_close( $ch );
74
+ return $output;
75
+ }
76
+
77
+ function jd_twit( $post_ID ) {
78
+ $jd_tweet_this = $_POST["jd_tweet_this"];
79
+ if ( $jd_tweet_this != "no" ) {
80
+ $twitterURI = "/statuses/update.xml";
81
+ $thisposttitle = urlencode( stripcslashes( $_POST['post_title'] ) );
82
+ $thispostlink = urlencode( get_permalink( $post_ID ) );
83
+ $thisblogtitle = urlencode( get_bloginfo( 'name' ) );
84
+ $cligsapi = get_option( 'cligsapi' );
85
+ $sentence = '';
86
+ $customTweet = stripcslashes( $_POST['jd_twitter'] );
87
+ $oldClig = get_post_meta( $post_ID, 'wp_jd_clig', TRUE );
88
+
89
+ if ( $_POST['publish'] == 'Publish' ){
90
+ // publish new post
91
+ if ( get_option( 'newpost-published-update' ) == '1' ) {
92
+ $sentence = get_option( 'newpost-published-text' );
93
+ if ( get_option( 'newpost-published-showlink') == '1' ) {
94
+ // Generate and grab the clig using the Cli.gs API
95
+ // cURL alternative contributed by Thor Erik (http://thorerik.net)
96
+
97
+ $shrink = @file_get_contents( "http://cli.gs/api/v1/cligs/create?t=fgc&appid=WP-to-Twitter&url=".$thispostlink."&title=".$thisposttitle."&key=".$cligsapi);
98
+ if ( $shrink === FALSE ) {
99
+ $shrink = getfilefromurl( "http://cli.gs/api/v1/cligs/create?t=gffu&appid=WP-to-Twitter&url=".$thispostlink."&title=".$thisposttitle."&key=".$cligsapi);
100
+ }
101
+ if ( stristr( $shrink, "http://" ) === FALSE ) {
102
+ $shrink = FALSE;
103
+ }
104
+ if ( $shrink === FALSE) {
105
+ update_option('wp_cligs_failure','1');
106
+ $shrink = $thispostlink;
107
+ }
108
+ $sentence = $sentence . " " . $shrink;
109
+
110
+ if ( $customTweet != "" ) {
111
+ // Get the custom Tweet message if it's been supplied. Truncate it to fit if necessary.
112
+ if ( get_option( 'newpost-published-showlink') == '1' ) {
113
+ if ( ( strlen( $customTweet ) + 21) > 140 ) {
114
+ $customTweet = substr( $customTweet, 0, 119 );
115
+ }
116
+ } else {
117
+ if ( strlen( $customTweet ) > 140 ) {
118
+ $customTweet = substr( $customTweet, 0, 140 );
119
+ }
120
+ }
121
+ if ( get_option( 'newpost-published-showlink') == '1' ) {
122
+ $sentence = $customTweet . " " . $shrink;
123
+ } else {
124
+ $sentence = $customTweet;
125
+ }
126
+ } else {
127
+ // Check the length of the tweet and truncate parts as necessary.
128
+ $twit_length = strlen( $sentence );
129
+ $title_length = strlen( $thisposttitle );
130
+ $blog_length = strlen( $thisblogtitle );
131
+ if ( ( ( $twit_length + $title_length ) - 7 ) < 140 ) {
132
+ $sentence = str_replace( '#title#', $thisposttitle, $sentence );
133
+ $twit_length = strlen( $sentence );
134
+ } else {
135
+ $thisposttitle = substr( $thisposttitle, 0, ( 140- ( $twit_length-3 ) ) ) . "...";
136
+ $sentence = str_replace ( '#title#', $thisposttitle, $sentence );
137
+ $twit_length = strlen( $sentence );
138
+ }
139
+ if ( ( ( $twit_length + $blog_length ) - 6 ) < 140 ) {
140
+ $thisblogtitle = substr( $thisblogtitle, 0, ( 140-( $twit_length-3 ) ) ) . "...";
141
+ $sentence = str_replace ( '#blog#',$thisblogtitle,$sentence );
142
+ }
143
+ }
144
+ // Stores the posts CLIG in a custom field for later use as needed.
145
+ add_post_meta ( $post_ID, 'wp_jd_clig', $shrink );
146
+ /* This is for testing. Creates a post meta field containing the Cli.gs API request string
147
+ //add_post_meta($post_ID, 'post_cligs_text',"http://cli.gs/api/v1/cligs/create?url=".$thispostlink."&title=".$thisposttitle."&key=".$cligsapi."&appid=WP-to-Twitter"); */
148
+ }
149
+ }
150
+ } else if ( ( $_POST['originalaction'] == "editpost" ) && ( $_POST['prev_status'] == 'publish' ) ) {
151
+ // if this is an old post and editing updates are enabled
152
+ if ( get_option( 'oldpost-edited-update') == '1' ) {
153
+ $sentence = get_option( 'oldpost-edited-text' );
154
+ if ( get_option( 'oldpost-edited-showlink') == '1') {
155
+ if ( $oldClig != '' ) {
156
+ $old_post_link = $oldClig;
157
+ } else {
158
+ $old_post_link = $thispostlink;
159
+ }
160
+ $thisposttitle = $thisposttitle . ' (' . $old_post_link . ')';
161
+ }
162
+ $sentence = str_replace( '#title#', $thisposttitle, $sentence );
163
+ $sentence = str_replace( '#blog#',$thisblogtitle,$sentence );
164
+
165
+ }
166
+ }
167
+
168
+ if ( $sentence != '' ) {
169
+ $sendToTwitter = jd_doTwitterAPIPost( 'source=wptotwitter&status='.$sentence, $twitterURI );
170
+ if ($sendToTwitter === FALSE) {
171
+ add_post_meta( $post_ID,'jd_wp_twitter',$sentence);
172
+ update_option('wp_twitter_failure','1');
173
+ }
174
+ }
175
+
176
+ return $post_ID;
177
+ }
178
+ }
179
+ // Add Tweets on links in Blogroll
180
+ function jd_twit_link( $link_ID ) {
181
+ $thislinkprivate = $_POST['link_visible'];
182
+ if ($thislinkprivate != 'N') {
183
+ $thislinkname = urlencode( stripcslashes( $_POST['link_name'] ) );
184
+ $thispostlink = urlencode( $_POST['link_url'] ) ;
185
+ $thislinkdescription = urlencode( stripcslashes( $_POST['link_description'] ) );
186
+ $cligsapi = get_option( 'cligsapi' );
187
+ $twitterURI = "/statuses/update.xml";
188
+ $sentence = '';
189
+
190
+ # || (get_option( 'jd-use-link-title' ) == '1' && $thislinkname == '')
191
+ if ( (get_option( 'jd-use-link-description' ) == '1' && $thislinkdescription == '') ) {
192
+ $sentence = get_option( 'newlink-published-text' );
193
+ } else {
194
+ if ( get_option( 'jd-use-link-description' ) == '1' && get_option ( 'jd-use-link-title' ) == '0' ) {
195
+ $sentence = $thislinkdescription;
196
+ } else if ( get_option( 'jd-use-link-description' ) == '0' && get_option ( 'jd-use-link-title' ) == '1' ) {
197
+ $sentence = $thislinkname;
198
+ }
199
+ }
200
+ if (strlen($sentence) > 120) {
201
+ $sentence = substr($sentence,0,116) . '...';
202
+ }
203
+ // Generate and grab the clig using the Cli.gs API
204
+ // cURL alternative contributed by Thor Erik (http://thorerik.net)
205
+
206
+ $shrink = @file_get_contents( "http://cli.gs/api/v1/cligs/create?t=fgc&v=$version&appid=WP-to-Twitter&url=".$thispostlink."&title=".$thislinkname."&key=".$cligsapi);
207
+ if ( $shrink === FALSE ) {
208
+ $shrink = getfilefromurl( "http://cli.gs/api/v1/cligs/create?t=gffu&v=$version&appid=WP-to-Twitter&url=".$thispostlink."&title=".$thislinkname."&key=".$cligsapi);
209
+ }
210
+ if ( stristr( $shrink, "http://" ) === FALSE ) {
211
+ $shrink = FALSE;
212
+ }
213
+ if ( $shrink === FALSE) {
214
+ update_option('wp_cligs_failure','1');
215
+ $shrink = $thispostlink;
216
+ }
217
+ $sentence = $sentence . " " . $shrink;
218
+
219
+ if ( $sentence != '' ) {
220
+ $sendToTwitter = jd_doTwitterAPIPost( 'source=wptotwitter&status='.$sentence, $twitterURI );
221
+ if ($sendToTwitter === FALSE) {
222
+ update_option('wp_twitter_failure','2');
223
+ }
224
+ }
225
+
226
+ return $link_ID;
227
+ } else {
228
+ return '';
229
+ }
230
+ }
231
+
232
+
233
+ // Add custom Tweet field on Post & Page write/edit forms
234
+ function jd_add_twitter_textinput() {
235
+ global $post;
236
+ $post_id = $post;
237
+ if (is_object($post_id)) {
238
+ $post_id = $post_id->ID;
239
+ }
240
+ $jd_twitter = htmlspecialchars(stripcslashes(get_post_meta($post_id, 'jd_twitter', true)));
241
+ $jd_tweet_this = get_post_meta($post_id, 'jd_tweet_this', true);
242
+ if ($jd_tweet_this == 'no' || get_option( 'jd_tweet_default' ) == '1' ) {
243
+ $jd_selected = ' checked="checked"';
244
+ }
245
+ ?>
246
+ <script type="text/javascript">
247
+ <!-- Begin
248
+ function countChars(field,cntfield) {
249
+ cntfield.value = field.value.length;
250
+ }
251
+ // End -->
252
+ </script>
253
+ <?php /* Compatibility with version 2.3 and below (needs to be tested.) */ ?>
254
+ <?php if (substr(get_bloginfo('version'), 0, 3) >= '2.5') { ?>
255
+ <div id="wp-to-twitter" class="postbox closed">
256
+ <h3><?php _e('WP to Twitter', 'wp-to-twitter') ?></h3>
257
+ <div class="inside">
258
+ <div id="jd-twitter">
259
+ <?php } else { ?>
260
+ <div class="dbx-b-ox-wrapper">
261
+ <fieldset id="twitdiv" class="dbx-box">
262
+ <div class="dbx-h-andle-wrapper">
263
+ <h3 class="dbx-handle"><?php _e('WP to Twitter', 'wp-to-twitter') ?></h3>
264
+ </div>
265
+ <div class="dbx-c-ontent-wrapper">
266
+ <div class="dbx-content">
267
+ <?php } ?>
268
+
269
+ <label for="jd_twitter"><?php _e('Twitter Post', 'wp-to-twitter') ?></label><br /><textarea name="jd_twitter" id="jd_twitter" rows="2" cols="60"
270
+ onKeyDown="countChars(document.post.jd_twitter,document.post.twitlength)"
271
+ onKeyUp="countChars(document.post.jd_twitter,document.post.twitlength)"><?php echo $jd_twitter ?></textarea>
272
+ <p><input readonly type="text" name="twitlength" size="3" maxlength="3" value="<?php echo strlen( $description); ?>" />
273
+ <?php _e(' characters. Twitter posts are a maximum of 140 characters; if your Cli.gs URL is appended to the end of your document, you have 119 characters available.', 'wp-to-twitter') ?> <a target="__blank" href="<?php echo $jd_plugin_url; ?>"><?php _e('Get Support', 'wp-to-twitter') ?></a> &raquo;
274
+ </p>
275
+ <p>
276
+ <input type="checkbox" name="jd_tweet_this" value="no"<?php echo $jd_selected; ?> /> <label for="jd_tweet_this">Don't Tweet this post.</label>
277
+ </p>
278
+ <?php if (substr(get_bloginfo('version'), 0, 3) >= '2.5') { ?>
279
+ </div></div></div>
280
+ <?php } else { ?>
281
+ </div>
282
+ </fieldset>
283
+ </div>
284
+ <?php } ?>
285
+
286
+ <?php
287
+ }
288
+ // Post the Custom Tweet into the post meta table
289
+ function post_jd_twitter( $id ) {
290
+ $jd_twitter = $_POST[ 'jd_twitter' ];
291
+ delete_post_meta( $id, 'jd_twitter' );
292
+ if (isset($jd_twitter) && !empty($jd_twitter)) {
293
+ add_post_meta( $id, 'jd_twitter', $jd_twitter );
294
+ }
295
+ $jd_tweet_this = $_POST[ 'jd_tweet_this' ];
296
+ delete_post_meta( $id, 'jd_tweet_this' );
297
+ if ($jd_tweet_this = 'no') {
298
+ add_post_meta( $id, 'jd_tweet_this', 'no');
299
+ } else {
300
+ add_post_meta( $id, 'jd_tweet_this', 'yes');
301
+ }
302
+ }
303
+
304
+ // Add the administrative settings to the "Settings" menu.
305
+ function jd_addTwitterAdminPages() {
306
+ if ( function_exists( 'add_submenu_page' ) ) {
307
+ add_options_page( 'WP -> Twitter', 'WP -> Twitter', 8, __FILE__, 'jd_wp_Twitter_manage_page' );
308
+ }
309
+ }
310
+ // Include the Manager page
311
+ function jd_wp_Twitter_manage_page() {
312
+ include(dirname(__FILE__).'/wp-to-twitter-manager.php' );
313
+ }
314
+ function plugin_action($links, $file) {
315
+ if ($file == plugin_basename(dirname(__FILE__).'/wp-to-twitter.php'))
316
+ $links[] = "<a href='options-general.php?page=wp-to-twitter/wp-to-twitter-manager.php'>" . __('Settings', 'wp-to-twitter') . "</a>";
317
+ return $links;
318
+ }
319
+
320
+ //Add Plugin Actions to WordPress
321
+
322
+ add_filter('plugin_action_links', 'plugin_action', -10, 2);
323
+
324
+ if ( substr( get_bloginfo( 'version' ), 0, 3 ) >= '2.5' ) {
325
+ add_action( 'edit_form_advanced','jd_add_twitter_textinput' );
326
+ if ( get_option( 'jd_twit_pages')=='1') {
327
+ add_action( 'edit_page_form','jd_add_twitter_textinput' );
328
+ }
329
+ } else {
330
+ add_action( 'dbx_post_advanced','jd_add_twitter_textinput' );
331
+ if (get_option( 'jd_twit_pages')=='1') {
332
+ add_action( 'dbx_page_advanced','jd_add_twitter_textinput' );
333
+ }
334
+ }
335
+ if ( get_option( 'wp_twitter_failure' ) == '1' || get_option( 'wp_cligs_failure' ) == '1' ) {
336
+ add_action('admin_notices', create_function( '', "echo '<div class=\"error\"><p>There\'s been an error posting your Twitter status! <a href=\"".get_bloginfo('wpurl')."/wp-admin/options-general.php?page=wp-to-twitter/wp-to-twitter.php\">Visit your WP to Twitter settings page</a> to get more information and to clear this error message.</div>';" ) );
337
+ }
338
+
339
+ if ( get_option( 'jd_twit_pages')=='1') {
340
+ add_action( 'publish_page', 'jd_twit' );
341
+ add_action( 'edit_page','post_jd_twitter' );
342
+ add_action( 'publish_page','post_jd_twitter' );
343
+ }
344
+ if ( get_option( 'jd_twit_blogroll') == '1') {
345
+ add_action( 'add_link', 'jd_twit_link' );
346
+ }
347
+ add_action( 'publish_post', 'jd_twit' );
348
+ add_action( 'admin_menu', 'jd_addTwitterAdminPages' );
349
+ add_action( 'edit_post','post_jd_twitter' );
350
+ add_action( 'publish_post','post_jd_twitter' );
351
  ?>