
XAO::DO::Web::Content -- Dynamic content management for XAO::Web

<%Content name="about_us"%>

For installation and usage instruction see "INSTALLATION AND USAGE" chapter below.
Content object allows to embed editable content stored in a database into a web page or any other part of a system based on XAO::Web. There are virtually no limitations as to how content can be used.
For instance the text on "News" page of the site might be a Content element. In that case site administrator would not need to modify any templates, but can edit, preview and publish news using web interface only.
Another example could be storing complete product description template as a Content object. In that case modifying all product pages at once would be controlled by modifying just one template over the web in content editor.
A content element is identified by a name that has the same set of restrictions as a XAO::FS ID - up to 30 characters, alpha-numeric and underscore characters only.
Every bit of content has multiple values associated with it arranged by date of their modification. Most current version of content can be in one of two states - published and unpublished. If it is unpublished then it can only be seen if the special preview mode is turned on. That gives an ability to a site administrator to preview changes and probably make corrections before making these changes available for regular site visitors.
A configuration for Content objects can be provided as a part of site configuration. Its URI is '/content' and parameters are:
list_uri => uri of content storage in the XAO FS, defaults
to '/Content'
cache_time => for how long to keep retrieved content in memory cache,
default is 5 minutes
cache_size => the size of memory cache in KB, default is 1024
flag_cb_uri => location of a flag in clipboard that indicates whether
or not the preview mode is on

The easiest way to install XAO Content is to use CPAN. Usually you would need to do something like this:
sudo perl -MCPAN -e'install XAO::DO::Web::Content'
If you downloaded archive and want to install it manually then usual four commands will do:
perl Makefile.PL make make test sudo make install
During execution of Makefile.PL you will be asked for a test database DSN, username and password. If you want to skip the tests enter 'none' for DSN or otherwise give it any disposable database DSN. In most cases OS:MySQL_DBI:test will do. Note: That database content will be completely destroyed after tests.
Once installed the XAO Content is ready to be used. There are two scenarios to start using it -- if you already have a site where you want to add dynamic content functionality and if you do not have a site and want to just see XAO Content in action.
Here are the steps you need to follow to get a simple working site that uses XAO Content:
mysqladmin create content
xao-fs --dsn=OS:MySQL_DBI:content init
cd /usr/local/xao/projects/content perl ./configure.pl
Enter OS:MySQL_DBI:content as the database DSN and username/password of a user that has full access to that database.
./bin/build-structure
<VirtualHost SOME_HOST_NAME>
ServerName SOME_HOST_NAME
<Directory /usr/local/xao/handlers>
Options ExecCGI
SetHandler cgi-script
</Directory>
RewriteEngine on
RewriteRule ^/(.*)$ \
/usr/local/xao/handlers/xao-apache.pl/content/$1 \
[L]
</VirtualHost>
Here you replace SOME_HOST_NAME with a something that you have in your DNS or at least in /etc/hosts file. At the last line of RewriteRule the last part of the path is the site name that you used -- you need to change it if you used a different name.
To integrate XAO Content into an existing site you shoul follow these steps (depending on your site setup not all of them might be applicable):
my $cobj=XAO::Objects->new(objname => 'Web::Content'); $cobj->build_structure;

