How to Add a New Page to SF-Active : sf-active
IMC / INFORMATION WARFARE MUNITIONS
sf-active :: indymedia
english | castellano | italian | Nederlands
download : documentation : support
irc : cvs : bugs : faq : servers
latest articles : sf-active sites
about sf-active
sf-active is a collection of object-oriented classes for content management, open publishing and news syndication. All the pages needed to run an indymedia site are distributed with the code

other links
indymedia codebases
indymedia global tech

software, politica e indymedia





printable version - email this article

How to Add a New Page to SF-Active
by gek Wednesday, Nov. 26, 2003 at 9:32 AM
gekked@indymedia.org

This is a step-by-step instruction on how to add a new page to sf-active with our current code architecture.

HOW TO MAKE A PAGE WITH THE NEW SF-ACTIVE FRAMEWORK

This is a more detailed document about how to make pages with the new sf-active framework. It is aimed at developers.

CODE STANDARDS:
Briefly, I have been doing 4-space indent, spaces instead of tabs, and you can look at classes/article_class.php for more formatting. I have been trying to make object variables protected even though php doesn't enforce it. You will see there is a lot of shortcuts going on with object variables.

MAKING A PAGE, STEP BY STEP:
First, there are now four files associated with a new sf-active webpage:

  1. webpage.tpl - the template file which goes in local/templates/pages/
  2. webpage.dict - the page-specific translation file, you might not need this one. in shared/dictionary/[es|en]/
  3. webpage.inc - the new class for the webpage code, in shared/classes/pages/
  4. webpage.php - the actual page in the document tree, admin ones are a little different.
Here is how you go through the process to make these files:
  1. Create the webpage template. For converting from previous sf-active pages, what I do is copy the entire html part of the existing file and paste it into a new file. Then, I remove all php code ... what can be replaced with a simple template variable, I replace with a template variable. If this is a new page, I just put the HTML for it in here.
  2. Create the dictionary file. Once I go through the template, I have a few variables I know I can put in the dictionary file. Note that you might not need a page-specific dictionary file, if all the general terms can be put into common.inc for that language.
  3. Create the PHP file. This is easy so I set it up, basically copy an existing one and replace the page name passed to the Page() constructor.
  4. Create the INC class file. This is the hard part. In a nutshell, you want to put all code in the execute() method. This method should do all the logic needed for a page AND set all the relevant template variables. That's it. The page class does everything else (i.e. merge it with the template, build the html, etc). See below for some important notes on this.
NOTES ABOUT WRITING PAGE CLASSES
The hard part with converting old sf-active pages is taking out all the old echo statements and making that stuff be displayed through the template. Once you got that, keep these things in mind:
  1. There is a new way to display paths. All the old path formats should be replaced. Most paths are represented through a php constant, which can be referenced as: SF_INCLUDE_PATH
  2. Include statements should instead use sf_include_file() ... this will apply the appropriate templating and internationalization
  3. You should set up your devbox to be latest PHP4 with strict new variables (the default install). This means that in a form with variable formvar, $formvar will not work but $_POST['formvar'] will work. Also, $HTTP_POST_VARS['formvar'] will not work.
  4. To set template variables in the page class, assign variables to $tkeys associative array. So, for instance, if I want to set a random message to be displayed, I do $this->tkeys['random_message'] = "This is a random message." However, to apply translation, I would do $this->tkeys['random_message'] = $tr->trans['random_message']
  5. How do you build dynamic form elements with templates? See Cache::make_select_form() and Cache::make_checkbox_form()
  6. Also, the "update" from a form and error from a form is standardized. See Cache::update_status(), Cache::update_error_status() and their affiliated methods.
NOTES ABOUT TRANSLATION
There are a number of sources that all go together to give you a translation table when you are writing a page class. These are:
  1. common.dict is always included for a language, these are generic terms that more than one page uses
  2. pagename.dict is included if it exists
  3. Whatever you assign to $pagename->tkeys, an associative array, is also available in the template
  4. See the Translation class for more information, including how to use the Translation::trans() method.

add your comments


LATEST COMMENTS ABOUT THIS ARTICLE
Listed below are the 10 latest comments of 20 posted about this article.
These comments are anonymously submitted by SF-IMC website visitors.
TITLE AUTHOR DATE
Hi all http://www.zayfa.com/flower/9952/Flower.html Pinho Saturday, Nov. 25, 2006 at 4:17 AM
Hello, nice site look this: [URL="http://www.cheapphentermine.kokoom.com/"]buy Britney Friday, Nov. 24, 2006 at 11:07 AM
http://forum.lixium.fr/cgi-bin/liste.eur?gifts Christmas Gifts Thursday, Nov. 23, 2006 at 6:53 PM
truck part service Usa Thursday, Nov. 23, 2006 at 3:42 PM
Christmas Paolo M. Thursday, Nov. 23, 2006 at 12:36 AM
Christmas Paolo M. Wednesday, Nov. 22, 2006 at 6:07 PM
Hi all Ali Tuesday, Nov. 21, 2006 at 6:05 AM
Hello, thank you Nana Tuesday, Nov. 21, 2006 at 1:53 AM
http://www.easterngp.co.uk/board/messages/3/replica-watches-1675.html replica watches Monday, Nov. 20, 2006 at 5:09 PM
http://wiki.exist-db.org/space/autocheapinsurance/auto+cheap+insurance.htm http://www.blo auto cheap insurance Saturday, Nov. 18, 2006 at 12:40 AM
pick a theme:

Latest Newswire
Publish your news
View Latest Comments