Example #1
0
        public void EcmaScriptEncodeTest()
        {
            string expected = "http://test";
            string result   = _extension.EcmaScriptEncode(expected);

            Assert.AreEqual(result, SPHttpUtility.EcmaScriptStringLiteralEncode(expected));
        }
        /// <summary>
        /// Generates the link to view.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="fullPath">The full path.</param>
        /// <returns></returns>
        private string GenerateLinkToView(string path, string fullPath)
        {
            // generate url + args
            string hrefArgs = string.Format("{0}?RootFolder={1}&View={2}",
                                            SPSTools.GetCurrentPageBaseUrl(Page),
                                            //SPHttpUtility.UrlKeyValueEncode(path),
                                            //FIX: 2.8 Ivalid characters
                                            SPHttpUtility.EcmaScriptStringLiteralEncode(
                                                SPHttpUtility.UrlPathEncode(fullPath, false, true)),
                                            SPHttpUtility.UrlKeyValueEncode(GetView().ID));

            //  onclick
            string onclick = string.Format("javascript:EnterFolder('{0}');javascript: return false;", hrefArgs);

            string href;

            // different html if we are in list context

            //if (IsListContext)
            //{
            //    href = string.Format("<a href=\"{0}\">{1}</a>", hrefArgs, path);
            //}
            //else
            {
                href = string.Format("<a href=\"\" onclick=\"{1}\">{2}</a>", hrefArgs, onclick, path);
            }

            return(href);
        }
        /// <summary>
        /// Gets the link to upload.
        /// </summary>
        /// <returns>javascript navigate to upload page</returns>
        private string GetLinkToUpload()
        {
            string prefixedUrl = string.Format("{0}/_layouts/Upload.aspx?List={1}&RootFolder={2}&Source={3}",
                                               SPContext.Current.Web.ServerRelativeUrl,
                                               SPHttpUtility.UrlKeyValueEncode(
                                                   new Guid(_listGuid).ToString("B").ToUpper()),
                                               _breadCrumb.GetCurrentFolder(),
                                               SPSTools.GetCurrentUrl());

            return(string.Format("javascript:STSNavigate('{0}')",
                                 SPHttpUtility.EcmaScriptStringLiteralEncode(
                                     SPUtility.GetServerRelativeUrlFromPrefixedUrl(prefixedUrl))));
        }
Example #4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         string scriptLiteralToEncode = base.Request.QueryString["Dialog"];
         this.PageName.Text = SPHttpUtility.EcmaScriptStringLiteralEncode(scriptLiteralToEncode);
         if (!string.IsNullOrEmpty(scriptLiteralToEncode) && (((scriptLiteralToEncode == "CreateLink") || (scriptLiteralToEncode == "InsertImage")) || (scriptLiteralToEncode == "InsertTable")))
         {
             this.PageTitle.Text     = SPHttpUtility.HtmlEncode("插入图片");
             this.FirstCaption.Text  = SPHttpUtility.HtmlEncode("提示:");
             this.SecondCaption.Text = SPHttpUtility.HtmlEncode("地址:");
         }
     }
 }
Example #5
0
        /// <summary>
        /// Generates the link to view.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>
        /// The current page url with the selected folder and view (javascript :EnterFolder)
        /// </returns>
        protected virtual string GenerateLinkToView(string path)
        {
            string hrefArgs = string.Format("{0}?RootFolder={1}&View={2}",
                                            SPSTools.GetCurrentPageBaseUrl(Page),
                                            //SPHttpUtility.UrlKeyValueEncode(path),
                                            //FIX: 2.8 Ivalid characters
                                            SPHttpUtility.EcmaScriptStringLiteralEncode(
                                                SPHttpUtility.UrlPathEncode(path, false, true)),
                                            SPHttpUtility.UrlKeyValueEncode(GetView().ID));

            string url = string.Format("javascript:EnterFolder('{0}');", hrefArgs);

            return(url);
        }
