Esempio n. 1
0
function mtphr_galleries_resource_data_update($resource)
{
    if (!is_array($resource)) {
        $updated_resource = array();
        $updated_resource['type'] = $type = mtphr_galleries_resource_type($resource);
        switch ($type) {
            case 'vimeo':
                // Strip out the id from url
                $value_array = explode('/', $resource);
                $value = end($value_array);
                $updated_resource['id'] = $value;
                $updated_resource['link'] = $resource;
                break;
            case 'youtube':
                // Strip out the id from url
                parse_str($resource, $value_array);
                if (isset($value_array['v'])) {
                    $value = $value_array['v'];
                } else {
                    $value = reset($value_array);
                }
                $updated_resource['id'] = $value;
                $updated_resource['link'] = $resource;
                break;
            default:
                $updated_resource['id'] = $resource;
                break;
        }
        if (!get_post($resource)) {
            $updated_resource['external'] = true;
        }
        return $updated_resource;
    }
    return $resource;
}
Esempio n. 2
0
 function mtphr_galleries_type($url)
 {
     return mtphr_galleries_resource_type($url);
 }
 function mtphr_galleries_thumbnail($url, $width = false, $height = false, $size = 'medium')
 {
     $type = '';
     $thumb = '';
     $post = get_post($url);
     if ($post) {
         $type = substr($post->post_mime_type, 0, 5);
         if ($type == 'image') {
             $img = wp_get_attachment_image_src($post->ID, $size);
             $url = $img[0];
         }
     }
     // Get the resource type
     if ($type == '') {
         $type = mtphr_galleries_resource_type($url);
     }
     switch ($type) {
         case 'image':
             return '<img src="' . $url . '" width="' . $width . '" height="' . $height . '" />';
             break;
         case 'vimeo':
             $id = substr($url, 17);
             $vimeo = simplexml_load_file('http://vimeo.com/api/v2/video/' . $id . '.xml');
             $url = $vimeo->video->thumbnail_large;
             return '<img src="' . $url . '" width="' . $width . '" height="' . $height . '" />';
             break;
         case 'youtube':
             $id = substr($url, 31);
             $url = 'http://img.youtube.com/vi/' . $id . '/0.jpg';
             return '<img src="' . $url . '" width="' . $width . '" height="' . $height . '" />';
             break;
         case 'video':
             return false;
         case 'audio':
             return false;
     }
     return false;
 }