On to “The news!” - News via the ModelAdmin

Posted by Simon Erkelens on 8 May 2013

Simon 'Sphere' Erkelens is a freelance developer, fulltime employee of We::Code in the Netherlands with a tertiary background in applied physics. Before that, Simon worked for Squal Media. He started using SilverStripe at the end of 2009. Simon has given multiple presentations on implementing Facebook API into PHP and on SilverStripe's lesser known features. Most of his personal development work is on Github.

I only develop core features. I'm not a front-ender of any kind. And if I have to... well, look at my website. As simple as possible.

 

On to... “The news!”

This news-module is compatible with Silverstripe 3.0.1 up to version 3.1. I wrote it because I got fed up with two things; first, was my own website, second was the most widely used blogmodule. It clutters the SiteTree, making it one big, confusing mess. These two factors encouraged me to write a slimmed-down version of a “news-in-the-sitetree” module.

The module is fully managed from the ModelAdmin. The downside of this decision is I had to make a sacrifice. The module does not track changes in the content. To make sure articles that have a new title still work, included is a Renamed-object, which tracks the changes of the URLSegment, but that's it. This decision, was to keep it a bit more “simple”. Mainly because news is usually just edited to fix typo's, not to fully change.

The news can be setup via the SiteConfig, where Twitter and Facebook (I think Facebook works) can be set up. Although those features require another module of mine. Also the amount of posts-per-page, comment-settings etc can be setup via SiteConfig.

Requirements are in the readme on my github page. Feel free to include anything from the readme config section here if needed/wanted.

Featured is comments on items. The comments are set up with a double anti-spam measure. First, there is the akismet protection as primary. But second, the well known "out of screen" input helps to prevent spam by having an invisible field for normal users, by positioning it absolute at -90000px or something. Spambots, however, do see the field and enter text in them. Entered text means it's a spambot.

Included are several shortcodes, like YouTube, Twitter's official "tweet" implementation, GeSHI code-highlighting via third-party libraries. These can be activated (globally!) or deactivated via the _config.php:

ShortcodeParser::get()->register('tweet',array('NewsHolderPage','TweetHandler'));
ShortcodeParser::get()->register('code',array('NewsHolderPage','GeshiParser'));
ShortcodeParser::get()->register('YT',array('NewsHolderPage','YouTubeHandler'));
ShortcodeParser::get()->register('slideshow', array('NewsHolderPage','createSlideshow'));

And addressed with, for example, [tweet id=326829146376388608] (You can find the ID by clicking the post-date and look at the URL. The full URL is accepted as well and will be split by the code to get the actual ID).

Besides that, there's also an option to create tags. A tagcloud javascript is included to create the tagcloud.

Newsitems are globally addressable with the Controller Extension, with a lot of options on what to show. Random, latest, latest related (via the tags) etc. The items all relate to a Holderpage. This holderpage can be translatable. By creating translatable, a new dropdown appears to set the language of the newspost. Possible future features might be to change the "only on one page" to "link to multiple languages", since English is quite widely accepted.

Furthermore, the post can have a publish from day X, which will then be preferred over the Created date. LastEdited is explicitly ignored in this case. Because often, a LastEdit just means a fix of a typo, no radical changes to the content.

Finally, there are reports. In the SS3 CMS, you can see the Tag-usage and comment-counts on the items created. This includes, for example, spamcount if you have Akismet enabled. Akismet comes included as a third party.

Upcoming is a report with the newsitems that don't have any tags linked. But I have not gotten into that yet.

Examples and more information can be found here:

Post your comment

Note: Comments are moderated and won't show until they are approved

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.