ID, '_aicitare_pros', true );
$cons = get_post_meta( $post->ID, '_aicitare_cons', true );
$table = get_post_meta( $post->ID, '_aicitare_table', true );
$rating = get_post_meta( $post->ID, '_aicitare_rating', true );
$rcount = get_post_meta( $post->ID, '_aicitare_rating_count', true );
// Render stored JSON table back to the friendly "a | b | c" line format.
$table_text = '';
if ( $table ) {
$rows = json_decode( $table, true );
if ( is_array( $rows ) ) {
$lines = array();
foreach ( $rows as $row ) {
$lines[] = implode( ' | ', (array) $row );
}
$table_text = implode( "\n", $lines );
}
}
$ta = 'width:100%;box-sizing:border-box;font-family:inherit;font-size:13px;padding:8px;border:1px solid #dcdcde;border-radius:6px;';
echo '
' . esc_html__( 'These feed the Pros/Cons and comparison-table fixes shown on the front end when the matching issue is fixed.', 'aicitare' ) . '
';
echo '';
echo '
';
echo '' . esc_html__( 'Pros (one per line)', 'aicitare' ) . ' ';
echo '';
echo '
';
echo '
';
echo '' . esc_html__( 'Cons (one per line)', 'aicitare' ) . ' ';
echo '';
echo '
';
echo '
';
echo '' . esc_html__( 'Comparison table', 'aicitare' ) . '
';
echo '' . esc_html__( 'One row per line; separate columns with " | ". The first row is the header.', 'aicitare' ) . '
';
echo '';
echo '';
}
/** Persist the content-block fields. */
public function save( $post_id, $post ) {
if ( ! isset( $_POST['aicitare_blocks_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['aicitare_blocks_nonce'] ) ), 'aicitare_blocks_save' ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
$pros = isset( $_POST['aicitare_pros'] ) ? sanitize_textarea_field( wp_unslash( $_POST['aicitare_pros'] ) ) : '';
$cons = isset( $_POST['aicitare_cons'] ) ? sanitize_textarea_field( wp_unslash( $_POST['aicitare_cons'] ) ) : '';
update_post_meta( $post_id, '_aicitare_pros', $pros );
update_post_meta( $post_id, '_aicitare_cons', $cons );
// Parse the "a | b | c" table into rows of cells, store as JSON.
$raw = isset( $_POST['aicitare_table'] ) ? sanitize_textarea_field( wp_unslash( $_POST['aicitare_table'] ) ) : '';
$rows = array();
foreach ( preg_split( '/\r\n|\r|\n/', $raw ) as $line ) {
$line = trim( $line );
if ( '' === $line ) {
continue;
}
$rows[] = array_map( 'trim', explode( '|', $line ) );
}
update_post_meta( $post_id, '_aicitare_table', $rows ? wp_json_encode( $rows ) : '' );
$rating = isset( $_POST['aicitare_rating'] ) ? floatval( wp_unslash( $_POST['aicitare_rating'] ) ) : 0;
$rcount = isset( $_POST['aicitare_rating_count'] ) ? intval( wp_unslash( $_POST['aicitare_rating_count'] ) ) : 0;
update_post_meta( $post_id, '_aicitare_rating', $rating > 0 ? $rating : '' );
update_post_meta( $post_id, '_aicitare_rating_count', $rcount > 0 ? $rcount : '' );
}
public function render( $post ) {
$fixed = AICitare_Data::get_fixed();
$page = $this->find_page( $post->ID );
if ( ! $page ) {
echo '';
esc_html_e( 'No GEO scan data for this post yet. Open AICitare and run a scan.', 'aicitare' );
echo '
';
$this->footer_link();
return;
}
$score = AICitare_Scanner::live_score( $page, $fixed );
$color = $score >= 80 ? '#16a34a' : ( $score >= 60 ? '#d97706' : '#dc2626' );
$open = array_filter( $page['issues'], fn( $i ) => empty( $fixed[ $i['id'] ] ) );
echo '';
}
private function footer_link() {
$url = admin_url( 'admin.php?page=' . AICITARE_SLUG );
echo '' . esc_html__( 'Open AICitare →', 'aicitare' ) . '
';
}
/** Match a scanned page record to a post by id (wp{ID}) or by relative URL. */
private function find_page( $post_id ) {
$rel = wp_make_link_relative( get_permalink( $post_id ) );
foreach ( AICitare_Data::get_pages() as $p ) {
if ( $p['id'] === 'wp' . $post_id || untrailingslashit( $p['url'] ) === untrailingslashit( $rel ) ) {
return $p;
}
}
return null;
}
}