Content is based in Web::Action object and such depends on 'mode' argument, with the default mode being 'show'.
All methods if not stated otherwise support the following set of arguments that defines which content object to use:
name => Name of content
data_id => ID of a specific version (optional, rarely used)
preview => if non-zero then unpublished version of content will
be used. If that argument is not present then the
clipboard preview flag is used (see flag_cb_uri above)
The following list of methods also shows 'mode' as the first element (order alphabetically).
Displays a form for creating new content and when the form is filled -- creates that content accordingly.
Arguments are:
form.path => path to form template success.path => path to success template
Displays data text by name according to preview argument or clipboard flag.
By default it just outputs the content literally without any processing. If 'parse' argument is true then the content will be parsed as if it were a template. Arguments given to 'content-data' will be available to that template in this case.
If there is a 'default.path' or 'default.template' arguments then they will be displayed in case where there is no content object by that name exists in the database. If default is not given and there is no content found in the database then an error will be thrown.
Example:
<%Content name="about_us"%>
<%Content name="about_us" parse="1" REAL_NAME="John Silver"%>
<%Content name="about_us"
parse="1"
default.path="/bits/default-about-us"
REAL_NAME="John Silver"
%>
Checks if preview mode is currently on and displays given 'path' or 'template' if it is.
Makes preview data block current for the given content. If there were no modifications to the content (no preview data block) then nothing is modified.
Arguments are:
name => content name path/template => what to display in case of success, optional
Makes preview data blocks current for all content elements.
Reverts given content to older date by creating or replacing preview data block with a copy of old content.
Date does not have to match exactly, the data block with closest date equal to or preceeding the given date will be used. If as a result of that the current content is to be used anf there is no preview block defined then no modifications are made.
If given content did not exist at all at the given time then no modifications are made as well.
Arguments are:
name => content name time => time to revert to
Loads older date content for all content elements at once.
Sets or drop preview flag in the clipboard indicating whether all subsequent calls to the Content should return current or preview content.
Usually this is used somewhere in the page header on all pages to check for a specific cookie or a CGI parameter to turn on site 'preview' mode.
Example:
<%Content
mode="content-set-preview"
value={<%Condition
a.cgiparam="preview_mode"
a.template="1"
b.cookie="preview_mode"
b.template="1"
default.template="0"
%>}
%>
Displays the content by a given name and optionally an ID of a specific release of that content.
Passes the following parameters to the given template:
COMMENT => comment for data CURRENT_ID => current published element ID DATA_ID => ID of data block being used DESCRIPTION => content description EFFECTIVE_TIME => publication effective time INSTRUCTION => instruction MIME_TYPE => content data MIME type MOD_TIME => last modification time NAME => content name PREVIEW_ID => id of unpublished data or empty string if published PREVIEW_URL => URL of a preview page TEXT => content data
Displays all publication dates in order from most recent to least recent. If 'name' parameter is given then dates are restricted to that specific element otherwise global list of dates is shown.
Example:
<SELECT NAME="xxx">
<%Content mode="content-show-dates"
path="/bits/content-date-option"%>
</SELECT>
Stores new content by either replacing current content in the preview data block or by creating a new preview data block if there is no one currently.
Arguments are:
name => content name
comment => comment for that release
text => full text for that release; stripped of whitespace
in the end and in the beginning
mime_type => MIME type, default is text/plain

The following methods are not available through 'mode' argument and serve various internal purposes.
Builds supporting structure in the database. Does not destroy existing data -- safe to call on already populated database.
Usually should be called in Config.pm's build_structure() method.
Returns content cache reference.
Returns a reference to a hash that describes database structure. Usually you would add it to your database description in Config.pm:
my $cobj=XAO::Objects->new(objname => 'Web::Content');
my %structure=(
MyData => {
...
},
%{$cobj->data_structure},
MyOtherData => {
...
}
);
If that looks ugly (it is ugly) then look at build_structure() method description instead.
This method returns a Data::Content and Data::Content objects using standard content location definition arguments described in METHODS section preface. It is used in almost every other method to get the data of a content object.
If called in scalar context then returns only content object, without data.
Arguments it accepts are (as stated above):
name => Name of content (required)
data_id => ID of a specific version (optional, rarely used)
preview => if non-zero then unpublished version of content will
be used. If that argument is not present then the
clipboard preview flag is used (see flag_cb_uri above)

Copyright (c) 2000-2002 XAO Inc.
Andrew Maltsev <am@xao.com>

Recommended reading: XAO::DO::Web::Content, XAO::FS, XAO::Web.