@@ -27,9 +27,18 @@ function sepiaFW_build_ui_cards(){
2727 //some specials
2828 Cards . canEmbedCustomPlayer = true ;
2929 Cards . canEmbedYouTube = true ;
30- Cards . canEmbedSoundCloud = false ; //TODO: for testing
30+ Cards . canEmbedSoundCloud = false ; //TODO: not selectable yet
3131 Cards . canEmbedSpotify = false ; //deactivated by default because it only works in desktop and gives no control over start/stop/volume
3232 Cards . canEmbedAppleMusic = false ; // "" ""
33+ Cards . getSupportedWebPlayers = function ( ) {
34+ var players = [ ] ;
35+ if ( Cards . canEmbedCustomPlayer ) players . push ( "embedded" ) ;
36+ if ( Cards . canEmbedYouTube ) players . push ( "youtube" ) ;
37+ if ( Cards . canEmbedSpotify ) players . push ( "spotify" ) ;
38+ if ( Cards . canEmbedAppleMusic ) players . push ( "apple_music" ) ;
39+ if ( Cards . canEmbedSoundCloud ) players . push ( "soundcloud" ) ;
40+ return players ;
41+ }
3342 Cards . canEmbedWebPlayer = function ( service ) {
3443 if ( ! service ) return false ;
3544 service = service . toLowerCase ( ) . replace ( / \s + / , "_" ) ; //support brands too
@@ -47,14 +56,18 @@ function sepiaFW_build_ui_cards(){
4756 return false ;
4857 }
4958 }
50- Cards . getSupportedWebPlayers = function ( ) {
51- var players = [ ] ;
52- if ( Cards . canEmbedCustomPlayer ) players . push ( "embedded" ) ;
53- if ( Cards . canEmbedYouTube ) players . push ( "youtube" ) ;
54- if ( Cards . canEmbedSpotify ) players . push ( "spotify" ) ;
55- if ( Cards . canEmbedAppleMusic ) players . push ( "apple_music" ) ;
56- if ( Cards . canEmbedSoundCloud ) players . push ( "soundcloud" ) ;
57- return players ;
59+ Cards . canEmbedUrl = function ( url ) {
60+ if ( ! url ) return false ;
61+ var testUrl = url . toLowerCase ( ) . trim ( ) ;
62+ //YouTube
63+ if ( Cards . canEmbedYouTube && testUrl . indexOf ( "https://www.youtube.com/embed/" ) == 0 ) {
64+ //TODO: add more variations
65+ return {
66+ type : "videoSearch" ,
67+ typeData : { service : "youtube" , uri : url }
68+ }
69+ }
70+ return false ;
5871 }
5972
6073 //get a full card result as DOM element
@@ -1228,6 +1241,29 @@ function sepiaFW_build_ui_cards(){
12281241 var typeInfo = { } ;
12291242 linkCardEle . className = 'linkCard cardBodyItem' ;
12301243 linkCardEle . id = 'link-' + currentLinkItemId ++ ; //links have no database event ID (compare: time-events) so we just create one here to connect item and context-menu
1244+
1245+ //check link sanity
1246+ if ( linkUrl ) {
1247+ var hasValidUrlProtocol = SepiaFW . tools . urlHasValidProtocol ( linkUrl ) ;
1248+ var isValidLocalHtmlPage = SepiaFW . tools . isRelativeFileUrl ( linkUrl , "html" ) ;
1249+ var isUrlOk = hasValidUrlProtocol || isValidLocalHtmlPage ;
1250+ if ( ! isUrlOk ) {
1251+ //is this enough? - For now its ok ^^
1252+ SepiaFW . ui . showInfo ( "URL has been removed from link card because it looked suspicious" , true ) ;
1253+ SepiaFW . debug . error ( "Link-Card - Tried to create card with suspicious URL: " + linkUrl ) ;
1254+ linkUrl = "" ;
1255+ }
1256+ }
1257+ //check for popular links, e.g. YouTube ...
1258+ if ( linkUrl && ( ! data . type || ! data . typeData ) ) {
1259+ var embedData = Cards . canEmbedUrl ( linkUrl ) ;
1260+ if ( ! ! embedData ) {
1261+ //set or overwrite data:
1262+ data . type = embedData . type ;
1263+ data . typeData = embedData . typeData ;
1264+ }
1265+ }
1266+
12311267 var leftElement ;
12321268 if ( data . type ) {
12331269 linkCardEle . className += ( " " + data . type ) ;
@@ -1260,19 +1296,6 @@ function sepiaFW_build_ui_cards(){
12601296 }
12611297 var description = data . desc ;
12621298 if ( description && description . length > 120 ) description = description . substring ( 0 , 119 ) + "..." ;
1263-
1264- //check link
1265- if ( linkUrl ) {
1266- var hasValidUrlProtocol = SepiaFW . tools . urlHasValidProtocol ( linkUrl ) ;
1267- var isValidLocalHtmlPage = SepiaFW . tools . isRelativeFileUrl ( linkUrl , "html" ) ;
1268- var isUrlOk = hasValidUrlProtocol || isValidLocalHtmlPage ;
1269- if ( ! isUrlOk ) {
1270- //TODO: is this enough?
1271- SepiaFW . ui . showInfo ( "URL has been removed from link card because it looked suspicious" , true ) ;
1272- SepiaFW . debug . error ( "Link-Card - Tried to create card with suspicious URL: " + linkUrl ) ;
1273- linkUrl = "" ;
1274- }
1275- }
12761299
12771300 //build actual card element
12781301 var rightElement = "<div class='itemRight linkCardRight'><a href='' target='_blank' rel='noopener'><i class='material-icons md-mnu'></i></a></div>" ;
0 commit comments