Documentation: overlays/overlay.php
- Class Overlay - The overlay interface used by articles
- Overlays/overlay.php - Attributes specific to this overlay
- Allows() - Allow or block operations
- Bind() - Create a new overlay from scratch
- Export() - Export an overlay as XML
- Get_extra_text() - Text to be inserted aside
- Get_fields() - Build the list of fields for one overlay
- Get_id() - Identify one instance
- Get_label() - Get an overlaid label
- Get_list_text() - Display the content of one overlay in a list
- Get_live_introduction() - Display a live introduction
- Get_live_title() - Display a live title
- Get_tabs() - Add some tabbed panels
- Get_text() - Display the content of one overlay
- Get_trailer_text() - Text to come after page description
- Get_type() - Retrieve overlay type
- Get_view_text() - Display the content of one overlay in main view panel
- Load() - Restore an instance
- Parse_fields() - Capture form content
- Render() - Render some page component
- Remember() - Remember an action once it's done
- Save() - Serialize overlay content
class Overlay - The overlay interface used by articles
Overlays are a straightforward way to extend YACS content pages. For example, articles can be transformed to recipes, or to other pages that has to include some structured data.Overlay data is saved along standard articles as a serialized snippet. The encoding and decoding of this field requires a specialized class.
The overlay interface masks these details and offers convenient methods to create, access and save piggy-back data.
As visible in articles/edit.php, the creation of a new overlay or the update of an existing one is achieved through following sequence:
// create a new overlay
$overlay = Overlay::bind($overlay_type);
// get form fields used to updated the overlay
$fields = $overlay->get_fields($item);
// get a label for some ordinary field
$label = $overlay->get_label('title', 'edit');
...
// process posted data
$overlay->parse_fields($_POST);
// save article and serialized overlay as well
$_POST['overlay'] = $overlay->save();
$_POST['overlay_id'] = $overlay->get_id();
Articles::post($_POST);
// save overlay state
$overlay->remember('insert', $item);
As visible into articles/view.php, an overlay is handled with following calls:
// extract overlay data from a record
$overlay = Overlay::load($item);
// get text related to this instance
$text = $overlay->get_text('view');
// get additional tabs
$text = $overlay->get_tabs('view');
Also, post-processing steps can include the removal of the hosting record, as shown in articles/delete.php
// extract overlay data from a record
$overlay = Overlay::load($item);
// post-processing steps specific to the overlay
$overlay->remember('delete', $item);
As a consequence, this class has two constructors:
bind()-- create an instance from scratchload()-- create an instance from one article of the database
The interface itself is made of following member functions, that have to be overloaded into child functions:
allows()-- re-enforce access rightsget_extra_text()-- to be integrated into page sideget_fields()-- build a form to modify overlay contentget_id()-- to retrieve an overlayget_label()-- specialize the overlaid pageget_list_text()-- to be integrated into a list of itemsget_live_introduction()-- change page introductionget_live_title()-- change page titleget_tabs()-- add information in panelsget_text()-- use overlay data in normal pagesget_trailer_text()-- to be appended after the descriptionget_type()-- basic informationget_view_text()-- to be integrated into the main page, between introduction and descriptionparse_fields()-- capture form contentrender()-- delegate rendering to the overlayremember()-- for specific post-processing steps
Following functions are aiming to simplify external calls:
export()-- to generate some XMLsave()-- to serialize overlay content
This script is a reference file of this system.
License: GNU Lesser General Public License
Authors:
- Bernard Paques
- GnapZ
Testers:
- Neige1963
overlays/overlay.php - Attributes specific to this overlay
allows() - Allow or block operations
function allows($type, $action)
- $type - string the kind of item to handle ('decision', ...)
- $action - string the foreseen operation ('edit', 'new', ...)
- returns TRUE if the operation is accepted, FALSE otherwise
bind() - Create a new overlay from scratch
function bind($type)
- $type - string overlay type
- returns a brand new instance
foo', the script file 'overlays/foo.php' is loaded.Example:
// create a new overlay
$overlay = Overlay::bind('recipe');
The provided string may include parameters after the type. These parameters, if any, are saved along overlay attributes.
Example:
// this overlay will preserve past events
$overlay = Overlay::bind('day without_past_dates');
See also:
export() - Export an overlay as XML
function export()
- returns some XML to be inserted into the resulting page
get_extra_text() - Text to be inserted aside
function &get_extra_text($host=NULL)
- $host=NULL - array the hosting record, if any
- returns some HTML to be inserted into the resulting page
get_fields() - Build the list of fields for one overlay
function get_fields($host)
- $host - the hosting attributes
- returns a list of ($label, $input, $hint)
See also:
get_id() - Identify one instance
function get_id()
This function returns a string that identify uniquely one overlay instance. When this information is saved, it can be used later on to retrieve one page and its content.@returns a unique string, or NULL
See also:
get_label() - Get an overlaid label
function get_label($name, $action='view')
- $name - string the target label
- $action='view' - string the on-going action
- returns the label to use, or NULL if no default label has been found
Accepted action codes:
- 'edit' modification of an existing object
- 'delete' deletion form
- 'new' creation of a new object
- 'view' rendering of the object
To be overloaded into derivated class
See also:
- articles/delete.php
- articles/duplicate.php
- articles/edit.php
- articles/fetch_as_msword.php
- articles/fetch_as_pdf.php
- articles/fetch_for_palm.php
- articles/layout_articles_as_alistapart.php
- articles/print.php
- articles/view.php
- sections/section.php
get_list_text() - Display the content of one overlay in a list
function &get_list_text($host=NULL)
- $host=NULL - array the hosting record, if any
- returns some HTML to be inserted into the resulting page
get_live_introduction() - Display a live introduction
function &get_live_introduction($host=NULL)
- $host=NULL - array the hosting record, if any
- returns some HTML to be inserted into the resulting page
get_live_title() - Display a live title
function &get_live_title($host=NULL)
- $host=NULL - array the hosting record, if any
- returns some HTML to be inserted into the resulting page
get_tabs() - Add some tabbed panels
function &get_tabs($variant='view', $host=NULL)
- $variant='view' - string the on-going action
- $host=NULL - array the hosting record
- returns an array of array('tab_id', 'tab_label', 'panel_id', 'panel_content') or NULL
Accepted action codes:
- 'view' - embedded into the main viewing page
- 'edit' - embedded into the main form page
See also:
get_text() - Display the content of one overlay
function &get_text($variant='view', $host=NULL)
- $variant='view' - string the variant code
- $host=NULL - array the hosting record, if any
- returns some HTML to be inserted into the resulting page
- 'extra' - displayed aside
- 'introduction' - as a live introduction
- 'list' - part of a list
- 'title' - as a live title
- 'trailer' - displayed at the bottom
- 'view' - in the main viewing panel
To be overloaded into derivated class
get_trailer_text() - Text to come after page description
function &get_trailer_text($host=NULL)
- $host=NULL - array the hosting record, if any
- returns some HTML to be inserted into the resulting page
get_type() - Retrieve overlay type
function get_type()
@returns stringSee also:
get_view_text() - Display the content of one overlay in main view panel
function &get_view_text($host=NULL)
- $host=NULL - array the hosting record, if any
- returns some HTML to be inserted into the resulting page
load() - Restore an instance
function load($host, $name='overlay')
- $host - array the hosting array
- $name='overlay' - string the attribute which contains overlay data
- returns a restored instance, or NULL
// get the record from the database
$item =& Articles::get($id);
// extract overlay data from $item['overlay']
$overlay = Overlay::load($item);
See also:
parse_fields() - Capture form content
function parse_fields($fields)
- $fields - array data transmitted to the server through a web form
To be overloaded into derivated class.
See also:
render() - Render some page component
function render($type, $reference, $page=1)
- $type - string type of component to render, e.g., 'articles'
- $reference - string anchor reference, such as 'section:123'
- $page=1 - int page
- returns mixed some text, or NULL
See also:
remember() - Remember an action once it's done
function remember($variant, $host)
- $variant - string the action 'insert', 'update' or 'delete'
- $host - array the hosting record
- returns FALSE on error, TRUE otherwise
To be overloaded into derivated class
See also:
save() - Serialize overlay content
function save()
- returns the serialized string
See also:
