/** * Сохранение файла изображения * @param string путь для сохранения * @param integer ID объекта * @param array данные о загрузке */ function saveImageFileCustom($sPath, $nID, $aUploadData) { $sFilename = func::generator(12) . '.' . $aUploadData['ext']; $oThumb = new CThumbnail($aUploadData['tmp_name'], false); $aSave = array(); $aSave[] = array('filename' => $sPath . $nID . 's' . $sFilename, 'width' => 74, 'height' => 74, 'autofit' => true, 'crop_h' => 'center', 'crop_v' => 'center', 'quality' => 90); $aSave[] = array('filename' => $sPath . $nID . 't' . $sFilename, 'width' => 102, 'height' => 102, 'autofit' => true, 'crop_h' => 'center', 'crop_v' => 'center', 'quality' => 90); $aSave[] = array('filename' => $sPath . $nID . $sFilename, 'width' => 600, 'height' => 480, 'autofit' => true, 'crop_h' => 'center', 'crop_v' => 'center', 'quality' => 90); if (!$oThumb->save($aSave)) { return false; } return $sFilename; }
function edit() { if (!$this->haveAccessTo('edit')) { return $this->showAccessDenied(); } $nRecordID = Func::POSTGET('rec', false, true); if (!$nRecordID) { $this->adminRedirect(Errors::IMPOSSIBLE); } $aData = $this->db->one_array('SELECT * FROM ' . TABLE_BANNERS . ' WHERE id=' . $nRecordID); if (empty($aData)) { $this->adminRedirect(Errors::IMPOSSIBLE); } $sPrevPosition = $aData['position']; if (bff::$isPost) { $this->input->postm(array('position' => TYPE_STR, 'cat' => TYPE_ARRAY_UINT, 'enabled' => TYPE_BOOL, 'banner_type' => TYPE_UINT, 'show_limit' => TYPE_UINT, 'resize_img' => TYPE_BOOL, 'code' => TYPE_STR, 'show_start' => TYPE_STR, 'show_finish' => TYPE_STR, 'clickurl' => TYPE_STR, 'showurl' => TYPE_STR, 'showurl_recursive' => TYPE_BOOL, 'flash_width' => TYPE_UINT, 'flash_height' => TYPE_UINT, 'flash_key' => TYPE_STR, 'title' => TYPE_STR, 'alt' => TYPE_STR, 'description' => TYPE_STR), $aData); if (!$aData['position']) { $this->errors->set('position'); } /* если при редактировании позиция меняется, проверить новую позицию на возможность ротации */ if ($aData['position'] != $sPrevPosition) { if (!$this->checkRotation($aData['position'])) { $this->errors->set('no_rotation'); } } $aData['clickurl'] = preg_replace("[^http://|www\\.|https://|ftp://]", '', $aData['clickurl']); $aData['showurl'] = preg_replace("[^http://|www\\.|https://|ftp://]", '', $aData['showurl']); $sFlashAddFields = ''; if ($aData['banner_type'] == BANNERS_TYPE_FLASH) { if (!$aData['flash_width'] || !$aData['flash_height']) { $this->errors->set('no_flash_size'); } $sFlashAddFields = 'flash = ' . $this->db->str2sql(serialize(array('width' => $aData['flash_width'], 'height' => $aData['flash_height'], 'key' => $aData['flash_key']))) . ','; } Func::setSESSION('banner_position', $aData['position']); if ($this->errors->no()) { $this->db->execute('UPDATE ' . TABLE_BANNERS . ' SET clickurl = :clickurl, position = :position, cat = :cat, show_start = :show_start, show_finish = :show_finish, showurl = :showurl, showurl_recursive =' . $aData['showurl_recursive'] . ', enabled =' . $aData['enabled'] . ', banner_type =' . $aData['banner_type'] . ',' . $sFlashAddFields . ' show_limit = ' . $aData['show_limit'] . ', title = :title, alt = :alt, description = :description WHERE id=' . $nRecordID, array(':clickurl' => $aData['clickurl'], ':position' => $aData['position'], ':cat' => join(',', $aData['cat']), ':show_start' => date('Y-m-d H:i', strtotime($aData['show_start'])), ':show_finish' => date('Y-m-d H:i', strtotime($aData['show_finish'])), ':showurl' => $aData['showurl'], ':title' => $aData['title'], ':alt' => $aData['alt'], ':description' => $aData['description'])); do { if ($aData['banner_type'] == BANNERS_TYPE_IMG) { $oUpload = new Upload('bnrimg', false); if (isset($_FILES['bnrimg']) && $_FILES['bnrimg']['error'] == 4) { break; } $oUpload->checkIsIMG(); if ($oUpload->isSuccessfull()) { $this->delImages($nRecordID, array('banner' => $aData['banner'])); $aImgInfo = getimagesize($_FILES['bnrimg']['tmp_name']); $sExtension = image_type_to_extension($aImgInfo[2], false); $sFilename = func::generateRandomName(5, true, true) . '.' . $sExtension; $aPositionInfo = $this->positions[$aData['position']]; if (!isset($aPositionInfo['height']) || !$aPositionInfo['height']) { $aPositionInfo['height'] = false; } if (!$aData['resize_img']) { $aWorkingImg = array('filename' => BANNERS_PATH . $nRecordID . '_work_' . $sFilename, 'width' => $aImgInfo[0], 'height' => $aImgInfo[1], 'autofit' => true, 'crop_v' => 'center', 'crop_h' => 'center'); } else { $aWorkingImg = array('filename' => BANNERS_PATH . $nRecordID . '_work_' . $sFilename, 'width' => $aPositionInfo['width'], 'height' => $aPositionInfo['height'], 'autofit' => true, 'crop_v' => 'center', 'crop_h' => 'center'); } $aParams = array(array('filename' => BANNERS_PATH . $nRecordID . '_th_' . $sFilename, 'width' => 100, 'height' => false, 'autofit' => true, 'crop_v' => 'center', 'crop_h' => 'center'), $aWorkingImg ? $aWorkingImg : ''); $oThumb = new CThumbnail($_FILES['bnrimg']['tmp_name'], false); $oThumb->save($aParams); $this->db->execute('UPDATE ' . TABLE_BANNERS . ' SET banner=' . $this->db->str2sql($sFilename) . ' WHERE id=' . $nRecordID); } } elseif ($aData['banner_type'] == BANNERS_TYPE_FLASH) { $fUpload = new Upload('flash', false); if (!empty($fUpload->filename)) { $this->delImages($nRecordID, array('banner' => $aData['banner'])); $fUpload->save(BANNERS_PATH, $nRecordID . '_src_'); $this->db->execute('UPDATE ' . TABLE_BANNERS . ' SET banner=' . $this->db->str2sql($fUpload->getFilename()) . ' WHERE id=' . $nRecordID); } } else { $this->db->execute('UPDATE ' . TABLE_BANNERS . ' SET banner=' . $this->db->str2sql($aData['code']) . ' WHERE id=' . $nRecordID); } } while (false); $this->adminRedirect(Errors::SUCCESSFULL); } $aData['banner'] = $this->db->one_data('SELECT banner FROM ' . TABLE_BANNERS . ' WHERE id=' . $nRecordID); } $aData['cat'] = explode(',', $aData['cat']); if (empty($aData['position'])) { $aData['position'] = Func::SESSION('banner_position'); } $aData['width'] = $this->positions[$aData['position']]['width']; $aData['height'] = $this->positions[$aData['position']]['height']; //prepare link $aData['link'] = $this->prepareClickURL($aData['id']); //prepare thumbnail path $aData['img_small'] = ''; $aData['img_big'] = ''; $sFilename = $aData['id'] . '_th_' . $aData['banner']; if (file_exists(BANNERS_PATH . $sFilename)) { $aData['img_small'] = BANNERS_URL . '/' . $sFilename; } $sFilename = $aData['id'] . '_work_' . $aData['banner']; if (file_exists(BANNERS_PATH . $sFilename)) { $aData['img_big'] = BANNERS_URL . '/' . $sFilename; } $aData['flash'] = unserialize($aData['flash']); $aData['resize_img'] = 1; $aData['date_min'] = date('Y,n,d', mktime(0, 0, 0, date('n') - 1, date('d'), date('y'))); $this->includeJS(array('datepicker')); $this->tplAssign('aCategories', $this->getBBSCategories($aData['cat'], false)); $this->tplAssign('aPosOptions', $this->positions); $this->tplAssign('aData', $aData); return $this->tplFetch('admin.form.tpl'); }