Exemplo n.º 1
0
        internal override void GetActiveForumsReplies(int tabId, out FriendlyUrlInfoCol urls)
        {
            urls = new FriendlyUrlInfoCol();
            var dr = SqlHelper.ExecuteReader(_connectionString, CommandType.Text,
                                             "select oldpostid, newreplyid, nr.topicid, nr.ContentId from "
                                             + GetFullyQualifiedName("dnntoaf_replies") + " r join "
                                             + GetFullyQualifiedName("ActiveForums_Replies") + " nr on (r.newreplyid=nr.replyid)");

            while (dr.Read())
            {
                var url = new FriendlyUrlInfo();
                if (!Convert.IsDBNull(dr["newReplyId"]))
                {
                    url.newId = Convert.ToInt32(dr["newReplyId"]);
                }
                if (!Convert.IsDBNull(dr["oldPostId"]))
                {
                    url.itemId = (int)dr["oldPostId"];
                }
                if (!Convert.IsDBNull(dr["TopicId"]))
                {
                    url.newParentId = Convert.ToInt32(dr["TopicId"]);
                }
                if (!Convert.IsDBNull(dr["ContentId"]))
                {
                    url.newContentId = Convert.ToInt32(dr["ContentId"]);
                }
                urls.Add(url);
            }
            dr.Close();
            dr.Dispose();
        }
