action.show_thumb_for_advert.php
Code: Select all
<?php
if(!isset($gCms)) exit;
$thumb_width = $this->GetPreference('thumb_for_advert_width', 120);
$thumb_heigth = $this->GetPreference('thumb_for_advert_height', 80);
if(empty($params['image_id']) || !$this->CorrectId($params['image_id'])){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 2'); // Niepoprawne ID
exit;
}
$db = &$this->GetDB();
$query = "SELECT image_name FROM module_FleaMarket_adverts_images WHERE image_id=".$params['image_id'];
$result = $db->Execute($query);
if(!$result) die($db->ErrorMsg());
if($result->NumRows() == 0){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 3'); // Nie istenieje takie ID
exit;
}
$row = $result->FetchRow();
$adverts_img_dir = realpath(cms_join_path(dirname(__FILE__), '..', '..', 'uploads', 'images', 'fleamarket'));
if(!$adverts_img_dir || !file_exists(cms_join_path($adverts_img_dir, $row['image_name']))){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 4'); // Nie istnieje taki plik
exit;
}
$image_path = cms_join_path($adverts_img_dir, $row['image_name']);
$image_info = @ getimagesize($image_path);
if(empty($image_info)){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 5'); // To nie obrazek
exit;
}
if($image_info[1] > $image_info[0]){
$percent = round(($this->GetPreference('thumb_for_advert_height', 80) * 100) / $image_info[1], 0);
$thumb_height = $this->GetPreference('thumb_for_advert_height', 80);
$thumb_width = ceil(($percent / 100) * $image_info[1]);
}else if($image_info[0] > $image_info[1]){
$percent = round(($this->GetPreference('thumb_for_advert_width', 120) * 100) / $image_info[0], 0);
$thumb_width = $this->GetPreference('thumb_for_advert_width', 120);
$thumb_heigth = ceil(($percent / 100) * $image_info[1]);
}else{
$thumb_width = $this->GetPreference('thumb_for_advert_width', 120);
$thumb_heigth = $this->GetPreference('thumb_for_advert_width', 120);
}
switch($image_info[2]){
case IMAGETYPE_GIF :
$img_full = @imagecreatefromgif($image_path);
if(!$img_full){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 6'); // Nie można otworzyć obrazka GIF
exit;
}
$img_thumb = imagecreatetruecolor($thumb_width, $thumb_heigth);
imagecopyresampled($img_thumb, $img_full, 0, 0, 0, 0, $thumb_width, $thumb_heigth, $image_info[0], $image_info[1]);
if(ini_get('zlib.output_compression')){
ini_set('zlib.output_compression', 'Off');
}
@ob_clean();
@ob_clean();
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: image/gif');
imagegif($img_thumb);
exit;
break;
case IMAGETYPE_JPEG :
$img_full = @imagecreatefromjpeg($image_path);
if(!$img_full){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 7'); // Nie można otworzyć obrazka JPEG
exit;
}
$img_thumb = imagecreatetruecolor($thumb_width, $thumb_heigth);
imagecopyresampled($img_thumb, $img_full, 0, 0, 0, 0, $thumb_width, $thumb_heigth, $image_info[0], $image_info[1]);
if(ini_get('zlib.output_compression')){
ini_set('zlib.output_compression', 'Off');
}
@ob_clean();
@ob_clean();
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: image/jpeg');
imagejpeg($img_thumb);
exit;
break;
default: $this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 8'); // To nie jest obrazek typu JPEG lub GIF
exit;
}
?>
Code: Select all
<?php
//....................................
$query = "SELECT image_id FROM module_FleaMarket_adverts_images WHERE advert_id=".$params['advert_id'];
$result = $db->Execute($query);
$adver_images = array();
if($result->NumRows() != 0){
$i = 0;
while($row = $result->FetchRow()){
$advert_images[$i]['image_thumb_link'] = $this->CreateLink($id, 'show_thumb_for_advert', $returnid, '',
array('image_id' =>$row['image_id'], 'showtemplate' => 'false'), '', true);
$advert_images[$i]['image_big_link'] = $this->CreateLink($id, 'show_big_image', $returnid, '',
array('image_id' =>$row['image_id'], 'showtemplate' => 'false'), '', true);
$i++;
}
}
if(empty($advert_images)){
$this->smarty->assign('advert_images', '');
}else{
$this->smarty->assign_by_ref('advert_images', $advert_images);
}
//...................................
?>
Code: Select all
{if !empty($advert_images)}
<div>
{foreach from=$advert_images item=image}
<a href="{$image.image_big_link}" target="_blank"><img src="{$image.image_thumb_link}" alt="zdjęcie" /></a>
{/foreach}
</div>
{/if}
action.admin_adverts_panel.php
Code: Select all
<?php
//............................
$query = "SELECT image_id FROM module_FleaMarket_adverts_images WHERE advert_id=".$row['advert_id'];
$result = $db->Execute($query);
if(!$result) die($db->ErrorMsg());
$adver_images = array();
if($result->NumRows() != 0){
$i = 0;
while($row = $result->FetchRow()){
$advert_images[$i]['image_thumb_link'] = $this->CreateLink($id, 'show_thumb_for_advert', $returnid, '',
array('image_id' =>$row['image_id'], 'showtemplate' => 'false'), '', true, true);
$advert_images[$i]['image_big_link'] = $this->CreateLink($id, 'show_big_image', $returnid, '',
array('image_id' =>$row['image_id'], 'showtemplate' => 'false'), '', true, true);
$i++;
}
}
if(empty($advert_images)){
$this->smarty->assign('advert_images', '');
}else{
$this->smarty->assign_by_ref('advert_images', $advert_images);
}
//............................
?>
Code: Select all
{if !empty($advert_images)}
<div>
{foreach from=$advert_images item=image}
<a href="{$image.image_big_link}" target="_blank"><img src="{$image.image_thumb_link}" alt="zdjęcie" /></a>
{/foreach}
</div>
{/if}
Code: Select all
http://domain.com/index.php?mact=FleaMarket,cntnt01,show_thumb_for_advert,0&cntnt01image_id=11&cntnt01showtemplate=false&cntnt01returnid=64
Code: Select all
http://domain.com/admin/moduleinterface.php?mact=FleaMarket,m1_,show_thumb_for_advert,1&m1_image_id=3&m1_showtemplate=false
And this is my thumbnail script:
Code: Select all
<?php
if(!isset($gCms)) exit;
$thumb_width = $this->GetPreference('thumb_for_advert_width', 120);
$thumb_heigth = $this->GetPreference('thumb_for_advert_height', 80);
if(empty($params['image_id']) || !$this->CorrectId($params['image_id'])){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 2'); // Niepoprawne ID
exit;
}
$db = &$this->GetDB();
$query = "SELECT image_name FROM module_FleaMarket_adverts_images WHERE image_id=".$params['image_id'];
$result = $db->Execute($query);
if(!$result) die($db->ErrorMsg());
if($result->NumRows() == 0){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 3'); // Nie istenieje takie ID
exit;
}
$row = $result->FetchRow();
$adverts_img_dir = realpath(cms_join_path(dirname(__FILE__), '..', '..', 'uploads', 'images', 'fleamarket'));
if(!$adverts_img_dir || !file_exists(cms_join_path($adverts_img_dir, $row['image_name']))){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 4'); // Nie istnieje taki plik
exit;
}
$image_path = cms_join_path($adverts_img_dir, $row['image_name']);
$image_info = @ getimagesize($image_path);
if(empty($image_info)){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 5'); // To nie obrazek
exit;
}
if($image_info[1] > $image_info[0]){
$percent = round(($this->GetPreference('thumb_for_advert_height', 80) * 100) / $image_info[1], 0);
$thumb_height = $this->GetPreference('thumb_for_advert_height', 80);
$thumb_width = ceil(($percent / 100) * $image_info[1]);
}else if($image_info[0] > $image_info[1]){
$percent = round(($this->GetPreference('thumb_for_advert_width', 120) * 100) / $image_info[0], 0);
$thumb_width = $this->GetPreference('thumb_for_advert_width', 120);
$thumb_heigth = ceil(($percent / 100) * $image_info[1]);
}else{
$thumb_width = $this->GetPreference('thumb_for_advert_width', 120);
$thumb_heigth = $this->GetPreference('thumb_for_advert_width', 120);
}
switch($image_info[2]){
case IMAGETYPE_GIF :
$img_full = @imagecreatefromgif($image_path);
if(!$img_full){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 6'); // Nie można otworzyć obrazka GIF
exit;
}
$img_thumb = imagecreatetruecolor($thumb_width, $thumb_heigth);
imagecopyresampled($img_thumb, $img_full, 0, 0, 0, 0, $thumb_width, $thumb_heigth, $image_info[0], $image_info[1]);
if(ini_get('zlib.output_compression')){
ini_set('zlib.output_compression', 'Off');
}
@ob_clean();
@ob_clean();
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: image/gif');
imagegif($img_thumb);
exit;
break;
case IMAGETYPE_JPEG :
$img_full = @imagecreatefromjpeg($image_path);
if(!$img_full){
$this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 7'); // Nie można otworzyć obrazka JPEG
exit;
}
$img_thumb = imagecreatetruecolor($thumb_width, $thumb_heigth);
imagecopyresampled($img_thumb, $img_full, 0, 0, 0, 0, $thumb_width, $thumb_heigth, $image_info[0], $image_info[1]);
if(ini_get('zlib.output_compression')){
ini_set('zlib.output_compression', 'Off');
}
@ob_clean();
@ob_clean();
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: image/jpeg');
imagejpeg($img_thumb);
exit;
break;
default: $this->CreateErrorThumb($thumb_width, $thumb_heigth, 'Error: 8'); // To nie jest obrazek typu JPEG lub GIF
exit;
}
?>
