New Classes for Websitebaker(CE),  1.4.1
Documentation for all new Classes in Websitebaker(CE)
Static Public Member Functions | Static Private Member Functions | Static Private Attributes
I Class Reference

This Class is the static facade for the insert class and provides global availability.
If you want to know how to insert scripts, metas and css whithin Websitebaker CE look here. More...

Static Public Member Functions

static AddTitle ($Title="", $Overwrite=false)
 Adds a value to the title var, default behavior is to append the value to an existing value. More...
 
static GetTitle ($Default=false)
 Returns the recent title or $Default, if title is not found or empty. More...
 
static RenderTitle ($Default="<title>No Title</title>")
 Renders the title and returns it. Returns $Default if title is not set. More...
 
static AddMeta ($Content)
 Allows to add additional Metas to the Head of the Template. More...
 
static GetMetas ($Default=false)
 Method to get the metas array for checking or processing. More...
 
static GetMeta ($SetName="", $Default=false)
 Method to get the values of a single Meta named whith "setname". More...
 
static RenderMetas ($Default="")
 Rendering the Metas dependent on defined rendering method(html, html5, xhtml). More...
 
static AddCss ($Content)
 Method to add CSS entries to the template via a storage array. More...
 
static GetCss ($Default=false)
 Method to get the CSS array for checking or processing. More...
 
static GetCs ($SetName="", $Default=false)
 Method to get the values of a single CSS entry named whith "setname". More...
 
static RenderCss ($Default="")
 Renders all the CSS entries saved in the array. More...
 
static AddJs ($Content)
 Method to add Js entries to the JS array. Compared to the AddMeta() this on got a fixed complement of available keys, but basic functionality is the same. More...
 
static GetJs ($Position="All", $Default=false)
 Method to get the Js array for checking or processing. More...
 
static GetJ ($SetName="", $Default=false)
 Method to get the values of a single JS entry named whith "setname". More...
 
static RenderJs ($Position="HeadLow", $Default="")
 Renders all the JS for a certain position.(e.g. HeadTop, HeadLow, BodyTop, BodyLow...) More...
 
static AddHtml ($Content)
 Method to add Html entries to the Html array. Compared to the AddMeta() this on got a fixed complement of available keys, but basic functionality is the same. More...
 
static GetHtmls ($Position="All", $Default=false)
 Method to get the Html array for checking or processing. More...
 
static GetHtml ($SetName="", $Default=false)
 Method to get the values of a single Html entry named whith "setname". More...
 
static RenderHtml ($Position="BodyLow", $Default="")
 Renders all the Html for a certain position.(e.g. BodyTop, BodyLow...) More...
 
static Filter ($Content)
 The output filter function that does the actual replacement of the template placeholders. More...
 

Static Private Member Functions

static getInstance ()
 Create a new instance of Insert if not already one. Store the object in static var. More...
 

Static Private Attributes

static $Instance ="nope"
 The recent instance of Insert Class. More...
 

Detailed Description

This Class is the static facade for the insert class and provides global availability.
If you want to know how to insert scripts, metas and css whithin Websitebaker CE look here.

As this class is a static facade for the insert class so we need to provide it whith a Instance to call on. But there is no problem if you manual initialize insert again for some other purpose(subtemplating for example). So i choose to not make it a singleton pattern. Later this even gets a static selector for multiple instances like selecting a Database in ReadbeanPHP.

How to use class I on Websitebaker CE

Using class I in WBCE is done in 2 Steps:

  1. Registration of Scripts
  2. Adding placeholders to Template

Registration

Registration of scripts, metas....and so on is done by by simply calling a static method for each type of script. Here we have some registration examples, more options and examples can be found in the documentation of each method:

//Meta
I::AddMeta(array (
"setname"=>"charset",
"charset"=>"ISO-8859-1"
));
//CSS
I::AddCss (array(
'setname'=>"font-awesome",
'href' =>"https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css",
'media' =>"screen"
));
I::AddCss (array(
'setname'=>"local-script2",
'style' =>"#htto {position:absolute}"
));
//Js
I::AddJs (array(
'setname'=>"jquery",
'position'=>"BodyLow",
'src'=>"https://code.jquery.com/jquery-2.1.4.min.js"
));
I::AddJs (array(
'setname'=>"test2",
'position'=>"HeadLow",
'src'=>WB_URL."modules/colorbox/js/colorbox.min.js",
'script'=>"jQuery('a.gallery').colorbox();"
));

Global Keys

AddMetas, AddCss and AddJs got some special keys that are used to provide at least some functionality to allow mamagement of double entries. Those are the same in all Add... methods except AddTitle.

    key          typ       default      description  
    --------------------------------------------------------------------------------------------------
    "setname"    string    Unique ID    Is a name that is simply for preventing doublets if 
                                        nothing is given it gets an unique id.
    "overwrite"  boolean   true         Per default metas whith the same setname are overwritten, 
                                        but if you set overwrite to false.
                                        The method returns an error message as result.  
    "setsave"    boolean   false        Metas whith "setsave" set true the Meta cannot be overwritten.

Additional Registration Examples

setname

I::AddCss (array(
'setname'=>"font-awesome",
'href' =>"https://maxcdn.bootstrapcdn.com/font-awesome/3.3.0/css/font-awesome.min.css",
'media' =>"screen"
));
I::AddCss (array(
'setname'=>"font-awesome",
'href' =>"https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css",
'media' =>"screen"
));

If two entries share the same setname the second overwrites the first. so only the second will be rendered.

overwrite

I::AddCss (array(
'setname'=>"font-awesome",
'href' =>"https://maxcdn.bootstrapcdn.com/font-awesome/3.5.0/css/font-awesome.min.css",
'media' =>"screen"
));
I::AddCss (array(
'setname'=>"font-awesome",
'href' =>"https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css",
'media' =>"screen",
'overwrite'=>false
));

If you do not want the above behavior, you can add 'overwrite'=>false and instead of overwriting an already existing entry I::AddCss() only returns an error message if an entry whith same setname already exits.

setsave

I::AddCss (array(
'setname'=>"font-awesome",
'href' =>"https://maxcdn.bootstrapcdn.com/font-awesome/3.5.0/css/font-awesome.min.css",
'media' =>"screen",
'setsave'=>true
));
I::AddCss (array(
'setname'=>"font-awesome",
'href' =>"https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css",
'media' =>"screen"
));

To ensure your never entry is overwritten you can add the 'setsave'=>true flag and the system will never overwrite this entry.

Attention
More examples can be found in the documentation for the specific method.

Template

There are a some placeholders that need to be added to the template. This replaces the old frontend functions. The old frontend functions are moved into a module. And we add a compatibility function that imports the old files into the new system. So old modules will still run whith the new system.

[[Metas]]
[[Title]]
[[Css]]
[[Js?pos=HeadTop]]
[[Js?pos=HeadLow]]
[[Js?pos=BodyTop]]
[[Js?pos=BodyLow]]

An example template may look like this:

<!DOCTYPE html>
<html lang="de">
<head>
[[Metas]]
[[Title]]
[[Css]]
[[Js?pos=HeadTop]]
<script>
var Hallo="HAllo";
</script>
[[Js?pos=HeadLow]]
</head>
<body>
[[Js?pos=BodyTop]]
[[Html?pos=BodyTop]]
<!-- Sichtbarer Dokumentinhalt im body -->
<p>Sehen Sie sich den Quellcode dieser Seite an.
<kbd>(Kontextmenu: Seitenquelltext anzeigen)</kbd></p>
[[Html?pos=BodyLow]]
[[Js?pos=BodyLow]]
</body>
</html>
Todo:
I need to add a manager to use different instances like in ReadbeanPHP.

Member Function Documentation

static getInstance ( )
staticprivate

Create a new instance of Insert if not already one. Store the object in static var.

This would be the constructor if this wasn't a static facade class.

static AddTitle (   $Title = "",
  $Overwrite = false 
)
static

Adds a value to the title var, default behavior is to append the value to an existing value.

If $Overwrite is set to true the old value will be replaced by the new value.

Parameters
string$Title
boolean$Overwrite
Returns
boolean false on sucess| string error message on failure

Example

I::AddTitle ("My Cool Website");
//renders as "\t<title>My Cool Website</title>"
I::AddTitle (" - Page Introduction");
//renders as "\t<title>My Cool Website - Page Introduction</title>"
I::AddTitle ("A far mor important title", true);
//now renders as "\t<title>A far mor important title</title>"
static GetTitle (   $Default = false)
static

Returns the recent title or $Default, if title is not found or empty.

Use it for debugging or doing complex processimg whith the title.

Parameters
undefined$Default
Returns
returns $Default on failure and the title as string if title is found.
static RenderTitle (   $Default = "<title>No Title</title>")
static

Renders the title and returns it. Returns $Default if title is not set.

Example

I::RenderTitle("\t<title>No Title</title>");
// renders : \t<title>No Title</title>
I::AddTitle('The Websitetitle');
I::RenderTitle("\t<title>No Title</title>");
// renders : \t<title>The Websitetitle</title>
Parameters
undefined$Default
Return values
stringthe full redered HTML title tag
static AddMeta (   $Content)
static

Allows to add additional Metas to the Head of the Template.

Expects an array to be given as metas got a countless number of attributes the array may contain anything you like.

//
I::AddMeta(array (
"setname"=>"description",
"name"=>"description",
"content"=>"This is a nice description"
));
// <meta name="description" content="This is a nice description" />
I::AddMeta(array (
"setname"=>"keywords",
"name"=>"keywords",
"content"=>"Dieses, Beschreibung, Was auch immer"
));
// <meta name="keywords" content="Dieses, Beschreibung, Was auch immer" />
// In an international enviroment
I::AddMeta(array (
"setname"=>"keywords_en",
"name"=>"keywords",
"content"=>"This, Description, Something",
"lang"=>"en"
));
I::AddMeta(array (
"setname"=>"keywords_de",
"name"=>"keywords",
"content"=>"Dieses, Jenes, Welches, Irgendwas",
"lang"=>"de"
));
// <meta name="keywords" content="This, Description, Something" lang="en" />
// <meta name="keywords" content="Dieses, Jenes, Welches, Irgendwas" lang="de" />
// Robots
I::AddMeta(array (
"name"=>"robots",
"content"=>"noindex,nofollow"
));
// Cache controll
I::AddMeta(array (
"setname"=>"expires",
"http-equiv"=>"expires",
"content"=>"43200"
));
// Redirect
I::AddMeta(array (
"setname"=>"refresh",
"http-equiv"=>"refresh",
"content"=>"0;url=http://www.domain.de/"
));
// <meta http-equiv="refresh" content="0;url=http://www.domain.de/">
// charset
I::AddMeta(array (
"setname"=>"charset",
"charset"=>"ISO-8859-1"
));
// depending on render method this will produce very different output
// html : <meta http-equiv="content-type" content="text/html; charset=utf-8">
// xhtml: <meta http-equiv="content-type" content="text/html; charset=utf-8" />
// html5: <meta charset="utf-8">
Parameters
array$ContentThis is always an array whith all atributes stored as "key" => "value" see example above.

All other parameters are simple piped to the meta output.

There are quite a few attributes that schould be used as setname so other Scripts can interact whith those correctly:

setname      function  
-------------------------------------------------------
author       name="author" content="Author Name" 
description  name="description" ....
keywords     name="keywords"..... 
date         name="date"
robots       name="robots"
charset      charset="utf-8" for example
expires      http-equiv="expires"
refresh      http-equiv="refresh"
Return values
boolean/stringReturns false on success, and an error message on failure.
static GetMetas (   $Default = false)
static

Method to get the metas array for checking or processing.

You can set a default return value if nothing is found.

Parameters
undefined$DefaultYou can define a special return var if the meta array is empty.
Return values
array/undefinedReturns the Array of already defined Metas.
static GetMeta (   $SetName = "",
  $Default = false 
)
static

Method to get the values of a single Meta named whith "setname".

The method returns $Default if nothing is found.

Parameters
string$SetNameSimply the setname used in AddMeta
undefined$DefaultWhatever you like as a returnvalue if the method does not find a matching entry.
Return values
array/undefinedReturns the value of the meta whith this "setname" or $Default if nothing is found.
static RenderMetas (   $Default = "")
static

