Ejemplo n.º 1
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        try
        {
            string userPath = Request.QueryString["path"];

            if (string.IsNullOrEmpty(userPath))
            {
                CurrentPath = CurrentDirPath = "~/";
                //ParentDirPath = string.Empty;
            }
            else
            {
                string appRelUserPath = null;
                try
                {
                    appRelUserPath = VirtualPathUtility.ToAppRelative(userPath);
                }
                catch (Exception /*e*/) { }


                if (!string.IsNullOrEmpty(appRelUserPath))
                {
                    CurrentPath = appRelUserPath;
                    CurrentDirPath = VirtualPathUtility.GetDirectory(appRelUserPath);
                    string tmpDirPath = VirtualPathUtility.RemoveTrailingSlash(CurrentDirPath);
                    if(!string.Equals(tmpDirPath, "~", StringComparison.Ordinal))
                        ParentDirPath = VirtualPathUtility.GetDirectory(tmpDirPath);
                }

                if (string.IsNullOrEmpty(CurrentDirPath))
                {
                    Close(string.Format("{0}: {1}!", GetMessage("COULD_NOT_PARSE_PATH"), userPath), BXDialogGoodbyeWindow.LayoutType.Error, -1);
                    return;
                }
                if (!System.IO.Directory.Exists(System.Web.Hosting.HostingEnvironment.MapPath(CurrentDirPath)))
                {
                    Close(string.Format("{0}: {1}!", GetMessage("COULD_NOT_FIND_FOLDER"), CurrentDirPath), BXDialogGoodbyeWindow.LayoutType.Error, -1);
                    return;
                }
            }

            string userQuery = Request.QueryString["query"];
            if (!string.IsNullOrEmpty(userQuery))
                CurrentQuery = userQuery;

            //...проверка авторизации на модификацию раздела (просмотр без права на изменение не разрешён).
            if (!IsAuthorized())
            { 
                //...диалог авторизации;
                Close(string.Format("{0}: {1}!", GetMessage("INSUFFICIENT_RIGHTS"), CurrentDirPath), BXDialogGoodbyeWindow.LayoutType.Error, -1);
                return;
            }

            BXSite site = BXSite.GetCurrentSite(CurrentDirPath, Request.Url.Host);
            if (site == null)
            {
                Close(string.Format("{0} '{1}'!", GetMessage("SITE_IS_NOT_FOUND"), CurrentDirPath), BXDialogGoodbyeWindow.LayoutType.Error, -1);
                return;
            }

            _keywords = new Dictionary<string, Dictionary<string, string>>();
            _keywordsTypes = BXPageManager.GetKeywords(site.Id);
            foreach (string key in _keywordsTypes.Keys)
            {
                Dictionary<string, string> paramDic = new Dictionary<string, string>();
                paramDic.Add("caption", _keywordsTypes[key]);
                _keywords.Add(key, paramDic);
            }

            bool isRoot = string.IsNullOrEmpty(ParentDirPath);
            if (!isRoot)
            {
                BXSectionInfo parSectionInfo = BXSectionInfo.GetCumulativeSection(ParentDirPath);
                foreach (KeyValuePair<string, string> parSectionKeyword in parSectionInfo.Keywords)
                {
                    if (!_keywordsTypes.ContainsKey(parSectionKeyword.Key))
                        continue;

                    Dictionary<string, string> paramDic = null;
                    if (!_keywords.TryGetValue(parSectionKeyword.Key, out paramDic))
                        continue;

                    paramDic.Add("defaultValue", parSectionKeyword.Value);
                }
            }

            BXSectionInfo curSectionInfo = BXSectionInfo.GetSection(CurrentDirPath);
            //ClientFolderTitle = curSectionInfo.Name;

            foreach (KeyValuePair<string, string> curSectionKeyword in curSectionInfo.Keywords)
            {
                if (!_keywordsTypes.ContainsKey(curSectionKeyword.Key))
                    continue;

                Dictionary<string, string> paramDic = null;
                if (!_keywords.TryGetValue(curSectionKeyword.Key, out paramDic))
                    continue;

                paramDic.Add("value", curSectionKeyword.Value);
            }



            LoadKeywords();

            Behaviour.Settings.MinWidth = 400;
            Behaviour.Settings.MinHeight = 250;
            Behaviour.Settings.Width = 600;
            Behaviour.Settings.Height = 320;
            Behaviour.Settings.Resizeable = true;

            string query = CurrentQuery;
            if (!string.IsNullOrEmpty(query))
                query = BXQueryString.RemoveParameter(BXConfigurationUtility.Constants.BackUrl, query);

            string backUrl = !string.IsNullOrEmpty(query) ? string.Concat(CurrentPath, "?", query) : CurrentPath;

            DescriptionIconClass = "bx-property-folder";
            DescriptionParagraphs.Add(string.Format("{0} <b>{1}</b>", GetMessage("DESCRIPTION_HEADER"), CurrentDirPath));
            DescriptionParagraphs.Add(
                string.Format(
                    "<a href=\"{0}?path={1}&{2}={3}\" >{4}</a>", 
                    VirtualPathUtility.ToAbsolute("~/bitrix/admin/FileManFolderSettings.aspx"), 
                    HttpUtility.UrlEncode(CurrentDirPath),
                    BXConfigurationUtility.Constants.BackUrl,
                    !string.IsNullOrEmpty(backUrl) ? HttpUtility.UrlEncode(backUrl) : string.Empty,
                    GetMessage("GOTO_CONTROL_PANEL")
                    )
                );
        }
        catch (System.Threading.ThreadAbortException /*exception*/)
        {
            //...игнорируем, вызвано Close();
        }
        catch (Exception exception)
        {
            Close(exception.Message, BXDialogGoodbyeWindow.LayoutType.Error, -1);
        }
    }
