namespace Friendica\Util;
use Friendica\Content\OEmbed;
+use Friendica\Core\Addon;
use Friendica\Object\Image;
+use Friendica\Util\Network;
use Friendica\Util\XML;
use dba;
use DOMDocument;
require_once 'include/dba.php';
-require_once "include/network.php";
/**
* @brief Class with methods for extracting certain content from an url
return false;
}
- $r = q(
- "SELECT * FROM `parsed_url` WHERE `url` = '%s' AND `guessing` = %d AND `oembed` = %d",
- dbesc(normalise_link($url)),
- intval(!$no_guessing),
- intval($do_oembed)
+ $parsed_url = dba::selectFirst('parsed_url', ['content'],
+ ['url' => normalise_link($url), 'guessing' => !$no_guessing, 'oembed' => $do_oembed]
);
-
- if ($r) {
- $data = $r[0]["content"];
- }
-
- if (!is_null($data)) {
- $data = unserialize($data);
+ if (!empty($parsed_url['content'])) {
+ $data = unserialize($parsed_url['content']);
return $data;
}
dba::insert(
'parsed_url',
- array(
+ [
'url' => normalise_link($url), 'guessing' => !$no_guessing,
'oembed' => $do_oembed, 'content' => serialize($data),
- 'created' => datetime_convert()),
+ 'created' => DateTimeFormat::utcNow()
+ ],
true
);
{
$a = get_app();
- $siteinfo = array();
+ $siteinfo = [];
// Check if the URL does contain a scheme
$scheme = parse_url($url, PHP_URL_SCHEME);
$url = trim($url, "'");
$url = trim($url, '"');
- $url = strip_tracking_query_params($url);
+ $url = Network::stripTrackingQueryParams($url);
$siteinfo["url"] = $url;
$siteinfo["type"] = "link";
- $data = z_fetch_url($url);
+ $data = Network::curl($url);
if (!$data['success']) {
return($siteinfo);
}
if ($do_oembed) {
$oembed_data = OEmbed::fetchURL($url);
- if (!in_array($oembed_data->type, array("error", "rich", ""))) {
- $siteinfo["type"] = $oembed_data->type;
- }
-
- if (($oembed_data->type == "link") && ($siteinfo["type"] != "photo")) {
- if (isset($oembed_data->title)) {
- $siteinfo["title"] = trim($oembed_data->title);
+ if (!empty($oembed_data->type)) {
+ if (!in_array($oembed_data->type, ["error", "rich", ""])) {
+ $siteinfo["type"] = $oembed_data->type;
}
- if (isset($oembed_data->description)) {
- $siteinfo["text"] = trim($oembed_data->description);
- }
- if (isset($oembed_data->thumbnail_url)) {
- $siteinfo["image"] = $oembed_data->thumbnail_url;
+
+ if (($oembed_data->type == "link") && ($siteinfo["type"] != "photo")) {
+ if (isset($oembed_data->title)) {
+ $siteinfo["title"] = trim($oembed_data->title);
+ }
+ if (isset($oembed_data->description)) {
+ $siteinfo["text"] = trim($oembed_data->description);
+ }
+ if (isset($oembed_data->thumbnail_url)) {
+ $siteinfo["image"] = $oembed_data->thumbnail_url;
+ }
}
}
}
$list = $xpath->query("//meta[@content]");
foreach ($list as $node) {
- $attr = array();
+ $attr = [];
if ($node->attributes->length) {
foreach ($node->attributes as $attribute) {
$attr[$attribute->name] = $attribute->value;
//$list = $xpath->query("head/meta[@name]");
$list = $xpath->query("//meta[@name]");
foreach ($list as $node) {
- $attr = array();
+ $attr = [];
if ($node->attributes->length) {
foreach ($node->attributes as $attribute) {
$attr[$attribute->name] = $attribute->value;
}
}
- $attr["content"] = trim(html_entity_decode($attr["content"], ENT_QUOTES, "UTF-8"));
+ if (!empty($attr["content"])) {
+ $attr["content"] = trim(html_entity_decode($attr["content"], ENT_QUOTES, "UTF-8"));
- if ($attr["content"] != "") {
switch (strtolower($attr["name"])) {
case "fulltitle":
$siteinfo["title"] = trim($attr["content"]);
}
if (isset($keywords)) {
- $siteinfo["keywords"] = array();
+ $siteinfo["keywords"] = [];
foreach ($keywords as $keyword) {
if (!in_array(trim($keyword), $siteinfo["keywords"])) {
$siteinfo["keywords"][] = trim($keyword);
//$list = $xpath->query("head/meta[@property]");
$list = $xpath->query("//meta[@property]");
foreach ($list as $node) {
- $attr = array();
+ $attr = [];
if ($node->attributes->length) {
foreach ($node->attributes as $attribute) {
$attr[$attribute->name] = $attribute->value;
}
}
- $attr["content"] = trim(html_entity_decode($attr["content"], ENT_QUOTES, "UTF-8"));
+ if (!empty($attr["content"])) {
+ $attr["content"] = trim(html_entity_decode($attr["content"], ENT_QUOTES, "UTF-8"));
- if ($attr["content"] != "") {
switch (strtolower($attr["property"])) {
case "og:image":
$siteinfo["image"] = $attr["content"];
if ((@$siteinfo["image"] == "") && !$no_guessing) {
$list = $xpath->query("//img[@src]");
foreach ($list as $node) {
- $attr = array();
+ $attr = [];
if ($node->attributes->length) {
foreach ($node->attributes as $attribute) {
$attr[$attribute->name] = $attribute->value;
$photodata[0] = round($photodata[0] * (300 / $photodata[1]));
$photodata[1] = 300;
}
- $siteinfo["images"][] = array("src" => $src,
+ $siteinfo["images"][] = ["src" => $src,
"width" => $photodata[0],
- "height" => $photodata[1]);
+ "height" => $photodata[1]];
}
}
- } elseif ($siteinfo["image"] != "") {
+ } elseif (!empty($siteinfo["image"])) {
$src = self::completeUrl($siteinfo["image"], $url);
unset($siteinfo["image"]);
$photodata = Image::getInfoFromURL($src);
if (($photodata) && ($photodata[0] > 10) && ($photodata[1] > 10)) {
- $siteinfo["images"][] = array("src" => $src,
+ $siteinfo["images"][] = ["src" => $src,
"width" => $photodata[0],
- "height" => $photodata[1]);
+ "height" => $photodata[1]];
}
}
}
if ($text != "") {
- $text = trim(str_replace(array("\n", "\r"), array(" ", " "), $text));
+ $text = trim(str_replace(["\n", "\r"], [" ", " "], $text));
while (strpos($text, " ")) {
$text = trim(str_replace(" ", " ", $text));
logger("parseurl_getsiteinfo: Siteinfo for ".$url." ".print_r($siteinfo, true), LOGGER_DEBUG);
- call_hooks("getsiteinfo", $siteinfo);
+ Addon::callHooks("getsiteinfo", $siteinfo);
return($siteinfo);
}
$arr_tags = str_getcsv($string);
if (count($arr_tags)) {
// add the # sign to every tag
- array_walk($arr_tags, array("self", "arrAddHashes"));
+ array_walk($arr_tags, ["self", "arrAddHashes"]);
return $arr_tags;
}