store_result(); $md = $stmt->result_metadata(); $params = array(); while($field = $md->fetch_field()) $params[] = &$row[$field->name]; return call_user_func_array(array($stmt, 'bind_result'), $params); } function copyArray($from){ $final = array(); foreach ($from as $key => $value){ $final[$key] = $value; } return $final; } function recurseCopy($src,$dst) { $dir = opendir($src); @mkdir($dst); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($src . '/' . $file) ) recurseCopy($src . '/' . $file,$dst . '/' . $file); else copy($src . '/' . $file,$dst . '/' . $file); } } closedir($dir); } function utf8_encode_deep(&$input) { if (is_string($input)) $input = utf8_encode($input); else if (is_array($input)) { foreach ($input as &$value) utf8_encode_deep($value); unset($value); } else if (is_object($input)) { $vars = array_keys(get_object_vars($input)); foreach ($vars as $var) utf8_encode_deep($input->$var); } } function deleteDir($dirPath){ if (is_dir($dirPath)) { if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') $dirPath .= '/'; $files = glob($dirPath . '*', GLOB_MARK); foreach ($files as $file) { if (is_dir($file))deleteDir($file); else unlink($file); } rmdir($dirPath); } } function getTotalRows($stmt2){ $mysqli = ConnectionFactory::getFactory()->getConnection(); $sql = $mysqli->prepare($stmt2); $sql->execute(); $row = array(); db_bind_array($sql, $row); $sql->fetch(); return $row["c"]; } function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } return $randomString; } function changeSpecialCharacters($string) { $string = trim($string); $string = str_replace(" ", "-", $string);; $string = str_replace(array('á', 'à', 'ä', 'â', 'ª', 'Á', 'À', 'Â', 'Ä'),array('a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A'),$string); $string = str_replace(array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ê', 'Ë'),array('e', 'e', 'e', 'e', 'E', 'E', 'E', 'E'),$string); $string = str_replace(array('í', 'ì', 'ï', 'î', 'Í', 'Ì', 'Ï', 'Î'),array('i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'),$string); $string = str_replace(array('ó', 'ò', 'ö', 'ô', 'Ó', 'Ò', 'Ö', 'Ô'),array('o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'),$string); $string = str_replace(array('ú', 'ù', 'ü', 'û', 'Ú', 'Ù', 'Û', 'Ü'),array('u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'),$string); $string = str_replace(array('ñ', 'Ñ', 'ç', 'Ç'),array('n', 'N', 'c', 'C',),$string); $string = str_replace(array("\\", "¨", "º","--", "~","#", "@", "|", "!", "\"","·", "$", "%", "&", "/","(", ")", "?", "'", "¡","¿", "[", "^", "`", "]", "+", "}", "{", "¨", "´",">", "<", ";", ",", ":","."),'',$string); return strtolower($string); } function removerCaracteresEspeciales($string) { $string = trim($string); $string = str_replace(" ", "-", $string);; $string = str_replace(array('á', 'à', 'ä', 'â', 'ª', 'Á', 'À', 'Â', 'Ä'),array('a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A'),$string); $string = str_replace(array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ê', 'Ë'),array('e', 'e', 'e', 'e', 'E', 'E', 'E', 'E'),$string); $string = str_replace(array('í', 'ì', 'ï', 'î', 'Ì', 'Í', 'Ï', 'Î'),array('i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'),$string); $string = str_replace(array('ó', 'ò', 'ö', 'ô', 'Ó', 'Ò', 'Ö', 'Ô'),array('o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'),$string); $string = str_replace(array('ú', 'ù', 'ü', 'û', 'Ú', 'Ù', 'Û', 'Ü'),array('u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'),$string); $string = str_replace(array('ñ', 'Ñ', 'ç', 'Ç'),array('n', 'N', 'c', 'C',),$string); $string = str_replace(array("\\", "¨", "°","--", "~","#", "@", "|", "!", "\"","·", "$", "%", "&", "/","(", ")", "?", "'", "¡","¿", "[", "^", "`", "]", "+", "}", "{", "´",">", "<", ";", ",", ":","."),'',$string); return strtolower($string); } function curPageURL() { $pageURL = 'http'; if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } function returnEncryptedName($name,$title){ $dotpos = strrpos($name, "."); if ($dotpos) $ext = strtolower(substr($name, $dotpos)); else $ext = ""; return uniqid("") . substr(md5($title), 2, 12) . $ext; } function generateBrief($text,$lenght){ $brief = $text; $brief = substr($brief, 0,$lenght); if (strlen($text) > $lenght) $brief .= "..."; return $brief; } //USE: list($_POST,$_GET,$_COOKIE) function stripPredefinedVariablesSlashes(){ if ( in_array( strtolower( ini_get( 'magic_quotes_gpc' ) ), array( '1', 'on' ) ) ){ $_POST = array_map( 'stripslashes', $_POST ); $_GET = array_map( 'stripslashes', $_GET ); $_COOKIE = array_map( 'stripslashes', $_COOKIE ); } return array($_POST,$_GET,$_COOKIE); } //////IMAGES //0: Widht; 1:Height function GetThumbnailSize($imgfilename, $maxw, $maxh){ $origsize = @getimagesize($imgfilename); $newsize = array($origsize[0], $origsize[1]); if ($newsize[0] > $maxw){ $newsize[0] = $maxw; $newsize[1] = round($origsize[1]/$origsize[0]*$maxw); } if ($newsize[1] > $maxh){ $newsize[1] = $maxh; $newsize[0] = round($origsize[0]/$origsize[1]*$maxh); } return $newsize; } function resizeImage($file, $w, $h, $crop=FALSE) { list($width, $height) = getimagesize($file); $r = $width / $height; if ($crop) { if ($width > $height) { $width = ceil($width-($width*($r-$w/$h))); } else { $height = ceil($height-($height*($r-$w/$h))); } $newwidth = $w; $newheight = $h; } else { if ($w/$h > $r) { $newwidth = $h*$r; $newheight = $h; } else { $newheight = $w/$r; $newwidth = $w; } } $src = getImageFromFile($file); $dst = imagecreatetruecolor($newwidth, $newheight); imagesavealpha($dst, true); $trans_colour = imagecolorallocatealpha($dst, 0, 0, 0, 127); imagefill($dst, 0, 0, $trans_colour); imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); return $dst; } function getImageFromFile($filename){ $size=getimagesize($filename); switch($size["mime"]){ case "image/jpeg": $img = ImageCreateFromJPEG($filename); break; case "image/gif": $img = imagecreatefromgif($filename); break; case "image/png": $img = imagecreatefrompng($filename); break; default: $img = FALSE; break; } return $img; } function saveImage($image,$path, $name){ $size=getimagesize($path); switch($size["mime"]){ case "image/jpeg": ImageJPEG($image , $name); break; case "image/gif": ImageGIF($image , $name); break; case "image/png": ImagePNG($image , $name); break; } } function returnThumbnailImage($imageName,$pathHtml,$pathPhp,$maxWidth,$maxHeight,$altHtml,$altPhp){ $url = $imageName; if (isset($url) && $url != null && $url != "" && file_exists($pathPhp.$url)) { $url = $pathHtml.$url; $urlPhp = $pathPhp.$imageName; }else { $url = $altHtml; $urlPhp = $altPhp; } $size = GetThumbnailSize($urlPhp, $maxWidth, $maxHeight); return array($url, $size); } function saveImageToPath($path,$photo,$fileName,$oldImage){ $uploadsDir = $path; if (!is_dir($uploadsDir)) mkdir($uploadsDir,0777); move_uploaded_file($_FILES[$fileName]["tmp_name"], "$uploadsDir/$photo"); if ($oldImage && file_exists($uploadsDir.$oldImage) && !is_dir($uploadsDir.$oldImage)) unlink($uploadsDir.$oldImage); } function saveOriginalImage($path,$photo,$fileName,$oldImage){ $uploadsDir = $path.'original/'; if (!is_dir($uploadsDir)) mkdir($uploadsDir,0777); move_uploaded_file($_FILES[$fileName]["tmp_name"], "$uploadsDir/$photo"); if ($oldImage && file_exists($uploadsDir.$oldImage) && !is_dir($uploadsDir.$oldImage)) unlink($uploadsDir.$oldImage); } function resizeAndSaveImage($path,$photo,$oldImage,$maxWidth,$maxHeight){ $uploadsDirThumb = $path.'thumb/'; $uploadsDir = $path.'original/'; if (!is_dir($uploadsDirThumb)) mkdir($uploadsDirThumb,0777); $image = resizeImage("$uploadsDir/$photo", $maxWidth, $maxHeight); saveImage($image , "$uploadsDir/$photo", "$uploadsDirThumb/$photo"); if ($oldImage && file_exists($uploadsDirThumb.$oldImage) && !is_dir($uploadsDirThumb.$oldImage)) unlink($uploadsDirThumb.$oldImage); } function is_image($path){ $a = getimagesize($path); $image_type = $a[2]; if(in_array($image_type , array(IMAGETYPE_GIF , IMAGETYPE_JPEG ,IMAGETYPE_PNG , IMAGETYPE_BMP))){ return true; } return false; } //////END IMAGES function convertMysqlDateTo($format,$date){ $phpdate = strtotime( $date ); $diff = USER_TIMEZONE + (DATABASE_TIMEZONE * -1); return date( $format, strtotime($diff.' hours', $phpdate) ); } /////////////////////////////////// ADMIN //////////////////////////////////////// function showAdminPagination($rows,$totalRows,$pageName, $page){ if(isset($_GET['page']))$page= $_GET['page']; else $page=1; $rows_per_page= $rows; $lastpage= ceil($totalRows / $rows_per_page); $page=(int)$page; if($page > $lastpage) $page= $lastpage; if($page < 1) $page=1; if($totalRows != 0){$nextpage= $page +1;$prevpage= $page -1;} if ($page == 1) { echo '