Ejemplo n.º 1
0
	/**
	 * Saves a folder
	 *
	 * @param int       $id
	 * @param string    $type
	 * @param TabTable  $tab
	 * @param UserTable $user
	 * @param UserTable $viewer
	 */
	private function saveFolderEdit( $id, $type, $tab, $user, $viewer )
	{
		global $_CB_framework, $_PLUGINS;

		$row						=	new cbgalleryFolderTable();

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

		$cbModerator				=	Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator();
		$canAccess					=	false;

		if ( ! $row->get( 'id' ) ) {
			if ( ( $user->get( 'id' ) != $viewer->get( 'id' ) ) && ( ! $cbModerator ) ) {
				$user				=	$viewer;
			}

			$canAccess				=	cbgalleryClass::canUserCreate( $viewer, $type, true );
		} elseif ( ( $row->get( 'type' ) == $type ) && ( $cbModerator || ( $viewer->get( 'id' ) == $row->get( 'user_id' ) ) ) ) {
			$canAccess				=	true;
		}

		if ( $this->input( 'folder', false, GetterInterface::BOOLEAN ) ) {
			$returnUrl				=	$_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'folders', 'func' => 'show', 'type' => $type, 'id' => (int) $row->get( 'id' ), '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 ( ! $canAccess ) {
			cbRedirect( $returnUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}

		switch( $type ) {
			case 'photos':
			case 'videos':
			case 'music':
				$typeTranslated		=	CBTxt::T( 'Album' );
				break;
			default:
				$typeTranslated		=	CBTxt::T( 'Folder' );
				break;
		}

		if ( $cbModerator || ( ! $this->params->get( $type . '_folder_approval', 0 ) ) || ( $row->get( 'id' ) && ( $row->get( 'published' ) != -1 ) ) ) {
			$row->set( 'published', $this->input( 'post/published', $row->get( 'published', 1 ), GetterInterface::INT ) );
		} else {
			$row->set( 'published', ( $this->params->get( $type . '_folder_approval', 0 ) ? -1 : $row->get( 'published', 1 ) ) );
		}

		$row->set( 'type', $type );
		$row->set( 'title', $this->input( 'post/title', $row->get( 'title' ), GetterInterface::STRING ) );
		$row->set( 'description', $this->input( 'post/description', $row->get( 'description' ), GetterInterface::STRING ) );

		if ( $cbModerator ) {
			$row->set( 'user_id', $this->input( 'post/user_id', $row->get( 'user_id', $viewer->get( 'id' ) ), GetterInterface::INT ) );
		} else {
			$row->set( 'user_id', $row->get( 'user_id', $viewer->get( 'id' ) ) );
		}

		if ( $this->params->get( $type . '_folder_captcha', 0 ) && ( ! $cbModerator ) ) {
			$_PLUGINS->loadPluginGroup( 'user' );

			$_PLUGINS->trigger( 'onCheckCaptchaHtmlElements', array() );

			if ( $_PLUGINS->is_errors() ) {
				$row->setError( $_PLUGINS->getErrorMSG() );
			}
		}

		$new						=	( $row->get( 'id' ) ? false : true );

		if ( $row->getError() || ( ! $row->check() ) ) {
			$this->showItemEdit( $id, $type, $tab, $user, $viewer, CBTxt::T( 'FOLDER_FAILED_TO_SAVE', '[type] failed to save! Error: [error]', array( '[type]' => $typeTranslated, '[error]' => $row->getError() ) ) );
			return;
		}

		if ( $row->getError() || ( ! $row->store() ) ) {
			$this->showItemEdit( $id, $type, $tab, $user, $viewer, CBTxt::T( 'FOLDER_FAILED_TO_SAVE', '[type] failed to save! Error: [error]', array( '[type]' => $typeTranslated, '[error]' => $row->getError() ) ) );
			return;
		}

		if ( $row->get( 'published' ) == -1 ) {
			if ( $new && ( ! $cbModerator ) && $this->params->get( $type . '_folder_approval_notify', 1 ) ) {
				$cbUser				=	CBuser::getInstance( (int) $row->get( 'user_id' ), false );

				$extraStrings		=	array(	'folder_id' => (int) $row->get( 'id' ),
												'folder_title' => ( $row->get( 'title' ) ? $row->get( 'title' ) : $row->get( 'date' ) ),
												'folder_description' => $row->get( 'description' ),
												'folder_date' => $row->get( 'date' ),
												'folder_url' => $_CB_framework->pluginClassUrl( $this->element, true, array( 'action' => 'folders', 'func' => 'show', 'type' => $type, 'id' => (int) $row->get( 'id' ), 'user' => (int) $row->get( 'user_id' ), 'tab' => (int) $tab->get( 'tabid' ) ) ),
												'folder_type' => $typeTranslated,
												'folder_tab_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => (int) $tab->get( 'tabid' ) ) ),
												'gallery_photos_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabPhotos' ) ),
												'gallery_videos_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabVideos' ) ),
												'gallery_music_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabMusic' ) ),
												'gallery_files_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabFiles' ) ),
												'user_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ) ) )
											);

				$subject			=	$cbUser->replaceUserVars( CBTxt::T( 'NOTIFY_NEW_FOLDER_CREATED_SUBJECT', 'Gallery - New [type] Created!', array( '[type]' => $typeTranslated ) ), false, true, $extraStrings, false );
				$message			=	$cbUser->replaceUserVars( CBTxt::T( 'NOTIFY_NEW_FOLDER_CREATED_BODY', '<a href="[user_url]">[formatname]</a> created [folder_type] <a href="[folder_url]">[folder_title]</a> and requires <a href="[folder_tab_url]">approval</a>!' ), false, true, $extraStrings, false );

				$notifications		=	new cbNotification();

				$notifications->sendToModerators( $subject, $message, false, 1 );
			}

			cbRedirect( $returnUrl, CBTxt::T( 'FOLDER_SAVED_SUCCESSFULLY_AND_AWAITING_APPROVAL', '[type] saved successfully and awaiting approval!', array( '[type]' => $typeTranslated ) ) );
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'FOLDER_SAVED_SUCCESSFULLY', '[type] saved successfully!', array( '[type]' => $typeTranslated ) ) );
		}
	}