mirror of
https://github.com/friendica/friendica
synced 2025-05-02 03:44:24 +02:00
Review update
Rename function, move others
This commit is contained in:
parent
0f1be37279
commit
f04d40a37e
55 changed files with 331 additions and 326 deletions
|
@ -78,7 +78,7 @@ class OEmbed
|
|||
if (!in_array($ext, $noexts)) {
|
||||
// try oembed autodiscovery
|
||||
$redirects = 0;
|
||||
$html_text = Network::fetchURL($embedurl, false, $redirects, 15, "text/*");
|
||||
$html_text = Network::fetchUrl($embedurl, false, $redirects, 15, "text/*");
|
||||
if ($html_text) {
|
||||
$dom = @DOMDocument::loadHTML($html_text);
|
||||
if ($dom) {
|
||||
|
@ -86,13 +86,13 @@ class OEmbed
|
|||
$entries = $xpath->query("//link[@type='application/json+oembed']");
|
||||
foreach ($entries as $e) {
|
||||
$href = $e->getAttributeNode("href")->nodeValue;
|
||||
$txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth);
|
||||
$txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth);
|
||||
break;
|
||||
}
|
||||
$entries = $xpath->query("//link[@type='text/json+oembed']");
|
||||
foreach ($entries as $e) {
|
||||
$href = $e->getAttributeNode("href")->nodeValue;
|
||||
$txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth);
|
||||
$txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ class OEmbed
|
|||
|
||||
$allowed = explode(',', $str_allowed);
|
||||
|
||||
return Network::allowedDomain($domain, $allowed);
|
||||
return Network::isDomainAllowed($domain, $allowed);
|
||||
}
|
||||
|
||||
public static function getHTML($url, $title = null)
|
||||
|
|
|
@ -6,7 +6,10 @@ namespace Friendica\Content\Text;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\Content\Text\Plaintext;
|
||||
use Friencica\Core\Config;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Util\ParseUrl;
|
||||
|
||||
|
@ -475,4 +478,74 @@ class BBCode
|
|||
|
||||
return($post);
|
||||
}
|
||||
|
||||
public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false)
|
||||
{
|
||||
// Suppress "view full size"
|
||||
if (intval(Config::get('system', 'no_view_full_size'))) {
|
||||
$include_link = false;
|
||||
}
|
||||
|
||||
// Picture addresses can contain special characters
|
||||
$s = htmlspecialchars_decode($srctext);
|
||||
|
||||
$matches = null;
|
||||
$c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER);
|
||||
if ($c) {
|
||||
foreach ($matches as $mtch) {
|
||||
logger('scale_external_image: ' . $mtch[1]);
|
||||
|
||||
$hostname = str_replace('www.', '', substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3));
|
||||
if (stristr($mtch[1], $hostname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// $scale_replace, if passed, is an array of two elements. The
|
||||
// first is the name of the full-size image. The second is the
|
||||
// name of a remote, scaled-down version of the full size image.
|
||||
// This allows Friendica to display the smaller remote image if
|
||||
// one exists, while still linking to the full-size image
|
||||
if ($scale_replace) {
|
||||
$scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]);
|
||||
} else {
|
||||
$scaled = $mtch[1];
|
||||
}
|
||||
$i = self::fetchURL($scaled);
|
||||
if (! $i) {
|
||||
return $srctext;
|
||||
}
|
||||
|
||||
// guess mimetype from headers or filename
|
||||
$type = Image::guessType($mtch[1], true);
|
||||
|
||||
if ($i) {
|
||||
$Image = new Image($i, $type);
|
||||
if ($Image->isValid()) {
|
||||
$orig_width = $Image->getWidth();
|
||||
$orig_height = $Image->getHeight();
|
||||
|
||||
if ($orig_width > 640 || $orig_height > 640) {
|
||||
$Image->scaleDown(640);
|
||||
$new_width = $Image->getWidth();
|
||||
$new_height = $Image->getHeight();
|
||||
logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
|
||||
$s = str_replace(
|
||||
$mtch[0],
|
||||
'[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]'
|
||||
. "\n" . (($include_link)
|
||||
? '[url=' . $mtch[1] . ']' . L10n::t('view full size') . '[/url]' . "\n"
|
||||
: ''),
|
||||
$s
|
||||
);
|
||||
logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// replace the special char encoding
|
||||
$s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
|
||||
return $s;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue