Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- $db = new mysqli("localhost", "root", "pass", "db");
- function isadmin()
- {
- if($_SERVER['REMOTE_ADDR'] == "IP:adress")
- return true;
- return false;
- }
- function pager($rpp, $count, $href, $minus = 0) {
- $pages = ceil($count / $rpp); // Skaita cik kopaa lapas
- if (!$opts["lastpagedefault"])
- $pagedefault = 0;
- else {
- $pagedefault = floor(($count - 1) / $rpp);
- if ($pagedefault < 0)
- $pagedefault = 0;
- }
- if (isset($_GET["p"])) {
- $page = $_GET["p"] - 1;
- if ($page < 0)
- $page = $pagedefault;
- }
- else
- $page = $pagedefault;
- $lastpage = $page;
- if($lastpage > 0)
- {
- $pager = "<div><a href=\"$href".($lastpage)."\">«</a></div>";
- }
- if($lastpage+2 <= $pages)
- {
- $pager2 = "<div><a href=\"$href".($lastpage+2)."\">»</a></div>";
- }
- if ($count) {
- $pagerarr = array();
- $dotted = 0;
- $dotspace = 3;
- $dotend = $pages+1 - $dotspace;
- $curdotend = $page +1 - $dotspace;
- $curdotstart = $page +1 + $dotspace ;
- for ($i = 1; $i <= $pages; $i++) {
- if (($i >= $dotspace && $i <= $curdotend) || ($i >= $curdotstart && $i < $dotend))
- {
- if (!$dotted)
- $pagerarr[] = "<div>...</div>";
- $dotted = 1;
- continue;
- }
- $dotted = 0;
- $start = $i * $rpp;
- $end = $start + $rpp - 1;
- if ($end > $count)
- $end = $count;
- $href2 = $href. $i;
- $text = $i;
- if ($i != $page +1)
- $pagerarr[] = "<div><a href=\"{$href2}\">$text</a></div>";
- else
- $pagerarr[] = "<div class=\"current\">$text</div>";
- }
- $pager2 .= "<br style='clear:both;'></br>";
- $pagerstr = join("", $pagerarr);
- $pagertop = "<div id=\"pages\">$pager$pagerstr$pager2</div>\n";
- $pagerbottom = "<div id=\"pages\">$pager$pagerstr$pager2</div>\n";
- }
- else {
- $pagertop = "<div id=\"pages\">$pager$pagerstr$pager2</div>\n";
- $pagerbottom = "<div id=\"pages\">$pager$pagerstr$pager2</div>\n";
- }
- $start = $page * $rpp;
- return array($pagertop, $pagerbottom, "LIMIT $start,$rpp");
- }
- function createThumb($sourcefile, $target_file, $new_w, $new_h)
- {
- $root = dirname(__FILE__) . "/";
- $source_path = $sourcefile;
- //
- // Add file validation code here
- //
- list( $source_width, $source_height, $source_type ) = getimagesize( $source_path );
- switch ( $source_type )
- {
- case IMAGETYPE_GIF:
- $source_gdim = imagecreatefromgif( $source_path );
- $ext = ".gif";
- $fija = "imagegif";
- break;
- case IMAGETYPE_JPEG:
- $source_gdim = imagecreatefromjpeg( $source_path );
- $ext = ".jpg";
- $fija = "imagejpeg";
- break;
- case IMAGETYPE_PNG:
- $source_gdim = imagecreatefrompng( $source_path );
- $ext = ".png";
- $fija = "imagepng";
- break;
- }
- $source_aspect_ratio = $source_width / $source_height;
- $desired_aspect_ratio = $new_w / $new_h;
- if ( $source_aspect_ratio > $desired_aspect_ratio )
- {
- //
- // Triggered when source image is wider
- //
- $temp_height = $new_h;
- $temp_width = ( int ) ( $new_h * $source_aspect_ratio );
- }
- else
- {
- //
- // Triggered otherwise (i.e. source image is similar or taller)
- //
- $temp_width = $new_w;
- $temp_height = ( int ) ( $new_w / $source_aspect_ratio );
- }
- //
- // Resize the image into a temporary GD image
- //
- $temp_gdim = imagecreatetruecolor( $temp_width, $temp_height );
- imagealphablending($temp_gdim, false);
- imagesavealpha($temp_gdim,true);
- $transparent = imagecolorallocatealpha($temp_gdim, 255, 255, 255, 127);
- imagefilledrectangle($temp_gdim, 0, 0, $temp_width,$temp_height, $transparent);
- imagecopyresampled(
- $temp_gdim,
- $source_gdim,
- 0, 0,
- 0, 0,
- $temp_width, $temp_height,
- $source_width, $source_height
- );
- //
- // Copy cropped region from temporary image into the desired GD image
- //
- $x0 = ( $temp_width - $new_w ) / 2;
- $y0 = ( $temp_height - $new_h ) / 2;
- $desired_gdim = imagecreatetruecolor( $new_w, $new_h );
- imagealphablending($desired_gdim, false);
- imagesavealpha($desired_gdim,true);
- $transparent = imagecolorallocatealpha($desired_gdim, 255, 255, 255, 127);
- imagefilledrectangle($desired_gdim, 0, 0, $new_w,$new_h, $transparent);
- imagecopy(
- $desired_gdim,
- $temp_gdim,
- 0, 0,
- $x0, $y0,
- $new_w, $new_h
- );
- //
- // Render the image
- // Alternatively, you can save the image in file-system or database
- //
- if($fija($desired_gdim, $root.$target_file.$ext)) {
- imagedestroy($desired_gdim );
- imagedestroy($temp_gdim);
- }
- return $ext;
- //
- // Add clean-up code here
- //
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement