예제 #1
0
	/**
	 * Sends a PM or Email notification with substitutions based off configuration
	 *
	 * @param int                  $type 1: Email, 2: PM, 3: Moderators, 4: Auto
	 * @param UserTable|int|null   $from
	 * @param UserTable|int|string $to
	 * @param string               $subject
	 * @param string               $body
	 * @param GroupTable           $group
	 * @param array                $extra
	 * @return bool
	 */
	static public function sendNotification( $type, $from, $to, $subject, $body, $group, $extra = array() )
	{
		global $_CB_framework, $_PLUGINS;

		if ( ( ! $subject ) || ( ! $body ) || ( ! $group->get( 'id' ) ) || ( $group->get( 'published', 1 ) != 1 ) || ( ! $group->category()->get( 'published', 1 ) ) || ( ! $to ) ) {
			return false;
		}

		if ( $from instanceof UserTable ) {
			$fromUser			=	$from;
		} elseif ( is_int( $from ) ) {
			$fromUser			=	\CBuser::getUserDataInstance( $from );
		} else {
			$fromUser			=	null;
		}

		if ( $to instanceof UserTable ) {
			$toUser				=	$to;
		} elseif ( is_int( $to ) ) {
			$toUser				=	\CBuser::getUserDataInstance( $to );
		} else {
			$toUser				=	null;
		}

		if ( $fromUser && $toUser && ( $fromUser->get( 'id' ) == $toUser->get( 'id' ) ) ) {
			return false;
		}

		static $plugin			=	null;
		static $params			=	null;

		if ( ! $params ) {
			$plugin				=	$_PLUGINS->getLoadedPlugin( 'user', 'cbgroupjive' );
			$params				=	$_PLUGINS->getPluginParams( $plugin );
		}

		$notifyBy				=	(int) $params->get( 'notifications_notifyby', 1 );
		$fromName				=	$params->get( 'notifications_from_name', null );
		$fromEmail				=	$params->get( 'notifications_from_address', null );
		$cbUser					=	\CBuser::getInstance( ( $fromUser ? (int) $fromUser->get( 'id' ) : ( $toUser ? (int) $toUser->get( 'id' ) : 0 ) ), false );
		$user					=	$cbUser->getUserData();

		$extras					=	array(	'category_id'		=>	(int) $group->category()->get( 'id' ),
											'category_name'		=>	( $group->category()->get( 'id' ) ? CBTxt::T( $group->category()->get( 'name' ) ) : CBTxt::T( 'Uncategorized' ) ),
											'category'			=>	'<a href="' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'categories', 'func' => 'show', 'id' => (int) $group->get( 'category' ) ) ) . '">' . ( $group->category()->get( 'id' ) ? CBTxt::T( $group->category()->get( 'name' ) ) : CBTxt::T( 'Uncategorized' ) ) . '</a>',
											'group_id'			=>	(int) $group->get( 'id' ),
											'group_name'		=>	htmlspecialchars( CBTxt::T( $group->get( 'name' ) ) ),
											'group'				=>	'<a href="' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ) . '">' . htmlspecialchars( CBTxt::T( $group->get( 'name' ) ) ) . '</a>',
											'user'				=>	'<a href="' . $_CB_framework->viewUrl( 'userprofile', false, array( 'user' => (int) $user->get( 'id' ) ) ) . '">' . getNameFormat( $user->get( 'name' ), $user->get( 'username' ), Application::Config()->get( 'name_format', 3 ) ) . '</a>'
										);

		if ( ! $toUser ) {
			$extras['email']	=	$to;
			$extras['name']		=	$to;
			$extras['username']	=	$to;
		}

		$extras					=	array_merge( $extras, $extra );
		$subject				=	$cbUser->replaceUserVars( $subject, true, false, $extras, false );
		$body					=	$cbUser->replaceUserVars( $body, false, false, $extras, false );

		if ( $type == 4 ) {
			$type				=	( $notifyBy == 2 ? 2 : 1 );
		}

		$notification			=	new \cbNotification();

		if ( $type == 3 ) {
			// Moderator Notification:
			$notification->sendToModerators( $subject, $body, false, 1 );
		} elseif ( ( $type == 2 ) && $toUser ) {
			// PM Notification:
			if ( ! $toUser->get( 'id' ) ) {
				return false;
			}

			$notification->sendUserPMSmsg( $toUser, 0, $subject, $body, true, false, 1, $extras );
		} else {
			// Email Notification:
			if ( $toUser ) {
				if ( ! $toUser->get( 'id' ) ) {
					return false;
				}

				$notification->sendFromSystem( $toUser, $subject, $body, 1, 1, null, null, null, $extras, true, $fromName, $fromEmail );
			} else {
				$userTo			=	new UserTable();

				$userTo->set( 'email', $to );
				$userTo->set( 'name', $to );
				$userTo->set( 'username', $to );

				$notification->sendFromSystem( $userTo, $subject, $body, 1, 1, null, null, null, $extras, true, $fromName, $fromEmail );
			}
		}

		return true;
	}
 /**
  * Activates a user
  * user plugins must have been loaded
  *
  * @param  UserTable  $user
  * @param  int        $ui               1=frontend, 2=backend, 0=no UI: machine-machine UI
  * @param  string     $cause            (one of: 'UserRegistration', 'UserConfirmation', 'UserApproval', 'NewUser', 'UpdateUser')
  * @param  boolean    $mailToAdmins     true if the standard new-user email should be sent to admins if moderator emails are enabled
  * @param  boolean    $mailToUser       true if the welcome new user email (from CB config) should be sent to the new user
  * @param  boolean    $triggerBeforeActivate
  * @return array                        Texts to display
  */
 function activateUser(&$user, $ui, $cause, $mailToAdmins = true, $mailToUser = true, $triggerBeforeActivate = true)
 {
     global $ueConfig, $_PLUGINS;
     static $notificationsSent = array();
     $activate = $user->confirmed && $user->approved == 1;
     $showSysMessage = true;
     $savedLanguage = CBTxt::setLanguage($user->getUserLanguage());
     $messagesToUser = getActivationMessage($user, $cause);
     CBTxt::setLanguage($savedLanguage);
     if ($cause == 'UserConfirmation' && $user->approved == 0) {
         $activate = false;
         $msg = array('emailAdminSubject' => array('sys' => CBTxt::T('UE_REG_ADMIN_PA_SUB', 'ACTION REQUIRED! New user sign up request pending approval')), 'emailAdminMessage' => array('sys' => CBTxt::T('UE_REG_ADMIN_PA_MSG', "A new user has signed up at [SITEURL] and requires approval.\nThis email contains their details\n\nName - [NAME]\nE-mail - [EMAILADDRESS]\nUsername - [USERNAME]\n\n\nPlease do not respond to this message as it is automatically generated and is for informational purposes only.\n")), 'emailUserSubject' => array(), 'emailUserMessage' => array());
     } elseif ($user->confirmed == 0) {
         $msg = array('emailAdminSubject' => array(), 'emailAdminMessage' => array());
         $savedLanguage = CBTxt::setLanguage($user->getUserLanguage());
         $msg['emailUserSubject'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_pend_appr_sub'])));
         $msg['emailUserMessage'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_pend_appr_msg'])));
         CBTxt::setLanguage($savedLanguage);
     } elseif ($cause == 'SameUserRegistrationAgain') {
         $activate = false;
         $msg = array('emailAdminSubject' => array(), 'emailAdminMessage' => array(), 'emailUserSubject' => array(), 'emailUserMessage' => array());
     } elseif ($user->confirmed && !($user->approved == 1)) {
         $msg = array('emailAdminSubject' => array('sys' => CBTxt::T('UE_REG_ADMIN_PA_SUB', 'ACTION REQUIRED! New user sign up request pending approval')), 'emailAdminMessage' => array('sys' => CBTxt::T('UE_REG_ADMIN_PA_MSG', "A new user has signed up at [SITEURL] and requires approval.\nThis email contains their details\n\nName - [NAME]\nE-mail - [EMAILADDRESS]\nUsername - [USERNAME]\n\n\nPlease do not respond to this message as it is automatically generated and is for informational purposes only.\n")));
         $savedLanguage = CBTxt::setLanguage($user->getUserLanguage());
         $msg['emailUserSubject'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_pend_appr_sub'])));
         $msg['emailUserMessage'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_pend_appr_msg'])));
         CBTxt::setLanguage($savedLanguage);
     } elseif ($user->confirmed && $user->approved == 1) {
         $msg = array('emailAdminSubject' => array('sys' => CBTxt::T('UE_REG_ADMIN_SUB', 'New user sign up')), 'emailAdminMessage' => array('sys' => CBTxt::T('UE_REG_ADMIN_MSG', "A new user has signed up at [SITEURL].\nThis email contains their details\n\nName - [NAME]\nE-mail - [EMAILADDRESS]\nUsername - [USERNAME]\n\n\nPlease do not respond to this message as it is automatically generated and is for information purposes only.\n")));
         $savedLanguage = CBTxt::setLanguage($user->getUserLanguage());
         $msg['emailUserSubject'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_welcome_sub'])));
         $msg['emailUserMessage'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_welcome_msg'])));
         CBTxt::setLanguage($savedLanguage);
     }
     $msg['messagesToUser'] = $messagesToUser;
     if ($triggerBeforeActivate) {
         $results = $_PLUGINS->trigger('onBeforeUserActive', array(&$user, $ui, $cause, $mailToAdmins, $mailToUser));
         if ($_PLUGINS->is_errors() && $ui != 0) {
             echo $_PLUGINS->getErrorMSG('<br />');
         }
         foreach ($results as $res) {
             if (is_array($res)) {
                 $activate = $activate && $res['activate'];
                 $mailToAdmins = $mailToAdmins && $res['mailToAdmins'];
                 $mailToUser = $mailToUser && $res['mailToUser'];
                 $showSysMessage = $showSysMessage && $res['showSysMessage'];
                 foreach (array_keys($msg) as $key) {
                     if (isset($res[$key]) && $res[$key]) {
                         array_push($msg[$key], $res[$key]);
                     }
                 }
             }
         }
         if (!($mailToAdmins && $ueConfig['moderatorEmail'] == 1)) {
             unset($msg['emailAdminSubject']['sys']);
             unset($msg['emailAdminMessage']['sys']);
         }
         if (!$mailToUser) {
             unset($msg['emailUserSubject']['sys']);
             unset($msg['emailUserMessage']['sys']);
         }
         if (!$showSysMessage) {
             unset($msg['messagesToUser']['sys']);
         }
     }
     if ($activate) {
         $user->block = 0;
         $user->storeBlock(false);
         $user->removeActivationCode();
     }
     if ($activate) {
         $_PLUGINS->trigger('onUserActive', array(&$user, $ui, $cause, $mailToAdmins, $mailToUser));
         if ($_PLUGINS->is_errors() && $ui != 0) {
             $msg['messagesToUser'] = $_PLUGINS->getErrorMSG('<br />') . $msg['messagesToUser'];
         }
     }
     if (!isset($notificationsSent[$user->id][$user->confirmed][$user->approved][$user->block])) {
         // in case done several times (e.g. plugins), avoid resending messages.
         $cbNotification = new cbNotification();
         if ($ueConfig['moderatorEmail'] && count($msg['emailAdminMessage'])) {
             $pwd = $user->password;
             $user->password = null;
             $cbNotification->sendToModerators(implode(', ', $msg['emailAdminSubject']), $cbNotification->_replaceVariables(implode('\\n\\n', $msg['emailAdminMessage']), $user));
             $user->password = $pwd;
         }
         if (count($msg['emailUserMessage'])) {
             $cbNotification->sendFromSystem($user, implode(', ', $msg['emailUserSubject']), implode('\\n\\n', $msg['emailUserMessage']), true, isset($ueConfig['reg_email_html']) ? (int) $ueConfig['reg_email_html'] : 0);
         }
         $notificationsSent[$user->id][$user->confirmed][$user->approved][$user->block] = true;
     }
     return $msg['messagesToUser'];
 }
예제 #3
0
	/**
	 * @param  null|int     $id
	 * @param  UserTable    $user
	 * @param  stdClass     $model
	 * @param  PluginTable  $plugin
	 */
	private function saveBlogEdit( $id, $user, $model, $plugin )
	{
		global $_CB_framework, $_PLUGINS;

		$blogLimit					=	(int) $plugin->params->get( 'blog_limit', null );
		$cbModerator				=	Application::User( (int) $user->get( 'id' ) )->isGlobalModerator();

		$row						=	new cbblogsBlogTable();

		$canAccess					=	false;

		if ( $row->load( (int) $id ) ) {
			if ( ! $row->get( 'id' ) ) {
				if ( $cbModerator ) {
					$canAccess		=	true;
				} elseif ( $user->get( 'id' ) && Application::MyUser()->canViewAccessLevel( $plugin->params->get( 'blog_create_access', 2 ) ) ) {
					if ( ( ! $blogLimit ) || ( $blogLimit && ( cbblogsModel::getBlogsTotal( null, $user, $user, $plugin ) < $blogLimit ) ) ) {
						$canAccess	=	true;
					}
				}
			} elseif ( $cbModerator || ( $row->get( 'user' ) == $user->get( 'id' ) ) ) {
				$canAccess			=	true;
			}
		}

		$profileUrl					=	$_CB_framework->userProfileUrl( $row->get( 'user', $user->get( 'id' ) ), false, 'cbblogsTab' );

		if ( $canAccess ) {
			if ( $plugin->params->get( 'blog_captcha', 0 ) && ( ! $row->get( 'id' ) ) && ( ! $cbModerator ) ) {
				$_PLUGINS->loadPluginGroup( 'user' );

				$_PLUGINS->trigger( 'onCheckCaptchaHtmlElements', array() );

				if ( $_PLUGINS->is_errors() ) {
					$row->setError( CBTxt::T( $_PLUGINS->getErrorMSG() ) );
				}
			}

			$new					=	( $row->get( 'id' ) ? false : true );

			if ( ! $row->bind( $_POST ) ) {
				$this->showBlogEdit( $id, $user, $model, $plugin, CBTxt::T( 'BLOG_FAILED_TO_BIND_ERROR_ERROR', 'Blog failed to bind! Error: [error]', array( '[error]' => $row->getError() ) ) ); return;
			}

			if ( ! $row->check() ) {
				$this->showBlogEdit( $id, $user, $model, $plugin, CBTxt::T( 'BLOG_FAILED_TO_VALIDATE_ERROR_ERROR', 'Blog failed to validate! Error: [error]', array( '[error]' => $row->getError() ) ) ); return;
			}

			if ( $row->getError() || ( ! $row->store() ) ) {
				$this->showBlogEdit( $id, $user, $model, $plugin, CBTxt::T( 'BLOG_FAILED_TO_SAVE_ERROR_ERROR', 'Blog failed to save! Error: [error]', array( '[error]' => $row->getError() ) ) ); return;
			}

			if ( $new && ( ! $row->get( 'published' ) ) && $plugin->params->get( 'approval_notify', 1 ) && ( ! $cbModerator ) ) {
				$cbUser				=	CBuser::getInstance( (int) $row->get( 'user' ), false );

				$extraStrings		=	array(	'site_name' => $_CB_framework->getCfg( 'sitename' ),
												'site' => '<a href="' . $_CB_framework->getCfg( 'live_site' ) . '">' . $_CB_framework->getCfg( 'sitename' ) . '</a>',
												'blog_id' => (int) $row->get( 'id' ),
												'blog_title' => $row->get( 'title' ),
												'blog_intro' => $row->get( 'blog_intro' ),
												'blog_full' => $row->get( 'blog_full' ),
												'blog_created' => $row->get( 'blog_created' ),
												'blog_user' => (int) $row->get( 'user' ),
												'blog_url' => cbblogsModel::getUrl( $row ),
												'blog_tab_url' => $_CB_framework->viewUrl( 'userprofile', false, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbblogsTab' ) ),
												'user_name' => $cbUser->getField( 'formatname', null, 'html', 'none', 'profile' ),
												'user' => '<a href="' . $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ) ) ) . '">' . $cbUser->getField( 'formatname', null, 'html', 'none', 'profile' ) . '</a>'
											);

				$subject			=	$cbUser->replaceUserVars( CBTxt::T( 'Blogs - New Blog Created!' ), false, true, $extraStrings, false );
				$message			=	$cbUser->replaceUserVars( CBTxt::T( '[user] created [blog_title] and requires <a href="[blog_tab_url]">approval</a>!' ), false, true, $extraStrings, false );

				$notifications		=	new cbNotification();

				$notifications->sendToModerators( $subject, $message, false, 1 );
			}

			cbRedirect( $profileUrl, CBTxt::T( 'Blog saved successfully!' ) );
		} else {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}
	}
예제 #4
0
 /**
  * Mutator:
  * Prepares field data commit
  * Override
  *
  * @param  FieldTable  $field
  * @param  UserTable   $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
  */
 public 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 = Application::MyUser()->isModeratorFor(Application::User((int) $user->id));
                 $_PLUGINS->trigger('onBeforeUserAvatarUpdate', array(&$user, &$user, $isModerator, &$value['tmp_name']));
                 if ($_PLUGINS->is_errors()) {
                     $this->_setErrorMSG($_PLUGINS->getErrorMSG());
                 }
                 $conversionType = (int) (isset($ueConfig['conversiontype']) ? $ueConfig['conversiontype'] : 0);
                 $imageSoftware = $conversionType == 5 ? 'gmagick' : ($conversionType == 1 ? 'imagick' : 'gd');
                 $imagePath = $_CB_framework->getCfg('absolute_path') . '/images/comprofiler/';
                 $fileName = ($col == 'avatar' ? '' : $col . '_') . uniqid($user->id . '_');
                 try {
                     $image = new \CBLib\Image\Image($imageSoftware, $this->_getImageFieldParam($field, 'avatarResizeAlways', 1), $this->_getImageFieldParam($field, 'avatarMaintainRatio', 1));
                     $image->setName($fileName);
                     $image->setSource($value);
                     $image->setDestination($imagePath);
                     $image->processImage($this->_getImageFieldParam($field, 'avatarWidth', 200), $this->_getImageFieldParam($field, 'avatarHeight', 500));
                     $newFileName = $image->getCleanFilename();
                     $image->setName('tn' . $fileName);
                     $image->processImage($this->_getImageFieldParam($field, 'thumbWidth', 60), $this->_getImageFieldParam($field, 'thumbHeight', 86));
                 } catch (Exception $e) {
                     $this->_setValidationError($field, $user, $reason, $e->getMessage());
                     return;
                 }
                 $uploadApproval = $this->_getImageFieldParam($field, 'avatarUploadApproval', 1);
                 if (isset($user->{$col}) && !($uploadApproval == 1 && !$isModerator)) {
                     // 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 ($uploadApproval == 1 && !$isModerator) {
                     $cbNotification = new cbNotification();
                     $cbNotification->sendToModerators(cbReplaceVars(CBTxt::T('UE_IMAGE_ADMIN_SUB', 'Image Pending Approval'), $user), cbReplaceVars(CBTxt::T('UE_IMAGE_ADMIN_MSG', 'A user has submitted an image for approval. Please log in and take the appropriate action.'), $user));
                     $user->{$col} = $newFileName;
                     $user->{$colapproved} = 0;
                 } else {
                     $user->{$col} = $newFileName;
                     $user->{$colapproved} = 1;
                 }
                 $_PLUGINS->trigger('onAfterUserAvatarUpdate', array(&$user, &$user, $isModerator, $newFileName));
             }
             break;
     }
 }
	/**
	 * @param int       $userId
	 * @param UserTable $user
	 * @return mixed
	 */
	public function deleteUser( $userId, $user )
	{
		global $_CB_framework, $_PLUGINS;

		if ( ! $userId ) {
			$userId					=	$user->get( 'id' );
		}

		$profileUrl					=	$_CB_framework->userProfileUrl( $userId, false );

		if ( ! $userId ) {
			$profileUrl				=	'index.php';
		}

		if ( $this->getDeleteField( $userId, $user ) ) {
			$cbUser					=	CBuser::getInstance( $userId, false );
			$deleteUser				=	$cbUser->getUserData();

			$_PLUGINS->trigger( 'privacy_onBeforeAccountDelete', array( &$deleteUser, $user ) );

			if ( $deleteUser->delete( $userId ) ) {
				$closed				=	new cbprivacyClosedTable();

				$closed->set( 'user_id', (int) $deleteUser->get( 'id' ) );
				$closed->set( 'username', $deleteUser->get( 'username' ) );
				$closed->set( 'name', $deleteUser->get( 'name' ) );
				$closed->set( 'email', $deleteUser->get( 'email' ) );
				$closed->set( 'type', 'delete' );
				$closed->set( 'date', $_CB_framework->getUTCDate() );
				$closed->set( 'reason', $this->input( 'reason', null, GetterInterface::STRING ) );

				$closed->store();

				$notification		=	new cbNotification();

				$extra				=	array(	'ip_address' => cbGetIPlist(),
												'reason' => $closed->get( 'reason' ),
												'date' => $closed->get( 'date' )
											);

				$subject			=	$cbUser->replaceUserVars( CBTxt::T( 'User Account Deleted' ), true, false, $extra, false );
				$body				=	$cbUser->replaceUserVars( CBTxt::T( 'Name: [name]<br />Username: [username]<br />Email: [email]<br />IP Address: [ip_address]<br />Date: [date]<br /><br />[reason]<br /><br />' ), false, false, $extra, false );

				if ( $subject && $body ) {
					$notification->sendToModerators( $subject, $body, false, 1 );
				}

				$subject			=	CBTxt::T( 'Your Account has been Deleted' );
				$body				=	CBTxt::T( 'This is a notice that your account [username] on [siteurl] has been deleted.' );

				if ( $subject && $body ) {
					$notification->sendFromSystem( $deleteUser, $subject, $body, true, 1, null, null, null, $extra );
				}

				$_PLUGINS->trigger( 'privacy_onAfterAccountDelete', array( $deleteUser, $user ) );

				cbRedirect( 'index.php', CBTxt::T( 'Account deleted successfully!' ) );
			} else {
				cbRedirect( $profileUrl, CBTxt::T( 'ACCOUNT_FAILED_TO_DELETE', 'Account failed to delete! Error: [error]', array( '[error]' => $deleteUser->getError() ) ), 'error' );
			}
		}

		cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
	}
예제 #6
0
function banUser( $option, $uid, $form=1, $act=1 ) {
	global $_CB_framework, $_CB_database, $ueConfig, $_POST;

	$isModerator=isModerator( $_CB_framework->myId() );
	if ( ( $_CB_framework->myId() < 1 ) || ( $uid < 1 ) )  {
			cbNotAuth();
			exit();
	}
	if ( $ueConfig['allowUserBanning'] == 0 ) {
			echo _UE_FUNCTIONALITY_DISABLED;
			exit();
	}

	if ( $form == 1 ) {
		$_CB_database->setQuery( "SELECT bannedreason FROM #__comprofiler WHERE id = " . (int) $uid );
		$orgbannedreason	=	$_CB_database->loadresult();

		HTML_comprofiler::banUserForm( $option, $uid, $act, $orgbannedreason);
	} else {

		$now				=	$_CB_framework->now();
		$dateStr			=	cbFormatDate( $now );

		$cbNotification		=	new cbNotification();
		if ( $act == 1 ) {
			// Ban by moderator:
			if ( ( ! $isModerator ) || ( $_CB_framework->myId() != cbGetParam( $_POST, 'bannedby', 0 ) ) ) {
				cbNotAuth();
				return;
			}
			// simple spoof check security
			cbSpoofCheck( 'banUserForm' );

			$bannedreason	=	'<b>' . htmlspecialchars("["._UE_MODERATORBANRESPONSE.", " . $dateStr . "]") . "</b>\n" . htmlspecialchars( stripslashes( cbGetParam( $_POST, 'bannedreason') ) ) ."\n";
			$sql="UPDATE #__comprofiler SET banned=1, bannedby=" . (int) $_CB_framework->myId() . ", banneddate='".date('Y-m-d\TH:i:s')."', bannedreason = CONCAT_WS('','" . $_CB_database->getEscaped( $bannedreason ) . "', bannedreason) WHERE id=". (int) $uid;
			$_CB_database->SetQuery($sql);
			$_CB_database->query();

			$cbNotification->sendFromSystem($uid,_UE_BANUSER_SUB,_UE_BANUSER_MSG);
			echo _UE_USERBAN_SUCCESSFUL;
		} elseif ( $act == 0 ) {
			// Unban by moderator:
			if (!$isModerator){
				cbNotAuth();
				return;
			}
			// $mineName		=	getNameFormat($_CB_framework->myName(), $_CB_framework->myUsername,$ueConfig['name_format']);
			// DEFINE('_UE_UNBANUSER_BY_ON','User profile unbanned by %s on %s');
			// $unbannedBy	=	"<b>" . addslashes( htmlspecialchars("[".sprintf( _UE_UNBANUSER_BY_ON, $mineName, $dateStr ) ) ) . "]</b>\n";
			$unbannedBy	=	"<b>" . htmlspecialchars("[". _UE_UNBANUSER . ", " . $dateStr ) . "]</b>\n";
			$sql="UPDATE #__comprofiler SET banned=0, unbannedby=" . (int) $_CB_framework->myId() . ", bannedreason = CONCAT_WS('','" . $_CB_database->getEscaped( $unbannedBy ) . "', bannedreason), unbanneddate='".date('Y-m-d\TH:i:s')."'  WHERE id=".(int) $uid;				// , bannedreason=null, bannedby=null, banneddate=null
			$_CB_database->SetQuery($sql);
			$_CB_database->query();
			$cbNotification->sendFromSystem($uid,_UE_UNBANUSER_SUB,_UE_UNBANUSER_MSG);

			echo _UE_USERUNBAN_SUCCESSFUL;
		} elseif ( $act == 2 ) {
			// Unban request from user:
			if ( $_CB_framework->myId() != $uid ) {
				cbNotAuth();
				return;
			}
			$bannedreason = "<b>".htmlspecialchars("["._UE_USERBANRESPONSE.", " . $dateStr . "]")."</b>\n" . htmlspecialchars( stripslashes( cbGetParam( $_POST, 'bannedreason' ) ) ) ."\n";
			$sql="UPDATE #__comprofiler SET banned=2, bannedreason = CONCAT_WS('','" . $_CB_database->getEscaped( $bannedreason) . "', bannedreason) WHERE id=" . (int) $uid;
			$_CB_database->SetQuery($sql);
			$_CB_database->query();
			if($ueConfig['moderatorEmail']==1) {
				$cbNotification->sendToModerators(_UE_UNBANUSERREQUEST_SUB,_UE_UNBANUSERREQUEST_MSG);
			}
			echo _UE_USERUNBANREQUEST_SUCCESSFUL;

		}
	}
}
예제 #7
0
 /**
  * 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;
     }
 }
/**
 * Activates a user
 * user plugins must have been loaded
 *
 * @param  moscomprofilerUser  $user
 * @param  int      $ui               1=frontend, 2=backend, 0=no UI: machine-machine UI
 * @param  string   $cause            (one of: 'UserRegistration', 'UserConfirmation', 'UserApproval', 'NewUser', 'UpdateUser')
 * @param  boolean  $mailToAdmins     true if the standard new-user email should be sent to admins if moderator emails are enabled
 * @param  boolean  $mailToUser       true if the welcome new user email (from CB config) should be sent to the new user
 * @param  boolean  $triggerBeforeActivate
 * @return array of string          texts to display
 */
function activateUser(&$user, $ui, $cause, $mailToAdmins = true, $mailToUser = true, $triggerBeforeActivate = true)
{
    global $_CB_database, $ueConfig, $_PLUGINS;
    static $notificationsSent = array();
    $activate = $user->confirmed && $user->approved == 1;
    $showSysMessage = true;
    $messagesToUser = getActivationMessage($user, $cause);
    if ($cause == 'UserConfirmation' && $user->approved == 0) {
        $activate = false;
        $msg = array('emailAdminSubject' => array('sys' => _UE_REG_ADMIN_PA_SUB), 'emailAdminMessage' => array('sys' => _UE_REG_ADMIN_PA_MSG), 'emailUserSubject' => array(), 'emailUserMessage' => array());
    } elseif ($user->confirmed == 0) {
        $msg = array('emailAdminSubject' => array(), 'emailAdminMessage' => array(), 'emailUserSubject' => array('sys' => getLangDefinition(stripslashes($ueConfig['reg_pend_appr_sub']))), 'emailUserMessage' => array('sys' => getLangDefinition(stripslashes($ueConfig['reg_pend_appr_msg']))));
    } elseif ($cause == 'SameUserRegistrationAgain') {
        $activate = false;
        $msg = array('emailAdminSubject' => array(), 'emailAdminMessage' => array(), 'emailUserSubject' => array(), 'emailUserMessage' => array());
    } elseif ($user->confirmed && !($user->approved == 1)) {
        $msg = array('emailAdminSubject' => array('sys' => _UE_REG_ADMIN_PA_SUB), 'emailAdminMessage' => array('sys' => _UE_REG_ADMIN_PA_MSG), 'emailUserSubject' => array('sys' => getLangDefinition(stripslashes($ueConfig['reg_pend_appr_sub']))), 'emailUserMessage' => array('sys' => getLangDefinition(stripslashes($ueConfig['reg_pend_appr_msg']))));
    } elseif ($user->confirmed && $user->approved == 1) {
        $msg = array('emailAdminSubject' => array('sys' => _UE_REG_ADMIN_SUB), 'emailAdminMessage' => array('sys' => _UE_REG_ADMIN_MSG), 'emailUserSubject' => array('sys' => getLangDefinition(stripslashes($ueConfig['reg_welcome_sub']))), 'emailUserMessage' => array('sys' => getLangDefinition(stripslashes($ueConfig['reg_welcome_msg']))));
    }
    $msg['messagesToUser'] = $messagesToUser;
    if ($triggerBeforeActivate) {
        $results = $_PLUGINS->trigger('onBeforeUserActive', array(&$user, $ui, $cause, $mailToAdmins, $mailToUser));
        if ($_PLUGINS->is_errors() && $ui != 0) {
            echo $_PLUGINS->getErrorMSG('<br />');
        }
        foreach ($results as $res) {
            if (is_array($res)) {
                $activate = $activate && $res['activate'];
                $mailToAdmins = $mailToAdmins && $res['mailToAdmins'];
                $mailToUser = $mailToUser && $res['mailToUser'];
                $showSysMessage = $showSysMessage && $res['showSysMessage'];
                foreach (array_keys($msg) as $key) {
                    if (isset($res[$key]) && $res[$key]) {
                        array_push($msg[$key], $res[$key]);
                    }
                }
            }
        }
        if (!($mailToAdmins && $ueConfig['moderatorEmail'] == 1)) {
            unset($msg['emailAdminSubject']['sys']);
            unset($msg['emailAdminMessage']['sys']);
        }
        if (!$mailToUser) {
            unset($msg['emailUserSubject']['sys']);
            unset($msg['emailUserMessage']['sys']);
        }
        if (!$showSysMessage) {
            unset($msg['messagesToUser']['sys']);
        }
    }
    if ($activate) {
        $user->block = 0;
        $user->storeBlock(false);
        $user->removeActivationCode();
    }
    if ($activate) {
        $_PLUGINS->trigger('onUserActive', array(&$user, $ui, $cause, $mailToAdmins, $mailToUser));
        if ($_PLUGINS->is_errors() && $ui != 0) {
            $msg['messagesToUser'] = $_PLUGINS->getErrorMSG('<br />') . $msg['messagesToUser'];
        }
    }
    if (!isset($notificationsSent[$user->id][$user->confirmed][$user->approved][$user->block])) {
        // in case done several times (e.g. plugins), avoid resending messages.
        $cbNotification = new cbNotification();
        if ($ueConfig['moderatorEmail'] && count($msg['emailAdminMessage'])) {
            $pwd = $user->password;
            $user->password = null;
            $cbNotification->sendToModerators(implode(', ', $msg['emailAdminSubject']), $cbNotification->_replaceVariables(implode('\\n\\n', $msg['emailAdminMessage']), $user));
            $user->password = $pwd;
        }
        if (count($msg['emailUserMessage'])) {
            $cbNotification->sendFromSystem($user, implode(', ', $msg['emailUserSubject']), implode('\\n\\n', $msg['emailUserMessage']));
        }
        $notificationsSent[$user->id][$user->confirmed][$user->approved][$user->block] = true;
    }
    return $msg['messagesToUser'];
}
	/**
	 * Saves a folder
	 *
	 * @param int       $id
	 * @param string    $type
	 * @param TabTable  $tab
	 * @param UserTable $user
	 * @param UserTable $viewer
	 */
	private function saveFolderEdit( $id, $type, $tab, $user, $viewer )
	{
		global $_CB_framework, $_PLUGINS;

		$row						=	new cbgalleryFolderTable();

		$row->load( (int) $id );

		$cbModerator				=	Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator();
		$canAccess					=	false;

		if ( ! $row->get( 'id' ) ) {
			if ( ( $user->get( 'id' ) != $viewer->get( 'id' ) ) && ( ! $cbModerator ) ) {
				$user				=	$viewer;
			}

			$canAccess				=	cbgalleryClass::canUserCreate( $viewer, $type, true );
		} elseif ( ( $row->get( 'type' ) == $type ) && ( $cbModerator || ( $viewer->get( 'id' ) == $row->get( 'user_id' ) ) ) ) {
			$canAccess				=	true;
		}

		if ( $this->input( 'folder', false, GetterInterface::BOOLEAN ) ) {
			$returnUrl				=	$_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'folders', 'func' => 'show', 'type' => $type, 'id' => (int) $row->get( 'id' ), 'user' => (int) $user->get( 'id' ), 'tab' => (int) $tab->get( 'tabid' ) ) );
		} else {
			$returnUrl				=	$_CB_framework->userProfileUrl( (int) $row->get( 'user_id', $user->get( 'id' ) ), false, $tab->get( 'tabid' ) );
		}

		if ( ! $canAccess ) {
			cbRedirect( $returnUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}

		switch( $type ) {
			case 'photos':
			case 'videos':
			case 'music':
				$typeTranslated		=	CBTxt::T( 'Album' );
				break;
			default:
				$typeTranslated		=	CBTxt::T( 'Folder' );
				break;
		}

		if ( $cbModerator || ( ! $this->params->get( $type . '_folder_approval', 0 ) ) || ( $row->get( 'id' ) && ( $row->get( 'published' ) != -1 ) ) ) {
			$row->set( 'published', $this->input( 'post/published', $row->get( 'published', 1 ), GetterInterface::INT ) );
		} else {
			$row->set( 'published', ( $this->params->get( $type . '_folder_approval', 0 ) ? -1 : $row->get( 'published', 1 ) ) );
		}

		$row->set( 'type', $type );
		$row->set( 'title', $this->input( 'post/title', $row->get( 'title' ), GetterInterface::STRING ) );
		$row->set( 'description', $this->input( 'post/description', $row->get( 'description' ), GetterInterface::STRING ) );

		if ( $cbModerator ) {
			$row->set( 'user_id', $this->input( 'post/user_id', $row->get( 'user_id', $viewer->get( 'id' ) ), GetterInterface::INT ) );
		} else {
			$row->set( 'user_id', $row->get( 'user_id', $viewer->get( 'id' ) ) );
		}

		if ( $this->params->get( $type . '_folder_captcha', 0 ) && ( ! $cbModerator ) ) {
			$_PLUGINS->loadPluginGroup( 'user' );

			$_PLUGINS->trigger( 'onCheckCaptchaHtmlElements', array() );

			if ( $_PLUGINS->is_errors() ) {
				$row->setError( $_PLUGINS->getErrorMSG() );
			}
		}

		$new						=	( $row->get( 'id' ) ? false : true );

		if ( $row->getError() || ( ! $row->check() ) ) {
			$this->showItemEdit( $id, $type, $tab, $user, $viewer, CBTxt::T( 'FOLDER_FAILED_TO_SAVE', '[type] failed to save! Error: [error]', array( '[type]' => $typeTranslated, '[error]' => $row->getError() ) ) );
			return;
		}

		if ( $row->getError() || ( ! $row->store() ) ) {
			$this->showItemEdit( $id, $type, $tab, $user, $viewer, CBTxt::T( 'FOLDER_FAILED_TO_SAVE', '[type] failed to save! Error: [error]', array( '[type]' => $typeTranslated, '[error]' => $row->getError() ) ) );
			return;
		}

		if ( $row->get( 'published' ) == -1 ) {
			if ( $new && ( ! $cbModerator ) && $this->params->get( $type . '_folder_approval_notify', 1 ) ) {
				$cbUser				=	CBuser::getInstance( (int) $row->get( 'user_id' ), false );

				$extraStrings		=	array(	'folder_id' => (int) $row->get( 'id' ),
												'folder_title' => ( $row->get( 'title' ) ? $row->get( 'title' ) : $row->get( 'date' ) ),
												'folder_description' => $row->get( 'description' ),
												'folder_date' => $row->get( 'date' ),
												'folder_url' => $_CB_framework->pluginClassUrl( $this->element, true, array( 'action' => 'folders', 'func' => 'show', 'type' => $type, 'id' => (int) $row->get( 'id' ), 'user' => (int) $row->get( 'user_id' ), 'tab' => (int) $tab->get( 'tabid' ) ) ),
												'folder_type' => $typeTranslated,
												'folder_tab_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => (int) $tab->get( 'tabid' ) ) ),
												'gallery_photos_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabPhotos' ) ),
												'gallery_videos_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabVideos' ) ),
												'gallery_music_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabMusic' ) ),
												'gallery_files_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabFiles' ) ),
												'user_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ) ) )
											);

				$subject			=	$cbUser->replaceUserVars( CBTxt::T( 'NOTIFY_NEW_FOLDER_CREATED_SUBJECT', 'Gallery - New [type] Created!', array( '[type]' => $typeTranslated ) ), false, true, $extraStrings, false );
				$message			=	$cbUser->replaceUserVars( CBTxt::T( 'NOTIFY_NEW_FOLDER_CREATED_BODY', '<a href="[user_url]">[formatname]</a> created [folder_type] <a href="[folder_url]">[folder_title]</a> and requires <a href="[folder_tab_url]">approval</a>!' ), false, true, $extraStrings, false );

				$notifications		=	new cbNotification();

				$notifications->sendToModerators( $subject, $message, false, 1 );
			}

			cbRedirect( $returnUrl, CBTxt::T( 'FOLDER_SAVED_SUCCESSFULLY_AND_AWAITING_APPROVAL', '[type] saved successfully and awaiting approval!', array( '[type]' => $typeTranslated ) ) );
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'FOLDER_SAVED_SUCCESSFULLY', '[type] saved successfully!', array( '[type]' => $typeTranslated ) ) );
		}
	}
