// For "custom" directory $id = GETPOST('id'); $w = GETPOST('w'); $h = GETPOST('h'); $query = GETPOST('query'); // Content type header('Content-Type: image/jpeg'); if ($query == "cat") { require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/categories.lib.php'; $object = new Categorie($db); $result = $object->fetch($id); $upload_dir = $conf->categorie->multidir_output[$object->entity]; $pdir = get_exdir($object->id, 2) . $object->id . "/photos/"; $dir = $upload_dir . '/' . $pdir; foreach ($object->liste_photos($dir) as $key => $obj) { $filename = $obj['photo']; } // The file $filename = $dir . $filename; if (!file_exists($filename)) { $filename = "empty.jpg"; } // Dimensions list($width, $height) = getimagesize($filename); $new_width = $w; $new_height = $h; // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
/** * Return path of a catergory image * @param int $idCat Id of Category * @param bool $thumb If enabled use thumb * @return string Image path */ public static function getImageCategory($idCat) { global $conf, $db; $extName = "_small"; $extImgTarget = ".jpg"; $outDir = "pos"; $maxWidth = 90; $maxHeight = 90; $quality = 50; if ($idCat > 0) { $objCat = new Categorie($db); $objCat->fetch($idCat); $pdir = get_exdir($idCat, 2) . $idCat . "/photos/"; $dir = $conf->categorie->multidir_output[$objCat->entity] . '/' . $pdir; foreach ($objCat->liste_photos($dir, 1) as $key => $obj) { $filename = $dir . $obj['photo']; $filethumbs = $dir . $outDir . '/' . $obj['photo']; $fileName = preg_replace('/(\\.gif|\\.jpeg|\\.jpg|\\.png|\\.bmp)$/i', '', $filethumbs); $fileName = basename($fileName); $imgThumbName = $dir . $outDir . '/' . $fileName . $extName . $extImgTarget; $file_osencoded = $imgThumbName; if (!file_exists($file_osencoded)) { $file_osencoded = dol_osencode($filename); if (file_exists($file_osencoded)) { require_once DOL_DOCUMENT_ROOT . "/core/lib/images.lib.php"; vignette($filename, $maxWidth, $maxHeight, $extName, $quality, $outDir, 2); } } $filename = $outDir . '/' . $fileName . $extName . $extImgTarget; $realpath = DOL_URL_ROOT . '/viewimage.php?modulepart=category&entity=' . $objCat->entity . '&file=' . urlencode($pdir . $filename); } if (!$realpath) { $realpath = DOL_URL_ROOT . '/viewimage.php?modulepart=product&file=' . urlencode('noimage.jpg'); } return $realpath; } }
/** * Get category infos and children * * @param array $authentication Array of authentication information * @param int $id Id of object * @return mixed */ function getCategory($authentication, $id) { global $db, $conf, $langs; dol_syslog("Function: getCategory login="******" id=" . $id); if ($authentication['entity']) { $conf->entity = $authentication['entity']; } $objectresp = array(); $errorcode = ''; $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); if (!$error && !$id) { $error++; $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id must be provided."; } if (!$error) { $fuser->getrights(); if ($fuser->rights->categorie->lire) { $categorie = new Categorie($db); $result = $categorie->fetch($id); if ($result > 0) { $dir = !empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output; $pdir = get_exdir($categorie->id, 2) . $categorie->id . "/photos/"; $dir = $dir . '/' . $pdir; $cat = array('id' => $categorie->id, 'id_mere' => $categorie->id_mere, 'label' => $categorie->label, 'description' => $categorie->description, 'socid' => $categorie->socid, 'type' => $categorie->type, 'dir' => $pdir, 'photos' => $categorie->liste_photos($dir, $nbmax = 10)); $cats = $categorie->get_filles(); if (count($cats) > 0) { foreach ($cats as $fille) { $dir = !empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output; $pdir = get_exdir($fille->id, 2) . $fille->id . "/photos/"; $dir = $dir . '/' . $pdir; $cat['filles'][] = array('id' => $fille->id, 'id_mere' => $categorie->id_mere, 'label' => $fille->label, 'description' => $fille->description, 'socid' => $fille->socid, 'type' => $fille->type, 'dir' => $pdir, 'photos' => $fille->liste_photos($dir, $nbmax = 10)); } } // Create $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'categorie' => $cat); } else { $error++; $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id=' . $id; } } else { $error++; $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; } } if ($error) { $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }