<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Filedata extends vB_Api { const SIZE_ICON = 'icon'; const SIZE_THUMB = 'thumb'; const SIZE_SMALL = 'small'; const SIZE_MEDIUM = 'medium'; const SIZE_LARGE = 'large'; const SIZE_FULL = 'full'; protected $disableWhiteList = array( 'fetchImageByFiledataid', ); public function sanitizeFiletype($type) { return vB_Library::instance('filedata')->sanitizeFiletype($type); } public function fetchImageByFiledataid($id, $type = vB_Api_Filedata::SIZE_FULL, $includeData = true, $attachmentnodeid = 0) { if (empty($id) OR !is_numeric($id) OR !intval($id)) { throw new vB_Exception_Api('invalid_request'); } $attachmentnodeid = (int) $attachmentnodeid; $type = $this->sanitizeFiletype($type); $userinfo = vB::getCurrentSession()->fetch_userinfo(); $params = ['filedataid' => $id, 'type' => $type]; $record = vB::getDbAssertor()->getRow('vBForum:getFiledataContent', $params); if (empty($record)) { return false; } $canView = false; if ($userinfo['userid'] == $record['userid'] OR $record['publicview'] > 0) { $canView = true; } if (!$canView AND $attachmentnodeid > 0) { $nodeLibrary = vB_Library::instance('node'); $attachment = $nodeLibrary->getNodeFullContent($attachmentnodeid); $attachment = $attachment[$attachmentnodeid] ?? $attachment; if ($id == $attachment['filedataid']) { $postnodeid = $attachment['parentid']; $post = $nodeLibrary->getNodeFullContent($postnodeid); $post = $post[$postnodeid] ?? $post; if ($post['canedit']) { $canView = true; } unset($post); } unset($attachment); } if ($canView) { $imageHandler = vB_Image::instance(); return $imageHandler->loadFileData($record, $type, $includeData); } throw new vB_Exception_Api('no_image_view_permissions'); } public function fetchFiledataByid($ids) { if (empty($ids) OR !is_array($ids)) { throw new vB_Exception_Api('invalid_request'); } $userinfo = vB::getCurrentSession()->fetch_userinfo(); $records = vB::getDbAssertor()->assertQuery('vBForum:getFiledataWithThumb', ['filedataid' => $ids]); $filedatas = []; foreach ($records as $record) { if (($userinfo['userid'] == $record['userid']) OR ($record['publicview'] > 0)) { $record['visible'] = $record['publicview']; $record['counter'] = $record['refcount']; $record['filename'] = $record['filehash'] . '.' . $record['extension']; $filedatas[$record['filedataid']] = $record; } } return $filedatas; } public function fetchLegacyAttachments($ids) { if (empty($ids) OR !is_array($ids)) { throw new vB_Exception_Api('invalid_request'); } $ids = array_map('intval', $ids); $rows = vB::getDbAssertor()->assertQuery('vBForum:fetchLegacyAttachments', array( 'oldids' => $ids, 'oldcontenttypeid' => array( vB_Api_ContentType::OLDTYPE_THREADATTACHMENT, vB_Api_ContentType::OLDTYPE_POSTATTACHMENT, vB_Api_ContentType::OLDTYPE_BLOGATTACHMENT, vB_Api_ContentType::OLDTYPE_ARTICLEATTACHMENT, ) ) ); $result = array(); $userContext = vB::getUserContext(); $publicFields = array( 'oldid', 'nodeid', 'contenttypeid', 'parentid', 'filedataid', 'filename', 'filesize', 'settings', 'resize_filesize', 'hasthumbnail', 'counter', 'dateline', 'resize_dateline', 'extension', ); foreach($rows AS $row) { $allowedData = array(); foreach ($publicFields AS $fieldname) { if (isset($row[$fieldname])) { $allowedData[$fieldname] = $row[$fieldname]; } } $allowedData['visible'] = $row['publicview']; $allowedData['counter'] = $row['refcount']; if (empty($allowedData['filename'])) { $allowedData['filename'] = $row['filehash']. '.' . $row['extension']; } $allowedData['cangetattachment'] = $userContext->getChannelPermission('forumpermissions', 'cangetattachment', $row['nodeid']); $allowedData['cangetimgattachment'] = $userContext->getChannelPermission('forumpermissions2', 'cangetimgattachment', $row['nodeid']); $result[$row['oldid']] = $allowedData; } return $result; } public function fetchPhotoFiledataid($nodeid) { if (!is_array($nodeid)) { $nodeid = array($nodeid); } $filedataids = array(); $resultSet = vB::getDbAssertor()->assertQuery('vBForum:photo', array( vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'nodeid' => $nodeid )); foreach ($resultSet as $filedata) { $filedataids[$filedata['nodeid']] = $filedata['filedataid']; } return $filedataids; } public function fetchAttachFiledataid($nodeid) { if (!is_array($nodeid)) { $nodeid = array($nodeid); } $filedataids = array(); $resultSet = vB::getDbAssertor()->assertQuery('vBForum:attach', array( vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'nodeid' => $nodeid )); foreach ($resultSet as $filedata) { $filedataids[$filedata['nodeid']] = $filedata['filedataid']; } return $filedataids; } public function fetchBestFitGTE($targetLength) { $type = vB_Library::instance('filedata')->fetchBestFitGTE($targetLength); return array( 'type' => $type, ); } } 