|
1
|
|
|
<?php |
|
2
|
|
|
class Zip_Manager extends \ZipArchive |
|
|
|
|
|
|
3
|
|
|
{ |
|
4
|
|
|
|
|
5
|
|
|
const CHMOD = 0755; |
|
6
|
|
|
|
|
7
|
|
|
public function filteredExtractTo($directory, array $filters = null) |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
if (count($filters) === 0) { |
|
10
|
|
|
return $this->extractTo($directory); |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
$this->createDir($directory); |
|
14
|
|
|
|
|
15
|
|
|
$copySource = 'zip://' . $this->filename . '#'; |
|
16
|
|
|
for ($i = 0; $i < $this->numFiles; $i ++) { |
|
17
|
|
|
$entry = $this->getNameIndex($i); |
|
18
|
|
|
$filename = basename($entry); |
|
19
|
|
|
|
|
20
|
|
|
if ($this->matchFileToFilter($filename, $filters)) { |
|
21
|
|
|
$base = dirname($entry); |
|
22
|
|
|
$newPath = $directory . DIRECTORY_SEPARATOR . $base . DIRECTORY_SEPARATOR; |
|
23
|
|
|
$this->createDir($newPath); |
|
24
|
|
|
|
|
25
|
|
|
// extract file |
|
26
|
|
|
copy($copySource . $entry, $newPath . $filename); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function createDir($path) |
|
32
|
|
|
{ |
|
33
|
|
|
if (! is_dir($path)) { |
|
34
|
|
|
if (! mkdir($path, self::CHMOD, true)) { |
|
35
|
|
|
throw new Exception('unable to create path ' . $path); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function matchFileToFilter($filename, array $filters) |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); |
|
43
|
|
|
if (in_array($ext, array_map('strtolower', $filters))) { |
|
44
|
|
|
|
|
45
|
|
|
return true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
foreach ($filters as $i => $filter) { |
|
49
|
|
|
|
|
50
|
|
|
if (! ctype_alnum($filter[0]) && preg_match($filter, $filename)) { |
|
51
|
|
|
return true; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function getTempNam($prefix = "php") |
|
59
|
|
|
{ |
|
60
|
|
|
$tmp = getenv('TMPDIR'); |
|
61
|
|
|
if ($tmp && @is_writable($tmp)) { |
|
62
|
|
|
$tmpDir = $tmp; |
|
63
|
|
|
} elseif (function_exists('sys_get_temp_dir') && @is_writable(sys_get_temp_dir())) { |
|
64
|
|
|
$tmpDir = sys_get_temp_dir(); |
|
65
|
|
|
} |
|
66
|
|
|
return tempnam($tmpDir, $prefix); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
function file_get_contents_curl($url, $file, $referer = null) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
$ch = curl_init(); |
|
72
|
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
73
|
|
|
$f = fopen($file, 'wb'); |
|
74
|
|
|
if (! $f) { |
|
75
|
|
|
return false; |
|
76
|
|
|
} |
|
77
|
|
|
curl_setopt($ch, CURLOPT_FILE, $f); |
|
78
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0); |
|
79
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
80
|
|
|
curl_setopt($ch, CURLOPT_ENCODING, ''); |
|
81
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
82
|
|
|
if ($referer) { |
|
83
|
|
|
curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
84
|
|
|
} |
|
85
|
|
|
$result = curl_exec($ch); |
|
86
|
|
|
if (!$result) { |
|
87
|
|
|
echo curl_error ($ch ); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
curl_close($ch); |
|
90
|
|
|
fclose($f); |
|
91
|
|
|
return $result; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
function getPDOConnection($config) |
|
95
|
|
|
{ |
|
96
|
|
|
$db_driver = $config['database_driver']; |
|
|
|
|
|
|
97
|
|
|
$db_host = $config['database_host']; |
|
|
|
|
|
|
98
|
|
|
$db_name = $config['database_name']; |
|
|
|
|
|
|
99
|
|
|
$db_user = $config['database_user']; |
|
|
|
|
|
|
100
|
|
|
$db_pass = $config['database_password']; |
|
|
|
|
|
|
101
|
|
|
$db_port = $config['database_port']; |
|
|
|
|
|
|
102
|
|
|
$pdo = new PDO("$db_driver:host=$db_host;port=$db_port;dbname=$db_name", $db_user, $db_pass); |
|
|
|
|
|
|
103
|
|
|
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); |
|
104
|
|
|
$pdo->query("SET NAMES 'UTF8'"); |
|
105
|
|
|
return $pdo; |
|
106
|
|
|
} |
|
107
|
|
|
function trim2($s) |
|
108
|
|
|
{ |
|
109
|
|
|
$s = trim($s, " \t\n\r\0\x0B-"); |
|
110
|
|
|
if ('' === $s) { |
|
111
|
|
|
return null; |
|
112
|
|
|
} else { |
|
113
|
|
|
return $s; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
function utf8_encode_recursivo($in) |
|
|
|
|
|
|
117
|
|
|
{ |
|
118
|
|
|
if (is_array($in)) { |
|
119
|
|
|
foreach ($in as $key => $value) { |
|
120
|
|
|
$out[utf8_encode_recursivo($key)] = utf8_encode_recursivo($value); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
} elseif(is_string($in)) { |
|
|
|
|
|
|
123
|
|
|
if(!mb_check_encoding($in, 'UTF-8') |
|
|
|
|
|
|
124
|
|
|
OR !($in === mb_convert_encoding(mb_convert_encoding($in, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) { |
|
|
|
|
|
|
125
|
|
|
$in = mb_convert_encoding($in, 'UTF-8'); |
|
126
|
|
|
} |
|
|
|
|
|
|
127
|
|
|
return $in; |
|
128
|
|
|
} else { |
|
129
|
|
|
return $in; |
|
130
|
|
|
} |
|
131
|
|
|
return $out; |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
class DneHelper |
|
|
|
|
|
|
134
|
|
|
{ |
|
135
|
|
|
|
|
136
|
|
|
protected $url = 'http://dne.procergs.reders/dne/controller.jsp'; |
|
137
|
|
|
|
|
138
|
|
|
protected $key = 'h3d8s74gf5'; |
|
139
|
|
|
|
|
140
|
|
|
protected $ch; |
|
141
|
|
|
|
|
142
|
|
|
protected $cookie; |
|
143
|
|
|
|
|
144
|
|
|
protected $proxy; |
|
145
|
|
|
|
|
146
|
|
|
public function setProxy($var) |
|
147
|
|
|
{ |
|
148
|
|
|
$this->proxy = $var; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
private function _common($header = array()) |
|
|
|
|
|
|
152
|
|
|
{ |
|
153
|
|
|
$this->ch = curl_init(); |
|
154
|
|
|
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); |
|
155
|
|
|
curl_setopt($this->ch, CURLOPT_HEADER, 0); |
|
156
|
|
|
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); |
|
157
|
|
|
if (ini_get('open_basedir')) { |
|
158
|
|
|
|
|
159
|
|
|
} else { |
|
160
|
|
|
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); |
|
161
|
|
|
} |
|
162
|
|
|
$proxy = $this->proxy; |
|
163
|
|
|
if (isset($proxy['type'], $proxy['host'], $proxy['port'])) { |
|
164
|
|
|
curl_setopt($this->ch, CURLOPT_PROXYTYPE, $proxy['type']); |
|
165
|
|
|
curl_setopt($this->ch, CURLOPT_PROXY, $proxy['host']); |
|
166
|
|
|
curl_setopt($this->ch, CURLOPT_PROXYPORT, $proxy['port']); |
|
167
|
|
|
if (isset($proxy['auth'])) { |
|
168
|
|
|
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $proxy['auth']); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
$headApp = array( |
|
172
|
|
|
'Accept: */*', |
|
173
|
|
|
'Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3', |
|
174
|
|
|
'Connection: keep-alive', |
|
175
|
|
|
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8', |
|
176
|
|
|
'Host: dne.procergs.reders', |
|
177
|
|
|
'Pragma: no-cache', |
|
178
|
|
|
'Referer: http://dne.procergs.reders/dne/', |
|
179
|
|
|
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0', |
|
180
|
|
|
'X-Requested-With: XMLHttpRequest' |
|
181
|
|
|
); |
|
182
|
|
|
$headApp = array_merge($headApp, $header); |
|
183
|
|
|
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headApp); |
|
184
|
|
|
if (! $this->cookie) { |
|
185
|
|
|
$tmp = getenv('TMPDIR'); |
|
186
|
|
|
if ($tmp && @is_writable($tmp)) { |
|
187
|
|
|
$tmpDir = $tmp; |
|
188
|
|
|
} elseif (function_exists('sys_get_temp_dir') && @is_writable(sys_get_temp_dir())) { |
|
189
|
|
|
$tmpDir = sys_get_temp_dir(); |
|
190
|
|
|
} |
|
191
|
|
|
$this->cookie = tempnam($tmpDir, "dne"); |
|
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie); |
|
194
|
|
|
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function findByCep($var) |
|
198
|
|
|
{ |
|
199
|
|
|
$this->_common(); |
|
200
|
|
|
$data = http_build_query(array( |
|
201
|
|
|
'action' => 'buscaporcep', |
|
202
|
|
|
'key' => $this->key, |
|
203
|
|
|
'cep' => $var |
|
204
|
|
|
)); |
|
205
|
|
|
$url = $this->url . '?' . $data; |
|
206
|
|
|
curl_setopt($this->ch, CURLOPT_URL, $url); |
|
207
|
|
|
$result = curl_exec($this->ch); |
|
208
|
|
|
curl_close($this->ch); |
|
209
|
|
|
return $this->_decode($result); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
public function find($var = array()) |
|
213
|
|
|
{ |
|
214
|
|
|
$this->_common(); |
|
215
|
|
|
$data = http_build_query(array( |
|
216
|
|
|
'logradouro' => isset($var['logradouro']) ? $var['logradouro'] : '', |
|
217
|
|
|
'localidade' => isset($var['localidade']) ? $var['localidade'] : '', |
|
218
|
|
|
'state' => isset($var['state']) ? $var['state'] : '', |
|
219
|
|
|
'numero' => isset($var['numero']) ? $var['numero'] : '' |
|
220
|
|
|
)); |
|
221
|
|
|
$dataGet = http_build_query(array( |
|
222
|
|
|
'action' => 'pesquisa', |
|
223
|
|
|
'key' => $this->key |
|
224
|
|
|
)); |
|
225
|
|
|
curl_setopt($this->ch, CURLOPT_URL, $this->url . '?' . $dataGet); |
|
226
|
|
|
curl_setopt($this->ch, CURLOPT_POST, 1); |
|
227
|
|
|
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data); |
|
228
|
|
|
$result = curl_exec($this->ch); |
|
229
|
|
|
curl_close($this->ch); |
|
230
|
|
|
return $this->_decode($result); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
private function _decode(&$result) { |
|
|
|
|
|
|
234
|
|
|
if ($result === false) { |
|
235
|
|
|
return false; |
|
236
|
|
|
} |
|
237
|
|
|
$dom = new \DOMDocument(); |
|
238
|
|
|
if (! @$dom->loadXML($result)) { |
|
239
|
|
|
return false; |
|
240
|
|
|
} |
|
241
|
|
|
$node = $dom->getElementsByTagName('valor'); |
|
242
|
|
|
if (! $node) { |
|
243
|
|
|
return false; |
|
244
|
|
|
} |
|
245
|
|
|
return json_decode($node->item(0)->nodeValue, true); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
} |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.