Здравейте!
Имам страшен проблем и не мога да разбера къде е проблема. Вече една седмица се мъча и повече не мога. Моля някой да помогне.
Проблема:
Сайт, в който хората си правят регистрация и могат да си едитват профила. Но когато искат да изтрият някоя картинка им излиза прозорец за логин в админ панел-а. Та въпроса е как да не препраща към админ-а а да си трие снимките.
Тези иконки които правят проблем са в тази част (това е първата за изтриване):
------------
$c .="<a href=\"#\" onclick=\"delPicture('".$v['hash']."', '$object_hash', '$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/icons/icon_delete.gif\" alt=\"delete\" /></a>";
------------
Ако някой иска повече инфо давам ФТП
Моля ви!!!
Добавям инфото от файла galleryEdit.php :
<?
class galleryEdit extends basicAdminController {
private $resizer;
private $img_types = array('jpg', 'jpeg', 'JPG', 'JPEG', 'gif', 'png');
private $big_w = 800;
private $big_h = 800;
private $small_w = 160;
private $small_h = 120;
//private $fields = array('alt', 'title');
//public $fields = array('title');
public $fields = array();
public $type = 'default';
public $options=array(
'crop'=>true
);
public $maxSize = 524288;
/**
* Конструктора
*
*/
function __construct(){
parent::init();
$this->resizer = new resizerClass();
}
function navigator(){
$this->setAjax(true);
if(isset($this->pars[2]) && method_exists($this, $this->pars[2])){
$this->{$this->pars[2]}();
}
exit;
}
/**
* Създава и оразмерява изображенията след ъплоуд
*
* @param array $files
* @param string $hash
* @param array $sizes
* @return bool
*/
public function createPicture($object_hash, $sizes=array(), $watermark=''){
if(empty($sizes)){
$sizes = array(
'large'=>array('method'=>'simple', 'width'=>$this->big_w , 'height'=>$this->big_h),
'small'=>array('method'=>'crop', 'width'=>$this->small_w, 'height'=>$this->small_h)
);
}
if (empty($_FILES['images_'.$this->type])){return false;}
$files = $_FILES['images_'.$this->type];
$count = count($files['name']);
if($count==0){return false;}
for ($i = 0; $i < $count; $i++) {
if (is_uploaded_file($files['tmp_name'][$i])){
#ако файла е по-голям от допустимото
if ($files['size'][$i] > $this->maxSize){ return false;}
$ext = $this->_getFileExtension($files['name'][$i]);
#ако файла има непозоволено разширение
if (!in_array($ext, $this->img_types)){return false;}
#вземаме следващото id
$inc = $this->db->fetchOne("SHOW TABLE STATUS LIKE '".$this->table_gallery."'");
$inc = $inc['Auto_increment'];
$name = $object_hash."_".$inc.".jpg";
$big_path = GALLERY_BIG.$object_hash."_".$inc.'.'.$ext;
$thumbs_path = GALLERY_THUMBS.$object_hash."_".$inc.'.'.$ext;
if (!move_uploaded_file($files['tmp_name'][$i], $big_path) || !copy($big_path, $thumbs_path)){
return false;
}else {
$hash = uniqueHash();
$order = $this->getNextOrder($this->table_gallery, "`object_hash`='$object_hash'");
#Вземаме езиците
$langs = $this->getLangs();
foreach ($langs as $l){
$ins = array();
$ins['hash'] = $hash;
$ins['object_hash'] = $object_hash;
$ins['name'] = $name;
$ins['order'] = $order;
$ins['lang_id'] = $l['id'];
$ins['type'] = $this->type;
if(!empty($this->fields)){
foreach($this->fields as $field){
$ins[$field] = $_POST['pic_'.$field][$l['id']][$i];
}
}
$this->db->insert($this->table_gallery, $ins);
}
$resizer = new resizerClass();
if($sizes['small']['method']=='crop'){$small_method='resize';}else{$small_method = 'simpleResize';}
if($sizes['large']['method']=='crop'){$large_method='resize';}else{$large_method = 'simpleResize';}
$resizer->$small_method($sizes['small']['width'],$sizes['small']['height'],$thumbs_path);
$resizer->$large_method($sizes['large']['width'],$sizes['large']['height'],$big_path);
if(!empty($watermark)){
$this->addWaterMark(GALLERY_BIG.$name, $watermark, 'center');
}
}
} //end if is_uploaded
}//end foreach
return true;
}
/**
* Връща разширенито на файла
*
* @param string $file името на файла
* @return string разширението на файла
*/
private function _getFileExtension($file){
return strtolower(end(explode('.',$file)));
}
function listPicture($object_hash){
$c = "";
$c .= '<div id="galleryList_'.$this->type.'">';
$c .= $this->realList($object_hash);
$c .= '</div>';
return $c;
}
private function realList($object_hash){
$c = '';
$c .= '<script type="text/javascript" src="'.BASE_PATH_WEB.'js/plugins/modal.js"></script>';
$wh = array();
$wh['object_hash'] = $object_hash;
$wh['lang_id'] = $this->lang_id;
$wh['type'] = $this->type;
$arr = $this->db->getRows($this->table_gallery, $wh, '', array('order'=>'desc'));
if(!empty($arr)){
foreach($arr as $v){
$rand = randomCode(4);
$c .= "<div class=\"pic_cont\">".
"<a href=\"".DOMAIN.GALLERY_BIG.$v['name']."\" class=\"modal\" target=\"_blank\"><img src=\"".DOMAIN.GALLERY_THUMBS.$v['name']."?r=$rand\" /></a><br />";
if(!empty($this->fields)){
foreach ($this->fields as $field){
$c .= '<b>'.$this->lang[$field].': </b>'.$v[$field].'<br />';
}
}
$c .="<a href=\"#\" onclick=\"delPicture('".$v['hash']."', '$object_hash', '$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/icons/icon_delete.gif\" alt=\"delete\" /></a>";
$c .="<a href=\"#\" onclick=\"movePicture('".$v['hash']."','up','$object_hash','$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/admin/icons/right.png\" alt=\"down\" /></a>";
$c .="<a href=\"#\" onclick=\"movePicture('".$v['hash']."','down','$object_hash','$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/admin/icons/left.png\" alt=\"up\" /></a>";
if($this->options['crop']){
$c .="<a href=\"#\" onclick=\"cropPicture('".$v['hash']."', '$object_hash','$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/admin/icons/crop.gif\" alt=\"crop\" /></a>";
}
if(!empty($this->fields)){
$fields = base64_encode(serialize($this->fields));
$c .="<a href=\"".DOMAIN."admin/gallery/editGallery/hash:".$v['hash']."/object_hash:$object_hash/fields:$fields\" class=\"modal\"><img src=\"".BASE_PATH_WEB."img/admin/icons/icon_edit.gif\" alt=\"edit\" /></a>";
}
$c .= "</div>";
}
$c.= "<div style=\"clear:both;\"></div>";
} else {
$c = $this->showStatus($this->lang['no_results_found']);
}
return $c;
}
function createUploadFields($more=true){
$c = '<div id="createUploadFieldsFiles_'.$this->type.'">';
$c .= '<div class="row">';
$c .= '<table>';
$c .= '<tr><td>Файл:</td><td><input type="file" name="images_'.$this->type.'[]" /></td></tr>';
if(!empty($this->fields)){
$langs = $this->getLangs();
//За всяко поле
foreach($this->fields as $ff){
$c .= '<tr><td>'.$this->lang[$ff].'</td><td>';
//за всеки език
foreach($langs as $v){
$c .= $v['lang'].": <input style=\"width: 100px;\" type=\"text\" name=\"pic_".$ff."[".$v['id']."][]\" />";
}
$c .= '</td></tr>';
}
}
$c .= '</table>';
$c .= '</div>';
$c .= '</div>';
if($more){
$c .= "<a href=\"#\" onclick=\"addRow('createUploadFieldsFiles_$this->type', '+'); return false;\">Добави поле</a> | ";
$c .= "<a href=\"#\" onclick=\"addRow('createUploadFieldsFiles_$this->type', '-'); return false;\">Премахни поле</a> ";
}
return $c;
}
function delPicture($hash){
if (empty($hash)){return false;}
#Вземаме инфото за файла
$pic = $this->db->getRow($this->table_gallery, array('hash'=>$hash));
#ако съществува
if(!empty($pic)){
#изтриваме записа от базата данни
$this->db->delete($this->table_gallery, array('hash'=>$hash));
$big_path = GALLERY_BIG.$pic['name'];
$thumb_path = GALLERY_THUMBS.$pic['name'];
#Изтриваме и снимките ако съществуват
if(file_exists($big_path)){unlink($big_path);}
if(file_exists($thumb_path)){unlink($thumb_path);}
return true;
}
}
function delObjectPictures($object_hash){
if (empty($object_hash)){return false;}
$wh = array('object_hash'=>$object_hash);
$order= array('order'=>'desc');
$arr = $this->db->getRows($this->table_gallery, $wh, 'name', $order);
if(empty($arr)){return false;}
foreach ($arr as $pic){
$big_path = GALLERY_BIG.$pic['name'];
$thumb_path = GALLERY_THUMBS.$pic['name'];
#Изтриваме снимките ако съществуват
if(file_exists($big_path)){unlink($big_path);}
if(file_exists($thumb_path)){unlink($thumb_path);}
}
$this->db->delete($this->table_gallery, $wh);
return true;
}
private function addWaterMark($image,$watermark,$position='bottom-left'){
if(!file_exists($image) || !file_exists($watermark)){return false;}
$img_ext = strtolower(end(explode('.',$image)));
if ($img_ext == "gif") {
$function = 'imagecreatefromgif';
} elseif ($img_ext == "jpg" || $img_ext == "jpeg") {
$function = 'imagecreatefromjpeg';
} elseif ($img_ext == "png") {
$function = 'imagecreatefrompng';
}else{
$function = 'imagecreatefromjpeg';
}
$Image = $function($image);
$Watermark = imagecreatefrompng($watermark);
switch ($position){
case 'bottom-right':
$PosX = imagesx($Image)-imagesx($Watermark)-5;
$PosY = imagesy($Image)-imagesy($Watermark)-5;
break;
case 'bottom-left':
$PosX = 5;
$PosY = imagesy($Image)-imagesy($Watermark)-5;
break;
case 'top-right':
$PosX = imagesx($Image)-imagesx($Watermark)-5;
$PosY = 5;
break;
case 'top-left':
$PosX = 5;
$PosY = 5;
break;
case 'center':
$PosX = (imagesx($Image)-imagesx($Watermark))/2;
$PosY = (imagesy($Image)-imagesy($Watermark))/2;
break;
}
imagecopy($Image,$Watermark,$PosX,$PosY,0,0,imagesx($Watermark),imagesy($Watermark));
$newImage3 = imagecreatetruecolor(imagesx($Image),imagesy($Image));
imagecopyresampled($newImage3,$Image,0,0,0,0,imagesx($Image),imagesy($Image),imagesx($Image),imagesy($Image));
imagejpeg($newImage3,$image,100);
}
function cropPicture(){
if($this->options['crop'] !=true){ return false;}
if(empty($_GET['hash']) || empty($_GET['object_hash'])){return false;}
$hash = $_GET['hash'];
$object_hash= $_GET['object_hash'];
#Вземаме инфото за файла
$ar = $this->db->getRow($this->table_gallery, array('hash'=>$hash));
if(empty($ar)){return false;}
$small_path = GALLERY_THUMBS.$ar['name'];
$big_path = GALLERY_BIG.$ar['name'];
if(!file_exists($small_path)){return false;}
list($width, $height) = getimagesize($small_path);
$ratio = $width/$height;
if(!empty($_POST)){
$resizer = new resizerClass();
$resizer->galleryCropper($big_path, $small_path, $width, $height, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
$this->smarty->assign('done', '1');
$this->smarty->assign('reloadUrl', DOMAIN.'admin/gallery/ajaxList/object_hash:'.$object_hash.'/type:'.$_POST['type']);
}
$vars = array();
$vars['img'] = $ar['name'];
$vars['ratio'] = $ratio;
$vars['width'] = $width;
$vars['height'] = $height;
$vars['hash'] = $hash;
$tpl = 'admin/crop.html';
$mess = $this->loadTemplate($tpl, $vars);
$this->smarty->append('styles', 'jcrop');
$this->smarty->append('scripts', 'jquery');
$this->smarty->append('scripts', 'plugins/jcrop');
$this->smarty->assign('text', $mess);
$this->smarty->display('site/empty.html');
}
function ajaxList(){
$this->setAjax();
$object_hash = $_GET['object_hash'];
if (!empty($_GET['type'])){
$this->type = $_GET['type'];
}
echo $this->listPicture($object_hash);
}
/*
* AJAX функция за редакция на текстовете към снимка
*/
function editGallery(){
$this->setAjax(true);
if(empty($_GET['hash'])){
$this->echoInfo($this->lang['error_try_later']);
return false;
}
$langs = $this->getLangs();
$hash = $_GET['hash'];
$object_hash = $_GET['object_hash'];
$ar = $this->db->getRows($this->table_gallery, array('hash'=>$hash));
$values = array();
if(!empty($ar)){
foreach ($ar as $v){
$values[$v['lang_id']]=$v;
}
}
$fields = array();
$fieldsArr = unserialize(base64_decode($_GET['fields']));
foreach($fieldsArr as $v){
$fields[$v] = $this->lang[$v];
}
$tpl = 'admin/files_texts.html';
$vars = array();
$vars['langs'] = $langs;
$vars['values'] = $values;
$vars['fields'] = $fields;
$vars['fieldsArr'] = $_GET['fields'];
$vars['hash'] = $hash;
$vars['type'] = 'gallery';
$vars['object_hash']=$object_hash;
$mess = $this->loadTemplate($tpl, $vars);
echo $mess;
}
/*
* Записва текстовете
*/
function saveTexts(){
$this->setAjax(true);
if(empty($_POST)){
echo $this->lang['error_try_later'];
return false;
}
if(empty($_POST['hash'])){return false;}
if(empty($_POST['object_hash'])){return false;}
$fieldsArray = unserialize(base64_decode( $_POST['fieldsArr']));
$hash = $_POST['hash'];
$object_hash = $_POST['object_hash'];
$langs = $this->getLangs();
foreach($langs as $v){
$upd = array();
foreach($fieldsArray as $field){
$upd[$field] = $_POST[$field][$v['id']];
}
$wh = array();
$wh['hash'] = $hash;
$wh['lang_id'] = $v['id'];
$this->db->update($this->table_gallery, $upd, $wh);
}
echo $this->listPicture($object_hash);
}
function movePic(){
if (empty($_GET['hash'])){return false;}
if (empty($_GET['d'])){return false;}
if (empty($_GET['object_hash'])){return false;}
$this->setAjax();
if (!empty($_GET['type'])){
$this->type = $_GET['type'];
}
$this->moveItem($this->table_gallery,'hash',$_GET['hash'],$_GET['d'], "`object_hash`='".$_GET['object_hash']."'");
echo $this->listPicture($_GET['object_hash']);
}
function delPic(){
$this->setAjax();
if (empty($_GET['hash'])){return false;}
if (empty($_GET['object_hash'])){return false;}
$this->delPicture($_GET['hash']);
if (!empty($_GET['type'])){
$this->type = $_GET['type'];
}
echo $this->listPicture($_GET['object_hash']);
exit;
}
/*
* Метод за добавяне на нови езици
*/
public function addLang($newLangId, $primaryLang){
$result = $this->generalAddLang($this->table_gallery, $newLangId, $primaryLang);
return $result;
}
/*
* Метод за добавяне на нови езици
*/
public function delLang($langId){
$result = $this->generalDelLang($this->table_gallery, $langId);
return $result;
}
}
?>
Имам страшен проблем и не мога да разбера къде е проблема. Вече една седмица се мъча и повече не мога. Моля някой да помогне.
Проблема:
Сайт, в който хората си правят регистрация и могат да си едитват профила. Но когато искат да изтрият някоя картинка им излиза прозорец за логин в админ панел-а. Та въпроса е как да не препраща към админ-а а да си трие снимките.
Тези иконки които правят проблем са в тази част (това е първата за изтриване):
------------
$c .="<a href=\"#\" onclick=\"delPicture('".$v['hash']."', '$object_hash', '$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/icons/icon_delete.gif\" alt=\"delete\" /></a>";
------------
Ако някой иска повече инфо давам ФТП
Добавям инфото от файла galleryEdit.php :
<?
class galleryEdit extends basicAdminController {
private $resizer;
private $img_types = array('jpg', 'jpeg', 'JPG', 'JPEG', 'gif', 'png');
private $big_w = 800;
private $big_h = 800;
private $small_w = 160;
private $small_h = 120;
//private $fields = array('alt', 'title');
//public $fields = array('title');
public $fields = array();
public $type = 'default';
public $options=array(
'crop'=>true
);
public $maxSize = 524288;
/**
* Конструктора
*
*/
function __construct(){
parent::init();
$this->resizer = new resizerClass();
}
function navigator(){
$this->setAjax(true);
if(isset($this->pars[2]) && method_exists($this, $this->pars[2])){
$this->{$this->pars[2]}();
}
exit;
}
/**
* Създава и оразмерява изображенията след ъплоуд
*
* @param array $files
* @param string $hash
* @param array $sizes
* @return bool
*/
public function createPicture($object_hash, $sizes=array(), $watermark=''){
if(empty($sizes)){
$sizes = array(
'large'=>array('method'=>'simple', 'width'=>$this->big_w , 'height'=>$this->big_h),
'small'=>array('method'=>'crop', 'width'=>$this->small_w, 'height'=>$this->small_h)
);
}
if (empty($_FILES['images_'.$this->type])){return false;}
$files = $_FILES['images_'.$this->type];
$count = count($files['name']);
if($count==0){return false;}
for ($i = 0; $i < $count; $i++) {
if (is_uploaded_file($files['tmp_name'][$i])){
#ако файла е по-голям от допустимото
if ($files['size'][$i] > $this->maxSize){ return false;}
$ext = $this->_getFileExtension($files['name'][$i]);
#ако файла има непозоволено разширение
if (!in_array($ext, $this->img_types)){return false;}
#вземаме следващото id
$inc = $this->db->fetchOne("SHOW TABLE STATUS LIKE '".$this->table_gallery."'");
$inc = $inc['Auto_increment'];
$name = $object_hash."_".$inc.".jpg";
$big_path = GALLERY_BIG.$object_hash."_".$inc.'.'.$ext;
$thumbs_path = GALLERY_THUMBS.$object_hash."_".$inc.'.'.$ext;
if (!move_uploaded_file($files['tmp_name'][$i], $big_path) || !copy($big_path, $thumbs_path)){
return false;
}else {
$hash = uniqueHash();
$order = $this->getNextOrder($this->table_gallery, "`object_hash`='$object_hash'");
#Вземаме езиците
$langs = $this->getLangs();
foreach ($langs as $l){
$ins = array();
$ins['hash'] = $hash;
$ins['object_hash'] = $object_hash;
$ins['name'] = $name;
$ins['order'] = $order;
$ins['lang_id'] = $l['id'];
$ins['type'] = $this->type;
if(!empty($this->fields)){
foreach($this->fields as $field){
$ins[$field] = $_POST['pic_'.$field][$l['id']][$i];
}
}
$this->db->insert($this->table_gallery, $ins);
}
$resizer = new resizerClass();
if($sizes['small']['method']=='crop'){$small_method='resize';}else{$small_method = 'simpleResize';}
if($sizes['large']['method']=='crop'){$large_method='resize';}else{$large_method = 'simpleResize';}
$resizer->$small_method($sizes['small']['width'],$sizes['small']['height'],$thumbs_path);
$resizer->$large_method($sizes['large']['width'],$sizes['large']['height'],$big_path);
if(!empty($watermark)){
$this->addWaterMark(GALLERY_BIG.$name, $watermark, 'center');
}
}
} //end if is_uploaded
}//end foreach
return true;
}
/**
* Връща разширенито на файла
*
* @param string $file името на файла
* @return string разширението на файла
*/
private function _getFileExtension($file){
return strtolower(end(explode('.',$file)));
}
function listPicture($object_hash){
$c = "";
$c .= '<div id="galleryList_'.$this->type.'">';
$c .= $this->realList($object_hash);
$c .= '</div>';
return $c;
}
private function realList($object_hash){
$c = '';
$c .= '<script type="text/javascript" src="'.BASE_PATH_WEB.'js/plugins/modal.js"></script>';
$wh = array();
$wh['object_hash'] = $object_hash;
$wh['lang_id'] = $this->lang_id;
$wh['type'] = $this->type;
$arr = $this->db->getRows($this->table_gallery, $wh, '', array('order'=>'desc'));
if(!empty($arr)){
foreach($arr as $v){
$rand = randomCode(4);
$c .= "<div class=\"pic_cont\">".
"<a href=\"".DOMAIN.GALLERY_BIG.$v['name']."\" class=\"modal\" target=\"_blank\"><img src=\"".DOMAIN.GALLERY_THUMBS.$v['name']."?r=$rand\" /></a><br />";
if(!empty($this->fields)){
foreach ($this->fields as $field){
$c .= '<b>'.$this->lang[$field].': </b>'.$v[$field].'<br />';
}
}
$c .="<a href=\"#\" onclick=\"delPicture('".$v['hash']."', '$object_hash', '$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/icons/icon_delete.gif\" alt=\"delete\" /></a>";
$c .="<a href=\"#\" onclick=\"movePicture('".$v['hash']."','up','$object_hash','$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/admin/icons/right.png\" alt=\"down\" /></a>";
$c .="<a href=\"#\" onclick=\"movePicture('".$v['hash']."','down','$object_hash','$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/admin/icons/left.png\" alt=\"up\" /></a>";
if($this->options['crop']){
$c .="<a href=\"#\" onclick=\"cropPicture('".$v['hash']."', '$object_hash','$this->type'); return false;\"><img src=\"".BASE_PATH_WEB."img/admin/icons/crop.gif\" alt=\"crop\" /></a>";
}
if(!empty($this->fields)){
$fields = base64_encode(serialize($this->fields));
$c .="<a href=\"".DOMAIN."admin/gallery/editGallery/hash:".$v['hash']."/object_hash:$object_hash/fields:$fields\" class=\"modal\"><img src=\"".BASE_PATH_WEB."img/admin/icons/icon_edit.gif\" alt=\"edit\" /></a>";
}
$c .= "</div>";
}
$c.= "<div style=\"clear:both;\"></div>";
} else {
$c = $this->showStatus($this->lang['no_results_found']);
}
return $c;
}
function createUploadFields($more=true){
$c = '<div id="createUploadFieldsFiles_'.$this->type.'">';
$c .= '<div class="row">';
$c .= '<table>';
$c .= '<tr><td>Файл:</td><td><input type="file" name="images_'.$this->type.'[]" /></td></tr>';
if(!empty($this->fields)){
$langs = $this->getLangs();
//За всяко поле
foreach($this->fields as $ff){
$c .= '<tr><td>'.$this->lang[$ff].'</td><td>';
//за всеки език
foreach($langs as $v){
$c .= $v['lang'].": <input style=\"width: 100px;\" type=\"text\" name=\"pic_".$ff."[".$v['id']."][]\" />";
}
$c .= '</td></tr>';
}
}
$c .= '</table>';
$c .= '</div>';
$c .= '</div>';
if($more){
$c .= "<a href=\"#\" onclick=\"addRow('createUploadFieldsFiles_$this->type', '+'); return false;\">Добави поле</a> | ";
$c .= "<a href=\"#\" onclick=\"addRow('createUploadFieldsFiles_$this->type', '-'); return false;\">Премахни поле</a> ";
}
return $c;
}
function delPicture($hash){
if (empty($hash)){return false;}
#Вземаме инфото за файла
$pic = $this->db->getRow($this->table_gallery, array('hash'=>$hash));
#ако съществува
if(!empty($pic)){
#изтриваме записа от базата данни
$this->db->delete($this->table_gallery, array('hash'=>$hash));
$big_path = GALLERY_BIG.$pic['name'];
$thumb_path = GALLERY_THUMBS.$pic['name'];
#Изтриваме и снимките ако съществуват
if(file_exists($big_path)){unlink($big_path);}
if(file_exists($thumb_path)){unlink($thumb_path);}
return true;
}
}
function delObjectPictures($object_hash){
if (empty($object_hash)){return false;}
$wh = array('object_hash'=>$object_hash);
$order= array('order'=>'desc');
$arr = $this->db->getRows($this->table_gallery, $wh, 'name', $order);
if(empty($arr)){return false;}
foreach ($arr as $pic){
$big_path = GALLERY_BIG.$pic['name'];
$thumb_path = GALLERY_THUMBS.$pic['name'];
#Изтриваме снимките ако съществуват
if(file_exists($big_path)){unlink($big_path);}
if(file_exists($thumb_path)){unlink($thumb_path);}
}
$this->db->delete($this->table_gallery, $wh);
return true;
}
private function addWaterMark($image,$watermark,$position='bottom-left'){
if(!file_exists($image) || !file_exists($watermark)){return false;}
$img_ext = strtolower(end(explode('.',$image)));
if ($img_ext == "gif") {
$function = 'imagecreatefromgif';
} elseif ($img_ext == "jpg" || $img_ext == "jpeg") {
$function = 'imagecreatefromjpeg';
} elseif ($img_ext == "png") {
$function = 'imagecreatefrompng';
}else{
$function = 'imagecreatefromjpeg';
}
$Image = $function($image);
$Watermark = imagecreatefrompng($watermark);
switch ($position){
case 'bottom-right':
$PosX = imagesx($Image)-imagesx($Watermark)-5;
$PosY = imagesy($Image)-imagesy($Watermark)-5;
break;
case 'bottom-left':
$PosX = 5;
$PosY = imagesy($Image)-imagesy($Watermark)-5;
break;
case 'top-right':
$PosX = imagesx($Image)-imagesx($Watermark)-5;
$PosY = 5;
break;
case 'top-left':
$PosX = 5;
$PosY = 5;
break;
case 'center':
$PosX = (imagesx($Image)-imagesx($Watermark))/2;
$PosY = (imagesy($Image)-imagesy($Watermark))/2;
break;
}
imagecopy($Image,$Watermark,$PosX,$PosY,0,0,imagesx($Watermark),imagesy($Watermark));
$newImage3 = imagecreatetruecolor(imagesx($Image),imagesy($Image));
imagecopyresampled($newImage3,$Image,0,0,0,0,imagesx($Image),imagesy($Image),imagesx($Image),imagesy($Image));
imagejpeg($newImage3,$image,100);
}
function cropPicture(){
if($this->options['crop'] !=true){ return false;}
if(empty($_GET['hash']) || empty($_GET['object_hash'])){return false;}
$hash = $_GET['hash'];
$object_hash= $_GET['object_hash'];
#Вземаме инфото за файла
$ar = $this->db->getRow($this->table_gallery, array('hash'=>$hash));
if(empty($ar)){return false;}
$small_path = GALLERY_THUMBS.$ar['name'];
$big_path = GALLERY_BIG.$ar['name'];
if(!file_exists($small_path)){return false;}
list($width, $height) = getimagesize($small_path);
$ratio = $width/$height;
if(!empty($_POST)){
$resizer = new resizerClass();
$resizer->galleryCropper($big_path, $small_path, $width, $height, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
$this->smarty->assign('done', '1');
$this->smarty->assign('reloadUrl', DOMAIN.'admin/gallery/ajaxList/object_hash:'.$object_hash.'/type:'.$_POST['type']);
}
$vars = array();
$vars['img'] = $ar['name'];
$vars['ratio'] = $ratio;
$vars['width'] = $width;
$vars['height'] = $height;
$vars['hash'] = $hash;
$tpl = 'admin/crop.html';
$mess = $this->loadTemplate($tpl, $vars);
$this->smarty->append('styles', 'jcrop');
$this->smarty->append('scripts', 'jquery');
$this->smarty->append('scripts', 'plugins/jcrop');
$this->smarty->assign('text', $mess);
$this->smarty->display('site/empty.html');
}
function ajaxList(){
$this->setAjax();
$object_hash = $_GET['object_hash'];
if (!empty($_GET['type'])){
$this->type = $_GET['type'];
}
echo $this->listPicture($object_hash);
}
/*
* AJAX функция за редакция на текстовете към снимка
*/
function editGallery(){
$this->setAjax(true);
if(empty($_GET['hash'])){
$this->echoInfo($this->lang['error_try_later']);
return false;
}
$langs = $this->getLangs();
$hash = $_GET['hash'];
$object_hash = $_GET['object_hash'];
$ar = $this->db->getRows($this->table_gallery, array('hash'=>$hash));
$values = array();
if(!empty($ar)){
foreach ($ar as $v){
$values[$v['lang_id']]=$v;
}
}
$fields = array();
$fieldsArr = unserialize(base64_decode($_GET['fields']));
foreach($fieldsArr as $v){
$fields[$v] = $this->lang[$v];
}
$tpl = 'admin/files_texts.html';
$vars = array();
$vars['langs'] = $langs;
$vars['values'] = $values;
$vars['fields'] = $fields;
$vars['fieldsArr'] = $_GET['fields'];
$vars['hash'] = $hash;
$vars['type'] = 'gallery';
$vars['object_hash']=$object_hash;
$mess = $this->loadTemplate($tpl, $vars);
echo $mess;
}
/*
* Записва текстовете
*/
function saveTexts(){
$this->setAjax(true);
if(empty($_POST)){
echo $this->lang['error_try_later'];
return false;
}
if(empty($_POST['hash'])){return false;}
if(empty($_POST['object_hash'])){return false;}
$fieldsArray = unserialize(base64_decode( $_POST['fieldsArr']));
$hash = $_POST['hash'];
$object_hash = $_POST['object_hash'];
$langs = $this->getLangs();
foreach($langs as $v){
$upd = array();
foreach($fieldsArray as $field){
$upd[$field] = $_POST[$field][$v['id']];
}
$wh = array();
$wh['hash'] = $hash;
$wh['lang_id'] = $v['id'];
$this->db->update($this->table_gallery, $upd, $wh);
}
echo $this->listPicture($object_hash);
}
function movePic(){
if (empty($_GET['hash'])){return false;}
if (empty($_GET['d'])){return false;}
if (empty($_GET['object_hash'])){return false;}
$this->setAjax();
if (!empty($_GET['type'])){
$this->type = $_GET['type'];
}
$this->moveItem($this->table_gallery,'hash',$_GET['hash'],$_GET['d'], "`object_hash`='".$_GET['object_hash']."'");
echo $this->listPicture($_GET['object_hash']);
}
function delPic(){
$this->setAjax();
if (empty($_GET['hash'])){return false;}
if (empty($_GET['object_hash'])){return false;}
$this->delPicture($_GET['hash']);
if (!empty($_GET['type'])){
$this->type = $_GET['type'];
}
echo $this->listPicture($_GET['object_hash']);
exit;
}
/*
* Метод за добавяне на нови езици
*/
public function addLang($newLangId, $primaryLang){
$result = $this->generalAddLang($this->table_gallery, $newLangId, $primaryLang);
return $result;
}
/*
* Метод за добавяне на нови езици
*/
public function delLang($langId){
$result = $this->generalDelLang($this->table_gallery, $langId);
return $result;
}
}
?>