70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace RomhackPlazaFS\Endpoints;
|
||
|
|
use RomhackPlazaFS\Library\Data;
|
||
|
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||
|
|
|
||
|
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||
|
|
|
||
|
|
class Markasprivate extends Abstract_Endpoint {
|
||
|
|
|
||
|
|
private int $post_id;
|
||
|
|
private string $custom_post_type;
|
||
|
|
private string $file_name;
|
||
|
|
|
||
|
|
protected function private_endpoint(): bool
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function require_token(): bool
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function get_post_params(): void {
|
||
|
|
|
||
|
|
$this->post_id = $this->swiffer_post( "post_id", "int" );
|
||
|
|
if( $this->post_id < 1 )
|
||
|
|
RomhackPlazaFS::invalid_parameter_stop( "post_id", "POST" );
|
||
|
|
|
||
|
|
$this->custom_post_type = $this->swiffer_post( "post_type", "string" );
|
||
|
|
if( $this->custom_post_type === "" )
|
||
|
|
RomhackPlazaFS::invalid_parameter_stop( "post_type", "POST" );
|
||
|
|
|
||
|
|
$this->file_name = $this->swiffer_post( "filename", "filename" );
|
||
|
|
if( $this->file_name === "" )
|
||
|
|
RomhackPlazaFS::invalid_parameter_stop( "filename", "POST" );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function process(): void {
|
||
|
|
|
||
|
|
$data = Data::setup(
|
||
|
|
$this->custom_post_type,
|
||
|
|
$this->post_id,
|
||
|
|
$this->file_name
|
||
|
|
);
|
||
|
|
|
||
|
|
if( !$data->file_exists() )
|
||
|
|
RomhackPlazaFS::fatal_stop( 404, "File not found." );
|
||
|
|
|
||
|
|
$new_data = Data::setup(
|
||
|
|
$this->custom_post_type,
|
||
|
|
$this->post_id,
|
||
|
|
$this->file_name,
|
||
|
|
Data::F_PRIVATE_FILE
|
||
|
|
);
|
||
|
|
|
||
|
|
if( $new_data->file_exists() )
|
||
|
|
RomhackPlazaFS::fatal_stop( 500, "File already exists. Can't replace. Please delete private file before." );
|
||
|
|
|
||
|
|
if( $data->change_data_location( $new_data ) )
|
||
|
|
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_PRIVATE ] );
|
||
|
|
|
||
|
|
RomhackPlazaFS::fatal_stop( 500, "Error during file marking" );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|