$ano = trim(sanitize_text_field($_POST['ano'] ?? '')); $doi = trim(sanitize_text_field($_POST['doi'] ?? '')); $page = max(1, intval($_POST['page'] ?? 1)); $per = max(1, min(50, intval($_POST['per'] ?? 10))); $off = ($page - 1) * $per; $w = array(); $p = array(); if ($q !== '') { $like = '%' . $wpdb->esc_like($q) . '%'; $w[] = '(titulo LIKE %s OR autores LIKE %s)'; $p[] = $like; $p[] = $like; } if ($issn !== '') { $w[] = 'issn = %s'; $p[] = $issn; } if ($revista !== '') { $w[] = 'revista LIKE %s'; $p[] = '%' . $wpdb->esc_like($revista) . '%'; } if ($ano !== '') { $w[] = 'ano = %d'; $p[] = (int)$ano; } if ($doi !== '') { $w[] = 'doi LIKE %s'; $p[] = '%' . $wpdb->esc_like($doi) . '%'; } $where = $w ? ('WHERE ' . implode(' AND ', $w)) : ''; $count_sql = "SELECT COUNT(*) FROM {$this->tb_artigos} {$where}"; $count = $p ? (int)$wpdb->get_var($wpdb->prepare($count_sql, $p)) : (int)$wpdb->get_var($count_sql); $pages = max(1, (int)ceil($count / $per)); $sql = "SELECT id,titulo,autores,doi,revista,issn,ano,volume,numero,paginas,pdf,created_at,link FROM {$this->tb_artigos} {$where} ORDER BY created_at DESC, id DESC LIMIT %d OFFSET %d"; $p2 = $p; $p2[] = $per; $p2[] = $off; $rows = $wpdb->get_results($wpdb->prepare($sql, $p2), ARRAY_A); $html = '
| ID | '; $html .= 'Título | '; $html .= 'Autores | '; $html .= 'DOI | '; $html .= 'Revista | '; $html .= 'ISSN | '; $html .= 'Ano | '; $html .= 'Vol. | '; $html .= 'Núm. | '; $html .= 'Páginas | '; $html .= 'Criado | '; $html .= '|
|---|---|---|---|---|---|---|---|---|---|---|---|
| (nenhum resultado) | |||||||||||
| ' . intval($r['id']) . ' | ' . '' . $titulo . ' | ' . '' . $autores . ' | ' . '' . $doi_html . ' | ' . '' . esc_html($r['revista']) . ' | ' . '' . esc_html($r['issn']) . ' | ' . '' . esc_html($r['ano']) . ' | ' . '' . esc_html($r['volume']) . ' | ' . '' . esc_html($r['numero']) . ' | ' . '' . esc_html($r['paginas']) . ' | ' . '' . $pdf_html . ' | ' . '' . esc_html($r['created_at']) . ' | ' . '