protected function saveAvatar() { $action = JRequest::getString('avatar', 'keep'); $current_avatar = $this->me->avatar; require_once KPATH_SITE . '/lib/kunena.upload.class.php'; $upload = new CKunenaUpload(); $upload->setAllowedExtensions('gif, jpeg, jpg, png'); if ($upload->uploaded('avatarfile')) { $filename = 'avatar' . $this->me->userid; if (preg_match('|^users/|', $this->me->avatar)) { // Delete old uploaded avatars: if (JFolder::exists(KPATH_MEDIA . '/avatars/resized')) { $deletelist = JFolder::folders(KPATH_MEDIA . '/avatars/resized', '.', false, true); foreach ($deletelist as $delete) { if (is_file($delete . '/' . $this->me->avatar)) { JFile::delete($delete . '/' . $this->me->avatar); } } } if (JFile::exists(KPATH_MEDIA . '/avatars/' . $this->me->avatar)) { JFile::delete(KPATH_MEDIA . '/avatars/' . $this->me->avatar); } } $upload->setImageResize(intval($this->config->avatarsize) * 1024, 200, 200, $this->config->avatarquality); $upload->uploadFile(KPATH_MEDIA . '/avatars/users', 'avatarfile', $filename, false); $fileinfo = $upload->getFileInfo(); if ($fileinfo['ready'] === true) { $this->me->avatar = 'users/' . $fileinfo['name']; } if (!$fileinfo['status']) { $this->me->avatar = $current_avatar; if (!$fileinfo['not_valid_img_ext']) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_UPLOAD_FAILED', htmlspecialchars($fileinfo['name'], ENT_COMPAT, 'UTF-8')) . ': ' . JText::sprintf('COM_KUNENA_AVATAR_UPLOAD_NOT_VALID_EXTENSIONS', 'gif, jpeg, jpg, png'), 'error'); } else { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_UPLOAD_FAILED', htmlspecialchars($fileinfo['name'], ENT_COMPAT, 'UTF-8')) . ': ' . $fileinfo['error'], 'error'); } return false; } else { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_PROFILE_AVATAR_UPLOADED')); } } else { if ($action == 'delete') { //set default avatar $this->me->avatar = ''; } else { if (substr($action, 0, 8) == 'gallery/' && strpos($action, '..') === false) { $this->me->avatar = $action; } } } return true; }
protected function saveAvatar() { $app = JFactory::getApplication(); $action = JRequest::getString('avatar', 'keep'); require_once (KPATH_SITE.'/lib/kunena.upload.class.php'); $upload = new CKunenaUpload(); $upload->setAllowedExtensions('gif, jpeg, jpg, png'); $db = JFactory::getDBO(); if ( $upload->uploaded('avatarfile') ) { $filename = 'avatar'.$this->profile->userid; if (preg_match('|^users/|' , $this->profile->avatar)) { // Delete old uploaded avatars: if ( JFolder::exists( KPATH_MEDIA.'/avatars/resized' ) ) { $deletelist = JFolder::folders(KPATH_MEDIA.'/avatars/resized', '.', false, true); foreach ($deletelist as $delete) { if (is_file($delete.'/'.$this->profile->avatar)) JFile::delete($delete.'/'.$this->profile->avatar); } } if ( JFile::exists( KPATH_MEDIA.'/avatars/'.$this->profile->avatar ) ) { JFile::delete(KPATH_MEDIA.'/avatars/'.$this->profile->avatar); } } $upload->setImageResize(intval($this->config->avatarsize)*1024, 200, 200, $this->config->avatarquality); $upload->uploadFile(KPATH_MEDIA . '/avatars/users' , 'avatarfile', $filename, false); $fileinfo = $upload->getFileInfo(); if ($fileinfo['ready'] === true) { $this->me->avatar = 'users/'.$fileinfo['name']; } if (!$fileinfo['status']) $app->enqueueMessage ( JText::sprintf ( 'COM_KUNENA_UPLOAD_FAILED', $fileinfo['name']).': '.$fileinfo['error'], 'error' ); else $app->enqueueMessage ( JText::sprintf ( 'COM_KUNENA_PROFILE_AVATAR_UPLOADED' ) ); } else if ( $action == 'delete' ) { //set default avatar $this->me->avatar = ''; } else if ( substr($action, 0, 8) == 'gallery/' && strpos($action, '..') === false) { $this->me->avatar = $action; } }
protected function saveAvatar() { $action = JRequest::getString('avatar', 'keep'); require_once KUNENA_PATH_LIB . '/kunena.upload.class.php'; $upload = new CKunenaUpload(); $upload->setAllowedExtensions('gif, jpeg, jpg, png'); if ($upload->uploaded('avatarfile')) { $filename = 'avatar' . $this->profile->userid; if (preg_match('|^users/|', $this->profile->avatar)) { // Delete old uploaded avatars: if (JFolder::exists(KPATH_MEDIA . '/avatars/resized')) { $deletelist = JFolder::folders(KPATH_MEDIA . '/avatars/resized', '.', false, true); foreach ($deletelist as $delete) { if (is_file($delete . '/' . $this->profile->avatar)) { JFile::delete($delete . '/' . $this->profile->avatar); } } } if (JFile::exists(KPATH_MEDIA . '/avatars/' . $this->profile->avatar)) { JFile::delete(KPATH_MEDIA . '/avatars/' . $this->profile->avatar); } } $upload->setImageResize(intval($this->config->avatarsize) * 1024, 200, 200, $this->config->avatarquality); $upload->uploadFile(KPATH_MEDIA . '/avatars/users', 'avatarfile', $filename, false); $fileinfo = $upload->getFileInfo(); if ($fileinfo['ready'] === true) { if (JDEBUG == 1 && defined('JFIREPHP')) { FB::log('Kunena save avatar: ' . $fileinfo['name']); } $this->_db->setQuery("UPDATE #__kunena_users SET avatar={$this->_db->quote('users/' . $fileinfo['name'])} WHERE userid='{$this->profile->userid}'"); if (!$this->_db->query() || $this->_db->getErrorNum()) { $upload->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_AVATAR_DATABASE_STORE')); $fileinfo = $upload->getFileInfo(); } } if (!$fileinfo['status']) { $this->_app->enqueueMessage(JText::sprintf('COM_KUNENA_UPLOAD_FAILED', $fileinfo['name']) . ': ' . $fileinfo['error'], 'error'); } else { $this->_app->enqueueMessage(JText::sprintf('COM_KUNENA_PROFILE_AVATAR_UPLOADED')); } //while (@ob_end_clean()); //$this->_app->redirect ( CKunenaLink::GetMyProfileURL($this->profile->userid, '', false), JText::_('COM_KUNENA_AVATAR_UPLOADED_WITH_SUCCESS')); } else { if ($action == 'delete') { //set default avatar $this->_db->setQuery("UPDATE #__kunena_users SET avatar='' WHERE userid={$this->_db->Quote($this->profile->userid)}"); $this->_db->query(); if (KunenaError::checkDatabaseError()) { return; } } else { if (substr($action, 0, 8) == 'gallery/' && strpos($action, '..') === false) { $this->_db->setQuery("UPDATE #__kunena_users SET avatar={$this->_db->quote($action)} WHERE userid={$this->_db->Quote($this->profile->userid)}"); $this->_db->query(); if (KunenaError::checkDatabaseError()) { return; } } } } }