3 * @file mod/parse_url.php
5 * @todo https://developers.google.com/+/plugins/snippet/
8 * <meta itemprop="name" content="Toller Titel">
9 * <meta itemprop="description" content="Eine tolle Beschreibung">
10 * <meta itemprop="image" content="http://maple.libertreeproject.org/images/tree-icon.png">
12 * <body itemscope itemtype="http://schema.org/Product">
13 * <h1 itemprop="name">Shiny Trinket</h1>
14 * <img itemprop="image" src="{image-url}" />
15 * <p itemprop="description">Shiny trinkets are shiny.</p>
20 use \Friendica\ParseUrl;
22 require_once("include/items.php");
24 function parse_url_content(&$a) {
31 if (local_user() && (!feature_enabled(local_user(), "richtext"))) {
35 $br = (($textmode) ? "\n" : "<br />");
37 if (x($_GET,"binurl")) {
38 $url = trim(hex2bin($_GET["binurl"]));
40 $url = trim($_GET["url"]);
44 $title = strip_tags(trim($_GET["title"]));
47 if ($_GET["description"]) {
48 $text = strip_tags(trim($_GET["description"]));
52 $arr_tags = ParseUrl::convertTagsToArray($_GET["tags"]);
53 if (count($arr_tags)) {
54 $str_tags = $br . implode(" ", $arr_tags) . $br;
58 // Add url scheme if it is missing
59 $arrurl = parse_url($url);
60 if (!x($arrurl, "scheme")) {
61 if (x($arrurl, "host")) {
64 $url = "http://".$url;
68 logger("prse_url: " . $url);
70 // If the URL is a image, video or audio file format the URL with the corresponding
73 // Fetch the header of the URL
74 $result = z_fetch_url($url, false, $redirects, array("novalidate" => true, "nobody" => true));
75 if($result["success"]) {
76 // Convert the header fields into an array
78 $h = explode("\n", $result["header"]);
80 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
83 if (array_key_exists("Content-Type", $hdrs)) {
84 $type = $hdrs["Content-Type"];
87 if(stripos($type, "image/") !== false) {
88 echo $br . "[img]" . $url . "[/img]" . $br;
91 if (stripos($type, "video/") !== false) {
92 echo $br . "[video]" . $url . "[/video]" . $br;
95 if (stripos($type, "audio/") !== false) {
96 echo $br . "[audio]" . $url . "[/audio]" . $br;
103 $template = "[bookmark=%s]%s[/bookmark]%s";
105 $template = "<a class=\"bookmark\" href=\"%s\" >%s</a>%s";
108 $arr = array("url" => $url, "text" => "");
110 call_hooks("parse_link", $arr);
112 if (strlen($arr["text"])) {
118 if ($url && $title && $text) {
120 $title = str_replace(array("\r","\n"),array("",""),$title);
123 $text = "[quote]" . trim($text) . "[/quote]" . $br;
125 $text = "<blockquote>" . htmlspecialchars(trim($text)) . "</blockquote><br />";
126 $title = htmlspecialchars($title);
129 $result = sprintf($template, $url, ($title) ? $title : $url, $text) . $str_tags;
131 logger("parse_url (unparsed): returns: " . $result);
137 // Fetch the information from the webpage
138 $siteinfo = ParseUrl::getSiteinfo($url);
140 unset($siteinfo["keywords"]);
142 // Format it as BBCode attachment
143 $info = add_page_info_data($siteinfo);
146 // Replace ' with ’ - not perfect - but the richtext editor has problems otherwise
147 $info = str_replace(array("'"), array("’"), $info);