1
1
Fork 0

Merge pull request #7466 from annando/api-alt

API: We now transmit the text description there as well
This commit is contained in:
Hypolite Petovan 2019-08-04 07:16:34 -04:00 committed by GitHub
commit d5fc4a268d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 20 deletions

View file

@ -2693,19 +2693,29 @@ function api_get_entitities(&$text, $bbcode)
}
}
preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
preg_match_all("/\[img\=(.*?)\](.*?)\[\/img\]/ism", $bbcode, $images, PREG_SET_ORDER);
$ordered_images = [];
foreach ($images as $image) {
$start = iconv_strpos($text, $image[1], 0, "UTF-8");
if (!($start === false)) {
$ordered_images[$start] = ['url' => $image[1], 'alt' => $image[2]];
}
}
preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
foreach ($images[1] as $image) {
//$start = strpos($text, $url, $offset);
$start = iconv_strpos($text, $image, 0, "UTF-8");
if (!($start === false)) {
$ordered_images[$start] = $image;
$ordered_images[$start] = ['url' => $image, 'alt' => ''];
}
}
//$entities["media"] = array();
$offset = 0;
foreach ($ordered_images as $url) {
foreach ($ordered_images as $image) {
$url = $image['url'];
$ext_alt_text = $image['alt'];
$display_url = str_replace(["http://www.", "https://www."], ["", ""], $url);
$display_url = str_replace(["http://", "https://"], ["", ""], $display_url);
@ -2752,6 +2762,7 @@ function api_get_entitities(&$text, $bbcode)
"url" => $url,
"display_url" => $display_url,
"expanded_url" => $url,
"ext_alt_text" => $ext_alt_text,
"type" => "photo",
"sizes" => $sizes];
}

View file

@ -1567,7 +1567,7 @@ function photos_content(App $a)
$a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
$a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
$a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
$a->page['htmlhead'] .= '<meta name="twitter:image" content="' . System::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
$a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
$a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";

View file

@ -1101,8 +1101,12 @@ class BBCode extends BaseObject
// if its a link to a picture then embed this picture
if (substr($curl_info["content_type"], 0, 6) == "image/") {
$text = "[img]" . $match[1] . "[/img]";
} else {
if (!empty($match[3])) {
$text = "[img=" . $match[2] . "]" . $match[3] . "[/img]";
} else {
$text = "[img]" . $match[2] . "[/img]";
}
// if its not a picture then look if its a page that contains a picture link
$body = Network::fetchUrl($match[1]);
@ -1120,10 +1124,14 @@ class BBCode extends BaseObject
}
if (strtolower($attr["name"]) == "twitter:image") {
if (!empty($match[3])) {
$text = "[img=" . $attr["content"] . "]" . $match[3] . "[/img]";
} else {
$text = "[img]" . $attr["content"] . "[/img]";
}
}
}
}
Cache::set($match[1], $text);
}
@ -1132,7 +1140,8 @@ class BBCode extends BaseObject
public static function cleanPictureLinks($text)
{
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $text);
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $text);
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $return);
return $return;
}

View file

@ -21,6 +21,7 @@ use Friendica\Protocol\DFRN;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Security;
use Friendica\Util\Strings;
require_once "include/dba.php";
@ -664,4 +665,48 @@ class Photo extends BaseObject
return true;
}
/**
* Strips known picture extensions from picture links
*
* @param string $name Picture link
* @return string stripped picture link
* @throws \Exception
*/
public static function stripExtension($name)
{
$name = str_replace([".jpg", ".png", ".gif"], ["", "", ""], $name);
foreach (Image::supportedTypes() as $m => $e) {
$name = str_replace("." . $e, "", $name);
}
return $name;
}
/**
* Returns the GUID from picture links
*
* @param string $name Picture link
* @return string GUID
* @throws \Exception
*/
public static function getGUID($name)
{
$a = \get_app();
$base = $a->getBaseURL();
$guid = str_replace([Strings::normaliseLink($base), '/photo/'], '', Strings::normaliseLink($name));
$guid = self::stripExtension($guid);
if (substr($guid, -2, 1) != "-") {
return '';
}
$scale = intval(substr($guid, -1, 1));
if (empty($scale)) {
return '';
}
$guid = substr($guid, 0, -2);
return $guid;
}
}

View file

@ -53,15 +53,15 @@ class Photo extends BaseModule
switch($a->argc) {
case 4:
$customsize = intval($a->argv[2]);
$uid = self::stripExtension($a->argv[3]);
$uid = MPhoto::stripExtension($a->argv[3]);
$photo = self::getAvatar($uid, $a->argv[1]);
break;
case 3:
$uid = self::stripExtension($a->argv[2]);
$uid = MPhoto::stripExtension($a->argv[2]);
$photo = self::getAvatar($uid, $a->argv[1]);
break;
case 2:
$photoid = self::stripExtension($a->argv[1]);
$photoid = MPhoto::stripExtension($a->argv[1]);
$scale = 0;
if (substr($photoid, -2, 1) == "-") {
$scale = intval(substr($photoid, -1, 1));
@ -117,15 +117,6 @@ class Photo extends BaseModule
exit();
}
private static function stripExtension($name)
{
$name = str_replace([".jpg", ".png", ".gif"], ["", "", ""], $name);
foreach (Image::supportedTypes() as $m => $e) {
$name = str_replace("." . $e, "", $name);
}
return $name;
}
private static function getAvatar($uid, $type="avatar")
{