/// <summary> /// Convert to html /// </summary> /// <param name="serverMediaFolder"></param> /// <param name="imageUrlPrefix"></param> /// <param name="input"></param> /// <returns></returns> public string ToHtml(string serverMediaFolder, string imageUrlPrefix, Stream input) { using (var stream = new MemoryStream()) { imageUrlPrefix = imageUrlPrefix.Replace("\\", "/"); input.CopyTo(stream); var data = stream.ToArray(); var helpServiceSetting = _siteSettingService.LoadSetting <EzCMSHelpConfigurationSetting>(); var result = WebUtilities.SendApiRequest <HtmlResult>( helpServiceSetting.HelpServiceUrl, helpServiceSetting.AuthorizeCode, "api/Helps/WordToHtml", HttpMethod.Post, new RouteValueDictionary(new { docx = data, mediaPath = imageUrlPrefix })); result.Html = HttpUtility.HtmlDecode(result.Html); if (!Directory.Exists(serverMediaFolder)) { Directory.CreateDirectory(serverMediaFolder); } if (result.Files != null) { foreach (var file in result.Files) { File.WriteAllBytes(Path.Combine(serverMediaFolder, file.Key), file.Value); } } return(result.Html); } }
/// <summary> /// The style file for editor /// </summary> /// <returns></returns> public ActionResult EditorStyleFile() { var model = _siteSettingService.LoadSetting <EditorSetting>(); var mime = System.Web.MimeMapping.GetMimeMapping(".css"); return(Content(model.StyleContent, mime)); }
/// <summary> /// Search the protected documents /// </summary> /// <returns></returns> public List <DocumentModel> GetDocuments(string encryptPath, ProtectedDocumentEnums.DocumentSearchType type = ProtectedDocumentEnums.DocumentSearchType.All, int?total = null) { // Convert encrypt path to real path var path = encryptPath.GetUniqueLinkInput(); var documents = new List <DocumentModel>(); var physicalPath = HttpContext.Current.Server.MapPath(path); if (Directory.Exists(physicalPath)) { var folderPermissions = GetDocumentPermissions(path); var documentTypeMapping = _siteSettingService.LoadSetting <DocumentTypeMappingSetting>(); var directory = new DirectoryInfo(physicalPath); var documentLogs = _protectedDocumentLogService.GetCurrentUserRelatedLogs(path); if (type == ProtectedDocumentEnums.DocumentSearchType.All || type == ProtectedDocumentEnums.DocumentSearchType.Folder) { // Loop through all directories and add if current user can see the documents foreach (var childDirectory in directory.GetDirectories()) { var mediaPath = childDirectory.FullName.ToRelativePath(EzCMSContants.ProtectedDocumentPath); if (CanCurrentUserAccessPath(mediaPath, folderPermissions)) { documents.Add(new DocumentModel(childDirectory, documentLogs)); } } } if (type == ProtectedDocumentEnums.DocumentSearchType.All || type == ProtectedDocumentEnums.DocumentSearchType.File) { // If user can access folder then they can view the files var canAccessPath = CanCurrentUserAccessPath(path); if (canAccessPath) { //Loop through all files in directory documents.AddRange( directory.GetFiles() .Select(file => new DocumentModel(file, documentLogs, documentTypeMapping.Mappings))); } } } // Get number of documents if (total.HasValue && total.Value > 0) { return(documents.Take(total.Value).ToList()); } return(documents); }
/// <summary> /// Get body template selector model /// </summary> /// <returns></returns> public BodyTemplateSelectorModel GetBodyTemplateSelector(BodyTemplateEnums.Mode mode) { var helpServiceSetting = _siteSettingService.LoadSetting <EzCMSHelpConfigurationSetting>(); return(new BodyTemplateSelectorModel { EnableOnlineTemplate = !helpServiceSetting.DisabledOnlineBodyTemplateService, Mode = mode, BodyTemplates = GetInstalledBodyTemplates() }); }
/// <summary> /// Load embedded script /// </summary> /// <param name="formId"></param> /// <returns></returns> public string LoadEmbeddedScript(int formId) { var form = GetById(formId); if (form != null) { var formRenderModel = new FormWidget(form); var formBuilderSetting = _siteSettingService.LoadSetting <FormBuilderSetting>(); var cacheName = SettingNames.FormBuilderSetting.GetTemplateCacheName(formBuilderSetting.EmbeddedTemplate); return(RazorEngineHelper.CompileAndRun(formBuilderSetting.EmbeddedTemplate, formRenderModel, null, cacheName)); } return(HtmlUtilities.BuildScript(ScriptAction.Alert, T("Form_Message_InvalidFormId"))); }
/// <summary> /// Return the content of RobotsSetting as a file. /// </summary> /// <returns></returns> public ActionResult Robots() { var enableLiveSiteMode = _siteSettingService.GetSetting <bool>(SettingNames.EnableLiveSiteMode); var robotsSetting = _siteSettingService.LoadSetting <RobotsSetting>(); if (enableLiveSiteMode) { return(Content(robotsSetting.LiveSiteModeContent, "text/plain")); } return(Content(robotsSetting.TestSiteModeContent, "text/plain")); }
/// <summary> /// Render testimonial widget /// </summary> /// <param name="parameters"></param> /// <returns></returns> public override string Render(string[] parameters) { var subscriptionConfiguration = _siteSettingService.LoadSetting <SubscriptionConfigurationSetting>(); if (!subscriptionConfiguration.DisableNotifySubscribers) { ParseParams(parameters); var model = _subscriptionService.GenerateSubscription(ModuleEnum, WorkContext.CurrentContact.Email, Parameters); var template = _widgetTemplateService.GetTemplateByName(Template) ?? _widgetTemplateService.GetTemplateByName(GetSetup().DefaultTemplate); return(_widgetTemplateService.ParseTemplate(template, model)); } return(string.Empty); }
/// <summary> /// Render widget /// </summary> /// <param name="parameters"></param> /// <returns></returns> public override string Render(string[] parameters) { ParseParams(parameters); var form = _formService.GetById(FormId); if (form == null) { return(_localizedResourceService.T("Widget_Form_Message_InvalidFormId")); } var formRenderModel = new FormWidget(form); var formBuilderSetting = _siteSettingService.LoadSetting <FormBuilderSetting>(); var cacheName = SettingNames.FormBuilderSetting.GetTemplateCacheName(formBuilderSetting.EmbeddedTemplate); return(RazorEngineHelper.CompileAndRun(formBuilderSetting.EmbeddedTemplate, formRenderModel, null, cacheName)); }
/// <summary> /// Gets the default value of a slide in help in case this is not available in dictionary /// </summary> /// <param name="langKey">Language key of the slide in help to get</param> /// <param name="textKey">Key of the string/text to get slide in help</param> /// <returns></returns> private SlideInHelpDictionaryItem GetDefaultValue(string langKey, string textKey) { var slideInHelp = _slideInHelpRepository.Get(langKey, textKey); if (slideInHelp != null) { var model = new SlideInHelpModel(slideInHelp); return(new SlideInHelpDictionaryItem(model)); } //Adding data only when no service required var slideInHelpSetting = _siteSettingService.LoadSetting <EzCMSHelpConfigurationSetting>(); if (slideInHelpSetting.DisabledSlideInHelpService) { return(UpdateDictionaryToDb(langKey, textKey)); } return(null); }
public ActionResult GoogleAnalyticApiSetup() { var model = _siteSettingService.LoadSetting <GoogleAnalyticApiSetting>(); return(View("Analytics/Partials/_AnalyticApiSetup", model)); }
public ActionResult FileUpload(string qqfile, string dir) { var physicalPath = Server.MapPath(dir); if (!Directory.Exists(physicalPath)) { Directory.CreateDirectory(physicalPath); } string file; try { var stream = Request.InputStream; if (String.IsNullOrEmpty(Request["qqfile"])) { // IE var postedFile = Request.Files[0]; if (postedFile != null) { stream = postedFile.InputStream; file = Path.Combine(physicalPath, Path.GetFileName(postedFile.FileName)); } else { return(Json(new ResponseModel { Success = false, Message = T("Media_Message_FileUploadEmpty") })); } } else { //Webkit, Mozilla file = Path.Combine(physicalPath, qqfile); } //Check if path exists or not, if exists then assign new path for image file = file.GetRightFilePathToSave(); if (file.IsImage()) { using (var img = System.Drawing.Image.FromStream(stream)) { var imageUploadSetting = _siteSettingService.LoadSetting <ImageUploadSetting>(); if (imageUploadSetting != null) { if (imageUploadSetting.MinWidth.HasValue && img.Width < imageUploadSetting.MinWidth) { return (Json( new { Success = false, Message = TFormat("Media_Message_InvalidMinWidth", imageUploadSetting.MinWidth) }, "text/html")); } if (imageUploadSetting.MinHeight.HasValue && img.Height < imageUploadSetting.MinHeight) { return (Json( new ResponseModel { Success = false, Message = TFormat("Media_Message_InvalidMinHeight", imageUploadSetting.MinHeight) }, "text/html")); } if (imageUploadSetting.MaxWidth.HasValue && img.Width > imageUploadSetting.MaxWidth) { return (Json( new ResponseModel { Success = false, Message = TFormat("Media_Message_InvalidMaxWidth", imageUploadSetting.MaxWidth) }, "text/html")); } if (imageUploadSetting.MaxHeight.HasValue && img.Height > imageUploadSetting.MaxHeight) { return (Json( new ResponseModel { Success = false, Message = TFormat("Media_Message_InvalidMaxHeight", imageUploadSetting.MaxHeight) }, "text/html")); } } img.Save(file); } } else { FileUtilities.SaveFile(file, stream); } } catch (Exception ex) { return(Json(new ResponseModel(ex), "text/html")); } var isImage = file.IsImage(); var location = string.Format("{0}/{1}", dir, Path.GetFileName(file)); return(Json(new { Success = true, Message = T("Media_Message_UploadSuccessfully"), fileLocation = location, id = location.ToIdString(), isImage }, "text/html")); }
/// <summary> /// Get google analytic model /// </summary> /// <returns></returns> public GoogleAnalyticDashboardModel GetGoogleAnalyticAccessToken() { if (!string.IsNullOrEmpty(WorkContext.GoogleAnalyticAccessToken)) { return(new GoogleAnalyticDashboardModel { AccessToken = WorkContext.GoogleAnalyticAccessToken, IsSetup = true, IsSetupInformationValid = true }); } const string googleApiUrl = "https://www.googleapis.com/oauth2/v3/token"; var googleAnalyticSetting = _siteSettingService.LoadSetting <GoogleAnalyticApiSetting>(); if (!string.IsNullOrEmpty(googleAnalyticSetting.ClientId) && !string.IsNullOrEmpty(googleAnalyticSetting.ClientSecret) && !string.IsNullOrEmpty(googleAnalyticSetting.RefreshToken)) { try { var url = string.Format( "client_secret={0}&grant_type=refresh_token&refresh_token={1}&client_id={2}", googleAnalyticSetting.ClientSecret, googleAnalyticSetting.RefreshToken, googleAnalyticSetting.ClientId); var req = WebRequest.Create(googleApiUrl); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; var encoder = new ASCIIEncoding(); var data = encoder.GetBytes(url); req.ContentLength = data.Length; req.GetRequestStream().Write(data, 0, data.Length); var resp = (HttpWebResponse)req.GetResponse(); var status = resp.StatusDescription; if (status == "OK") { var responseStream = resp.GetResponseStream(); if (responseStream != null) { var tokenResponse = new StreamReader(responseStream).ReadToEnd(); var token = JToken.Parse(tokenResponse); WorkContext.GoogleAnalyticAccessToken = token["access_token"].ToString(); return(new GoogleAnalyticDashboardModel { AccessToken = WorkContext.GoogleAnalyticAccessToken, IsSetup = true, IsSetupInformationValid = true }); } } } catch (Exception exception) { return(new GoogleAnalyticDashboardModel { IsSetup = true, IsSetupInformationValid = false, Message = exception.Message }); } } return(new GoogleAnalyticDashboardModel { IsSetup = false, IsSetupInformationValid = false }); }
/// <summary> /// Load complex setting /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T SValue <T>() where T : ComplexSetting { return(_siteSettingService.LoadSetting <T>()); }