id = $data; } return $this->id; } function fecha( $data = NULL ) { if ( ! is_null( $data ) ) { $this->fecha = $data; } return $this->fecha; } function plugin_version( $data = NULL ) { if ( ! is_null( $data ) ) { $this->plugin_version = $data; } return $this->plugin_version; } function generador( $data = NULL ) { if ( ! is_null( $data ) ) { $this->generador = $data; } return $this->generador; } function modelo( $data = NULL ) { if ( ! is_null( $data ) ) { $this->modelo = $data; } return $this->modelo; } function idioma( $data = NULL ) { if ( ! is_null( $data ) ) { $this->idioma = $data; } return $this->idioma; } function longitud_solicitada( $data = NULL ) { if ( ! is_null( $data ) ) { $this->longitud_solicitada = $data; } return $this->longitud_solicitada; } function tono( $data = NULL ) { if ( ! is_null( $data ) ) { $this->tono = $data; } return $this->tono; } function mensaje_sistema( $data = NULL ) { if ( ! is_null( $data ) ) { $this->mensaje_sistema = $data; } return $this->mensaje_sistema; } function contexto( $data = NULL ) { if ( ! is_null( $data ) ) { $this->contexto = $data; } return $this->contexto; } function titulo( $data = NULL ) { if ( ! is_null( $data ) ) { $this->titulo = $data; } return $this->titulo; } function directrices_adicionales( $data = NULL ) { if ( ! is_null( $data ) ) { $this->directrices_adicionales = $data; } return $this->directrices_adicionales; } function prompt( $data = NULL ) { if ( ! is_null( $data ) ) { $this->prompt = $data; } return $this->prompt; } function solicitud( $data = NULL ) { if ( ! is_null( $data ) ) { $this->solicitud = $data; } return $this->solicitud; } function respuesta( $data = NULL ) { if ( ! is_null( $data ) ) { $this->respuesta = $data; } return $this->respuesta; } function error( $data = NULL ) { if ( ! is_null( $data ) ) { $this->error = $data; } return $this->error; } function contenido( $data = NULL ) { if ( ! is_null( $data ) ) { $this->contenido = $data; } return $this->contenido; } function meta_description( $data = NULL ) { if ( ! is_null( $data ) ) { $this->meta_description = $data; } return $this->meta_description; } function meta_keywords( $data = NULL ) { if ( ! is_null( $data ) ) { $this->meta_keywords = $data; } return $this->meta_keywords; } function valida( $data = NULL ) { if ( ! is_null( $data ) ) { $this->valida = $data; } return $this->valida; } function validacion_errores( $data = NULL ) { if ( ! is_null( $data ) ) { $this->validacion_errores = $data; } return $this->validacion_errores; } function validacion_advertencias( $data = NULL ) { if ( ! is_null( $data ) ) { $this->validacion_advertencias = $data; } return $this->validacion_advertencias; } function validacion_notificaciones( $data = NULL ) { if ( ! is_null( $data ) ) { $this->validacion_notificaciones = $data; } return $this->validacion_notificaciones; } function validada_por( $data = NULL ) { if ( ! is_null( $data ) ) { $this->validada_por = $data; } return $this->validada_por; } function validada_fecha( $data = NULL ) { if ( ! is_null( $data ) ) { $this->validada_fecha = $data; } return $this->validada_fecha; } function autor( $data = NULL ) { if ( ! is_null( $data ) ) { $this->autor = $data; } return $this->autor; } function publicada_post_id( $data = NULL ) { if ( ! is_null( $data ) ) { $this->publicada_post_id = $data; } return $this->publicada_post_id; } function publicable_slug( $data = NULL ) { if ( ! is_null( $data ) ) { $this->publicable_slug = $data; } return $this->publicable_slug; } function publicada_fecha( $data = NULL ) { if ( ! is_null( $data ) ) { $this->publicada_fecha = $data; } return $this->publicada_fecha; } function __construct() { $this->limpiar(); } public function limpiar() { $this->id = null; $this->fecha = '0000-00-00 00:00:00'; $this->plugin_version = ''; $this->generador = ''; $this->modelo = ''; $this->idioma = ''; $this->longitud_solicitada = 0; $this->tono = ''; $this->mensaje_sistema = ''; $this->contexto = ''; $this->titulo = ''; $this->directrices_adicionales = ''; $this->prompt = ''; $this->solicitud = ''; $this->respuesta = ''; $this->error = 0; $this->contenido = ''; $this->meta_description = ''; $this->meta_keywords = ''; $this->valida = 0; $this->validacion_errores = ''; $this->validacion_advertencias = ''; $this->validacion_notificaciones = ''; $this->validada_por = ''; $this->validada_fecha = '0000-00-00 00:00:00'; $this->autor = ''; $this->publicada_post_id = 0; $this->publicable_slug = ''; $this->publicada_fecha = '0000-00-00 00:00:00'; } public function grabar() { // Método para grabar las propiedades a la base de datos global $wpdb; // Objeto global de WordPress para acceder a la base de datos // Retira la clave de API de la solicitud por seguridad $solicitud_anonimizada = $this->solicitud; $solicitud_anonimizada['headers']['Authorization'] = 'Bearer sk-my-hidden-api-key'; $datos = array( 'fecha' => $this->fecha, 'plugin_version' => $this->plugin_version, 'generador' => $this->generador, 'modelo' => $this->modelo, 'idioma' => $this->idioma, 'longitud_solicitada' => $this->longitud_solicitada, 'tono' => $this->tono, 'mensaje_sistema' => $this->mensaje_sistema, 'contexto' => $this->contexto, 'titulo' => $this->titulo, 'directrices_adicionales' => $this->directrices_adicionales, 'prompt' => $this->prompt, 'solicitud' => wp_json_encode( $solicitud_anonimizada ), 'respuesta' => wp_json_encode( $this->respuesta ), 'error' => $this->error, 'contenido' => $this->contenido, 'meta_description' => $this->meta_description, 'meta_keywords' => $this->meta_keywords, 'valida' => $this->valida, 'validacion_errores' => wp_json_encode( $this->validacion_errores ), 'validacion_advertencias' => wp_json_encode( $this->validacion_advertencias ), 'validacion_notificaciones' => wp_json_encode( $this->validacion_notificaciones ), 'validada_por' => $this->validada_por, 'validada_fecha' => $this->validada_fecha, 'autor' => $this->autor, 'publicada_post_id' => $this->publicada_post_id, 'publicable_slug' => $this->publicable_slug, 'publicada_fecha' => $this->publicada_fecha ); $tabla = aicc_tabla_generaciones(); if ( $this->id ) { $resultado = $wpdb->update( $tabla, $datos, array( 'id' => $this->id ) ); } else { $resultado = $wpdb->insert( $tabla, $datos ); $this->id = $wpdb->insert_id; } return ($resultado !== false); } public function cargar( $id ) { // Método para cargar las propiedades desde la base de datos global $wpdb; // Si no se indica id, se carga el de la instancia if ( ! $id ) { $id = $this->id; } //$tabla = $wpdb->prefix . 'mi_tabla'; // Reemplaza 'mi_tabla' con el nombre de tu tabla $tabla = aicc_tabla_generaciones(); // Preparamos la sentencia SQL para obtener las propiedades de la fila con el id correspondiente $sql = $wpdb->prepare( "SELECT * FROM $tabla WHERE id = %d", $id ); // Ejecutamos la consulta $fila = $wpdb->get_row( $sql ); // Si la consulta no devuelve resultados, devolvemos false if ( is_null( $fila ) ) { return false; } // Asignamos los valores recuperados a las propiedades del objeto // https://www.php.net/manual/es/function.json-decode.php Observar parámetros $this->id = $fila->id; $this->fecha = $fila->fecha; $this->plugin_version = $fila->plugin_version; $this->generador = $fila->generador; $this->modelo = $fila->modelo; $this->idioma = $fila->idioma; $this->longitud_solicitada = $fila->longitud_solicitada; $this->tono = $fila->tono; $this->mensaje_sistema = $fila->mensaje_sistema; $this->contexto = $fila->contexto; $this->titulo = $fila->titulo; $this->directrices_adicionales = $fila->directrices_adicionales; $this->prompt = $fila->prompt; $this->solicitud = json_decode( $fila->solicitud, true ); $this->respuesta = json_decode( $fila->respuesta, true ); $this->error = $fila->error; $this->contenido = $fila->contenido; $this->meta_description = $fila->meta_description; $this->meta_keywords = $fila->meta_keywords; $this->valida = $fila->valida; $this->validacion_errores = json_decode( $fila->validacion_errores, true ); $this->validacion_advertencias = json_decode( $fila->validacion_advertencias, true ); $this->validacion_notificaciones = json_decode( $fila->validacion_notificaciones, true ); $this->validada_por = $fila->validada_por; $this->validada_fecha = $fila->validada_fecha; $this->autor = $fila->autor; $this->publicada_post_id = $fila->publicada_post_id; $this->publicable_slug = $fila->publicable_slug; $this->publicada_fecha = $fila->publicada_fecha; return true; } public function url_editar_post() { // URL de WP para editar el borrador $url = ''; if ( $this->publicada_post_id ) { $url = get_edit_post_link( $this->publicada_post_id ); } return $url; } public function crear_borrador() { // Crear un borrador con la generación //$post_category = array( 'category1', 'category2' ); //$post_tags = 'etiqueta1, etiqueta2'; $post_category = array(); $post_tags = ''; $new_post = array( 'post_title' => $this->titulo, 'post_content' => wp_kses_post( $this->contenido ), 'post_status' => 'draft', 'post_category' => $post_category, 'tags_input' => $post_tags ); $post_id = wp_insert_post( $new_post ); if ( $post_id > 0 ) { $this->publicada_post_id = $post_id; $this->publicada_fecha = current_time( 'Y-m-d H:i:s' ); $this->grabar(); } return $post_id; } public function borrar( $id ) { // Borrar una fila dado el id global $wpdb; // Si no se indica id, se borra el de la instancia if ( ! $id ) { $id = $this->id; } $tabla = aicc_tabla_generaciones(); $result = $wpdb->delete( $tabla, array( 'id' => $id ) ); if ( $result !== false ) { $this->id = null; return true; } else { return false; } } public function ver_html() { // Ver el contenido de un artículo $html = esc_html( sprintf( __( 'Created: %s by %s', 'ai-content-creator' ), $this->fecha_hora_corta( $this->fecha ), $this->modelo ) ); if ( $this->generador ) { $html .= esc_html( ' (' . $this->generador . ')' ); } $html .= "
\n"; $html .= '

' . __( 'Title', 'ai-content-creator' ) . ': ' . esc_html( $this->titulo ) . "

\n"; $html .= $this->ver_errores_html(); if ($this->contenido ) { $html .= '' . __( 'Content', 'ai-content-creator' ) . ':'; $html .= $this->iframe_contenido_html(); } elseif ( aicc_modo_debug() ) { $html .= ' ' . __( 'No content', 'ai-content-creator' ) . ".
\n"; } return $html; } public function ver_errores_html() { // Ver la lista de errores $html = ''; $errores_acumulados = array(); if ( $this->error_proceso_api() ) { $errores_acumulados[] = __( 'Error', 'ai-content-creator' ) . ' HTTP: '. esc_html( $this->error_proceso_api() ); } if ( $this->error_respuesta_ai() ) { $errores_acumulados[] = __( 'Error', 'ai-content-creator' ) . ' IA: '. esc_html( $this->error_respuesta_ai() ); } if ( $this->error_finalizacion_ai() ) { $errores_acumulados[] = __( 'Article termination reason', 'ai-content-creator' ) . ': '. esc_html( $this->error_finalizacion_ai() ); } if ( ! empty ( $this->validacion_errores ) ) { $errores_acumulados = array_merge ( $errores_acumulados, $this->validacion_errores ); } // Escapa el html antes de agregar el icono, que sí ha de aplicarse como html. // Errores $errores_acumulados_html = array(); if ( ! empty ( $errores_acumulados ) ) { foreach ( $errores_acumulados as $error_acumulado ) { $errores_acumulados_html[] = esc_html($error_acumulado); } } // Advertencias $advertencias_html = array(); if ( ! empty ( $this->validacion_advertencias ) ) { foreach ( $this->validacion_advertencias as $advertencia ) { $advertencias_html[] = esc_html($advertencia); } } // Notificaciones $notificaciones_html = array(); if ( ! empty ( $this->validacion_notificaciones ) ) { foreach ( $this->validacion_notificaciones as $notificacion ) { $notificaciones_html[] = esc_html($notificacion); } } if ( ! empty ( $errores_acumulados ) ) { $html .= $this->icono_aviso_html( $tipo_aviso = 'error' ) . ' '; $html .= nl2br( join( "\n" . $this->icono_aviso_html( $tipo_aviso = 'error' ) . ' ' , $errores_acumulados_html ) ); $html .= "
\n"; } elseif ( aicc_modo_debug() ) { $html .= $this->icono_aviso_html( $tipo_aviso = 'notificacion' ) . ' ' . __( 'No errors found', 'ai-content-creator' ) . ".
\n"; } if ( ! empty ( $advertencias_html ) ) { $html .= $this->icono_aviso_html( $tipo_aviso = 'advertencia' ) . ' '; $html .= nl2br( join( "\n" . $this->icono_aviso_html( $tipo_aviso = 'advertencia' ) . ' ', $advertencias_html ) ); $html .= "
\n"; } elseif ( aicc_modo_debug() ) { $html .= $this->icono_aviso_html( $tipo_aviso = 'notificacion' ) . ' ' . __( 'No warnings found', 'ai-content-creator' ) . ".
\n"; } if ( ! empty ( $this->validacion_notificaciones ) ) { $html .= $this->icono_aviso_html( $tipo_aviso = 'notificacion' ) . ' '; $html .= nl2br( join( "\n" . $this->icono_aviso_html( $tipo_aviso = 'notificacion' ) . ' ', $notificaciones_html ) ); $html .= "
\n"; } elseif ( aicc_modo_debug() ) { $html .= $this->icono_aviso_html( $tipo_aviso = 'notificacion' ) . ' ' . __( 'No notifications found', 'ai-content-creator' ) . ".
\n"; } // Agrega un salto de línea final si hay contenido if ( $html ) { $html .= "
\n"; } return $html; } public function ver_solicitud() { // Ver la solicitud de generación $html = __( 'Request', 'ai-content-creator' ) . ': ' . nl2br( esc_html( var_export( $this->solicitud, true ) ) ) . "
\n"; return $html; } public function ver_respuesta() { // Ver la respuesta a la generación $html = __( 'Response', 'ai-content-creator' ) . ': ' . nl2br( esc_html( var_export( $this->respuesta, true ) ) ) . "
\n"; return $html; } public function procesar_respuesta_auto() { // Procesa la respuesta de la comunicación consultando a la API, tomando de ahí los posibles errores y el contenido de . if ( $this->error_proceso_api() ) { // Errores HTTP $this->error( 1 ); //$this->texto_error_ai( $this->error_proceso_api() ); } else { // Errores indicados expresamente por la AI if ( $this->error_respuesta_ai() ) { $this->error( 1 ); //$this->texto_error_ai( $this->error_respuesta_ai() ); } else { // Contenido del artículo y posible error si se le detecta alguno list( $article_text, $estado_error ) = aicc_procesar_respuesta_auto( $this ); $this->contenido( $article_text ); $this->error( $estado_error ); } } } public function validar_contenido_auto() { // Validar el contenido de un artículo automáticamente /* // He visto respuestas que son solo repeticiones consecutivas de la pregunta, igual o cambiando el h1 por h2, quizás en temperaturas de 0.1 y 0.2 den GPT-2 // en 0.5 baja a h3, h4, h5... y quitando los

// y hace diveros h2 con variaciones del título... sin cerrar el

*/ $this->valida = aicc_validar_contenido_auto( $this->contenido ); // Toma la lista de errores de validación $this->validacion_errores = aicc_errores_validacion_contenido( $this->contenido ); $this->validacion_advertencias = aicc_advertencias_validacion_contenido( $this->contenido ); $this->validacion_notificaciones = aicc_notificaciones_validacion_contenido( $this->contenido ); $this->validada_por = aicc_validador_auto_actual(); $this->validada_fecha = current_time( 'Y-m-d H:i:s' ); return $this->valida; } public function error_proceso_api() { // Texto del posible error en el proceso $error_proceso_api = ''; if ( is_wp_error( $this->respuesta ) ) { // Típicamente errores en la comunicación HTTP $error_proceso_api = $this->respuesta->get_error_message(); } return $error_proceso_api; } public function error_respuesta_ai() { // Errores indicados como respuesta de la IA $error_respuesta_ai = ''; if ( ! is_wp_error( $this->respuesta ) ) { $body = wp_remote_retrieve_body( $this->respuesta ); $respuesta_body = json_decode( $body, true ); if ( isset ( $respuesta_body['error'] ) ) { $error_respuesta_ai = $respuesta_body['error']['message']; // Algunos errores de la AI, siendo estándar y conocidos, los puedo traducir como constantes $error_respuesta_ai = aicc_traduce_error_externo( $error_respuesta_ai ); } } return $error_respuesta_ai; } public function error_finalizacion_ai() { // Errores indicados como causa de finalización de la IA $error_finalizacion_ai = ''; $body = wp_remote_retrieve_body( $this->respuesta ); $response_body = json_decode( $body, true ); $error_finalizacion_ai = aicc_causa_fin_respuesta( $this->generador, $response_body ); if ( 'stop' == $error_finalizacion_ai ) { // stop indica la terminación normal $error_finalizacion_ai = ''; } return $error_finalizacion_ai; } public function iframe_contenido_html() { // Uso de sandbox admitiendo tan solo allow-same-origin para poder redimensionar la altura del marco. $html = '' . "\n"; // Script para ajustar la altura del frame en el contenedor padre. $html .= "\n"; return $html; } public function cabecera_tabla_lista_html() { $html = '' . "\n"; $html .= "\n"; $html .= '\n"; $html .= '\n"; $html .= '\n"; $html .= '\n"; $html .= '\n"; $html .= '\n"; $html .= '\n"; $html .= '\n"; $html .= "\n"; return $html; } public function elemento_tabla_lista_html() { $html = ''; $html .= "\n"; $html .= '\n"; $html .= '\n"; $html .= '\n"; $html .= '\n"; // Ver $html .= '\n"; // Estado $html .= '\n"; // Acción. En función del estado del artículo y del posprocesaror, indica la acción recomendada $html .= '\n"; // Borrar $html .= '\n"; $html .= "\n"; return $html; } public function pie_tabla_lista_html() { return "
' . __( 'ID', 'ai-content-creator' ) . "' . __( 'Date', 'ai-content-creator' ) . "' . __( 'Model', 'ai-content-creator' ) . "' . __( 'Title', 'ai-content-creator' ) . "' . __( 'View', 'ai-content-creator' ) . "' . __( 'Status', 'ai-content-creator' ) . "' . __( 'Action', 'ai-content-creator' ) . "' . __( 'Delete', 'ai-content-creator' ) . "
'; $html .= esc_html( $this->id ); $html .= "'; $html .= esc_html( $this->fecha_hora_corta( $this->fecha ) ); $html .= "'; $html .= esc_html( aicc_denominacion_modelo( $this->modelo ) ); $html .= "'; if ( $this->titulo ) { $html .= esc_html( $this->titulo ); } else { $html .= '[' . esc_html( __( 'Untitled', 'ai-content-creator' ) ) . ']'; } $html .= "'; $html .= ' '; $html .= $this->dashicon_html( 'dashicons-visibility', __( 'View', 'ai-content-creator' ), 'text-decoration:none;' ); $html .= ''; $html .= "'; $html .= $this->icono_estado_html(); $html .= "'; $html .= $this->icono_accion_html(); $html .= "'; //$tooltip = 'No borrable, hay un post creado basado en este artículo.'; if ( ! $this->publicada_post_id ) { $tooltip = __( 'Delete', 'ai-content-creator' ); $html .= ' '; $html .= $this->dashicon_html( 'dashicons-trash', $tooltip, 'text-decoration:none;' ); $html .= ''; } $html .= "
\n"; } public function bloque_operaciones_html() { $html = ''; // Reprocesar if ( $this->validada_por != aicc_validador_auto_actual() ) { $html_contenido = '

' . __( 'You have a different version of the articles post-production system than the one initially used.', 'ai-content-creator' ); $html_contenido .= ' ' . __( 'That system is responsible for the basic validation of the content received from the AI and a subsequent process to facilitate its publication.', 'ai-content-creator' ) . "

\n"; $html_contenido .= '

' . __( 'You can repeat post-production in search of a possible better result.', 'ai-content-creator' ) . "

\n"; if ( $this->publicada_post_id ) { $html_contenido .= '

' . __( 'The reprocessing does not affect the previously created draft.', 'ai-content-creator' ) . "

\n"; } $html_boton = $this->formulario_operacion_html( 'reprocesar', __( 'Reprocess', 'ai-content-creator' ), 'dashicons-update' ); $html .= $this->bloque_formulario_operacion_html( $html_contenido, $html_boton ); } // Regenerar $html_contenido = '

' . __( 'You can go back to the beginning to create a new article based on the request used in this one.', 'ai-content-creator' ) . "

\n"; $html_contenido .= '

' . __( 'The new article will not overwrite the data of this one', 'ai-content-creator' ); if ( $this->publicada_post_id ) { $html_contenido .= ' '; $html_contenido .= __( 'nor will affect the previously created draft', 'ai-content-creator' ); } $html_contenido .= ".

\n"; // Alternativas: dashicons-welcome-add-page, dashicons-controls-repeat, dashicons-redo, dashicons-editor-break $html_boton = $this->formulario_operacion_html( 'regenerar', __( 'Create another', 'ai-content-creator' ), 'dashicons-welcome-add-page' ); $html .= $this->bloque_formulario_operacion_html( $html_contenido, $html_boton ); // Editar post + borrar generación if ( $this->publicada_post_id ) { $html_contenido = '

' . __( 'You can', 'ai-content-creator' ) . ' '; //$html_contenido .= ''; $html_contenido .= __( 'edit the article', 'ai-content-creator' ); //$html_contenido .= ''; $html_contenido .= ' '; $html_contenido .= __( "with your WordPress's usual system", 'ai-content-creator' ) . ".

\n"; // Enlace como falso botón $html_boton = '
'; $html_boton .= $this->falso_boton_editar_articulo_html(); $html_boton .= '
'; $html .= $this->bloque_formulario_operacion_html( $html_contenido, $html_boton ); $html_contenido = '

' . __( 'If you are sure that you will not need any revision of how it was generated anymore, you can delete it. This change is not reversible. The draft or published article will not be affected.', 'ai-content-creator' ) . "

\n"; $html_boton = $this->formulario_operacion_html( 'borrar', __( 'Delete', 'ai-content-creator' ), 'dashicons-trash' ); $html .= $this->bloque_formulario_operacion_html( $html_contenido, $html_boton ); } else { if ( current_user_can( 'edit_posts' ) ) { if ( $this->valida ) { // Crear borrador $html_contenido = '

' . __( 'Create a draft using the generated content to edit and finalize its publishing.', 'ai-content-creator' ) . "

\n"; // Alternativa: dashicons-migrate $html_boton = $this->formulario_operacion_html( 'borrador', __( 'Create draft', 'ai-content-creator' ), 'dashicons-external' ); $html .= $this->bloque_formulario_operacion_html( $html_contenido, $html_boton ); } else { // Crear borrador aun con error if ( $this->contenido ) { $html_contenido = '

' . __( 'Although errors have been detected in the generated content, if you want to take advantage of it, you can create a draft to edit and finalize its publishing.', 'ai-content-creator' ) . "

\n"; $texto_confirmacion = __( 'I understand that the content of the draft may be defective.', 'ai-content-creator' ); $html_contenido .= '

' . $texto_confirmacion . "

\n"; $html_boton = $this->formulario_operacion_html( 'borrador', __( 'Create draft', 'ai-content-creator' ), 'dashicons-external' ); $html .= $this->bloque_formulario_operacion_html( $html_contenido, $html_boton ); $html .= ''; // Llama inicialmente para deshabilitar, así uso el código estándar con el botón habilitado en origen $html .= ''; //javascript que deshabilite el botón 'borrador' directamente //javascript que habilite el botón 'borrador' al hacer click en la casilla //onchange="isChecked(this, 'borrador')" } } } else { // No tiene permisos para crear ni editar borradores // En principio no debería llegar aquí tampoco si no los tiene. $html .= '

' . __( "You don't have permission to create drafts.", 'ai-content-creator' ) . "

\n"; } // Borrar $html_contenido = '

' . __( 'If the content is not useful and you will not need any revision of how it was generated or create a draft with it, you can delete it. This change is not reversible.', 'ai-content-creator' ) . "

\n"; $html_boton = $this->formulario_operacion_html( 'borrar', __( 'Delete', 'ai-content-creator' ), 'dashicons-trash' ); $html .= $this->bloque_formulario_operacion_html( $html_contenido, $html_boton ); } // Otros dashicons útiles: dashicons-editor-help, dashicons-download, dashicons-upload // https://developer.wordpress.org/resource/dashicons/ return $html; } public function bloque_formulario_operacion_html( $html_contenido, $html_boton ) { $html = '
'; $html .= $html_contenido; $html .= $html_boton; $html .= '
'; return $html; } public function formulario_operacion_html( $accion, $texto, $dashicon = '' ) { // Reprocesar ha de ir a la página de creación y con POST // Los demás, a la de artículos y con GET if ( 'regenerar' == $accion ) { $action = 'admin.php'; $pagina = 'aicc_menu'; $metodo = 'GET'; } else { $action = 'admin.php'; $pagina = 'aicc_articles'; $metodo = 'GET'; } $html = '
' . "\n"; if ( $pagina ){ $html .= ' ' . "\n"; } $html .= ' ' . "\n"; // Todos indican id menos reprocesar_todo if ( 'reprocesar_todo' != $accion ) { $html .= ' ' . "\n"; if ( 'borrar' == $accion ) { $html .= wp_nonce_field('borrado', 'campo_nonce');; } } // Proporciona estilo centrar el botón. $html .= '
'; $html .= ' ' . $this->boton_formulario_operacion_html( $texto, $accion, $dashicon ) . "\n"; $html .= '
'; $html .= '
'; return $html; } public function falso_boton_editar_articulo_html() { // Enlace como falso botón // Icono y texto en funciçon de si es borrador o está publicado if ( 'publish' == get_post_status( $this->publicada_post_id ) ) { $dashicon = 'dashicons-media-document'; $texto = __( 'Edit published article', 'ai-content-creator' ); } else { $dashicon = 'dashicons-edit-page'; //$texto = sprintf( __( 'Edit draft prepared on %s', 'ai-content-creator' ), $this->fecha_hora_corta( $this->publicada_fecha ) ); $texto = __( 'Edit draft', 'ai-content-creator' ); } // Forma el enlace con dashicon y texto al estilo de boton $html = ''; if ( $dashicon ) { $html .= ' '; } $html .= $texto; $html .= ''; return $html; } private function fecha_hora_corta ( $fecha ) { // Convierte un formato datetime de MySQL a fecha/hora del usuario $fecha_php = strtotime( $fecha ); $fecha_corta = date_i18n( get_option('date_format') . ' ' . get_option('time_format'), $fecha_php ); return $fecha_corta; } private function icono_estado_html () { // Indica en html estado de un artículo $html = ''; if ( $this->error ) { // Alternativo: dashicons-no-alt $html .= $this->dashicon_html( 'dashicons-dismiss', __( 'An error occurred while trying to create the article and it is not valid.', 'ai-content-creator' ), 'color:red;' ); } elseif ( $this->publicada_post_id ) { if ( 'publish' == get_post_status( $this->publicada_post_id ) ) { $html .= $this->dashicon_html( 'dashicons-media-document', __( 'Article published', 'ai-content-creator' ), 'color:green;' ); } else { $html .= $this->dashicon_html( 'dashicons-media-document', sprintf( __( 'Draft prepared on %s', 'ai-content-creator' ), $this->fecha_hora_corta( $this->publicada_fecha ) ), 'color:orange;' ); } } elseif ( $this->valida ) { if ( $this->validada_por ) { $html .= $this->dashicon_html( 'dashicons-yes-alt', __( 'Validated', 'ai-content-creator' ) . $this->por_validador_fecha_html(), 'color:green;' ); } else { // Supuestamente ya no procede $html .= $this->dashicon_html( 'dashicons-yes', __( 'Automatic preliminary validation', 'ai-content-creator' ), 'color:green;' ); } } else { if ( $this->validada_por ) { $html .= $this->dashicon_html( 'dashicons-warning', __( 'Did not pass validation', 'ai-content-creator' ) . $this->por_validador_fecha_html(), 'color:orange;' ); } else { $html .= $this->dashicon_html( 'dashicons-warning', __( 'Did not pass validation', 'ai-content-creator' ), 'color:orange;' ); } } return $html; } private function icono_accion_html() { $html = ''; if ( $this->publicada_post_id ) { // Editable o no if ( current_user_can( 'edit_post', $this->publicada_post_id ) ) { $html .= ''; // Publicado o no if ( 'publish' == get_post_status( $this->publicada_post_id ) ) { $html .= $this->dashicon_html( 'dashicons-media-document', __( 'Edit published article', 'ai-content-creator' ) ); } else { $html .= $this->dashicon_html( 'dashicons-edit-page', esc_attr( sprintf( __( 'Edit draft prepared on %s', 'ai-content-creator' ), $this->fecha_hora_corta( $this->publicada_fecha ) ) ) ); } $html .= ''; } else { // Publicado o no if ( 'publish' == get_post_status( $this->publicada_post_id ) ) { $html .= $this->dashicon_html( 'dashicons-media-document', esc_attr( __( 'You don\'t have permission to edit the published article.', 'ai-content-creator' ) ), 'color:gray;' ); } else { $html .= $this->dashicon_html( 'dashicons-edit-page', esc_attr( __( 'You don\'t have permission to edit the published draft.', 'ai-content-creator' ) ), 'color:gray;' ); } } } elseif ( $this->validada_por != aicc_validador_auto_actual() ) { $html .= ''; $html .= $this->dashicon_html( 'dashicons-update', __( 'Reprocess', 'ai-content-creator' ), 'text-decoration:none;' ); $html .= ''; } elseif ( $this->valida ) { if ( current_user_can( 'edit_posts' ) ) { $html .= ''; $html .= $this->dashicon_html( 'dashicons-external', __( 'Create draft', 'ai-content-creator' ), 'text-decoration:none;' ); $html .= ''; } else { $html .= $this->dashicon_html( 'dashicons-external', esc_attr( __( 'You don\'t have permission to create drafts.', 'ai-content-creator' ) ), 'color:gray;' ); } } else { $html .= ''; $html .= $this->dashicon_html( 'dashicons-welcome-add-page', __( 'Create another', 'ai-content-creator' ), 'text-decoration:none;' ); $html .= ''; } return $html; } private function icono_aviso_html( $tipo_aviso = 'error' ) { $titulo = ''; if ( 'notificacion' == $tipo_aviso ) { $dashicon = 'dashicons-info'; $color = 'blue'; } elseif ( 'advertencia' == $tipo_aviso ) { $dashicon = 'dashicons-warning'; $color = 'orange'; } else { $dashicon = 'dashicons-dismiss'; $color = 'red'; } $estilo = "color: $color;"; $html = $this->dashicon_html ( $dashicon, $titulo, $estilo ) ; return $html; } private function por_validador_fecha_html() { // Crea el texto de la validación u otras operaciones reliazadas por algún agente y fecha $html = $this->por_agente_fecha_html( $this->validada_por, $this->validada_fecha ); return $html; } private function por_agente_fecha_html( $agente, $fecha ) { // Crea el texto de la validación u otras operaciones reliazadas por algún agente y fecha $html = ' ' . sprintf( __( "by '%s' at %s", 'ai-content-creator' ), $agente, $this->fecha_hora_corta( $fecha ) ); return $html; } private function dashicon_html ( $dashicon, $titulo, $estilo = '' ) { // Muestra el código de un dashicon con el tooltip que pueda proceder $html = '