function parse_link(data) { if (data == null) { return ""; } var html = data; var recommendedWidth = 400; var recommendedHeight = 300; var extraViewClasses = ""; var sourceLink = null; var plainText = false; var genericEmbedMatcher = /embed\:(https?\:\/\/[^ <]+)/; var genericUriMatcher = /(https?\:\/\/[^ <]+)/; var type = "unknown"; var provider_name = "unknown"; isDataFileUrl = function(url) { var file, suffix; try { if (url.split("/").length < 4) { return false; } file = _.last(url.split("/")); if (file.indexOf(".") < 0) { return false; } suffix = _.last(file.split(".")); if (!suffix) { return false; } if (_.include(["png", "jpg", "jpeg", "gif", "zip", "rar", "7z", "tar", "tgz", "gz", "xls", "xlsx", "doc", "docx", "ppt", "pptx", "mp3", "ogg", "oga", "ogv", "pdf", "dmg", "exe", "iso", "dxf", "ipa", "mov", "wmv", "wma", "wav", "aiff", "mp4", "m4a", "prg", "bin", "dat", "psd", "ai", "eps", "key"], suffix)) { return true; } } catch (_error) {} return false; }; if (m = data.match(genericEmbedMatcher)) { embedUri = m[1]; html = ""; recommendedWidth = 640 / 2; recommendedHeight = 390 / 2; sourceLink = embedUri; extraViewClasses = "external-embed"; } else if (data.match(/http/) && data.replace(/[^<]/g, "").length < 3) { youtubeMatcher = /youtube\.com\/.*v=([^&<]+)/; youtubeMatcher2 = /youtu\.be\/([^&<]+)/; soundcloudMatcher = /soundcloud\.com\/([^<]+)/; vimeoMatcher = /vimeo.com\/([^<]*)/; dailyMotionMatcher = /dailymotion.com\/video\/([^<]*)/; googleMapsMatcher = /google.com\/maps\?([^<]*)/; spacedeckMatcher = new RegExp(location.host + "\/(spaces|folders)\/([0-9a-f]{24})"); if (m = data.match(youtubeMatcher) || (m = data.match(youtubeMatcher2))) { videoId = m[1]; html = ""; recommendedWidth = 640 / 2; recommendedHeight = 390 / 2; provider_name = "youtube"; type = "video"; } else if (m = data.match(dailyMotionMatcher)) { videoId = m[1]; html = ""; recommendedWidth = 536 / 2; recommendedHeight = 302 / 2; provider_name = "dailymotion"; type = "video"; } else if (m = data.match(vimeoMatcher)) { videoId = m[1]; html = ""; recommendedWidth = 536 / 2; recommendedHeight = 302 / 2; provider_name = "vimeo"; type = "video"; } else if (m = data.match(soundcloudMatcher)) { var scurl = "https://" + m[0]; var url; if (m[0].indexOf("soundcloud.com/player")>=0) { url = "https://w." + m[0]; } else { url = "https://w.soundcloud.com/player/?url="+encodeURI(scurl); } html = ""; recommendedWidth = 720 / 2; recommendedHeight = 184; sourceLink = scurl; provider_name = "soundcloud"; type = "audio"; } else if ((m = data.match(googleMapsMatcher))) { mapsParams = m[1]; html = ""; recommendedWidth = 640 / 2; recommendedHeight = 390 / 2; provider_name = "google"; type = "map"; } else if ((m = data.match(genericUriMatcher)) && !isDataFileUrl(m[1])) { uri = m[1]; grabUri = uri; endPoint = "/api/webgrabber/" + (encodeURIComponent(btoa(grabUri))); html = data.replace(uri, " "); recommendedWidth = 300; recommendedHeight = 300; sourceLink = uri; } else { plainText = true; } } else { plainText = true; } if (plainText) { // replace links with clickable links return null; } result = { html: html, thumbnail_width: recommendedWidth, thumbnail_height: recommendedHeight, type: type, provider_name: provider_name, url: sourceLink }; return result; };