Пример #1
0
	public void SetSettings(BXParamsBag<object> settings)
	{
		Precision.Text = settings.ContainsKey("Precision") ? settings["Precision"].ToString() : String.Empty;
		DefaultValue.Text = settings.ContainsKey("DefaultValue") ? settings.Get<double>("DefaultValue").ToString(CultureInfo.InvariantCulture) : String.Empty;
		TextBoxSize.Text = settings.ContainsKey("TextBoxSize") ? settings["TextBoxSize"].ToString() : String.Empty;
		MinValue.Text = settings.ContainsKey("MinValue") ? settings["MinValue"].ToString().ToString(CultureInfo.InvariantCulture) : String.Empty;
		MaxValue.Text = settings.ContainsKey("MaxValue") ? settings["MaxValue"].ToString().ToString(CultureInfo.InvariantCulture) : String.Empty;
	}
Пример #2
0
		public IndexerInfo(string id, BXParamsBag<object> info, Uri currentUrl)
		{
			Id = id;
			Title = info.GetString("title");
			CreateOptionsControl = info.Get<Delegate>("createOptionsControl");
			GetOptions = info.Get<Delegate>("getOptions");
			if (CreateOptionsControl != null)
				OptionsControl = (Control)CreateOptionsControl.DynamicInvoke();
			string icon = info.GetString("icon");
			if (!string.IsNullOrEmpty(icon))
			{
				Uri iconUri;
				if (Uri.TryCreate(currentUrl, icon.StartsWith("~/") ? VirtualPathUtility.ToAbsolute(icon) : icon, out iconUri))
					IconUrl = iconUri.AbsoluteUri;
			}
		}
Пример #3
0
	public void Activate(BXParamsBag<object> state)
	{
		D.StartHidden = false;
		if (!dynamicsLoaded)
			InitStatics();

		UserTypeIdTextBox.SelectedValue = state.Get("CustomTypeId", "Bitrix.System.Text");
		DontEditInList.Checked = !state.Get("EditInList", true);
		FieldNameTextBox.Text = state.Get("FieldName", string.Empty);
		IsSearchable.Checked = state.Get("IsSearchable", false);
		Mandatory.Checked = state.Get("Mandatory", false);
		MultipleCheckBox.Checked = state.Get("Multiple", false);
		ShowFilter.SelectedValue = ((BXCustomFieldFilterVisibility)state.Get("ShowInFilter", (int)BXCustomFieldFilterVisibility.CompleteMatch)).ToString();
		DontShowInList.Checked = !state.Get("ShowInList", true);
		Sort.Text = state.Get("Sort", string.Empty);
		XmlId.Text = state.Get("XmlId", string.Empty);

		foreach (KeyValuePair<string, Dictionary<string, TextBox>> l in locControls)
		{
			string key = "Loc." + l.Key;
			if (state.ContainsKey(key))
			{
				string[] phrases = (string[])state[key];

				l.Value["EditFormLabel"].Text = phrases[0];
				l.Value["ErrorMessage"].Text = phrases[1];
				l.Value["HelpMessage"].Text = phrases[2];
				l.Value["ListColumnLabel"].Text = phrases[3];
				l.Value["ListFilterLabel"].Text = phrases[4];
			}
		}

		userTypeId = state.Get<string>("@CustomTypeId");
		if (string.IsNullOrEmpty(userTypeId))
			userTypeId = null;

		fieldName = state.Get<string>("@FieldName");
		if (string.IsNullOrEmpty(fieldName))
			fieldName = null;

		if (state.ContainsKey("@Multiple"))
			multiple = state.Get("@Multiple", false);
		else
			multiple = null;

		InstantiateSettings();
		BXParamsBag<object> settingsState = state.Get<BXParamsBag<object>>("Settings");
		if (settings != null && settingsState != null)
			settings.SetSettings(settingsState);
		
		object extrasState = state.Get("Extras", null);
		InstantiateExtraSettings(extrasState);

		StoredSender.Value = state.Get("@Sender", string.Empty);
	}
Пример #4
0
	public void FillField(BXCustomField field, BXParamsBag<object> state)
	{
		field.ShowInList = state.Get("ShowInList", true);
		field.Sort = state.Get("Sort", 10);
		field.Settings.Assign(state.Get<BXParamsBag<object>>("Settings"));
		field.EditInList = state.Get("EditInList", true);
		field.IsSearchable = state.Get("IsSearchable", false);
		field.Mandatory = state.Get("Mandatory", false);
		field.ShowInFilter = (BXCustomFieldFilterVisibility)state.Get("ShowInFilter", (int)BXCustomFieldFilterVisibility.CompleteMatch);
		field.XmlId = state.Get("XmlId", string.Empty);
	}
Пример #5
0
	public void FillLocalization(BXCustomField field, BXParamsBag<object> state)
	{
		foreach (string lang in BXLoc.Locales)
		{
			string key = "Loc." + lang;


			BXCustomFieldLocalization l = field.Localization[lang];
			if (l == null) 
			{
				l = new BXCustomFieldLocalization();
				field.Localization[lang] = l;
			}

			if (!state.ContainsKey(key))
				continue;

			string[] phrases = state.Get<string[]>(key);
			l.EditFormLabel = phrases[0];
			l.ErrorMessage = phrases[1];
			l.HelpMessage = phrases[2];
			l.ListColumnLabel = phrases[3];
			l.ListFilterLabel = phrases[4];
		}
	}
Пример #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region HackUnSef

        BXParamsBag<string> urlToPage = new BXParamsBag<string>();
        BXParamsBag<object> request = new BXParamsBag<object>();
        string PageKey = String.Empty;        

        urlToPage.Add("ElementTOP", TOPElementURL);
        urlToPage.Add("SectionPage", SectionPageURL);
        urlToPage.Add("Element", ElementURL);
        urlToPage.Add("Section", SectionURL);

        if (EnableSef)
        {
            PageKey = MapVariable(SEFFolder, urlToPage, request, String.Empty);

            Results["ParamSectionId"] = ParamSectionId;
            Results["ParamElementId"] = ParamElementId;
            Results["ParamPageId"] = ParamPageId;
            Results["ParamElementCode"] = ParamElementCode;
            Results["ParamSectionCode"] = ParamSectionCode;
        }
        else
        {
            BXParamsBag<string> variableAliases = new BXParamsBag<string>();
            variableAliases.Add(ParamSectionId, AliasSectionId);
            variableAliases.Add(ParamElementId, AliasElementId);
            variableAliases.Add(ParamPageId, AliasPageId);
            variableAliases.Add(ParamSectionCode, AliasSectionCode);
            variableAliases.Add(ParamElementCode, AliasElementCode);
            MapVariable(variableAliases, request);

            Results["ParamSectionId"] = AliasSectionId;
            Results["ParamElementId"] = AliasElementId;
            Results["ParamPageId"] = AliasPageId;
            Results["ParamElementCode"] = AliasElementCode;
            Results["ParamSectionCode"] = AliasSectionCode;
        }

        SectionId = request.Get(ParamSectionId, SectionId);
        ElementId = request.Get(ParamElementId, ElementId);
        PageId = request.Get(ParamPageId, PageId);
        ElementCode = request.Get(ParamElementCode, ElementCode);
        SectionCode = request.Get(ParamSectionCode, SectionCode);

        if (!EnableSef)
        {
            if (PageId > 0) PageKey = "SectionPage";
            else if (ElementId > 0 || !String.IsNullOrEmpty(ElementCode)) PageKey = "Element";
            else if (SectionId > 0 || !String.IsNullOrEmpty(SectionCode)) PageKey = "Section";
        }

        #endregion

        if (String.IsNullOrEmpty(SectionCode) && SectionId <= 0 && IBlockId > 0)
        {
            Results["ShowTopElements"] = true;
        }
        
        Results["SectionURL"] = SectionURL;
        Results["SectionPageURL"] = SectionPageURL;
        Results["ElementURL"] = ElementURL;
        Results["TOPElementURL"] = TOPElementURL;

        Results["SectionId"] = SectionId;
        Results["ElementId"] = ElementId;
        Results["PageId"] = PageId;
        Results["ElementCode"] = ElementCode;
        Results["SectionCode"] = SectionCode;

        Results["PageKey"] = PageKey;

        if (String.IsNullOrEmpty(PageKey))
            IncludeComponentTemplate();
        else if (PageKey == "Element" || PageKey == "ElementTOP")
            IncludeComponentTemplate("element");
        else
            IncludeComponentTemplate();
    }
