class Custom{ public static function CurrDate(){ return date("Y-m-d"); } public static function Rand(){ return md5(rand() * time()); } } class Format{ // Date with leading zeros public static function DateZ($date){ return date("d.m.Y", $date); } // Date with leading zeros public static function DateTimeZ($datetime){ return date("d.m.Y H.i.s", $datetime); } public static function Mysql_DateZ($date){ return Format :: DateZ(strtotime($date)); } public static function Mysql_DateTimeZ($date){ return Format :: DateTimeZ(strtotime($date)); } // Price public static function Price($price){ return number_format($price, 2, ",", "."); } // Quantity public static function Quantity($quantity){ return number_format($quantity, 0, ",", ""); } // Discount public static function Discount($Discount){ return number_format($Discount, 0, ",", "") . "%"; } // Discount - precise public static function DiscountPrecise($Discount){ return number_format($Discount, 2, ",", "") . "%"; } } class Check{ // Ali je liha public static function is_odd($number) { return ($number % 2) == 1; // 0 = even, 1 = odd } public static function is_int($int_str) { $IntValue = intval($int_str); $StrValue = strval($IntValue); if($StrValue == $int_str) { return true; } return false; } } class Convert{ public static function str_to_int($int_str) { $intRetVal = false; $IntValue = intval($int_str); $StrValue = strval($IntValue); if($StrValue == $int_str) { $intRetVal = $IntValue; } return $intRetVal; } } class Seo{ public static function friendlyurl($start,$title,$end){ // To lower $title = strtolower($title); // convert slo chars $title = str_replace("č" ,"c",$title); $title = str_replace("š" ,"s",$title); $title = str_replace("ž" ,"z",$title); $title = str_replace("Č" ,"C",$title); $title = str_replace("Š" ,"S",$title); $title = str_replace("Ž" ,"Z",$title); $title = str_replace("ć" ,"c",$title); $title = str_replace("Ć" ,"C",$title); $title = str_replace("\"" ,"",$title); $title = str_replace(""", '-', $title); $title = str_replace("đ" ,"dz",$title); $title = str_replace("Đ" ,"dz",$title); //$title = str_replace("‚", "-", $title); $title = str_replace('ë', 'e', $title); $title = str_replace('ü', 'u', $title); $title = str_replace('ä', 'a', $title); $title = str_replace('ö', 's', $title); $title = str_replace(":" ,"",$title); $title = preg_replace("/[^0-9a-z]+/i", "-", $title); // Replace all non english $title = trim($title, "-"); return $start . $title . $end; } public static function html_to_txt($document){ $search = array('@@si', // javascript '@@siU', // style '@<[\/\!]*?[^<>]*?>@si', // htmls '@@' // komentarji ); $text = preg_replace($search, ' ', $document); $text = trim($text); $text = str_replace(" ", " ", $text ); $text = str_replace("\"", " ", $text ); $text = str_replace("š", "š", $text ); $text = str_replace("Š", "Š", $text ); return $text; } public static function left($cNiz, $nLen=150) { $cNiz = trim($cNiz); if (strlen($cNiz) > $nLen) { $cNiz = substr($cNiz, 0, $nLen); if ($nAt=strrpos($cNiz, ' ')) { $cNiz = substr($cNiz, 0, $nAt); } } return $cNiz; } } class Calc{ public static function Price_Discount($price, $discount){ return ($price - ($price * $discount / 100)); } public static function Discount_Price($price, $discounted_price){ return 100 - ($discounted_price / $price ) * 100; } } class Html{ public static function is_empy($str){ $str = Seo::html_to_txt($str); $str = trim($str); return $str; } } class Upload{ /* * @return: * "" - file was not uploaded * "filename" - name of the file * false - error occur * */ public static function File($upload_fieldname, $save_dir, $save_filename = "", $save_overwrite = false){ $upload_file = $_FILES[$upload_fieldname]; if (trim($upload_file['tmp_name']) != '') { $upload_filename = $upload_file['name']; $upload_ext = substr(strrchr($upload_filename, "."), 1); // Save filename if($save_filename == ""){ $save_filename = $upload_filename; } else { $save_filename = $save_filename . ".$upload_ext"; } $save_file_full_path = $save_dir . $save_filename; // Check if can overwrite if(! $save_overwrite){ if(file_exists($save_file_full_path)){ return false; } } // Save file to disk $imagePath = move_uploaded_file($upload_file['tmp_name'], $save_file_full_path); return $save_filename; } return ""; } } class Download{ public static function file($filepath, $filename, $die=true){ if ($fd = fopen ($filepath, "r")) { $fsize = filesize($filepath); $path_parts = pathinfo($filepath); $ext = strtolower($path_parts["extension"]); switch ($ext) { case "pdf": header("Content-type: application/pdf"); // add here more headers for diff. extensions header("Content-Disposition: attachment; filename=\"".$filename."\""); // use 'attachment' to force a download break; default; header("Content-type: application/octet-stream"); header("Content-Disposition: filename=\"".$filename."\""); } header("Content-length: $fsize"); header("Cache-control: private"); //use this to open files directly while(!feof($fd)) { $buffer = fread($fd, 2048); echo $buffer; } } fclose ($fd); exit; if($die){ die(); } } } class Image{ // Rounder corners http://www.assemblysys.com/dataServices/rounded_corners.php public static function Round($file, $corner_image, $radius = 20, $angle = 0, $option = array("topleft" => true, "topright" => true, "bottomleft" => true, "bottomright" => true)){ //$image_file = $_GET['src']; //$corner_radius = isset($_GET['radius']) ? $_GET['radius'] : 20; // The default corner radius is set to 20px //$angle = isset($_GET['angle']) ? $_GET['angle'] : 0; // The default angle is set to 0o $topleft = $option["topleft"]; //(isset($_GET['topleft']) and $_GET['topleft'] == "no") ? false : true; // Top-left rounded corner is shown by default $bottomleft = $option["topright"]; //(isset($_GET['bottomleft']) and $_GET['bottomleft'] == "no") ? false : true; // Bottom-left rounded corner is shown by default $bottomright = $option["bottomleft"]; //(isset($_GET['bottomright']) and $_GET['bottomright'] == "no") ? false : true; // Bottom-right rounded corner is shown by default $topright = $option["bottomright"]; //(isset($_GET['topright']) and $_GET['topright'] == "no") ? false : true; // Top-right rounded corner is shown by default //$images_dir = 'images/'; //http://www.assemblysys.com/dataServices/rounded_corners.php $corner_source = imagecreatefrompng($corner_image);//imagecreatefrompng('images/rounded_corner.png'); $corner_width = imagesx($corner_source); $corner_height = imagesy($corner_source); $corner_resized = ImageCreateTrueColor($radius, $radius); ImageCopyResampled($corner_resized, $corner_source, 0, 0, 0, 0, $radius, $radius, $corner_width, $corner_height); $corner_width = imagesx($corner_resized); $corner_height = imagesy($corner_resized); $image = imagecreatetruecolor($corner_width, $corner_height); $image = imagecreatefromjpeg($file); // replace filename with $_GET['src'] $size = getimagesize($file); // replace filename with $_GET['src'] $white = ImageColorAllocate($image,255,255,255); $black = ImageColorAllocate($image,0,0,0); // Top-left corner if ($topleft == true) { $dest_x = 0; $dest_y = 0; imagecolortransparent($corner_resized, $black); imagecopymerge($image, $corner_resized, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); } // Bottom-left corner if ($bottomleft == true) { $dest_x = 0; $dest_y = $size[1] - $corner_height; $rotated = imagerotate($corner_resized, 90, 0); imagecolortransparent($rotated, $black); imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); } // Bottom-right corner if ($bottomright == true) { $dest_x = $size[0] - $corner_width; $dest_y = $size[1] - $corner_height; $rotated = imagerotate($corner_resized, 180, 0); imagecolortransparent($rotated, $black); imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); } // Top-right corner if ($topright == true) { $dest_x = $size[0] - $corner_width; $dest_y = 0; $rotated = imagerotate($corner_resized, 270, 0); imagecolortransparent($rotated, $black); imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); } // Rotate image $image = imagerotate($image, $angle, $white); // Output final image imagejpeg($image); imagedestroy($image); imagedestroy($corner_source); } } ?>