예제 #10
0
	function _pgSave($id,$pgitemorder,$pgitemtype,$pgitemfilename,$pgitemsize,$pgitemtitle,$pgitemdescription,&$user,$cbpgtotalitems,$cbpgtotalsize,$pgitempublished,$pgitemapproved,$moderatornotify) {
		global $_CB_framework, $_CB_database, $Itemid;

		$html2return = "";
		
		$query = "INSERT INTO #__comprofiler_plug_profilegallery SET "
			. "userid="					. (int) $user->id
			. ", pgitemorder="			. (int) $pgitemorder
			. ", pgitemtype="			. $_CB_database->Quote( stripslashes( $pgitemtype ) )
			. ", pgitemfilename="		. $_CB_database->Quote( stripslashes( $pgitemfilename ) )
			. ", pgitemtitle="			. $_CB_database->Quote( stripslashes( $pgitemtitle ) )
			. ", pgitemdescription="	. $_CB_database->Quote( stripslashes( $pgitemdescription ) )
			. ", pgitemdate=now()"
			. ", pgitemsize="			. (int) $pgitemsize
			. ", pgitempublished="		. (int) $pgitempublished
			. ", pgitemapproved="		. (int) $pgitemapproved
			;
		$_CB_database->setQuery( $query );
		$_CB_database->query();
		
		// Notification
		$isModerator=isModerator($_CB_framework->myId());
		if($moderatornotify && !$isModerator){
			if (is_numeric($Itemid)) $andItemid = "&Itemid=".$Itemid;
				else $andItemid = "";
			
			$profile_url = $_CB_framework->getCfg( 'live_site' ) . "/index.php?option=com_comprofiler&task=userProfile&user="******"A new Gallery item has just been uploaded and may require approval.\n"
                                    ."This email contains the item details\n\n"
                                    ."Gallery Item Type - %1\$s\n"
                                    ."Gallery Item Title - %2\$s\n"
                                    ."Gallery Item Description - %3\$s\n\n"
                                    ."Username - %4\$s\n"
                                    ."Profile Link - %5\$s \n\n\n"
                                    ."Please do not respond to this message as it is automatically generated and is for information purposes only\n"
                                    ),$pgitemtype,$pgitemtitle,$pgitemdescription,$user->username,$profile_url);
			//eval ("\$notificationmessage = \"$notificationmessage\";");
			
			$cbNotification = new cbNotification();
			if (!$cbNotification->sendToModerators(CBTxt::Th("New Gallery Item just uploaded"),$notificationmessage)) {
                $this->_setErrorMSG("CB Gallery failed to send moderation email");    
            }
		}
		
		$html2return .= $this->pgCBUpdate($user,$cbpgtotalitems,$cbpgtotalsize);
		return $html2return;
		
	}