Пример #7
0
    public override void ProcessMessage(BXCommand cmd, bool executionContext, string executionVirtualPath)
    {
        if (cmd.Action == "Bitrix.Search.ProvideUrl")
        {
            if (cmd.Parameters.Get<string>("moduleId") != "iblock")
                return;
            int iblockId = Parameters.Get("IBlockId", -1);
            if (iblockId < 0 || cmd.Parameters.Get<int>("itemGroup") != iblockId)
                return;
            int elementId = cmd.Parameters.Get("itemId", -1);
            if (elementId < 0)
                return;

            BXIBlockElement ibe = BXIBlockElement.GetById(elementId);
            BXIBlockSection ibs = null;
            if (ibe != null)
                foreach (int sid in ibe.Sections.ToList())
                {
                    ibs = BXIBlockSection.GetById(sid);
                    if (ibs != null)
                        break;
                }
            if (ibe == null || ibs == null)
                return;

            Results["SECTION_ID"] = ibs.Id;
            Results["ELEMENT_ID"] = ibe.Id;
            Results["SECTION_CODE"] = ibs.Code ?? string.Empty;
            Results["ELEMENT_CODE"] = ibe.Code ?? string.Empty;

            string url;
            if (Parameters.Get<bool>("EnableSEF"))
                url =
                    MakeLink(Parameters.Get<string>("SEFFolder"),
                             Parameters.Get<string>("SEF_URL_TEMPLATES_element", "#SECTION_ID#/#ELEMENT_ID#/"));
            else
                url = MakeLink(string.Format(
                                   "{0}?{1}=#SECTION_ID#&{2}=#ELEMENT_ID#",
                                   VirtualPathUtility.ToAbsolute(executionVirtualPath),
                                   Parameters.Get<string>("VARIABLE_ALIASES_SECTION_ID", "SECTION_ID"),
                                   Parameters.Get<string>("VARIABLE_ALIASES_ELEMENT_ID", "ELEMENT_ID")
                                   ));
            cmd.AddCommandResult("bitrix:catalog@" + executionVirtualPath,
                                 new BXCommandResult(BXCommandResultType.Ok, url));
        }

		if (cmd.Action == "Bitrix.Main.GeneratePublicMenu")
		{
			//Bitrix.Diagnostics.BXDump.ToFile(
			//    String.Format(
			//        "executionVirtualPath={0}, uriPath={1}, uri={2}, SefFolder={3}, GenerateMenuType={4}, menuType={5}", 
			//        executionVirtualPath, 
			//        cmd.Parameters.Get<string>("uriPath"), 
			//        cmd.Parameters.Get<string>("uri"), 
			//        Bitrix.IO.BXPath.ToVirtualRelativePath(SEFFolder.TrimStart('\\', '/')),
			//        Parameters.Get("GenerateMenuType", "left"),
			//        cmd.Parameters.Get<string>("menuType")
			//    )
			//);

			//if (!cmd.Parameters.Get<string>("uriPath").StartsWith(Bitrix.IO.BXPath.ToVirtualRelativePath(SEFFolder.TrimStart('\\', '/')) + "/", StringComparison.InvariantCultureIgnoreCase))
				//return;

			//Генерируем меню только для тех адресов, которые выводит сам компонент.
			if (!Parameters.Get<bool>("EnableSEF") && !executionVirtualPath.Equals(cmd.Parameters.Get<string>("uriPath"), StringComparison.InvariantCultureIgnoreCase))
				return;
			else if (Parameters.Get<bool>("EnableSEF") && !cmd.Parameters.Get<string>("uriPath").StartsWith(Bitrix.IO.BXPath.ToVirtualRelativePath(SEFFolder.TrimStart('\\', '/')) + "/", StringComparison.InvariantCultureIgnoreCase))
				return;

			if (!Parameters.Get("GenerateMenuType", "left").Equals(cmd.Parameters.Get<string>("menuType"), StringComparison.InvariantCultureIgnoreCase))
				return;

			int iblockId = Parameters.Get("IBlockId", -1);
			if (iblockId < 0)
			    return;

			BXParamsBag<string> urlToPage = new BXParamsBag<string>();
			BXParamsBag<object> request = new BXParamsBag<object>();
			string PageKey = String.Empty;

			urlToPage.Add("ElementTOP", TOPElementURL.TrimEnd('/', '\\'));
			urlToPage.Add("SectionPage", SectionPageURL.TrimEnd('/', '\\'));
			urlToPage.Add("Element", ElementURL.TrimEnd('/', '\\'));
			urlToPage.Add("Section", SectionURL.TrimEnd('/', '\\'));

			if (EnableSef)
			{
				PageKey = MapVariable(SEFFolder, urlToPage, request, String.Empty, BXUri.ToRelativeUri(cmd.Parameters.Get<string>("uri")));
			}
			else
			{
				BXParamsBag<string> variableAliases = new BXParamsBag<string>();
				variableAliases.Add(ParamSectionId, AliasSectionId);
				variableAliases.Add(ParamElementId, AliasElementId);
				variableAliases.Add(ParamPageId, AliasPageId);
				variableAliases.Add(ParamSectionCode, AliasSectionCode);
				variableAliases.Add(ParamElementCode, AliasElementCode);

				MapVariable(variableAliases, request, BXUri.ToRelativeUri(cmd.Parameters.Get<string>("uri")));
			}

			SectionId = request.Get(ParamSectionId, SectionId);
			ElementId = request.Get(ParamElementId, ElementId);
			PageId = request.Get(ParamPageId, PageId);
			ElementCode = request.Get(ParamElementCode, ElementCode);
			SectionCode = request.Get(ParamSectionCode, SectionCode);

			List<BXPublicMenuItem> resultList = null;
			string parentLevelUri = null;

			if (ElementId > 0 || !String.IsNullOrEmpty(ElementCode))
			{
				if (SectionId > 0 || !String.IsNullOrEmpty(SectionCode))
				{
					BXParamsBag<object> p = new BXParamsBag<object>();
					p["SECTION_ID"] = SectionId;
					p["SECTION_CODE"] = SectionCode;
					parentLevelUri = MakeMenuUri(executionVirtualPath, p);
				}
				else
				{
					BXFilter elFilter = new BXFilter(
						new BXFilterItem(BXIBlockElement.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
						new BXFilterItem(BXIBlockElement.Fields.ActiveDate, BXSqlFilterOperators.Equal, "Y")
					);
					if (ElementId > 0)
						elFilter.Add(new BXFilterItem(BXIBlockElement.Fields.ID, BXSqlFilterOperators.Equal, ElementId));
					else
						elFilter.Add(new BXFilterItem(BXIBlockElement.Fields.Code, BXSqlFilterOperators.Equal, ElementCode));

					BXIBlockElementCollection collElement = BXIBlockElement.GetList(elFilter, null);
					if (collElement != null)
					{
						if (collElement.Count > 0)
						{
							BXIBlockElement.BXInfoBlockElementSectionCollection es = collElement[0].Sections;
							if (es != null)
							{
								if (es.Count > 0)
								{
									SectionId = es[0].SectionId;

									BXParamsBag<object> p = new BXParamsBag<object>();
									p["SECTION_ID"] = SectionId;

									if (Parameters.Get<bool>("EnableSEF") && SectionURL.Contains("#SECTION_CODE#"))
									{
										BXIBlockSectionCollection collSection = BXIBlockSection.GetList(
											new BXFilter(
												new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
												new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
												new BXFilterItem(BXIBlockSection.Fields.ID, BXSqlFilterOperators.Equal, SectionId),
												new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, iblockId)
											),
											null
										);
										if (collSection != null)
										{
											if (collSection.Count > 0)
											{
												SectionCode = collSection[0].Code;
												p["SECTION_CODE"] = SectionCode;
											}
										}
									}

									parentLevelUri = MakeMenuUri(executionVirtualPath, p);
								}
							}
						}
					}
				}
			}

			if (parentLevelUri == null)
			{
				if (SectionId > 0 || !String.IsNullOrEmpty(SectionCode))
				{
					int parentSectionId = 0;
					bool parentSectionFound = false;

					if (SectionId <= 0)
					{
						BXIBlockSectionCollection coll = BXIBlockSection.GetList(
							new BXFilter(
								new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
								new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
								new BXFilterItem(BXIBlockSection.Fields.Code, BXSqlFilterOperators.Equal, SectionCode),
								new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, iblockId)
							),
							null
						);
						if (coll != null)
						{
							if (coll.Count > 0)
							{
								SectionId = coll[0].Id;
								parentSectionId = coll[0].SectionId;
								parentSectionFound = true;
							}
						}
					}

					if (SectionId > 0)
					{
						BXIBlockSectionCollection coll = BXIBlockSection.GetList(
							new BXFilter(
								new BXFilterItem(BXIBlockSection.Fields.SectionId, BXSqlFilterOperators.Equal, SectionId),
								new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
								new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
								new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, iblockId)
							),
							new BXOrderBy(
								new BXOrderByPair(BXIBlockSection.Fields.Sort, BXOrderByDirection.Asc),
								new BXOrderByPair(BXIBlockSection.Fields.Name, BXOrderByDirection.Asc)
							)
						);

						resultList = ExtractMenuItemsFromCollection(executionVirtualPath, resultList, coll);

						if (resultList == null)
						{
							if (!parentSectionFound)
							{
								coll = BXIBlockSection.GetList(
									new BXFilter(
										new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
										new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
										new BXFilterItem(BXIBlockSection.Fields.ID, BXSqlFilterOperators.Equal, SectionId),
										new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, iblockId)
									),
									null
								);
								if (coll != null)
								{
									if (coll.Count > 0)
									{
										parentSectionFound = true;
										parentSectionId = coll[0].SectionId;
									}
								}
							}

							if (parentSectionFound && parentSectionId > 0)
							{
								BXParamsBag<object> p = new BXParamsBag<object>();
								p["SECTION_ID"] = parentSectionId;

								if (Parameters.Get<bool>("EnableSEF") && SectionURL.Contains("#SECTION_CODE#"))
								{
									coll = BXIBlockSection.GetList(
										new BXFilter(
											new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
											new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
											new BXFilterItem(BXIBlockSection.Fields.ID, BXSqlFilterOperators.Equal, parentSectionId),
											new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, iblockId)
										),
										null
									);
									if (coll != null)
									{
										if (coll.Count > 0)
											p["SECTION_CODE"] = coll[0].Code;
									}
								}

								parentLevelUri = MakeMenuUri(executionVirtualPath, p);
							}
							else
							{
								if (Parameters.Get<bool>("EnableSEF"))
									parentLevelUri = MakeLink(Parameters.Get<string>("SEFFolder"), "");
								else
									parentLevelUri = BXUri.ToAppRelativeUri(executionVirtualPath);
							}
						}
					}
				}
			}

			if (parentLevelUri == null)
			{
				if (resultList == null)
				{
					BXIBlockSectionCollection coll = BXIBlockSection.GetList(
						new BXFilter(
							new BXFilterItem(BXIBlockSection.Fields.SectionId, BXSqlFilterOperators.Equal, null),
							new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
							new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
							new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, iblockId)
						),
						new BXOrderBy(
							new BXOrderByPair(BXIBlockSection.Fields.Sort, BXOrderByDirection.Asc),
							new BXOrderByPair(BXIBlockSection.Fields.Name, BXOrderByDirection.Asc)
						)
					);

					resultList = ExtractMenuItemsFromCollection(executionVirtualPath, resultList, coll);
				}
			}

			BXPublicMenu.BXLoadMenuCommandParameter r = new BXPublicMenu.BXLoadMenuCommandParameter(resultList, true, parentLevelUri);
			cmd.AddCommandResult("bitrix:catalog@" + executionVirtualPath, new BXCommandResult(BXCommandResultType.Ok, r));
		}
	}
