From 904f8ac422e4907ca8501186d74adb7a43e230a1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 3 Oct 2014 12:18:33 +0200 Subject: [PATCH 1/2] Creating hashtags from keywords of a feed, when additional data should be fetched. --- include/items.php | 11 ++++++++--- mod/parse_url.php | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/items.php b/include/items.php index 8cbcc3e6e9..4d6d6dcb14 100644 --- a/include/items.php +++ b/include/items.php @@ -872,7 +872,7 @@ function get_atom_elements($feed, $item, $contact = array()) { } if (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND $contact['fetch_further_information']) { - $res["body"] = $res["title"].add_page_info($res['plink']); + $res["body"] = $res["title"].add_page_info($res['plink'], false, "", true); $res["title"] = ""; $res["object-type"] = ACTIVITY_OBJ_BOOKMARK; } elseif (isset($contact["network"]) AND ($contact["network"] == NETWORK_OSTATUS)) @@ -888,7 +888,7 @@ function get_atom_elements($feed, $item, $contact = array()) { return $res; } -function add_page_info($url, $no_photos = false, $photo = "") { +function add_page_info($url, $no_photos = false, $photo = "", $keywords = false) { require_once("mod/parse_url.php"); $data = parseurl_getsiteinfo($url, true); @@ -920,7 +920,12 @@ function add_page_info($url, $no_photos = false, $photo = "") { if (($data["type"] != "photo") AND is_string($data["text"])) $text .= "[quote]".$data["text"]."[/quote]"; - return("\n[class=type-".$data["type"]."]".$text."[/class]"); + $hashtags = ""; + if ($keywords AND isset($data["keywords"])) + foreach ($data["keywords"] AS $keyword) + $hashtags .= "#".str_replace(" ", "", $keyword)." "; + + return("\n[class=type-".$data["type"]."]".$text."[/class]".$hashtags); } function add_page_info_to_body($body, $texturl = false, $no_photos = false) { diff --git a/mod/parse_url.php b/mod/parse_url.php index c5f010ac11..d314c6c67f 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -205,11 +205,23 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co case "dc.description": $siteinfo["text"] = $attr["content"]; break; + case "keywords": + $keywords = explode(",", $attr["content"]); + break; + case "news_keywords": + $keywords = explode(",", $attr["content"]); + break; } if ($siteinfo["type"] == "summary") $siteinfo["type"] = "link"; } + if (isset($keywords)) { + $siteinfo["keywords"] = array(); + foreach ($keywords as $keyword) + $siteinfo["keywords"][] = trim($keyword); + } + //$list = $xpath->query("head/meta[@property]"); $list = $xpath->query("//meta[@property]"); foreach ($list as $node) { From 759f199b6ffcdbdfcc872fbd83bbdd6bdc0991dd Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 3 Oct 2014 13:02:15 +0200 Subject: [PATCH 2/2] Created hashtags from keywords now are links. URL are cleaned from tracking data. --- include/items.php | 13 +++++++++---- mod/parse_url.php | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/items.php b/include/items.php index 4d6d6dcb14..0d37fa1a6e 100644 --- a/include/items.php +++ b/include/items.php @@ -908,7 +908,7 @@ function add_page_info($url, $no_photos = false, $photo = "", $keywords = false) return(""); if (($data["type"] != "photo") AND is_string($data["title"])) - $text .= "[bookmark=".$url."]".trim($data["title"])."[/bookmark]"; + $text .= "[bookmark=".$data["url"]."]".trim($data["title"])."[/bookmark]"; if (($data["type"] != "video") AND ($photo != "")) $text .= '[img]'.$photo.'[/img]'; @@ -921,9 +921,14 @@ function add_page_info($url, $no_photos = false, $photo = "", $keywords = false) $text .= "[quote]".$data["text"]."[/quote]"; $hashtags = ""; - if ($keywords AND isset($data["keywords"])) - foreach ($data["keywords"] AS $keyword) - $hashtags .= "#".str_replace(" ", "", $keyword)." "; + if ($keywords AND isset($data["keywords"])) { + $a = get_app(); + $hashtags = "\n"; + foreach ($data["keywords"] AS $keyword) { + $hashtag = str_replace(" ", "", $keyword); + $hashtags .= "#[url=".$a->get_baseurl()."/search?tag=".rawurlencode($hashtag)."]".$hashtag."[/url] "; + } + } return("\n[class=type-".$data["type"]."]".$text."[/class]".$hashtags); } diff --git a/mod/parse_url.php b/mod/parse_url.php index d314c6c67f..4830be5d6f 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -51,6 +51,7 @@ function completeurl($url, $scheme) { } function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $count = 1) { + require_once("include/network.php"); $a = get_app(); @@ -63,6 +64,9 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co $url = trim($url, "'"); $url = trim($url, '"'); + + $url = original_url($url); + $siteinfo["url"] = $url; $siteinfo["type"] = "link";