Example #6
0
        protected override void OnLoad(EventArgs args)
        {
            base.OnLoad(args);
            string commandName = this.Request.QueryString["Dialog"];

            PageName.Text = SPHttpUtility.EcmaScriptStringLiteralEncode(commandName);
            if (commandName != null && string.Equals(commandName, "CreateVideoLink", StringComparison.OrdinalIgnoreCase))
            {
                VideoEmbedCodePanel.Visible = false;
            }
            else
            {
                VideoUrlPanel.Visible = false;
            }
        }
        private string GenerateContextScript()
        {
            StringBuilder context = new StringBuilder();

            context.Append("function SearchFieldChangedResult(searchOperators, context)");
            context.Append("{");
            context.Append("var drpdSearchOperators = document.getElementById('" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.drpdSearchOperators.ClientID) + "');");
            context.Append("drpdSearchOperators.length=0;");
            context.Append("var operators = searchOperators.split(';');");
            context.Append("for(op=0;op<operators.length;op++)");
            context.Append("{");
            context.Append("var operator = operators[op].split(',');");
            context.Append("var option = document.createElement('option');");
            context.Append("option.text = operator[0];");
            context.Append("option.value = operator[1];");
            context.Append("drpdSearchOperators.add(option);");
            context.Append("}");
            context.Append("}");

            return(context.ToString());
        }
        /// <summary>
        /// Generates the link to list.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>Link to view url and passed folder path</returns>
        protected override string GenerateLinkToList(string path)
        {
            // use base GenerateLinkToList url
            SPView view;
            string hrefArgs = string.Empty;

            if (!string.IsNullOrEmpty(_navigateToListView))
            {
                view     = GetList().Views[new Guid(_navigateToListView)];
                hrefArgs = string.Format("{0}/{1}?RootFolder={2}&View={3}",
                                         SPContext.Current.Web.Url,
                                         SPHttpUtility.UrlKeyValueEncode(view.Url),
                                         //SPHttpUtility.UrlKeyValueEncode(path),
                                         //FIX: 2.8 Ivalid characters
                                         SPHttpUtility.EcmaScriptStringLiteralEncode(
                                             SPHttpUtility.UrlPathEncode(path, false, true)),
                                         SPHttpUtility.UrlKeyValueEncode(view.ID));
            }

            return(hrefArgs);
        }
        protected override void OnPreRender(EventArgs e)
        {
            //generate callback script for search field changes
            ClientScriptManager cs = Page.ClientScript;
            string context         = GenerateContextScript();
            string cbr             = cs.GetCallbackEventReference(this, "searchField", "SearchFieldChangedResult", context, false);
            String callbackScript  = "function SearchFieldChanged() {"
                                     + "var searchField= 'searchFieldChangedTo:' + document.getElementById('" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.ColumnList.ClientID) + "').value;"
                                     + cbr + "; }";

            cs.RegisterClientScriptBlock(this.GetType(), "SearchFieldChanged",
                                         callbackScript, true);

            ColumnList.Attributes.Add("onchange", "SearchFieldChanged();");

            //HACK: fragment from the base class with query operators hack
            string str = this.Page.ClientScript.GetCallbackEventReference(this, "search", "PickerDialogHandleQueryResult", "ctx", "PickerDialogHandleQueryError", true);

            this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), "__SEARCH__", "<script>\r\n                function executeQuery()\r\n                {\r\n   var operators=document.getElementById('" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.drpdSearchOperators.ClientID) + "');                 var query=document.getElementById('" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.QueryTextBox.ClientID) + "');\r\n                    var list=document.getElementById('" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.ColumnList.ClientID) + "');\r\n                    var search='';\r\n                    var multiParts = new Array();\r\n       multiParts.push(operators.value);\r\n             if(list!=null)\r\n                        multiParts.push(list.value);\r\n                    else\r\n                        multiParts.push('');\r\n                    multiParts.push(query.value);\r\n\r\n                    search = ConvertMultiColumnValueToString(multiParts);\r\n                    PickerDialogSetClearState();\r\n                    \r\n                    var ctx = new PickerDialogCallbackContext();\r\n                    ctx.resultTableId = 'resultTable';\r\n                    ctx.queryTextBoxElementId = '" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.QueryTextBox.ClientID) + "';\r\n                    ctx.errorElementId = '" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.PickerDialog.ErrorLabel.ClientID) + "';\r\n                    ctx.htmlMessageElementId = '" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.PickerDialog.HtmlMessageLabel.ClientID) + "';\r\n                    ctx.queryButtonElementId = '" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.QueryButton.ClientID) + "';\r\n                    PickerDialogShowWait(ctx);\r\n                    " + str + ";\r\n                }\r\n                </script>");
            this.QueryTextBox.Text = this.QueryText;
            this.QueryTextBox.Attributes.Add("onKeyDown", "var e=event; if(!e) e=window.event; if(!browseris.safari && e.keyCode==13) { document.getElementById('" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.QueryButton.ClientID) + "').click(); return false; }");
            if ((this.QueryTextBox.Text.Length > 0) && !this.Page.IsPostBack)
            {
                string group = string.Empty;
                if (this.ColumnList.SelectedItem != null)
                {
                    group = this.ColumnList.SelectedItem.Value;
                }
                this.ExecuteQuery(group, this.QueryText);
            }
            this.Page.ClientScript.RegisterStartupScript(base.GetType(), "SetFocus", "<script>\r\n                    var objQueryTextBox = document.getElementById('" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.QueryTextBox.ClientID) + "'); \r\n                    if (objQueryTextBox != null)\r\n                    {\r\n                        try\r\n                        {\r\n                            objQueryTextBox.focus();\r\n                        }\r\n                        catch(e)\r\n                        {\r\n                        }\r\n                    }\r\n                  </script>");
        }
        private void CreateTable()
        {
            resultTable = new Table
            {
                Width       = Unit.Percentage(100.0),
                ID          = "resultTable",
                CssClass    = "ms-pickerresulttable",
                CellSpacing = 0,
                CellPadding = 0,
                BackColor   = Color.White
            };
            resultTable.ID = "resultTable";
            resultTable.Attributes.Add("hideFocus", "true");
            resultTable.Attributes.Add("EditorControlClientId", PickerDialog.EditorControl.ClientID);

            //Create Table Header Row
            TableRow child = null;

            if (PickerDialog.Results != null)
            {
                dt = PickerDialog.Results;


                child = new TableRow
                {
                    CssClass = "ms-pickerresultheadertr"
                };

                foreach (string column in columns)
                {
                    TableHeaderCell cell = new TableHeaderCell
                    {
                        CssClass = "ms-ph"
                    };
                    cell.Attributes.Add("UNSELECTABLE", "on");
                    Literal literal = new Literal
                    {
                        Text = SPHttpUtility.HtmlEncode(column)
                    };

                    cell.Controls.Add(literal);
                    child.Controls.Add(cell);
                }

                resultTable.Controls.Add(child);


                if (dt.Rows.Count == 0)
                {
                    child = new TableRow
                    {
                        CssClass = "ms-pickeremptyresulttexttr"
                    };

                    TableCell cell2 = new TableCell
                    {
                        CssClass   = "ms-descriptiontext",
                        ColumnSpan = columns.Length
                    };
                    Literal literal2 = new Literal
                    {
                        Text = SPHttpUtility.HtmlEncode("No search was given")
                    };
                    cell2.Controls.Add(literal2);
                    child.Controls.Add(cell2);
                    resultTable.Controls.Add(child);
                }
                else
                {
                    int    num          = 0;
                    string selectSingle = "PickerResultsSingleSelectOnClick(this);";
                    string selectDouble = "PickerResultsSingleSelectOnDblClick(this);";

                    foreach (HTML5VideoDataSet.HTML5VideosRow row in dt.Rows)
                    {
                        HTML5VideoPickerEntity entity = PickerDialog.QueryControl.GetEntity(row);

                        if (entity != null)
                        {
                            child = new TableRow
                            {
                                ID = string.Format(CultureInfo.InvariantCulture, "row{0}", new object[] { num })
                            };

                            child.Attributes.Add("tabindex", "-1");
                            child.Attributes.Add("resultRow", "resultRow");

                            if ((num % 2) == 0)
                            {
                                child.CssClass = "ms-alternating";
                            }

                            ArrayList entities = new ArrayList();

                            entities.Add(entity);

                            string callback = PickerDialog.EditorControl.GenerateCallbackData(entities, false);
                            child.Attributes.Add("entityXml", callback);
                            child.Attributes.Add("onmousedown", "return singleselectevent(event);");
                            child.Attributes.Add("onclick", selectSingle);
                            child.Attributes.Add("ondblclick", selectDouble);
                            child.Attributes.Add("onkeydown", "PickerResultsNameOnKeyDown(this, event,false);");
                            child.Attributes.Add("onfocus", "PickerResultsNameOnFocus(this, event, false);");

                            child.Attributes.Add("key", entity.Key);

                            for (int i = 0; i < columns.Length; i++)
                            {
                                this.RenderRowColumn(row, i, child);
                            }
                            resultTable.Controls.Add(child);
                            num++;
                        }
                    }

                    if (base.PickerDialog.Results.Rows.Count > 1)
                    {
                        child = new TableRow
                        {
                            CssClass = "ms-pickersearchsummarytr",
                            ID       = "PickerSearchResultSummaryRow"
                        };
                        TableCell cell3 = new TableCell
                        {
                            CssClass   = "ms-descriptiontext",
                            ColumnSpan = dt.Columns.Count
                        };
                        cell3.Controls.Add(new LiteralControl(SPHttpUtility.HtmlEncode(String.Format("{0} results found.", new object[] { base.PickerDialog.Results.Rows.Count }))));
                        child.Controls.Add(cell3);
                        resultTable.Controls.Add(child);
                    }

                    this.Page.ClientScript.RegisterClientScriptBlock(GetType(), "__SELECTION__HELPER__", "<script type=\"text/javascript\">\r\n                // <![CDATA[\r\n                function " + SPHttpUtility.EcmaScriptStringLiteralEncode(PickerDialog.GetSelectedClientSideFunctionName) + "()\r\n                {\r\n                    var selKeys=new Array(selected.length);\r\n                    for(i=0;i<selected.length;i++)\r\n                    {\r\n                        var uniquekey=selected[i].getAttribute('key').toString();\r\n                        selKeys[i]=uniquekey;\r\n                    }\r\n                    return selKeys;\r\n                }\r\n                // ]]>\r\n                </script>");
                }
            }
        }
        protected new void CreateButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                SPLongOperation.Begin(delegate(SPLongOperation longOperation)
                {
                    SPWeb web = SPContext.Current.Web;
                    PublishingWeb currentPublishingWeb = PublishingWeb.GetPublishingWeb(web);
                    PublishingPage publishingPage      = null;
                    SPFolder sPFolder = null;
                    if (!string.IsNullOrEmpty(folderUrl))
                    {
                        sPFolder = currentPublishingWeb.Web.GetFolder(folderUrl);
                        if (!sPFolder.Exists)
                        {
                            string url = Helper.ConcatUrls(folderUrl, nameInput.Text);
                            SPUtility.CreateParentFoldersForFile(currentPublishingWeb.PagesList, url, false);
                            sPFolder = currentPublishingWeb.Web.GetFolder(folderUrl);
                        }
                    }
                    PageLayout pageLayout = null;
                    string text           = base.Request.QueryString.Get("PLUrl");
                    if (string.IsNullOrEmpty(text))
                    {
                        pageLayout = currentPublishingWeb.DefaultPageLayout;
                    }
                    else
                    {
                        try
                        {
                            pageLayout = new PageLayout(base.Web.GetListItem(text));
                        }
                        catch (Exception)
                        {
                            Logger.ToLog(new Exception(string.Format("Unable to create PageLayout from listitem of path : {0}", text)));
                            pageLayout = currentPublishingWeb.DefaultPageLayout;
                        }
                    }
                    publishingPage = SPHelper.CreatePublishingPage(currentPublishingWeb, nameInput.Text, pageLayout, sPFolder, false);
                    if (publishingPage != null && originalRequestedName != null)
                    {
                        publishingPage.Title = originalRequestedName;
                        publishingPage.ListItem["NewsType"] = ddlNewsType.SelectedValue;
                        publishingPage.Update();
                    }

                    string text2     = SPHttpUtility.UrlPathEncode(publishingPage.ListItem.File.ServerRelativeUrl, false);
                    string FinishUrl = SPHelper.DesignModeUrl(text2);

                    if (!string.IsNullOrEmpty(base.Request.QueryString.Get("IsDlg")))
                    {
                        if (base.Request.QueryString["shouldRedirectPage"] == "0")
                        {
                            string scriptLiteralToEncode = SPHelper.ConvertToAbsoluteUrl(FinishUrl, currentPublishingWeb.Web.Site, true);
                            longOperation.EndScript("window.frameElement.commitPopup('" + SPHttpUtility.EcmaScriptStringLiteralEncode(scriptLiteralToEncode) + "');");
                        }
                        else
                        {
                            longOperation.EndScript("window.frameElement.navigateParent('" + SPHttpUtility.EcmaScriptStringLiteralEncode(FinishUrl) + "');");
                        }
                    }
                    else
                    {
                        longOperation.End(FinishUrl);
                    }
                });
            }
        }
