Пример #1
0
	/**
	 * @param cbautoactionsActionTable $trigger
	 * @param UserTable $user
	 */
	public function execute( $trigger, $user )
	{
		if ( ! $this->installed() ) {
			if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
				var_dump( CBTxt::T( 'AUTO_ACTION_PRIVACY_NOT_INSTALLED', ':: Action [action] :: CB Privacy is not installed', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
			}

			return;
		}

		foreach ( $trigger->getParams()->subTree( 'privacy' ) as $row ) {
			/** @var ParamsInterface $row */
			$owner						=	$row->get( 'owner', null, GetterInterface::STRING );

			if ( ! $owner ) {
				$owner					=	(int) $user->get( 'id' );
			} else {
				$owner					=	(int) $trigger->getSubstituteString( $owner );
			}

			if ( ! $owner ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_PRIVACY_NO_OWNER', ':: Action [action] :: CB Privacy skipped due to missing owner', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
				}

				continue;
			}

			$type						=	$trigger->getSubstituteString( $row->get( 'type', null, GetterInterface::STRING ) );

			if ( ! $type ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_PRIVACY_NO_TYPE', ':: Action [action] :: CB Privacy skipped due to missing type', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
				}

				continue;
			}

			$rule						=	$row->get( 'rule', null, GetterInterface::STRING );

			if ( ! $rule ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_PRIVACY_NO_RULE', ':: Action [action] :: CB Privacy skipped due to missing rule', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
				}

				continue;
			}

			$subtype					=	$trigger->getSubstituteString( $row->get( 'subtype', null, GetterInterface::STRING ) );
			$item						=	$trigger->getSubstituteString( $row->get( 'item', null, GetterInterface::STRING ) );

			$privacy					=	new cbprivacyPrivacyTable();

			if ( $item && $row->get( 'load', true, GetterInterface::BOOLEAN ) ) {
				$load					=	array( 'user_id' => $owner, 'type' => $type, 'item' => $item );

				if ( $subtype ) {
					$load['subtype']	=	$subtype;
				}

				$privacy->load( $load );
			}

			$privacy->set( 'user_id', $user );
			$privacy->set( 'type', $type );

			if ( $subtype ) {
				$privacy->set( 'subtype', $subtype );
			}

			if ( $item ) {
				$privacy->set( 'item', $item );
			}

			$privacy->set( 'rule', implode( '|*|', cbprivacyClass::validatePrivacy( $rule ) ) );

			if ( ! $privacy->store() ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_PRIVACY_FAILED', ':: Action [action] :: CB Privacy failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $privacy->getError() ) ) );
				}
			}
		}
	}
Пример #2
0
	/**
	 * @param FieldTable $field
	 * @param UserTable  $user
	 * @param array      $postdata
	 * @param string     $reason
	 */
	public function commitFieldDataSave( &$field, &$user, &$postdata, $reason )
	{
		if ( in_array( $reason, array( 'edit', 'register' ) ) ) {
			$value			=	implode( '|*|', cbprivacyClass::validatePrivacy( $this->input( $field->get( 'name' ), '0', GetterInterface::RAW ) ) );

			if ( $value != '' ) {
				$privacy	=	new cbprivacyPrivacyTable();

				$query		=	'SELECT *'
							.	"\n FROM " . $privacy->getDbo()->NameQuote( $privacy->getTableName() )
							.	"\n WHERE " . $privacy->getDbo()->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' )
							.	"\n AND " . $privacy->getDbo()->NameQuote( 'type' ) . " = " . $privacy->getDbo()->Quote( 'profile' )
							.	"\n AND ( " . $privacy->getDbo()->NameQuote( 'subtype' ) . " IS NULL OR " . $privacy->getDbo()->NameQuote( 'subtype' ) . " = " . $privacy->getDbo()->Quote( '' ) . " )";
				$privacy->getDbo()->setQuery( $query, 0, 1 );
				$privacy->getDbo()->loadObject( $privacy );

				if ( ( ! $privacy->get( 'id' ) ) || ( $privacy->get( 'rule' ) != $value ) ) {
					if ( ! $privacy->get( 'id' ) ) {
						$privacy->set( 'user_id', (int) $user->get( 'id' ) );
						$privacy->set( 'type', 'profile' );
					}

					$privacy->set( 'rule', $value );

					$privacy->store();
				}
			}
		}
	}