0; if ($is_editing) { $id = intval($_REQUEST['id']); $super1status=$id; } else { $super1status=botwriter_super1_check_task_finish(); } $table_name = $wpdb->prefix . 'botwriter_tasks'; $dir_images = plugin_dir_url(dirname(__FILE__)) . '/assets/images/'; ?>

0, /* translators: %d: next super task number */ 'task_name' => sprintf(__('Super Task %d', 'botwriter'), $wpdb->get_var("SELECT COUNT(*) FROM $table_name WHERE website_type LIKE 'super%'") + 1), 'writer' => 'ai_cerebro', 'narration' => 'Descriptive', 'custom_style' => '', 'post_language' => '', 'post_length' => '800', 'custom_post_length' => '', 'post_status' => 'publish', 'days' => '', 'times_per_day' => 1, 'execution_count' => 0, // Initialize execution count to zero 'last_execution_date' => gmdate('Y-m-d H:i:s', current_time('timestamp')), // Set last execution date to null initially 'website_type' => 'ai', 'website_name' => '', 'domain_name' => '', 'category_id' => '0', 'website_category_id' => '', 'website_category_name' => '', 'aigenerated_title' => '', 'aigenerated_content' => '', 'aigenerated_tags' => '', 'aigenerated_image' => '', 'post_count' => '', 'post_order' => '', 'title_prompt' => '', 'content_prompt' => '', 'tags_prompt' => '', 'image_prompt' => '', 'image_generating_status' => '', 'author_selection' => '', 'news_keyword' => '', 'news_country' => '', 'news_language' => '', 'news_time_published' => '', 'news_source' => '', 'rss_source' => '', 'ai_keywords' => '', 'disable_ai_images' => 0, 'template_id' => null, ); if ( isset($_REQUEST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['nonce'])), basename(__FILE__))) { /* echo "
";
      print_r($_POST);
      echo "
"; */ $days = isset($_POST['days']) ? implode(",", array_map('sanitize_text_field', wp_unslash($_POST['days']))) : ""; $times_per_day = isset($_POST['times_per_day']) ? intval(wp_unslash($_POST['times_per_day'])) : 1; // Process only the specific values needed $item = array( 'id' => isset($_POST['id']) ? intval(wp_unslash($_POST['id'])) : 0, 'task_name' => isset($_POST['task_name']) ? sanitize_text_field(wp_unslash($_POST['task_name'])) : '', 'post_status' => isset($_POST['post_status']) ? sanitize_text_field(wp_unslash($_POST['post_status'])) : '', 'days' => $days, 'times_per_day' => $times_per_day, 'writer' => 'ai_cerebro', 'narration' => isset($_POST['narration']) ? sanitize_text_field(wp_unslash($_POST['narration'])) : '', 'post_length' => isset($_POST['post_length']) ? sanitize_text_field(wp_unslash($_POST['post_length'])) : '', 'custom_post_length'=> isset($_POST['custom_post_length']) ? sanitize_text_field(wp_unslash($_POST['custom_post_length'])) : '', 'custom_style' => isset($_POST['custom_style']) ? sanitize_text_field(wp_unslash($_POST['custom_style'])) : '', 'post_language' => isset($_POST['post_language']) ? sanitize_text_field(wp_unslash($_POST['post_language'])) : '', 'website_type' => 'super2', 'website_name' => '', 'domain_name' => isset($_POST['domain_name']) ? sanitize_url(wp_unslash($_POST['domain_name'])) : '', 'category_id' => isset($_POST['category_id']) ? sanitize_text_field(wp_unslash($_POST['category_id'])) : '0', 'website_category_id'=> '', 'website_category_name'=> '', 'aigenerated_title' => '', 'aigenerated_content'=> '', 'aigenerated_tags' => '', 'aigenerated_image' => '', 'post_count' => 5, 'post_order' => '', 'title_prompt' => '', 'content_prompt' => '', 'tags_prompt' => '', 'image_prompt' => '', 'image_generating_status' => '', 'author_selection' => isset($_POST['author_selection']) ? sanitize_text_field(wp_unslash($_POST['author_selection'])) : '', 'news_keyword' => isset($_POST['news_keyword']) ? sanitize_text_field(wp_unslash($_POST['news_keyword'])) : '', 'news_country' => isset($_POST['news_country']) ? sanitize_text_field(wp_unslash($_POST['news_country'])) : '', 'news_language' => isset($_POST['news_language']) ? sanitize_text_field(wp_unslash($_POST['news_language'])) : '', 'news_time_published' => isset($_POST['news_time_published']) ? sanitize_text_field(wp_unslash($_POST['news_time_published'])) : '', 'news_source' => isset($_POST['news_source']) ? sanitize_text_field(wp_unslash($_POST['news_source'])) : '', 'rss_source' => isset($_POST['rss_source']) ? sanitize_text_field(wp_unslash($_POST['rss_source'])) : '', 'ai_keywords' => isset($_POST['ai_keywords']) ? sanitize_text_field(wp_unslash($_POST['ai_keywords'])) : '', 'disable_ai_images' => isset($_POST['disable_ai_images']) ? intval(wp_unslash($_POST['disable_ai_images'])) : 0, 'template_id' => isset($_POST['template_id']) && !empty($_POST['template_id']) ? intval(wp_unslash($_POST['template_id'])) : null ); //$item_valid = botwriter_validate_website($item); $item_valid = true; if ($item_valid === true) { //$item = array_map('sanitize_text_field', $item); // Sanitize all inputs if ($item['id'] == 0) { // Do not insert primary key 'id' explicitly to allow AUTO_INCREMENT to work $insert_data = $item; unset($insert_data['id']); $result = $wpdb->insert($table_name, $insert_data); //echo "

