[xoops-cvslog 1880] CVS update: xoops2jp/html/modules/user/forms

Zurück zum Archiv-Index

Minahito minah****@users*****
2006年 1月 19日 (木) 21:13:45 JST


Index: xoops2jp/html/modules/user/forms/AvatarUploadForm.class.php
diff -u xoops2jp/html/modules/user/forms/AvatarUploadForm.class.php:1.1.2.2 xoops2jp/html/modules/user/forms/AvatarUploadForm.class.php:1.1.2.3
--- xoops2jp/html/modules/user/forms/AvatarUploadForm.class.php:1.1.2.2	Thu Jan 19 02:14:23 2006
+++ xoops2jp/html/modules/user/forms/AvatarUploadForm.class.php	Thu Jan 19 21:13:45 2006
@@ -7,13 +7,22 @@
  */
 class AvatarUploadForm extends XCube_ActionForm
 {
+	var $mOldAvatarFilename = null;
+	var $mFormFile = null;
+	
+	var $mWidth;
+	var $mHeight;
+	
 	function getTokenName()
 	{
 		return "module.user.AvatarUploadForm.TOKEN";
 	}
 
-	function prepare()
+	function prepare($width, $height, $maxfilesize)
 	{
+		$this->mWidth = $width;
+		$this->mHeight = $height;
+		
 		//
 		// Set form properties
 		//
@@ -24,22 +33,44 @@
 		// Set field properties
 		//
 		$this->mFieldProperties['uploadavatar'] =& new XCube_FieldProperty($this);
-		$this->mFieldProperties['uploadavatar']->setDependsByArray(array('extension'));
-		$this->mFieldProperties['uploadavatar']->addMessage('required', _MD_USER_ERROR_REQUIRED, _MD_USER_LANG_EMAIL);
+		$this->mFieldProperties['uploadavatar']->setDependsByArray(array('extension,maxfilesize'));
+		$this->mFieldProperties['uploadavatar']->addMessage('extension', _MD_USER_ERROR_AVATAR_EXTENSION);
 		$this->mFieldProperties['uploadavatar']->addVar('extension', "jpg,gif,png");
+		$this->mFieldProperties['uploadavatar']->addMessage('maxfilesize', _MD_USER_ERROR_AVATAR_MAXFILESIZE);
+		$this->mFieldProperties['uploadavatar']->addVar('maxfilesize', $maxfilesize);
 	}
 
+	function validateUploadavatar()
+	{
+		if ($this->get('uploadavatar') != null) {
+			$formfile = $this->get('uploadavatar');
+			if ($formfile->getWidth() > $this->mWidth) {
+				$this->addErrorMessage(_MD_USER_ERROR_AVATAR_SIZE);
+			}
+			elseif ($formfile->getHeight() > $this->mHeight) {
+				$this->addErrorMessage(_MD_USER_ERROR_AVATAR_SIZE);
+			}
+		}
+	}
+	
 	function load(&$obj)
 	{
 		$this->setVar('uid', $obj->get('uid'));
+		$this->mOldAvatarFilename = $obj->get('user_avatar');
 	}
 
 	function update(&$obj)
 	{
 		$obj->setVar('uid', $this->get('uid'));
 		
-		$fileform = $this->get('uploadavatar');
-		$obj->setVar('uploadavatar', $this->get($fileform->getFileName()));	//< TODO
+		$this->mFormFile = $this->get('uploadavatar');
+
+		$this->mFormFile->setRandomToBodyName('cavt');
+		
+		$filename = $this->mFormFile->getFileName();
+		$this->mFormFile->setBodyName(substr($filename, 0, 25));
+		
+		$obj->setVar('user_avatar', $this->mFormFile->getFileName());	//< TODO
 	}
 }
 


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