Example #1
0
    protected void Page_Load(object sender, System.EventArgs e)
    {
        Page.Response.ContentType = "text/xml";
        Page.Response.Clear();
        Page.Response.BufferOutput = true;

        string text = "";
        int pageNumber = 1;
        int totalPages = 0;
        int MaxResults = 0;
        int iLoop = 1;
        string strID = "";
        StringBuilder strFields = new StringBuilder();
        string strOnclick = "";
        long contentId = 0;
        long selectedId = -1;
        int languageID = m_commonApi.RequestInformationRef.ContentLanguage;
        m_refMsg = m_commonApi.EkMsgRef;

        Ektron.Cms.ContentAPI content_api = null;
        content_api = new Ektron.Cms.ContentAPI();
        if (content_api.GetCookieValue("LastValidLanguageID") != "" && Convert.ToInt32(content_api.GetCookieValue("LastValidLanguageID")) != -1)
        {
            languageID = Convert.ToInt32(content_api.GetCookieValue("LastValidLanguageID"));
        }

        text = Request.QueryString["text"];
        if (!string.IsNullOrEmpty(Request.QueryString["pnum"]) && Convert.ToInt32(Request.QueryString["pnum"]) > 0)
        {
            pageNumber = Convert.ToInt32(Request.QueryString["pnum"]);
        }

        if (!string.IsNullOrEmpty(Request.QueryString["cid"]))
        {
            contentId = Convert.ToInt64(Request.QueryString["cid"]);
        }

        if (!string.IsNullOrEmpty(Request.QueryString["selectedid"]))
        {
            selectedId = Convert.ToInt64(Request.QueryString["selectedid"]);
        }

        Ektron.Cms.API.Search.SearchManager search = new Ektron.Cms.API.Search.SearchManager();
        SearchRequestData requestData = new SearchRequestData();
        requestData.SearchFor = Ektron.Cms.WebSearch.SearchDocumentType.all;
        requestData.SearchText = text;
        requestData.PageSize = 10;
        requestData.LanguageID = languageID;
        requestData.CurrentPage = pageNumber;
        int resultCount = 0;
        SearchResponseData[] result = search.Search(requestData, HttpContext.Current, ref resultCount);
        StringBuilder str = new StringBuilder();
        StringBuilder strRet = new StringBuilder();
        int tmpCount = 0;
        string strLink = "";
        string[] arLink = null;
        MaxResults = requestData.PageSize;
        if (resultCount != 0)
        {
            str.Append("<table width=\"100%\" class=\"ektronGrid\">");
            foreach (SearchResponseData data in result)
            {
                strLink = "";
                strID = (string)("ek_sel_cont" + iLoop);
                if (data.QuickLink.IndexOf("http://") > -1)
                {
                    strLink = (string)(data.QuickLink);
                    strLink = strLink.Substring(7);
                    strLink = "http://" + strLink.Replace("\'", "\\\'").Replace("//", "/");
                }
                if (strLink.ToLower().IndexOf("window.open") < 0)
                {
                    arLink = strLink.Split("?".ToCharArray());
                    if (arLink.Length > 1)
                    {
                        strLink = arLink[0];
                        arLink = arLink[1].Split("&amp;".ToCharArray());
                        foreach (string val in arLink)
                        {
                            if (val.IndexOf("terms=") == -1)
                            {
                                if (strLink == "")
                                {
                                    strLink = val;
                                }
                                else
                                {
                                    if (strLink.IndexOf("?") < 0)
                                    {
                                        strLink = strLink + "?" + val;
                                    }
                                    else
                                    {
                                        strLink = strLink + "&" + val;
                                    }
                                }
                            }
                        }
                    }
                }

                strOnclick = "SelectContent(\'" + strID + "\',\'" + strLink + "\')";
                str.Append("<tr><td valign=\"top\" style=\"width:1%;\" valign=\"top\">");
                str.Append("<input type=\"radio\" ");
                if (selectedId != -1 && selectedId == data.ContentID)
                {
                    str.Append(" checked=\"true\" ");
                }

                if (data.ContentID == contentId)
                {
                    str.Append(" disabled ");
                }

                str.Append("onclick=\"" + strOnclick + "\" id=\"");
                str.Append(strID);
                str.Append("\" name=\"ek_sel_cont\"/></td><td valign=\"top\">");
                str.Append("<span onclick=\"" + strOnclick + "\" class=\"title\">");
                str.Append(data.Title).Append("</span><br/>");
                str.Append("<span onclick=\"SelectContent(\'" + strID + "\',\'" + strLink + "\')\" class=\"summary\">");
                if (data.ContentType != 2 && data.ContentType != 4)
                {
                    str.Append(data.Summary.Replace("<p> </p>", "").Replace("<p>&nbsp;</p>", "").Replace("<p>&#160;</p>", ""));
                }

                str.Append("</span></td></tr>");
                strFields.Append(",").Append(strID);
                iLoop++;
            }
        }

        if (resultCount > 0 && MaxResults > 0)
        {
            if (resultCount % MaxResults == 0)
            {
                totalPages = resultCount / MaxResults;
            }
            else
            {
                tmpCount = System.Convert.ToInt32(resultCount / MaxResults);
                if (tmpCount * MaxResults < resultCount)
                {
                    totalPages = tmpCount + 1;
                }
                else
                {
                    totalPages = tmpCount;
                }
            }
        }

        str.Append("</table>");
        if (totalPages == 0)
        {
            strRet = new StringBuilder();
            strRet.Append("<content>");
            strRet.Append("<table style=\"width:100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
            strRet.Append("<tr><td>" + m_refMsg.GetMessage("alt no related content") + "</td></tr>");
            strRet.Append("</table>");
            strRet.Append("</content>");
            strRet.Append("<totalPages>").Append(totalPages).Append("</totalPages>");
        }
        else
        {
            strRet.Append("<content>");
            strRet.Append("<div class=\"header\">" + m_refMsg.GetMessage("lbl total") + ": ").Append(resultCount).Append("<br/>");
            strRet.Append("" + m_refMsg.GetMessage("page lbl") + ": ").Append(pageNumber).Append(" " + m_refMsg.GetMessage("lbl of") + " ").Append(totalPages).Append("</div>");
            strRet.Append(str.ToString());
            strRet.Append("</content>");
            strRet.Append("<totalPages>").Append(totalPages).Append("</totalPages>");
        }

        Response.Write(strRet.ToString());
    }
Example #2
0
    protected void Page_Load(object sender, System.EventArgs e)
    {
        Ektron.Cms.ContentAPI content_api = new Ektron.Cms.ContentAPI();
            try
            {
                Ektron.Cms.ContentData content_data = null;
                long asset_id = 0;
                bool valid_attempt = false;
                int LangbackUp = 0;
                if (! (Request.QueryString["id"] == null))
                {
                    asset_id = Convert.ToInt64(Request.QueryString["id"]);
                }
                LangbackUp = content_api.ContentLanguage;
                if (Request.QueryString["LangType"] != null && content_api.ContentLanguage == -1)
                {
                    content_api.ContentLanguage = Convert.ToInt32(Request.QueryString["LangType"]);
                }
                if (content_api.ContentLanguage == -1)
                {
                    content_api.ContentLanguage = int.Parse(content_api.GetCookieValue("SiteLanguage"));
                }
                long iTmpCaller = content_api.RequestInformationRef.CallerId;
                if (asset_id > 0)
                {
                    content_api.RequestInformationRef.CallerId = Ektron.Cms.Common.EkConstants.InternalAdmin;
                    content_api.RequestInformationRef.UserId = Ektron.Cms.Common.EkConstants.InternalAdmin;
                    try
                    {
                        content_data = content_api.GetContentById(asset_id, 0);
                    }
                    catch
                    {
                    }
                    finally
                    {
                        content_api.RequestInformationRef.CallerId = iTmpCaller;
                        content_api.RequestInformationRef.UserId = iTmpCaller;
                    }
                    if (content_data != null)
                    {
                        content_api.ContentLanguage = content_data.LanguageId;
                        content_data = null;
                    }
                    content_data = content_api.ShowContentById(asset_id, content_api.CmsPreview, System.Convert.ToBoolean(! content_api.CmsPreview));
                    content_api.ContentLanguage = LangbackUp;
                }
                if ((content_data != null) && (content_data.AssetData != null) && (content_data.AssetData.Version.Length > 0))
                {
                    string filepath = Page.Server.MapPath((string) (content_api.EkContentRef.GetViewUrl(Convert.ToInt32(content_data.Type), content_data.AssetData.Id).Replace(Page.Request.Url.Scheme + "://" + Page.Request.Url.Authority, "").Replace(":443", "").Replace(":80", "")));
                    if (filepath != null)
                    {
                        if (File.Exists(filepath))
                        {
                            valid_attempt = true;
                            string filename = Path.GetFileName(filepath);
                            string ext = "";
                            ext = Path.GetExtension(filepath);
                            AssetData _assetData = new AssetData();
                            _assetData.AssetDataFromAssetID(content_data.AssetData.Id);
                            if (ext.Contains("pdf") || ext.Contains("pps"))
                            {
                                WebClient client = new WebClient();
                                byte[] Buffer = client.DownloadData(Convert.ToString(filepath));
                                if (Buffer.Length > 0)
                                {
                                    valid_attempt = true;
                                    Response.Clear();
                                    Response.ContentType = (string) ((ext.Contains("pdf")) ? "application/pdf" : "application/vnd.ms-powerpoint");
                                    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + (Request.Browser.Browser == "IE" ? (Server.UrlPathEncode(System.IO.Path.GetFileNameWithoutExtension(_assetData.Handle))) : (System.IO.Path.GetFileNameWithoutExtension(_assetData.Handle))) + ext + "\"");
                                    Response.AddHeader("Content-Length", Buffer.Length.ToString());
                                    Response.BinaryWrite(Buffer);
                                }
                            }
                            else
                            {
                                //if (ext.Contains("txt") || ext.Contains("nxb"))
                                //{
                                //    filepath = DocumentManagerData.Instance.StorageLocation + _assetData.Storage + ConfigManager.pathChar + _assetData.Name;
                                //}
                                Response.Clear();
                                Response.ContentType = content_data.AssetData.MimeType;
                                Response.AddHeader("Content-Disposition", "attachment; filename=\"" + (Request.Browser.Browser == "IE" ? (Server.UrlPathEncode(_assetData.Handle)) : _assetData.Handle) + "\"");
                                try
                                {
                                    FileInfo fi = new FileInfo(filepath);
                                    Response.AddHeader("Content-Length", fi.Length.ToString());
                                }
                                catch { }
                                Response.WriteFile(filepath);
                            }
                            Response.Flush();
                            try
                            {
                                Response.End();
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                if (! valid_attempt)
                {
                    notification_message.Text = "File does not exist or you do not have permission to view this file";
                    notification_message.ToolTip = "Error Message - " + notification_message.Text;
                    // Register CSS
                    Ektron.Cms.API.Css.RegisterCss(this, Ektron.Cms.API.Css.ManagedStyleSheet.EktronWorkareaCss);
                    Ektron.Cms.API.Css.RegisterCss(this, Ektron.Cms.API.Css.ManagedStyleSheet.EktronWorkareaIeCss, Ektron.Cms.API.Css.BrowserTarget.AllIE);
                    Login.Visible = System.Convert.ToBoolean(!content_api.IsLoggedIn);
                    content_api.RequestInformationRef.RedirectFromLoginKeyName = Request.Url.PathAndQuery.ToString();
                    Login.RedirectFromLoginPage();
                    Login.Fill();
                }

            }
            catch (Exception)
            {
                notification_message.Text = "File does not exist or you do not have permission to view this file";
                // Register CSS
                Ektron.Cms.API.Css.RegisterCss(this, Ektron.Cms.API.Css.ManagedStyleSheet.EktronWorkareaCss);
                Ektron.Cms.API.Css.RegisterCss(this, Ektron.Cms.API.Css.ManagedStyleSheet.EktronWorkareaIeCss, Ektron.Cms.API.Css.BrowserTarget.AllIE);
                Login.Visible = System.Convert.ToBoolean(!content_api.IsLoggedIn);
                content_api.RequestInformationRef.RedirectFromLoginKeyName = Request.Url.PathAndQuery.ToString();
                Login.RedirectFromLoginPage();
                Login.Fill();
            }
    }