Exemplo n.º 2
0
        private static FriendlyUrlInfo FriendlyUrlInfoFromArchive(Services.ViewModels.ArchiveViewModel a, bool addYear = false)
        {
            var f = new FriendlyUrlInfo();

            f.itemType = "archive";
            f.urlDate  = DateTime.Now;
            f.urlNum   = 0;
            if (addYear)
            {
                f.urlNum      = a.Year;
                f.itemId      = a.Year;
                f.parentId    = -1;
                f.qsValue     = "&articleType=archiveview&year=" + a.Year.ToString();
                f.urlFragment = a.Year.ToString();
            }
            else
            {
                f.urlNum      = a.Month;
                f.itemId      = int.Parse(a.Year.ToString() + a.Month.ToString());
                f.parentId    = a.Year;
                f.qsValue     = "&articleType=archiveview&year=" + a.Year.ToString() + "&month=" + a.Month.ToString();
                f.urlFragment = a.Year.ToString() + '/' + a.Month.ToString();
            }
            return(f);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a Friendly Url For the Item
        /// </summary>
        /// <param name="friendlyUrl">Object containing the relevant properties to create a friendly url from</param>
        /// <param name="provider">The active module provider</param>
        /// <param name="options">THe current friendly Url Options</param>
        /// <returns></returns>
        private static string MakeItemFriendlyUrl(FriendlyUrlInfo friendlyUrl, ActiveForumsModuleProvider provider, FriendlyUrlOptions options)
        {
            //calls back up the module provider to utilise the CleanNameForUrl method, which creates a safe Url using the current Url Master options.
            string friendlyUrlPath = provider.CleanNameForUrl(friendlyUrl.urlFragment, options);

            return(friendlyUrlPath);
        }
Exemplo n.º 4
0
        internal override FriendlyUrlInfo GetNewsArticleItem(int itemId, string itemType, TabUrlOptions urlOptions, int tabId)
        {
            FriendlyUrlInfo fuf = null;
            //[dnn_ifty_nap_GetNewsArticlesEntry]
            string sp = GetFullyQualifiedName("GetNewsArticlesEntry");

            SqlParameter[] parms = new SqlParameter[3];
            parms[0] = new SqlParameter("@TabId", tabId);
            parms[1] = new SqlParameter("@startingArticleId", urlOptions.StartingArticleId);
            parms[2] = new SqlParameter("@itemId", itemId);
            SqlDataReader rdr = SqlHelper.ExecuteReader(_connectionString, CommandType.StoredProcedure, sp, parms);

            //work out which url fragment to use
            string articleFragmentName = "";
            string pageFragmentName    = "";
            string authorFragmentName  = "";

            GetFragmentNames(urlOptions, out articleFragmentName, out pageFragmentName, out authorFragmentName);

            if (rdr.Read())
            {
                BindReaderToFriendlyUrl(ref fuf, rdr, articleFragmentName, pageFragmentName, authorFragmentName);
            }
            rdr.Close();
            rdr.Dispose();
            return(fuf);
        }
Exemplo n.º 5
0
        public static List <FriendlyUrlInfo> GetAuthorsForProvider(int TabId)
        {
            List <FriendlyUrlInfo> result = new List <FriendlyUrlInfo>();
            var authors = ArticleRepo.Instance.GetAuthors(TabId);

            authors.ToList().ForEach(a => {
                var res = new FriendlyUrlInfo();
                result.Add(FriendlyUrlInfoFromAuthor(a.Key, a.Value));
            });
            return(result);
        }
Exemplo n.º 6
0
        private static FriendlyUrlInfo FriendlyUrlInfoFromAuthor(int id, string name)
        {
            var f = new FriendlyUrlInfo();

            f.itemId      = id;
            f.itemType    = "author";
            f.parentId    = -1;
            f.urlDate     = DateTime.Now;
            f.urlNum      = 0;
            f.qsValue     = "&articleType=authorview&authorId=" + id.ToString();
            f.urlFragment = name;
            return(f);
        }
Exemplo n.º 7
0
        private static FriendlyUrlInfo FriendlyUrlInfoFromCategory(Category c)
        {
            var f = new FriendlyUrlInfo();

            f.itemId      = c.CategoryID;
            f.itemType    = "category";
            f.parentId    = c.ParentID;
            f.urlDate     = DateTime.Now;
            f.urlNum      = c.ParentID;
            f.qsValue     = "&articleType=categoryview&categoryId=" + c.CategoryID.ToString();
            f.urlFragment = c.URL;
            return(f);
        }
Exemplo n.º 8
0
        private static FriendlyUrlInfo FriendlyUrlInfoFromArticle(Article a)
        {
            var f = new FriendlyUrlInfo();

            f.itemId      = (int)a.ArticleID;
            f.itemType    = "article";
            f.parentId    = -1;
            f.urlDate     = a.LastUpdated;
            f.urlNum      = 0;
            f.qsValue     = "&articleType=articleview&articleId=" + a.ArticleID.ToString();
            f.urlFragment = a.URL;
            return(f);
        }
        /// <summary>
        /// Checks for, and adds to the indexes, a missing item.
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="tabId"></param>
        /// <param name="portalId"></param>
        /// <param name="provider"></param>
        /// <param name="options"></param>
        /// <param name="messages"></param>
        /// <returns>Valid path if found</returns>
        internal static string CheckForMissingNewsArticleItem(int itemId, string itemType, int tabId, int portalId, NewsArticlesModuleProvider provider, FriendlyUrlOptions options, TabUrlOptions urlOptions, ref List <string> messages)
        {
            string          path        = null;
            FriendlyUrlInfo friendlyUrl = Data.DataProvider.Instance().GetNewsArticleItem(itemId, itemType, urlOptions, tabId);

            messages.Add("articleId not found : " + itemId.ToString() + " Checking Item directly");
            if (friendlyUrl != null)
            {
                messages.Add("articleId found : " + itemId.ToString() + " Rebuilding indexes");
                //call and get the path
                path = UrlController.MakeItemFriendlyUrl(friendlyUrl, provider, options, urlOptions);
                //so this entry did exist but wasn't in the index.  Rebuild the index
                UrlController.RebuildIndexes(tabId, portalId, provider, options, urlOptions);
            }
            return(path);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Checks for, and adds to the indexes, a missing item.
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="tabId"></param>
        /// <param name="portalId"></param>
        /// <param name="provider"></param>
        /// <param name="options"></param>
        /// <param name="messages"></param>
        /// <returns>Valid path if found</returns>
        internal static string CheckForMissingItemId(int itemId, string itemType, int portalId, SocialUrlProvider provider, FriendlyUrlOptions options, ref List <string> messages)
        {
            string          path        = null;
            FriendlyUrlInfo friendlyUrl = null;

            messages.Add("Item not found Id : " + itemId.ToString() + ", Type : " + itemType + " Checking Item directly");
            Data.DataProvider.Instance().GetSocialUrl(portalId, itemId, itemType, out friendlyUrl);
            if (friendlyUrl != null)
            {
                messages.Add("itemId found : " + itemId.ToString() + " , Type : " + itemType + " - Rebuilding indexes");
                //call and get the path
                path = UrlController.MakeItemFriendlyUrl(friendlyUrl, provider, options);
                //so this entry did exist but wasn't in the index.  Rebuild the index
                UrlController.RebuildIndexes(portalId, provider, options);
            }
            return(path);
        }
        /// <summary>
        /// Creates a Friendly Url For the Item
        /// </summary>
        /// <param name="friendlyUrl">Object containing the relevant properties to create a friendly url from</param>
        /// <param name="provider">The active module provider</param>
        /// <param name="options">THe current friendly Url Options</param>
        /// <returns></returns>
        private static string MakeItemFriendlyUrl(FriendlyUrlInfo friendlyUrl, NewsArticlesModuleProvider provider, FriendlyUrlOptions options, TabUrlOptions urlOptions)
        {
            //calls back up the module provider to utilise the CleanNameForUrl method, which creates a safe Url using the current Url Master options.
            string friendlyUrlPath = provider.CleanNameForUrl(friendlyUrl.urlFragment, options);

            switch (friendlyUrl.itemType.ToLower())
            {
            case "article":
            case "page":
                switch (urlOptions.ArticleStyle)
                {
                case ArticleUrlStyle.BlogStyle:
                    friendlyUrlPath = MakeBlogStyleUrl(friendlyUrl.urlDate, friendlyUrlPath, friendlyUrl.urlNum, DateUrlStyle.Day);
                    break;

                case ArticleUrlStyle.TitleStyle:
                    if (friendlyUrl.urlNum > 1)        //page number is whole index
                    {
                        friendlyUrlPath += "/p/" + friendlyUrl.urlNum.ToString();
                    }
                    break;
                }

                /*if (friendlyUrl.urlNum > 1)//page number is whole index, so add on page
                 *  friendlyUrlPath += "/p/" + friendlyUrl.urlNum.ToString();*/
                break;

            case "author":
                //no difference - authorStyle chosen at index build stage
                break;

            case "category":
                //no difference - category style chosen at index build stage
                break;

            case "archive":
                //holds dates in format of yyyy/mm, which is how it is returned from db
                break;
            }
            return(friendlyUrlPath);
        }
Exemplo n.º 12
0
        internal override void GetActiveForumsThreads(int tabId, out FriendlyUrlInfoCol urls)
        {
            urls = new FriendlyUrlInfoCol();
            var dr = SqlHelper.ExecuteReader(_connectionString, CommandType.Text,
                                             "select * from " + GetFullyQualifiedName("dnntoaf_topics"));

            while (dr.Read())
            {
                var url = new FriendlyUrlInfo();
                if (!Convert.IsDBNull(dr["newTopicId"]))
                {
                    url.newId = Convert.ToInt32(dr["newTopicId"]);
                }
                if (!Convert.IsDBNull(dr["oldPostId"]))
                {
                    url.itemId = (int)dr["oldPostId"];
                }
                urls.Add(url);
            }
            dr.Close();
            dr.Dispose();
        }
Exemplo n.º 13
0
        internal override void GetSocialUrl(int portalId, int itemId, string itemType, out FriendlyUrlInfo url)
        {
            url = null;
            string sp = GetFullyQualifiedName("GetSocialUrl");

            SqlParameter[] parms = new SqlParameter[3];
            parms[0] = new SqlParameter("@portalId", portalId);
            parms[1] = new SqlParameter("@itemId", itemId);
            parms[2] = new SqlParameter("@itemType", itemType);
            SqlDataReader rdr = SqlHelper.ExecuteReader(_connectionString, CommandType.StoredProcedure, sp, parms);

            if (rdr.Read())
            {
                url = new FriendlyUrlInfo();
                if (!Convert.IsDBNull(rdr["UrlFragment1"]))
                {
                    url.UrlFragment1 = (string)rdr["UrlFragment1"];
                }
                if (!Convert.IsDBNull(rdr["UrlFragment2"]))
                {
                    url.UrlFragment2 = (string)rdr["UrlFragment2"];
                }
                if (!Convert.IsDBNull(rdr["ItemType"]))
                {
                    url.ItemType = (string)rdr["ItemType"];
                }
                if (!Convert.IsDBNull(rdr["ItemId"]))
                {
                    url.ItemId = (int)rdr["ItemId"];
                }
            }

            rdr.Close();
            rdr.Dispose();
        }
        private void BindReaderToFriendlyUrl(ref FriendlyUrlInfo url, SqlDataReader rdr, string articleFragmentName, string pageFragmentName, string authorFragmentName)
        {
            if (url == null)
            {
                url = new FriendlyUrlInfo();
            }
            if (!Convert.IsDBNull(rdr["ItemId"]))
            {
                url.itemId = (int)rdr["ItemId"];
            }

            if (!Convert.IsDBNull(rdr["ParentId"]))
            {
                url.parentId = (int)rdr["ParentId"];
            }
            else
            {
                url.parentId = -1;
            }

            string itemType = "";

            if (!Convert.IsDBNull(rdr["ItemType"]))
            {
                itemType = (string)rdr["ItemType"];
            }

            //the date is a general purpose field that is context-dependent on the item type
            if (!Convert.IsDBNull(rdr["urlDate"]))
            {
                url.urlDate = (DateTime)rdr["urlDate"];
            }
            else
            {
                url.urlDate = DateTime.MinValue;
            }

            //the num is a general purpose field that is context-dependent on the item Type
            url.urlNum = (int)rdr["UrlNum"];

            url.itemType = itemType;
            //get the 3 different types of url fragment
            switch (itemType.ToLower())
            {
            case "article":
                string fragment = GetSafeString(rdr, articleFragmentName);
                if (fragment == "")    //fallback if empty
                {
                    fragment = GetSafeString(rdr, "UrlFragment1");
                }
                url.urlFragment = fragment;
                break;

            case "author":
                url.urlFragment = GetSafeString(rdr, authorFragmentName);
                break;

            case "category":
                url.urlFragment = GetSafeString(rdr, "UrlFragment1");
                break;

            case "page":
                string pageFragment = GetSafeString(rdr, pageFragmentName);
                if (pageFragment == "")    //fallback if empty
                {
                    pageFragment = GetSafeString(rdr, "UrlFragment1");
                }
                url.urlFragment = pageFragment;
                break;
            }
        }
        internal override void GetNewsArticlesItemsForTab(int tabId, TabUrlOptions urlOptions, out FriendlyUrlInfoCol urls, out NewsArticleOptions naOptions)
        {
            urls = new FriendlyUrlInfoCol();

            string sp = GetFullyQualifiedName("GetNewsArticlesEntriesForTab");

            SqlParameter[] parms = new SqlParameter[2];
            parms[0] = new SqlParameter("@TabId", tabId);
            if (urlOptions != null)
            {
                parms[1] = new SqlParameter("@startingArticleId", urlOptions.StartingArticleId);
            }
            else
            {
                parms[1] = new SqlParameter("@startingArticleId", 0);
            }
            //call the db
            SqlDataReader rdr = SqlHelper.ExecuteReader(_connectionString, CommandType.StoredProcedure, sp, parms);

            //work out which url fragment to use
            string articleFragmentName = "";
            string pageFragmentName    = "";
            string authorFragmentName  = "";

            GetFragmentNames(urlOptions, out articleFragmentName, out pageFragmentName, out authorFragmentName);

            while (rdr.Read())
            {
                FriendlyUrlInfo fuf = new FriendlyUrlInfo();
                BindReaderToFriendlyUrl(ref fuf, rdr, pageFragmentName, articleFragmentName, authorFragmentName);
                urls.Add(fuf);
            }
            //get any options in the mix
            naOptions = new NewsArticleOptions();
            if (rdr.NextResult())
            {
                /*AlwaysShowPageID	False
                 * SEOShorternID	ID
                 * SEOUrlMode	Shorterned
                 * TitleReplacementType	Dash*/
                //set defaults - module settings may not be there
                naOptions.TitleReplacement = "-";
                while (rdr.Read())
                {
                    string settingName  = (string)rdr["SettingName"];
                    string settingValue = (string)rdr["SettingValue"];
                    if (settingName != null)
                    {
                        switch (settingName.ToLower())
                        {
                        case "seoshorternid":
                            naOptions.SeoShortenId = settingValue;
                            break;

                        case "seourlmode":
                            naOptions.SeoUrlMode = settingValue;
                            break;

                        case "titlereplacementtype":
                            if (settingValue.ToLower() == "dash")
                            {
                                naOptions.TitleReplacement = "-";
                            }
                            else
                            {
                                naOptions.TitleReplacement = "_";
                            }
                            break;

                        case "alwaysshowpageid":
                            bool result = false;
                            bool.TryParse(settingValue, out result);
                            naOptions.AlwaysShowPageId = result;
                            break;
                        }
                    }
                    else
                    {
                        //no value, use defaults
                        naOptions.TitleReplacement = "-";
                        naOptions.AlwaysShowPageId = false;
                    }
                }
            }
            rdr.Close();
            rdr.Dispose();
        }
Exemplo n.º 16
0
        public override bool CheckForRedirect(int tabId, int portalid, string httpAlias, Uri requestUri, NameValueCollection queryStringCol, FriendlyUrlOptions options, out string redirectLocation,
                                              ref List <string> messages)
        {
            bool doRedirect = false;

            redirectLocation = "";//set blank location
            //compare to known pattern of old Urls
            string path = requestUri.AbsoluteUri;

            if (string.IsNullOrEmpty(path) == false && Regex.IsMatch(path, @"(^|/)(mid|moduleId)/\d+/?", RegexOptions.IgnoreCase) == false)
            {
                //could be in old /groupId/xx format - if so, we want to redirect it
                Regex pathRegex = new Regex(@"/groupid/(?<groupid>\d+)", RegexOptions.IgnoreCase);
                Match pathMatch = pathRegex.Match(path);
                if (pathMatch.Success)
                {
                    string groupIdRaw = pathMatch.Groups["groupid"].Value;
                    int    groupId;
                    if (int.TryParse(groupIdRaw, out groupId))
                    {
                        //ok, valid item Id found
                        //get the valid Url for this item
                        Hashtable friendlyUrlIndex = UrlController.GetFriendlyUrlIndex(portalid, this, options);
                        //look up the friendly url index using the item key
                        string furlKey = FriendlyUrlInfo.MakeKey("group", groupId);
                        if (friendlyUrlIndex != null)
                        {
                            string        friendlyUrl = null;
                            TabController tc          = new TabController();
                            TabInfo       tab         = tc.GetTab(tabId, portalid, false);
                            if (tab != null && tab.ParentId == GroupPagePathTabId)
                            {
                                //this is the child tab of the group tab
                                string cpFurlKey = "t" + tabId.ToString() + furlKey;
                                friendlyUrl = (string)friendlyUrlIndex[cpFurlKey];
                            }
                            if (friendlyUrl == null)
                            {
                                friendlyUrl = (string)friendlyUrlIndex[furlKey];
                            }
                            if (friendlyUrl != null)
                            {
                                //ok, we're going to replace this in the Url
                                if (HideGroupPagePath == false)
                                {
                                    friendlyUrl = base.EnsureLeadingChar("/", friendlyUrl);
                                    string result = pathRegex.Replace(path, friendlyUrl);
                                    doRedirect       = true;
                                    redirectLocation = result;
                                }
                                else
                                {
                                    DotNetNuke.Entities.Portals.PortalAliasInfo pa = DotNetNuke.Entities.Portals.PortalAliasController.GetPortalAliasInfo(httpAlias);
                                    if (pa != null)
                                    {
                                        DotNetNuke.Entities.Portals.PortalSettings ps = new DotNetNuke.Entities.Portals.PortalSettings(tabId, pa);
                                        redirectLocation = DotNetNuke.Common.Globals.NavigateURL(tabId, ps, "", "groupid=" + groupId);
                                        doRedirect       = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(doRedirect);
        }
Exemplo n.º 17
0
        public override string ChangeFriendlyUrl(TabInfo tab, string friendlyUrlPath, FriendlyUrlOptions options, string cultureCode, ref string endingPageName, out bool useDnnPagePath,
                                                 ref List <string> messages)
        {
            //set default values for out parameters
            useDnnPagePath = true;
            if (messages == null)
            {
                messages = new List <string>();
            }
            //check if we want to try and modify this Url
            //first check to see if this Url is an 'edit' Url - something that loads a module-specific page.
            //we don't want to mess with these, because they're always permissions based Urls and thus
            //no need to be friendly
            if (string.IsNullOrEmpty(friendlyUrlPath) == false && Regex.IsMatch(friendlyUrlPath, @"(^|/)(mid|moduleId)/\d+/?", RegexOptions.IgnoreCase) == false)
            {
                Hashtable friendlyUrlIndex = null; //the friendly url index is the lookup we use
                //try and match incoming friendly url path to what we would expect from the module
                Regex groupUrlRegex = new Regex(@"(?<l>/)?groupid/(?<groupid>\d+)", RegexOptions.IgnoreCase);
                Match groupUrlMatch = groupUrlRegex.Match(friendlyUrlPath);
                if (groupUrlMatch.Success)
                {
                    //this is a group Url we want to try and modify
                    string rawId   = groupUrlMatch.Groups["groupid"].Value;
                    int    groupId = 0;
                    if (int.TryParse(rawId, out groupId))
                    {
                        //we have obtained the groupId out of the Url
                        //get the friendlyUrlIndex (it comes from the database via the cache)
                        friendlyUrlIndex = UrlController.GetFriendlyUrlIndex(tab.PortalID, this, options);
                        if (friendlyUrlIndex != null)
                        {
                            //item urls are indexed with i + itemId ("i5") - this is so we could mix and match entities if necessary
                            string furlkey = FriendlyUrlInfo.MakeKey("group", groupId);  //create the lookup key for the friendly url index
                            string path    = null;
                            //check for a child pages / group ID in the index first
                            if (GroupPagePathTabId > -1 && tab.ParentId == GroupPagePathTabId)
                            {
                                string cpFurlKey = "t" + tab.TabID.ToString() + furlkey;
                                path = (string)friendlyUrlIndex[cpFurlKey]; //check if in the index for a child page
                            }
                            if (path == null)                               //now check for a match in the index
                            {
                                path = (string)friendlyUrlIndex[furlkey];   //check if in the index
                            }
                            if (path == null)
                            {
                                //don't normally expect to have a no-match with a friendly url path when an itemId was in the Url.
                                //could be a new item that has been created and isn't in the index
                                //do a direct call and find out if it's there
                                path = UrlController.CheckForMissingItemId(groupId, "group", tab.PortalID, this, options, ref messages);
                            }
                            if (path != null) //got a valid path
                            {
                                //url found in the index for this entry.  So replace the matched part of the path with the friendly url
                                if (groupUrlMatch.Groups["l"].Success) //if the path had a leading /, then make sure to add that onto the replacement
                                {
                                    path = base.EnsureLeadingChar("/", path);
                                }

                                /* finish it all off */
                                messages.Add("Group Friendly Url Replacing : " + friendlyUrlPath + " in Path : " + path);

                                //this is the point where the Url is modified!
                                //replace the path in the path - which leaves any other parts of a path intact.
                                friendlyUrlPath = groupUrlRegex.Replace(friendlyUrlPath, path);//replace the part in the friendly Url path with it's replacement.

                                //check if this tab is the one specified to not use a path
                                if ((GroupPagePathTabId == tab.TabID || GroupPagePathTabId == tab.ParentId) && HideGroupPagePath)
                                {
                                    useDnnPagePath = false;//make this Url relative from the site root
                                }
                                //set back to default.aspx so that DNN Url Rewriter removes it - just in case it wasn't standard
                                endingPageName = DotNetNuke.Common.Globals.glbDefaultPage;
                            }
                        }
                    }
                }
            }
            return(friendlyUrlPath);
        }
Exemplo n.º 18
0
 internal abstract void GetSocialUrl(int portalId, int itemId, string itemType, out FriendlyUrlInfo url);