Exemplo n.º 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_BLOGS_NOT_INSTALLED', ':: Action [action] :: CB Blogs is not installed', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
			}

			return;
		}

		foreach ( $trigger->getParams()->subTree( 'blog' ) as $row ) {
			/** @var ParamsInterface $row */
			$blog			=	new cbblogsBlogTable();

			$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_BLOGS_NO_OWNER', ':: Action [action] :: CB Blogs skipped due to missing owner', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
				}

				continue;
			}

			$blogData		=	array(	'user' => $owner,
										'title' => $trigger->getSubstituteString( $row->get( 'title', null, GetterInterface::STRING ) ),
										'blog_intro' => $trigger->getSubstituteString( $row->get( 'intro', null, GetterInterface::RAW ), false ),
										'blog_full' => $trigger->getSubstituteString( $row->get( 'full', null, GetterInterface::RAW ), false ),
										'category' => $row->get( 'category', null, GetterInterface::STRING ),
										'published' => (int) $row->get( 'published', 1, GetterInterface::INT ),
										'access' => (int) $row->get( 'access', 1, GetterInterface::INT )
									);

			if ( ! $blog->bind( $blogData ) ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_BLOGS_BIND_FAILED', ':: Action [action] :: CB Blogs failed to bind. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $blog->getError() ) ) );
				}

				continue;
			}

			if ( ! $blog->store() ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_BLOGS_FAILED', ':: Action [action] :: CB Blogs failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $blog->getError() ) ) );
				}
			}
		}
	}
Exemplo n.º 2
0
	/**
	 * @param  int          $state
	 * @param  int          $id
	 * @param  UserTable    $user
	 * @param  stdClass     $model
	 * @param  PluginTable  $plugin
	 */
	private function stateBlog( $state, $id, $user, /** @noinspection PhpUnusedParameterInspection */ $model, $plugin )
	{
		global $_CB_framework;

		$row						=	new cbblogsBlogTable();

		$canAccess					=	false;

		if ( $row->load( (int) $id ) ) {
			if ( $row->get( 'id' ) && ( Application::User( (int) $user->get( 'id' ) )->isGlobalModerator() || ( ( $row->get( 'user' ) == $user->get( 'id' ) ) && ( ! $plugin->params->get( 'blog_approval', 0 ) ) ) ) ) {
				$canAccess			=	true;
			}
		}

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

		if ( $canAccess ) {
			$_POST['published']		=	(int) $state;

			if ( ! $row->bind( $_POST ) ) {
				cbRedirect( $profileUrl, CBTxt::T( 'BLOG_STATE_FAILED_TO_BIND_ERROR_ERROR', 'Blog state failed to bind! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
			}

			if ( ! $row->check() ) {
				cbRedirect( $profileUrl, CBTxt::T( 'BLOG_STATE_FAILED_TO_VALIDATE_ERROR_ERROR', 'Blog state failed to validate! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
			}

			if ( $row->getError() || ( ! $row->store() ) ) {
				cbRedirect( $profileUrl, CBTxt::T( 'BLOG_STATE_FAILED_TO_SAVE_ERROR_ERROR', 'Blog state failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
			}

			cbRedirect( $profileUrl, CBTxt::T( 'Blog state saved successfully!' ) );
		} else {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}
	}