Utilities for DataType "Url" with enclosed options. StripURL returns URL string with options stripped off. Options are appended delimited by "|" and preceeded by "options=". Supported options: W open in new window
コード例 #1
0
        public override void RenderValuesToHtmlInsideDataSet(DataSet ds, int moduleId, bool noScript)
        {
            if (ds != null)
            {
                var fields = new ArrayList();
                //List of columns that contains URLs
                var tableData    = ds.Tables[DataSetTableName.Data];
                var tokenReplace = new TokenReplace {
                    ModuleId = moduleId
                };
                foreach (DataRow row in ds.Tables[DataSetTableName.Fields].Rows)
                {
                    if (row[FieldsTableColumn.Type].ToString() == Name)
                    {
                        var fieldId = (int)row[FieldsTableColumn.Id];
                        var field   = new FieldSettings
                        {
                            Title               = row[FieldsTableColumn.Title].ToString(),
                            OutputFormat        = row[FieldsTableColumn.OutputSettings].AsString(),
                            Abbreviate          = GetFieldSetting("Abbreviate", fieldId, ds).AsBoolean(),
                            ShowOpenInNewWindow = GetFieldSetting("ShowOpenInNewWindow", fieldId, ds).AsBoolean(),
                            EnforceDownload     = GetFieldSetting("EnforceDownload", fieldId, ds).AsBoolean()
                        };
                        fields.Add(field);
                        tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Url, typeof(string)));
                        tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Caption,
                                                             typeof(string)));
                        tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Original,
                                                             typeof(string)));
                    }
                }
                if (fields.Count > 0)
                {
                    var portalSettings = PortalController.Instance.GetCurrentPortalSettings();


                    foreach (DataRow row in tableData.Rows)
                    {
                        foreach (FieldSettings field in fields)
                        {
                            var strFieldvalue   = string.Empty;
                            var strFileId       = row[field.Title].ToString();
                            var openInNewWindow = !field.ShowOpenInNewWindow || UrlUtil.OpenUrlInNewWindow(strFileId);
                            strFileId = UrlUtil.StripURL(strFileId);
                            var strUrl = "";
                            //Link readable by browsers

                            var strCaption = string.Empty;
                            if (strFileId != string.Empty)
                            {
                                strUrl =
                                    HttpUtility.HtmlEncode(Globals.LinkClick(strFileId, portalSettings.ActiveTab.TabID,
                                                                             moduleId));
                                var fName          = "";
                                var strDisplayName = "";
                                if (strFileId.Like("FileID=*"))
                                {
                                    var f = FileManager.Instance.GetFile(int.Parse(UrlUtils.GetParameterValue(strFileId)));
                                    if (f != null)
                                    {
                                        fName = f.FileName;
                                        if (field.Abbreviate)
                                        {
                                            strDisplayName = (f.Folder + fName);
                                        }
                                        else
                                        {
                                            strDisplayName = fName;
                                        }
                                    }
                                }
                                else
                                {
                                    fName          = Globals.ResolveUrl(strUrl);
                                    strDisplayName = field.Abbreviate
                                        ? fName.Substring(Convert.ToInt32(fName.LastIndexOf("/", StringComparison.Ordinal) + 1))
                                        : fName;
                                }
                                strCaption = field.OutputFormat;
                                strCaption = string.IsNullOrEmpty(strCaption)
                                    ? fName
                                    : tokenReplace.ReplaceEnvironmentTokens(strCaption, row);
                                if (field.EnforceDownload)
                                {
                                    strUrl += "&forcedownload=true";
                                }
                                strFieldvalue = string.Format("<!--{0}--><a href=\"{1}\" {2}>{3}</a>", strDisplayName,
                                                              strUrl, (openInNewWindow ? " target=\"_blank\"" : ""),
                                                              strCaption);
                            }
                            row[field.Title] = strFieldvalue;
                            row[field.Title + DataTableColumn.Appendix_Caption]  = strCaption;
                            row[field.Title + DataTableColumn.Appendix_Original] = strFileId;
                            row[field.Title + DataTableColumn.Appendix_Url]      = strUrl;
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: URL.cs プロジェクト: kcjs/UserDefinedTable
        void FillTypeColumns(int moduleId, TokenReplace objTokenReplace, PortalSettings portalSettings,
                             TabController tabCtrl,
                             DataRow row, FieldSetting field)
        {
            var link = row[field.Title].ToString();
            //Link showed to the user
            bool openInNewWindow;

            if (field.ShowOpenInNewWindow)  //mit URL gepeicherten Wert lesen
            {
                openInNewWindow = UrlUtil.OpenUrlInNewWindow(link);
            }
            else
            {
                switch (Globals.GetURLType(UrlUtil.StripURL(link)))
                {
                case TabType.File:
                    openInNewWindow = true;
                    break;

                case TabType.Tab:     //link to internal tab
                    openInNewWindow = false;
                    break;

                default:
                    openInNewWindow = link.Like(Globals.ApplicationMapPath + "*");
                    break;
                }
            }

            //set caption:
            var caption = field.OutputFormat;

            if (!string.IsNullOrEmpty(caption))
            {
                caption = objTokenReplace.ReplaceEnvironmentTokens(caption, row);
            }
            var isLink = true;
            var url    = "";

            //Link readable by browsers
            link = UrlUtil.StripURL(link);
            if (link != string.Empty)
            {
                switch (Globals.GetURLType(link))
                {
                case TabType.Tab:
                    var tab = tabCtrl.GetTab(int.Parse(link), portalSettings.PortalId, false);
                    if (tab != null)
                    {
                        if (caption == string.Empty)
                        {
                            if (!field.Abbreviate)
                            {
                                var strPath = string.Empty;
                                if (tab.BreadCrumbs != null && tab.BreadCrumbs.Count > 0)
                                {
                                    foreach (TabInfo b in tab.BreadCrumbs)
                                    {
                                        var strLabel = b.TabName;
                                        if (strPath != string.Empty)
                                        {
                                            strPath +=
                                                string.Format(
                                                    "<img src=\"{0}/images/breadcrumb.gif\" border=\"0\" alt=\"Spacer\"/>",
                                                    Globals.ApplicationPath);
                                        }
                                        strPath += strLabel;
                                    }
                                }
                                caption = tab.TabPath.Replace("//",
                                                              string.Format(
                                                                  "<img src=\"{0}/images/breadcrumb.gif\" border=\"0\" alt=\"Spacer\"/>",
                                                                  Globals.ApplicationPath));
                            }
                            else
                            {
                                caption = tab.TabName;
                            }
                        }
                        url = field.EnforceDownload
                                ? Globals.LinkClick(link, portalSettings.ActiveTab.TabID, moduleId)
                                : Globals.NavigateURL(int.Parse(link));
                    }
                    else
                    {
                        caption = Localization.GetString("PageNotFound.ErrorMessage",
                                                         Globals.ResolveUrl(
                                                             string.Format("~{0}{1}/SharedResources.resx",
                                                                           Definition.PathOfModule,
                                                                           Localization.LocalResourceDirectory)));
                        url    = string.Empty;
                        isLink = false;
                    }
                    break;

                case TabType.File:
                    if (caption == string.Empty)
                    {
                        if (link.ToLowerInvariant().StartsWith("fileid="))
                        {
                            var file = FileManager.Instance.GetFile(int.Parse(link.Substring(7)));
                            if (file != null)
                            {
                                if (!field.Abbreviate)
                                {
                                    caption = file.Folder + file.FileName;
                                }
                                else
                                {
                                    caption = file.FileName;
                                }
                            }
                        }
                        else if (field.Abbreviate && link.IndexOf("/", StringComparison.Ordinal) > -1)
                        {
                            caption = link.Substring(Convert.ToInt32(link.LastIndexOf("/", StringComparison.Ordinal) + 1));
                        }
                        else
                        {
                            caption = link;
                        }
                    }
                    url = Globals.LinkClick(link, portalSettings.ActiveTab.TabID, moduleId);
                    break;

                case TabType.Url:
                case TabType.Normal:
                    if (caption == string.Empty)
                    {
                        if (field.Abbreviate && link.IndexOf("/", StringComparison.Ordinal) > -1)
                        {
                            caption = link.Substring(Convert.ToInt32(link.LastIndexOf("/", StringComparison.Ordinal) + 1));
                        }
                        else
                        {
                            caption = link;
                        }
                    }
                    if (!field.TrackDownloads)
                    {
                        url = link;
                    }
                    break;
                }


                if (field.EnforceDownload)
                {
                    url += "&amp;forcedownload=true";
                }

                string strFieldvalue;
                if (isLink)
                {
                    strFieldvalue = string.Format("<!--{1}--><a href=\"{0}\"{2}>{1}</a>", HttpUtility.HtmlEncode(url),
                                                  caption, (openInNewWindow ? " target=\"_blank\"" : ""));
                }
                else
                {
                    strFieldvalue = caption;
                }
                row[field.Title] = strFieldvalue;
                row[field.Title + DataTableColumn.Appendix_Caption]  = caption;
                row[field.Title + DataTableColumn.Appendix_Original] = link;
                row[field.Title + DataTableColumn.Appendix_Url]      = url;
            }
        }
コード例 #3
0
        public override void RenderValuesToHtmlInsideDataSet(DataSet ds, int moduleId, bool noScript)
        {
            if (ds != null)
            {
                var fields       = new ArrayList();
                var tableData    = ds.Tables[DataSetTableName.Data];
                var tokenReplace = new TokenReplace {
                    ModuleId = moduleId
                };
                foreach (DataRow row in ds.Tables[DataSetTableName.Fields].Rows)
                {
                    if (row[FieldsTableColumn.Type].ToString() == Name)
                    {
                        var fieldId = (int)row[FieldsTableColumn.Id];
                        var field   = new FieldSetting
                        {
                            Title           = row[FieldsTableColumn.Title].ToString(),
                            TokenText       = GetFieldSetting("TokenText", fieldId, ds).AsString(),
                            ShowUserName    = GetFieldSetting("ShowUserName", fieldId, ds).AsBoolean(),
                            OpenInNewWindow = GetFieldSetting("OpenInNewWindow", fieldId, ds).AsBoolean()
                        };
                        fields.Add(field);
                        tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Url, typeof(string)));
                        tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Original, typeof(string)));
                        tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Caption, typeof(string)));
                    }
                }

                if (fields.Count > 0)
                {
                    PortalSettings portalSettings = null;
                    if (HttpContext.Current != null)
                    {
                        portalSettings = PortalController.Instance.GetCurrentPortalSettings();
                    }
                    var mc       = new ModuleController();
                    var settings = mc.GetModule(moduleId).ModuleSettings;

                    foreach (DataRow row in tableData.Rows)
                    {
                        foreach (FieldSetting field in fields)
                        {
                            var strFieldvalue = string.Empty;
                            //Link showed to the user
                            var link = row[field.Title].ToString();


                            //set caption:
                            var caption = field.TokenText;
                            var url     = string.Empty;
                            //Link readable by browsers

                            link = UrlUtil.StripURL(link);
                            if (link != string.Empty)     //valid link
                            {
                                //var isLink = true;
                                var intUser = Convert.ToInt32(-1);
                                if (link.Like("userid=*") && portalSettings != null)
                                {
                                    try
                                    {
                                        intUser           = int.Parse(link.Substring(7));
                                        tokenReplace.User = new UserController().GetUser(portalSettings.PortalId,
                                                                                         intUser);
                                    }
                                    catch
                                    {
                                    }
                                }
                                if (intUser == -1)
                                {
                                    tokenReplace.User = new UserInfo {
                                        Username = "******"
                                    };
                                }


                                if (caption == string.Empty)
                                {
                                    caption = field.ShowUserName ? "[User:DisplayName]" : "[User:UserName]";
                                }

                                caption = tokenReplace.ReplaceEnvironmentTokens(caption, row);
                                if (caption == string.Empty)     //DisplayName empty
                                {
                                    caption = tokenReplace.ReplaceEnvironmentTokens("[User:username]");
                                }

                                url =
                                    HttpUtility.HtmlEncode(Globals.LinkClick(link, portalSettings.ActiveTab.TabID,
                                                                             moduleId));

                                strFieldvalue = string.Format("<!--{1}--><a href=\"{0}\"{2}>{1}</a>",
                                                              url,
                                                              caption,
                                                              (field.OpenInNewWindow ? " target=\"_blank\"" : ""));
                            }
                            row[field.Title] = strFieldvalue;
                            row[field.Title + DataTableColumn.Appendix_Original] = link;
                            row[field.Title + DataTableColumn.Appendix_Url]      = url;
                            row[field.Title + DataTableColumn.Appendix_Caption]  = caption;
                        }
                    }
                }
            }
        }