Minahito
minah****@users*****
2006年 5月 25日 (木) 18:30:34 JST
Index: xoops2jp/html/modules/base/admin/forms/ImageAdminEditForm.class.php diff -u xoops2jp/html/modules/base/admin/forms/ImageAdminEditForm.class.php:1.1.2.4 xoops2jp/html/modules/base/admin/forms/ImageAdminEditForm.class.php:1.1.2.5 --- xoops2jp/html/modules/base/admin/forms/ImageAdminEditForm.class.php:1.1.2.4 Mon May 15 17:34:09 2006 +++ xoops2jp/html/modules/base/admin/forms/ImageAdminEditForm.class.php Thu May 25 18:30:34 2006 @@ -4,13 +4,10 @@ require_once XOOPS_ROOT_PATH . "/class/XCube_ActionForm.class.php"; require_once XOOPS_MODULE_PATH . "/base/class/Legacy_Validator.class.php"; +require_once XOOPS_MODULE_PATH . "/base/forms/ImageUploadForm.class.php"; -class Legacy_ImageAdminEditForm extends XCube_ActionForm +class Legacy_ImageAdminEditForm extends Legacy_ImageUploadForm { - var $mOldFileName = null; - var $_mIsNew = null; - var $mFormFile = null; - function getTokenName() { return "module.base.ImageAdminEditForm.TOKEN" . $this->get('image_id'); @@ -18,15 +15,14 @@ function prepare() { + parent::prepare(); + // // Set form properties // $this->mFormProperties['image_id'] =& new XCube_IntProperty('image_id'); - $this->mFormProperties['image_name'] =& new XCube_ImageFileProperty('image_name'); - $this->mFormProperties['image_nicename'] =& new XCube_StringProperty('image_nicename'); $this->mFormProperties['image_display'] =& new XCube_BoolProperty('image_display'); $this->mFormProperties['image_weight'] =& new XCube_IntProperty('image_weight'); - $this->mFormProperties['imgcat_id'] =& new XCube_IntProperty('imgcat_id'); // // Set field properties @@ -35,112 +31,29 @@ $this->mFieldProperties['image_id']->setDependsByArray(array('required')); $this->mFieldProperties['image_id']->addMessage('required', _AD_BASE_ERROR_REQUIRED, _AD_BASE_LANG_IMAGE_ID); - $this->mFieldProperties['image_name'] =& new XCube_FieldProperty($this); - $this->mFieldProperties['image_name']->setDependsByArray(array('extension')); - $this->mFieldProperties['image_name']->addMessage('required', _AD_BASE_ERROR_REQUIRED, _AD_BASE_LANG_IMAGE_NAME); - $this->mFieldProperties['image_name']->addMessage('maxlength', _AD_BASE_ERROR_EXTENSION, _AD_BASE_LANG_IMAGE_NAME); - $this->mFieldProperties['image_name']->addVar('extension', 'jpg,gif,png'); - - $this->mFieldProperties['image_nicename'] =& new XCube_FieldProperty($this); - $this->mFieldProperties['image_nicename']->setDependsByArray(array('required')); - $this->mFieldProperties['image_nicename']->addMessage('required', _AD_BASE_ERROR_REQUIRED, _AD_BASE_LANG_IMAGE_NICENAME); - $this->mFieldProperties['image_weight'] =& new XCube_FieldProperty($this); $this->mFieldProperties['image_weight']->setDependsByArray(array('required')); $this->mFieldProperties['image_weight']->addMessage('required', _AD_BASE_ERROR_REQUIRED, _AD_BASE_LANG_IMAGE_WEIGHT); - - $this->mFieldProperties['imgcat_id'] =& new XCube_FieldProperty($this); - $this->mFieldProperties['imgcat_id']->setDependsByArray(array('required','objectExist')); - $this->mFieldProperties['imgcat_id']->addMessage('required', _AD_BASE_ERROR_REQUIRED, _AD_BASE_LANG_IMGCAT_ID); - $this->mFieldProperties['imgcat_id']->addMessage('objectExist', _AD_BASE_ERROR_OBJECTEXIST, _AD_BASE_LANG_IMGCAT_ID); - $this->mFieldProperties['imgcat_id']->addVar('handler', 'imagecategory'); - $this->mFieldProperties['imgcat_id']->addVar('module', 'base'); } - function validateImage_name() + function validateImgcat_id() { - $formFile = $this->get('image_name'); - - if ($formFile == null && $this->_mIsNew ) { - $this->addErrorMessage(_AD_BASE_ERROR_REQUIRED); - } } - function validate() - { - parent::validate(); - - $handler =& xoops_getmodulehandler('imagecategory', 'base'); - $category =& $handler->get($this->get('imgcat_id')); - - $formFile = $this->get('image_name'); - - if ($formFile != null && is_object($category)) { - // - // Imagefile width & height check. - // - if ($formFile->getWidth() > $category->get('imgcat_maxwidth') || $formFile->getHeight() > $category->get('imgcat_maxheight')) { - $this->addErrorMessage(XCube_Utils::formatMessage(_AD_BASE_ERROR_IMG_SIZE, $category->get('imgcat_maxwidth'), $category->get('imgcat_maxheight'))); - } - - // - // Check file size - // - if ($formFile->getFilesize() > $category->get('imgcat_maxsize')) { - $this->addErrorMessage(XCube_Utils::formatMessage(_AD_BASE_ERROR_IMG_FILESIZE, $category->get('imgcat_maxsize'))); - } - } - } - function load(&$obj) { + parent::load($obj); $this->set('image_id', $obj->get('image_id')); - $this->set('image_nicename', $obj->get('image_nicename')); $this->set('image_display', $obj->get('image_display')); $this->set('image_weight', $obj->get('image_weight')); - $this->set('imgcat_id', $obj->get('imgcat_id')); - - $this->_mIsNew = $obj->isNew(); - $this->mOldFileName = $obj->get('image_name'); } function update(&$obj) { + parent::update($obj); $obj->set('image_id', $this->get('image_id')); - $obj->set('image_nicename', $this->get('image_nicename')); $obj->set('image_display', $this->get('image_display')); $obj->set('image_weight', $this->get('image_weight')); - $obj->set('imgcat_id', $this->get('imgcat_id')); - - $handler =& xoops_getmodulehandler('imagecategory', 'base'); - $category =& $handler->get($this->get('imgcat_id')); - - $this->mFormFile = $this->get('image_name'); - - if ($this->mFormFile != null) { - $this->mFormFile->setRandomToBodyName('img'); - - $filename = $this->mFormFile->getBodyName(); - $this->mFormFile->setBodyName(substr($filename, 0, 24)); - - $obj->set('image_name', $this->mFormFile->getFileName()); - $obj->set('image_mimetype', $this->mFormFile->getContentType()); - - // - // To store db - // - if ($category->get('imgcat_storetype') == 'db') { - $obj->loadImageBody(); - if (!is_object($obj->mImageBody)) { - $obj->mImageBody =& $obj->createImageBody(); - } - - // - // Access to private member property. - // - $obj->mImageBody->set('image_body', file_get_contents($this->mFormFile->_mTmpFileName)); - } - } } }