Browse Source

PSR

pull/4/head v2.3.3
Cerdic 11 months ago
parent
commit
780ee89ac6
  1. 18
      action/api_oembed.php
  2. 98
      action/oembed_nettoyer_iframes.php
  3. 213
      inc/oembed.php
  4. 29
      inc/oembed_recuperer_url.php
  5. 22
      inc/ressource.php
  6. 86
      oembed_fonctions.php
  7. 152
      oembed_pipelines.php
  8. 2
      paquet.xml

18
action/api_oembed.php

@ -5,11 +5,11 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) {
if (!defined('_ECRIRE_INC_VERSION')){
return;
}
function action_api_oembed_dist() {
function action_api_oembed_dist(){
$args = array(
'url' => $url = _request('url'),
@ -23,32 +23,32 @@ 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);
$format = ($args['format']=='xml'?'xml':'json');
$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)) {
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);
if (!isset($contexte['type-page'])
or !$type = $contexte['type-page']) {
or !$type = $contexte['type-page']){
return '';
}
$res = '';
// chercher le modele json si il existe
if (trouver_fond($f = "oembed/output/modeles/$type.json")) {
if (trouver_fond($f = "oembed/output/modeles/$type.json")){
$res = trim(recuperer_fond($f, $contexte));
if ($format=='xml') {
if ($format=='xml'){
$res = json_decode($res, true);
$output = charger_fonction('xml', 'oembed/output');
$res = $output($res, false);
@ -57,7 +57,7 @@ function action_api_oembed_dist() {
ecrire_fichier($oembed_cache, $res);
}
if (!$res) {
if (!$res){
include_spip('inc/headers');
http_status(404);
echo '404 Not Found';

98
action/oembed_nettoyer_iframes.php

@ -5,7 +5,7 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) {
if (!defined('_ECRIRE_INC_VERSION')){
return;
}
@ -15,71 +15,71 @@ if (!defined('_ECRIRE_INC_VERSION')) {
* 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>';
$simu = true;
if (_request('modif')) {
if (_request('modif')){
$simu = false;
}
if ($simu) {
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'),
'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)) {
$pre = "$primary=".$row[$primary].":$champ:";
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) {
if (count($iframes)){
foreach ($iframes as $iframe){
$url = '';
$src = extraire_attribut($iframe, 'src');
if (strncmp($src, '//', 2) == 0) {
if (strncmp($src, '//', 2)==0){
$src = 'http:' . $src;
}
if (strpos($iframe, 'youtube') !== false) {
if (strpos($src, '/embed/') !== false) {
if (strpos($iframe, 'youtube')!==false){
if (strpos($src, '/embed/')!==false){
$url = str_replace('?', '&', $src);
$url = str_replace('/embed/videoseries&', '/playlist?', $url);
$url = str_replace('/embed/', '/watch?v=', $url);
$url = str_replace('&feature=player_embedded', '', $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) {
} 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) {
} 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);
@ -87,7 +87,7 @@ function action_oembed_nettoyer_iframes_dist() {
#var_dump($url);
echo "$pre Vimeo $url<br />";
}
if (!$url) {
if (!$url){
var_dump($row);
var_dump($iframe);
die('vimeo inconnue');
@ -115,77 +115,77 @@ function action_oembed_nettoyer_iframes_dist() {
var_dump($iframe);
die('soundcloud inconnue');
}
} */else {
echo "$pre iframe inconnue : ".entites_html($iframe).'<br />';
} */ else {
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);
}
}
if ($texte!==$row[$champ]) {
if ($texte!==$row[$champ]){
echo "$pre Corrige $champ <br />";
if (!$simu) {
if (!$simu){
echo "$pre Corrige $champ <br />";
objet_modifier($objet, $row[$primary], array($champ=>$texte));
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) {
if (count($objects)){
foreach ($objects as $object){
$url = '';
$embed = extraire_balise($object, 'embed');
$src = extraire_attribut($embed, 'src');
if (strncmp($src, '//', 2) == 0) {
if (strncmp($src, '//', 2)==0){
$src = 'http:' . $src;
}
if (strpos($embed, 'youtube') !== false) {
if (strpos($src, '/v/') !== false) {
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) {
} 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) {
} 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) {
} 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');
@ -194,18 +194,18 @@ function action_oembed_nettoyer_iframes_dist() {
$url = $u;
echo "$pre Nettoyage Object url $url<br />";
} else {
echo "$pre object inconnue : ".entites_html($object).'<br />';
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);
}
}
if ($texte!==$row[$champ]) {
if (!$simu) {
if ($texte!==$row[$champ]){
if (!$simu){
echo "$pre Corrige $champ <br />";
objet_modifier($objet, $row[$primary], array($champ => $texte));
} else {

213
inc/oembed.php

@ -5,7 +5,7 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) {
if (!defined('_ECRIRE_INC_VERSION')){
return;
}
@ -13,7 +13,7 @@ if (!defined('_ECRIRE_INC_VERSION')) {
* Lister les providers connus
* @return array
*/
function oembed_lister_providers() {
function oembed_lister_providers(){
// liste des providers par defaut
@ -24,66 +24,66 @@ function oembed_lister_providers() {
// https://github.com/panzi/oembedendpoints/blob/master/endpoints-simple.json
// voir aussi http://embed.ly/providers qui donne les scheme mais pas les endpoint
$providers = array(
'http://*.youtube.com/watch*' => 'https://www.youtube.com/oembed',
'http://*.youtube.com/playlist*' => 'https://www.youtube.com/oembed',
'http://youtu.be/*' => 'https://www.youtube.com/oembed',
'http://*.vimeo.com/*' => 'https://vimeo.com/api/oembed.json',
'http://vimeo.com/*' => 'https://vimeo.com/api/oembed.json',
'http://*.dailymotion.com/*' => 'https://www.dailymotion.com/services/oembed',
'http://dai.ly/*' => 'https://www.dailymotion.com/services/oembed',
'http://*.flickr.com/*' => 'https://www.flickr.com/services/oembed/',
'http://flickr.com/*' => 'https://www.flickr.com/services/oembed/',
'http://flic.kr/*' => 'https://www.flickr.com/services/oembed/',
'http://soundcloud.com/*' => 'https://soundcloud.com/oembed',
'http://mixcloud.com/*' => 'https://mixcloud.com/oembed',
'http://*.soundcloud.com/*' => 'https://soundcloud.com/oembed',
'http://*.mixcloud.com/*' => 'https://mixcloud.com/oembed',
'http://*.slideshare.net/*/*' => 'https://www.slideshare.net/api/oembed/2',
'http://www.slideshare.net/*/*' => 'https://www.slideshare.net/api/oembed/2',
'http://instagr.am/*' => 'https://api.instagram.com/oembed',
'http://*.instagr.am/*' => 'https://api.instagram.com/oembed',
'http://instagram.com/*' => 'https://api.instagram.com/oembed',
'http://*.instagram.com/*' => 'https://api.instagram.com/oembed',
'http://huffduffer.com/*/*' => 'http://huffduffer.com/oembed',
'http://nfb.ca/film/*' => 'http://www.nfb.ca/remote/services/oembed/',
'http://dotsub.com/view/*' => 'http://dotsub.com/services/oembed',
'http://clikthrough.com/theater/video/*' => 'http://clikthrough.com/services/oembed',
'http://kinomap.com/*' => 'http://www.kinomap.com/oembed',
'http://photobucket.com/albums/*' => 'http://api.photobucket.com/oembed',
'http://photobucket.com/groups/*' => 'http://api.photobucket.com/oembed',
'http://*.smugmug.com/*' => 'https://api.smugmug.com/services/oembed/',
'http://meetup.com/*' => 'https://api.meetup.com/oembed',
'http://meetup.ps/*' => 'http://api.meetup.com/oembed',
'http://*.wordpress.com/*' => 'https://public-api.wordpress.com/oembed/1.0/',
'http://twitter.com/*/status/*' => 'https://publish.twitter.com/oembed',
'http://twitter.com/*/likes' => 'https://publish.twitter.com/oembed',
'http://twitter.com/*/lists/*' => 'https://publish.twitter.com/oembed',
'http://twitter.com/*/timelines/*' => 'https://publish.twitter.com/oembed',
'http://twitter.com/i/moments/*' => 'https://publish.twitter.com/oembed',
'http://techcrunch.com/*' => 'http://public-api.wordpress.com/oembed/1.0/',
'http://wp.me/*' => 'http://public-api.wordpress.com/oembed/1.0/',
'http://my.opera.com/*' => 'http://my.opera.com/service/oembed',
'http://www.collegehumor.com/video/*' => 'http://www.collegehumor.com/oembed.json',
'http://imgur.com/*' => 'http://api.imgur.com/oembed',
'http://*.imgur.com/*' => 'http://api.imgur.com/oembed',
'http://*.onf.ca/*' => 'http://www.onf.ca/remote/services/oembed/',
'http://vine.co/v/*' => 'https://vine.co/oembed.json',
'http://*.tumblr.com/post/*' => 'https://www.tumblr.com/oembed/1.0',
'http://*.kickstarter.com/projects/*' => 'https://www.kickstarter.com/services/oembed',
'http://speakerdeck.com/*' => 'https://speakerdeck.com/oembed.json',
'http://issuu.com/*/docs/*' => 'https://issuu.com/oembed',
'http://*.calameo.com/books/*' => 'https://www.calameo.com/services/oembed',
'http://*.calameo.com/read/*' => 'https://www.calameo.com/services/oembed',
'http://www.facebook.com/*/posts/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/*/activity/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/*/photos/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/media/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/questions/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/notes/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/*/videos/*' => 'https://www.facebook.com/plugins/video/oembed.json/',
'http://*.arte.tv/*/videos/*' => 'https://api.arte.tv/api/player/v1/oembed/',
'http://egliseinfo.catholique.fr/*' => 'http://egliseinfo.catholique.fr/api/oembed',
'http://*.youtube.com/watch*' => 'https://www.youtube.com/oembed',
'http://*.youtube.com/playlist*' => 'https://www.youtube.com/oembed',
'http://youtu.be/*' => 'https://www.youtube.com/oembed',
'http://*.vimeo.com/*' => 'https://vimeo.com/api/oembed.json',
'http://vimeo.com/*' => 'https://vimeo.com/api/oembed.json',
'http://*.dailymotion.com/*' => 'https://www.dailymotion.com/services/oembed',
'http://dai.ly/*' => 'https://www.dailymotion.com/services/oembed',
'http://*.flickr.com/*' => 'https://www.flickr.com/services/oembed/',
'http://flickr.com/*' => 'https://www.flickr.com/services/oembed/',
'http://flic.kr/*' => 'https://www.flickr.com/services/oembed/',
'http://soundcloud.com/*' => 'https://soundcloud.com/oembed',
'http://mixcloud.com/*' => 'https://mixcloud.com/oembed',
'http://*.soundcloud.com/*' => 'https://soundcloud.com/oembed',
'http://*.mixcloud.com/*' => 'https://mixcloud.com/oembed',
'http://*.slideshare.net/*/*' => 'https://www.slideshare.net/api/oembed/2',
'http://www.slideshare.net/*/*' => 'https://www.slideshare.net/api/oembed/2',
'http://instagr.am/*' => 'https://api.instagram.com/oembed',
'http://*.instagr.am/*' => 'https://api.instagram.com/oembed',
'http://instagram.com/*' => 'https://api.instagram.com/oembed',
'http://*.instagram.com/*' => 'https://api.instagram.com/oembed',
'http://huffduffer.com/*/*' => 'http://huffduffer.com/oembed',
'http://nfb.ca/film/*' => 'http://www.nfb.ca/remote/services/oembed/',
'http://dotsub.com/view/*' => 'http://dotsub.com/services/oembed',
'http://clikthrough.com/theater/video/*' => 'http://clikthrough.com/services/oembed',
'http://kinomap.com/*' => 'http://www.kinomap.com/oembed',
'http://photobucket.com/albums/*' => 'http://api.photobucket.com/oembed',
'http://photobucket.com/groups/*' => 'http://api.photobucket.com/oembed',
'http://*.smugmug.com/*' => 'https://api.smugmug.com/services/oembed/',
'http://meetup.com/*' => 'https://api.meetup.com/oembed',
'http://meetup.ps/*' => 'http://api.meetup.com/oembed',
'http://*.wordpress.com/*' => 'https://public-api.wordpress.com/oembed/1.0/',
'http://twitter.com/*/status/*' => 'https://publish.twitter.com/oembed',
'http://twitter.com/*/likes' => 'https://publish.twitter.com/oembed',
'http://twitter.com/*/lists/*' => 'https://publish.twitter.com/oembed',
'http://twitter.com/*/timelines/*' => 'https://publish.twitter.com/oembed',
'http://twitter.com/i/moments/*' => 'https://publish.twitter.com/oembed',
'http://techcrunch.com/*' => 'http://public-api.wordpress.com/oembed/1.0/',
'http://wp.me/*' => 'http://public-api.wordpress.com/oembed/1.0/',
'http://my.opera.com/*' => 'http://my.opera.com/service/oembed',
'http://www.collegehumor.com/video/*' => 'http://www.collegehumor.com/oembed.json',
'http://imgur.com/*' => 'http://api.imgur.com/oembed',
'http://*.imgur.com/*' => 'http://api.imgur.com/oembed',
'http://*.onf.ca/*' => 'http://www.onf.ca/remote/services/oembed/',
'http://vine.co/v/*' => 'https://vine.co/oembed.json',
'http://*.tumblr.com/post/*' => 'https://www.tumblr.com/oembed/1.0',
'http://*.kickstarter.com/projects/*' => 'https://www.kickstarter.com/services/oembed',
'http://speakerdeck.com/*' => 'https://speakerdeck.com/oembed.json',
'http://issuu.com/*/docs/*' => 'https://issuu.com/oembed',
'http://*.calameo.com/books/*' => 'https://www.calameo.com/services/oembed',
'http://*.calameo.com/read/*' => 'https://www.calameo.com/services/oembed',
'http://www.facebook.com/*/posts/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/*/activity/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/*/photos/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/media/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/questions/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/notes/*' => 'https://www.facebook.com/plugins/post/oembed.json/',
'http://www.facebook.com/*/videos/*' => 'https://www.facebook.com/plugins/video/oembed.json/',
'http://*.arte.tv/*/videos/*' => 'https://api.arte.tv/api/player/v1/oembed/',
'http://egliseinfo.catholique.fr/*' => 'http://egliseinfo.catholique.fr/api/oembed',
#'https://gist.github.com/*' => 'http://github.com/api/oembed?format=json'
);
@ -93,7 +93,7 @@ function oembed_lister_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);
@ -120,32 +120,32 @@ function oembed_lister_providers() {
* @param bool $force_reload forcer le rechargement de l'oembed depuis la source sans utiliser le cache local
* @return bool|array false si aucun retour ou erreur ; tableau des éléménents de la réponse oembed
*/
function oembed_recuperer_data($url, $maxwidth = null, $maxheight = null, $format = 'json', $detecter_lien = 'non', $force_reload = false) {
function oembed_recuperer_data($url, $maxwidth = null, $maxheight = null, $format = 'json', $detecter_lien = 'non', $force_reload = false){
static $cache = array();
$provider = false;
include_spip('inc/config');
$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 = url_absolue($provider['endpoint'], url_de_base());
// certains oembed fournissent un endpoint qui contient deja l'URL, parfois differente de celle de la page
if (!parametre_url($data_url, 'url')) {
if (!parametre_url($data_url, 'url')){
$data_url = parametre_url($data_url, 'url', $url, '&');
}
if (!$maxwidth) {
if (!$maxwidth){
$maxwidth = lire_config('oembed/maxwidth', '600');
}
if (!$maxheight) {
if (!$maxheight){
$maxheight = lire_config('oembed/maxheight', '400');
}
@ -153,49 +153,48 @@ function oembed_recuperer_data($url, $maxwidth = null, $maxheight = null, $forma
$data_url = parametre_url($data_url, 'maxheight', $maxheight, '&');
$data_url = parametre_url($data_url, 'format', $format, '&');
if (isset($provider['provider_name']) and $provider['provider_name']) {
if (isset($provider['provider_name']) and $provider['provider_name']){
$provider_name = $provider['provider_name'];
}
else {
} else {
// pre-traitement du provider si besoin
$provider_name = explode('//', $provider['endpoint']);
$provider_name = explode('/', $provider_name[1]);
$provider_name = reset($provider_name);
}
$provider_name = preg_replace(',\W+,', '_', strtolower($provider_name));
if ($oembed_endpoint_pretraite = charger_fonction("pretraite_$provider_name", 'oembed/input', true)) {
if ($oembed_endpoint_pretraite = charger_fonction("pretraite_$provider_name", 'oembed/input', true)){
$a = func_get_args();
$args = array('url'=>array_shift($a));
if (count($a)) {
$args = array('url' => array_shift($a));
if (count($a)){
$args['maxwidth'] = array_shift($a);
}
if (count($a)) {
if (count($a)){
$args['maxheight'] = array_shift($a);
}
if (count($a)) {
if (count($a)){
$args['format'] = array_shift($a);
}
$args['endpoint'] = $provider['endpoint'];
$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 (!$force_reload and file_exists($oembed_cache) and _VAR_MODE !== 'recalcul') {
if (!$force_reload and file_exists($oembed_cache) and _VAR_MODE!=='recalcul'){
lire_fichier($oembed_cache, $cache[$data_url]);
$cache[$data_url]=unserialize($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);
// si une fonction de post-traitement est fourni pour ce provider+type, l'utiliser
if ($cache[$data_url]) {
$provider_name2= str_replace(' ', '_', strtolower($cache[$data_url]['provider_name']));
if ($cache[$data_url]){
$provider_name2 = 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_name2}_$type");
@ -206,12 +205,12 @@ function oembed_recuperer_data($url, $maxwidth = null, $maxheight = null, $forma
$oembed_provider_posttraite = charger_fonction($f1, 'oembed/input', true)
or $oembed_provider_posttraite = charger_fonction($f2, 'oembed/input', true)
or $oembed_provider_posttraite = charger_fonction($f3, 'oembed/input', true)
or $oembed_provider_posttraite = charger_fonction($f4, 'oembed/input', true) ) {
or $oembed_provider_posttraite = charger_fonction($f4, 'oembed/input', true)){
$cache[$data_url] = $oembed_provider_posttraite($cache[$data_url], $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];
}
@ -223,15 +222,15 @@ function oembed_recuperer_data($url, $maxwidth = null, $maxheight = null, $forma
* @return bool|array
* 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) {
function oembed_verifier_provider($url){
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);
if (preg_match($regex, $url)) {
if (preg_match($regex, $url)){
return array('endpoint' => $endpoint);
}
}
@ -244,12 +243,12 @@ function oembed_verifier_provider($url) {
* @param string $url url de la page à analyser
* @return bool|string false si pas de lien ; url du contenu oembed
*/
function oembed_detecter_lien($url) {
function oembed_detecter_lien($url){
$providers = array();
$oembed_recuperer_url = charger_fonction('oembed_recuperer_url', 'inc');
// on recupere le contenu de la page
if ($html = $oembed_recuperer_url($url, $url, 'html')) {
if ($html = $oembed_recuperer_url($url, $url, 'html')){
// types de liens oembed à détecter
$linktypes = array(
'application/json+oembed' => 'json',
@ -263,24 +262,24 @@ function oembed_detecter_lien($url) {
// un test rapide...
$tagfound = false;
foreach ($linktypes as $linktype => $format) {
if (stripos($head, $linktype)) {
foreach ($linktypes as $linktype => $format){
if (stripos($head, $linktype)){
$tagfound = true;
break;
}
}
if ($tagfound && preg_match_all('/<link([^<>]+)>/i', $head, $links)) {
if (!function_exists('extraire_attribut')) {
if ($tagfound && preg_match_all('/<link([^<>]+)>/i', $head, $links)){
if (!function_exists('extraire_attribut')){
include_spip('inc/filtres');
}
foreach ($links[0] as $link) {
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)) {
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;
}
}
@ -291,7 +290,7 @@ function oembed_detecter_lien($url) {
$res = array();
// on préfère le json au xml
if (!empty($providers['json'])) {
if (!empty($providers['json'])){
$res['endpoint'] = $providers['json'];
} elseif (!empty($providers['xml'])) {
$res['endpoint'] = $providers['xml'];
@ -300,7 +299,7 @@ function oembed_detecter_lien($url) {
}
// detecter certains providers specifiques : ex mastodon, chaque instance a son nom et on peut pas l'identifier par son URL
if (strpos($html, '//github.com/tootsuite/mastodon') !== false or strpos($html, '//joinmastodon.org') !== false) {
if (strpos($html, '//github.com/tootsuite/mastodon')!==false or strpos($html, '//joinmastodon.org')!==false){
$res['provider_name'] = 'Mastodon';
}
@ -313,7 +312,7 @@ 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');
@ -321,16 +320,16 @@ function oembed_embarquer_lien($lien) {
if ($url
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) {
if (strncmp($url, $base, strlen($base))!=0){
$fond = recuperer_fond('modeles/oembed', array('url' => $url, 'lien' => $lien));
if ($fond = trim($fond)) {
if ($fond = trim($fond)){
$texte = $fond;
}
}

29
inc/oembed_recuperer_url.php

@ -5,7 +5,7 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) {
if (!defined('_ECRIRE_INC_VERSION')){
return;
}
@ -17,7 +17,7 @@ if (!defined('_ECRIRE_INC_VERSION')) {
* @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){
$erreur = "";
// on recupere le contenu de la page
@ -59,34 +59,31 @@ function inc_oembed_recuperer_url($oembed_url, $url, $format) {
// si c'est une erreur de protocole SSL, on tente avec un exec mechant car ca peut venir de la version de CURL PHP
// (ca marche au moins en local)
if (!$data and $errno == 35) {
exec('curl "'.$oembed_url.'"',$output);
if (!$data and $errno==35){
exec('curl "' . $oembed_url . '"', $output);
$data = implode("\n", $output);
}
else {
} else {
$data = '';
}
}
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');
// recuperer_page utilise par defaut l'adresse du site comme $referer
$data = recuperer_page($oembed_url);
}
if (!$data) {
spip_log('infos oembed brutes pour '."$url | $oembed_url".' : ' . "ECHEC $erreur", 'oembed.'._LOG_ERREUR);
}
else {
spip_log('infos oembed brutes pour '."$url | $oembed_url".' : '.(($format == 'html')?substr($data,0,100):$data), 'oembed.'._LOG_DEBUG);
if (!$data){
spip_log('infos oembed brutes pour ' . "$url | $oembed_url" . ' : ' . "ECHEC $erreur", 'oembed.' . _LOG_ERREUR);
} else {
spip_log('infos oembed brutes pour ' . "$url | $oembed_url" . ' : ' . (($format=='html') ? substr($data, 0, 100) : $data), 'oembed.' . _LOG_DEBUG);
}
if ($data) {
if ($format == 'json') {
if ($data){
if ($format=='json'){
$data = json_decode($data, true);
$data['oembed_url_source'] = $url;
$data['oembed_url'] = $oembed_url;

22
inc/ressource.php

@ -6,21 +6,21 @@
*
*/
define('_EXTRAIRE_RESSOURCES', ',' . '<"?(https?://|[\w][\w -]*\.[\w -]+).*>'.',UimsS');
define('_EXTRAIRE_RESSOURCES', ',' . '<"?(https?://|[\w][\w -]*\.[\w -]+).*>' . ',UimsS');
/* pipeline pour typo, evitons une erreur dans les logs */
function tw_post_typo($t) {
function tw_post_typo($t){
return $t;
}
/* pipeline pour propre, evitons une erreur dans les logs */
function tw_pre_liens($t) {
function tw_pre_liens($t){
return $t;
}
function traiter_ressources($r) {
if ($ressource = charger_fonction('ressource', 'inc', true)) {
function traiter_ressources($r){
if ($ressource = charger_fonction('ressource', 'inc', true)){
$html = $ressource($r[0]);
} else {
$html = htmlspecialchars($r[0]);
@ -29,27 +29,27 @@ function traiter_ressources($r) {
return $html;
}
function inc_ressource_dist($html) {
return tw_traiter_ressources(array(0=>$html));
function inc_ressource_dist($html){
return tw_traiter_ressources(array(0 => $html));
}
function tw_traiter_ressources($r) {
function tw_traiter_ressources($r){
$html = null;
include_spip('inc/lien');
$url = explode(' ', trim($r[0], '<>'));
$url = $url[0];
# <http://url/absolue>
if (preg_match(',^https?://,i', $url)) {
if (preg_match(',^https?://,i', $url)){
$html = PtoBR(propre("<span class='ressource spip_out'>&lt;[->" . $url . ']&gt;</span>'));
} # <url/relative>
else {
if (false !== strpos($url, '/')) {
if (false!==strpos($url, '/')){
$html = PtoBR(propre("<span class='ressource spip_in'>&lt;[->" . $url . ']&gt;</span>'));
} # <fichier.rtf>
else {
if (preg_match(',\.([^.]+)$,', $url, $regs)
and file_exists($f = _DIR_IMG . $regs[1] . '/' . $url)) {
and file_exists($f = _DIR_IMG . $regs[1] . '/' . $url)){
$html = PtoBR(propre("<span class='ressource spip_in'>&lt;[" . $url . '->' . $f . ']&gt;</span>'));
} else {
$html = PtoBR(propre("<span class='ressource'>&lt;" . $url . '&gt;</span>'));

86
oembed_fonctions.php

@ -5,13 +5,13 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) {
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))) {
function mime_type_oembed($id_document){
if (!($id_document = intval($id_document))){
return '';
}
$extension = sql_getfetsel(
@ -24,27 +24,27 @@ function mime_type_oembed($id_document) {
'spip_types_documents',
'extension = ' . sql_quote($extension)
);
if ($mime_type == 'text/html'
and sql_getfetsel('oembed', 'spip_documents', "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;
}
// balise #MIME_TYPE pour oembed
function balise_MIME_TYPE_dist($p) {
function balise_MIME_TYPE_dist($p){
$b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle;
$key = $p->boucles[$b]->primary;
/**
* 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 {
/* explorer la pile memoire pour atteindre le 'vrai' champ */
$id_document = champ_sql('id_document', $p);
/* le code php qui sera execute */
$p->code = "mime_type_oembed(".$id_document.")";
$p->code = "mime_type_oembed(" . $id_document . ")";
}
return $p;
}
@ -54,10 +54,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;
}
@ -70,14 +70,14 @@ 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)) {
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;
}
}
@ -91,11 +91,11 @@ function oembed($url, $maxwidth = 0, $maxheight = 0) {
* @param $html
* @return mixed
*/
function oembed_force_video_autoplay($html) {
function oembed_force_video_autoplay($html){
if ($e = extraire_balise($html, 'iframe')
and $src = extraire_attribut($e, 'src')) {
and $src = extraire_attribut($e, 'src')){
$src_amp = parametre_url($src, 'dummy', null);
if (strpos($src, 'soundcloud') !== false) {
if (strpos($src, 'soundcloud')!==false){
$src_autoplay = parametre_url($src, 'auto_play', '1', '&');
} else {
$src_autoplay = parametre_url($src, 'autoplay', '1', '&');
@ -104,8 +104,8 @@ function oembed_force_video_autoplay($html) {
* Ne pas mettre d'autoplay sur les vidéos facebook sinon elles perdent le son
* Le son est plus compliqué à remettre qu'à recliquer une seconde fois pour voir la vidéo
*/
if (strpos($src, 'facebook') == false) {
if (strpos($html, $src_amp)) {
if (strpos($src, 'facebook')==false){
if (strpos($html, $src_amp)){
$html = str_replace($src_amp, $src_autoplay, $html);
} else {
$html = str_replace($src, $src_autoplay, $html);
@ -116,23 +116,23 @@ function oembed_force_video_autoplay($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)) {
if (is_null($html)){
$html = inc_ressource_dist($rac);
}
return $html;
}
} else {
// SPIP 3.0
function inc_ressource_dist($rac) {
function inc_ressource_dist($rac){
return oembed_traiter_ressource($rac);
}
}
function oembed_traiter_ressource($rac) {
function oembed_traiter_ressource($rac){
static $null_allowed = null;
include_spip('inc/lien');
@ -141,43 +141,43 @@ 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 https://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($texte)){
if (is_null($null_allowed)){
if (version_compare($GLOBALS['spip_version_branche'], '3.0.14', '<')){
$null_allowed = false;
} else {
$null_allowed = true;
}
}
if (!$null_allowed) {
if (!$null_allowed){
include_spip('inc/lien');
$url = explode(' ', trim($rac, '<>'));
$url = $url[0];
# <http://url/absolue>
if (preg_match(',^https?://,i', $url)) {
$texte = PtoBR(propre("<span class='ressource spip_out'>&lt;[->".$url.']&gt;</span>'));
# <url/relative>
} elseif (false !== strpos($url, '/')) {
$texte = PtoBR(propre("<span class='ressource spip_in'>&lt;[->".$url.']&gt;</span>'));
# <fichier.rtf>
if (preg_match(',^https?://,i', $url)){
$texte = PtoBR(propre("<span class='ressource spip_out'>&lt;[->" . $url . ']&gt;</span>'));
# <url/relative>
} elseif (false!==strpos($url, '/')) {
$texte = 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)) {
$texte = PtoBR(propre("<span class='ressource spip_in'>&lt;[".$url.'->'.$f.']&gt;</span>'));
if (file_exists($f = _DIR_IMG . $regs[1] . '/' . $url)){
$texte = PtoBR(propre("<span class='ressource spip_in'>&lt;[" . $url . '->' . $f . ']&gt;</span>'));
} else {
$texte = PtoBR(propre("<span class='ressource'>&lt;".$url.'&gt;</span>'));
$texte = PtoBR(propre("<span class='ressource'>&lt;" . $url . '&gt;</span>'));
}
}
}
@ -193,10 +193,10 @@ function oembed_traiter_ressource($rac) {
* @param string $img
* @return string
*/
function oembed_safe_thumbnail($img) {
function oembed_safe_thumbnail($img){
if (!tester_url_absolue($img) and file_exists($img)) {
if (!function_exists('image_filtrer')) {
if (!tester_url_absolue($img) and file_exists($img)){
if (!function_exists('image_filtrer')){
include_spip('inc/filtres');
}
$img = image_filtrer(array('image_reduire', $img, 1200, 1200));

152
oembed_pipelines.php

@ -5,7 +5,7 @@
*
*/
if (!defined('_ECRIRE_INC_VERSION')) {
if (!defined('_ECRIRE_INC_VERSION')){
return;
}
@ -14,8 +14,8 @@ if (!defined('_ECRIRE_INC_VERSION')) {
* @param $head
* @return string
*/
function oembed_insert_head_css($head) {
$head .= '<link rel="stylesheet" type="text/css" href="'.timestamp(find_in_path('css/oembed.css')).'" />'."\n";
function oembed_insert_head_css($head){
$head .= '<link rel="stylesheet" type="text/css" href="' . timestamp(find_in_path('css/oembed.css')) . '" />' . "\n";
return $head;
}
@ -25,20 +25,20 @@ function oembed_insert_head_css($head) {
* @param string $head
* @return string
*/
function oembed_insert_head($head) {
if(lire_config('oembed/inserer_head')=='non') {
function oembed_insert_head($head){
if (lire_config('oembed/inserer_head')=='non'){
return $head;
}
$service = 'oembed.api/';
$ins = '<link rel="alternate" type="application/json+oembed" href="<?php include_spip(\'inc/filtres_mini\');echo parametre_url(url_absolue("'.parametre_url($service, 'format', 'json').'"), "url", url_absolue(self()));?>" />'."\n";
$ins = '<link rel="alternate" type="application/json+oembed" href="<?php include_spip(\'inc/filtres_mini\');echo parametre_url(url_absolue("' . parametre_url($service, 'format', 'json') . '"), "url", url_absolue(self()));?>" />' . "\n";
/*
$ins .= '<link rel="alternate" type="text/xml+oembed" href="<?php echo parametre_url(url_absolue("'.parametre_url($service,'format','xml').'"),"url",url_absolue(self()));?>" />'."\n";
*/
$ins = "<?php if (!in_array(_request(_SPIP_PAGE),array('login')) AND strpos(\$_SERVER['REQUEST_URI'],'debut_')===false){?>$ins<?php } ?>";
return $head.$ins;
return $head . $ins;
}
/**
@ -46,10 +46,10 @@ function oembed_insert_head($head) {
* @param $flux
* @return
*/
function oembed_formulaire_charger($flux) {
if ($flux['args']['form']=='editer_document') {
function oembed_formulaire_charger($flux){
if ($flux['args']['form']=='editer_document'){
if ($flux['data']['oembed']
and !isset($flux['data']['apercu'])) {
and !isset($flux['data']['apercu'])){
$flux['data']['_inclus'] = 'embed';
}
}
@ -61,31 +61,33 @@ function oembed_formulaire_charger($flux) {
* @param $flux
* @return array
*/
function oembed_recuperer_fond($flux) {
if ($flux['args']['fond'] == 'formulaires/inc-upload_document') {
function oembed_recuperer_fond($flux){
if ($flux['args']['fond']=='formulaires/inc-upload_document'){
include_spip('inc/oembed');
$providers = oembed_lister_providers();
$hosts = array();
foreach ($providers as $scheme => $endpoint) {
foreach ($providers as $scheme => $endpoint){
$h = parse_url($scheme, PHP_URL_HOST);
$hosts[trim(preg_replace(',^(\*|www)\.,i', '', $h))] = true;
}
$hosts = implode(', ', array_keys($hosts));
$i = _T('oembed:explication_upload_url', array('hosts' => $hosts));
$i = "<p class='explication small'>$i</p>";
$flux['data'] = str_replace($t = '<!--editer_url-->', $t. $i, $flux['data']);
} else if ($flux['args']['fond'] == 'modeles/document_case') {
$infos_doc = sql_fetsel('id_document, mode, media, oembed', 'spip_documents', 'id_document='.intval($flux['args']['contexte']['id_document']));
if (in_array($infos_doc['media'], array('video', 'audio'))
and ($infos_doc['mode'] == 'document')
and (strlen($infos_doc['oembed']) > 1)) {
$info_vignette = '<span>' . _T('medias:info_inclusion_vignette') . '</span>';
$flux['data'] = str_replace("<div class='raccourcis'>", "<div class='raccourcis'>".$info_vignette, $flux['data']);
$raccourci = "<div class='raccourcis'><span>" . _T('medias:info_inclusion_directe') . '</span>'
. affiche_raccourci_doc('emb', $infos_doc['id_document'], 'left')
. affiche_raccourci_doc('emb', $infos_doc['id_document'], 'center')
. affiche_raccourci_doc('emb', $infos_doc['id_document'], 'right').'</div>';
$flux['data'] = str_replace('<div class="actions', $raccourci.'<div class="actions', $flux['data']);
$flux['data'] = str_replace($t = '<!--editer_url-->', $t . $i, $flux['data']);
} else {
if ($flux['args']['fond']=='modeles/document_case'){
$infos_doc = sql_fetsel('id_document, mode, media, oembed', 'spip_documents', 'id_document=' . intval($flux['args']['contexte']['id_document']));
if (in_array($infos_doc['media'], array('video', 'audio'))
and ($infos_doc['mode']=='document')
and (strlen($infos_doc['oembed'])>1)){
$info_vignette = '<span>' . _T('medias:info_inclusion_vignette') . '</span>';
$flux['data'] = str_replace("<div class='raccourcis'>", "<div class='raccourcis'>" . $info_vignette, $flux['data']);
$raccourci = "<div class='raccourcis'><span>" . _T('medias:info_inclusion_directe') . '</span>'
. affiche_raccourci_doc('emb', $infos_doc['id_document'], 'left')
. affiche_raccourci_doc('emb', $infos_doc['id_document'], 'center')
. affiche_raccourci_doc('emb', $infos_doc['id_document'], 'right') . '</div>';
$flux['data'] = str_replace('<div class="actions', $raccourci . '<div class="actions', $flux['data']);
}
}
}
return $flux;
@ -99,17 +101,17 @@ function oembed_recuperer_fond($flux) {
* @param array $flux
* @return array
*/
function oembed_renseigner_document_distant($flux) {
$medias = array('photo' => 'image','video' => 'video', 'sound'=>'audio');
function oembed_renseigner_document_distant($flux){
$medias = array('photo' => 'image', 'video' => 'video', 'sound' => 'audio');
include_spip('inc/config');
include_spip('inc/oembed');
// on tente de récupérer les données oembed
if ($data = oembed_recuperer_data($flux['source'], null, null, 'json', 'non', true)) {
if ($data = oembed_recuperer_data($flux['source'], null, null, 'json', 'non', true)){
// si on a recupere une URL c'est direct un doc distant
if (isset($data['url'])
and $data['type'] !== 'rich'
and $data['type']!=='rich'
// on recupere les infos du document distant
and $doc = recuperer_infos_distantes($data['url'])) {
and $doc = recuperer_infos_distantes($data['url'])){
unset($doc['body']);
$doc['distant'] = 'oui';
$doc['mode'] = 'document';
@ -122,17 +124,17 @@ function oembed_renseigner_document_distant($flux) {
// $doc['titre'] = '['.$doc['titre'].'->'.$data['web_page'].']';
//}
$doc['credits'] = $data['author_name'];
if (isset($data['author_url'])) {
$doc['credits']= '['.$doc['credits'].'->'.$data['author_url'].']';
if (isset($data['author_url'])){
$doc['credits'] = '[' . $doc['credits'] . '->' . $data['author_url'] . ']';
}
if (isset($data['media'])) {
if (isset($data['media'])){
$doc['media'] = $data['media'];
} elseif (isset($medias[$data['type']])) {
$doc['media'] = $medias[$data['type']];
}
return $doc;
} elseif (isset($data['html']) or $data['type'] == 'link') {
if ($data['type']=='link') {
} elseif (isset($data['html']) or $data['type']=='link') {
if ($data['type']=='link'){
$data['html'] = '<a href="' . $flux['source'] . '">' . sinon($data['title'], $flux['source']) . '</a>';
}
// créer une copie locale du contenu html
@ -140,7 +142,7 @@ function oembed_renseigner_document_distant($flux) {
// generer un nom de fichier unique : on l'index sur l'id du prochain document + uniqid
$id = sql_getfetsel('id_document', 'spip_documents', '', '', 'id_document DESC', '0,1');
include_spip('inc/acces');
$id = "id$id-".creer_uniqid();
$id = "id$id-" . creer_uniqid();
$id = substr(md5($id), 0, 7);
$doc['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($flux['source'], 'html');
$doc['fichier'] = preg_replace(',\.html$,i', "-$id.html", $doc['fichier']);
@ -158,10 +160,10 @@ function oembed_renseigner_document_distant($flux) {
// $doc['titre'] = '['.$doc['titre'].'->'.$data['web_page'].']';
//}
$doc['credits'] = $data['author_name'];
if (isset($data['author_url'])) {
$doc['credits']= '['.$doc['credits'].'->'.$data['author_url'].']';
if (isset($data['author_url'])){
$doc['credits'] = '[' . $doc['credits'] . '->' . $data['author_url'] . ']';
}
if (isset($data['media'])) {
if (isset($data['media'])){
$doc['media'] = $data['media'];
} elseif (isset($medias[$data['type']])) {
$doc['media'] = $medias[$data['type']];
@ -180,19 +182,19 @@ function oembed_renseigner_document_distant($flux) {
* @param array $flux
* @return array
*/
function oembed_post_edition($flux) {
function oembed_post_edition($flux){
if (
isset($flux['args']['action'])
and $flux['args']['action'] == 'ajouter_document'
and $flux['args']['action']=='ajouter_document'
and !empty($flux['data']['oembed'])
) {
){
$id_document = $flux['args']['id_objet'];
if ($data = oembed_recuperer_data($flux['data']['oembed'])) {
if ($data = oembed_recuperer_data($flux['data']['oembed'])){
// vignette disponible ? la recupérer et l'associer au document
if ((isset($data['thumbnail_url']) and $v = $data['thumbnail_url'])
or (isset($data['image']) and $v = $data['image'])
) {
spip_log('ajout de la vignette '.$v.' pour '.$flux['data']['oembed'], 'oembed.'._LOG_DEBUG);
){
spip_log('ajout de la vignette ' . $v . ' pour ' . $flux['data']['oembed'], 'oembed.' . _LOG_DEBUG);
// cf formulaires_illustrer_document_traiter_dist()
$ajouter_documents = charger_fonction('ajouter_documents', 'action');
$files = false;
@ -202,18 +204,18 @@ function oembed_post_edition($flux) {
$name = explode('?', $name);
$name = reset($name);
if (!preg_match(',\.\w+$,', $name)) {
if (!function_exists('recuperer_infos_distantes')) {
if (!preg_match(',\.\w+$,', $name)){
if (!function_exists('recuperer_infos_distantes')){
include_spip('inc/distant');
}
// si on peut trouver une extension utilisons la
if ($infov = recuperer_infos_distantes($v)
and !empty($infov['extension'])) {
spip_log("URL ".$flux['data']['oembed']." vignette $v sans extension : extension detecteee -> ".$infov['extension'], 'oembed.'._LOG_DEBUG);
and !empty($infov['extension'])){
spip_log("URL " . $flux['data']['oembed'] . " vignette $v sans extension : extension detecteee -> " . $infov['extension'], 'oembed.' . _LOG_DEBUG);
$name .= "." . $infov['extension'];
}
}
if (preg_match(',^(\w+:)?//,', $v)) {
if (preg_match(',^(\w+:)?//,', $v)){
$files = array(
array(
'name' => $name,
@ -229,13 +231,13 @@ function oembed_post_edition($flux) {
}
if ($files
and $ajoute = action_ajouter_documents_dist('new', $files, '', 0, 'vignette')
and intval(reset($ajoute))) {
and intval(reset($ajoute))){
$id_vignette = reset($ajoute);
include_spip('action/editer_document');
document_modifier($id_document, array('id_vignette' => $id_vignette));
}
} else {
spip_log('pas de vignette pour '.$flux['data']['oembed'], 'oembed.'._LOG_DEBUG);
spip_log('pas de vignette pour ' . $flux['data']['oembed'], 'oembed.' . _LOG_DEBUG);
}
}
}
@ -248,31 +250,31 @@ function oembed_post_edition($flux) {
* @param string $texte
* @return mixed
*/
function oembed_pre_propre($texte) {
function oembed_pre_propre($texte){
include_spip('inc/config');
// si oembed/embed_auto==oui on oembed les liens qui sont tous seuls sur une ligne
// (mais jamais les liens inline dans le texte car ca casse trop l'ancien contenu)
if (stripos($texte, '<a') !== false
and stripos($texte, 'auto') !== false
and stripos($texte, 'spip_out') !== false
and lire_config('oembed/embed_auto', 'oui') != 'non'
and strpos($texte, "\n") !== false) {
if (stripos($texte, '<a')!==false
and stripos($texte, 'auto')!==false
and stripos($texte, 'spip_out')!==false
and lire_config('oembed/embed_auto', 'oui')!='non'
and strpos($texte, "\n")!==false){
preg_match_all(",(^|(?:\r?\n\r?\n)) *(<a\b[^>]*>[^\r\n]*</a>) *((?:\r?\n\r?\n)|$),Uims", trim($texte), $matches, PREG_SET_ORDER);
if (count($matches)) {
if (count($matches)){
$replace = array();
include_spip('inc/oembed');
foreach ($matches as $match) {
foreach ($matches as $match){
if (!isset($replace[$match[0]])
and preg_match(',\bauto\b,', extraire_attribut($match[2], 'class'))
and !is_null($emb = oembed_embarquer_lien($match[2]))) {
if ($wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true)) {
$emb = $wrap_embed_html($match[2],$emb);
and !is_null($emb = oembed_embarquer_lien($match[2]))){
if ($wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true)){
$emb = $wrap_embed_html($match[2], $emb);
}
$replace[$match[0]] = $match[1] . echappe_html("<html>$emb</html>") . $match[3];
}
}
if (count($replace)) {
if (count($replace)){
$texte = str_replace(array_keys($replace), array_values($replace), $texte);
}
}
@ -287,8 +289,8 @@ function oembed_pre_propre($texte) {
* @param $t
* @return mixed
*/
function oembed_post_typo($t) {
if (strpos($t, '<') !== false) {
function oembed_post_typo($t){
if (strpos($t, '<')!==false){
$t = preg_replace_callback(_EXTRAIRE_RESSOURCES, 'traiter_ressources', $t);
}
return $t;
@ -300,26 +302,26 @@ function oembed_post_typo($t) {
* @param $t
* @return mixed
*/
function oembed_pre_liens($t) {
if (strpos($t, '<') !== false) {
function oembed_pre_liens($t){
if (strpos($t, '<')!==false){
$t = preg_replace_callback(_EXTRAIRE_RESSOURCES, 'traiter_ressources', $t);
// echapper les autoliens eventuellement inseres (en une seule fois)
if (strpos($t, '<html>') !== false) {
if (strpos($t, '<html>')!==false){
$t = echappe_html($t);
}
}
return $t;
}
function oembed_declarer_tables_interfaces($interfaces) {
$interfaces['table_des_traitements']['CREDITS']['documents']= 'PtoBR('._TRAITEMENT_RACCOURCIS.')';