" . $wpdb->last_error . "

"; $item['id'] = $wpdb->insert_id; if ($result) { $message = __('New task was successfully saved!', 'botwriter'); // asignamos el id de la tarea botwriter_super_assign_id_task($item['id']); // y borramos el log, solo puede haber 1 tarea super1 $wpdb->delete($wpdb->prefix . 'botwriter_logs', array('website_type' => 'super1')); ?>
update($table_name, $item, array('id' => $item['id'])); if ($result !== false) { if ($result === 0) { $message = __('It was successfully updated', 'botwriter'); ?>
last_error; } } } else { $notice = $item_valid; } } else { $item = $default; if (isset($_REQUEST['id'])) { $sanitized_id = absint($_REQUEST['id']); // Sanitize as an integer $item = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$table_name} WHERE id = %d", $sanitized_id), ARRAY_A); if (!$item) { $item = $default; $notice = __('Item not found', 'botwriter'); } } } // end of process the form data ?>

First Time! Welcome to the Super Task AI!

Super Task AI is a powerful tool that allows you to create a large number of articles in a few seconds. You can choose from predefined article packs or create a custom pack. The AI will generate titles and summaries for your articles based on your blog content. You can customize the prompts or use the default ones.

The first time Botwriter proposes some articles to improve your blog, review them below and save the task.

<?php echo esc_attr__('AI', 'botwriter'); ?>>

Choose a pack and the AI will automatically propose articles based on your blog content. Choose Custom Pack for a custom prompt, or Manual Titles to paste your own list.




Select an author from the list.

Select the status of the post. Choose 'Draft' if you want to revise it before publishing.


" . esc_html($day) . "
"; } ?>

Select the days on which you want to write and publish.



Select the desired post length or choose custom to enter a specific number of words.

Enter the number of words you want the post to have.



>

All Sources Images' ); ?>


false, // Obtener también las categorías sin posts 'taxonomy' => 'category' // Asegura que solo obtenemos categorías de posts, no de productos )); $cats = array(); if (!empty($categories)) { foreach ($categories as $cat) { // Configurar argumentos para obtener los últimos 5 posts de la categoría actual $args = array( 'post_type' => 'post', // Solo posts, no productos ni otros CPTs 'post_status' => 'publish', 'cat' => $cat->term_id, // Filtrar por el ID de la categoría 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC' ); $query = new WP_Query($args); $posts = array(); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $posts[] = array( 'title' => get_the_title(), 'description' => get_the_excerpt(), // Para contenido completo usar get_the_content() 'date' => get_the_date() // Fecha del post ); } wp_reset_postdata(); // Importante para restaurar el loop principal } // Agregar la categoría incluso si no tiene posts $cats[] = array( 'id' => $cat->term_id, 'name' => $cat->name, 'description' => $cat->description, 'posts' => $posts // Se agrega vacío si no tiene posts ); } } // Obtener páginas publicadas $pages_args = array( 'post_type' => 'page', 'post_status' => 'publish', 'posts_per_page' => 10, 'orderby' => 'date', 'order' => 'DESC' ); $pages_query = new WP_Query($pages_args); $pages = array(); if ($pages_query->have_posts()) { while ($pages_query->have_posts()) { $pages_query->the_post(); // Obtener el excerpt, y si no existe, tomar los primeros 200 caracteres del contenido $excerpt = get_the_excerpt(); if (empty($excerpt)) { $content = wp_strip_all_tags(get_the_content()); // Quitar etiquetas HTML del contenido $excerpt = substr($content, 0, 250); // Tomar los primeros 200 caracteres if (strlen($content) > 250) { $excerpt .= '...'; // Agregar puntos suspensivos si el contenido es más largo } } $pages[] = array( 'id' => get_the_ID(), 'title' => get_the_title(), 'description' => $excerpt, // Usar el excerpt o los primeros 200 caracteres //'date' => get_the_date(), // Fecha de creación //'modified' => get_the_modified_date(), // Fecha de última modificación //'slug' => get_post_field('post_name') // Slug de la página ); } wp_reset_postdata(); // Restaurar el loop principal } // Armar el array con la información completa del blog $info_blog = array( 'title' => $blog_title, 'description' => $blog_description, 'categories' => $cats, 'pages' => $pages // Nueva sección para las páginas ); return $info_blog; } function botwriter_super1_create_first_task() { $info_blog = botwriter_get_info_blog(); $json_info_blog = json_encode($info_blog, JSON_PRETTY_PRINT); $content_prompt = $json_info_blog; botwriter_super1_create_task('FIRSTSUPER1',"", $content_prompt); } // create a log not task, only 1 for titles function botwriter_super1_create_task($task_name, $title_prompt, $content_prompt,$post_count=10,$category_id=0) { global $wpdb; $table_name = $wpdb->prefix . 'botwriter_logs'; $current_time = gmdate('Y-m-d H:i:s', current_time('timestamp')); botwriter_log('Initializing super1 task log', [ 'task_name' => $task_name, 'post_count' => $post_count, 'category_id' => $category_id, ]); // default values $data = array( 'id' => 1, 'id_task' => 0, 'created_at' => '', 'last_execution_time' => $current_time = gmdate('Y-m-d H:i:s', current_time('timestamp')), 'intentosfase1' => 0, 'intentosfase2' => 0, 'task_status' => '', 'error' => '', 'link_post_original' => '', 'id_post_published' => 0, 'post_status' => 'draft', 'task_name' => $task_name, 'writer' => 'ai_cerebro', 'narration' => 'Descriptive', 'custom_style' => '', 'post_language' => substr(get_locale(), 0, 2), 'post_length' => 2000, 'custom_post_length' => '', 'website_name' => '', 'website_type' => 'super1', 'domain_name' => '', 'category_id' => $category_id, 'website_category_id' => '', 'aigenerated_title' => '', 'aigenerated_content' => '', 'aigenerated_tags' => '', 'aigenerated_image' => '', 'post_count' => $post_count, 'post_order' => '', 'title_prompt' => $title_prompt, 'content_prompt' => $content_prompt, 'tags_prompt' => '', 'image_prompt' => '', 'image_generating_status' => '', 'author_selection' => 1, 'news_time_published' => '', 'news_language' => '', 'news_country' => '', 'news_keyword' => '', 'news_source' => '', 'rss_source' => '', 'ai_keywords' => '', 'version' => '', 'user_domainname' => '', 'ai_image_size' => '', 'titles' => '', 'links' => '', ); $event=$data; $event["task_status"] = "pending"; $event["id_task"] = $data["id"]; $event["intentosfase1"] = 0; $id_log=botwriter_logs_register($event); // create log in db $event["id"]=$id_log; botwriter_log('Super1 log registered', [ 'log_id' => $id_log, 'task_name' => $task_name, ]); botwriter_send1_data_to_server( (array) $event); return $id_log; } function botwriter_super1_log_to_bd($result,$id_log) { global $wpdb; $table_name = $wpdb->prefix . 'botwriter_super'; $aigenerated_content = $result["aigenerated_content"]; $title_prompt = $result["title_prompt"]; try { $data_array=json_decode($aigenerated_content, true); } catch (Exception $e) { echo "Error: " . esc_html($e->getMessage()); } if (!is_array($data_array)) { botwriter_log('Super1 JSON decode failed', [ 'log_id' => $id_log, ]); return false; // Or throw an exception as needed } /* echo "

Finish Task titulos etc

"; echo "
";
    print_r($data_array);
    echo "
"; */ botwriter_log('Persisting super1 outlines', [ 'log_id' => $id_log, 'articles' => count($data_array), ]); foreach ($data_array as $post) { // Verifica si el artículo ya existe para evitar duplicados (por título) $existing_post = $wpdb->get_row($wpdb->prepare( "SELECT * FROM $table_name WHERE title = %s", $post['title'] )); if (!$existing_post) { if ($title_prompt!="Custom") { $data = array( 'title' => $post['title'], 'content' => $post['resumen'], 'category_name' => $post['categoria'], 'category_id' => $post['categoria_id'], 'id_log' => $id_log ); } else { $data = array( 'title' => $post['title'], 'content' => $post['resumen'], 'category_name' => get_cat_name($result['category_id']), 'category_id' => $result['category_id'], 'id_log' => $id_log ); } $wpdb->insert($table_name, $data); botwriter_log('Super1 outline stored', [ 'log_id' => $id_log, 'title' => $post['title'], ]); } else { botwriter_log('Super1 outline skipped (duplicate)', [ 'log_id' => $id_log, 'title' => $post['title'], ]); } } } function botwriter_super1_view_articles_html($id_task=0) { global $wpdb; $table_name = $wpdb->prefix . 'botwriter_super'; $posts = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE id_task = %d ORDER BY category_id", $id_task), ARRAY_A); // $html = ''; $contador = 0; $auxcategoria = ""; foreach ($posts as $post) { $task_status = $post['task_status']; if ($auxcategoria != $post['category_name']) { $html .= '

