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
14 use Friendica\ParseUrl;
16 require_once("include/items.php");
18 function parse_url_content(App $a) {
25 if (x($_GET,"binurl")) {
26 $url = trim(hex2bin($_GET["binurl"]));
28 $url = trim($_GET["url"]);
32 $title = strip_tags(trim($_GET["title"]));
35 if ($_GET["description"]) {
36 $text = strip_tags(trim($_GET["description"]));
40 $arr_tags = ParseUrl::convertTagsToArray($_GET["tags"]);
41 if (count($arr_tags)) {
42 $str_tags = $br . implode(" ", $arr_tags) . $br;
46 // Add url scheme if it is missing
47 $arrurl = parse_url($url);
48 if (!x($arrurl, "scheme")) {
49 if (x($arrurl, "host")) {
52 $url = "http://".$url;
56 logger("prse_url: " . $url);
58 // Check if the URL is an image, video or audio file. If so format
59 // the URL with the corresponding BBCode media tag
61 // Fetch the header of the URL
62 $result = z_fetch_url($url, false, $redirects, array("novalidate" => true, "nobody" => true));
63 if($result["success"]) {
64 // Convert the header fields into an array
66 $h = explode("\n", $result["header"]);
68 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
71 if (array_key_exists("Content-Type", $hdrs)) {
72 $type = $hdrs["Content-Type"];
75 if(stripos($type, "image/") !== false) {
76 echo $br . "[img]" . $url . "[/img]" . $br;
79 if (stripos($type, "video/") !== false) {
80 echo $br . "[video]" . $url . "[/video]" . $br;
83 if (stripos($type, "audio/") !== false) {
84 echo $br . "[audio]" . $url . "[/audio]" . $br;
90 $template = "[bookmark=%s]%s[/bookmark]%s";
92 $arr = array("url" => $url, "text" => "");
94 call_hooks("parse_link", $arr);
96 if (strlen($arr["text"])) {
101 // If there is allready some content information submitted we don't
102 // need to parse the url for content.
103 if ($url && $title && $text) {
105 $title = str_replace(array("\r","\n"),array("",""),$title);
107 $text = "[quote]" . trim($text) . "[/quote]" . $br;
109 $result = sprintf($template, $url, ($title) ? $title : $url, $text) . $str_tags;
111 logger("parse_url (unparsed): returns: " . $result);
117 // Fetch the information directly from the webpage
118 $siteinfo = ParseUrl::getSiteinfo($url);
120 unset($siteinfo["keywords"]);
122 // Format it as BBCode attachment
123 $info = add_page_info_data($siteinfo);
131 * @brief Legacy function to call ParseUrl::getSiteinfoCached
133 * Note: We have moved the function to ParseUrl.php. This function is only for
134 * legacy support and will be remove in the future
136 * @param type $url The url of the page which should be scraped
137 * @param type $no_guessing If true the parse doens't search for
139 * @param type $do_oembed The false option is used by the function fetch_oembed()
140 * to avoid endless loops
142 * @return array which contains needed data for embedding
144 * @see ParseUrl::getSiteinfoCached()
146 * @todo Remove this function after all Addons has been changed to use
147 * ParseUrl::getSiteinfoCached
149 function parseurl_getsiteinfo_cached($url, $no_guessing = false, $do_oembed = true) {
150 $siteinfo = ParseUrl::getSiteinfoCached($url, $no_guessing, $do_oembed);