(ajustes): ajustes da última refatoracao. Exclusao de coisas que nao se usa mais.
This commit is contained in:
1 parent
c64609a233
commit
2b8862c5cd
7 files changed
+133
-202
No files matched your search
+108
-63
@@ -24,7 +24,7 @@ function reduzirArk($tamanho, $pedacos) {
|
||||
function limpar_ark($str){
|
||||
|
||||
// Lista de caracteres a serem removidos
|
||||
$caracteresParaRemover = array('<', '>', ':', ';', '(', ')', '&', '$');
|
||||
$caracteresParaRemover = array('<', '>', ':', ';', '(', '&', ')', '$');
|
||||
|
||||
// Substitui os caracteres da lista por uma string vazia
|
||||
$stringLimpa = str_replace($caracteresParaRemover, '', $str);
|
||||
@@ -47,7 +47,7 @@ function init() {
|
||||
|
||||
$ark = "";
|
||||
|
||||
return ['ok'=>false,'destino'=>'','msg'=>'Nenhum ARK foi passado...','qrark'=> false,'ark'=>''];
|
||||
return ['ok'=>false,'destino'=>'','msg'=>'Nenhum ARK foi passado...','qrark'=> false,'ark_full'=>'', 'tem_interrogacao'=>false];
|
||||
|
||||
}
|
||||
|
||||
@@ -67,22 +67,39 @@ function init() {
|
||||
// Remova a barra no início
|
||||
$ark= substr($ark, 1);
|
||||
}
|
||||
|
||||
$tem_interrogacao = false;
|
||||
|
||||
// remove até 2 interrogações no final e marca flag. Ark para consultar metadados se coloca uma interrogacao no final. Duas interrogacoes verifica a persistencia, o tempo de existencia do ark, mas aqui na Editora Moan nao implementamos isso
|
||||
$ark = rtrim($ark);
|
||||
for ($k = 0; $k < 2; $k++) {
|
||||
if (substr($ark, -1) === '?') {
|
||||
$tem_interrogacao = true;
|
||||
$ark = substr($ark, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
$pedacos = explode("/", $ark);
|
||||
|
||||
// ARK completo “sem o prefixo ark:” e sem barra inicial, fixo:
|
||||
$ark_full = implode("/", array_filter($pedacos, fn($p) => $p !== ''));
|
||||
|
||||
$NAAN = $pedacos[0]; //NAAN é o número de registro da Editora Moan na Ark Alliance
|
||||
|
||||
$ark_sem_NAAN = reduzirArk(count($pedacos), $pedacos);
|
||||
|
||||
// sem NAAN
|
||||
$ark_base = implode("/", array_slice($pedacos, 1));
|
||||
|
||||
$ark_completo_sem_NAAN = $ark_sem_NAAN;
|
||||
|
||||
$ark_completo_sem_NAAN = ltrim($ark_completo_sem_NAAN, '/');
|
||||
|
||||
|
||||
if ($ark === '') {
|
||||
return ['ok'=>false,'destino'=>'','msg'=>'ARK vazio.','qrark'=>$qrark,'ark'=>''];
|
||||
return ['ok'=>false,'destino'=>'','msg'=>'ARK vazio.','qrark'=>$qrark,'ark_full'=>'', 'tem_interrogacao'=>false];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------- PREFIXOS ARK --------------------------
|
||||
$prefixo_editora = "eM";
|
||||
|
||||
@@ -90,12 +107,12 @@ function init() {
|
||||
|
||||
$buscar_ark = null;
|
||||
|
||||
if (str_starts_with($ark_completo_sem_NAAN, $prefixo_editora)) {
|
||||
if (str_starts_with($ark_base, $prefixo_editora)) {
|
||||
// Prefixo eM
|
||||
require __DIR__ . '/LogicaPrefixos/processarPrefixo_eM.php';
|
||||
$buscar_ark = 'processarPrefixo_eM';
|
||||
|
||||
} elseif (str_starts_with($ark_completo_sem_NAAN, $prefixo_museu_da_matematica)) {
|
||||
} elseif (str_starts_with($ark_base, $prefixo_museu_da_matematica)) {
|
||||
// Prefixo M
|
||||
require __DIR__ . '/LogicaPrefixos/processarPrefixo_M.php';
|
||||
$buscar_ark = 'processarPrefixo_M';
|
||||
@@ -107,7 +124,7 @@ function init() {
|
||||
//-------------------------- FIM PREFIXOS ARK --------------------------
|
||||
|
||||
if (!is_callable($buscar_ark)) {
|
||||
return ['ok'=>false,'destino'=>'','msg'=>'Prefixo ARK desconhecido.','qrark'=>$qrark,'ark'=>$ark_completo_sem_NAAN];
|
||||
return ['ok'=>false,'destino'=>'','msg'=>'Prefixo ARK desconhecido.','qrark'=>$qrark,'ark_full'=>$ark_full, 'tem_interrogacao'=>$tem_interrogacao];
|
||||
}
|
||||
|
||||
|
||||
@@ -117,8 +134,10 @@ function init() {
|
||||
|
||||
$identificador_ark = false;
|
||||
|
||||
$resultado = ['ok'=>false,'destino'=>'','msg'=>'ARK não encontrado.Erro não identificado.','qrark'=>$qrark,'ark'=>$ark_completo_sem_NAAN];
|
||||
|
||||
$resultado = ['ok'=>false,'destino'=>'','msg'=>'ARK não encontrado.Erro não identificado.','qrark'=>$qrark,'ark'=>$ark_full, 'tem_interrogacao'=>$tem_interrogacao];
|
||||
|
||||
|
||||
|
||||
do {
|
||||
|
||||
$resto = "";
|
||||
@@ -145,29 +164,6 @@ function init() {
|
||||
break;
|
||||
}
|
||||
|
||||
$len_ark_sem_NAAN = strlen($ark_sem_NAAN);
|
||||
|
||||
$tem_interrogacao = false;
|
||||
|
||||
|
||||
if($ark_sem_NAAN[$len_ark_sem_NAAN-1] == "?"){// Um ARK com ? é uma pergunta para saber seus metadados e, por isso, em vez da obra em si, temos que retornar os metadados do ARK
|
||||
|
||||
$tem_interrogacao = true;
|
||||
|
||||
$ark_sem_NAAN = substr($ark_sem_NAAN, 0, -1);
|
||||
|
||||
}//Fecha if
|
||||
|
||||
|
||||
$len_ark_sem_NAAN = strlen($ark_sem_NAAN);
|
||||
|
||||
if($ark_sem_NAAN[$len_ark_sem_NAAN-1] == "?"){// É executado duas vezes porque um ARK, pela especificação, pode conter duas interrogações e nesse caso deveria retornar se o arquivo é temporário ou não. Mas na Editora Moan não implementamos isso.
|
||||
|
||||
$ark_sem_NAAN = substr($ark_sem_NAAN, 0, -1);
|
||||
|
||||
}//Fecha if
|
||||
|
||||
|
||||
|
||||
$resultado = $buscar_ark($NAAN, $ark_sem_NAAN, $tem_interrogacao, $resto);
|
||||
|
||||
@@ -177,8 +173,12 @@ function init() {
|
||||
|
||||
} while ($tamanho > 1 && !$identificador_ark);
|
||||
|
||||
$resultado['qrark'] = $qrark;
|
||||
$resultado['ark'] = $ark_completo_sem_NAAN;
|
||||
|
||||
|
||||
$resultado['qrark'] = $qrark;
|
||||
$resultado['ark_full'] = $ark_full; // <-- use este no JS/analytics
|
||||
$resultado['tem_interrogacao'] = $tem_interrogacao;
|
||||
|
||||
|
||||
return $resultado;
|
||||
|
||||
@@ -192,10 +192,32 @@ $destino = $conteudo["destino"];
|
||||
|
||||
$msg = $conteudo["msg"];
|
||||
|
||||
$ark = $conteudo["ark"];
|
||||
$arkFull = $conteudo['ark_full'] ?? '';
|
||||
|
||||
$qrark = $conteudo["qrark"];
|
||||
|
||||
$tem_interrogacao = $conteudo['tem_interrogacao'];
|
||||
|
||||
function slug_titulo($s) {
|
||||
$s = trim((string)$s);
|
||||
if ($s === '') return '';
|
||||
|
||||
// remove acentos
|
||||
$s = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
|
||||
$s = strtolower($s);
|
||||
|
||||
// troca tudo que não é letra/número por hífen
|
||||
$s = preg_replace('/[^a-z0-9]+/', '-', $s);
|
||||
$s = trim($s, '-');
|
||||
|
||||
// limita tamanho (pra não virar um trem sem freio)
|
||||
return substr($s, 0, 80);
|
||||
}
|
||||
|
||||
$tituloSlug = slug_titulo($conteudo['titulo'] ?? '');
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -207,22 +229,21 @@ $qrark = $conteudo["qrark"];
|
||||
<title><?= $ok ? "Redirecionando…" : "ARK não encontrado" ?></title>
|
||||
|
||||
<style>
|
||||
html,body{margin:0;width:100%;height:100%;display:flex;align-items:center;justify-content:center;font-family:system-ui,sans-serif;background:#fff}
|
||||
html,body{margin:0;width:100%;height:100%;display:flex;align-items:center;justify-content:center;font-family:system-ui,sans-serif;background: #FF5F6D; /* fallback for old browsers */
|
||||
background: -webkit-linear-gradient(to right, #FFC371, #FF5F6D); /* Chrome 10-25, Safari 5.1-6 */
|
||||
background: linear-gradient(to right, #FFC371, #FF5F6D); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
|
||||
}
|
||||
.spinner{width:52px;height:52px;border:5px solid #ddd;border-top-color:#555;border-radius:50%;animation:spin 1s linear infinite}
|
||||
@keyframes spin{to{transform:rotate(360deg)}}
|
||||
.msg{max-width:420px;text-align:center;padding:24px}
|
||||
</style>
|
||||
|
||||
|
||||
<?php
|
||||
// Injeta o snippet do plausible (arquivo ignorado no git)
|
||||
@include __DIR__ . '/analytics/plausible.php';
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<?php if ($ok): ?>
|
||||
<meta http-equiv="refresh" content="0;url=<?= htmlspecialchars($destino, ENT_QUOTES, 'UTF-8') ?>">
|
||||
<?php endif; ?>
|
||||
</head>
|
||||
<body>
|
||||
<div class="spinner" id="spinner" aria-label="Carregando"></div>
|
||||
@@ -235,30 +256,54 @@ $qrark = $conteudo["qrark"];
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Passando PHP -> JS (seguro)
|
||||
const ok = <?= json_encode($ok) ?>;
|
||||
const destino = <?= json_encode($destino) ?>;
|
||||
const msg = <?= json_encode($msg) ?>;
|
||||
const ark = <?= json_encode($ark) ?>;
|
||||
const qrark = <?= json_encode($qrark) ?>;
|
||||
const ok = <?= json_encode($ok) ?>;
|
||||
const destino = <?= json_encode($destino) ?>;
|
||||
const msg = <?= json_encode($msg) ?>;
|
||||
|
||||
const spinner = document.getElementById('spinner');
|
||||
const msgBox = document.getElementById('msgBox');
|
||||
const msgTitle = document.getElementById('msgTitle');
|
||||
const msgText = document.getElementById('msgText');
|
||||
const arkFull = <?= json_encode($arkFull) ?>; // "68745/eM8Rf/gJ.ht"
|
||||
const qrark = <?= json_encode($qrark) ?>; // boolean
|
||||
const consultaMetadados = <?= json_encode($tem_interrogacao) ?>; // boolean
|
||||
const tituloSlug = <?= json_encode($tituloSlug) ?>; // "o-titulo-do-livro"
|
||||
|
||||
if (ok) {
|
||||
if (typeof plausible === "function") {
|
||||
plausible("ARK Resolve", { props: { ark, qrark } });
|
||||
}
|
||||
setTimeout(() => location.replace(destino), 120);
|
||||
const spinner = document.getElementById('spinner');
|
||||
const msgBox = document.getElementById('msgBox');
|
||||
const msgTitle = document.getElementById('msgTitle');
|
||||
const msgText = document.getElementById('msgText');
|
||||
|
||||
function pathSafe(a) {
|
||||
return String(a)
|
||||
.split('/')
|
||||
.filter(Boolean)
|
||||
.map(encodeURIComponent)
|
||||
.join('/');
|
||||
}
|
||||
|
||||
const go = () => location.replace(destino);
|
||||
|
||||
if (ok) {
|
||||
const parts = [];
|
||||
if (qrark) parts.push('qrcodeLivro');
|
||||
if (consultaMetadados) parts.push('meta');
|
||||
if (tituloSlug) parts.push(tituloSlug);
|
||||
|
||||
const suffix = parts.length ? '_' + parts.join('_') : '';
|
||||
const virtualUrl = location.origin + '/' + pathSafe(arkFull) + suffix;
|
||||
|
||||
if (typeof plausible === "function") {
|
||||
plausible("pageview", {
|
||||
u: virtualUrl,
|
||||
callback: () => go()
|
||||
});
|
||||
setTimeout(go, 1500); // fallback
|
||||
} else {
|
||||
// terminou e deu ruim: troca spinner por mensagem
|
||||
spinner.style.display = 'none';
|
||||
msgBox.style.display = 'block';
|
||||
msgTitle.textContent = 'Erro';
|
||||
msgText.textContent = msg;
|
||||
go();
|
||||
}
|
||||
} else {
|
||||
spinner.style.display = 'none';
|
||||
msgBox.style.display = 'block';
|
||||
msgTitle.textContent = 'Erro';
|
||||
msgText.textContent = msg;
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
Reference in new issue
Block a user