-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoad_assets.php
131 lines (124 loc) · 3.32 KB
/
Load_assets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* Load assets(CSS/JS/JS Code) class
* Classe utilizada para carregar arquivos .css/.js e códigos js, dinamicamente no template HTML.
* Basta apenas informar local dos arquivos(opcional) e o nome do mesmo, esta classe gera código HTML(link/script) para a chamada dos arquivos.
*
* @author Marcelo Garbin <[email protected]>
* @version 1.1
* @link https://bitbucket.org/marcelogarbin/load_assets
*
*/
class Load_assets{
/**
* Variáveis da classe
*/
private $pathCSS;
private $pathJS;
/**
* Define o caminho para a pasta de arquivos CSS
*/
public function base_pathCSS($path = NULL){
if(isset($path)){
$this->pathCSS = $path;
}else{
$this->pathCSS = NULL;
}
}
/**
* Define o caminho para a pasta de arquivos JS
*/
public function base_pathJS($path = NULL){
if(isset($path)){
$this->pathJS = $path;
}else{
$this->pathJS = NULL;
}
}
/**
* Gera os links CSS utilizados no template
*
*/
public function CSSLinks($links = NULL){
// Faz a limpeza do array
$links = array_filter($links);
if(isset($links) && is_array($links)){
if(count($links) > 0){
$html = "";
$count = 0;
foreach($links as $key => $value){
// Verifica se a string no array possui cabeçalho http/https
// Se tiver cabeçalho o caminho do diretorio é removido
$cabecalho = substr($value, 0, strripos($value, ':'));
if($cabecalho === 'http' || $cabecalho === 'https'){
$html .= "<link rel='stylesheet' type='text/css' href='" . $value . ".css' />";
}else{
$html .= "<link rel='stylesheet' type='text/css' href='" . $this->pathCSS . $value . ".css' />";
}
$html .= ($count >= 0) ? "\n\t" : "\t";
$count++;
}
return $html;
}else{
return NULL;
}
}else{
return "\nErro ao Carregar Arquivos .CSS (Verificar Parâmetro).\n";
}
}
/**
* Gera os links JS utilizados no template
*
*/
public function JSLinks($links = NULL){
// Faz a limpeza do array
$links = array_filter($links);
if(isset($links) && is_array($links)){
if(count($links) > 0){
$html = "";
$count = 0;
foreach($links as $key => $value){
// Verifica se a string no array possui cabeçalho http/https
// Se tiver cabeçalho o caminho do diretorio é removido
$cabecalho = substr($value, 0, strripos($value, ':'));
if($cabecalho === 'http' || $cabecalho === 'https'){
$html .= "<script src='" . $value . ".js'></script>";
}else{
$html .= "<script src='" . $this->pathJS . $value . ".js'></script>";
}
$html .= ($count >= 0) ? "\n\t" : "\t";
$count++;
}
return $html;
}else{
return NULL;
}
}else{
return "\nErro ao Carregar Arquivos .JS (Verificar Parâmetro).\n";
}
}
/**
* Gera os código JS utilizados no template após os links JS
*
*/
public function JSCodes($codes = NULL){
// Faz a limpeza do array
$codes = array_filter($codes);
if(isset($codes) && is_array($codes)){
if(count($codes) > 0){
$html = "";
$count = 0;
foreach($codes as $key => $value){
$html .= "<script>\n\t\t" . $value . "\n\t</script>";
$html .= ($count >= 0) ? "\n\t" : "\t";
$count++;
}
return $html;
}else{
return NULL;
}
}else{
return "\nErro ao Carregar Código Javascript (Verificar Parâmetro).\n";
}
}
}