Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
20.00% |
4 / 20 |
CRAP | |
19.59% |
29 / 148 |
| THtmlPage | |
0.00% |
0 / 1 |
|
20.00% |
4 / 20 |
3222.36 | |
19.05% |
28 / 147 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
19 / 19 |
|||
| show | |
0.00% |
0 / 1 |
182 | |
0.00% |
0 / 21 |
|||
| addJsCssFile | |
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 8 |
|||
| getArrJsCssFile | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getPathJsCssFiles | |
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 20 |
|||
| includeJsCssFiles | |
0.00% |
0 / 1 |
72 | |
0.00% |
0 / 14 |
|||
| addInBody | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 6 |
|||
| addInTitle | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 6 |
|||
| addInHead | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 6 |
|||
| addForm | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getForm | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| addJavascript | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 6 |
|||
| getJavascript | |
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 21 |
|||
| getBody | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| addStyle | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getJsOnLoad | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| setJsOnLoad | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| getCharset | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
| getContentType | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| setTitle | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| getTitle | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setFavIcon | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getFavIcon | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| 1 | <?php |
| 2 | /* |
| 3 | * Formdin Framework |
| 4 | * Copyright (C) 2012 Ministério do Planejamento |
| 5 | * Criado por Luís Eugênio Barbosa |
| 6 | * Essa versão é um Fork https://github.com/bjverde/formDin |
| 7 | * |
| 8 | * ---------------------------------------------------------------------------- |
| 9 | * This file is part of Formdin Framework. |
| 10 | * |
| 11 | * Formdin Framework is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Lesser General Public License version 3 |
| 13 | * as published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public License version 3 |
| 21 | * along with this program; if not, see <http://www.gnu.org/licenses/> |
| 22 | * or write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 23 | * Fifth Floor, Boston, MA 02110-1301, USA. |
| 24 | * ---------------------------------------------------------------------------- |
| 25 | * Este arquivo é parte do Framework Formdin. |
| 26 | * |
| 27 | * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou |
| 28 | * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação |
| 29 | * do Software Livre (FSF). |
| 30 | * |
| 31 | * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA |
| 32 | * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou |
| 33 | * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português |
| 34 | * para maiores detalhes. |
| 35 | * |
| 36 | * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título |
| 37 | * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> |
| 38 | * ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 39 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 40 | */ |
| 41 | |
| 42 | include_once( 'autoload_formdin.php'); |
| 43 | /** |
| 44 | * Classe para gerar a pagina HMTL |
| 45 | */ |
| 46 | class THtmlPage extends TElement |
| 47 | { |
| 48 | private static $arrJsCssFile; |
| 49 | private static $arrJsOnLoad; |
| 50 | private static $style; |
| 51 | private static $js; |
| 52 | private $objHtml; |
| 53 | private $objHead; |
| 54 | private $objTitle; |
| 55 | private $objBody; |
| 56 | private $objForm; |
| 57 | private $favIcon; |
| 58 | |
| 59 | public function __construct() { |
| 60 | parent::__construct('DOCTYPE'); |
| 61 | |
| 62 | // elstilo da página |
| 63 | self::$style = new TElement('style'); |
| 64 | // scripts da página |
| 65 | self::$js = new TElement('script'); |
| 66 | $this->objHtml = new TElement('html'); |
| 67 | $this->objHtml->clearCss(); |
| 68 | $this->add($this->objHtml); |
| 69 | //$this->objHtml->setProperty('lang','pt-br'); |
| 70 | $this->objHead = new TElement('head'); |
| 71 | $this->objHead->clearCss(); |
| 72 | $this->objHtml->add($this->objHead); |
| 73 | |
| 74 | $this->objBody = new TElement('body'); |
| 75 | $this->objBody->clearCss(); |
| 76 | $this->objHtml->add($this->objBody); |
| 77 | $this->objHead->add('<meta http-equiv="Expires" content="Tue, 20 Aug 1996 14:25:27 GMT">'); |
| 78 | $this->objHead->add('<meta charset="'.$this->getCharset().'">'); |
| 79 | $this->objHead->add(HtmlHelper::getViewPort()); |
| 80 | |
| 81 | $this->objTitle = new TElement('title'); |
| 82 | $this->objTitle->clearCss(); |
| 83 | $this->objHead->add($this->objTitle); |
| 84 | } |
| 85 | /** |
| 86 | * Método para gerar o html da página |
| 87 | * Se $print for false retorna o html se for true manda para o browser |
| 88 | * |
| 89 | * @param boolean $print |
| 90 | * @return mixed |
| 91 | */ |
| 92 | public function show($print=true) { |
| 93 | if( !$this->getParentControl() ) { |
| 94 | $this->includeJsCssFiles(); |
| 95 | if( self::$style->getChildren()) { |
| 96 | $this->addInHead(self::$style); |
| 97 | } |
| 98 | $this->getJavascript(); |
| 99 | } |
| 100 | if($this->getFavIcon()) { |
| 101 | $this->addInHead('<link rel="shortcut icon" href="'.$this->getFavIcon().'" />'); |
| 102 | } |
| 103 | if( $this->getForm()) { |
| 104 | //$this->addJsFile($this->objForm->getJs()); |
| 105 | $this->addInBody($this->objForm); |
| 106 | } |
| 107 | if ( $this->objBody->getChildren()) { |
| 108 | foreach($this->objBody->getChildren() as $child ) { |
| 109 | if(is_object($child) && method_exists($child,'getFieldType') && $child->getFieldType() == 'form') { |
| 110 | //print 'tem um formulario'; |
| 111 | $this->addJsCssFile($child->getJsCss()); |
| 112 | // o form já esta dentro de uma tag html, então nao precisa imprimir a tag html nes os js e css dele |
| 113 | if ( method_exists( $child, 'autoIncludeJsCss' ) ) { |
| 114 | $child->autoIncludeJsCss(false); |
| 115 | } |
| 116 | if ( method_exists( $child, 'showHtmlTag' ) ) { |
| 117 | $child->showHtmlTag(false); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | // inserir no HEAD as funções e comandos javascripts |
| 123 | //if( $js = $this->getJavascript()) |
| 124 | //{ |
| 125 | /*$js = new TElement('script'); |
| 126 | $js->clearCss(); |
| 127 | $js->add('jQuery(document).ready(function() {'); |
| 128 | $js->add(chr(9).'// javasripts que serão executados depois que o documento estiver 100% carregado.'); |
| 129 | foreach($this->getJavascript() as $k=>$strJs) |
| 130 | { |
| 131 | $js->add(chr(9).str_replace(";;",";",$strJs.";")); |
| 132 | } |
| 133 | $js->add('});'); |
| 134 | */ |
| 135 | //$this->addInHead($js); |
| 136 | //} |
| 137 | if($this->getParentControl()){ |
| 138 | $this->getBody()->setTagType(''); |
| 139 | return $this->getBody()->show($print); |
| 140 | } else { |
| 141 | return parent::show($print); |
| 142 | } |
| 143 | } |
| 144 | /** |
| 145 | * Médoto para adicionar um arquivo javascript ou css na página |
| 146 | * se o arquivo estiver na pasta padrão base/js ou base/css |
| 147 | * não precisa informar o caminho |
| 148 | * Pode ser informado um array de arquivos no formato key/value |
| 149 | * |
| 150 | * @param string $mixJsCssFile |
| 151 | */ |
| 152 | public function addJsCssFile($mixJsCssFile) { |
| 153 | if( is_array($mixJsCssFile) ) { |
| 154 | foreach($mixJsCssFile as $file) { |
| 155 | $this->addJsCssFile($file); |
| 156 | } |
| 157 | } else if( is_string($mixJsCssFile) ) { |
| 158 | // ignorar se já tiver adicionado |
| 159 | $notArray = !is_array(self::$arrJsCssFile); |
| 160 | if( $notArray || !isset($mixJsCssFile) || array_search($mixJsCssFile,self::$arrJsCssFile,true) === false) { |
| 161 | self::$arrJsCssFile[] = $mixJsCssFile; |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | public function getArrJsCssFile() { |
| 167 | return self::$arrJsCssFile; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Verifica se o arquivo existe e devolve o caminho. Se não existir |
| 172 | * retona null |
| 173 | * @param array $aFile |
| 174 | * @return NULL|string |
| 175 | */ |
| 176 | protected function getPathJsCssFiles($file) |
| 177 | { |
| 178 | $aFile = explode('?',$file); |
| 179 | $aFile[1] = ( isset( $aFile[1]) ? $aFile[1] : '' ); |
| 180 | if( !file_exists( $aFile[0] ) ) { |
| 181 | $fileTemp = $this->getBase().'js/'.$aFile[0]; |
| 182 | |
| 183 | if( file_exists($fileTemp) ){ |
| 184 | $file = $fileTemp.$aFile[1]; |
| 185 | } else { |
| 186 | $fileTemp = $this->getBase().'css/'.$aFile[0]; |
| 187 | if(file_exists($fileTemp)) { |
| 188 | $file = $fileTemp.$aFile[1]; |
| 189 | } else { |
| 190 | $fileTemp = $this->getRoot().'css/'.$aFile[0]; |
| 191 | if(file_exists($fileTemp)) { |
| 192 | $file = $fileTemp.$aFile[1]; |
| 193 | } else { |
| 194 | $fileTemp = $this->getRoot().'js/'.$aFile[0]; |
| 195 | if(file_exists($fileTemp)) { |
| 196 | $file = $fileTemp.$aFile[1]; |
| 197 | } else { |
| 198 | $file = null; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | if ( $file == null && file_exists($this->getBase().$aFile[0]) ){ |
| 206 | $file = $this->getBase().$aFile[0]; |
| 207 | } else { |
| 208 | $message = __CLASS__.' failed to load file:'.$aFile[0]; |
| 209 | //MessageHelper::logRecordSimple($message); |
| 210 | } |
| 211 | |
| 212 | return $file; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Método interno para gerar o codigo html de inserção do arquivo js |
| 217 | * |
| 218 | */ |
| 219 | protected function includeJsCssFiles() |
| 220 | { |
| 221 | if( is_array(self::$arrJsCssFile)) { |
| 222 | $jquery=false; |
| 223 | foreach(self::$arrJsCssFile as $file) { |
| 224 | $file = $this->getPathJsCssFiles($file); |
| 225 | if($file) { |
| 226 | if( strpos($file,'.js')) { |
| 227 | $this->objHead->add('<script type="text/javascript" src="'.$file.'"></script>'); |
| 228 | if( strpos($file,'jquery')!==false) { |
| 229 | $jquery=true; |
| 230 | } |
| 231 | } else if( strpos($file,'.css')) { |
| 232 | $this->objHead->add('<link rel="stylesheet" type="text/css" href="'.$file.'" />'); |
| 233 | |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | if( $jquery ) { |
| 238 | $this->objHead->add('<script>try{jQuery.noConflict();}catch(e){}</script>'); |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | /** |
| 243 | * Adiciona conteudo dentro da tag body. Pode ser um texto ou outro objeto da classe Element |
| 244 | * |
| 245 | * @param mixed $child |
| 246 | */ |
| 247 | public function addInBody($child) |
| 248 | { |
| 249 | if( is_array($child) ) { |
| 250 | foreach ($child as $v) { |
| 251 | $this->objBody->add($v); |
| 252 | } |
| 253 | } else { |
| 254 | if($child != null ) { |
| 255 | $this->objBody->add($child); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Adiciona conteudo dentro da tag title. Pode ser um texto ou outro objeto da classe Element |
| 262 | * |
| 263 | * @param mixed $child |
| 264 | */ |
| 265 | public function addInTitle($child) |
| 266 | { |
| 267 | if( is_array($child) ) { |
| 268 | foreach ($child as $v) { |
| 269 | $this->objTitle->add($v); |
| 270 | } |
| 271 | } else { |
| 272 | if($child != null ) { |
| 273 | $this->objTitle->add($child); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Adiciona conteudo dentro da tag head. Pode ser um texto ou outro objeto da classe Element |
| 280 | * |
| 281 | * @param mixed $child |
| 282 | */ |
| 283 | public function addInHead($child) |
| 284 | { |
| 285 | if( is_array($child) ) { |
| 286 | foreach ($child as $v) { |
| 287 | $this->objHead->add($v); |
| 288 | } |
| 289 | } else { |
| 290 | if($child != null ) { |
| 291 | $this->objHead->add($child); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | public function addForm($strTitle=null, $strFormName=null, $strWidth=null, $strHeight=null, $strMethod=null, $strAction=null) |
| 297 | { |
| 298 | $this->objForm = new TForm($strTitle, $strHeight, $strWidth, $strFormName, $strMethod, $strAction); |
| 299 | return $this->objForm; |
| 300 | } |
| 301 | public function getForm() |
| 302 | { |
| 303 | return $this->objForm; |
| 304 | } |
| 305 | //----------------------------------------------------------------------------- |
| 306 | /** |
| 307 | * Método para adicionar funções javascript na pagina que serão executadas |
| 308 | * após o mesmo tiver sido completamente carregado pelo browser |
| 309 | * O parametro, opcional, $intIndex deve ser utilizado para estabelecer a ordem de |
| 310 | * execução, os menores serão executados primeiro; |
| 311 | * ex: addJavascript("alert('mensagem 1')"); |
| 312 | * addJavascript("alert('mensagem 2')",10); |
| 313 | * |
| 314 | * @param mixed $mixJs |
| 315 | * @param integer $intIndex |
| 316 | */ |
| 317 | public function addJavascript( $mixJs ,$intIndex=null ) { |
| 318 | if( isset($intIndex) ) { |
| 319 | self::$arrJsOnLoad[$intIndex] = $mixJs; |
| 320 | } else { |
| 321 | if( !is_array(self::$arrJsOnLoad) ) { |
| 322 | // começar no indice 20 para poder inserir algum javascript que precise |
| 323 | // ser executado primeiro |
| 324 | self::$arrJsOnLoad[20] = $mixJs; |
| 325 | } else { |
| 326 | self::$arrJsOnLoad[] = $mixJs; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | //----------------------------------------------------------------------------- |
| 331 | /** |
| 332 | * Retorna o texto javascript ou o objeto javascripts adicionados na pagina |
| 333 | * |
| 334 | */ |
| 335 | public function getJavascript($boolReturnText=false,$boolOnLoad=true) |
| 336 | { |
| 337 | $boolReturnText = $boolReturnText === null ? false : $boolReturnText; |
| 338 | $boolOnLoad = $boolOnLoad === null ? true : $boolOnLoad; |
| 339 | $arrTemp=null; |
| 340 | if(is_array(self::$arrJsOnLoad)) { |
| 341 | $arrTemp = (array)self::$arrJsOnLoad; |
| 342 | // colocar em ordem crescente de execução |
| 343 | ksort($arrTemp); |
| 344 | self::$js->setProperty('language','javascript'); |
| 345 | self::$js->clearCss(); |
| 346 | if( $boolOnLoad ) { |
| 347 | self::$js->add('if( typeof jQuery=="function" ){try{ jQuery(document).ready(function() {'); |
| 348 | } |
| 349 | self::$js->add(chr(9).'// javasripts que serão executados depois que o documento estiver 100% carregado.'); |
| 350 | foreach($arrTemp as $mixJs) { |
| 351 | if( is_object( $mixJs ) ) { |
| 352 | self::$js->add( $mixJs ); |
| 353 | } else { |
| 354 | self::$js->add(chr(9).str_replace(";;",";",$mixJs.";")); |
| 355 | } |
| 356 | } |
| 357 | if( $boolOnLoad) { |
| 358 | self::$js->add('})} catch(e){ alert( e.message ); } }'); |
| 359 | } |
| 360 | if( $boolReturnText===true ) { |
| 361 | return self::$js->show(false); |
| 362 | } else { |
| 363 | $this->addInHead(self::$js); |
| 364 | } |
| 365 | } |
| 366 | return null; |
| 367 | } |
| 368 | public function getBody() { |
| 369 | return $this->objBody; |
| 370 | } |
| 371 | |
| 372 | public function addStyle($strStyle) { |
| 373 | self::$style->add($strStyle); |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * compatibilidade com jLayou |
| 378 | * @codeCoverageIgnore |
| 379 | */ |
| 380 | public function getJsOnLoad() { |
| 381 | return null; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * @codeCoverageIgnore |
| 386 | */ |
| 387 | public function setJsOnLoad(){} |
| 388 | |
| 389 | public function getCharset() { |
| 390 | if ( ! defined('CHARSET') ) { |
| 391 | define('CHARSET', ENCODINGS); |
| 392 | } |
| 393 | return CHARSET; |
| 394 | } |
| 395 | /** |
| 396 | * @deprecated - substituido pelo método getCharset(); |
| 397 | * @codeCoverageIgnore |
| 398 | */ |
| 399 | public function getContentType() { |
| 400 | return $this->getCharset(); |
| 401 | } |
| 402 | |
| 403 | public function setTitle($strNewValue=null) |
| 404 | { |
| 405 | $this->objTitle->clearChildren(); |
| 406 | $this->objTitle->add($strNewValue); |
| 407 | } |
| 408 | |
| 409 | public function getTitle() |
| 410 | { |
| 411 | return $this->objTitle->getChildren[0]; |
| 412 | } |
| 413 | |
| 414 | public function setFavIcon($urlImage=null) |
| 415 | { |
| 416 | $this->favIcon=$urlImage; |
| 417 | } |
| 418 | public function getFavIcon() |
| 419 | { |
| 420 | $result = $this->favIcon; |
| 421 | if( empty($this->favIcon) ){ |
| 422 | $result = $this->getBase().'/imagens/favicon-32x32.png'; |
| 423 | } |
| 424 | return $result; |
| 425 | } |
| 426 | } |
| 427 | ?> |