comprofiler.php
上传用户:stephen_wu
上传日期:2008-07-05
资源大小:1757k
文件大小:77k
- <?php
- /**
- * Joomla/Mambo Community Builder
- * @version $Id: comprofiler.php 609 2006-12-13 17:30:15Z beat $
- * @package Community Builder
- * @subpackage comprofiler.php
- * @author JoomlaJoe and Beat
- * @copyright (C) JoomlaJoe and Beat, www.joomlapolis.com
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU/GPL version 2
- */
- if ( ! ( defined( '_VALID_CB' ) || defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); }
- $memMax = trim( @ini_get( 'memory_limit' ) );
- if ( $memMax ) {
- $last = strtolower( $memMax{strlen( $memMax ) - 1} );
- switch( $last ) {
- case 'g':
- $memMax *= 1024;
- case 'm':
- $memMax *= 1024;
- case 'k':
- $memMax *= 1024;
- }
- if ( $memMax < 16000000 ) {
- @ini_set( 'memory_limit', '16M' );
- }
- }
- /**
- * CB framework
- * @global CBframework $_CB_framework
- */
- global $_CB_framework;
- /** @global mosMainFrame $mainframe
- * @global stdClass $access
- */
- global $mainframe;
- require_once ( $mainframe->getPath( 'front_html' ) );
- /** @global string $_CB_adminpath
- * @global string $_CB_joomla_adminpath
- * @global array $ueConfig
- */
- global $_CB_joomla_adminpath, $_CB_adminpath, $ueConfig;
- if ( defined( 'JPATH_ADMINISTRATOR' ) ) {
- $_CB_joomla_adminpath = JPATH_ADMINISTRATOR;
- $option = JRequest::getString('option');
- $task = JRequest::getString('task');
- } else {
- $_CB_joomla_adminpath = $mainframe->getCfg( 'absolute_path' ). "/administrator";
- global $option, $task;
- }
- $_CB_adminpath = $_CB_joomla_adminpath. "/components/com_comprofiler";
- include_once($_CB_adminpath."/ue_config.php" );
- include_once($_CB_adminpath."/plugin.class.php");
- $_CB_framework->cbset( '_ui', 1 ); // we're in 1: frontend, 2: admin back-end
- if($_CB_framework->getCfg( 'debug' )) {
- ini_set('display_errors',true);
- error_reporting(E_ALL);
- }
- $UElanguagePath = $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/plugin/language';
- $UElanguage = $_CB_framework->getCfg( 'lang' );
- if ( ! file_exists( $UElanguagePath . '/' . $UElanguage . '/' . $UElanguage . '.php' ) ) {
- $UElanguage = 'default_language';
- }
- include_once( $UElanguagePath . '/' . $UElanguage . '/' . $UElanguage . '.php' );
- if ( class_exists( 'JFactory' ) ) { // Joomla 1.5 : for string WARNREG_EMAIL_INUSE used in error js popup.
- $lang =& JFactory::getLanguage();
- $lang->load( "com_user" );
- }
- include_once($_CB_adminpath."/comprofiler.class.php");
- include_once($_CB_adminpath."/imgToolbox.class.php");
- $form = cbGetParam( $_REQUEST, 'reportform', 1 );
- $uid = cbGetParam( $_REQUEST, 'uid', 0 );
- $act = cbGetParam( $_REQUEST, 'act', 1 );
- $oldignoreuserabort = null;
- switch( $task ) {
- case "userDetails":
- case "userdetails":
- userEdit( $option, $uid, _UE_UPDATE );
- break;
- case "saveUserEdit":
- case "saveuseredit":
- $oldignoreuserabort = ignore_user_abort(true);
- userSave( $option, (int) cbGetParam( $_POST, 'id', 0 ) );
- break;
-
- case "userProfile":
- case "userprofile":
- userProfile($option, $_CB_framework->myId(), _UE_UPDATE);
- break;
- case "usersList":
- case "userslist":
- usersList( $_CB_framework->myId() );
- break;
- case "userAvatar":
- case "useravatar":
- userAvatar($option, $uid, _UE_UPDATE);
- break;
- case "lostPassword":
- case "lostpassword":
- lostPassForm( $option );
- break;
- case "sendNewPass":
- case "sendnewpass":
- $oldignoreuserabort = ignore_user_abort(true);
- sendNewPass( $option );
- break;
- case "registers":
- registerForm( $option, isset( $ueConfig['emailpass'] ) ? $ueConfig['emailpass'] : '0' );
- break;
- case "saveregisters":
- $oldignoreuserabort = ignore_user_abort(true);
- saveRegistration( $option );
- break;
- case "login":
- $oldignoreuserabort = ignore_user_abort(true);
- login();
- break;
-
- case "logout":
- $oldignoreuserabort = ignore_user_abort(true);
- logout();
- break;
- case "confirm":
- $oldignoreuserabort = ignore_user_abort(true);
- confirm( cbGetParam( $_GET, 'confirmcode', '1' ) ); // mambo 4.5.3h braindead: does intval of octal from hex in cbGetParam...
- break;
- case "moderateImages":
- case "moderateimages":
- $oldignoreuserabort = ignore_user_abort(true);
- moderateImages($option);
- break;
- case "moderateReports":
- case "moderatereports":
- $oldignoreuserabort = ignore_user_abort(true);
- moderateReports($option);
- break;
- case "moderateBans":
- case "moderatebans":
- $oldignoreuserabort = ignore_user_abort(true);
- moderateBans($option,$act,$uid);
- break;
- case "approveImage":
- case "approveimage":
- $oldignoreuserabort = ignore_user_abort(true);
- approveImage();
- break;
- case "reportUser":
- case "reportuser":
- $oldignoreuserabort = ignore_user_abort(true);
- reportUser($option,$form,$uid);
- break;
- case "processReports":
- case "processreports":
- $oldignoreuserabort = ignore_user_abort(true);
- processReports();
- break;
- case "banProfile":
- case "banprofile":
- $oldignoreuserabort = ignore_user_abort(true);
- banUser($option,$uid,$form,$act);
- break;
- case "viewReports":
- case "viewreports":
- viewReports($option,$uid,$act);
- break;
- case "emailUser":
- case "emailuser":
- emailUser($option,$uid);
- break;
- case "pendingApprovalUser":
- case "pendingapprovaluser":
- pendingApprovalUsers($option);
- break;
- case "approveUser":
- case "approveuser":
- $oldignoreuserabort = ignore_user_abort(true);
- approveUser(cbGetParam($_POST,'uids'));
- break;
- case "rejectUser":
- case "rejectuser":
- $oldignoreuserabort = ignore_user_abort(true);
- rejectUser(cbGetParam($_POST,'uids'));
- break;
- case "sendUserEmail":
- case "senduseremail":
- $oldignoreuserabort = ignore_user_abort(true);
- sendUserEmail( $option, (int) cbGetParam( $_POST, 'toID', 0 ), (int) cbGetParam( $_POST, 'fromID', 0 ), cbGetParam( $_POST, 'emailSubject', '' ), cbGetParam( $_POST, 'emailBody', '' ) );
- break;
- case "addConnection":
- case "addconnection":
- $oldignoreuserabort = ignore_user_abort(true);
- addConnection( $_CB_framework->myId(), (int) cbGetParam($_REQUEST,'connectionid'), ((isset($_POST['message'])) ? cbGetParam($_POST,'message') : ""));
- break;
- case "removeConnection":
- case "removeconnection":
- $oldignoreuserabort = ignore_user_abort(true);
- removeConnection( $_CB_framework->myId(), (int) cbGetParam($_REQUEST, 'connectionid') );
- break;
- case "denyConnection":
- case "denyconnection":
- $oldignoreuserabort = ignore_user_abort(true);
- denyConnection( $_CB_framework->myId(), (int) cbGetParam($_REQUEST,'connectionid'));
- break;
- case "acceptConnection":
- case "acceptconnection":
- $oldignoreuserabort = ignore_user_abort(true);
- acceptConnection( $_CB_framework->myId(), (int) cbGetParam($_REQUEST,'connectionid'));
- break;
- case "manageConnections":
- case "manageconnections":
- manageConnections( $_CB_framework->myId() );
- break;
- case "saveConnections":
- case "saveconnections":
- $oldignoreuserabort = ignore_user_abort(true);
- saveConnections(cbGetParam($_POST,'uid'));
- break;
- case "processConnectionActions":
- case "processconnectionactions":
- $oldignoreuserabort = ignore_user_abort(true);
- processConnectionActions(cbGetParam($_POST,'uid'));
- break;
- case "teamCredits":
- case "teamcredits":
- teamCredits(1);
- break;
- case "fieldclass":
- case "tabclass":
- case "pluginclass":
- tabClass( $option, $task, $_CB_framework->myId() );
- break;
- case "done":
- break;
- case "performcheckusername":
- performCheckUsername( cbGetParam( $_POST, 'value' ), cbGetParam( $_GET, 'function' ) );
- break;
- case "performcheckemail":
- performCheckEmail( cbGetParam( $_POST, 'value' ), cbGetParam( $_GET, 'function' ) );
- break;
- default:
- userProfile($option, $_CB_framework->myId(), _UE_UPDATE);
- break;
- }
- echo $_CB_framework->getAllJsPageCodes();
- if (!is_null($oldignoreuserabort)) ignore_user_abort($oldignoreuserabort);
- // END OF MAIN.
- function sendUserEmail( $option, $toid, $fromid, $subject, $message ) {
- global $ueConfig, $_CB_framework, $_CB_database, $_POST, $_PLUGINS;
- // simple spoof check security
- cbSpoofCheck( 'emailUser' );
- $errorMsg = cbAntiSpamCheck( false );
- if (($_CB_framework->myId() == 0) || ($_CB_framework->myId() != $fromid) || ( ! $toid ) || ($ueConfig['allow_email_display']!=1 && $ueConfig['allow_email_display']!=3)) {
- cbNotAuth();
- return;
- }
- $rowFrom = new moscomprofilerUser( $_CB_database );
- $rowFrom->load( (int) $fromid );
-
- $rowTo = new moscomprofilerUser( $_CB_database );
- $rowTo->load( (int) $toid );
- $subject = stripslashes( $subject ); // cbGetParam() adds slashes...remove'em...
- $message = stripslashes( $message );
-
- if ( ! $errorMsg ) {
- $errorMsg = _UE_SESSIONTIMEOUT . " " . _UE_SENTEMAILFAILED;
- if ( isset( $_POST["protect"] ) ) {
- $parts = explode( '_', cbGetParam( $_POST, 'protect', '' ) );
- if ( ( count( $parts ) == 3 ) && ( $parts[0] == 'cbmv1' ) && ( strlen( $parts[2] ) == 16 ) && ( $parts[1] == md5($parts[2].$rowTo->id.$rowTo->password.$rowTo->lastvisitDate.$rowFrom->password.$rowFrom->lastvisitDate) ) ) {
- $errorMsg = null;
- $_PLUGINS->loadPluginGroup('user');
- $pluginResults = $_PLUGINS->trigger( 'onBeforeEmailUser', array( &$rowFrom, &$rowTo, 1 )); //$ui=1
- if ($_PLUGINS->is_errors()) {
- $errorMsg = $_PLUGINS->getErrorMSG( '<br />') . "n";
- } else {
- $spamCheck = cbSpamProtect( $_CB_framework->myId(), true );
- if ( $spamCheck ) {
- $errorMsg = $spamCheck;
- } else {
- $cbNotification = new cbNotification();
- $res = $cbNotification->sendUserEmail($toid,$fromid,$subject,$message, true);
-
- if ($res) {
- echo _UE_SENTEMAILSUCCESS;
- if (is_array($pluginResults)) {
- echo implode( "<br />", $pluginResults );
- }
- return;
- }
- else {
- $errorMsg = _UE_SENTEMAILFAILED;
- }
- }
- }
- }
- }
- }
- echo '<div class="error">' . $errorMsg . '</div>';
- HTML_comprofiler::emailUser( $option, $rowFrom, $rowTo, $subject, $message );
- }
- function emailUser($option,$uid) {
- global $_CB_framework, $_CB_database, $ueConfig;
- if (($_CB_framework->myId() == 0) || ($ueConfig['allow_email_display']!=1 && $ueConfig['allow_email_display']!=3)) {
- cbNotAuth();
- return;
- }
-
- $spamCheck = cbSpamProtect( $_CB_framework->myId(), false );
- if ( $spamCheck ) {
- echo $spamCheck;
- return;
- }
- $rowFrom = new moscomprofilerUser( $_CB_database );
- $rowFrom->load( $_CB_framework->myId() );
-
- $rowTo = new moscomprofilerUser( $_CB_database );
- $rowTo->load( (int) $uid );
- HTML_comprofiler::emailUser($option,$rowFrom,$rowTo);
- }
- function userEdit( $option, $uid, $submitvalue, $regErrorMSG = null ) {
- global $_CB_framework, $_CB_database, $_POST, $_PLUGINS;
- $msg = cbCheckIfUserCanPerformUserTask( $uid, 'allowModeratorsUserEdit');
- if ( ( $uid != $_CB_framework->myId() ) && ( $msg === null ) ) {
- // safeguard against missconfiguration of the above: also avoids lower-level users editing higher level ones:
- $msg = checkCBpermissions( array( (int) $uid ), 'profile', true );
- }
- if ( $msg ) {
- echo $msg;
- return;
- }
- $_PLUGINS->loadPluginGroup('user');
- $user = new moscomprofilerUser( $_CB_database );
- if ( $user->load( (int) $uid ) ) {
- HTML_comprofiler::userEdit( $user, $option, $submitvalue, $regErrorMSG );
- } else {
- echo '<div class="error">' . _UE_ERROR_USER_NOT_SYNCHRONIZED . '</div>';
- }
- }
- function userSave( $option, $uid ) {
- global $_CB_framework, $_CB_database, $ueConfig, $_POST, $_PLUGINS;
- // simple spoof check security
- cbSpoofCheck( 'userEdit' );
- // check rights to access:
- if ( $uid == null ) {
- echo _UE_USER_PROFILE_NOT;
- return;
- }
- $msg = cbCheckIfUserCanPerformUserTask( $uid, 'allowModeratorsUserEdit' );
- if ( $msg ) {
- echo $msg;
- return;
- }
- $_PLUGINS->loadPluginGroup('user');
- // Get current user state:
- $userComplete = new moscomprofilerUser( $_CB_database );
- if ( ! $userComplete->load( (int) $uid ) ) {
- echo _UE_USER_PROFILE_NOT;
- return;
- }
- // Update lastupdatedate of profile by user:
- if ( $_CB_framework->myId() == $uid ) {
- $userComplete->lastupdatedate = date( 'Y-m-d H:i:s' );
- }
-
- // Store new user state:
- $saveResult = $userComplete->saveSafely( $_POST, $_CB_framework->getUi(), 'profile' );
- if ( ! $saveResult ) {
- $regErrorMSG = $userComplete->getError();
- echo "<script type="text/javascript">alert('" . str_replace( '\\n', '\n', addslashes( strip_tags( str_replace( '<br />', 'n', $regErrorMSG ) ) ) ) . "'); </script>n";
- // userEdit( $option, $uid, _UE_UPDATE, $userComplete->getError() );
- HTML_comprofiler::userEdit( $userComplete, $option, _UE_UPDATE, $regErrorMSG );
- return;
- }
- cbRedirectToProfile( $uid, _USER_DETAILS_SAVE );
- }
- 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='".date('Y-m-dTH:i:s')."' 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( date('Y-m-d H:i:s') )
- . " 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='" . date('Y-m-d H:i:s') . "' WHERE id=" . (int) $row->id);
- $_CB_database->query();
- }
- cbRedirectToProfile( $row->id, _USER_DETAILS_SAVE );
- }
- }
- function & loadComprofilerUser( $uid ) {
- global $_CB_framework, $_CB_database, $_REQUEST;
-
- if ( ! isset( $_REQUEST['user'] ) ) {
- if ( ! $uid ) {
- $null = null;
- return $null;
- }
- } else {
- $userReq = urldecode( stripslashes( cbGetParam( $_REQUEST, 'user' ) ) );
- $len = strlen( $userReq );
- if ( ( $len > 2 ) && ( $userReq[0] == "'" ) && ( $userReq[$len-1] == "'" ) ) {
- $userReq = substr($userReq, 1, $len-2);
- $uid = $_CB_framework->getUserIdFrom( 'username', utf8ToISO( $userReq ) );
- } else {
- $uid = (int) $userReq;
- }
- }
- if ( $uid ) {
- $user = new moscomprofilerUser( $_CB_database );
- if ( $user->load( (int) $uid ) ) {
- return $user;
- }
- }
- $null = null;
- return $null;
- }
- function userProfile( $option, $uid, $submitvalue) {
- global $_CB_database, $_REQUEST, $ueConfig, $_CB_framework;
- if ( isset( $_REQUEST['user'] ) ) {
- if ( ! allowAccess( $ueConfig['allow_profileviewbyGID'], 'RECURSE', userGID( $_CB_framework->myId() ) ) ) {
- if ( ( $_CB_framework->myId() < 1 )
- && ( ! ( ( ( $_CB_framework->getCfg( 'allowUserRegistration' ) == '0' )
- && ( ( ! isset($ueConfig['reg_admin_allowcbregistration']) ) || $ueConfig['reg_admin_allowcbregistration'] != '1' ) )
- )
- )
- &&
- allowAccess( $ueConfig['allow_profileviewbyGID'], 'RECURSE', $_CB_framework->acl->get_group_id('Registered','ARO') )
- ) {
- echo _UE_REGISTERFORPROFILEVIEW;
- } else {
- echo _UE_NOT_AUTHORIZED;
- }
- return;
- }
- } else {
- if ($uid==0) {
- echo _UE_REGISTERFORPROFILE;
- return;
- }
- }
- $user = loadComprofilerUser( $uid );
- if ( $user === null ) {
- echo _UE_NOSUCHPROFILE;
- return;
- }
- HTML_comprofiler::userProfile( $user, $option, $submitvalue);
- }
- // NB for now duplicated in frontend an admin backend:
- function tabClass( $option, $task, $uid ) {
- global $_CB_framework, $_PLUGINS, $_REQUEST, $_POST;
- $user = loadComprofilerUser( $uid );
- $unsecureChars = array( '/', '\', ':', ';', '{', '}', '(', ')', """, "'", '.', ',', "