Class Enrober

Description

Located in /enrober.php (line 37)


	
			
Method Summary
static object singleton ()
void add_cache_modifier (string $modifier)
void add_css (string $filepath, [array $config = null])
void add_desc (string $desc)
void add_filter (string $filter, [bool $filter_everything = false])
void add_js (string $filepath)
void add_keywords (mixed $keywords)
void add_tag (string $name, string $value, [integer $location = 0], [bool $sanitize = true])
mixed debug (mixed 0)
void force_cache (bool $cache)
void go ([string $title = ''], [string $theme = null])
void manual_cache (bool|int $valid)
void url (string $url)
Methods
static singleton (line 125)

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.

  • access: public
static object singleton ()
add_cache_modifier (line 235)

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.

  • access: public
void add_cache_modifier (string $modifier)
  • string $modifier: A string that identifies this version of the page.
    1.  <?php
    2.  if ($_GET['mode'=== '1'{
    3.      $enrober->add_cache_modifier('mode1');
    4.  }
    5.  ?>
add_css (line 604)

Adds a CSS file to be inserted at the %css% tag.

  1.  <?php
  2.  $enrober->add_css('extra.css')// Linked as a regular stylesheet
  3.  // Linked as a print-only stylesheet
  4.  $enrober->add_css('print.css'array('media' => 'print');
  5.  // Linked as an alternative stylesheet
  6.  $enrober->add_css('alternate.css'array('rel' => 'alt''title' => 'Alternate layout');
  7.  ?>

  • access: public
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.
add_desc (line 372)

Adds a <meta> description to the page.

Calling add_desc() a second time will replace any previous values.

  • access: public
void add_desc (string $desc)
  • string $desc: What to put in the <meta> description tag
add_filter (line 685)

Adds a content filter to be applied with ob_start()

  • access: public
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)

    1.  <?php
    2.  
    3.  // Apply the HTML Tidy callback to the body of the
    4.  // page to fix any broken markup (Requires the Tidy
    5.  // extention for PHP). We are only applying it to
    6.  // the body because the header/footer should already
    7.  // contain valid markup.
    8.  $enrober->add_filter('ob_tidyhandler');
    9.  
    10.  // This filter function collapses any whitespace
    11.  // between HTML tags down to a single space
    12.  function collapse_whitespace($in{
    13.      return preg_replace('/>\s+</','> <'$in);
    14.  }
    15.  
    16.  // add our custom filter, filtering everything
    17.  // including the header and footer
    18.  $enrober->add_filter('collapse_whitespace'true);
    19.  ?>

add_js (line 648)

Adds a JavaScript file to be linked via the %js% tag.

  • access: public
void add_js (string $filepath)
  • string $filepath:

    The url of the JavaScript file to add absolute or relative to the calling script.

    1.  <?php
    2.  $enrober->add_js('http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js')// Import jQuery from the Google CDN
    3.  $enrober->add_js('blink.js')// Add a JavaScript file that is in the same
    4.                                // directory as the page using it.
    5.  ?>

add_keywords (line 353)

Adds <meta> keywords to the page.

Multiple calls append to the list.

  • access: public
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
add_tag (line 740)

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().

  1.  <?php
  2.  $enrober->add_tag('foo''bar')// Adds the text "bar" anywhere in the
  3.                                   // header or footer that "%foo%" appears
  4.  $enrober->add_tag('foo''bar'0)// Same as previous
  5.  $enrober->add_tag('foo''bar'1)// Adds the text "bar" only in the header
  6.  $enrober->add_tag('foo''bar'2)// Adds the text "bar" only in the footer
  7.  
  8.  // By default anything added to a theme tag is run through htmlentities()
  9.  // to prevent XSS attacks. If you need to use HTML you can set the $sanitize
  10.  // parameter to false but if you are including any user generated content
  11.  // in it you will need to sanitize it yourself!
  12.  $enrober->add_tag('foo''<em>bar</em>')// Adds the text "bar", wrapped
  13.                                            // in a text representation of em tags
  14.  $enrober->add_tag('foo''<em>bar</em>'0true)// Same as previous
  15.  $enrober->add_tag('foo''<em>bar</em>'0false)// Adds the text "bar",
  16.                                                      // wrapped in em tags
  17.  ?>

  • access: public
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!
debug (line 166)

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.

  • return: Depends on the provided parameter, see debug() method notes.
  • access: public
mixed debug (mixed 0)
  • mixed 0: [$msg] Turn on/off if Bool, a string to add the debug message stack or null
force_cache (line 771)

Manually turn on/off caching, overriding the ENROBER_CACHE constant from the config file.

  • access: public
void force_cache (bool $cache)
  • bool $cache: Should caching be enabled for this page? True = Cache, False = Don't cache
get_cache_file_path (line 287)

Returns the complete file system path to the cache file for the current version of the calling script

  • return: The path to the cache file
  • access: public
string get_cache_file_path ()
go (line 398)

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.

  1.  <?php
  2.  $enrober->go()// Invoke Enrober without a page title, using the default theme
  3.  $enrober->go('Example')// Invoke Enrober with the page title 'Example', using
  4.                           // the default theme
  5.  $enrober->go('Example''my-theme')// Invoke Enrober with the page title 'Example',
  6.                                       // using a theme called 'my-theme'
  7.  $enrober->go('''my-theme')// Invoke Enrober without a page title, using a theme
  8.                                // called 'my-theme'
  9.  ?>

  • access: public
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.
manual_cache (line 330)

Manually specify whether or not the file's cache should be invalidated

  • access: public
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.
    1.  $enrober->cache_valid(true)// cache file is assumed to still be good no
    2.                               // matter how old it is
    3.  $enrober->cache_valid(false)// cache file is assumed to be expired and
    4.                                // must be re-processed
    5.  $enrober->cache_valid(time(60)// cache file is assumed to be expired
    6.                                      // if it is more than 60 seconds old
    7.  $enrober->cache_valid(mktime(0,0,0,4,1))// cache file is assumed to be
    8.                                            // expired if it was created
    9.                                            // before April 1st of the current year
url (line 762)

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.

Documentation generated on Mon, 17 Jan 2011 14:05:03 -0800 by phpDocumentor 1.4.3