Version Description
Download this release
Release Info
Developer | joedolson |
Plugin | WP to Twitter |
Version | 1.1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 1.1.1
- images/cligs.png +0 -0
- images/twitter.png +0 -0
- readme.txt +63 -49
- images/wp-to-twitter-custom.png → screenshot-1.png +0 -0
- images/wp-to-twitter-options.png → screenshot-2.png +0 -0
- wp-to-twitter-manager.php +104 -34
- wp-to-twitter.php +279 -234
images/cligs.png
DELETED
Binary file
|
images/twitter.png
DELETED
Binary file
|
readme.txt
CHANGED
@@ -1,50 +1,64 @@
|
|
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.
|
6 |
-
Tested up to: 2.6
|
7 |
-
Stable tag:
|
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
|
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 |
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, 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 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)
|
26 |
+
|
27 |
+
(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!)
|
28 |
+
|
29 |
+
== Installation ==
|
30 |
+
|
31 |
+
1. Upload the `wp-to-twitter` folder to your `/wp-content/plugins/` directory
|
32 |
+
2. Activate the plugin using the `Plugins` menu in WordPress
|
33 |
+
3. Go to Settings > WP->Twitter
|
34 |
+
4. Adjust the WP->Twitter Options as you prefer them.
|
35 |
+
5. Supply your Twitter username and login.
|
36 |
+
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.
|
37 |
+
7. That's it! You're all set.
|
38 |
+
|
39 |
+
== Frequently Asked Questions ==
|
40 |
+
|
41 |
+
= Do I have to have a Twitter.com account to use this plugin? =
|
42 |
+
|
43 |
+
Yes, you need an account to use this plugin.
|
44 |
+
|
45 |
+
= Do I have to have a Cli.gs account to use this plugin? =
|
46 |
+
|
47 |
+
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.
|
48 |
+
|
49 |
+
= Twitter goes down a lot. What happens if it's not available? =
|
50 |
+
|
51 |
+
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.
|
52 |
+
|
53 |
+
= What if Cli.gs isn't available when I make my post? =
|
54 |
+
|
55 |
+
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.
|
56 |
+
|
57 |
+
= What if my server doesn't support the methods you use to contact these other sites? =
|
58 |
+
|
59 |
+
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.
|
60 |
+
|
61 |
+
== Screenshots ==
|
62 |
+
|
63 |
+
1. WP to Twitter custom Tweet box
|
64 |
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,67 @@
|
|
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','
|
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'] == '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 +70,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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
58 |
}
|
|
|
59 |
?>
|
60 |
<style type="text/css">
|
61 |
<!--
|
@@ -70,6 +106,10 @@ padding: 10px 5px;
|
|
70 |
margin: 4px 0;
|
71 |
border: 1px solid #eee;
|
72 |
}
|
|
|
|
|
|
|
|
|
73 |
.floatright {
|
74 |
float: right;
|
75 |
}
|
@@ -83,16 +123,46 @@ 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>
|
@@ -161,7 +231,7 @@ For any update field, you can use the codes <code>#title#</code> for the title o
|
|
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" /> » <small>Don't have a Cli.gs account or Cligs API key? <a href=
|
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( 'twitterInitialised', '1' );
|
17 |
+
update_option( 'cligsapi','' );
|
18 |
+
update_option( 'jd_twit_pages','0' );
|
19 |
+
update_option( 'jd_functions_checked','0' );
|
20 |
+
update_option( 'wp_twitter_failure','0' );
|
21 |
+
update_option( 'wp_cligs_failure','0' );
|
22 |
$message = "Set your Twitter login information and Cli.gs API to use this plugin!";
|
23 |
}
|
|
|
24 |
|
25 |
+
if ( $_POST['submit-type'] == 'clear-error' ) {
|
26 |
+
update_option( 'wp_twitter_failure','0' );
|
27 |
+
update_option( 'wp_cligs_failure','0' );
|
28 |
+
$message = "WP to Twitter Errors Cleared";
|
29 |
+
}
|
30 |
+
if ( get_option( 'wp_twitter_failure' ) == '1' || get_option( 'wp_cligs_failure' ) == '1' ) {
|
31 |
+
if ( get_option( 'wp_cligs_failure' ) == '1' ) {
|
32 |
+
$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>";
|
33 |
+
}
|
34 |
+
if ( get_option( 'wp_twitter_failure' ) == '1' ) {
|
35 |
+
$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>";
|
36 |
+
}
|
37 |
+
} else {
|
38 |
+
$wp_to_twitter_failure = '';
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
if ( $_POST['submit-type'] == 'options' ) {
|
43 |
//UPDATE OPTIONS
|
44 |
+
update_option( 'newpost-published-update', $_POST['newpost-published-update'] );
|
45 |
+
update_option( 'newpost-published-text', $_POST['newpost-published-text'] );
|
46 |
+
update_option( 'newpost-published-showlink', $_POST['newpost-published-showlink'] );
|
47 |
+
|
48 |
+
update_option( 'oldpost-edited-update', $_POST['oldpost-edited-update'] );
|
49 |
+
update_option( 'oldpost-edited-text', $_POST['oldpost-edited-text'] );
|
50 |
+
update_option( 'oldpost-edited-showlink', $_POST['oldpost-edited-showlink'] );
|
51 |
+
update_option( 'jd_twit_pages',$_POST['jd_twit_pages'] );
|
52 |
$message = "WP to Twitter Options Updated";
|
53 |
|
54 |
+
}else if ( $_POST['submit-type'] == 'login' ){
|
55 |
//UPDATE LOGIN
|
56 |
+
if( ( $_POST['twitterlogin'] != '' ) AND ( $_POST['twitterpw'] != '' ) ) {
|
57 |
+
update_option( 'twitterlogin', $_POST['twitterlogin'] );
|
58 |
+
update_option( 'twitterlogin_encrypted', base64_encode( $_POST['twitterlogin'].':'.$_POST['twitterpw'] ) );
|
59 |
$message = "Twitter login and password updated.";
|
60 |
} else {
|
61 |
$message = "You need to provide your twitter login and password!";
|
62 |
}
|
63 |
+
} else if ( $_POST['submit-type'] == 'cligsapi' ) {
|
64 |
+
if ( $_POST['cligsapi'] != '' ) {
|
65 |
+
update_option( 'cligsapi',$_POST['cligsapi'] );
|
66 |
$message = "Cligs API Key Updated";
|
67 |
} else {
|
68 |
$message = "Cli.gs API Key not added - <a href='http://cli.gs/user/api/'>get one here</a>!";
|
70 |
}
|
71 |
|
72 |
// FUNCTION to see if checkboxes should be checked
|
73 |
+
function jd_checkCheckbox( $theFieldname ){
|
74 |
+
if( get_option( $theFieldname ) == '1'){
|
75 |
+
echo 'checked="true"';
|
76 |
+
}
|
77 |
+
}
|
78 |
+
// Check whether the server has supported for needed functions.
|
79 |
+
if ( get_option('jd-functions-checked') == '0') {
|
80 |
+
$wp_twitter_error = FALSE;
|
81 |
+
if ( !function_exists( 'fputs' ) ) {
|
82 |
+
$wp_twitter_error = TRUE;
|
83 |
+
$message = "Your server does not support <code>fputs</code>, the function used to send information to Twitter.";
|
84 |
+
}
|
85 |
+
if ( !function_exists( 'curl_init' ) && ( file_get_contents ( "http://www.joedolson.com/scripts/wp-to-twitter-check.txt" ) != 1 ) ) {
|
86 |
+
$wp_twitter_error = TRUE;
|
87 |
+
$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.";
|
88 |
+
}
|
89 |
+
// If everything's OK, there's no reason to do this again.
|
90 |
+
if ($wp_twitter_error == FALSE) {
|
91 |
+
update_option( 'jd-functions-checked','1' );
|
92 |
}
|
93 |
}
|
94 |
+
|
95 |
?>
|
96 |
<style type="text/css">
|
97 |
<!--
|
106 |
margin: 4px 0;
|
107 |
border: 1px solid #eee;
|
108 |
}
|
109 |
+
#wp-to-twitter form .error p {
|
110 |
+
background: none;
|
111 |
+
border: none;
|
112 |
+
}
|
113 |
.floatright {
|
114 |
float: right;
|
115 |
}
|
123 |
}
|
124 |
-->
|
125 |
</style>
|
126 |
+
<?php if ($wp_twitter_error == TRUE) {
|
127 |
+
echo "<div class='error'><p>This plugin will not work in your server environment.</p></div>";
|
128 |
+
}
|
129 |
+
if ( get_option( 'wp_twitter_failure' ) == '1' || get_option( 'wp_cligs_failure' ) == '1' ) {
|
130 |
+
echo $wp_to_twitter_failure;
|
131 |
+
}
|
132 |
+
?>
|
133 |
<?php if ($message) : ?>
|
134 |
<div id="message" class="updated fade"><p><?php echo $message; ?></p></div>
|
135 |
<?php endif; ?>
|
136 |
<div id="dropmessage" class="updated" style="display:none;"></div>
|
137 |
|
138 |
<div class="wrap" id="wp-to-twitter">
|
139 |
+
<?php if ( get_option( 'wp_twitter_failure' ) == '1' || get_option( 'wp_cligs_failure' ) == '1' ) { ?>
|
140 |
+
<form method="post">
|
141 |
+
<div class="error">
|
142 |
+
<div>
|
143 |
+
<input type="hidden" name="submit-type" value="clear-error">
|
144 |
+
</div>
|
145 |
+
<p><input type="submit" name="submit" value="Clear 'WP to Twitter' Error" /> <strong>Why are you seeing this field?</strong><br />
|
146 |
+
<?php if ( get_option( 'wp_twitter_failure' ) == '1' ) {
|
147 |
+
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.";
|
148 |
+
}
|
149 |
+
if ( get_option( 'wp_cligs_failure' ) == '1' ) {
|
150 |
+
echo "The query to the Cli.gs API failed, and your URL was not shrunk. The normal post URL was attached to your Tweet.";
|
151 |
+
}
|
152 |
+
?>
|
153 |
+
If you see these errors frequently, please <a href="http://www.joedolson.com/articles/wp-to-twitter/">notify the developer</a>.
|
154 |
+
</p>
|
155 |
+
</div>
|
156 |
+
</form>
|
157 |
+
<?php
|
158 |
+
}
|
159 |
+
?>
|
160 |
+
|
161 |
<h2>WP to Twitter Options</h2>
|
162 |
<p>
|
163 |
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.
|
164 |
</p>
|
165 |
+
|
166 |
<form method="post">
|
167 |
<div>
|
168 |
<fieldset>
|
231 |
<div>
|
232 |
<input type="hidden" name="submit-type" value="cligsapi">
|
233 |
</div>
|
234 |
+
<p><input type="submit" name="submit" value="Save Cli.gs API Key" /> » <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>
|
235 |
</div>
|
236 |
<div>
|
237 |
|
wp-to-twitter.php
CHANGED
@@ -1,235 +1,280 @@
|
|
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.
|
7 |
-
Author: Joseph Dolson
|
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 |
-
|
29 |
-
|
30 |
-
|
31 |
-
$
|
32 |
-
$
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
} else {
|
42 |
-
|
43 |
-
fputs( $fp, "
|
44 |
-
|
45 |
-
|
46 |
-
fputs( $fp, "
|
47 |
-
fputs( $fp, "
|
48 |
-
fputs( $fp, "
|
49 |
-
fputs( $fp,
|
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 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
}
|
188 |
-
//
|
189 |
-
|
190 |
-
|
191 |
-
if (
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
}
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 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.1.1
|
7 |
+
Author: Joseph Dolson
|
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 |
+
$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 |
+
$twitterURI = "/statuses/update.xml";
|
79 |
+
$thisposttitle = urlencode( stripcslashes( $_POST['post_title'] ) );
|
80 |
+
$thispostlink = get_permalink( $post_ID );
|
81 |
+
$thisblogtitle = urlencode( get_bloginfo( 'name' ) );
|
82 |
+
$cligsapi = get_option( 'cligsapi' );
|
83 |
+
$sentence = '';
|
84 |
+
$customTweet = stripcslashes( $_POST['jd_twitter'] );
|
85 |
+
$oldClig = get_post_meta( $post_ID, 'wp_jd_clig', TRUE );
|
86 |
+
|
87 |
+
if ( $_POST['publish'] == 'Publish' ){
|
88 |
+
// publish new post
|
89 |
+
if ( get_option( 'newpost-published-update' ) == '1' ) {
|
90 |
+
$sentence = get_option( 'newpost-published-text' );
|
91 |
+
if ( get_option( 'newpost-published-showlink') == '1' ) {
|
92 |
+
// Generate and grab the clig using the Cli.gs API
|
93 |
+
// cURL alternative contributed by Thor Erik (http://thorerik.net)
|
94 |
+
|
95 |
+
$shrink = @file_get_contents( "http://cli.gs/api/v1/cligs/create?url=".$thispostlink."&title=".$thisposttitle."&key=".$cligsapi."&appid=WP-to-Twitter" );
|
96 |
+
if ( $shrink === FALSE ) {
|
97 |
+
$shrink = getfilefromurl( "http://cli.gs/api/v1/cligs/create?url=".$thispostlink."&title=".$thisposttitle."&key=".$cligsapi."&appid=WP-to-Twitter" );
|
98 |
+
}
|
99 |
+
if ( $shrink === FALSE ) {
|
100 |
+
update_option('wp_cligs_failure','1');
|
101 |
+
$shrink = $thispostlink;
|
102 |
+
}
|
103 |
+
$sentence = $sentence . " " . $shrink;
|
104 |
+
|
105 |
+
if ( $customTweet != "" ) {
|
106 |
+
// Get the custom Tweet message if it's been supplied. Truncate it to fit if necessary.
|
107 |
+
if ( get_option( 'newpost-published-showlink') == '1' ) {
|
108 |
+
if ( ( strlen( $customTweet ) + 21) > 140 ) {
|
109 |
+
$customTweet = substr( $customTweet, 0, 119 );
|
110 |
+
}
|
111 |
+
} else {
|
112 |
+
if ( strlen( $customTweet ) > 140 ) {
|
113 |
+
$customTweet = substr( $customTweet, 0, 140 );
|
114 |
+
}
|
115 |
+
}
|
116 |
+
if ( get_option( 'newpost-published-showlink') == '1' ) {
|
117 |
+
$sentence = $customTweet . " " . $shrink;
|
118 |
+
} else {
|
119 |
+
$sentence = $customTweet;
|
120 |
+
}
|
121 |
+
} else {
|
122 |
+
// Check the length of the tweet and truncate parts as necessary.
|
123 |
+
$twit_length = strlen( $sentence );
|
124 |
+
$title_length = strlen( $thisposttitle );
|
125 |
+
$blog_length = strlen( $thisblogtitle );
|
126 |
+
if ( ( ( $twit_length + $title_length ) - 7 ) < 140 ) {
|
127 |
+
$sentence = str_replace( '#title#', $thisposttitle, $sentence );
|
128 |
+
$twit_length = strlen( $sentence );
|
129 |
+
} else {
|
130 |
+
$thisposttitle = substr( $thisposttitle, 0, ( 140- ( $twit_length-3 ) ) ) . "...";
|
131 |
+
$sentence = str_replace ( '#title#', $thisposttitle, $sentence );
|
132 |
+
$twit_length = strlen( $sentence );
|
133 |
+
}
|
134 |
+
if ( ( ( $twit_length + $blog_length ) - 6 ) < 140 ) {
|
135 |
+
$thisblogtitle = substr( $thisblogtitle, 0, ( 140-( $twit_length-3 ) ) ) . "...";
|
136 |
+
$sentence = str_replace ( '#blog#',$thisblogtitle,$sentence );
|
137 |
+
}
|
138 |
+
}
|
139 |
+
// Stores the posts CLIG in a custom field for later use as needed.
|
140 |
+
add_post_meta ( $post_ID, 'wp_jd_clig', $shrink );
|
141 |
+
/* This is for testing. Creates a post meta field containing the Cli.gs API request string
|
142 |
+
//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"); */
|
143 |
+
}
|
144 |
+
}
|
145 |
+
} else if ( ( $_POST['originalaction'] == "editpost" ) && ( $_POST['prev_status'] == 'publish' ) ) {
|
146 |
+
// if this is an old post and editing updates are enabled
|
147 |
+
if ( get_option( 'oldpost-edited-update') == '1' ) {
|
148 |
+
$sentence = get_option( 'oldpost-edited-text' );
|
149 |
+
if ( get_option( 'oldpost-edited-showlink') == '1') {
|
150 |
+
if ( $oldClig != '' ) {
|
151 |
+
$old_post_link = $oldClig;
|
152 |
+
} else {
|
153 |
+
$old_post_link = $thispostlink;
|
154 |
+
}
|
155 |
+
$thisposttitle = $thisposttitle . ' (' . $old_post_link . ')';
|
156 |
+
}
|
157 |
+
$sentence = str_replace( '#title#', $thisposttitle, $sentence );
|
158 |
+
$sentence = str_replace( '#blog#',$thisblogtitle,$sentence );
|
159 |
+
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
if ( $sentence != '' ) {
|
164 |
+
$sendToTwitter = jd_doTwitterAPIPost( 'source=wptotwitter&status='.$sentence, $twitterURI );
|
165 |
+
if ($sendToTwitter === FALSE) {
|
166 |
+
add_post_meta( $post_ID,'jd_wp_twitter',$sentence);
|
167 |
+
update_option('wp_twitter_failure','1');
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
return $post_ID;
|
172 |
+
}
|
173 |
+
|
174 |
+
// Add custom Tweet field on Post & Page write/edit forms
|
175 |
+
function jd_add_twitter_textinput() {
|
176 |
+
global $post;
|
177 |
+
$post_id = $post;
|
178 |
+
if (is_object($post_id)) {
|
179 |
+
$post_id = $post_id->ID;
|
180 |
+
}
|
181 |
+
$jd_twitter = htmlspecialchars(stripcslashes(get_post_meta($post_id, 'jd_twitter', true)));
|
182 |
+
?>
|
183 |
+
<script type="text/javascript">
|
184 |
+
<!-- Begin
|
185 |
+
function countChars(field,cntfield) {
|
186 |
+
cntfield.value = field.value.length;
|
187 |
+
}
|
188 |
+
// End -->
|
189 |
+
</script>
|
190 |
+
<?php /* Compatibility with version 2.3 and below (needs to be tested.) */ ?>
|
191 |
+
<?php if (substr(get_bloginfo('version'), 0, 3) >= '2.5') { ?>
|
192 |
+
<div id="wp-to-twitter" class="postbox closed">
|
193 |
+
<h3><?php _e('WP to Twitter', 'wp-to-twitter') ?></h3>
|
194 |
+
<div class="inside">
|
195 |
+
<div id="jd-twitter">
|
196 |
+
<?php } else { ?>
|
197 |
+
<div class="dbx-b-ox-wrapper">
|
198 |
+
<fieldset id="twitdiv" class="dbx-box">
|
199 |
+
<div class="dbx-h-andle-wrapper">
|
200 |
+
<h3 class="dbx-handle"><?php _e('WP to Twitter', 'wp-to-twitter') ?></h3>
|
201 |
+
</div>
|
202 |
+
<div class="dbx-c-ontent-wrapper">
|
203 |
+
<div class="dbx-content">
|
204 |
+
<?php } ?>
|
205 |
+
|
206 |
+
<input value="jd_twit_edit" type="hidden" name="jd_twit_edit" />
|
207 |
+
|
208 |
+
<label for="jd_twitter"><?php _e('Twitter Post', 'wp-to-twitter') ?></label><br /><textarea name="jd_twitter" id="jd_twitter" rows="2" cols="60"
|
209 |
+
onKeyDown="countChars(document.post.jd_twitter,document.post.twitlength)"
|
210 |
+
onKeyUp="countChars(document.post.jd_twitter,document.post.twitlength)"><?php echo $jd_twitter ?></textarea>
|
211 |
+
<p><input readonly type="text" name="twitlength" size="3" maxlength="3" value="<?php echo strlen( $description); ?>" />
|
212 |
+
<?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> »
|
213 |
+
</p>
|
214 |
+
<?php if (substr(get_bloginfo('version'), 0, 3) >= '2.5') { ?>
|
215 |
+
</div></div></div>
|
216 |
+
<?php } else { ?>
|
217 |
+
</div>
|
218 |
+
</fieldset>
|
219 |
+
</div>
|
220 |
+
<?php } ?>
|
221 |
+
|
222 |
+
<?php
|
223 |
+
}
|
224 |
+
// Post the Custom Tweet into the post meta table
|
225 |
+
function post_jd_twitter( $id ) {
|
226 |
+
$jd_twit_edit = $_POST["jd_twit_edit"];
|
227 |
+
if (isset($jd_twit_edit) && !empty($jd_twit_edit)) {
|
228 |
+
$jd_twitter = $_POST["jd_twitter"];
|
229 |
+
delete_post_meta( $id, 'jd_twitter' );
|
230 |
+
if (isset($jd_twitter) && !empty($jd_twitter)) {
|
231 |
+
add_post_meta( $id, 'jd_twitter', $jd_twitter );
|
232 |
+
}
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
// Add the administrative settings to the "Settings" menu.
|
237 |
+
function jd_addTwitterAdminPages() {
|
238 |
+
if ( function_exists( 'add_submenu_page' ) ) {
|
239 |
+
add_options_page( 'WP -> Twitter', 'WP -> Twitter', 8, __FILE__, 'jd_wp_Twitter_manage_page' );
|
240 |
+
}
|
241 |
+
}
|
242 |
+
// Include the Manager page
|
243 |
+
function jd_wp_Twitter_manage_page() {
|
244 |
+
include(dirname(__FILE__).'/wp-to-twitter-manager.php' );
|
245 |
+
}
|
246 |
+
function plugin_action($links, $file) {
|
247 |
+
if ($file == plugin_basename(dirname(__FILE__).'/wp-to-twitter.php'))
|
248 |
+
$links[] = "<a href='options-general.php?page=wp-to-twitter/wp-to-twitter-manager.php'>" . __('Settings', 'wp-to-twitter') . "</a>";
|
249 |
+
return $links;
|
250 |
+
}
|
251 |
+
|
252 |
+
//Add Plugin Actions to WordPress
|
253 |
+
|
254 |
+
add_filter('plugin_action_links', 'plugin_action', -10, 2);
|
255 |
+
|
256 |
+
if ( substr( get_bloginfo( 'version' ), 0, 3 ) >= '2.5' ) {
|
257 |
+
add_action( 'edit_form_advanced','jd_add_twitter_textinput' );
|
258 |
+
if ( get_option( 'jd_twit_pages')=='1') {
|
259 |
+
add_action( 'edit_page_form','jd_add_twitter_textinput' );
|
260 |
+
}
|
261 |
+
} else {
|
262 |
+
add_action( 'dbx_post_advanced','jd_add_twitter_textinput' );
|
263 |
+
if (get_option( 'jd_twit_pages')=='1') {
|
264 |
+
add_action( 'dbx_page_advanced','jd_add_twitter_textinput' );
|
265 |
+
}
|
266 |
+
}
|
267 |
+
if ( get_option( 'wp_twitter_failure' ) == '1' || get_option( 'wp_cligs_failure' ) == '1' ) {
|
268 |
+
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>';" ) );
|
269 |
+
}
|
270 |
+
|
271 |
+
if ( get_option( 'jd_twit_pages')=='1') {
|
272 |
+
add_action( 'publish_page', 'jd_twit' );
|
273 |
+
add_action( 'edit_page','post_jd_twitter' );
|
274 |
+
add_action( 'publish_page','post_jd_twitter' );
|
275 |
+
}
|
276 |
+
add_action( 'publish_post', 'jd_twit' );
|
277 |
+
add_action( 'admin_menu', 'jd_addTwitterAdminPages' );
|
278 |
+
add_action( 'edit_post','post_jd_twitter' );
|
279 |
+
add_action( 'publish_post','post_jd_twitter' );
|
280 |
?>
|