Rendering the Metas dependent on defined rendering method(html, html5, xhtml).

Returns $Default if nothing is set. Especially having set "charset" will get very different results depending on render method. having set charset also stops the rendering of other fields

Parameters
undefined$DefaultWhatever you like as a returnvalue if the meta array is empty.
Return values
stringAll metas rendered are returned as a string.
static AddCss (   $Content)
static

Method to add CSS entries to the template via a storage array.

Compared to the AddMeta() this on got a fixed complement of available keys, but basic functionality is the same.

// adding font awesome
I::AddCss (array(
'setname'=>"font-awesome",
'href' =>"https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css",
'media' =>"screen"
));
// adding some direct style commands
I::AddCss (array(
'setname'=>"superheadline",
'style' =>"h1 #htto {position:absolute}"
));

Allowed Keys

Key         Typ         Description  
--------------------------------------------------------------------------------------------------
href        string      Simply the full URL where to load the Script
style       string      The plain style definitions to insert.
media       string      The "media" attribute for stylesheets.
title       string      "title" atribute NOT IMPLEMENTED YET! 

All other Keys are only the default ones you find in the class description(setname,overwrite,setsave..).

For good setnames pleass try to use the lowercase version of the script loaded.

jquery
font-awesome
colorbox
fancybox
... 
Parameters
array$ContentThe array that defines an entry.
Return values
boolean/stringReturns false on success, and an error message on failure.
static GetCss (   $Default = false)
static

Method to get the CSS array for checking or processing.

You can set a default return value if nothing is found.

Parameters
undefined$DefaultYou can define a special return var if the CSS array is empty.
Return values
array/undefinedReturns the Array of already defined CSS.
static GetCs (   $SetName = "",
  $Default = false 
)
static

Method to get the values of a single CSS entry named whith "setname".

The method returns $Default if nothing is found.

Parameters
string$SetNameSimply the setname used in AddCss().
undefined$DefaultWhatever you like as a returnvalue if the method does not find a matching entry.
Return values
array/undefinedReturns the value of the CSS whith this "setname" or $Default if nothing is found.
static RenderCss (   $Default = "")
static

Renders all the CSS entries saved in the array.

Dependent on defined rendering method(html, html5, xhtml).

Parameters
undefined$DefaultYou can define a special return var if the CSS array is empty.
Return values
string/undefinedRenders all of already defined CSS or $Default if empty
static AddJs (   $Content)
static

Method to add Js entries to the JS array. Compared to the AddMeta() this on got a fixed complement of available keys, but basic functionality is the same.

I::AddJs (array(
'setname'=>"myalert",
'position'=>"HeadLow",
'script'=>"var hier='Das ist ein Alert'; alert(hier);",
'overwrite'=>true
));
I::AddJs (array(
'setname'=>"jquery",
'position'=>"BodyLow",
'src'=>"https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"
));

###Allowed Keys

Key         Typ         Description  
--------------------------------------------------------------------------------------------------
position    string      The Position where to insert this piece of JS
script      string      The scritp to insert. 
src         string      Simply the full URL where to load the Script

All other Keys are the default ones you find in the class description.

For good setmanes pleass try to use the lowercase version of the script loaded.

jquery
font-awesome
colorbox
fancybox
... 

###The default positions for insert JS are.

HeadTop, HeadLow, BodyTop, BodyLow 

But you can define your own positions if you like.

Parameters
array$ContentThe array that defines an entry.
Return values
boolean/stringReturns false on success, and an error message on failure.
static GetJs (   $Position = "All",
  $Default = false 
)
static

Method to get the Js array for checking or processing.

You can set a default return value if nothing is found.

Parameters
undefined$DefaultYou can define a special return var if the Js array is empty.
string$PositionSet this to only return Scripts whith a certain position set. Default position names can be found in docs to AddJs(). $Position="All" returns the full Js array.
Return values
array/undefinedReturns the Array of already defined Java Scripts(for a certain position).
static GetJ (   $SetName = "",
  $Default = false 
)
static

Method to get the values of a single JS entry named whith "setname".

