Class SGL_Output

Description

High level HTML transform methods, 'Template Helpers' in Yahoo speak, 50% html, 50% php.

  • author: Demian Turner <demian@phpkitchen.com>
  • version: $Revision: 1.22 $
  • todo: look at PEAR::Date to improve various date methods used here

Located in /SGL/Output.php (line 50)


	
			
Variable Summary
Method Summary
 static string translate (string $key, [string $filter = false], [ $aParams = array()], [ $output = null], [ $lang = null])
 SGL_Output SGL_Output ()
 SGL_Output __construct ()
 void addCssFile (mixed $file)
 void addHeader ( $header)
 void addJavascriptFile (mixed $file, [boolean $optimize = true])
 void addOnLoadEvent ( $event, [ $bOnReady = false])
 void addOnUnloadEvent ( $event)
 void assign ( &$a,  $b)
 void camelise ( $lowerCaseWithSpacesWordsString)
 void exportJsVar (string $k, string $v, [boolean $replace = true])
 int formatBytes ( $size, int $bytes)
 string formatDate ([ $date = ''], string $input)
 string formatDatePretty ([string $date = ''])
 string generateCheckbox (string $name, string $value, boolean $checked, [array $options = null])
 string generateCheckboxList (array $hElements, array $aChecked, string $groupName, [array $options = null])
 string generateRadioList (array $elements, string $selected, string $groupname, [integer $newline = false], [boolean $inTable = true], [array $options = null])
 string generateRadioPair (string $radioName, boolean $checked, [array $options = null])
 string generateSelect ( $aValues, [mixed $selected = null], [boolean $multiple = false], [array $options = null], [ $translate = false], array $array)
 void getCurrentId ()
 void getCurrentUrl ()
 string getDateFormat ()
 current getExecutionTime ()
 string getExportedJsVars ()
 void getHeaders ()
 memory getMemoryUsage ()
 string getNoExpiryCheckbox (array $aDate, string $sFormName)
 void getOnLoadEvents ()
 query getQueryCount ()
 boolean hasPerms (string $permName)
 void humanise ( $lowerCaseAndUnderscoredWord)
 void increment ( $int)
 boolean isAdmin ([ $rid = null])
 boolean isAdminOrUnassigned ( $rid)
 void isAuthenticated ()
 void isChecked ( $value)
 void isEqual ( $a,  $b)
 void isVerticalNav ( $styleSheet)
 boolean isWin ()
 void makeCssLink ( $theme,  $navStylesheet,  $moduleName)
 string makeCssOptimizerLink ([array $aCssHelperParams = array()], [mixed $aDefaultThemeFiles = null], [string $themePreloadFile = null])
 string makeUrl ([string $action = ''], [string $mgr = ''], [string $mod = ''], [array $aList = array()], [string $params = ''], [integer $idx = 0])
 void msgGet ()
 mixed msgGetAdmin ()
 string nl2br (string $text)
 void outputBody ([ $templateEngine = null])
 string printf ()
 void setStatusCode ( $code)
 string showDateSelector (array $aDate, string $sFormName, [boolean $bShowTime = true], [bool $asc = true], [int $years = 5])
 string summarise (string $str, [integer $limit = 50], [ $element = SGL_WORD], [string $appendString = ' ...'])
 string switchRowClass ([boolean $isBold = false], [string $pColor = 'backDark'], [string $sColor = 'backLight'], [ $id = 'default'])
 bool switchTrueFalse ([int $elementsToCount = 2])
 void tr ( $key, [ $filter = false], [ $aParams = array()], [ $output = null], [ $lang = null])
 void _extractVariableValue ( $varString, [ $output = null])
 integer _getFilesModifiedTime (array $aFiles)
Variables
mixed $aCssFiles = array() (line 60)
mixed $aHeaders = array() (line 61)
mixed $aJavascriptFiles = array() (line 58)
mixed $aOnLoadEvents = array() (line 53)
mixed $aOnReadyDomEvents = array() (line 57)
mixed $aOnUnloadEvents = array() (line 55)
mixed $aRawJavascriptFiles = array() (line 59)
mixed $aStatusCodes = array(
// Informational 1xx
100 => 'Continue',
101 => 'Switching Protocols',

// Success 2xx
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',

// Redirection 3xx
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found', // 1.1
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
// 306 is deprecated but reserved
307 => 'Temporary Redirect',

// Client Error 4xx
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',

// Server Error 5xx
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
509 => 'Bandwidth Limit Exceeded'
)
(line 63)
mixed $httpProtocol = 'HTTP/1.0' (line 62)
mixed $onLoad = '' (line 52)
mixed $onReadyDom = '' (line 56)
mixed $onUnload = '' (line 54)
array $_aJsExportVars = array() (line 123)
  • access: private
Methods
static translate (line 149)

Translates source text into target language.

  • return: translated text
  • see: setLanguage()
  • access: public
string translate (string $key, [string $filter = false], [ $aParams = array()], [ $output = null], [ $lang = null])
  • string $key: translation term
  • string $filter: optional filter fn, ie, strtoupper()
  • $aParams
  • $output
  • $lang
Constructor SGL_Output (line 134)
SGL_Output SGL_Output ()
Constructor __construct (line 125)
SGL_Output __construct ()
addCssFile (line 820)

For adding CSS files to include.

void addCssFile (mixed $file)
  • mixed $file: or array $file path/to/cssFile, relative to www/ dir e.g. css/foo.css
addHeader (line 1100)
void addHeader ( $header)
  • $header
addJavascriptFile (line 756)

For adding Javascript files to include.

  • access: public
void addJavascriptFile (mixed $file, [boolean $optimize = true])
  • mixed $file: string (file) or array of strings (files) path/to/jsFile relative to www/ dir e.g. js/foo.js, can also be remote js file e.g. http://example.com/foo.js
  • boolean $optimize
addOnLoadEvent (line 690)
void addOnLoadEvent ( $event, [ $bOnReady = false])
  • $event
  • $bOnReady
addOnUnloadEvent (line 699)
void addOnUnloadEvent ( $event)
  • $event
assign (line 950)

Makes new var and assign value.

void assign ( &$a,  $b)
  • &$a
  • $b
camelise (line 1067)
void camelise ( $lowerCaseWithSpacesWordsString)
  • $lowerCaseWithSpacesWordsString
exportJsVar (line 1426)

Export js var.

void exportJsVar (string $k, string $v, [boolean $replace = true])
  • string $k
  • string $v
  • boolean $replace
formatBytes (line 452)

Wrapper for SGL_String::formatBytes(), Converts bytes to Kb or MB as appropriate.

  • return: kb/MB
  • access: public
int formatBytes ( $size, int $bytes)
  • int $bytes
  • $size
formatDate (line 468)

Converts date (may be in the ISO, TIMESTAMP or UNIXTIME format) into dd.mm.yyyy.

  • return: user-friendly format (european)
  • access: public
string formatDate ([ $date = ''], string $input)
  • string $input: date (may be in the ISO, TIMESTAMP or UNIXTIME format) value
  • $date
formatDatePretty (line 483)

Converts date (may be in the ISO, TIMESTAMP or UNIXTIME format) into "Mar 31, 2003 18:29".

  • return: user-friendly format (european)
  • access: public
string formatDatePretty ([string $date = ''])
  • string $date: Date (may be in the ISO, TIMESTAMP or UNIXTIME format) value
generateCheckbox (line 318)

Generate checkbox.

  • return: html checkbox tag w/label
  • access: public
string generateCheckbox (string $name, string $value, boolean $checked, [array $options = null])
  • string $name: element name
  • string $value: element value
  • boolean $checked: is checked
  • array $options: attibutes to add to the input tag : array() {"class" => "myClass", "onclick" => "myClickEventHandler()"}
generateCheckboxList (line 285)

Generates sequence checkboxes.

  • return: html list of checkboxes
  • access: public
string generateCheckboxList (array $hElements, array $aChecked, string $groupName, [array $options = null])
  • array $hElements: hash of checkbox values
  • array $aChecked: array of checked elements
  • string $groupName: name of element group
  • array $options: attibutes to add to the input tag : array() {"class" => "myClass", "onclick" => "myClickEventHandler()"}
generateRadioList (line 386)

Generates sequence of radio button from array.

  • return: a list of radio buttons
  • access: public
string generateRadioList (array $elements, string $selected, string $groupname, [integer $newline = false], [boolean $inTable = true], [array $options = null])
  • array $elements: array of values or radio button
  • string $selected: selected key (there can be only one selected element in a radio list)
  • string $groupname: usually an array name that will contain all elements
  • integer $newline: how many columns to display for this radio group (one if not informed)
  • array $options: attibutes to add to the input tag : array() {"class" => "myClass", "onclick" => "myClickEventHandler()"}
  • boolean $inTable: true for adding table formatting
generateRadioPair (line 347)

Generates a yes/no radio pair.

  • return: html yes/no radio pair
  • access: public
string generateRadioPair (string $radioName, boolean $checked, [array $options = null])
  • string $radioName: name of radio element
  • boolean $checked: is checked
  • array $options: attibutes to add to the input tag : array() {"class" => "myClass", "onclick" => "myClickEventHandler()"}
generateSelect (line 225)

Generates options for an HTML select object.

  • return: select options
  • access: public
string generateSelect ( $aValues, [mixed $selected = null], [boolean $multiple = false], [array $options = null], [ $translate = false], array $array)
  • array $array: hash of select values
  • mixed $selected: default selected element, array for multiple elements
  • boolean $multiple: true if multiple
  • array $options: attibutes to add to the input tag : array() {"class" => "myClass", "onclick" => "myClickEventHandler()"}
  • $aValues
  • $translate
getCurrentId (line 1005)
void getCurrentId ()
getCurrentManager (line 983)
void getCurrentManager ()
getCurrentModule (line 972)
void getCurrentModule ()
getCurrentTemplate (line 994)
void getCurrentTemplate ()
getCurrentUrl (line 902)
void getCurrentUrl ()
getDateFormat (line 497)

Gets appropriate date format

  • return: template (e.g. "%d %B %Y, %H:%M" for FR date format)
  • access: public
string getDateFormat ()
getExecutionTime (line 1075)
  • return: ms since script start
current getExecutionTime ()
getExportedJsVars (line 1441)
  • access: public
string getExportedJsVars ()
getHeaders (line 1115)
void getHeaders ()
getJavascriptFiles (line 774)
void getJavascriptFiles ()
getLangDirection (line 1401)
void getLangDirection ()
getLangDirectionOpposite (line 1409)
void getLangDirectionOpposite ()
getMemoryUsage (line 1091)
  • return: usage
memory getMemoryUsage ()
getNoExpiryCheckbox (line 527)

Creates a checkbox for infinite Articles (no expiry)

  • return: with checkbox. Name of checkbox will be $sFormName.NoExpire, e.g. ExpiryDateNoExpire
  • access: public
string getNoExpiryCheckbox (array $aDate, string $sFormName)
  • array $aDate: if NULL checkbox is checked
  • string $sFormName: Name of Date Selector to reset if checkbox is clicked
getOnLoadEvents (line 704)
void getOnLoadEvents ()
getOnReadyDomEvents (line 730)
void getOnReadyDomEvents ()
getOnUnloadEvents (line 717)
void getOnUnloadEvents ()
getQueryCount (line 1083)
  • return: count
query getQueryCount ()
hasPerms (line 1033)

Check permission at the template level and returns true if permission exists.

