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, further 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 (separate mobile and regular versions for instance), etc.
void
add_cache_modifier
(string $modifier)
-
string
$modifier: A string that identifies this version of the page. Can contain letters, numbers and underscores.
<?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
// extension 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://cdn.example.com/1.4.4/jquery.min.js'); // Import jQuery from a 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()
- %site_name% - The value for ENROBER_SITE_NAME specified in enrober-config.php
- %tagline% - The value for ENROBER_TAGLINE specified 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 process 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!
Manually turn on/off caching, overriding the ENROBER_CACHE constant from the config file.
When caching is turned on with force_cache(), normal caching rules apply. To guarantee that the cached version of a page gets returned when one exists use manual_cache() set to true.
void
force_cache
(bool $cache)
-
bool
$cache: Should caching be enabled for this page? True = Cache, False = Don't cache
Forces the mobile or non-mobile version of a page to be displayed.
void
force_mobile
(bool|null $force)
-
bool|null
$force: True === force mobile, False === force non-mobile, null === revert to auto-detect
Returns the complete file system path to the cache file for the current version of the calling script.
set_theme() must be called before get_cache_file_path() because the theme name is used to generate the cache file's filename.
string
get_cache_file_path
()
Returns a list of themes currently available.
array
get_themes
()
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
$enrober->go('Example'); // Invoke Enrober with the page title 'Example'
?>
void
go
([string $title = ''])
-
string
$title: If specified this string will be inserted into a <title> tag
Figure out if there is a cached version of this file/theme/cache-modifier combo.
set_theme() must be called before is_cached() because it uses the theme name to figure out the name of the cache file
bool
is_cached
()
Determines if the page should be served as a mobile page.
A return value of true does not necessarily mean that the user agent is a mobile device, it is possible that force_mobile() has forced the mobile version. For a more definitive answer use m().
bool
is_mobile
()
Examines the user agent string to try to determine whether the client is a mobile device.
mixed
m
()
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->manual_cache(true); // cache file is assumed to still be good no
// matter how old it is
$enrober->manual_cache(false); // cache file is assumed to be expired and
// must be re-processed
// expired if the current date is
// after midnight April 1st of the current year
Override the default theme.
Can only be called once, subsequent calls will be ignored. If no $theme is provided, the default theme is explicitly set as the theme.
Certain methods (for example get_cache_file_path) require that the theme be set before they are called or they may raise warnings or errors, in these cases call set_theme() (with no parameters if you want to use the default theme) to avoid errors.
set_theme() must be called before go(), go() uses the default theme if one has not been set before go() is called.
$enrober->set_theme('pressy'); // Change the them from the default to the 'pressy' theme
void
set_theme
([string $theme = null])
-
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.
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.