New Classes for WBCE CMS,  1.4.1
Documentation for all new Classes in WBCE CMS
Public Member Functions | Data Fields | Private Attributes
Insert Class Reference

Class for insertion of Javascript, Metas, Title and CSS into a pagetemplate on WB and maybe other systems.
In WBCE CMS this class will use a global facade (class I) to guarantee a fully global presence. More...

Public Member Functions

 __construct ()
 The constructor only fetches the WB_RENDER Constant and copies the value to the local $Render variable. More...
 
 AddTitle ($Title="", $Overwrite=false)
 Adds a value to the title var. More...
 
 GetTitle ($Default=false)
 Returns the recent title or $Default if title is not found. More...
 
 RenderTitle ($Default="\t<title></title>")
 Renders the Title and returns it. More...
 
 AddMeta ($Content="")
 Allows to add additional Metas to the Head of the Template. More...
 
 GetMetas ($Default=false)
 Method to get the metas array for checking or processing. More...
 
 GetMeta ($SetName="", $Default=false)
 Method to get the values of a single Meta named whith "setname". More...
 
 RenderMetas ($Default="")
 Rendering the Metas dependent on defined rendering method(html, html5, xhtml). More...
 
 AddCss ($Content)
 Method to add CSS entries to the CSS array. More...
 
 GetCss ($Default=false)
 Method to get the CSS array for checking or processing. More...
 
 GetCs ($SetName="", $Default=false)
 Method to get the values of a single CSS entry named whith "setname". More...
 
 RenderCss ($Default="")
 Renders all the CSS entries saved in the array. More...
 
 AddJs ($Content)
 Method to add Js entries to the JS array. More...
 
 GetJs ($Position="All", $Default=false)
 Method to get the Js array for checking or processing. More...
 
 GetJ ($SetName="", $Default=false)
 Method to get the values of a single JS entry named whith "setname" The method returns $Default if nothing is found. More...
 
 RenderJs ($Position="HeadLow", $Default="")
 Renders all the JS for a certain position. More...
 
 AddHtml ($Content)
 Method to add Html entries to the Html array. More...
 
 GetHtmls ($Position="All", $Default=false)
 Method to get the Html array for checking or processing. More...
 
 GetHtml ($SetName="", $Default=false)
 Method to get the values of a single Html entry named whith "setname" The method returns $Default if nothing is found. More...
 
 RenderHtml ($Position="BodyLow", $Default="")
 Renders all the Html for a certain position. More...
 
 Filter ($Content)
 The output filter function that does the actual replacement of the template placeholders. More...
 

Data Fields

 $Render = "html5"
 What is the prefered Rendering method. More...
 

Private Attributes

 $Js = array()
 Storage array for javascript. More...
 
 $Css = array()
 Storage array for CSS. More...
 
 $Metas = array()
 Storage array for Meta entries. More...
 
 $Html = array()
 Storage array for Html entries. More...
 
 $Title =""
 Storage variable for Title. More...
 

Detailed Description

Class for insertion of Javascript, Metas, Title and CSS into a pagetemplate on WB and maybe other systems.
In WBCE CMS this class will use a global facade (class I) to guarantee a fully global presence.

The basic idea is to have global available methods that allow any script whithin Websitbaker CE to register metadata, javascript and stylesheets. Later those are inserted into the Websitetemplate. The actual insertion is done via outputfilter placeholders (Droplets [[Css]], [[Js]]....) The outputfilter is delivered whith this class.

Attention
The following documentation is about using this class drirectly, if you want to know how to use script insertion whith WBCE CMS
please look into class I(facade).

Register

$i=new Insert();
//Meta
$i->AddMeta(array (
"setname"=>"charset",
"charset"=>"ISO-8859-1"
));
//CSS
$i->AddCss (array(
'setname'=>"test",
'href' =>"https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css",
'media' =>"screen"
));
$i->AddCss (array(
'setname'=>"test2",
'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'=>"http://google.de",
'script'=>"alert('TaTaaa');"
));

Special keys

AddMetas, AddCss and AddJs got some special keys that are used to provide some functionality to allow mamagement of double entries.

    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.

Template

The Template should look like this:

<!DOCTYPE html>
<html lang="de">
<head>
[[Metas]]
[[Title]]
[[Css]]
[[Js?pos=HeadTop]]
[[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>

Replacement

Replacement is done by the filter function

echo $i->Filter($string);

Constructor & Destructor Documentation

__construct ( )

The constructor only fetches the WB_RENDER Constant and copies the value to the local $Render variable.

Default value is "html5".

Member Function Documentation

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

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 overwritten by the new value replaced.

Parameters
string$Title
boolean$Overwrite
Returns
boolean false on sucess| string error message on failure
GetTitle (   $Default = false)

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

Parameters
undefined$Default
Returns
returns $Default on failure and th title as string if title is found.
RenderTitle (   $Default = "\t<title></title>")

Renders the Title and returns it.

Returns $Default if Title is not set.

$i= new Insert();
$i->AddTitle('The Websitetitle');
$i->RenderTitle();
$i->RenderTitle("\t<title>No Title</title>")
Parameters
undefined$Default
Return values
stringthe full redered HTML title tag
AddMeta (   $Content = "")

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 ("name"=>"description", "content"=>"This is a nice description", -8", "overwrite"=>true, "setsave"=>true));
$i->AddMeta(array ("name"=>"keywords", "content"=>"Dieses, Beschreibung, Was auch immer", "lang"=>"de" ));
$i->AddMeta(array ("setname"=>"keywords_en", "name"=>"keywords", "content"=>"This, Description, Something", "lang"=>"en"));
$i->AddMeta(array ("setname"=>"keywords_en", "name"=>"keywords", "content"=>"This, Bla, Blub, blubber, Something", "lang"=>"en", "overwrite"=>false));
$i->AddMeta(array ("name"=>"robots", "content"=>"noindex,nofollow" ));
$i->AddMeta(array ("name"=>"robots", "content"=>"index,follow"));
$i->AddMeta(array ("setname"=>"expires", "http-equiv"=>"expires", "content"=>"43200"));
$i->AddMeta(array ("setname"=>"expires", "http-equiv"=>"expires", "content"=>"0")); //overwrites the former setting
$i->AddMeta(array ("setname"=>"charset", "charset"=>"ISO-8859-1" ));
Parameters
array$ContentThis is always an array whith all atributes stored as "key" => "value" see example above.

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 (This key gets special threatment in the render section.)
expires      http-equiv="expires"
refresh      http-equiv="refresh"

All other parameters are simply piped to the meta output.
Return values
boolean/stringReturns false on success, and an error message on failure.
GetMetas (   $Default = false)

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.
GetMeta (   $SetName = "",
  $Default = false 
)

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.
RenderMetas (   $Default = "")

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

Or return nothing or maybe a defined $Default if you like. Especially having "charset" set 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.
AddCss (   $Content)

Method to add CSS entries to the CSS array.

Compared to the AddMeta() this one 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'=>"test23",
'style' =>"#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 the default ones you find in the class description.

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.
GetCss (   $Default = false)

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.
GetCs (   $SetName = "",
  $Default = false 
)

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.
RenderCss (   $Default = "")

Renders all the CSS entries saved in the array.

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

$i->AddJs (array(
'setname'=>"test1",
'position'=>"HeadLow",
'script'=>"var hier='dfdfdf'",
'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. But you can define your own if you like.

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

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).
GetJ (   $SetName = "",
  $Default = false 
)

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.
RenderJs (   $Position = "HeadLow",
  $Default = "" 
)

Renders all the JS for a certain position.

The prefered render method is taken into account.

$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.
AddHtml (   $Content)

Method to add Html entries to the Html array.

AddHtml is for adding plain HTML to a set of predifined places. (BodyTop, BodyLow). You even can define your own locations but then you have to add extra placeholders in the template. E.G 'position'=>"SomePos" then you have to add [[Html?pos=SomePos]] somewhere in you template.

$i->AddHtml (array(
'position'=>"BodyLow",
'html'=>'<a href="http://www.startpage.de">Startpage, search whithout tracking</a>',
'overwrite'=>true
));
$i->AddHtml (array(
'setname'=>"cookie-warn",
'position'=>"BodyTop",
'html'=>'<div style="position: absolut top left; whidth: 100%; height: 50px">... Some Cookie Waring Stuff ...</div>'
));

###Allowed Keys

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

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

For good setmanes pleass try to use the lowercase version of what this thing is.

footer
cookie-warning
... 

###The default Positions for insert Html are listed here. But you can define your own if you like.

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

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 AddHtml(). $Position="All" returns the full Js array.
Return values
array/undefinedReturns the Array of already defined Java Scripts(for a certain position).
GetHtml (   $SetName = "",
  $Default = false 
)

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.
RenderHtml (   $Position = "BodyLow",
  $Default = "" 
)

Renders all the Html for a certain position.

$i->RenderHtml(); //renders the default JS "BodyLow"
$i->RenderHtml("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 AddHtml(). NO $Position="All" !!!
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.
Filter (   $Content)

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

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

Field Documentation

array $Js = array()
private

Storage array for javascript.

array $Css = array()
private

Storage array for CSS.

array $Metas = array()
private

Storage array for Meta entries.

array $Html = array()
private

Storage array for Html entries.

string $Title =""
private

Storage variable for Title.

string $Render = "html5"

What is the prefered Rendering method.

Possible values are "html", "xhtml", "html5"


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