Minde/Klaidos/JustPageIT/get.php
Iš PHP, MySQL.
<?php function get_real_data( $id, $type ) { global $setupdata; global $imageclass; global $mysqlclass; $tmp = round( $id / 250 ); $path_to_cache_file = $setupdata['binary_path']."/ids/".$tmp."/".$id; if ( file_exists( $path_to_cache_file ) ) { require( $path_to_cache_file ); if ( isset( $data_id ) ) { $rows['parent'] = $data_id['parent']; $data_id = $data_id['info']; $rows['link'] = $data_id['name']; $rows['size'] = $data_id['size']; $rows['mime'] = $data_id['type']; return $rows; } } $mysqlclass->connect_db( $setupdata['HostName'], $setupdata['UserName'], $setupdata['Password'], $setupdata['DBName'] ); $result = $imageclass->image_get_link( $id, $type ); $mysqlclass->close_db( ); return $result; } function paste_watermark( $path, $watermark ) { global $setupdata; $imagedata = getimagesize( $path ); if ( $imagedata[2] == 1 ) { $tmp = imagecreatefromgif( $path ); $tmpfname = tempnam( "/tmp", "FOO" ); imagejpeg( $tmp, $tmpfname, 90 ); $photoImage = imagecreatefromjpeg( $tmpfname ); imagedestroy( $tmp ); unlink( $tmpfname ); } else if ( $imagedata[2] == 2 ) { $photoImage = imagecreatefromjpeg( $path ); } imagealphablending( $photoImage, true ); $logoImage = imagecreatefrompng( $setupdata['null_binary_path']."/watermark/".$watermark['info']['name'] ); $logoW = imagesx( $logoImage ); $logoH = imagesy( $logoImage ); if ( $watermark['x'] == 66.66 ) { $x = imagesx( $photoImage ) / 100 * $watermark['x'] - imagesx( $photoImage ) / 100 * 16.5 - $logoW / 2; } else if ( $watermark['x'] == 100 ) { $x = imagesx( $photoImage ) - $logoW; } else { $x = 0; } if ( $watermark['y'] == 66.66 ) { $y = imagesy( $photoImage ) / 100 * $watermark['y'] - imagesy( $photoImage ) / 100 * 16.5 - $logoH / 2; } else if ( $watermark['y'] == 100 ) { $y = imagesy( $photoImage ) - $logoH; } else { $y = 0; } imagecopy( $photoImage, $logoImage, $x, $y, 0, 0, $logoW, $logoH ); header( "Last-Modified: ".gmdate( "D, d M Y H:i:s", time( ) )." GMT" ); header( "Content-type: image/jpeg" ); imagejpeg( $photoImage ); imagedestroy( $photoImage ); imagedestroy( $logoImage ); } function resize( $img, $w, $h, $path, $watermark = NULL ) { $imagedata = getimagesize( $img ); if ( isset( $imagedata['mime'] ) ) { if ( $imagedata[2] == 1 ) { $imagedata['mime'] = "image/gif"; } else if ( $imagedata[2] == 2 ) { $imagedata['mime'] = "image/jpeg"; } } if ( $imagedata['mime'] == "image/jpeg" ) { $image = imagecreatefromjpeg( $img ); } else if ( $imagedata['mime'] == "image/gif" ) { $image = imagecreatefromgif( $img ); } if ( function_exists( "imagecreatetruecolor" ) && function_exists( "imagecopyresampled" ) ) { $thumb = imagecreatetruecolor( $w, $h ); imagecopyresampled( $thumb, $image, 0, 0, 0, 0, $w, $h, $imagedata[0], $imagedata[1] ); } else { $thumb = imagecreate( $w, $h ); imagecopyresized( $thumb, $image, 0, 0, 0, 0, $w, $h, $imagedata[0], $imagedata[1] ); } imagejpeg( $thumb, $path, 90 ); if ( $watermark == NULL ) { header( "Last-Modified: ".gmdate( "D, d M Y H:i:s", time( ) )." GMT" ); header( "Content-type: image/jpeg" ); imagejpeg( $thumb, "", 90 ); chmod( $path, 438 ); imagedestroy( $image ); imagedestroy( $thumb ); } else { paste_watermark( $path, $watermark ); } } function not_resize( $path, $watermark = NULL ) { if ( $watermark == NULL ) { header( "Last-Modified: ".gmdate( "D, d M Y H:i:s", filemtime( $path ) )." GMT" ); header( "Content-type: image/jpeg" ); header( "Content-Length: ".filesize( $path ) ); readfile( $path ); exit( ); } paste_watermark( $path, $watermark ); } function display_default( $dir ) { $name = $dir."/design/img/no_image.jpg"; $fp = fopen( $name, "rb" ); header( "Last-Modified: ".gmdate( "D, d M Y H:i:s", filemtime( $name ) )." GMT" ); header( "Content-Type: image/jpg" ); header( "Content-Length: ".filesize( $name ) ); readfile( $name ); exit( ); } if ( !eregi( "i.", $_SERVER['QUERY_STRING'] ) && !eregi( "f.", $_SERVER['QUERY_STRING'] ) && !eregi( "s.", $_SERVER['QUERY_STRING'] ) && !eregi( "m.", $_SERVER['QUERY_STRING'] ) && !eregi( "c.", $_SERVER['QUERY_STRING'] ) && !eregi( "d.", $_SERVER['QUERY_STRING'] ) ) { header( "HTTP/1.0 404 Not Found" ); exit( ); } session_cache_limiter( ); include( $setupdata['core_dir']."/setup.php" ); $setupdata['null_binary_path'] = $setupdata['binary_path']; $setupdata['default_languages'] = strtolower( $setupdata['default_languages'] ); include( $setupdata['core_dir']."/classes/mysql.php" ); $mysqlclass = new mysqlclass( ); include( $setupdata['core_dir']."/classes/images.php" ); $imageclass = new imagesclass( ); include( $setupdata['core_dir']."/classes/files.php" ); $fileclass = new filesclass( ); $_SERVER['QUERY_STRING'] = preg_replace( "'%3Aw'si", ":w", $_SERVER['QUERY_STRING'] ); $arr = explode( ":", $_SERVER['QUERY_STRING'] ); if ( 0 < count( $arr ) ) { $error = 0; $arr1 = explode( ".", $arr[0] ); if ( $arr1[0] == "i" ) { $id = $arr1[1]; if ( count( $arr ) == 3 || count( $arr ) == 4 ) { $arr1 = explode( ".", $arr[1] ); if ( $arr1[0] != "w" && $arr1[0] != "h" ) { $error = 1; } else if ( $arr1[0] == "w" ) { $w = $arr1[1]; } else if ( $arr1[0] == "h" ) { $h = $arr1[1]; } $arr1 = explode( ".", $arr[2] ); if ( $arr1[0] != "w" && $arr1[0] != "h" ) { $error = 1; } else { if ( $arr1[0] == "w" ) { $w = $arr1[1]; } else { if ( $arr1[0] == "h" ) { $h = $arr1[1]; } } } } else { $h = 0; $w = 0; } if ( count( $arr ) == 4 ) { if ( $arr[3] == "force" ) { $force = true; } } else if ( count( $arr ) == 2 && $arr[1] == "force" ) { $force = true; } $files = get_real_data( $id, "image" ); if ( $files['link'] == NULL ) { display_default( $setupdata['core_dir'] ); } $info = $files; $files = $files['link']; $watermark = NULL; if ( isset( $setupdata['watermark']['name'] ) ) { $watermark['info']['height'] = $setupdata['watermark']['height']; $watermark['info']['width'] = $setupdata['watermark']['width']; $watermark['info']['name'] = $setupdata['watermark']['name']; $watermark['x'] = $setupdata['watermark']['x']; $watermark['y'] = $setupdata['watermark']['y']; } $scr = $setupdata['binary_path']."/".$files; if ( file_exists( $scr ) ) { $setupdata['binary_path'] = $setupdata['binary_path']."/".$info['parent']; $scr = $setupdata['binary_path']."/".$files; } if ( !file_exists( $scr ) || is_dir( $scr ) ) { display_default( $setupdata['core_dir'] ); } if ( strlen( $scr ) == 0 ) { display_default( $setupdata['core_dir'] ); } $t1 = explode( "/", $scr ); $t2 = explode( "-", $t1[count( $t1 ) - 1] ); $e = explode( ".", $t2[2] )[1]; $s = explode( ".", $t2[2] )[0]; $s = $setupdata['binary_path']."/".$t2[0]."-".$t2[1]."-"; $imagedata = getimagesize( $scr ); $image_original_width = $imagedata[0]; $image_original_height = $imagedata[1]; if ( $h == 0 || $w == 0 || $error == 1 || !( !$image_original_width < $w ) ) { $h = $image_original_height; $w = $image_original_width; } else { $mult_x = $w / $image_original_width; $mult_y = $h / $image_original_height; if ( $image_original_height * $mult_x < $h ) { $new_width = $w; $new_height = $image_original_height * $mult_x; } else { $new_width = $image_original_width * $mult_y; $new_height = $h; } $h = round( $new_height ); $w = round( $new_width ); } if ( $watermark == NULL || $h < $watermark['info']['height'] || $w < $watermark['info']['width'] ) { $watermark = NULL; } $s .= $w."x".$h.".".$e; if ( isset( $force ) && $force === true ) { $s .= "_force"; } if ( is_file( $s ) ) { resize( $scr, $w, $h, $s, $watermark ); exit( ); } not_resize( $s, $watermark ); exit( ); } if ( $arr1[0] == "f" ) { $mysqlclass->connect_db( $setupdata['HostName'], $setupdata['UserName'], $setupdata['Password'], $setupdata['DBName'] ); $id = $arr1[1]; $info = $fileclass->file_info( $id ); $files = $fileclass->file_get_link( $id ); $file = $setupdata['binary_path']."/".$files; if ( file_exists( $file ) ) { $setupdata['binary_path'] = $setupdata['binary_path']."/".$info['parent']; $file = $setupdata['binary_path']."/".$files; } $t1 = explode( "/", $file ); $t2 = explode( "-", $t1[count( $t1 ) - 1] ); $name = $t2[count( $t2 ) - 1]; if ( is_file( $file ) && 0 < strlen( $file ) ) { header( "Content-type: ".$info['mime'] ); header( "Content-Disposition: attachment; filename=\"".$name."\"" ); header( "Content-length: ".$info['size'] ); readfile( $file ); } $mysqlclass->close_db( ); exit( ); } if ( $arr1[0] == "s" ) { $mysqlclass->connect_db( $setupdata['HostName'], $setupdata['UserName'], $setupdata['Password'], $setupdata['DBName'] ); $id = $arr1[1]; $files = $imageclass->image_get_link( $id, "flash" ); $info = $files; $files = $files['link']; $file = $setupdata['binary_path']."/".$files; if ( file_exists( $file ) ) { $setupdata['binary_path'] = $setupdata['binary_path']."/".$info['parent']; $file = $setupdata['binary_path']."/".$files; } $t1 = explode( "/", $file ); $t2 = explode( "-", $t1[count( $t1 ) - 1] ); $name = $t2[count( $t2 ) - 1]; if ( is_file( $file ) && 0 < strlen( $file ) ) { header( "Last-Modified: ".gmdate( "D, d M Y H:i:s", filemtime( $file ) )." GMT" ); header( "Content-type: application/x-shockwave-flash" ); header( "Content-length: ".$info['size'] ); readfile( $file ); } $mysqlclass->close_db( ); exit( ); } if ( $arr1[0] == "m" ) { $mysqlclass->connect_db( $setupdata['HostName'], $setupdata['UserName'], $setupdata['Password'], $setupdata['DBName'] ); $id = $arr1[1]; if ( count( $arr ) == 4 ) { $arr1 = explode( ".", $arr[1] ); if ( $arr1[0] != "w" && $arr1[0] != "h" ) { $error = 1; } else if ( $arr1[0] == "w" ) { $w = $arr1[1]; } else if ( $arr1[0] == "h" ) { $h = $arr1[1]; } $arr1 = explode( ".", $arr[2] ); if ( $arr1[0] != "w" && $arr1[0] != "h" ) { $error = 1; } else if ( $arr1[0] == "w" ) { $w = $arr1[1]; } else if ( $arr1[0] == "h" ) { $h = $arr1[1]; } $arr1 = explode( ".", $arr[3] ); if ( $arr1[0] != "page" ) { display_default( $setupdata['core_dir'] ); } else { $page_id = $arr1[1]; } } else if ( count( $arr ) == 2 ) { $arr1 = explode( ".", $arr[1] ); if ( $arr1[0] != "page" ) { display_default( $setupdata['core_dir'] ); } else { $h = 0; $w = 0; $page_id = $arr1[1]; } } else { display_default( $setupdata['core_dir'] ); } $files = $imageclass->image_get_link( $id, "imagew" ); if ( $files['link'] == NULL ) { display_default( $setupdata['core_dir'] ); } $info = $files; $files = $files['link']; include( $setupdata['core_dir']."/modules/watermark/watermarkclass.php" ); $watermarkclass = new watermarkclass( ); $watermark = $watermarkclass->get_watermark_data_by_page_id( $page_id ); if ( $files == NULL || $watermark == NULL ) { display_default( $setupdata['core_dir'] ); } $scr = $setupdata['binary_path']."/".$files; if ( file_exists( $scr ) ) { $setupdata['binary_path'] = $setupdata['binary_path']."/".$info['parent']; $scr = $setupdata['binary_path']."/".$files; } if ( !file_exists( $scr ) || is_dir( $scr ) ) { display_default( $setupdata['core_dir'] ); } if ( strlen( $scr ) == 0 ) { display_default( $setupdata['core_dir'] ); } $t1 = explode( "/", $scr ); $t2 = explode( "-", $t1[count( $t1 ) - 1] ); $e = explode( ".", $t2[2] )[1]; $s = explode( ".", $t2[2] )[0]; $s = $setupdata['binary_path']."/".$t2[0]."-".$t2[1]."-"; $imagedata = getimagesize( $scr ); $image_original_width = $imagedata[0]; $image_original_height = $imagedata[1]; if ( $h == 0 || $w == 0 || $error == 1 || !( !$image_original_width < $w ) ) { $h = $image_original_height; $w = $image_original_width; } else { $mult_x = $w / $image_original_width; $mult_y = $h / $image_original_height; if ( $image_original_height * $mult_x < $h ) { $new_width = $w; $new_height = $image_original_height * $mult_x; } else { $new_width = $image_original_width * $mult_y; $new_height = $h; } $h = round( $new_height ); $w = round( $new_width ); } if ( $watermark == NULL || $h < $watermark['info']['height'] || $w < $watermark['info']['width'] ) { $watermark = NULL; } $s .= $w."x".$h.".".$e; if ( is_file( $s ) ) { resize( $scr, $w, $h, $s, $watermark ); } else { not_resize( $s, $watermark ); } $mysqlclass->close_db( ); exit( ); } if ( $arr1[0] == "c" ) { session_name( "tvs_session_id" ); session_start( ); include( $setupdata['core_dir']."/classes/captcha.php" ); $captcha = new captchaclass( 4 ); $captcha->setfont( $setupdata['core_dir']."/fonts/arial.ttf" ); $captcha->setfontdir( $setupdata['core_dir']."/fonts/" ); $captcha->display( ); $_SESSION['captcha'] = $captcha->getstring( "1" ); exit( ); } if ( $arr1[0] == "d" ) { session_name( "tvs_session_id" ); session_start( ); include( $setupdata['core_dir']."/classes/captcha.php" ); $captcha = new captchaclass( 6 ); $captcha->setfont( $setupdata['core_dir']."/fonts/arial.ttf" ); $captcha->setfontdir( $setupdata['core_dir']."/fonts/" ); $captcha->display( 1 ); $_SESSION['captcha'] = $captcha->getstring( "2" ); } } exit( ); ?>