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/'; ?>
";
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 "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.
>
";
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['content']) . '
'; $html .= '"; 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; } }