function userAvatar( $option, $uid, $submitvalue) { global $_CB_database, $_CB_framework, $_REQUEST, $ueConfig, $_PLUGINS, $_FILES; if ( ! $uid ) { $uid = $_CB_framework->myId(); } if ( ! $uid ) { echo _UE_NOT_AUTHORIZED; return; } $msg = cbCheckIfUserCanPerformUserTask( $uid, 'allowModeratorsUserEdit'); if ( $msg ) { echo $msg; return; } $row = new moscomprofilerUser( $_CB_database ); if ( ! $row->load( (int) $uid ) ) { echo _UE_NOSUCHPROFILE; return; } $do = cbGetParam( $_REQUEST, 'do', 'init' ); if ( $do == 'init' ) { HTML_comprofiler::userAvatar( $row, $option, $submitvalue); } elseif ( $do == 'validate' ) { // simple spoof check security cbSpoofCheck( 'userAvatar' ); if ( ! $ueConfig['allowAvatarUpload'] ) { cbNotAuth(); return; } $isModerator=isModerator( $_CB_framework->myId() ); if ( ( ! isset( $_FILES['avatar']['tmp_name'] ) ) || empty( $_FILES['avatar']['tmp_name'] ) || ( $_FILES['avatar']['error'] != 0 ) || ( ! is_uploaded_file( $_FILES['avatar']['tmp_name'] ) ) ) { cbRedirectToProfile( $row->id, _UE_UPLOAD_ERROR_EMPTY, 'userAvatar' ); } $_PLUGINS->loadPluginGroup( 'user' ); $_PLUGINS->trigger( 'onBeforeUserAvatarUpdate', array( &$row, &$row, $isModerator, &$_FILES['avatar']['tmp_name'] ) ); if ($_PLUGINS->is_errors()) { cbRedirectToProfile( $row->id, $_PLUGINS->getErrorMSG(), 'userAvatar' ); } $imgToolBox = new imgToolBox(); $imgToolBox->_conversiontype = $ueConfig['conversiontype']; $imgToolBox->_IM_path = $ueConfig['im_path']; $imgToolBox->_NETPBM_path = $ueConfig['netpbm_path']; $imgToolBox->_maxsize = $ueConfig['avatarSize']; $imgToolBox->_maxwidth = $ueConfig['avatarWidth']; $imgToolBox->_maxheight = $ueConfig['avatarHeight']; $imgToolBox->_thumbwidth = $ueConfig['thumbWidth']; $imgToolBox->_thumbheight = $ueConfig['thumbHeight']; $imgToolBox->_debug = 0; $allwaysResize = ( isset( $ueConfig['avatarResizeAlways'] ) ? $ueConfig['avatarResizeAlways'] : 1 ); $newFileName = $imgToolBox->processImage( $_FILES['avatar'], uniqid($row->id."_"), $_CB_framework->getCfg('absolute_path') . '/images/comprofiler/', 0, 0, 1, $allwaysResize ); if ( ! $newFileName ) { cbRedirectToProfile( $row->id, $imgToolBox->_errMSG, 'userAvatar' ); } if ($row->avatar != null && $row->avatar!="") { deleteAvatar($row->avatar); } if ($ueConfig['avatarUploadApproval']==1 && $isModerator==0) { $cbNotification = new cbNotification(); $cbNotification->sendToModerators(_UE_IMAGE_ADMIN_SUB,_UE_IMAGE_ADMIN_MSG); $_CB_database->setQuery("UPDATE #__comprofiler SET avatar='" . $_CB_database->getEscaped($newFileName) . "', avatarapproved=0 WHERE id=" . (int) $row->id); $redMsg = _UE_UPLOAD_PEND_APPROVAL; } else { $_CB_database->setQuery("UPDATE #__comprofiler SET avatar='" . $_CB_database->getEscaped($newFileName) . "', avatarapproved=1, lastupdatedate=". $_CB_database->Quote( $_CB_framework->dateDbOfNow() ) . " WHERE id=" . (int) $row->id); $redMsg = _UE_UPLOAD_SUCCESSFUL; } $_CB_database->query(); $_PLUGINS->trigger( 'onAfterUserAvatarUpdate', array(&$row,&$row,$isModerator,$newFileName) ); cbRedirectToProfile( $row->id, $redMsg ); } elseif ( $do == 'fromgallery' ) { // simple spoof check security cbSpoofCheck( 'userAvatar' ); if( ! $ueConfig['allowAvatarGallery'] ) { cbNotAuth(); return; } $newAvatar = cbGetParam( $_POST, 'newavatar', null ); if ( ( $newAvatar == '' ) || preg_match( '/[^-_a-zA-Z0-9.]/', $newAvatar ) || ( strpos( $newAvatar, '..' ) !== false ) ) { cbRedirectToProfile( $row->id, _UE_UPLOAD_ERROR_CHOOSE, 'userAvatar' ); } $_CB_database->setQuery( "UPDATE #__comprofiler SET avatar = " . $_CB_database->Quote( 'gallery/' . $newAvatar ) . ", avatarapproved=1, lastupdatedate = " . $_CB_database->Quote( $_CB_framework->dateDbOfNow() ) . " WHERE id = " . (int) $row->id); if( ! $_CB_database->query() ) { $msg = _UE_USER_PROFILE_NOT; }else { // delete old avatar: deleteAvatar( $row->avatar ); $msg = _UE_USER_PROFILE_UPDATED; } cbRedirectToProfile( $row->id, $msg ); } elseif ( $do == 'deleteavatar' ) { if ( $row->avatar != null && $row->avatar != "" ) { deleteAvatar( $row->avatar ); $_CB_database->setQuery("UPDATE #__comprofiler SET avatar=null, avatarapproved=1, lastupdatedate=" . $_CB_database->Quote( $_CB_framework->dateDbOfNow() ) . " WHERE id=" . (int) $row->id); $_CB_database->query(); } cbRedirectToProfile( $row->id, _USER_DETAILS_SAVE ); } }
/** * 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(cbReplaceVars(_UE_IMAGE_ADMIN_SUB, $user), cbReplaceVars(_UE_IMAGE_ADMIN_MSG, $user)); $user->{$col} = $newFileName; $user->{$colapproved} = 0; } else { $user->{$col} = $newFileName; $user->{$colapproved} = 1; } $_PLUGINS->trigger('onAfterUserAvatarUpdate', array(&$user, &$user, $isModerator, $newFileName)); } break; } }
/** * prepares and stores group logo * * @param string $file * @return string */ public function storeLogo( $file ) { global $ueConfig; if ( isset( $_FILES[$file]['tmp_name'] ) && ! empty( $_FILES[$file]['tmp_name'] ) && ( $_FILES[$file]['error'] == 0 ) && ( is_uploaded_file( $_FILES[$file]['tmp_name'] ) ) ) { $plugin = cbgjClass::getPlugin(); $logoSize = $plugin->params->get( 'logo_size', 2000 ); $logoWidth = $plugin->params->get( 'logo_width', 200 ); $logoHeight = $plugin->params->get( 'logo_height', 500 ); $logoThumbwidth = $plugin->params->get( 'logo_thumbwidth', 60 ); $logoThumbheight = $plugin->params->get( 'logo_thumbheight', 86 ); $categoryPath = $plugin->imgsAbs . '/' . (int) $this->get( 'category' ); $groupPath = $categoryPath . '/' . (int) $this->get( 'id' ); $mode = cbgjClass::getFilePerms(); cbgjClass::createFolderPath( $plugin->imgsAbs, $categoryPath, $groupPath ); $allwaysResize = ( isset( $ueConfig['avatarResizeAlways'] ) ? $ueConfig['avatarResizeAlways'] : 1 ); $fileNameInDir = preg_replace( '/[^-a-zA-Z0-9_]/', '', uniqid( (int) $this->get( 'user_id' ) . '_' ) ); $imgToolBox = new imgToolBox(); $imgToolBox->_conversiontype = $ueConfig['conversiontype']; $imgToolBox->_IM_path = $ueConfig['im_path']; $imgToolBox->_NETPBM_path = $ueConfig['netpbm_path']; $imgToolBox->_maxsize = (int) ( $logoSize ? $logoSize : $ueConfig['avatarSize'] ); $imgToolBox->_maxwidth = (int) ( $logoWidth ? $logoWidth : $ueConfig['avatarWidth'] ); $imgToolBox->_maxheight = (int) ( $logoHeight ? $logoHeight : $ueConfig['avatarHeight'] ); $imgToolBox->_thumbwidth = (int) ( $logoThumbwidth ? $logoThumbwidth : $ueConfig['thumbWidth'] ); $imgToolBox->_thumbheight = (int) ( $logoThumbheight ? $logoThumbheight : $ueConfig['thumbHeight'] ); $imgToolBox->_debug = 0; $newFileName = $imgToolBox->processImage( $_FILES[$file], $fileNameInDir, $groupPath . '/', 0, 0, 1, $allwaysResize ); if ( $newFileName ) { if ( $this->get( 'logo' ) ) { if ( file_exists( $groupPath . '/' . $this->getCleanLogo() ) ) { @unlink( $groupPath . '/' . $this->getCleanLogo() ); } if ( file_exists( $groupPath . '/tn' . $this->getCleanLogo() ) ) { @unlink( $groupPath . '/tn' . $this->getCleanLogo() ); } } $this->set( 'logo', $newFileName ); @chmod( $groupPath . '/', $this->getCleanLogo(), $mode ); @chmod( $groupPath . '/tn', $this->getCleanLogo(), $mode ); $this->store(); } else { $this->set( '_error', CBTxt::T( str_replace( 'Error: ', '', $imgToolBox->_errMSG ) ) ); } } elseif ( $this->get( 'logo' ) && isset( $this->_previousCategory ) && ( $this->_previousCategory != $this->get( 'category' ) ) ) { $plugin = cbgjClass::getPlugin(); $categoryPath = $plugin->imgsAbs . '/' . (int) $this->get( 'category' ); $groupPath = $categoryPath . '/' . (int) $this->get( 'id' ); $oldCategoryPath = $plugin->imgsAbs . '/' . (int) $this->_previousCategory; $oldGroupPath = $oldCategoryPath . '/' . (int) $this->get( 'id' ); if ( file_exists( $oldGroupPath ) ) { cbgjClass::createFolderPath( $plugin->imgsAbs, $categoryPath, $groupPath ); cbgjClass::copyDirectory( $oldGroupPath, $groupPath ); cbgjClass::deleteDirectory( $oldGroupPath ); } } }
/** * This function is called when a profile owner sumbits a new gallery item * It should perform all validations and upload the file to the correct storage area and * then call the _pgSave() function * $this->_pgProcessNewItem($user->id,$pgautopublish,$pgtotalitems,$pgtotalsize); * * @access private * @param int $id gallery item id * @param object mosUser reflecting the user being displayed */ function _pgProcessNewItem($id,&$user){ global $ueConfig,$_CB_framework; $PGItemAbsolutePath=$_CB_framework->GetCfg( 'absolute_path' ).'/images/comprofiler/plug_profilegallery/'; $html2return = ""; $userid = $user->id; // Get all relevant tab parameters and user settings $tabparams = $this->_pgGetTabParameters($user); $pgitemfilename = $this->_getPagingParamName("pgitemfilename"); $pgitemtitle = $_POST[$this->_getPagingParamName("pgitemtitle")]; $pgitemdescription = $_POST[$this->_getPagingParamName("pgitemdescription")]; $pgitemorder = "999"; // default setting for new feature $upload_pgitem_name = $_FILES[$pgitemfilename]['name']; $upload_pgitem_tmpname = $_FILES[$pgitemfilename]["tmp_name"]; $upload_pgitem_size = $_FILES[$pgitemfilename]["size"]; $upload_pgitem_nameparts = explode(".",$upload_pgitem_name); $upload_pgitem_ext = $upload_pgitem_nameparts[count($upload_pgitem_nameparts)-1]; $upload_pgitem_baseparts = explode("." . $upload_pgitem_ext,$upload_pgitem_name); $upload_pgitem_base = $upload_pgitem_baseparts[0]; $upload_pgitem_base = str_replace(" ", "_", $upload_pgitem_base); $pgitemtype = $upload_pgitem_ext = strtolower($upload_pgitem_ext); // Get last item id for this user $lastitemid = $this->_pgLastItemId($userid); if ($lastitemid != $_POST[$this->_getPagingParamName("pglastitemid")]) { // reload catch @unlink($upload_pgitem_tmpname); $html2return .= '<font color="red">' . CBTxt::Th("No item uploaded!") . "</font><br />"; return $html2return; } // Check for valid upload! if (filesize($upload_pgitem_tmpname) == 0){ $html2return .= '<font color="red">' . CBTxt::Th("No item uploaded!") . "</font><br />"; return $html2return; } list(/*$in_width*/, /*$in_height*/, $in_type, /*$in_attr*/) = getimagesize($upload_pgitem_tmpname); // First check size of uploaded item and stop right away if size has exceeded // maximum allowable if ($upload_pgitem_size > $tabparams["cbpguploadsize"] * 1024) { $html2return .= '<font color="red">' . CBTxt::Th("Maximum allowable single upload size exceeded - gallery item rejected") . "</font><br />"; return $html2return; } // Generate random base name for upload $random_upload_pgitem_base = "pg_" . mt_rand(); // Check file extension type $inimagelist = in_array($upload_pgitem_ext,explode(",",$tabparams["pgimagefiletypelist"])); $infilelist = in_array($upload_pgitem_ext,explode(",",$tabparams["pgotherfiletypelist"])); $consider_imgToolBox = 0; switch ($tabparams["pgopmode"]) { case 'IMAGEMODE': if ( !$inimagelist) { $html2return .= '<font color="red">' . CBTxt::Th("File extension not authorized") . "</font><br />"; return $html2return; } $consider_imgToolBox = 1; break; case 'FILEMODE' : if ( !$infilelist) { $html2return .= '<font color="red">' . CBTxt::Th("File extension not authorized") . "</font><br />"; return $html2return; } $consider_imgToolBox = 0; break; case 'MIXEDMODE' : if ( !$infilelist && !$inimagelist) { $html2return .= '<font color="red">' . CBTxt::Th("File extension not authorized") . "</font><br />"; return $html2return; } if (!$infilelist) { $consider_imgToolBox = 1; } break; default : $consider_imgToolBox = 0; break; } // Categorize uploaded item based on type attribute $imgToolBox_needed_typecheck = 0; if ($consider_imgToolBox) { switch ($in_type) { case 1: // GIF case 2: // JPG case 3: // PNG $imgToolBox_needed_typecheck = 1; break; default: // Other TYPES $imgToolBox_needed_typecheck = 0; if ($pgitemtype == "gif" || $pgitemtype == "jpg" || $pgitemtype == "png") { // trying to upload non image as image extension $html2return .= '<font color="red">' . CBTxt::Th("Bad File - Item rejected") . "</font><br />"; return $html2return; } break; } } // determine if user storage repository has been created (from some previous upload) // if not create it now and give it proper permissions! $mode = octdec( $_CB_framework->getCfg( 'dirperms' ) ); if ( ! $mode ) { $mode = 0755; } $PGItemAbsoluteUserPath = $PGItemAbsolutePath . $userid . "/"; if(!file_exists($PGItemAbsoluteUserPath)){ if(mkdir($PGItemAbsolutePath . $userid,$mode)) { chmod( $PGItemAbsolutePath . $userid , $mode); IF(copy($PGItemAbsolutePath . "index.html", $PGItemAbsoluteUserPath . "index.html")) { // Success action or message would go here } ELSE { //print '<font color="red">' . CBTxt::Th("Failed to be add index.html to the plugin gallery - please contact administrator!") . "</font><br />"; $this->_setError(CBTxt::Th("Failed to be add index.html to the plugin gallery - please contact administrator!")); } $html2return .= "<font color=green>" . CBTxt::Th("Gallery repository successfully created!") . "</font><br />"; } else { $html2return .= '<font color="red">' . CBTxt::Th("Gallery repository could not be created! Please notify system admin!") . "</font><br />"; return $html2return; } } $final_uploaded_fullfilename = $PGItemAbsoluteUserPath . $random_upload_pgitem_base . "." . $upload_pgitem_ext; $final_uploaded_tn_fullfilename = $PGItemAbsoluteUserPath . "tn" . $random_upload_pgitem_base . "." . $upload_pgitem_ext; $final_uploaded_filename = $random_upload_pgitem_base . "." . $upload_pgitem_ext; // Check to see if filename is unique and make it unique if not $unique_suffix = 1; $new_upload_pgitem_base = $random_upload_pgitem_base; while (file_exists($final_uploaded_fullfilename)) { $new_upload_pgitem_base = $random_upload_pgitem_base . "_" . $unique_suffix++; $final_uploaded_fullfilename = $PGItemAbsoluteUserPath . $new_upload_pgitem_base . "." . $upload_pgitem_ext; $final_uploaded_tn_fullfilename = $PGItemAbsoluteUserPath . "tn" . $new_upload_pgitem_base . "." . $upload_pgitem_ext; } $final_uploaded_filename = $new_upload_pgitem_base . "." . $upload_pgitem_ext; if ($imgToolBox_needed_typecheck) { $imgToolBox = new imgToolBox(); $imgToolBox->_conversiontype=$ueConfig['conversiontype']; $imgToolBox->_IM_path = $ueConfig['im_path']; $imgToolBox->_NETPBM_path = $ueConfig['netpbm_path']; $imgToolBox->_maxsize = $tabparams["cbpguploadsize"]; $imgToolBox->_maxwidth = $tabparams["pgmaxwidth"]; $imgToolBox->_maxheight = $tabparams["pgmaxheight"]; $imgToolBox->_thumbwidth = $tabparams["pgtnmaxwidth"]; $imgToolBox->_thumbheight = $tabparams["pgtnmaxheight"]; $imgToolBox->_debug = 0; if ( ! ( $imgToolBox->processImage($_FILES[$this->_getPagingParamName("pgitemfilename")],$new_upload_pgitem_base,$PGItemAbsoluteUserPath, 0, 0, 1 ) ) ) { $html2return .= '<font color="red">' . CBTxt::Th("Image ToolBox failure! - Please notify system admin - ") . $imgToolBox->_errMSG . "</font><br />"; return $html2return; } } else { if (!move_uploaded_file($upload_pgitem_tmpname,$final_uploaded_fullfilename)) { $html2return .= '<font color="red">' . CBTxt::Th("The file upload has failed! - Please notify your system admin!") . "</font><br />"; return $html2return; } } chmod($final_uploaded_fullfilename, 0755); $pgitemsize = filesize($final_uploaded_fullfilename); if ($tabparams["cbpgtotalsize"] + $pgitemsize > $tabparams["cbpgtotalquotasize"] * 1024) { $html2return .= '<font color="red">' . CBTxt::Th("This file would cause you to exceed you quota - gallery item rejected") . "</font><br />"; @unlink($final_uploaded_fullfilename); if (file_exists($final_uploaded_tn_fullfilename)) @unlink($final_uploaded_tn_fullfilename); return $html2return; } $new_cbpgtotalsize = $tabparams["cbpgtotalsize"] + $pgitemsize; $new_cbpgtotalitems = $tabparams["cbpgtotalitems"] + 1; // if we get here it means that we have validated the new entry // and should finally save it to the database $this->_pgSave($id,$pgitemorder,$pgitemtype,$final_uploaded_filename,$pgitemsize,$pgitemtitle,$pgitemdescription,$user,$new_cbpgtotalitems,$new_cbpgtotalsize,$tabparams["cbpgautopublish"],$tabparams["cbpgautoapprove"],$tabparams["pgmoderatornotification"]); $successmessage = ""; if (!$imgToolBox_needed_typecheck) { $successmessage = "<font color=green>" . sprintf(CBTxt::Th('The file %1$s has been successfully uploaded!'),$final_uploaded_filename) . "</font><br />"; } else { $successmessage .= "<font color=green>" . sprintf(CBTxt::Th('The file %1$s has been successfully uploaded and tn%1$s thumbnail created!'),$final_uploaded_filename, $successmessage) . "</font><br />"; } if (!$tabparams["cbpgautoapprove"]) { $successmessage .= "<br />" . "<font color=green>" . CBTxt::Th("Your Gallery item is pending approval by a site moderator.") . "</font><br />"; } return $successmessage; }
/** * Prepares field data for saving to database (safe transfer from $postdata to $user) * 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 profile edit, 'register' for registration, 'search' for searches */ function prepareFieldDataSave( &$field, &$user, &$postdata, $reason ) { global $_CB_framework, $ueConfig, $_PLUGINS, $_FILES; $this->_prepareFieldMetaSave( $field, $user, $postdata, $reason ); $col = $field->name; $colapproved = $col . 'approved'; $col_choice = $col . '__choice'; $col_file = $col . '__file'; $col_gallery = $col . '__gallery'; $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; case 'gallery': $newAvatar = stripslashes( cbGetParam( $postdata, $col_gallery ) ); if ( $this->validate( $field, $user, $choice, $newAvatar, $postdata, $reason ) ) { $value = 'gallery/' . $newAvatar; if ( isset( $user->$col ) ) { $this->_logFieldUpdate( $field, $user, $reason, $user->$col, $value ); } deleteAvatar( $user->$col ); // delete old avatar $user->$col = $value; $user->$colapproved = 1; } break; case 'delete': if ( $user->id && ( $user->$col != null ) && ( $user->$col != '' ) ) { global $_CB_database; if ( isset( $user->$col ) ) { $this->_logFieldUpdate( $field, $user, $reason, $user->$col, '' ); } deleteAvatar( $user->$col ); // delete old avatar $user->$col = null; // this will not update, so we do query below: $user->$colapproved = 1; $query = 'UPDATE ' . $_CB_database->NameQuote( $field->table ) . "\n SET " . $_CB_database->NameQuote( $col ) . ' = NULL' . ', ' . $_CB_database->NameQuote( $col . 'approved' ) . ' = 1' . ', ' . $_CB_database->NameQuote( 'lastupdatedate' ) . ' = ' . $_CB_database->Quote( $_CB_framework->dateDbOfNow() ) . "\n WHERE " . $_CB_database->NameQuote( 'id' ) . ' = ' . (int) $user->id; $_CB_database->setQuery( $query ); $_CB_database->query(); } break; case 'approve': if ( isset( $user->$col ) && ( $_CB_framework->getUi() == 2 ) && $user->id && ( $user->$col != null ) && ( $user->$colapproved == 0 ) ) { $this->_logFieldUpdate( $field, $user, $reason, '', $user->$col ); // here we are missing the old value, so can't give it... $user->$colapproved = 1; $user->lastupdatedate = $_CB_framework->dateDbOfNow(); $cbNotification = new cbNotification(); $cbNotification->sendFromSystem( $user, _UE_IMAGEAPPROVED_SUB, _UE_IMAGEAPPROVED_MSG ); } break; case '': default: $this->validate( $field, $user, $choice, $newAvatar, $postdata, $reason ); break; } }