예제 #11
0
	/**
	 * 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;
		}
	}
예제 #12
0
 static function save_avatar_cb($userid, $pic_url)
 {
     $pic = JoomdleHelperContent::get_file($pic_url);
     if (!$pic) {
         return;
     }
     if ($moodle_version == 19) {
         $extension = '.jpg';
         // Moodle stores JPG always in 1.9
         $type = 'image/jpeg';
     } else {
         $extension = '.png';
         // Moodle stores PNG always in 2.0
         $type = 'image/png';
     }
     $newFileName = uniqid($userid . "_") . '.' . $extension;
     file_put_contents(JPATH_SITE . '/images/comprofiler/' . $newFileName, $pic);
     $db = JFactory::getDBO();
     if ($ueConfig['avatarUploadApproval'] == 1) {
         $cbNotification = new cbNotification();
         $cbNotification->sendToModerators(_UE_IMAGE_ADMIN_SUB, _UE_IMAGE_ADMIN_MSG);
         $db->setQuery("UPDATE #__comprofiler SET avatar=" . $db->Quote($newFileName) . ", avatarapproved=0 WHERE id=" . (int) $userid);
     } else {
         $db->setQuery("UPDATE #__comprofiler SET avatar=" . $db->Quote($newFileName) . ", avatarapproved=1, lastupdatedate=now()  WHERE id=" . (int) $userid);
     }
     $db->query();
 }
예제 #13
0
function reportUser($option, $form = 1, $uid = 0)
{
    global $_CB_framework, $ueConfig, $_PLUGINS, $_POST;
    if ($ueConfig['allowUserReports'] == 0) {
        $msg = CBTxt::Th('UE_FUNCTIONALITY_DISABLED', 'This functionality is currently disabled.');
    } elseif (!CBuser::getMyInstance()->authoriseView('profile', $uid)) {
        $msg = CBTxt::Th('UE_NOT_AUTHORIZED', 'You are not authorized to view this page!');
    } else {
        $msg = null;
    }
    $_PLUGINS->loadPluginGroup('user');
    $_PLUGINS->trigger('onBeforeReportUserRequest', array($uid, &$msg, $form));
    if ($msg) {
        $_CB_framework->enqueueMessage($msg, 'error');
        return;
    }
    $reportedByUser = CBuser::getUserDataInstance($_CB_framework->myId());
    $reportedUser = CBuser::getUserDataInstance($uid);
    if ($form == 1) {
        $results = $_PLUGINS->trigger('onBeforeReportUserForm', array($uid, &$reportedByUser, &$reportedUser));
        if ($_PLUGINS->is_errors()) {
            $_CB_framework->enqueueMessage($_PLUGINS->getErrorMSG('<br />'), 'error');
            return;
        }
        if (implode('', $results) != "") {
            $return = '<div class="cb_template cb_template_' . selectTemplate('dir') . '">' . '<div>' . implode('</div><div>', $results) . '</div>' . '</div>';
            echo $return;
            return;
        }
        HTML_comprofiler::reportUserForm($option, $uid, $reportedByUser, $reportedUser);
    } else {
        cbSpoofCheck('reportuser');
        $row = new UserReportTable();
        $_PLUGINS->trigger('onStartSaveReportUser', array(&$row, &$reportedByUser, &$reportedUser));
        if ($_PLUGINS->is_errors()) {
            cbRedirect($_CB_framework->viewUrl('reportuser', false), $_PLUGINS->getErrorMSG(), 'error');
            return;
        }
        if (!$row->bind($_POST)) {
            cbRedirect($_CB_framework->viewUrl('reportuser', false), $row->getError(), 'error');
            return;
        }
        $row->reportedondate = htmlspecialchars($row->reportedondate, ENT_QUOTES);
        //TBD: remove this: not urgent but isn't right
        $row->reportexplaination = htmlspecialchars($row->reportexplaination, ENT_QUOTES);
        //TBD: remove this: not urgent but isn't right
        $row->reportedondate = $_CB_framework->getUTCDate();
        if (!$row->check()) {
            cbRedirect($_CB_framework->viewUrl('reportuser', false), $row->getError(), 'error');
            return;
        }
        $_PLUGINS->trigger('onBeforeSaveReportUser', array(&$row, &$reportedByUser, &$reportedUser));
        if (!$row->store()) {
            cbRedirect($_CB_framework->viewUrl('reportuser', false), $row->getError(), 'error');
            return;
        }
        if ($ueConfig['moderatorEmail'] == 1) {
            $cbNotification = new cbNotification();
            $cbNotification->sendToModerators(CBTxt::T('UE_USERREPORT_SUB', 'User Report Pending Review'), CBTxt::T('UE_USERREPORT_MSG', 'A user has submitted a report regarding a user that requires your review. Please log in and take the appropriate action.'));
        }
        $_PLUGINS->trigger('onAfterSaveReportUser', array(&$row, &$reportedByUser, &$reportedUser));
        $_CB_framework->enqueueMessage(CBTxt::Th('UE_USERREPORT_SUCCESSFUL', 'User report submitted successfully.'));
    }
}