Пример #8
0
    public override void ProcessMessage(BXCommand cmd, bool executionContext, string executionVirtualPath)
    {
        #region Search
        if (cmd.Action == "Bitrix.Search.ProvideUrl")
        {
            string moduleId = cmd.Parameters.Get("moduleId", string.Empty);
            if (string.Equals(moduleId, "forum", StringComparison.OrdinalIgnoreCase) 
                && AllowComments 
                && BXModuleManager.IsModuleInstalled("Forum"))
            {
                //Поиск по комментариям к новостям
                int blockId = IBlockId;
                int forumId = cmd.Parameters.GetInt("itemGroup", 0);
                int postId = cmd.Parameters.GetInt("itemId", 0);
                int topicId = cmd.Parameters.GetInt("param1");


                if (blockId == 0 || !string.Equals(moduleId, "forum", StringComparison.OrdinalIgnoreCase) || forumId <= 0 || postId <= 0)
                    return;

                BXFilter f = new BXFilter(
                        new BXFilterItem(BXIBlockElement.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
                        new BXFilterItem(BXIBlockElement.Fields.ActiveDate, BXSqlFilterOperators.Equal, "Y"),
                        new BXFilterItem(BXIBlockElement.Fields.IBlock.ID, BXSqlFilterOperators.Equal, blockId),
                        new BXFilterItem(BXIBlockElement.Fields.CustomFields[blockId].GetFieldByKey(CommentCustomPropertyName), BXSqlFilterOperators.Equal, topicId)
                        );

                string siteId = DesignerSite;
                if (!string.IsNullOrEmpty(siteId))
                    f.Add(new BXFilterItem(BXIBlockElement.Fields.IBlock.Sites.SiteId, BXSqlFilterOperators.Equal, siteId));

                BXIBlockElementCollection c = BXIBlockElement.GetList(f, null);
                if (c.Count == 0)
                    return;

                BXIBlockElement el = c[0];
                //формируем постоянную ссылку на комментарий
                string commentUrl = string.Empty;
                if (!EnableSef)
                    commentUrl = string.Format("{0}?{1}={2}&{3}={4}#comment{4}", BXSite.GetUrlForPath(executionVirtualPath, null, cmd.SiteId), ParamNews, el.Id.ToString(), ParamComment, postId.ToString());
                else
                {
                    BXParamsBag<object> commentSefParams = new BXParamsBag<object>();
                    commentSefParams["SectionId"] = string.Empty;
                    commentSefParams["ElementId"] = el.Id.ToString();
                    commentSefParams["CommentId"] = postId.ToString();
                    string t = SefDetailCommentRead;
                    if (t.IndexOf("##") < 0)
                        t = string.Concat(t, "##comment#CommentId#");
                    commentUrl = BXSefUrlUtility.MakeLink(CombineLink(SefFolder, t), commentSefParams).Replace("//", "/");
                }
                cmd.AddCommandResult(string.Concat("bitrix:forum@", executionVirtualPath), new BXCommandResult(BXCommandResultType.Ok, commentUrl));                    
                return;
            }

            if (!string.Equals(moduleId, "iblock", StringComparison.OrdinalIgnoreCase))
                return;

            if (IBlockId < 0 || cmd.Parameters.Get<int>("itemGroup") != IBlockId)
                return;

            int elementId = cmd.Parameters.Get("itemId", -1);
            if (elementId < 0)
                return;

            BXIBlockElement elm = BXIBlockElement.GetById(elementId);
            if (elm == null) return;
            BXParamsBag<object> p = new BXParamsBag<object>();
            p.Add("ElementId", elementId);
            p.Add("SectionId", elm.Sections.Count > 0 ? elm.Sections[0].SectionId.ToString() : String.Empty);
            string url;
            if (EnableSef)
            {
                url = MakeLink(SefFolder, SefNews, p);
                if (elm.Sections.Count == 0)
                    url = url.Replace("//", "/");
            }
            else
                url = MakeLink(string.Format("{0}?{1}=#ElementId#", BXSite.GetUrlForPath(executionVirtualPath, null, cmd.SiteId), ParamNews), p);
            cmd.AddCommandResult("bitrix:news@" + executionVirtualPath, new BXCommandResult(BXCommandResultType.Ok, url));
        }
        #endregion

        if (cmd.Action == "Bitrix.Main.GeneratePublicMenu")
        {
            //Совпадает ли тип меню в параметрах компонента с типом, который запрашивает система.
            if (!Parameters.Get("GenerateMenuType", "left").Equals(cmd.Parameters.Get<string>("menuType"), StringComparison.InvariantCultureIgnoreCase))
                return;

            //Генерируем меню только для тех адресов, которые выводит сам компонент.
            if (!Parameters.Get<bool>("EnableSEF") && !BXSiteRemapUtility.UnmapVirtualPath(executionVirtualPath).Equals(cmd.Parameters.Get<string>("uriPath"), StringComparison.InvariantCultureIgnoreCase))
                return;
            else if (Parameters.Get<bool>("EnableSEF") && !cmd.Parameters.Get<string>("uriPath").StartsWith(Bitrix.IO.BXPath.ToVirtualRelativePath(SefFolder.TrimStart('\\', '/')) + "/", StringComparison.InvariantCultureIgnoreCase))
                return;

            if (IBlockId < 0)
                return;

            BXParamsBag<object> request = new BXParamsBag<object>();
            BXParamsBag<string> urlToPage = new BXParamsBag<string>();

            if (EnableSef)
            {
                urlToPage["detail"] = SefNews;
                urlToPage["section"] = SefSection;
                urlToPage["news.page"] = SefPage;
                urlToPage["news.showall"] = SefShowAll;
                urlToPage["rss"] = Parameters.Get("Sef_Rss", String.Empty);
                urlToPage["sectionrss"] = Parameters.Get("Sef_Rss_Section", String.Empty);

                MapVariable(SefFolder, urlToPage, request, String.Empty, BXUri.ToRelativeUri(cmd.Parameters.Get<string>("uri")));
            }
            else
            {
                BXParamsBag<string> variableAlias = new BXParamsBag<string>();
                variableAlias["ElementId"] = ParamNews;
                variableAlias["SectionId"] = ParamSection;

                MapVariable(variableAlias, request, BXUri.ToRelativeUri(cmd.Parameters.Get<string>("uri")));
            }

            //Определим уровень доступа пунктов
            if ((menuItemPermisson = (string)BXCacheManager.MemoryCache.Get(PermissionCacheKey)) == null)
            {
                menuItemPermisson = String.Empty;
                StringBuilder menuItemRoles = new StringBuilder();
                if (Parameters.Get<bool>("UsePermissions"))
                {
                    foreach (string permission in Parameters.GetList("GroupPermissions", new List<object>()))
                    {
                        menuItemRoles.Append(permission);
                        menuItemRoles.Append(";");
                    }

                    if (menuItemRoles.Length > 0)
                        menuItemRoles.Append("Admin");
                }
                else
                {
                    BXRoleCollection iblockRoles = BXRoleManager.GetAllRolesForOperation("IBlockRead", "iblock", IBlockId.ToString());
                    foreach (BXRole role in iblockRoles)
                    {
                        //Если доступно всем
                        if (role.RoleName == "Guest")
                        {
                            menuItemRoles = null;
                            break;
                        }
                        //Если доступно группе User, значит достаточно проверить только для этой группы
                        else if (role.RoleName == "User")
                        {
                            menuItemRoles = null;
                            menuItemPermisson = "User";
                            break;
                        }
                        else
                        {
                            menuItemRoles.Append(role.RoleName);
                            menuItemRoles.Append(";");
                        }
                    }
                }

                if (menuItemRoles != null && menuItemRoles.Length > 0)
                    menuItemPermisson = menuItemRoles.ToString();

                BXCacheManager.MemoryCache.Insert(PermissionCacheKey, menuItemPermisson);
            }

            int elementId = 0, sectionId = 0;
            elementId = request.Get<int>("ElementId", elementId);
            sectionId = request.Get<int>("SectionId", sectionId);

            string parentLevelUri = null;
            List<BXPublicMenuItem> menuList = null;

            if (elementId > 0 && sectionId > 0)
            {
                parentLevelUri = MakeMenuUri(executionVirtualPath, sectionId);
            }
            //Если указан только элемент
            else if (elementId > 0)
            {
                BXFilter elementFilter = new BXFilter(
                    new BXFilterItem(BXIBlockElement.Fields.ID, BXSqlFilterOperators.Equal, elementId),
                    new BXFilterItem(BXIBlockElement.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId)
                );

                if (Parameters.Get<bool>("ShowActiveElements", true))
                {
                    elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.Active, BXSqlFilterOperators.Equal, "Y"));
                    elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.ActiveDate, BXSqlFilterOperators.Equal, "Y"));
                }

                BXIBlockElementCollection element = BXIBlockElement.GetList(elementFilter, null);
                if (element != null && element.Count > 0)
                {
                    BXIBlockElement.BXInfoBlockElementSectionCollection sections = element[0].Sections;
                    if (sections != null && sections.Count > 0)
                    {
                        sectionId = sections[0].SectionId;
                        parentLevelUri = MakeMenuUri(executionVirtualPath, sectionId); //Меню строится для раздела, к которому привязан элемент
                    }
                }
            }

            //Если указан раздел выводим его дочерние разделы
            if (parentLevelUri == null && sectionId > 0)
            {
                BXIBlockSectionCollection sectionList = BXIBlockSection.GetList(
                    new BXFilter(
                        new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
                        new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
                        new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId),
                        new BXFilterItem(BXIBlockSection.Fields.SectionId, BXSqlFilterOperators.Equal, sectionId)
                    ),
                    new BXOrderBy(
                        new BXOrderByPair(BXIBlockSection.Fields.Sort, BXOrderByDirection.Asc),
                        new BXOrderByPair(BXIBlockSection.Fields.Name, BXOrderByDirection.Asc)
                    )
                );

                menuList = ExtractMenuItemsFromCollection(sectionList, executionVirtualPath);

                //Если нет дочерних разделов, то меню строится для родителя указанного раздела 
                if (menuList == null)
                {
                    sectionList = BXIBlockSection.GetList(
                        new BXFilter(
                            new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
                            new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
                            new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId),
                            new BXFilterItem(BXIBlockSection.Fields.ID, BXSqlFilterOperators.Equal, sectionId)
                        ),
                        new BXOrderBy(
                            new BXOrderByPair(BXIBlockSection.Fields.Sort, BXOrderByDirection.Asc),
                            new BXOrderByPair(BXIBlockSection.Fields.Name, BXOrderByDirection.Asc)
                        )
                    );

                    if (sectionList != null && sectionList.Count > 0 && sectionList[0].SectionId > 0)
                    {
                        parentLevelUri = MakeMenuUri(executionVirtualPath, sectionList[0].SectionId);
                    }
                    else
                    {
                        //Если такой раздел не существует или это раздел корневой (нет родителя)
                        if (Parameters.Get<bool>("EnableSEF"))
                            parentLevelUri = SefFolder;
                        else
                            parentLevelUri = BXSiteRemapUtility.UnmapVirtualPath(executionVirtualPath);
                    }
                }
            }

            //Если ничего не указано выводим корневые разделы
            Dictionary<string, BXPublicMenu.BXLoadMenuCommandParameter> menuTree = new Dictionary<string, BXPublicMenu.BXLoadMenuCommandParameter>();
            if (parentLevelUri == null && menuList == null)
            {

                /*BXIBlockSectionCollection sectionList = BXIBlockSection.GetList(
                    new BXFilter(
                        new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
                        new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
                        new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId),
                        new BXFilterItem(BXIBlockSection.Fields.SectionId, BXSqlFilterOperators.Equal, null)
                    ),

                    new BXOrderBy(
                        new BXOrderByPair(BXIBlockSection.Fields.Sort, BXOrderByDirection.Asc),
                        new BXOrderByPair(BXIBlockSection.Fields.Name, BXOrderByDirection.Asc)
                    )
                );

                            menuList = ExtractMenuItemsFromCollection(sectionList, executionVirtualPath);
            */
                BXIBlockSectionCollection sectionsList = BXIBlockSection.GetList(
                    new BXFilter(
                        new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
                        new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
                        new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId)
                    ),
                    new BXOrderBy(
                        new BXOrderByPair(BXIBlockSection.Fields.LeftMargin, BXOrderByDirection.Asc),
                        new BXOrderByPair(BXIBlockSection.Fields.Sort, BXOrderByDirection.Asc),
                        new BXOrderByPair(BXIBlockSection.Fields.Name, BXOrderByDirection.Asc)
                    )
                );

                Dictionary<int, List<BXPublicMenuItem>> sectionTree = new Dictionary<int, List<BXPublicMenuItem>>();
                foreach (BXIBlockSection section in sectionsList)
                {
                    if (!sectionTree.ContainsKey(section.SectionId))
                        sectionTree.Add(section.SectionId, new List<BXPublicMenuItem>());

                    BXPublicMenuItem menuItem = new BXPublicMenuItem();
                    menuItem.Title = section.Name;
                    menuItem.Links.Add(MakeMenuUri(executionVirtualPath, section.Id));
                    menuItem.Sort = section.Sort;
                    if (!String.IsNullOrEmpty(menuItemPermisson))
                    {
                        menuItem.ConditionType = ConditionType.Group;
                        menuItem.Condition = menuItemPermisson;
                    }
                    sectionTree[section.SectionId].Add(menuItem);
                }

                foreach (KeyValuePair<int, List<BXPublicMenuItem>> submenuList in sectionTree)
                {
                    string url = null;
                    if (submenuList.Key > 0)
                    {
                        url = MakeMenuUri(executionVirtualPath, submenuList.Key);
                    }
                    else
                    {
                        if (Parameters.Get<bool>("EnableSEF"))
                            url = SefFolder;
                        else
                            url = BXSiteRemapUtility.UnmapVirtualPath(executionVirtualPath);
                    }

                    menuTree.Add(url, new BXPublicMenu.BXLoadMenuCommandParameter(submenuList.Value, true, null));
                }
            }

            if (menuTree.Count > 0)
                cmd.AddCommandResult("bitrix:news@" + executionVirtualPath, new BXCommandResult(BXCommandResultType.Ok, menuTree));
            else
            {
                BXPublicMenu.BXLoadMenuCommandParameter menuResult = new BXPublicMenu.BXLoadMenuCommandParameter(menuList, true, parentLevelUri);
                cmd.AddCommandResult("bitrix:news@" + executionVirtualPath, new BXCommandResult(BXCommandResultType.Ok, menuResult));
            }


        }
    }
