public static void ExecuteContentLink(UrlEntity link) { System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() => { if (link == null) return; if (SettingsData.Instance.ShowMediaPreviews) Messenger.Default.Send<GenericMessage<UrlEntity>>(new GenericMessage<UrlEntity>(link), (object)DialogType.MediaPreview); else CommonCommands.OpenLink(link.Url); }), DispatcherPriority.Background, new object[0]); }
internal static string LinkifiedText(EntityCollection entities, string text) { if (entities == null || entities.Count == 0) { return(text); } string linkedText = text; var entitiesSorted = entities.OrderBy(e => e.StartIndex).Reverse(); foreach (Entity entity in entitiesSorted) { if (entity is HashTagEntity) { HashTagEntity tagEntity = (HashTagEntity)entity; linkedText = string.Format( "{0}<a href=\"http://twitter.com/search?q=%23{1}\">{1}</a>{2}", linkedText.Substring(0, entity.StartIndex), tagEntity.Text, linkedText.Substring(entity.EndIndex)); } if (entity is UrlEntity) { UrlEntity urlEntity = (UrlEntity)entity; linkedText = string.Format( "{0}<a href=\"{1}\">{1}</a>{2}", linkedText.Substring(0, entity.StartIndex), urlEntity.Url, linkedText.Substring(entity.EndIndex)); } if (entity is MentionEntity) { MentionEntity mentionEntity = (MentionEntity)entity; linkedText = string.Format( "{0}<a href=\"http://twitter.com/{1}\">@{1}</a>{2}", linkedText.Substring(0, entity.StartIndex), mentionEntity.ScreenName, linkedText.Substring(entity.EndIndex)); } } return(linkedText); }
public static void CopyUrl(UrlEntity url) { try { if (url == null) return; System.Windows.Clipboard.SetText(!string.IsNullOrEmpty(url.ExpandedUrl) ? url.ExpandedUrl : url.Url); } catch { } }
/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns>The object value.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { EntityCollection result = existingValue as EntityCollection; if (result == null) { result = new EntityCollection(); } int startDepth = reader.Depth; string entityType = string.Empty; Entity entity = null; try { while (reader.Read() && reader.Depth > startDepth) { if (reader.TokenType == JsonToken.PropertyName && reader.Depth == startDepth + 1) { entityType = (string)reader.Value; continue; } if (reader.TokenType == JsonToken.StartArray || reader.TokenType == JsonToken.EndArray) { continue; } switch (entityType) { case "urls": if (reader.TokenType == JsonToken.StartObject) { entity = new UrlEntity(); } UrlEntity tue = entity as UrlEntity; if (tue != null) { ReadFieldValue(reader, "url", entity, () => tue.Url); ReadFieldValue(reader, "display_url", entity, () => tue.DisplayUrl); ReadFieldValue(reader, "expanded_url", entity, () => tue.ExpandedUrl); } break; case "user_mentions": if (reader.TokenType == JsonToken.StartObject) { entity = new MentionEntity(); } MentionEntity tme = entity as MentionEntity; if (tme != null) { ReadFieldValue(reader, "screen_name", entity, () => tme.ScreenName); ReadFieldValue(reader, "name", entity, () => tme.Name); ReadFieldValue(reader, "id", entity, () => tme.UserId); } break; case "hashtags": if (reader.TokenType == JsonToken.StartObject) { entity = new HashTagEntity(); } HashTagEntity the = entity as HashTagEntity; if (the != null) { ReadFieldValue(reader, "text", entity, () => the.Text); } break; case "media": // Move to object start and parse the entity reader.Read(); entity = parseMediaEntity(reader); break; } // Read the indicies (for all entities except Media) if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "indices" && entity != null) { reader.Read(); reader.Read(); entity.StartIndex = Convert.ToInt32((long)reader.Value); reader.Read(); entity.EndIndex = Convert.ToInt32((long)reader.Value); } if ((reader.TokenType == JsonToken.EndObject && entity != null) || entity is MediaEntity) { result.Add(entity); entity = null; } } } catch { } return(result); }
public MediaPreviewViewModel(UrlEntity url) { this.ThrobberVisible = Visibility.Visible; this.TitleVisibility = Visibility.Collapsed; this.WebBrowserVisible = Visibility.Collapsed; this.ImageVisible = Visibility.Collapsed; this.DescriptionVisibility = Visibility.Collapsed; this.MediaWidth = 400.0; this.MediaHeight = 0.0; this.Link = url; this.LinkCommand = new RelayCommand<string>(new Action<string>(this.ExecuteLinkWithClose)); this.CloseCommand = new RelayCommand(new Action(this.Close)); Task.Run((Action) (() => this.LoadMedia())); }
private void ExecuteContentLink(UrlEntity link) { App.LastURLClickMousePosition = new Point?(System.Windows.Application.Current.MainWindow.PointToScreen(Mouse.GetPosition((IInputElement)System.Windows.Application.Current.MainWindow))); CommonCommands.ExecuteContentLink(link); }
internal static MediaEntity CheckEntityandCreateMedia(UrlEntity u) { string absolutePath; if (((((!u.ExpandedUrl.EndsWith(".gif", StringComparison.InvariantCultureIgnoreCase) && !u.ExpandedUrl.EndsWith(".jpg", StringComparison.InvariantCultureIgnoreCase)) && (!u.ExpandedUrl.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase) && !u.ExpandedUrl.Contains("instagr.am", StringComparison.InvariantCultureIgnoreCase))) && ((!u.ExpandedUrl.Contains("instagram.com", StringComparison.InvariantCultureIgnoreCase) && !u.ExpandedUrl.Contains("yfrog.com", StringComparison.InvariantCultureIgnoreCase)) && (!u.ExpandedUrl.Contains("twitpic.com", StringComparison.InvariantCultureIgnoreCase) && !u.ExpandedUrl.Contains("youtube.com", StringComparison.InvariantCultureIgnoreCase)))) && ((!u.ExpandedUrl.Contains("youtu.be", StringComparison.InvariantCultureIgnoreCase) && !u.ExpandedUrl.Contains("sdrv.ms", StringComparison.InvariantCultureIgnoreCase)) && !u.ExpandedUrl.Contains("skydrive.live.com", StringComparison.InvariantCultureIgnoreCase))) && !u.ExpandedUrl.Contains("lockerz", StringComparison.InvariantCultureIgnoreCase)) { return null; } MediaEntity entity = new MediaEntity { DisplayUrl = u.DisplayUrl, ExpandedUrl = u.ExpandedUrl, Url = u.Url, EndIndex = u.EndIndex, StartIndex = u.StartIndex, MediaType = MediaEntity.MediaTypes.Photo }; if (u.ExpandedUrl.Contains("instagr.am", StringComparison.InvariantCultureIgnoreCase) || u.ExpandedUrl.Contains("instagram.com", StringComparison.InvariantCultureIgnoreCase)) { absolutePath = u.ExpandedUrl.EndsWith("/") ? u.ExpandedUrl.Remove(u.ExpandedUrl.Length - 1) : u.ExpandedUrl; entity.MediaUrl = absolutePath + "/media/"; entity.MediaUrlSecure = absolutePath + "/media/"; return entity; } if (u.ExpandedUrl.Contains("yfrog.com", StringComparison.InvariantCultureIgnoreCase)) { entity.MediaUrl = u.ExpandedUrl + ":medium"; entity.MediaUrlSecure = u.ExpandedUrl + ":medium"; return entity; } if (u.ExpandedUrl.Contains("twitpic.com", StringComparison.InvariantCultureIgnoreCase)) { absolutePath = new Uri(u.ExpandedUrl).AbsolutePath; entity.MediaUrl = "https://twitpic.com/show/full" + absolutePath; entity.MediaUrlSecure = u.ExpandedUrl; return entity; } if (u.ExpandedUrl.Contains("youtube.com", StringComparison.InvariantCultureIgnoreCase) || u.ExpandedUrl.Contains("youtu.be", StringComparison.InvariantCultureIgnoreCase)) { entity.MediaType = MediaEntity.MediaTypes.Unknown; Uri uri = new Uri(u.ExpandedUrl); if (u.ExpandedUrl.Contains("v=", StringComparison.InvariantCultureIgnoreCase)) { absolutePath = HttpUtility.ParseQueryString(uri.Query).Get("v"); } else { absolutePath = uri.AbsolutePath.Replace("/", ""); } if (!string.IsNullOrEmpty(absolutePath)) { entity.MediaUrl = "http://i.ytimg.com/vi/" + absolutePath + "/0.jpg"; entity.MediaUrlSecure = u.ExpandedUrl; return entity; } return null; } if (u.ExpandedUrl.Contains("sdrv.ms", StringComparison.InvariantCultureIgnoreCase) || u.ExpandedUrl.Contains("skydrive.live.com", StringComparison.InvariantCultureIgnoreCase)) { entity.MediaUrl = "https://apis.live.net/v5.0/skydrive/get_item_preview?type=normal&url=" + HttpUtility.UrlEncode(u.ExpandedUrl); entity.MediaUrlSecure = "https://apis.live.net/v5.0/skydrive/get_item_preview?type=normal&url=" + HttpUtility.UrlEncode(u.ExpandedUrl); return entity; } if (u.ExpandedUrl.Contains("lockerz", StringComparison.OrdinalIgnoreCase)) { entity.MediaUrl = "http://api.plixi.com/api/tpapi.svc/imagefromurl?url=" + u.ExpandedUrl + "&size=medium"; entity.MediaUrlSecure = "http://api.plixi.com/api/tpapi.svc/imagefromurl?url=" + u.ExpandedUrl + "&size=medium"; return entity; } entity.MediaUrl = u.ExpandedUrl; entity.MediaUrlSecure = u.ExpandedUrl; return entity; }