' . esc_html($post['category_name']) . '

'; } $html .= '
'; $html .= '
' . ++$contador . '
'; $html .= '
'; $html .= '

' . esc_html($post['title']) . '

'; $html .= '

' . esc_html($post['content']) . '

'; $html .= '
'; if ($task_status == 'completed') { $html .= '
Completed ✅
'; } // si esta en cola if ($task_status == 'inqueue') { $html .= '
In Queue 🔄
'; } // si hay un error if ($task_status == 'error') { $html .= '
Error ❌
'; } // si es blanco o null if ($task_status == '') { $html .= '
'; $html .= ''; $html .= ''; $html .= '
'; } $html .= '
'; $auxcategoria = $post['category_name']; } return $html; } function botwriter_super1_check_task_exist() { global $wpdb; $table_name = $wpdb->prefix . 'botwriter_logs'; $task = $wpdb->get_row($wpdb->prepare( "SELECT * FROM $table_name WHERE website_type = %d", 'super1' )); if ($task) { return true; } else { return false; } } // crea una funcion que mire en la tabla task si la tarea super esta completeda (la ultima que se ha creado) function botwriter_super1_check_task_finish() { global $wpdb; $table_name = $wpdb->prefix . 'botwriter_logs'; $task = $wpdb->get_row("SELECT * FROM $table_name WHERE website_type = 'super1' order by id desc limit 1"); if ($task) { if ($task->task_status == 'completed') { botwriter_log('Super1 task status completed', [ 'log_id' => $task->id, ]); return 'completed'; } if ($task->task_status == 'error') { botwriter_log('Super1 task status error', [ 'log_id' => $task->id, ]); return 'error'; } if ($task->task_status == 'pending' || $task->task_status == 'inqueue') { botwriter_log('Super1 task still pending', [ 'log_id' => $task->id, 'status' => $task->task_status, ]); botwriter_execute_events_pass2(); return 'inqueue'; } } botwriter_log('Super1 task status unknown'); return ""; } function botwriter_super_prepare_event($event) { global $wpdb; $table_name = $wpdb->prefix . 'botwriter_super'; $articulo = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE id_task = %d AND (task_status IS NULL OR task_status = '') ORDER BY category_id", $event["id_task"]), ARRAY_A); /* echo "