Example #12
0
        protected override void RenderWebPart(HtmlTextWriter output)
        {
            if (this.ServerInitialRender)
            {
                Type       typeWebPartPlatform     = typeof(OriginalSearchBoxScriptWebPart).Assembly.GetType("Microsoft.Office.Server.Search.WebControls.WebPartPlatform");
                object     instanceWebPartPlatform = typeWebPartPlatform.GetProperty("Current", BindingFlags.Static | BindingFlags.NonPublic).GetValue(typeWebPartPlatform);
                MethodInfo wppgetLocResourceString = typeWebPartPlatform.GetMethod("GetLocResourceString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                Type typeLocStringIdO = typeof(OriginalSearchBoxScriptWebPart).Assembly.GetType("Microsoft.Office.Server.Search.LocStringId");
                Type typeLocStringIdP = typeof(OriginalSearchBoxScriptWebPart).Assembly.GetType("Microsoft.SharePoint.Portal.WebControls.LocStringId");

                Type       typeSearchCommon        = typeof(OriginalSearchBoxScriptWebPart).Assembly.GetType("Microsoft.SharePoint.Portal.WebControls.SearchCommon");
                MethodInfo scGetLocResourceStringO = typeSearchCommon.GetMethod("GetLocResourceString", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeLocStringIdO }, null);
                MethodInfo scGetLocResourceStringP = typeSearchCommon.GetMethod("GetLocResourceString", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeLocStringIdP }, null);

                SPWeb  web      = SPContext.Current.Web;
                bool   flag     = this.NavigationNodes != null && this.NavigationNodes.Length > 1;
                string text     = string.Empty;
                Type   kv       = typeof(OriginalScriptApplicationManager).Assembly.GetType("Microsoft.Office.Server.Search.WebControls.KeywordQueryReader");
                var    instance = kv.GetMethod("GetInstance", new Type[] { this.Page.GetType() }).Invoke(kv, new object[] { this.Page });
                if (instance != null)
                {
                    text = (string)kv.GetProperty("Keywords", BindingFlags.Public | BindingFlags.Instance).GetValue(instance, null);
                }
                string locResourceString = this.InitialPrompt;
                if (string.IsNullOrEmpty(locResourceString))
                {
                    locResourceString = (string)wppgetLocResourceString.Invoke(instanceWebPartPlatform, new object[] { Enum.Parse(typeLocStringIdO, "SearchBox_KeywordTextBoxToolTip_Text") });
                }
                string text2 = "";
                if (string.IsNullOrWhiteSpace(text))
                {
                    text  = locResourceString;
                    text2 = "ms-srch-sb-prompt ms-helperText";
                }
                string text3 = base.CsrContainerId + "_sboxdiv";
                string text4 = base.CsrContainerId + "_sbox";
                string text5 = base.CsrContainerId + "_NavButton";
                string text6 = base.CsrContainerId + "_AutoCompList";
                string text7 = base.CsrContainerId + "_NavDropdownList";
                string text8 = base.CsrContainerId + "_SearchLink";
                string scriptLiteralToEncode = "ms-srch-sbprogress";
                output.Write("<div componentid=\"{0}\" id=\"{0}\"><div id=\"SearchBox\" data-ddd=\"DDD\" name=\"Control\"><div class=\"ms-srch-sb ms-srch-sb-border\" id=\"{1}\">", HttpUtility.HtmlAttributeEncode(base.CsrContainerId), HttpUtility.HtmlAttributeEncode(text3));
                output.Write("<input type=\"text\" value=\"{0}\" maxlength=\"2048\" accessKey=\"{1}\" title=\"{2}\" id=\"{3}\" autocomplete=\"off\" autocorrect=\"off\" onkeypress=\"{4}\" onkeydown=\"{5}\" onfocus=\"{6}\" onblur=\"{7}\" class=\"ms-textSmall {8}\"/>", new object[]
                {
                    HttpUtility.HtmlAttributeEncode((text != null) ? text : ""),
                    HttpUtility.HtmlAttributeEncode((string)scGetLocResourceStringP.Invoke(typeSearchCommon, new object[] { Enum.Parse(typeLocStringIdP, "ResultMgmt_ToggleAdvControls_AccessKey") })),
                    HttpUtility.HtmlAttributeEncode(locResourceString),
                    HttpUtility.HtmlAttributeEncode(text4),
                    string.Concat(new string[]
                    {
                        "EnsureScriptFunc('Search.ClientControls.js', 'Srch.U', function() {if (Srch.U.isEnterKey(String.fromCharCode(event.keyCode))) {$find('",
                        SPHttpUtility.EcmaScriptStringLiteralEncode(base.CsrContainerId),
                        "').search($get('",
                        SPHttpUtility.EcmaScriptStringLiteralEncode(text4),
                        "').value);return Srch.U.cancelEvent(event);}})"
                    }),
                    "EnsureScriptFunc('Search.ClientControls.js', 'Srch.U', function() {var ctl = $find('" + SPHttpUtility.EcmaScriptStringLiteralEncode(base.CsrContainerId) + "');ctl.activateDefaultQuerySuggestionBehavior();})",
                    "EnsureScriptFunc('Search.ClientControls.js', 'Srch.U', function() {var ctl = $find('" + SPHttpUtility.EcmaScriptStringLiteralEncode(base.CsrContainerId) + "');ctl.hidePrompt();ctl.setBorder(true);})",
                    "EnsureScriptFunc('Search.ClientControls.js', 'Srch.U', function() {var ctl = $find('" + SPHttpUtility.EcmaScriptStringLiteralEncode(base.CsrContainerId) + "'); if (ctl){ ctl.showPrompt(); ctl.setBorder(false);}})",
                    HttpUtility.HtmlAttributeEncode(text2)
                });
                string text9 = null;
                if (web != null)
                {
                    text9 = SPUtility.GetThemedImageUrl(SPUtility.ConcatUrls("/", SPUtility.ConcatUrls(SPUtility.ContextLayoutsFolder, "images/searchresultui.png")), "searchresultui");
                }
                if (flag)
                {
                    output.Write("<a title=\"{0}\" id=\"{1}\" onclick=\"{2}\" href=\"{3}\" class=\"ms-srch-sb-navLink\" >", new object[]
                    {
                        HttpUtility.HtmlAttributeEncode((string)wppgetLocResourceString.Invoke(instanceWebPartPlatform, new object[] { Enum.Parse(typeLocStringIdO, "SearchBox_NavigationButtonToolTip_Text") })),
                        HttpUtility.HtmlAttributeEncode(text5),
                        "EnsureScriptFunc('Search.ClientControls.js', 'Srch.U', function() {$find('" + SPHttpUtility.EcmaScriptStringLiteralEncode(base.CsrContainerId) + "').activateDefaultNavigationBehavior();return Srch.U.cancelEvent(event);})",
                        "javascript: {}"
                    });
                    if (!string.IsNullOrEmpty(text9))
                    {
                        output.Write("<img src=\"{0}\" class=\"ms-srch-sb-navImg\" id=\"navImg\" alt=\"{1}\" />", HttpUtility.HtmlAttributeEncode(text9), HttpUtility.HtmlAttributeEncode((string)wppgetLocResourceString.Invoke(instanceWebPartPlatform, new object[] { Enum.Parse(typeLocStringIdO, "SearchBox_NavigationButtonToolTip_Text") })));
                    }
                    output.Write("</a>");
                }
                output.Write("<a title=\"{0}\" class=\"ms-srch-sb-searchLink\" id=\"{1}\" onclick=\"{2}\" href=\"{3}\" >", new object[]
                {
                    HttpUtility.HtmlAttributeEncode((string)wppgetLocResourceString.Invoke(instanceWebPartPlatform, new object[] { Enum.Parse(typeLocStringIdO, "SearchBox_SearchButtonToolTip_Text") })),
                    HttpUtility.HtmlAttributeEncode(text8),
                    string.Concat(new string[]
                    {
                        "EnsureScriptFunc('Search.ClientControls.js', 'Srch.U', function() {$find('",
                        SPHttpUtility.EcmaScriptStringLiteralEncode(base.CsrContainerId),
                        "').search($get('",
                        SPHttpUtility.EcmaScriptStringLiteralEncode(text4),
                        "').value);})"
                    }),
                    "javascript: {}"
                });
                if (!string.IsNullOrEmpty(text9))
                {
                    output.Write("<img src=\"{0}\" class=\"ms-srch-sb-searchImg\" id=\"searchImg\" alt=\"{1}\" />", HttpUtility.HtmlAttributeEncode(text9), HttpUtility.HtmlAttributeEncode((string)wppgetLocResourceString.Invoke(instanceWebPartPlatform, new object[] { Enum.Parse(typeLocStringIdO, "SearchBox_SearchButtonToolTip_Text") })));
                }
                output.Write("</a>");
                if (this.ShowQuerySuggestions)
                {
                    output.Write("<div class=\"ms-qSuggest-container ms-shadow\" id=\"AutoCompContainer\">");
                    output.Write("<div id=\"{0}\"></div>", HttpUtility.HtmlAttributeEncode(text6));
                    output.Write("</div>");
                }
                if (flag)
                {
                    output.Write("<div class=\"ms-qSuggest-container ms-shadow\" id=\"NavDropdownListContainer\">");
                    output.Write("<div id=\"{0}\"></div>", HttpUtility.HtmlAttributeEncode(text7));
                    output.Write("</div>");
                }
                output.Write("</div>");
                if (this.ShowAdvancedLink && !string.IsNullOrEmpty(this.AdvancedSearchPageAddress))
                {
                    output.Write("<div class='ms-srch-sb-link'><a id='AdvancedLink' href='{0}'>{1}</a></div>", SPHttpUtility.HtmlUrlAttributeEncode(this.AdvancedSearchPageAddress), SPHttpUtility.HtmlEncode((string)wppgetLocResourceString.Invoke(instanceWebPartPlatform, new object[] { Enum.Parse(typeLocStringIdO, "SearchBox_AdvancedSearchText") })));
                }
                if (this.ShowPreferencesLink)
                {
                    string text10 = string.Empty;
                    if (web != null)
                    {
                        text10 = SPUtility.ConcatUrls(SPUtility.ContextLayoutsFolder, "EditUserPref.aspx?Source=" + SPHttpUtility.UrlKeyValueEncode(SPAlternateUrl.ContextUri.OriginalString));
                        text10 = SPUtility.ConcatUrls(web.ServerRelativeUrl, text10);
                    }
                    if (!string.IsNullOrEmpty(text10))
                    {
                        output.Write("<div class='ms-srch-sb-link'><a id='PreferencesLink' href='{0}'>{1}</a></div>", SPHttpUtility.HtmlUrlAttributeEncode(text10), SPHttpUtility.HtmlEncode((string)wppgetLocResourceString.Invoke(instanceWebPartPlatform, new object[] { Enum.Parse(typeLocStringIdO, "SearchBox_PreferencesText") })));
                    }
                }
                output.Write("</div>");
                output.Write("</div>");

                Type swpsbd = typeof(OriginalScriptApplicationManager).Assembly.GetType("Microsoft.Office.Server.Search.WebControls.ScriptWebPartScriptBehaviorDescriptor");
                var  scriptWebPartScriptBehaviorDescriptor = Activator.CreateInstance(swpsbd, this.ClientControlType, base.CsrContainerId);
                typeof(ScriptObjectBuilder).GetMethod("DescribeSimpleComponent", BindingFlags.NonPublic | BindingFlags.Static).Invoke(typeof(ScriptObjectBuilder), new object[] { this, scriptWebPartScriptBehaviorDescriptor });
                string behaviorScript = (string)swpsbd.GetMethod("GetBehaviorScript", BindingFlags.Instance | BindingFlags.Public).Invoke(scriptWebPartScriptBehaviorDescriptor, new object[] { });
                this.OnAfterSerializeToClient(new ScriptWebPart.AfterSerializeToClientEventArgs(this));
                string text11 = string.Concat(new string[]
                {
                    "\r\n                    ExecuteOrDelayUntilScriptLoaded(\r\n                        function() \r\n                        {\r\n                            if ($isNull($find('",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(base.CsrContainerId),
                    "')))\r\n                            {\r\n                                var sb = ",
                    behaviorScript,
                    "\r\n                                sb.activate('",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(locResourceString),
                    "', '",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(text4),
                    "', '",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(text3),
                    "', '",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(text5),
                    "', '",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(text6),
                    "', '",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(text7),
                    "', '",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(text8),
                    "', '",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(scriptLiteralToEncode),
                    "', '",
                    SPHttpUtility.EcmaScriptStringLiteralEncode(text2),
                    "');\r\n                            }\r\n                        }, 'Search.ClientControls.js');"
                });

                if (this.SetFocusOnPageLoad)
                {
                    Guid   guid   = Guid.NewGuid();
                    string text12 = text11;
                    text11 = string.Concat(new string[]
                    {
                        text12,
                        "\r\n                        function initSearchBox",
                        guid.ToString("N"),
                        "() {\r\n                            $get('",
                        SPHttpUtility.EcmaScriptStringLiteralEncode(text4),
                        "').focus();\r\n                        }\r\n                        _spBodyOnLoadFunctionNames.push('initSearchBox",
                        guid.ToString("N"),
                        "');"
                    });
                }

                if (!SPPageContentManager.IsStartupScriptRegistered(this.Page, base.GetType(), "SearchBoxScriptWebPart" + text4))
                {
                    SPPageContentManager.RegisterStartupScript(this.Page, base.GetType(), "SearchBoxScriptWebPart" + text4, text11);
                }
            }

            typeof(ScriptWebPart).GetMethod("RenderWebPart", BindingFlags.Instance | BindingFlags.NonPublic).InvokeNotOverride(this, output);
        }
