Site news administration
We will start from the easiest one - the site news only containing text. We have three modules to write: a list module, an update form module and a db update module. Only two of these will produce output but we shall write them as modules anyhow as we want to reserve the option of adding output to the update module as well.
News List module
The news list module needs a few icons, preferably
16x16px. The "show record" link needs an icon called arrow_down.png, the delete link needs delete.png and the edit link respectively edit.png. You can use whatever images you want but using the default image in the icon directory saves a few lines of code.
The module is surprisingly short for this task:
news_list_module.php
... wait a moment...
Some lines need clarification, presumably.
The most important thing to have is the inclusion of the
DataBrowser class. Another thing to note is the creation of the edit links. They have been created with the convention of adding an editact parameter which can be "insert", "edit" or "delete". These lines will make sure that you have buttons created for the purpose. The edit and delete buttons (or icons) will the last be on the data grid row and the insert button will be below the grid.
The
addColumn method parameters areaddColumn(<heading text>, <width>, <type>, <show>,[ <callback>[, <parm>]]);
The
heading text parameter simply sets the column heading text, say "Email address", for instance.
The
width parameter can be absolute (like 100 or "100") or any valid HTML width value like "50%".
Some common column
types and how they are handled are
"text" |
Just the plain text
|
|
"
texttohtml" |
newlines are converted to <br /> tags
|
|
"
date" |
Short date using locale set in the config file
|
|
"
time" |
hh:mm:ss
|
|
"
time_hhmm" |
hh:mm
|
|
"
image" |
wraps the <img> tag around the value which must be a full path
|
|
"
email" |
wraps <a href='mailto'…> around the value
|
|
"
url" |
wraps <a href=…> around the value and adds "http" if needed
|
The "
show" parameter is an important one tells what to do with the value.
0 Hide the column and the data
1 Show the data in the grid on the same line
2 Show the data in below the line after the user clicks the arrow down button
3 combination of 1 and 2
The
callback sets a user-defined function where the formatting is done. In the example the article value is fed into function cb_article() and returned newlines replaced by <br />tags. If the callback is in an object (as it is this case) the properties or methods of the object are not visible unless you pass the object itself as an extra parameter ($this). This is a bit tricky but seems to work. Have a look at the Menu Editor example later.
If there is an
id parameter in the URL the user has pressed the "show full record" button (arrow down) and setActiveRecord advices the object to open a full record between the grid lines under the "active record".
But where is the template? No problem. The template is in the package, just uncompress it to
/admin/templates and that's it. It will be rewritten some day but it will do for the time being.
The current template implementation needs a few CSS definitions and a few are still missing. Here is the current DataBrowser set, change them if you wish.
.info {
font-family : Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size : 14px;
font-weight:bold;
text-align:center;
vertical-align:middle;
padding:4px;
color : #7F97B9;
background-color : #FDF9F2;
border-color : #C2CFDD #C2CFDD #C2CFDD #C2CFDD;
border-width : 1px 2px 2px 1px;
border-style: solid;
}
.alert {
font-family : Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size : 14px;
font-weight : bold;
text-align:center;
vertical-align:middle;
padding: 4px;
color : #7B1D00;
background-color : #FFAF47;
border-color : #FFE4B5 #7B4E00 #7B4E00 #FFE4B5;
border-width : 1px 2px 2px 1px;
border-style : solid solid solid solid;
}
/* data browser */
.databrowser { }
table.databrowser td { padding:4px; vertical-align:top }
.databrowser th {text-align:left; font-weight:bold; color:#fff}
tr.dbheading {background-color:#60490E;}
tr.dbheading th {padding:2px;}
tr.dbodd { background-color:#fff; }
tr.dbeven { background-color:#ddd; }
The "_info" and "_alert" are special cases for displaying information or error messages from the DBUpdate process when the process uses the header() to redirect the browser back to the DataBrowser view. After you have finiished with the code, yo can test the functionality simply by typing:
http://?act=list_news&_alert=Beware of the big bad wolf http://?act=list_news&_info=Complete Success
This is a quick and dirty way of informing the user. Okay, now let's write the news edit module but before that we will have a look at what the grid should look like:

And here is another: the parameter &alert=Beware of the big bad wolf has been appended to the URL

Update
The latest version of the DataBrowser class lets you create the edit, delete and update links using a shortcut. One single line:
$dataBrowser->createStandardLinks("edit_news");
will create all the three links and you only need to set the insert button text - if you need to change it from "Add item";