WordPress.org

Plugin Directory

Changeset 476261


Ignore:
Timestamp:
12/16/11 07:34:37 (2 years ago)
Author:
ozh
Message:

1.5.4:
Fixed: two sprintf issues for the meta box rendering
Fixed: Using post type singular label in the meta box
Added: two more tags: %X{taxonomy} and %Y{taxonomy}.
Improved: tag replacement (when parsing %A, first check if tag is used, and than get's author data and replace)
All fixes in 1.5.4 from Milan Petrovic, thanks a bunch!

Location:
yourls-wordpress-to-twitter/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • yourls-wordpress-to-twitter/trunk/inc/core.php

    r419993 r476261  
    390390} 
    391391 
    392  
    393392// Fetch a remote page. Input url, return content 
    394393function wp_ozh_yourls_fetch_url( $url, $method='GET', $body=array(), $headers=array() ) { 
     
    409408} 
    410409 
    411  
    412410// Parse the tweet template and make a 140 char string 
    413411function wp_ozh_yourls_maketweet( $url, $title, $id ) { 
     
    418416 
    419417    $tweet = $wp_ozh_yourls['twitter_message']; 
    420      
     418 
    421419    // Plugin author: interrupt here before everything is parsed 
    422420    $tweet = apply_filters( 'pre_ozh_yourls_tweet', $tweet, $url, $title, $id ); 
     
    433431        unset( $matches ); 
    434432    } 
    435      
    436     // Get author info 
    437     $post = get_post( $id ); 
    438     $author_id = $post->post_author; 
    439     $author_info = get_userdata( $author_id ); 
    440     unset( $post ); 
    441      
    442     // Replace %A{bleh} with author data 'bleh' 
    443     if( preg_match_all( '/%A\{([^\}]+)\}/', $tweet, $matches ) ) { 
    444         foreach( $matches[1] as $match ) { 
    445             $tweet = str_replace('%A{'.$match.'}', $author_info->$match, $tweet); 
    446         } 
    447         unset( $matches ); 
    448     } 
    449      
    450     // Replace %A with author display name 
    451     $tweet = str_replace('%A', $author_info->display_name, $tweet); 
    452      
    453     // Get tags (up to 3) 
    454     $_tags = array_slice( (array)get_the_tags( $id ), 0, 3 ); 
    455     $tags = array(); 
    456     foreach( $_tags as $tag ) { $tags[] = strtolower( str_replace( " ", "", $tag->name ) ); } 
    457     unset( $_tags ); 
    458  
    459     // Get categories (up to 3) 
    460     $_cats = array_slice( (array)get_the_category( $id ), 0, 3 ); 
    461     $cats = array(); 
    462     foreach( $_cats as $cat ) { $cats[] = strtolower( str_replace( " ", "", $cat->name ) ); } 
    463     unset( $_cats ); 
    464  
    465     // Replace %L with tags as plaintext (space separated if more than one) (up to 3 tags) 
    466     $tweet = str_replace('%L', join(' ', $tags), $tweet); 
    467      
    468     // Replace %H with tags as hashtags (space separated if more than one) (up to 3 tags)  
    469     $tweet = str_replace('%H', '#'.join(' #', $tags), $tweet); 
    470      
    471     // Replace %C with categories (space separated if more than one) (up to 3 categories)  
    472     $tweet = str_replace('%C', join(' ', $cats), $tweet); 
    473      
    474     // Replace %D with categories as hashtags (space separated if more than one) (up to 3 categories)  
    475     $tweet = str_replace('%D', '#'.join(' #', $cats), $tweet); 
     433 
     434        if (strpos($tweet, '%A') !== false) { 
     435            // Get author info 
     436            $post = get_post( $id ); 
     437            $author_id = $post->post_author; 
     438            $author_info = get_userdata( $author_id ); 
     439            unset( $post ); 
     440 
     441            // Replace %A{bleh} with author data 'bleh' 
     442            if( preg_match_all('/%A\{([^\}]+)\}/', $tweet, $matches)) { 
     443                foreach( $matches[1] as $match ) { 
     444                    $tweet = str_replace('%A{'.$match.'}', $author_info->$match, $tweet); 
     445                } 
     446                unset( $matches ); 
     447            } 
     448 
     449            // Replace %A with author display name 
     450            $tweet = str_replace('%A', $author_info->display_name, $tweet); 
     451        } 
     452 
     453        if (strpos($tweet, '%X') !== false) { 
     454            if (preg_match_all('/%X\{([^\}]+)\}/', $tweet, $matches)) { 
     455                foreach ($matches[1] as $tax) { 
     456                    $_terms = array_slice((array)get_the_terms($id, $tax), 0, 3); 
     457                    $terms = array(); 
     458                    foreach ($_terms as $term) { 
     459                        $terms[] = strtolower(str_replace(" ", "", $term->name)); 
     460                    } 
     461                    unset($_terms); 
     462 
     463                    $tweet = str_replace('%X{'.$tax.'}', join(' ', $terms), $tweet); 
     464                } 
     465                unset($matches); 
     466            } 
     467        } 
     468 
     469        if (strpos($tweet, '%Y') !== false) { 
     470            if (preg_match_all('/%Y\{([^\}]+)\}/', $tweet, $matches)) { 
     471                foreach ($matches[1] as $tax) { 
     472                    $_terms = array_slice((array)get_the_terms($id, $tax), 0, 3); 
     473                    $terms = array(); 
     474                    foreach ($_terms as $term) { 
     475                        $terms[] = strtolower(str_replace(" ", "", $term->name)); 
     476                    } 
     477                    unset($_terms); 
     478 
     479                    $tweet = str_replace('%Y{'.$tax.'}', "#".join(' #', $terms), $tweet); 
     480                } 
     481                unset($matches); 
     482            } 
     483        } 
     484 
     485        if (strpos($tweet, '%L') !== false || strpos($tweet, '%H') !== false) { 
     486            // Get tags (up to 3) 
     487            $_tags = array_slice( (array)get_the_tags( $id ), 0, 3 ); 
     488            $tags = array(); 
     489            foreach( $_tags as $tag ) { $tags[] = strtolower( str_replace( " ", "", $tag->name ) ); } 
     490            unset( $_tags ); 
     491 
     492            // Replace %L with tags as plaintext (space separated if more than one) (up to 3 tags) 
     493            $tweet = str_replace('%L', join(' ', $tags), $tweet); 
     494 
     495            // Replace %H with tags as hashtags (space separated if more than one) (up to 3 tags)  
     496            $tweet = str_replace('%H', '#'.join(' #', $tags), $tweet); 
     497        } 
     498 
     499        if (strpos($tweet, '%C') !== false || strpos($tweet, '%D') !== false) { 
     500            // Get categories (up to 3) 
     501            $_cats = array_slice( (array)get_the_category( $id ), 0, 3 ); 
     502            $cats = array(); 
     503            foreach( $_cats as $cat ) { $cats[] = strtolower( str_replace( " ", "", $cat->name ) ); } 
     504            unset( $_cats ); 
     505 
     506            // Replace %C with categories (space separated if more than one) (up to 3 categories)  
     507            $tweet = str_replace('%C', join(' ', $cats), $tweet); 
     508 
     509            // Replace %D with categories as hashtags (space separated if more than one) (up to 3 categories)  
     510            $tweet = str_replace('%D', '#'.join(' #', $cats), $tweet); 
     511        } 
    476512 
    477513    // Finally replace %T with as many chars as possible to keep under 140 
     
    619655    echo wp_ozh_yourls_get_shortener_base_url(); 
    620656} 
    621     /** 
    622      * Gets the current shortener's base URL. Looks first in the saved settings, and if not 
    623      * found there, calculates it based on the current service and 
    624      * wp_ozh_yourls_determine_base_url() 
    625      * 
    626      * @package YOURLS WordPress to Twitter 
    627      * @since 1.5 
    628      * 
    629      * @return str $url The base URL for the shortener (eg http://bit.ly) 
    630      */ 
    631     function wp_ozh_yourls_get_shortener_base_url() { 
    632         // Usually this will be stored in the settings 
    633         $wp_ozh_yourls = get_option( 'ozh_yourls' ); 
    634          
    635         if ( isset( $wp_ozh_yourls['shortener_base_url'] ) ) { 
    636             $url = $wp_ozh_yourls['shortener_base_url']; 
    637         } else { 
    638             $url = wp_ozh_yourls_determine_base_url(); 
    639         } 
    640          
    641         return $url; 
    642     } 
     657 
     658/** 
     659 * Gets the current shortener's base URL. Looks first in the saved settings, and if not 
     660 * found there, calculates it based on the current service and 
     661 * wp_ozh_yourls_determine_base_url() 
     662 * 
     663 * @package YOURLS WordPress to Twitter 
     664 * @since 1.5 
     665 * 
     666 * @return str $url The base URL for the shortener (eg http://bit.ly) 
     667 */ 
     668function wp_ozh_yourls_get_shortener_base_url() { 
     669        // Usually this will be stored in the settings 
     670        $wp_ozh_yourls = get_option( 'ozh_yourls' ); 
     671 
     672        if ( isset( $wp_ozh_yourls['shortener_base_url'] ) ) { 
     673                $url = $wp_ozh_yourls['shortener_base_url']; 
     674        } else { 
     675                $url = wp_ozh_yourls_determine_base_url(); 
     676        } 
     677 
     678        return $url; 
     679} 
    643680 
    644681/** 
  • yourls-wordpress-to-twitter/trunk/inc/options.php

    r445842 r476261  
    414414            <li><b><tt>%A{<?php _e( 'something', 'wp-ozh-yourls' ) ?>}</tt></b>: <?php _e( 'author\'s \'something\' as stored in the database. Example: %A{first_name}. See <a href="http://codex.wordpress.org/Function_Reference/get_userdata">get_userdata()</a>.', 'wp-ozh-yourls' ) ?></li> 
    415415            <li><b><tt>%F{<?php _e( 'something', 'wp-ozh-yourls' ) ?>}</tt></b>: <?php _e( 'custom post field \'something\'. See <a href="http://codex.wordpress.org/Function_Reference/get_post_meta">get_post_meta()</a>.', 'wp-ozh-yourls' ) ?></li> 
     416            <li><b><tt>%X{<?php _e( 'taxonomy', 'wp-ozh-yourls' ) ?>}</tt></b>: <?php _e( 'terms as plaintext and lowercase for taxonomy. Example: %X{category} (space separated if more than one, up to 3 tags)', 'wp-ozh-yourls' ) ?></li> 
     417            <li><b><tt>%Y{<?php _e( 'taxonomy', 'wp-ozh-yourls' ) ?>}</tt></b>: <?php _e( 'terms as #hashtags and lowercase for taxonomy. Example: %Y{category} (space separated if more than one, up to 3 tags)', 'wp-ozh-yourls' ) ?></li> 
    416418            <li><b><tt>%L</tt></b>: <?php _e( 'tags as plaintext and lowercase (space separated if more than one, up to 3 tags)', 'wp-ozh-yourls' ) ?></li> 
    417419            <li><b><tt>%H</tt></b>: <?php _e( 'tags as #hashtags and lowercase (space separated if more than one, up to 3 tags)', 'wp-ozh-yourls' ) ?></li> 
     
    474476    $id = $post->ID; 
    475477    $title = $post->post_title; 
     478        $post_type = get_post_type_object($type); 
     479        $type_label = $post_type->labels->singular_name; 
    476480     
    477481    $account = wp_ozh_yourls_get_twitter_screen_name(); 
     
    512516     
    513517    $action = __( 'Tweet this', 'wp-ozh-yourls' ); 
    514     $promote = sprintf( __( "Promote this $s", 'wp-ozh-yourls' ), $type ); 
     518    $promote = sprintf( __( "Promote this %s", 'wp-ozh-yourls' ), $type_label ); 
    515519    $tweeted = get_post_meta( $id, 'yourls_tweeted', true ); 
    516520 
     
    519523    if ($tweeted) { 
    520524        $action = __( 'Retweet this', 'wp-ozh-yourls' ); 
    521         $promote = sprintf( __( "Promote this $s again", 'wp-ozh-yourls' ), $type ); 
     525        $promote = sprintf( __( "Promote this %s again", 'wp-ozh-yourls' ), $type_label ); 
    522526        echo '<p>' . __( '<em>Note:</em> this post has already been tweeted. Not that there\'s something wrong to promote it again, of course :)', 'wp-ozh-yourls' ) . '</p>'; 
    523527    } 
  • yourls-wordpress-to-twitter/trunk/plugin.php

    r445842 r476261  
    66Author: Ozh 
    77Author URI: http:/ozh.org/ 
    8 Version: 1.5.3 
     8Version: 1.5.4 
    99*/ 
    1010 
     
    5555 * 1.5.2:     Added: Spanish translation. Thanks myhosting.com team! 
    5656 * 1.5.3:     Fixed: metaboxes now appear on custom post type pages 
     57 * 1.5.4:     Fixed: two sprintf issues for the meta box rendering 
     58              Fixed: Using post type singular label in the meta box 
     59              Added: two more tags: %X{taxonomy} and %Y{taxonomy}. 
     60              Improved: tag replacement (when parsing %A, first check if tag is used, and than get's author data and replace) 
     61              All fixes in 1.5.4 from Milan Petrovic, thanks a bunch! 
    5762 */ 
    5863 
  • yourls-wordpress-to-twitter/trunk/readme.txt

    r445481 r476261  
    55Requires at least: 3.0 
    66Tested up to: 9.9 
    7 Stable tag: 1.5.3 
     7Stable tag: 1.5.4 
    88 
    99Use YOURLS (a free GPL URL shortener service) or another public service (tinyURL...) to create short URLs of your posts and tweet them, or to create short URLs for your BuddyPress groups and users 
Note: See TracChangeset for help on using the changeset viewer.