define('DB_SERVER','185.88.154.198');
define('DB_USER','pishroc8_KamalSaeidi');
define('DB_PASS' ,'Kamkamak@1');
define('DB_NAME','pishroc8_pish');
$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
// Check connection
if (mysqli_connect_errno())
{
echo "خطا در اتصال به پایگاه داده: " . mysqli_connect_error();
}
//session_start();
//// Manager Login to Dashboard
define("ADMIN_USERNAME","admin");
define("ADMIN_PASSWORD","admin12305");
// End Manager Define to Log
require_once 'function.php';
require_once 'action.php';
function array_unique_compact($a){
$tmparr = array_unique($a);
$i=0;
foreach ($tmparr as $v) {
$newarr[$i] = $v;
$i++;
}
return $newarr;
}
//getting categories
function getCat()
{
global $con;
$get_cat="select * from tblcategory";
//for persion languge
$run_cat=@mysqli_query($con,"SET NAMES utf8");
$run_cat=@mysqli_query($con,"SET CHARACTER SET utf8");
$run_cat=@mysqli_query($con,$get_cat);
while($row_cat=@mysqli_fetch_array($run_cat))
{
$cat_id=$row_cat['id'];
$cat_title=$row_cat['CategoryName'];
echo "
$cat_title";
}
}
//getting brands
function getBrand()
{
global $con;
$get_brand="select * from tblsubcategory";
$run_brand =@mysqli_query($con,"SET NAMES utf8");
$run_brand =@mysqli_query($con,"SET CHARACTER SET utf8");
$run_brand=@mysqli_query($con,$get_brand);
while($row_brand=@mysqli_fetch_array($run_brand))
{
$brand_id=$row_brand['SubCategoryId'];
$brand_title=$row_brand['Subcategory'];
echo "$brand_title";
}
}
function getOptimizedImage($imagePath, $maxWidth = 800, $quality = 75) {
$basePath = 'admin/postimages/';
$originalImage = $basePath . $imagePath;
// Check if WebP version exists
$webpPath = $basePath . 'webp/' . pathinfo($imagePath, PATHINFO_FILENAME) . '.webp';
if (!file_exists(dirname($webpPath))) {
mkdir(dirname($webpPath), 0755, true);
}
// Create WebP version if it doesn't exist
if (!file_exists($webpPath) && file_exists($originalImage)) {
createWebPImage($originalImage, $webpPath, $quality);
}
// Return WebP if available, otherwise original
if (file_exists($webpPath)) {
return $webpPath;
}
return $originalImage;
}
function createWebPImage($sourcePath, $destPath, $quality = 75) {
$imageInfo = getimagesize($sourcePath);
if (!$imageInfo) return false;
list($width, $height, $type) = $imageInfo;
switch ($type) {
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($sourcePath);
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($sourcePath);
imagepalettetotruecolor($image);
imagealphablending($image, true);
imagesavealpha($image, true);
break;
default:
return false;
}
if ($image) {
$result = imagewebp($image, $destPath, $quality);
imagedestroy($image);
return $result;
}
return false;
}
function getImageDimensions($imagePath) {
$fullPath = 'admin/postimages/' . $imagePath;
if (file_exists($fullPath)) {
$dimensions = getimagesize($fullPath);
if ($dimensions) {
return [
'width' => $dimensions[0],
'height' => $dimensions[1],
'ratio' => $dimensions[1] / $dimensions[0]
];
}
}
return ['width' => 800, 'height' => 600, 'ratio' => 0.75]; // Default fallback
}
// Caching headers function
function setStaticCachingHeaders() {
$request_uri = $_SERVER['REQUEST_URI'];
// Check if it's a static resource
if (preg_match('/\.(css|js|png|jpg|jpeg|gif|webp|ico|woff|woff2|svg)(\?.*)?$/i', $request_uri)) {
header('Cache-Control: public, max-age=31536000, immutable');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
header('Pragma: public');
}
}
?>
Database connection failed