The method returns $Default if nothing is found.

Parameters
string$SetNameSimply the setname used in AddJs().
undefined$DefaultWhatever you like as a returnvalue if the method does not find a matching entry.
Return values
array/undefinedReturns the value of the JS whith this "setname" or $Default if nothing is found.
static RenderJs (   $Position = "HeadLow",
  $Default = "" 
)
static

Renders all the JS for a certain position.(e.g. HeadTop, HeadLow, BodyTop, BodyLow...)

The prefered render method is taken into account.
Returns $Default if array is empty.

I::RenderJs(); //renders the default JS "HeadLow"
I::RenderJs("BodyLow"); //Renders JS for "BodyLow" position.
Parameters
string$PositionSet this to only return Scripts whith a certain position set. Default position names can be found in docs to AddJs(). NO $Position="All" here!!!
undefined$DefaultWhatever you like as a returnvalue if the method does not find a matching entrys.
Return values
string/undefinedReturns the rendered Javascript definitions for one position or $Default if nothing is found.
static AddHtml (   $Content)
static

Method to add Html entries to the Html array. Compared to the AddMeta() this on got a fixed complement of available keys, but basic functionality is the same.

I::AddHtml (array(
'setname'=>"alert",
'position'=>"BodyTop",
'html'=>'<div class="alert">Sie haben vergessen ein Feld auszuf├╝llen</div>',
'overwrite'=>true
));
I::AddHtml (array(
'setname'=>"footer",
'position'=>"BodyLow",
'html'=>'<div class="footer">Copyright Mustermann KG</div>'
));

###Allowed Keys

Key         Typ         Description  
--------------------------------------------------------------------------------------------------
position    string      The Position where to insert this piece of JS
html        string      The Html to insert 

All other Keys are the default ones you find in the class description.

For good setmanes pleass try to use something logical connented to the content.

warning
footer
install-alert
load-google-map
... 

###The default positions for insert Html are.

BodyTop, BodyLow 

But you can define your own positions if you like.

Parameters
array$ContentThe array that defines an entry.
Return values
boolean/stringReturns false on success, and an error message on failure.
static GetHtmls (   $Position = "All",
  $Default = false 
)
static

Method to get the Html array for checking or processing.

You can set a default return value if nothing is found.

Parameters
undefined$DefaultYou can define a special return var if the Html array is empty.
string$PositionSet this to only return Scripts whith a certain position set. Default position names can be found in docs to AddJs(). $Position="All" returns the full Js array.
Return values
array/undefinedReturns the Array of already defined Java Scripts(for a certain position).
static GetHtml (   $SetName = "",
  $Default = false 
)
static

Method to get the values of a single Html entry named whith "setname".

The method returns $Default if nothing is found.

Parameters
string$SetNameSimply the setname used in AddHtml().
undefined$DefaultWhatever you like as a returnvalue if the method does not find a matching entry.
Return values
array/undefinedReturns the value of the Html whith this "setname" or $Default if nothing is found.
static RenderHtml (   $Position = "BodyLow",
  $Default = "" 
)
static

Renders all the Html for a certain position.(e.g. BodyTop, BodyLow...)

Returns $Default if array is empty.

I::RenderHtml(); //renders the default Html "BodyLow"
I::RenderHtml("BodyTop"); //Renders Html for "BodyTop" position.
Parameters
string$PositionSet this to only return Scripts whith a certain position set. Default position names can be found in docs to AddHtml(). NO $Position="All" here!!!
undefined$DefaultWhatever you like as a returnvalue if the method does not find a matching entrys.
Return values
string/undefinedReturns the rendered Html for one position or $Default if nothing is found.
static Filter (   $Content)
static

The output filter function that does the actual replacement of the template placeholders.

In Websitebaker (CE) you do not need to take care of this as this is loaded by the default output filters. Although the method needs to be public for outputfilter call.

Parameters
string$ContentThe HTML content to filter
Return values
stringThe filtered/replaced content.

Field Documentation

instance $Instance ="nope"
staticprivate

The recent instance of Insert Class.

later this will get a management for multiple instances like managing multiple DBs in ReadbeanPhp


The documentation for this class was generated from the following file: