Browse Source

Oembed Twitter : on a toutes les infos dans la page mobile pour generer un joli tweet facon masto, on le traite donc comme tel si possible

+ petit fix sur le modele toot
yohooo-patch-1 v2.3.1
Cerdic 1 year ago
parent
commit
74e33a6796
  1. 1
      css/oembed.css
  2. 2
      modeles/toot.html
  3. 2
      oembed/input/posttraite_mastodon.php
  4. 60
      oembed/input/posttraite_twitter.php
  5. 2
      paquet.xml

1
css/oembed.css

@ -76,6 +76,7 @@ figure.oe-image-block figcaption {background:#eee;padding: 10px;text-align: left
.oembed_twitter .oembed-source {display: none;}
.oembed_twitter .oe-rich {max-width:none !important;}
.oembed_twitter .thumbnail {max-width:none !important;width: 100%;height: auto;}
.oembed_twitter .mastodon-toot {margin: 10px;}
.oe-descriptif {font-style: italic;}
.oe-quote-text {}

2
modeles/toot.html

@ -1,4 +1,4 @@
<blockquote class="mastodon-toot" style="[max-width:(#ENV{width});]">
<blockquote class="mastodon-toot" style="[max-width:(#ENV{width})px;]">
<span class="toot-author">
[<a href="#ENV{url}" class="toot-published">(#ENV{published}|affdate_heure)</a>]

2
oembed/input/posttraite_mastodon.php

@ -49,7 +49,7 @@ function oembed_input_posttraite_mastodon_dist($data) {
$screen_name = emojify($data['author_name'], $need_emoji);
$contexte = array(
'url' => $data['oembed_url_source'],
'width' => $data['width'],
'width' => max($data['width'],600),
'height' => $data['height'],
'author_screen_name' => $screen_name,
'author_url' => $data['author_url'],

60
oembed/input/posttraite_twitter.php

@ -44,6 +44,8 @@ function oembed_input_posttraite_twitter_dist($data) {
$content = end($content);
$imgs = extraire_balises($content, 'img');
$enclosure = '';
$enclosure_type = '';
$has_image = false;
foreach ($imgs as $img) {
$src = extraire_attribut($img, 'src');
@ -53,7 +55,11 @@ function oembed_input_posttraite_twitter_dist($data) {
if (in_array(end($src), ['large', 'small'])) {
$has_image = true;
array_pop($src);
if (preg_match(",.(\w+)$,", end($src), $m)) {
$enclosure_type = sql_getfetsel('mime_type', 'spip_types_documents', 'extension = ' . sql_quote($m[1]));
}
$src = implode(':', $src) . ':medium';
$enclosure = $src;
break;
}
}
@ -63,6 +69,60 @@ function oembed_input_posttraite_twitter_dist($data) {
//$src = str_replace(':large', ':small', $src);
$data['html'] = "<img src='$src' class='thumbnail p' />" . $data['html'];
}
// on va essayer de recuperer plus d'infos et de generer un tweet propre si on y arrive
$metadata = explode('metadata', $content, 2);
$links = extraire_balises(end($metadata), 'a');
$link = reset($links);
$link = strip_tags($link); // 5:14 AM - 3 Mar 2017
$link = explode('-', $link);
$link = array_reverse($link);
$link = implode(' ', $link);
$published_w_h = strtotime($link);
$content = extraire_balise($data['html'], 'blockquote');
$content = explode('&mdash;', $content);
$published = extraire_balise(end($content), 'a');
$published = strip_tags($published);
$published = strtotime($published);
if ($published_w_h and abs($published_w_h - $published)<24*3600) {
$published = $published_w_h;
}
$content = reset($content);
$content = explode('>', $content, 2);
$content = end($content);
if ($content and $author_thumbnail and $published) {
include_spip('oembed/input/posttraite_mastodon');
$need_emoji = false;
$screen_name = emojify($data['author_name'], $need_emoji);
$content = emojify($content, $need_emoji);
if ($enclosure) {
$content .= "<img src='$enclosure' class='thumbnail p' />";
}
$contexte = array(
'url' => $data['oembed_url_source'],
'width' => max($data['width'],600),
'height' => $data['height'],
'author_screen_name' => $screen_name,
'author_url' => $data['author_url'],
'author_name' => '@' . ltrim(basename($data['author_url']), '@') . '@twitter.com',
// A renseigner
'author_thumbnail' => $author_thumbnail,
'author_thumbnail_width' => '',
'author_thumbnail_height' => '',
'content' => $content,
'published' => date('Y-m-d H:i:s', $published),
'enclosure' => '',
'enclosure_type' => '',
);
$contexte['need_emoji'] = $need_emoji;
$data['html'] = recuperer_fond('modeles/toot', $contexte);
}
}
return $data;

2
paquet.xml

@ -1,7 +1,7 @@
<paquet
prefix="oembed"
categorie="multimedia"
version="2.3.0"
version="2.3.1"
etat="stable"
compatibilite="[3.0.0;3.3.*]"
logo="prive/themes/spip/images/oembed-64.png"

Loading…
Cancel
Save