source: spip-zone/_plugins_/oeproxy/oeproxy/storify.php @ 59459

Last change on this file since 59459 was 59459, checked in by cedric@…, 9 years ago

Le proxy oembed sait importer storify

File size: 3.3 KB
Line 
1<?php
2/*
3 * Plugin oEmebed The Web
4 * (c) 2011 Cedric Morin
5 * Distribue sous licence GPL
6 *
7 * http://oembed.com/
8 *
9 */
10
11if (!defined("_ECRIRE_INC_VERSION")) return;
12
13include_spip('inc/filtres');
14include_spip('inc/distant');
15
16/**
17 * Proxy storify :
18 * utilise l'api storify pour reformater le contenu
19 *
20 * @param string $url
21 * @param array $options
22 * @param string $html
23 * @return array|int
24 */
25function oeproxy_storify_dist($url,$options,$html=null){
26
27        // http://api.storify.com/v1/stories/user/story
28        $segments = explode('/',$url);
29        $story = array_pop($segments);
30        $user = array_pop($segments);
31
32        $url_api = "http://api.storify.com/v1/stories/$user/$story?per_page=50";
33
34        // recuperer la story en json
35        if (!$json_story = recuperer_page_cache($url_api)
36          OR !$json_story = json_decode($json_story,true))
37                return 404;
38
39        $nbs = array_sum($json_story['content']['stats']['elements']);
40        $total_page = intval(ceil($nbs/50));
41        // et les pages suivantes jusqu'a un max raisonable
42        $page=2;
43        do {
44                if ($sub_story = recuperer_page_cache(parametre_url($url_api,'page',$page++,'&'))
45                        AND $sub_story = json_decode($sub_story,true)){
46                        $json_story['content']['elements'] = array_merge($json_story['content']['elements'],$sub_story['content']['elements']);
47                }
48        } while ($sub_story AND count($sub_story['content']['elements']) AND $page<$total_page);
49
50        $title = $json_story['content']['title'];
51
52
53        $result = array(
54                // type (required)
55    // The resource type. Valid values, along with value-specific parameters, are described below.
56                'type' => 'rich',
57
58                // version (required)
59    // The oEmbed version number. This must be 1.0.
60                'version' => '1.0',
61
62                // title (optional)
63    // A text title, describing the resource.
64                'title' => $title,
65
66                // html (required)
67    // The HTML required to display the resource. The HTML should have no padding or margins. Consumers may wish to load the HTML in an off-domain iframe to avoid XSS vulnerabilities. The markup should be valid XHTML 1.0 Basic.
68                'html' => recuperer_fond('modeles/oeproxy/storify',$json_story),
69
70                // width (required)
71    // The width in pixels required to display the HTML.
72                'width' => ($options['width']?$options['width']:'300'),
73
74                // height (required)
75    // The height in pixels required to display the HTML.
76                'height' => ($options['height']?$options['height']:'100'),
77
78                // author_name (optional)
79    // The name of the author/owner of the resource.
80                'author_name' => $json_story['author']['name'],
81
82                // author_url (optional)
83    // A URL for the author/owner of the resource.
84                'author_url' => $json_story['author']['permalink'],
85
86
87                // thumbnail_url (optional)
88    // A URL to a thumbnail image representing the resource. The thumbnail must respect any maxwidth and maxheight parameters. If this paramater is present, thumbnail_width and thumbnail_height must also be present.
89                //'thumbnail_url' => $contexte['picture'],
90
91                // thumbnail_width (optional)
92    // The width of the optional thumbnail. If this paramater is present, thumbnail_url and thumbnail_height must also be present.
93                //'thumbnail_width' => 50,
94
95                // thumbnail_height (optional)
96    // The height of the optional thumbnail. If this paramater is present, thumbnail_url and thumbnail_width must also be present.
97                //'thumbnail_height' => 50,
98
99        );
100#echo $result['html'];
101#       die();
102        return $result;
103}
Note: See TracBrowser for help on using the repository browser.