OpenUrlInNewWindow() public static method

public static OpenUrlInNewWindow ( string strUrl ) : bool
strUrl string
return bool
Exemplo n.º 1
0
        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;

            //Link readable by browsers
            link = UrlUtil.StripURL(link);
            var url = Globals.LinkClick(link, portalSettings.ActiveTab.TabID, moduleId, field.TrackDownloads, field.EnforceDownload);

            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 ? url : 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;
                        }
                    }
                    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>", 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;
            }
        }
Exemplo n.º 2
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.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 += "&amp;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;
                        }
                    }
                }
            }
        }