예제 #1
0
	/**
	 * @param cbautoactionsActionTable $trigger
	 * @param UserTable $user
	 * @return null|string
	 */
	public function execute( $trigger, $user )
	{
		global $_CB_database;

		if ( ! $this->installed() ) {
			if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
				var_dump( CBTxt::T( 'AUTO_ACTION_GALLERY_NOT_INSTALLED', ':: Action [action] :: CB Gallery is not installed', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
			}

			return null;
		}

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

				continue;
			}

			$mode							=	$row->get( 'mode', 'item', GetterInterface::STRING );
			$type							=	$row->get( 'type', 'photos', GetterInterface::STRING );
			$value							=	$trigger->getSubstituteString( $row->get( 'value', null, GetterInterface::STRING ) );
			$title							=	$trigger->getSubstituteString( $row->get( 'title', null, GetterInterface::STRING ) );
			$description					=	$trigger->getSubstituteString( $row->get( 'description', null, GetterInterface::STRING ) );

			switch ( $mode ) {
				case 'folder':
					$object					=	new cbgalleryFolderTable( $_CB_database );
					break;
				case 'item':
				default:
					$object					=	new cbgalleryItemTable( $_CB_database );
					break;
			}

			$object->set( 'user_id', $owner );

			if ( $type ) {
				$object->set( 'type', $type );
			}

			if ( $title ) {
				$object->set( 'title', $title );
			}

			if ( $description ) {
				$object->set( 'description', $description );
			}

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

					continue;
				}

				$object->set( 'value', $value );
			}

			if ( ! $object->store() ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_GALLERY_FAILED', ':: Action [action] :: CB Gallery failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $object->getError() ) ) );
				}
			}
		}

		return null;
	}
	/**
	 * Sets the published state of an item
	 *
	 * @param int       $state
	 * @param int       $id
	 * @param string    $type
	 * @param TabTable  $tab
	 * @param UserTable $user
	 * @param UserTable $viewer
	 */
	private function stateItem( $state, $id, $type, $tab, $user, $viewer )
	{
		global $_CB_framework;

		$row						=	new cbgalleryItemTable();

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

		if ( $row->get( 'folder' ) ) {
			$returnUrl				=	$_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'folders', 'func' => 'show', 'type' => $type, 'id' => (int) $row->get( 'folder' ), 'user' => (int) $user->get( 'id' ), 'tab' => (int) $tab->get( 'tabid' ) ) );
		} else {
			$returnUrl				=	$_CB_framework->userProfileUrl( (int) $row->get( 'user_id', $user->get( 'id' ) ), false, $tab->get( 'tabid' ) );
		}

		if ( ( ! $row->get( 'id' ) ) || ( $row->get( 'type' ) != $type ) || ( ( $viewer->get( 'id' ) != $row->get( 'user_id' ) ) && ( ! Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator() ) ) || ( ( $viewer->get( 'id' ) == $row->get( 'user_id' ) ) && ( $row->get( 'published' ) == -1 ) && $this->params->get( $type . '_item_approval', 0 ) ) ) {
			cbRedirect( $returnUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}

		switch( $type ) {
			case 'photos':
				$typeTranslated		=	CBTxt::T( 'Photo' );
				break;
			case 'files':
				$typeTranslated		=	CBTxt::T( 'File' );
				break;
			case 'videos':
				$typeTranslated		=	CBTxt::T( 'Video' );
				break;
			case 'music':
				$typeTranslated		=	CBTxt::T( 'Music' );
				break;
			default:
				$typeTranslated		=	CBTxt::T( 'Item' );
				break;
		}

		$row->set( 'published', (int) $state );

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

		cbRedirect( $returnUrl, CBTxt::T( 'ITEM_STATE_SAVED_SUCCESSFULLY', '[type] state saved successfully!', array( '[type]' => $typeTranslated ) ) );
	}