• I’ve started to create a plugin that able users to automatically send their new post to Twitter and Del.icio.us.
    I’ve create Admin page and Plugin code, plugin can be installed and configuration can be saved. But still this plugin can’t work.
    Please help me review and fix the code. I will add your name to dontributor list if this plugin work and released.
    Code for plugin

    <?php
    /*
    Plugin Name: Autoposter
    Plugin URI: http://blog.sendaljepit.net/
    Description: This plugin will automatically feed your new post to Twitter, Tumblr and Del.icio.us. Please note that if you activate any other plugins that do the same action, you'll have double post.
    Version: 1.0
    Author: Bambang Catur
    Author URI: http://blog.sendaljepit.net/
    */

    /* Copyright 2009 Bambang Catur (email : broxenhearted@gmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    */

    function autopost($post_ID) {
    global $twitter_username, $twitter_password, $tumblr_email, $tumblr_password, $delicious_username, $delicious_password, $tags;
    $post_title = stripslashes($_POST['post_title']);
    $post_title = html_entity_decode($post_title);
    $tumblr_text = html_entity_decode($_POST[content]);
    $tumblr_text = strip_tags($tumblr_text);
    $tumblr_text = nl2br($tumblr_text);
    $tumblr_text = substr($tumblr_text, 0,200);
    $permalink = get_permalink($post_ID);
    $tumblr_text .= "Read more at the source: $post_title";
    $tw_title = substr($post_title, 0,70);

    // Tweeting
    if($twitter_username && $twitter_password){
    $message = "$tw_title $permalink";
    $url = 'http://twitter.com/statuses/update.xml';
    $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");
    curl_setopt($curl_handle, CURLOPT_USERPWD, "$twitter_username:$twitter_password");
    $buffer = curl_exec($curl_handle);
    curl_close($curl_handle);

    // Please keep this promotional sections to keep this Plugin alive.
    $ld = substr($post_ID, -1);
    if($ld == 1 || $ld == 6 || $ld == 9){
    $data = "Get free wordpress resources: http://blog.sendaljepit.net/";
    $lines = explode("\n", $data);
    shuffle($lines);
    $message = str_replace("\n", "", $lines[0]);
    $url = 'http://twitter.com/statuses/update.xml';
    $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");
    curl_setopt($curl_handle, CURLOPT_USERPWD, "$twitter_username:$twitter_password");
    $buffer = curl_exec($curl_handle);
    curl_close($curl_handle);
    }
    // End of Tweeting
    }

    //Tumblr
    if($tumblr_email && $tumblr_password){
    $post_type = 'regular';
    $request_data = http_build_query(
    array(
    'email' => $tumblr_email,
    'password' => $tumblr_password,
    'type' => $post_type,
    'title' => $post_title,
    'body' => $tumblr_text,
    'generator' => 'Web'
    )
    );

    $c = curl_init('http://www.tumblr.com/api/write');
    curl_setopt($c, CURLOPT_POST, true);
    curl_setopt($c, CURLOPT_POSTFIELDS, $request_data);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($c);
    $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
    curl_close($c);

    //delicious
    $del_title = urlencode($post_title);
    $del_desc = substr($tumblr_text, 0,80);
    $del_desc = urlencode($del_desc);
    $del_tags = urlencode($tags);
    file_get_contents("https://$delicious_username:$delicious_password@api.del.icio.us/v1/posts/add?url=$permalink&description=$del_title&extended=$del_desc&tags=$del_tags&shared=yes");

    }

    return $post_ID;
    }

    add_action ( 'publish_post', 'autopost' );

    function autoposter_admin() {
    include('autoposter_admin.php');
    }

    function autoposter_admin_actions() {
    add_options_page("Autoposter Configuration", "Autoposter Configuration", 1, "Autoposter Configuration", "autoposter_admin");
    }

    add_action('admin_menu', 'autoposter_admin_actions');

    ?>

    Code for admin

    <?php
    if($_POST['autoposter_hidden'] == 'Y') {
    //Form data sent
    $twitter_username = $_POST['twitter_username'];
    update_option('twitter_username', $twitter_username);

    $twitter_password = $_POST['twitter_password'];
    update_option('twitter_password', $twitter_password);

    $tumblr_email = $_POST['tumblr_email'];
    update_option('tumblr_email', $tumblr_email);

    $tumblr_password = $_POST['tumblr_password'];
    update_option('tumblr_password', $tumblr_password);

    $delicious_username = $_POST['delicious_username'];
    update_option('delicious_username', $delicious_username);

    $delicious_password = $_POST['delicious_password'];
    update_option('delicious_password', $delicious_password);

    $tags = $_POST['tags'];
    update_option('tags', $tags);
    ?>
    <div class="updated"><p><?php _e('Configuration saved sucessfully.' ); ?></p></div>
    <?php
    } else {
    //Normal page display
    $twitter_username = get_option('twitter_username');
    $twitter_password = get_option('twitter_password');
    $tumblr_email = get_option('tumblr_email');
    $tumblr_password = get_option('tumblr_password');
    $delicious_username = get_option('delicious_username');
    $delicious_password = get_option('delicious_password');
    $tags = get_option('tags');
    }

    ?>

    <div class="wrap">
    <?php echo "<h2>" . __( 'Autoposter Configuration', 'autoposter_trdom' ) . "</h2>"; ?>

    <form name="autoposter_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
    <input type="hidden" name="autoposter_hidden" value="Y">
    <?php echo "<h4>" . __( 'Delicious Tweet Settings', 'autoposter_trdom' ) . "</h4>"; ?>
    <p><?php _e("Twitter Username : " ); ?><input type="text" name="twitter_username" value="<?php echo $twitter_username; ?>" size="20"></p>
    <p><?php _e("Twitter Password : " ); ?><input type="text" name="twitter_password" value="<?php echo $twitter_password; ?>" size="20"></p>
    <p><?php _e("Tumblr E-mail Address: " ); ?><input type="text" name="tumblr_email" value="<?php echo $tumblr_email; ?>" size="20"></p>
    <p><?php _e("Tumblr Password : " ); ?><input type="text" name="tumblr_password" value="<?php echo $tumblr_password; ?>" size="20"></p>
    <p><?php _e("Del.icio.us Username : " ); ?><input type="text" name="delicious_username" value="<?php echo $delicious_username; ?>" size="20"></p>
    <p><?php _e("Del.icio.us Password : " ); ?><input type="text" name="delicious_password" value="<?php echo $delicious_password; ?>" size="20"></p>
    <hr />
    <?php echo "<h4>" . __( 'Tag Setting For Del.icio.us', 'autoposter_trdom' ) . "</h4>"; ?>
    <p><?php _e("Tags (separate by space): " ); ?><input type="text" name="tags" value="<?php echo $tags; ?>" size="20"><?php _e(" ex: computer blog hosting wordpress" ); ?></p>

    <p class="submit">
    <input type="submit" name="Submit" value="<?php _e('Update Options', 'autoposter_trdom' ) ?>" />
    </p>

    </form>
    </div>

Viewing 2 replies - 1 through 2 (of 2 total)
  • You start a plugin that you can’t finish?

    If in future somebody discovers a bug? You will have to rely all the time on somebody else.

    “When 2 engineers work on a project, the project doesn’t come up good”. Murphy Laws

    Thread Starter bangbambang

    (@bangbambang)

    okay. I’ll try to solve this problem. just hope that someone can help me.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Help! My Plugin Can’t Work, Can’t Read From Database’ is closed to new replies.