Browse Source

PSR SPIP

svn/attic/oembed/119131
kent1@arscenic.info 5 years ago
parent
commit
c3956cad8b
  1. 53
      action/api_oembed.php
  2. 190
      action/oembed_nettoyer_iframes.php
  3. 139
      inc/oembed.php
  4. 32
      inc/oembed_recuperer_url.php
  5. 17
      inc/ressource.php
  6. 6
      modeles/oembed_fonctions.php
  7. 8
      oembed/input/posttraite_huffduffer_rich.php
  8. 12
      oembed/input/posttraite_instagram_rich.php
  9. 8
      oembed/input/posttraite_issuu.php
  10. 8
      oembed/input/posttraite_oeproxy_default_rich.php
  11. 11
      oembed/input/posttraite_oeproxy_imdb_rich.php
  12. 12
      oembed/input/posttraite_office_national_du_film_du_canada_video.php
  13. 8
      oembed/input/posttraite_rdio_rich.php
  14. 10
      oembed/input/posttraite_slideshare_rich.php
  15. 19
      oembed/input/posttraite_soundcloud_rich.php
  16. 10
      oembed/input/posttraite_twitter.php
  17. 20
      oembed/input/posttraite_youtube_video.php
  18. 10
      oembed/input/pretraite_www_youtube_com.php
  19. 15
      oembed/output/json.php
  20. 29
      oembed/output/xml.php
  21. 60
      oembed_administrations.php
  22. 102
      oembed_fonctions.php
  23. 129
      oembed_pipelines.php

53
action/api_oembed.php

