本文整理汇总了PHP中vB_Image::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP vB_Image::instance方法的具体用法?PHP vB_Image::instance怎么用?PHP vB_Image::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vB_Image
的用法示例。
在下文中一共展示了vB_Image::instance方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: array
$crop = array();
if (!empty($_FILES['upload']['tmp_name'])) {
if (!file_exists($_FILES['upload']['tmp_name'])) {
throw new Exception('Upload failed. PHP upload error: ' . intval($_FILES['upload']['error']));
}
$filearray = $_FILES['upload'];
$data['org_file_info'] = pathinfo($_FILES['upload']['name']);
$filesize = filesize($_FILES['upload']['tmp_name']);
$fileContents = file_get_contents($_FILES['upload']['tmp_name']);
$filename = $_FILES['upload']['tmp_name'];
$crop['org_file_info'] = pathinfo($_FILES['upload']['name']);
} elseif (!empty($vbulletin->GPC['avatarurl'])) {
//Make a local copy
require_once DIR . '/includes/class_upload.php';
$upload = new vB_Upload_Image($vbulletin);
$upload->image = vB_Image::instance();
$upload->path = vB_Utilities::getTmpDir();
$filename = $upload->process_upload($vbulletin->GPC['avatarurl']);
}
if ($filename) {
vB_Library::instance('user')->uploadAvatar($filename, $crop, $userinfo['userid']);
} else {
print_stop_message2('upload_file_failed');
}
} else {
// not using an avatar
$vbulletin->GPC['avatarid'] = 0;
$userpic = new vB_Datamanager_Userpic_Avatar($vbulletin, vB_DataManager_Constants::ERRTYPE_CP);
$userpic->condition = array(array('field' => 'userid', 'value' => $userinfo['userid'], 'operator' => vB_dB_Query::OPERATOR_EQ));
$userpic->delete();
}
示例3: __construct
protected function __construct()
{
parent::__construct();
$this->imageHandler = vB_Image::instance();
}
示例4: 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();
//.........这里部分代码省略.........
示例5: 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);
}
示例6: cropFileData
public function cropFileData($filedataid, $data = array())
{
$usercontext = vB::getUserContext();
if (!$usercontext->fetchUserId() or !$usercontext->hasPermission('genericpermissions', 'canuseavatar') or !$usercontext->hasPermission('genericpermissions', 'canmodifyprofile')) {
throw new vB_Exception_API('no_permission_use_avatar');
}
//Did we get a valid url?
if (empty($filedataid)) {
throw new vB_Exception_API('upload_invalid_url');
}
//add @ to suppress warnings caused by invalid url
$filedata = vB_Api::instanceInternal('filedata')->fetchImageByFiledataid($filedataid);
if (empty($filedata)) {
throw new vB_Exception_API('upload_invalid_url');
}
$imageHandler = vB_Image::instance();
$extension_map = $imageHandler->getExtensionMap();
if (!array_key_exists(strtolower($filedata['extension']), $extension_map)) {
throw new vB_Exception_API('error_thumbnail_notcorrectimage');
}
//Make a local copy
$filename = vB_Utilities::getTmpFileName('', 'vbprofile', ".{$filedata['extension']}");
file_put_contents($filename, $filedata['filedata']);
$crop = array();
if (!empty($data) and is_array($data) and array_key_exists('crop', $data)) {
$crop = $data['crop'];
}
return vB_Library::instance('user')->uploadAvatar($filename, $crop);
}
示例7: header
} else {
if (!($imageinfo = vB::getDbAssertor()->getRow('humanverify', array('hash' => $vbulletin->GPC['hash'], 'viewed' => 0)))) {
header('Content-type: image/gif');
readfile(DIR . '/' . vB::getDatastore()->getOption('cleargifurl'));
exit;
} else {
$affected_rows = vB::getDbAssertor()->update('humanverify', array('viewed' => 1), array('hash' => $vbulletin->GPC['hash'], 'viewed' => 0));
if ($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 . '/' . vB::getDatastore()->getOption('cleargifurl'));
exit;
}
}
}
$image = vB_Image::instance();
$imageInfo = $image->getImageFromString($imageinfo['answer'], $moveabout);
header('Content-disposition: inline; filename=image.' . $imageInfo['filetype']);
header('Content-transfer-encoding: binary');
header('Content-Type: ' . $imageInfo['contentType']);
header("Content-Length: " . $imageInfo['filesize']);
echo $imageInfo['filedata'];
} else {
if ($vbulletin->GPC['userid']) {
$vbulletin->input->clean_array_gpc('r', array('dateline' => vB_Cleaner::TYPE_UINT));
$filedata = 'filedata';
if ($vbulletin->GPC['type'] == 'profile') {
$table = 'customavatar';
} else {
if ($vbulletin->GPC['type'] == 'sigpic') {
$table = 'sigpic';
示例8: fetchImageByPhotoid
public function fetchImageByPhotoid($id, $type = vB_Api_Filedata::SIZE_FULL, $includeData = true)
{
if (empty($id) or !intval($id)) {
throw new vB_Exception_Api('invalid_request');
}
//Normal permissions check
$userContext = vB::getUserContext();
if (!$userContext->getChannelPermission('forumpermissions', 'canview', $id)) {
throw new vB_Exception_Api('no_permission');
}
$params = array('nodeid' => $id, 'type' => $type);
$record = $this->assertor->getRow('vBForum:getPhotoContent', $params);
if (empty($record)) {
return false;
}
if (!$this->imageHandler) {
$this->imageHandler = vB_Image::instance();
}
return $this->imageHandler->loadFileData($record, $type, $includeData);
}
示例9: 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;
}
}
示例10: 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']);
}
示例11: 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);
}
示例12: 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;
}
}
}
示例13: fetchImageByFiledataid
/**
* Fetch image information about an attachment based on file data id
*
* @param int Filedataid
* @param bool Thumbnail version requested?
* @param bool Should we include the image content
*
* @return mixed Array of data, includes filesize, dateline, htmltype, filename, extension, and filedataid
*/
public function fetchImageByFiledataid($id, $type = vB_Api_Filedata::SIZE_FULL, $includeData = true)
{
if (empty($id) or !intval($id)) {
throw new Exception('invalid_request');
}
$type = vB_Api::instanceInternal('filedata')->sanitizeFiletype($type);
//If the record belongs to this user, or if this user can view attachments
//in this section, then this is O.K.
$userinfo = vB::getCurrentSession()->fetch_userinfo();
$params = array('filedataid' => $id, 'type' => $type);
$record = vB::getDbAssertor()->getRow('vBForum:getFiledataContent', $params);
if (empty($record)) {
return false;
}
if ($userinfo['userid'] == $record['userid'] or $record['publicview'] > 0) {
return vB_Image::instance()->loadFileData($record, $type, $includeData);
}
throw new vB_Exception_Api('no_view_permissions');
}
示例14: __construct
/**
* Constructor - checks that the registry object has been passed correctly.
*
* @param vB_Registry Instance of the vBulletin data registry object - expected to have the database object as one of its $this->db member.
* @param integer One of the ERRTYPE_x constants
*/
function __construct($registry = NULL, $errtype = vB_DataManager_Constants::ERRTYPE_STANDARD)
{
parent::__construct($registry, $errtype);
$this->imageHandler = vB_Image::instance();
}