本文整理汇总了PHP中KunenaAttachmentHelper类的典型用法代码示例。如果您正苦于以下问题:PHP KunenaAttachmentHelper类的具体用法?PHP KunenaAttachmentHelper怎么用?PHP KunenaAttachmentHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KunenaAttachmentHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: before
/**
* Prepare user attachments list.
*
* @return void
*/
protected function before()
{
parent::before();
$userid = $this->input->getInt('userid');
$params = array('file' => '1', 'image' => '1', 'orderby' => 'desc', 'limit' => '30');
$this->template = KunenaFactory::getTemplate();
$this->me = KunenaUserHelper::getMyself();
$this->profile = KunenaUserHelper::get($userid);
$this->attachments = KunenaAttachmentHelper::getByUserid($this->profile, $params);
// Pre-load messages.
$messageIds = array();
foreach ($this->attachments as $attachment)
{
$messageIds[] = (int) $attachment->mesid;
}
$messages = KunenaForumMessageHelper::getMessages($messageIds, 'none');
// Pre-load topics.
$topicIds = array();
foreach ($messages as $message)
{
$topicIds[] = $message->thread;
}
KunenaForumTopicHelper::getTopics($topicIds, 'none');
$this->headerText = JText::_('COM_KUNENA_MANAGE_ATTACHMENTS');
}
示例2: before
/**
* Prepare reply history display.
*
* @return void
*/
protected function before()
{
parent::before();
$id = $this->input->getInt('id');
$this->topic = KunenaForumTopicHelper::get($id);
$this->history = KunenaForumMessageHelper::getMessagesByTopic($this->topic, 0, (int) $this->config->historylimit, 'DESC');
$this->replycount = $this->topic->getReplies();
$this->historycount = count($this->history);
KunenaAttachmentHelper::getByMessage($this->history);
$userlist = array();
foreach ($this->history as $message) {
$userlist[(int) $message->userid] = (int) $message->userid;
}
KunenaUserHelper::loadUsers($userlist);
// Run events
$params = new JRegistry();
$params->set('ksource', 'kunena');
$params->set('kunena_view', 'topic');
$params->set('kunena_layout', 'history');
$dispatcher = JEventDispatcher::getInstance();
JPluginHelper::importPlugin('kunena');
$dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->history, &$params, 0));
// FIXME: need to improve BBCode class on this...
$this->attachments = KunenaAttachmentHelper::getByMessage($this->history);
$this->inline_attachments = array();
$this->headerText = JText::_('COM_KUNENA_POST_EDIT') . ' ' . $this->topic->subject;
}
示例3: delete
/**
* @throws Exception
*/
public function delete()
{
if (!JSession::checkToken('post')) {
$this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
return;
}
$cid = JFactory::getApplication()->input->get('cid', array(), 'post', 'array');
// Array of integers
Joomla\Utilities\ArrayHelper::toInteger($cid);
if (!$cid) {
$this->app->enqueueMessage(JText::_('COM_KUNENA_NO_ATTACHMENTS_SELECTED'), 'error');
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
return;
}
foreach ($cid as $id) {
$attachment = KunenaAttachmentHelper::get($id);
$message = $attachment->getMessage();
$attachments = array($attachment->id, 1);
$attach = array();
$removeList = array_keys(array_diff_key($attachments, $attach));
Joomla\Utilities\ArrayHelper::toInteger($removeList);
$message->removeAttachments($removeList);
$message->save();
$topic = $message->getTopic();
$attachment->delete();
if ($topic->attachments > 0) {
$topic->attachments = $topic->attachments - 1;
$topic->save(false);
}
}
$this->app->enqueueMessage(JText::_('COM_KUNENA_ATTACHMENTS_DELETED_SUCCESSFULLY'));
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
}
示例4: before
/**
* Prepare topic reply form.
*
* @return void
*
* @throws RuntimeException
* @throws KunenaExceptionAuthorise
*/
protected function before()
{
parent::before();
$catid = $this->input->getInt('catid');
$id = $this->input->getInt('id');
$mesid = $this->input->getInt('mesid');
$quote = $this->input->getBool('quote', false);
$saved = $this->app->getUserState('com_kunena.postfields');
$this->me = KunenaUserHelper::getMyself();
$this->template = KunenaFactory::getTemplate();
if (!$mesid) {
$this->topic = KunenaForumTopicHelper::get($id);
$parent = KunenaForumMessageHelper::get($this->topic->first_post_id);
} else {
$parent = KunenaForumMessageHelper::get($mesid);
$this->topic = $parent->getTopic();
}
$this->category = $this->topic->getCategory();
if ($parent->isAuthorised('reply') && $this->me->canDoCaptcha()) {
if (JPluginHelper::isEnabled('captcha')) {
$plugin = JPluginHelper::getPlugin('captcha');
$params = new JRegistry($plugin[0]->params);
$captcha_pubkey = $params->get('public_key');
$catcha_privkey = $params->get('private_key');
if (!empty($captcha_pubkey) && !empty($catcha_privkey)) {
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$result = $dispatcher->trigger('onInit', 'dynamic_recaptcha_1');
$this->captchaEnabled = $result[0];
}
} else {
$this->captchaEnabled = false;
}
}
$parent->tryAuthorise('reply');
// Run event.
$params = new JRegistry();
$params->set('ksource', 'kunena');
$params->set('kunena_view', 'topic');
$params->set('kunena_layout', 'reply');
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('kunena');
$dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0));
// Can user edit topic icons?
if ($this->config->topicicons && $this->topic->isAuthorised('edit')) {
$this->topicIcons = $this->template->getTopicIcons(false, $saved ? $saved['icon_id'] : $this->topic->icon_id);
}
list($this->topic, $this->message) = $parent->newReply($saved ? $saved : $quote);
$this->action = 'post';
$this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category);
$this->post_anonymous = $saved ? $saved['anonymous'] : !empty($this->category->post_anonymous);
$this->subscriptionschecked = $saved ? $saved['subscribe'] : $this->config->subscriptionschecked == 1;
$this->app->setUserState('com_kunena.postfields', null);
$this->canSubscribe = $this->canSubscribe();
$this->headerText = JText::_('COM_KUNENA_BUTTON_MESSAGE_REPLY') . ' ' . $this->topic->subject;
}
示例5: _getList
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$this->_db->setQuery($query, $limitstart, $limit);
$ids = $this->_db->loadColumn();
$results = KunenaAttachmentHelper::getById($ids);
$userids = array();
$mesids = array();
foreach ($results as $result) {
$userids[$result->userid] = $result->userid;
$mesids[$result->mesid] = $result->mesid;
}
KunenaUserHelper::loadUsers($userids);
KunenaForumMessageHelper::getMessages($mesids);
return $results;
}
示例6: delete
/**
* Method to delete the KunenaForumTopic object from the database.
*
* @param bool $recount
*
* @return bool True on success.
*/
public function delete($recount = true)
{
if (!$this->exists()) {
return true;
}
if (!parent::delete()) {
return false;
}
// Clear authentication cache
$this->_authfcache = $this->_authccache = $this->_authcache = array();
// NOTE: shadow topic doesn't exist, DO NOT DELETE OR CHANGE ANY EXTERNAL INFORMATION
if ($this->moved_id == 0) {
$db = JFactory::getDBO();
// Delete user topics
$queries[] = "DELETE FROM #__kunena_user_topics WHERE topic_id={$db->quote($this->id)}";
// Delete user read
$queries[] = "DELETE FROM #__kunena_user_read WHERE topic_id={$db->quote($this->id)}";
// Delete poll (users)
$queries[] = "DELETE FROM #__kunena_polls_users WHERE pollid={$db->quote($this->poll_id)}";
// Delete poll (options)
$queries[] = "DELETE FROM #__kunena_polls_options WHERE pollid={$db->quote($this->poll_id)}";
// Delete poll
$queries[] = "DELETE FROM #__kunena_polls WHERE id={$db->quote($this->poll_id)}";
// Delete thank yous
$queries[] = "DELETE t FROM #__kunena_thankyou AS t INNER JOIN #__kunena_messages AS m ON m.id=t.postid WHERE m.thread={$db->quote($this->id)}";
// Delete all messages
$queries[] = "DELETE m, t FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON m.id=t.mesid WHERE m.thread={$db->quote($this->id)}";
foreach ($queries as $query) {
$db->setQuery($query);
$db->query();
KunenaError::checkDatabaseError();
}
// FIXME: add recount statistics
if ($recount) {
KunenaUserHelper::recount();
KunenaForumCategoryHelper::recount();
KunenaAttachmentHelper::cleanup();
KunenaForumMessageThankyouHelper::recount();
}
}
return true;
}
示例7: 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();
}
示例8: getAttachments
/**
* @param bool|array $ids
* @param string $action
*
* @return KunenaAttachment[]
*/
public function getAttachments($ids = false, $action = 'read')
{
if ($ids === false) {
$attachments = KunenaAttachmentHelper::getByMessage($this->id, $action);
} else {
$attachments = KunenaAttachmentHelper::getById($ids, $action);
foreach ($attachments as $id => $attachment) {
if ($attachment->mesid && $attachment->mesid != $this->id) {
unset($attachments[$id]);
}
}
}
return $attachments;
}
示例9: authoriseUpload
/**
* @param KunenaUser $user
*
* @return KunenaExceptionAuthorise|null
*/
protected function authoriseUpload(KunenaUser $user)
{
// Check if attachments are allowed
if (KunenaAttachmentHelper::getExtensions($this, $user) === false) {
return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_LIB_CATEGORY_AUTHORISE_FAILED_UPLOAD_NOT_ALLOWED'), 403);
}
return null;
}
示例10: DoAttachment
function DoAttachment($bbcode, $action, $name, $default, $params, $content)
{
if ($action == BBCODE_CHECK) {
return true;
}
$attachments = null;
if ($bbcode->parent instanceof KunenaForumMessage) {
$attachments = $bbcode->parent->getAttachments();
} elseif (is_object($bbcode->parent) && isset($bbcode->parent->attachments)) {
$attachments =& $bbcode->parent->attachments;
}
/** @var KunenaAttachment $att */
/** @var KunenaAttachment $attachment */
$attachment = null;
if (!empty($default)) {
$attachment = KunenaAttachmentHelper::get($default);
unset($attachments[$attachment->id]);
} elseif (empty($content)) {
$attachment = array_shift($attachments);
} elseif (!empty($attachments)) {
foreach ($attachments as $att) {
if ($att->getFilename() == $content) {
$attachment = $att;
unset($attachments[$att->id]);
break;
}
}
}
// Display tag in activity streams etc..
if (!isset($attachments) || !empty($bbcode->parent->forceMinimal)) {
if ($attachment->isImage()) {
$hide = KunenaFactory::getConfig()->showimgforguest == 0 && JFactory::getUser()->id == 0;
if (!$hide) {
return "<div class=\"kmsgimage\">{$attachment->getImageLink()}</div>";
}
} else {
$hide = KunenaFactory::getConfig()->showfileforguest == 0 && JFactory::getUser()->id == 0;
if (!$hide) {
return "<div class=\"kmsgattach\"><h4>" . JText::_('COM_KUNENA_FILEATTACH') . "</h4>" . JText::_('COM_KUNENA_FILENAME') . " <a href=\"" . $attachment->getUrl() . "\" target=\"_blank\" rel=\"nofollow\">" . $attachment->filename . "</a><br />" . JText::_('COM_KUNENA_FILESIZE') . ' ' . number_format(intval($attachment->size) / 1024, 0, '', ',') . ' KB' . "</div>";
}
}
}
if (!$attachment && !empty($bbcode->parent->inline_attachments)) {
foreach ($bbcode->parent->inline_attachments as $att) {
if ($att->getFilename() == trim(strip_tags($content))) {
$attachment = $att;
break;
}
}
}
if (!$attachment) {
return $bbcode->HTMLEncode($content);
}
return $this->renderAttachment($attachment, $bbcode);
}
示例11: DoAttachment
function DoAttachment($bbcode, $action, $name, $default, $params, $content)
{
if ($action == BBCODE_CHECK) {
return true;
}
$attachments = null;
if ($bbcode->parent instanceof KunenaForumMessage) {
$attachments = $bbcode->parent->getAttachments();
} elseif (is_object($bbcode->parent) && isset($bbcode->parent->attachments)) {
$attachments =& $bbcode->parent->attachments;
}
// Display tag in activity streams etc..
if (!isset($attachments) || !empty($bbcode->parent->forceMinimal)) {
$filename = basename(trim(strip_tags($content)));
return '[' . JText::_('COM_KUNENA_FILEATTACH') . ' ' . basename(!empty($params["name"]) ? $params["name"] : $filename) . ']';
}
/** @var KunenaAttachment $att */
/** @var KunenaAttachment $attachment */
$attachment = null;
if (!empty($default)) {
$attachment = KunenaAttachmentHelper::get($default);
unset($attachments[$attachment->id]);
} elseif (empty($content)) {
$attachment = array_shift($attachments);
} elseif (!empty($attachments)) {
foreach ($attachments as $att) {
if ($att->getFilename() == $content) {
$attachment = $att;
unset($attachments[$att->id]);
break;
}
}
}
// Display tag in activity streams etc..
if (!empty($bbcode->parent->forceMinimal) || !is_object($bbcode->parent) && !isset($bbcode->parent->attachments)) {
$filename = basename(trim(strip_tags($content)));
return $attachment->getThumbnailLink();
}
if (!$attachment && !empty($bbcode->parent->inline_attachments)) {
foreach ($bbcode->parent->inline_attachments as $att) {
if ($att->getFilename() == trim(strip_tags($content))) {
$attachment = $att;
break;
}
}
}
if (!$attachment) {
return $bbcode->HTMLEncode($content);
}
return $this->renderAttachment($attachment, $bbcode);
}
示例12: getMessages
public function getMessages()
{
if ($this->messages === false) {
$layout = $this->getState('layout');
$threaded = $layout == 'indented' || $layout == 'threaded';
$this->messages = KunenaForumMessageHelper::getMessagesByTopic($this->getState('item.id'), $this->getState('list.start'), $this->getState('list.limit'), $this->getState('list.direction'), $this->getState('hold'), $threaded);
// Get thankyous for all messages in the page
$thankyous = KunenaForumMessageThankyouHelper::getByMessage($this->messages);
// First collect ids and users
$userlist = array();
$this->threaded = array();
$location = $this->getState('list.start');
foreach ($this->messages as $message) {
$message->replynum = ++$location;
if ($threaded) {
// Threaded ordering
if (isset($this->messages[$message->parent])) {
$this->threaded[$message->parent][] = $message->id;
} else {
$this->threaded[0][] = $message->id;
}
}
$userlist[intval($message->userid)] = intval($message->userid);
$userlist[intval($message->modified_by)] = intval($message->modified_by);
$thankyou_list = $thankyous[$message->id]->getList();
$message->thankyou = array();
if (!empty($thankyou_list)) {
$message->thankyou = $thankyou_list;
}
}
if (!isset($this->messages[$this->getState('item.mesid')]) && !empty($this->messages)) {
$this->setState('item.mesid', reset($this->messages)->id);
}
if ($threaded) {
if (!isset($this->messages[$this->topic->first_post_id])) {
$this->messages = $this->getThreadedOrdering(0, array('edge'));
} else {
$this->messages = $this->getThreadedOrdering();
}
}
// Prefetch all users/avatars to avoid user by user queries during template iterations
KunenaUserHelper::loadUsers($userlist);
// Get attachments
KunenaAttachmentHelper::getByMessage($this->messages);
}
return $this->messages;
}
示例13: canManageAttachments
/**
* @return bool
*/
function canManageAttachments()
{
if ($this->config->show_imgfiles_manage_profile) {
$params = array('file' => '1', 'image' => '1', 'orderby' => 'desc', 'limit' => '30');
$this->userattachs = KunenaAttachmentHelper::getByUserid($this->profile, $params);
if ($this->userattachs) {
if ($this->me->isModerator() || $this->profile->userid == $this->me->userid) {
return true;
} else {
return false;
}
} else {
return false;
}
}
return false;
}
示例14: defined
<?php
/**
* Kunena Component
*
* @package Kunena.Template.Crypsis
* @subpackage BBCode
*
* @copyright (C) 2008 - 2016 Kunena Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link https://www.kunena.org
**/
defined('_JEXEC') or die ();
/** @var KunenaAttachment $attachment */
$attachment = $this->attachment;
$config = KunenaConfig::getInstance();
$attributesLink = $attachment->isImage() && $config->lightbox ? ' class="fancybox-button" rel="fancybox-button"' : '';
?>
<a class="btn btn-small" rel="popover" data-placement="bottom" data-trigger="hover" target="_blank" data-content="Filesize: <?php echo number_format($attachment->size / 1024, 0, '', ',') . JText::_('COM_KUNENA_USER_ATTACHMENT_FILE_WEIGHT'); ?>
" data-original-title="<?php echo $attachment->getShortName(); ?>" href="<?php echo $attachment->getUrl(); ?>" title="<?php echo KunenaAttachmentHelper::shortenFileName($attachment->getFilename(), 0, 26); ?>">
<i class="icon icon-info"></i>
</a>
示例15: defined
<?php
/**
* Kunena Component
* @package Kunena.Template.Crypsis
* @subpackage BBCode
*
* @copyright (C) 2008 - 2016 Kunena Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link https://www.kunena.org
**/
defined ( '_JEXEC' ) or die ();
/** @var KunenaAttachment $attachment */
$attachment = $this->attachment;
if (!$attachment->isImage()) return;
$config = KunenaConfig::getInstance();
$attributesLink = $config->lightbox ? ' rel="lightbox[imagelink' . $attachment->mesid . ']"' : '';
$attributesImg = ' style="max-height:' . (int) $config->imageheight . 'px;"';
?>
<a href="<?php echo $attachment->getUrl(); ?>" title="<?php echo KunenaAttachmentHelper::shortenFileName($attachment->getFilename(), 0,7); ?>"<?php echo $attributesLink; ?>>
<img src="<?php echo $attachment->getUrl(); ?>"<?php echo $attributesImg; ?> alt="" />
</a>