Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AdminLTE renderer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
AdminLTE renderer
Commits
59275159
Commit
59275159
authored
9 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
remove unneeded methods; simplify icon methods; update phpdocs
parent
4b6a0825
Branches
Branches containing commit
No related tags found
1 merge request
!20
htmlentities: remove unneeded methods; simplify icon methods; update phpdocs
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
public_html/classes/htmlelements.class.php
+15
-118
15 additions, 118 deletions
public_html/classes/htmlelements.class.php
with
15 additions
and
118 deletions
public_html/classes/htmlelements.class.php
+
15
−
118
View file @
59275159
...
...
@@ -17,26 +17,19 @@
* @author Axel
*
* 2024-07-04 <axel.hahn@unibe.ch> added type declarations; update php docs
* 2024-08-26 <axel.hahn@unibe.ch> remove unneeded methods; simplify icon methods; update phpdocs
*/
class
htmlelements
{
/**
* set of auto generated icon prefixes
* @var array
*/
var
$_aIcons
=
[
// 'fa-'=>'fa ',
];
/**
* label of an html tag (pseudo attribute)
* Extracted label from array with attributes
* @var string
*/
var
$_sLabel
=
''
;
/**
*
hash
of attributes
and values of
a
n
html tag
*
Array
of attributes
for
a html tag
* @var array
*/
var
$_aAttributes
=
[];
...
...
@@ -48,7 +41,7 @@ class htmlelements
public
function
__construct
()
{
return
true
;
// nothiung here
}
// ----------------------------------------------------------------------
...
...
@@ -60,6 +53,7 @@ class htmlelements
/**
* generate html attibutes with all internal attributes key -> values
* to be added in opening tag
* @return string
*/
protected
function
_addAttributes
():
string
...
...
@@ -69,15 +63,14 @@ class htmlelements
if
(
is_array
(
$sValue
))
{
echo
"ERROR: an html tag was defined with array in attribute [
$sAttr
]:<br><pre>"
.
print_r
(
$this
->
_aAttributes
,
1
)
.
"</pre>"
;
}
$sReturn
.
=
' '
.
$sAttr
.
'="'
.
$sValue
.
'"'
;
$sReturn
.
=
"
$sAttr
=
\"
$sValue
\"
"
;
}
return
$sReturn
;
}
/**
*
i
nternal helper: fetch all attributes from key-value hash;
*
I
nternal helper: fetch all attributes from key-value hash;
* Specialties here:
* - label will be extracted from key 'label'
* - and optional existing key 'icon' will be added at beginning of a label
...
...
@@ -108,12 +101,12 @@ class htmlelements
// ----------------------------------------------------------------------
/**
*
g
eneric function to get html code for a single tag
*
G
eneric function to get html code for a single tag
*
* @param string $sTag tag name
* @param array $aAttributes array with attributes (optional including 'icon' and 'label')
* @param boolean $bCloseTag optional: set false if tag has no closing tag (= ending with "/>")
* @return
typ
e
* @return
string html cod
e
*/
public
function
getTag
(
string
$sTag
,
array
$aAttributes
,
bool
$bCloseTag
=
true
):
string
{
...
...
@@ -130,118 +123,22 @@ class htmlelements
// ----------------------------------------------------------------------
/**
* get html code for an icon
* includes a helper detect prefix of a string add prefix of a framework
* Helper detect prefix of a string add prefix of a framework
* i.e. value "fa-close" detects font awesome and adds "fa " as prefix
*
* @param string $sIconclass
name of the icon
* @return string
* @param string $sIconclass
* @return string
HTML code
*/
public
function
getIcon
(
string
$sIconclass
=
''
):
string
{
if
(
!
$sIconclass
)
{
return
''
;
}
$sPrefix
=
''
;
foreach
(
$this
->
_aIcons
as
$sPrefix
=>
$add
)
{
if
(
strpos
(
$sIconclass
,
$sPrefix
)
===
0
)
{
$sPrefix
=
$add
;
continue
;
}
}
return
'<i class="'
.
$sPrefix
.
$sIconclass
.
'"></i> '
;
}
// do not use this .. it overrides internal attribute vars
// return $this->getTag('i', ['class'=>$sIconclass]);
// ----------------------------------------------------------------------
//
// PUBLIC FUNCTIONS
// HTML COMPONENTS
//
// ----------------------------------------------------------------------
/**
* get html code for an input field
*
* @param array $aAttributes attributes of the select tag
* @return string
*/
public
function
getFormInput
(
array
$aAttributes
):
string
{
$sTpl
=
'<input %s/>'
;
$this
->
_setAttributes
(
$aAttributes
);
return
sprintf
(
$sTpl
,
$this
->
_addAttributes
());
}
/**
* get html code for an option field in a select drop down
*
* @param array $aAttributes attributes of the option tag
* @return string
*/
public
function
getFormOption
(
array
$aAttributes
):
string
{
$sTpl
=
'<option %s>%s</option>'
;
$this
->
_setAttributes
(
$aAttributes
);
return
sprintf
(
$sTpl
,
$this
->
_addAttributes
(),
$this
->
_sLabel
);
}
/**
* get html code for a select drop down
*
* @param array $aAttributes attributes of the select tag
* @param array $aOptions array for all option fields
* @return string
*/
public
function
getFormSelect
(
array
$aAttributes
,
array
$aOptions
=
[]):
string
{
// $sTpl = '<select %s>%s</select>';
if
(
!
count
(
$aOptions
))
{
return
''
;
}
$sOptions
=
''
;
foreach
(
$aOptions
as
$aOptionAttributes
)
{
// $sOptions.=$this->getFormOption($aOptionAttributes);
$sOptions
.
=
$this
->
getTag
(
'option'
,
$aOptionAttributes
);
}
$aAttributes
[
'label'
]
=
$sOptions
;
return
$this
->
getTag
(
'select'
,
$aAttributes
);
return
"<i class=
\"
$sIconclass
\"
></i> "
;
}
/**
* Generates an HTML table based on the provided header and body arrays.
*
* @param array $aHead An array of strings representing the table headers.
* @param array $aBody A 2-dimensional array of strings representing the table body rows and cells.
* @param array $aTableAttributes An optional array of attributes to be applied to the table element.
* @return string The HTML code for the generated table.
*/
public
function
getTable
(
array
$aHead
,
array
$aBody
,
array
$aTableAttributes
=
[]):
string
{
$sReturn
=
''
;
$sTdata
=
''
;
$sThead
=
''
;
$sTpl
=
'<table %s>'
.
'<thead><tr>%s</tr></thead>'
.
'<tbody>%s</tbody>'
.
'</table>'
;
foreach
(
$aHead
as
$sTh
)
{
$sThead
.
=
'<th>'
.
$sTh
.
'</th>'
;
}
foreach
(
$aBody
as
$aTr
)
{
$sTdata
.
=
'<tr>'
;
foreach
(
$aTr
as
$sTd
)
{
$sTdata
.
=
'<td>'
.
$sTd
.
'</td>'
;
}
$sTdata
.
=
'</tr>'
;
}
$this
->
_setAttributes
(
$aTableAttributes
);
return
sprintf
(
$sTpl
,
$this
->
_addAttributes
(),
$sThead
,
$sTdata
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment