Esempio n. 1
0
 /**
  * Constructor. Sets up resizable types, extensions, etc.
  *
  * @return	void
  */
 public function __construct($options)
 {
     parent::__construct($options);
     $this->info_extensions = array('gif' => true, 'jpg' => true, 'jpe' => true, 'jpeg' => true, 'png' => true, 'psd' => true, 'bmp' => true, 'tiff' => true, 'tif' => true);
     $this->thumb_extensions = array('gif' => true, 'jpg' => true, 'jpe' => true, 'jpeg' => true, 'png' => true);
     $this->resize_types = array('JPEG' => true, 'PNG' => true, 'GIF' => true);
     if (preg_match('~#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})~i', $this->options['thumbcolor'], $match)) {
         $this->thumbcolor = array('r' => hexdec($match[1]), 'g' => hexdec($match[2]), 'b' => hexdec($match[3]));
     }
 }
Esempio n. 2
0
 /**
  * Constructor
  * Sets ImageMagick paths to convert and identify
  *
  * @return	void
  */
 public function __construct($options)
 {
     parent::__construct($options);
     $path = preg_replace('#[/\\\\]+$#', '', $this->options['magickpath']);
     if (preg_match('#^WIN#i', PHP_OS)) {
         $this->identifypath = '"' . $path . '\\identify.exe"';
         $this->convertpath = '"' . $path . '\\convert.exe"';
     } else {
         $this->identifypath = "'" . $path . "/identify'";
         $this->convertpath = "'" . $path . "/convert'";
     }
     $this->must_convert_types = array('PSD' => true, 'BMP' => true, 'TIFF' => true, 'PDF' => true);
     $this->resize_types = array('GIF' => true, 'JPEG' => true, 'PNG' => true, 'BMP' => true, 'TIFF' => true);
     $this->thumb_extensions = array('gif' => true, 'jpg' => true, 'jpe' => true, 'jpeg' => true, 'png' => true, 'psd' => true, 'pdf' => true, 'bmp' => true, 'tiff' => true, 'tif' => true);
     $this->info_extensions =& $this->thumb_extensions;
     if (preg_match('~^#([0-9A-F]{6})$~i', $this->options['thumbcolor'], $match)) {
         $this->thumbcolor = $match[0];
     }
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 /**
  * 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);
 }
Esempio n. 5
0
            $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;
Esempio n. 6
0
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;
}
	/**
	* 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);
	}
Esempio n. 8
0
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);
}
Esempio n. 9
0
 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);
 }
Esempio n. 10
0
 /**
  * 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();
             if ($userpic->has_errors(false)) {
                 throw $userpic->get_exception();
             }
         }
     } else {
         // not using an avatar
         $avatarid = 0;
         $userpic = new vB_DataManager_Userpic_Avatar(vB_DataManager_Constants::ERRTYPE_ARRAY_UNPROCESSED);
         $userpic->condition = array('userid' => $userinfo['userid']);
         $userpic->delete();
         if ($userpic->has_errors(false)) {
             throw $userpic->get_exception();
         }
     }
     $userdata->set('avatarid', $avatarid);
     if (!$userdata->save()) {
         throw $userpic->get_exception();
     }
     unset($this->avatarsCache['avatar'][$userid]);
     unset($this->avatarsCache['thumb'][$userid]);
     return true;
 }
Esempio n. 11
0
 protected function __construct()
 {
     parent::__construct();
     $this->imageHandler = vB_Image::instance();
 }
Esempio n. 12
0
/**
* 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;
}
Esempio n. 13
0
		'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
Esempio n. 14
0
 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;
     }
 }
Esempio n. 15
0
 /**
  * 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']);
 }
Esempio n. 16
0
 /**
  * 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);
 }
Esempio n. 17
0
 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;
         }
     }
 }
Esempio n. 18
0
 /**
  * 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');
 }
Esempio n. 19
0
 public function UpdatevBAvatar(array $info)
 {
     if (empty($info['username'])) {
         return false;
     }
     $username = $info['username'];
     if (DLE_CHARSET && DLE_CHARSET != $this->vbulletin->userinfo['lang_charset']) {
         $username = iconv($this->vbulletin->userinfo['lang_charset'], DLE_CHARSET, $username);
     }
     if ($this->vbulletin->userinfo['username'] != $username) {
         $this->vbulletin->userinfo = $this->vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE username='******'");
     }
     if ($this->vbulletin->userinfo['userid']) {
         $this->vbulletin->userinfo = fetch_userinfo($this->vbulletin->userinfo['userid'], (defined('IN_CONTROL_PANEL') ? 16 : 0) + (defined('AVATAR_ON_NAVBAR') ? 2 : 0));
         cache_permissions($this->vbulletin->userinfo);
         if (!empty($info['delete'])) {
             if ($this->vbulletin->userinfo['avatarid']) {
                 $userdata =& datamanager_init('User', $this->vbulletin, ERRTYPE_STANDARD);
                 $userdata->set_existing($this->vbulletin->userinfo);
                 $userdata->set('avatarid', 0);
                 $userdata->save();
             } else {
                 $userpic =& datamanager_init('Userpic_Avatar', $this->vbulletin, ERRTYPE_STANDARD, 'userpic');
                 $userpic->condition = 'userid = ' . $this->vbulletin->userinfo['userid'];
                 $userpic->delete();
             }
         } elseif (!empty($info['avatarurl'])) {
             require_once DIR . '/includes/class_upload.php';
             require_once DIR . '/includes/class_image.php';
             $upload = new vB_Upload_Userpic($this->vbulletin);
             $upload->data =& datamanager_init('Userpic_Avatar', $this->vbulletin, ERRTYPE_STANDARD, 'userpic');
             $upload->image =& vB_Image::fetch_library($this->vbulletin);
             $upload->maxwidth = $this->vbulletin->userinfo['permissions']['avatarmaxwidth'];
             $upload->maxheight = $this->vbulletin->userinfo['permissions']['avatarmaxheight'];
             $upload->maxuploadsize = $this->vbulletin->userinfo['permissions']['avatarmaxsize'];
             $upload->allowanimation = $this->vbulletin->userinfo['permissions']['genericpermissions'] & $this->vbulletin->bf_ugp_genericpermissions['cananimateavatar'] ? true : false;
             $upload->process_upload($info['avatarurl']);
             $userdata =& datamanager_init('User', $this->vbulletin, ERRTYPE_STANDARD);
             $userdata->set_existing($this->vbulletin->userinfo);
             $userdata->set('avatarid', 0);
             $userdata->save();
         }
     }
 }
Esempio n. 20
0
 function doAction($action)
 {
     global $vbulletin, $vbphrase, $KBANK_HOOK_NAME;
     if ($action == 'use') {
         if ($this->ready2Enable()) {
             $item_new = array('status' => KBANK_ITEM_USED_WAITING, 'expire_time' => iif($this->data['options']['duration'] > 0, TIMENOW + $this->data['options']['duration'] * 24 * 60 * 60, -1));
             $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data[itemid]}"));
             if ($this->isAvatarItem and !$this->isSigPicItem) {
                 $vbulletin->url = "profile.php?" . $vbulletin->session->vars['sessionurl'] . "do=editavatar";
             } else {
                 if (!$this->isAvatarItem and $this->isSigPicItem) {
                     $vbulletin->url = "profile.php?" . $vbulletin->session->vars['sessionurl'] . "do=editsignature";
                 } else {
                     $vbulletin->url = "profile.php?" . $vbulletin->session->vars['sessionurl'];
                 }
             }
             eval(print_standard_redirect('kbank_use_successful'));
         }
     }
     if ($action == 'work' && $KBANK_HOOK_NAME == KBANK_GLOBAL_START && THIS_SCRIPT == 'profile') {
         global $permissions;
         $this->do_permissions($permissions, $this->itemtypedata['options']);
         //Update for later use (?)
         $vbulletin->userinfo['permissions'] = $permissions;
     }
     if ($action == 'work_expired') {
         global $vbphrase, $kbank_profile_images;
         $donow = true;
         $actionStatus = true;
         echo "Processing item ID#{$this->data[itemid]}<br/>";
         //Search for activating item
         if (!isset($kbank_profile_images[$this->data['userid']])) {
             $kbank_profile_images[$this->data['userid']] = array();
             $itemtypes = $vbulletin->db->query_read("\n\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\titems.itemid AS itemid\n\t\t\t\t\t\t\t, itemtypes.options AS itemtypeoptions\n\t\t\t\t\t\tFROM `" . TABLE_PREFIX . "kbank_items` AS items\n\t\t\t\t\t\tINNER JOIN `" . TABLE_PREFIX . "kbank_itemtypes` AS itemtypes ON (itemtypes.itemtypeid = items.type)\n\t\t\t\t\t\tWHERE itemtypes.filename = 'profile_images.kbank.php'\n\t\t\t\t\t\t\tAND items.status = " . KBANK_ITEM_USED_WAITING . "\n\t\t\t\t\t\t\tAND (items.expire_time > " . TIMENOW . "\n\t\t\t\t\t\t\t\tOR items.expire_time < 0)\n\t\t\t\t\t\t\tAND items.userid = {$this->data['userid']}\n\t\t\t\t\t");
             while ($itemtype = $vbulletin->db->fetch_array($itemtypes)) {
                 $tmp = unserialize($itemtype['itemtypeoptions']);
                 foreach ($this->vars as $var) {
                     $kbank_profile_images[$this->data['userid']][$var] = max($kbank_profile_images[$this->data['userid']][$var], $tmp[$var]);
                 }
             }
         }
         //Check for activating item
         $donow = false;
         foreach ($this->vars as $var) {
             if ($kbank_profile_images[$this->data['userid']][$var] < $this->itemtypedata['options'][$var]) {
                 $donow = true;
             }
         }
         if (!$donow) {
             //Found other stuff can handle everything
             echo 'User have other item(s), nothing to do now!<br/>';
         }
         $status = array();
         $message = array();
         if ($donow) {
             $owner = fetch_userinfo($this->data['userid']);
             cache_permissions($owner, false);
             //Apply activating options to owner permissions;
             $this->do_permissions($owner['permissions'], $kbank_profile_images[$this->data['userid']]);
             foreach (array('Avatar', 'SigPic') as $type) {
                 //If this item is this type
                 eval('$work = iif($this->is' . $type . 'Item,true,false);');
                 switch ($type) {
                     case 'Avatar':
                         $table = 'customavatar';
                         $fullname = 'avatar';
                         $bits = $vbulletin->bf_ugp_genericpermissions;
                         $permkey = 'genericpermissions';
                         $canuse = 'canuseavatar';
                         $dm = 'Userpic_Avatar';
                         break;
                     case 'SigPic':
                         $table = 'sigpic';
                         $fullname = 'sigpic';
                         $bits = $vbulletin->bf_ugp_signaturepermissions;
                         $permkey = 'signaturepermissions';
                         $canuse = 'cansigpic';
                         $dm = 'Userpic_Sigpic';
                         break;
                 }
                 if ($work) {
                     $removenow = false;
                     $updatedone = false;
                     $message[$type] = '';
                     $status[$type] = 'none';
                     //Check if user using system avatar
                     if ($type == 'Avatar' and $owner['avatarid'] != 0) {
                         //Check for System Avatar (only check with type = avatar)
                         echo 'User using System Avatar, do nothing!<br/>';
                     } else {
                         //Check for custom image
                         if ($customimg = $vbulletin->db->query_first("\n\t\t\t\t\t\t\t\t\tSELECT filedata, dateline, filename, filesize\n\t\t\t\t\t\t\t\t\tFROM `" . TABLE_PREFIX . $table . "`\n\t\t\t\t\t\t\t\t\tWHERE userid = " . intval($owner['userid']) . "\n\t\t\t\t\t\t\t\t\tORDER BY dateline DESC\n\t\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t\t")) {
                             $extension = trim(substr(strrchr(strtolower($customimg['filename']), '.'), 1));
                             $tmp_filename = DIR . "/includes/tmp_profile_images_{$customimg['dateline']}.{$extension}";
                             $tmp_file = fopen($tmp_filename, 'w');
                             fwrite($tmp_file, $customimg['filedata']);
                             fclose($tmp_file);
                             require_once DIR . '/includes/class_image.php';
                             $image =& vB_Image::fetch_library($vbulletin);
                             $imginfo = $image->fetch_image_info($tmp_filename);
                             if (!($owner['permissions'][$permkey] & $bits[$canuse])) {
                                 //Check if user can use Avatar/SigPic
                                 echo "User doesn't have permission to use {$type}<br/>";
                                 $removenow = true;
                             } else {
                                 if (!($owner['permissions'][$permkey] & $bits['cananimate' . $fullname]) and $imginfo['scenes'] > 1) {
                                     //gif, we will not process this one! remove now
                                     echo "GIF image found! Remove now!<br/>";
                                     $removenow = true;
                                 } else {
                                     if ($owner['permissions'][$fullname . 'maxwidth'] < $imginfo[0] or $owner['permissions'][$fullname . 'maxheight'] < $imginfo[1] or $owner['permissions'][$fullname . 'maxsize'] < $customimg['filesize']) {
                                         //Check if current custom image exceed user permission options
                                         echo "{$type} need to be updated/removed!<br/>";
                                         if ($newimg = $image->fetch_thumbnail(basename($tmp_filename), $tmp_filename, $owner['permissions'][$fullname . 'maxwidth'], $owner['permissions'][$fullname . 'maxheight'], $vbulletin->options['thumbquality'])) {
                                             //Trying to update with smaller size
                                             echo 'Updating with smaller size! ' . $owner['permissions'][$fullname . 'maxwidth'] . 'x' . $owner['permissions'][$fullname . 'maxheight'] . '<br/>';
                                             $status[$type] = 'update';
                                             $data =& datamanager_init($dm, $vbulletin, ERRTYPE_STANDARD, 'userpic');
                                             $data->set('userid', $owner['userid']);
                                             $data->set('dateline', TIMENOW);
                                             $data->set('filename', $customimg['filename']);
                                             $data->set('width', $newimg['width']);
                                             $data->set('height', $newimg['height']);
                                             $data->setr('filedata', $newimg['filedata']);
                                             if ($newimg['width'] <= $owner['permissions'][$fullname . 'maxwidth'] and $newimg['height'] <= $owner['permissions'][$fullname . 'maxheight'] and $newimg['filesize'] <= $owner['permissions'][$fullname . 'maxsize'] and $data->save()) {
                                                 $updatedone = true;
                                             } else {
                                                 $removenow = true;
                                             }
                                         } else {
                                             $removenow = true;
                                         }
                                     } else {
                                         echo "{$type} Size Is Okie, do nothing!<br/>";
                                     }
                                 }
                             }
                             //Send PM
                             if ($updatedone) {
                                 $message[$type] = construct_phrase($vbphrase['kbank_pm_profile_images_message_update'], $newimg['width'], $newimg['height'], $type);
                             }
                             if ($removenow) {
                                 //Just remove record
                                 echo 'Just remove!<br/>';
                                 $status[$type] = 'remove';
                                 $vbulletin->db->query_write("\n\t\t\t\t\t\t\t\t\t\t\tDELETE FROM `" . TABLE_PREFIX . $table . "`\n\t\t\t\t\t\t\t\t\t\t\tWHERE userid = " . intval($owner['userid']) . "\n\t\t\t\t\t\t\t\t\t\t");
                                 $message[$type] = construct_phrase($vbphrase['kbank_pm_profile_images_message_remove'], $type);
                             }
                             @unlink($tmp_filename);
                         } else {
                             echo "No Custom {$type} found, do nothing!<br/>";
                         }
                     }
                 }
             }
             if (isset($message['Avatar']) or isset($message['SigPic'])) {
                 //Send PM
                 $from = array('userid' => 1, 'username' => $vbphrase['kbank'], 'permissions' => array('pmsendmax' => 5));
                 $to =& $owner;
                 $subject = $vbphrase['kbank_pm_profile_images_subject'];
                 $message = construct_phrase($vbphrase['kbank_pm_profile_images_message'], $this->data['name'], vbdate($vbulletin->options['dateformat'] . ' ' . $vbulletin->options['timeformat'], $this->data['expire_time']), implode(', ', $message), $vbulletin->options['bburl'] . '/' . $vbulletin->kbank['phpfile'] . '?do=myitems', $vbulletin->options['bburl'] . '/usercp.php');
                 $result = kbank_sendPM($from, $to, $subject, $message, false);
             }
         }
         $vbulletin->db->query_write("\n\t\t\t\t\tUPDATE `" . TABLE_PREFIX . "kbank_items`\n\t\t\t\t\tSET status = " . KBANK_ITEM_USED . "\n\t\t\t\t\tWHERE itemid = {$this->data['itemid']}\n\t\t\t\t");
         if (count($status) == 2) {
             //Really? Item with both options for Avatar & SigPic. Nothing's impossible!
             return "Avatar: {$status['Avatar']}; SigPic: {$status['SigPic']}";
         } else {
             foreach ($status as $tmp) {
                 return $tmp;
             }
         }
     }
     return parent::doAction($action);
 }
Esempio n. 21
0
 public function upload($files, $urls, $filedata, $imageonly = false)
 {
     $errors = array();
     require_once DIR . '/includes/class_upload.php';
     require_once DIR . '/includes/class_image.php';
     // check for any funny business
     $filecount = 1;
     if (!empty($files['tmp_name'])) {
         foreach ($files['tmp_name'] as $filename) {
             if (!empty($filename)) {
                 if ($filecount > $this->registry->options['attachboxcount']) {
                     @unlink($filename);
                 }
                 $filecount++;
             }
         }
     }
     // Move any urls into the attachment array if we allow url upload
     if ($this->registry->options['attachurlcount']) {
         $urlcount = 1;
         foreach ($urls as $url) {
             if (!empty($url) and $urlcount <= $this->registry->options['attachurlcount']) {
                 $index = count($files['name']);
                 $files['name']["{$index}"] = $url;
                 $files['url']["{$index}"] = true;
                 $urlcount++;
             }
         }
     }
     if (!empty($filedata)) {
         foreach ($filedata as $filedataid) {
             $index = count($files['name']);
             $files['name']["{$index}"] = 'filedata';
             $files['filedataid']["{$index}"] = $filedataid;
         }
     }
     //$this->attachcount = 0;
     $ids = array();
     $uploadsum = count($files['name']);
     for ($x = 0; $x < $uploadsum; $x++) {
         if (!$files['name']["{$x}"]) {
             if ($files['tmp_name']["{$x}"]) {
                 @unlink($files['tmp_name']["{$x}"]);
             }
             continue;
         }
         $attachdata =& $this->fetch_attachdm();
         $upload = new vB_Upload_Attachment($this->registry);
         $upload->contenttypeid = $this->contenttypeid;
         $image =& vB_Image::fetch_library($this->registry);
         $upload->userinfo = $this->userinfo;
         $upload->data =& $attachdata;
         $upload->image =& $image;
         if ($uploadsum > 1) {
             $upload->emptyfile = false;
         }
         if ($files['filedataid']["{$x}"]) {
             if (!($filedatainfo = $this->registry->db->query_first_slave("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tacu.filedataid, acu.filename, fd.filehash, fd.filesize, fd.extension\n\t\t\t\t\tFROM " . TABLE_PREFIX . "attachmentcategoryuser AS acu\n\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "filedata AS fd ON (acu.filedataid = fd.filedataid)\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tacu.filedataid = " . intval($files['filedataid']["{$x}"]) . "\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\tacu.userid = " . $this->registry->userinfo['userid'] . "\n\t\t\t\t"))) {
                 $this->errors[] = array('filename' => "", 'error' => fetch_error('invalid_filedataid_x', $files['filedataid']["{$x}"]));
                 continue;
             }
             $attachment = array('filedataid' => $files['filedataid']["{$x}"], 'name' => $filedatainfo['filename'], 'filehash' => $filedatainfo['filehash'], 'filesize' => $filedatainfo['filesize'], 'extension' => $filedatainfo['extension'], 'filename' => $filedatainfo['filename']);
         } else {
             if ($files['url']["{$x}"]) {
                 $attachment = $files['name']["{$x}"];
             } else {
                 $attachment = array('name' => $files['name']["{$x}"], 'tmp_name' => $files['tmp_name']["{$x}"], 'error' => $files['error']["{$x}"], 'size' => $files['size']["{$x}"], 'utf8_name' => $files['utf8_names']);
             }
         }
         $this->attachcount++;
         $ids[] = $this->process_upload($upload, $attachment, $imageonly);
     }
     return implode(',', $ids);
 }
Esempio n. 22
0
 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);
 }
Esempio n. 23
0
     $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();
 }
Esempio n. 24
0
    } 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';
Esempio n. 25
0
 /**
  * Attempt to resize file if the filesize is too large after an initial resize to max dimensions or the file is already within max dimensions but the filesize is too large
  *
  * @param	bool	Has the image already been resized once?
  * @param	bool	Attempt a resize
  */
 function fetch_best_resize(&$jpegconvert, $resize = true)
 {
     if (!$jpegconvert and $this->upload['filesize'] > $this->maxuploadsize and $resize and $this->image->is_valid_resize_type($this->imginfo[2])) {
         // Linear Regression
         switch ($this->registry->options['thumbquality']) {
             case 65:
                 // No Sharpen
                 // $magicnumber = round(379.421 + .00348171 * $this->maxuploadsize);
                 // Sharpen
                 $magicnumber = round(277.652 + 0.00428902 * $this->maxuploadsize);
                 break;
             case 85:
                 // No Sharpen
                 // $magicnumber = round(292.53 + .0027378 * $this-maxuploadsize);
                 // Sharpen
                 $magicnumber = round(189.939 + 0.00352439 * $this->maxuploadsize);
                 break;
             case 95:
                 // No Sharpen
                 // $magicnumber = round(188.11 + .0022561 * $this->maxuploadsize);
                 // Sharpen
                 $magicnumber = round(159.146 + 0.00234146 * $this->maxuploadsize);
                 break;
             default:
                 //75
                 // No Sharpen
                 // $magicnumber = round(328.415 + .00323415 * $this->maxuploadsize);
                 // Sharpen
                 $magicnumber = round(228.201 + 0.00396951 * $this->maxuploadsize);
         }
         $xratio = $this->imginfo[0] > $magicnumber ? $magicnumber / $this->imginfo[0] : 1;
         $yratio = $this->imginfo[1] > $magicnumber ? $magicnumber / $this->imginfo[1] : 1;
         if ($xratio > $yratio and $xratio != 1) {
             $new_width = round($this->imginfo[0] * $xratio);
             $new_height = round($this->imginfo[1] * $xratio);
         } else {
             $new_width = round($this->imginfo[0] * $yratio);
             $new_height = round($this->imginfo[1] * $yratio);
         }
         if ($new_width == $this->imginfo[0] and $new_height == $this->imginfo[1]) {
             // subtract one pixel so that requested size isn't the same as the image size
             $new_width--;
             $forceresize = false;
         } else {
             $forceresize = true;
         }
         $this->upload['resized'] = $this->image->fetch_thumbnail($this->upload['filename'], $this->upload['location'], $new_width, $new_height, $this->registry->options['thumbquality'], false, false, true, false);
         if (empty($this->upload['resized']['filedata'])) {
             if ($this->image->is_valid_thumbnail_extension(file_extension($this->upload['filename'])) and !empty($this->upload['resized']['imageerror']) and $this->registry->userinfo['permissions']['adminpermissions'] & $this->registry->bf_ugp_adminpermissions['cancontrolpanel']) {
                 if (($error = $this->image->fetch_error()) !== false and $this->registry->userinfo['permissions']['adminpermissions'] & $this->registry->bf_ugp_adminpermissions['cancontrolpanel']) {
                     $this->set_error('image_resize_failed_x', htmlspecialchars_uni($error));
                     return false;
                 } else {
                     $this->set_error($this->upload['resized']['imageerror']);
                     return false;
                 }
             } else {
                 $this->set_error('upload_file_exceeds_forum_limit', vb_number_format($this->upload['filesize'], 1, true), vb_number_format($this->maxuploadsize, 1, true));
                 #$this->set_error('upload_exceeds_dimensions', $this->maxwidth, $this->maxheight, $this->imginfo[0], $this->imginfo[1]);
                 return false;
             }
         } else {
             $jpegconvert = true;
         }
     }
     if (!$jpegconvert and $this->upload['filesize'] > $this->maxuploadsize) {
         $this->set_error('upload_file_exceeds_forum_limit', vb_number_format($this->upload['filesize'], 1, true), vb_number_format($this->maxuploadsize, 1, true));
         return false;
     } else {
         if ($jpegconvert and $this->upload['resized']['filesize'] and ($this->upload['resized']['filesize'] > $this->maxuploadsize or $forceresize)) {
             $ratio = $this->maxuploadsize / $this->upload['resized']['filesize'];
             $newwidth = $this->upload['resized']['width'] * sqrt($ratio);
             $newheight = $this->upload['resized']['height'] * sqrt($ratio);
             if ($newwidth > $this->imginfo[0]) {
                 $newwidth = $this->imginfo[0] - 1;
             }
             if ($newheight > $this->imginfo[1]) {
                 $newheight = $this->imginfo[1] - 1;
             }
             $this->upload['resized'] = $this->image->fetch_thumbnail($this->upload['filename'], $this->upload['location'], $newwidth, $newheight, $this->registry->options['thumbquality'], false, false, true, false);
             if (empty($this->upload['resized']['filedata'])) {
                 if (!empty($this->upload['resized']['imageerror']) and $this->registry->userinfo['permissions']['adminpermissions'] & $this->registry->bf_ugp_adminpermissions['cancontrolpanel']) {
                     if (($error = $this->image->fetch_error()) !== false and $this->registry->userinfo['permissions']['adminpermissions'] & $this->registry->bf_ugp_adminpermissions['cancontrolpanel']) {
                         $this->set_error('image_resize_failed_x', htmlspecialchars_uni($error));
                         return false;
                     } else {
                         $this->set_error($this->upload['resized']['imageerror']);
                         return false;
                     }
                 } else {
                     $this->set_error('upload_file_exceeds_forum_limit', vb_number_format($this->upload['filesize'], 1, true), vb_number_format($this->maxuploadsize, 1, true));
                     #$this->set_error('upload_exceeds_dimensions', $this->maxwidth, $this->maxheight, $this->imginfo[0], $this->imginfo[1]);
                     return false;
                 }
             } else {
                 $jpegconvert = true;
             }
         }
     }
     return true;
 }
Esempio n. 26
0
 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);
 }
