Esempio n. 1
0
 protected function _getURL($user, $sizex, $sizey)
 {
     $user = KunenaFactory::getUser($user);
     $avatar = $user->avatar;
     $config = KunenaFactory::getConfig();
     $path = KPATH_MEDIA . "/avatars";
     if (!is_file("{$path}/{$avatar}")) {
         // If avatar does not exist use default image
         if ($sizex <= 90) {
             $avatar = 's_nophoto.jpg';
         } else {
             $avatar = 'nophoto.jpg';
         }
     }
     $dir = dirname($avatar);
     $file = basename($avatar);
     if ($sizex == $sizey) {
         $resized = "resized/size{$sizex}/{$dir}";
     } else {
         $resized = "resized/size{$sizex}x{$sizey}/{$dir}";
     }
     if (!is_file("{$path}/{$resized}/{$file}")) {
         require_once KPATH_SITE . '/lib/kunena.image.class.php';
         CKunenaImageHelper::version("{$path}/{$avatar}", "{$path}/{$resized}", $file, $sizex, $sizey, intval($config->avatarquality));
     }
     return KURL_MEDIA . "avatars/{$resized}/{$file}";
 }
 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;
 }