現在、マイクロブログは Twitter をメインに呟いていますが、なんだか今日あたり、Wassr への流れができていたので、アカウント作ってみました。
WordPress から Twitter への更新通知のポストは、Twitpress で行えていますが、Wassr も API が公開されているので、これを改造して対応できないかといじってみたらできたみたいなので、パッチを置いておきます。
適当にやったので関数名とかDB名の頭が大文字になっちゃってますが、気持ち悪いようなら適宜小文字に変更するなどして下さい。というか、置換で大文字小文字区別しなかったせいですががが。
ちょっと長くなったので、続きを読むの後に置いておきます。素人が適当にいじったせいで動作保証も何もあったものではないので、書き換えた場所だけチェックして自力で改造するのが良いと思います(^^;
一応、動くことは確認してありますが、ご利用の際は注意してください。
Wassbacker
Wassbacker を使えば、ブログツールから Ping を送信するだけで通知できるので、こちらのサービスにパスワード等を預けることを許容できるなら、こちらを利用するのも良いかもしれません。
--- twitpress.php 2008-07-03 21:17:32.000000000 +0900
+++ wassrpress.php 2008-07-03 21:36:15.000000000 +0900
@@ -1,8 +1,8 @@
<?php
/*
-Plugin Name: Twitpress
+Plugin Name: Wassrpress
Plugin URI: http://www.thomaspurnell.com/twitpress/
-Description: Announces new posts on twitter
+Description: Announces new posts on Wassr
Version: 0.3.2
Author: Tom Purnell
Author URI: http://www.thomaspurnell.com
@@ -26,40 +26,40 @@
*/
//Hooks and wordpress options
-register_activation_hook( __FILE__, 'twitpress_install' );
-add_action( 'delete_post', 'twitpress_db_delete_post' );
-add_action( 'admin_menu', 'twitpress_add_menu' );
-add_action( 'wp_insert_post', 'twitpress_run' );
-add_option( 'twitpress_uid', '', 'Twitter user name', 'yes' );
-add_option( 'twitpress_password', '', 'Twitter password', 'yes' );
-add_option( 'twitpress_message', 'New blog entry: [title] [permalink]', 'Twitpress message format', 'yes' );
+register_activation_hook( __FILE__, 'Wassrpress_install' );
+add_action( 'delete_post', 'Wassrpress_db_delete_post' );
+add_action( 'admin_menu', 'Wassrpress_add_menu' );
+add_action( 'wp_insert_post', 'Wassrpress_run' );
+add_option( 'Wassrpress_uid', '', 'Wassrr user name', 'yes' );
+add_option( 'Wassrpress_password', '', 'Wassr password', 'yes' );
+add_option( 'Wassrpress_message', 'New blog entry: [title] [permalink]', 'Wassrpress message format', 'yes' );
//Runs when a post record is inserted into the database
-function twitpress_run( $postID ) {
+function Wassrpress_run( $postID ) {
//get the post
$post = get_post( $postID );
//we only want to do anything if the post was not previously twittered
- if ( !twitpress_was_twittered( $postID ) ){
+ if ( !Wassrpress_was_wassrered( $postID ) ){
//Update the post to reflect it's current status
- twitpress_db_update_post( $postID, $post->post_status );
+ Wassrpress_db_update_post( $postID, $post->post_status );
}
//process the posts, including twittering newly published posts
- twitpress_process_posts();
+ Wassrpress_process_posts();
}
-//Install the twitpress database
-function twitpress_install() {
+//Install the Wassrpress database
+function Wassrpress_install() {
global $wpdb;
- $table_name = "twitpress";
+ $table_name = "Wassrpress";
- twitpress_db_drop_table();
+ Wassrpress_db_drop_table();
if( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) != $table_name ) {
$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL,
- status enum( 'publish', 'draft', 'private', 'static', 'object', 'attachment', 'inherit', 'future', 'twittered' ) NOT NULL,
+ status enum( 'publish', 'draft', 'private', 'static', 'object', 'attachment', 'inherit', 'future', 'wassrered' ) NOT NULL,
UNIQUE KEY id (id)
);";
@@ -70,7 +70,7 @@
dbDelta( $sql );
- add_option( "twitpress_db_version", "0.3.2" );
+ add_option( "Wassrpress_db_version", "0.3.2" );
}
//Populate table to avoid twittering previously published posts when they are edited
@@ -78,17 +78,17 @@
$posts = $wpdb->get_results( $sql, OBJECT );
foreach ($posts as $post){
if ( $post->post_status == "publish" ){
- twitpress_db_update_post( $post->ID, "twittered" );
+ Wassrpress_db_update_post( $post->ID, "wassrered" );
} else {
- twitpress_db_update_post( $post->ID, $post->post_status );
+ Wassrpress_db_update_post( $post->ID, $post->post_status );
}
}
}
-//Delete twitpress table
-function twitpress_db_drop_table() {
+//Delete Wassrpress table
+function Wassrpress_db_drop_table() {
global $wpdb;
- $table_name = "twitpress";
+ $table_name = "Wassrpress";
if( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) != $table_name ) {
$sql = "DROP TABLE " . $table_name;
}
@@ -101,13 +101,13 @@
dbDelta( $sql );
}
-//Add / update a twitpress record of a post
-function twitpress_db_update_post( $postID, $status ){
+//Add / update a Wassrpress record of a post
+function Wassrpress_db_update_post( $postID, $status ){
global $wpdb;
- $table_name = "twitpress";
+ $table_name = "Wassrpress";
//delete any old record of this entry (could use update instead)
- twitpress_db_delete_post( $postID );
+ Wassrpress_db_delete_post( $postID );
//insert the new version of the record
$query = "INSERT INTO " . $table_name .
@@ -118,9 +118,9 @@
}
//Get a wordpress post status
-function twitpress_db_get_post_status( $postID ){
+function Wassrpress_db_get_post_status( $postID ){
global $wpdb;
- $table_name = "twitpress";
+ $table_name = "Wassrpress";
//find post by id
$query = "SELECT id, status from " . $wpdb->posts .
@@ -129,65 +129,65 @@
}
//Check if a post was previously twittered
-function twitpress_was_twittered( $postID ){
+function Wassrpress_was_wassrered( $postID ){
global $wpdb;
- $table_name = "twitpress";
+ $table_name = "Wassrpress";
$query = "SELECT id, status from " . $table_name .
" WHERE id = " . $wpdb->escape( $postID );
- return $wpdb->get_var( $query, 1 ) == 'twittered';
+ return $wpdb->get_var( $query, 1 ) == 'wassrered';
}
-//Delete a twitpress post status (n.b this doesnt delete any wordpress posts :) )
-function twitpress_db_delete_post( $postID ){
+//Delete a Wassrpress post status (n.b this doesnt delete any wordpress posts :) )
+function Wassrpress_db_delete_post( $postID ){
global $wpdb;
- $table_name = "twitpress";
+ $table_name = "Wassrpress";
$query = "DELETE FROM " . $table_name .
" WHERE id like " . $wpdb->escape( $postID );
return $wpdb->query( $query );
}
-//Process posts currently stored in the twitpress database table
-function twitpress_process_posts() {
+//Process posts currently stored in the Wassrpress database table
+function Wassrpress_process_posts() {
global $wpdb;
- $table_name = "twitpress";
+ $table_name = "Wassrpress";
$query = "SELECT * FROM " . $table_name;
//get the currently stored posts
$tp_rows = $wpdb->get_results( $query, ARRAY_A );
- //for each entry in the twitpress table
+ //for each entry in the Wassrpress table
foreach( $tp_rows as $row ){
$tp_wp_status = $row["status"];
//if the entry has been published, we can publish to twitter and mark
//that this post has been twittered
if ( $tp_wp_status == "publish" ){
- twitpress_publish( $row["id"] );
- twitpress_db_update_post( $row["id"], 'twittered' );
+ Wassrpress_publish( $row["id"] );
+ Wassrpress_db_update_post( $row["id"], 'wassrered' );
}
}
}
-//Add the twitpress menu to the management page
-function twitpress_add_menu() {
- add_management_page( 'Twitpress', 'Twitpress', 8, 'twitpressoptions', 'twitpress_options_page' );
+//Add the Wassrpress menu to the management page
+function Wassrpress_add_menu() {
+ add_management_page( 'Wassrpress', 'Wassrpress', 8, 'Wassrpressoptions', 'Wassrpress_options_page' );
}
//Options page code and html
-function twitpress_options_page() {
+function Wassrpress_options_page() {
global $wpdb;
- $table_name = "twitpress";
- $username = get_option( 'twitpress_uid' );
- $password = get_option( 'twitpress_password' );
- $message = get_option( 'twitpress_message' );
- $submitFieldID = 'twitpress_submit_hidden';
+ $table_name = "Wassrpress";
+ $username = get_option( 'Wassrpress_uid' );
+ $password = get_option( 'Wassrpress_password' );
+ $message = get_option( 'Wassrpress_message' );
+ $submitFieldID = 'Wassrpress_submit_hidden';
if ( $_POST[ $submitFieldID ] == 'Y' ) {
- update_option( 'twitpress_uid', $_POST[ 'twitpress_form_username' ] );
- update_option( 'twitpress_password', str_rot13($_POST[ 'twitpress_form_password' ]) );
- update_option( 'twitpress_message', $_POST[ 'twitpress_form_message' ] );
+ update_option( 'Wassrpress_uid', $_POST[ 'Wassrpress_form_username' ] );
+ update_option( 'Wassrpress_password', str_rot13($_POST[ 'Wassrpress_form_password' ]) );
+ update_option( 'Wassrpress_message', $_POST[ 'Wassrpress_form_message' ] );
?>
<div class="updated"><p><strong><?php _e('Options saved.', 'mt_trans_domain' ); ?></strong></p></div>
<?php
@@ -195,28 +195,28 @@
}
echo '<div class="wrap">';
- echo "<h2>" . __( 'Twitpress Plugin Options', 'mt_trans_domain' ) . "</h2>"; ?>
+ echo "<h2>" . __( 'Wassrpress Plugin Options', 'mt_trans_domain' ) . "</h2>"; ?>
- <form name="twitpress_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI'] ); ?>">
- <input type="hidden" name="twitpress_submit_hidden" value="Y" />
+ <form name="Wassrpress_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI'] ); ?>">
+ <input type="hidden" name="Wassrpress_submit_hidden" value="Y" />
<p><h3>Username</h3><input type="text"
-name="twitpress_form_username" value="<?php echo ( get_option ( 'twitpress_uid' ) ); ?>" /></p>
+name="Wassrpress_form_username" value="<?php echo ( get_option ( 'Wassrpress_uid' ) ); ?>" /></p>
<p><h3>Password</h3><input type="password"
-name="twitpress_form_password" value="<?php echo str_rot13( get_option( 'twitpress_password' ) ); ?>" /></p>
+name="Wassrpress_form_password" value="<?php echo str_rot13( get_option( 'Wassrpress_password' ) ); ?>" /></p>
<p><h3>Message format</h3><textarea
-name="twitpress_form_message" /><?php echo (get_option('twitpress_message')); ?></textarea></p>
+name="Wassrpress_form_message" /><?php echo (get_option('Wassrpress_message')); ?></textarea></p>
<p class="submit"><input type="submit" name="Submit"
value="<?php _e( 'Update Options', 'mt_trans_domain' ) ?>" /></p>
<p>The following message format tags are supported:
<ul>
<li><strong>[title]</strong> is replaced with the post title</li>
-<li><strong>[permalink]</strong> is replaced with the post's permalink using your permalink format <em>(domain.com/index.php?/twitpress)</em></li>
+<li><strong>[permalink]</strong> is replaced with the post's permalink using your permalink format <em>(domain.com/index.php?/Wassrpress)</em></li>
<li><strong>[link]</strong> is replaced with a default style link to the post (depreciated, not recommended) <em>(domain.com/index.php?p=1)</em></li>
</ul>
</p>
</form><!--[Coming Soon]
<hr />
- <p>Twitpress stores it's data in a table ( '<? echo $table_name ?>' on this wordpress installation ) in your wordpress database. If you want to delete this table (and cause twitpress to stop working in the process, click here. There is no undo. You will need to deactivate and then activate twitpress again, regenerating this table, before twitpress will work again.</p>
+ <p>Wassrpress stores it's data in a table ( '<? echo $table_name ?>' on this wordpress installation ) in your wordpress database. If you want to delete this table (and cause Wassrpress to stop working in the process, click here. There is no undo. You will need to deactivate and then activate Wassrpress again, regenerating this table, before Wassrpress will work again.</p>
<form action=" <? echo __FILE__ ?> ">
<p class="submit"><input type="submit" value="Drop table" /></p>
</form>
@@ -229,21 +229,21 @@
}
//Publishes a tweet given only the postID
-function twitpress_publish( $postID ){
+function Wassrpress_publish( $postID ){
//get the post
$post = get_post( $postID );
//Now redundant check to make sure the post has been published
if ( $post->post_status == "publish" ){
- $message = twitpress_get_message( $postID );
- twitpress_postMessage( get_option( 'twitpress_uid' ), get_option( 'twitpress_password' ), $message );
+ $message = Wassrpress_get_message( $postID );
+ Wassrpress_postMessage( get_option( 'Wassrpress_uid' ), get_option( 'Wassrpress_password' ), $message );
}
}
//Converts a wordpress post into a string with user formatting for twitter posting
-function twitpress_get_message( $postID ){
- $proto = get_option( 'twitpress_message' );
+function Wassrpress_get_message( $postID ){
+ $proto = get_option( 'Wassrpress_message' );
$post = get_post( $postID );
$proto = str_replace( "[title]", $post->post_title, $proto );
$proto = str_replace( "[permalink]", $post->guid, $proto );
@@ -252,15 +252,15 @@
}
//Standard curl function, handles actual submission of message to twitter
-function twitpress_postMessage( $twitter_username, $twitter_password, $message ){
- $url = 'http://twitter.com/statuses/update.xml';
+function Wassrpress_postMessage( $wassr_username, $wassr_password, $message ){
+ $url = 'http://api.wassr.jp/statuses/update.json';
$curl_handle = curl_init();
curl_setopt( $curl_handle, CURLOPT_URL, "$url" );
curl_setopt( $curl_handle, CURLOPT_CONNECTTIMEOUT, 2 );
curl_setopt( $curl_handle, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl_handle, CURLOPT_POST, 1 );
- curl_setopt( $curl_handle, CURLOPT_POSTFIELDS, "status=$message&source=twitpress" );
- curl_setopt( $curl_handle, CURLOPT_USERPWD, "$twitter_username:".str_rot13( $twitter_password ) );
+ curl_setopt( $curl_handle, CURLOPT_POSTFIELDS, "status=$message&source=Wassrpress" );
+ curl_setopt( $curl_handle, CURLOPT_USERPWD, "$wassr_username:".str_rot13( $wassr_password ) );
$buffer = curl_exec( $curl_handle );
curl_close( $curl_handle );
}





2 Trackbacks to Twitpress を改造して Wassrpress (仮)にする
[...] from : 「Twitpress を改造して Wassrpress (仮)にする」) ■Oepra 9.51 リリース Opera today added Ask.com, a leading search engine, to the latest [...]
Wassrpress…
èªæ¸ãã³ã®æ¹ã§å ¥ãããWordPressãã©ã°ã¤ã³ã®Wassrpressãã¡ããã¨åãã¦ããããã ã
ããè¦ãã¨ããã¼ããªã³ã¯ãã¡ãã£ã¨ä¸å®å®ããªã
Wassrpressã¯ãããã°ã®æ´æ°ãWassrã«æç¨¿ãããã©ã°ã¤…
0 Responses to Twitpress を改造して Wassrpress (仮)にする