Prepare Event

"; echo "
";
  print_r($articulo);
  echo "
"; */ if (!empty($articulo['title'])) { botwriter_log('Super2 outline selected', [ 'task_id' => $event['id_task'], 'log_id' => $event['id'], 'article_id' => $articulo['id'], ]); // For rewriter/siterewriter tasks, preserve the original content_prompt // (rewrite instructions) before overwriting with the article content. $task_type = $event['task_type'] ?? ''; if (in_array($task_type, ['rewriter', 'siterewriter'], true) && !empty($event['content_prompt'])) { $event['rewrite_prompt'] = $event['content_prompt']; } $event['content_prompt'] = $articulo['content']; $event['title_prompt'] = $articulo['title']; $event['category_id'] = $articulo['category_id']; $id = $articulo['id']; $id_log=$event["id"]; // actualizamos el status y el id_log con el nuevo id_log $wpdb->update($table_name, array('id_log' => $id_log, 'task_status' => 'inqueue'), array('id' => $id)); } else { botwriter_log('Super2 outline not found', [ 'task_id' => $event['id_task'], 'log_id' => $event['id'], ]); return false; } return $event; } function botwriter_super_assign_id_task($id_task) { global $wpdb; $table_name = $wpdb->prefix . 'botwriter_super'; // update the super table with the id_task for those with id_task 0 $wpdb->update($table_name, array('id_task' => $id_task), array('id_task' => 0)); return $id_task; } function botwriter_super1_check_first_time() { global $wpdb; $table_name = $wpdb->prefix . 'botwriter_logs'; $task = $wpdb->get_row("SELECT * FROM $table_name WHERE website_type = 'super1' AND task_name = 'FIRSTSUPER1'"); if ($task) { return true; } else { return false; } }