示例#1
0
        protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
        {
            if (!Sitecore.Web.UI.Sheer.SheerResponse.CheckModified())
            {
                return;
            }

            if (args.IsPostBack)
            {
                Sitecore.Web.UI.Sheer.SheerResponse.Confirm(Sitecore.Globalization.Translate.Text(
                                                                "Reset {0} to its standard value?",
                                                                new object[] { args.Parameters["field"] }));
                args.WaitForPostBack();
            }

            if (!args.HasResult)
            {
                return;
            }

            if (args.Result != "yes")
            {
                return;
            }

            Sitecore.Data.Database          database = Sitecore.Configuration.Factory.GetDatabase(args.Parameters["database"]);
            Sitecore.Globalization.Language language = Sitecore.Globalization.Language.Parse(args.Parameters["language"]);
            Sitecore.Data.Version           version  = Sitecore.Data.Version.Parse(args.Parameters["version"]);
            Sitecore.Data.Items.Item        item     = database.GetItem(args.Parameters["id"], language, version);

            using (new Sitecore.Data.Items.EditContext(item))
            {
                item.Fields[args.Parameters["field"]].Reset();
            }
        }
示例#2
0
 private bool HasVersionInLanguage(
     Sitecore.Data.Items.Item item,
     Sitecore.Globalization.Language language)
 {
     Sitecore.Data.Items.Item langItem = Sitecore.Context.Item.Database.GetItem(Sitecore.Context.Item.ID, language);
     return(langItem.Versions.Count > 0);
 }
示例#3
0
        private Sitecore.Data.Items.Item retrieveItem(ListviewItem listItem)
        {
            string path = listItem.Header;

            Sitecore.Globalization.Language lang    = Sitecore.Globalization.Language.Current;
            Sitecore.Data.Version           version = Sitecore.Data.Version.Latest;
            Sitecore.Data.Items.Item        item    = null;
            if (listItem.ColumnValues.Contains("lang"))
            {
                Sitecore.Globalization.Language.TryParse(listItem.ColumnValues["lang"].ToString(), out lang);
            }
            if (listItem.ColumnValues.Contains("version"))
            {
                version = new Sitecore.Data.Version(listItem.ColumnValues["version"].ToString());
            }

            item =
                Properties.Db.GetItem(path, lang, version);
            if (item == null)
            {
                if (Properties.Db.HasContentItem)
                {
                    path = "/sitecore/content/" + path;
                    item = Properties.Db.GetItem(path, lang, version);
                    if (item != null)
                    {
                        return(item);
                    }
                }
                throw new Exception("Item does not exist in such language");
            }
            return(item);
        }
        private void UpdateMediaItem(RequestArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Item item = args.Context.Item;

            if (item == null)
            {
                throw new BadRequestException("The specified location not found.");
            }
            Database database = args.Context.Database;

            Assert.IsNotNull(database, "Database not resolved.");
            Sitecore.Globalization.Language currentLanguage = args.Context.Language;
            if (!item.Access.CanCreate())
            {
                throw new AccessDeniedException(string.Format("Access denied (access right: 'item:create', item: '{0}')", item.Paths.ParentPath));
            }
            HttpFileCollection files     = args.Context.HttpContext.Request.Files;
            List <Item>        list      = new List <Item>();
            MediaItem          mediaItem = Common.Functions.UpdateMediaItem(item, args.Context.HttpContext);

            if (mediaItem != null)
            {
                list.Add(mediaItem.InnerItem);
                ReadArgs readArgs = new ReadArgs(list.ToArray());
                CorePipeline.Run("itemWebApiRead", readArgs);
                args.Result = readArgs.Result;
            }
        }
示例#5
0
文件: Url.cs 项目: Praveencls/cxm
        /// <summary>
        /// Oarse the language part of the URL.
        /// </summary>
        /// <param name="path">The URL string.</param>
        /// <returns>The remainder of the URL, excluding the language.</returns>
        protected string ParseLanguage(string path)
        {
            if (!String.IsNullOrEmpty(path))
            {
                int separator = path.IndexOfAny(new[] { '/', '.' }, 1);

                if (separator < 0)
                {
                    separator = path.Length;
                }

                string langName = path.Substring(1, separator - 1);

                if (!String.IsNullOrEmpty(langName))
                {
                    Sitecore.Globalization.Language language = null;

                    if (Sitecore.Globalization.Language.TryParse(langName, out language))
                    {
                        this.LanguageName = language.Name;
                        path = path.Substring(this.LanguageName.Length);
                    }
                }
            }

            return(path);
        }
示例#6
0
        private void SetContextLanguage(Sitecore.Globalization.Language language, bool spanRequests)
        {
            Sitecore.Context.SetLanguage(language, spanRequests);
            Sitecore.Context.Item = Sitecore.Context.Item.Database.GetItem(Sitecore.Context.Item.ID, language);

            if (spanRequests && this.PersistLanguage)
            {
                string cookieName = Sitecore.Context.Site.GetCookieKey("lang");
                Sitecore.Web.WebUtil.SetCookieValue(cookieName, language.Name, DateTime.MaxValue);
            }
        }
        public static List <object[]> GetLanguagePropertiesFull(Sitecore.Globalization.Language l)
        {
            var results = new List <object[]>()
            {
                new object[] { "Language Property", "Value" },
                new object[] { "Name", l.Name },
                new object[] { "DisplayName", l.GetDisplayName() },
                new object[] { "CultureInfo", GetCulturePropertiesFull(l.CultureInfo) },
                new object[] { "Origin Item Id", (l.Origin != null && l.Origin.ItemId != (Sitecore.Data.ID)null) ? l.Origin.ItemId.Guid.ToString() : string.Empty },
            };

            return(results);
        }
        private Sitecore.Data.ItemUri parseItemUri(string Message)
        {
            Match match = Regex.Match(Message, @"(?<db>\w+):(?<path>[^,]+), language: (?<language>[^,]+), version: (?<version>[^,]+), id: (?<id>\{.{36}\}).*");

            if (!match.Success)
            {
                return(null);
            }

            Sitecore.Data.Version           version  = new Sitecore.Data.Version(match.Groups["version"].Value);
            Sitecore.Globalization.Language language = Sitecore.Globalization.Language.Parse(match.Groups["language"].Value);
            Sitecore.Data.ID       id = Sitecore.Data.ID.Parse(match.Groups["id"].Value);
            Sitecore.Data.Database db = Sitecore.Data.Database.GetDatabase(match.Groups["db"].Value);
            return(new Sitecore.Data.ItemUri(id, language, version, db));
        }
        private Sitecore.Data.ItemUri parseItemUri(string Message)
        {
            Match match = Regex.Match(Message, @"(?<db>\w+):(?<path>[^,]+), language: (?<language>[^,]+), version: (?<version>[^,]+), id: (?<id>\{.{36}\}).*");

            if (!match.Success)
            {
                return(null);
            }
            var versionNumber  = int.Parse(match.Groups["version"].Value);
            var item           = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(match.Groups["id"].Value));
            var currentVersion = item.Versions.GetVersionNumbers().First(x => x.Number == versionNumber);

            Sitecore.Globalization.Language language = Sitecore.Globalization.Language.Parse(match.Groups["language"].Value);
            Sitecore.Data.ID       id = Sitecore.Data.ID.Parse(match.Groups["id"].Value);
            Sitecore.Data.Database db = Sitecore.Data.Database.GetDatabase(match.Groups["db"].Value);
            return(new Sitecore.Data.ItemUri(id, language, currentVersion, db));
        }
 private string GetMarkup(Sitecore.Data.Items.Item item, Sitecore.Globalization.Language lang)
 {
     if (lang != item.Language)
     {
         Sitecore.Links.UrlOptions opts = Sitecore.Links.LinkManager.GetDefaultUrlOptions();
         opts.Language = lang;
         return(String.Format(
                    @"<a href=""{0}""><img border=""0"" src=""{1}"" alt=""{2}"" /></a>",
                    Sitecore.Links.LinkManager.GetItemUrl(item, opts),
                    Sitecore.Resources.Images.GetThemedImageSource(lang.GetIcon(item.Database)),
                    lang.GetDisplayName()));
     }
     else
     {
         return(String.Format(
                    @"<img src=""{0}"" alt=""{1}"" />",
                    Sitecore.Resources.Images.GetThemedImageSource(lang.GetIcon(item.Database)),
                    lang.GetDisplayName()));
     }
 }
        public void HowToUnitTestLocalization()
        {
            // init languages
            Sitecore.Globalization.Language en = Sitecore.Globalization.Language.Parse("en");
            Sitecore.Globalization.Language da = Sitecore.Globalization.Language.Parse("da");

            const string Phrase = "Welcome!";

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
            {
                db.Configuration.Settings.AutoTranslate       = true;
                db.Configuration.Settings.AutoTranslatePrefix = "{lang}:";

                // translate
                string enTranslation = Sitecore.Globalization.Translate.TextByLanguage(Phrase, en);
                string daTranslation = Sitecore.Globalization.Translate.TextByLanguage(Phrase, da);

                Xunit.Assert.Equal("en:Welcome!", enTranslation);
                Xunit.Assert.Equal("da:Welcome!", daTranslation);
            }
        }
示例#12
0
        public override void Execute(SC.Shell.Framework.Commands.CommandContext context)
        {
            SC.Diagnostics.Assert.IsNotNull(context, "context");
            SC.Text.UrlString webSiteUrl = new SC.Text.UrlString("/");
            webSiteUrl.Add("sc_debug", "1");
            webSiteUrl.Add("sc_prof", "1");
            webSiteUrl.Add("sc_trace", "1");
            webSiteUrl.Add("sc_ri", "1");
            SC.Data.Database          db   = SC.Context.ContentDatabase;
            SC.Globalization.Language lang = SC.Context.ContentLanguage;

            // if the context for invoking the command specifies exactly one item
            if (context.Items != null &&
                context.Items.Length == 1 &&
                context.Items[0] != null)
            {
                // ensure the user has saved the selected item
                SC.Context.ClientPage.ClientResponse.CheckModified(false);
                SC.Data.Items.Item item = context.Items[0];
                db   = item.Database;
                lang = item.Language;
                webSiteUrl.Add("sc_itemid", item.ID.ToString());
            }

            if (db != null)
            {
                webSiteUrl.Add("sc_database", db.Name);
            }

            if (lang != null)
            {
                webSiteUrl.Add("sc_lang", lang.ToString());
            }

            // without this, I didn't see the ribbon
            SC.Publishing.PreviewManager.RestoreUser();
            SC.Context.ClientPage.ClientResponse.Eval(
                "window.open('" + webSiteUrl + "', '_blank')");
        }
示例#13
0
 public SkinnyItem(string id, string language, string version, string databaseName)
     : this(new ItemUri(ID.Parse(id), SCLang.Parse(language), SCVersion.Parse(version), databaseName))
 {
 }
        private IEnumerable <UrlDefinition> ProcessSite(Sitecore.Data.Items.Item homeItem, SiteDefinition def, Sitecore.Globalization.Language language)
        {
            IProviderSearchContext ctx;

            if (string.IsNullOrEmpty(this.indexName))
            {
                ctx = ContentSearchManager.GetIndex((SitecoreIndexableItem)homeItem).CreateSearchContext();
            }
            else
            {
                ctx = ContentSearchManager.GetIndex(this.indexName).CreateSearchContext();
            }

            try
            {
                var results = ctx.GetQueryable <SitemapResultItem>()
                              .Where(i => i.Paths.Contains(homeItem.ID) && i.Language == language.Name);
                var tmplPred = PredicateBuilder.False <SitemapResultItem>();
                foreach (var tmpl in def.IncludedBaseTemplates.Select(i => Sitecore.Data.ID.Parse(i)))
                {
                    tmplPred = tmplPred.Or(i => i.AllTemplates.Contains(tmpl));
                }
                foreach (var tmpl in def.IncludedTemplates.Select(i => Sitecore.Data.ID.Parse(i)))
                {
                    tmplPred = tmplPred.Or(i => i.TemplateId == tmpl);
                }
                var itemPred = PredicateBuilder.True <SitemapResultItem>();
                foreach (var id in def.ExcludedItems.Select(i => Sitecore.Data.ID.Parse(i)))
                {
                    itemPred = itemPred.And(i => i.ItemId != id);
                }
                results = results.Where(tmplPred.And(itemPred));

                var items = results
                            .Select(i => Sitecore.Configuration.Factory.GetDatabase(i.DatabaseName).GetItem(i.ItemId, Sitecore.Globalization.Language.Parse(i.Language), Sitecore.Data.Version.Latest))
                            .Where(i => i != null) // exclude results that exist in the index but not in the database
                            .ToList();

                var sb      = new StringBuilder();
                var options = Sitecore.Links.UrlOptions.DefaultOptions;
                options.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving;
                options.Site          = SiteContext.GetSite(def.SiteName);
                if (def.EmbedLanguage)
                {
                    options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Always;
                }
                else
                {
                    options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Never;
                }
                options.AlwaysIncludeServerUrl = true;
                options.Language = language;
                foreach (var item in items)
                {
                    if (item.Versions.Count > 0)
                    {
                        yield return(new UrlDefinition(Sitecore.Links.LinkManager.GetItemUrl(item, options), item.Statistics.Updated));
                    }
                }
            }
            finally
            {
                ctx.Dispose();
            }
        }