Пример #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region InitializeStartup
        SectionId = Parameters.Get("SectionId", 0);

        bool COUNT_ELEMENTS = Parameters.Get<bool>("COUNT_ELEMENTS", false);
        string SortByWhat = Parameters.Get<string>("SortBy", "sort");
        string OrderByWhat = Parameters.Get<string>("OrderBy", "asc");
        #endregion

        BXParamsBag<object> request = new BXParamsBag<object>();

        if (EnableSef)
        {
            BXParamsBag<string> urlToPage = new BXParamsBag<string>();
            urlToPage.Add("Catalog.List0", SectionURL);
            urlToPage.Add("Catalog.List1", SectionPageURL);

            MapVariable(SEFFolder, urlToPage, request);

            Results["ParamSectionId"] = ParamSectionId;
            Results["ParamSectionCode"] = ParamSectionCode;
        }
        else
        {
            BXParamsBag<string> variableAlias = new BXParamsBag<string>();
            variableAlias[ParamSectionId] = AliasSectionId;
            variableAlias[ParamSectionCode] = AliasSectionCode;

            MapVariable(variableAlias, request);

            Results["ParamSectionId"] = AliasSectionId;
            Results["ParamSectionCode"] = AliasSectionCode;
        }

        //IBlockId = request.Get("iblock_id", IBlockId);
        SectionId = request.Get(ParamSectionId, SectionId);
        SectionCode = request.Get<string>(ParamSectionCode, SectionCode);

        // Rewrite default variables
        request.Add(ParamSectionId, SectionId);
        request.Add(ParamSectionCode, SectionCode);        

        Results["SectionURL"] = SectionURL;

        Results["SectionId"] = SectionId;
        Results["SectionCode"] = SectionCode;

        if (EnableSef)
            Results["CatalogRoot"] = BXPath.ToVirtualAbsolutePath(SEFFolder);
        else
            Results["CatalogRoot"] = Parameters.Get<string>("CatalogRoot", BXSefUrlManager.CurrentUrl.AbsolutePath);

        if (!IsCached(IBlockId, SectionId, SectionCode))
        {
            if (IBlockId > 0)
            {
                List<Dictionary<string, string>> sList = new List<Dictionary<string, string>>();
                                        
                int i = 0, baseDepth = 0;
                BXIBlockSectionCollection sections = null;


                if (SectionId <= 0 && String.IsNullOrEmpty(SectionCode))
                {
                    sections = BXIBlockSection.GetTree(IBlockId, Depth + 1);
                }
                else
                {
                    #region SectionList
                    BXOrderBy sOrder = new BXOrderBy();
					sOrder.Add(BXIBlockSection.Fields, String.Format("{0} {1}", SortByWhat, OrderByWhat));
					//sOrder.Add(BXIBlockSection.Fields, String.Format("{0} {1}", "id", "asc"));
                    BXIBlockSection parentSection = null;

                    if (String.IsNullOrEmpty(SectionCode))
                    {
                        if (SectionId > 0)
                            parentSection = BXIBlockSection.GetById(SectionId);
                    }
                    else
                    {
                        BXFilter sParentFilter = new BXFilter(
							new BXFilterItem(BXIBlockSection.Fields.Code, BXSqlFilterOperators.Equal, SectionCode),
							new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y")
                            );

                        BXIBlockSectionCollection sCol = BXIBlockSection.GetList(sParentFilter, null);
                        if (sCol != null && sCol.Count > 0)
                            parentSection = sCol[0];
                    }

                    BXFilter sFilter = new BXFilter(
							new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId),
							new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y")
                        );

                    if (parentSection != null)
                    {
                        ParentSectionId = parentSection.Id;                        
                        baseDepth = parentSection.DepthLevel;

						sFilter.Add(new BXFilterItem(BXIBlockSection.Fields.LeftMargin, BXSqlFilterOperators.GreaterOrEqual, parentSection.LeftMargin));
						sFilter.Add(new BXFilterItem(BXIBlockSection.Fields.RightMargin, BXSqlFilterOperators.Less, parentSection.RightMargin));
						sFilter.Add(new BXFilterItem(BXIBlockSection.Fields.DepthLevel, BXSqlFilterOperators.LessOrEqual, parentSection.DepthLevel + Depth));

                        sections = BXIBlockSection.GetList(sFilter, sOrder);
                    }
                    #endregion
                    #region NavChain
                    BXIBlockSectionCollection navChain = null;

                    if (SectionId > 0)
                    {
                        navChain = BXIBlockSection.GetNavChain(SectionId);
                    }
                    else if (ParentSectionId > 0)
                    {
                        navChain = BXIBlockSection.GetNavChain(ParentSectionId);                        
                    }

                    Results["NavChain"] = navChain;
                    SetupNavchain(navChain, request);  
                    #endregion
                }
                Results["DataVolume"] = (sections != null) ? sections.Count : 0;
				if (sections != null)
				{
					string str = String.Empty;
					if (EnableSef)
						str = String.Concat(SEFFolder, "/", SectionURL);
					else
						str = SectionURL;

					foreach (BXIBlockSection s in sections)
					{
						Dictionary<string, string> v = new Dictionary<string, string>();
						if (s.DepthLevel == 1)
						{
							i++;
							v.Add("I", (i < 10) ? "0" + i : i.ToString());
						}
						v.Add("SectionId", s.Id.ToString());
						v.Add("Depth", (s.DepthLevel - baseDepth).ToString());
						v.Add("Name", s.Name);
						if (COUNT_ELEMENTS)
							v.Add("ElementsCount", s.ElementsCount.ToString());
						if (!String.IsNullOrEmpty(SectionURL))
						{
							request["iblock_id"] = s.IBlockId;
							request["section_id"] = s.Id;
							request["section_code"] = String.IsNullOrEmpty(s.Code) ? String.Empty : s.Code;
							v.Add("Path", BXUri.ToRelativeUri(MakeLink(str, request)));
						}
						sList.Add(v);
					}
				}

                Results["Section"] = sList;

                Results["EnableAjaxA"] = Parameters.Get<bool>("EnableAjax", false)?
                    "EnableAjax=\"True\"": "";
            }

            IncludeComponentTemplate();
        }
        else
        {
             // 1. NavChain
            if (Results.ContainsKey("NavChain")) SetupNavchain((BXIBlockSectionCollection)Results["NavChain"], request);
        }
	}
Пример #10
0
        public override void ProcessMessage(BXCommand cmd, bool executionContext, string executionVirtualPath)
        {
            if (cmd.Action == "Bitrix.Main.GeneratePublicMenu")
            {
                //Совпадает ли тип меню в параметрах компонента с типом, который запрашивает система.
                if (!Parameters.Get("GenerateMenuType", "left").Equals(cmd.Parameters.Get<string>("menuType"), StringComparison.InvariantCultureIgnoreCase))
                    return;

                //Генерируем меню только для тех адресов, которые выводит сам компонент.
                if (!EnableSef && !BXSiteRemapUtility.UnmapVirtualPath(executionVirtualPath).Equals(cmd.Parameters.Get<string>("uriPath"), StringComparison.InvariantCultureIgnoreCase))
                    return;
                else if (EnableSef && !cmd.Parameters.Get<string>("uriPath").StartsWith(Bitrix.IO.BXPath.ToVirtualRelativePath(SefFolder.TrimStart('\\', '/')) + "/", StringComparison.InvariantCultureIgnoreCase))
                    return;

                if (IBlockId < 0)
                    return;

                BXParamsBag<object> request = new BXParamsBag<object>();
                if (EnableSef)
                {
                    BXParamsBag<string> urlToPage = new BXParamsBag<string>();
                    urlToPage["index.page"] = CommonListPageTemplate;
                    urlToPage["index.all"] = CommonListShowAllTemplate;
                    urlToPage["list"] = ElementListTemplate;
                    urlToPage["list.page"] = SectionListPageTemplate;
                    urlToPage["list.all"] = SectionListShowAllTemplate;
                    urlToPage["detail"] = ElementDetailTemplate;

                    MapVariable(SefFolder, urlToPage, request, "index", BXUri.ToRelativeUri(cmd.Parameters.Get<string>("uri")));
                }
                else
                {
                    BXParamsBag<string> variableAlias = new BXParamsBag<string>();
                    variableAlias["SectionId"] = SectionIdVariable;
                    variableAlias["ElementId"] = ElementIdVariable;
                    variableAlias["PageId"] = PageIdVariable;
                    variableAlias["ShowAll"] = ShowAllVariable;

                    MapVariable(variableAlias, request, BXUri.ToRelativeUri(cmd.Parameters.Get<string>("uri")));
                }

                #region Menu Item Permission
                string permissionCacheKey = "mediaGallery-" + IBlockId.ToString() + "-menu-permission";
                if ((menuItemPermisson = (string)BXCacheManager.MemoryCache.Get(permissionCacheKey)) == null)
                {
                    menuItemPermisson = string.Empty;
                    StringBuilder menuItemRoles = new StringBuilder();

                    BXRoleCollection iblockRoles = BXRoleManager.GetAllRolesForOperation("IBlockRead", "iblock", IBlockId.ToString());
                    foreach (BXRole role in iblockRoles)
                    {
                        //Если доступно всем
                        if (role.RoleName == "Guest")
                        {
                            menuItemRoles = null;
                            break;
                        }
                        //Если доступно группе User, значит достаточно проверить только для этой группы
                        else if (role.RoleName == "User")
                        {
                            menuItemRoles = null;
                            menuItemPermisson = "User";
                            break;
                        }
                        else
                        {
                            menuItemRoles.Append(role.RoleName);
                            menuItemRoles.Append(";");
                        }
                    }

                    if (menuItemRoles != null && menuItemRoles.Length > 0)
                        menuItemPermisson = menuItemRoles.ToString();

                    BXCacheManager.MemoryCache.Insert(permissionCacheKey, menuItemPermisson);
                }
                #endregion

                int elementId = 0, sectionId = 0;
                string elementCode = String.Empty, sectionCode = String.Empty;

                elementId = request.Get<int>("ElementId", elementId);
                sectionId = request.Get<int>("SectionId", sectionId);
                elementCode = request.Get<string>("ElementCode", elementCode);
                sectionCode = request.Get<string>("SectionCode", sectionCode);

                string parentLevelUri = null;
                List<BXPublicMenuItem> menuList = null;

                //Указан идентификатор или символьный код
                if (elementId > 0 || !String.IsNullOrEmpty(elementCode))
                {
                    BXFilter elementFilter = new BXFilter(
                        new BXFilterItem(BXIBlockElement.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId),
                        new BXFilterItem(BXIBlockElement.Fields.Active, BXSqlFilterOperators.Equal, "Y")
                    );

                    if (elementId > 0)
                        elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.ID, BXSqlFilterOperators.Equal, elementId));
                    if (!String.IsNullOrEmpty(elementCode))
                        elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.Code, BXSqlFilterOperators.Equal, elementCode));
                    if (sectionId > 0)
                        elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.Sections.Section.SectionId, BXSqlFilterOperators.Equal, sectionId));
                    if (!String.IsNullOrEmpty(sectionCode))
                        elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.Sections.Section.Code, BXSqlFilterOperators.Equal, sectionCode));

                    BXIBlockElementCollection element = BXIBlockElement.GetList(elementFilter, null);
                    if (element != null && element.Count > 0)
                    {
                        BXIBlockElement.BXInfoBlockElementSectionCollection sections = element[0].Sections;
                        if (sections != null && sections.Count > 0)
                        {
                            BXParamsBag<object> replaceItems = new BXParamsBag<object>();
                            replaceItems["SectionId"] = sections[0].SectionId;
                            replaceItems["SectionCode"] = GetSectionCode(sections[0].SectionId);

                            parentLevelUri = MakeMenuUriForElementList(executionVirtualPath, replaceItems); //Меню строится для раздела, к которому привязан элемент
                        }
                    }
                }

                //Если ничего не указано выводим все дерево
                Dictionary<string, BXPublicMenu.BXLoadMenuCommandParameter> menuTree = new Dictionary<string, BXPublicMenu.BXLoadMenuCommandParameter>();
                if (parentLevelUri == null && menuList == null)
                {
                    BXIBlockSectionCollection sectionsList = BXIBlockSection.GetList(
                        new BXFilter(
                            new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
                            new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
                            new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId)
                        ),
                        new BXOrderBy(
                            new BXOrderByPair(BXIBlockSection.Fields.LeftMargin, BXOrderByDirection.Asc)
                        )
                    );

                    int previousDepthLevel = 1;
                    int previousSectionId = 0;
                    Dictionary<int, MenuSectionTree> sectionTree = new Dictionary<int, MenuSectionTree>();
                    foreach (BXIBlockSection section in sectionsList)
                    {
                        BXParamsBag<object> replaceItems = new BXParamsBag<object>();
                        replaceItems["SectionId"] = section.Id;
                        replaceItems["SectionCode"] = section.Code ?? String.Empty;

                        sectionTree[section.Id] = new MenuSectionTree();
                        string url = MakeMenuUriForElementList(executionVirtualPath, replaceItems);
                        sectionTree[section.Id].url = url;
                        sectionTree[section.Id].sectionId = section.SectionId;

                        //Если предыдущий раздел не имеет вложенных (дочерних) разделов, то для него дополнительно указывается URL на родительскую секцию (и эл-ты меню для данной секции будут запрошены из этой родительской)
                        if (previousSectionId > 0 && section.DepthLevel <= previousDepthLevel)
                            sectionTree[previousSectionId].parentLevelUrl = sectionTree[sectionTree[previousSectionId].sectionId].url;
                        previousDepthLevel = section.DepthLevel;
                        previousSectionId = section.Id;

                        BXPublicMenuItem menuItem = new BXPublicMenuItem();
                        menuItem.Title = section.Name;
                        menuItem.Links.Add(url);
                        menuItem.Sort = section.LeftMargin;

                        if (!String.IsNullOrEmpty(menuItemPermisson))
                        {
                            menuItem.ConditionType = ConditionType.Group;
                            menuItem.Condition = menuItemPermisson;
                        }

                        if (!sectionTree.ContainsKey(section.SectionId))
                        {
                            sectionTree[section.SectionId] = new MenuSectionTree();
                            sectionTree[section.SectionId].menuItems = new List<BXPublicMenuItem>();

                            if (section.SectionId < 1)
                                sectionTree[section.SectionId].url = EnableSef ? SefFolder : BXUri.ToAppRelativeUri(executionVirtualPath);
                        }

                        if (sectionTree[section.SectionId].menuItems == null)
                            sectionTree[section.SectionId].menuItems = new List<BXPublicMenuItem>();

                        sectionTree[section.SectionId].menuItems.Add(menuItem);
                    }

                    //Последний раздел точно не имеет вложенных (дочерних) разделов, для него обязательно указывается URL на родительскую секцию (и эл-ты меню для данной секции будут запрошены из этой родительской)
                    if (sectionTree.ContainsKey(previousSectionId) && sectionTree.ContainsKey(sectionTree[previousSectionId].sectionId))
                        sectionTree[previousSectionId].parentLevelUrl = sectionTree[sectionTree[previousSectionId].sectionId].url;

                    foreach (KeyValuePair<int, MenuSectionTree> sectionItem in sectionTree)
                        menuTree.Add(
                            sectionItem.Value.url,
                            new BXPublicMenu.BXLoadMenuCommandParameter(sectionItem.Value.menuItems, true, sectionItem.Value.parentLevelUrl)
                        );
                }

                if (menuTree.Count > 0)
                    cmd.AddCommandResult("bitrix:mediaGallery@" + executionVirtualPath, new BXCommandResult(BXCommandResultType.Ok, menuTree));
                else if (menuList != null || parentLevelUri != null)
                {
                    BXPublicMenu.BXLoadMenuCommandParameter menuResult = new BXPublicMenu.BXLoadMenuCommandParameter(menuList, true, parentLevelUri);
                    cmd.AddCommandResult("bitrix:mediaGallery@" + executionVirtualPath, new BXCommandResult(BXCommandResultType.Ok, menuResult));
                }
            }
        }
Пример #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region SetupParameters
        SectionId = Parameters.Get("SectionId", 0);

        ShowSubelements = Parameters.Get("ShowSubelements", true);

        SortBy1 = Parameters.Get("SortBy1", "sort");
        SortOrder1 = Parameters.Get("SortOrder1", "Desc");

        PerPageCount = Parameters.Get("PerPageCount", 30);
        PerLineCount = Parameters.Get("PerLineCount", 3);
        Properties = Parameters.GetListString("Properties");

        string PropertyKeywords = Parameters.Get("PropertyKeywords", "-");
        string PropertyDescription = Parameters.Get("PropertyDescription", "-");
        bool AddAdminPanelButtons = Parameters.Get("AddAdminPanelButtons", false);
        bool ShowCompareButton = Parameters.Get("ShowCompareButton", false);
        bool SetPageTitle = Parameters.Get("SetPageTitle", true);
        bool CacheOnFilter = Parameters.Get("CacheOnFilter", false);

		Parameters["PagingAllowAll"] = false.ToString();
        /*bool PagerOverList = Parameters.GetBool("PagerOverList", false);
        bool PagerUnderList = Parameters.GetBool("PagerUnderList", false);
        string CategoryTitle = Parameters.GetString("CategoryTitle", "");
        bool PagerAlways = Parameters.GetBool("PagerAlways", true);
        string TemplateTitle = Parameters.GetString("TemplateTitle", "");
        bool UseInvertedNavigation = Parameters.GetBool("UseInvertedNavigation", false);
        int CacheTimeOnInvertedNavigation = Parameters.GetInt("CacheTimeOnInvertedNavigation", 36000);*/
        #endregion
        
        #region HackUnSef
        string PageKey = String.Empty;

        BXParamsBag<object> request = new BXParamsBag<object>();
        BXParamsBag<string> urlToPage = new BXParamsBag<string>();
        urlToPage.Add("SectionPage", SectionPageURL);
        urlToPage.Add("Section", SectionURL);
        
        if (EnableSef)
        {
            PageKey = MapVariable(SEFFolder, urlToPage, request, String.Empty);

            Results["ParamSectionId"] = ParamSectionId;
            Results["ParamElementId"] = ParamElementId;
            Results["ParamPageId"] = ParamPageId;
            Results["ParamElementCode"] = ParamElementCode;
            Results["ParamSectionCode"] = ParamSectionCode;
        }
        else
        {
            BXParamsBag<string> variableAliases = new BXParamsBag<string>();
			variableAliases.Add(ParamSectionId, AliasSectionId);
			variableAliases.Add(ParamElementId, AliasElementId);
			variableAliases.Add(ParamPageId, AliasPageId);
			variableAliases.Add(ParamSectionCode, AliasSectionCode);
			variableAliases.Add(ParamElementCode, AliasElementCode);
            MapVariable(variableAliases, request);

            Results["ParamSectionId"] = AliasSectionId;
            Results["ParamElementId"] = AliasElementId;
            Results["ParamPageId"] = AliasPageId;
            Results["ParamElementCode"] = AliasElementCode;
            Results["ParamSectionCode"] = AliasSectionCode;
        }

        SectionId = request.Get(ParamSectionId, SectionId);
        //ElementId = request.Get(ParamElementId, ElementId);
        PageId = request.Get(ParamPageId, PageId);
        ElementCode = request.Get<string>(ParamElementCode, ElementCode);
        SectionCode = request.Get<string>(ParamSectionCode, SectionCode);

        // Rewrite default variables
        request.Add(ParamSectionId, SectionId);
        //request.Add(ParamElementId, ElementId);
        request.Add(ParamElementCode, ElementCode);
        request.Add(ParamSectionCode, SectionCode);

        if (!EnableSef)
        {
            if (PageId > 0) PageKey = "SectionPage";
            //else if (ElementId > 0 || !String.IsNullOrEmpty(ElementCode)) PageKey = "Element";
            else if (SectionId > 0 || !String.IsNullOrEmpty(SectionCode)) PageKey = "Section";
        }

        Results["SectionURL"] = SectionURL;
        Results["SectionPageURL"] = SectionPageURL;
        Results["ElementURL"] = ElementURL;

        Results["SectionId"] = SectionId;
        //Results["ElementId"] = ElementId;
        Results["PageId"] = PageId;
        Results["ElementCode"] = ElementCode;
        Results["SectionCode"] = SectionCode;

        Results["PageKey"] = PageKey;
        #endregion

        if (!IsCached(IBlockTypeId, IBlockId, SectionId, PageId, SectionCode))
        {
			if (IBlockId > 0)
			{
				#region MakeComponentDataFilter
				BXIBlockElementCollection es = null;

				BXFilter esf = new BXFilter();
				BXOrderBy eso = new BXOrderBy();

				esf.Add(new BXFilterItem(BXIBlockElement.Fields.Active, BXSqlFilterOperators.Equal, "Y"));

				eso.Add(BXIBlockElement.Fields, String.Format("{0} {1}", SortBy1, SortOrder1));

				if (IBlockId > 0)
				{
					esf.Add(new BXFilterItem(BXIBlockElement.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId));
				}
				if (!String.IsNullOrEmpty(SectionCode))
				{
					esf.Add(new BXFilterItem(BXIBlockElement.Fields.Sections.Section.Code, BXSqlFilterOperators.Equal, SectionCode));
					if (ShowSubelements)
					{
						esf.Add(new BXFilterItem(BXIBlockElement.Fields.IncludeParentSections, BXSqlFilterOperators.Equal, "Y"));
					}
				}
				else if (SectionId > 0)
				{
					esf.Add(new BXFilterItem(BXIBlockElement.Fields.Sections.Section.ID, BXSqlFilterOperators.Equal, SectionId));
					if (ShowSubelements)
					{
						esf.Add(new BXFilterItem(BXIBlockElement.Fields.IncludeParentSections, BXSqlFilterOperators.Equal, "Y"));
					}
				}
				else
				{
					if (ShowSubelements)
					{
						esf.Add(new BXFilterItem(BXIBlockElement.Fields.IncludeParentSections, BXSqlFilterOperators.Equal, "Y"));
					}
					else
						esf.Add(new BXFilterItem(BXIBlockElement.Fields.Sections.Section.ID, BXSqlFilterOperators.Equal, "0"));
				}
				#endregion

				#region Paging Operations
				string PageUrlTemplate = String.Empty;
				string DefaultPageUrl = String.Empty;
				if (EnableSef)
				{
					DefaultPageUrl = BXComponentManager.MakeLink(SEFFolder, SectionURL);
					PageUrlTemplate = BXComponentManager.MakeLink(SEFFolder, SectionPageURL);
				}
				else
				{
					DefaultPageUrl = SectionURL;
					PageUrlTemplate = SectionPageURL;
				}

				BXQueryParams queryParams = PreparePaging(
					delegate
					{
						return BXIBlockElement.Count(esf);
					},
					request,
					Results.Get<string>("ParamPageId"),
					false,
					DefaultPageUrl,
					PageUrlTemplate,
					string.Empty
				);
				es = BXIBlockElement.GetList(esf, eso, null, queryParams);

				#endregion

				#region SetPageTitle
				if (SetPageTitle)
				{
					string PageTitle = Parameters.Get<string>("SectionTitle", String.Empty);
					if (String.IsNullOrEmpty(PageTitle))
					{
						BXIBlockSection rootSection = null;
						if (!String.IsNullOrEmpty(SectionCode))
						{
							BXFilter sParentFilter = new BXFilter(
									new BXFilterItem(BXIBlockSection.Fields.Code, BXSqlFilterOperators.Equal, SectionCode),
									new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y")
									);

							BXIBlockSectionCollection sCol = BXIBlockSection.GetList(sParentFilter, null);
							if (sCol != null && sCol.Count > 0)
								rootSection = sCol[0];
						}
						else if (SectionId > 0)
							rootSection = BXIBlockSection.GetById(SectionId);

						if (rootSection != null)
							PageTitle = rootSection.Name;
						else
						{
							BXIBlock iblock = BXIBlock.GetById(IBlockId);
							if (iblock != null)
								PageTitle = iblock.Name;
						}
					}

					Results["SectionName"] = PageTitle;
				}
				#endregion

				if (es != null)
				{
					Results["DataVolume"] = es.Count;
				}

				if (es != null && es.Count > 0)
				{
					List<Dictionary<string, string>> data = new List<Dictionary<string, string>>();
					foreach (BXIBlockElement el in es)
					{
						Dictionary<string, string> v = new Dictionary<string, string>();

						string imageUrl = String.Empty;
						BXFile image = el.DetailImageId > 0 ? el.DetailImage : el.PreviewImage;

						if (image != null)
							imageUrl = String.Format(
							"{0}ImageResizer.ashx?path={1}&width={2}&height={3}&fit={4}",
							BXUri.ToAbsoluteUri("~/bitrix/handlers/Main/"),
							UrlEncode(image.FileVirtualPath),
							Parameters.Get("PreviewWidth", 150),
							Parameters.Get("PreviewHeight", 150),
							!Parameters.Get<bool>("FlickrMode", false));

						v.Add("Id", el.Id.ToString());
						v.Add("Title", el.Name);
						v.Add("PreviewText", el.PreviewText);
						v.Add("PreviewTextType", el.PreviewTextType.ToString());
						v.Add("PreviewImage", imageUrl);

						request.Add(ParamElementId, el.Id);
						request.Add(ParamElementCode, String.IsNullOrEmpty(el.Code) ? String.Empty : el.Code);
						if (EnableSef)
							v.Add("ElementLink", BXStringUtility.HtmlEncodeEx(MakeLink(SEFFolder, ElementURL, request)));
						else
							v.Add("ElementLink", BXStringUtility.HtmlEncodeEx(MakeLink(ElementURL, request)));

						data.Add(v);

						Dictionary<string, BXCustomProperty> v2 = new Dictionary<string, BXCustomProperty>();
						BXCustomPropertyCollection props = el.Properties;
						if (props != null)
							foreach (KeyValuePair<string, BXCustomProperty> kcs in props)
								if (Properties.Exists(delegate(string x)
								{
									return x.Equals(kcs.Key, StringComparison.InvariantCultureIgnoreCase);
								}))
									v2[kcs.Key] = kcs.Value;

						Results["DataProperties_" + el.Id] = v2;
					}

					Results["Data"] = data;
				}

				Results["EnableAjaxA"] = Parameters.Get<bool>("EnableAjax", false) ? "EnableAjax=\"True\"" : "";
			}
			IncludeComponentTemplate();
        }

		if (SetPageTitle && Results.ContainsKey("SectionName") && Results["SectionName"] != null)
		{
			string PageTitle = Results.Get<string>("SectionName");

			if (Page is BXPublicPage)
				(Page as BXPublicPage).BXTitle = PageTitle;
		}
	}
