Example #1
0
	/**
	 * Accessor:
	 * Returns a field in specified format
	 *
	 * @param  FieldTable  $field
	 * @param  UserTable   $user
	 * @param  string      $output               'html', 'xml', 'json', 'php', 'csvheader', 'csv', 'rss', 'fieldslist', 'htmledit'
	 * @param  string      $reason               'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'search' for searches
	 * @param  int         $list_compare_types   IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search
	 * @return mixed
	 */
	public function getField( &$field, &$user, $output, $reason, $list_compare_types )
	{
		$modOnly				=	$field->params->get( 'cbantispam_ipaddress_display', 1 );
		$return					=	null;

		if ( ( Application::MyUser()->isGlobalModerator() && $modOnly ) || ( ! $modOnly ) ) {
			$ipAddress			=	cbantispamClass::getUserIP( $user );

			switch ( $output ) {
				case 'html':
				case 'rss':
					$return		=	$this->_formatFieldOutput( $field->get( 'name' ), $ipAddress, $output, true );
					break;
				case 'htmledit':
					$return		=	null;
					break;
				default:
					$return		=	$this->_formatFieldOutput( $field->get( 'name' ), $ipAddress, $output, false );
					break;
			}
		}

		return $return;
	}
	/**
	 * Displays whitelist user page
	 *
	 * @param int         $id
	 * @param string      $type
	 * @param UserTable   $user
	 * @param null|string $message
	 * @param null|string $messageType
	 */
	public function showWhitelist( $id, $type, $user, $message = null, $messageType = 'error' )
	{
		global $_CB_framework;

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

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

		$ipAddress				=	cbantispamClass::getUserIP( $user );
		$value					=	null;

		switch ( $type ) {
			case 'user':
				$value			=	(int) $user->get( 'id' );
				break;
			case 'ip':
				$value			=	$ipAddress;
				break;
			case 'email':
				$value			=	$user->get( 'email' );
				break;
			case 'domain':
				$emailParts		=	explode( '@', $user->get( 'email' ) );

				if ( count( $emailParts ) > 1 ) {
					$value		=	array_pop( $emailParts );
				}
				break;
		}

		$row					=	new cbantispamWhitelistTable();

		if ( $id ) {
			$row->load( (int) $id );
		}

		cbantispamClass::getTemplate( 'whitelist' );

		$input					=	array();

		$listType				=	array();
		$listType[]				=	moscomprofilerHTML::makeOption( 'user', CBTxt::T( 'User' ) );
		$listType[]				=	moscomprofilerHTML::makeOption( 'ip', CBTxt::T( 'IP Address' ) );
		$listType[]				=	moscomprofilerHTML::makeOption( 'email', CBTxt::T( 'Email Address' ) );
		$listType[]				=	moscomprofilerHTML::makeOption( 'domain', CBTxt::T( 'Email Domain' ) );

		$type					=	$this->input( 'post/type', $row->get( 'type', $type ), GetterInterface::STRING );
		$typeTooltip			=	cbTooltip( null, CBTxt::T( 'Select whitelist block type. Type determines what value should be supplied.' ), null, null, null, null, null, 'data-hascbtooltip="true"' );

		$input['type']			=	moscomprofilerHTML::selectList( $listType, 'type', 'class="form-control required"' . ( $typeTooltip ? ' ' . $typeTooltip : null ), 'value', 'text', $type, 1, true, false, false );

		$valueTooltip			=	cbTooltip( null, CBTxt::T( 'Input whitelist 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).' ), null, null, null, null, null, 'data-hascbtooltip="true"' );

		$input['value']			=	'<input type="text" id="value" name="value" value="' . htmlspecialchars( $this->input( 'post/value', $row->get( 'value', $value ), GetterInterface::STRING ) ) . '" class="form-control required" size="25"' . ( $valueTooltip ? ' ' . $valueTooltip : null ) . ' />';

		$reasonTooltip			=	cbTooltip( null, CBTxt::T( 'Optionally input whitelist reason. Note this is for administrative purposes only.' ), null, null, null, null, null, 'data-hascbtooltip="true"' );

		$input['reason']		=	'<textarea id="reason" name="reason" class="form-control" cols="40" rows="5"' . ( $reasonTooltip ? ' ' . $reasonTooltip : null ) . '>' . htmlspecialchars( $this->input( 'post/reason', $row->get( 'reason' ), GetterInterface::STRING ) ) . '</textarea>';

		if ( $message ) {
			$_CB_framework->enqueueMessage( $message, $messageType );
		}

		HTML_cbantispamWhitelist::showWhitelist( $row, $input, $type, $this->_tab, $user, $this );
	}