Adding a custom bit of text to PHP Twitter code -


i using code below, bulked in "keyring social importer" plugin wordpress, import tweets on regular basis individual blog posts in wordpress blog.

i add line of text within each created blog post, after tweet, says "follow me on twitter" link twitter page. how achieve this?

so, posts this... title of post = tweet 15 word limit , "..." after it. content = tweet in full. after tweet in full within content, want follow link.

many in advance can offer.

ht

<?php  function keyring_twitter_importer() {  class keyring_twitter_importer extends keyring_importer_base {     const slug              = 'twitter';    // e.g. 'twitter' (should match service in keyring)     const label             = 'twitter';    // e.g. 'twitter'     const keyring_service   = 'keyring_service_twitter';    // full class name of keyring_service importer requires     const requests_per_load = 3;     // how many remote requests should made before reloading page?      var $auto_import = false;      function __construct() {         parent::__construct();         add_action( 'keyring_importer_twitter_custom_options', array( $this, 'custom_options' ) );     }      function custom_options() {         ?><tr valign="top">             <th scope="row">                 <label for="include_rts"><?php _e( 'import retweets', 'keyring' ); ?></label>             </th>             <td>                 <input type="checkbox" value="1" name="include_rts" id="include_rts"<?php echo checked( $this->get_option( 'include_rts', true ) ); ?> />             </td>         </tr>         <tr valign="top">             <th scope="row">                 <label for="include_replies"><?php _e( 'import @replies', 'keyring' ); ?></label>             </th>             <td>                 <input type="checkbox" value="1" name="include_replies" id="include_replies"<?php echo checked( $this->get_option( 'include_replies', true ) ); ?> />             </td>         </tr><?php     }      function handle_request_options() {         // validate options , store them can used in auto-imports         if ( empty( $_post['category'] ) || !ctype_digit( $_post['category'] ) )             $this->error( __( "make sure select valid category import checkins into." ) );          if ( empty( $_post['author'] ) || !ctype_digit( $_post['author'] ) )             $this->error( __( "you must select author assign checkins." ) );          if ( isset( $_post['auto_import'] ) )             $_post['auto_import'] = true;         else             $_post['auto_import'] = false;          if ( isset( $_post['include_rts'] ) )             $_post['include_rts'] = true;         else             $_post['include_rts'] = false;          if ( isset( $_post['include_replies'] ) )             $_post['include_replies'] = true;         else             $_post['include_replies'] = false;          // if there errors, output them, otherwise store options , start importing         if ( count( $this->errors ) ) {             $this->step = 'greet';         } else {             $this->set_option( array(                 'category'        => (int) $_post['category'],                 'tags'            => explode( ',', $_post['tags'] ),                 'author'          => (int) $_post['author'],                 'include_replies' => (bool) $_post['include_replies'],                 'include_rts'     => (bool) $_post['include_rts'],                 'auto_import'     => (bool) $_post['auto_import'],                 'user_id'         => $this->service->get_token()->get_meta( 'user_id' ),             ) );              $this->step = 'import';         }     }      function build_request_url() {         // base request url         $url = "http://api.twitter.com/1/statuses/user_timeline.json?";         $params = array(             'user_id' => $this->get_option( 'user_id' ),             'trim_user' => 'true',             'count' => 75, // more , twitter seems flaky             'include_entities' => 'true',         );         if ( false == $this->get_option( 'include_replies' ) )             $params['exclude_replies'] = 'true';         if ( true == $this->get_option( 'include_rts' ) )             $params['include_rts'] = 'true';         $url = $url . http_build_query( $params );           if ( $this->auto_import ) {             // locate our imported tweet, , ones since             $latest = get_posts( array(                 'numberposts' => 1,                 'orderby' => 'date',                 'order' => 'desc',                 'meta_key'    => 'keyring_service', // in case there other asides                 'meta_value'  => 'twitter',                 'tax_query' => array( array(                     'taxonomy' => 'post_format',                     'field' => 'slug',                     'terms' => array( 'post-format-standard' ), // tweets stored asides                     'operator' => 'in',                 ) ),             ) );              // if have imported some, start since recent             if ( $latest ) {                 $max = get_post_meta( $latest[0]->id, 'twitter_id', true );                 $url = add_query_arg( 'since_id', $max, $url );             }         } else {             // handle page offsets (only non-auto-import requests)             $url = add_query_arg( 'page', $this->get_option( 'page', 0 ), $url );         }          return $url;     }      function extract_posts_from_data( $raw ) {         global $wpdb;          $importdata = $raw;          if ( null === $importdata ) {             $this->finished = true;             return new keyring_error( 'keyring-twitter-importer-failed-download', __( 'failed download tweets twitter. please wait few minutes , try again.', 'keyring' ) );         }          // check api overage/errors         if ( !empty( $importdata->error ) ) {             $this->finished = true;             return new keyring_error( 'keyring-twitter-importer-throttled', __( 'you have made many requests twitter , have been temporarily blocked. please try again in 1 hour (duplicate tweets skipped).', 'keyring' ) );         }          // make sure have tweets parse         if ( !is_array( $importdata ) || !count( $importdata ) ) {             $this->finished = true;             return;         }          // total number of tweets we're importing         if ( !empty( $importdata[0]->user->statuses_count ) )             $this->set_option( 'total', $importdata[0]->user->statuses_count );          // parse/convert wp post structs         foreach ( $importdata $post ) {             // double-check @replies, shouldn't included @ if chose skip them             if ( true == $this->get_option( 'exclude_replies' ) && null != $post->in_reply_to_screen_name )                 continue;              // post title can empty asides, makes them easier manage if have *something*             $title_words = explode( ' ', strip_tags( $post->text ) );             $post_title  = implode( ' ', array_slice( $title_words, 0, 15 ) ); // use first 15 words             if ( count( $title_words ) > 15 )                 $post_title .= '&hellip;';                // parse/adjust dates             $post_date_gmt = strtotime( $post->created_at );             $post_date_gmt = gmdate( 'y-m-d h:i:s', $post_date_gmt );             $post_date     = get_date_from_gmt( $post_date_gmt );              // apply selected category             $post_category = array( $this->get_option( 'category' ) );              // clean content bit             $post_content = $post->text;             $post_content = $wpdb->escape( html_entity_decode( trim( $post_content ) ) );              // handle entities supplied twitter             if ( count( $post->entities->urls ) ) {                 foreach ( $post->entities->urls $url ) {                     $post_content = str_replace( $url->url, $url->expanded_url, $post_content );                 }             }              // hashtags used in tweet applied post tags in wp             $tags = $this->get_option( 'tags' );             if ( preg_match_all( '/(^|[(\[\s])#(\w+)/', $post_content, $tag ) )                 $tags = array_merge( $tags, $tag[2] );              // add html links urls, usernames , hashtags             $post_content = make_clickable( esc_html( $post_content ) );              // include geo data (if provided twitter)             if ( !empty( $post->geo ) && 'point' == strtolower( $post->geo->type ) )                 $geo = array(                     'lat' => $post->geo->coordinates[0],                     'long' => $post->geo->coordinates[1]                 );             else                 $geo = array();              // guid twitter, plus other important ids store in postmeta later             $user = $this->service->get_token()->get_meta( 'username' );             $twitter_id              = $post->id_str;             $twitter_permalink       = "https://twitter.com/{$user}/status/{$twitter_id}";             $in_reply_to_user_id     = $post->in_reply_to_user_id;             $in_reply_to_screen_name = $post->in_reply_to_screen_name;             $in_reply_to_status_id   = $post->in_reply_to_status_id;             $post_author             = $this->get_option( 'author' );             $post_status             = 'publish';             $twitter_raw             = $post;              // build post array, , hang onto along others             $this->posts[] = compact(                 'post_author',                 'post_date',                 'post_date_gmt',                 'post_content',                 'post_title',                 'post_status',                 'post_category',                 'tags',                 'twitter_id',                 'twitter_permalink',                 'geo',                 'in_reply_to_user_id',                 'in_reply_to_screen_name',                 'in_reply_to_status_id',                 'twitter_raw'             );         }     }      function insert_posts() {         global $wpdb;         $imported = 0;         $skipped  = 0;         foreach ( $this->posts $post ) {             extract( $post );             if (                 $wpdb->get_var( $wpdb->prepare( "select meta_id {$wpdb->postmeta} meta_key = 'twitter_id' , meta_value = %s", $twitter_id ) )             ||                 $post_id = post_exists( $post_title, $post_content, $post_date )             ) {                 // looks duplicate                 $skipped++;             } else {                 $post_id = wp_insert_post( $post );                  if ( is_wp_error( $post_id ) )                     return $post_id;                  if ( !$post_id )                     continue;                   // track keyring service used                 add_post_meta( $post_id, 'keyring_service', $this->service->get_name() );                  // store twitter id, reply ids etc                 add_post_meta( $post_id, 'twitter_id', $twitter_id );                 add_post_meta( $post_id, 'twitter_permalink', $twitter_permalink );                 if ( !empty( $in_reply_to_user_id ) )                     add_post_meta( $post_id, 'twitter_in_reply_to_user_id', $in_reply_to_user_id );                 if ( !empty( $in_reply_to_screen_name ) )                     add_post_meta( $post_id, 'twitter_in_reply_to_screen_name', $in_reply_to_screen_name );                 if ( !empty( $in_reply_to_status_id ) )                     add_post_meta( $post_id, 'twitter_in_reply_to_status_id', $in_reply_to_status_id );                  // update category , tags                 wp_set_post_categories( $post_id, $post_category );                 if ( count( $tags ) )                     wp_set_post_terms( $post_id, implode( ',', $tags ) );                  // store geodata if it's available                 if ( !empty( $geo ) ) {                     add_post_meta( $post_id, 'geo_latitude', $geo['lat'] );                     add_post_meta( $post_id, 'geo_longitude', $geo['long'] );                     add_post_meta( $post_id, 'geo_public', 1 );                 }                  add_post_meta( $post_id, 'raw_import_data', json_encode( $twitter_raw ) );                  $imported++;             }         }         $this->posts = array();          // return, handler can output info (or update db, or whatever)         return array( 'imported' => $imported, 'skipped' => $skipped );     } }  } // end function keyring_twitter_importer   add_action( 'init', function() {     keyring_twitter_importer(); // load class code above     keyring_register_importer(         'twitter',         'keyring_twitter_importer',         plugin_basename( __file__ ),         __( 'import of tweets twitter posts (marked "asides") in wordpress.', 'keyring' )     ); } ); 

this may work you.

after:

keyring_twitter_importer(); // load class code above 

try this:

keyring_twitter_importer(); // load class code above print "<br><a href=\"http://twitter-link.com/you\">follow me on twitter</a><br>"; 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -