|
|
 Rank: Fanatic
Joined: 9/17/2007 Posts: 265 Location: London, UK.
|
Hi, could someone explain to me how the sample umbracoBlog package manages to automatically create the date folders when making a post?
Thanks and have a good weekend.
Richard
2 * 3 * 3 * 37 : The prime factorisation of The Beast.
|
|
 Rank: Devotee
Joined: 7/20/2006 Posts: 76 Location: Italy
|
I uses a actionhandler. I found on google archive a blog post from Daniel Bjornbakk http://64.233.169.104/search?q=cache:Y-3OACWOsVkJ:weblog.151278.org/snippets-library/umbraco-hacks/archive-date-folder-actionhandler.aspx+umbraco+actionhandler&hl=is&ct=clnk&cd=2&gl=is&client=firefox-a
"We come from the land of the ice and snow, From the midnight sun where the hot springs blow"
|
|
Rank: Devotee
Joined: 9/12/2007 Posts: 58 Location: Honoluu, HI
|
the umbracoblog uses an action handler that moves the blog item into the proper folder (based on the create date) during the action new event.
|
|
 Rank: Fanatic
Joined: 9/17/2007 Posts: 265 Location: London, UK.
|
Aha! That makes sense. Very interesting.
Unfortunately, although the link above works, the page is broken and I can't access any of the links on it... Do you have another link?
Richard
2 * 3 * 3 * 37 : The prime factorisation of The Beast.
|
|
Rank: Devotee
Joined: 9/12/2007 Posts: 58 Location: Honoluu, HI
|
Here is the umbraco Blog code in C#. The execute method is the one that does all work. I hope this help :D Code: public bool Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action) { if (documentObject.ContentType.Alias == "umbracoBlogPost") {
if (new Document(documentObject.Parent.Id).ContentType.Alias != "umbracoBlogDateFolder") { string[] refNr = (documentObject.CreateDateTime.Year.ToString() + "-" + documentObject.CreateDateTime.Month.ToString() + "-" + documentObject.CreateDateTime.Day.ToString()) .Split("-".ToCharArray()); if (refNr.Length == 3) { // Check if year exists Document year = null; foreach(umbraco.BusinessLogic.console.IconI i in documentObject.Parent.Children) { if (i.Text == refNr[0]) { year = new Document(i.Id); break; } }
if (year == null) { year = Document.MakeNew(refNr[0], DocumentType.GetByAlias("umbracoBlogDateFolder"), documentObject.User, documentObject.Parent.Id); year.Publish(documentObject.User); umbraco.library.PublishSingleNode(year.Id); } else umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, documentObject.User, documentObject.Id, "executed - year not null");
// Check if month exists Document month = null; foreach(umbraco.BusinessLogic.console.IconI i in year.Children) { if (i.Text == refNr[1]) { month = new Document(i.Id); break; } } if (month == null) { month = Document.MakeNew(refNr[1], DocumentType.GetByAlias("umbracoBlogDateFolder"), documentObject.User, year.Id); month.Publish(documentObject.User); umbraco.library.PublishSingleNode(month.Id); }
// Check if day exists Document day = null; foreach(umbraco.BusinessLogic.console.IconI i in month.Children) { if (i.Text == refNr[2]) { day = new Document(i.Id); break; } } if (day == null) { day = Document.MakeNew(refNr[2], DocumentType.GetByAlias("umbracoBlogDateFolder"), documentObject.User, month.Id); day.Publish(documentObject.User); umbraco.library.PublishSingleNode(day.Id); }
documentObject.Move(day.Id); }
}
return true;
} else return false; }
|
|
Rank: Devotee
Joined: 9/12/2007 Posts: 58 Location: Honoluu, HI
|
I hope niels doesnt mind that I posted his code :blush:
|
|
Rank: Devotee
Joined: 9/12/2007 Posts: 58 Location: Honoluu, HI
|
I hope niels doesnt mind that I posted his code :blush:
|
|
Rank: Devotee
Joined: 2/4/2008 Posts: 38
|
How do I implement this as a .NET user control and make it work when e.g. creating a new news article or so?
Greets.
|
|
 Rank: Devotee
Joined: 12/6/2007 Posts: 62
|
|
|
Rank: Devotee
Joined: 2/4/2008 Posts: 38
|
It's working great now. Thansk :)
|
|
 Rank: Addict
Joined: 2/19/2007 Posts: 819 Location: Belgium
|
You can also use this package: http://forum.umbraco.org/packages/new-package---datefolder-Cheers, Tim
Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
|
|
|
Guest |