' . "\n"; aicc_cabecera_pagina_admin(); echo '

'; echo __( 'Articles', 'ai-content-creator' ); echo "

\n"; $id=''; // Procesa si el id recibido es valido if ( isset( $_GET['id'] ) ) { $id = aicc_valida_id_articulo( $_GET['id'] ); if ( ! $id ) { echo aicc_admin_notice( __( 'The requested article is incorrect', 'ai-content-creator' ), 'error' ); } } $accion=''; if ( isset( $_GET['accion'] ) ) { $accion = aicc_filtra_accion( $_GET['accion'] ); if ( ! $accion ) { echo aicc_admin_notice( __( 'The requested action is incorrect', 'ai-content-creator' ), 'error' ); } } if ( $id ) { if ( 'reprocesar' == $accion ) { if ( aicc_reprocesa_articulo( $id ) ) { // Ha causado modificación aicc_ver_articulo( $id ); } else { // Sin cambios, muestra la lista entonces aicc_lista_articulos(); } //aicc_lista_articulos(); } elseif ( 'ver' == $accion ) { aicc_ver_articulo( $id ); } elseif ( 'borrar' == $accion ) { aicc_confirma_borrado_articulo( $id ); } elseif ( 'borrar_confirmado' == $accion ) { aicc_borra_articulo( $id ); aicc_lista_articulos(); } elseif ( 'borrador' == $accion ) { aicc_crear_borrador_articulo( $id ); } else { // Lista los artículos de la tabla aicc_lista_articulos(); } } elseif ( 'reprocesar_todo' == $accion ) { aicc_reprocesa_articulos(); aicc_lista_articulos(); //aicc_lista_articulos(); } else { // Lista los artículos de la tabla aicc_lista_articulos(); } echo "\n"; function aicc_lista_articulos() { global $wpdb; $tabla = aicc_tabla_generaciones(); $results = $wpdb->get_results( "SELECT id FROM $tabla ORDER BY fecha DESC;" ); if ( $results ) { $aicc_generacion = new AIccGeneracion(); // Muestra la tabla de creaciones completa echo $aicc_generacion->cabecera_tabla_lista_html(); foreach ($results as $result) { $id = $result->id; if ( $aicc_generacion->cargar( $id ) ) { echo $aicc_generacion->elemento_tabla_lista_html(); } else{ $mensaje_error .= __( 'Error loading the article', 'ai-content-creator' ) . " $id
"; aicc_admin_notice( $mensaje_error, 'error' ); } } echo $aicc_generacion->pie_tabla_lista_html(); // Muestra El botón de reprocesar todo si procede aicc_boton_reprocesar_todo(); } else { $mensaje = __( 'There are no articles to show. Generate them from', 'ai-content-creator' ) . ' ' . __( 'Create article' ) . '.
'; echo aicc_admin_notice( $mensaje, 'warning' ); } return; } function aicc_boton_reprocesar_todo() { $cantidad_articulos_reprocesables = aicc_cantidad_articulos_reprocesables(); if ( $cantidad_articulos_reprocesables > 1 ) { $html_contenido = '

' . __( 'It is recommended to repeat post-processing', 'ai-content-creator' ) . ".

\n"; $html_contenido .= '

' . __( 'You now have a version' , 'ai-content-creator' ). ' ' . aicc_validador_auto_actual() . ' ' . __( 'of the article post-processing system different from the one initially used in some articles', 'ai-content-creator' ) . '. '; $html_contenido .= __( 'The post-processing system takes care of basic validation of the content received from AI and a subsequent process to facilitate its publication', 'ai-content-creator' ) . ".

\n"; $html_contenido .= '

' . __( 'You can repeat the process in the affected articles in search of possible better results', 'ai-content-creator' ) . ".

\n"; $html_contenido .= '

' . __( 'The reprocessing does not affect possible drafts already created or previous publications', 'ai-content-creator' ) . ".

\n"; $html_contenido .= '

' . sprintf( __( 'A maximum of %s articles per batch will be reprocessed', 'ai-content-creator' ), aicc_limite_posproduccion() ) . ' ' . ".