@ -5,9 +5,11 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function action_api_oembed_dist(){
function action_api_oembed_dist() {
$args = array(
'url' => $url = _request('url'),
@ -19,50 +21,49 @@ function action_api_oembed_dist(){
);
// Un pipeline pour pouvoir manipuler les arguments (en ajouter des spécifiques par ex.)
$args = pipeline('oembed_liste_arguments',$args);
$args = pipeline('oembed_liste_arguments', $args);
$format = ($args['format']=='xml'?'xml':'json');
$md5 = md5(serialize($args));
$oembed_cache = sous_repertoire(_DIR_CACHE,substr($md5,0,1))."oe-".$md5.".".$format;
$oembed_cache = sous_repertoire(_DIR_CACHE, substr($md5, 0, 1)). 'oe-'.$md5.'.'.$format;
// si cache oembed dispo et pas de recalcul demande, l'utiliser (perf issue)
if (file_exists($oembed_cache)
AND _VAR_MODE!=='recalcul'
AND (!defined('_VAR_NOCACHE') OR !_VAR_NOCACHE)){
lire_fichier($oembed_cache,$res);
}
else {
and _VAR_MODE!=='recalcul'
and (!defined('_VAR_NOCACHE')
or !_VAR_NOCACHE)) {
lire_fichier($oembed_cache, $res);
} else {
include_spip('inc/urls');
define('_DEFINIR_CONTEXTE_TYPE_PAGE',true);
list($fond,$contexte,$url_redirect) = urls_decoder_url($url,'',$args);
define('_DEFINIR_CONTEXTE_TYPE_PAGE', true);
list($fond, $contexte, $url_redirect) = urls_decoder_url($url, '', $args);
if (!isset($contexte['type-page'])
OR !$type=$contexte['type-page'])
return "";
or !$type = $contexte['type-page']) {
return '';
}
$res = "";
$res = '';
// chercher le modele json si il existe
if (trouver_fond($f="oembed/output/modeles/$type.json")){
$res = trim(recuperer_fond($f,$contexte));
if (trouver_fond($f = "oembed/output/modeles/$type.json")) {
$res = trim(recuperer_fond($f, $contexte));
if ($format=='xml'){
$res = json_decode($res,true);
$output = charger_fonction("xml","oembed/output");
if ($format=='xml') {
$res = json_decode($res, true);
$output = charger_fonction('xml', 'oembed/output');
$res = $output($res, false);
}
}
ecrire_fichier($oembed_cache,$res);
ecrire_fichier($oembed_cache, $res);
}
if (!$res) {
include_spip('inc/headers');
http_status(404);
echo "404 Not Found";
}
else {
$content_type = ($format=='xml'?"text/xml":"application/json");
echo '404 Not Found';
} else {
$content_type = ($format=='xml' ? 'text/xml' : 'application/json');
header("Content-type: $content_type; charset=utf-8");
echo $res;
}
}
}

190
action/oembed_nettoyer_iframes.php

@ -5,7 +5,9 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
@ -13,200 +15,198 @@ if (!defined('_ECRIRE_INC_VERSION')) return;
* appeler manuellement avec ?action=oembed_nettoyer_iframes
* autorise pour les seuls webmestres
*/
function action_oembed_nettoyer_iframes_dist(){
function action_oembed_nettoyer_iframes_dist() {
include_spip('inc/autoriser');
include_spip('inc/filtres');
include_spip('action/editer_objet');
if (!autoriser('webmestre')){
if (!autoriser('webmestre')) {
die('Pas autorise');
}
echo "<h1>Conversion des &lt;iframe&gt; en liens oembed</h1>";
echo '<h1>Conversion des &lt;iframe&gt; en liens oembed</h1>';
$simu = true;
if (_request('modif')) $simu=false;
if ($simu) echo "<p><strong>mode SIMULATION</strong> (ajoutez &modif=1 dans l'url pour modifier les contenus)</p>";
if (_request('modif')) {
$simu = false;
}
if ($simu) {
echo "<p><strong>mode SIMULATION</strong> (ajoutez &modif=1 dans l'url pour modifier les contenus)</p>";
}
$tables = array(
'spip_articles'=>array('descriptif','chapo','texte','ps'),
);
foreach ($tables as $table=>$champs){
foreach ($tables as $table => $champs) {
$objet = objet_type($table);
foreach($champs as $champ){
foreach ($champs as $champ) {
$primary = id_table_objet($table);
$res = sql_select("$primary,$champ", $table, "$champ LIKE '%iframe%' OR $champ LIKE '%object%'");
while ($row = sql_fetch($res)){
while ($row = sql_fetch($res)) {
$pre = "$primary=".$row[$primary].":$champ:";
$texte = $row[$champ];
$iframes = extraire_balises($texte, "iframe");
if (count($iframes)){
foreach ($iframes as $iframe){
$url = "";
$src = extraire_attribut($iframe, "src");
if (strncmp($src, "//", 2)==0)
$src = "http:" . $src;
if (strpos($iframe, "youtube")!==false){
if (strpos($src, "/embed/")!==false){
$url = str_replace("?", "&", $src);
$url = str_replace("/embed/", "/watch?v=", $url);
$iframes = extraire_balises($texte, 'iframe');
if (count($iframes)) {
foreach ($iframes as $iframe) {
$url = '';
$src = extraire_attribut($iframe, 'src');
if (strncmp($src, '//', 2) == 0) {
$src = 'http:' . $src;
}
if (strpos($iframe, 'youtube') !== false) {
if (strpos($src, '/embed/') !== false) {
$url = str_replace('?', '&', $src);
$url = str_replace('/embed/', '/watch?v=', $url);
echo "$pre Youtube $url<br />";
}
if (!$url){
if (!$url) {
var_dump($row);
var_dump(entites_html($iframe));
die('youtube inconnue');
}
} elseif (strpos($iframe, "dailymotion")!==false) {
if (strpos($src, "/embed/")!==false){
$url = str_replace("/embed/", "/", $src);
$url = explode("?",$url);
} elseif (strpos($iframe, 'dailymotion') !== false) {
if (strpos($src, '/embed/') !== false) {
$url = str_replace('/embed/', '/', $src);
$url = explode('?', $url);
$url = reset($url);
#var_dump($url);
echo "$pre DailyMotion $url<br />";
}
if (!$url){
if (!$url) {
var_dump($row);
var_dump($iframe);
die('dailymotion inconnue');
}
} elseif (strpos($iframe, "player.vimeo")!==false) {
if (strpos($src, "/video/")!==false){
$url = str_replace("/video/", "/", $src);
$url = str_replace("player.vimeo","vimeo",$url);
$url = explode("?",$url);
} elseif (strpos($iframe, 'player.vimeo') !== false) {
if (strpos($src, '/video/')!==false) {
$url = str_replace('/video/', '/', $src);
$url = str_replace('player.vimeo', 'vimeo', $url);
$url = explode('?', $url);
$url = reset($url);
#var_dump($url);
echo "$pre Vimeo $url<br />";
}
if (!$url){
if (!$url) {
var_dump($row);
var_dump($iframe);
die('vimeo inconnue');
}
} elseif (strpos($iframe, "soundcloud")!==false) {
} elseif (strpos($iframe, 'soundcloud') !== false) {
// un peu complique :
// il faut faire une requete oembed sur l'url api, avec iframe=false
// pour recuperer du html avec un lien vers la page soundcloud
parse_str(end(explode("?",$src)),$args);
parse_str(end(explode('?', $src)), $args);
$api_url = $args['url'];
include_spip("inc/oembed");
include_spip("inc/distant");
include_spip('inc/oembed');
include_spip('inc/distant');
$provider = oembed_verifier_provider($api_url);
$data_url = parametre_url(url_absolue($provider['endpoint'],url_de_base()),'url',$api_url,'&');
$data_url = parametre_url($data_url,'format','json','&');
$data_url = parametre_url($data_url,'iframe','false','&');
$data_url = parametre_url(url_absolue($provider['endpoint'], url_de_base()), 'url', $api_url, '&');
$data_url = parametre_url($data_url, 'format', 'json', '&');
$data_url = parametre_url($data_url, 'iframe', 'false', '&');
$json = recuperer_page($data_url);
$json = json_decode($json,true);
$link = extraire_balise($json['html'],'a');
if ($url = extraire_attribut($link,"href")){
$json = json_decode($json, true);
$link = extraire_balise($json['html'], 'a');
if ($url = extraire_attribut($link, 'href')) {
echo "$pre SoundCloud $url<br />";
}
if (!$url){
if (!$url) {
var_dump($row);
var_dump($iframe);
die('soundcloud inconnue');
}
} else {
echo "$pre iframe inconnue : ".entites_html($iframe)."<br />";
echo "$pre iframe inconnue : ".entites_html($iframe).'<br />';
}
if ($url){
if ($url) {
$texte = str_replace($iframe, "\n\n" . $url . "\n\n", $texte);
if (preg_match(",<center>\s*" . preg_quote($url, ",") . ".*</center>,Uims", $texte, $m)){
if (preg_match(',<center>\s*' . preg_quote($url, ',') . '.*</center>,Uims', $texte, $m)) {
$texte = str_replace($m[0], "\n\n" . $url . "\n\n", $texte);
}
$texte = preg_replace(",\s+" . preg_quote($url, ",") . "\s+,ims", "\n\n" . $url . "\n\n", $texte);
$texte = preg_replace(',\s+' . preg_quote($url, ',') . '\s+,ims', "\n\n" . $url . "\n\n", $texte);
}
}
if ($texte!==$row[$champ]){
if ($texte!==$row[$champ]) {
echo "$pre Corrige $champ <br />";
if (!$simu) {
echo "$pre Corrige $champ <br />";
objet_modifier($objet,$row[$primary],array($champ=>$texte));
}
else {
objet_modifier($objet, $row[$primary], array($champ=>$texte));
} else {
echo "SIMU : $pre Corrige $champ <br />";
}
}
}
$objects = extraire_balises($texte, "object");
if (count($objects)){
foreach ($objects as $object){
$url = "";
$embed = extraire_balise($object, "embed");
$src = extraire_attribut($embed, "src");
if (strncmp($src, "//", 2)==0)
$src = "http:" . $src;
if (strpos($embed, "youtube")!==false){
if (strpos($src, "/v/")!==false){
$url = str_replace("?", "&", $src);
$url = str_replace("/v/", "/watch?v=", $url);
$objects = extraire_balises($texte, 'object');
if (count($objects)) {
foreach ($objects as $object) {
$url = '';
$embed = extraire_balise($object, 'embed');
$src = extraire_attribut($embed, 'src');
if (strncmp($src, '//', 2) == 0) {
$src = 'http:' . $src;
}
if (strpos($embed, 'youtube') !== false) {
if (strpos($src, '/v/') !== false) {
$url = str_replace('?', '&', $src);
$url = str_replace('/v/', '/watch?v=', $url);
echo "$pre Youtube $url<br />";
}
elseif (strpos($src, "/embed/")!==false){
$url = str_replace("?", "&", $src);
$url = str_replace("/embed/", "/watch?v=", $url);
} elseif (strpos($src, '/embed/') !== false) {
$url = str_replace('?', '&', $src);
$url = str_replace('/embed/', '/watch?v=', $url);
echo "$pre Youtube $url<br />";
}
if (!$url){
if (!$url) {
var_dump($row);
var_dump(entites_html($object));
die('youtube inconnue');
}
} elseif (strpos($embed, "dailymotion")!==false) {
if (strpos($src, "/swf/video/")!==false){
$url = str_replace("/swf/video/", "/video/", $src);
$url = explode("?",$url);
} elseif (strpos($embed, 'dailymotion') !== false) {
if (strpos($src, '/swf/video/') !== false) {
$url = str_replace('/swf/video/', '/video/', $src);
$url = explode('?', $url);
$url = reset($url);
#var_dump($url);
echo "$pre DailyMotion $url<br />";
}
elseif (strpos($src, "/swf/")!==false){
$url = str_replace("/swf/", "/video/", $src);
$url = explode("?",$url);
} elseif (strpos($src, '/swf/') !== false) {
$url = str_replace('/swf/', '/video/', $src);
$url = explode('?', $url);
$url = reset($url);
#var_dump($url);
echo "$pre DailyMotion $url<br />";
}
if (!$url){
if (!$url) {
var_dump($row);
var_dump($object);
die('dailymotion inconnue');
}
}
elseif(strpos($embed,"vimeo.com")!==false){
if (strpos($src, "moogaloop")!==false
AND $id = parametre_url($src,"clip_id")){
} elseif (strpos($embed, 'vimeo.com') !== false) {
if (strpos($src, 'moogaloop') !== false
and $id = parametre_url($src, 'clip_id')) {
$url = "https://vimeo.com/$id";
echo "$pre Vimeo $url<br />";
}
if (!$url){
if (!$url) {
var_dump($row);
var_dump(entites_html($object));
die('vimeo inconnue');
}
}
elseif(preg_match(",^https?://,",$u=trim(strip_tags($object)))) {
} elseif (preg_match(',^https?://,', $u = trim(strip_tags($object)))) {
$url = $u;
echo "$pre Nettoyage Object url $url<br />";
} else {
echo "$pre object inconnue : ".entites_html($object).'<br />';
}
else {
echo "$pre object inconnue : ".entites_html($object)."<br />";
}
if ($url){
if ($url) {
$texte = str_replace($object, "\n\n" . $url . "\n\n", $texte);
if (preg_match(",<center>\s*" . preg_quote($url, ",") . ".*</center>,Uims", $texte, $m)){
if (preg_match(',<center>\s*' . preg_quote($url, ',') . '.*</center>,Uims', $texte, $m)) {
$texte = str_replace($m[0], "\n\n" . $url . "\n\n", $texte);
}
$texte = preg_replace(",\s+" . preg_quote($url, ",") . "\s+,ims", "\n\n" . $url . "\n\n", $texte);
$texte = preg_replace(',\s+' . preg_quote($url, ',') . '\s+,ims', "\n\n" . $url . "\n\n", $texte);
}
}
if ($texte!==$row[$champ]){
if ($texte!==$row[$champ]) {
if (!$simu) {
echo "$pre Corrige $champ <br />";
objet_modifier($objet,$row[$primary],array($champ=>$texte));
}
else {
objet_modifier($objet, $row[$primary], array($champ => $texte));
} else {
echo "SIMU : $pre Corrige $champ <br />";
}
}

139
inc/oembed.php

@ -5,13 +5,15 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Lister les providers connus
* @return array
*/
function oembed_lister_providers(){
function oembed_lister_providers() {
// liste des providers par defaut
@ -66,18 +68,18 @@ function oembed_lister_providers(){
'http://*.kickstarter.com/projects/*' => 'https://www.kickstarter.com/services/oembed',
'http://speakerdeck.com/*' => 'https://speakerdeck.com/oembed.json',
'http://issuu.com/*' => 'http://issuu.com/oembed',
'http://egliseinfo.catholique.fr/*' => 'http://egliseinfo.catholique.fr/api/oembed',
#'https://gist.github.com/*' => 'http://github.com/api/oembed?format=json'
);
// pipeline pour permettre aux plugins d'ajouter/supprimer/modifier des providers
$providers = pipeline('oembed_lister_providers',$providers);
$providers = pipeline('oembed_lister_providers', $providers);
// merger avec la globale pour perso mes_options dans un site
// pour supprimer un scheme il suffit de le renseigner avec un endpoint vide
if (isset($GLOBALS['oembed_providers'])){
if (isset($GLOBALS['oembed_providers'])) {
$providers = array_merge($providers, $GLOBALS['oembed_providers']);
// retirer les providers avec un endpoint vide
$providers = array_filter($providers);
@ -106,72 +108,82 @@ function oembed_lister_providers(){
function oembed_recuperer_data($url, $maxwidth = null, $maxheight = null, $format = 'json', $detecter_lien = 'non') {
static $cache = array();
$provider = false;
$provider = oembed_verifier_provider($url);
if ((!$provider)
AND (($detecter_lien != 'non') OR lire_config('oembed/detecter_lien','non')=='oui')) {
and (($detecter_lien != 'non')
or lire_config('oembed/detecter_lien', 'non') == 'oui')) {
$provider = oembed_detecter_lien($url);
}
if (!$provider)
if (!$provider) {
return false;
$data_url = parametre_url(url_absolue($provider['endpoint'],url_de_base()),'url',$url,'&');
}
$data_url = parametre_url(url_absolue($provider['endpoint'], url_de_base()), 'url', $url, '&');
include_spip('inc/config');
if (!$maxwidth){
$maxwidth = lire_config('oembed/maxwidth','600');
if (!$maxwidth) {
$maxwidth = lire_config('oembed/maxwidth', '600');
}
if (!$maxheight){
$maxheight = lire_config('oembed/maxheight','400');
if (!$maxheight) {
$maxheight = lire_config('oembed/maxheight', '400');
}
$data_url = parametre_url($data_url,'maxwidth',$maxwidth,'&');
$data_url = parametre_url($data_url,'maxheight',$maxheight,'&');
$data_url = parametre_url($data_url,'format',$format,'&');
$data_url = parametre_url($data_url, 'maxwidth', $maxwidth, '&');
$data_url = parametre_url($data_url, 'maxheight', $maxheight, '&');
$data_url = parametre_url($data_url, 'format', $format, '&');
// pre-traitement du provider si besoin
$endpoint = explode("//",$provider['endpoint']);
$endpoint = explode("/",$endpoint[1]);
$endpoint = explode('//', $provider['endpoint']);
$endpoint = explode('/', $endpoint[1]);
$endpoint = reset($endpoint);
$endpoint = preg_replace(",\W+,","_",$endpoint);
if ($oembed_endpoint_pretraite = charger_fonction("pretraite_$endpoint",'oembed/input',true)){
$endpoint = preg_replace(',\W+,', '_', $endpoint);
if ($oembed_endpoint_pretraite = charger_fonction("pretraite_$endpoint", 'oembed/input', true)) {
$a = func_get_args();
$args = array('url'=>array_shift($a));
if (count($a)) $args['maxwidth'] = array_shift($a);
if (count($a)) $args['maxheight'] = array_shift($a);
if (count($a)) $args['format'] = array_shift($a);
$data_url = $oembed_endpoint_pretraite($data_url,$args);
if (count($a)) {
$args['maxwidth'] = array_shift($a);
}
if (count($a)) {
$args['maxheight'] = array_shift($a);
}
if (count($a)) {
$args['format'] = array_shift($a);
}
$data_url = $oembed_endpoint_pretraite($data_url, $args);
}
if (isset($cache[$data_url]))
if (isset($cache[$data_url])) {
return $cache[$data_url];
}
$oembed_cache = sous_repertoire(_DIR_CACHE,'oembed').md5($data_url).".".$format;
$oembed_cache = sous_repertoire(_DIR_CACHE, 'oembed').md5($data_url). '.'.$format;
// si cache oembed dispo et pas de recalcul demande, l'utiliser (perf issue)
if (file_exists($oembed_cache) AND _VAR_MODE!=='recalcul'){
lire_fichier($oembed_cache,$cache[$data_url]);
if (file_exists($oembed_cache) and _VAR_MODE !== 'recalcul') {
lire_fichier($oembed_cache, $cache[$data_url]);
$cache[$data_url]=unserialize($cache[$data_url]);
return $cache[$data_url];
}
$oembed_recuperer_url = charger_fonction('oembed_recuperer_url','inc');
$cache[$data_url] = $oembed_recuperer_url($data_url,$url,$format);
$oembed_recuperer_url = charger_fonction('oembed_recuperer_url', 'inc');
$cache[$data_url] = $oembed_recuperer_url($data_url, $url, $format);
// si une fonction de post-traitement est fourni pour ce provider+type, l'utiliser
if ($cache[$data_url]){
$provider_name= str_replace(" ", "_", strtolower($cache[$data_url]['provider_name']));
if ($cache[$data_url]) {
$provider_name= str_replace(' ', '_', strtolower($cache[$data_url]['provider_name']));
$type = strtolower($cache[$data_url]['type']);
// securisons le nom de la fonction (provider peut contenir n'importe quoi)
$f1 = preg_replace(",\W,","","posttraite_{$provider_name}_$type");
$f2 = preg_replace(",\W,","","posttraite_{$provider_name}");
if ($oembed_provider_posttraite = charger_fonction($f1,'oembed/input',true)
OR $oembed_provider_posttraite = charger_fonction($f2,'oembed/input',true))
$cache[$data_url] = $oembed_provider_posttraite($cache[$data_url],$url);
$f1 = preg_replace(',\W,', '', "posttraite_{$provider_name}_$type");
$f2 = preg_replace(',\W,', '', "posttraite_{$provider_name}");
if ($oembed_provider_posttraite = charger_fonction($f1, 'oembed/input', true)
or $oembed_provider_posttraite = charger_fonction($f2, 'oembed/input', true)) {
$cache[$data_url] = $oembed_provider_posttraite($cache[$data_url], $url);
}
ecrire_fichier($oembed_cache,serialize($cache[$data_url]));
ecrire_fichier($oembed_cache, serialize($cache[$data_url]));
}
spip_log('infos oembed pour '.$url.' : '.var_export($cache[$data_url],true),'oembed.'._LOG_DEBUG);
spip_log('infos oembed pour '.$url.' : '.var_export($cache[$data_url], true), 'oembed.'._LOG_DEBUG);
return $cache[$data_url];
}
@ -184,12 +196,13 @@ function oembed_recuperer_data($url, $maxwidth = null, $maxheight = null, $forma
* false si non ; details du provider dans un tabeau associatif si oui
*/
function oembed_verifier_provider($url) {
if (strncmp($url,$GLOBALS['meta']['adresse_site'],strlen($GLOBALS['meta']['adresse_site']))==0)
if (strncmp($url, $GLOBALS['meta']['adresse_site'], strlen($GLOBALS['meta']['adresse_site'])) == 0) {
return false;
}
$providers = oembed_lister_providers();
foreach ($providers as $scheme=>$endpoint) {
foreach ($providers as $scheme => $endpoint) {
$regex = '#' . str_replace('\*', '(.+)', preg_quote($scheme, '#')) . '#';
$regex = preg_replace( '|^#http\\\://|', '#https?\://', $regex );
$regex = preg_replace('|^#http\\\://|', '#https?\://', $regex);
if (preg_match($regex, $url)) {
return array('endpoint' => $endpoint);
}
@ -209,7 +222,6 @@ function oembed_detecter_lien($url) {
// on recupere le contenu de la page
include_spip('inc/distant');
if ($html = recuperer_page($url)) {
// types de liens oembed à détecter
$linktypes = array(
'application/json+oembed' => 'json',
@ -219,7 +231,7 @@ function oembed_detecter_lien($url) {
);
// on ne garde que le head de la page
$head = substr($html,0,stripos($html,'</head>'));
$head = substr($html, 0, stripos($html, '</head>'));
// un test rapide...
$tagfound = false;
@ -232,25 +244,27 @@ function oembed_detecter_lien($url) {
if ($tagfound && preg_match_all('/<link([^<>]+)>/i', $head, $links)) {
foreach ($links[0] as $link) {
$type = extraire_attribut($link,'type');
$href = extraire_attribut($link,'href');
if (!empty($type) AND !empty($linktypes[$type]) AND !empty($href)) {
$type = extraire_attribut($link, 'type');
$href = extraire_attribut($link, 'href');
if (!empty($type) and !empty($linktypes[$type]) and !empty($href)) {
$providers[$linktypes[$type]] = $href;
// on a le json, ça nous suffit
if ('json' == $linktypes[$type])
if ('json' == $linktypes[$type]) {
break;
}
}
}
}
}
// on préfère le json au xml
if (!empty($providers['json']))
if (!empty($providers['json'])) {
return array('endpoint'=>$providers['json']);
elseif (!empty($providers['xml']))
return array('endpoint'=>$providers['xml']);
else
} elseif (!empty($providers['xml'])) {
return array('endpoint' => $providers['xml']);
} else {
return false;
}
}
@ -259,23 +273,24 @@ function oembed_detecter_lien($url) {
* @param string $lien
* @return string
*/
function oembed_embarquer_lien($lien){
function oembed_embarquer_lien($lien) {
static $base = null;
$url = extraire_attribut($lien, 'href');
$texte = null;
if ($url
AND (
and (
oembed_verifier_provider($url)
OR (lire_config('oembed/detecter_lien','non')=='oui'))
){
if (is_null($base))
or (lire_config('oembed/detecter_lien', 'non') == 'oui'))
) {
if (is_null($base)) {
$base = url_de_base();
}
// on embarque jamais un lien de soi meme car c'est une mise en abime qui donne le tourni
// (et peut provoquer une boucle infinie de requetes http)
if (strncmp($url,$base,strlen($base))!=0){
$fond = recuperer_fond('modeles/oembed',array('url'=>$url,'lien'=>$lien));
if ($fond = trim($fond)){
if (strncmp($url, $base, strlen($base)) != 0) {
$fond = recuperer_fond('modeles/oembed', array('url' => $url, 'lien' => $lien));
if ($fond = trim($fond)) {
$texte = $fond;
}
}
@ -283,5 +298,3 @@ function oembed_embarquer_lien($lien){
return $texte;
}
?>

32
inc/oembed_recuperer_url.php

@ -5,7 +5,9 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Recuperer une URL oembed, si possible via curl et IPv4 pour contourner le bug de Youtube sur les IPv6
@ -15,23 +17,23 @@ if (!defined('_ECRIRE_INC_VERSION')) return;
* @param string $format
* @return bool|mixed|string
*/
function inc_oembed_recuperer_url($oembed_url,$url,$format){
function inc_oembed_recuperer_url($oembed_url, $url, $format) {
$data = false;
// on recupere le contenu de la page
// si possible via curl en IPv4 car youtube bug en IPv6
// uniquement si PHP >= 5.3.0 pour utiliser l'option CURLOPT_IPRESOLVE
if (function_exists('curl_init') and version_compare(phpversion(), '5.3.0', '>=')) {
spip_log('Requete oembed (curl) pour '.$url.' : '.$oembed_url,'oembed.'._LOG_DEBUG);
spip_log('Requete oembed (curl) pour '.$url.' : '.$oembed_url, 'oembed.'._LOG_DEBUG);
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $oembed_url);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
if (isset($GLOBALS['meta']["http_proxy"]) AND $GLOBALS['meta']["http_proxy"]){
curl_setopt($c, CURLOPT_PROXY, $GLOBALS['meta']["http_proxy"]);
if (isset($GLOBALS['meta']["http_noproxy"])){
curl_setopt($c, CURLOPT_NOPROXY, $GLOBALS['meta']["http_proxy"]);
if (isset($GLOBALS['meta']['http_proxy']) and $GLOBALS['meta']['http_proxy']) {
curl_setopt($c, CURLOPT_PROXY, $GLOBALS['meta']['http_proxy']);
if (isset($GLOBALS['meta']['http_noproxy'])) {
curl_setopt($c, CURLOPT_NOPROXY, $GLOBALS['meta']['http_proxy']);
}
}
@ -39,23 +41,23 @@ function inc_oembed_recuperer_url($oembed_url,$url,$format){
// http://stackoverflow.com/questions/26089067/youtube-oembed-api-302-then-503-errors
curl_setopt($c, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$data = curl_exec($c);
$status = curl_getinfo($c,CURLINFO_HTTP_CODE);
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
}
else {
spip_log('Requete oembed (recuperer_page) pour '.$url.' : '.$oembed_url,'oembed.'._LOG_DEBUG);
} else {
spip_log('Requete oembed (recuperer_page) pour '.$url.' : '.$oembed_url, 'oembed.'._LOG_DEBUG);
include_spip('inc/distant');
$data = recuperer_page($oembed_url);
}
spip_log('infos oembed brutes pour '.$url.' : '.($data?$data:'ECHEC'),'oembed.'._LOG_DEBUG);
spip_log('infos oembed brutes pour '.$url.' : '.($data?$data:'ECHEC'), 'oembed.'._LOG_DEBUG);
if ($data) {
if ($format == 'json')
$data = json_decode($data,true);
if ($format == 'json') {
$data = json_decode($data, true);
}
// TODO : format xml
//if ($format == 'xml')
// $cache[$oembed_url] = false;
}
return $data;
}
}

17
inc/ressource.php

@ -2,22 +2,23 @@
/*
* transforme un raccourci de ressource en un joli html a embed
*
*
*
*/
define('_EXTRAIRE_RESSOURCES', ',' . '<"?(https?://|[\w -]+\.[\w -]+).*>'.',UimsS');
function traiter_ressources($r) {
if ($ressource = charger_fonction('ressource', 'inc', true))
if ($ressource = charger_fonction('ressource', 'inc', true)) {
$html = $ressource($r[0]);
else
} else {
$html = htmlspecialchars($r[0]);
}
return '<html>'.$html.'</html>';
}
function inc_ressource_dist($html){
function inc_ressource_dist($html) {
return tw_traiter_ressources(array(0=>$html));
}
@ -29,18 +30,18 @@ function tw_traiter_ressources($r) {
$url = $url[0];
# <http://url/absolue>
if (preg_match(',^https?://,i', $url)) {
$html = PtoBR(propre("<span class='ressource spip_out'>&lt;[->" . $url . "]&gt;</span>"));
$html = PtoBR(propre("<span class='ressource spip_out'>&lt;[->" . $url . ']&gt;</span>'));
} # <url/relative>
else {
if (false !== strpos($url, '/')) {
$html = PtoBR(propre("<span class='ressource spip_in'>&lt;[->" . $url . "]&gt;</span>"));
$html = PtoBR(propre("<span class='ressource spip_in'>&lt;[->" . $url . ']&gt;</span>'));
} # <fichier.rtf>
else {
preg_match(',\.([^.]+)$,', $url, $regs);
if (file_exists($f = _DIR_IMG . $regs[1] . '/' . $url)) {
$html = PtoBR(propre("<span class='ressource spip_in'>&lt;[" . $url . "->" . $f . "]&gt;</span>"));
$html = PtoBR(propre("<span class='ressource spip_in'>&lt;[" . $url . '->' . $f . ']&gt;</span>'));
} else {
$html = PtoBR(propre("<span class='ressource'>&lt;" . $url . "&gt;</span>"));
$html = PtoBR(propre("<span class='ressource'>&lt;" . $url . '&gt;</span>'));
}
}
}

6
modeles/oembed_fonctions.php

@ -5,8 +5,8 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
include_spip('inc/oembed');
?>

8
oembed/input/posttraite_huffduffer_rich.php

@ -5,11 +5,13 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_huffduffer_rich_dist($data){
function oembed_input_posttraite_huffduffer_rich_dist($data) {
$data['media'] = 'audio';
return $data;
}
}

12
oembed/input/posttraite_instagram_rich.php

@ -5,16 +5,18 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_instagram_rich_dist($data){
function oembed_input_posttraite_instagram_rich_dist($data) {
#var_dump($data);
// Instagram est un fournisseur de photo, on ne veut pas de leur mouchard iframe+js sociaux
$data['media'] = 'image';
if (isset($data['thumbnail_url'])
AND isset($data['thumbnail_width'])
AND isset($data['thumbnail_height'])){
and isset($data['thumbnail_width'])
and isset($data['thumbnail_height'])) {
$data['type'] = 'photo';
$data['url'] = $data['thumbnail_url'];
$data['width'] = $data['thumbnail_width'];
@ -22,4 +24,4 @@ function oembed_input_posttraite_instagram_rich_dist($data){
}
return $data;
}
}

8
oembed/input/posttraite_issuu.php

@ -5,10 +5,12 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_issuu_dist($data, $url){
function oembed_input_posttraite_issuu_dist($data, $url) {
// le thumbnail génère un bloc avec un arrière plan tout moche
$data['thumbnail_url'] = '';
return $data;
}
}

8
oembed/input/posttraite_oeproxy_default_rich.php

@ -5,11 +5,13 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_oeproxy_default_rich_dist($data, $url){
function oembed_input_posttraite_oeproxy_default_rich_dist($data, $url) {
#$data['html'] = "<blockquote class='spip oe-cite' cite='$url'>".$data['html']."</blockquote>";
return $data;
}
}

11
oembed/input/posttraite_oeproxy_imdb_rich.php

@ -5,12 +5,13 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
function oembed_input_posttraite_oeproxy_imdb_rich_dist($data, $url){
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_oeproxy_imdb_rich_dist($data, $url) {
include_spip('inc/filtres');
$data['html'] = filtrer('image_reduire',$data['html'],75,100);
$data['html'] = filtrer('image_reduire', $data['html'], 75, 100);
return $data;
}
}

12
oembed/input/posttraite_office_national_du_film_du_canada_video.php

@ -5,11 +5,13 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_office_national_du_film_du_canada_video_dist($data){
$data['html'] = htmlspecialchars_decode(preg_replace(",&lt;p.*/p&gt;,",'',$data['html']));
function oembed_input_posttraite_office_national_du_film_du_canada_video_dist($data) {
$data['html'] = htmlspecialchars_decode(preg_replace(',&lt;p.*/p&gt;,', '', $data['html']));
return $data;
}
}

8
oembed/input/posttraite_rdio_rich.php

@ -5,11 +5,13 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_rdio_rich_dist($data){
function oembed_input_posttraite_rdio_rich_dist($data) {
$data['media'] = 'audio';
return $data;
}
}

10
oembed/input/posttraite_slideshare_rich.php

@ -5,13 +5,15 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_slideshare_rich_dist($data){
function oembed_input_posttraite_slideshare_rich_dist($data) {
if (!isset($data['thumbnail_url']) AND isset($data['thumbnail'])){
if (!isset($data['thumbnail_url']) and isset($data['thumbnail'])) {
$data['thumbnail_url'] = _DIR_RACINE . copie_locale($data['thumbnail']);
}
return $data;
}
}

19
oembed/input/posttraite_soundcloud_rich.php

@ -5,19 +5,20 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_soundcloud_rich_dist($data){
function oembed_input_posttraite_soundcloud_rich_dist($data) {
$data['media'] = 'audio';
$data['html'] = preg_replace(",width=['\"][0-9]+['\"],i",'width="100%"',$data['html']);
$data['html'] = preg_replace(",width=['\"][0-9]+['\"],i", 'width="100%"', $data['html']);
if (!isset($data['thumbnail_url'])){
$data['thumbnail_url'] = find_in_path("oembed/input/vignettes/soundcloud.png");
}
else {
$data['thumbnail_url'] = preg_replace(',^http://,Uims','https://',$data['thumbnail_url']);
if (!isset($data['thumbnail_url'])) {
$data['thumbnail_url'] = find_in_path('oembed/input/vignettes/soundcloud.png');
} else {
$data['thumbnail_url'] = preg_replace(',^http://,Uims', 'https://', $data['thumbnail_url']);
}
return $data;
}
}

10
oembed/input/posttraite_twitter.php

@ -5,11 +5,13 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_twitter_dist($data){
function oembed_input_posttraite_twitter_dist($data) {
$data['html'] = trim(preg_replace(",<script[^>]*></script>,i",'',$data['html']));
$data['html'] = trim(preg_replace(',<script[^>]*></script>,i', '', $data['html']));
return $data;
}
}

20
oembed/input/posttraite_youtube_video.php

@ -5,26 +5,30 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_posttraite_youtube_video_dist($data,$url_orig){
function oembed_input_posttraite_youtube_video_dist($data, $url_orig) {
$html = $data['html'];
if ($e = extraire_balise($html,'embed')
AND $src = extraire_attribut($e,'src')){
if ($e = extraire_balise($html, 'embed')
and $src = extraire_attribut($e, 'src')) {
$data['url'] = $src;
}
// On regarde si l'attribut rel est placé dans l'URL
// pour éviter l'affichage des vidéo liées à la fin de la vidéo
if (strpos($url_orig,"&rel=0") OR strpos($url_orig, "?rel=0"))
if (strpos($url_orig, '&rel=0') or strpos($url_orig, '?rel=0')) {
$data['html'] = str_replace('feature=oembed', 'feature=oembed&rel=0', $data['html']);
}
// On regarde si l'attribut wmode=opaque est placé dans l'URL
// pour forcer l'affichage des vidéo au bon z-index
if (strpos(strtolower($url_orig),"&wmode=opaque") OR strpos(strtolower($url_orig), "?wmode=opaque"))
if (strpos(strtolower($url_orig), '&wmode=opaque') or strpos(strtolower($url_orig), '?wmode=opaque')) {
$data['html'] = str_replace('feature=oembed', 'feature=oembed&wmode=Opaque', $data['html']);
}
// un bug chez youtube ?
$data['html'] = rtrim($data['html'],")");
$data['html'] = rtrim($data['html'], ')');
return $data;
}
}

10
oembed/input/pretraite_www_youtube_com.php

@ -5,11 +5,13 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_input_pretraite_www_youtube_com_dist($data_url,$args){
function oembed_input_pretraite_www_youtube_com_dist($data_url, $args) {
$data_url = parametre_url($data_url,"scheme","https","&");
$data_url = parametre_url($data_url, 'scheme', 'https', '&');
return $data_url;
}
}

15
oembed/output/json.php

@ -5,20 +5,25 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Generer une sortie json a partit d'un tableau associatif
* @param array $res
* @param bool $output
* @return void|string
*/
function oembed_output_json_dist($res, $output=true){
function oembed_output_json_dist($res, $output = true) {
$out = json_encode($res);
$out = str_replace(array("<",">"),array("\u003C","\u003E"),$out);
$out = str_replace(array('<', '>'), array('\u003C', '\u003E'), $out);
if (!$output)
if (!$output) {
return $out;
}
header("Content-type: application/json; charset=utf-8");
header('Content-type: application/json; charset=utf-8');
echo $out;
}
}

29
oembed/output/xml.php

@ -5,6 +5,10 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
include_spip('inc/filtres');
/**
@ -13,16 +17,17 @@ include_spip('inc/filtres');
* @param bool $output
* @return void|string
*/
function oembed_output_xml_dist($res, $output=true){
function oembed_output_xml_dist($res, $output = true) {
$out = '<'.'?xml version="1.0" encoding="utf-8" standalone="yes"?>'."\n";
$out .= "<oembed>";
$out .= oembed_assocToXML($res,0);
$out .= '<oembed>';
$out .= oembed_assocToXML($res, 0);
$out .= "\n</oembed>\n";
if (!$output)
if (!$output) {
return $out;
}
header("Content-type: text/xml; charset=utf-8");
header('Content-type: text/xml; charset=utf-8');
echo $out;
}
@ -36,22 +41,22 @@ function oembed_output_xml_dist($res, $output=true){
* @param : $theArray - The jagged Associative Array
* @param : $tabCount - for persisting tab count across recursive function calls
*/
function oembed_assocToXML($theArray, $tabCount = 2){
function oembed_assocToXML($theArray, $tabCount = 2) {
//echo "The Array: ";
//var_dump($theArray);
// variables for making the XML output easier to read
// with human eyes, with tabs delineating nested relationships, etc.
$theXML = "";
$theXML = '';
$tabCount++;
$tabSpace = "";
for ($i = 0; $i<$tabCount; $i++){
$tabSpace = '';
for ($i = 0; $i<$tabCount; $i++) {
$tabSpace .= "\t";
}
// parse the array for data and output xml
foreach ($theArray as $tag => $val){
if (!is_array($val)){
foreach ($theArray as $tag => $val) {
if (!is_array($val)) {
$theXML .= PHP_EOL
.$tabSpace
.'<'.$tag.'>'.
@ -66,5 +71,3 @@ function oembed_assocToXML($theArray, $tabCount = 2){
return $theXML;
}
?>

60
oembed_administrations.php

@ -1,30 +1,30 @@
<?php
/**
* Plugin oEmbed
* Licence GPL3
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
function oembed_upgrade($nom_meta_base_version,$version_cible){
$maj = array();
$maj['create'] = array(
array('sql_alter',"TABLE spip_documents ADD oembed text NOT NULL DEFAULT ''"),
);
// toujours un update des nouveaux providers sur la version cible
$maj[$version_cible] = array(
array('sql_drop_table',"spip_oembed_providers"),
);
include_spip('base/upgrade');
maj_plugin($nom_meta_base_version, $version_cible, $maj);
}
function oembed_vider_tables($nom_meta_base_version) {
sql_drop_table("spip_oembed_providers");
effacer_meta($nom_meta_base_version);
}
?>
<?php
/**
* Plugin oEmbed
* Licence GPL3
*
*/
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function oembed_upgrade($nom_meta_base_version, $version_cible) {
$maj = array();
$maj['create'] = array(
array('sql_alter',"TABLE spip_documents ADD oembed text NOT NULL DEFAULT ''"),
);
// toujours un update des nouveaux providers sur la version cible
$maj[$version_cible] = array(
array('sql_drop_table', 'spip_oembed_providers'),
);
include_spip('base/upgrade');
maj_plugin($nom_meta_base_version, $version_cible, $maj);
}
function oembed_vider_tables($nom_meta_base_version) {
sql_drop_table('spip_oembed_providers');
effacer_meta($nom_meta_base_version);
}

102
oembed_fonctions.php

@ -5,16 +5,24 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
// renvoyer un mim_type text/oembed pour les videos oembed
function mime_type_oembed($id_document) {
if(!($id_document = intval($id_document)))
if (!($id_document = intval($id_document))) {
return '';
$mime_type = sql_getfetsel('mime_type', 'spip_types_documents',
"extension IN (SELECT extension FROM spip_documents where id_document=$id_document)");
if ($mime_type == 'text/html' AND sql_getfetsel('oembed', 'spip_documents',"id_document=$id_document"))
}
$mime_type = sql_getfetsel(
'mime_type',
'spip_types_documents',
"extension IN (SELECT extension FROM spip_documents where id_document=$id_document)"
);
if ($mime_type == 'text/html'
and sql_getfetsel('oembed', 'spip_documents', "id_document=$id_document")) {
$mime_type = 'text/oembed';
}
return $mime_type;
}
@ -25,9 +33,9 @@ function balise_MIME_TYPE_dist($p) {
/**
* Si la clé est extension, on est dans une boucle sur la table spip_documents
*/
if($key == 'extension'){
if ($key == 'extension') {
$p->code = champ_sql('mime_type', $p);
}else{
} else {
/* explorer la pile memoire pour atteindre le 'vrai' champ */
$id_document = champ_sql('id_document', $p);
/* le code php qui sera execute */
@ -41,10 +49,10 @@ function balise_MIME_TYPE_dist($p) {
* @param $texte
* @return string
*/
function json_encode_html($texte){
function json_encode_html($texte) {
#$texte = json_encode($texte,JSON_HEX_TAG);
$texte = json_encode($texte);
$texte = str_replace(array("<",">"),array("\u003C","\u003E"),$texte);
$texte = str_replace(array('<', '>'), array('\u003C','\u003E'), $texte);
return $texte;
}
@ -57,15 +65,16 @@ function json_encode_html($texte){
* @param int $maxheight
* @return string
*/
function oembed($url, $maxwidth=0, $maxheight=0){
function oembed($url, $maxwidth = 0, $maxheight = 0) {
include_spip('inc/oembed');
if (oembed_verifier_provider($url)) {
$fond = recuperer_fond(
'modeles/oembed',
array('url'=>$url,'lien'=>'','maxwidth'=>$maxwidth,'maxheight'=>$maxheight)
array('url'=>$url, 'lien' => '', 'maxwidth' => $maxwidth, 'maxheight' => $maxheight)
);
if ($fond = trim($fond))
if ($fond = trim($fond)) {
return $fond;
}
}
return $url;
@ -77,38 +86,37 @@ function oembed($url, $maxwidth=0, $maxheight=0){
* @param $html
* @return mixed
*/
function oembed_force_video_autoplay($html){
if ($e = extraire_balise($html,'iframe')
AND $src = extraire_attribut($e,'src')){
$src_amp = parametre_url($src,"dummy",null);
if (strpos($src,"soundcloud")!==false)
$src_autoplay = parametre_url($src,"auto_play","1","&");
else
$src_autoplay = parametre_url($src,"autoplay","1","&");
if (strpos($html,$src_amp))
$html = str_replace($src_amp,$src_autoplay,$html);
else
$html = str_replace($src,$src_autoplay,$html);
function oembed_force_video_autoplay($html) {
if ($e = extraire_balise($html, 'iframe')
and $src = extraire_attribut($e, 'src')) {
$src_amp = parametre_url($src, 'dummy', null);
if (strpos($src, 'soundcloud') !== false) {
$src_autoplay = parametre_url($src, 'auto_play', '1', '&');
} else {
$src_autoplay = parametre_url($src, 'autoplay', '1', '&');
}
if (strpos($html, $src_amp)) {
$html = str_replace($src_amp, $src_autoplay, $html);
} else {
$html = str_replace($src, $src_autoplay, $html);
}
}
return $html;
}
include_spip('inc/ressource');
if (function_exists('inc_ressource_dist')){
if (function_exists('inc_ressource_dist')) {
// SPIP 3.1
function inc_ressource($rac){
function inc_ressource($rac) {
$html = oembed_traiter_ressource($rac);
if (is_null($html)) {
$html = inc_ressource_dist($rac);
}
return $html;
}
}
else {
} else {
// SPIP 3.0
function inc_ressource_dist($rac){
function inc_ressource_dist($rac) {
return oembed_traiter_ressource($rac);
}
}
@ -122,48 +130,46 @@ function oembed_traiter_ressource($rac) {
$texte = null;
# <http://url/absolue>
if (preg_match(',^https?://,i', $url)){
if (preg_match(',^https?://,i', $url)) {
include_spip('inc/oembed');
$lien = PtoBR(propre("[->".$url."]"));
$lien = PtoBR(propre('[->'.$url.']'));
// null si pas embedable
$texte = oembed_embarquer_lien($lien);
if ($texte){
if ($texte) {
$texte = "<html>$texte</html>";
}
}
// compat SPIP < 3.0.14
// sans le patch http://zone.spip.org/trac/spip-zone/changeset/79139/_core_/branches/spip-3.0/plugins/textwheel
if (is_null($texte)) {
if (is_null($null_allowed)){
if (version_compare($GLOBALS['spip_version_branche'],"3.0.14","<"))
if (is_null($null_allowed)) {
if (version_compare($GLOBALS['spip_version_branche'], '3.0.14', '<')) {
$null_allowed = false;
else
} else {
$null_allowed = true;
}
}
if(!$null_allowed){
if (