mirror of
https://github.com/friendica/friendica
synced 2025-04-25 07:10:11 +00:00
Use the "attachment" element instead of a mixture of several elements
This commit is contained in:
parent
5b6a708007
commit
6cdcbabb3b
5 changed files with 236 additions and 354 deletions
|
@ -1,20 +1,11 @@
|
|||
<?php
|
||||
function get_attached_data($body) {
|
||||
/*
|
||||
- text:
|
||||
- type: link, video, photo
|
||||
- title:
|
||||
- url:
|
||||
- image:
|
||||
- description:
|
||||
- (thumbnail)
|
||||
*/
|
||||
function get_old_attachment_data($body) {
|
||||
|
||||
$post = array();
|
||||
|
||||
// Simplify image codes
|
||||
$body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
|
||||
|
||||
$post = array();
|
||||
|
||||
if (preg_match_all("(\[class=(.*?)\](.*?)\[\/class\])ism",$body, $attached, PREG_SET_ORDER)) {
|
||||
foreach ($attached AS $data) {
|
||||
if (!in_array($data[1], array("type-link", "type-video", "type-photo")))
|
||||
|
@ -43,6 +34,116 @@ function get_attached_data($body) {
|
|||
}
|
||||
}
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
function get_attachment_data($body) {
|
||||
|
||||
$data = array();
|
||||
|
||||
if (!preg_match("/(.*)\[attachment(.*)\](.*?)\[\/attachment\](.*)/ism", $body, $match))
|
||||
return get_old_attachment_data($body);
|
||||
|
||||
$attributes = $match[2];
|
||||
|
||||
$data["text"] = trim($match[1]);
|
||||
|
||||
$type = "";
|
||||
preg_match("/type='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$type = strtolower($matches[1]);
|
||||
|
||||
preg_match('/type="(.*?)"/ism', $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$type = strtolower($matches[1]);
|
||||
|
||||
if ($type == "")
|
||||
return(array());
|
||||
|
||||
if (!in_array($type, array("link", "audio", "video")))
|
||||
return(array());
|
||||
|
||||
if ($type != "")
|
||||
$data["type"] = $type;
|
||||
|
||||
$url = "";
|
||||
preg_match("/url='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$url = $matches[1];
|
||||
|
||||
preg_match('/url="(.*?)"/ism', $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$url = $matches[1];
|
||||
|
||||
if ($url != "")
|
||||
$data["url"] = $url;
|
||||
|
||||
$title = "";
|
||||
preg_match("/title='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$title = $matches[1];
|
||||
|
||||
preg_match('/title="(.*?)"/ism', $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$title = $matches[1];
|
||||
|
||||
//$title = htmlentities($title, ENT_QUOTES, 'UTF-8', false);
|
||||
$title = bbcode(html_entity_decode($title, ENT_QUOTES, 'UTF-8'), false, false, true);
|
||||
$title = str_replace(array("[", "]"), array("[", "]"), $title);
|
||||
|
||||
if ($title != "")
|
||||
$data["title"] = $title;
|
||||
|
||||
$image = "";
|
||||
if ($type != "video") {
|
||||
preg_match("/image='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$image = $matches[1];
|
||||
|
||||
preg_match('/image="(.*?)"/ism', $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$image = $matches[1];
|
||||
}
|
||||
|
||||
if ($image != "")
|
||||
$data["image"] = $image;
|
||||
|
||||
$preview = "";
|
||||
if ($type != "video") {
|
||||
preg_match("/preview='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$preview = $matches[1];
|
||||
|
||||
preg_match('/preview="(.*?)"/ism', $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
$preview = $matches[1];
|
||||
}
|
||||
|
||||
if (($image == "") AND ($preview != ""))
|
||||
$data["image"] = $preview;
|
||||
else
|
||||
$data["preview"] = $preview;
|
||||
|
||||
$data["description"] = trim($match[3]);
|
||||
|
||||
$data["after"] = trim($match[4]);
|
||||
|
||||
return($data);
|
||||
}
|
||||
|
||||
function get_attached_data($body) {
|
||||
/*
|
||||
- text:
|
||||
- type: link, video, photo
|
||||
- title:
|
||||
- url:
|
||||
- image:
|
||||
- description:
|
||||
- (thumbnail)
|
||||
*/
|
||||
|
||||
$post = get_attachment_data($body);
|
||||
|
||||
// if nothing is found, it maybe having an image.
|
||||
if (!isset($post["type"])) {
|
||||
require_once("mod/parse_url.php");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue