class Estilos extends BD {
public $caminho;
public $css_inicial;
public $css_painel;
public $css_screen;
public $css_print;
public $css;
public $tipo;
public function __construct($tipo="", $caminho="css") {
$this->caminho = $caminho;
if (!empty($tipo)) {
$css_tipo = "css_".$tipo;
$this->$css_tipo = $this->listarCss($tipo);
return $this->$css_tipo;
}
$this->css_inicial = $this->listarCss("inicial");
$this->css_painel = $this->listarCss("painel");
$this->css_screen = $this->listarCss("screen");
$this->css_print = $this->listarCss("print");
$this->css = array_merge($this->css_inicial, $this->css_painel, $this->css_screen, $this->css_print);
}
public function __toString() {
header("Content-type: text/css");
$tipo = $this->tipo;
if(!empty($tipo)) {
$css_tipo = "_".$tipo;
}
$css_tipo = "css".$css_tipo;
$estilos = $this->$css_tipo;
if(is_array($estilos)) {
$estilos = "\n/* +++ CSS: $tipo +++ */\n\n" . implode("\n\n/* " . str_repeat(".", 72) . " */\n\n", $this->$css_tipo);
}
return $estilos;
}
private function listarCss($tipo="painel") {
switch ($tipo) {
case "inicial":
return array($this->cssInicial());
break;
case "painel":
return array($this->estilosPainel());
break;
case "print":
$pasta = $this->caminho . "/impressao";
$ext = "css";
break;
default:
$pasta = $this->caminho;
$ext = "css";
}
$arquivos = listar($pasta, $ext);
$css = array();
if (!empty($arquivos))
foreach ($arquivos as $indice => $arquivo) {
$css[] = "/* $arquivo */\n\n".file_get_contents("$pasta/" . $arquivo);
}
return $css;
}
public function incorporar($tipo="screen", $midia="screen") {
$var_tipo = "css_" . $tipo;
if (!empty($this->$var_tipo)) {
$estilos = "\n\n";
return $estilos;
}
return false;
}
public function linkar($tipo="screen", $midia="screen") {
$var_tipo = "css_" . $tipo;
if (!empty($this->$var_tipo)) {
$estilos = "\n";
return $estilos;
}
return false;
}
public function cssInicial() {
$estilos = "
html,body {
height: 100%;
padding: 0;
margin: 0;
}
* {
padding:0;
margin: 0;
}
table {
padding:0;
margin:0;
}
img {
border:none;
}
";
return $estilos;
}
private function estilosPainel($tipo="painel") {
$Banco = new BD;
$arr_estilos = $Banco->bd_lista("SELECT * FROM ger_estilo WHERE lixo = 0");
$estilos = "";
foreach ($arr_estilos as $chave => $L) {
foreach ($L as $atributo => $valor) {
$$atributo = $valor;
}
if (!$tag)
$estilos .= ".";
$estilos .= $nome . " {\n";
if (!empty($fonte))
$estilos .= " font-family: $fonte;\n";
if (!empty($tamanho))
$estilos .= " font-size: " . $tamanho . "px;\n";
if (!empty($italico))
$estilos .= " font-style: $italico;\n"; else
$estilos .= " font-style: normal;\n";
if (!empty($negrito))
$estilos .= " font-weight: $negrito;\n"; else
$estilos .= " font-weight: normal;\n";
if (!empty($cor))
$estilos .= " color: #$cor;\n";
if (!empty($sublinhado))
$estilos .= " text-decoration: $sublinhado;\n"; else
$estilos .= " text-decoration: none;\n";
if (!empty($fundo))
$estilos .= " background-color: #$fundo;\n";
if (!empty($fundo_imagem))
$estilos .= " background-image: url($fundo_imagem);\n";
if (!empty($fundo_posicao))
$estilos .= " background-position: $fundo_posicao;\n";
if (!empty($fundo_repete))
$estilos .= " background-repeat: $fundo_repete;\n";
if (!empty($fundo_movimento))
$estilos .= " background-attachment: $fundo_movimento;\n";
if (!empty($padding))
$estilos .= " padding: $padding;\n";
if (!empty($margem))
$estilos .= " margin: $margem;\n";
if (!empty($largura))
$estilos .= " width: $largura$largura_unidade;\n";
if (!empty($altura))
$estilos .= " height: $altura$altura_unidade;\n";
if (!empty($alinhamento))
$estilos .= " text-align: $alinhamento;\n";
if (!empty($alinhamentov))
$estilos .= " vertical-align: $alinhamentov;\n";
if (!empty($float))
$estilos .= " float: $float;\n";
if (!empty($clear))
$estilos .= " clear: $clear;\n";
if (!empty($display))
$estilos .= " display: $display;\n";
if (!empty($lineHeight))
$estilos .= " line-height: ".$lineHeight."px;\n";
if (!empty($textIndent))
$estilos .= " text-indent: ".$textIndent."px;\n";
if (!empty($textTransform))
$estilos .= " text-transform: $textTransform;\n";
if (!empty($fontVariant))
$estilos .= " font-variant: $fontVariant;\n";
if (!empty($listStyle))
$estilos .= " list-style: $listStyle;\n";
if (!empty($position))
$estilos .= " position: $position;\n";
if (!empty($overflow))
$estilos .= " overflow: $overflow;\n";
if (!empty($letterSpacing))
$estilos .= " letter-spacing:" . $letterSpacing . "px;\n";
if (!empty($minWidth))
$estilos .= " min-width: $minWidth;\n";
if (!empty($maxWidth))
$estilos .= " max-width: $maxWidth;\n";
if (!empty($minHeight))
$estilos .= " min-Height: $minHeight;\n";
if (!empty($maxHeight))
$estilos .= " max-height: $maxHeight;\n";
//bordas:
if (!empty($bordasuplargura) || !empty($bordasupestilo) || !empty($bordasupcor)) {
$borda = " border-top: ";
if (!empty($bordasuplargura))
$borda .= $bordasuplargura . "px";
if (!empty($bordasupestilo))
$borda .= " $bordasupestilo";
if (!empty($bordasupcor))
$borda .= " #$bordasupcor";
$borda .= ";";
}
if ($borda != " border-top: none;") {
$estilos .= $borda . "\n";
}
if (!empty($bordadirlargura) || !empty($bordadirestilo) || !empty($bordadircor)) {
$borda = " border-right: ";
if (!empty($bordadirlargura))
$borda .= $bordadirlargura . "px";
if (!empty($bordadirestilo))
$borda .= " $bordadirestilo";
if (!empty($bordadircor))
$borda .= " #$bordadircor";
$borda .= ";";
}
if ($borda != " border-right: none;") {
$estilos .= $borda . "\n";
}
if (!empty($bordainflargura) || !empty($bordainfestilo) || !empty($bordainfcor)) {
$borda = " border-bottom: ";
if (!empty($bordainflargura))
$borda .= $bordainflargura . "px";
if (!empty($bordainfestilo))
$borda .= " $bordainfestilo";
if (!empty($bordainfcor))
$borda .= " #$bordainfcor";
$borda .= ";";
}
if ($borda != " border-bottom: none;") {
$estilos .= $borda . "\n";
}
if (!empty($bordaesqlargura) || !empty($bordaesqestilo) || !empty($bordaesqcor)) {
$borda = " border-left: ";
if (!empty($bordaesqlargura))
$borda .= $bordaesqlargura . "px";
if (!empty($bordaesqestilo))
$borda .= " $bordaesqestilo";
if (!empty($bordaesqcor))
$borda .= " #$bordaesqcor";
$borda .= ";";
}
if ($borda != " border-left: none;") {
$estilos .= $borda . "\n";
}
$estilos .= " \n}\n";
}
return $estilos;
}
}
?>