Creates the $enrober singleton object.
Automatically called when enrober.php is included. The created object is assigned to the $enrober variable. Because Enrober is a singleton, futher calls to singleton() will result in a reference to the original object instead of a new instance.
static object
singleton
()
Adds a cache modifier.
Cache modifiers are used to differentiate between different versions of a page. This can be useful if you want to cache pages show different information when they have certain query string parameters, if you want to create different versions of the page based on the user agent (seperate mobile and regular versions for instance), etc.
void
add_cache_modifier
(string $modifier)
-
string
$modifier: A string that identifies this version of the page.
<?php
if ($_GET['mode'] === '1') {
}
?>
Adds a CSS file to be inserted at the %css% tag.
<?php
$enrober->add_css('extra.css'); // Linked as a regular stylesheet
// Linked as a print-only stylesheet
$enrober->add_css('print.css', array('media' =>
'print');
// Linked as an alternative stylesheet
$enrober->add_css('alternate.css', array('rel' =>
'alt', 'title' =>
'Alternate layout');
?>
void
add_css
(string $filepath, [array $config = null])
-
string
$filepath: The url to the css file to be included. If the css file is in the same directory as the calling script only the filename needs to be specified.
-
array
$config: An array that allows you to add additional optional attributes to the link tag. These attributes are:
- 'media': Which media types the stylesheet should be applied to, 'all' by default.
- 'rel': The rel attribute of the <link> tag, 'stylesheet' by default can also be set to 'alternate stylesheet' to specify an alternate stylesheet. If set to 'alt' it will automatically be expanded to 'alternate stylesheet'.
- 'title': The title attribute for the link, most browsers that support alternative stylesheets will use this as a label in the stylesheet switching interface.
Adds a <meta> description to the page.
Calling add_desc() a second time will replace any previous values.
void
add_desc
(string $desc)
-
string
$desc: What to put in the <meta> description tag
Adds a content filter to be applied with ob_start()
void
add_filter
(string $filter, [bool $filter_everything = false])
-
string
$filter: A string with the name of the filter function to use
-
bool
$filter_everything:
Should only the body be filtered or the entire generated page? (By default only the body of the page is filtered)
<?php
// Apply the HTML Tidy callback to the body of the
// page to fix any broken markup (Requires the Tidy
// extention for PHP). We are only applying it to
// the body because the header/footer should already
// contain valid markup.
// This filter function collapses any whitespace
// between HTML tags down to a single space
function collapse_whitespace($in) {
}
// add our custom filter, filtering everything
// including the header and footer
$enrober->add_filter('collapse_whitespace', true);
?>
Adds a JavaScript file to be linked via the %js% tag.
void
add_js
(string $filepath)
-
string
$filepath:
The url of the JavaScript file to add absolute or relative to the calling script.
<?php
$enrober->add_js('http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'); // Import jQuery from the Google CDN
$enrober->add_js('blink.js'); // Add a JavaScript file that is in the same
// directory as the page using it.
?>
Adds <meta> keywords to the page.
Multiple calls append to the list.
void
add_keywords
(mixed $keywords)
-
mixed
$keywords: What to put in the <meta> keywords tag. Either a string of comma delimited keywords or an array of keywords
Adds a new theme tag.
Theme tags allow you to specify where things Enrober generates are injected into the theme. There are a number of built in tags:
- %title% - The page's <title> tag
- %desc% - The page's description <meta> tag
- %keywords% - The page's keywords <meta> tag
- %themepath% - The URI for the directory that the current theme is stored in, useful for including the theme's CSS file.
- %css% - Any <link> tags for CSS files added via $enrober->add_css()
- %js% - Any <script> tags for JavaScript files added via $enrober->add_js()
- %generated% - Inserts a "Generated on" or "Cached on" message depending on whether or not caching is enabled on the current page.
- %canonical% - Where in the head to insert the Canonical URL if one was set with $enrober->url()
- %debug% - Where to insert debugging information that was added via $enrober->debug() or by Enrober itself.
- %site_name% - The value for ENROBER_SITE_NAME specifed in enrober-config.php
- %tagline% - The value for ENROBER_TAGLINE specifed in enrober-config.php
If you add your own tags to your templates you can then set their value for any particular page with add_tag().
<?php
$enrober->add_tag('foo', 'bar'); // Adds the text "bar" anywhere in the
// header or footer that "%foo%" appears
$enrober->add_tag('foo', 'bar', 0); // Same as previous
$enrober->add_tag('foo', 'bar', 1); // Adds the text "bar" only in the header
$enrober->add_tag('foo', 'bar', 2); // Adds the text "bar" only in the footer
// By default anything added to a theme tag is run through htmlentities()
// to prevent XSS attacks. If you need to use HTML you can set the $sanitize
// parameter to false but if you are including any user generated content
// in it you will need to sanitize it yourself!
$enrober->add_tag('foo', '<em>bar</em>'); // Adds the text "bar", wrapped
// in a text representation of em tags
$enrober->add_tag('foo', '<em>bar</em>', 0, true); // Same as previous
$enrober->add_tag('foo', '<em>bar</em>', 0, false); // Adds the text "bar",
// wrapped in em tags
?>
void
add_tag
(string $name, string $value, [integer $location = 0], [bool $sanitize = true])
-
string
$name: The name of the theme tag to define (sans %%)
-
string
$value: The value to insert at the new theme tag
-
integer
$location: Where to proccess the tag. 0 = Header and Footer, 1 = Header only, 2 = Footer only
-
bool
$sanitize: If true, the $value is run through htmlentities() before inclusion in the page. Set to false if you need to include HTML, but you will need to sanitize any user input you include yourself!
Turns on/off debugging, adds a message to the debug stack or returns a copy of the debug stack.
debug() behaves differently depending on what parameters it is called with:
- If $msg is a String, it will be added to the debug message stack.
- If $msg is a Boolen, debug() will turn debugging on or off.
- If $msg is not provided, the on/off status of debug logging is
returned as a Boolean.
- If it is null the debug stack array is returned.
When debugging is turned on, the %debug% tag can be used to automatically insert formatted debug information into a template. (It will be added as a OL tag with and id of "enroberdebug").
Note: If debugging is turned on at any point during a pages execution caching will be forced off so stale pages don't cause debugging headaches.
Note: debug() will return null when called to add something to the debug log or when debugging is off.
mixed
debug
(mixed 0)
-
mixed
0: [$msg] Turn on/off if Bool, a string to add the debug message stack or null
Manually turn on/off caching, overriding the ENROBER_CACHE constant from the config file.
void
force_cache
(bool $cache)
-
bool
$cache: Should caching be enabled for this page? True = Cache, False = Don't cache
Returns the complete file system path to the cache file for the current version of the calling script
string
get_cache_file_path
()
Invokes Enrober's page wrapping; invoke after calling any of the other Enrober methods you want to use and before page content starts.
Enrober will automatically call ob_start('ob_gzhandler') on every page it wraps; don't make your own calls to the ob_gzhandler callback or you will get error messages or garbled gz-encoded text instead of the plain HTML page you intended.
<?php
$enrober->go(); // Invoke Enrober without a page title, using the default theme
$enrober->go('Example'); // Invoke Enrober with the page title 'Example', using
// the default theme
$enrober->go('Example', 'my-theme'); // Invoke Enrober with the page title 'Example',
// using a theme called 'my-theme'
$enrober->go('', 'my-theme'); // Invoke Enrober without a page title, using a theme
// called 'my-theme'
?>
void
go
([string $title = ''], [string $theme = null])
-
string
$title: If specified this string will be inserted into a <title> tag
-
string
$theme: A string containing the name of the theme to wrap the page in. If not provided the value of the ENROBER_DEFAULT_THEME constant from the config file is used.
Manually specify whether or not the file's cache should be invalidated
void
manual_cache
(bool|int $valid)
-
bool|int
$valid: - If True assume the cached is still good, if False the file is old and should be regenerated, if an integer is supplied it is assumed to be a unix timestamp and compared to the cache file's timestamp to determine the cache file's validity.
$enrober->cache_valid(true); // cache file is assumed to still be good no
// matter how old it is
$enrober->cache_valid(false); // cache file is assumed to be expired and
// must be re-processed
$enrober->cache_valid(time() -
60); // cache file is assumed to be expired
// if it is more than 60 seconds old
$enrober->cache_valid(mktime(0,0,0,4,1)); // cache file is assumed to be
// expired if it was created
// before April 1st of the current year
Sets the canonical URL for the page to be inserted at the %canonical% tag.
Google's webmaster central has more information about canonical URLs.
void
url
(string $url)
-
string
$url: The url to set as the canonical url.