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()
 {
     $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;
                 }
             }
         }
     }
 }