本文整理汇总了PHP中vB_Image类的典型用法代码示例。如果您正苦于以下问题:PHP vB_Image类的具体用法?PHP vB_Image怎么用?PHP vB_Image使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vB_Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pre_save
function pre_save($doquery = true)
{
if ($this->presave_called !== null) {
return $this->presave_called;
}
if ($file =& $this->fetch_field('filedata')) {
$this->setr_info('filedata', $file);
$this->do_unset('filedata');
$this->set('filesize', strlen($this->info['filedata']));
chdir(DIR);
if (!is_writable($this->filepath)) {
$this->error('upload_invalid_imagepath');
return false;
}
if ($thumb =& $this->fetch_field('filedata_thumb')) {
$this->setr_info('filedata_thumb', $thumb);
$this->do_unset('filedata_thumb');
}
$image =& vB_Image::instance();
}
return parent::pre_save($doquery);
}
示例2: fetchChannelIcon
/**
* Get a blog icon
*
* @param int The channel or nodeid
* @param string Thumbnail version/size requested (SIZE_* constanst in vB_Api_Filedata)
*
* @return mixed the raw content of the image.
*/
function fetchChannelIcon($nodeid, $type = vB_Api_Filedata::SIZE_FULL)
{
if (!vB::getUserContext()->getChannelPermission('forumpermissions', 'canview', $nodeid)) {
return $this->getDefaultChannelIcon($nodeid);
}
$channel = $this->assertor->getRow('vBForum:channel', array('nodeid' => $nodeid));
if ($channel['filedataid']) {
$params = array('filedataid' => $channel['filedataid'], 'type' => $type);
$record = vB::getDbAssertor()->getRow('vBForum:getFiledataContent', $params);
if (!empty($record)) {
return vB_Image::instance()->loadFileData($record, $type, true);
}
}
//If we don't have a valid custom icon, return the default.
return $this->getDefaultChannelIcon($nodeid);
}
示例3: header
$db->query_write("\n\t\t\tUPDATE " . TABLE_PREFIX . "humanverify\n\t\t\tSET viewed = 1\n\t\t\tWHERE hash = '" . $db->escape_string($vbulletin->GPC['hash']) . "' AND\n\t\t\t\tviewed = 0\n\t\t");
if ($db->affected_rows() == 0) {
// image managed to get viewed by someone else between the $imageinfo query above and now
header('Content-type: image/gif');
readfile(DIR . '/' . $vbulletin->options['cleargifurl']);
exit;
}
}
}
if ($vbulletin->GPC['i'] == 'gd') {
$image = new vB_Image_GD($vbulletin);
} else {
if ($vbulletin->GPC['i'] == 'im') {
$image = new vB_Image_Magick($vbulletin);
} else {
$image =& vB_Image::fetch_library($vbulletin, 'regimage');
}
}
$db->close();
$image->print_image_from_string($imageinfo['answer'], $moveabout);
} else {
if ($vbulletin->GPC['userid']) {
$vbulletin->input->clean_array_gpc('r', array('dateline' => TYPE_UINT));
$filedata = 'filedata';
if ($vbulletin->GPC['type'] == 'profile') {
$table = 'customprofilepic';
$can_view_profile_pic = ($vbulletin->options['profilepicenabled'] and ($vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseeprofilepic'] or $vbulletin->userinfo['userid'] == $vbulletin->GPC['userid']));
if ($can_view_profile_pic) {
require_once DIR . '/includes/functions_user.php';
if (!can_view_profile_section($vbulletin->GPC['userid'], 'profile_picture')) {
$can_view_profile_pic = false;
示例4: attach_image
function attach_image ($file_name, $filedirectory, $nodeid)
{
global $vbulletin;
//make a copy of the file, the attachment code assumes its a temp file and deletes it.
$file_location = "$filedirectory/$file_name";
if (!$file_name OR !file_exists($file_location))
{
echo "<p>Could not find file $file_location\n";
exit;
}
if ($vbulletin->options['safeupload'])
{
$temp_name = $vbulletin->options['tmppath'] . '/vbupload-install-' . substr(TIMENOW, -4);
}
else
{
$temp_name = @tempnam(ini_get('upload_tmp_dir'), 'vbupload');
}
if (!copy($file_location, $temp_name))
{
echo "<p>Could not make temporary copy of image in $temp_name</p>";
exit;
}
//need to clear the cache so that the filesize operation works below.
clearstatcache();
$attachment = array(
'name' => $file_name,
'tmp_name' => $temp_name,
'error' => array(),
'size' => filesize($temp_name)
);
$poststarttime = time();
$posthash = md5($vbulletin->GPC['poststarttime'] . $vbulletin->userinfo['userid'] . $vbulletin->userinfo['salt']);
$contenttypeid = vB_Types::instance()->getContentTypeId("vBCms_Article");
// here we call the attach/file data combined dm
$attachdata =& datamanager_init('AttachmentFiledata', $vbulletin, ERRTYPE_ARRAY, 'attachment');
$attachdata->set('contenttypeid', $contenttypeid);
$attachdata->set('posthash', $posthash);
$attachdata->set('contentid', $nodeid);
$attachdata->set_info('categoryid', 0);
$attachdata->set('state', 'visible');
$upload = new vB_Upload_Attachment_Backend($vbulletin);
$upload->contenttypeid = $contenttypeid;
$upload->userinfo = $vbulletin->userinfo;
$upload->data =& $attachdata;
$upload->image =& vB_Image::fetch_library($vbulletin);
$attachmentid = $upload->process_upload($attachment);
if(!$attachmentid)
{
echo "<p>Error loading image '$file_name':" . $upload->error . "</p>";
}
return $attachmentid;
}
示例5: pre_save
/**
* Any checks to run immediately before saving. If returning false, the save will not take place.
*
* @access protected
*
* @param boolean $doquery Do the query?
* @return boolean True on success; false if an error occurred
*/
function pre_save($doquery = true)
{
if ($this->presave_called !== null)
{
return $this->presave_called;
}
if ($file =& $this->fetch_field('filedata'))
{
$this->setr_info('filedata', $file);
$this->do_unset('filedata');
if (!is_writable($this->fetch_path($this->fetch_field('groupid'), $this->info['group']['icondateline'], false, true)))
{
$this->error('upload_invalid_imagepath');
return false;
}
if ($thumb =& $this->fetch_field('thumbnail_filedata'))
{
$this->setr_info('thumbnail_filedata', $thumb);
$this->do_unset('thumbnail_filedata');
}
require_once(DIR . '/includes/class_image.php');
$image =& vB_Image::fetch_library($this->registry);
}
return parent::pre_save($doquery);
}
示例6: do_upload_avatar
function do_upload_avatar()
{
global $vbulletin, $db, $show, $vbphrase, $permissions;
if (!($permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canmodifyprofile'])) {
print_no_permission();
}
if (!$vbulletin->options['avatarenabled']) {
standard_error(fetch_error('avatardisabled'));
}
if ($vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canuseavatar']) {
$vbulletin->input->clean_gpc('f', 'upload', TYPE_FILE);
// begin custom avatar code
require_once DIR . '/includes/class_upload.php';
require_once DIR . '/includes/class_image.php';
$upload = new vB_Upload_Userpic($vbulletin);
$upload->data =& datamanager_init('Userpic_Avatar', $vbulletin, ERRTYPE_STANDARD, 'userpic');
$upload->image =& vB_Image::fetch_library($vbulletin);
$upload->maxwidth = $vbulletin->userinfo['permissions']['avatarmaxwidth'];
$upload->maxheight = $vbulletin->userinfo['permissions']['avatarmaxheight'];
$upload->maxuploadsize = $vbulletin->userinfo['permissions']['avatarmaxsize'];
$upload->allowanimation = $vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['cananimateavatar'] ? true : false;
if (!$upload->process_upload($vbulletin->GPC['avatarurl'])) {
standard_error($upload->fetch_error());
}
}
// init user data manager
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$userdata->set_existing($vbulletin->userinfo);
$userdata->set('avatarid', 0);
($hook = vBulletinHook::fetch_hook('profile_updateavatar_complete')) ? eval($hook) : false;
$userdata->save();
return array('success' => true);
}
示例7: pre_save
function pre_save($doquery = true)
{
if ($this->presave_called !== null) {
return $this->presave_called;
}
if ($file =& $this->fetch_field('filedata')) {
$this->setr_info('filedata', $file);
$this->do_unset('filedata');
$this->set('filesize', strlen($this->info['filedata']));
if (!is_writable($this->filepath)) {
$this->error('upload_invalid_imagepath');
return false;
}
if ($thumb =& $this->fetch_field('filedata_thumb')) {
$this->setr_info('filedata_thumb', $thumb);
$this->do_unset('filedata_thumb');
}
require_once DIR . '/includes/class_image.php';
$image =& vB_Image::fetch_library($this->registry);
}
return parent::pre_save($doquery);
}
示例8: updateAvatar
/**
* Update avatar
*
* @param integer $userid User ID whose avatar is going to be updated
* @param integer $avatarid Predefined avatar ID. -1 means to remove avatar
* from the user. 0 means use custom avatar defined in $avatardata
* @param array $data Avatar data. It should be an array contains
* the following items: 'filename', 'width', 'height', 'filedata', 'location'
*/
public function updateAvatar($userid, $avatarid, $data = array(), $cropped = false)
{
$userContext = vB::getUserContext();
$currentUserId = $userContext->fetchUserId();
$userid = intval($userid);
if ($userid <= 0 and $currentUserId) {
$userid = $currentUserId;
}
// Check if current user canadminusers
try {
$this->checkHasAdminPermission('canadminusers');
} catch (Exception $e) {
// No. Then we need to do something here.
if ($currentUserId != $userid) {
// If current user isn't the same as passed $userid
throw new vB_Exception_Api('no_permission');
}
}
$useavatar = $avatarid == -1 ? 0 : 1;
$bf_ugp_genericpermissions = vB::getDatastore()->getValue('bf_ugp_genericpermissions');
$userinfo = vB_User::fetchUserInfo(intval($userid));
if (!$userinfo) {
throw new vB_Exception_Api('invalid_user_specified');
}
// init user datamanager
$userdata = new vB_Datamanager_User(vB_DataManager_Constants::ERRTYPE_ARRAY_UNPROCESSED);
$userdata->set_existing($userinfo);
if ($useavatar) {
if (!$avatarid) {
$userpic = new vB_DataManager_Userpic(vB_DataManager_Constants::ERRTYPE_ARRAY_UNPROCESSED);
// user's group doesn't have permission to use custom avatars so set override
if (!$this->userContext->hasPermission('genericpermissions', 'canuseavatar')) {
// init user datamanager
$userdata->set_bitfield('adminoptions', 'adminavatar', 1);
}
$userpic->set('userid', $userinfo['userid']);
$userpic->set('dateline', vB::getRequest()->getTimeNow());
$userpic->set('width', $data['width']);
$userpic->set('height', $data['height']);
if (empty($data['extension'])) {
$filebits = explode('.', $data['filename']);
$data['extension'] = end($filebits);
}
$userpic->set('extension', $data['extension']);
if (vB::getDatastore()->getOption('usefileavatar')) {
$avatarpath = vB::getDatastore()->getOption('avatarpath');
$prev_dir = getcwd();
chdir(DIR);
$oldavatarfilename = "avatar{$userid}_{$userinfo['avatarrevision']}.{$data['extension']}";
$avatarrevision = $userinfo['avatarrevision'] + 1;
$avatarfilename = "avatar{$userid}_{$avatarrevision}.{$data['extension']}";
@unlink($avatarpath . '/' . $oldavatarfilename);
@unlink($avatarpath . '/thumbs/' . $oldavatarfilename);
$avatarres = @fopen("{$avatarpath}/{$avatarfilename}", 'wb');
$userpic->set('filename', $avatarfilename);
fwrite($avatarres, $data['filedata']);
@fclose($avatarres);
if (!empty($data['filedata_thumb'])) {
$thumbres = @fopen("{$avatarpath}/thumbs/{$avatarfilename}", 'wb');
fwrite($thumbres, $data['filedata_thumb']);
@fclose($thumbres);
$userpic->set('width_thumb', $data['width_thumb']);
$userpic->set('height_thumb', $data['height_thumb']);
}
chdir($prev_dir);
$userpic->set('filesize', $data['filesize']);
$userdata->set('avatarrevision', $userinfo['avatarrevision'] + 1);
} else {
$avatarfilename = "avatar{$userid}_{$userinfo['avatarrevision']}.{$data['extension']}";
$userpic->setr('filedata', $data['filedata']);
$userpic->set('filename', $avatarfilename);
$imageHandler = vB_Image::instance();
if (!$cropped) {
$thumb = $imageHandler->fetchThumbNail($data['name'], $data['location']);
}
if (!$cropped) {
$userpic->set('filedata_thumb', $thumb['filedata']);
$userpic->set('width_thumb', $thumb['width']);
$userpic->set('height_thumb', $thumb['height']);
} else {
$userpic->set('filedata_thumb', $data['filedata_thumb']);
$userpic->set('width_thumb', $data['width_thumb']);
$userpic->set('height_thumb', $data['height_thumb']);
}
}
$userpic->save();
} else {
// predefined avatar
$userpic = new vB_DataManager_Userpic_Avatar(vB_DataManager_Constants::ERRTYPE_ARRAY_UNPROCESSED);
$userpic->condition = array('userid' => $userinfo['userid']);
$userpic->delete();
//.........这里部分代码省略.........
示例9: __construct
protected function __construct()
{
parent::__construct();
$this->imageHandler = vB_Image::instance();
}
示例10: save_fbavatar
/**
* Saves the facebook avatar specified from facebook url
*
* @param vB_DataManager_User, the datamanager to put any upload errors into
* @param string, the url to retrieve the avatar from
* @param bool, flag denoting if we want to try a different URL if this one fails
* @param string, the url to retrieve the avatar from if the first one fails
*
* @return bool true if saved worked, false otherwise
*/
function save_fbavatar($userdata, $avatarurl = '', $do_fallback = true, $fallback_avatarurl = '')
{
global $vbulletin;
// if we are not passed an avatar url, grab it from fb api
if (empty($avatarurl)) {
$pf = get_vbprofileinfo();
$avatarurl = $pf['avatarurl'];
}
// begin custom avatar code
require_once DIR . '/includes/class_upload.php';
require_once DIR . '/includes/class_image.php';
// grab permissions info from logged in user, if user not logged in, use permissions from registered usergroup
$usergroup_info = !empty($vbulletin->userinfo['userid']) ? $vbulletin->userinfo['permissions'] : $vbulletin->usergroupcache[2];
// if user does not have permission to user custom avatar, skip this step
if (!($usergroup_info['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canuseavatar'])) {
return;
}
// initialize the uploader and populate with the avatar permissions
$upload = new vB_Upload_Userpic($vbulletin);
$upload->data =& datamanager_init('Userpic_Avatar', $vbulletin, ERRTYPE_STANDARD, 'userpic');
$upload->image =& vB_Image::fetch_library($vbulletin);
$upload->maxwidth = $usergroup_info['avatarmaxwidth'];
$upload->maxheight = $usergroup_info['avatarmaxheight'];
$upload->maxuploadsize = $usergroup_info['avatarmaxsize'];
$upload->allowanimation = $usergroup_info['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['cananimateavatar'] ? true : false;
// upload and validate
if (!$upload->process_upload($avatarurl)) {
// check if we want to try a fallback url
if ($do_fallback) {
// if we are not passed a fallback url, grab smaller pic from FB api
if (empty($fallback_avatarurl)) {
$pf = get_vbprofileinfo();
$fallback_avatarurl = $pf['fallback_avatarurl'];
}
// do this again, but don't use a fallback if that one fails
return save_fbavatar($userdata, $fallback_avatarurl, false);
} else {
$userdata->error($upload->fetch_error());
return false;
}
}
// if we get here, there were no errors, so return true
return true;
}
示例11: max
'perpage' => TYPE_UINT,
'startat' => TYPE_UINT
));
// Increase memlimit
if (($memory_limit = ini_size_to_bytes(@ini_get('memory_limit'))) < 128 * 1024 * 1024 AND $memory_limit > 0)
{
@ini_set('memory_limit', 128 * 1024 * 1024);
}
// Get dimension constants
require_once(DIR . '/includes/functions_socialgroup.php');
// Get image handler
require_once(DIR . '/includes/class_image.php');
$image = vB_Image::fetch_library($vbulletin);
// Check if image manip is supported
if ($vbulletin->options['imagetype'] != 'Magick' AND !function_exists('imagetypes'))
{
print_stop_message('your_version_no_image_support');
}
$vbulletin->GPC['perpage'] = max($vbulletin->GPC['perpage'], 20);
echo '<p>' . construct_phrase($vbphrase['building_sgicon_thumbnails'], "misc.php?" . $vbulletin->session->vars['sessionurl'] . "do=rebuildsgicons&startat=" . $vbulletin->GPC['startat'] . "&pp=" . $vbulletin->GPC['perpage'] . "&autoredirect=" . $vbulletin->GPC['autoredirect'] . "&quality=" . $vbulletin->GPC['quality']) . '</p>';
// Get group info
$result = $vbulletin->db->query_read("
SELECT socialgroupicon.dateline, socialgroupicon.userid, socialgroupicon.filedata, socialgroupicon.extension,
socialgroupicon.width, socialgroupicon.height, socialgroupicon.groupid
示例12: uploadAvatar
public function uploadAvatar($filename, $crop = array(), $userid = false)
{
$imageHandler = vB_Image::instance();
$fileInfo = $imageHandler->fetchImageInfo($filename);
if (!$fileInfo) {
throw new vB_Exception_Api('upload_invalid_image');
}
if ($userid === false) {
$userid = vB::getCurrentSession()->get('userid');
}
$usercontext = vB::getUserContext($userid);
$pathinfo = empty($crop['org_file_info']) ? pathinfo($filename) : $crop['org_file_info'];
$dimensions['src_width'] = $fileInfo[0];
$dimensions['src_height'] = $fileInfo[1];
if (empty($crop['width']) and empty($crop['height'])) {
$crop['width'] = $dimensions['src_width'];
$crop['height'] = $dimensions['src_height'];
}
$crop['width'] = min($crop['width'], $dimensions['src_width']);
$crop['height'] = min($crop['height'], $dimensions['src_height']);
// the crop area should be square
$crop['width'] = $crop['height'] = min($crop['width'], $crop['height']);
$maxwidth = $usercontext->getLimit('avatarmaxwidth');
$maxheight = $usercontext->getLimit('avatarmaxheight');
//see if we need to resize the cropped image (if the crop happened on a resized image)
$resize_ratio = 1;
if (!empty($crop['resized_width']) and $crop['resized_width'] < $dimensions['src_width']) {
$resize_ratio = $dimensions['src_height'] / $crop['resized_height'];
}
$dimensions['x1'] = round(empty($crop['x1']) ? 0 : $crop['x1'] * $resize_ratio);
$dimensions['y1'] = round(empty($crop['y1']) ? 0 : $crop['y1'] * $resize_ratio);
$dimensions['width'] = round((empty($crop['width']) ? $maxwidth : $crop['width']) * $resize_ratio);
$dimensions['height'] = round((empty($crop['height']) ? $maxheight : $crop['height']) * $resize_ratio);
$isCropped = ($dimensions['src_width'] > $dimensions['width'] or $dimensions['src_height'] > $dimensions['height']);
$ext = strtolower($fileInfo[2]);
$dimensions['extension'] = empty($ext) ? $pathinfo['extension'] : $ext;
$dimensions['filename'] = $filename;
$dimensions['filedata'] = file_get_contents($filename);
// Check max height and max weight from the usergroup's permissions
$forceResize = false;
// force a resize if the uploaded file has the right dimensions but the file size exceeds the limits
if ($resize_ratio == 1 and !$isCropped and strlen($dimensions['filedata']) > $usercontext->getLimit('avatarmaxsize')) {
$new_dimensions = $imageHandler->bestResize($dimensions['src_width'], $dimensions['src_height']);
$crop['width'] = $new_dimensions['width'];
$crop['height'] = $new_dimensions['height'];
$forceResize = true;
}
$extension_map = $imageHandler->getExtensionMap();
if ($forceResize or $maxwidth < $fileInfo[0] or $maxheight < $fileInfo[1]) {
$fileArray_cropped = $imageHandler->cropImg($dimensions, min(empty($crop['width']) ? $maxwidth : $crop['width'], $maxwidth), min(empty($crop['height']) ? $maxheight : $crop['height'], $maxheight), $forceResize);
//want to get the thumbnail based on the cropped image
$fh = fopen($filename, 'w');
fwrite($fh, $fileArray_cropped['filedata']);
fclose($fh);
$fileArray_thumb = $imageHandler->fetchThumbnail($pathinfo['basename'], $filename);
$filearray = array('size' => $fileArray_cropped['filesize'], 'filename' => $filename, 'name' => $pathinfo['filename'], 'location' => $pathinfo['dirname'], 'type' => 'image/' . $extension_map[strtolower($dimensions['extension'])], 'filesize' => $fileArray_cropped['filesize'], 'height' => $fileArray_cropped['height'], 'width' => $fileArray_cropped['width'], 'filedata_thumb' => $fileArray_thumb['filedata'], 'filesize_thumb' => $fileArray_thumb['filesize'], 'height_thumb' => $fileArray_thumb['height'], 'width_thumb' => $fileArray_thumb['width'], 'extension' => $dimensions['extension'], 'filedata' => $fileArray_cropped['filedata']);
} else {
$fileArray_thumb = $imageHandler->fetchThumbnail($pathinfo['basename'], $filename);
$filearray = array('size' => strlen($dimensions['filedata']), 'filename' => $filename, 'name' => $pathinfo['filename'], 'location' => $pathinfo['dirname'], 'type' => 'image/' . $extension_map[strtolower($dimensions['extension'])], 'filesize' => strlen($dimensions['filedata']), 'height' => $fileInfo[1], 'width' => $fileInfo[0], 'filedata_thumb' => $fileArray_thumb['filedata'], 'filesize_thumb' => $fileArray_thumb['filesize'], 'height_thumb' => $fileArray_thumb['source_height'], 'width_thumb' => $fileArray_thumb['source_width'], 'extension' => $dimensions['extension'], 'filedata' => $dimensions['filedata']);
}
$api = vB_Api::instanceInternal('user');
$result = $api->updateAvatar($userid, false, $filearray, true);
if (empty($result['errors'])) {
return $api->fetchAvatar($userid);
} else {
return $result;
}
}
示例13: fetchHvImage
/**
* Fetch Human Verification Image Data
*
* @param $hash
* @return array 'type' => Image type 'data' => Image binary data
*/
public function fetchHvImage($hash = '')
{
$vboptions = vB::getDatastore()->getValue('options');
$moveabout = true;
if (!$hash or $hash == 'test' or $vboptions['hv_type'] != 'Image') {
$imageinfo = array('answer' => 'vBulletin');
$moveabout = $hash == 'test' ? true : false;
} else {
if (!($imageinfo = $this->assertor->getRow('humanverify', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'hash' => $hash, 'viewed' => 0)))) {
return array('type' => 'gif', 'data' => file_get_contents(DIR . '/' . $vboptions['cleargifurl']));
} else {
$this->assertor->assertQuery('humanverify', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'viewed' => 1, vB_dB_Query::CONDITIONS_KEY => array('hash' => $hash, 'viewed' => 0)));
if ($this->assertor->affected_rows() == 0) {
// image managed to get viewed by someone else between the $imageinfo query above and now
return array('type' => 'gif', 'data' => file_get_contents(DIR . '/' . $vboptions['cleargifurl']));
}
}
}
$image = vB_Image::instance();
$imageInfo = $image->getImageFromString($imageinfo['answer'], $moveabout);
return array('type' => $imageInfo['filetype'], 'data' => $imageInfo['filedata']);
}
示例14: fetchImageByLinkId
/**
* This returns a link image by nodeid
*
* @param int Node ID
* @param string Thumbnail version/size requested (SIZE_* constanst in vB_Api_Filedata)
*
* @return mixed Array of filedataid,filesize, extension, filedata, htmltype.
*/
public function fetchImageByLinkId($linkid, $type = vB_Api_Filedata::SIZE_FULL)
{
$link = $this->getContent($linkid);
$link = $link[$linkid];
if (empty($link)) {
return array();
}
//First validate permission.
if ($link['userid'] != vB::getUserContext()->fetchUserId()) {
if (!$link['showpublished']) {
if (!vB::getUserContext()->hasChannelPermission('moderatorpermissions', 'caneditposts', $linkid, false, $link['parentid'])) {
throw new vB_Exception_Api('no_permission');
}
} else {
if (!vB::getUserContext()->getChannelPermission('forumpermissions', 'canview', $linkid, false, $link['parentid'])) {
throw new vB_Exception_Api('no_permission');
}
}
}
//if we got here, this user is authorized to see this. image.
$params = array('filedataid' => $link['filedataid'], 'type' => $type);
$image = vB::getDbAssertor()->getRow('vBForum:getFiledataContent', $params);
if (empty($image)) {
return false;
}
$imageHandler = vB_Image::instance();
return $imageHandler->loadFileData($image, $type, true);
}
示例15: prefetchFiledata
public function prefetchFiledata($filedataids)
{
if (!empty($filedataids)) {
$imagehandler = vB_Image::instance();
$filedataRecords = Api_InterfaceAbstract::instance()->callApi('filedata', 'fetchFiledataByid', array($filedataids));
foreach ($filedataRecords as $record) {
$record['isImage'] = $imagehandler->isImage($record['extension']);
$this->filedatas[$record['filedataid']] = $record;
}
}
}