=3) { $topic=$tmp[0]; $domain_keyword=$tmp[1]; $x_main_keyword=$tmp[2]; } } /* ----------------------------- Queue marching orders ----------------------- */ $queue_row = null; if ($qLink && $queue_id) { $rs = @mysql_query("SELECT * FROM c_domain_build_queue WHERE id=".(int)$queue_id." LIMIT 1", $qLink); } elseif ($qLink && $domain !== '') { $rs = @mysql_query("SELECT * FROM c_domain_build_queue WHERE domain='".mysql_real_escape_string($domain)."' ORDER BY id DESC LIMIT 1", $qLink); } if (isset($rs) && $rs && mysql_num_rows($rs)) { $queue_row = mysql_fetch_assoc($rs); } if (is_array($queue_row)) { if (isset($queue_row['slug']) && $queue_row['slug']!=='') { $SLUG = $queue_row['slug']; } if (isset($queue_row['type']) && $queue_row['type']!=='') { $TEMPLATE = $queue_row['type']; } } /* ------------------------------- Build plan -------------------------------- */ $PLAN = @json_decode('{{PLAN_JSON}}', true); if (!is_array($PLAN)) $PLAN=array(); /* ------------------------------- Meta/title -------------------------------- */ $dividers = array(' - ', ' | '); $divider = $dividers[ (crc32($domain) % count($dividers)) ]; $meta_title = (isset($PLAN['title_prefix'])?$PLAN['title_prefix']:'') . $divider . $topic; $meta_title = trim($meta_title, ' -|'); if (function_exists('ai_complete')) { $ask = "Write a concise, data-backed H1 title (max 60 chars) for a page about: {$topic}. Return ONLY the title."; $meta_title = ai_complete($ask, 'Title'); } $meta_desc = isset($PLAN['meta_override'])?$PLAN['meta_override']:''; if ($meta_desc==='') { if (function_exists('ai_complete')) { $meta_desc = ai_complete("Write a 2-sentence meta description (<= 160 chars) about {$topic}. No emojis. No guarantees.", "Meta Description"); } else { $meta_desc = "Learn about {$topic}."; } } if (function_exists('smart_meta')) $meta_desc = smart_meta($meta_desc, 160); /* ------------------------------ Content HTML -------------------------------- */ $content = array(); // collect sections, then implode // Intro paragraph if (function_exists('ai_complete')) { $intro = ai_complete("Write a short, friendly intro paragraph about {$topic}. No links, no guarantees.", "Intro"); } else { $intro = "Welcome! This page covers {$topic}."; } $content[] = '

'.htmlspecialchars($intro, ENT_QUOTES, 'UTF-8').'

'; // Images $imgCount = isset($PLAN['images_count']) ? intval($PLAN['images_count']) : 0; $imgTopic = isset($PLAN['images_topic']) && strlen($PLAN['images_topic']) ? $PLAN['images_topic'] : $topic; if ($imgCount > 0) { $imgs = array(); for ($i=0; $i<$imgCount; $i++) { // At runtime you likely use your vector/images helper $imgs[] = ''.htmlspecialchars($imgTopic, ENT_QUOTES, 'UTF-8').''; } $content[] = '
'.implode("\n", $imgs).'
'; } // Table $r = isset($PLAN['table_rows'])?intval($PLAN['table_rows']):0; $c = isset($PLAN['table_cols'])?intval($PLAN['table_cols']):0; if ($r>0 && $c>0) { $tt = isset($PLAN['table_topic'])?$PLAN['table_topic']:$topic; $html = ''; for ($j=0;$j<$c;$j++){ $html.=''; } $html.=''; for ($i=0;$i<$r;$i++){ $html.=''; for ($j=0;$j<$c;$j++){ $cell = $tt.' R'.($i+1).'C'.($j+1); $html.=''; } $html.=''; } $html.='
'.htmlspecialchars($tt.' Col '.($j+1), ENT_QUOTES, 'UTF-8').'
'.htmlspecialchars($cell, ENT_QUOTES, 'UTF-8').'
'; $content[] = $html; } // Freeform block $free = isset($PLAN['freeform'])?$PLAN['freeform']:''; if ($free !== '') { if (function_exists('ai_complete')) { $ask = "Using this instruction, write an HTML-ready section about {$topic}: \n".$free."\nRules: no links, no claims, neutral tone."; $free_html = ai_complete($ask, 'Freeform'); $content[] = '
'. $free_html .'
'; } else { $content[] = '

'.htmlspecialchars($free, ENT_QUOTES, 'UTF-8').'

'; } } $CONTENT_HTML = implode("\n\n", $content); /* ------------------------------- Upsert ------------------------------------ */ $TARGET = '{{TARGET}}'; // custom_page | content_group $SLUG = '{{SLUG}}'; $TEMPLATE = '{{TEMPLATE}}'; $payload = array( 'conn_id' => $conn_id, 'domain' => $domain, 'slug' => $SLUG, 'title' => $meta_title, 'meta_title' => $meta_title, 'meta_description' => $meta_desc, 'type' => $TEMPLATE, 'type_data' => array() ); if ($TARGET === 'content_group') { $payload['body'] = $CONTENT_HTML; } else { $payload['content'] = $CONTENT_HTML; } $result = array('error'=>'LpV2ApiHelper not available'); if (class_exists('\\App\\Support\\LpV2ApiHelper')) { if (!$DRY_RUN) { if ($TARGET === 'content_group') { $result = \App\Support\LpV2ApiHelper::contentGroupsUpsert($payload); } else { $result = \App\Support\LpV2ApiHelper::customPagesUpsert($payload); } } else { $result = array('dry_run'=>1); } } /* ------------------------------- Output ------------------------------------ */ header('Content-Type: application/json; charset=UTF-8'); echo json_encode(array( 'ok' => 1, 'payload' => $payload, 'result' => $result, 'meta' => array('title'=>$meta_title, 'description'=>$meta_desc), 'plan' => $PLAN ), JSON_UNESCAPED_SLASHES);