[xoops-cvslog 3154] CVS update: xoops2jp/html/modules/base/forms

Zurück zum Archiv-Index

Minahito minah****@users*****
2006年 5月 25日 (木) 18:31:49 JST


Index: xoops2jp/html/modules/base/forms/ImageUploadForm.class.php
diff -u /dev/null xoops2jp/html/modules/base/forms/ImageUploadForm.class.php:1.1.2.1
--- /dev/null	Thu May 25 18:31:49 2006
+++ xoops2jp/html/modules/base/forms/ImageUploadForm.class.php	Thu May 25 18:31:49 2006
@@ -0,0 +1,158 @@
+<?php
+
+if (!defined('XOOPS_ROOT_PATH')) exit();
+
+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/admin/forms/ImageAdminEditForm.class.php";
+
+class Legacy_ImageUploadForm extends XCube_ActionForm
+{
+	var $mOldFileName = null;
+	var $_mIsNew = null;
+	var $mFormFile = null;
+
+	function getTokenName()
+	{
+		return "module.base.ImageUploadForm.TOKEN" . $this->get('imgcat_id');
+	}
+
+	function prepare()
+	{
+		//
+		// Set form properties
+		//
+		$this->mFormProperties['image_name'] =& new XCube_ImageFileProperty('image_name');
+		$this->mFormProperties['image_nicename'] =& new XCube_StringProperty('image_nicename');
+		$this->mFormProperties['imgcat_id'] =& new XCube_IntProperty('imgcat_id');
+	
+		//
+		// Set field properties
+		//
+		$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['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');
+	}
+	
+	/**
+	 * Check the permission of uploading.
+	 */	
+	function validateImgcat_id()
+	{
+		$imgcat_id = $this->get('imgcat_id');
+		if ($imgcat_id != null) {
+			$root =& XCube_Root::getSingleton();
+			$xoopsUser =& $root->mController->getXoopsUser();
+			
+			$groups = array();
+			if (is_object($xoopsUser)) {
+				$groups =& $xoopsUser->getGroups();
+			}
+			else {
+				$groups = array(XOOPS_GROUP_ANONYMOUS);
+			}
+			
+			$handler =& xoops_getmodulehandler('imagecategory', 'base');
+			$imgcat =& $handler->get($imgcat_id);
+			if (is_object($imgcat) && !$imgcat->hasUploadPerm($groups)) {
+				$this->addErrorMessage(_MD_BASE_ERROR_PERMISSION);
+			}
+		}
+	}
+
+	function validateImage_name()
+	{
+		$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)
+	{
+		$this->set('image_nicename', $obj->get('image_nicename'));
+		$this->set('imgcat_id', $obj->get('imgcat_id'));
+		
+		$this->_mIsNew = $obj->isNew();
+		$this->mOldFileName = $obj->get('image_name');
+	}
+
+	function update(&$obj)
+	{
+		$obj->set('image_nicename', $this->get('image_nicename'));
+		$obj->set('image_display', true);
+		$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));
+			}
+		}
+	}
+}
+
+?>
Index: xoops2jp/html/modules/base/forms/ImageFilterForm.class.php
diff -u /dev/null xoops2jp/html/modules/base/forms/ImageFilterForm.class.php:1.1.2.1
--- /dev/null	Thu May 25 18:31:49 2006
+++ xoops2jp/html/modules/base/forms/ImageFilterForm.class.php	Thu May 25 18:31:49 2006
@@ -0,0 +1,61 @@
+<?php
+
+if (!defined('XOOPS_ROOT_PATH')) exit();
+
+require_once XOOPS_MODULE_PATH . "/base/class/AbstractFilterForm.class.php";
+
+define('IMAGE_SORT_KEY_IMAGE_ID', 1);
+define('IMAGE_SORT_KEY_IMAGE_NAME', 2);
+define('IMAGE_SORT_KEY_IMAGE_NICENAME', 3);
+define('IMAGE_SORT_KEY_IMAGE_MIMETYPE', 4);
+define('IMAGE_SORT_KEY_IMAGE_CREATED', 5);
+define('IMAGE_SORT_KEY_IMAGE_DISPLAY', 6);
+define('IMAGE_SORT_KEY_IMAGE_WEIGHT', 7);
+define('IMAGE_SORT_KEY_IMGCAT_ID', 8);
+define('IMAGE_SORT_KEY_MAXVALUE', 8);
+
+define('IMAGE_SORT_KEY_DEFAULT', IMAGE_SORT_KEY_IMAGE_WEIGHT);
+
+class Legacy_ImageFilterForm extends Legacy_AbstractFilterForm
+{
+	var $mSort = 0;
+	var $_mSortKeys = array(
+		IMAGE_SORT_KEY_IMAGE_ID => 'image_id',
+		IMAGE_SORT_KEY_IMAGE_NAME => 'image_name',
+		IMAGE_SORT_KEY_IMAGE_NICENAME => 'image_nicename',
+		IMAGE_SORT_KEY_IMAGE_MIMETYPE => 'image_mimetype',
+		IMAGE_SORT_KEY_IMAGE_CREATED => 'image_created',
+		IMAGE_SORT_KEY_IMAGE_DISPLAY => 'image_display',
+		IMAGE_SORT_KEY_IMAGE_WEIGHT => 'image_weight',
+		IMAGE_SORT_KEY_IMGCAT_ID => 'imgcat_id'
+	);
+	var $_mCriteria = null;
+
+	function fetch()
+	{
+		$this->mSort = isset($_REQUEST['sort']) ? intval($_REQUEST['sort']) : IMAGE_SORT_KEY_DEFAULT;
+	
+		if ($this->mSort > IMAGE_SORT_KEY_MAXVALUE) {
+			$this->mSort = IMAGE_SORT_KEY_DEFAULT;
+		}
+		
+		$this->_mNavi->addExtra('target', xoops_getrequest('target'));
+	
+		if (isset($_REQUEST['imgcat_id'])) {
+			$this->_mNavi->addExtra('imgcat_id', xoops_getrequest('imgcat_id'));
+			$this->_mCriteria->add(new Criteria('imgcat_id', array(XOBJ_DTYPE_INT, xoops_getrequest('imgcat_id'))));
+		}
+		else {
+			$this->_mCriteria->add(new Criteria('imgcat_id', 0));
+		}
+		
+		$this->_mCriteria->add(new Criteria('image_display', 1));
+
+		$this->_mCriteria->addSort($this->getSort(), $this->getOrder());
+		if (abs($this->mSort) != IMAGE_SORT_KEY_IMAGE_WEIGHT) {
+			$this->_mCriteria->addSort(IMAGE_SORT_KEY_IMAGE_WEIGHT, $this->getOrder());
+		}
+	}
+}
+
+?>


xoops-cvslog メーリングリストの案内
Zurück zum Archiv-Index