Skip to content

Commit

Permalink
[Composite.Web.Html.DeviceSpecificContent] 1.0.0 Device Specific Cont…
Browse files Browse the repository at this point in the history
…ent package
  • Loading branch information
InnaBoitsun committed Aug 30, 2016
1 parent 35da286 commit e07dab5
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Composite.Web.Html.DeviceSpecificContent", "Composite.Web.Html.DeviceSpecificContent\Composite.Web.Html.DeviceSpecificContent.csproj", "{F94F7249-F09D-4A3E-834F-06F2A0CC0D03}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F94F7249-F09D-4A3E-834F-06F2A0CC0D03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F94F7249-F09D-4A3E-834F-06F2A0CC0D03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F94F7249-F09D-4A3E-834F-06F2A0CC0D03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F94F7249-F09D-4A3E-834F-06F2A0CC0D03}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F94F7249-F09D-4A3E-834F-06F2A0CC0D03}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Composite.Web.Html.DeviceSpecificContent</RootNamespace>
<AssemblyName>Composite.Web.Html.DeviceSpecificContent</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<UseIISExpress>true</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<UseGlobalApplicationHostFile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Package\install.xml" />
<Content Include="_PackageCreator\Composite.Web.Html.DeviceSpecificContent.xml" />
</ItemGroup>
<ItemGroup>
<Content Include="Package\App_Data\Razor\Composite\Web\Html\DeviceSpecificContent.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Release\Composite.Web.Html.DeviceSpecificContent.zip" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>62305</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:62305/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<PropertyGroup>
<PreBuildEvent>"$(DevEnvDir)\TF.exe" checkout /lock:none "$(ProjectDir)Release\$(SolutionName).zip"
"$(SolutionDir)..\References\7za.exe" d "$(ProjectDir)Release\$(SolutionName).zip"
"$(SolutionDir)..\References\7za.exe" a -tzip "$(ProjectDir)Release\$(SolutionName).zip" -r "$(ProjectDir)Package\*" -x!*designer.cs
</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@using System.Text.RegularExpressions
@using Composite.C1Console.Security
@using Composite.Core.WebClient.Renderings.Page

@inherits RazorFunction

