Plugin Directory

Changeset 805652


Ignore:
Timestamp:
11/17/2013 06:05:13 AM (12 years ago)
Author:
apokalyptik
Message:

handle videos in photostreams

File:
1 edited

Legend:

Unmodified
Added
Removed
  • photostream-sync/trunk/photostream-sync.php

    r661759 r805652  
    33/*
    44Plugin Name: photostream-sync
    5 Description: Synchronize your public iCloud photostreams to your WordPress installation. Import images, create gellery posts, and more.
     5Description: Synchronize your public iCloud photostreams to your WordPress installation. Import images, Import videos, create gellery posts, and more.
    66Author: Demitrious Kelly <apokalyptik@apokalyptik.com>
    7 Version: 1.0.3
     7Version: 2.0.0
    88Author URI: http://blog.apokalyptik.com/
    99*/
     
    240240                                        name="photostream[edit][<?php esc_attr_e( $key );?>][rename_file]"
    241241                                        value="<?php esc_attr_e( $stream->rename_file ); ?>"
    242                                         placeholder="stream->title - owner->fullName -- image->date(Y-m-d).jpg"/>
     242                                        placeholder="stream->title - owner->fullName -- file->date(Y-m-d).jpg"/>
    243243                                    <br/>
    244244                                    <?php $this->display_text_transform_options(); ?>
     
    342342                            name="photostream[add][rename_file]"
    343343                            value="<?php esc_attr_e( $stream->rename_file ); ?>"
    344                             placeholder="stream->title - owner->fullName -- image->date(Y-m-d).jpg"/>
     344                            placeholder="stream->title - owner->fullName -- file->date(Y-m-d).jpg"/>
    345345                        <br/>
    346346                        <?php $this->display_text_transform_options(); ?>
     
    477477            if ( !$processed )
    478478                $ready = false;
     479            if ( $processed['type'] == 'video/mp4' ) {
     480                $group_post['post_content'] = $group_post['post_content'] . sprintf( '[video mp4="%s"]', $processed['url'] );
     481                wp_update_post($group_post);
     482            }
    479483        }
    480484        if ( !$ready )
     
    510514        $path = $this->apply_image_centric_text_transforms( $path, $image );
    511515        $path = $this->apply_generic_text_transforms( $path );
     516        $path = preg_replace( '/\.(jpe?g|mp4)$/i', '', $path );
     517        if ( isset( $image->mediaAssetType ) && $image->mediaAssetType == 'video' )
     518            $path = "$path.mp4";
     519        else
     520            $path = "$path.jpg";
    512521        if ( empty( $path ) )
    513522            return false;
     
    515524        if ( empty( $mime ) || empty( $mime['type'] ) )
    516525            return false;
    517         foreach( $derivatives[$width]->_wp_ps_url as $url ) {
    518             $bits = wp_remote_retrieve_body( $response = wp_remote_get( $url ) );
    519             if ( $bits )
    520                 break;
     526        if ( isset( $image->mediaAssetType ) && $image->mediaAssetType == 'video' ) {
     527            foreach( array( '720p', '360p' ) as $resolution ) {
     528                foreach( $derivatives[$resolution]->_wp_ps_url as $url ) {
     529                    $bits = wp_remote_retrieve_body( $response = wp_remote_get( $url ) );
     530                    if ( $bits )
     531                        break;
     532                }
     533                if ( $bits )
     534                    break;
     535            }
     536        } else {
     537            foreach( $derivatives[$width]->_wp_ps_url as $url ) {
     538                $bits = wp_remote_retrieve_body( $response = wp_remote_get( $url ) );
     539                if ( $bits )
     540                    break;
     541            }
    521542        }
    522543        if ( empty( $bits ) )
     
    535556            'guid' => $upload[ 'url' ]
    536557        );
    537         if ( function_exists( 'exif_read_data' ) ) {
    538             $exif = exif_read_data( $upload[ 'file' ] );
    539         } else {
    540             $exif = false;
     558
     559        $exif = false;
     560        if ( !isset( $image->mediaAssetType ) || $image->mediaAssetType != 'video' ) {
     561            if ( function_exists( 'exif_read_data' ) )
     562                $exif = exif_read_data( $upload[ 'file' ] );
    541563        }
    542564        $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
     
    553575        $struct = array(
    554576            'id'   => strval( $id ),
    555             'file' => $name,
     577            'file' => $upload['file'],
    556578            'url'  => $upload[ 'url' ],
    557             'type' => $type
     579            'type' => $mime['type']
    558580        );
    559581        $stream->processed_groups[$group_key][$image->photoGuid] = time();
     
    629651
    630652        // Image Replacements
    631         $text = str_replace( 'image->caption', $image->caption, $text );
    632         $text = str_replace( 'image->guid', $image->photoGuid, $text );
    633         if ( preg_match_all( '/image->date\(([^)]+)\)/', $text, $matches ) ) {
     653        $text = str_replace( 'image->', 'file->', $text ); // Maintain backwards compatibility
     654        $text = str_replace( 'video->', 'file->', $text ); // Just in case someone tries this...
     655        $text = str_replace( 'file->caption', $image->caption, $text );
     656        $text = str_replace( 'file->guid', $image->photoGuid, $text );
     657        if ( preg_match_all( '/file->date\(([^)]+)\)/', $text, $matches ) ) {
    634658            $datetime = strtotime( $image->dateCreated );
    635659            foreach( array_keys( $matches[0] ) as $m )
Note: See TracChangeset for help on using the changeset viewer.