Пример #12
0
	public override bool ProcessCommand(string commandName, BXParamsBag<object> commandParameters, List<string> commandErrors)
	{
		string url;
		if ( commandName.Equals("delete",StringComparison.OrdinalIgnoreCase)){
			int delAlbumId = commandParameters.GetInt("AlbumId", AlbumId);


			int parentAlbumId = 0;
			try
			{
				parentAlbumId = BXIBlockSection.GetById(delAlbumId).SectionId;
				BXIBlockSection.Delete(delAlbumId);
			}
			catch (Exception ex)
			{
				errorMessage = GetMessage("Error.FailedToDeleteAlbum");
			}

			if (EnableSef)
			{
				if (parentAlbumId > 0)
				{
					Results["AlbumId"] = parentAlbumId;
					url = MakeLink(Parameters.Get<string>("SefFolder"), Parameters.Get<string>("Sef_Album"), Results);
				}
				else
				{
					url = MakeLink(Parameters.Get<string>("SefFolder"), string.Empty, Results);
				}
			}
			else
			{
				if (parentAlbumId > 0)
				{
					url = string.Format("{0}?{1}={2}",
										Request.Path,
										Parameters.Get<string>("ParamAlbum", "Album"),
										parentAlbumId);
				}
				else
				{
					url = Request.Path;
				}
			}
			if (errorMessage == String.Empty)
			{
				if (Parameters.Get("EnableAjax", false) && !IsComponentDesignMode)
				{
					string script = string.Format("setTimeout(\"PageTransfer('{0}');\",1);",
												  url);
					ScriptManager.RegisterStartupScript(Page, typeof(Page), "AJAX_BUTTON_CLICK", script, true);
				}
				else
					Response.Redirect(url);
				return true;
			}


		}
		else if (commandName.Equals("deletephotos", StringComparison.OrdinalIgnoreCase))
		{
			var photos = commandParameters.Get<List<int>>("photoIds", new List<int>());

			foreach (var id in photos)
			{
				BXIBlockElement photo = null;
				try
				{
					photo = BXIBlockElement.GetById(id);
					if (photo != null)
						photo.Delete();
				}
				catch (Exception ex2)
				{
					commandErrors.Add(GetMessage("UnableToDeletePhoto") + (photo != null ? " " + photo.Name : ""));
				}

			}
			if (BXModuleManager.IsModuleInstalled("forum") && EnableComments)// have to delete comments for all photos
			{
				var c = new IncludeComponent("bitrix:forum.comment.block", "blog_comments");
				c.Attributes["ForumId"] = Component.Parameters.GetString("CommentForumId", "0");
				c.Attributes["IdentityPropertyName"] = Component.Parameters.GetString("CommentStoragePropertyName");
				c.Attributes["IdentityPropertyValue"] = photos[0].ToString();//required by design
				c.Attributes["PostOperation"] = "DeleteCommentsForEntityList";
				c.Attributes["EntityList"] = BXStringUtility.ListToCsv(photos.ConvertAll(x => x.ToString()));
				CommentsDeletePlaceHolder.Controls.Add(c);
			}
			if (EnableSef)
			{

					if (AlbumId > 0)
					{
						Results["AlbumId"] = AlbumId;
						url = MakeLink(Parameters.Get<string>("SefFolder"), Parameters.Get<string>("Sef_Album"), Results);
					}
					else
					{
						url = MakeLink(Parameters.Get<string>("SefFolder"), string.Empty, Results);
					}
			}
			else
			{
						NameValueCollection pars = HttpUtility.ParseQueryString(Request.Url.Query);
						pars.Remove("target");
						pars.Remove("ValidationToken");
						pars.Remove("del");
						url = string.Format("{0}?{1}",
													Request.Path,
													pars.ToString());
			}
			
			Response.Redirect(url);
		}
		
		return false;

	}
Пример #13
0
		private void ParseVariableAliases(BXParamsBag<object> result)
		{
			string[,] variableAlias = {
					{"SectionId", "SECTION_ID"},
					{"SectionCode", "SECTION_CODE"},
					{"ElementId", "ELEMENT_ID"},
					{"ElementCode", "ELEMENT_CODE"},
					{"IblockId", "IBLOCK_ID"}
				};

			for (int i = 0, length = variableAlias.GetLength(0); i < length; i++)
				if (result.ContainsKey(variableAlias[i, 1]))
					result[variableAlias[i, 0]] = result.Get<string>(variableAlias[i, 1], String.Empty);
		}