Ejemplo n.º 2
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        try
        {
			string userPath = string.Empty;
			this.siteId = Request.QueryString["siteId"];
			if (string.IsNullOrEmpty(this.siteId))
			{
				throw new ArgumentNullException("siteId");
			}

			var site = BXSite.GetById(this.siteId);

			if (BXApplicationHelper.ApplicationType == BXApplicationTechnologyType.Mvc)
			{
				var path = Request.QueryString["path"].Replace(site.UrlVirtualPath.TrimEnd(new char[] { '/' }), string.Empty).Replace("~", string.Empty);
				userPath = string.Format(_defaultPathSite, this.siteId) + path.TrimStart(new char[] { '/' });
			}
			else
			{
				userPath = !string.IsNullOrEmpty(Request.QueryString["path"]) ? Request.QueryString["path"] : "~";
			}

			//string userPath = !string.IsNullOrEmpty(Request["path"]) ? Request["path"] : "~/";
            if (!VirtualPathUtility.IsAppRelative(userPath))
            {
                Close(string.Format(GetMessage("ERROR_FORMATTED_PATH_IS_NOT_APP_RELATIVE"), userPath), BXDialogGoodbyeWindow.LayoutType.Error, -1);
                return;
            }

            CurPath = userPath;
            mCurDir = VirtualPathUtility.GetDirectory(CurPath);
            mCurFile = VirtualPathUtility.GetFileName(CurPath);

            string userQuery = Request.QueryString["query"];
            if (!string.IsNullOrEmpty(userQuery))
                CurQuery = userQuery;

            if (site == null)
            {
                Close(string.Format("{0} '{1}'!", GetMessage("SITE_IS_NOT_FOUND"), CurPath), BXDialogGoodbyeWindow.LayoutType.Error, -1);
                return;
            }

            if (BXUser.IsCanOperate(BXRoleOperation.Operations.FileManage))
            {
                CurrentMarkup = BXSecureIO.FileReadAllText(CurPath, BXConfigurationUtility.DefaultEncoding);
            }

            mClientPageTitle = !IsPostBack ? !string.IsNullOrEmpty(CurrentMarkup) ? BXParser.ParsePageTitle(CurrentMarkup) : string.Empty : Request.Form["pageTitle"];
            if (string.IsNullOrEmpty(mClientPageTitle))
                mClientPageTitle = GetMessage("UNTITLED_PAGE");

            _keywords = new Dictionary<string, Dictionary<string, string>>();
            _keywordsTypes = BXPageManager.GetKeywords(site.Id);
            foreach (string key in _keywordsTypes.Keys)
            {
                Dictionary<string, string> paramDic = new Dictionary<string, string>();
                paramDic.Add("caption", _keywordsTypes[key]);
                //paramDic.Add("value", GetMessage(string.Format("DefaultKeyword_{0}", key)));
                _keywords.Add(key, paramDic);
            }


            BXSectionInfo curSectionInfo = BXSectionInfo.GetCumulativeSection(mCurDir);
            foreach (KeyValuePair<string, string> curSectionKeyword in curSectionInfo.Keywords)
            {
                if (!_keywordsTypes.ContainsKey(curSectionKeyword.Key))
                    continue;

                Dictionary<string, string> paramDic = null;
                if (!_keywords.TryGetValue(curSectionKeyword.Key, out paramDic))
                    continue;

                paramDic.Add("defaultValue", curSectionKeyword.Value);
            }

            if (BXUser.IsCanOperate(BXRoleOperation.Operations.FileManage))
            {
                BXParamsBag<string> keywordBag = BXParser.ParsePageKeywords(mCurrentMarkup);
                if (keywordBag != null)
                    foreach (KeyValuePair<string, string> keyword in keywordBag)
                    {
                        if (!_keywordsTypes.ContainsKey(keyword.Key))
                            continue;
                        Dictionary<string, string> paramDic = null;
                        if (!_keywords.TryGetValue(keyword.Key, out paramDic))
                            continue;

                        paramDic.Add("value", keyword.Value);
                        //if (!paramDic.ContainsKey("value"))
                        //    paramDic.Add("value", keyword.Value);
                        //else
                        //    paramDic["value"] = keyword.Value;
                    }
            }
            LoadKeywords();

            Behaviour.Settings.MinWidth = 400;
            Behaviour.Settings.MinHeight = 250;
            Behaviour.Settings.Width = 600;
            Behaviour.Settings.Height = 320;
            Behaviour.Settings.Resizeable = true;

            string query = CurQuery;
            if (!string.IsNullOrEmpty(query))
                query = BXQueryString.RemoveParameter(BXConfigurationUtility.Constants.BackUrl, query);

            string backUrl = !string.IsNullOrEmpty(query) ? string.Concat(CurPath, "?", query) : CurPath;

            DescriptionIconClass = "bx-property-page";
            DescriptionParagraphs.Add(string.Format("{0} <b>{1}</b>", GetMessage("DESCRIPTION_HEADER"), CurPath));
            DescriptionParagraphs.Add(
                string.Format(
                    "<a href=\"{0}?path={1}&selectedTabIndex=1&{2}={3}\" >{4}</a>", 
                    VirtualPathUtility.ToAbsolute("~/bitrix/admin/FileManEdit.aspx"), 
                    HttpUtility.UrlEncode(mCurPath), 
                    BXConfigurationUtility.Constants.BackUrl,
                    HttpUtility.UrlEncode(backUrl),
                    GetMessage("GOTO_CONTROL_PANEL")
                    )
                );

			if (BXApplicationHelper.ApplicationType == BXApplicationTechnologyType.Mvc)
			{
				Behaviour.EnableFormIdReplace = false;
			}
        }
        catch (System.Threading.ThreadAbortException /*exception*/)
        {
            //...игнорируем, вызвано Close();
        }
        catch (Exception exception)
        {
            Close(exception.Message, BXDialogGoodbyeWindow.LayoutType.Error, -1);
        }
    }