Minahito
minah****@users*****
2006年 1月 19日 (木) 21:10:59 JST
Index: xoops2jp/html/modules/user/actions/AvatarUploadAction.class.php diff -u xoops2jp/html/modules/user/actions/AvatarUploadAction.class.php:1.1.2.1 xoops2jp/html/modules/user/actions/AvatarUploadAction.class.php:1.1.2.2 --- xoops2jp/html/modules/user/actions/AvatarUploadAction.class.php:1.1.2.1 Wed Jan 18 22:09:25 2006 +++ xoops2jp/html/modules/user/actions/AvatarUploadAction.class.php Thu Jan 19 21:10:59 2006 @@ -3,8 +3,27 @@ require_once XOOPS_MODULE_PATH . "/user/class/AbstractEditAction.class.php"; require_once XOOPS_MODULE_PATH . "/user/forms/AvatarUploadForm.class.php"; -class User_EditUserAction extends User_AbstractEditAction +class User_AvatarUploadAction extends User_AbstractEditAction { + var $mAvatarWidth = 0; + var $mAvatarHeight = 0; + var $mAvatarMaxfilesize = 0; + + var $_mMinPost = 0; + var $_mAllowUpload = false; + + function prepare(&$controller, &$xoopsUser, &$moduleConfig) + { + $this->mAvatarWidth = $moduleConfig['avatar_width']; + $this->mAvatarHeight = $moduleConfig['avatar_height']; + $this->mAvatarMaxfilesize = $moduleConfig['avatar_maxsize']; + + $this->_mMinPost = $moduleConfig['avatar_minposts']; + $this->_mAllowUpload = $moduleConfig['avatar_allow_upload']; + + parent::prepare($controller, $xoopsUser, $moduleConfig); + } + function _getId() { return isset($_REQUEST['uid']) ? intval($_REQUEST['uid']) : 0; @@ -19,7 +38,7 @@ function _setupActionForm() { $this->mActionForm=new AvatarUploadForm(); - $this->mActionForm->prepare(); + $this->mActionForm->prepare($this->mAvatarWidth, $this->mAvatarHeight, $this->mAvatarMaxfilesize); } function isEnableCreate() @@ -34,18 +53,52 @@ function isPerm(&$controller, &$xoopsUser) { - if ($this->mObject != null) { - return ($this->mObject->get('uid') == $xoopsUser->get('uid') || $xoopsUser->isAdmin()); + if (!is_object($this->mObject) || $this->_mAllowUpload == 0) { + return false; + } + + if ($this->mObject->get('uid') == $xoopsUser->get('uid')) { + return ($this->mObject->get('posts') >= $this->_mMinPost); + } + elseif ($this->mObject->isAdmin()) { + return true; } return false; } + function _doExecute() + { + if (!$this->mActionForm->mFormFile->saveAs(XOOPS_UPLOAD_PATH)) { + return false; + } + + if ($this->mActionForm->mOldAvatarFilename != null && $this->mActionForm->mOldAvatarFilename != "blank.gif") { + @unlink(XOOPS_UPLOAD_PATH . "/" . $this->mActionForm->mOldAvatarFilename); + } + + return parent::_doExecute(); + } + function executeViewInput(&$controller,&$xoopsUser,&$renderSystem) { - $renderSystem->setTemplateName("user_avatarupload.html"); + $renderSystem->setTemplateName("user_avatar_upload.html"); $renderSystem->setAttribute("actionForm",$this->mActionForm); $renderSystem->setAttribute("thisUser",$this->mObject); + + $renderSystem->setAttribute("avatarWidth",$this->mAvatarWidth); + $renderSystem->setAttribute("avatarHeight",$this->mAvatarHeight); + $renderSystem->setAttribute("avatarMaxfilesize",$this->mAvatarMaxfilesize); + } + + function executeViewSuccess(&$controller,&$xoopsUser,&$renderSystem) + { + $controller->executeForward("./index.php?action=UserInfo&uid=" . $this->mActionForm->get('uid')); + } + + function executeViewError(&$controller,&$xoopsUser,&$renderSystem) + { + redirect_header("./index.php?action=UserInfo&uid=" . $this->mActionForm->get('uid'), 1, _MD_ERROR_DBUPDATE_FAILED); } }