Пример #14
0
		public override void ProcessMessage(BXCommand cmd, bool executionContext, string executionVirtualPath)
		{
			#region Search
			if (cmd.Action == "Bitrix.Search.ProvideUrl")
			{
                string moduleId = cmd.Parameters.Get("moduleId", string.Empty);
                if (string.Equals(moduleId, "forum", StringComparison.OrdinalIgnoreCase)
                    && AboutCommentsShow()
                    && BXModuleManager.IsModuleInstalled("Forum"))
                {
                    //Поиск по комментариям к эл-там каталога
                    int blockId = IBlockId;
                    int forumId = cmd.Parameters.GetInt("itemGroup", 0);
                    int postId = cmd.Parameters.GetInt("itemId", 0);
                    int topicId = cmd.Parameters.GetInt("param1");


                    if (blockId == 0 || !string.Equals(moduleId, "forum", StringComparison.OrdinalIgnoreCase) || forumId <= 0 || postId <= 0)
                        return;

                    BXSchemeFieldBase commentCpField =  BXIBlockElement.Fields.CustomFields[blockId].GetFieldByKey(CommentCustomPropertyName);
                    if (commentCpField == null)
                        return;

                    BXFilter f = new BXFilter(
                            new BXFilterItem(BXIBlockElement.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
                            new BXFilterItem(BXIBlockElement.Fields.ActiveDate, BXSqlFilterOperators.Equal, "Y"),
                            new BXFilterItem(BXIBlockElement.Fields.IBlock.ID, BXSqlFilterOperators.Equal, blockId),
                            new BXFilterItem(commentCpField, BXSqlFilterOperators.Equal, topicId)
                            );

                    string siteId = DesignerSite;
                    if (!string.IsNullOrEmpty(siteId))
                        f.Add(new BXFilterItem(BXIBlockElement.Fields.IBlock.Sites.SiteId, BXSqlFilterOperators.Equal, siteId));

                    BXIBlockElementCollection c = BXIBlockElement.GetList(f, null);
                    if (c.Count == 0)
                        return;

                    BXIBlockElement el = c[0];
                    //формируем постоянную ссылку на комментарий
                    string commentUrl = string.Empty;
                    if (!EnableSef)
                        commentUrl = string.Format("{0}?{1}={2}&{3}={4}#comment{4}", BXSite.GetUrlForPath(executionVirtualPath, null), ElementIdVariable, el.Id.ToString(), CommentVariable, postId.ToString());
                    else
                    {
                        BXParamsBag<object> commentSefParams = new BXParamsBag<object>();
                        commentSefParams["SectionId"] = string.Empty;
                        commentSefParams["ElementId"] = el.Id.ToString();
                        commentSefParams["CommentId"] = postId.ToString();
                        string t = ElementDetailCommentReadTemplate;
                        if (t.IndexOf("##") < 0)
                            t = string.Concat(t, "##comment#CommentId#");
                        commentUrl = BXSefUrlUtility.MakeLink(CombineLink(SefFolder, t), commentSefParams).Replace("//", "/");
                    }
                    cmd.AddCommandResult(string.Concat("bitrix:forum@", executionVirtualPath), new BXCommandResult(BXCommandResultType.Ok, commentUrl));
                    return;
                }

				if (cmd.Parameters.Get<string>("moduleId") != "iblock")
					return;

				if (IBlockId < 0 || cmd.Parameters.Get<int>("itemGroup") != IBlockId)
					return;

				int elementId = cmd.Parameters.Get("itemId", -1);
				if (elementId < 0)
					return;

				BXFilter elementFilter = new BXFilter(
					new BXFilterItem(BXIBlockElement.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
					new BXFilterItem(BXIBlockElement.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId),
					new BXFilterItem(BXIBlockElement.Fields.ID, BXSqlFilterOperators.Equal, elementId)
				);

				BXIBlockElementCollection element = BXIBlockElement.GetList(elementFilter, null);
				if (element != null && element.Count < 1)
					return;

				BXIBlockElement iblockElement = element[0];
				int replaceSectionId = 0;
				if (iblockElement.Sections.Count != 0)
					replaceSectionId = iblockElement.Sections[0].SectionId;

				string url;
				if (EnableSef)
				{
					string replaceSectionCode = String.Empty;
					if (ElementDetailTemplate.Contains("#SECTION_CODE#") || ElementDetailTemplate.Contains("#SectionCode#"))
					{
						BXIBlockSection elementSection = BXIBlockSection.GetById(replaceSectionId);
						if (elementSection != null)
							replaceSectionCode = elementSection.Code;
					}

					BXParamsBag<object> replaceItems = new BXParamsBag<object>();
					replaceItems.Add("IblockId", iblockElement.IBlockId);
					replaceItems.Add("IBLOCK_ID", iblockElement.IBlockId);
					replaceItems.Add("ELEMENT_ID", iblockElement.Id);
					replaceItems.Add("ElementId", iblockElement.Id);
					replaceItems.Add("ElementCode", iblockElement.Code);
					replaceItems.Add("ELEMENT_CODE", iblockElement.Code);
					replaceItems.Add("SectionId", replaceSectionId);
					replaceItems.Add("SECTION_ID", replaceSectionId);
					replaceItems.Add("SectionCode", replaceSectionCode);
					replaceItems.Add("SECTION_CODE", replaceSectionCode);

					//url = MakeLink(SefFolder, ElementDetailTemplate, replaceItems);
					url = CombineLink(SefFolder, BXSefUrlUtility.MakeLink(ElementDetailTemplate, replaceItems));
				}
				else
				{
					url = String.Format("{0}?{1}={2}&{3}={4}", BXSite.GetUrlForPath(executionVirtualPath, null), SectionIdVariable, replaceSectionId, ElementIdVariable, elementId);
				}

				cmd.AddCommandResult("bitrix:catalogue@" + executionVirtualPath, new BXCommandResult(BXCommandResultType.Ok, url));
			}
			#endregion

			if (cmd.Action == "Bitrix.Main.GeneratePublicMenu")
			{
				//return;
				//Совпадает ли тип меню в параметрах компонента с типом, который запрашивает система.
				if (!Parameters.Get("GenerateMenuType", "left").Equals(cmd.Parameters.Get<string>("menuType"), StringComparison.InvariantCultureIgnoreCase))
					return;

				//Генерируем меню только для тех адресов, которые выводит сам компонент.
				if (!EnableSef && !BXSiteRemapUtility.UnmapVirtualPath(executionVirtualPath).Equals(cmd.Parameters.Get<string>("uriPath"), StringComparison.InvariantCultureIgnoreCase))
					return;
				else if (EnableSef && !cmd.Parameters.Get<string>("uriPath").StartsWith(Bitrix.IO.BXPath.ToVirtualRelativePath(SefFolder.TrimStart('\\', '/')) + "/", StringComparison.InvariantCultureIgnoreCase))
					return;

				if (IBlockId < 0)
					return;

				BXParamsBag<object> request = new BXParamsBag<object>();
				if (EnableSef)
				{
					BXParamsBag<string> urlToPage = new BXParamsBag<string>();
					urlToPage["index.page"] = CommonListPageTemplate;
					urlToPage["index.all"] = CommonListShowAllTemplate;
					urlToPage["list"] = ElementListTemplate;
					urlToPage["list.page"] = SectionListPageTemplate;
					urlToPage["list.all"] = SectionListShowAllTemplate;
					urlToPage["detail"] = ElementDetailTemplate;

					//MapVariable(SefFolder, urlToPage, request, "index", BXUri.ToRelativeUri(cmd.Parameters.Get<string>("uri")));
					Uri url = new Uri(BXUri.ToAbsoluteUri(cmd.Parameters.Get<string>("uri")));
					BXSefUrlUtility.MapVariable(SefFolder, urlToPage, request, "index", url, null);

					ParseVariableAliases(request);
				}
				else
				{
					BXParamsBag<string> variableAlias = new BXParamsBag<string>();
					variableAlias["SectionId"] = SectionIdVariable;
					variableAlias["ElementId"] = ElementIdVariable;
					variableAlias["PageId"] = PageIdVariable;
					variableAlias["ShowAll"] = ShowAllVariable;

					MapVariable(variableAlias, request, BXUri.ToRelativeUri(cmd.Parameters.Get<string>("uri")));
				}

				#region Menu Item Permission
				string permissionCacheKey = "catalogue-" + IBlockId.ToString() + "-menu-permission";
				if ((menuItemPermisson = (string)BXCacheManager.MemoryCache.Get(permissionCacheKey)) == null)
				{
					menuItemPermisson = String.Empty;
					StringBuilder menuItemRoles = new StringBuilder();

					BXRoleCollection iblockRoles = BXRoleManager.GetAllRolesForOperation("IBlockRead", "iblock", IBlockId.ToString());
					foreach (BXRole role in iblockRoles)
					{
						//Если доступно всем
						if (role.RoleName == "Guest")
						{
							menuItemRoles = null;
							break;
						}
						//Если доступно группе User, значит достаточно проверить только для этой группы
						else if (role.RoleName == "User")
						{
							menuItemRoles = null;
							menuItemPermisson = "User";
							break;
						}
						else
						{
							menuItemRoles.Append(role.RoleName);
							menuItemRoles.Append(";");
						}
					}

					if (menuItemRoles != null && menuItemRoles.Length > 0)
						menuItemPermisson = menuItemRoles.ToString();

					BXCacheManager.MemoryCache.Insert(permissionCacheKey, menuItemPermisson);
				}
				#endregion

				int elementId = 0, sectionId = 0;
				string elementCode = String.Empty, sectionCode = String.Empty;

				elementId = request.Get<int>("ElementId", elementId);
				sectionId = request.Get<int>("SectionId", sectionId);
				elementCode = request.Get<string>("ElementCode", elementCode);
				sectionCode = request.Get<string>("SectionCode", sectionCode);

				string parentLevelUri = null;
				List<BXPublicMenuItem> menuList = null;

				//Указан идентификатор или символьный код
				if (elementId > 0 || !String.IsNullOrEmpty(elementCode))
				{
					BXFilter elementFilter = new BXFilter(
						new BXFilterItem(BXIBlockElement.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId),
						new BXFilterItem(BXIBlockElement.Fields.Active, BXSqlFilterOperators.Equal, "Y")
					);

					if (elementId > 0)
						elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.ID, BXSqlFilterOperators.Equal, elementId));
					if (!String.IsNullOrEmpty(elementCode))
						elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.Code, BXSqlFilterOperators.Equal, elementCode));
					if (sectionId > 0)
						elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.Sections.Section.ID, BXSqlFilterOperators.Equal, sectionId));
					if (!String.IsNullOrEmpty(sectionCode))
						elementFilter.Add(new BXFilterItem(BXIBlockElement.Fields.Sections.Section.Code, BXSqlFilterOperators.Equal, sectionCode));

					BXIBlockElementCollection element = BXIBlockElement.GetList(elementFilter, null);
					if (element != null && element.Count > 0)
					{
						BXIBlockElement.BXInfoBlockElementSectionCollection sections = element[0].Sections;
						if (sections != null && sections.Count > 0)
						{
							BXParamsBag<object> replaceItems = new BXParamsBag<object>();
							replaceItems["SECTION_ID"] = sections[0].SectionId;
							replaceItems["SectionId"] = replaceItems["SECTION_ID"];
							replaceItems["SECTION_CODE"] = GetSectionCode(sections[0].SectionId);
							replaceItems["SectionCode"] = replaceItems["SECTION_CODE"];

							parentLevelUri = MakeMenuUri(executionVirtualPath, replaceItems); //Меню строится для раздела, к которому привязан элемент
						}
					}
				}

				//Если ничего не указано выводим все дерево
				Dictionary<string, BXPublicMenu.BXLoadMenuCommandParameter> menuTree = new Dictionary<string, BXPublicMenu.BXLoadMenuCommandParameter>();
				if (parentLevelUri == null && menuList == null)
				{
					BXIBlockSectionCollection sectionsList = BXIBlockSection.GetList(
						new BXFilter(
							new BXFilterItem(BXIBlockSection.Fields.Active, BXSqlFilterOperators.Equal, "Y"),
							new BXFilterItem(BXIBlockSection.Fields.ActiveGlobal, BXSqlFilterOperators.Equal, "Y"),
							new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, IBlockId)
						),
						new BXOrderBy(
							new BXOrderByPair(BXIBlockSection.Fields.LeftMargin, BXOrderByDirection.Asc)
						),
						null,
						null,
						BXTextEncoder.EmptyTextEncoder
					);

					int previousDepthLevel = 1;
					int previousSectionId = 0;
					Dictionary<int, MenuSectionTree> sectionTree = new Dictionary<int, MenuSectionTree>();
					foreach (BXIBlockSection section in sectionsList)
					{
						BXParamsBag<object> replaceItems = new BXParamsBag<object>();
						replaceItems["SECTION_ID"] = section.Id;
						replaceItems["SECTION_CODE"] = section.Code ?? String.Empty;
						replaceItems["SectionId"] = replaceItems["SECTION_ID"];
						replaceItems["SectionCode"] = replaceItems["SECTION_CODE"];

						sectionTree[section.Id] = new MenuSectionTree();
						string url = MakeMenuUri(executionVirtualPath, replaceItems);
						sectionTree[section.Id].url = url;
						sectionTree[section.Id].sectionId = section.SectionId;

						//Если предыдущий раздел не имеет дочерних разделов, то устанавливаем у него parentLevelUrl
						if (previousSectionId > 0 && section.DepthLevel <= previousDepthLevel)
							sectionTree[previousSectionId].parentLevelUrl = sectionTree[sectionTree[previousSectionId].sectionId].url;
						previousDepthLevel = section.DepthLevel;
						previousSectionId = section.Id;

						BXPublicMenuItem menuItem = new BXPublicMenuItem();
						menuItem.Title = section.Name;
						menuItem.Links.Add(url);
						menuItem.Sort = section.LeftMargin;

						menuItem.ConditionType = ConditionType.Group;
						menuItem.Condition = menuItemPermisson;

						if (!sectionTree.ContainsKey(section.SectionId))
						{
							sectionTree[section.SectionId] = new MenuSectionTree();
							sectionTree[section.SectionId].menuItems = new List<BXPublicMenuItem>();

							if (section.SectionId < 1)
								sectionTree[section.SectionId].url = EnableSef ? BXPath.ToVirtualRelativePath(BXPath.TrimStart(SefFolder)) : BXSiteRemapUtility.UnmapVirtualPath(executionVirtualPath);
						}

						if (sectionTree[section.SectionId].menuItems == null)
							sectionTree[section.SectionId].menuItems = new List<BXPublicMenuItem>();

						sectionTree[section.SectionId].menuItems.Add(menuItem);
					}

					//Последний элемент не может иметь дочерних элементов, поэтому указываем parentLevelUrl
					if (sectionTree.ContainsKey(previousSectionId) && sectionTree.ContainsKey(sectionTree[previousSectionId].sectionId))
						sectionTree[previousSectionId].parentLevelUrl = sectionTree[sectionTree[previousSectionId].sectionId].url;

					foreach (KeyValuePair<int, MenuSectionTree> sectionItem in sectionTree)
					{
						if (!menuTree.ContainsKey(sectionItem.Value.url))
						{
							menuTree.Add(
								sectionItem.Value.url,
								new BXPublicMenu.BXLoadMenuCommandParameter(sectionItem.Value.menuItems, true, sectionItem.Value.parentLevelUrl)
							);
						}
					}
				}

				if (menuTree.Count > 0)
					cmd.AddCommandResult("bitrix:catalogue@" + executionVirtualPath, new BXCommandResult(BXCommandResultType.Ok, menuTree));
				else if (menuList != null || parentLevelUri != null)
				{
					BXPublicMenu.BXLoadMenuCommandParameter menuResult = new BXPublicMenu.BXLoadMenuCommandParameter(menuList, true, parentLevelUri);
					cmd.AddCommandResult("bitrix:catalogue@" + executionVirtualPath, new BXCommandResult(BXCommandResultType.Ok, menuResult));
				}
			}
		}