| Server IP : 188.114.96.3 / Your IP : 216.73.216.143 Web Server : Apache System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64 User : ( 3194769) PHP Version : 8.5.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /polana/admin/ |
Upload File : |
<?php
declare(strict_types=1);
require_once dirname(__DIR__).'/includes/functions.php';
require_admin_role();
require_once dirname(__DIR__).'/includes/polana_v12_pages.php';
header('Content-Type: application/json; charset=UTF-8');
header('Cache-Control: no-store, private');
header('X-Content-Type-Options: nosniff');
if($_SERVER['REQUEST_METHOD']!=='POST'){
http_response_code(405);echo json_encode(['ok'=>false,'error'=>'POST only']);exit;
}
verify_csrf();
if(session_status()===PHP_SESSION_ACTIVE)session_write_close();
try{
p12_schema();
$action=(string)($_POST['action']??'');
if($action==='status')$payload=['counts'=>p12_counts()];
elseif($action==='translate'){
$lock=(int)db()->query("SELECT GET_LOCK('polana_v12_translate',0)")->fetchColumn();
if(!$lock){$payload=['busy'=>true,'counts'=>p12_counts()];}
else{
try{$batch=p12_work(1);$payload=['batch'=>$batch,'counts'=>p12_counts()];}
finally{db()->query("SELECT RELEASE_LOCK('polana_v12_translate')");}
}
}elseif($action==='approve'){
$ids=$_POST['ids']??[];
if(!is_array($ids))throw new RuntimeException('Nieprawidlowa lista');
$payload=p12_approve($ids);$payload['counts']=p12_counts();
}elseif($action==='save_translation'){
$id=(int)($_POST['id']??0);
$text=trim((string)($_POST['text']??''));
if($id<1||$text===''||mb_strlen($text,'UTF-8')>6000)throw new RuntimeException('Nieprawidłowy tekst');
$q=db()->prepare("UPDATE polana_v12_page_phrases SET translated_text=?,status='review',error_text=NULL WHERE id=? AND status IN ('review','approved')");
$q->execute([$text,$id]);$payload=['updated'=>$q->rowCount()];
}elseif($action==='retry'){
$id=(int)($_POST['id']??0);
$q=db()->prepare("UPDATE polana_v12_page_phrases SET status='pending',attempts=0,error_text=NULL WHERE id=? AND status<>'approved'");
$q->execute([$id]);$payload=['updated'=>$q->rowCount()];
}else{http_response_code(400);throw new RuntimeException('Nieznana operacja');}
echo json_encode(['ok'=>true]+$payload,JSON_UNESCAPED_UNICODE|JSON_INVALID_UTF8_SUBSTITUTE);
}catch(Throwable $e){
error_log('POLANA V12 API: '.$e->getMessage());
http_response_code(500);
echo json_encode(['ok'=>false,'error'=>$e->getMessage()],JSON_UNESCAPED_UNICODE|JSON_INVALID_UTF8_SUBSTITUTE);
}