Пример #1
0
	/**
	 * Handles registration blocking
	 *
	 * @param UserTable $user
	 * @param UserTable $userDuplicate
	 */
	public function onBeforeUserRegistration( &$user, &$userDuplicate )
	{
		global $_CB_framework, $_CB_database, $_PLUGINS;

		$ipAddresses					=	cbGetIParray();
		$ipAddress						=	trim( array_shift( $ipAddresses ) );
		$blocked						=	cbantispamClass::getUserBlock( $user, $ipAddress );

		if ( $blocked ) {
			$this->blockRegistration( $blocked->get( 'reason' ), $blocked->get( 'duration' ), $blocked->get( 'date' ), $blocked->getExpire() );
		} elseif ( ( ( ! $_PLUGINS->is_errors() ) && ( ! $user->getError() ) ) ) {
			if ( $this->params->get( 'reg_duplicate', 0 ) ) {
				if ( ! cbantispamClass::isUserBlockable( $user, $ipAddress ) ) {
					return;
				}

				$timeframe				=	$this->params->get( 'reg_duplicate_timeframe', '-1 YEAR' );

				$query					=	'SELECT COUNT(*)'
										.	"\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_log' ) . " AS l"
										.	"\n INNER JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS u"
										.	' ON u.' . $_CB_database->NameQuote( 'id' ) . ' = l.' . $_CB_database->NameQuote( 'user_id' )
										.	"\n WHERE l." . $_CB_database->NameQuote( 'ip_address' ) . " = " . $_CB_database->Quote( $ipAddress );
				if ( $timeframe ) {
					$query				.=	"\n AND l." . $_CB_database->NameQuote( 'date' ) . " >= " . $_CB_database->Quote( $_CB_framework->getUTCDate( 'Y-m-d H:i:s', $timeframe ) );
				}
				$_CB_database->setQuery( $query );
				$accounts				=	$_CB_database->loadResult();

				$count					=	(int) $this->params->get( 'reg_duplicate_count', 1 );

				if ( ! $count ) {
					$count				=	1;
				}

				if ( $accounts >= $count ) {
					$method				=	(int) $this->params->get( 'reg_duplicate_method', 0 );
					$reason				=	$this->params->get( 'reg_duplicate_reason', 'Already registered.' );

					if ( $method == 1 ) {
						$row			=	new cbantispamBlockTable();

						$row->set( 'type', 'ip' );
						$row->set( 'value', $ipAddress );
						$row->set( 'date', $_CB_framework->getUTCDate() );
						$row->set( 'duration', $this->params->get( 'reg_duplicate_dur', '+1 HOUR' ) );
						$row->set( 'reason', $reason );

						$row->store();

						$this->blockRegistration( $row->get( 'reason' ), $row->get( 'duration' ), $row->get( 'date' ), $row->getExpire() );
					} else {
						$this->blockRegistration( $reason );
					}
				}
			}
		}
	}
