/** * Deletes an item * * @param int $id * @param string $type * @param TabTable $tab * @param UserTable $user * @param UserTable $viewer */ private function deleteItem( $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() ) ) ) { 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; } if ( ! $row->canDelete() ) { cbRedirect( $returnUrl, CBTxt::T( 'ITEM_FAILED_TO_DELETE', '[type] failed to delete! Error: [error]', array( '[type]' => $typeTranslated, '[error]' => $row->getError() ) ), 'error' ); } if ( ! $row->delete() ) { cbRedirect( $returnUrl, CBTxt::T( 'ITEM_FAILED_TO_DELETE', '[type] failed to delete! Error: [error]', array( '[type]' => $typeTranslated, '[error]' => $row->getError() ) ), 'error' ); } cbRedirect( $returnUrl, CBTxt::T( 'ITEM_DELETED_SUCCESSFULLY', '[type] deleted successfully!', array( '[type]' => $typeTranslated ) ) ); }