GRIS_TEMPLATE
in package
Class to manage html templates
With this class all html templates can be maneged to get nicely formatted code
PHP version 7
Copyright (c) 2012, Holger Heuser, GESIS Leibniz Institute for the Social Sciences Unter Sachsenhausen 6-8 50667 Cologne, Germany
Tags
Table of Contents
- settings_group = "template"
- The constant for the settings group
- $base_path : string
- The base path of the object (for file operations)
- $data : array<string|int, mixed>
- The data for the template markers
- $i18n : object
- The object for translations
- $logger : object
- The object for logs
- $settings : object
- The object for settings
- $template_list : array<string|int, mixed>
- The list of loaded templates
- $use_javascript : bool
- The use special markers for javascript code
- __construct() : mixed
- The class constructor
- add_ajax_tabs() : string
- Adds tabs with ajax based content
- add_basedata_dialogue() : string
- Adds a dialogue box for changing the base data of a person
- add_box() : string
- Adds a content box
- add_button() : string
- Adds a button
- add_category_dialogue() : string
- Adds a dialogue box for editing the categories
- add_confirm_change_dialogue() : string
- Adds a dialogue box to confirm a change action
- add_confirm_delete_dialogue() : string
- Adds a dialogue box to confirm a delete action
- add_dialogue() : string
- Adds a standard dialogue box
- add_editlog_dialogue() : string
- Adds a dialogue box for the edit log
- add_history_form() : string
- Adds a form for history events
- add_ida_reporting_year_dialogue() : string
- Adds a dialogue box for changing ida reporting year
- add_identifier_dialogue() : string
- Adds a dialogue box to edit oder create identifiers
- add_image_box() : void
- Adds a box for image uploads
- add_info() : string
- Adds an information symbol to an element
- add_links_dialogue() : string
- Adds a dialogue box for new links (URL)
- add_location_dialogue() : string
- Adds a dialogue box for locations
- add_message() : string
- Adds a system message (e. g. error oder success)
- add_message_box() : string
- Adds a box for state messages
- add_pagebrowser() : string
- Adds a pagebrowser
- add_pdf_box() : void
- Adds a box for pdf uploads
- add_person() : string
- Adds a dialogue box for adding persons
- add_personname_dialogue() : string
- Adds a dialogue box for personnames
- add_project_dialogue() : string
- Adds a dialogue box for new projects
- add_project_institute_dialogue() : string
- Adds a dialogue box for prject-related institutes
- add_project_person_dialogue() : string
- Adds a dialogue box for project-related persons
- add_project_units_dialogue() : string
- Adds a dialogue box for project related units
- add_promotion_program() : string
- Adds a dialogue box for new promotion programs
- add_publication_dialogue() : string
- Adds a dialogue box for new publications
- add_replace_dialogue() : string
- Adds a dialogue box for replacing items by another ID or name
- add_resourcetype_chooser() : string
- Adds a resourcetype chooser (for jsTree)
- add_searchbucket_dialogue() : string
- Adds a dialogue box for adding the searchbucketname
- add_state() : string
- Returns a formatted state message
- add_state_dialogue() : string
- Adds a dialogue box for state
- add_tab_filter() : string
- Adds a range of tabs as filters
- add_workflow_info_dialogue() : string
- Adds a dialogue box for workflow informations
- add_wrap() : string
- Wraps a given string around the content
- check_data() : int
- Validates the data concerning a special format
- create_link() : string
- Creates an hyperlink
- get_template() : string
- Fills the template markers with data and returns the code
- wrap_template() : string
- Wraps the template with data around another element (Marker is {#})
- get_condition() : string
- The callback function for conditional patterns in function get_template
- get_repeat() : string
- The callback function for repeating patterns in function get_template
- get_setting() : string
- The callback function for setting patterns in function get_template
- get_translation() : string
- The callback function for wrapping patterns in function get_template
- get_wrap() : string
- The callback function for wrapping patterns in function get_template
- load_template() : bool
- Loads a template file into storage if it is not already loaded
Constants
settings_group
The constant for the settings group
public
mixed
settings_group
= "template"
Properties
$base_path
The base path of the object (for file operations)
private
string
$base_path
Tags
$data
The data for the template markers
private
array<string|int, mixed>
$data
Tags
$i18n
The object for translations
private
object
$i18n
Tags
$logger
The object for logs
private
object
$logger
Tags
$settings
The object for settings
private
object
$settings
= null
Tags
$template_list
The list of loaded templates
private
array<string|int, mixed>
$template_list
Tags
$use_javascript
The use special markers for javascript code
private
bool
$use_javascript
Tags
Methods
__construct()
The class constructor
public
__construct() : mixed
Initializes the objects
Return values
mixed —add_ajax_tabs()
Adds tabs with ajax based content
public
add_ajax_tabs(array<string|int, mixed> $tabs) : string
Parameters
- $tabs : array<string|int, mixed>
-
Array with tab name (key) and url (value)
Return values
string —The html code
add_basedata_dialogue()
Adds a dialogue box for changing the base data of a person
public
add_basedata_dialogue() : string
Return values
string —The html code
add_box()
Adds a content box
public
add_box(string $title, string $content[, string $type = NULL ][, string $type_content = NULL ][, string $type_class = NULL ][, string $id = NULL ][, string $text = NULL ][, string $class = NULL ][, string $additional_params = NULL ][, string $placeholder = NULL ]) : string
Parameters
- $title : string
-
The title of the box
- $content : string
-
The main content for the box
- $type : string = NULL
-
The type of the box (e. g. "image", "toolbar")
- $type_content : string = NULL
-
The content for the special type (e. g. "image", "toolbar")
- $type_class : string = NULL
-
The class for the box type (e. g. for JQuery functions)
- $id : string = NULL
-
An optional ID (HTML/DOM) for the box
- $text : string = NULL
-
An optional text at the top of the box (but above the headline)
- $class : string = NULL
-
An optional class for the whole box
- $additional_params : string = NULL
-
Free additional params (e.g. style='xyz')
- $placeholder : string = NULL
-
A placeholder for the input field (for searchbar)
Return values
string —The html code
add_button()
Adds a button
public
add_button(string $action_class, string $id, string $text[, string $small_button = false ][, string $onclick = NULL ][, string $additional_classes = NULL ]) : string
Parameters
- $action_class : string
-
The type of action fot this button. Possible types: "add", "delete", "edit", "show", "hide" Predefined icons for "add", "delete", "edit" in combination with small button option.
- $id : string
-
The ID of the button
- $text : string
-
The text of the button (text is also used to create a title attribute if not empty)
- $small_button : string = false
-
Optional size of the button (if true, button is small and without additional Icon)
- $onclick : string = NULL
-
Optional onClick event for the button
- $additional_classes : string = NULL
-
Additional CSS classes for the button
Return values
string —The html code
add_category_dialogue()
Adds a dialogue box for editing the categories
public
add_category_dialogue(mixed $cat_options) : string
Parameters
- $cat_options : mixed
Return values
string —The html code
add_confirm_change_dialogue()
Adds a dialogue box to confirm a change action
public
add_confirm_change_dialogue() : string
Return values
string —The html code
add_confirm_delete_dialogue()
Adds a dialogue box to confirm a delete action
public
add_confirm_delete_dialogue([string $message = NULL ]) : string
Parameters
- $message : string = NULL
-
An optional message for the dialog (default is used if empty)
Return values
string —The html code
add_dialogue()
Adds a standard dialogue box
public
add_dialogue(array<string|int, mixed> $id, array<string|int, mixed> $class, array<string|int, mixed> $title, array<string|int, mixed> $content) : string
Parameters
- $id : array<string|int, mixed>
-
The id of the main div
- $class : array<string|int, mixed>
-
The class of the main div
- $title : array<string|int, mixed>
-
The title of the dialogue
- $content : array<string|int, mixed>
-
The id of the main div
Return values
string —The html code
add_editlog_dialogue()
Adds a dialogue box for the edit log
public
add_editlog_dialogue() : string
Return values
string —The html code
add_history_form()
Adds a form for history events
public
add_history_form(array<string|int, mixed> $history_event, array<string|int, mixed> $history_fields[, bool $form_disabled = false ]) : string
Parameters
- $history_event : array<string|int, mixed>
-
The event data
- $history_fields : array<string|int, mixed>
-
Information about the display of fields according to the type
- $form_disabled : bool = false
-
Disable the whole form
Return values
string —The html code
add_ida_reporting_year_dialogue()
Adds a dialogue box for changing ida reporting year
public
add_ida_reporting_year_dialogue() : string
Return values
string —The html code
add_identifier_dialogue()
Adds a dialogue box to edit oder create identifiers
public
add_identifier_dialogue(array<string|int, mixed> $params_select) : string
Parameters
- $params_select : array<string|int, mixed>
-
The parameters for the form elements
Return values
string —The html code
add_image_box()
Adds a box for image uploads
public
add_image_box(int $person_id, string $upload_name, string $gender, bool $edit_photo) : void
Parameters
- $person_id : int
-
The person ID
- $upload_name : string
-
The name for the upload
- $gender : string
-
The gender (f, m, n)
- $edit_photo : bool
-
Switch to diable photo editing
Return values
void —add_info()
Adds an information symbol to an element
public
add_info(string $name[, bool $float = true ][, bool $margin_right = false ][, mixed $position = "right" ]) : string
Parameters
- $name : string
-
The name of the element
- $float : bool = true
-
Add a class for floating the element to the right
- $margin_right : bool = false
-
Add a class for a right margin
- $position : mixed = "right"
Return values
string —The hmtl code for the info symbol
add_links_dialogue()
Adds a dialogue box for new links (URL)
public
add_links_dialogue() : string
Return values
string —The html code
add_location_dialogue()
Adds a dialogue box for locations
public
add_location_dialogue() : string
Return values
string —The html code
add_message()
Adds a system message (e. g. error oder success)
public
add_message(string $type, string $detail, array<string|int, mixed> $element_messages[, array<string|int, mixed> $id = NULL ]) : string
Parameters
- $type : string
-
The messagetype (ERROR|SUCESS|...)
- $detail : string
-
The error details (duplicate|invalid|...)
- $element_messages : array<string|int, mixed>
-
The DOM elements and messages
- $id : array<string|int, mixed> = NULL
-
The returned ID (only if success)
Return values
string —The html code
add_message_box()
Adds a box for state messages
public
add_message_box(string $message[, string $title = NULL ][, string $id = "gris_message" ]) : string
Parameters
- $message : string
-
The message to show
- $title : string = NULL
-
The title (set to default if empty)
- $id : string = "gris_message"
-
The DOM ID for the box
Return values
string —The html code
add_pagebrowser()
Adds a pagebrowser
public
add_pagebrowser(string $number_of_hits, string $hits_per_page, string $offset, string $pid[, string $params = NULL ][, string $action = NULL ]) : string
Parameters
- $number_of_hits : string
-
The total amount of pages
- $hits_per_page : string
-
The hits per page
- $offset : string
-
The current offset
- $pid : string
-
The page ID
- $params : string = NULL
-
Additional page parameters
- $action : string = NULL
-
The action for this page
Return values
string —The html code
add_pdf_box()
Adds a box for pdf uploads
public
add_pdf_box(int $id[, string $name = "PDF hochladen" ][, string $upload_type = "pdf" ][, string $prefix = "" ][, bool $disabled = false ]) : void
Parameters
- $id : int
-
The person ID
- $name : string = "PDF hochladen"
-
The name (e.g. for ALT tags)
- $upload_type : string = "pdf"
-
The type of the upload (pdf|fulltext|publist)
- $prefix : string = ""
-
The type of the upload (pdf|fulltext|publist)
- $disabled : bool = false
-
Disable upload and delete
Return values
void —add_person()
Adds a dialogue box for adding persons
public
add_person() : string
Return values
string —The html code
add_personname_dialogue()
Adds a dialogue box for personnames
public
add_personname_dialogue([bool $short = false ][, bool $institute = false ]) : string
Parameters
- $short : bool = false
-
A short version for authors and publishers only with firstname and name
- $institute : bool = false
-
A version for authors and publishers with institute connection
Return values
string —The html code
add_project_dialogue()
Adds a dialogue box for new projects
public
add_project_dialogue(array<string|int, mixed> $person_id) : string
Parameters
- $person_id : array<string|int, mixed>
-
The person ID to show available names
Return values
string —The html code
add_project_institute_dialogue()
Adds a dialogue box for prject-related institutes
public
add_project_institute_dialogue(object $show) : string
Parameters
- $show : object
-
The show object to check if fields are shown or not
Return values
string —The html code
add_project_person_dialogue()
Adds a dialogue box for project-related persons
public
add_project_person_dialogue([array<string|int, mixed> $foo = NULL ]) : string
Parameters
- $foo : array<string|int, mixed> = NULL
Return values
string —The html code
add_project_units_dialogue()
Adds a dialogue box for project related units
public
add_project_units_dialogue() : string
Return values
string —The html code
add_promotion_program()
Adds a dialogue box for new promotion programs
public
add_promotion_program() : string
Return values
string —The html code
add_publication_dialogue()
Adds a dialogue box for new publications
public
add_publication_dialogue(array<string|int, mixed> $person_id) : string
Parameters
- $person_id : array<string|int, mixed>
-
The person ID to show available names
Return values
string —The html code
add_replace_dialogue()
Adds a dialogue box for replacing items by another ID or name
public
add_replace_dialogue(array<string|int, mixed> $id) : string
Parameters
- $id : array<string|int, mixed>
-
The ID of the item
Return values
string —The html code
add_resourcetype_chooser()
Adds a resourcetype chooser (for jsTree)
public
add_resourcetype_chooser(array<string|int, mixed> $data) : string
Parameters
- $data : array<string|int, mixed>
-
The array with additinal template data (id, class, label)
Return values
string —The html code
add_searchbucket_dialogue()
Adds a dialogue box for adding the searchbucketname
public
add_searchbucket_dialogue(array<string|int, mixed> $params) : string
Parameters
- $params : array<string|int, mixed>
-
The params for the form
Return values
string —The html code
add_state()
Returns a formatted state message
public
add_state(string $element_messages[, array<string|int, mixed> $dialogue = false ]) : string
Parameters
- $element_messages : string
-
The message
- $dialogue : array<string|int, mixed> = false
-
Format the message for dialogue boxes
Return values
string —The wrapped content
add_state_dialogue()
Adds a dialogue box for state
public
add_state_dialogue() : string
Return values
string —The html code
add_tab_filter()
Adds a range of tabs as filters
public
add_tab_filter(array<string|int, mixed> $values, string $current, string $pid[, string $params = NULL ][, string $action = NULL ][, string $use_keys = false ]) : string
Parameters
- $values : array<string|int, mixed>
-
The values
- $current : string
-
Thecurrent value
- $pid : string
-
The page ID
- $params : string = NULL
-
Additional page parameters
- $action : string = NULL
-
The action for this page
- $use_keys : string = false
-
Use the array keys als title and the value as a param. Otherwise only values are used for both. (array has to be associative)
Return values
string —The html code
add_workflow_info_dialogue()
Adds a dialogue box for workflow informations
public
add_workflow_info_dialogue() : string
Return values
string —The html code
add_wrap()
Wraps a given string around the content
public
add_wrap(string $content, string $wrap) : string
Parameters
- $content : string
-
The content to be wrapped
- $wrap : string
-
The wrap (if open and close are different, they could be separated by the pipe "|")
Return values
string —The wrapped content
check_data()
Validates the data concerning a special format
public
check_data(string $data, string $format[, string $min = NULL ][, string $max = NULL ]) : int
Parameters
- $data : string
-
The data
- $format : string
-
The data format
- $min : string = NULL
-
An optional min range for the data
- $max : string = NULL
-
An optional max range for the data
Return values
int —Returns 1 for valid, 0 for invalid format and -1 for out of range
create_link()
Creates an hyperlink
public
create_link(int $pid, int $id[, string $text = NULL ][, string $title = NULL ][, string $target = NULL ][, string $class = NULL ][, string $action = NULL ][, string $params = NULL ][, string $external = false ]) : string
Parameters
- $pid : int
-
The page ID
- $id : int
-
The ID of the entity
- $text : string = NULL
-
The link text (only url is returned without a-tag if no text is given)
- $title : string = NULL
-
The link title (default: "Link")
- $target : string = NULL
-
The target for the links (default: "_self")
- $class : string = NULL
-
The link class
- $action : string = NULL
-
The page action (default: "show")
- $params : string = NULL
-
Optional parameters
- $external : string = false
-
Create an external (absolute) link with base url and protocol (default is a relative link)
Return values
string —Returns the hyperlink as html
get_template()
Fills the template markers with data and returns the code
public
get_template(string $template_file, array<string|int, mixed> $data[, string $wrap = NULL ][, bool $javascript = false ]) : string
Parameters
- $template_file : string
-
The name of the template file
- $data : array<string|int, mixed>
-
The data to insert
- $wrap : string = NULL
-
The tag to be wrapped around the template (without brackets, if opening and ending tag should be different [e. g. an opener with a class], use pipe for separation)
- $javascript : bool = false
-
Template for Javascript (different markers to avoid bracket problems "{=" and "=}") Example for wrap: p class="wrapper"|p
Return values
string —The filled template
wrap_template()
Wraps the template with data around another element (Marker is {#})
public
wrap_template(string $template_file, array<string|int, mixed> $data, int $part[, bool $javascript = false ]) : string
Parameters
- $template_file : string
-
The name of the template file
- $data : array<string|int, mixed>
-
The data to insert
- $part : int
-
The part of the wrapper
- $javascript : bool = false
-
Template for Javascript (different markers to avoid bracket problems "{=" and "=}")
Return values
string —The filled template
get_condition()
The callback function for conditional patterns in function get_template
private
get_condition(array<string|int, mixed> $match) : string
Parameters
- $match : array<string|int, mixed>
-
The matches of the regular expression
Return values
string —Returns the replacement for the pattern
get_repeat()
The callback function for repeating patterns in function get_template
private
get_repeat(array<string|int, mixed> $match) : string
Parameters
- $match : array<string|int, mixed>
-
The matches of the regular expression (array -> ordernumber -> items)
Return values
string —Returns the replacement for the pattern
get_setting()
The callback function for setting patterns in function get_template
private
get_setting(array<string|int, mixed> $match) : string
Parameters
- $match : array<string|int, mixed>
-
The matches of the regular expression
Return values
string —Returns the replacement for the pattern
get_translation()
The callback function for wrapping patterns in function get_template
private
get_translation(array<string|int, mixed> $match) : string
Parameters
- $match : array<string|int, mixed>
-
The matches of the regular expression
Return values
string —Returns the replacement for the pattern
get_wrap()
The callback function for wrapping patterns in function get_template
private
get_wrap(array<string|int, mixed> $match) : string
Parameters
- $match : array<string|int, mixed>
-
The matches of the regular expression
Return values
string —Returns the replacement for the pattern
load_template()
Loads a template file into storage if it is not already loaded
private
load_template(string $template_file) : bool
Parameters
- $template_file : string
-
The name of the template file
Return values
bool —Returns true if file is successfully loaded or already in the memory