Пример #2
0
	/**
	 * @param cbantispamBlockTable $row
	 * @param array                $input
	 * @param string               $type
	 * @param int|string           $tab
	 * @param UserTable            $user
	 * @param cbPluginHandler      $plugin
	 */
	static public function showBlock( $row, $input, $type, $tab, $user, $plugin )
	{
		global $_CB_framework, $ueConfig;

		cbValidator::loadValidation();

		$name			=	CBuser::getInstance( (int) $user->get( 'id' ), false )->getField( 'formatname', null, 'html', 'none', 'profile', 0, true );
		$pageTitle		=	CBTxt::T( 'BLOCK_NAME', 'Block [name]', array( '[name]' => $name ) );

		$_CB_framework->setPageTitle( $pageTitle );
		$_CB_framework->appendPathWay( htmlspecialchars( CBTxt::T( 'Blocks' ) ), $_CB_framework->userProfileUrl( (int) $user->get( 'id' ), true, $tab ) );
		$_CB_framework->appendPathWay( htmlspecialchars( $pageTitle ), $_CB_framework->pluginClassUrl( $plugin->element, true, ( $row->get( 'id' ) ? array( 'action' => 'block', 'func' => ( $type ? $type : 'edit' ), 'id' => (int) $row->get( 'id' ), 'usr' => (int) $user->get( 'id' ) ) : array( 'action' => 'block', 'func' => ( $type ? $type : 'new' ), 'usr' => (int) $user->get( 'id' ) ) ) ) );

		$return			=	'<div class="blockEdit">'
						.		'<form action="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'block', 'func' => 'save', 'id' => (int) $row->get( 'id' ), 'usr' => (int) $user->get( 'id' ) ) ) . '" method="post" enctype="multipart/form-data" name="blockForm" id="blockForm" class="cb_form blockForm form-auto cbValidation">'
						.			( $pageTitle ? '<div class="blockTitle page-header"><h3>' . $pageTitle . '</h3></div>' : null )
						.			'<div class="cbft_select cbtt_select form-group cb_form_line clearfix">'
						.				'<label for="type" class="col-sm-3 control-label">' . CBTxt::T( 'Type' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['type']
						.					getFieldIcons( 1, 1, null, CBTxt::T( 'Select the block type. Type determines what value should be supplied.' ) )
						.				'</div>'
						.			'</div>'
						.			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
						.				'<label for="value" class="col-sm-3 control-label">' . CBTxt::T( 'Value' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['value']
						.					getFieldIcons( 1, 1, null, CBTxt::T( 'Input block value in relation to the type. User type use the users user_id (e.g. 42). IP Address type use a full valid IP Address (e.g. 192.168.0.1). Email type use a fill valid email address (e.g. invalid@cb.invalid). Email Domain type use a full email address domain after @ (e.g. example.com).' ) )
						.				'</div>'
						.			'</div>'
						.			'<div class="cbft_date cbtt_input form-group cb_form_line clearfix">'
						.				'<label for="date" class="col-sm-3 control-label">' . CBTxt::T( 'Date' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['date']
						.					getFieldIcons( 1, 1, null, CBTxt::T( 'Select the date and time the block should go in affect. Note date and time always functions in UTC.' ) )
						.				'</div>'
						.			'</div>'
						.			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
						.				'<label for="duration" class="col-sm-3 control-label">' . CBTxt::T( 'Duration' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['duration'] . ' ' . $input['durations']
						.					getFieldIcons( 1, 0, null, CBTxt::T( 'Input the strtotime relative date (e.g. +1 Day). This duration will be added to the datetime specified above. Leave blank for a forever duration.' ) )
						.				'</div>'
						.			'</div>'
						.			'<div class="cbft_textarea cbtt_textarea form-group cb_form_line clearfix">'
						.				'<label for="reason" class="col-sm-3 control-label">' . CBTxt::T( 'Reason' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['reason']
						.					getFieldIcons( 1, 0, null, CBTxt::T( 'Optionally input block reason. If left blank will default to spam.' ) )
						.				'</div>'
						.			'</div>';

		if ( isset( $ueConfig['allowUserBanning'] ) && $ueConfig['allowUserBanning'] ) {
			$return		.=			'<div id="banUsr" class="cbft_select cbtt_select form-group cb_form_line clearfix">'
						.				'<label for="ban_user" class="col-sm-3 control-label">' . CBTxt::T( 'Ban Profile' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['ban_user']
						.					getFieldIcons( 1, 0, null, CBTxt::T( 'Optionally ban the users profile using Community Builder moderator ban feature. Note normal ban notification will be sent with the ban.' ) )
						.				'</div>'
						.			'</div>'
						.			'<div id="banUsrReason" class="cbft_textarea cbtt_textarea form-group cb_form_line clearfix">'
						.				'<label for="ban_reason" class="col-sm-3 control-label">' . CBTxt::T( 'Ban Reason' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['ban_reason']
						.					getFieldIcons( 1, 0, null, CBTxt::T( 'Optionally input reason for profile ban.' ) )
						.				'</div>'
						.			'</div>';
		}

		$return			.=			'<div id="blockUsr" class="cbft_select cbtt_select form-group cb_form_line clearfix">'
						.				'<label for="block_user" class="col-sm-3 control-label">' . CBTxt::T( 'Block Profile' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['block_user']
						.					getFieldIcons( 1, 0, null, CBTxt::T( 'Optionally block the users profile using Joomla block state.' ) )
						.				'</div>'
						.			'</div>'
						.			'<div class="form-group cb_form_line clearfix">'
						.				'<div class="col-sm-offset-3 col-sm-9">'
						.					'<input type="submit" value="' . htmlspecialchars( ( $row->get( 'id' ) ? CBTxt::T( 'Update Block' ) : CBTxt::T( 'Create Block' ) ) ) . '" class="blockButton blockButtonSubmit btn btn-primary"' . cbValidator::getSubmitBtnHtmlAttributes() . ' />&nbsp;'
						.					' <input type="button" value="' . htmlspecialchars( CBTxt::T( 'Cancel' ) ) . '" class="blockButton blockButtonCancel btn btn-default" onclick="if ( confirm( \'' . addslashes( CBTxt::T( 'Are you sure you want to cancel? All unsaved data will be lost!' ) ) . '\' ) ) { location.href = \'' . $_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, $tab ) . '\'; }" />'
						.				'</div>'
						.			'</div>'
						.			cbGetSpoofInputTag( 'plugin' )
						.		'</form>'
						.	'</div>';

		echo $return;
	}
	/**
	 * Deletes a user block
	 *
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function deleteBlock( $id, $user )
	{
		global $_CB_framework;

		$row			=	new cbantispamBlockTable();

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

		$profileUrl		=	$_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, $this->_tab );

		if ( ! $row->get( 'id' ) ) {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}

		if ( ! $row->delete() ) {
			cbRedirect( $profileUrl, CBTxt::T( 'BLOCK_DELETE_FAILED', 'Block failed to delete! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		cbRedirect( $profileUrl, CBTxt::T( 'Block deleted successfully!' ) );
	}