WordPress.org

Plugin Directory

Changeset 530511


Ignore:
Timestamp:
04/13/12 02:42:01 (2 years ago)
Author:
sterlo
Message:

w00t 2.0! No more shortcodes!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • scalable-vector-graphics-svg/trunk/scalable-vector-graphics.php

    r530488 r530511  
    44 * Plugin URI: http://sterlinghamilton.com/scalable-vector-graphics-plugin 
    55 * Description: Scalable Vector Graphics are two-dimensional vector graphics, that can be both static and dynamic. This plugin allows your to easily use them on your site. 
    6  * Version: 1.2 
     6 * Version: 2.0 
    77 * Author: Sterling Hamilton 
    8  * Author URI: http://www.sterlinghamilton.com 
     8 * Author URI: http://sterlinghamilton.com 
    99 * License: GPLv2 or later 
    1010 
     
    2828    public function execute() { 
    2929        $this->_enable_svg_mime_type(); 
    30         $this->_enable_shortcode_processing(); 
    3130    } 
    3231 
     
    3534    } 
    3635 
    37     private function _enable_shortcode_processing() { 
    38         add_shortcode( 'svg', array( &$this, 'process_shortcode' ) ); 
     36    private function _sanitize_input( $input ) { 
     37        if( is_scalar( $input ) ) { 
     38            return wp_kses( $input ); 
     39        } else { 
     40            $this->_error( 'Unable to sanitize given input: Not scalar: integer, float, string or boolean.' ); 
     41        } 
     42 
     43        return false; 
     44    } 
     45 
     46    private function _error( $message ) { 
     47        return new WP_Error( __CLASS__, __METHOD__ . __( $message ) ); 
    3948    } 
    4049 
    4150    public function allow_svg_uploads( $existing_mime_types = array() ) { 
    42         $new_mime_types = $existing_mime_types; 
    43         $new_mime_types[ 'svg' ] = 'mime/type'; 
    44  
    45         return $new_mime_types; 
     51        return $this->_add_mime_type( $existing_mime_types ); 
    4652    } 
    4753 
    48     public function process_shortcode( $atts ) { 
    49         $valid_attributes = array( 'src' , 'style' , 'type' , 'width' , 'height' ); 
     54    private function _add_mime_type( $mime_types ) { 
     55        $mime_types[ 'svg' ] = 'image/svg+xml'; 
    5056 
    51         $content = NULL; 
    52  
    53         foreach( $atts as $attribute => $value ) { 
    54             if( ! in_array( $attribute, $valid_attributes ) ) { 
    55                 $content .= "\n" . '<!-- Invalid attribute ignored: ' . $attribute . ' -->' . "\n"; 
    56             } 
    57         } 
    58  
    59         switch( $atts[ 'type' ] ) { 
    60             case 'iframe': 
    61                 $content .= '<iframe src="' . $atts[ 'src' ] . '" width="' . $atts[ 'width' ] . '" height="' . $atts[ 'height' ] . '" style="' . $atts[ 'style' ] . '">'; 
    62                 $content .= '</iframe>'; 
    63             break; 
    64             case 'embed': 
    65             default: 
    66                 $content .= '<embed src="' . $atts[ 'src' ] . '" width="' . $atts[ 'width' ] . '" height="' . $atts[ 'height' ] . '" '; 
    67                 $content .= 'type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" style="' . $atts[ 'style' ] . '" /> '; 
    68             break; 
    69         } 
    70  
    71         return $content; 
     57        return $mime_types; 
    7258    } 
    7359 
Note: See TracChangeset for help on using the changeset viewer.