Adding a newspaper
The newspaper is designed to be used in specialized layouts. When you create a new newspaper the default view is actually geared toward the website maintainters instead of your visitors.
The best way to use the newspaper in your site is to call it from a template in a directory. Say you want to create a homepage for a company and you want to include a newspaper on that homepage. You start with a directory for the company, e.g. /yac/ (which stands for Yet Another Company). In this directory you create a newspaper, e.g. /yac/news/.
Now you create a new template 'view.html' for /yac/ like this:
<HTML> <HEAD> <TITLE><pinp> echo $nlsdata->name; </pinp></TITLE> </HEAD> <BODY BGCOLOR="WHITE"> <H1><pinp> echo $nlsdata->name; </pinp></H1> <pinp> ShowPage(); get("news/","show.html"); </pinp> </BODY> </HTML>
Ofcourse Then you need to define the template show.html for the newspaper:
<DL> <pinp> $articles=get_articles("default"); if (is_array($articles)) { while (list($key,$article)=each($articles)) { $article->call("show.html"); } } </pinp> </DL>
There is one important new call in this template, which is only available in the newspaper object:
- get_articles($display)
This call searches the newspaper for all articles which are now 'current' in the given 'display phase'. To understand this you'll need to know something about how articles are created.
The display phases are defined in /system/newspaper/displays/. The normal distribution of Ariadne defines only one display: 'Default' with the value 'default'. These display phases are then used in the scenario's, which are defined in /system/newspaper/scenarios/. The normal distribution of Ariadne again defines two scenario's: 'News', and 'Announcement'.
If you edit a scenario, you'll see a short form with a name and priority field, and also a list of defined display phases with a start and end value. What happens is that each article must follow a certain scenario in it's 'life'. The scenario defines how important the article is (the priority field) and through which display phases it moves. For each display phase you can tell the scenario how many days before the start time and after the end time of the article it is active in that phase.
Now when an article is saved, it sets a property for each display phase entered in the scenario with the phase and a start and end time. These times are calculated from the start and end time of the article combined with the start and end times for the display phase in the given scenario.
e.g. The 'News' scenario has only one display phase: 'default'. In this phase an article is 'active' starting 0 days before the starttime of the article itself untill 14 days after the end time of the article. In the 'Announcement' scenario, this works just the other way around. Here the article becomes active 14 days before the starttime of the article, and disappears immediately after the endtime.
This means that if you create a new article with scenario 'News' you'll only need to enter the startdate and time, and the article will be visible from that time, for 14 days. For an announcement, all you need to enter is the start and end date and time of the event you are announcing, and the announcement will be visible 14 days before the event, and disappear just as the event is scheduled to end.
So thats how get_articles finds your articles. The result is an array of objects, in this case all of them articles. You can then call methods on the articles, or get data from them, by prefixing '$article->' to all the normal methods and variables that an article object has. e.g. $article->name, $article->summary, but also $article->ShowPage(), $article->find(), etc. In this case the method called is 'call()', allowing you to apply a template on the article directly.
Now that that's explained, let's go back to the templates. There is now a template for the homepage of YAC and for the news list, but not for the articles themselves. A simple object template for an article might be:
<DT><pinp> echo $nlsdata->name; </pinp> <DD><pinp> echo $nlsdata->summary; </pinp>
Remember to set the template as default for all children.
Combined with the previous templates this will display a simple list of news items, ordered by date and priority. But you'll see that there's no link to the news items, as you might have entered a whole page of data with an item. You could ofcourse simply define the name as a link to the whole article, but wouldn't it be nicer if you could define a phrase in the summary to use as a link? Well you can..
Change the show.html template for articles as follows:
<DT><pinp> echo $nlsdata->name; </pinp> <DD><pinp> echo $nlsdata->summary; </pinp>
And create a new article. Select a phrase in the summary of the article to use as a link and add '' and ' ' around that phrase. Now go back to the news list and you'll see your phrase is now a link to the whole article.
The next step is to create an archive of your newspaper. For this we'll define a new template called 'archive.html' on the newspaper object:
<HTML> <HEAD> <TITLE>Archive</TITLE> </HEAD> <BODY BGCOLOR="WHITE"> <H1>Archive</H1> <FORM> Start : <INPUT TYPE="TEXT" NAME="start"> End : <INPUT TYPE="TEXT" NAME="end"> </FORM> <DL> <pinp> $start=getvar("start"); $end=getvar("end"); if (!$start) { $start=-14; // 14 days ago } if (!$end) { $end=0; } $startdate=time()+($start*24*60*60); $enddate=time()+($end*24*60*60); $articles=get_articles("default", 20, $startdate, $enddate); if (is_array($articles)) { while (list($key,$article)=each($articles)) { $article->call("show.html"); } } </pinp> </DL> </BODY> </HTML>
As you can see, we've taken the previously defined show.html template for pnewspaper, added some HTML and a form and used the call to get_articles with a few extra arguments, it is defined as:
array get_articles(string $display, int $max=0, int $start=0, int $end=0)
The first argument is the display phase you want, the second is the maximum number of articles you want returned, with 0 meaning 'all articles'. The third and fourth argument are the start and enddate to use for the given display phase.
If the start and enddate are equal, you get a snapshot of what your newspage looked like on an exact moment in time, but if you use a range, like we do in this template, you'll get a list of all articles which were 'active' at some time in that range.
For a nice archive you'll probably want a better way to select the start and enddate, but for the purpose of this tutorial this suffices.