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

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

Proxy storify :
fixer une largeur maxi sur les oembed explicites
si un contenu link possede des infos oembed les utiliser de preference, grace au modele oembed correspondant au type de contenu
correction bug sur la pagination : la derniere page>2 manquait

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
42        // et les pages suivantes jusqu'a un max raisonable
43        $page=2;
44        do {
45                if ($sub_story = recuperer_page_cache(parametre_url($url_api,'page',$page++,'&'))
46                        AND $sub_story = json_decode($sub_story,true)){
47                        $json_story['content']['elements'] = array_merge($json_story['content']['elements'],$sub_story['content']['elements']);
48                }
49        } while ($sub_story AND count($sub_story['content']['elements']) AND $page<=$total_page);
50
51        $title = $json_story['content']['title'];
52
53
54        $result = array(
55                // type (required)
56    // The resource type. Valid values, along with value-specific parameters, are described below.
57                'type' => 'rich',
58
59                // version (required)
60    // The oEmbed version number. This must be 1.0.
61                'version' => '1.0',
62
63                // title (optional)
64    // A text title, describing the resource.
65                'title' => $title,
66
67                // html (required)
68    // 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.
69                'html' => recuperer_fond('modeles/oeproxy/storify',$json_story),
70
71                // width (required)
72    // The width in pixels required to display the HTML.
73                'width' => ($options['width']?$options['width']:'300'),
74
75                // height (required)
76    // The height in pixels required to display the HTML.
77                'height' => ($options['height']?$options['height']:'100'),
78
79                // author_name (optional)
80    // The name of the author/owner of the resource.
81                'author_name' => $json_story['author']['name'],
82
83                // author_url (optional)
84    // A URL for the author/owner of the resource.
85                'author_url' => $json_story['author']['permalink'],
86
87
88                // thumbnail_url (optional)
89    // 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.
90                //'thumbnail_url' => $contexte['picture'],
91
92                // thumbnail_width (optional)
93    // The width of the optional thumbnail. If this paramater is present, thumbnail_url and thumbnail_height must also be present.
94                //'thumbnail_width' => 50,
95
96                // thumbnail_height (optional)
97    // The height of the optional thumbnail. If this paramater is present, thumbnail_url and thumbnail_width must also be present.
98                //'thumbnail_height' => 50,
99
100        );
101#echo $result['html'];
102#       die();
103        return $result;
104}
Note: See TracBrowser for help on using the repository browser.