Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('SALT','hfdlshvavh;elvha;ohva');
- function tampermonkey_retrieve_html($recurred = 1)
- {
- sleep(1);
- $html = Storage::get('/tampermonkey/html.txt');
- if(strlen($html) < 1)
- {
- if($recurred < 100)
- {
- $html = tampermonkey_retrieve_html(++$recurred);
- }
- }
- $html = '<html>' . $html . '</html>';
- if(strlen($html) > 100)
- {
- Storage::put('/tampermonkey/cache/' . \Carbon\Carbon::now()->format('Y_m_d_H_i_s') . '.txt', $html);
- }
- return $html;
- }
- function tampermonkey_set($url){
- $data = [];
- $data['url'] = $url;
- $data['mode'] = 'body';
- \Storage::put('/tampermonkey/command.json', json_encode($data));
- \Storage::put('/tampermonkey/html.txt', '');
- }
- function clean_tampermonkey()
- {
- $data = [];
- $data['url'] = '';
- $data['mode'] = '';
- \Storage::put('/tampermonkey/command.json', json_encode($data));
- }
- function multiExplode($delimiters,$string) {
- return explode($delimiters[0],strtr($string,array_combine(array_slice($delimiters,1),array_fill(0,count($delimiters)-1,array_shift($delimiters)))));
- }
- function trim_all( $str , $what = NULL , $with = ' ' )
- {
- if( $what === NULL )
- {
- // Character Decimal Use
- // "\0" 0 Null Character
- // "\t" 9 Tab
- // "\n" 10 New line
- // "\x0B" 11 Vertical Tab
- // "\r" 13 New Line in Mac
- // " " 32 Space
- $what = "\\x00-\\x20"; //all white-spaces and control chars
- }
- return trim( preg_replace( "/[".$what."]+/" , $with , $str ) , $what );
- }
- //WEBCACHE
- function getcache($url) {
- if(!file_exists(storage_path().'/webcache/'."w".sha1($url).".html")) {
- return false;
- }else{
- return file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
- }
- }
- /*
- function webcache($url,$withpost=true, $phantomjs = false, $strip_tags = false, $try = 1) {
- if(!file_exists(storage_path().'/webcache/'."w".sha1($url).".html")) {
- if($phantomjs)
- {
- $fgc = phantomjs($url);
- }
- else
- {
- tampermonkey_set($url);
- $fgc = tampermonkey_retrieve_html();
- clean_tampermonkey();
- }
- if(strlen(trim($fgc)) > 500)
- {
- file_put_contents(storage_path().'/webcache/'."w".sha1($url).".html",websig($url).$fgc);
- }
- }
- else
- {
- $fgc = file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
- }
- // file_put_contents(storage_path().'/webcache/'."w".sha1($url).".html",websig($url).$fgc);
- // $fgc = file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
- return $fgc;
- }
- */
- function the_new_way($url)
- {
- $postfields = 'JSESSIONID=C0B570CA943885FA0AB3197EC2C9E0A1.tmdsview1; TS018f6762=01601e1d32d821bd1ee4c75affdd848cea25b6f472825a5ad6ae9c045beb60d1e923bf24730286d86099f799c5617b5b056450739f4321fc6dcb066ce893afac5895c0ba71; TSPD_101=0827db1318ab2800d24820c53400ecc7ace1a98b8532c404b96c50fe1f84bec6a87b9e89388088801160cb495cde29e0:; TS01a8cc48_77=0827db1318ab2800eb902eca03032f0322da5e111ae774aa2f504829693bd45627c1309382ed48580e4444ba93da4bae08a74963b9823800c9a6cc780c10b89966101c807e9eb82d331ddb3e0c1dc8f48b6591f41ce471c17f44833b9985802b5d93f20fdb71bfef40602343f1484da0; TS01a8cc48=01601e1d329d4ea19df58c9f16aa24db3b5d4517c9ed672b20a4de8c97124c815d15c0ad04f751acc1d2adaca27052d03594f88450; TS01a8cc48_31=01edc21ef03568de230dccb1123540bd88d657c4dc0104b2a87eb1903b17893f19cdd3ea788d6c1d6e0c048cdf27711d56a899f62c; TS018289ca=01601e1d3286a998c5b56097cc9cda769511587a929804f3edf3102034fae0512f558c01644bffcbe1f2a2d32f30168a846922f94a';
- //$ch = set_proxy($ch);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
- curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
- curl_setopt($ch, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
- curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
- //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
- curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
- curl_setopt($ch, CURLOPT_REFERER, 'https://www.tmdn.org/tmview/get-detail?st13=DE503020170049099');
- curl_setopt($ch, CURLOPT_URL,$url );
- curl_setopt($ch, CURLOPT_COOKIE, $postfields);
- //curl_setopt($ch, CURLOPT_PROXY, $proxy);
- //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
- //curl_setopt($ch, CURLOPT_POST, 1);
- //curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
- $curl_scraped_page = curl_exec($ch);
- curl_close($ch);
- return $curl_scraped_page;
- }
- function webcache($url,$withpost=true, $phantomjs = false) {
- //search log
- $logfile = storage_path().'/webcache.log';
- if(file_exists($logfile)) $logf = file_get_contents($logfile); else $logf = '';
- $logf = $logf.Request::getClientIp()." - ".date("Y-m-d H:i:s")." - ".$url.' - hash: '.sha1($url)."\n";
- if(trim($url)!='') file_put_contents($logfile,$logf);
- //end search log
- if(!file_exists(storage_path().'/webcache/'."w".sha1($url).".html")) {
- try {
- if($phantomjs)
- {
- $fgc = phantomjs($url);
- }
- else if($withpost) //$fgc = file_get_contents_post($url); else $fgc = file_get_contents_ref($url);
- $fgc = file_get_contents_post($url);
- else $fgc = file_get_contents_ref($url);
- //retry once
- if(strlen(trim($fgc))<2){
- sleep(3);
- if($withpost) //$fgc = file_get_contents_post($url); else $fgc = file_get_contents_ref($url);
- $fgc = phantomjs($url); else $fgc = file_get_contents_ref($url);
- }
- //retry twice
- if(strlen(trim($fgc))<2){
- sleep(2);
- if($withpost) //$fgc = file_get_contents_post($url); else $fgc = file_get_contents_ref($url);
- $fgc = phantomjs($url); else $fgc = file_get_contents_ref($url);
- }
- file_put_contents(storage_path().'/webcache/'."w".sha1($url).".html",websig($url).$fgc);
- } catch (Exception $e) {
- return false;
- //return file_get_contents_proxy($url);
- }
- }else{
- $fgc = file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
- }
- return $fgc;
- }
- function websig($url){
- return "";
- //return "<!-- url: $url -->".PHP_EOL;
- }
- function webcacheproxy($url){
- if(!file_exists(storage_path().'/webcache/'."w".sha1($url).".html")) {
- try {
- $fgc = file_get_contents_proxy($url);
- file_put_contents(storage_path().'/webcache/'."w".sha1($url).".html",websig($url).$fgc);
- } catch (Exception $e) {
- return false;
- }
- }else{
- $fgc = file_get_contents(storage_path().'/webcache/'."w".sha1($url).".html");
- }
- return $fgc;
- }
- function file_get_contents_post($url){
- $referer = "https://www.tmdn.org/";
- $ch = curl_init();
- /*
- curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
- curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
- curl_setopt($ch, CURLOPT_MAXREDIRS, 2); //if http server gives redirection responce
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
- //curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
- //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
- curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
- curl_setopt($ch, CURLOPT_REFERER, $referer);
- curl_setopt($ch, CURLOPT_URL,$url);
- //curl_setopt($ch, CURLOPT_PROXY, $proxy);
- //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
- $curl_scraped_page = curl_exec($ch);
- curl_close($ch);
- */
- $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";
- //$postfields = 'TS82d731_id=3&TS82d731_75=bedfe8ebd5e7283d8a7ee318a46c721f%3Ajklj%3A28PM92r2%3A1988019743&TS82d731_md=1&TS82d731_rf=0&TS82d731_ct=0&TS82d731_pd=0';
- //$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';
- $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';
- $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';
- $ch = set_proxy($ch);
- curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
- curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
- curl_setopt($ch, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
- //curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
- //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
- curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
- curl_setopt($ch, CURLOPT_REFERER, $referer);
- curl_setopt($ch, CURLOPT_URL,$url);
- //curl_setopt($ch, CURLOPT_PROXY, $proxy);
- //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
- $curl_scraped_page = curl_exec($ch);
- curl_close($ch);
- return $curl_scraped_page;
- }
- function file_get_contents_ref($url){
- $referer = "https://www.tmdn.org/";
- $ch = curl_init();
- $ch = set_proxy($ch);
- curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
- curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
- curl_setopt($ch, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
- //curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
- //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
- curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
- curl_setopt($ch, CURLOPT_REFERER, $referer);
- curl_setopt($ch, CURLOPT_URL,$url);
- //curl_setopt($ch, CURLOPT_PROXY, $proxy);
- //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
- $curl_scraped_page = curl_exec($ch);
- curl_close($ch);
- return $curl_scraped_page;
- }
- function file_get_contents_proxy($url){
- //$url = 'http://dynupdate.no-ip.com/ip.php';
- $proxy = '127.0.0.1:8888';
- //$proxyauth = 'user:password';
- $proxy = '72.159.148.20:10000';
- $proxy = '37.59.101.237:3128';
- $referer = "https://www.tmdn.org/";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
- curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
- curl_setopt($ch, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
- //curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
- //curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
- curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
- curl_setopt($ch, CURLOPT_REFERER, $referer);
- curl_setopt($ch, CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_PROXY, $proxy);
- //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
- $curl_scraped_page = curl_exec($ch);
- curl_close($ch);
- return $curl_scraped_page;
- }
- function phantomjs($url, $repeated = 0)
- {
- $data = [];
- $data['url'] = $url;
- $data['maxWait'] = 10;
- $data['renderType'] = 'html';
- $data['requestSettings'] = [
- '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',
- 'clearCache' => 'false',
- 'clearCookies' => 'false',
- 'cookies' => [],
- 'deleteCookies' => [],
- 'ignoreImages' => 'true',
- 'resourceWait' => 5000,
- 'resourceTimeout' => 50000,
- 'maxWait' => 5000,
- 'waitInterval' => 1000,
- ];
- /*
- $data = [];
- $data['url'] = $url;
- $data['maxWait'] = 25000;
- $data['renderType'] = 'html';
- $data['requestSettings'] = [
- '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',
- 'clearCache' => 'true',
- 'clearCookies' => 'false',
- 'cookies' => [],
- 'deleteCookies' => [],
- 'ignoreImages' => 'true',
- 'resourceWait' => 10000,
- 'resourceTimeout' => 100000,
- 'maxWait' => 20000,
- 'waitInterval' => 5000,
- ];
- */
- $url = 'https://PhantomJScloud.com/api/browser/v2/ak-jvezz-kgk8a-jd1ac-373w9-3gnps/';
- $payload = json_encode($data);
- $options = array(
- 'http' => array(
- 'header' => "Content-type: application/json\r\n",
- 'method' => 'POST',
- 'content' => $payload,
- )
- );
- if (is_array($data))
- {
- $post = json_encode($data);
- }
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_ENCODING, "UTF-8");
- $headers = array( "Accept:" );
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
- curl_setopt($ch,CURLOPT_TIMEOUT,15000);
- $result = curl_exec($ch);
- if(strlen(strip_tags($result)) < 500)
- {
- if($repeated < 6)
- {
- phantomjs($url, ++$repeated);
- }
- }
- $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- if ($result === FALSE) {
- echo "Curl - niepoprawny response header";
- return "STATUS NOT 200";
- }
- return $result;
- }
- function checkauth($inputEmail,$inputPassword){
- $authok = false;
- $f=file(storage_path().'/auth.txt');
- foreach($f as $a){
- $e = explode(' ',$a);
- if(trim($e[0])==trim($inputEmail) && hash_equals(trim($e[1]),sha1(SALT.$inputPassword))) $authok = true;
- }
- return $authok;
- }
- function checkhash($inputEmail,$hsh){
- $authok = false;
- $f=file(storage_path().'/auth.txt');
- foreach($f as $a){
- $e = explode(' ',$a);
- if(trim($e[0])==trim($inputEmail) && hash_equals(trim($e[1]),$hsh)) $authok = true;
- }
- return $authok;
- }
- function autho(){
- $login = Request::cookie('login');
- $pass = Request::cookie('pass');
- if(checkhash($login,$pass)){
- Session::put('login', $login);
- return true;
- }else{
- Session::flush();
- Cookie::queue('login', null, -1);
- Cookie::queue('pass', null, -1);
- return false;
- }
- }
- function setif($arr,$name){
- if(isset($arr[$name])) return $arr[$name]; else return '';
- }
- if (!function_exists('hash_equals')) {
- /**
- * Timing attack safe string comparison
- *
- * Compares two strings using the same time whether they're equal or not.
- * This function should be used to mitigate timing attacks; for instance, when testing crypt() password hashes.
- *
- * @param string $known_string The string of known length to compare against
- * @param string $user_string The user-supplied string
- * @return boolean Returns TRUE when the two strings are equal, FALSE otherwise.
- */
- function hash_equals($known_string, $user_string)
- {
- //var_dump($known_string);
- // var_dump($user_string);
- //exit;
- if (func_num_args() !== 2) {
- // handle wrong parameter count as the native implentation
- trigger_error('hash_equals() expects exactly 2 parameters, ' . func_num_args() . ' given', E_USER_WARNING);
- return null;
- }
- if (is_string($known_string) !== true) {
- trigger_error('hash_equals(): Expected known_string to be a string, ' . gettype($known_string) . ' given', E_USER_WARNING);
- return false;
- }
- $known_string_len = strlen($known_string);
- $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
- if (is_string($user_string) !== true) {
- trigger_error($user_string_type_error, E_USER_WARNING);
- // 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)
- $user_string_len = strlen($user_string);
- $user_string_len = $known_string_len + 1;
- } else {
- $user_string_len = $known_string_len + 1;
- $user_string_len = strlen($user_string);
- }
- if ($known_string_len !== $user_string_len) {
- $res = $known_string ^ $known_string; // use $known_string instead of $user_string to handle strings of diffrent length.
- $ret = 1; // set $ret to 1 to make sure false is returned
- } else {
- $res = $known_string ^ $user_string;
- $ret = 0;
- }
- for ($i = strlen($res) - 1; $i >= 0; $i--) {
- $ret |= ord($res[$i]);
- }
- return $ret === 0;
- }
- }
- /*
- * PHP function to resize an image maintaining aspect ratio
- * http://salman-w.blogspot.com/2008/10/resize-images-using-phpgd-library.html
- *
- * Creates a resized (e.g. thumbnail, small, medium, large)
- * version of an image file and saves it as another file
- */
- define('THUMBNAIL_IMAGE_MAX_WIDTH', 100);
- define('THUMBNAIL_IMAGE_MAX_HEIGHT', 100);
- function generate_image_thumbnail($source_image_path, $thumbnail_image_path)
- {
- list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_image_path);
- switch ($source_image_type) {
- case IMAGETYPE_GIF:
- $source_gd_image = imagecreatefromgif($source_image_path);
- break;
- case IMAGETYPE_JPEG:
- $source_gd_image = imagecreatefromjpeg($source_image_path);
- break;
- case IMAGETYPE_PNG:
- $source_gd_image = imagecreatefrompng($source_image_path);
- break;
- }
- if ($source_gd_image === false) {
- return false;
- }
- $source_aspect_ratio = $source_image_width / $source_image_height;
- $thumbnail_aspect_ratio = THUMBNAIL_IMAGE_MAX_WIDTH / THUMBNAIL_IMAGE_MAX_HEIGHT;
- if ($source_image_width <= THUMBNAIL_IMAGE_MAX_WIDTH && $source_image_height <= THUMBNAIL_IMAGE_MAX_HEIGHT) {
- $thumbnail_image_width = $source_image_width;
- $thumbnail_image_height = $source_image_height;
- } elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) {
- $thumbnail_image_width = (int) (THUMBNAIL_IMAGE_MAX_HEIGHT * $source_aspect_ratio);
- $thumbnail_image_height = THUMBNAIL_IMAGE_MAX_HEIGHT;
- } else {
- $thumbnail_image_width = THUMBNAIL_IMAGE_MAX_WIDTH;
- $thumbnail_image_height = (int) (THUMBNAIL_IMAGE_MAX_WIDTH / $source_aspect_ratio);
- }
- $thumbnail_gd_image = imagecreatetruecolor($thumbnail_image_width, $thumbnail_image_height);
- imagecopyresampled($thumbnail_gd_image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $source_image_width, $source_image_height);
- imagejpeg($thumbnail_gd_image, $thumbnail_image_path, 90);
- imagedestroy($source_gd_image);
- imagedestroy($thumbnail_gd_image);
- return true;
- }
- define('DOC_IMAGE_MAX_WIDTH', 280);
- define('DOC_IMAGE_MAX_HEIGHT', 100);
- function generate_image_doc($source_image_path, $thumbnail_image_path)
- {
- list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_image_path);
- switch ($source_image_type) {
- case IMAGETYPE_GIF:
- $source_gd_image = imagecreatefromgif($source_image_path);
- break;
- case IMAGETYPE_JPEG:
- $source_gd_image = imagecreatefromjpeg($source_image_path);
- break;
- case IMAGETYPE_PNG:
- $source_gd_image = imagecreatefrompng($source_image_path);
- break;
- }
- if ($source_gd_image === false) {
- return false;
- }
- $source_aspect_ratio = $source_image_width / $source_image_height;
- $thumbnail_aspect_ratio = DOC_IMAGE_MAX_WIDTH / DOC_IMAGE_MAX_HEIGHT;
- if ($source_image_width <= DOC_IMAGE_MAX_WIDTH && $source_image_height <= DOC_IMAGE_MAX_HEIGHT) {
- $thumbnail_image_width = $source_image_width;
- $thumbnail_image_height = $source_image_height;
- } elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) {
- $thumbnail_image_width = (int) (DOC_IMAGE_MAX_HEIGHT * $source_aspect_ratio);
- $thumbnail_image_height = DOC_IMAGE_MAX_HEIGHT;
- } else {
- $thumbnail_image_width = DOC_IMAGE_MAX_WIDTH;
- $thumbnail_image_height = (int) (DOC_IMAGE_MAX_WIDTH / $source_aspect_ratio);
- }
- $thumbnail_gd_image = imagecreatetruecolor($thumbnail_image_width, $thumbnail_image_height);
- imagecopyresampled($thumbnail_gd_image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $source_image_width, $source_image_height);
- imagejpeg($thumbnail_gd_image, $thumbnail_image_path, 90);
- imagedestroy($source_gd_image);
- imagedestroy($thumbnail_gd_image);
- return true;
- }
- function prepara_texto($texto)
- {
- #$texto = html_entity_decode($texto);
- return $texto;
- //setlocale(LC_CTYPE, 'cs_CZ');
- $texto = str_replace('&','and',$texto);
- //$texto = fixchars($texto);
- try {
- $r = html_entity_decode(iconv('UTF-8', 'windows-1252',$texto));
- } catch (Exception $e) {
- $r = html_entity_decode($texto);
- }
- //return html_entity_decode(iconv('UTF-8', 'windows-1252',$texto));
- //$r = html_entity_decode(iconv("utf-8", "cp1252//TRANSLIT", $texto));
- //$r = html_entity_decode(iconv('UTF-8', 'CP1252//TRANSLIT', $texto));
- //$r = clean($r);
- return $r;
- }
- function fixchars($string, $alphanumonly=true) {
- $normalizeChars = array(
- 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A',
- 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I',
- 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U',
- 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a',
- 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i',
- 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u',
- 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f', 'Ą'=>'A', 'Ć'=>'C', 'Ę'=>'E',
- 'Ł'=>'L', 'Ń'=>'N', 'Ó'=>'O', 'Ś'=>'S', 'Ż'=>'Z', 'Ź'=>'Z', 'ą'=>'a', 'ć'=>'c', 'ę'=>'e', 'ł'=>'l',
- 'ń'=>'n', 'ó'=>'o', 'ś'=>'s', 'ż'=>'z', 'ź'=>'z', 'Č'=>'C', 'Á'=>'A', 'Í'=>'I', 'Ý'=>'Y', 'Ř'=>'R',
- 'Ĺ'=>'L', 'Ž'=>'Z', 'Ň'=>'N', 'Ú'=>'U', 'Ě'=>'E', 'Ž'=>'Z', 'Š'=>'S', 'č'=>'c', 'á'=>'a', 'í'=>'i',
- 'ý'=>'y', 'ř'=>'r', 'ĺ'=>'l', 'ž'=>'z', 'ň'=>'n', 'ú'=>'u', 'ě'=>'e', 'ž'=>'z', 'š'=>'s'
- );
- $sText = strtr($string,$normalizeChars);
- //$sText = str_replace('<','char123456789',$sText);
- //$sText = str_replace('>','char987654321',$sText);
- if($alphanumonly) $sText = preg_replace('|[^0-9A-Za-z \-\.\;\&\#\_\/+]|', '', $sText);
- //$sText = str_replace('char123456789','<',$sText);
- //$sText = str_replace('char987654321','>',$sText);
- return $sText;
- }
- function clean($var) {
- $regEx="/[^a-zA-Z0-9.,]/";
- $var = preg_replace($regEx, "", $var);
- return str_replace(array("&", "'"),
- array("&", "'"), $var);
- }
- function prepara_texto_json($texto)
- {
- $texto = str_replace('&','and',$texto);
- return html_entity_decode($texto);
- }
- function chmod_r($path) {
- $dir = new DirectoryIterator($path);
- foreach ($dir as $item) {
- chmod($item->getPathname(), 0777);
- if ($item->isDir() && !$item->isDot()) {
- chmod_r($item->getPathname());
- }
- }
- }
- function capitaliser($str){
- //return ucfirst(strtolower($str));
- return ucwords(strtolower($str));
- }
- function unicode2html($string){
- $string = html_entity_decode($string);
- $f = file_get_contents(storage_path().'/unics-decimal_html_entity-mini.json');
- $normalizeChars = json_decode($f,true);
- $s = strtr($string,$normalizeChars);
- $s = fixchars($s);
- return $s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement