Plugin Directory

Changeset 862503


Ignore:
Timestamp:
02/21/2014 05:57:36 PM (12 years ago)
Author:
sutherlandboswell
Message:

Custom field detection. Minor fixes and improvements.

Location:
video-thumbnails
Files:
2 added
4 deleted
4 edited
26 copied

Legend:

Unmodified
Added
Removed
  • video-thumbnails/tags/2.6.2/php/class-video-thumbnails-settings.php

    r859638 r862503  
    3838        // Initialize options
    3939        add_action( 'admin_init', array( &$this, 'initialize_options' ) );
     40        // Custom field detection callback
     41        add_action( 'wp_ajax_video_thumbnail_custom_field_detection', array( &$this, 'custom_field_detection_callback' ) );
    4042        // Ajax clear all callback
    4143        add_action( 'wp_ajax_clear_all_video_thumbnails', array( &$this, 'ajax_clear_all_callback' ) );
     
    134136
    135137    function admin_scripts() {
    136         wp_enqueue_script( 'video_thumbnails_test', plugins_url( 'js/test.js' , VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ) );
    137         wp_enqueue_script( 'video_thumbnails_clear', plugins_url( 'js/clear.js' , VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ) );
     138        wp_enqueue_script( 'video_thumbnails_settings', plugins_url( 'js/settings.js' , VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ), array( 'jquery' ), VIDEO_THUMBNAILS_VERSION );
     139    }
     140
     141    function custom_field_detection_callback() {
     142        if ( current_user_can( 'manage_options' ) ) {
     143            echo $this->detect_custom_field();
     144        }
     145        die();
     146    }
     147
     148    function detect_custom_field() {
     149        global $video_thumbnails;
     150        $latest_post = get_posts( array(
     151            'posts_per_page'  => 1,
     152            'post_type'  => $this->options['post_types'],
     153            'orderby' => 'modified',
     154        ) );
     155        $latest_post = $latest_post[0];
     156        $custom = get_post_meta( $latest_post->ID );
     157        foreach ( $custom as $name => $values ) {
     158            foreach ($values as $value) {
     159                if ( $video_thumbnails->get_first_thumbnail_url( $value ) ) {
     160                    return $name;
     161                }
     162            }
     163        }
    138164    }
    139165
     
    323349            'custom_field',
    324350            'Custom Field (optional)',
    325             'Enter the name of the custom field where your embed code or video URL is stored.'
     351            '<a href="#" class="button" id="vt_detect_custom_field">Automatically Detect</a> Enter the name of the custom field where your embed code or video URL is stored.'
    326352        );
    327353        register_setting( 'video_thumbnails', 'video_thumbnails', array( &$this, 'sanitize_callback' ) );
  • video-thumbnails/tags/2.6.2/php/providers/class-vimeo-thumbnails.php

    r846693 r862503  
    8585            $result = $response->thumbnails->thumbnail[count($response->thumbnails->thumbnail)-1]->_content;
    8686        } else {
    87             $request = "http://vimeo.com/api/oembed.xml?url=http%3A//vimeo.com/$id";
     87            $request = "http://vimeo.com/api/oembed.json?url=http%3A//vimeo.com/$id";
    8888            $response = wp_remote_get( $request, array( 'sslverify' => false ) );
    8989            if( is_wp_error( $response ) ) {
     
    9494                $result = new WP_Error( 'vimeo_info_retrieval', __( 'The Vimeo endpoint located at <a href="' . $request . '">' . $request . '</a> returned a 403 error.<br />This can occur when a video has embedding disabled or restricted to certain domains. Try entering API credentials in the provider settings.' ) );
    9595            } else {
    96                 $xml = new SimpleXMLElement( $response['body'] );
    97                 $result = (string) $xml->thumbnail_url;
     96                $result = json_decode( $response['body'] );
     97                $result = $result->thumbnail_url;
    9898            }
    9999        }
  • video-thumbnails/tags/2.6.2/readme.txt

    r859790 r862503  
    55Requires at least: 3.2
    66Tested up to: 3.8.1
    7 Stable tag: 2.6.1
     7Stable tag: 2.6.2
    88
    99Video Thumbnails simplifies the process of automatically displaying video thumbnails in your WordPress template.
     
    118118
    119119== Changelog ==
     120
     121= 2.6.2 =
     122* Added feature to settings page that automatically detects the custom field
     123* Switched to JSON for Vimeo's oEmbed endpoint
     124* Added support for the "image/gif" MIME type
    120125
    121126= 2.6.1 =
  • video-thumbnails/tags/2.6.2/video-thumbnails.php

    r859790 r862503  
    66Author: Sutherland Boswell
    77Author URI: http://sutherlandboswell.com
    8 Version: 2.6.1
     8Version: 2.6.2
    99License: GPL2
    1010*/
     
    2929define( 'VIDEO_THUMBNAILS_PATH', dirname(__FILE__) );
    3030define( 'VIDEO_THUMBNAILS_FIELD', '_video_thumbnail' );
    31 define( 'VIDEO_THUMBNAILS_VERSION', '2.6.1' );
     31define( 'VIDEO_THUMBNAILS_VERSION', '2.6.2' );
    3232
    3333// Providers
     
    331331            } elseif ( $image_type == 'image/png' ) {
    332332                $image_extension = '.png';
     333            } elseif ( $image_type == 'image/gif' ) {
     334                $image_extension = '.gif';
    333335            } else {
    334336                return new WP_Error( 'thumbnail_upload', __( 'Unsupported MIME type:' ) . ' ' . $image_type );
  • video-thumbnails/trunk/php/class-video-thumbnails-settings.php

    r859638 r862503  
    3838        // Initialize options
    3939        add_action( 'admin_init', array( &$this, 'initialize_options' ) );
     40        // Custom field detection callback
     41        add_action( 'wp_ajax_video_thumbnail_custom_field_detection', array( &$this, 'custom_field_detection_callback' ) );
    4042        // Ajax clear all callback
    4143        add_action( 'wp_ajax_clear_all_video_thumbnails', array( &$this, 'ajax_clear_all_callback' ) );
     
    134136
    135137    function admin_scripts() {
    136         wp_enqueue_script( 'video_thumbnails_test', plugins_url( 'js/test.js' , VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ) );
    137         wp_enqueue_script( 'video_thumbnails_clear', plugins_url( 'js/clear.js' , VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ) );
     138        wp_enqueue_script( 'video_thumbnails_settings', plugins_url( 'js/settings.js' , VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ), array( 'jquery' ), VIDEO_THUMBNAILS_VERSION );
     139    }
     140
     141    function custom_field_detection_callback() {
     142        if ( current_user_can( 'manage_options' ) ) {
     143            echo $this->detect_custom_field();
     144        }
     145        die();
     146    }
     147
     148    function detect_custom_field() {
     149        global $video_thumbnails;
     150        $latest_post = get_posts( array(
     151            'posts_per_page'  => 1,
     152            'post_type'  => $this->options['post_types'],
     153            'orderby' => 'modified',
     154        ) );
     155        $latest_post = $latest_post[0];
     156        $custom = get_post_meta( $latest_post->ID );
     157        foreach ( $custom as $name => $values ) {
     158            foreach ($values as $value) {
     159                if ( $video_thumbnails->get_first_thumbnail_url( $value ) ) {
     160                    return $name;
     161                }
     162            }
     163        }
    138164    }
    139165
     
    323349            'custom_field',
    324350            'Custom Field (optional)',
    325             'Enter the name of the custom field where your embed code or video URL is stored.'
     351            '<a href="#" class="button" id="vt_detect_custom_field">Automatically Detect</a> Enter the name of the custom field where your embed code or video URL is stored.'
    326352        );
    327353        register_setting( 'video_thumbnails', 'video_thumbnails', array( &$this, 'sanitize_callback' ) );
  • video-thumbnails/trunk/php/providers/class-vimeo-thumbnails.php

    r846693 r862503  
    8585            $result = $response->thumbnails->thumbnail[count($response->thumbnails->thumbnail)-1]->_content;
    8686        } else {
    87             $request = "http://vimeo.com/api/oembed.xml?url=http%3A//vimeo.com/$id";
     87            $request = "http://vimeo.com/api/oembed.json?url=http%3A//vimeo.com/$id";
    8888            $response = wp_remote_get( $request, array( 'sslverify' => false ) );
    8989            if( is_wp_error( $response ) ) {
     
    9494                $result = new WP_Error( 'vimeo_info_retrieval', __( 'The Vimeo endpoint located at <a href="' . $request . '">' . $request . '</a> returned a 403 error.<br />This can occur when a video has embedding disabled or restricted to certain domains. Try entering API credentials in the provider settings.' ) );
    9595            } else {
    96                 $xml = new SimpleXMLElement( $response['body'] );
    97                 $result = (string) $xml->thumbnail_url;
     96                $result = json_decode( $response['body'] );
     97                $result = $result->thumbnail_url;
    9898            }
    9999        }
  • video-thumbnails/trunk/readme.txt

    r859790 r862503  
    55Requires at least: 3.2
    66Tested up to: 3.8.1
    7 Stable tag: 2.6.1
     7Stable tag: 2.6.2
    88
    99Video Thumbnails simplifies the process of automatically displaying video thumbnails in your WordPress template.
     
    118118
    119119== Changelog ==
     120
     121= 2.6.2 =
     122* Added feature to settings page that automatically detects the custom field
     123* Switched to JSON for Vimeo's oEmbed endpoint
     124* Added support for the "image/gif" MIME type
    120125
    121126= 2.6.1 =
  • video-thumbnails/trunk/video-thumbnails.php

    r859790 r862503  
    66Author: Sutherland Boswell
    77Author URI: http://sutherlandboswell.com
    8 Version: 2.6.1
     8Version: 2.6.2
    99License: GPL2
    1010*/
     
    2929define( 'VIDEO_THUMBNAILS_PATH', dirname(__FILE__) );
    3030define( 'VIDEO_THUMBNAILS_FIELD', '_video_thumbnail' );
    31 define( 'VIDEO_THUMBNAILS_VERSION', '2.6.1' );
     31define( 'VIDEO_THUMBNAILS_VERSION', '2.6.2' );
    3232
    3333// Providers
     
    331331            } elseif ( $image_type == 'image/png' ) {
    332332                $image_extension = '.png';
     333            } elseif ( $image_type == 'image/gif' ) {
     334                $image_extension = '.gif';
    333335            } else {
    334336                return new WP_Error( 'thumbnail_upload', __( 'Unsupported MIME type:' ) . ' ' . $image_type );
Note: See TracChangeset for help on using the changeset viewer.