Esempio n. 27
0
    if (!$vbulletin->options['profilepicenabled']) {
        print_no_permission();
    }
    $vbulletin->input->clean_array_gpc('p', array('deleteprofilepic' => TYPE_BOOL, 'avatarurl' => TYPE_STR));
    ($hook = vBulletinHook::fetch_hook('profile_updateprofilepic_start')) ? eval($hook) : false;
    if ($vbulletin->GPC['deleteprofilepic']) {
        $userpic =& datamanager_init('Userpic_Profilepic', $vbulletin, ERRTYPE_STANDARD, 'userpic');
        $userpic->condition = "userid = " . $vbulletin->userinfo['userid'];
        $userpic->delete();
    } else {
        $vbulletin->input->clean_gpc('f', 'upload', TYPE_FILE);
        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_Profilepic', $vbulletin, ERRTYPE_STANDARD, 'userpic');
        $upload->image =& vB_Image::fetch_library($vbulletin);
        $upload->maxwidth = $vbulletin->userinfo['permissions']['profilepicmaxwidth'];
        $upload->maxheight = $vbulletin->userinfo['permissions']['profilepicmaxheight'];
        $upload->maxuploadsize = $vbulletin->userinfo['permissions']['profilepicmaxsize'];
        $upload->allowanimation = $vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['cananimateprofilepic'] ? true : false;
        if (!$upload->process_upload($vbulletin->GPC['avatarurl'])) {
            eval(standard_error($upload->fetch_error()));
        }
    }
    ($hook = vBulletinHook::fetch_hook('profile_updateprofilepic_complete')) ? eval($hook) : false;
    $vbulletin->url = 'profile.php?' . $vbulletin->session->vars['sessionurl'] . 'do=editprofilepic';
    eval(print_standard_redirect('redirect_updatethanks'));
}
// ############################### start choose displayed usergroup ###############################
if ($_POST['do'] == 'updatedisplaygroup') {
    $vbulletin->input->clean_array_gpc('p', array('usergroupid' => TYPE_UINT));
Esempio n. 28
0
 /**
  * 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();
 }