Skip to content

Commit

Permalink
Added gravatar helper and fixed so permalinks are generated from navi…
Browse files Browse the repository at this point in the history
…gation title of set.
  • Loading branch information
tidyui committed Jan 31, 2012
1 parent 51b69c9 commit 7c7a6d5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Data/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static IDbConnection OpenConnection(string name = "piranha") {
/// </summary>
/// <param name="name">Optional name of the connection string to use</param>
/// <returns>An open transaction</returns>
public static IDbTransaction OpenTransaction(string name = "default") {
public static IDbTransaction OpenTransaction(string name = "piranha") {
return OpenConnection().BeginTransaction() ;
}

Expand Down
3 changes: 2 additions & 1 deletion Models/Manager/PageModels/EditModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public virtual bool SaveAll() {
try {
Page.Save(tx) ;
if (Permalink.IsNew)
Permalink.Name = Permalink.Generate(Page.Title) ;
Permalink.Name = Permalink.Generate(!String.IsNullOrEmpty(Page.NavigationTitle) ?
Page.NavigationTitle : Page.Title) ;
Permalink.Save(tx) ;
foreach (Region r in PageRegions)
r.Save(tx) ;
Expand Down
1 change: 0 additions & 1 deletion Piranha.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@
<EmbeddedResource Include="Areas\Manager\Content\Js\Ext\jquery-ui-1.8.16.custom.min.js" />
<EmbeddedResource Include="Areas\Manager\Content\Js\Ext\jquery.equalheights.js" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
38 changes: 33 additions & 5 deletions WebPages/PiranhaHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.WebPages;
Expand All @@ -15,18 +16,45 @@ namespace Piranha.WebPages
/// </summary>
public class PiranhaHelper
{
#region Inner classes
/// <summary>
/// Gravatar helper.
/// </summary>
public class GravatarHelper {
/// <summary>
/// Gets the image URL for the gravatar with the given email
/// </summary>
/// <param name="email">The gravatar email</param>
/// <param name="size">Optional size</param>
/// <returns>The image URL</returns>
public IHtmlString Image(string email, int size = 0) {
string hash = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(email.Trim().ToLower(), "MD5") ;
return new HtmlString("http://www.gravatar.com/avatar/" + hash.ToLower() +
(size > 0 ? "?s=" + size : "")) ;
}
}
#endregion

#region Members
private HtmlHelper Html ;
private WebPage Parent ;
#endregion

#region Properties
/// <summary>
/// Gets the gravatar helper
/// </summary>
public GravatarHelper Gravatar { get ; private set ; }
#endregion

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="html"></param>
public PiranhaHelper(WebPage parent, HtmlHelper html) {
Parent = parent ;
Html = html ;
Gravatar = new GravatarHelper() ;
}

/// <summary>
Expand Down Expand Up @@ -85,8 +113,8 @@ public IHtmlString Head() {
/// <param name="id">The content id</param>
/// <param name="size">Optional image size</param>
/// <returns>The content url</returns>
public IHtmlString Media(Guid id, int size = 0) {
Content cnt = Content.GetSingle(id) ;
public IHtmlString Content(Guid id, int size = 0) {
Content cnt = Models.Content.GetSingle(id) ;

if (cnt != null)
return new HtmlString(Parent.Href("~/media/" + id.ToString() + (size > 0 ? "/" + size.ToString() : ""))) ;
Expand All @@ -99,8 +127,8 @@ public IHtmlString Media(Guid id, int size = 0) {
/// <param name="id">The content id</param>
/// <param name="size">Optional image size</param>
/// <returns>The content url</returns>
public IHtmlString Media(string id, int size = 0) {
return Media(new Guid(id), size) ;
public IHtmlString Content(string id, int size = 0) {
return Content(new Guid(id), size) ;
}

/// <summary>
Expand All @@ -110,7 +138,7 @@ public IHtmlString Media(string id, int size = 0) {
/// <param name="size">Optional size</param>
/// <returns>The image html string</returns>
public IHtmlString Thumbnail(Guid id, int size = 0) {
Content cnt = Content.GetSingle(id) ;
Content cnt = Models.Content.GetSingle(id) ;

if (cnt != null)
return new HtmlString(String.Format("<img src=\"{0}\" alt=\"{1}\" />", Parent.Href("~/thumb/" +
Expand Down

0 comments on commit 7c7a6d5

Please sign in to comment.