Plugin Directory

Changeset 727581


Ignore:
Timestamp:
06/17/2013 06:00:55 PM (13 years ago)
Author:
jayarjo
Message:

Add support for oEmbeds.

Location:
rich-tax-description-editor/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rich-tax-description-editor/trunk/main.php

    r727559 r727581  
    22/*
    33Plugin Name: Rich Tax Description Editor
    4 Plugin URI: http://infinity-8.me
     4Plugin URI: http://wordpress.org/support/plugin/rich-tax-description-editor
    55Description: Turns Description field on Taxonomy pages into the full scale Rich Text Editor.
    6 Version: 1.1
     6Version: 1.2
    77Author: Davit Barbakadze
    8 Author URI: http://profiles.wordpress.org/jayarjo
     8Author URI: http://wordpress.org/support/profile/jayarjo
    99*/
    1010
    1111require_once(dirname(__FILE__) . '/i8/class.Plugino.php');
    1212
     13class RTE_Embed extends WP_Embed {
     14   
     15    private $rte;
     16   
     17    function __construct($rte) {
     18        $this->rte = $rte;
     19        parent::__construct(); 
     20    }
     21   
     22    function shortcode( $attr, $url = '' ) {
     23        global $rte;
     24
     25        if ( empty( $url ) )
     26            return '';
     27
     28        $rawattr = $attr;
     29        $attr = wp_parse_args( $attr, wp_embed_defaults() );
     30
     31        // kses converts & into & and we need to undo this
     32        // See http://core.trac.wordpress.org/ticket/11311
     33        $url = str_replace( '&', '&', $url );
     34
     35        // Look for known internal handlers
     36        ksort( $this->handlers );
     37        foreach ( $this->handlers as $priority => $handlers ) {
     38            foreach ( $handlers as $id => $handler ) {
     39                if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
     40                    if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
     41                        return apply_filters( 'embed_handler_html', $return, $url, $attr );
     42                }
     43            }
     44        }
     45
     46        // Check for a cached result (stored in the post meta)
     47        $cachekey = '_oembed_' . md5( $url . serialize( $attr ) );
     48        if ( $this->usecache ) {
     49            $cache = $this->rte->get_cache($cachekey);
     50
     51            // Failures are cached
     52            if ( '{{unknown}}' === $cache )
     53                return $this->maybe_make_link( $url );
     54
     55            if ( ! empty( $cache ) )
     56                return apply_filters( 'embed_oembed_html', $cache, $url, $attr);
     57        }
     58
     59        // Use oEmbed to get the HTML
     60        $attr['discover'] = ( apply_filters('embed_oembed_discover', false) && author_can( $post_ID, 'unfiltered_html' ) );
     61        $html = wp_oembed_get( $url, $attr );
     62
     63        // Cache the result
     64        $cache = ( $html ) ? $html : '{{unknown}}';
     65        $this->rte->set_cache($cachekey, $cache, 3600 * 24 * 7); // one day
     66
     67        // If there was a result, return it
     68        if ( $html )
     69            return apply_filters( 'embed_oembed_html', $html, $url, $attr);
     70
     71        // Still unknown
     72        return $this->maybe_make_link( $url );
     73    }
     74}
     75
     76
    1377class RTE extends RTE_Plugino {
     78
     79    var $rte_embed;
    1480   
    1581    function __construct()
     
    2086            $this->warn("<strong>{$this->info['Name']}</strong> requires <strong><i>wp_editor API</i></strong>, which seems to be not available in <i>your version</i> of WordPress. Make sure that you are running at least <strong><i>version 3.3</i></strong>.<br /><br /> Plugin will <strong><i>deactivate</i></strong> itself now!");
    2187        }
     88       
     89        $this->rte_embed = new RTE_Embed($this);
    2290    }
    2391   
     
    3098            add_action("{$tax}_edit_form", array($this, 'a_term_edit_form'), 10, 2);
    3199        }
     100       
     101        // Hack to get the [embed] shortcode to run before wpautop()
     102        add_filter('term_description', array($this->rte_embed, 'run_shortcode'), 8);
    32103
     104        // Shortcode placeholder for strip_shortcodes()
     105        add_shortcode('embed', '__return_false');
     106
     107        // Attempts to embed all URLs in a post
     108        add_filter('term_description', array($this->rte_embed, 'autoembed'), 8);
     109       
    33110        add_filter('term_description', 'do_shortcode');
    34111    }
     
    70147        return $description;   
    71148    }
    72 
     149   
     150   
    73151    // truncate term description
    74152    function f_10_3__get_terms($terms, $taxonomies, $args)
     
    83161    }
    84162   
     163   
    85164    private function to_plain_text($text)
    86165    {       
  • rich-tax-description-editor/trunk/readme.txt

    r727559 r727581  
    4242Truncate description on listing pages.
    4343Process shortcodes.
     44
     45= 1.2 =
     46Support oEmbed.
Note: See TracChangeset for help on using the changeset viewer.