-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 20715ee
Showing
347 changed files
with
118,937 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
<?php | ||
########################################################################################################### | ||
#DataBase.class.php | ||
#Extensão da Classe PDO. | ||
#Com médotos para auxilio de execução de queries. | ||
#Página Orientada a Objetos | ||
#Desenvolvido pela Head Trust | ||
#Criado em: 09/05/2008 | ||
#Modificado em: (26/08/2008) - (13/10/2008) - (19/10/2008) - (20/10/2008) - (30/10/2008)- (14/12/2008) | ||
# - (25/12/2008) - (27/02/2009) - (16/03/2009) - (18/03/2009) - (06/05/2009) - (03/07/2009) - (13/05/2010) | ||
# - (07/02/2011) | ||
########################################################################################################### | ||
|
||
class DataBase extends PDO { | ||
|
||
private $debug, $debugCode; //Atributos de Debug | ||
private $showQuery = 0;//Status do ShowQuery | ||
private $affected = array(), $countedRows = array(), $fetchedResult = array(), $fetchList = array(), $numberResult = 0; //Atributos de resultados de operações | ||
static $_SHOW_OFF = 0, $_SHOW_ON = 1; | ||
|
||
/* | ||
* Métodos get e set dos atributos para acesso externo | ||
*/ | ||
|
||
public function getDbServer(){ | ||
return $this->dbServer; | ||
} | ||
|
||
public function setDbServer($server){ | ||
$this->dbServer = $server; | ||
} | ||
|
||
public function getDbLog(){ | ||
return $this->dbLog; | ||
} | ||
|
||
public function setDbLog($log){ | ||
$this->dbLog = $log; | ||
} | ||
|
||
public function getDbPass(){ | ||
return $this->dbPass; | ||
} | ||
|
||
public function setDbPass($pass){ | ||
$this->dbPass = $pass; | ||
} | ||
|
||
public function getDebug(){ | ||
return $this->debug; | ||
} | ||
|
||
public function setDebug($debug){ | ||
$this->debug = $debug; | ||
} | ||
|
||
/* | ||
* Fim dos métodos get e set | ||
*/ | ||
|
||
//Construtor da classe DataBase :: DataBase() | ||
public function __construct($dbServer, $dbLog, $dbPass){ | ||
try{ | ||
parent::__construct($dbServer, $dbLog, $dbPass); | ||
} catch(Exception $e){} | ||
} | ||
|
||
//Retorna um array com os resultados de uma query | ||
//Parametros: Resultado do método query() | ||
//mixed fetchArray ([int]) | ||
public function fetchArray($result = ''){ | ||
$numberResult = ($result == '') ? $this->numberResult : $result; | ||
$key = $this->fetchList[$numberResult]; | ||
$this->fetchList[$numberResult]++; | ||
if(array_key_exists($key,$this->fetchedResult[$numberResult])){ | ||
return $this->fetchedResult[$numberResult][$key]; | ||
} else { | ||
$this->fetchList[$numberResult] = 0; | ||
return false; | ||
} | ||
} | ||
|
||
//Retorna um array com os resultados de uma query | ||
//Parametros: Resultado do método query() | ||
//mixed fetchAll ([int]) | ||
public function fetchAll($result = ''){ | ||
$numberResult = ($result == '') ? $this->numberResult : $result; | ||
if(array_key_exists($key,$this->fetchedResult[$numberResult])){ | ||
return $this->fetchedResult[$numberResult]; | ||
} else { | ||
$this->fetchList[$numberResult] = 0; | ||
return false; | ||
} | ||
} | ||
|
||
//Retorna a quantidade de linhas afetadas por uma query | ||
//Parametros: Resultado do método query() | ||
//mixedaffectedRows ([int]) | ||
public function affectedRows($result = ''){ | ||
$key = ($result == '') ? $this->numberResult : $result; | ||
if(array_key_exists($key,$this->affected)){ | ||
return $this->affected[$key]; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
//Retorna a quantidade de linhas selecionadas por uma query | ||
//Parametros: Resultado do método query() | ||
//mixed numRows ([int]) | ||
public function numRows($result=''){ | ||
$key = ($result == '') ? $this->numberResult : $result; | ||
if(array_key_exists($key,$this->countedRows)){ | ||
return $this->countedRows[$key]; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
//Retorna um único resultado de uma requisição query | ||
//Parametros: Resultado do método query(), Posição do array, Posição do array ou chave do array associativo | ||
//mixed fetchResult (int, int, mixed) | ||
public function result($result, $position, $column){ | ||
if(array_key_exists($result,$this->fetchedResult)){ | ||
if(array_key_exists($position,$this->fetchedResult[$result])){ | ||
if(array_key_exists($column,$this->fetchedResult[$result][$position])){ | ||
return $this->fetchedResult[$result][$position][$column]; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public function showQuery($status = 1){ | ||
$this->showQuery = $status; | ||
} | ||
//Executa uma query, o parametro bind se for passado irá fazer um bind automático conforme o array | ||
//Parametros: (Query a ser executada, Array de binds) | ||
//mixed query (string $query , [ array $bind ] ) | ||
public function query($query, array $bind = array()){ | ||
if($this->showQuery == self::$_SHOW_ON){ | ||
echo $query . '<br />'; | ||
} | ||
|
||
//Escolhe um número aleatóriamente para o sistema descançar. | ||
$state = parent::prepare($query); | ||
|
||
//É feito um descanço ao sistema | ||
// System::noExhaust(); | ||
|
||
if($state->execute($bind)){ | ||
$this->analysis($state,$query); | ||
return $this->numberResult; | ||
} else { | ||
$this->debug($state->errorInfo(),$query); | ||
return false; | ||
} | ||
} | ||
|
||
//Analisa a query e verifica quais valores devem ser atribuido a quais atributos. | ||
//Parametros (Objeto PDO, Query executada) | ||
//void analysis (Object, String) | ||
private function analysis(PDOStatement $state, $query){ | ||
$numResult = ++$this->numberResult; | ||
$words = explode(' ', $query); | ||
$haystack = array('select', 'show', 'describe', 'explain', 'load', 'flush', 'reset', 'status', 'privileges', 'slave', 'user_resources', 'hosts', 'des_key_files'); | ||
if(!in_array(strtolower($words[0]), $haystack)){ | ||
$this->affected[$numResult] = $state->rowCount(); | ||
} else { | ||
$results = $state->fetchAll(); | ||
$count = count($results); | ||
$this->fetchList[$numResult] = 0; | ||
$this->fetchedResult[$numResult] = $results; | ||
$this->countedRows[$numResult] = $count; | ||
} | ||
} | ||
|
||
//Pega um array de Queries e executa todas dentro de uma trasação | ||
//Parametros (Array de queries a serem executadas, Array de valores para bind) | ||
//bool transaction (Array, [Array]) | ||
public function transaction(array $queries, array $bind = array()){ | ||
parent::beginTransaction(); | ||
$count = count($queries); | ||
for($i = 0; $i < $count; $i++){ | ||
$binding = (isset($bind[$i])) ? $bind[$i] : array(); | ||
$result = $this->query($queries[$i], $binding); | ||
$results[] = ($result != false) ? $this->affectedRows($result) : false; | ||
} | ||
|
||
if(array_search(false, $results, 1) === false){ | ||
parent::commit(); | ||
return true; | ||
} else { | ||
parent::rollBack(); | ||
return false; | ||
} | ||
} | ||
|
||
//Gera uma string contendo todos os erros que foram gerados | ||
//Parametros: (Texto com o erro gerado, A query executada) | ||
//void debug (String, String) | ||
private function debug($errors, $query){ | ||
$this->debug .= "\n[" . ++$this->debugCode . "] Problemas com a execução da query\n"; | ||
$this->debug .= "Erro gerado (" . end($errors) . ")\n"; | ||
$this->debug .= "Query executada (" . $query . ")\n"; | ||
} | ||
|
||
//Limpa todos os grupos atributos de resultados desta classe. | ||
//Parametros: void | ||
//void cleanResults (void) | ||
public function cleanResults(){ | ||
$this->affected = array(); | ||
$this->countedRows = array(); | ||
$this->fetchedResult = array(); | ||
$this->fetchList = array(); | ||
$this->numberResult = null; | ||
} | ||
|
||
//Limpa um único grupo de atributos de resultados desta classe. | ||
//Parametros (Valor retornado pelo método query) | ||
//void cleanSingleResult (int) | ||
public function cleanSingleResult($result){ | ||
if(array_key_exists($result, $this->affected)){ | ||
$this->affected[$result] = array(); | ||
} | ||
|
||
if(array_key_exists($result, $this->countedRows)){ | ||
$this->countedRows[$result] = array(); | ||
} | ||
|
||
if(array_key_exists($result, $this->$this->fetchedResult)){ | ||
$this->$this->fetchedResult[$result] = array(); | ||
} | ||
|
||
if(array_key_exists($result, $this->$this->fetchList)){ | ||
$this->$this->fetchList[$result] = array(); | ||
} | ||
} | ||
|
||
public function __destruct(){} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
For anyone who is interested: | ||
|
||
1) GSView/GhostScript references some tables in the TTF font file called 'cvt ', 'fpgm', and 'gasp' which are optional for Adobe Reader (and other Windows based PDF viewers). These tables contain font "instructions" used to fine-tune the rasterisation of the characters. mPDF <=5.1 did not include these tables in the embedded subset font files it created. Without these tables, any characters which have diacritics (compound glyphs) do not show in GSView, and give error message: "Failed to interpret TT instructions for glyph index ...". This is now fixed by including the 'cvt ' 'fpgm' and 'gasp' tables in mPDF-created embedded subset files. | ||
|
||
N.B. A new set of Indic fonts have been created which include these tables ind_hi_1_001 etc. In the version 1 indic fonts, all ASCII characters were 'imported' from the dejavusanscondensed font - including the space character and the digits which were present in the original files - but the originals are restored in these new files; this is why the word spacing appears to differ | ||
|
||
2) When embedding the full font file, mPDF just embeds a compressed copy of the TTF file in the PDF. For some reason, any TTF file which contains a 'GSUB' table, displayed all the characters with incorrect character spacing - all jumbled - in GSView/GhostScript. The GSUB table is ignored by Adobe Reader, and I cannot imagine why this happens in GSView, as the GSUB table only contains information about glyph substitutions. | ||
This can be fixed in mPDF >= 5.2 by setting mpdf->repackageTTF=true; This forces mPDF to take the original TTF font file, and remove unnecessary tables (especially GSUB) before embedding it in the PDF file. | ||
|
||
3) Error messages "Warning: Font Widths array size is smaller than character range" were due to an error in mPDF when embedding fonts containing characters from the Supplementary Planes (SIP/SMP). This did not seem to affect the display, and is now fixed. | ||
|
||
4) When displaying right-justified or fully-justified text in GSView, the text did not align correctly. This was because of incorrect word-spacing. | ||
The PDF specification says that the Tw command (word spacing) will have no effect when the PDF file content is multibyte/UTF-16 encoded - which is what mPDF uses for everything except core-fonts. mPDF inserts a Tw command to adjust word-spacing, but then adds a horizontal adjustment to create the effect of word spacing. | ||
Adobe reader and others just ignored the Tw command - as the spec. says they would. | ||
GSView/GhostScript added word spacing specified by the Tw command, and then added the extra correction as well. | ||
This is now fixed. | ||
|
||
|
||
P.S. Adding several tables ('cvt ', 'fpgm', 'prep', and 'gasp') into the embedded font subsets has improved the screen display of some fonts (in Adobe Reader at least). |
Oops, something went wrong.