本文整理汇总了PHP中KunenaConfig类的典型用法代码示例。如果您正苦于以下问题:PHP KunenaConfig类的具体用法?PHP KunenaConfig怎么用?PHP KunenaConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KunenaConfig类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
$this->config = KunenaConfig::getInstance();
$this->limit = $this->config->userlist_rows;
$this->query->leftJoin('#__kunena_users AS ku ON ku.userid=a.id');
}
开发者ID:Ruud68,项目名称:Kunena-Forum,代码行数:10,代码来源:finder.php
示例2: before
/**
* Load user list.
*
* @throws KunenaExceptionAuthorise
*/
protected function before()
{
parent::before();
$config = KunenaConfig::getInstance();
if ($config->userlist_allowed && JFactory::getUser()->guest) {
throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), '401');
}
require_once KPATH_SITE . '/models/user.php';
$this->model = new KunenaModelUser(array(), $this->input);
$this->model->initialize($this->getOptions(), $this->getOptions()->get('embedded', false));
$this->state = $this->model->getState();
$this->me = KunenaUserHelper::getMyself();
$this->config = KunenaConfig::getInstance();
$start = $this->state->get('list.start');
$limit = $this->state->get('list.limit');
// Get list of super admins to exclude or not in filter by configuration.
$filter = JAccess::getUsersByGroup(8);
$finder = new KunenaUserFinder();
$finder->filterByConfiguration($filter)->filterByName($this->state->get('list.search'));
$this->total = $finder->count();
$this->pagination = new KunenaPagination($this->total, $start, $limit);
$alias = 'ku';
$aliasList = array('id', 'name', 'username', 'email', 'block', 'registerDate', 'lastvisitDate');
if (in_array($this->state->get('list.ordering'), $aliasList)) {
$alias = 'a';
}
$this->users = $finder->order($this->state->get('list.ordering'), $this->state->get('list.direction') == 'asc' ? 1 : -1, $alias)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find();
}
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:33,代码来源:display.php
示例3: before
/**
* Prepare announcement box display.
*
* @return bool
*/
protected function before()
{
parent::before();
$config = KunenaConfig::getInstance();
if (!$config->showannouncement)
{
return false;
}
$items = KunenaForumAnnouncementHelper::getAnnouncements();
$this->announcement = array_pop($items);
if (!$this->announcement || !$this->announcement->authorise('read'))
{
return false;
}
$view = $this->input->getWord('view', 'default');
$layout = $this->input->getWord('layout', 'default');
if ($view == 'topic' && $layout != 'default' || $view == 'user' || $view == 'search' || $view == 'announcement' && $layout == 'default') {
return false;
}
return true;
}
开发者ID:BillVGN,项目名称:PortalPRP,代码行数:33,代码来源:display.php
示例4: __construct
/**
* Method to instantiate the layout.
*
* @param string $name
* @param array $paths The paths queue.
*/
public function __construct($name, array $paths = null)
{
// Setup dependencies.
$this->_name = $name;
$this->includePaths = isset($paths) ? $paths : $this->loadPaths();
$this->debug = JDEBUG || KunenaConfig::getInstance()->get('debug');
}
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:13,代码来源:base.php
示例5: initialize
/**
* Initialize class.
*/
static public function initialize()
{
KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
if (KunenaConfig::getInstance()->get('cache_cat'))
{
// FIXME: Experimental caching.
/** @var JCache|JCacheControllerCallback $cache */
$cache = JFactory::getCache('com_kunena', 'callback');
$cache->setLifeTime(180);
self::$_instances = $cache->call(array('KunenaForumCategoryHelper', 'loadCategories'));
}
else
{
self::$_instances = self::loadCategories();
}
if (is_null(self::$_tree))
{
self::buildTree(self::$_instances);
}
self::$allowed = KunenaAccess::getInstance()->getAllowedCategories();
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
}
开发者ID:BillVGN,项目名称:PortalPRP,代码行数:28,代码来源:helper.php
示例6: before
/**
* Executed before display.
*/
protected function before()
{
$this->layout = $this->input->getCmd('layout', 'default');
$this->config = KunenaConfig::getInstance();
if ($this->primary) {
$this->document = JFactory::getDocument();
}
}
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:11,代码来源:display.php
示例7: before
/**
* Prepare AJAX display.
*
* @return void
*/
protected function before()
{
// Load language files.
KunenaFactory::loadLanguage('com_kunena.sys', 'admin');
KunenaFactory::loadLanguage('com_kunena.templates');
KunenaFactory::loadLanguage('com_kunena.models');
KunenaFactory::loadLanguage('com_kunena.views');
$this->me = KunenaUserHelper::getMyself();
$this->config = KunenaConfig::getInstance();
$this->document = JFactory::getDocument();
$this->template = KunenaFactory::getTemplate();
$this->template->initialize();
}
开发者ID:giabmf11,项目名称:Kunena-Forum,代码行数:18,代码来源:display.php
示例8: before
/**
* Prepare statistics box display.
*
* @return boolean
*/
protected function before()
{
parent::before();
$this->config = KunenaConfig::getInstance();
if (!$this->config->get('showstats') || !$this->config->statslink_allowed && !KunenaUserHelper::get()->exists()) {
throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), '404');
}
$statistics = KunenaForumStatistics::getInstance();
$statistics->loadGeneral();
$this->setProperties($statistics);
$this->latestMemberLink = KunenaFactory::getUser(intval($this->lastUserId))->getLink();
$this->statisticsUrl = KunenaFactory::getProfile()->getStatisticsURL();
return true;
}
开发者ID:Ruud68,项目名称:Kunena-Forum,代码行数:19,代码来源:display.php
示例9: before
/**
* Prepare general statistics display.
*
* @return void
*
* @throws KunenaExceptionAuthorise
*/
protected function before()
{
parent::before();
$this->config = KunenaConfig::getInstance();
if (!$this->config->get('showstats')) {
throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), '404');
}
if (!$this->config->statslink_allowed && JFactory::getUser()->guest) {
throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), '401');
}
$statistics = KunenaForumStatistics::getInstance();
$statistics->loadAll();
$this->setProperties($statistics);
$this->latestMemberLink = KunenaFactory::getUser((int) $this->lastUserId)->getLink();
$this->userlistUrl = KunenaFactory::getProfile()->getUserListUrl();
}
开发者ID:giabmf11,项目名称:Kunena-Forum,代码行数:23,代码来源:display.php
示例10: before
/**
* Prepare Who is online display.
*
* @return void
*
* @throws KunenaExceptionAuthorise
*/
protected function before()
{
parent::before();
$this->config = KunenaConfig::getInstance();
if (!$this->config->get('showwhoisonline')) {
throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), '404');
}
$me = KunenaUserHelper::getMyself();
$moderator = intval($me->isModerator()) + intval($me->isAdmin());
$users = KunenaUserHelper::getOnlineUsers();
KunenaUserHelper::loadUsers(array_keys($users));
$onlineusers = KunenaUserHelper::getOnlineCount();
$who = '<strong>' . $onlineusers['user'] . ' </strong>';
if ($onlineusers['user'] == 1) {
$who .= JText::_('COM_KUNENA_WHO_ONLINE_MEMBER') . ' ';
} else {
$who .= JText::_('COM_KUNENA_WHO_ONLINE_MEMBERS') . ' ';
}
$who .= JText::_('COM_KUNENA_WHO_AND');
$who .= '<strong> ' . $onlineusers['guest'] . ' </strong>';
if ($onlineusers['guest'] == 1) {
$who .= JText::_('COM_KUNENA_WHO_ONLINE_GUEST') . ' ';
} else {
$who .= JText::_('COM_KUNENA_WHO_ONLINE_GUESTS') . ' ';
}
$who .= JText::_('COM_KUNENA_WHO_ONLINE_NOW');
$this->membersOnline = $who;
$this->onlineList = array();
$this->hiddenList = array();
foreach ($users as $userid => $usertime) {
$user = KunenaUserHelper::get($userid);
if (!$user->showOnline) {
if ($moderator) {
$this->hiddenList[$user->getName()] = $user;
}
} else {
$this->onlineList[$user->getName()] = $user;
}
}
ksort($this->onlineList);
ksort($this->hiddenList);
$profile = KunenaFactory::getProfile();
$this->usersUrl = $profile->getUserListURL();
}
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:51,代码来源:display.php
示例11: checkFileSize
/**
* Check if filesize on file which on going to be uploaded doesn't exceed the limits set by Kunena configuration and Php configuration
*
* @param int $filesize The size of file in bytes
* @param boolean $avatar If the file is an avatar
*
* @return boolean
*/
protected function checkFileSize($filesize, $avatar)
{
if (!$avatar) {
if ($filesize > $this->getMaxSize()) {
return false;
}
} else {
if ($avatar && $filesize > intval(KunenaConfig::getInstance()->avatarsize) * 1024) {
return false;
}
}
return true;
}
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:21,代码来源:upload.php
示例12: getConfig
/**
* Get a Kunena configuration object
*
* Returns the global {@link KunenaConfig} object, only creating it if it doesn't already exist.
*
* @return KunenaConfig
*/
public static function getConfig() {
return KunenaConfig::getInstance();
}
开发者ID:kosmosby,项目名称:medicine-prof,代码行数:10,代码来源:factory.php
示例13: build
protected static function build()
{
KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
if (self::$search === false)
{
$user = KunenaUserHelper::getMyself();
$language = strtolower(JFactory::getDocument()->getLanguage());
self::$search = false;
if (KunenaConfig::getInstance()->get('cache_mid'))
{
// FIXME: Experimental caching.
$cache = self::getCache();
self::$search = unserialize($cache->get('search', "com_kunena.route.v1.{$language}.{$user->userid}"));
}
if (self::$search === false)
{
self::$search['home'] = array();
foreach (self::$menu as $item)
{
// Skip menu items that aren't pointing to Kunena or are using wrong language.
if (($item->component != 'com_kunena' && $item->type != 'alias')
|| ($item->language != '*' && strtolower($item->language) != $language))
{
continue;
}
// Follow links.
if ($item->type == 'alias')
{
if (empty($item->query['Itemid']) || empty(self::$menu[$item->query['Itemid']]))
{
continue;
}
$item = self::$menu[$item->query['Itemid']];
if ($item->component != 'com_kunena' || ($item->language != '*' && strtolower($item->language) != $language))
{
continue;
}
}
// Ignore legacy menu items without view in it.
if (!isset($item->query['view']))
{
continue;
}
// Save Kunena menu items so that we can make fast searches
$home = self::getHome($item);
self::$search[$item->query['view']][$home ? $home->id : 0][$item->id] = $item->id;
}
if (isset($cache))
{
$cache->store(serialize(self::$search), 'search', "com_kunena.route.v1.{$language}.{$user->userid}");
}
}
}
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
}
开发者ID:BillVGN,项目名称:PortalPRP,代码行数:63,代码来源:route.php
示例14: getAvailableFilename
/**
* Find filename which isn't already taken in the filesystem.
*
* @param string $folder Relative path from JPATH_ROOT.
* @param string $basename Filename without extension.
* @param string $extension File extension.
* @param bool $protected True to randomize the filename. If not given, uses Kunena configuration setting.
*
* @return string
*
* @since K4.0
*/
public static function getAvailableFilename($folder, $basename, $extension, $protected = null)
{
if (is_null($protected)) {
$protected = (bool) KunenaConfig::getInstance()->attachment_protection;
}
if ($protected) {
// Ignore proposed filename and return totally random and unique name without file extension.
do {
$name = md5(rand());
} while (file_exists(JPATH_ROOT . "/{$folder}/{$name}"));
return $name;
}
// Lets find out if we need to rename the filename.
$basename = preg_replace('/[[:space:]]/', '', KunenaFile::makeSafe($basename));
$extension = trim($extension, '.');
if (empty($basename)) {
$basename = 'file_' . substr(md5(rand()), 2, 7);
}
$newName = "{$basename}.{$extension}";
$date = date('Y-m-d');
// Rename file if there is already one with the same name
if (file_exists(JPATH_ROOT . "/{$folder}/{$newName}")) {
$newName = "{$basename}_{$date}.{$extension}";
for ($i = 2; file_exists(JPATH_ROOT . "/{$folder}/{$newName}"); $i++) {
$newName = "{$basename}_{$date}-{$i}.{$extension}";
}
}
return $newName;
}
开发者ID:giabmf11,项目名称:Kunena-Forum,代码行数:41,代码来源:helper.php
示例15: getList
/**
* Get a list of the menu items (taken from Joomla 2.5.1).
* This only method need to be used only in frontend part
*
* @param JRegistry $params The module options.
*
* @return array
* @see modules/mod_menu/helper.php
*/
public static function getList(&$params)
{
$app = JFactory::getApplication();
$menu = $app->getMenu();
// If no active menu, use default
$active = $menu->getActive() ? $menu->getActive() : $menu->getDefault();
$items = false;
// FIXME: Experimental caching.
if (KunenaConfig::getInstance()->get('cache_menu')) {
$levels = JFactory::getUser()->getAuthorisedViewLevels();
asort($levels);
$key = 'menu_items' . $params . implode(',', $levels) . '.' . $active->id;
$cache = JFactory::getCache('com_kunena.menu', '');
$items = $cache->get($key);
}
if ($items === false) {
// Initialise variables.
$path = $active->tree;
$start = (int) $params->get('startLevel');
$end = (int) $params->get('endLevel');
$showAll = $params->get('showAllChildren');
$items = $menu->getItems('menutype', $params->get('menutype'));
if ($items) {
foreach ($items as $i => $item) {
if ($start && $start > $item->level || $end && $item->level > $end || !$showAll && $item->level > 1 && !in_array($item->parent_id, $path) || $start > 1 && !in_array($item->tree[$start - 2], $path)) {
unset($items[$i]);
continue;
}
$item->deeper = false;
$item->shallower = false;
$item->level_diff = 0;
if (isset($lastitem)) {
$lastitem->deeper = $item->level > $lastitem->level;
$lastitem->shallower = $item->level < $lastitem->level;
$lastitem->level_diff = $lastitem->level - $item->level;
}
$item->parent = (bool) $menu->getItems('parent_id', (int) $item->id, true);
$lastitem = $item;
$item->active = false;
$item->flink = $item->link;
switch ($item->type) {
case 'separator':
// No further action needed.
continue;
case 'url':
if (strpos($item->link, 'index.php?') === 0 && strpos($item->link, 'Itemid=') === false) {
// If this is an internal Joomla link, ensure the Itemid is set.
$item->flink = $item->link . '&Itemid=' . $item->id;
}
break;
case 'alias':
// If this is an alias use the item id stored in the parameters to make the link.
$item->flink = 'index.php?Itemid=' . $item->params->get('aliasoptions');
break;
default:
$router = $app::getRouter();
if ($router->getMode() == JROUTER_MODE_SEF) {
$item->flink = 'index.php?Itemid=' . $item->id;
} else {
$item->flink .= '&Itemid=' . $item->id;
}
break;
}
if (strcasecmp(substr($item->flink, 0, 4), 'http') && strpos($item->flink, 'index.php?') !== false) {
$item->flink = JRoute::_($item->flink, false, $item->params->get('secure'));
} else {
$item->flink = JRoute::_($item->flink, false);
}
$item->title = htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8');
$item->anchor_css = htmlspecialchars($item->params->get('menu-anchor_css', ''), ENT_COMPAT, 'UTF-8');
$item->anchor_title = htmlspecialchars($item->params->get('menu-anchor_title', ''), ENT_COMPAT, 'UTF-8');
$item->menu_image = $item->params->get('menu_image', '') ? htmlspecialchars($item->params->get('menu_image', ''), ENT_COMPAT, 'UTF-8') : '';
}
if (isset($lastitem)) {
$lastitem->deeper = ($start ? $start : 1) > $lastitem->level;
$lastitem->shallower = ($start ? $start : 1) < $lastitem->level;
$lastitem->level_diff = $lastitem->level - ($start ? $start : 1);
}
}
if (isset($cache)) {
$cache->store($items, $key);
}
}
return $items;
}
开发者ID:giabmf11,项目名称:Kunena-Forum,代码行数:94,代码来源:helper.php
示例16: clearCache
/**
* @throws Exception
*/
public function clearCache()
{
$this->adminsByCatid = array();
$this->adminsByUserid = array();
$this->moderatorsByCatid = array();
$this->moderatorsByUserid = array();
// Reset read access for the current session
$me = KunenaUserHelper::getMyself();
JFactory::getApplication()->setUserState("com_kunena.user{$me->userid}_read", null);
// @var KunenaAccess $access
foreach ($this->accesstypes['all'] as $access) {
if (method_exists($access, 'loadCategoryRoles')) {
$this->storeRoles((array) $access->loadCategoryRoles());
}
}
// Load native category moderators and administrators
$db = JFactory::getDBO();
$query = "SELECT user_id, category_id, role FROM #__kunena_user_categories WHERE role IN (1,2)";
$db->setQuery($query);
$this->storeRoles((array) $db->loadObjectList());
KunenaError::checkDatabaseError();
// FIXME: enable caching after fixing the issues
if (KunenaConfig::getInstance()->get('cache_adm')) {
// Store new data into cache
$cache = JFactory::getCache('com_kunena', 'output');
$cache->store(serialize(array('ac' => $this->adminsByCatid, 'au' => $this->adminsByUserid, 'mc' => $this->moderatorsByCatid, 'mu' => $this->moderatorsByUserid)), self::$cacheKey, 'com_kunena');
}
}
开发者ID:Ruud68,项目名称:Kunena-Forum,代码行数:31,代码来源:access.php
示例17: defined
<?php
/**
* Kunena Component
* @package Kunena.Template.Crypsis
* @subpackage Layout.Email
*
* @copyright (C) 2008 - 2015 Kunena Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.kunena.org
**/
defined('_JEXEC') or die;
// New post email for subscribers (HTML)
$this->mail->isHtml(true);
$config = KunenaConfig::getInstance();
$subject = $this->message->subject ? $this->message->subject : $this->message->getTopic()->subject;
$author = $this->message->getAuthor();
?>
<h2><?php
echo JText::_('COM_KUNENA_POST_EMAIL_MOD1') . " " . $config->board_title;
?>
</h2>
<div><?php
echo JText::_('COM_KUNENA_MESSAGE_SUBJECT') . " : " . $subject;
?>
</div>
<div><?php
echo JText::_('COM_KUNENA_CATEGORY') . " : " . $this->message->getCategory()->name;
?>
开发者ID:giabmf11,项目名称:Kunena-Forum,代码行数:31,代码来源:moderator.php
示例18: saveAvatar
/**
* Upload and resize if needed the new avatar for user, or set one from the gallery or the default one
*
* @return boolean
*/
protected function saveAvatar()
{
$action = JRequest::getString('avatar', 'keep');
$current_avatar = $this->me->avatar;
$avatarFile = $this->app->input->files->get('avatarfile');
if (!empty($avatarFile['tmp_name']))
{
if ($avatarFile['size'] < intval(KunenaConfig::getInstance()->avatarsize) * 1024)
{
$this->deleteOldAvatars();
}
$upload = KunenaUpload::getInstance(array('gif, jpeg, jpg, png'));
$uploaded = $upload->upload($avatarFile, KPATH_MEDIA . '/avatars/users/avatar' . $this->me->userid, 'avatar');
if (!empty($uploaded))
{
$imageInfo = KunenaImage::getImageFileProperties($uploaded->destination);
// If image is not inside allowed size limits, resize it
if ($uploaded->size > intval($this->config->avatarsize) * 1024 || $imageInfo->width > '200' || $imageInfo->height > '200')
{
if ($this->config->avatarquality < 1 || $this->config->avatarquality > 100)
{
$quality = 70;
}
else
{
$quality = $this->config->avatarquality;
}
$resized = KunenaImageHelper::version($uploaded->destination, KPATH_MEDIA . '/avatars/users', 'avatar' . $this->me->userid . '.' . $uploaded->ext, 200, 200, $quality, KunenaImage::SCALE_INSIDE, $this->config->avatarcrop);
}
$this->app->enqueueMessage(JText::sprintf('COM_KUNENA_PROFILE_AVATAR_UPLOADED'));
$this->me->avatar = 'users/avatar' . $this->me->userid . '.' . $uploaded->ext;
}
else
{
$this->me->avatar = $current_avatar;
return false;
}
}
elseif ($action == 'delete')
{
$this->deleteOldAvatars();
// Set default avatar
$this->me->avatar = '';
}
elseif (substr($action, 0, 8) == 'gallery/' && strpos($action, '..') === false)
{
$this->me->avatar = $action;
}
return true;
}
开发者ID:BillVGN,项目名称:PortalPRP,代码行数:65,代码来源:user.php
示例19:
$lang->load('com_kunena.install', JPATH_ADMINISTRATOR . '/components/com_kunena');
JResponse::setHeader('Status', '503 Service Temporarily Unavailable', true);
?>
<h2><?php echo JText::_('COM_KUNENA_INSTALL_OFFLINE_TOPIC') ?></h2>
<div><?php echo JText::_('COM_KUNENA_INSTALL_OFFLINE_DESC') ?></div>
<?php
return;
}
// Display time it took to create the entire page in the footer.
$kunena_profiler = KunenaProfiler::instance('Kunena');
$kunena_profiler->start('Total Time');
KUNENA_PROFILER ? $kunena_profiler->mark('afterLoad') : null;
// Prevent direct access to the component if the option has been disabled.
if (!KunenaConfig::getInstance()->get('access_component', 1))
{
$active = JFactory::getApplication()->getMenu()->getActive();
if (!$active)
{
// Prevent access without using a menu item.
JLog::add("Kunena: Direct access denied: " . JUri::getInstance()->toString(array('path', 'query')), JLog::WARNING, 'kunena');
JError::raiseError(404, JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'));
}
elseif ($active->type != 'component' || $active->component != 'com_kunena')
{
// Prevent spoofed access by using random menu item.
JLog::add("Kunena: spoofed access denied: " . JUri::getInstance()->toString(array('path', 'query')), JLog::WARNING, 'kunena');
JError::raiseError(404, JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'));
}
开发者ID:BillVGN,项目名称:PortalPRP,代码行数:31,代码来源:kunena.php
示例20: upload
/**
* Upload files with AJAX.
*
* @throws RuntimeException
*/
public function upload()
{
// Only support JSON requests.
if ($this->input->getWord('format', 'html') != 'json') {
throw new RuntimeException(JText::_('Bad Request'), 400);
}
$upload = KunenaUpload::getInstance();
// We are converting all exceptions into JSON.
try {
if (!JSession::checkToken('request')) {
throw new RuntimeException(JText::_('Forbidden'), 403);
}
$me = KunenaUserHelper::getMyself();
$catid = $this->input->getInt('catid', 0);
$mesid = $this->input->getInt('mesid', 0);
if ($mesid) {
$message = KunenaForumMessageHelper::get($mesid);
$message->tryAuthorise('attachment.create');
$category = $message->getCategory();
} else {
$category = KunenaForumCategoryHelper::get($catid);
// TODO: Some room for improvements in here... (maybe ask user to pick up category first)
if ($category->id) {
if (stripos($this->input->getString('mime'), 'image/') !== false) {
$category->tryAuthorise('topic.post.attachment.createimage');
} else {
$category->tryAuthorise('topic.post.attachment.createfile');
}
}
}
$caption = $this->input->getString('caption');
$options = array('filename' => $this->input->getString('filename'), 'size' => $this->input->getInt('size'), 'mime' => $this->input->getString('mime'), 'hash' => $this->input->getString('hash'), 'chunkStart' => $this->input->getInt('chunkStart', 0), 'chunkEnd' => $this->input->getInt('chunkEnd', 0));
// Upload!
$upload->addExtensions(KunenaAttachmentHelper::getExtensions($category->id, $me->userid));
$response = (object) $upload->ajaxUpload($options);
if (!empty($response->completed)) {
// We have it all, lets create the attachment.
$uploadFile = $upload->getProtectedFile();
list($basename, $extension) = $upload->splitFilename();
$attachment = new KunenaAttachment();
$attachment->bind(array('mesid' => 0, 'userid' => (int) $me->userid, 'protected' => null, 'hash' => $response->hash, 'size' => $response->size, 'folder' => null, 'filetype' => $response->mime, 'filename' => null, 'filename_real' => $response->filename, 'caption' => $caption));
// Resize image if needed.
if ($attachment->isImage()) {
$imageInfo = KunenaImage::getImageFileProperties($uploadFile);
$config = KunenaConfig::getInstance();
if ($imageInfo->width > $config->imagewidth || $imageInfo->height > $config->imageheight) {
// Calculate quality for both JPG and PNG.
$quality = $config->imagequality;
if ($quality < 1 || $quality > 100) {
$quality = 70;
}
if ($imageInfo->type == IMAGETYPE_PNG) {
$quality = intval(($quality - 1) / 10);
}
$image = new KunenaImage($uploadFile);
$image = $image->resize($config->imagewidth, $config->imageheight, false);
$options = array('quality' => $quality);
$image->toFile($uploadFile, $imageInfo->type, $options);
unset($image);
$attachment->hash = md5_file($uploadFile);
$attachment->size = filesize($uploadFile);
}
}
$attachment->saveFile($uploadFile, $basename, $extension, true);
// Set id and override response variables just in case if attachment was modified.
$response->id = $attachment->id;
$response->hash = $attachment->hash;
$response->size = $attachment->size;
$response->mime = $attachment->filetype;
$response->filename = $attachment->filename_real;
}
} catch (Exception $response) {
$upload->cleanup();
// Use the exception as the response.
}
header('Content-type: application/json');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
while (@ob_end_clean()) {
}
echo $upload->ajaxResponse($response);
jexit();
}
开发者ID:giabmf11,项目名称:Kunena-Forum,代码行数:91,代码来源:topic.php
注:本文中的KunenaConfig类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论