4 * @file mod/parse_url.php
5 * @brief The parse_url module
7 * This module does parse an url for embeddable content (audio, video, image files or link)
8 * information and does format this information to BBCode
10 * @see ParseUrl::getSiteinfo() for more information about scraping embeddable content
13 use \Friendica\ParseUrl;
15 require_once("include/items.php");
17 function parse_url_content(App $a) {
24 if (x($_GET,"binurl")) {
25 $url = trim(hex2bin($_GET["binurl"]));
27 $url = trim($_GET["url"]);
31 $title = strip_tags(trim($_GET["title"]));
34 if ($_GET["description"]) {
35 $text = strip_tags(trim($_GET["description"]));
39 $arr_tags = ParseUrl::convertTagsToArray($_GET["tags"]);
40 if (count($arr_tags)) {
41 $str_tags = $br . implode(" ", $arr_tags) . $br;
45 // Add url scheme if it is missing
46 $arrurl = parse_url($url);
47 if (!x($arrurl, "scheme")) {
48 if (x($arrurl, "host")) {
51 $url = "http://".$url;
55 logger("prse_url: " . $url);
57 // Check if the URL is an image, video or audio file. If so format
58 // the URL with the corresponding BBCode media tag
60 // Fetch the header of the URL
61 $result = z_fetch_url($url, false, $redirects, array("novalidate" => true, "nobody" => true));
62 if($result["success"]) {
63 // Convert the header fields into an array
65 $h = explode("\n", $result["header"]);
67 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
70 if (array_key_exists("Content-Type", $hdrs)) {
71 $type = $hdrs["Content-Type"];
74 if(stripos($type, "image/") !== false) {
75 echo $br . "[img]" . $url . "[/img]" . $br;
78 if (stripos($type, "video/") !== false) {
79 echo $br . "[video]" . $url . "[/video]" . $br;
82 if (stripos($type, "audio/") !== false) {
83 echo $br . "[audio]" . $url . "[/audio]" . $br;
89 $template = "[bookmark=%s]%s[/bookmark]%s";
91 $arr = array("url" => $url, "text" => "");
93 call_hooks("parse_link", $arr);
95 if (strlen($arr["text"])) {
100 // If there is allready some content information submitted we don't
101 // need to parse the url for content.
102 if ($url && $title && $text) {
104 $title = str_replace(array("\r","\n"),array("",""),$title);
106 $text = "[quote]" . trim($text) . "[/quote]" . $br;
108 $result = sprintf($template, $url, ($title) ? $title : $url, $text) . $str_tags;
110 logger("parse_url (unparsed): returns: " . $result);
116 // Fetch the information directly from the webpage
117 $siteinfo = ParseUrl::getSiteinfo($url);
119 unset($siteinfo["keywords"]);
121 // Format it as BBCode attachment
122 $info = add_page_info_data($siteinfo);
130 * @brief Legacy function to call ParseUrl::getSiteinfoCached
132 * Note: We have moved the function to ParseUrl.php. This function is only for
133 * legacy support and will be remove in the future
135 * @param type $url The url of the page which should be scraped
136 * @param type $no_guessing If true the parse doens't search for
138 * @param type $do_oembed The false option is used by the function fetch_oembed()
139 * to avoid endless loops
141 * @return array which contains needed data for embedding
143 * @see ParseUrl::getSiteinfoCached()
145 * @todo Remove this function after all Addons has been changed to use
146 * ParseUrl::getSiteinfoCached
148 function parseurl_getsiteinfo_cached($url, $no_guessing = false, $do_oembed = true) {
149 $siteinfo = ParseUrl::getSiteinfoCached($url, $no_guessing, $do_oembed);