Beispiel #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() ) ) );
				}
			}
		}
	}
Beispiel #2
0
	/**
	 * @param FieldTable $field
	 * @param UserTable  $user
	 * @param array      $postdata
	 * @param string     $reason
	 * @return null|string
	 */
	public function fieldCommitSave( &$field, &$user, &$postdata, $reason )
	{
		static $rows								=	array();

		if ( ( $reason != 'search' ) && $field->get( 'profile' ) && $user->get( 'id' ) ) {
			if ( $field instanceof FieldTable ) {
				$userId								=	(int) $user->get( 'id' );
				$fieldId							=	(int) $field->get( 'fieldid' );
				$value								=	implode( '|*|', cbprivacyClass::validatePrivacy( $this->input( 'privacy_field_' . $fieldId, '0', GetterInterface::RAW ) ) );

				if ( $value != '' ) {
					if ( ! ( $field->params instanceof ParamsInterface ) ) {
						$field->params				=	new Registry( $field->params );
					}

					if ( ! isset( $rows[$userId][$fieldId] ) ) {
						$row						=	new cbprivacyPrivacyTable();

						$row->load( array( 'user_id' => (int) $userId, 'type' => 'profile', 'subtype' => 'field', 'item' => (int) $fieldId ) );

						$rows[$userId][$fieldId]	=	$row;
					}

					/** @var cbprivacyPrivacyTable $privacy */
					$privacy						=	$rows[$userId][$fieldId];
					$rule							=	$privacy->get( 'rule', $field->params->get( 'cbprivacy_display', '0' ) );

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

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

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