Skip to content

Commit

Permalink
changed a logic of the patch to resolve the current site according to…
Browse files Browse the repository at this point in the history
… the current host name if possible
  • Loading branch information
Evgen Savinov committed Jun 7, 2017
1 parent 32f7d0a commit cac309c
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,111 +15,126 @@
using System;
using System.Collections.Specialized;
using System.Globalization;
using Sitecore.Web;

namespace Sitecore.Support.Shell.Applications.WebEdit.Commands
{


[Serializable]
public class OpenExperienceEditor : Command
{
public override void Execute(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
NameValueCollection parameters = new NameValueCollection();
bool flag = false;
if (context.Items.Length == 1)
{
Item item = context.Items[0];
parameters["uri"] = item.Uri.ToString();
parameters.Add("sc_lang", item.Language.ToString());
parameters.Add("sc_version", item.Version.Number.ToString(CultureInfo.InvariantCulture));
if (HasPresentationPipeline.Run(item))
{
parameters.Add("sc_itemid", item.ID.ToString());
}
else
{
flag = true;
}
}
ClientPipelineArgs args = new ClientPipelineArgs(parameters);
if (!flag)
{
args.Result = "yes";
args.Parameters.Add("needconfirmation", "false");
}
Context.ClientPage.Start(this, "Run", args);
}

public override CommandState QueryState(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
if ((!UIUtil.IsIE() || (UIUtil.GetBrowserMajorVersion() >= 7)) && Settings.WebEdit.Enabled)
{
return base.QueryState(context);
}
return CommandState.Hidden;
}

protected void Run(ClientPipelineArgs args)
[Serializable]
public class OpenExperienceEditor : Command
{
Assert.ArgumentNotNull(args, "args");
if (SheerResponse.CheckModified())
{
if ((args.Parameters["needconfirmation"] == "false") || args.IsPostBack)
public override void Execute(CommandContext context)
{
if (args.Result != "no")
{
UrlString str = new UrlString("/");
str.Add("sc_mode", "edit");
if (!string.IsNullOrEmpty(args.Parameters["sc_itemid"]))
Assert.ArgumentNotNull(context, "context");
NameValueCollection parameters = new NameValueCollection();
bool flag = false;
if (context.Items.Length == 1)
{
str.Add("sc_itemid", args.Parameters["sc_itemid"]);
Item item = context.Items[0];
parameters["uri"] = item.Uri.ToString();
parameters.Add("sc_lang", item.Language.ToString());
parameters.Add("sc_version", item.Version.Number.ToString(CultureInfo.InvariantCulture));
if (HasPresentationPipeline.Run(item))
{
parameters.Add("sc_itemid", item.ID.ToString());
}
else
{
flag = true;
}
}
if (!string.IsNullOrEmpty(args.Parameters["sc_version"]))
ClientPipelineArgs args = new ClientPipelineArgs(parameters);
if (!flag)
{
str.Add("sc_version", args.Parameters["sc_version"]);
args.Result = "yes";
args.Parameters.Add("needconfirmation", "false");
}
SiteContext previewSiteContext = null;
if (!string.IsNullOrEmpty(args.Parameters["uri"]))
{
Item item = Database.GetItem(ItemUri.Parse(args.Parameters["uri"]));
if (item == null)
{
SheerResponse.Alert("Item not found.", new string[0]);
return;
}
previewSiteContext = LinkManager.GetPreviewSiteContext(item);
}
SiteContext site = previewSiteContext ?? Factory.GetSite(Settings.Preview.DefaultSite);
if (site == null)
{
object[] parameters = new object[] { Settings.Preview.DefaultSite };
SheerResponse.Alert(Translate.Text("Site \"{0}\" not found", parameters), new string[0]);
}
else
Context.ClientPage.Start(this, "Run", args);
}

public override CommandState QueryState(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
if ((!UIUtil.IsIE() || (UIUtil.GetBrowserMajorVersion() >= 7)) && Settings.WebEdit.Enabled)
{
string str2 = args.Parameters["sc_lang"];
if (string.IsNullOrEmpty(str2))
{
str2 = WebEditUtility.ResolveContentLanguage(site).ToString();
}
if (!string.IsNullOrEmpty(args.Parameters["sc_lang"]))
{
str.Add("sc_lang", str2);
}
PreviewManager.RestoreUser();
Context.ClientPage.ClientResponse.Eval("window.open('" + str + "', '_blank')");
return base.QueryState(context);
}
}
return CommandState.Hidden;
}
else

protected void Run(ClientPipelineArgs args)
{
SheerResponse.Confirm("The current item does not have a layout for the current device.\n\nDo you want to open the start Web page instead?");
args.WaitForPostBack();
Assert.ArgumentNotNull(args, "args");
if (SheerResponse.CheckModified())
{
if ((args.Parameters["needconfirmation"] == "false") || args.IsPostBack)
{
if (args.Result != "no")
{
UrlString str = new UrlString("/");
str.Add("sc_mode", "edit");
if (!string.IsNullOrEmpty(args.Parameters["sc_itemid"]))
{
str.Add("sc_itemid", args.Parameters["sc_itemid"]);
}
if (!string.IsNullOrEmpty(args.Parameters["sc_version"]))
{
str.Add("sc_version", args.Parameters["sc_version"]);
}
SiteContext previewSiteContext = null;
if (!string.IsNullOrEmpty(args.Parameters["uri"]))
{
Item item = Database.GetItem(ItemUri.Parse(args.Parameters["uri"]));
if (item == null)
{
SheerResponse.Alert("Item not found.", new string[0]);
return;
}
previewSiteContext = LinkManager.GetPreviewSiteContext(item);
}
//fix for 119280. If the current item is null and previewSiteContext has not been resolved, we try to resolve site context by using current host name only
if (previewSiteContext == null)
{
System.Collections.Generic.List<SiteInfo> sites = SiteContextFactory.Sites;
foreach (SiteInfo current in sites)
{
if (current.HostName.ToLowerInvariant().Equals(WebUtil.GetRequestUri().Host.ToLowerInvariant()))
{
previewSiteContext = new SiteContext(current);
break;
}
}
}
SiteContext site = previewSiteContext ?? Factory.GetSite(Settings.Preview.DefaultSite);
if (site == null)
{
object[] parameters = new object[] {Settings.Preview.DefaultSite};
SheerResponse.Alert(Translate.Text("Site \"{0}\" not found", parameters), new string[0]);
}
else
{
string str2 = args.Parameters["sc_lang"];
if (string.IsNullOrEmpty(str2))
{
str2 = WebEditUtility.ResolveContentLanguage(site).ToString();
}
if (!string.IsNullOrEmpty(args.Parameters["sc_lang"]))
{
str.Add("sc_lang", str2);
}
str["sc_site"] = site.Name;

PreviewManager.RestoreUser();
Context.ClientPage.ClientResponse.Eval("window.open('" + str + "', '_blank')");
}
}
}
else
{
SheerResponse.Confirm(
"The current item does not have a layout for the current device.\n\nDo you want to open the start Web page instead?");
args.WaitForPostBack();
}
}
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Sitecore.Support.119280/Sitecore.Support.119280.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:64588/</IISUrl>
<IISUrl>http://localhost:64443/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
Expand Down

0 comments on commit cac309c

Please sign in to comment.