Project

General

Profile

Bug #2766 » cb.core.patch

krileon, 26 October 2011 16:19

View differences:

components/com_comprofiler/plugin/user/plug_cbcore/cb.core.php
case 'upload':
$value = ( isset( $_FILES[$col_file] ) ? $_FILES[$col_file] : null );
if ( $this->validate( $field, $user, $choice, $value, $postdata, $reason ) ) {
$_PLUGINS->loadPluginGroup( 'user' );
$isModerator = isModerator( $_CB_framework->myId() );
$_PLUGINS->trigger( 'onBeforeUserAvatarUpdate', array( &$user, &$user, $isModerator, &$value['tmp_name'] ) );
if ( $_PLUGINS->is_errors() ) {
$this->_setErrorMSG( $_PLUGINS->getErrorMSG() );
}
$imgToolBox = new imgToolBox();
$imgToolBox->_conversiontype = $ueConfig['conversiontype'];
$imgToolBox->_IM_path = $ueConfig['im_path'];
$imgToolBox->_NETPBM_path = $ueConfig['netpbm_path'];
$imgToolBox->_maxsize = $this->_getImageFieldParam( $field, 'avatarSize' );
$imgToolBox->_maxwidth = $this->_getImageFieldParam( $field, 'avatarWidth' );
$imgToolBox->_maxheight = $this->_getImageFieldParam( $field, 'avatarHeight' );
$imgToolBox->_thumbwidth = $this->_getImageFieldParam( $field, 'thumbWidth' );
$imgToolBox->_thumbheight = $this->_getImageFieldParam( $field, 'thumbHeight' );
$imgToolBox->_debug = 0;
$allwaysResize = ( isset( $ueConfig['avatarResizeAlways'] ) ? $ueConfig['avatarResizeAlways'] : 1 );
$fileNameInDir = ( $col == 'avatar' ? '' : $col . '_' ) . uniqid( $user->id . '_' );
$newFileName = $imgToolBox->processImage( $value, $fileNameInDir, $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/', 0, 0, 1, $allwaysResize );
if ( ! $newFileName ) {
$this->_setValidationError( $field, $user, $reason, $imgToolBox->_errMSG ); // needed if uploaded file fails in imgToolbox
//BB: maybe this needed instead ? :
// $this->_setErrorMSG( $imgToolBox->_errMSG );
return;
}
if ( isset( $user->$col ) && ! ( ( $col == 'avatar' ) && ( $ueConfig['avatarUploadApproval'] == 1 ) && ( $isModerator == 0 ) ) ) {
// if auto-approved: //TBD: else need to log update on image approval !
$this->_logFieldUpdate( $field, $user, $reason, $user->$col, $newFileName );
}
if ( isset( $user->$col ) && ( $user->$col != '' ) ) {
deleteAvatar( $user->$col );
}
if ( ( $col == 'avatar' ) && ( $ueConfig['avatarUploadApproval'] == 1 ) && ( $isModerator == 0 ) ) {
$cbNotification = new cbNotification();
$cbNotification->sendToModerators( _UE_IMAGE_ADMIN_SUB, _UE_IMAGE_ADMIN_MSG );
$user->$col = $newFileName;
$user->$colapproved = 0;
} else {
$user->$col = $newFileName;
$user->$colapproved = 1;
}
$_PLUGINS->trigger( 'onAfterUserAvatarUpdate', array( &$user, &$user, $isModerator, $newFileName ) );
}
// Image is uploaded in the commit, but lets validate it here as well:
$this->validate( $field, $user, $choice, $value, $postdata, $reason );
break;
case 'gallery':
$newAvatar = stripslashes( cbGetParam( $postdata, $col_gallery ) );
......
}
/**
* Mutator:
* Prepares field data commit
* Override
*
* @param moscomprofilerFields $field
* @param moscomprofilerUser $user RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit)
* @param array $postdata Typically $_POST (but not necessarily), filtering required.
* @param string $reason 'edit' for save user edit, 'register' for save registration
*/
function commitFieldDataSave( &$field, &$user, &$postdata, $reason ) {
global $_CB_framework, $ueConfig, $_PLUGINS, $_FILES;
$col = $field->name;
$colapproved = $col . 'approved';
$col_choice = $col . '__choice';
$col_file = $col . '__file';
$choice = stripslashes( cbGetParam( $postdata, $col_choice ) );
switch ( $choice ) {
case 'upload':
$value = ( isset( $_FILES[$col_file] ) ? $_FILES[$col_file] : null );
if ( $this->validate( $field, $user, $choice, $value, $postdata, $reason ) ) {
$_PLUGINS->loadPluginGroup( 'user' );
$isModerator = isModerator( $_CB_framework->myId() );
$_PLUGINS->trigger( 'onBeforeUserAvatarUpdate', array( &$user, &$user, $isModerator, &$value['tmp_name'] ) );
if ( $_PLUGINS->is_errors() ) {
$this->_setErrorMSG( $_PLUGINS->getErrorMSG() );
}
$imgToolBox = new imgToolBox();
$imgToolBox->_conversiontype = $ueConfig['conversiontype'];
$imgToolBox->_IM_path = $ueConfig['im_path'];
$imgToolBox->_NETPBM_path = $ueConfig['netpbm_path'];
$imgToolBox->_maxsize = $this->_getImageFieldParam( $field, 'avatarSize' );
$imgToolBox->_maxwidth = $this->_getImageFieldParam( $field, 'avatarWidth' );
$imgToolBox->_maxheight = $this->_getImageFieldParam( $field, 'avatarHeight' );
$imgToolBox->_thumbwidth = $this->_getImageFieldParam( $field, 'thumbWidth' );
$imgToolBox->_thumbheight = $this->_getImageFieldParam( $field, 'thumbHeight' );
$imgToolBox->_debug = 0;
$allwaysResize = ( isset( $ueConfig['avatarResizeAlways'] ) ? $ueConfig['avatarResizeAlways'] : 1 );
$fileNameInDir = ( $col == 'avatar' ? '' : $col . '_' ) . uniqid( $user->id . '_' );
$newFileName = $imgToolBox->processImage( $value, $fileNameInDir, $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/', 0, 0, 1, $allwaysResize );
if ( ! $newFileName ) {
$this->_setValidationError( $field, $user, $reason, $imgToolBox->_errMSG ); // needed if uploaded file fails in imgToolbox
//BB: maybe this needed instead ? :
// $this->_setErrorMSG( $imgToolBox->_errMSG );
return;
}
if ( isset( $user->$col ) && ! ( ( $col == 'avatar' ) && ( $ueConfig['avatarUploadApproval'] == 1 ) && ( $isModerator == 0 ) ) ) {
// if auto-approved: //TBD: else need to log update on image approval !
$this->_logFieldUpdate( $field, $user, $reason, $user->$col, $newFileName );
}
if ( isset( $user->$col ) && ( $user->$col != '' ) ) {
deleteAvatar( $user->$col );
}
if ( ( $col == 'avatar' ) && ( $ueConfig['avatarUploadApproval'] == 1 ) && ( $isModerator == 0 ) ) {
$cbNotification = new cbNotification();
$cbNotification->sendToModerators( _UE_IMAGE_ADMIN_SUB, _UE_IMAGE_ADMIN_MSG );
$user->$col = $newFileName;
$user->$colapproved = 0;
} else {
$user->$col = $newFileName;
$user->$colapproved = 1;
}
$_PLUGINS->trigger( 'onAfterUserAvatarUpdate', array( &$user, &$user, $isModerator, $newFileName ) );
}
break;
}
}
/**
* Mutator:
* Prepares field data rollback
* Override
*
* @param moscomprofilerFields $field
* @param moscomprofilerUser $user RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit)
* @param array $postdata Typically $_POST (but not necessarily), filtering required.
* @param string $reason 'edit' for save user edit, 'register' for save registration
*/
function rollbackFieldDataSave( &$field, &$user, &$postdata, $reason ) {
global $_CB_framework, $ueConfig, $_PLUGINS, $_FILES;
$col = $field->name;
$colapproved = $col . 'approved';
$col_choice = $col . '__choice';
$col_file = $col . '__file';
$choice = stripslashes( cbGetParam( $postdata, $col_choice ) );
switch ( $choice ) {
case 'upload':
$value = ( isset( $_FILES[$col_file] ) ? $_FILES[$col_file] : null );
if ( $this->validate( $field, $user, $choice, $value, $postdata, $reason ) ) {
deleteAvatar( $user->$col );
}
break;
}
}
/**
* Validator:
* Validates $value for $field->required and other rules
* Override
(1-1/4)