From 3600289262a27158f45accd6bb274e3873b89906 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 20 Oct 2014 08:03:47 +0200 Subject: [PATCH] New hook "getsiteinfo", separating fetching site info from generating bbcode --- include/items.php | 25 +++++++++++++++++-------- mod/parse_url.php | 9 +++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/items.php b/include/items.php index 0d37fa1a6e..428c8e27d7 100644 --- a/include/items.php +++ b/include/items.php @@ -888,13 +888,7 @@ function get_atom_elements($feed, $item, $contact = array()) { return $res; } -function add_page_info($url, $no_photos = false, $photo = "", $keywords = false) { - require_once("mod/parse_url.php"); - - $data = parseurl_getsiteinfo($url, true); - - logger('add_page_info: fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG); - +function add_page_info_data($data) { // It maybe is a rich content, but if it does have everything that a link has, // then treat it that way if (($data["type"] == "rich") AND is_string($data["title"]) AND @@ -921,7 +915,7 @@ function add_page_info($url, $no_photos = false, $photo = "", $keywords = false) $text .= "[quote]".$data["text"]."[/quote]"; $hashtags = ""; - if ($keywords AND isset($data["keywords"])) { + if (isset($data["keywords"]) AND count($data["keywords"])) { $a = get_app(); $hashtags = "\n"; foreach ($data["keywords"] AS $keyword) { @@ -933,6 +927,21 @@ function add_page_info($url, $no_photos = false, $photo = "", $keywords = false) return("\n[class=type-".$data["type"]."]".$text."[/class]".$hashtags); } +function add_page_info($url, $no_photos = false, $photo = "", $keywords = false) { + require_once("mod/parse_url.php"); + + $data = parseurl_getsiteinfo($url, true); + + logger('add_page_info: fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG); + + if (!$keywords AND isset($data["keywords"])) + unset($data["keywords"]); + + $text = add_page_info_data($data); + + return($text); +} + function add_page_info_to_body($body, $texturl = false, $no_photos = false) { logger('add_page_info_to_body: fetch page info for body '.$body, LOGGER_DEBUG); diff --git a/mod/parse_url.php b/mod/parse_url.php index 4830be5d6f..564b22c042 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -333,6 +333,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co logger("parseurl_getsiteinfo: Siteinfo for ".$url." ".print_r($siteinfo, true), LOGGER_DEBUG); + call_hooks('getsiteinfo', $siteinfo); + return($siteinfo); } @@ -410,6 +412,13 @@ function parse_url_content(&$a) { $siteinfo = parseurl_getsiteinfo($url); +// if ($textmode) { +// require_once("include/items.php"); +// +// echo add_page_info_data($siteinfo); +// killme(); +// } + $url= $siteinfo["url"]; $sitedata = "";