1 ? end($variacao_arr) : false; $ark_procurado = '-' . ltrim($variacao_arr[0] , '/'); // O recursive=1 é OBRIGATÓRIO para ver pastas dentro de pastas $api_url = "https://gitea.livro.online/api/v1/repos/$usuario/$repositorio/git/trees/$branch?recursive=1"; $options = [ "http" => [ "method" => "GET", "header" => "User-Agent: PHP-Script\r\n" ] ]; $context = stream_context_create($options); $response = @file_get_contents($api_url, false, $context); $dados = json_decode($response); $destino=''; $titulo=''; $encontrado = false; if (isset($dados->tree)) { foreach ($dados->tree as $item) { // Se NÃO for pasta (tree), pula para o próximo item if ($item->type !== 'tree') { continue; } // Se chegou aqui, é uma pasta. if (str_ends_with($item->path, $ark_procurado)) { // Define o destino padrão (redirecionamento) $destino = $variacao ? $localizacao_base . "{$item->path}/README.md#variação-{$variacao}" : $localizacao_base . "{$item->path}/README.md"; $titulo = strstr($item->path, $ark_procurado, true); $encontrado = true; // SE TIVER INTERROGAÇÃO -> ACIONA API JSON if ($tem_interrogacao) { require __DIR__ . '/../Mjson/processador.php'; buscarOuCriarJson( $item->path, $variacao, $usuario, $repositorio, $branch, $site_base ); } break; } } } if ($encontrado) { return [ 'ok' => true, 'destino' => $destino, 'msg' => $destino . ' encontrado.', 'titulo' => $titulo ]; } else { // Se saiu do loop sem encontrar nada, retorna FALSE return [ 'ok' => false, 'destino' => '', 'msg' => 'ark:68745/' . $ark_sem_NAAN . ' não encontrada.', 'titulo' => '' ]; } } ?>