3 * @file mod/parse_url.php
4 * @brief The parse_url module
6 * This module does parse an url for embedable content (audio, video, image files or link)
7 * information and does format this information to BBCode or html (this depends
8 * on the user settings - default is BBCode output).
9 * If the user has enabled the richtext editor setting the output will be in html
10 * (Note: This is not always possible and in some case not useful because
11 * the richtext editor doesn't support all ind of html).
12 * Otherwise the output will be constructed BBCode.
14 * @todo https://developers.google.com/+/plugins/snippet/
17 * <meta itemprop="name" content="Toller Titel">
18 * <meta itemprop="description" content="Eine tolle Beschreibung">
19 * <meta itemprop="image" content="http://maple.libertreeproject.org/images/tree-icon.png">
21 * <body itemscope itemtype="http://schema.org/Product">
22 * <h1 itemprop="name">Shiny Trinket</h1>
23 * <img itemprop="image" src="{image-url}" />
24 * <p itemprop="description">Shiny trinkets are shiny.</p>
29 use \Friendica\ParseUrl;
31 require_once("include/items.php");
33 function parse_url_content(&$a) {
40 if (local_user() && (!feature_enabled(local_user(), "richtext"))) {
44 $br = (($textmode) ? "\n" : "<br />");
46 if (x($_GET,"binurl")) {
47 $url = trim(hex2bin($_GET["binurl"]));
49 $url = trim($_GET["url"]);
53 $title = strip_tags(trim($_GET["title"]));
56 if ($_GET["description"]) {
57 $text = strip_tags(trim($_GET["description"]));
61 $arr_tags = ParseUrl::convertTagsToArray($_GET["tags"]);
62 if (count($arr_tags)) {
63 $str_tags = $br . implode(" ", $arr_tags) . $br;
67 // Add url scheme if it is missing
68 $arrurl = parse_url($url);
69 if (!x($arrurl, "scheme")) {
70 if (x($arrurl, "host")) {
73 $url = "http://".$url;
77 logger("prse_url: " . $url);
79 // Check if the URL is an image, video or audio file. If so format
80 // the URL with the corresponding BBCode media tag
82 // Fetch the header of the URL
83 $result = z_fetch_url($url, false, $redirects, array("novalidate" => true, "nobody" => true));
84 if($result["success"]) {
85 // Convert the header fields into an array
87 $h = explode("\n", $result["header"]);
89 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
92 if (array_key_exists("Content-Type", $hdrs)) {
93 $type = $hdrs["Content-Type"];
96 if(stripos($type, "image/") !== false) {
97 echo $br . "[img]" . $url . "[/img]" . $br;
100 if (stripos($type, "video/") !== false) {
101 echo $br . "[video]" . $url . "[/video]" . $br;
104 if (stripos($type, "audio/") !== false) {
105 echo $br . "[audio]" . $url . "[/audio]" . $br;
112 $template = "[bookmark=%s]%s[/bookmark]%s";
114 $template = "<a class=\"bookmark\" href=\"%s\" >%s</a>%s";
117 $arr = array("url" => $url, "text" => "");
119 call_hooks("parse_link", $arr);
121 if (strlen($arr["text"])) {
126 // If there is allready some content information submitted we don't
127 // need to parse the url for content.
128 if ($url && $title && $text) {
130 $title = str_replace(array("\r","\n"),array("",""),$title);
133 $text = "[quote]" . trim($text) . "[/quote]" . $br;
135 $text = "<blockquote>" . htmlspecialchars(trim($text)) . "</blockquote><br />";
136 $title = htmlspecialchars($title);
139 $result = sprintf($template, $url, ($title) ? $title : $url, $text) . $str_tags;
141 logger("parse_url (unparsed): returns: " . $result);
147 // Fetch the information directly from the webpage
148 $siteinfo = ParseUrl::getSiteinfo($url);
150 unset($siteinfo["keywords"]);
152 // Format it as BBCode attachment
153 $info = add_page_info_data($siteinfo);
156 // Replace ' with ’ - not perfect - but the richtext editor has problems otherwise
157 $info = str_replace(array("'"), array("’"), $info);