Пример #1
0
        /// <summary>
        /// Used by <see cref="SFLink"/> constructor, includes logic to ensure the url is
        /// a valid URI, gets a corresponding uri and extension, while fixing things such as
        /// links without a protocol (defaults to http).
        /// </summary>
        public static bool FixOrValidateInputUrl(string inUrl, out string url, out Uri uri, out string ext)
        {
            url = inUrl.NullIfEmptyTrimmed();
            uri = null;
            ext = null;

            if (url.IsNulle())
            {
                return(false);
            }

            if (!ExtraTextFuncs.IsWebLink(url, checkForWww: true))
            {
                return(false);
            }

            if (url[0] == 'w')            // above check determines if [0] == 'w', then this == 'www.'
            {
                url = "http://" + url;
            }

            if (url.IndexOf(' ') > 0)            // is pry a quicker check than always running the replace...
            {
                url = url.Replace(" ", "%20");   // some links have spaces in them that invalidate the IsWellFormedOriginalString check below
            }
            try {
                // note: this WILL throw an Ex for some things.
                // however, it also accepts ALL kinds of JUNK that
                // obviously is not a valid Uri, I don't get it.
                // So we're still doing the IsWellFormedOriginalString
                // check, but that is largely useless in some of my tests

                uri = new Uri(url);
                if (uri == null || !uri.IsWellFormedOriginalString())
                {
                    return(false);
                }

                url = uri.AbsoluteUri;                 // do NOT do .ToString(), that is the 'canonical' form which ruins escapes, like replacing ' ' (space) for %20! dumb
            }
            catch {
                return(false);
            }

            // do NOT place this within the try/catch. there should be NO errors in this call
            // so if it does throw we need to know the bug
            UriPathInfo pathInfo = new UriPathInfo(uri.AbsolutePath);

            ext = pathInfo.Extension;
            //Ext = UriPathInfo.GetExtFromUrl(_uri.AbsolutePath);
            // BasicMimeTypesX.GetExtFromUrl(_uri.AbsolutePath); //AbsolutePath removes any query string ending
            return(true);
        }
Пример #2
0
        public void AddMeta(XElement item)
        {
            var f = ParentSettings?.ParentFeed;

            if (item == null || f == null)
            {
                return;
            }

            // rawvoice
            // http://www.rawvoice.com/services/tools-and-resources/rawvoice-rss-2-0-module-xmlns-namespace-rss2/

            /* metamark, if present as a sub-item of <item> and <item> includes an <enclosure> item,
             * specifies additional meta information that may complement the enclosure and/or may be used
             * during the playback of the enclosure’s media. It has four attributes:
             * type, link, position and duration and may contain a value. */
            if (f.HasRawVoice)
            {
                foreach (var metaX in item.Elements(SimpleFeed.xname_rawvoice_metamark))
                {
                    var meta = new SFFeedMeta()
                    {
                        Source = "rawvoice.meta",
                        Type   = metaX.Attribute("type")?.Value?.Trim(),                      //.ValueN().TrimN();
                        Url    = metaX.Attribute("link")?.Value?.Trim(),                      //.ValueN().TrimN();
                        Value  = metaX?.Value?.Trim()
                    };
                    if (meta.Value.NotNulle() || meta.Url.NotNulle())
                    {
                        Metas.Add(meta);

                        //BasicMimeType typ = isLinkRVMeta.V(meta.Type, BasicMimeType.none);
                        string url = ExtraTextFuncs.IsWebLink(meta.Url)
                                                        ? meta.Url
                                                        : (ExtraTextFuncs.IsWebLink(meta.Value) ? meta.Value : null);

                        if (url != null)
                        {
                            var lnk = new SFLink(url, meta.Type);
                            if (lnk != null && lnk.IsValid)
                            {
                                AddLink(lnk);
                            }
                        }
                    }
                }
            }
        }