private void SerializeContent(Dictionary <string, object> options) { if (ContentUrl.HasValue()) { options["content"] = new Dictionary <string, object>() { { "url", ContentUrl } }; } else if (ContentHandler.HasValue()) { options["content"] = ContentHandler; } else if (!String.IsNullOrEmpty(ContentTemplateId)) { var idPrefix = "#"; if (IsInClientTemplate) { idPrefix = "\\" + idPrefix; } options["content"] = new ClientHandlerDescriptor { HandlerName = String.Format("kendo.template($('{0}{1}').html())", idPrefix, ContentTemplateId) }; } else if (Content.HasValue()) { options["content"] = HttpUtility.UrlDecode(Content); } }
public string GetFileName() { string extension; if (!TLString.IsNullOrEmpty(Url)) { extension = Path.GetExtension(Url.ToString()); if (!string.IsNullOrEmpty(extension)) { return(ResultId + extension); } } if (!TLString.IsNullOrEmpty(ContentUrl)) { extension = Path.GetExtension(ContentUrl.ToString()); if (!string.IsNullOrEmpty(extension)) { return(ResultId + extension); } } return(ResultId + TLUtils.ContentTypeToFileExt(ContentType)); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (ContentType != null) { hashCode = hashCode * 59 + ContentType.GetHashCode(); } if (ContentUrl != null) { hashCode = hashCode * 59 + ContentUrl.GetHashCode(); } if (Content != null) { hashCode = hashCode * 59 + Content.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (ThumbnailUrl != null) { hashCode = hashCode * 59 + ThumbnailUrl.GetHashCode(); } return(hashCode); } }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Returns HashCode</returns> public override int GetHashCode() { return(String.Format("{0}|{1}|{2}|{3}|", EntityId?.GetHashCode() ?? 0, ContentUrl?.GetHashCode() ?? 0, RemoveUrl?.GetHashCode() ?? 0, WebsiteUrl?.GetHashCode() ?? 0 ).GetHashCode()); }
public bool IsGoogleDoc() { if (!ContentUrl.IsNullOrEmptyOrWhiteSpace()) { if (ContentUrl.Contains("https://docs.google.com/document")) { return(true); } } return(false); }
public override void ToStream(Stream output) { output.Write(TLUtils.SignatureToBytes(Signature)); Url.ToStream(output); ThumbUrl.ToStream(output); ContentUrl.ToStream(output); ContentType.ToStream(output); W.ToStream(output); H.ToStream(output); }
public bool Published() { if (IsPublished) { return(true); } if (IsGoogleDoc() && ContentUrl.Contains("edit")) { return(false); } return(false); }
/// <summary> /// Take the result of the ie (may be modified) and resolve all unresolved /// references (URLs, playlist items). /// It will also download the videos if 'download'. /// </summary> /// <returns>Returns the resolved ie_result.</returns> public async Task <InfoDict> ProcessIEResult(InfoDict ie_result, bool download = true, Dictionary <string, object> extra_info = null) { if (ie_result.GetType() == typeof(ContentUrl) || ie_result.GetType() == typeof(TransparentUrl)) { ContentUrl url = (ContentUrl)ie_result; url.Url = Util.SanitizeUrl(url.Url); if (Options.ExtractFlat != null) { if ((Options.ExtractFlat == "in_playlist" && extra_info != null && extra_info.ContainsKey("playlist")) || (Options.ExtractFlat.ToUpper() == "TRUE")) { if (Options.ForceUrl && url.Url != null) { LogInfo(url.Url); } return(ie_result); } } } if (ie_result is Video video) { video.AddExtraInfo(extra_info, false); return(await ProcessVideoResult(video, download).ConfigureAwait(false)); } else if (ie_result is ContentUrl curl) { return(await ExtractInfoAsync(curl.Url, download, curl.IEKey, extra_info).ConfigureAwait(false)); } else if (ie_result is TransparentUrl turl) { var info = await ExtractInfoAsync(turl.Url, false, turl.IEKey, extra_info, false).ConfigureAwait(false); if (info == null) { return(info); } // *force properties* //if (info.Type == "url") //{ // info.Type = "url-transparent"; //} return(await ProcessIEResult(info, download, extra_info).ConfigureAwait(false)); } else if (ie_result is Playlist playlist) { return(await ProcessPlaylistResult(playlist, download).ConfigureAwait(false)); } return(null); }
public override void ToStream(Stream output) { output.Write(TLUtils.SignatureToBytes(Signature)); Id.ToStream(output); ResultId.ToStream(output); Type.ToStream(output); ThumbUrl.ToStream(output); ContentType.ToStream(output); ContentUrl.ToStream(output); Url.ToStream(output); Attributes.ToStream(output); }
/// <summary> /// Returns true if Attachment instances are equal /// </summary> /// <param name="other">Instance of Attachment to be compared</param> /// <returns>Boolean</returns> public bool Equals(Attachment other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( ContentType == other.ContentType || ContentType != null && ContentType.Equals(other.ContentType) ) && ( ContentUrl == other.ContentUrl || ContentUrl != null && ContentUrl.Equals(other.ContentUrl) ) && ( Content == other.Content || Content != null && Content.Equals(other.Content) ) && ( Name == other.Name || Name != null && Name.Equals(other.Name) ) && ( ThumbnailUrl == other.ThumbnailUrl || ThumbnailUrl != null && ThumbnailUrl.Equals(other.ThumbnailUrl) )); }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (string.IsNullOrEmpty(FileName) ? 0 : FileName.GetHashCode()); hashCode = (hashCode * 397) ^ FileSize.GetHashCode(); hashCode = (hashCode * 397) ^ (string.IsNullOrEmpty(ContentType) ? 0 : ContentType.GetHashCode()); hashCode = (hashCode * 397) ^ (Author == null ? 0 : Author.GetHashCode()); hashCode = (hashCode * 397) ^ (CreatedOn == null ? 0 : CreatedOn.Value.GetHashCode()); hashCode = (hashCode * 397) ^ (string.IsNullOrEmpty(Description) ? 0 : Description.GetHashCode()); hashCode = (hashCode * 397) ^ (string.IsNullOrEmpty(ContentUrl) ? 0 : ContentUrl.GetHashCode()); return(hashCode); } }
public ActionResult Urls(ContentUrlsViewModel model) { if (!User.IsInRole("artikel-administrator")) { return RedirectToRoute("ContentIndex"); } var content = _entities.Contents .Include(c => c.Urls) .FirstOrDefault(c => c.Id == model.ContentId); if (content == null) { return RedirectToRoute("ContentIndex"); } if (ModelState.IsValid) { // remove leading and trailing slashes model.UrlName = model.UrlName.Trim(' ', '/'); var urls = _entities.ContentUrls.Where(u => u.Url == model.UrlName).Include("Content"); if (!urls.Any() || urls.First().Enabled == false) { // Remove Urls with the same name, if they were disabled before _entities.ContentUrls.RemoveRange(urls); var url = new ContentUrl { Url = model.UrlName, ContentId = content.Id, Type = model.SetDefault ? UrlType.Default : UrlType.Alternative, Enabled = true }; if (model.SetDefault) { if (content.DefaultUrl != null && content.DefaultUrl.Type != UrlType.System) { content.DefaultUrl.Type = UrlType.Alternative; } content.DefaultUrl = url; } _entities.ContentUrls.Add(url); _entities.SaveChanges(); model.Saved = true; } else { ViewBag.Error = String.Format("Die URL {0} existiert bereits.", model.UrlName); } } model.Content = content; model.IsContentAdministrator = User.IsInRole("artikel-administrator"); return View("~/Areas/mitarbeit/Views/Content/Urls.cshtml", model); }
public ActionResult Edit(ContentEditViewModel model) { Content content = null; if (ModelState.IsValid) { ContentVersion latestVersion = null; if (model.ContentId == null) { // Create a new Content Object if there is none var c = new Content { Version = 1, EditPermissionId = null, Published = DateTime.MinValue, PublishedByUserId = null, Created = DateTime.Now, AuthorUserId = User.Identity.GetUserId<int>(), UnparsedContent = "", StylesheetCss = "" }; content = _entities.Contents.Add(c); var v = new ContentVersion { ContentId = content.Id, UserId = content.AuthorUserId, UnparsedContent = "", StylesheetCode = "", Title = "", Description = "", Teaser = "", Notes = "" }; latestVersion = _entities.ContentVersions.Add(v); _entities.SaveChanges(); model.ContentId = content.Id; var url = new ContentUrl { Url = String.Format("inhalt/{0}", content.Id), ContentId = content.Id, Type = UrlType.System, Enabled = true }; _entities.ContentUrls.Add(url); content.DefaultUrl = url; } else { // Try to find the existing content object var result = _entities.Contents .Include("EditPermission") .Include("Boilerplates") .Include("BoilerplatesUsed") .Where(c => c.Id == model.ContentId); if (result.Any()) { content = result.First(); if (content.EditPermission != null && !User.IsInRole(content.EditPermission.Name)) { return RedirectToRoute("ContentIndex"); } } else { return RedirectToRoute("ContentIndex"); } } if (User.IsInRole("artikel-administrator")) { if (model.Status == ContentStatus.Published && content.Status != ContentStatus.Published) { // Publish the content content.Published = DateTime.Now; content.PublishedByUserId = User.Identity.GetUserId<int>(); } else if (model.Status != ContentStatus.Published && content.Status == ContentStatus.Published) { // Unpublish the content content.Published = DateTime.MinValue; content.PublishedByUserId = null; } var permission = _entities.Roles.FirstOrDefault(r => r.Id == model.PermissionId); if (permission != null && permission.Metapermission.Name == "mitarbeiter") { content.EditPermissionId = model.PermissionId; } if (string.IsNullOrEmpty(model.Url) && model.Status == ContentStatus.Published) { if (model.Type == ContentType.News) { // Default url is /news/-/1234 model.Url = "-"; } } if (!string.IsNullOrEmpty(model.Url)) { model.Url = model.Url.Trim('/'); if (model.Type == ContentType.News && !Regex.IsMatch(model.Url, @"news/[a-zA-Z0-9_\-/]+/\d+")) { model.Url = String.Format("news/{0}/{1}", model.Url, content.Id); } if (content.DefaultUrl == null || content.DefaultUrl.Url != model.Url) { var duplicates = _entities.ContentUrls .Where(u => u.Url == model.Url); if (!duplicates.Any() || duplicates.First().Enabled == false) { _entities.ContentUrls.RemoveRange(duplicates); var url = new ContentUrl { ContentId = content.Id, Enabled = true, Type = UrlType.Default, Url = model.Url }; if (content.DefaultUrl != null && content.DefaultUrl.Type == UrlType.Default) { content.DefaultUrl.Type = UrlType.Alternative; } content.DefaultUrl = _entities.ContentUrls.Add(url); } else { ModelState.AddModelError("Url", "Die gewählte URL existiert bereits."); } } } } else { // Normal editors cannot change these options model.HomePageOptions = content.HomePageOptions; model.PermissionId = content.EditPermissionId; model.Url = content.DefaultUrl.Url; // Normal editors cannot un-publish content if (model.Status != ContentStatus.Published && content.Status == ContentStatus.Published) { model.Status = content.Status; } } // Update Database Fields model.UpdateContent(content); content.Updated = DateTime.Now; int userId; if (content.Version > 0) { latestVersion = latestVersion ?? _entities.ContentVersions.Where(v => v.ContentId == content.Id).OrderByDescending(v => v.Updated).First(); userId = latestVersion.UserId; } else { userId = content.AuthorUserId; } try { content.CompileLess(); } catch (ArgumentException) { ViewBag.Error = "Dein artikelspezifischer CSS-Code enthält Fehler und wurde daher nicht in den Artikel übernommen (aber in der Datenbank gespeichert)."; } content.Parse(); // Calculate Changes int updateCharsDeleted = 0; int updateCharsInserted = 0; double updateMagnificance = 0; if (latestVersion != null) { var dmp = new diff_match_patch(); var diffs = dmp.diff_main(latestVersion.UnparsedContent ?? "", model.UnparsedContent ?? ""); foreach (var diffItem in diffs.Where(diffItem => diffItem.text.Trim().Length != 0)) { switch (diffItem.operation) { case Operation.DELETE: { updateCharsDeleted += diffItem.text.Length; break; } case Operation.INSERT: { updateCharsInserted += diffItem.text.Length; break; } } } updateMagnificance = Math.Min(updateCharsInserted * 0.9 / Math.Max(1, latestVersion.UnparsedContent.Length) + updateCharsDeleted * 0.1 / Math.Max(1, latestVersion.UnparsedContent.Length), 1); updateMagnificance = Math.Min(1, Math.Tan(updateMagnificance)); } // If the user was not the one who updated last we have to create a new version if (userId != User.Identity.GetUserId<int>()) { content.Version++; latestVersion = new ContentVersion { ContentId = content.Id, Title = content.Title, Version = content.Version, UnparsedContent = content.UnparsedContent, ParsedContent = content.ParsedContent, Description = content.Description, StylesheetCss = content.StylesheetCss, StylesheetCode = content.StylesheetCode, Teaser = content.Teaser, UserId = User.Identity.GetUserId<int>(), Note = content.Notes, Updated = DateTime.Now, UpdateMagnificance = updateMagnificance, UpdateCharsChanged = updateCharsInserted, UpdateCharsDeleted = updateCharsDeleted }; _entities.ContentVersions.Add(latestVersion); } else { if (latestVersion != null) { model.UpdateContentVersion(latestVersion); latestVersion.Version = content.Version; latestVersion.ParsedContent = content.ParsedContent; latestVersion.StylesheetCss = content.StylesheetCss; latestVersion.Updated = DateTime.Now; latestVersion.UpdateMagnificance = updateMagnificance; latestVersion.UpdateCharsChanged = updateCharsInserted; latestVersion.UpdateCharsDeleted = updateCharsDeleted; } } // Save all Changes _entities.SaveChanges(); } model.Saved = ModelState.IsValid; model.Categories = model.Categories ?? _entities.ContentCategories.OrderBy(c => c.OrderingPosition); model.IsContentAdministrator = User.IsInRole("artikel-administrator"); // Remove status options the user cannot use var statusOptions = Enum.GetValues(typeof(ContentStatus)) .OfType<ContentStatus>(); if (content != null) { if (!model.IsContentAdministrator) { statusOptions = content.Status == ContentStatus.Published ? statusOptions.Where(e => e == ContentStatus.Published) : statusOptions.Where(e => e != ContentStatus.Published); } } else { statusOptions = statusOptions.Where(e => e != ContentStatus.Published); } model.ContentStatusList = statusOptions.Select(e => new SelectListItem { Text = e.GetDisplayName(), Value = ((int)e).ToString() }); model.ContentPermissionList = _entities.Roles .Where(r => r.Metapermission.Name == "mitarbeiter") .Select(r => new SelectListItem { Text = r.FriendlyName, Value = r.Id.ToString() }); return View("~/Areas/mitarbeit/Views/Content/Edit.cshtml", model); }