Rev 379 | Rev 392 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 379 | Rev 386 | ||
---|---|---|---|
Line 27... | Line 27... | ||
27 | $data = str_replace('\'', '\\\'', $data); |
27 | $data = str_replace('\'', '\\\'', $data); |
28 | return "'" . $data . "'"; |
28 | return "'" . $data . "'"; |
29 | } |
29 | } |
30 | 30 | ||
31 | function trim_br($html) { |
31 | function trim_br($html) { |
- | 32 | $count = 0; |
|
32 | do { $html = preg_replace('@^\s*<\s*br\s*/{0,1}\s*>@isU', '', $html, -1, $count); } while ($count > 0); // left trim |
33 | do { $html = preg_replace('@^\s*<\s*br\s*/{0,1}\s*>@isU', '', $html, -1, $count); } while ($count > 0); // left trim |
33 | do { $html = preg_replace('@<\s*br\s*/{0,1}\s*>\s*$@isU', '', $html, -1, $count); } while ($count > 0); // right trim |
34 | do { $html = preg_replace('@<\s*br\s*/{0,1}\s*>\s*$@isU', '', $html, -1, $count); } while ($count > 0); // right trim |
34 | return $html; |
35 | return $html; |
35 | } |
36 | } |
36 | 37 | ||
37 | function verify_private_public_key($privKey, $pubKey) { |
38 | function verify_private_public_key($privKey, $pubKey) { |
38 | try { |
39 | try { |
39 | if (empty($privKey)) return false; |
40 | if (empty($privKey)) return false; |
40 | if (empty($pubKey)) return false; |
41 | if (empty($pubKey)) return false; |
41 | $data = 'TEST'; |
42 | $data = 'TEST'; |
- | 43 | $encrypted = ''; |
|
- | 44 | $decrypted = ''; |
|
42 | if (!@openssl_public_encrypt($data, $encrypted, $pubKey)) return false; |
45 | if (!@openssl_public_encrypt($data, $encrypted, $pubKey)) return false; |
43 | if (!@openssl_private_decrypt($encrypted, $decrypted, $privKey)) return false; |
46 | if (!@openssl_private_decrypt($encrypted, $decrypted, $privKey)) return false; |
44 | return $decrypted == $data; |
47 | return $decrypted == $data; |
45 | } catch (Exception $e) { |
48 | } catch (Exception $e) { |
46 | return false; |
49 | return false; |
Line 186... | Line 189... | ||
186 | 189 | ||
187 | $res = my_vsprintf($res, $sprintfArgs); |
190 | $res = my_vsprintf($res, $sprintfArgs); |
188 | 191 | ||
189 | return $res; |
192 | return $res; |
190 | } |
193 | } |
- | 194 | ||
- | 195 | function extractHtmlContents($cont) { |
|
- | 196 | // make sure the program works even if the user provided HTML is not UTF-8 |
|
- | 197 | $cont = iconv(mb_detect_encoding($cont, mb_detect_order(), true), 'UTF-8//IGNORE', $cont); |
|
- | 198 | $bom = pack('H*','EFBBBF'); |
|
- | 199 | $cont = preg_replace("/^$bom/", '', $cont); |
|
- | 200 | ||
- | 201 | $out_js = ''; |
|
- | 202 | $m = array(); |
|
- | 203 | preg_match_all('@<script[^>]*>(.+)</script>@ismU', $cont, $m); |
|
- | 204 | foreach ($m[1] as $x) { |
|
- | 205 | $out_js = $x . "\n\n"; |
|
- | 206 | } |
|
- | 207 | ||
- | 208 | $out_css = ''; |
|
- | 209 | $m = array(); |
|
- | 210 | preg_match_all('@<style[^>]*>(.+)</style>@ismU', $cont, $m); |
|
- | 211 | foreach ($m[1] as $x) { |
|
- | 212 | $out_css = $x . "\n\n"; |
|
- | 213 | } |
|
- | 214 | ||
- | 215 | $out_html = $cont; |
|
- | 216 | $out_html = preg_replace('@^(.+)<body[^>]*>@isU', '', $out_html); |
|
- | 217 | $out_html = preg_replace('@</body>.+$@isU', '', $out_html); |
|
- | 218 | $out_html = preg_replace('@<title>.+</title>@isU', '', $out_html); |
|
- | 219 | $out_html = preg_replace('@<h1>.+</h1>@isU', '', $out_html, 1); |
|
- | 220 | $out_html = preg_replace('@<script[^>]*>(.+)</script>@ismU', '', $out_html); |
|
- | 221 | $out_html = preg_replace('@<style[^>]*>(.+)</style>@ismU', '', $out_html); |
|
- | 222 | ||
- | 223 | return array($out_html, $out_js, $out_css); |
|
- | 224 | } |
|
191 | 225 |