function upload($mesid = 0, $key = 'kattachment', $ajax = true, &$message = null)
 {
     require_once KUNENA_PATH_LIB . '/kunena.upload.class.php';
     $path = KUNENA_PATH_UPLOADED . '/' . $this->_my->id;
     $upload = new CKunenaUpload();
     $upload->uploadFile($path, $key, '', $ajax);
     $fileinfo = $upload->getFileInfo();
     $folder = KUNENA_RELPATH_UPLOADED . '/' . $this->_my->id;
     if ($fileinfo['ready'] === true) {
         if (JDEBUG == 1 && defined('JFIREPHP')) {
             FB::log('Kunena save attachment: ' . $fileinfo['name']);
         }
         $this->_db->setQuery("INSERT INTO #__kunena_attachments (mesid, userid, hash, size, folder, filetype, filename) values (" . (int) $mesid . "," . (int) $this->_my->id . "," . $this->_db->quote($fileinfo['hash']) . "," . $this->_db->quote($fileinfo['size']) . "," . $this->_db->quote($folder) . "," . $this->_db->quote(isset($fileinfo['mime']) ? $fileinfo['mime'] : '') . "," . $this->_db->quote($fileinfo['name']) . ")");
         $this->_db->query();
         $fileinfo['id'] = $this->_db->insertId();
         if (KunenaError::checkDatabaseError() || !$fileinfo['id']) {
             $upload->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_ATTACHMENT_DATABASE_STORE'));
             $fileinfo = $upload->getFileInfo();
         }
     }
     if (!empty($fileinfo['mime']) && $this->isImage($fileinfo['mime'])) {
         CKunenaImageHelper::version($path . '/' . $fileinfo['name'], $path . '/thumb', $fileinfo['name'], $this->_config->thumbwidth, $this->_config->thumbheight, intval($this->_config->imagequality));
     }
     // Fix attachments names inside message
     $found = preg_match('/\\D*(\\d)+/', $key, $matches);
     if (!empty($message) && $found) {
         $intkey = $matches[1];
         if (empty($fileinfo['error'])) {
             $message = preg_replace('/\\[attachment\\:' . $intkey . '\\].*?\\[\\/attachment\\]/u', '[attachment=' . $fileinfo['id'] . ']' . $fileinfo['name'] . '[/attachment]', $message);
         } else {
             $message = preg_replace('/\\[attachment\\:' . $intkey . '\\](.*?)\\[\\/attachment\\]/u', '[attachment]\\1[/attachment]', $message);
         }
     }
     if (JDEBUG == 1 && defined('JFIREPHP')) {
         FB::log('Kunena save attachment ready');
     }
     return $fileinfo;
 }
Пример #2
0
	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;
		}
	}
Пример #3
0
 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;
 }
Пример #4
0
 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;
                 }
             }
         }
     }
 }
Пример #5
0
 function upload($key = 'kattachment')
 {
     require_once KPATH_SITE . '/lib/kunena.upload.class.php';
     $path = JPATH_ROOT . '/media/kunena/attachments/' . $this->userid;
     $upload = new CKunenaUpload();
     $upload->uploadFile($path, $key, '', false);
     $fileinfo = $upload->getFileInfo();
     if ($fileinfo['status'] && $fileinfo['ready'] === true) {
         $this->hash = $fileinfo['hash'];
         $this->size = $fileinfo['size'];
         $this->folder = '/media/kunena/attachments/' . $this->userid;
         $this->filetype = $fileinfo['mime'];
         $this->filename = $fileinfo['name'];
         return true;
     }
     $this->setError(JText::sprintf('COM_KUNENA_UPLOAD_FAILED', $fileinfo['name']) . ': ' . $fileinfo['error']);
     return false;
 }