Example #1
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);
 }
Example #2
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);
 }
Example #3
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;
 }
Example #4
0
/**
* Class factory. This is used for instantiating the extended classes.
*
* @param	string			The type of the class to be called (user, forum etc.)
* @param	vB_Registry		An instance of the vB_Registry object.
* @param	integer			One of the ERRTYPE_x constants
* @param	string			Option to force loading a class from a specific file; no extension
*
* @return	vB_DataManager	An instance of the desired class
*/
function &datamanager_init($classtype, &$registry, $errtype = ERRTYPE_STANDARD, $forcefile = '')
{
	static $called;

	if (empty($called))
	{
		// include the abstract base class
		require_once(DIR . '/includes/class_dm.php');
		$called = true;
	}

	if (preg_match('#^\w+$#', $classtype))
	{
		$classtype = strtolower($classtype);
		if ($forcefile)
		{
			$classfile = preg_replace('#[^a-z0-9_]#i', '', $forcefile);
		}
		else
		{
			$classfile = str_replace('_multiple', '', $classtype);
		}
		require_once(DIR . '/includes/class_dm_' . $classfile . '.php');

		switch($classtype)
		{
			case 'userpic_avatar':
			case 'userpic_profilepic':
			case 'userpic_sigpic':
				$object = vB_DataManager_Userpic::fetch_library($registry, $errtype, $classtype);
				break;
			case('socialgroupicon'):
				$object = vB_DataManager_SocialGroupIcon::fetch_library($registry, $errtype, $classtype);
				break;
			default:
				$classname = 'vB_DataManager_' . $classtype;
				$object = new $classname($registry, $errtype);
		}

		return $object;
	}
}
Example #5
0
         $userpic->set_existing($image);
         $userpic->setr('filedata', $image['afiledata']);
         if (!$userpic->save()) {
             print_stop_message2(array('error_writing_x', $image['afilename']));
         }
     }
     if (!empty($image['pfiledata'])) {
         $userpic = vB_DataManager_Userpic::fetch_library($vbulletin, vB_DataManager_Constants::ERRTYPE_CP, 'userpic_profilepic', true);
         $userpic->set_existing($image);
         $userpic->setr('filedata', $image['pfiledata']);
         if (!$userpic->save()) {
             print_stop_message2(array('error_writing_x', $image['pfilename']));
         }
     }
     if (!empty($image['sfiledata'])) {
         $userpic = vB_DataManager_Userpic::fetch_library($vbulletin, vB_DataManager_Constants::ERRTYPE_CP, 'userpic_sigpic', true);
         $userpic->set_existing($image);
         $userpic->setr('filedata', $image['sfiledata']);
         if (!$userpic->save()) {
             print_stop_message2(array('error_writing_x', $image['sfilename']));
         }
     }
     unset($userpic);
     $vbulletin->options['usefileavatar'] = false;
 } else {
     $vbulletin->options['usefileavatar'] = false;
     // Converting FROM fs TO mysql
     if (!empty($image['afilename'])) {
         $path = $vbulletin->options['avatarpath'] . "/{$image['afilename']}";
         $thumbpath = $vbulletin->options['avatarpath'] . "/thumbs/{$image['afilename']}";
         chdir(DIR);
Example #6
0
 $useavatar = iif($vbulletin->GPC['avatarid'] == -1, 0, 1);
 $userinfo = fetch_userinfo($vbulletin->GPC['userid']);
 if (!$userinfo) {
     print_modcp_stop_message2('invalid_user_specified');
 }
 // init user datamanager
 $userdata = new vB_Datamanager_User($vbulletin, vB_DataManager_Constants::ERRTYPE_CP);
 $userdata->set_existing($userinfo);
 if ($useavatar) {
     if (!$vbulletin->GPC['avatarid']) {
         // custom avatar
         $vbulletin->input->clean_gpc('f', 'upload', vB_Cleaner::TYPE_FILE);
         require_once DIR . '/includes/class_upload.php';
         $upload = new vB_Upload_Userpic($vbulletin);
         $upload->data = new vB_DataManager_Userpic_Avatar($vbulletin, vB_DataManager_Constants::ERRTYPE_CP);
         $object =& vB_DataManager_Userpic::fetch_library($vbulletin, vB_DataManager_Constants::ERRTYPE_CP);
         $upload->data->validfields = array_merge($object->validfields, $upload->data->validfields);
         $upload->image =& vB_Image::instance();
         $upload->userinfo =& $userinfo;
         cache_permissions($userinfo, false);
         // user's group doesn't have permission to use custom avatars so set override
         if (!($userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canuseavatar'])) {
             $userdata->set_bitfield('adminoptions', 'adminavatar', 1);
         }
         if (($userinfo['permissions']['avatarmaxwidth'] > 0 or $userinfo['permissions']['avatarmaxheight'] > 0) and ($vbulletin->GPC['resize'] or !($vbulletin->userinfo['permissions']['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel']))) {
             $upload->maxwidth = $userinfo['permissions']['avatarmaxwidth'];
             $upload->maxheight = $userinfo['permissions']['avatarmaxheight'];
         }
         if (!$upload->process_upload($vbulletin->GPC['avatarurl'])) {
             print_modcp_stop_message2(array('there_were_errors_encountered_with_your_upload_x', $upload->fetch_error()));
         }
Example #7
0
 function __construct($registry = NULL, $errtype = NULL)
 {
     parent::__construct($registry, $errtype);
     $this->setStorageOptions('sigpic');
 }