Use as follows in any Flexy template:

  1.  {if:hasPerms(#faqmgr_delete#)} on {else:} off {end:}

To get various perm names, select User module then go to 'perms' section.

  • access: public
boolean hasPerms (string $permName)
  • string $permName: Name of permission eg. "faqmgr_delete"
humanise (line 1062)
void humanise ( $lowerCaseAndUnderscoredWord)
  • $lowerCaseAndUnderscoredWord
increment (line 957)
void increment ( $int)
  • $int
isAdmin (line 666)

Returns true if current user or passed role ID is that of an admin.

boolean isAdmin ([ $rid = null])
  • $rid
isAdminOrUnassigned (line 679)

Returns true if $rid is 1 or -1.

boolean isAdminOrUnassigned ( $rid)
  • $rid
isAuthenticated (line 684)
void isAuthenticated ()
isChecked (line 962)
void isChecked ( $value)
  • $value
isEqual (line 941)

Returns true if a and b are equal.

void isEqual ( $a,  $b)
  • $a
  • $b
isVerticalNav (line 909)
void isVerticalNav ( $styleSheet)
  • $styleSheet
isWin (line 932)

Returns true if client OS is windows.

boolean isWin ()
makeCssLink (line 1050)
void makeCssLink ( $theme,  $navStylesheet,  $moduleName)
  • $theme
  • $navStylesheet
  • $moduleName
makeCssOptimizerLink (line 1213)

Makes CSS optimizer link.

  1. {makeCssOptimizerLink():h} Loads default "CSS fw" stylesheets + stylesheets specified in mgr.
2. {makeCssOptimizerLink(##,#a.css,b.css#):h} Loads "a.css" and "b.css" from current theme + stylesheets specified in mgr.

3. {makeCssOptimizerLink(##,##):h} Loads only stylesheets specified in mgr.

  • access: public
string makeCssOptimizerLink ([array $aCssHelperParams = array()], [mixed $aDefaultThemeFiles = null], [string $themePreloadFile = null])
  • array $aCssHelperParams: additional params passed to css helper
  • mixed $aDefaultThemeFiles: if null default css files are loaded otherwise custom files specified as array or string (CSV)
  • string $themePreloadFile: file which is "prepended" to every CSS request (even in non-production mode)
makeJsOptimizerLink (line 1135)

Makes optimizer link for JavaScript files.

How to use:

  1. in your template you need to add the following line <script type="text/javascript" src="{makeJsOptimizerLink()}" />
  2. specify global js files in $conf['site']['globalJavascriptFiles'] separated by comma e.g. 'js/SGL.js,js/SGL/Util/String.js'
  3. to add module/manager specific js files just use $output->addJavascriptFile('path/to/custom/js/file.js')

  • access: public
string makeJsOptimizerLink ()
makeUrl (line 850)

Wrapper for SGL_Url::makeLink.

Generates URL for easy access to modules and actions.

  • access: public
string makeUrl ([string $action = ''], [string $mgr = ''], [string $mod = ''], [array $aList = array()], [string $params = ''], [integer $idx = 0])
  • string $action
  • string $mgr
  • string $mod
  • array $aList
  • string $params
  • integer $idx
msgGet (line 1359)

Get message, which outputs html in default2 style.

  • access: public
void msgGet ()
msgGetAdmin (line 617)

Prints formatted error message to standard out.

(For default_admin theme)

mixed msgGetAdmin ()
nl2br (line 1463)

nl2br

  • access: public
string nl2br (string $text)
  • string $text
outputBody (line 914)
void outputBody ([ $templateEngine = null])
  • $templateEngine
printf (line 1044)

printf function wrapper.

string printf ()
setStatusCode (line 1107)
void setStatusCode ( $code)
  • $code
showDateSelector (line 514)

Wrapper for SGL_Date::showDateSelector(), Generates date/time selector widget.

  • return: html for widget
  • access: public
string showDateSelector (array $aDate, string $sFormName, [boolean $bShowTime = true], [bool $asc = true], [int $years = 5])
  • array $aDate
  • string $sFormName: name of form
  • boolean $bShowTime: toggle to display HH:MM:SS
  • bool $asc
  • int $years: number of years to show
summarise (line 605)

Wrapper for SGL_String::summarise(), Returns a shortened version of text string.

  • return: Correctly shortened text
  • access: public
string summarise (string $str, [integer $limit = 50], [ $element = SGL_WORD], [string $appendString = ' ...'])
  • string $str: Text to be shortened
  • integer $limit: Number of characters to cut to
  • string $appendString: Trailing string to be appended
  • $element
switchRowClass (line 546)

Generates alternate classes for rows in tables, used to switch row colors.

  • return: string representing class found in stylesheet
  • access: public
string switchRowClass ([boolean $isBold = false], [string $pColor = 'backDark'], [string $sColor = 'backLight'], [ $id = 'default'])
  • boolean $isBold
  • string $pColor: optional primary color, override default
  • string $sColor: optional secondary color, override default
  • $id
switchTrueFalse (line 578)

Generates alternate value (false/true) to be used in template

  • access: public
bool switchTrueFalse ([int $elementsToCount = 2])
  • int $elementsToCount: Number of elements to reach to switch from false/true, default 2
tr (line 210)
void tr ( $key, [ $filter = false], [ $aParams = array()], [ $output = null], [ $lang = null])
  • $key
  • $filter
  • $aParams
  • $output
  • $lang
_extractVariableValue (line 193)
void _extractVariableValue ( $varString, [ $output = null])
  • $varString
  • $output
_getFilesModifiedTime (line 1341)

Identifies latest mod time for specified files array.

Is used to get "revision" number for optimizer link.

  • access: private
integer _getFilesModifiedTime (array $aFiles)
  • array $aFiles

Documentation generated on Tue, 23 Feb 2010 18:14:32 +0000 by phpDocumentor 1.4.3