@functions {
public override string FunctionDescription
{
get { return "Deliver either 'Mobile' or 'Desktop' content , depending on the browser requesting the page."; }
}

[FunctionParameter(Label = "Mobile Content", Help = "What you put here will be shown in mobile view")]
public Lazy<XhtmlDocument> Mobile { get; set; }

[FunctionParameter(Label = "Desktop Content", Help = "What you put here will be shown in desktop view")]
public Lazy<XhtmlDocument> Desktop { get; set; }

// for more on these regexs, see http://detectmobilebrowsers.com/
private static readonly Regex b = new Regex(@"(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino", RegexOptions.IgnoreCase | RegexOptions.Multiline);
private static readonly Regex v = new Regex(@"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-", RegexOptions.IgnoreCase | RegexOptions.Multiline);
private static bool cahceKeyInitialized = false;
private static object cahceKeyInitializedLock = new object();

private static bool IsMobileClient(HttpContext context)
{
var debugMobile = UserValidationFacade.IsLoggedIn() && (context.Request["mobile"] != null);

This comment has been minimized.

Copy link
@burningice2866

burningice2866 Aug 30, 2016

I remember a long discussion on using such magic querystrings in this thread Orckestra/C1-CMS-Foundation#4

This should at least by something like c1mobile or c1device=mobile when following your own logic

cc @mawtex

This comment has been minimized.

Copy link
@mawtex

mawtex Aug 31, 2016

Collaborator

True

var u = context.Request.ServerVariables["HTTP_USER_AGENT"] ?? "UNKNOWN";

This comment has been minimized.

Copy link
@burningice2866

burningice2866 Aug 30, 2016

Its better to rely on IsMobileDevice on Request.Mobile, since this allows to expand the support for devices using ie. 51Degrees

return debugMobile || ((b.IsMatch(u) || v.IsMatch(u.Substring(0, 4))));
}

private const string DeviceTypeLabelStyle = "position:absolute; background:#ccc; color: #666; width:7em; right:0; padding: 10px 15px; font-size: 16px; letter-spacing: 2px;";
}
@{
if (!cahceKeyInitialized)
{
lock (cahceKeyInitializedLock)
{
cahceKeyInitialized = true;
// ensure all full page caching will respect mobile/desktop diffference
Composite.Core.WebClient.ApplicationLevelEventHandlers.RegisterC1PageVaryByCustomStringProvider("IsMobileClient",
f => IsMobileClient(f) ? "mobile" : "desktop");
}
}

var isMobileClient = IsMobileClient(HttpContext.Current);
var isScreenshotGeneration = PageRenderer.RenderingReason == RenderingReason.ScreenshotGeneration;
}
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://www.composite.net/ns/function/1.0">
<head>
</head>
<body>
@if (isScreenshotGeneration)
{
<div style="max-height: 450px; overflow: hidden; margin-bottom: 20px;">
<div style="@DeviceTypeLabelStyle">MOBILE</div>
@Markup(Mobile.Value)
</div>
<div>
<div style="@(DeviceTypeLabelStyle)">DESKTOP</div>
@Markup(Desktop.Value)
</div>
}
@if (isMobileClient && !isScreenshotGeneration)
{
@Markup(Mobile.Value)
}
@if (!isMobileClient && !isScreenshotGeneration)
{
@Markup(Desktop.Value)
}
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" standalone="yes"?>
<mi:PackageInstaller xmlns:mi="http://www.composite.net/ns/management/packageinstaller/1.0">
<mi:PackageRequirements minimumCompositeVersion="4.3.5555.25838" maximumCompositeVersion="9.9999.9999.9999" />
<mi:PackageInformation name="Composite.Web.Html.DeviceSpecificContent" groupName="Composite.Web" version="1.0.0" author="Composite A/S" website="http://composite.net" readMoreUrl="http://docs.composite.net/Composite.Web.Html.DeviceSpecificContent" id="8302eb16-7c64-4aa5-aa8e-b27cc710b3c4" canBeUninstalled="true" systemLocking="hard" flushOnCompletion="true">
<TechnicalDetails>Based on http://detectmobilebrowsers.com/</TechnicalDetails>
<Description>Deliver either 'Mobile' or 'Desktop' content , depending on the browser requesting the page.</Description>
</mi:PackageInformation>
<mi:PackageFragmentInstallerBinaries />
<mi:PackageFragmentInstallers>
<mi:Add installerType="Composite.Core.PackageSystem.PackageFragmentInstallers.FilePackageFragmentInstaller, Composite" uninstallerType="Composite.Core.PackageSystem.PackageFragmentInstallers.FilePackageFragmentUninstaller, Composite">
<Files>
<File sourceFilename="~\App_Data/Razor/Composite/Web/Html/DeviceSpecificContent.cshtml" targetFilename="~\App_Data/Razor/Composite/Web/Html/DeviceSpecificContent.cshtml" allowOverwrite="false" />
</Files>
</mi:Add>
</mi:PackageFragmentInstallers>
</mi:PackageInstaller>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Composite.StarterSite.PageBlock.DeviceSpecificContent")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Composite.StarterSite.PageBlock.DeviceSpecificContent")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2736de56-5b4a-49c0-a456-0eda5c200b81")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<pc:PackageCreator xmlns:mi="http://www.composite.net/ns/management/packageinstaller/1.0" xmlns:pc="http://www.composite.net/ns/management/packagecreator/2.0" xmlns:help="http://www.composite.net/ns/help/1.0">
<pc:Functions>
<Add name="PageBlocks.DeviceSpecificContent" />
</pc:Functions>
<mi:PackageRequirements minimumCompositeVersion="4.3.5555.25838" maximumCompositeVersion="9.9999.9999.9999" />
<mi:PackageInformation name="Composite.Web.Html.DeviceSpecificContent" groupName="Composite.Web" version="1.0.0" author="Composite A/S" website="http://composite.net" readMoreUrl="http://docs.composite.net/Composite.Web.Html.DeviceSpecificContent" id="8302eb16-7c64-4aa5-aa8e-b27cc710b3c4" canBeUninstalled="true" systemLocking="hard" flushOnCompletion="true">
<TechnicalDetails>Based on http://detectmobilebrowsers.com/</TechnicalDetails>
<Description>Deliver either 'Mobile' or 'Desktop' content , depending on the browser requesting the page.</Description>
</mi:PackageInformation>
</pc:PackageCreator>

0 comments on commit e07dab5

Please sign in to comment.