Example #13
0
 /// <summary>
 /// ECMAs the script encode.
 /// </summary>
 /// <param name="stringToEncode">The string to encode.</param>
 /// <returns>The encoded string</returns>
 public string EcmaScriptEncode(string stringToEncode)
 {
     return(SPHttpUtility.EcmaScriptStringLiteralEncode(stringToEncode));
 }
Example #14
0
        protected override void RenderContents(HtmlTextWriter writer)
        {
            bool             inEditMode = false;
            SPWebPartManager swpm       = (SPWebPartManager)SPWebPartManager.GetCurrentWebPartManager(this.Page);

            inEditMode = !swpm.GetDisplayMode().AllowPageDesign;

            if (inEditMode)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ID);
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "webpartzone");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                base.RenderBody(writer);
                writer.RenderEndTag();
            }
            else
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "ms-SPButton ms-WPAddButton");
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "CoreInvoke('ShowWebPartAdder', '" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.ID) + "');return false;");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                //writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:");
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "CoreInvoke('ShowWebPartAdder', '" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.ID) + "');return false;");
                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.RenderBeginTag(HtmlTextWriterTag.Span);
                //writer.Write(SPHttpUtility.HtmlEncode(WebPartPageResource.GetString("WebPartQuickAdd_AddANewWebPart")));
                //base.RenderBody(writer);
                writer.RenderEndTag();
                writer.RenderEndTag();
                writer.RenderEndTag();

                base.RenderContents(writer);
            }
        }
 /// <summary>
 /// Call after completing custom logic in the Application Page.
 /// </summary>
 /// <param name="result">Result code to pass to the output. Available results: -1 = invalid; 0 = cancel; 1 = OK</param>
 /// <param name="returnValue">Value to pass to the callback method defined when opening the Modal Dialog.</param>
 public void EndOperation(ModalDialogResult result, string returnValue)
 {
     if (IsPopUI)
     {
         if (string.IsNullOrEmpty(PageToRedirectOnOK))
         {
             Page.Response.Clear();
             Page.Response.Write(String.Format(CultureInfo.InvariantCulture, "<script type=\"text/javascript\">window.frameElement.commonModalDialogClose({0}, {1});</script>",
                                               new object[] {
                 (int)result,
                 String.IsNullOrEmpty(returnValue) ? "null" :  returnValue
             }));
             Page.Response.End();
         }
         else
         {
             ScriptManager.RegisterStartupScript((Page)this, typeof(EnhancedLayoutsPage), "RedirectToCreatedPage", "window.frameElement.navigateParent('" + SPHttpUtility.EcmaScriptStringLiteralEncode(SPHttpUtility.UrlPathEncode(PageToRedirectOnOK, false)) + "');", true);
         }
     }
     else
     {
         RedirectOnOK();
     }
 }