aboutsummaryrefslogtreecommitdiff
path: root/mod/videolist/lib/Videolist/Platform/Vimeo.php
blob: 6930cdb2d55b46da75d479b4a19ac34e01838966 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

class Videolist_Platform_Vimeo implements Videolist_PlatformInterface
{
    public function getType()
    {
        return "vimeo";
    }

    public function parseUrl($url)
    {
        $parsed = parse_url($url);
        $path = explode('/', $parsed['path']);

        if ($parsed['host'] != 'vimeo.com' || !(int) $path[1]) {
            return false;
        }

        return array(
            'video_id' => $path[1],
        );
    }

    public function getData($parsed)
    {
        $video_id = $parsed['video_id'];

        $buffer = file_get_contents("https://vimeo.com/api/v2/video/$video_id.xml");
        $xml = new SimpleXMLElement($buffer);

        $videos = $xml->children();
        $video = $videos[0];

        return array(
            'title' => $video->title,
            'description' => strip_tags($video->description),
            'thumbnail' => $video->thumbnail_medium,
        );
    }
}