2019-06-07 08:59:07 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
*
|
|
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
|
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
|
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
|
|
*
|
|
|
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
|
|
* in every copy of the program you distribute.
|
|
|
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
2019-08-15 12:04:42 +00:00
|
|
|
using System.Linq;
|
2019-06-07 08:59:07 +00:00
|
|
|
using ASC.Common.Caching;
|
|
|
|
using ASC.Common.Utils;
|
|
|
|
using ASC.Core;
|
2019-08-15 12:04:42 +00:00
|
|
|
using ASC.Web.Studio.Utility;
|
2019-06-07 08:59:07 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
|
|
namespace ASC.Web.Core.WhiteLabel
|
|
|
|
{
|
|
|
|
public class TenantLogoManager
|
|
|
|
{
|
2019-07-23 09:06:05 +00:00
|
|
|
private static readonly ICache Cache = AscCache.Memory;
|
|
|
|
private static readonly ICacheNotify<TenantLogoCacheItem> CacheNotify;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
|
|
|
private static string CacheKey
|
|
|
|
{
|
|
|
|
get { return "letterlogodata" + TenantProvider.CurrentTenantID; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool WhiteLabelEnabled
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
private set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static TenantLogoManager()
|
|
|
|
{
|
|
|
|
var hideSettings = (ConfigurationManager.AppSettings["web.hide-settings"] ?? "").Split(new[] { ',', ';', ' ' });
|
2019-07-23 09:06:05 +00:00
|
|
|
WhiteLabelEnabled = !hideSettings.Contains("WhiteLabel", StringComparer.CurrentCultureIgnoreCase);
|
|
|
|
CacheNotify = new KafkaCache<TenantLogoCacheItem>();
|
|
|
|
CacheNotify.Subscribe(r => Cache.Remove(r.Key), CacheNotifyAction.Remove);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetFavicon(bool general, bool timeParam)
|
|
|
|
{
|
|
|
|
string faviconPath;
|
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
|
|
|
var tenantWhiteLabelSettings = TenantWhiteLabelSettings.Load();
|
|
|
|
faviconPath = tenantWhiteLabelSettings.GetAbsoluteLogoPath(WhiteLabelLogoTypeEnum.Favicon, general);
|
2019-08-15 12:04:42 +00:00
|
|
|
if (timeParam)
|
|
|
|
{
|
2019-06-07 08:59:07 +00:00
|
|
|
var now = DateTime.Now;
|
2019-08-15 13:16:39 +00:00
|
|
|
faviconPath = string.Format("{0}?t={1}", faviconPath, now.Ticks);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
faviconPath = TenantWhiteLabelSettings.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.Favicon, general);
|
2019-08-15 12:04:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-07 08:59:07 +00:00
|
|
|
return faviconPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string GetTopLogo(bool general)//LogoLightSmall
|
|
|
|
{
|
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
|
|
|
var tenantWhiteLabelSettings = TenantWhiteLabelSettings.Load();
|
|
|
|
|
|
|
|
return tenantWhiteLabelSettings.GetAbsoluteLogoPath(WhiteLabelLogoTypeEnum.LightSmall, general);
|
|
|
|
}
|
|
|
|
return TenantWhiteLabelSettings.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.LightSmall, general);
|
|
|
|
}
|
|
|
|
|
2019-08-15 12:04:42 +00:00
|
|
|
public static string GetLogoDark(bool general)
|
|
|
|
{
|
2019-06-07 08:59:07 +00:00
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
|
|
|
var tenantWhiteLabelSettings = TenantWhiteLabelSettings.Load();
|
|
|
|
return tenantWhiteLabelSettings.GetAbsoluteLogoPath(WhiteLabelLogoTypeEnum.Dark, general);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** simple scheme ***/
|
|
|
|
var tenantInfoSettings = TenantInfoSettings.Load();
|
|
|
|
return tenantInfoSettings.GetAbsoluteCompanyLogoPath();
|
|
|
|
/***/
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string GetLogoDocsEditor(bool general)
|
|
|
|
{
|
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
|
|
|
var tenantWhiteLabelSettings = TenantWhiteLabelSettings.Load();
|
|
|
|
return tenantWhiteLabelSettings.GetAbsoluteLogoPath(WhiteLabelLogoTypeEnum.DocsEditor, general);
|
|
|
|
}
|
|
|
|
return TenantWhiteLabelSettings.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.DocsEditor, general);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string GetLogoText()
|
|
|
|
{
|
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
|
|
|
var tenantWhiteLabelSettings = TenantWhiteLabelSettings.LoadForDefaultTenant();
|
|
|
|
|
|
|
|
return tenantWhiteLabelSettings.LogoText ?? TenantWhiteLabelSettings.DefaultLogoText;
|
|
|
|
}
|
|
|
|
return TenantWhiteLabelSettings.DefaultLogoText;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsRetina(HttpRequest request)
|
|
|
|
{
|
|
|
|
var isRetina = false;
|
|
|
|
if (request != null)
|
|
|
|
{
|
|
|
|
var cookie = request.Cookies["is_retina"];
|
2019-08-15 13:16:39 +00:00
|
|
|
if (cookie != null && !string.IsNullOrEmpty(cookie))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-08-15 13:16:39 +00:00
|
|
|
if (bool.TryParse(cookie, out var result))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
isRetina = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isRetina;
|
2019-08-15 12:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool WhiteLabelPaid
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return CoreContext.TenantManager.GetTenantQuota(TenantProvider.CurrentTenantID).WhiteLabel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get logo stream or null in case of default logo
|
|
|
|
/// </summary>
|
|
|
|
public static Stream GetWhitelabelMailLogo()
|
|
|
|
{
|
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
|
|
|
var tenantWhiteLabelSettings = TenantWhiteLabelSettings.Load();
|
|
|
|
return tenantWhiteLabelSettings.GetWhitelabelLogoData(WhiteLabelLogoTypeEnum.Dark, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** simple scheme ***/
|
|
|
|
var tenantInfoSettings = TenantInfoSettings.Load();
|
|
|
|
return tenantInfoSettings.GetStorageLogoData();
|
|
|
|
/***/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] GetMailLogoDataFromCache()
|
|
|
|
{
|
|
|
|
return Cache.Get<byte[]>(CacheKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void InsertMailLogoDataToCache(byte[] data)
|
|
|
|
{
|
|
|
|
Cache.Insert(CacheKey, data, DateTime.UtcNow.Add(TimeSpan.FromDays(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void RemoveMailLogoDataFromCache()
|
2019-07-23 09:06:05 +00:00
|
|
|
{
|
|
|
|
CacheNotify.Publish(new TenantLogoCacheItem() { Key = CacheKey }, CacheNotifyAction.Remove);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|