\n"; $aicc_generacion = new AIccGeneracion(); $html_boton = $aicc_generacion->formulario_operacion_html( 'reprocesar_todo', __( 'Reprocess articles', 'ai-content-creator' ), 'dashicons-update' ); $html = $aicc_generacion->bloque_formulario_operacion_html( $html_contenido, $html_boton ); echo $html; } return; } function aicc_cantidad_articulos_reprocesables() { global $wpdb; $tabla = aicc_tabla_generaciones(); $cantidad = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $tabla WHERE validada_por <> %s;", aicc_validador_auto_actual() ) ); if ( aicc_modo_debug() ) { echo "[modo_debug] Artículos reprocesables: $cantidad
"; } return $cantidad; } function aicc_reprocesa_articulos() { // Reprocesa todos los artículos global $wpdb; $mensaje = ''; $hay_novedades = 0; $tabla = aicc_tabla_generaciones(); $results = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM $tabla WHERE validada_por <> %s LIMIT %d;", aicc_validador_auto_actual(), aicc_limite_posproduccion() ) ); if ( count( $results ) > 0 ) { //if ( $results ) { $aicc_generacion = new AIccGeneracion(); $hay_novedades = false; foreach ($results as $result) { $id = $result->id; if ( $aicc_generacion->cargar( $id ) ) { if ( aicc_modo_debug() ) { echo "[modo_debug] Reprocesando artículo: $id
"; } // Guarda el contenido viejo para contrastar si hay cambios $contenido_viejo = ''; if ( $aicc_generacion->contenido() ) { $contenido_viejo = $aicc_generacion->contenido(); } $aicc_generacion->procesar_respuesta_auto(); $aicc_generacion->validar_contenido_auto(); $aicc_generacion->grabar(); // Comprueba si ha causado novedades. if ( $aicc_generacion->contenido() != $contenido_viejo ) { $hay_novedades = true; $mensaje .= __( 'The reprocessing has modified the content of the article', 'ai-content-creator' ) . " $id: " . esc_html( $aicc_generacion->titulo() ) . '
'; } } else{ $mensaje_error .= __( 'Error loading the article', 'ai-content-creator' ) . " $id
"; aicc_admin_notice( $mensaje_error, 'error' ); } } } else { $mensaje .= __( 'There are no articles to reprocess', 'ai-content-creator' ) . '.
'; } if ( ! $hay_novedades ) { $mensaje .= __( 'The reprocessing has not caused the modification of any article', 'ai-content-creator' ) . '.
'; } echo aicc_admin_notice( $mensaje, 'notice' ); return; } function aicc_reprocesa_articulo( $id ) { if ( aicc_modo_debug() ) { echo "[modo_debug] Proceso de la generación: $id
"; } $aicc_generacion = new AIccGeneracion(); if ( $aicc_generacion->cargar( $id ) ) { // Guarda contenido y resultadoss de validaciones viejos para contrastar si hay cambios $contenido_viejo = ''; $notificaciones = ''; if ( $aicc_generacion->contenido() ) { $contenido_viejo = $aicc_generacion->contenido(); } $validacion_errores_viejo = array(); if ( $aicc_generacion->validacion_errores() ) { $validacion_errores_viejo = $aicc_generacion->validacion_errores(); } $validacion_advertencias_viejo = array(); if ( $aicc_generacion->validacion_advertencias() ) { $validacion_advertencias_viejo = $aicc_generacion->validacion_advertencias(); } $validacion_notificaciones_viejo = array(); if ( $aicc_generacion->validacion_notificaciones() ) { $validacion_notificaciones_viejo = $aicc_generacion->validacion_notificaciones(); } $aicc_generacion->procesar_respuesta_auto(); $aicc_generacion->validar_contenido_auto(); // Comprueba si ha causado novedades de contenido. $hay_novedades = false; if ( $aicc_generacion->contenido() !== $contenido_viejo ) { $hay_novedades = true; $notificaciones .= __( 'The process has modified the content compared to the previous one', 'ai-content-creator' ) . '.
'; } else { $notificaciones .= __( 'The process has not modified the generated content', 'ai-content-creator' ) . '.
'; } // Comprueba si ha causado novedades en errores. if ( array_diff ( $aicc_generacion->validacion_errores(), $validacion_errores_viejo ) ) { $hay_novedades = true; $notificaciones .= __( 'New errors have been detected', 'ai-content-creator' ) . '.
'; } elseif ( array_diff ( $validacion_errores_viejo, $aicc_generacion->validacion_errores() ) ) { $hay_novedades = true; $notificaciones .= __( 'Previous errors have been removed', 'ai-content-creator' ) . '.
'; } elseif ( aicc_modo_debug() ) { $notificaciones .= '[modo_debug] El proceso no ha modificado los errores generados.
'; } // Comprueba si ha causado novedades en advertencias. if ( array_diff ( $aicc_generacion->validacion_advertencias(), $validacion_advertencias_viejo ) ) { $hay_novedades = true; $notificaciones .= __( 'Warnings have been added', 'ai-content-creator' ) . '.
'; } elseif ( array_diff ( $validacion_advertencias_viejo, $aicc_generacion->validacion_advertencias() ) ) { $hay_novedades = true; $notificaciones .= __( 'Previous warnings have been removed', 'ai-content-creator' ) . '.
'; } elseif ( aicc_modo_debug() ) { $notificaciones .= '[modo_debug] El proceso no ha modificado las advertencias generadas.
'; } // Comprueba si ha causado novedades en notificaciones. if ( array_diff ( $aicc_generacion->validacion_notificaciones(), $validacion_notificaciones_viejo ) ) { $hay_novedades = true; $notificaciones .= __( 'Notifications have been added', 'ai-content-creator' ) . '.
'; } elseif ( array_diff ( $validacion_notificaciones_viejo, $aicc_generacion->validacion_notificaciones() ) ) { $hay_novedades = true; $notificaciones .= __( 'Previous notifications have been removed', 'ai-content-creator' ) . '.
'; } elseif ( aicc_modo_debug() ) { $notificaciones .= '[modo_debug] El proceso no ha modificado las notificaciones generadas.
'; } if ( ! $aicc_generacion->grabar() ) { echo aicc_admin_notice( __( 'Failed to save the reprocessing result', 'ai-content-creator' ) . " $id.", 'error' ); } else { echo aicc_admin_notice( $notificaciones, 'success' ); } } else { echo aicc_admin_notice( sprintf( __( 'Failed to load %s to reprocess it.', 'ai-content-creator' ), $id ), 'error' ); } return $hay_novedades; } function aicc_ver_articulo( $id ) { echo '' . __( 'Viewing the article generation result', 'ai-content-creator' ) . ": $id
"; $aicc_generacion = new AIccGeneracion(); if ( $aicc_generacion->cargar( $id ) ) { if ( aicc_modo_debug() ) { echo "
[modo_debug] \n"; echo $aicc_generacion->ver_solicitud(); } echo $aicc_generacion->ver_html(); // Para debug de contenido no válido if ( aicc_modo_debug() ) { echo "
[modo_debug] \n"; echo $aicc_generacion->ver_respuesta(); } echo $aicc_generacion->bloque_operaciones_html(); } else { echo aicc_admin_notice( sprintf( __( 'Failed to load article %s to view it', 'ai-content-creator' ), $id ), 'error' ); } return; } function aicc_crear_borrador_articulo( $id ) { $url_edicion = ''; $aicc_generacion = new AIccGeneracion(); if ( $aicc_generacion->cargar( $id ) ) { $aicc_generacion->crear_borrador(); if ( $aicc_generacion->publicada_post_id() ) { echo aicc_admin_notice( __( 'Draft created', 'ai-content-creator' ), 'success' ); /* echo ''; echo __( 'Draft edit', 'ai-content-creator' ); echo ''; */ echo '

'; echo __( 'A draft entry has been created with the article. You can now find it in the Posts section of your WordPress admin panel.', 'ai-content-creator' ); echo ' '; echo __( 'Make sure the content meets all desired technical, legal, and editorial requirements before publishing.', 'ai-content-creator' ); echo '

'; // Enlace como falso botón echo '
'; echo $aicc_generacion->falso_boton_editar_articulo_html(); echo '
'; } else { echo aicc_admin_notice( __( 'Failed to create the draft', 'ai-content-creator' ), 'error' ); } } else { echo aicc_admin_notice( sprintf( __( 'Failed to load %s to create a draft', 'ai-content-creator' ), $id ), 'error' ); } return; } function aicc_confirma_borrado_articulo( $id ) { $aicc_generacion = new AIccGeneracion(); // Cargarlo valida el id y toma el título if ( $aicc_generacion->cargar( $id ) ) { echo '

' . sprintf( __( 'Confirm that you want to delete the article %s', 'ai-content-creator' ), $id ) . '' . esc_html( $aicc_generacion->titulo ) . ' ' . __( 'created on', 'ai-content-creator' ) . ' ' . esc_html( $aicc_generacion->fecha ) . "

\n" ; // https://taller.abcdatos.net/wp-admin/admin.php?page=aicc_articles&id=59&accion=borrar ?>
contenido() ){ echo $aicc_generacion->iframe_contenido_html(); } } else { echo aicc_admin_notice( __( 'Cannot delete non-existent article', 'ai-content-creator' ) . " $id", 'error' ); } return; } function aicc_borra_articulo( $id ) { // Verifica el nonce antes del intento de borrar if ( isset( $_GET['campo_nonce'] ) && wp_verify_nonce( $_GET['campo_nonce'], 'borrado' ) ) { if ( isset( $_GET['aceptar'] ) ) { $aicc_generacion = new AIccGeneracion(); // Si existe, borra el artículo if ( $aicc_generacion->borrar( $id ) ) { echo aicc_admin_notice( sprintf( __( 'Article %s deleted', 'ai-content-creator' ), $id ), 'success' ); } else { echo aicc_admin_notice( sprintf( __( 'Failed to delete article %s', 'ai-content-creator' ), $id ), 'error' ); } } elseif ( isset( $_GET['cancelar'] ) ) { echo aicc_admin_notice( sprintf( __( 'Article %s deletion operation canceled', 'ai-content-creator' ), $id ), 'warning' ); } else { echo aicc_admin_notice( sprintf( __( 'Article %s deletion operation not processed', 'ai-content-creator' ), $id ), 'error' ); } } else { // Nomce no superado echo aicc_admin_notice( __( 'The followed link does not allow deleting the article', 'ai-content-creator' ), 'error' ); } return; }