Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.55 KB | None | 0 0
  1. <?php
  2.  
  3. define('SALT','hfdlshvavh;elvha;ohva');
  4.  
  5.  
  6.  
  7. function tampermonkey_retrieve_html($recurred = 1)
  8. {
  9. sleep(1);
  10. $html = Storage::get('/tampermonkey/html.txt');
  11.  
  12. if(strlen($html) < 1)
  13. {
  14. if($recurred < 100)
  15. {
  16.  
  17. $html = tampermonkey_retrieve_html(++$recurred);
  18. }
  19. }
  20. $html = '<html>' . $html . '</html>';
  21. if(strlen($html) > 100)
  22. {
  23. Storage::put('/tampermonkey/cache/' . \Carbon\Carbon::now()->format('Y_m_d_H_i_s') . '.txt', $html);
  24. }
  25. return $html;
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
  32. function tampermonkey_set($url){
  33.  
  34. $data = [];
  35. $data['url'] = $url;
  36. $data['mode'] = 'body';
  37.  
  38. \Storage::put('/tampermonkey/command.json', json_encode($data));
  39. \Storage::put('/tampermonkey/html.txt', '');
  40.  
  41. }
  42.  
  43.  
  44. function clean_tampermonkey()
  45. {
  46. $data = [];
  47. $data['url'] = '';
  48. $data['mode'] = '';
  49.  
  50. \Storage::put('/tampermonkey/command.json', json_encode($data));
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. function multiExplode($delimiters,$string) {
  59. return explode($delimiters[0],strtr($string,array_combine(array_slice($delimiters,1),array_fill(0,count($delimiters)-1,array_shift($delimiters)))));
  60. }
  61.  
  62.  
  63. function trim_all( $str , $what = NULL , $with = ' ' )
  64. {
  65. if( $what === NULL )
  66. {
  67. // Character Decimal Use
  68. // "\0" 0 Null Character
  69. // "\t" 9 Tab
  70. // "\n" 10 New line
  71. // "\x0B" 11 Vertical Tab
  72. // "\r" 13 New Line in Mac
  73. // " " 32 Space
  74.  
  75. $what = "\\x00-\\x20"; //all white-spaces and control chars
  76. }
  77.  
  78. return trim( preg_replace( "/[".$what."]+/" , $with , $str ) , $what );
  79. }
  80.  
  81.  
  82.  
  83. //WEBCACHE
  84.  
  85. function getcache($url) {
  86. if(!file_exists(storage_path().'/webcache/'."w".sha1($url).".html")) {
  87. return false;
  88. }else{
  89. return file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
  90. }
  91. }
  92.  
  93.  
  94.  
  95. /*
  96. function webcache($url,$withpost=true, $phantomjs = false, $strip_tags = false, $try = 1) {
  97.  
  98. if(!file_exists(storage_path().'/webcache/'."w".sha1($url).".html")) {
  99.  
  100.  
  101.  
  102. if($phantomjs)
  103. {
  104. $fgc = phantomjs($url);
  105. }
  106. else
  107. {
  108.  
  109.  
  110. tampermonkey_set($url);
  111. $fgc = tampermonkey_retrieve_html();
  112. clean_tampermonkey();
  113. }
  114.  
  115. if(strlen(trim($fgc)) > 500)
  116. {
  117. file_put_contents(storage_path().'/webcache/'."w".sha1($url).".html",websig($url).$fgc);
  118. }
  119.  
  120. }
  121. else
  122. {
  123. $fgc = file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
  124. }
  125.  
  126. // file_put_contents(storage_path().'/webcache/'."w".sha1($url).".html",websig($url).$fgc);
  127. // $fgc = file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
  128.  
  129. return $fgc;
  130. }
  131. */
  132.  
  133. function the_new_way($url)
  134. {
  135.  
  136. $postfields = 'JSESSIONID=C0B570CA943885FA0AB3197EC2C9E0A1.tmdsview1; TS018f6762=01601e1d32d821bd1ee4c75affdd848cea25b6f472825a5ad6ae9c045beb60d1e923bf24730286d86099f799c5617b5b056450739f4321fc6dcb066ce893afac5895c0ba71; TSPD_101=0827db1318ab2800d24820c53400ecc7ace1a98b8532c404b96c50fe1f84bec6a87b9e89388088801160cb495cde29e0:; TS01a8cc48_77=0827db1318ab2800eb902eca03032f0322da5e111ae774aa2f504829693bd45627c1309382ed48580e4444ba93da4bae08a74963b9823800c9a6cc780c10b89966101c807e9eb82d331ddb3e0c1dc8f48b6591f41ce471c17f44833b9985802b5d93f20fdb71bfef40602343f1484da0; TS01a8cc48=01601e1d329d4ea19df58c9f16aa24db3b5d4517c9ed672b20a4de8c97124c815d15c0ad04f751acc1d2adaca27052d03594f88450; TS01a8cc48_31=01edc21ef03568de230dccb1123540bd88d657c4dc0104b2a87eb1903b17893f19cdd3ea788d6c1d6e0c048cdf27711d56a899f62c; TS018289ca=01601e1d3286a998c5b56097cc9cda769511587a929804f3edf3102034fae0512f558c01644bffcbe1f2a2d32f30168a846922f94a';
  137.  
  138. //$ch = set_proxy($ch);
  139. $ch = curl_init();
  140. curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
  141. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
  142. curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
  143. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
  144. curl_setopt($ch, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce
  145. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
  146. curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
  147. //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
  148. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
  149. curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
  150. curl_setopt($ch, CURLOPT_REFERER, 'https://www.tmdn.org/tmview/get-detail?st13=DE503020170049099');
  151. curl_setopt($ch, CURLOPT_URL,$url );
  152. curl_setopt($ch, CURLOPT_COOKIE, $postfields);
  153. //curl_setopt($ch, CURLOPT_PROXY, $proxy);
  154. //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
  155. //curl_setopt($ch, CURLOPT_POST, 1);
  156. //curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
  157. $curl_scraped_page = curl_exec($ch);
  158. curl_close($ch);
  159. return $curl_scraped_page;
  160.  
  161.  
  162.  
  163.  
  164. }
  165.  
  166.  
  167.  
  168.  
  169.  
  170. function webcache($url,$withpost=true, $phantomjs = false) {
  171.  
  172.  
  173.  
  174. //search log
  175. $logfile = storage_path().'/webcache.log';
  176. if(file_exists($logfile)) $logf = file_get_contents($logfile); else $logf = '';
  177. $logf = $logf.Request::getClientIp()." - ".date("Y-m-d H:i:s")." - ".$url.' - hash: '.sha1($url)."\n";
  178. if(trim($url)!='') file_put_contents($logfile,$logf);
  179. //end search log
  180.  
  181.  
  182. if(!file_exists(storage_path().'/webcache/'."w".sha1($url).".html")) {
  183.  
  184. try {
  185. if($phantomjs)
  186. {
  187. $fgc = phantomjs($url);
  188. }
  189. else if($withpost) //$fgc = file_get_contents_post($url); else $fgc = file_get_contents_ref($url);
  190. $fgc = file_get_contents_post($url);
  191. else $fgc = file_get_contents_ref($url);
  192. //retry once
  193. if(strlen(trim($fgc))<2){
  194. sleep(3);
  195. if($withpost) //$fgc = file_get_contents_post($url); else $fgc = file_get_contents_ref($url);
  196. $fgc = phantomjs($url); else $fgc = file_get_contents_ref($url);
  197. }
  198.  
  199. //retry twice
  200. if(strlen(trim($fgc))<2){
  201. sleep(2);
  202. if($withpost) //$fgc = file_get_contents_post($url); else $fgc = file_get_contents_ref($url);
  203. $fgc = phantomjs($url); else $fgc = file_get_contents_ref($url);
  204. }
  205.  
  206.  
  207.  
  208.  
  209. file_put_contents(storage_path().'/webcache/'."w".sha1($url).".html",websig($url).$fgc);
  210. } catch (Exception $e) {
  211.  
  212. return false;
  213. //return file_get_contents_proxy($url);
  214. }
  215. }else{
  216.  
  217. $fgc = file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
  218. }
  219. return $fgc;
  220. }
  221.  
  222.  
  223.  
  224. function websig($url){
  225. return "";
  226. //return "<!-- url: $url -->".PHP_EOL;
  227. }
  228.  
  229.  
  230. function webcacheproxy($url){
  231. if(!file_exists(storage_path().'/webcache/'."w".sha1($url).".html")) {
  232. try {
  233. $fgc = file_get_contents_proxy($url);
  234. file_put_contents(storage_path().'/webcache/'."w".sha1($url).".html",websig($url).$fgc);
  235. } catch (Exception $e) {
  236. return false;
  237. }
  238. }else{
  239. $fgc = file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
  240. }
  241. return $fgc;
  242. }
  243.  
  244.  
  245.  
  246.  
  247.  
  248. function file_get_contents_post($url){
  249.  
  250. $referer = "https://www.tmdn.org/";
  251.  
  252. $ch = curl_init();
  253.  
  254.  
  255.  
  256. /*
  257. curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
  258. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
  259. curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
  260. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
  261. curl_setopt($ch, CURLOPT_MAXREDIRS, 2); //if http server gives redirection responce
  262. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
  263. //curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
  264. //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
  265. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
  266. curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
  267. curl_setopt($ch, CURLOPT_REFERER, $referer);
  268. curl_setopt($ch, CURLOPT_URL,$url);
  269. //curl_setopt($ch, CURLOPT_PROXY, $proxy);
  270. //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
  271. $curl_scraped_page = curl_exec($ch);
  272. curl_close($ch);
  273. */
  274.  
  275. $postfields = "TSd805d5_id=3&TSd805d5_75=e4c8b93ca2f9ce16fca253c6ada053bd:rqqp:Rh4Awz7S:721943986&TSd805d5_md=1&TSd805d5_rf=https%3a%2f%2fwww.tmdn.org%2f&TSd805d5_ct=0&TSd805d5_pd=0";
  276. //$postfields = 'TS82d731_id=3&TS82d731_75=bedfe8ebd5e7283d8a7ee318a46c721f%3Ajklj%3A28PM92r2%3A1988019743&TS82d731_md=1&TS82d731_rf=0&TS82d731_ct=0&TS82d731_pd=0';
  277. //$postfields = 'TS01a8cc48_id=3&TS01a8cc48_cr=02b2ebe5a9863e8a3913b79553418c16:abda:PQ0Z4Bm6:483549760&TS01a8cc48_76=0&TS01a8cc48_md=1&TS01a8cc48_rf=0&TS01a8cc48_ct=0&TS01a8cc48_pd=0';
  278. $postfields = 'TS01a8cc48_id=3&TS01a8cc48_cr=02518683b2023b8b9fd84e1aa71beebd:sqpo:kbZ809WJ:842733783&TS01a8cc48_76=0&TS01a8cc48_md=1&TS01a8cc48_rf=0&TS01a8cc48_ct=0&TS01a8cc48_pd=0';
  279.  
  280. $postfields = 'TS01a8cc48_id=3&TS01a8cc48_cr=ba19e9ba3ebf528162d88876ef97636d%3Azxwv%3ALBsgkAJU%3A2032000554&TS01a8cc48_76=0&TS01a8cc48_md=1&TS01a8cc48_rf=0&TS01a8cc48_ct=0&TS01a8cc48_pd=0';
  281.  
  282. $ch = set_proxy($ch);
  283.  
  284. curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
  285. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
  286. curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
  287. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
  288. curl_setopt($ch, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce
  289. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
  290. //curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
  291. //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
  292. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
  293. curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
  294. curl_setopt($ch, CURLOPT_REFERER, $referer);
  295. curl_setopt($ch, CURLOPT_URL,$url);
  296. //curl_setopt($ch, CURLOPT_PROXY, $proxy);
  297. //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
  298. curl_setopt($ch, CURLOPT_POST, 1);
  299. curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
  300. $curl_scraped_page = curl_exec($ch);
  301. curl_close($ch);
  302. return $curl_scraped_page;
  303.  
  304. }
  305.  
  306.  
  307. function file_get_contents_ref($url){
  308.  
  309.  
  310.  
  311.  
  312. $referer = "https://www.tmdn.org/";
  313.  
  314. $ch = curl_init();
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321. $ch = set_proxy($ch);
  322.  
  323.  
  324. curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
  325. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
  326. curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
  327. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
  328. curl_setopt($ch, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce
  329. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
  330. //curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
  331. //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
  332. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
  333. curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
  334. curl_setopt($ch, CURLOPT_REFERER, $referer);
  335. curl_setopt($ch, CURLOPT_URL,$url);
  336. //curl_setopt($ch, CURLOPT_PROXY, $proxy);
  337. //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
  338. $curl_scraped_page = curl_exec($ch);
  339.  
  340. curl_close($ch);
  341.  
  342.  
  343.  
  344. return $curl_scraped_page;
  345.  
  346. }
  347.  
  348. function file_get_contents_proxy($url){
  349.  
  350. //$url = 'http://dynupdate.no-ip.com/ip.php';
  351.  
  352. $proxy = '127.0.0.1:8888';
  353. //$proxyauth = 'user:password';
  354. $proxy = '72.159.148.20:10000';
  355. $proxy = '37.59.101.237:3128';
  356. $referer = "https://www.tmdn.org/";
  357.  
  358. $ch = curl_init();
  359.  
  360. curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
  361. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
  362. curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
  363. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
  364. curl_setopt($ch, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce
  365. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
  366. //curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
  367. //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
  368. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
  369. curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
  370. curl_setopt($ch, CURLOPT_REFERER, $referer);
  371. curl_setopt($ch, CURLOPT_URL,$url);
  372. curl_setopt($ch, CURLOPT_PROXY, $proxy);
  373. //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
  374. $curl_scraped_page = curl_exec($ch);
  375. curl_close($ch);
  376.  
  377. return $curl_scraped_page;
  378.  
  379. }
  380.  
  381.  
  382.  
  383.  
  384. function phantomjs($url, $repeated = 0)
  385. {
  386.  
  387.  
  388. $data = [];
  389. $data['url'] = $url;
  390. $data['maxWait'] = 10;
  391. $data['renderType'] = 'html';
  392. $data['requestSettings'] = [
  393. 'userAgent' => 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36',
  394. 'clearCache' => 'false',
  395. 'clearCookies' => 'false',
  396. 'cookies' => [],
  397. 'deleteCookies' => [],
  398. 'ignoreImages' => 'true',
  399. 'resourceWait' => 5000,
  400. 'resourceTimeout' => 50000,
  401. 'maxWait' => 5000,
  402. 'waitInterval' => 1000,
  403. ];
  404.  
  405. /*
  406. $data = [];
  407. $data['url'] = $url;
  408. $data['maxWait'] = 25000;
  409. $data['renderType'] = 'html';
  410. $data['requestSettings'] = [
  411. 'userAgent' => 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36',
  412. 'clearCache' => 'true',
  413. 'clearCookies' => 'false',
  414. 'cookies' => [],
  415. 'deleteCookies' => [],
  416. 'ignoreImages' => 'true',
  417. 'resourceWait' => 10000,
  418. 'resourceTimeout' => 100000,
  419. 'maxWait' => 20000,
  420. 'waitInterval' => 5000,
  421. ];
  422. */
  423.  
  424.  
  425.  
  426. $url = 'https://PhantomJScloud.com/api/browser/v2/ak-jvezz-kgk8a-jd1ac-373w9-3gnps/';
  427.  
  428.  
  429.  
  430.  
  431.  
  432. $payload = json_encode($data);
  433. $options = array(
  434. 'http' => array(
  435. 'header' => "Content-type: application/json\r\n",
  436. 'method' => 'POST',
  437. 'content' => $payload,
  438. )
  439. );
  440.  
  441.  
  442. if (is_array($data))
  443. {
  444. $post = json_encode($data);
  445. }
  446.  
  447.  
  448.  
  449. $ch = curl_init($url);
  450. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  451. curl_setopt($ch, CURLOPT_ENCODING, "UTF-8");
  452. $headers = array( "Accept:" );
  453. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  454. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  455. curl_setopt($ch, CURLOPT_POST, 1);
  456. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  457. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  458. curl_setopt($ch,CURLOPT_TIMEOUT,15000);
  459.  
  460. $result = curl_exec($ch);
  461.  
  462.  
  463. if(strlen(strip_tags($result)) < 500)
  464. {
  465. if($repeated < 6)
  466. {
  467. phantomjs($url, ++$repeated);
  468. }
  469. }
  470.  
  471.  
  472.  
  473. $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  474. curl_close($ch);
  475.  
  476. if ($result === FALSE) {
  477. echo "Curl - niepoprawny response header";
  478.  
  479. return "STATUS NOT 200";
  480. }
  481.  
  482.  
  483.  
  484.  
  485.  
  486. return $result;
  487.  
  488.  
  489. }
  490.  
  491.  
  492.  
  493. function checkauth($inputEmail,$inputPassword){
  494.  
  495.  
  496. $authok = false;
  497. $f=file(storage_path().'/auth.txt');
  498. foreach($f as $a){
  499.  
  500. $e = explode(' ',$a);
  501. if(trim($e[0])==trim($inputEmail) && hash_equals(trim($e[1]),sha1(SALT.$inputPassword))) $authok = true;
  502. }
  503.  
  504. return $authok;
  505. }
  506.  
  507.  
  508.  
  509. function checkhash($inputEmail,$hsh){
  510.  
  511.  
  512. $authok = false;
  513. $f=file(storage_path().'/auth.txt');
  514. foreach($f as $a){
  515. $e = explode(' ',$a);
  516. if(trim($e[0])==trim($inputEmail) && hash_equals(trim($e[1]),$hsh)) $authok = true;
  517. }
  518.  
  519. return $authok;
  520. }
  521.  
  522.  
  523.  
  524. function autho(){
  525.  
  526. $login = Request::cookie('login');
  527. $pass = Request::cookie('pass');
  528.  
  529.  
  530.  
  531. if(checkhash($login,$pass)){
  532. Session::put('login', $login);
  533. return true;
  534.  
  535. }else{
  536.  
  537. Session::flush();
  538. Cookie::queue('login', null, -1);
  539. Cookie::queue('pass', null, -1);
  540. return false;
  541.  
  542. }
  543.  
  544.  
  545. }
  546.  
  547. function setif($arr,$name){
  548. if(isset($arr[$name])) return $arr[$name]; else return '';
  549. }
  550.  
  551.  
  552.  
  553. if (!function_exists('hash_equals')) {
  554.  
  555. /**
  556. * Timing attack safe string comparison
  557. *
  558. * Compares two strings using the same time whether they're equal or not.
  559. * This function should be used to mitigate timing attacks; for instance, when testing crypt() password hashes.
  560. *
  561. * @param string $known_string The string of known length to compare against
  562. * @param string $user_string The user-supplied string
  563. * @return boolean Returns TRUE when the two strings are equal, FALSE otherwise.
  564. */
  565. function hash_equals($known_string, $user_string)
  566. {
  567. //var_dump($known_string);
  568. // var_dump($user_string);
  569. //exit;
  570. if (func_num_args() !== 2) {
  571. // handle wrong parameter count as the native implentation
  572. trigger_error('hash_equals() expects exactly 2 parameters, ' . func_num_args() . ' given', E_USER_WARNING);
  573. return null;
  574. }
  575. if (is_string($known_string) !== true) {
  576. trigger_error('hash_equals(): Expected known_string to be a string, ' . gettype($known_string) . ' given', E_USER_WARNING);
  577. return false;
  578. }
  579. $known_string_len = strlen($known_string);
  580. $user_string_type_error = 'hash_equals(): Expected user_string to be a string, ' . gettype($user_string) . ' given'; // prepare wrong type error message now to reduce the impact of string concatenation and the gettype call
  581. if (is_string($user_string) !== true) {
  582. trigger_error($user_string_type_error, E_USER_WARNING);
  583. // prevention of timing attacks might be still possible if we handle $user_string as a string of diffent length (the trigger_error() call increases the execution time a bit)
  584. $user_string_len = strlen($user_string);
  585. $user_string_len = $known_string_len + 1;
  586. } else {
  587. $user_string_len = $known_string_len + 1;
  588. $user_string_len = strlen($user_string);
  589. }
  590. if ($known_string_len !== $user_string_len) {
  591. $res = $known_string ^ $known_string; // use $known_string instead of $user_string to handle strings of diffrent length.
  592. $ret = 1; // set $ret to 1 to make sure false is returned
  593. } else {
  594. $res = $known_string ^ $user_string;
  595. $ret = 0;
  596. }
  597. for ($i = strlen($res) - 1; $i >= 0; $i--) {
  598. $ret |= ord($res[$i]);
  599. }
  600. return $ret === 0;
  601. }
  602.  
  603. }
  604.  
  605.  
  606.  
  607. /*
  608. * PHP function to resize an image maintaining aspect ratio
  609. * http://salman-w.blogspot.com/2008/10/resize-images-using-phpgd-library.html
  610. *
  611. * Creates a resized (e.g. thumbnail, small, medium, large)
  612. * version of an image file and saves it as another file
  613. */
  614.  
  615. define('THUMBNAIL_IMAGE_MAX_WIDTH', 100);
  616. define('THUMBNAIL_IMAGE_MAX_HEIGHT', 100);
  617.  
  618. function generate_image_thumbnail($source_image_path, $thumbnail_image_path)
  619. {
  620. list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_image_path);
  621. switch ($source_image_type) {
  622. case IMAGETYPE_GIF:
  623. $source_gd_image = imagecreatefromgif($source_image_path);
  624. break;
  625. case IMAGETYPE_JPEG:
  626. $source_gd_image = imagecreatefromjpeg($source_image_path);
  627. break;
  628. case IMAGETYPE_PNG:
  629. $source_gd_image = imagecreatefrompng($source_image_path);
  630. break;
  631. }
  632. if ($source_gd_image === false) {
  633. return false;
  634. }
  635. $source_aspect_ratio = $source_image_width / $source_image_height;
  636. $thumbnail_aspect_ratio = THUMBNAIL_IMAGE_MAX_WIDTH / THUMBNAIL_IMAGE_MAX_HEIGHT;
  637. if ($source_image_width <= THUMBNAIL_IMAGE_MAX_WIDTH && $source_image_height <= THUMBNAIL_IMAGE_MAX_HEIGHT) {
  638. $thumbnail_image_width = $source_image_width;
  639. $thumbnail_image_height = $source_image_height;
  640. } elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) {
  641. $thumbnail_image_width = (int) (THUMBNAIL_IMAGE_MAX_HEIGHT * $source_aspect_ratio);
  642. $thumbnail_image_height = THUMBNAIL_IMAGE_MAX_HEIGHT;
  643. } else {
  644. $thumbnail_image_width = THUMBNAIL_IMAGE_MAX_WIDTH;
  645. $thumbnail_image_height = (int) (THUMBNAIL_IMAGE_MAX_WIDTH / $source_aspect_ratio);
  646. }
  647. $thumbnail_gd_image = imagecreatetruecolor($thumbnail_image_width, $thumbnail_image_height);
  648. imagecopyresampled($thumbnail_gd_image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $source_image_width, $source_image_height);
  649. imagejpeg($thumbnail_gd_image, $thumbnail_image_path, 90);
  650. imagedestroy($source_gd_image);
  651. imagedestroy($thumbnail_gd_image);
  652. return true;
  653. }
  654.  
  655.  
  656.  
  657. define('DOC_IMAGE_MAX_WIDTH', 280);
  658. define('DOC_IMAGE_MAX_HEIGHT', 100);
  659.  
  660. function generate_image_doc($source_image_path, $thumbnail_image_path)
  661. {
  662. list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_image_path);
  663. switch ($source_image_type) {
  664. case IMAGETYPE_GIF:
  665. $source_gd_image = imagecreatefromgif($source_image_path);
  666. break;
  667. case IMAGETYPE_JPEG:
  668. $source_gd_image = imagecreatefromjpeg($source_image_path);
  669. break;
  670. case IMAGETYPE_PNG:
  671. $source_gd_image = imagecreatefrompng($source_image_path);
  672. break;
  673. }
  674. if ($source_gd_image === false) {
  675. return false;
  676. }
  677. $source_aspect_ratio = $source_image_width / $source_image_height;
  678. $thumbnail_aspect_ratio = DOC_IMAGE_MAX_WIDTH / DOC_IMAGE_MAX_HEIGHT;
  679. if ($source_image_width <= DOC_IMAGE_MAX_WIDTH && $source_image_height <= DOC_IMAGE_MAX_HEIGHT) {
  680. $thumbnail_image_width = $source_image_width;
  681. $thumbnail_image_height = $source_image_height;
  682. } elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) {
  683. $thumbnail_image_width = (int) (DOC_IMAGE_MAX_HEIGHT * $source_aspect_ratio);
  684. $thumbnail_image_height = DOC_IMAGE_MAX_HEIGHT;
  685. } else {
  686. $thumbnail_image_width = DOC_IMAGE_MAX_WIDTH;
  687. $thumbnail_image_height = (int) (DOC_IMAGE_MAX_WIDTH / $source_aspect_ratio);
  688. }
  689. $thumbnail_gd_image = imagecreatetruecolor($thumbnail_image_width, $thumbnail_image_height);
  690. imagecopyresampled($thumbnail_gd_image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $source_image_width, $source_image_height);
  691. imagejpeg($thumbnail_gd_image, $thumbnail_image_path, 90);
  692. imagedestroy($source_gd_image);
  693. imagedestroy($thumbnail_gd_image);
  694. return true;
  695. }
  696.  
  697.  
  698.  
  699. function prepara_texto($texto)
  700. {
  701. #$texto = html_entity_decode($texto);
  702. return $texto;
  703.  
  704.  
  705. //setlocale(LC_CTYPE, 'cs_CZ');
  706. $texto = str_replace('&amp;','and',$texto);
  707. //$texto = fixchars($texto);
  708. try {
  709. $r = html_entity_decode(iconv('UTF-8', 'windows-1252',$texto));
  710. } catch (Exception $e) {
  711. $r = html_entity_decode($texto);
  712. }
  713.  
  714. //return html_entity_decode(iconv('UTF-8', 'windows-1252',$texto));
  715.  
  716. //$r = html_entity_decode(iconv("utf-8", "cp1252//TRANSLIT", $texto));
  717. //$r = html_entity_decode(iconv('UTF-8', 'CP1252//TRANSLIT', $texto));
  718. //$r = clean($r);
  719. return $r;
  720. }
  721.  
  722.  
  723.  
  724.  
  725. function fixchars($string, $alphanumonly=true) {
  726.  
  727. $normalizeChars = array(
  728. 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A',
  729. 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I',
  730. 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U',
  731. 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a',
  732. 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i',
  733. 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u',
  734. 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f', 'Ą'=>'A', 'Ć'=>'C', 'Ę'=>'E',
  735. 'Ł'=>'L', 'Ń'=>'N', 'Ó'=>'O', 'Ś'=>'S', 'Ż'=>'Z', 'Ź'=>'Z', 'ą'=>'a', 'ć'=>'c', 'ę'=>'e', 'ł'=>'l',
  736. 'ń'=>'n', 'ó'=>'o', 'ś'=>'s', 'ż'=>'z', 'ź'=>'z', 'Č'=>'C', 'Á'=>'A', 'Í'=>'I', 'Ý'=>'Y', 'Ř'=>'R',
  737. 'Ĺ'=>'L', 'Ž'=>'Z', 'Ň'=>'N', 'Ú'=>'U', 'Ě'=>'E', 'Ž'=>'Z', 'Š'=>'S', 'č'=>'c', 'á'=>'a', 'í'=>'i',
  738. 'ý'=>'y', 'ř'=>'r', 'ĺ'=>'l', 'ž'=>'z', 'ň'=>'n', 'ú'=>'u', 'ě'=>'e', 'ž'=>'z', 'š'=>'s'
  739. );
  740.  
  741. $sText = strtr($string,$normalizeChars);
  742. //$sText = str_replace('<','char123456789',$sText);
  743. //$sText = str_replace('>','char987654321',$sText);
  744.  
  745. if($alphanumonly) $sText = preg_replace('|[^0-9A-Za-z \-\.\;\&\#\_\/+]|', '', $sText);
  746.  
  747. //$sText = str_replace('char123456789','<',$sText);
  748. //$sText = str_replace('char987654321','>',$sText);
  749.  
  750. return $sText;
  751. }
  752.  
  753. function clean($var) {
  754. $regEx="/[^a-zA-Z0-9.,]/";
  755. $var = preg_replace($regEx, "", $var);
  756. return str_replace(array("&", "'"),
  757. array("&amp;", "&apos;"), $var);
  758. }
  759.  
  760.  
  761. function prepara_texto_json($texto)
  762. {
  763. $texto = str_replace('&amp;','and',$texto);
  764. return html_entity_decode($texto);
  765. }
  766.  
  767.  
  768. function chmod_r($path) {
  769. $dir = new DirectoryIterator($path);
  770. foreach ($dir as $item) {
  771. chmod($item->getPathname(), 0777);
  772. if ($item->isDir() && !$item->isDot()) {
  773. chmod_r($item->getPathname());
  774. }
  775. }
  776. }
  777.  
  778.  
  779. function capitaliser($str){
  780. //return ucfirst(strtolower($str));
  781. return ucwords(strtolower($str));
  782. }
  783.  
  784.  
  785. function unicode2html($string){
  786. $string = html_entity_decode($string);
  787. $f = file_get_contents(storage_path().'/unics-decimal_html_entity-mini.json');
  788. $normalizeChars = json_decode($f,true);
  789. $s = strtr($string,$normalizeChars);
  790. $s = fixchars($s);
  791. return $s;
  792.  
  793. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement