'Version'), false); return $plugin_data['Version']; } function aimogen_add_custom_column_to_posts($columns) { if(defined('AIMOGEN_IS_PRO')) { return $columns; } $screen = get_current_screen(); if (!$screen || empty($screen->post_type)) { return $columns; } $excluded = defined('AIMOGEN_EXCEPTED_POST_TYPES_FROM_EDITING') ? AIMOGEN_EXCEPTED_POST_TYPES_FROM_EDITING : []; if (in_array($screen->post_type, $excluded, true)) { return $columns; } $columns['aimogen_edited'] = esc_html__('Aimogen Edited', 'aimogen'); return $columns; } add_action('admin_enqueue_scripts', 'aimogen_enqueue_live_feed_scripts'); function aimogen_enqueue_live_feed_scripts($hook) { if (empty($hook) || (strpos($hook, 'aiomatic') === false && strpos($hook, 'aimogen') === false)) { return; } wp_register_script('aiomatic-live-feed', '', [], '1.0', true); $data = [ 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('aiomatic_live_feed'), 'poll_ms' => 2500, 'limit' => 50, ]; wp_add_inline_script('aiomatic-live-feed', 'window.AIOMATIC_LIVE_FEED=' . wp_json_encode($data) . ';', 'before'); wp_add_inline_script('aiomatic-live-feed', <</g,'>') .replace(/"/g,'"') .replace(/'/g,'''); } var box = null, statusEl = null, lastIdEl = null; var lastId = 0; var timer = null; var paused = false; function setStatus(t){ if (statusEl) statusEl.textContent = t; } document.addEventListener('click', function(e){ var row = e.target.closest('.aiomatic-live-row'); if (!row) return; var id = row.getAttribute('data-id'); var details = document.getElementById('aiomatic-live-details-' + id); var inner = details ? details.querySelector('.aiomatic-live-details-inner') : null; if (!details || !inner) return; if (details.style.display === 'block') { details.style.display = 'none'; return; } document.querySelectorAll('.aiomatic-live-details').forEach(function(el){ el.style.display = 'none'; }); details.style.display = 'block'; if (details.dataset.loaded) return; var cfg = window.AIOMATIC_LIVE_FEED || {}; var fd = new FormData(); fd.append('action', 'aiomatic_live_log_details'); fd.append('nonce', cfg.nonce || ''); fd.append('log_id', id); fetch(cfg.ajax_url, { method:'POST', credentials:'same-origin', body: fd }) .then(function(r){ return r.json(); }) .then(function(j){ if (!j || !j.success || !j.data || !j.data.html){ inner.textContent = 'No details available.'; return; } inner.innerHTML = j.data.html; details.dataset.loaded = '1'; }) .catch(function(){ inner.textContent = 'Failed to load details.'; }); }); function renderItem(it){ var assistant = it.assistant_id ? (' · asst:' + it.assistant_id) : ''; var price = it.price ? (' · ' + it.price) : ''; var who = ''; if (it.userId && it.userId > 0) who = ' · user:' + it.userId; else if (it.ip) who = ' · ip:' + it.ip; return ( '
' + '#' + esc(it.id) + ' ' + '' + esc(it.time) + '' + '' + ' · ' + esc(it.env) + ' · ' + esc(it.mode) + ' · ' + esc(it.model) + assistant + ' · ' + esc(it.units) + ' ' + esc(it.type) + price + who + (it.session ? (' · sess:' + esc(it.session)) : '') + '' + ' ⯈' + '
' + '' ); } function appendItems(items){ if (!box || !items || !items.length) return; var atBottom = (box.scrollTop + box.clientHeight + 20) >= box.scrollHeight; var html = ''; for (var i=0;i lastId) lastId = items[i].id; } box.insertAdjacentHTML('beforeend', html); var rows = box.querySelectorAll('.aiomatic-live-row'); if (rows.length > 300){ for (var k=0;kis_main_query()) { return; } if ($query->get('orderby') == 'aimogen_edited') { $aimogen_Spinner_Settings = get_option('aimogen_Spinner_Settings', false); if (isset($aimogen_Spinner_Settings['custom_name']) && trim($aimogen_Spinner_Settings['custom_name']) != '') { $custom_name = trim($aimogen_Spinner_Settings['custom_name']); $custom_name = str_replace('%%current_date%%', gmdate("Y-m-d"), $custom_name); } else { $custom_name = 'aimogen_published'; } $query->set('meta_query', array( 'relation' => 'OR', array( 'key' => $custom_name, 'compare' => 'EXISTS', ) )); $query->set('orderby', 'meta_value'); } } add_action('pre_get_posts', 'aimogen_custom_column_orderby'); add_filter('manage_edit-post_sortable_columns', 'aimogen_custom_column_sortable'); add_action('manage_posts_custom_column', 'aimogen_custom_column_content', 10, 2); add_filter('manage_posts_columns', 'aimogen_add_custom_column_to_posts'); function aimogen_custom_admin_favicon() { $screen = get_current_screen(); if ($screen && isset($screen->id) && (aimogen_starts_with($screen->id, 'aimogen_page_') !== false || aimogen_starts_with($screen->id, 'toplevel_page_aimogen_') !== false || $screen->id == 'media_page_aimogen-automatic-ai-content-writer')) { $favicon_url = plugins_url('/images/icon-old.png', __FILE__); echo ''; } } add_action('admin_head', 'aimogen_custom_admin_favicon'); function aimogen_get_max_tokens($model) { $model_tokens = array( 'gpt-4-1106-preview' => 4000, //4096 for output, 128000 for input 'gpt-4-0125-preview' => 4000, //4096 for output, 128000 for input 'gpt-4-turbo-preview' => 4000, //4096 for output, 128000 for input 'gpt-4-turbo' => 4000, //4096 for output, 128000 for input 'gpt-4-turbo-2024-04-09' => 4000, //4096 for output, 128000 for input 'gpt-4o' => 16000, //4096 for output, 128000 for input 'gpt-4o-2024-05-13' => 4000, //4096 for output, 128000 for input 'o1-pro' => 100000, //100000 for output, 200000 for input , 'o3-mini' => 100000, //100000 for output, 200000 for input , 'o3-mini-2025-01-31' => 100000, //100000 for output, 200000 for input , 'o3' => 100000, //100000 for output, 200000 for input , 'o3-2025-04-16' => 100000, //100000 for output, 200000 for input , 'o4-mini' => 100000, //100000 for output, 200000 for input , 'o4-mini-2025-04-16' => 100000, //100000 for output, 200000 for input , 'o3-pro' => 100000, //100000 for output, 200000 for input , 'o3-pro-2025-06-10' => 100000, //100000 for output, 200000 for input , 'o1' => 100000, //100000 for output, 128000 for input , 'o1-2024-12-17' => 100000, //100000 for output, 128000 for input , 'gpt-4o-2024-08-06' => 16000, //16384 for output, 128000 for input 'gpt-4o-2024-11-20' => 16000, //16384 for output, 128000 for input 'gpt-4o-mini' => 16000, //16384 for output, 128000 for input 'gpt-4o-mini-2024-07-18' => 16000, //16384 for output, 128000 for input 'gpt-4o-search-preview' => 16000, //16384 for output, 128000 for input 'gpt-4o-mini-search-preview' => 16000, //16384 for output, 128000 for input 'gpt-4.1' => 32000, //32768 for output, 1047576 for input 'gpt-4.1-2025-04-14' => 32000, //32768 for output, 1047576 for input 'gpt-4.1-mini' => 32000, //32768 for output, 1047576 for input 'gpt-4.1-mini-2025-04-14' => 32000, //32768 for output, 1047576 for input 'gpt-4.1-nano' => 32000, //32768 for output, 1047576 for input 'gpt-4.1-nano-2025-04-14' => 32000, //32768 for output, 1047576 for input 'gpt-5' => 127000, //32768 for output, 1047576 for input 'gpt-5.2' => 127000, //32768 for output, 1047576 for input 'gpt-5.2-2025-12-11' => 127000, //32768 for output, 1047576 for input 'gpt-5.5-pro' => 127000, //32768 for output, 1047576 for input 'gpt-5.5' => 127000, //32768 for output, 1047576 for input 'gpt-5.6-luna' => 127000, //32768 for output, 1047576 for input 'gpt-5.6-terra' => 127000, //32768 for output, 1047576 for input 'gpt-5.6-sol' => 127000, //32768 for output, 1047576 for input 'gpt-6-astra' => 128000, //128000 for output, 1050000 for input 'gpt-5.4' => 127000, //32768 for output, 1047576 for input 'gpt-5.4-mini' => 127000, //32768 for output, 1047576 for input 'gpt-5.4-nano' => 127000, //32768 for output, 1047576 for input 'gpt-5.4-pro' => 127000, //32768 for output, 1047576 for input 'gpt-5.3-codex' => 127000, //32768 for output, 1047576 for input 'gpt-5.2-pro' => 127000, //32768 for output, 1047576 for input 'gpt-5.2-pro-2025-12-11' => 127000, //32768 for output, 1047576 for input 'gpt-5.1' => 127000, //32768 for output, 1047576 for input 'gpt-5.1-2025-11-13' => 127000, //32768 for output, 1047576 for input 'gpt-5-2025-08-07' => 127000, //32768 for output, 1047576 for input 'gpt-5-mini' => 127000, //32768 for output, 1047576 for input 'gpt-5-mini-2025-08-07' => 127000, //32768 for output, 1047576 for input 'gpt-5-nano' => 127000, //32768 for output, 1047576 for input 'gpt-5-nano-2025-08-07' => 127000, //32768 for output, 1047576 for input 'gpt-5-pro-2025-10-06' => 250000, //32768 for output, 1047576 for input 'gpt-5-pro' => 250000, //32768 for output, 1047576 for input 'gpt-3.5-turbo-0125' => 4000, //4096, 'gpt-3.5-turbo' => 4000, //4096, 'gpt-4' => 8000, //8192, 'gpt-4-0613' => 8000, //8192, 'gpt-3.5-turbo-1106' => 4000, //4096, 'gpt-3.5-turbo-16k' => 16200, //16385, 'gpt-3.5-turbo-instruct' => 4000, //4096, 'omni-moderation-latest' => 32600, //32768, 'babbage-002' => 16200, //16385, 'davinci-002' => 16200, //16385, 'text-curie-001' => 2000, //2049, 'text-babbage-001' => 2000, //2049, 'text-ada-001' => 2000, //2049, 'davinci' => 2000, //2049, 'curie' => 2000, //2049, 'babbage' => 2000, //2049, 'ada' => 2000, //2049, 'text-davinci-edit-001' => 4000, //4096, 'code-davinci-edit-001' => 4000, //4096, 'text-embedding-ada-002' => 8000, //8191, 'text-embedding-3-small' => 8000, //8191, 'text-embedding-3-large' => 8000, //8191, 'claude-3-5-haiku-20241022' => 4000, //4096, 'claude-3-haiku-20240307' => 4000, //4096, 'claude-fable-5' => 120000, //120000, 'claude-fable-5-1' => 120000, //120000, 'claude-mythos-5' => 120000, //120000, 'claude-opus-4-7' => 4000, //4096, 'claude-opus-4-6' => 4000, //4096, 'claude-opus-4-8' => 4000, //4096, 'claude-opus-5' => 4000, //4096, 'claude-sonnet-4-6' => 4000, //4096, 'claude-sonnet-5' => 4000, //4096, 'claude-opus-4-5-20251101' => 4000, //4096, 'claude-3-7-sonnet-20250219' => 4000, //4096, 'claude-haiku-4-5-20251001' => 8000, //8192, 'claude-sonnet-4-20250514' => 8000, //8192, 'claude-opus-4-20250514' => 8000, //8192, 'claude-opus-4-1-20250805' => 8000, //8192, 'claude-sonnet-4-5-20250929' => 8000, //8192, //google api limits https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models#foundation_models 'gemini-2.0-flash-exp' => 8000, //8191, 'gemini-3.8-flash' => 65000, //65536, 'gemini-2.0-flash' => 8000, //8191, 'gemini-2.0-flash-lite' => 8000, //8191, 'chat-bison-001' => 1000, //1024, 'text-bison-001' => 1000, //1024, 'grok-4.20-multi-agent-0309' => 8000, 'grok-4.20-0309-non-reasoning' => 8000, 'grok-4.20-0309-reasoning' => 8000, 'grok-4.3' => 8000, 'grok-4.5' => 8000, 'grok-build-0.1' => 8000, 'text-embedding-005' => 2048, //2048, 'gemini-embedding-001' => 2048, //2048, 'gemini-embedding-2-preview' => 2048, //2048, ); $model_tokens = array_merge($model_tokens, aimogen_get_perplexity_model_tokens()); $model_tokens = array_merge($model_tokens, aimogen_get_groq_model_tokens()); $model_tokens = array_merge($model_tokens, aimogen_get_nvidia_model_tokens()); $model_tokens = array_merge($model_tokens, aimogen_get_openrouter_model_tokens()); if(isset($model_tokens[$model])) { return $model_tokens[$model]; } return AIMOGEN_DEFAULT_MAX_TOKENS; } function aimogen_get_max_input_tokens($model) { $model_tokens = array( 'gpt-4-1106-preview' => 128000, //4096 for output, 128000 for input 'gpt-4-0125-preview' => 128000, //4096 for output, 128000 for input 'gpt-4-turbo-preview' => 128000, //4096 for output, 128000 for input 'gpt-4-turbo' => 128000, //4096 for output, 128000 for input 'gpt-4-turbo-2024-04-09' => 128000, //4096 for output, 128000 for input 'gpt-4o' => 128000, //4096 for output, 128000 for input 'gpt-4o-2024-05-13' => 128000, //4096 for output, 128000 for input 'o1-pro' => 200000, //100000 for output, 200000 for input 'o3-mini' => 200000, //100000 for output, 200000 for input 'o3-mini-2025-01-31' => 200000, //100000 for output, 200000 for input 'o3' => 200000, //100000 for output, 200000 for input , 'o3-2025-04-16' => 200000, //100000 for output, 200000 for input , 'o4-mini' => 200000, //100000 for output, 200000 for input , 'o4-mini-2025-04-16' => 200000, //100000 for output, 200000 for input , 'o3-pro' => 200000, //100000 for output, 200000 for input , 'o3-pro-2025-06-10' => 200000, //100000 for output, 200000 for input , 'o1' => 200000, //200000 for output, 128000 for input , 'o1-2024-12-17' => 200000, //200000 for output, 128000 for input , 'gpt-4o-2024-08-06' => 128000, //16384 for output, 128000 for input 'gpt-4o-2024-11-20' => 128000, //16384 for output, 128000 for input 'gpt-4o-mini' => 128000, //4096 for output, 128000 for input 'gpt-4o-mini-2024-07-18' => 128000, //4096 for output, 128000 for input 'gpt-4o-mini-search-preview' => 128000, //16385 for output, 128000 for input 'gpt-4o-search-preview' => 128000, //16385 for output, 128000 for input 'gpt-4.1' => 1000000, //32768 for output, 1047576 for input 'gpt-4.1-2025-04-14' => 1000000, //32768 for output, 1047576 for input 'gpt-4.1-mini' => 1000000, //32768 for output, 1047576 for input 'gpt-4.1-mini-2025-04-14' => 1000000, //32768 for output, 1047576 for input 'gpt-4.1-nano' => 1000000, //32768 for output, 1047576 for input 'gpt-4.1-nano-2025-04-14' => 1000000, //32768 for output, 1047576 for input 'gpt-5' => 390000, //32768 for output, 1047576 for input 'gpt-5.2' => 390000, //32768 for output, 1047576 for input 'gpt-5.2-2025-12-11' => 390000, //32768 for output, 1047576 for input 'gpt-5.5-pro' => 1000000, //32768 for output, 1047576 for input 'gpt-5.5' => 1000000, //32768 for output, 1047576 for input 'gpt-5.6-luna' => 1000000, //32768 for output, 1047576 for input 'gpt-5.6-terra' => 1000000, //32768 for output, 1047576 for input 'gpt-5.6-sol' => 1000000, //32768 for output, 1047576 for input 'gpt-6-astra' => 1050000, //128000 for output, 1050000 for input 'gpt-5.4' => 1000000, //32768 for output, 1047576 for input 'gpt-5.4-mini' => 390000, //32768 for output, 1047576 for input 'gpt-5.4-nano' => 390000, //32768 for output, 1047576 for input 'gpt-5.4-pro' => 1000000, //32768 for output, 1047576 for input 'gpt-5.3-codex' => 390000, //32768 for output, 1047576 for input 'gpt-5.2-pro' => 390000, //32768 for output, 1047576 for input 'gpt-5.2-pro-2025-12-11' => 390000, //32768 for output, 1047576 for input 'gpt-5.1' => 390000, //32768 for output, 1047576 for input 'gpt-5.1-2025-11-13' => 390000, //32768 for output, 1047576 for input 'gpt-5-2025-08-07' => 390000, //32768 for output, 1047576 for input 'gpt-5-mini' => 390000, //32768 for output, 1047576 for input 'gpt-5-mini-2025-08-07' => 390000, //32768 for output, 1047576 for input 'gpt-5-nano' => 390000, //32768 for output, 1047576 for input 'gpt-5-nano-2025-08-07' => 390000, //32768 for output, 1047576 for input 'gpt-5-pro-2025-10-06' => 390000, //32768 for output, 1047576 for input 'gpt-5-pro' => 390000, //32768 for output, 1047576 for input 'gpt-3.5-turbo-0125' => 16385, //16385, 'gpt-3.5-turbo' => 16385, //16385, 'gpt-4' => 8192, //8192, 'gpt-4-0613' => 8192, //8192, 'gpt-3.5-turbo-1106' => 16385, //4096, 16385 for input 'gpt-3.5-turbo-16k' => 16385, //16385, 'gpt-3.5-turbo-instruct' => 4096, //4096, 'omni-moderation-latest' => 32768, //32768, 'babbage-002' => 16385, //16385, 'davinci-002' => 16385, //16385, 'text-curie-001' => 2049, //2049, 'text-babbage-001' => 2049, //2049, 'text-ada-001' => 2049, //2049, 'davinci' => 2049, //2049, 'curie' => 2049, //2049, 'babbage' => 2049, //2049, 'ada' => 2049, //2049, 'text-davinci-edit-001' => 4096, //4096, 'code-davinci-edit-001' => 4096, //4096, 'text-embedding-ada-002' => 8000, //8191, 'text-embedding-3-small' => 8000, //8191, 'text-embedding-3-large' => 8000, //8191, 'claude-3-5-haiku-20241022' => 199800, //200000, 'claude-3-haiku-20240307' => 199800, //200000, 'claude-fable-5' => 999000, //1000000, 'claude-fable-5-1' => 999000, //1000000, 'claude-mythos-5' => 999000, //1000000, 'claude-opus-4-7' => 199800, //200000, 'claude-opus-4-6' => 199800, //200000, 'claude-opus-4-8' => 199800, //200000, 'claude-opus-5' => 199800, //200000, 'claude-sonnet-4-6' => 199800, //200000, 'claude-sonnet-5' => 199800, //200000, 'claude-opus-4-5-20251101' => 199800, //200000, 'claude-3-7-sonnet-20250219' => 199800, //200000, 'claude-haiku-4-5-20251001' => 199800, //200000, 'claude-sonnet-4-20250514' => 199800, //200000, 'claude-opus-4-20250514' => 199800, //200000, 'claude-opus-4-1-20250805' => 199800, //200000, 'claude-sonnet-4-5-20250929' => 199800, //200000, //google api limits https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models#foundation_models 'gemini-2.0-flash-exp' => 999000, //1000000, 'gemini-3.8-flash' => 999000, //1048576, 'gemini-2.0-flash' => 999000, //1000000, 'gemini-2.0-flash-lite' => 999000, //1000000, 'gemini-2.0-flash-thinking-exp-01-21' => 999000, //1000000, 'gemini-2.5-pro-exp-03-25' => 999000, //1000000, 'gemini-2.5-pro' => 999000, //1000000, 'gemini-2.5-flash' => 999000, //1000000, 'gemini-2.5-flash-lite' => 999000, //1000000, 'gemini-2.5-flash-lite-preview-06-17' => 999000, //1000000, 'gemini-2.5-flash-preview-04-17' => 999000, //1000000, 'gemma-3-27b-it' => 999000, //1000000, 'gemini-2.0-pro-exp-02-05' => 999000, //1000000, 'gemini-3.1-flash-lite-preview' => 999000, //1000000, 'gemini-3.5-flash' => 999000, //1000000, 'gemini-3-flash-preview' => 999000, //1000000, 'gemini-3.1-pro-preview' => 999000, //1000000, 'chat-bison-001' => 8192, //8192, 'text-bison-001' => 8192, //8192, 'grok-4.20-multi-agent-0309' => 250000, 'grok-4.20-0309-non-reasoning' => 250000, 'grok-4.20-0309-reasoning' => 250000, 'grok-4.3' => 250000, 'grok-4.5' => 250000, 'grok-build-0.1' => 250000, 'text-embedding-005' => 2048, //2048, 'gemini-embedding-001' => 2048, //2048, 'gemini-embedding-2-preview' => 2048, //2048, ); $model_tokens = array_merge($model_tokens, aimogen_get_perplexity_model_tokens()); $model_tokens = array_merge($model_tokens, aimogen_get_groq_model_tokens()); $model_tokens = array_merge($model_tokens, aimogen_get_nvidia_model_tokens()); $model_tokens = array_merge($model_tokens, aimogen_get_openrouter_model_tokens()); if(isset($model_tokens[$model])) { return $model_tokens[$model]; } return AIMOGEN_DEFAULT_MAX_TOKENS; } function aimogen_get_max_input_tokens_openrouter($model) { static $openrouter_arr = false; if($openrouter_arr === false) { try { $openrouter_arr = aimogen_get_openrouter_models(); if($openrouter_arr !== false) { foreach($openrouter_arr['source_list'] as $smodel) { if($model === $smodel['model']) { return $smodel['maxContextualTokens']; } } } } catch(Exception $e) { aimogen_log_to_file('Failed to list OpenRouter models: ' . $e->getMessage()); } } return AIMOGEN_DEFAULT_MAX_TOKENS; } function aimogen_get_openrouter_model_tokens() { $models = array(); try { $openrouter_arr = aimogen_get_openrouter_models(); if($openrouter_arr !== false) { foreach($openrouter_arr['source_list'] as $smodel) { $models[$smodel['model']] = intval($smodel['maxCompletionTokens']) - 100; if($models[$smodel['model']] > 100000) { $models[$smodel['model']] = intval($smodel['maxCompletionTokens']) - 7000; } } } } catch(Exception $e) { aimogen_log_to_file('Failed to list OpenRouter models: ' . $e->getMessage()); } return $models; } function aimogen_get_perplexity_model_tokens() { return array( 'sonar' => 100000, 'sonar-pro' => 150000, 'sonar-reasoning' => 100000, 'sonar-reasoning-pro' => 100000, 'sonar-deep-research' => 100000 ); } function aimogen_get_groq_model_tokens() { return array( 'distil-whisper-large-v3-en' => 8000, 'gemma2-9b-it' => 8000, 'llama-3.3-70b-versatile' => 8000, 'llama-3.1-8b-instant' => 8000, 'llama-guard-3-8b' => 8000, 'llama3-70b-8192' => 8000, 'llama3-8b-8192' => 8000, 'mixtral-8x7b-32768' => 8000, 'mistral-saba-24b' => 8000, 'qwen-2.5-coder-32b' => 8000, 'qwen-2.5-32b' => 8000, 'deepseek-r1-distill-qwen-32b' => 16000, 'deepseek-r1-distill-llama-70b-specdec' => 16000, 'deepseek-r1-distill-llama-70b' => 8000, 'llama-3.3-70b-specdec' => 8000, 'llama-3.2-1b-preview' => 8000, 'llama-3.2-3b-preview' => 8000, 'llama-3.2-11b-vision-preview' => 8000, 'llama-3.2-90b-vision-preview' => 8000 ); } function aimogen_get_nvidia_model_tokens() { return array( 'nvidia/llama-3.1-nemotron-70b-instruct' => 4000, 'utter-project/eurollm-9b-instruct' => 4000, 'gotocompany/gemma-2-9b-cpt-sahabatai-instruct' => 4000, 'nvidia/usdcode-llama-3.1-70b-instruct' => 4000, 'qwen/qwq-32b' => 4000, 'nvidia/llama-3.3-nemotron-super-49b-v1' => 4000, 'google/gemma-3-1b-it' => 4000, 'deepseek-ai/deepseek-r1' => 4000, 'qwen/qwen2.5-7b-instruct' => 4000, 'writer/palmyra-creative-122b' => 4000, 'microsoft/phi-4-mini-instruct' => 4000, 'zyphra/zamba2-7b-instruct' => 4000, 'institute-of-science-tokyo/llama-3.1-swallow-70b-instruct-v0.1' => 4000, 'nvidia/nemotron-4-mini-hindi-4b-instruct' => 2000, 'ibm/granite-guardian-3.0-8b' => 2000, 'ibm/granite-3.0-8b-instruct' => 2000, 'ibm/granite-3.0-3b-a800m-instruct' => 2000, 'nvidia/mistral-nemo-minitron-8b-8k-instruct' => 8000, 'nvidia/llama-3.1-nemotron-70b-reward' => 4000, 'meta/llama-3.2-3b-instruct' => 4000, 'meta/llama-3.2-1b-instruct' => 2000, 'nvidia/llama-3.1-nemotron-51b-instruct' => 4000, 'qwen/qwen2-7b-instruct' => 2000, 'abacusai/dracarys-llama-3.1-70b-instruct' => 4000, 'ai21labs/jamba-1.5-mini-instruct' => 2000, 'nvidia/nemotron-mini-4b-instruct' => 2000, 'microsoft/phi-3.5-moe-instruct' => 8000, 'microsoft/phi-3.5-mini-instruct' => 4000, 'mistralai/mathstral-7b-v0.1' => 2000, 'rakuten/rakutenai-7b-instruct' => 2000, 'rakuten/rakutenai-7b-chat' => 2000, 'mistralai/mistral-large-2-instruct' => 4000, 'writer/palmyra-fin-70b-32k' => 32000, 'thudm/chatglm3-6b' => 4000, 'baichuan-inc/baichuan2-13b-chat' => 4000, 'meta/llama-3.1-70b-instruct' => 4000, 'meta/llama-3.1-8b-instruct' => 4000, 'nv-mistralai/mistral-nemo-12b-instruct' => 8000, 'nvidia/llama3-chatqa-1.5-70b' => 1000, 'nvidia/llama3-chatqa-1.5-8b' => 1000, '01-ai/yi-large' => 4000, 'nvidia/nemotron-4-340b-instruct' => 4000, 'writer/palmyra-med-70b-32k' => 32000, 'writer/palmyra-med-70b' => 4000, 'upstage/solar-10.7b-instruct' => 2000, 'mediatek/breeze-7b-instruct' => 1000, 'ibm/granite-34b-code-instruct' => 2000, 'ibm/granite-8b-code-instruct' => 4000, 'aisingapore/sea-lion-7b-instruct' => 1000, 'microsoft/phi-3-mini-4k-instruct' => 4000, 'mistralai/mixtral-8x22b-instruct-v0.1' => 4000, 'meta/llama3-70b-instruct' => 4000, 'meta/llama3-8b-instruct' => 4000, 'google/codegemma-7b' => 2000, 'google/gemma-2b' => 2000, 'google/gemma-7b' => 2000, 'meta/codellama-70b' => 1000, 'mistralai/mixtral-8x7b-instruct-v0.1' => 4000 ); } function aimogen_get_xai_model_tokens() { return array( 'grok-4.20-multi-agent-0309' => 128000, 'grok-4.20-0309-non-reasoning' => 128000, 'grok-4.20-0309-reasoning' => 128000, 'grok-4.3' => 128000, 'grok-4.5' => 250000, 'grok-build-0.1' => 128000, ); } function aimogen_get_max_input_tokens_perplexity($model) { static $perplexity_arr = AIMOGEN_PERPLEXITY_MODELS; if(!in_array($model, $perplexity_arr)) { return AIMOGEN_DEFAULT_MAX_TOKENS; } $ppmodel_tokens = aimogen_get_perplexity_model_tokens(); if(isset($ppmodel_tokens[$model])) { return $ppmodel_tokens[$model]; } return AIMOGEN_DEFAULT_MAX_TOKENS; } function aimogen_get_max_input_tokens_groq($model) { static $groq_arr = AIMOGEN_GROQ_MODELS; if(!in_array($model, $groq_arr)) { return AIMOGEN_DEFAULT_MAX_TOKENS; } $ppmodel_tokens = aimogen_get_groq_model_tokens(); if(isset($ppmodel_tokens[$model])) { return $ppmodel_tokens[$model]; } return AIMOGEN_DEFAULT_MAX_TOKENS; } function aimogen_get_max_input_tokens_nvidia($model) { static $nvidia_arr = AIMOGEN_NVIDIA_MODELS; if(!in_array($model, $nvidia_arr)) { return AIMOGEN_DEFAULT_MAX_TOKENS; } $ppmodel_tokens = aimogen_get_nvidia_model_tokens(); if(isset($ppmodel_tokens[$model])) { return $ppmodel_tokens[$model]; } return AIMOGEN_DEFAULT_MAX_TOKENS; } function aimogen_get_max_input_tokens_xai($model) { static $xai_arr = AIMOGEN_XAI_MODELS; if(!in_array($model, $xai_arr)) { return AIMOGEN_DEFAULT_MAX_TOKENS; } $ppmodel_tokens = aimogen_get_xai_model_tokens(); if(isset($ppmodel_tokens[$model])) { return $ppmodel_tokens[$model]; } return AIMOGEN_DEFAULT_MAX_TOKENS; } function aimogen_get_max_output_tokens_openrouter($model) { static $openrouter_arr = false; if($openrouter_arr === false) { try { $openrouter_arr = aimogen_get_openrouter_models(); if($openrouter_arr !== false) { foreach($openrouter_arr['source_list'] as $smodel) { if($model === $smodel['model']) { return $smodel['maxCompletionTokens']; } } } } catch(Exception $e) { aimogen_log_to_file('Failed to list OpenRouter models: ' . $e->getMessage()); } } return AIMOGEN_DEFAULT_MAX_TOKENS; } function aimogen_sanitize_ai_result($generated_text) { if(is_string($generated_text)) { $generated_text = trim($generated_text); if (($generated_text[0] === '"' && $generated_text[aimogen_strlen($generated_text) - 1] === '"') || ($generated_text[0] === '\'' && $generated_text[aimogen_strlen($generated_text) - 1] === '\'')) { $generated_text = aimogen_substr($generated_text, 1, -1); $generated_text = trim($generated_text); } else { $generated_text = $generated_text; } } return $generated_text; } function aimogen_load_textdomain() { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (isset($aimogen_Main_Settings['app_id']) && trim($aimogen_Main_Settings['app_id']) != '') { if (isset($aimogen_Main_Settings['assistant_disable']) && ($aimogen_Main_Settings['assistant_disable'] == 'front' || $aimogen_Main_Settings['assistant_disable'] == 'both')) { if(!defined('AIMOGEN_IS_PRO')) { add_filter("mce_external_plugins", "aimogen_enqueue_plugin_scripts"); add_action('wp_head', 'aimogen_classic_mce_inline_script_always'); add_filter("mce_buttons", "aimogen_register_buttons_editor"); } } $appids = preg_split('/\r\n|\r|\n/', trim($aimogen_Main_Settings['app_id'])); $appids = array_filter($appids); $token = $appids[array_rand($appids)]; $token = apply_filters('aimogen_openai_api_key', $token); $aimogen_Chatbot_Settings = get_option('aimogen_Chatbot_Settings', false); if (isset($aimogen_Chatbot_Settings['enable_front_end']) && $aimogen_Chatbot_Settings['enable_front_end'] != '') { if(!function_exists('is_plugin_active')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (!is_plugin_active('aimogen-pro/aimogen-pro.php')) { if(($aimogen_Chatbot_Settings['enable_front_end'] === 'front' || $aimogen_Chatbot_Settings['enable_front_end'] === 'both')) { add_action( 'wp_footer', 'aimogen_inject_chat' ); } if(($aimogen_Chatbot_Settings['enable_front_end'] === 'back' || $aimogen_Chatbot_Settings['enable_front_end'] === 'both')) { add_action( 'admin_footer', 'aimogen_inject_chat_admin' ); } } } } } add_action( 'init', 'aimogen_load_textdomain' ); function aimogen_check_additional_chats(&$chatfound, $aimogen_Chatbot_Settings) { if(isset($aimogen_Chatbot_Settings['aimogen_chat_json']) && !empty(isset($aimogen_Chatbot_Settings['aimogen_chat_json']))) { $jsdec = json_decode($aimogen_Chatbot_Settings['aimogen_chat_json']); if($jsdec != null) { foreach($jsdec as $dataid => $value) { $data = $value->data; if (isset($data->not_show_urls) && trim($data->not_show_urls) != '') { $no_show_urls = preg_split('/\r\n|\r|\n/', trim($data->not_show_urls)); $no_show_urls = array_filter($no_show_urls); if(count($no_show_urls) > 0) { global $wp; $current_url = home_url( $wp->request ); foreach($no_show_urls as $nsurl) { if(rtrim($current_url, '/') == rtrim(trim($nsurl), '/')) { continue; } } } } if (isset($data->only_show_urls) && trim($data->only_show_urls) != '') { $only_show_urls = preg_split('/\r\n|\r|\n/', trim($data->only_show_urls)); $only_show_urls = array_filter($only_show_urls); if(count($only_show_urls) > 0) { $url_found = false; global $wp; $current_url = home_url( $wp->request ); foreach($only_show_urls as $nsurl) { if(rtrim($current_url, '/') == rtrim(trim($nsurl), '/')) { $url_found = true; } } if($url_found === false) { continue; } } } if (isset($data->never_show) && is_array($data->never_show)) { $this_day = gmdate('l'); if(in_array($this_day, $data->never_show)) { continue; } } if (isset($data->show_content_wp) && is_array($data->show_content_wp) && !empty($data->show_content_wp)) { $post_chars = aimogen_get_post_characteristics(); $fnd = false; foreach($data->show_content_wp as $showme) { if(in_array($showme, $post_chars)) { $fnd = true; break; } } if($fnd == false) { continue; } } if (isset($data->no_show_content_wp) && is_array($data->no_show_content_wp) && !empty($data->no_show_content_wp)) { $post_chars = aimogen_get_post_characteristics(); $fnd = false; foreach($data->no_show_content_wp as $showme) { if(in_array($showme, $post_chars)) { $fnd = true; break; } } if($fnd == true) { continue; } } if (isset($data->no_show_locales) && is_array($data->no_show_locales) && !empty($data->no_show_locales)) { $locale = get_user_locale(); $fnd = false; foreach($data->no_show_locales as $showme) { if($showme == $locale) { $fnd = true; break; } } if($fnd == true) { continue; } } if (isset($data->show_locales) && is_array($data->show_locales) && !empty($data->show_locales)) { $locale = get_user_locale(); $fnd = false; foreach($data->show_locales as $showme) { if($showme == $locale) { $fnd = true; break; } } if($fnd == false) { continue; } } if (isset($data->no_show_roles) && is_array($data->no_show_roles) && !empty($data->no_show_roles)) { $user = wp_get_current_user(); $fnd = false; if ( null !== $user ) { foreach ( $user->roles as $role ) { if ( in_array( $role, $data->no_show_roles, true ) ) { $fnd = true; break; } } if($fnd == true) { continue; } } } if (isset($data->show_roles) && is_array($data->show_roles) && !empty($data->show_roles)) { $user = wp_get_current_user(); $fnd = false; if ( null !== $user ) { foreach ( $user->roles as $role ) { if ( in_array( $role, $data->show_roles, true ) ) { $fnd = true; break; } } } if($fnd == false) { continue; } } if (isset($data->no_show_devices) && is_array($data->no_show_devices) && !empty($data->no_show_devices)) { require_once(dirname(__FILE__) . "/res/mobile-detect.php"); $fnd = false; $detect = new AimogenMobileDetect; $device = 'desktop'; if ( $detect->isTablet() ) { $device = 'tablet'; } if ( $detect->isMobile() && ! $detect->isTablet() ) { $device = 'mobile'; } if ( in_array( $device, $data->no_show_devices, true ) ) { $fnd = true; } if($fnd == true) { continue; } } if (isset($data->show_devices) && is_array($data->show_devices) && !empty($data->show_devices)) { require_once(dirname(__FILE__) . "/res/mobile-detect.php"); $fnd = false; $detect = new AimogenMobileDetect; $device = 'desktop'; if ( $detect->isTablet() ) { $device = 'tablet'; } if ( $detect->isMobile() && ! $detect->isTablet() ) { $device = 'mobile'; } if ( in_array( $device, $data->show_devices, true ) ) { $fnd = true; } if($fnd == false) { continue; } } if (isset($data->no_show_oses) && is_array($data->no_show_oses) && !empty($data->no_show_oses)) { $fnd = false; foreach($data->no_show_oses as $showme) { if ( aimogen_detectOS($showme) ) { $fnd = true; break; } } if($fnd == true) { continue; } } if (isset($data->show_oses) && is_array($data->show_oses) && !empty($data->show_oses)) { $fnd = false; foreach($data->show_oses as $showme) { if ( aimogen_detectOS($showme) ) { $fnd = true; break; } } if($fnd == false) { continue; } } if (isset($data->no_show_browsers) && is_array($data->no_show_browsers) && !empty($data->no_show_browsers)) { $fnd = false; foreach($data->no_show_browsers as $showme) { if ( aimogen_detectBrowser($showme) ) { $fnd = true; break; } } if($fnd == true) { continue; } } if (isset($data->show_browsers) && is_array($data->show_browsers) && !empty($data->show_browsers)) { $fnd = false; foreach($data->show_browsers as $showme) { if ( aimogen_detectBrowser($showme) ) { $fnd = true; break; } } if($fnd == false) { continue; } } if (isset($data->show_ips) && !empty($data->show_ips)) { $fnd = false; $sips = preg_split('/\r\n|\r|\n/', $data->show_ips); foreach($sips as $showme) { if ( aimogen_passIPs($showme) ) { $fnd = true; break; } } if($fnd == false) { continue; } } if (isset($data->no_show_ips) && !empty($data->no_show_ips)) { $fnd = false; $sips = preg_split('/\r\n|\r|\n/', $data->no_show_ips); foreach($sips as $showme) { if ( aimogen_passIPs($showme) ) { $fnd = true; break; } } if($fnd == true) { continue; } } if (isset($data->min_time) && $data->min_time != '' && isset($data->max_time) && $data->max_time != '') { $always_show = false; if (isset($data->always_show) && is_array($data->always_show)) { $this_day = gmdate('l'); if(in_array($this_day, $data->always_show)) { $always_show = true; } } if($always_show === false) { $exit = true; $mytime = gmdate("H:i"); $min_time = $data->min_time; $max_time = $data->max_time; $date1 = DateTime::createFromFormat('H:i', $mytime); $date2 = DateTime::createFromFormat('H:i', $min_time); $date3 = DateTime::createFromFormat('H:i', $max_time); if ($date1 > $date2 && $date1 < $date3) { $exit = false; } if($exit == true) { continue; } } } $shortcode = $data->shortcode; if(trim($shortcode) != '') { $global_chat_params = array( 'temperature' => '', 'top_p' => '', 'presence_penalty' => '', 'frequency_penalty' => '', 'model' => '', 'instant_response' => '', 'show_in_window' => 'true', 'disable_filters' => '1' ); $temp_arr = shortcode_parse_atts(stripslashes(trim($shortcode))); if(!empty($temp_arr)) { $global_chat_params = $temp_arr; $global_chat_params['show_in_window'] = 'true'; $global_chat_params['disable_filters'] = '1'; } $chatrez = aimogen_chat_shortcode($global_chat_params); if(!empty($chatrez)) { $chatfound = true; echo wp_kses_post($chatrez); break; } } } } } } function aimogen_inject_chat() { $chatfound = false; $aimogen_Chatbot_Settings = get_option('aimogen_Chatbot_Settings', false); aimogen_check_additional_chats($chatfound, $aimogen_Chatbot_Settings); if($chatfound === false) { $global_chat_params = array( 'temperature' => '', 'top_p' => '', 'presence_penalty' => '', 'frequency_penalty' => '', 'model' => '', 'instant_response' => '', 'show_in_window' => 'true' ); if (isset($aimogen_Chatbot_Settings['custom_global_shortcode']) && trim($aimogen_Chatbot_Settings['custom_global_shortcode']) != '') { $temp_arr = shortcode_parse_atts(trim($aimogen_Chatbot_Settings['custom_global_shortcode'])); if(!empty($temp_arr)) { $global_chat_params = $temp_arr; $global_chat_params['show_in_window'] = 'true'; } } if (isset($aimogen_Chatbot_Settings['god_mode_front_end']) && (trim($aimogen_Chatbot_Settings['god_mode_front_end']) == 'front' || trim($aimogen_Chatbot_Settings['god_mode_front_end']) == 'both')) { $global_chat_params['enable_god_mode'] = 'enabled'; } echo aimogen_chat_shortcode($global_chat_params); } } function aimogen_inject_chat_admin() { $chatfound = false; $aimogen_Chatbot_Settings = get_option('aimogen_Chatbot_Settings', false); aimogen_check_additional_chats($chatfound, $aimogen_Chatbot_Settings); if($chatfound === false) { $global_chat_params = array( 'temperature' => '', 'top_p' => '', 'presence_penalty' => '', 'frequency_penalty' => '', 'model' => '', 'instant_response' => '', 'show_in_window' => 'true' ); if (isset($aimogen_Chatbot_Settings['custom_global_shortcode']) && trim($aimogen_Chatbot_Settings['custom_global_shortcode']) != '') { $temp_arr = shortcode_parse_atts(trim($aimogen_Chatbot_Settings['custom_global_shortcode'])); if(!empty($temp_arr)) { $global_chat_params = $temp_arr; $global_chat_params['show_in_window'] = 'true'; } } if (isset($aimogen_Chatbot_Settings['god_mode_front_end']) && (trim($aimogen_Chatbot_Settings['god_mode_front_end']) == 'back' || trim($aimogen_Chatbot_Settings['god_mode_front_end']) == 'both')) { $global_chat_params['enable_god_mode'] = 'enabled'; } echo aimogen_chat_shortcode( $global_chat_params ) ?? ''; } } function aimogen_is_gutenberg() { if(isset($GLOBALS['post']->ID) && function_exists('has_blocks') && has_blocks($GLOBALS['post']->ID)) { return true; } else { return false; } } function aimogen_enqueue_plugin_scripts($plugin_array) { $plugin_array["aimogen_editor"] = plugin_dir_url(__FILE__) . "scripts/classic-editor.js"; return $plugin_array; } function aimogen_register_buttons_editor($buttons) { array_push($buttons, "aimogen"); return $buttons; } function aimogen_classic_mce_inline_script_always() { aimogen_add_inline_js_object(); } function aimogen_classic_mce_inline_script() { global $pagenow; if ($pagenow !== 'post.php' && $pagenow !== 'post-new.php' && $pagenow !== 'admin.php') { return; } aimogen_add_inline_js_object(); } function aimogen_add_inline_js_object () { $aimogen_build_plugin_js_config = aimogen_build_plugin_js_config(); $name = md5(get_bloginfo()); wp_enqueue_script( sanitize_key( $name ) . '-admin-footer-script', plugins_url( 'scripts/admin-footer.js', __FILE__ ), array( 'jquery' ), AIMOGEN_LITE_MAJOR_VERSION, true ); wp_add_inline_script( sanitize_key( $name ) . '-admin-footer-script', 'var aimogen = ' . wp_json_encode($aimogen_build_plugin_js_config), 'after' ); } function aimogen_build_plugin_js_config() { $assistant_placement = 'below'; $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (isset($aimogen_Main_Settings['assistant_placement']) && $aimogen_Main_Settings['assistant_placement'] != '') { $assistant_placement = $aimogen_Main_Settings['assistant_placement']; } $nonce = wp_create_nonce('wp_rest' ); $prompts = aimogen_get_assistant(); if(!is_array($prompts)) { $prompts = array(); } $aimogenScriptVars = array( 'nonce' => $nonce, 'ajaxurl' => admin_url('admin-ajax.php'), 'prompts' => $prompts, 'placement' => $assistant_placement, 'xicon' => plugins_url('/images/icon-old.png', __FILE__) ); return $aimogenScriptVars; } $plugin = plugin_basename(__FILE__); if(is_admin()) { if(!aimogen_is_gutenberg()) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); { if (!isset($aimogen_Main_Settings['assistant_disable']) || ($aimogen_Main_Settings['assistant_disable'] == 'back' || $aimogen_Main_Settings['assistant_disable'] == 'both')) { if(!defined('AIMOGEN_IS_PRO')) { add_filter("mce_external_plugins", "aimogen_enqueue_plugin_scripts"); add_action('admin_head', 'aimogen_classic_mce_inline_script'); add_filter("mce_buttons", "aimogen_register_buttons_editor"); } } } } require(dirname(__FILE__) . "/res/aimogen-single-list.php"); require(dirname(__FILE__) . "/res/aimogen-spinner-list.php"); require(dirname(__FILE__) . "/res/aimogen-chatbot.php"); require(dirname(__FILE__) . "/res/aimogen-assistants.php"); require(dirname(__FILE__) . "/res/aimogen-logs.php"); } function aimogen_admin_enqueue_all() { $name = md5(get_bloginfo()); $reg_css_code = '.cr_auto_update{background-color:#fff8e5;margin:5px 20px 15px 20px;border-left:4px solid #fff;padding:12px 12px 12px 12px !important;border-left-color:#ffb900;}'; wp_register_style( sanitize_key($name) . '-plugin-reg-style', false, false, AIMOGEN_LITE_MAJOR_VERSION ); wp_enqueue_style( sanitize_key($name) . '-plugin-reg-style' ); wp_add_inline_style( sanitize_key($name) . '-plugin-reg-style', $reg_css_code ); } add_action('admin_menu', 'aimogen_register_my_custom_menu_page'); add_action('network_admin_menu', 'aimogen_register_my_custom_menu_page'); function aimogen_register_my_custom_menu_page() { if(!function_exists('is_plugin_active')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (!is_plugin_active('aimogen-pro/aimogen-pro.php')) { require(dirname(__FILE__) . "/res/aimogen-main.php"); $skip_main = false; $skip_single = false; $skip_editor = false; $skip_chatbot = false; $skip_assistant = false; $skip_logs = false; $base_slug = 'aimogen_admin_settings'; add_menu_page('Aimogen AI Content Writer, Editor & Chatbot', 'Aimogen', 'manage_options', $base_slug, $base_slug, plugins_url('images/icon.png', __FILE__)); if($skip_main == false) { $main = add_submenu_page('aimogen_admin_settings', esc_html__("Settings", 'aimogen'), esc_html__("Settings", 'aimogen'), 'manage_options', 'aimogen_admin_settings'); add_action( 'load-' . $main, 'aimogen_load_all_main_js' ); add_action( 'load-' . $main, 'aimogen_load_main_admin_js' ); add_action( 'load-' . $main, 'aimogen_load_playground' ); } { if($skip_single == false) { $single = add_submenu_page($base_slug, esc_html__('AI Content Creator', 'aimogen'), esc_html__('AI Content Creator', 'aimogen'), 'manage_options', 'aimogen_single_panel', 'aimogen_single_panel'); add_action( 'load-' . $single, 'aimogen_load_admin_js_no_rules' ); add_action( 'load-' . $single, 'aimogen_load_all_main_js' ); add_action( 'load-' . $single, 'aimogen_load_single' ); add_action( 'load-' . $single, 'aimogen_load_playground' ); } if($skip_editor == false) { $auto = add_submenu_page($base_slug, esc_html__('AI Content Editor', 'aimogen'), esc_html__('AI Content Editor', 'aimogen'), 'manage_options', 'aimogen_spinner_panel', 'aimogen_spinner_panel'); add_action( 'load-' . $auto, 'aimogen_load_post_admin_js' ); add_action( 'load-' . $auto, 'aimogen_load_all_main_js' ); add_action( 'load-' . $auto, 'aimogen_load_playground' ); add_action( 'load-' . $auto, 'aimogen_load_auto_rules_css' ); add_action( 'load-' . $auto, 'aimogen_load_spin' ); } if($skip_chatbot == false) { $chatbot = add_submenu_page($base_slug, esc_html__('AI Chatbot', 'aimogen'), esc_html__('AI Chatbot', 'aimogen'), 'manage_options', 'aimogen_chatbot_panel', 'aimogen_chatbot_panel'); add_action( 'load-' . $chatbot, 'aimogen_load_all_main_js' ); add_action( 'load-' . $chatbot, 'aimogen_load_playground' ); add_action( 'load-' . $chatbot, 'aimogen_load_live_preview' ); } if($skip_assistant == false && !(defined('AIMOGEN_ASSISTANTS_API_RETIRED') && AIMOGEN_ASSISTANTS_API_RETIRED)) { $assistants = add_submenu_page($base_slug, esc_html__('AI Assistants', 'aimogen'), esc_html__('AI Assistants', 'aimogen'), 'manage_options', 'aimogen_assistants_panel', 'aimogen_assistants_panel'); add_action( 'load-' . $assistants, 'aimogen_load_all_main_js' ); add_action( 'load-' . $assistants, 'aimogen_load_playground' ); add_action( 'load-' . $assistants, 'aimogen_load_assistants' ); } if($skip_logs == false) { $logs = add_submenu_page($base_slug, esc_html__("Logs & Info", 'aimogen'), esc_html__("Logs & Info", 'aimogen'), 'manage_options', 'aimogen_logs', 'aimogen_logs'); add_action( 'load-' . $logs, 'aimogen_load_all_main_js' ); add_action( 'load-' . $logs, 'aimogen_load_playground' ); } $media = add_media_page( 'Aimogen Images', 'Aimogen Images', 'manage_options', 'aimogen', 'aimogen_media_page' ); add_action( 'load-' . $media, 'aimogen_load_all_admin_js' ); } } } function aimogen_load_post_admin_js() { add_action('admin_enqueue_scripts', 'aimogen_admin_load_post_files'); } function aimogen_admin_load_post_files() { $name = md5(get_bloginfo()); wp_register_script(sanitize_key($name) . '-submitter-script', plugins_url('scripts/poster.js', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_script(sanitize_key($name) . '-submitter-script'); wp_localize_script(sanitize_key($name) . '-submitter-script', 'aimogen_object', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('openai-ajax-nonce'), 'modelsvision' => aimogen_get_all_vision_models() )); } function aimogen_load_auto_rules_css(){ add_action('admin_enqueue_scripts', 'aimogen_enqueue_only_rules'); } function aimogen_load_spin(){ add_action('admin_enqueue_scripts', 'aimogen_enqueue_only_spin'); } function aimogen_enqueue_only_spin() { $name = md5(get_bloginfo()); wp_enqueue_script(sanitize_key($name) . '-spin-script', plugins_url('scripts/spin.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION, true); } function aimogen_enqueue_only_rules() { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); $more_logs = '0'; if (isset($aimogen_Main_Settings['enable_detailed_logging']) && $aimogen_Main_Settings['enable_detailed_logging'] == 'on') { $more_logs = '1'; } $name = md5(get_bloginfo()); wp_enqueue_script('aimogen-bulk-script', plugins_url('scripts/bulk-editor.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION, true); $footer_conf_settings = array( 'plugin_dir_url' => plugin_dir_url(__FILE__), 'nonce' => wp_create_nonce('openai-bulk-nonce'), 'more_logs' => $more_logs, 'ajaxurl' => admin_url('admin-ajax.php') ); wp_localize_script('aimogen-bulk-script', 'aimogen_mybulksettings', $footer_conf_settings); } function aimogen_load_admin_js(){ add_action('admin_enqueue_scripts', 'aimogen_enqueue_admin_js'); } function aimogen_load_admin_js_no_rules(){ add_action('admin_enqueue_scripts', 'aimogen_enqueue_admin_js_no_rules'); } function aimogen_enqueue_admin_js() { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); $more_logs = '0'; if (isset($aimogen_Main_Settings['enable_detailed_logging']) && $aimogen_Main_Settings['enable_detailed_logging'] == 'on') { $more_logs = '1'; } $name = md5(get_bloginfo()); wp_enqueue_script('aimogen-modeselect-script', plugins_url('scripts/modeselect.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION, true); $footer_conf_settingsx = array( 'showme' => esc_html__("Show Tutorial Video", 'aimogen'), 'hideme' => esc_html__("Hide Tutorial Video", 'aimogen') ); wp_localize_script('aimogen-modeselect-script', 'aimogen_varsx', $footer_conf_settingsx); wp_enqueue_script('aimogen-footer-script', plugins_url('scripts/footer.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION, true); $cr_miv = ini_get('max_input_vars'); if($cr_miv === null || $cr_miv === false || !is_numeric($cr_miv)) { $cr_miv = '9999999'; } $footer_conf_settings = array( 'max_input_vars' => $cr_miv, 'plugin_dir_url' => plugin_dir_url(__FILE__), 'more_logs' => $more_logs, 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('openai-run-nonce'), 'bulk_nonce' => wp_create_nonce('openai-bulk-nonce') ); wp_localize_script('aimogen-footer-script', 'aimogen_mycustomsettings', $footer_conf_settings); wp_register_style(sanitize_key($name) . '-rules-style', plugins_url('styles/aimogen-rules.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-rules-style'); } function aimogen_enqueue_admin_js_no_rules() { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); $more_logs = '0'; if (isset($aimogen_Main_Settings['enable_detailed_logging']) && $aimogen_Main_Settings['enable_detailed_logging'] == 'on') { $more_logs = '1'; } $name = md5(get_bloginfo()); wp_enqueue_script('aimogen-modeselect-script', plugins_url('scripts/modeselect.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION, true); $footer_conf_settingsx = array( 'showme' => esc_html__("Show Tutorial Video", 'aimogen'), 'hideme' => esc_html__("Hide Tutorial Video", 'aimogen') ); wp_localize_script('aimogen-modeselect-script', 'aimogen_varsx', $footer_conf_settingsx); wp_enqueue_script('aimogen-footer-script', plugins_url('scripts/footer.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION, true); $cr_miv = ini_get('max_input_vars'); if($cr_miv === null || $cr_miv === false || !is_numeric($cr_miv)) { $cr_miv = '9999999'; } $footer_conf_settings = array( 'max_input_vars' => $cr_miv, 'plugin_dir_url' => plugin_dir_url(__FILE__), 'more_logs' => $more_logs, 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('openai-run-nonce'), 'bulk_nonce' => wp_create_nonce('openai-bulk-nonce') ); wp_localize_script('aimogen-footer-script', 'aimogen_mycustomsettings', $footer_conf_settings); } function aimogen_load_main_admin_js(){ add_action('admin_enqueue_scripts', 'aimogen_enqueue_main_admin_js'); } function aimogen_enqueue_main_admin_js(){ $name = md5(get_bloginfo()); $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); wp_enqueue_script('aimogen-main-script', plugins_url('scripts/main.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION); if(!isset($aimogen_Main_Settings['best_user'])) { $best_user = ''; } else { $best_user = $aimogen_Main_Settings['best_user']; } if(!isset($aimogen_Main_Settings['best_password'])) { $best_password = ''; } else { $best_password = $aimogen_Main_Settings['best_password']; } $header_main_settings = array( 'best_user' => $best_user, 'best_password' => $best_password, 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('openai-ajax-nonce'), ); wp_localize_script('aimogen-main-script', 'aimogen_mycustommainsettings', $header_main_settings); } function aimogen_load_single() { $name = md5(get_bloginfo()); add_action('admin_enqueue_scripts', 'aimogen_admin_single'); wp_enqueue_script( 'jquery-ui-dialog' ); wp_enqueue_style( 'wp-jquery-ui-dialog' ); wp_enqueue_media(); wp_enqueue_script( sanitize_key($name) . '-media-loader-js', plugins_url( 'scripts/media.js' , __FILE__ ), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION ); wp_localize_script(sanitize_key($name) . '-media-loader-js', 'aimogen_ajax_object', array( 'nonce' => wp_create_nonce('openai-single-nonce') )); } function aimogen_enqueue_custom_css_for_toc_meta() { if ( is_singular() ) { global $post; if(isset($post->ID)) { $transient_key = 'aimogen_toc_' . $post->ID; $meta_value = get_transient($transient_key); if ($meta_value == false) { $meta_value = get_post_meta( $post->ID, 'aimogen_toc', true ); set_transient($transient_key, $meta_value, 12 * HOUR_IN_SECONDS); } if ( $meta_value === '1' ) { $name = md5(get_bloginfo()); wp_register_style(sanitize_key($name) . '-toc-css-ai', plugins_url('styles/toc.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-toc-css-ai'); } } } } add_action( 'wp_enqueue_scripts', 'aimogen_enqueue_custom_css_for_toc_meta' ); function aimogen_admin_single() { $name = md5(get_bloginfo()); wp_register_script(sanitize_key($name) . '-single-script', plugins_url('scripts/single.js', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_script(sanitize_key($name) . '-single-script'); $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (isset($aimogen_Main_Settings['no_jobs']) && $aimogen_Main_Settings['no_jobs'] === 'on') { $no_jobs = '1'; } else { $no_jobs = '0'; } wp_localize_script(sanitize_key($name) . '-single-script', 'aimogen_ajax_object', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('openai-single-nonce'), 'no_jobs' => $no_jobs )); } function aimogen_load_all_admin_js(){ add_action('admin_enqueue_scripts', 'aimogen_admin_load_files'); } function aimogen_load_all_main_js(){ add_action('admin_enqueue_scripts', 'aimogen_admin_load_main'); } function aimogen_load_playground(){ add_action('admin_enqueue_scripts', 'aimogen_admin_load_playground'); } function aimogen_load_live_preview(){ add_action('admin_enqueue_scripts', 'aimogen_admin_load_live_preview'); } function aimogen_load_assistants(){ add_action('admin_enqueue_scripts', 'aimogen_admin_load_assistants'); add_action('admin_footer', 'aimogen_admin_footer'); } add_filter("plugin_action_links_$plugin", 'aimogen_add_settings_link'); function aimogen_add_settings_link($links) { $settings_link = '' . esc_html__('Settings', 'aimogen') . ''; array_push($links, $settings_link); return $links; } function aimogen_log_to_file($str) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (isset($aimogen_Main_Settings['enable_logging']) && $aimogen_Main_Settings['enable_logging'] == 'on') { $d = gmdate("j-M-Y H:i:s e", current_time( 'timestamp' )); set_transient('aimogen_log_history', $str, 60*60*12); if(function_exists('error_log')) { if(AIMOGEN_IS_DEBUG) { $upload = wp_upload_dir(); $dir = trailingslashit( $upload['basedir'] ) . 'aimogen'; if ( ! file_exists( $dir ) ) { wp_mkdir_p( $dir ); } $log_file = trailingslashit( $dir ) . 'aimogen_info.log'; } else { $log_file = trailingslashit(get_temp_dir()) . 'aimogen_info.log'; } //error_log is used for logging purposes in the plugin, to write the log file // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log("[$d] " . $str . "
\r\n", 3, $log_file); } } } function aimogen_try_new_key($app_id, $token) { $appids = preg_split('/\r\n|\r|\n/', trim($app_id)); $appids = array_map('trim', $appids); $appids = array_filter($appids); if(count($appids) > 1) { if (($key = array_search($token, $appids)) !== false) { unset($appids[$key]); } if(count($appids) > 0) { $token_new = $appids[array_rand($appids)]; if(!empty($token_new)) { $token = $token_new; } } } $token = apply_filters('aimogen_openai_api_key', $token); return $token; } function aimogen_clearFromList($param, $type) { $GLOBALS['wp_object_cache']->delete('aimogen_running_list', 'options'); $running = get_option('aimogen_running_list'); if($running !== false) { $key = array_search(array( $param => $type ), $running); if ($key !== FALSE) { unset($running[$key]); aimogen_update_option('aimogen_running_list', $running); } } } function aimogen_replaceSynergyShortcodes($the_content) { $regex = '#%%([a-z0-9]+?)(?:_title)?_(\d+?)_(\d+?)%%#'; $rezz = preg_match_all($regex, $the_content, $matches); if ($rezz === FALSE) { return $the_content; } if(isset($matches[1][0])) { $two_var_functions = array('pdfomatic'); $three_var_functions = array('bhomatic', 'crawlomatic', 'dmomatic', 'ezinomatic', 'fbomatic', 'flickomatic', 'imguromatic', 'iui', 'instamatic', 'linkedinomatic', 'mediumomatic', 'pinterestomatic', 'echo', 'spinomatic', 'tumblomatic', 'wordpressomatic', 'wpcomomatic', 'youtubomatic', 'mastermind', 'businessomatic'); $four_var_functions = array('aiomatic', 'contentomatic', 'quoramatic', 'newsomatic', 'aliomatic', 'amazomatic', 'blogspotomatic', 'bookomatic', 'careeromatic', 'cbomatic', 'cjomatic', 'craigomatic', 'ebayomatic', 'etsyomatic', 'rakutenomatic', 'learnomatic', 'eventomatic', 'gameomatic', 'gearomatic', 'giphyomatic', 'gplusomatic', 'hackeromatic', 'imageomatic', 'midas', 'movieomatic', 'nasaomatic', 'ocartomatic', 'okomatic', 'playomatic', 'recipeomatic', 'redditomatic', 'soundomatic', 'mp3omatic', 'ticketomatic', 'tmomatic', 'trendomatic', 'tuneomatic', 'twitchomatic', 'twitomatic', 'vimeomatic', 'viralomatic', 'vkomatic', 'walmartomatic', 'bestbuyomatic', 'wikiomatic', 'xlsxomatic', 'yelpomatic', 'yummomatic'); for ($i = 0; $i < count($matches[1]); $i++) { $replace_me = false; if(in_array($matches[1][$i], $four_var_functions)) { $za_function = $matches[1][$i] . '_run_rule'; if(function_exists($za_function)) { $xreflection = new ReflectionFunction($za_function); if($xreflection->getNumberOfParameters() >= 4) { $rule_runner = $za_function($matches[3][$i], $matches[2][$i], 0, 1); if($rule_runner != 'fail' && $rule_runner != 'nochange' && $rule_runner != 'ok' && $rule_runner !== false) { if(is_array($rule_runner)) { $the_content = str_replace('%%' . $matches[1][$i] . '_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', $rule_runner[0], $the_content); $the_content = str_replace('%%' . $matches[1][$i] . '_title_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', $rule_runner[1], $the_content); } else { $the_content = str_replace('%%' . $matches[1][$i] . '_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', $rule_runner, $the_content); $the_content = str_replace('%%' . $matches[1][$i] . '_title_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', '', $the_content); } $replace_me = true; } } $xreflection = null; unset($xreflection); } } elseif(in_array($matches[1][$i], $three_var_functions)) { $za_function = $matches[1][$i] . '_run_rule'; if(function_exists($za_function)) { $xreflection = new ReflectionFunction($za_function); if($xreflection->getNumberOfParameters() >= 3) { $rule_runner = $za_function($matches[3][$i], 0, 1); if($rule_runner != 'fail' && $rule_runner != 'nochange' && $rule_runner != 'ok' && $rule_runner !== false) { if(is_array($rule_runner)) { $the_content = str_replace('%%' . $matches[1][$i] . '_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', $rule_runner[0], $the_content); $the_content = str_replace('%%' . $matches[1][$i] . '_title_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', $rule_runner[1], $the_content); } else { $the_content = str_replace('%%' . $matches[1][$i] . '_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', $rule_runner, $the_content); $the_content = str_replace('%%' . $matches[1][$i] . '_title_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', '', $the_content); } $replace_me = true; } } $xreflection = null; unset($xreflection); } } elseif(in_array($matches[1][$i], $two_var_functions)) { $za_function = $matches[1][$i] . '_run_rule'; if(function_exists($za_function)) { $xreflection = new ReflectionFunction($za_function); if($xreflection->getNumberOfParameters() >= 2) { $rule_runner = $za_function($matches[3][$i], 1); if($rule_runner != 'fail' && $rule_runner != 'nochange' && $rule_runner != 'ok' && $rule_runner !== false) { if(is_array($rule_runner)) { $the_content = str_replace('%%' . $matches[1][$i] . '_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', $rule_runner[0], $the_content); $the_content = str_replace('%%' . $matches[1][$i] . '_title_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', $rule_runner[1], $the_content); } else { $the_content = str_replace('%%' . $matches[1][$i] . '_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', $rule_runner, $the_content); $the_content = str_replace('%%' . $matches[1][$i] . '_title_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', '', $the_content); } $replace_me = true; } } $xreflection = null; unset($xreflection); } } if($replace_me == false) { $the_content = str_replace('%%' . $matches[1][$i] . '_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', '', $the_content); $the_content = str_replace('%%' . $matches[1][$i] . '_title_' . $matches[2][$i] . '_' . $matches[3][$i] . '%%', '', $the_content); } } } return $the_content; } class Aimogen_lite_keywords{ public static $charset = 'UTF-8'; public static $banned_words = array('adsbygoogle', 'able', 'about', 'above', 'act', 'add', 'afraid', 'after', 'again', 'against', 'age', 'ago', 'agree', 'all', 'almost', 'alone', 'along', 'already', 'also', 'although', 'always', 'am', 'amount', 'an', 'and', 'anger', 'angry', 'animal', 'another', 'answer', 'any', 'appear', 'apple', 'are', 'arrive', 'arm', 'arms', 'around', 'arrive', 'as', 'ask', 'at', 'attempt', 'aunt', 'away', 'back', 'bad', 'bag', 'bay', 'be', 'became', 'because', 'become', 'been', 'before', 'began', 'begin', 'behind', 'being', 'bell', 'belong', 'below', 'beside', 'best', 'better', 'between', 'beyond', 'big', 'body', 'bone', 'born', 'borrow', 'both', 'bottom', 'box', 'boy', 'break', 'bring', 'brought', 'bug', 'built', 'busy', 'but', 'buy', 'by', 'call', 'came', 'can', 'cause', 'choose', 'close', 'close', 'consider', 'come', 'consider', 'considerable', 'contain', 'continue', 'could', 'cry', 'cut', 'dare', 'dark', 'deal', 'dear', 'decide', 'deep', 'did', 'die', 'do', 'does', 'dog', 'done', 'doubt', 'down', 'during', 'each', 'ear', 'early', 'eat', 'effort', 'either', 'else', 'end', 'enjoy', 'enough', 'enter', 'even', 'ever', 'every', 'except', 'expect', 'explain', 'fail', 'fall', 'far', 'fat', 'favor', 'fear', 'feel', 'feet', 'fell', 'felt', 'few', 'fill', 'find', 'fit', 'fly', 'follow', 'for', 'forever', 'forget', 'from', 'front', 'gave', 'get', 'gives', 'goes', 'gone', 'good', 'got', 'gray', 'great', 'green', 'grew', 'grow', 'guess', 'had', 'half', 'hang', 'happen', 'has', 'hat', 'have', 'he', 'hear', 'heard', 'held', 'hello', 'help', 'her', 'here', 'hers', 'high', 'hill', 'him', 'his', 'hit', 'hold', 'hot', 'how', 'however', 'I', 'if', 'ill', 'in', 'indeed', 'instead', 'into', 'iron', 'is', 'it', 'its', 'just', 'keep', 'kept', 'knew', 'know', 'known', 'late', 'least', 'led', 'left', 'lend', 'less', 'let', 'like', 'likely', 'likr', 'lone', 'long', 'look', 'lot', 'make', 'many', 'may', 'me', 'mean', 'met', 'might', 'mile', 'mine', 'moon', 'more', 'most', 'move', 'much', 'must', 'my', 'near', 'nearly', 'necessary', 'neither', 'never', 'next', 'no', 'none', 'nor', 'not', 'note', 'nothing', 'now', 'number', 'of', 'off', 'often', 'oh', 'on', 'once', 'only', 'or', 'other', 'ought', 'our', 'out', 'please', 'prepare', 'probable', 'pull', 'pure', 'push', 'put', 'raise', 'ran', 'rather', 'reach', 'realize', 'reply', 'require', 'rest', 'run', 'said', 'same', 'sat', 'saw', 'say', 'see', 'seem', 'seen', 'self', 'sell', 'sent', 'separate', 'set', 'shall', 'she', 'should', 'side', 'sign', 'since', 'so', 'sold', 'some', 'soon', 'sorry', 'stay', 'step', 'stick', 'still', 'stood', 'such', 'sudden', 'suppose', 'take', 'taken', 'talk', 'tall', 'tell', 'ten', 'than', 'thank', 'that', 'the', 'their', 'them', 'then', 'there', 'therefore', 'these', 'they', 'this', 'those', 'though', 'through', 'till', 'to', 'today', 'told', 'tomorrow', 'too', 'took', 'tore', 'tought', 'toward', 'tried', 'tries', 'trust', 'try', 'turn', 'two', 'under', 'until', 'up', 'upon', 'us', 'use', 'usual', 'various', 'verb', 'very', 'visit', 'want', 'was', 'we', 'well', 'went', 'were', 'what', 'when', 'where', 'whether', 'which', 'while', 'white', 'who', 'whom', 'whose', 'why', 'will', 'with', 'within', 'without', 'would', 'yes', 'yet', 'you', 'young', 'your', 'br', 'img', 'p','lt', 'gt', 'quot', 'copy'); public static $min_word_length = 4; public static function text($text, $length = 160) { return self::limit_chars(self::clean($text), $length,'',TRUE); } public static function keywords($text, $max_keys = 3) { $wordcount = array_count_values(str_word_count(self::clean($text), 1)); foreach ($wordcount as $key => $value) { if ( (aimogen_strlen($key)<= self::$min_word_length) OR in_array($key, self::$banned_words)) unset($wordcount[$key]); } uasort($wordcount,[self::class, 'cmp']); $wordcount = array_slice($wordcount,0, $max_keys); return implode(' ', array_keys($wordcount)); } private static function clean($text) { $text = html_entity_decode($text,ENT_QUOTES,self::$charset); $text = wp_strip_all_tags($text); $text = preg_replace('/\s\s+/', ' ', $text); $text = str_replace (array('\r\n', '\n', '+'), ',', $text); return trim($text); } private static function cmp($a, $b) { if ($a == $b) return 0; return ($a < $b) ? 1 : -1; } private static function limit_chars($str, $limit = 100, $end_char = NULL, $preserve_words = FALSE) { $end_char = ($end_char === NULL) ? '…' : $end_char; $limit = (int) $limit; if (trim($str) === '' OR aimogen_strlen($str) <= $limit) return $str; if ($limit <= 0) return $end_char; if ($preserve_words === FALSE) return rtrim(aimogen_substr($str, 0, $limit)).$end_char; if ( ! preg_match('/^.{0,'.$limit.'}\s/us', $str, $matches)) return $end_char; return rtrim($matches[0]).((aimogen_strlen($matches[0]) === aimogen_strlen($str)) ? '' : $end_char); } } function aimogen_scrape_related_questions($query, $headings, $model, $temperature, $top_p, $presence_penalty, $frequency_penalty, $max_tokens, $headings_ai_command, $headings_assistant_id = '') { $headings = intval($headings); $results = array(); $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (isset($aimogen_Main_Settings['valueserp_auth']) && trim($aimogen_Main_Settings['valueserp_auth']) != '') { $serpapi = 'https://api.valueserp.com/search?q=' . urlencode($query) . '&api_key=' . trim($aimogen_Main_Settings['valueserp_auth']); $html_data = aimogen_get_web_page($serpapi); if ($html_data !== FALSE) { $json = json_decode($html_data); if ($json !== null) { if(isset($json->related_searches[0]->query)) { foreach($json->related_searches as $qq) { $answer = ''; if(isset($qq->answer)) { $answer = $qq->answer; } $rec = array("q" => $qq->query, "a" => $answer, "l" => $qq->link); if(!isset($results[$qq->query])) { $results[$qq->query] = $rec; } if(count($results) >= $headings) { break; } } if(count($results) > 0 && count($results) < $headings) { $ok = true; while($ok && count($results) < $headings) { $last_elem = end($results); $serpapi = 'https://api.valueserp.com/search?q=' . urlencode($last_elem['q']) . '&api_key=' . trim($aimogen_Main_Settings['valueserp_auth']); $html_data = aimogen_get_web_page($serpapi); if ($html_data !== FALSE) { $json = json_decode($html_data); if ($json !== null) { if(isset($json->related_searches[0]->query)) { $count_before = count($results); foreach($json->related_searches as $qq) { $answer = ''; if(isset($qq->answer)) { $answer = $qq->answer; } $rec = array("q" => $qq->query, "a" => $answer, "l" => $qq->link); if(!isset($results[$qq->query])) { $results[$qq->query] = $rec; } if(count($results) >= $headings) { break; } } $count_after = count($results); if($count_after == $count_before) { $ok = false; } } else { $ok = false; } } else { $ok = false; } } else { $ok = false; } } } } } } } if (isset($aimogen_Main_Settings['serpapi_auth']) && trim($aimogen_Main_Settings['serpapi_auth']) != '') { if(count($results) < $headings) { $serpapi = 'https://serpapi.com/search.json?q=' . urlencode($query) . '&api_key=' . trim($aimogen_Main_Settings['serpapi_auth']); $html_data = aimogen_get_web_page($serpapi); if ($html_data !== FALSE) { $json = json_decode($html_data); if ($json !== null) { if(isset($json->related_questions[0]->question)) { foreach($json->related_questions as $qq) { $answer = ''; if(isset($qq->snippet)) { $answer = $qq->snippet; } elseif(isset($qq->title)) { $answer = $qq->title; if(isset($qq->list)) { $answer .= ' '; foreach($qq->list as $ll) { $answer .= trim($ll, ' .') . ', '; } $answer = trim($answer, ' ,'); } } $rec = array("q" => $qq->question, "a" => $answer, "l" => $qq->link); if(!isset($results[$qq->question])) { $results[$qq->question] = $rec; } if(count($results) >= $headings) { break; } } if(count($results) > 0 && count($results) < $headings) { $ok = true; while($ok && count($results) < $headings) { $last_elem = end($results); $serpapi = 'https://serpapi.com/search.json?q=' . urlencode($last_elem['q']) . '&api_key=' . trim($aimogen_Main_Settings['serpapi_auth']); $html_data = aimogen_get_web_page($serpapi); if ($html_data !== FALSE) { $json = json_decode($html_data); if ($json !== null) { if(isset($json->related_questions[0]->question)) { $count_before = count($results); foreach($json->related_questions as $qq) { $answer = ''; if(isset($qq->snippet)) { $answer = $qq->snippet; } elseif(isset($qq->title)) { $answer = $qq->title; if(isset($qq->list)) { $answer .= ' '; foreach($qq->list as $ll) { $answer .= trim($ll, ' .') . ', '; } $answer = trim($answer, ' ,'); } } $rec = array("q" => $qq->question, "a" => $answer, "l" => $qq->link); if(!isset($results[$qq->question])) { $results[$qq->question] = $rec; } if(count($results) >= $headings) { break; } } $count_after = count($results); if($count_after == $count_before) { $ok = false; } } else { $ok = false; } } else { $ok = false; } } else { $ok = false; } } } } } } } } if (!empty($aimogen_Main_Settings['bing_auth_internet'])) { if (count($results) < $headings) { $kkey = trim($aimogen_Main_Settings['bing_auth_internet']); $queryUrl = "https://api.bing.microsoft.com/v7.0/search?q=" . urlencode($query); $args = [ 'method' => 'GET', 'headers' => [ 'Ocp-Apim-Subscription-Key' => $kkey ], 'timeout' => 120, 'sslverify' => false ]; $response = wp_remote_get($queryUrl, $args); if (!is_wp_error($response)) { $html_data = wp_remote_retrieve_body($response); $json = json_decode($html_data); if ($json !== null && isset($json->relatedSearches->value)) { foreach ($json->relatedSearches->value as $jsx) { if (isset($jsx->text)) { if (!isset($results[$jsx->text])) { $results[$jsx->text] = ''; } if (count($results) >= $headings) { break; } } } } } } } if (isset($aimogen_Main_Settings['serper_auth']) && trim($aimogen_Main_Settings['serper_auth']) != '') { if (count($results) < $headings) { $body = wp_json_encode([ 'q' => str_replace('"', "'", $query) ]); $args = [ 'method' => 'POST', 'headers' => [ 'X-API-KEY' => trim($aimogen_Main_Settings['serper_auth']), 'Content-Type' => 'application/json' ], 'body' => $body, 'timeout' => 120, 'sslverify' => false ]; $response = wp_remote_post('https://google.serper.dev/search', $args); if (!is_wp_error($response)) { $html_data = wp_remote_retrieve_body($response); $json = json_decode($html_data); if ($json !== null) { if (isset($json->peopleAlsoAsk)) { foreach ($json->peopleAlsoAsk as $jsx) { if (isset($jsx->question)) { if (!isset($results[$jsx->question])) { $results[$jsx->question] = $jsx->snippet; } if (count($results) >= $headings) { break; } } } } if (count($results) < $headings && isset($json->relatedSearches)) { foreach ($json->relatedSearches as $jsx) { if (isset($jsx->query)) { if (!isset($results[$jsx->query])) { $results[$jsx->query] = ''; } if (count($results) >= $headings) { break; } } } } } } } } if ((!isset($aimogen_Main_Settings['ai_off']) || trim($aimogen_Main_Settings['ai_off']) != 'on') && $model !== '' && $headings_ai_command !== '') { if(count($results) < $headings) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (!isset($aimogen_Main_Settings['app_id']) || trim($aimogen_Main_Settings['app_id']) == '') { return $results; } $appids = preg_split('/\r\n|\r|\n/', trim($aimogen_Main_Settings['app_id'])); $appids = array_filter($appids); $token = $appids[array_rand($appids)]; $token = apply_filters('aimogen_openai_api_key', $token); if(empty($headings_ai_command)) { $headings_ai_command = 'Write ' . ($headings - count($results)) . ' PAA related questions, each on a new line, for the title: "' . $query . '"'; } else { $headings_ai_command = str_replace('%%needed_heading_count%%', $headings - count($results), $headings_ai_command); $headings_ai_command = str_replace('%%post_title%%', $query, $headings_ai_command); } $query_token_count = count(aimogen_encode($headings_ai_command)); $available_tokens = aimogen_compute_available_tokens($model, $max_tokens, $headings_ai_command, $query_token_count); if($available_tokens <= AIMOGEN_MINIMUM_TOKENS_FOR_COMPLETIONS) { $string_len = aimogen_strlen($headings_ai_command); $string_len = $string_len / 2; $string_len = intval(0 - $string_len); $headings_ai_command = aimogen_substr($headings_ai_command, 0, $string_len); $headings_ai_command = trim($headings_ai_command); $query_token_count = count(aimogen_encode($headings_ai_command)); $available_tokens = $max_tokens - $query_token_count; } if (isset($aimogen_Main_Settings['enable_detailed_logging'])) { $api_service = aimogen_get_api_service($token, $model); aimogen_log_to_file('Calling ' . $api_service . ' (' . $headings_assistant_id . '\\' . $model . ')(' . $available_tokens . ') for headings generator: ' . $headings_ai_command); } $thread_id = ''; $aierror = ''; $finish_reason = ''; $generated_text = aimogen_generate_text($token, $model, $headings_ai_command, $available_tokens, $temperature, $top_p, $presence_penalty, $frequency_penalty, false, 'shortcodeHeadingsArticle', 0, $finish_reason, $aierror, false, false, false, '', '', 'user', $headings_assistant_id, $thread_id, '', 'disabled', '', false, false, array(), ''); if($generated_text === false) { aimogen_log_to_file('Title generator error: ' . $aierror); return $results; } else { $generated_text = ucfirst(trim(trim(trim(trim($generated_text), '.'), ' "\''))); $generated_text_arr = preg_split('/\r\n|\r|\n/', $generated_text); $generated_text_arr = array_filter($generated_text_arr); foreach($generated_text_arr as $gen_head) { $rec = array("q" => $gen_head, "a" => '', "l" => ''); if(!isset($results[$gen_head])) { $results[$gen_head] = $rec; } if(count($results) >= $headings) { break; } } } } } return $results; } function aimogen_check_if_available_token_recalc_needed($model, $aimogen_Main_Settings) { if(aimogen_check_if_azure($aimogen_Main_Settings)) { return true; } if(!aimogen_is_o1_model($model) && !aimogen_is_chatgpt_o_model($model) && !aimogen_is_chatgpt_turbo_model($model) && !aimogen_is_chatgpt35_16k_context_model($model) && !aimogen_is_claude_model($model) && !aimogen_is_openrouter_model($model) && !aimogen_is_huggingface_model($model) && !aimogen_is_ollama_model($model) && !aimogen_is_perplexity_model($model) && !aimogen_is_groq_model($model) && !aimogen_is_nvidia_model($model) && !aimogen_is_xai_model($model) && !aimogen_is_custom_model($model, $aimogen_Main_Settings)) { return true; } return false; } function aimogen_is_aimogen_key($token) { if(empty($token)) { return false; } $token_prepro = explode('_', $token); if(isset($token_prepro[1]) && aimogen_strlen($token_prepro[1]) > 10 && (is_numeric($token_prepro[0]) || $token_prepro[0] === 'appsu')) { return true; } return false; } function aimogen_is_trained_model($model) { if(stristr($model, ':ft-') !== false || aimogen_starts_with($model, 'ft:') !== false) { return true; } return false; } function aimogen_get_internet_embeddings_result($aimogen_Main_Settings, $env, &$embeddings_enabled, &$internet_enabled, &$embeddings_namespace) { if(stristr($env, 'singlePostWriter') !== false) { if(isset($aimogen_Main_Settings['embeddings_single']) && $aimogen_Main_Settings['embeddings_single'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_single_namespace']) && $aimogen_Main_Settings['embeddings_single_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_single_namespace']; } } if(isset($aimogen_Main_Settings['internet_single']) && $aimogen_Main_Settings['internet_single'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'shortcodeHeadingsArticle') !== false) { if(isset($aimogen_Main_Settings['embeddings_related']) && $aimogen_Main_Settings['embeddings_related'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_related_namespace']) && $aimogen_Main_Settings['embeddings_related_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_related_namespace']; } } if(isset($aimogen_Main_Settings['internet_related']) && $aimogen_Main_Settings['internet_related'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'formsText') !== false) { if(isset($aimogen_Main_Settings['embeddings_forms']) && $aimogen_Main_Settings['embeddings_forms'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_forms_namespace']) && $aimogen_Main_Settings['embeddings_forms_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_forms_namespace']; } } if(isset($aimogen_Main_Settings['internet_forms']) && $aimogen_Main_Settings['internet_forms'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'omniBlocks') !== false) { if(isset($aimogen_Main_Settings['embeddings_omni']) && $aimogen_Main_Settings['embeddings_omni'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_omni_namespace']) && $aimogen_Main_Settings['embeddings_omni_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_omni_namespace']; } } if(isset($aimogen_Main_Settings['internet_omni']) && $aimogen_Main_Settings['internet_omni'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'aiAssistantWriter') !== false) { if(isset($aimogen_Main_Settings['embeddings_assistant']) && $aimogen_Main_Settings['embeddings_assistant'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_assistant_namespace']) && $aimogen_Main_Settings['embeddings_assistant_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_assistant_namespace']; } } if(isset($aimogen_Main_Settings['internet_assistant']) && $aimogen_Main_Settings['internet_assistant'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'shortcodeContentArticle') !== false || stristr($env, 'shortcodeHeadingArticle') !== false || stristr($env, 'shortcodeKeywordArticle') !== false || stristr($env, 'shortcodeCompletion') !== false) { if(isset($aimogen_Main_Settings['embeddings_article_short']) && $aimogen_Main_Settings['embeddings_article_short'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_article_short_namespace']) && $aimogen_Main_Settings['embeddings_article_short_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_article_short_namespace']; } } if(isset($aimogen_Main_Settings['internet_article_short']) && $aimogen_Main_Settings['internet_article_short'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'shortcodeChat') !== false) { if(isset($aimogen_Main_Settings['embeddings_chat_short']) && $aimogen_Main_Settings['embeddings_chat_short'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_chat_short_namespace']) && $aimogen_Main_Settings['embeddings_chat_short_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_chat_short_namespace']; } } if(isset($aimogen_Main_Settings['internet_chat_short']) && $aimogen_Main_Settings['internet_chat_short'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'shortcodeCEditor') !== false) { if(isset($aimogen_Main_Settings['embeddings_edit_short']) && $aimogen_Main_Settings['embeddings_edit_short'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_edit_short_namespace']) && $aimogen_Main_Settings['embeddings_edit_short_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_edit_short_namespace']; } } if(isset($aimogen_Main_Settings['internet_edit_short']) && $aimogen_Main_Settings['internet_edit_short'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'keywordCompletion') !== false || stristr($env, 'titleCEditor') !== false || stristr($env, 'contentCEditor') !== false || stristr($env, 'contentCompletion') !== false || stristr($env, 'headingCompletion') !== false || stristr($env, 'excerptCEditor') !== false || stristr($env, 'slugCEditor') !== false) { if(isset($aimogen_Main_Settings['embeddings_edit']) && $aimogen_Main_Settings['embeddings_edit'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_edit_namespace']) && $aimogen_Main_Settings['embeddings_edit_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_edit_namespace']; } } if(isset($aimogen_Main_Settings['internet_edit']) && $aimogen_Main_Settings['internet_edit'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'tagID') !== false || stristr($env, 'categoryID') !== false || stristr($env, 'keywordID') !== false || stristr($env, 'titleID') !== false || stristr($env, 'contentID') !== false || stristr($env, 'headingID') !== false || stristr($env, 'topicContentWriter') !== false) { if(isset($aimogen_Main_Settings['embeddings_bulk']) && $aimogen_Main_Settings['embeddings_bulk'] == 'on') { if(stristr($env, 'titleID') !== false || stristr($env, 'topicContentWritertitle') !== false) { if(isset($aimogen_Main_Settings['embeddings_bulk_title']) && $aimogen_Main_Settings['embeddings_bulk_title'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_bulk_title_namespace']) && $aimogen_Main_Settings['embeddings_bulk_title_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_bulk_title_namespace']; } } } elseif(stristr($env, 'contentID') !== false || stristr($env, 'topicContentWritercontent') !== false) { if(isset($aimogen_Main_Settings['embeddings_bulk_content']) && $aimogen_Main_Settings['embeddings_bulk_content'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_bulk_content_namespace']) && $aimogen_Main_Settings['embeddings_bulk_content_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_bulk_content_namespace']; } } } elseif(stristr($env, 'headingID') !== false || stristr($env, 'topicContentWritersections') !== false) { if(isset($aimogen_Main_Settings['embeddings_bulk_sections']) && $aimogen_Main_Settings['embeddings_bulk_sections'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_bulk_sections_namespace']) && $aimogen_Main_Settings['embeddings_bulk_sections_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_bulk_sections_namespace']; } } } elseif(stristr($env, 'topicContentWriterintro') !== false) { if(isset($aimogen_Main_Settings['embeddings_bulk_intro']) && $aimogen_Main_Settings['embeddings_bulk_intro'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_bulk_intro_namespace']) && $aimogen_Main_Settings['embeddings_bulk_intro_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_bulk_intro_namespace']; } } } elseif(stristr($env, 'topicContentWriterqa') !== false) { if(isset($aimogen_Main_Settings['embeddings_bulk_qa']) && $aimogen_Main_Settings['embeddings_bulk_qa'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_bulk_qa_namespace']) && $aimogen_Main_Settings['embeddings_bulk_qa_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_bulk_qa_namespace']; } } } elseif(stristr($env, 'topicContentWriteroutro') !== false) { if(isset($aimogen_Main_Settings['embeddings_bulk_outro']) && $aimogen_Main_Settings['embeddings_bulk_outro'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_bulk_outro_namespace']) && $aimogen_Main_Settings['embeddings_bulk_outro_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_bulk_outro_namespace']; } } } elseif(stristr($env, 'topicContentWriterexcerpt') !== false) { if(isset($aimogen_Main_Settings['embeddings_bulk_excerpt']) && $aimogen_Main_Settings['embeddings_bulk_excerpt'] == 'on') { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_bulk_excerpt_namespace']) && $aimogen_Main_Settings['embeddings_bulk_excerpt_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_bulk_excerpt_namespace']; } } } else { $embeddings_enabled = true; if(isset($aimogen_Main_Settings['embeddings_bulk_content_namespace']) && $aimogen_Main_Settings['embeddings_bulk_content_namespace'] != '') { $embeddings_namespace = $aimogen_Main_Settings['embeddings_bulk_content_namespace']; } } } if(isset($aimogen_Main_Settings['internet_bulk']) && $aimogen_Main_Settings['internet_bulk'] == 'on') { if(stristr($env, 'titleID') !== false || stristr($env, 'topicContentWritertitle') !== false) { if(isset($aimogen_Main_Settings['internet_bulk_title']) && $aimogen_Main_Settings['internet_bulk_title'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'contentID') !== false || stristr($env, 'topicContentWritercontent') !== false) { if(isset($aimogen_Main_Settings['internet_bulk_content']) && $aimogen_Main_Settings['internet_bulk_content'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'headingID') !== false || stristr($env, 'topicContentWritersections') !== false) { if(isset($aimogen_Main_Settings['internet_bulk_sections']) && $aimogen_Main_Settings['internet_bulk_sections'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'topicContentWriterintro') !== false) { if(isset($aimogen_Main_Settings['internet_bulk_intro']) && $aimogen_Main_Settings['internet_bulk_intro'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'topicContentWriterqa') !== false) { if(isset($aimogen_Main_Settings['internet_bulk_qa']) && $aimogen_Main_Settings['internet_bulk_qa'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'topicContentWriteroutro') !== false) { if(isset($aimogen_Main_Settings['internet_bulk_outro']) && $aimogen_Main_Settings['internet_bulk_outro'] == 'on') { $internet_enabled = true; } } elseif(stristr($env, 'topicContentWriterexcerpt') !== false) { if(isset($aimogen_Main_Settings['internet_bulk_excerpt']) && $aimogen_Main_Settings['internet_bulk_excerpt'] == 'on') { $internet_enabled = true; } } else { $internet_enabled = true; } } } if(strstr($embeddings_namespace, '%%') !== false) { $current_user = wp_get_current_user(); if ( !($current_user instanceof WP_User) || !is_user_logged_in()) { $embeddings_namespace = str_replace('%%user_name%%', '', $embeddings_namespace); $embeddings_namespace = str_replace('%%user_email%%', '' , $embeddings_namespace); $embeddings_namespace = str_replace('%%user_display_name%%', '', $embeddings_namespace); $embeddings_namespace = str_replace('%%user_role%%', '', $embeddings_namespace); $embeddings_namespace = str_replace('%%user_id%%', '' , $embeddings_namespace); $embeddings_namespace = str_replace('%%user_firstname%%', '' , $embeddings_namespace); $embeddings_namespace = str_replace('%%user_lastname%%', '' , $embeddings_namespace); $embeddings_namespace = str_replace('%%user_description%%', '' , $embeddings_namespace); $embeddings_namespace = str_replace('%%user_url%%', '' , $embeddings_namespace); } else { $embeddings_namespace = str_replace('%%user_name%%', $current_user->user_login, $embeddings_namespace); $embeddings_namespace = str_replace('%%user_email%%', $current_user->user_email , $embeddings_namespace); $embeddings_namespace = str_replace('%%user_display_name%%', $current_user->display_name, $embeddings_namespace); $embeddings_namespace = str_replace('%%user_role%%', implode(',', $current_user->roles), $embeddings_namespace); $embeddings_namespace = str_replace('%%user_id%%', $current_user->ID , $embeddings_namespace); $embeddings_namespace = str_replace('%%user_firstname%%', $current_user->user_firstname , $embeddings_namespace); $embeddings_namespace = str_replace('%%user_lastname%%', $current_user->user_lastname , $embeddings_namespace); $user_desc = get_the_author_meta( 'description', $current_user->ID ); $embeddings_namespace = str_replace('%%user_description%%', $user_desc , $embeddings_namespace); $user_url = get_the_author_meta( 'user_url', $current_user->ID ); $embeddings_namespace = str_replace('%%user_url%%', $user_url , $embeddings_namespace); } } } function aimogen_add_proxy($curl) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (isset($aimogen_Main_Settings['proxy_ai']) && $aimogen_Main_Settings['proxy_ai'] == 'on' && isset($aimogen_Main_Settings['proxy_url']) && $aimogen_Main_Settings['proxy_url'] != '' && $aimogen_Main_Settings['proxy_url'] != 'disable' && $aimogen_Main_Settings['proxy_url'] != 'disabled') { $prx = explode(',', $aimogen_Main_Settings['proxy_url']); $randomness = array_rand($prx); curl_setopt($curl, CURLOPT_PROXY , trim($prx[$randomness]));// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt if (isset($aimogen_Main_Settings['proxy_auth']) && $aimogen_Main_Settings['proxy_auth'] != '') { $prx_auth = explode(',', $aimogen_Main_Settings['proxy_auth']); if(isset($prx_auth[$randomness]) && trim($prx_auth[$randomness]) != '') { curl_setopt($curl, CURLOPT_PROXYUSERPWD , trim($prx_auth[$randomness]));// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt } } } } function aimogen_check_if_azure($aimogen_Main_Settings) { if(isset($aimogen_Main_Settings['api_selector']) && trim($aimogen_Main_Settings['api_selector']) == 'azure') { return true; } return false; } function aimogen_check_if_stable($model) { if(in_array($model, AIMOGEN_STABLE_IMAGE_MODELS)) { return true; } return false; } function aimogen_check_if_midjourney($model) { if($model == 'fast' || $model == 'mixed' || $model == 'turbo') { return true; } return false; } function aimogen_check_if_replicate($model) { if(aimogen_strlen($model) == 64) { return true; } return false; } function aimogen_check_if_ideogram($model) { if(in_array($model, AIMOGEN_IDEOGRAM_MODELS) !== false) { return true; } return false; } function aimogen_check_if_others($model = '') { if (!empty($model)) { if(aimogen_is_claude_model($model) || aimogen_is_google_model($model) || aimogen_is_perplexity_model($model) || aimogen_is_groq_model($model) || aimogen_is_nvidia_model($model) || aimogen_is_xai_model($model)) { return true; } } return false; } function aimogen_check_if_azure_or_others($aimogen_Main_Settings, $model = '') { if(isset($aimogen_Main_Settings['api_selector']) && (trim($aimogen_Main_Settings['api_selector']) == 'azure' || trim($aimogen_Main_Settings['api_selector']) == 'custom')) { return true; } if (!empty($model)) { if(aimogen_is_claude_model($model) || aimogen_is_google_model($model) || aimogen_is_perplexity_model($model) || aimogen_is_groq_model($model) || aimogen_is_nvidia_model($model) || aimogen_is_xai_model($model)) { return true; } } return false; } function aimogen_is_request_allowed() { return true; } add_filter( 'aimogen_is_ai_query_allowed', 'aimogen_is_request_allowed' ); add_filter( 'aimogen_is_ai_edit_allowed', 'aimogen_is_request_allowed' ); add_filter( 'aimogen_is_ai_image_allowed', 'aimogen_is_request_allowed' ); add_filter( 'aimogen_is_ai_video_allowed', 'aimogen_is_request_allowed' ); function aimogen_parse_markdown($text) { $text = str_replace(["\r\n", "\r"], "\n", $text); $escapes = []; $text = preg_replace_callback('/\\\\([\\[\\](){}`*_#+.!|>-])/', function($m) use (&$escapes){ $i = count($escapes); $escapes[$i] = $m[1]; return "??ESC{$i}??"; }, $text); $fenced = []; $text = preg_replace_callback('/^(```|~~~)([^\n]*)\n([\s\S]*?)\n\1\s*$/m', function($m) use (&$fenced){ $code = htmlspecialchars($m[3], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); $i = count($fenced); $fenced[$i] = "
{$code}
"; return "??FENCED{$i}??"; }, $text ); $inline = []; $text = preg_replace_callback('/`([^`\n]+)`/', function($m) use (&$inline){ $code = htmlspecialchars($m[1], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); $i = count($inline); $inline[$i] = "{$code}"; return "??INLINE{$i}??"; }, $text ); $text = preg_replace_callback( '/^\s{0,3}(#{1,6})\s+(.+?)(?:\s+#+\s*)?$/m', function($m){ $level = aimogen_strlen($m[1]); return "{$m[2]}"; }, $text ); $text = preg_replace('/^\s*(.+)\n=+\s*$/m', '

$1

', $text); $text = preg_replace('/^\s*(.+)\n-+\s*$/m', '

$1

', $text); $text = preg_replace('/^\s{0,3}([*_ -]\s*){3,}$/m', '
', $text); $text = preg_replace_callback('/^(?:\s{0,3}>\s?.*(?:\n|$))+?/m', function($m){ $b = rtrim($m[0]); $b = preg_replace('/^\s{0,3}>\s?/m', '', $b); return '
' . $b . '
' . "\n"; }, $text); $text = preg_replace_callback('/(?:^\s*\|.*\|\s*$\R?)+/m', function ($m) { $block = trim($m[0]); $lines = preg_split('/\R/', $block); $rows = []; foreach ($lines as $line) { $line = trim($line); if ($line === '') continue; $line = trim($line, '| '); $cells = array_map('trim', explode('|', $line)); $rows[] = $cells; } if (count($rows) < 1) return $m[0]; $thead = ''; $startBody = 0; if (count($rows) >= 2) { $isSep = true; foreach ($rows[1] as $cell) { if (!preg_match('/^:?-{3,}:?$/', $cell)) { $isSep = false; break; } } if ($isSep) { $ths = array_map(fn($c)=>"{$c}", $rows[0]); $thead = '' . implode('', $ths) . ''; $startBody = 2; } } $tbody = ''; for ($i = $startBody; $i < count($rows); $i++) { $tds = array_map(fn($c)=>"{$c}", $rows[$i]); $tbody .= '' . implode('', $tds) . ''; } $tbody .= ''; return '' . $thead . $tbody . '
'; }, $text); $lines = explode("\n", $text); $inUL = false; $inOL = false; $buf = ''; foreach ($lines as $line) { if (preg_match('/^\s*-\s+(.+?)$/', $line)) { if (!$inUL) { $inUL = true; $buf .= "
    \n"; } $buf .= '
  • ' . preg_replace('/^\s*-\s+(.+?)$/', '$1', $line) . "
  • \n"; } elseif (preg_match('/^\s*(\d+)\.\s+(.+?)$/', $line, $m)) { if (!$inOL) { $inOL = true; $start = (int)$m[1]; $buf .= ($start > 1) ? "
      \n" : "
        \n"; } $buf .= '
      1. ' . $m[2] . "
      2. \n"; } else { if ($inUL) { $inUL = false; $buf .= "
\n"; } if ($inOL) { $inOL = false; $buf .= "\n"; } $buf .= $line . "\n"; } } if ($inUL) { $buf .= "\n"; } if ($inOL) { $buf .= "\n"; } $text = $buf; $text = preg_replace('/\*\*(.+?)\*\*/s', '$1', $text); $text = preg_replace('/__(.+?)__/s', '$1', $text); $text = preg_replace('/(?$1', $text); $text = preg_replace('/(?$1', $text); $text = preg_replace('/~~(.+?)~~/s', '$1', $text); $text = preg_replace('/<((https?:\/\/|mailto:)[^>\s]+)>/i', '$1', $text); $text = preg_replace('/\[(.+?)\]\(\s*(<)?([^\s)]+)(?(2)>)\s*(?:"([^"]*)")?\s*\)/', '$1', $text); $text = preg_replace_callback('/(]*?)>([^<]+)<\/a>/', function($m){ $tag = $m[0]; return $tag; }, $text); $text = preg_replace_callback('/!\[(.*?)\]\(\s*(<)?([^\s)]+)(?(2)>)\s*(?:"([^"]*)")?\s*\)/', function($m){ $alt = $m[1]; $src = $m[3]; $title = isset($m[4]) && $m[4] !== '' ? ' title="'.htmlspecialchars($m[4], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8').'"' : ''; return ''.$alt.''; }, $text); $text = preg_replace('/
  • \s*\[\s\]\s*/', '
  • ', $text); $text = preg_replace('/
  • \s*\[x\]\s*/i', '
  • ', $text); $blocks = preg_split("/\n{2,}/", trim($text)); foreach ($blocks as &$b) { if (preg_match('/^\s*<(h\d|ul|ol|pre|blockquote|table|hr|img|p|div|section|article)\b/i', $b)) { continue; } $b = '

    ' . preg_replace("/\n/", "
    \n", $b) . '

    '; } $text = implode("\n\n", $blocks) . "\n"; $text = preg_replace_callback('/??INLINE(\d+)??/', fn($m)=>$inline[(int)$m[1]] ?? '', $text); $text = preg_replace_callback('/??FENCED(\d+)??/', fn($m)=>$fenced[(int)$m[1]] ?? '', $text); $text = preg_replace_callback('/??ESC(\d+)??/', fn($m)=>'\\' . ($escapes[(int)$m[1]] ?? ''), $text); return $text; } function aimogen_find_local_assistant_id($assistant_id) { $return_id = false; $args = array( 'post_type' => 'aimogen_assistants', 'posts_per_page' => 1, 'meta_query' => array( array( 'key' => '_assistant_id', 'value' => $assistant_id, 'compare' => '=', ) ) ); $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $return_id = get_the_ID(); } } wp_reset_postdata(); return $return_id; } function aimogen_get_models_xai() { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); $appids_xai = preg_split('/\r\n|\r|\n/', trim($aimogen_Main_Settings['app_id_xai'])); $appids_xai = array_filter($appids_xai); $token = $appids_xai[array_rand($appids_xai)]; add_action('http_api_curl', 'aimogen_add_proxy'); $api_call = wp_remote_post( 'https://api.x.ai/v1/models', array( 'headers' => array( 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $token, ), 'method' => 'GET', 'data_format' => 'body', 'timeout' => AIMOGEN_DEFAULT_BIG_TIMEOUT, ) ); remove_action('http_api_curl', 'aimogen_add_proxy'); $result = json_decode( $api_call['body'] ); return $result; } function aimogen_get_embedding_models_xai() { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); $appids_xai = preg_split('/\r\n|\r|\n/', trim($aimogen_Main_Settings['app_id_xai'])); $appids_xai = array_filter($appids_xai); $token = $appids_xai[array_rand($appids_xai)]; add_action('http_api_curl', 'aimogen_add_proxy'); $api_call = wp_remote_post( 'https://api.x.ai/v1/embedding-models', array( 'headers' => array( 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $token, ), 'method' => 'GET', 'data_format' => 'body', 'timeout' => AIMOGEN_DEFAULT_BIG_TIMEOUT, ) ); remove_action('http_api_curl', 'aimogen_add_proxy'); $result = json_decode( $api_call['body'] ); return $result; } function aimogen_convertIntToStrings($array) { if(!is_array($array)) { return $array; } foreach ($array as &$value) { if (is_int($value)) { $value = (string) $value; } elseif (is_array($value)) { $value = aimogen_convertIntToStrings($value); } } unset($value); return $array; } function aimogen_get_default_model_name($aimogen_Main_Settings) { $model = AIMOGEN_DEFAULT_MODEL; if (isset($aimogen_Main_Settings['default_ai_model']) && $aimogen_Main_Settings['default_ai_model'] != '') { $model = $aimogen_Main_Settings['default_ai_model']; } return $model; } function aimogen_filterCurlForStream($handle) { //cURL is needed for STREAMING curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt curl_setopt($handle, CURLOPT_WRITEFUNCTION, function ($curl_info, $data)// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt { $my_copy_data = trim($data); $prefix = 'data: '; if (aimogen_substr($my_copy_data, 0, aimogen_strlen($prefix)) == $prefix) { $my_copy_data = aimogen_substr($my_copy_data, aimogen_strlen($prefix)); } $suffix = 'data: [DONE]'; $needle_length = aimogen_strlen($suffix); if (aimogen_substr($my_copy_data, -$needle_length) === $suffix) { $my_copy_data = aimogen_substr($my_copy_data, 0, -$needle_length); } $my_copy_data = trim($my_copy_data); $response = json_decode($my_copy_data, true); if (isset($response['error']) && !empty($response['error'])) { $message = isset($response['error']['message']) && !empty($response['error']['message']) ? $response['error']['message'] : ''; if (empty($message) && isset($response['error']['code']) && $response['error']['code'] == 'invalid_api_key') { $message = "Incorrect API key provided. You can find your API key at https://platform.openai.com/account/api-keys."; } echo "event: message\n"; echo 'data: {"error":[{"message":"' . esc_js($message) . '"}]}'; echo "\n\n"; $l1 = ob_get_length(); if($l1 === false) { $l1 = 0; } if (ob_get_length()) { ob_end_flush(); } flush(); echo 'data: {"choices":[{"finish_reason":"stop"}]}'; echo "\n\n"; $l2 = ob_get_length(); if($l2 === false) { $l2 = 0; } if (ob_get_length()) { ob_end_flush(); } flush(); return $l1 + $l2; } else { // needed to not escape because of streaming // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped // added wp_strip_all_tags now! echo esc_html(wp_strip_all_tags( $data )); if (ob_get_length()) { ob_flush(); } flush(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped return aimogen_strlen($data); } }); } function aimogen_get_models($token, $retry_count, &$error) { $delay = ''; $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (aimogen_check_if_azure_or_others($aimogen_Main_Settings)) { $error = 'Only OpenAI/AimogenAPI APIs are currently supported for model listing.'; return false; } if (isset($aimogen_Main_Settings['request_delay']) && $aimogen_Main_Settings['request_delay'] != '') { if(stristr($aimogen_Main_Settings['request_delay'], ',') !== false) { $tempo = explode(',', $aimogen_Main_Settings['request_delay']); if(isset($tempo[1]) && is_numeric(trim($tempo[1])) && is_numeric(trim($tempo[0]))) { $delay = wp_rand(trim($tempo[0]), trim($tempo[1])); } } else { if(is_numeric(trim($aimogen_Main_Settings['request_delay']))) { $delay = intval(trim($aimogen_Main_Settings['request_delay'])); } } } if($delay != '' && is_numeric($delay)) { usleep($delay); } if(aimogen_is_aimogen_key($token)) { $pargs = array(); $api_url = 'https://aiomaticapi.com/apis/ai/v1/models/'; $api_headers = array( 'Authorization' => 'Bearer ' . trim($token) ); $ai_response = aimogen_get_web_page_api($api_url, $pargs, $api_headers); if($ai_response === false) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') AimogenAPI model API call after initial failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_get_models($token, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to get AimogenAPI response!'; return false; } } $ai_json = json_decode($ai_response); if($ai_json === null) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') AimogenAPI model API call after decode failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_get_models($token, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to decode AimogenAPI response: ' . $ai_response; return false; } } if(isset($ai_json->error)) { if (stristr($ai_json->error, 'Your subscription expired, please renew it.') === false && stristr($ai_json->error, '[RATE LIMITED]') === false && isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') AimogenAPI model API call after error failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_get_models($token, intval($retry_count) + 1, $error); } else { $error = 'Error while processing AI response: ' . $ai_json->error; return false; } } if(!isset($ai_json->result)) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') AimogenAPI model API call after result failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_get_models($token, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to parse AimogenAPI response: ' . $ai_response; return false; } } if(isset($ai_json->remainingtokens)) { set_transient('aimogenapi_tokens', $ai_json->remainingtokens, 86400); } return $ai_json->result; } else { remove_action('http_api_curl', 'aimogen_add_proxy'); $xh = array( 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $token, ); if (isset($aimogen_Main_Settings['openai_organization']) && $aimogen_Main_Settings['openai_organization'] != '') { $xh['OpenAI-Organization'] = $aimogen_Main_Settings['openai_organization']; } if (isset($aimogen_Main_Settings['api_selector']) && trim($aimogen_Main_Settings['api_selector']) == 'custom' && isset($aimogen_Main_Settings['custom_endpoint']) && trim($aimogen_Main_Settings['custom_endpoint'], ' /') != '') { $api_endpoint = trim($aimogen_Main_Settings['custom_endpoint'], ' /'); } else { $api_endpoint = aimogen_get_openai_api_base_url($aimogen_Main_Settings); } $api_call = wp_remote_get( $api_endpoint . '/v1/models', array( 'headers' => $xh, 'data_format' => 'body', 'timeout' => AIMOGEN_DEFAULT_BIG_TIMEOUT, ) ); remove_action('http_api_curl', 'aimogen_add_proxy'); if(is_wp_error( $api_call )) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') model API call after initial failure: ' . json_encode($api_call)); sleep(pow(2, $retry_count)); return aimogen_get_models($token, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to get initial API response: ' . json_encode($api_call); return false; } } else { $result = json_decode( $api_call['body'] ); if($result === null) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') model API call after decode failure: ' . json_encode($api_call['body'])); sleep(pow(2, $retry_count)); return aimogen_get_models($token, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to decode initial API response: ' . json_encode($api_call); return false; } } if(isset($result->error)) { $result = $result->error; } if(isset($result->type)) { if($result->type == 'insufficient_quota') { $error = 'Error: You exceeded your OpenAI general quota limit. To fix this, if you are using a free OpenAI account, you need to add a VISA card to your account, as OpenAI heavily limits free accounts. Please check details here: https://platform.openai.com/docs/guides/rate-limits'; return false; } elseif($result->type == 'invalid_request_error') { $error = 'Error: Invalid request submitted to the models API! Result: ' . json_encode($result); return false; } else { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') model API call after type failure: ' . json_encode($api_call['body'])); sleep(pow(2, $retry_count)); return aimogen_get_models($token, intval($retry_count) + 1, $error); } else { $error = 'Error: An error occurred when initially calling OpenAI models API: ' . json_encode($result); return false; } } } if(!isset($result->data[0]->id)) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') model API call after model listing failure: ' . json_encode($api_call['body'])); sleep(pow(2, $retry_count)); return aimogen_get_models($token, intval($retry_count) + 1, $error); } else { if(isset($result->code) && $result->code == 'content_filter') { $error = 'Error: The response was filtered by our content management policy.'; return false; } else { $error = 'Error: Choices not found in initial API result: ' . json_encode($result); return false; } } } else { return $result->data; } } } $error = 'Failed to finish API call correctly.'; return false; } function aimogen_edit_text($token, $model, $instruction, $aicontent, $temperature, $top_p, $env, $retry_count, &$error) { $is_allowed = apply_filters('aimogen_is_ai_edit_allowed', true, $instruction, $aicontent); if ( $is_allowed !== true ) { $error = is_string( $is_allowed ) ? $is_allowed : esc_html__('You are not allowed to do this query', 'aimogen'); $error = apply_filters('aimogen_modify_ai_error', $error); return false; } $aicontent = apply_filters('aimogen_modify_ai_edit_content', $instruction, $aicontent); $instruction = apply_filters('aimogen_modify_ai_edit_instruction', $instruction, $aicontent); $aimogen_Limit_Settings = get_option('aimogen_Limit_Settings', false); $stop = null; $session = aimogen_get_session_id(); $mode = 'edit'; $maxResults = 1; $available_tokens = 1000; $query = new Aimogen_lite_Query($aicontent, $available_tokens, $model, $temperature, $stop, $env, $mode, $token, $session, $maxResults, '', ''); $ok = apply_filters( 'aimogen_ai_allowed', true, $aimogen_Limit_Settings ); if ( $ok !== true ) { $error = $ok; $error = apply_filters('aimogen_modify_ai_error', $error); return false; } $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (aimogen_check_if_azure_or_others($aimogen_Main_Settings, $model)) { $error = 'Azure and Claude APIs are not currently supported for edit endpoints.'; $error = apply_filters('aimogen_modify_ai_error', $error); return false; } if(isset($aimogen_Main_Settings['enable_detailed_logging']) && $aimogen_Main_Settings['enable_detailed_logging'] == 'on' && AIMOGEN_IS_DEBUG === true) { aimogen_log_to_file('Generating AI editing using model: ' . $model . ' using instruction: "' . $instruction . '" and text: "' . $aicontent . '"'); } $delay = ''; if (isset($aimogen_Main_Settings['request_delay']) && $aimogen_Main_Settings['request_delay'] != '') { if(stristr($aimogen_Main_Settings['request_delay'], ',') !== false) { $tempo = explode(',', $aimogen_Main_Settings['request_delay']); if(isset($tempo[1]) && is_numeric(trim($tempo[1])) && is_numeric(trim($tempo[0]))) { $delay = wp_rand(trim($tempo[0]), trim($tempo[1])); } } else { if(is_numeric(trim($aimogen_Main_Settings['request_delay']))) { $delay = intval(trim($aimogen_Main_Settings['request_delay'])); } } } if($delay != '' && is_numeric($delay)) { usleep($delay); } if(aimogen_is_aimogen_key($token)) { $pargs = array(); $api_url = 'https://aiomaticapi.com/apis/ai/v1/edit/'; $pargs['temperature'] = $temperature; $pargs['top_p'] = $top_p; $pargs['instruction'] = trim($instruction); $pargs['input'] = trim($aicontent); $pargs['model'] = trim($model); $api_headers = array( 'Authorization' => 'Bearer ' . trim($token) ); $ai_response = aimogen_get_web_page_api($api_url, $pargs, $api_headers); if($ai_response === false) { $error = 'Error: Failed to get AimogenAPI response!'; $error = apply_filters('aimogen_modify_ai_error', $error); return false; } $ai_json = json_decode($ai_response); if($ai_json === null) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after decode edit failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_edit_text($token, $model, $instruction, $aicontent, $temperature, $top_p, $env, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to decode AimogenAPI response: ' . $ai_response; $error = apply_filters('aimogen_modify_ai_error', $error); return false; } } if(isset($ai_json->error)) { if (stristr($ai_json->error, 'Your subscription expired, please renew it.') === false && stristr($ai_json->error, '[RATE LIMITED]') === false && isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after error edit failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_edit_text($token, $model, $instruction, $aicontent, $temperature, $top_p, $env, intval($retry_count) + 1, $error); } else { $error = 'Error while processing AI response: ' . $ai_json->error; $error = apply_filters('aimogen_modify_ai_error', $error); return false; } } if(!isset($ai_json->result)) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after result edit failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_edit_text($token, $model, $instruction, $aicontent, $temperature, $top_p, $env, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to parse AimogenAPI response: ' . $ai_response; $error = apply_filters('aimogen_modify_ai_error', $error); return false; } } if(isset($ai_json->remainingtokens)) { set_transient('aimogenapi_tokens', $ai_json->remainingtokens, 86400); } $ai_json = apply_filters( 'aimogen_edit_reply_raw', $ai_json, $instruction, $aicontent ); apply_filters( 'aimogen_ai_reply', $ai_json->result, $query ); return $ai_json->result; } else { try { $send_json = aimogen_safe_json_encode( [ 'model' => $model, 'input' => $aicontent, 'instruction' => $instruction, 'temperature' => $temperature, 'top_p' => $top_p ] ); } catch(Exception $e) { $error = 'Error: Exception in API payload encoding: ' . $e->getMessage(); $error = apply_filters('aimogen_modify_ai_error', $error); return false; } if($send_json === false) { $error = 'Error: Failed to encode API payload: ' . json_encode($aicontent); $error = apply_filters('aimogen_modify_ai_error', $error); return false; } add_action('http_api_curl', 'aimogen_add_proxy'); $xh = array( 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $token, ); if (isset($aimogen_Main_Settings['openai_organization']) && $aimogen_Main_Settings['openai_organization'] != '') { $xh['OpenAI-Organization'] = $aimogen_Main_Settings['openai_organization']; } if (isset($aimogen_Main_Settings['api_selector']) && trim($aimogen_Main_Settings['api_selector']) == 'custom' && isset($aimogen_Main_Settings['custom_endpoint']) && trim($aimogen_Main_Settings['custom_endpoint'], ' /') != '') { $api_endpoint = trim($aimogen_Main_Settings['custom_endpoint'], ' /'); } else { $api_endpoint = aimogen_get_openai_api_base_url($aimogen_Main_Settings); } $api_call = wp_remote_post( $api_endpoint . '/v1/edits', array( 'headers' => $xh, 'body' => $send_json, 'method' => 'POST', 'data_format' => 'body', 'timeout' => AIMOGEN_DEFAULT_BIG_TIMEOUT, ) ); remove_action('http_api_curl', 'aimogen_add_proxy'); if(is_wp_error( $api_call )) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after initial edit failure: ' . json_encode($api_call)); sleep(pow(2, $retry_count)); return aimogen_edit_text($token, $model, $instruction, $aicontent, $temperature, $top_p, $env, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to get initial API response: ' . json_encode($api_call); $error = apply_filters('aimogen_modify_ai_error', $error); return false; } } else { $result = json_decode( $api_call['body'] ); if($result === null) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after decode edit failure: ' . json_encode($api_call['body'])); sleep(pow(2, $retry_count)); return aimogen_edit_text($token, $model, $instruction, $aicontent, $temperature, $top_p, $env, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to decode initial API response: ' . json_encode($api_call); $error = apply_filters('aimogen_modify_ai_error', $error); return false; } } $is_error = false; $sleep_time = false; if(isset($result->error)) { $result = $result->error; $is_error = true; } if($is_error && isset($result->type)) { if($result->type == 'insufficient_quota') { $error = 'Error: You exceeded your OpenAI edits quota limit. To fix this, if you are using a free OpenAI account, you need to add a VISA card to your account, as OpenAI heavily limits free accounts. Please check details here: https://platform.openai.com/docs/guides/rate-limits'; $error = apply_filters('aimogen_modify_ai_error', $error); return false; } elseif($result->type == 'invalid_request_error') { $error = 'Error: Invalid request submitted to the edits API, result: ' . json_encode($result); $error = apply_filters('aimogen_modify_ai_error', $error); return false; } else { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { if(isset($result->code) && $result->code == 'rate_limit_exceeded') { $errmessage = $result->message; preg_match_all('#Rate limit reached for.*?in organization.*?Please try again in ([\d.]*?)s#i', $errmessage, $htmlrez); if(isset($htmlrez[1][0])) { $sleep_time = ceil(floatval($htmlrez[1][0])); if(isset($aimogen_Main_Settings['enable_detailed_logging']) && $aimogen_Main_Settings['enable_detailed_logging'] == 'on') { aimogen_log_to_file('Rate limit reached for model: ' . $model . ', sleeping for: ' . $sleep_time . ' seconds'); } sleep($sleep_time); } } aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after initial edit failure: ' . json_encode($api_call['body'])); if($sleep_time === false) { sleep(pow(2, $retry_count)); } return aimogen_edit_text($token, $model, $instruction, $aicontent, $temperature, $top_p, $env, intval($retry_count) + 1, $error); } else { $error = 'Error: An error occurred when initially calling OpenAI API: ' . json_encode($result); $error = apply_filters('aimogen_modify_ai_error', $error); return false; } } } if(!isset($result->choices[0]->text)) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after choices edit failure: ' . json_encode($api_call['body'])); sleep(pow(2, $retry_count)); return aimogen_edit_text($token, $model, $instruction, $aicontent, $temperature, $top_p, $env, intval($retry_count) + 1, $error); } else { if(isset($result->code) && $result->code == 'content_filter') { $error = 'Error: The response was filtered by our content management policy.'; $error = apply_filters('aimogen_modify_ai_error', $error); return false; } else { $error = 'Error: Choices not found in initial API result: ' . json_encode($result); $error = apply_filters('aimogen_modify_ai_error', $error); return false; } } } else { $result = apply_filters( 'aimogen_edit_reply_raw', $result, $instruction, $aicontent ); apply_filters( 'aimogen_ai_reply', $result->choices[0]->text, $query ); return $result->choices[0]->text; } } } $error = 'Failed to finish API call correctly.'; $error = apply_filters('aimogen_modify_ai_error', $error); return false; } function aimogen_embeddings_aimogenapi($token, $model, $input, $retry_count, &$error) { if(aimogen_is_aimogen_key($token)) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); $pargs = array(); $api_url = 'https://aiomaticapi.com/apis/ai/v1/embeddings/'; $pargs['input'] = trim($input); $pargs['model'] = trim($model); $api_headers = array( 'Authorization' => 'Bearer ' . trim($token) ); $ai_response = aimogen_get_web_page_api($api_url, $pargs, $api_headers); if($ai_response === false) { $error = 'Error: Failed to get AimogenAPI response!'; return false; } $ai_json = json_decode($ai_response); if($ai_json === null) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after decode embeddings failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_embeddings_aimogenapi($token, $model, $input, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to decode AimogenAPI response: ' . $ai_response; return false; } } if(isset($ai_json->error)) { if (stristr($ai_json->error, 'Your subscription expired, please renew it.') === false && stristr($ai_json->error, '[RATE LIMITED]') === false && isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after error embeddings failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_embeddings_aimogenapi($token, $model, $input, intval($retry_count) + 1, $error); } else { $error = 'Error while processing AI response: ' . $ai_json->error; return false; } } if(!isset($ai_json->result)) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') API call after result embeddings failure: ' . $api_url); sleep(pow(2, $retry_count)); return aimogen_embeddings_aimogenapi($token, $model, $input, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to parse AimogenAPI response: ' . $ai_response; return false; } } if(isset($ai_json->remainingtokens)) { set_transient('aimogenapi_tokens', $ai_json->remainingtokens, 86400); } return $ai_json->result; } $error = 'This function works only for AimogenAPI keys!'; return false; } function aimogen_embeddings_azure($token, $model, $input, $retry_count, &$error) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (aimogen_check_if_azure($aimogen_Main_Settings)) { if (!isset($aimogen_Main_Settings['azure_endpoint']) || trim($aimogen_Main_Settings['azure_endpoint']) == '') { $error = 'You need to enter an Azure Endpoint for this to work!'; return false; } if(in_array($model, AIMOGEN_AZURE_MODELS) === false) { $error = 'This model is not currently supported by Azure API: ' . $model; return false; } if(aimogen_is_trained_model($model)) { $error = 'Fine-tuned models are not supported for Azure API'; return false; } $localAzureDeployments = array(); $depl_arr = aimogen_get_deployments($token); if(is_array($depl_arr)) { foreach($depl_arr as $dar) { if(empty($dar)) { continue; } if(is_string($dar)) { $localAzureDeployments[trim($dar)] = trim($dar); } else { $localAzureDeployments[trim($dar->model)] = trim($dar->id); } } } $azureDeployment = ''; foreach ( $localAzureDeployments as $dmodel => $dname ) { if ( $dmodel === str_replace('.', '', $model) || $dmodel === $model ) { $azureDeployment = $dname; break; } } if ( $azureDeployment == '' ) { $new_dep = aimogen_update_deployments_azure($token); if($new_dep !== false) { $localAzureDeployments = array(); foreach($new_dep as $dar) { if(empty($dar)) { continue; } if(is_string($dar)) { $localAzureDeployments[trim($dar)] = trim($dar); } else { $localAzureDeployments[trim($dar->model)] = trim($dar->id); } } foreach ( $localAzureDeployments as $dmodel => $dname ) { if ( $dmodel === str_replace('.', '', $model) || $dmodel === $model ) { $azureDeployment = $dname; break; } } } if ( $azureDeployment == '' ) { $error = 'No added Azure deployment found for embeddings model: ' . $model . ' - you need to add this model in your Azure Portal as a Deployment'; return false; } } if (isset($aimogen_Main_Settings['azure_api_selector_embeddings']) && $aimogen_Main_Settings['azure_api_selector_embeddings'] != '' && $aimogen_Main_Settings['azure_api_selector_embeddings'] != 'default') { $api_ver = '?api-version=' . $aimogen_Main_Settings['azure_api_selector_embeddings']; } else { $api_ver = AIMOGEN_AZURE_API_VERSION_EMBEDDINGS; } $apiurl = trailingslashit(trim($aimogen_Main_Settings['azure_endpoint'])) . 'openai/deployments/' . $azureDeployment . '/embeddings' . $api_ver; $base_params = [ 'model' => str_replace('.', '', $model), 'input' => $input ]; try { $send_json = aimogen_safe_json_encode($base_params); } catch(Exception $e) { $error = 'Error: Exception in Embeddings Azure API payload encoding: ' . json_encode($e->getMessage()); return false; } if($send_json === false) { $error = 'Error: Failed to encode Embeddings Azure API payload: ' . json_encode($base_params); return false; } add_action('http_api_curl', 'aimogen_add_proxy'); $api_call = wp_remote_post( $apiurl, array( 'headers' => array( 'Content-Type' => 'application/json', 'api-key' => $token ), 'body' => $send_json, 'method' => 'POST', 'data_format' => 'body', 'timeout' => AIMOGEN_DEFAULT_BIG_TIMEOUT, ) ); remove_action('http_api_curl', 'aimogen_add_proxy'); if(is_wp_error( $api_call )) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') Azure embeddings API call after initial failure: ' . json_encode($api_call)); sleep(pow(2, $retry_count)); return aimogen_embeddings_azure($token, $model, $input, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to get initial Embeddings Azure API response: ' . json_encode($api_call); return false; } } else { $result = json_decode( $api_call['body'] ); if($result === null) { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') Embeddings Azure API call after decode failure(4): ' . json_encode($api_call['body'])); sleep(pow(2, $retry_count)); return aimogen_embeddings_azure($token, $model, $input, intval($retry_count) + 1, $error); } else { $error = 'Error: Failed to decode initial Embeddings Azure API response: ' . json_encode($api_call); return false; } } $is_error = false; $sleep_time = false; if(isset($result->error)) { $result = $result->error; $is_error = true; } if($is_error && isset($result->type)) { if($result->type == 'insufficient_quota') { $error = 'Error: You exceeded your Azure OpenAI quota limit for embeddings, please wait a period for the Azure quota to refill (Embeddings Azure initial call).'; return false; } elseif($result->type == 'invalid_request_error') { $error = 'Error: Invalid request submitted to the Embeddings Azure Azure API, result: ' . json_encode($result); return false; } else { if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { if(isset($result->code) && $result->code == 'rate_limit_exceeded') { $errmessage = $result->message; preg_match_all('#Rate limit reached for.*?in organization.*?Please try again in ([\d.]*?)s#i', $errmessage, $htmlrez); if(isset($htmlrez[1][0])) { $sleep_time = ceil(floatval($htmlrez[1][0])); if(isset($aimogen_Main_Settings['enable_detailed_logging']) && $aimogen_Main_Settings['enable_detailed_logging'] == 'on') { aimogen_log_to_file('Rate limit reached for model: ' . $model . ', sleeping for: ' . $sleep_time . ' seconds'); } sleep($sleep_time); } } aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') Embeddings Azure Azure API call after type failure: ' . json_encode($api_call['body'])); if($sleep_time === false) { sleep(pow(2, $retry_count)); } return aimogen_embeddings_azure($token, $model, $input, intval($retry_count) + 1, $error); } else { $error = 'Error: An error occurred when initially calling OpenAI Embeddings Azure API: ' . json_encode($result); return false; } } } if(!isset($result->data)) { delete_option('aimogen_deployments_list'); if (isset($aimogen_Main_Settings['max_retry']) && $aimogen_Main_Settings['max_retry'] != '' && is_numeric($aimogen_Main_Settings['max_retry']) && intval($aimogen_Main_Settings['max_retry']) > $retry_count) { aimogen_log_to_file('Retrying (' . (intval($retry_count) + 1) . ') Embeddings Azure API call after Azure data failure: ' . json_encode($api_call['body'])); sleep(pow(2, $retry_count)); return aimogen_embeddings_azure($token, $model, $input, intval($retry_count) + 1, $error); } else { if(isset($result->code) && $result->code == 'content_filter') { $error = 'Error: The response was filtered by our content management policy.'; return false; } else { $error = 'Error: Choices not found in initial Embeddings Azure API result: ' . prijson_encodent_r($result); return false; } } } else { $zempty = array(); $result->data[0]->usage = (object)$zempty; $result->data[0]->usage->total_tokens = count(aimogen_encode($input)); return $result->data; } } } else { $error = 'This method is available only when Azure API is used in the plugin!'; return false; } $error = 'Unexpected embedding error occured'; return false; } function aimogen_get_deployments($token) { $deployments_option_value = get_option('aimogen_deployments_list', false); if(!empty($deployments_option_value)) { return $deployments_option_value; } $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if(isset($aimogen_Main_Settings['azure_model_deployments']) && is_array($aimogen_Main_Settings['azure_model_deployments'])) { $localAzureDeployments = array(); foreach($aimogen_Main_Settings['azure_model_deployments'] as $modelName => $deploymentName) { $deplObj = new stdClass(); $deplObj->model = $modelName; $deplObj->id = $deploymentName; $localAzureDeployments[] = $deploymentName; } if(count($localAzureDeployments) > 0) { return $localAzureDeployments; } } $error = ''; $deployments = aimogen_list_deployments_azure($token, $error); if(is_array($deployments)) { aimogen_update_option('aimogen_deployments_list', $deployments); return $deployments; } else { aimogen_log_to_file('Failed to list deployments from Azure, error: ' . $error); } return false; } function aimogen_update_deployments_azure($token) { $error = ''; //$deployments = aimogen_list_deployments_azure($token, $error); $deployments = array(); if(is_array($deployments) && !empty($deployments)) { aimogen_update_option('aimogen_deployments_list', $deployments); return $deployments; } else { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if(isset($aimogen_Main_Settings['azure_model_deployments']) && is_array($aimogen_Main_Settings['azure_model_deployments'])) { $localAzureDeployments = array(); foreach($aimogen_Main_Settings['azure_model_deployments'] as $modelName => $deploymentName) { $deplObj = new stdClass(); $deplObj->model = $modelName; $deplObj->id = $deploymentName; $localAzureDeployments[] = $deplObj; } if(count($localAzureDeployments) > 0) { aimogen_update_option('aimogen_deployments_list', $localAzureDeployments); return $localAzureDeployments; } } aimogen_log_to_file('Failed to update deployments from Azure, error: ' . $error); } return false; } function aimogen_list_deployments_azure($token, &$error) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (aimogen_check_if_azure($aimogen_Main_Settings)) { if (!isset($aimogen_Main_Settings['azure_endpoint']) || trim($aimogen_Main_Settings['azure_endpoint']) == '') { $error = 'You need to enter an Azure Endpoint for this to work!'; return false; } $apiurl = trailingslashit(trim($aimogen_Main_Settings['azure_endpoint'])) . 'openai/deployments' . AIMOGEN_AZURE_DEPLOYMENT_API_VERSION; $base_params = []; try { $send_json = aimogen_safe_json_encode($base_params); } catch(Exception $e) { $error = 'Error: Exception in deployment listing API payload encoding: ' . $e->getMessage(); return false; } if($send_json === false) { $error = 'Error: Failed to encode deployment listing API payload: ' . json_encode($base_params); return false; } $api_call = wp_remote_get( $apiurl, array( 'headers' => array( 'Content-Type' => 'application/json', 'api-key' => $token ), 'timeout' => AIMOGEN_DEFAULT_BIG_TIMEOUT, ) ); if(is_wp_error( $api_call )) { $error = 'Error: Failed to get initial deployment listing API response: ' . json_encode($api_call); return false; } else { $result = json_decode( $api_call['body'] ); if($result === null) { $error = 'Error: Failed to decode initial deployment listing API response: ' . json_encode($api_call); return false; } if(isset($result->error)) { $result = $result->error; } if(isset($result->type)) { if($result->type == 'insufficient_quota') { $error = 'Error: You exceeded your Azure OpenAI quota limit for listings, please wait a period for the quota to refill (deployment listing initial call).'; return false; } elseif($result->type == 'invalid_request_error') { $error = 'Error: Invalid request submitted to the deployment listing API, result: ' . json_encode($result); return false; } else { $error = 'Error: An error occurred when initially calling OpenAI deployment listing API: ' . json_encode($result); return false; } } if(!isset($result->data)) { if(isset($result->code) && $result->code == 'content_filter') { $error = 'Error: The response was filtered by our content management policy.'; return false; } else { if(isset($result->code) && $result->code == 'content_filter') { $error = 'Error: The response was filtered by our content management policy.'; return false; } else { $error = 'Error: Choices not found in initial deployment listing API result: ' . json_encode($result); return false; } } } else { return $result->data; } } } else { $error = 'This method is available only when Azure API is used in the plugin!'; return false; } $error = 'Unexpected embedding error occured'; return false; } function aimogen_get_dalle_image_models() { return AIMOGEN_DALLE_IMAGE_MODELS; } function aimogen_get_stable_image_models() { return AIMOGEN_STABLE_IMAGE_MODELS; } function aimogen_copy_video_locally($image_url, $filename, $location = 'local') { $extension = 'mp4'; $image_data = aimogen_get_web_page($image_url); if ($image_data === FALSE || strpos($image_data, 'Access Denied') !== FALSE || strpos($image_data, 'Just a moment...') !== FALSE || strpos($image_data, 'exists($file)) { wp_delete_file($file); } $ret = $wp_filesystem->put_contents($file, $image_data); if ($ret === FALSE) { return false; } $filename = urldecode($filename); $filename = sanitize_file_name($filename); $wp_filetype = wp_check_filetype( $filename . '.' . $extension, null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => $filename . '.' . $extension, 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $file ); if(!function_exists('wp_generate_attachment_metadata')) { require_once(ABSPATH . 'wp-admin/includes/image.php'); require_once(ABSPATH . 'wp-admin/includes/media.php'); } $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); wp_update_attachment_metadata( $attach_id, $attach_data ); return array($ret_path, $file); } else { return false; } } function aimogen_copy_image_locally($image_url, &$attach_id, $copy_locally = '', $del_existing = false, $possible_file_name = '') { $attach_id = ''; $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if(!empty($copy_locally)) { $aimogen_Main_Settings['copy_locally'] = $copy_locally; } if(isset($aimogen_Main_Settings['enable_detailed_logging']) && $aimogen_Main_Settings['enable_detailed_logging'] == 'on') { aimogen_log_to_file('Copying image (' . $aimogen_Main_Settings['copy_locally'] . '): ' . $image_url); } if (isset($aimogen_Main_Settings['copy_locally']) && $aimogen_Main_Settings['copy_locally'] == 'on') { $upload_dir = wp_upload_dir(); global $wp_filesystem; if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base') ){ require_once ABSPATH . 'wp-admin/includes/file.php'; $creds = request_filesystem_credentials( site_url() ); wp_filesystem($creds); } if(aimogen_substr( $image_url, 0, 10 ) === "data:image") { $data = explode(',', $image_url); if(isset($data[1])) { $image_data = base64_decode($data[1]); if($image_data === FALSE) { return false; } } else { return false; } preg_match('{data:image/(.*?);}', $image_url, $ex_matches); if(isset($ex_matches[1])) { $image_url = 'image.' . $ex_matches[1]; } else { $image_url = 'image.jpg'; } } else { $image_data = aimogen_get_web_page($image_url); if ($image_data === FALSE || strpos($image_data, 'Access Denied') !== FALSE || strpos($image_data, 'Just a moment...') !== FALSE || strpos($image_data, '', '-', $filename); $filename = str_replace('*', '-', $filename); $filename = str_replace('/', '-', $filename); $filename = str_replace('$', '-', $filename); $filename = str_replace('\'', '-', $filename); $filename = str_replace('"', '-', $filename); $filename = str_replace(':', '-', $filename); $filename = str_replace('@', '-', $filename); $filename = str_replace('+', '-', $filename); $filename = str_replace('|', '-', $filename); $filename = str_replace('=', '-', $filename); $filename = str_replace('`', '-', $filename); } $file_parts = pathinfo($filename); if(!isset($file_parts['extension'])) { $file_parts['extension'] = ''; } switch($file_parts['extension']) { case "": if(!aimogen_endsWith($filename, '.jpg')) $filename .= '.jpg'; break; case NULL: if(!aimogen_endsWith($filename, '.jpg')) $filename .= '.jpg'; break; } if (wp_mkdir_p($upload_dir['path'])) { $file = $upload_dir['path'] . '/' . $filename; $ret_path = $upload_dir['url'] . '/' . $filename; } else { $file = $upload_dir['basedir'] . '/' . $filename; $ret_path = $upload_dir['baseurl'] . '/' . $filename; } if($wp_filesystem->exists($file)) { if($del_existing) { wp_delete_file($file); } else { if(empty($file_parts['extension'])) { $file_parts['extension'] = 'jpg'; } $unid = uniqid(); $randomStart = wp_rand(0, aimogen_strlen($unid) - 4); $unid = aimogen_substr($unid, $randomStart, 4); $file .= $unid . '.' . $file_parts['extension']; $ret_path .= $unid . '.' . $file_parts['extension']; } } $validate = wp_check_filetype_and_ext($file, $filename); if (empty($validate['type']) || !in_array(strtolower($validate['ext']), ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'tif', 'tiff', 'avif', 'heic', 'heif', 'ico'])) { return false; } $ret = $wp_filesystem->put_contents($file, $image_data); if ($ret === FALSE) { if(isset($aimogen_Main_Settings['enable_detailed_logging']) && $aimogen_Main_Settings['enable_detailed_logging'] == 'on') { aimogen_log_to_file('Failed to save image locally: ' . $image_url . ' - to: ' . $file); } return false; } $filename = urldecode($filename); $filename = sanitize_file_name($filename); $wp_filetype = wp_check_filetype( $filename, null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => $filename, 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $file ); if(!function_exists('wp_generate_attachment_metadata')) { require_once(ABSPATH . 'wp-admin/includes/image.php'); require_once(ABSPATH . 'wp-admin/includes/media.php'); } $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); wp_update_attachment_metadata( $attach_id, $attach_data ); return array($ret_path, $file); } else { return false; } } function aimogen_file_get_contents_advanced($url, $headers = '', $referrer = 'self', $user_agent = false) { $content = false; if (function_exists('curl_init')) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); $headers_array = []; $headers = trim($headers); if (aimogen_strlen($headers)) { foreach (explode(PHP_EOL, $headers) as $h) { if (strpos($h, ':') !== false) { list($k, $v) = explode(':', $h, 2); $headers_array[trim($k)] = trim($v); } } } $args = [ 'method' => 'GET', 'headers' => $headers_array, 'timeout' => 10, 'sslverify' => false, 'redirection' => 10 ]; if (strtolower($referrer) == 'self') { $args['headers']['Referer'] = $url; } elseif (aimogen_strlen($referrer)) { $args['headers']['Referer'] = $referrer; } if ($user_agent) { $args['user-agent'] = $user_agent; } if ( isset($aimogen_Main_Settings['proxy_url']) && $aimogen_Main_Settings['proxy_url'] !== '' && $aimogen_Main_Settings['proxy_url'] !== 'disable' && $aimogen_Main_Settings['proxy_url'] !== 'disabled' ) { $prx = array_map('trim', explode(',', $aimogen_Main_Settings['proxy_url'])); $rnd = array_rand($prx); $args['proxy'] = $prx[$rnd]; if (!empty($aimogen_Main_Settings['proxy_auth'])) { $authList = array_map('trim', explode(',', $aimogen_Main_Settings['proxy_auth'])); if (!empty($authList[$rnd])) { $args['headers']['Proxy-Authorization'] = 'Basic ' . base64_encode($authList[$rnd]); } } } $response = wp_remote_get($url, $args); if (is_wp_error($response)) { $content = false; } else { $code = wp_remote_retrieve_response_code($response); $content = $code == 200 ? wp_remote_retrieve_body($response) : false; } } return $content; } function aimogen_get_random_image_google($keyword, $min_width = 0, $min_height = 0, $chance = '', &$added_img_list = array(), &$full_result_list = array()) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if(isset($aimogen_Main_Settings['image_pool']) && $aimogen_Main_Settings['image_pool'] != '') { $max_res = intval($aimogen_Main_Settings['image_pool']); } else { $max_res = 4; } if($chance != '' && is_numeric($chance)) { $chance = intval($chance); if(wp_rand(0, 99) >= $chance) { return ''; } } if(isset($aimogen_Main_Settings['image_query_translate_en']) && $aimogen_Main_Settings['image_query_translate_en'] == 'on') { $text_trans = aimogen_translate_stability($keyword); if($text_trans != $keyword && !empty($text_trans)) { aimogen_log_to_file('Google Images query translated from: "' . $keyword . '" to: "' . $text_trans . '"'); $keyword = $text_trans; } } $gimageurl = 'https://www.google.com/search?q=' . urlencode($keyword . ' -site:depositphotos.com -site:123rf.com') . '&tbm=isch&tbs=il:cl&sa=X'; $res = aimogen_file_get_contents_advanced($gimageurl, '', 'self', 'Mozilla/5.0 (Windows NT 10.0;WOW64;rv:97.0) Gecko/20000101 Firefox/97.0/3871tuT2p1u-81'); preg_match_all('/\["([\w%-\.\/:\?&=]+\.jpg|\.jpeg|\.gif|\.png|\.bmp|\.wbmp|\.webm|\.xbm)",\d+,\d+\]/i', $res, $matches); $items = $matches[0]; if (count($items)) { foreach($items as $it) { preg_match('#\["(.*?)",(.*?),(.*?)\]#', $it, $xmatches); if (count($xmatches) == 4 && ($min_width > 0 || $min_width <= $xmatches[3]) && ($min_height > 0 || $min_height <= $xmatches[2])) { $full_result_list[] = $xmatches[1]; } } $items = array_slice($items, 0, $max_res, true); if(!isset($aimogen_Main_Settings['random_results_order']) || $aimogen_Main_Settings['random_results_order'] != 'on') { shuffle($items); } foreach ($items as $item) { preg_match('#\["(.*?)",(.*?),(.*?)\]#', $item, $matches); if (count($matches) == 4 && ($min_width > 0 || $min_width <= $matches[3]) && ($min_height > 0 || $min_height <= $matches[2])) { if(!in_array($matches[1], $added_img_list)) { $added_img_list[] = $matches[1]; return $matches[1]; } } } } return ''; } $aimogen_fatal = false; function aimogen_clear_flag_at_shutdown($param, $type) { $error = error_get_last(); if ($error !== null && ($error['type'] === E_ERROR || $error['type'] === E_PARSE || $error['type'] === E_CORE_ERROR || $error['type'] === E_COMPILE_ERROR || $error['type'] === E_USER_ERROR) && $GLOBALS['aimogen_fatal'] === false) { $GLOBALS['aimogen_fatal'] = true; $running = array(); aimogen_update_option('aimogen_running_list', $running); aimogen_log_to_file('[FATAL] Exit error: ' . $error['message'] . ', file: ' . $error['file'] . ', line: ' . $error['line'] . ' - rule ID: ' . $param . '!'); aimogen_clearFromList($param, $type); } else { aimogen_clearFromList($param, $type); } } function aimogen_endsWith($haystack, $needle) { $length = aimogen_strlen($needle); if ($length == 0) { return true; } return (aimogen_substr($haystack, -$length) === $needle); } function aimogen_generate_featured_image($image_url, $post_id) { if(empty($image_url)) { return false; } if(!function_exists('is_plugin_active')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if(!aimogen_url_is_image($image_url)) { aimogen_log_to_file('Provided remote image is not valid: ' . $image_url); return false; } $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (isset($aimogen_Main_Settings['url_image']) && $aimogen_Main_Settings['url_image'] == 'on' && (is_plugin_active('featured-image-from-url/featured-image-from-url.php') || is_plugin_active('fifu-premium/fifu-premium.php'))) { if(function_exists('fifu_dev_set_image')) { fifu_dev_set_image($post_id, $image_url); } else { $value = aimogen_get_formatted_value($image_url, '', $post_id); $attach_id = aimogen_insert_attachment_by($value); update_post_meta($post_id, '_thumbnail_id', $attach_id); update_post_meta($post_id, 'fifu_image_url', $image_url); update_post_meta($attach_id, '_wp_attached_file', ';' . $image_url); $attach = get_post( $attach_id ); if($attach !== null) { $attach->post_author = 77777; wp_update_post( $attach ); } } return true; } $img_local = false; $old_attachment_id = false; $upload_dir = wp_upload_dir(); if (strpos($image_url, $upload_dir['baseurl']) !== false || strpos($image_url, site_url()) !== false) { $old_attachment_id = attachment_url_to_postid($image_url); if ($old_attachment_id) { $img_local = true; } } $response = wp_remote_get( $image_url ); if ( is_wp_error( $response ) ) { return false; } $image_data = wp_remote_retrieve_body( $response ); if ($image_data === FALSE || empty($image_data)) { $image_data = aimogen_get_web_page($image_url); if ($image_data === FALSE || empty($image_data) || strpos($image_data, 'Access Denied') !== FALSE || strpos($image_data, 'Just a moment...') !== FALSE || strpos($image_data, '', '-', $filename); $filename = str_replace('*', '-', $filename); $filename = str_replace('/', '-', $filename); $filename = str_replace('$', '-', $filename); $filename = str_replace('\'', '-', $filename); $filename = str_replace('"', '-', $filename); $filename = str_replace(':', '-', $filename); $filename = str_replace('@', '-', $filename); $filename = str_replace('+', '-', $filename); $filename = str_replace('|', '-', $filename); $filename = str_replace('=', '-', $filename); $filename = str_replace('`', '-', $filename); $filename = stripslashes(preg_replace_callback('#(%[a-zA-Z0-9_]*)#', function($matches){ return wp_rand(0, 9); }, preg_quote($filename))); $file_parts = pathinfo($filename); $post_title = get_the_title($post_id); if($post_title != '') { $post_title = remove_accents( $post_title ); $invalid = array( ' ' => '-', '%20' => '-', '_' => '-', ); $post_title = str_replace( array_keys( $invalid ), array_values( $invalid ), $post_title ); $post_title = preg_replace('/[\x{1F3F4}](?:\x{E0067}\x{E0062}\x{E0077}\x{E006C}\x{E0073}\x{E007F})|[\x{1F3F4}](?:\x{E0067}\x{E0062}\x{E0073}\x{E0063}\x{E0074}\x{E007F})|[\x{1F3F4}](?:\x{E0067}\x{E0062}\x{E0065}\x{E006E}\x{E0067}\x{E007F})|[\x{1F3F4}](?:\x{200D}\x{2620}\x{FE0F})|[\x{1F3F3}](?:\x{FE0F}\x{200D}\x{1F308})|[\x{0023}\x{002A}\x{0030}\x{0031}\x{0032}\x{0033}\x{0034}\x{0035}\x{0036}\x{0037}\x{0038}\x{0039}](?:\x{FE0F}\x{20E3})|[\x{1F415}](?:\x{200D}\x{1F9BA})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F467}\x{200D}\x{1F467})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F467}\x{200D}\x{1F466})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F467})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F466}\x{200D}\x{1F466})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F466})|[\x{1F468}](?:\x{200D}\x{1F468}\x{200D}\x{1F467}\x{200D}\x{1F467})|[\x{1F468}](?:\x{200D}\x{1F468}\x{200D}\x{1F466}\x{200D}\x{1F466})|[\x{1F468}](?:\x{200D}\x{1F468}\x{200D}\x{1F467}\x{200D}\x{1F466})|[\x{1F468}](?:\x{200D}\x{1F468}\x{200D}\x{1F467})|[\x{1F468}](?:\x{200D}\x{1F468}\x{200D}\x{1F466})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F469}\x{200D}\x{1F467}\x{200D}\x{1F467})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F469}\x{200D}\x{1F466}\x{200D}\x{1F466})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F469}\x{200D}\x{1F467}\x{200D}\x{1F466})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F469}\x{200D}\x{1F467})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F469}\x{200D}\x{1F466})|[\x{1F469}](?:\x{200D}\x{2764}\x{FE0F}\x{200D}\x{1F469})|[\x{1F469}\x{1F468}](?:\x{200D}\x{2764}\x{FE0F}\x{200D}\x{1F468})|[\x{1F469}](?:\x{200D}\x{2764}\x{FE0F}\x{200D}\x{1F48B}\x{200D}\x{1F469})|[\x{1F469}\x{1F468}](?:\x{200D}\x{2764}\x{FE0F}\x{200D}\x{1F48B}\x{200D}\x{1F468})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F9BD})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F9BC})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F9AF})|[\x{1F575}\x{1F3CC}\x{26F9}\x{1F3CB}](?:\x{FE0F}\x{200D}\x{2640}\x{FE0F})|[\x{1F575}\x{1F3CC}\x{26F9}\x{1F3CB}](?:\x{FE0F}\x{200D}\x{2642}\x{FE0F})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F692})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F680})|[\x{1F468}\x{1F469}](?:\x{200D}\x{2708}\x{FE0F})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F3A8})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F3A4})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F4BB})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F52C})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F4BC})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F3ED})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F527})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F373})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F33E})|[\x{1F468}\x{1F469}](?:\x{200D}\x{2696}\x{FE0F})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F3EB})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F393})|[\x{1F468}\x{1F469}](?:\x{200D}\x{2695}\x{FE0F})|[\x{1F471}\x{1F64D}\x{1F64E}\x{1F645}\x{1F646}\x{1F481}\x{1F64B}\x{1F9CF}\x{1F647}\x{1F926}\x{1F937}\x{1F46E}\x{1F482}\x{1F477}\x{1F473}\x{1F9B8}\x{1F9B9}\x{1F9D9}\x{1F9DA}\x{1F9DB}\x{1F9DC}\x{1F9DD}\x{1F9DE}\x{1F9DF}\x{1F486}\x{1F487}\x{1F6B6}\x{1F9CD}\x{1F9CE}\x{1F3C3}\x{1F46F}\x{1F9D6}\x{1F9D7}\x{1F3C4}\x{1F6A3}\x{1F3CA}\x{1F6B4}\x{1F6B5}\x{1F938}\x{1F93C}\x{1F93D}\x{1F93E}\x{1F939}\x{1F9D8}](?:\x{200D}\x{2640}\x{FE0F})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F9B2})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F9B3})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F9B1})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F9B0})|[\x{1F471}\x{1F64D}\x{1F64E}\x{1F645}\x{1F646}\x{1F481}\x{1F64B}\x{1F9CF}\x{1F647}\x{1F926}\x{1F937}\x{1F46E}\x{1F482}\x{1F477}\x{1F473}\x{1F9B8}\x{1F9B9}\x{1F9D9}\x{1F9DA}\x{1F9DB}\x{1F9DC}\x{1F9DD}\x{1F9DE}\x{1F9DF}\x{1F486}\x{1F487}\x{1F6B6}\x{1F9CD}\x{1F9CE}\x{1F3C3}\x{1F46F}\x{1F9D6}\x{1F9D7}\x{1F3C4}\x{1F6A3}\x{1F3CA}\x{1F6B4}\x{1F6B5}\x{1F938}\x{1F93C}\x{1F93D}\x{1F93E}\x{1F939}\x{1F9D8}](?:\x{200D}\x{2642}\x{FE0F})|[\x{1F441}](?:\x{FE0F}\x{200D}\x{1F5E8}\x{FE0F})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1E9}\x{1F1F0}\x{1F1F2}\x{1F1F3}\x{1F1F8}\x{1F1F9}\x{1F1FA}](?:\x{1F1FF})|[\x{1F1E7}\x{1F1E8}\x{1F1EC}\x{1F1F0}\x{1F1F1}\x{1F1F2}\x{1F1F5}\x{1F1F8}\x{1F1FA}](?:\x{1F1FE})|[\x{1F1E6}\x{1F1E8}\x{1F1F2}\x{1F1F8}](?:\x{1F1FD})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1EC}\x{1F1F0}\x{1F1F2}\x{1F1F5}\x{1F1F7}\x{1F1F9}\x{1F1FF}](?:\x{1F1FC})|[\x{1F1E7}\x{1F1E8}\x{1F1F1}\x{1F1F2}\x{1F1F8}\x{1F1F9}](?:\x{1F1FB})|[\x{1F1E6}\x{1F1E8}\x{1F1EA}\x{1F1EC}\x{1F1ED}\x{1F1F1}\x{1F1F2}\x{1F1F3}\x{1F1F7}\x{1F1FB}](?:\x{1F1FA})|[\x{1F1E6}\x{1F1E7}\x{1F1EA}\x{1F1EC}\x{1F1ED}\x{1F1EE}\x{1F1F1}\x{1F1F2}\x{1F1F5}\x{1F1F8}\x{1F1F9}\x{1F1FE}](?:\x{1F1F9})|[\x{1F1E6}\x{1F1E7}\x{1F1EA}\x{1F1EC}\x{1F1EE}\x{1F1F1}\x{1F1F2}\x{1F1F5}\x{1F1F7}\x{1F1F8}\x{1F1FA}\x{1F1FC}](?:\x{1F1F8})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1EA}\x{1F1EB}\x{1F1EC}\x{1F1ED}\x{1F1EE}\x{1F1F0}\x{1F1F1}\x{1F1F2}\x{1F1F3}\x{1F1F5}\x{1F1F8}\x{1F1F9}](?:\x{1F1F7})|[\x{1F1E6}\x{1F1E7}\x{1F1EC}\x{1F1EE}\x{1F1F2}](?:\x{1F1F6})|[\x{1F1E8}\x{1F1EC}\x{1F1EF}\x{1F1F0}\x{1F1F2}\x{1F1F3}](?:\x{1F1F5})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1E9}\x{1F1EB}\x{1F1EE}\x{1F1EF}\x{1F1F2}\x{1F1F3}\x{1F1F7}\x{1F1F8}\x{1F1F9}](?:\x{1F1F4})|[\x{1F1E7}\x{1F1E8}\x{1F1EC}\x{1F1ED}\x{1F1EE}\x{1F1F0}\x{1F1F2}\x{1F1F5}\x{1F1F8}\x{1F1F9}\x{1F1FA}\x{1F1FB}](?:\x{1F1F3})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1E9}\x{1F1EB}\x{1F1EC}\x{1F1ED}\x{1F1EE}\x{1F1EF}\x{1F1F0}\x{1F1F2}\x{1F1F4}\x{1F1F5}\x{1F1F8}\x{1F1F9}\x{1F1FA}\x{1F1FF}](?:\x{1F1F2})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1EC}\x{1F1EE}\x{1F1F2}\x{1F1F3}\x{1F1F5}\x{1F1F8}\x{1F1F9}](?:\x{1F1F1})|[\x{1F1E8}\x{1F1E9}\x{1F1EB}\x{1F1ED}\x{1F1F1}\x{1F1F2}\x{1F1F5}\x{1F1F8}\x{1F1F9}\x{1F1FD}](?:\x{1F1F0})|[\x{1F1E7}\x{1F1E9}\x{1F1EB}\x{1F1F8}\x{1F1F9}](?:\x{1F1EF})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1EB}\x{1F1EC}\x{1F1F0}\x{1F1F1}\x{1F1F3}\x{1F1F8}\x{1F1FB}](?:\x{1F1EE})|[\x{1F1E7}\x{1F1E8}\x{1F1EA}\x{1F1EC}\x{1F1F0}\x{1F1F2}\x{1F1F5}\x{1F1F8}\x{1F1F9}](?:\x{1F1ED})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1E9}\x{1F1EA}\x{1F1EC}\x{1F1F0}\x{1F1F2}\x{1F1F3}\x{1F1F5}\x{1F1F8}\x{1F1F9}\x{1F1FA}\x{1F1FB}](?:\x{1F1EC})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1EC}\x{1F1F2}\x{1F1F3}\x{1F1F5}\x{1F1F9}\x{1F1FC}](?:\x{1F1EB})|[\x{1F1E6}\x{1F1E7}\x{1F1E9}\x{1F1EA}\x{1F1EC}\x{1F1EE}\x{1F1EF}\x{1F1F0}\x{1F1F2}\x{1F1F3}\x{1F1F5}\x{1F1F7}\x{1F1F8}\x{1F1FB}\x{1F1FE}](?:\x{1F1EA})|[\x{1F1E6}\x{1F1E7}\x{1F1E8}\x{1F1EC}\x{1F1EE}\x{1F1F2}\x{1F1F8}\x{1F1F9}](?:\x{1F1E9})|[\x{1F1E6}\x{1F1E8}\x{1F1EA}\x{1F1EE}\x{1F1F1}\x{1F1F2}\x{1F1F3}\x{1F1F8}\x{1F1F9}\x{1F1FB}](?:\x{1F1E8})|[\x{1F1E7}\x{1F1EC}\x{1F1F1}\x{1F1F8}](?:\x{1F1E7})|[\x{1F1E7}\x{1F1E8}\x{1F1EA}\x{1F1EC}\x{1F1F1}\x{1F1F2}\x{1F1F3}\x{1F1F5}\x{1F1F6}\x{1F1F8}\x{1F1F9}\x{1F1FA}\x{1F1FB}\x{1F1FF}](?:\x{1F1E6})|[\x{00A9}\x{00AE}\x{203C}\x{2049}\x{2122}\x{2139}\x{2194}-\x{2199}\x{21A9}-\x{21AA}\x{231A}-\x{231B}\x{2328}\x{23CF}\x{23E9}-\x{23F3}\x{23F8}-\x{23FA}\x{24C2}\x{25AA}-\x{25AB}\x{25B6}\x{25C0}\x{25FB}-\x{25FE}\x{2600}-\x{2604}\x{260E}\x{2611}\x{2614}-\x{2615}\x{2618}\x{261D}\x{2620}\x{2622}-\x{2623}\x{2626}\x{262A}\x{262E}-\x{262F}\x{2638}-\x{263A}\x{2640}\x{2642}\x{2648}-\x{2653}\x{265F}-\x{2660}\x{2663}\x{2665}-\x{2666}\x{2668}\x{267B}\x{267E}-\x{267F}\x{2692}-\x{2697}\x{2699}\x{269B}-\x{269C}\x{26A0}-\x{26A1}\x{26AA}-\x{26AB}\x{26B0}-\x{26B1}\x{26BD}-\x{26BE}\x{26C4}-\x{26C5}\x{26C8}\x{26CE}-\x{26CF}\x{26D1}\x{26D3}-\x{26D4}\x{26E9}-\x{26EA}\x{26F0}-\x{26F5}\x{26F7}-\x{26FA}\x{26FD}\x{2702}\x{2705}\x{2708}-\x{270D}\x{270F}\x{2712}\x{2714}\x{2716}\x{271D}\x{2721}\x{2728}\x{2733}-\x{2734}\x{2744}\x{2747}\x{274C}\x{274E}\x{2753}-\x{2755}\x{2757}\x{2763}-\x{2764}\x{2795}-\x{2797}\x{27A1}\x{27B0}\x{27BF}\x{2934}-\x{2935}\x{2B05}-\x{2B07}\x{2B1B}-\x{2B1C}\x{2B50}\x{2B55}\x{3030}\x{303D}\x{3297}\x{3299}\x{1F004}\x{1F0CF}\x{1F170}-\x{1F171}\x{1F17E}-\x{1F17F}\x{1F18E}\x{1F191}-\x{1F19A}\x{1F201}-\x{1F202}\x{1F21A}\x{1F22F}\x{1F232}-\x{1F23A}\x{1F250}-\x{1F251}\x{1F300}-\x{1F321}\x{1F324}-\x{1F393}\x{1F396}-\x{1F397}\x{1F399}-\x{1F39B}\x{1F39E}-\x{1F3F0}\x{1F3F3}-\x{1F3F5}\x{1F3F7}-\x{1F3FA}\x{1F400}-\x{1F4FD}\x{1F4FF}-\x{1F53D}\x{1F549}-\x{1F54E}\x{1F550}-\x{1F567}\x{1F56F}-\x{1F570}\x{1F573}-\x{1F57A}\x{1F587}\x{1F58A}-\x{1F58D}\x{1F590}\x{1F595}-\x{1F596}\x{1F5A4}-\x{1F5A5}\x{1F5A8}\x{1F5B1}-\x{1F5B2}\x{1F5BC}\x{1F5C2}-\x{1F5C4}\x{1F5D1}-\x{1F5D3}\x{1F5DC}-\x{1F5DE}\x{1F5E1}\x{1F5E3}\x{1F5E8}\x{1F5EF}\x{1F5F3}\x{1F5FA}-\x{1F64F}\x{1F680}-\x{1F6C5}\x{1F6CB}-\x{1F6D2}\x{1F6D5}\x{1F6E0}-\x{1F6E5}\x{1F6E9}\x{1F6EB}-\x{1F6EC}\x{1F6F0}\x{1F6F3}-\x{1F6FA}\x{1F7E0}-\x{1F7EB}\x{1F90D}-\x{1F93A}\x{1F93C}-\x{1F945}\x{1F947}-\x{1F971}\x{1F973}-\x{1F976}\x{1F97A}-\x{1F9A2}\x{1F9A5}-\x{1F9AA}\x{1F9AE}-\x{1F9CA}\x{1F9CD}-\x{1F9FF}\x{1FA70}-\x{1FA73}\x{1FA78}-\x{1FA7A}\x{1FA80}-\x{1FA82}\x{1FA90}-\x{1FA95}]/u', '', $post_title); $post_title = preg_replace('/\.(?=.*\.)/', '', $post_title); $post_title = preg_replace('/-+/', '-', $post_title); $post_title = str_replace('-.', '.', $post_title); $post_title = strtolower( $post_title ); if($post_title == '') { $post_title = uniqid(); } if(isset($file_parts['extension'])) { switch($file_parts['extension']) { case "": $filename = sanitize_title($post_title) . '.jpg'; break; case NULL: $filename = sanitize_title($post_title) . '.jpg'; break; default: $filename = sanitize_title($post_title) . '.' . $file_parts['extension']; break; } } else { $filename = sanitize_title($post_title) . '.jpg'; } } else { if(isset($file_parts['extension'])) { switch($file_parts['extension']) { case "": if(!aimogen_endsWith($filename, '.jpg')) $filename .= '.jpg'; break; case NULL: if(!aimogen_endsWith($filename, '.jpg')) $filename .= '.jpg'; break; default: if(!aimogen_endsWith($filename, '.' . $file_parts['extension'])) $filename .= '.' . $file_parts['extension']; break; } } else { if(!aimogen_endsWith($filename, '.jpg')) $filename .= '.jpg'; } } $filename = urldecode($filename); $filename = sanitize_file_name($filename); if (wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'] . '/' . $post_id . '-' . $filename; else $file = $upload_dir['basedir'] . '/' . $post_id . '-' . $filename; global $wp_filesystem; if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base') ){ require_once ABSPATH . 'wp-admin/includes/file.php'; $creds = request_filesystem_credentials( site_url() ); wp_filesystem($creds); } $allowed_mimes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/svg+xml', 'image/vnd.microsoft.icon', 'image/tiff', 'image/x-icon', 'image/bmp', 'image/vnd.adobe.photoshop', 'image/x-tga', 'image/heic', 'image/vnd.dwg', 'image/x-dds']; $real_filetype = wp_check_filetype_and_ext($file, $filename); if (empty($real_filetype['ext']) || !in_array($real_filetype['type'], $allowed_mimes)) { aimogen_log_to_file('Invalid image detected: ' . $image_url); return false; } $ret = $wp_filesystem->put_contents($file, $image_data); if ($ret === FALSE) { global $wp_filesystem; if (method_exists($wp_filesystem, 'errors') && is_wp_error($wp_filesystem->errors)) { $errors = $wp_filesystem->errors->get_error_messages(); aimogen_log_to_file('WP Filesystem Errors: ' . json_encode($errors)); } else { $error_details = error_get_last(); aimogen_log_to_file('Failed to copy image to disk: ' . $image_url . ' | Last PHP Error: ' . json_encode($error_details)); } return false; } $wp_filetype = wp_check_filetype($filename, null); if($wp_filetype['type'] == '') { $wp_filetype['type'] = 'image/png'; } $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => $filename, 'post_content' => '', 'post_status' => 'inherit' ); if ((isset($aimogen_Main_Settings['resize_height']) && $aimogen_Main_Settings['resize_height'] !== '') || (isset($aimogen_Main_Settings['resize_width']) && $aimogen_Main_Settings['resize_width'] !== '')) { try { if(!class_exists('\Aimogen\ImageResize')){require_once (dirname(__FILE__) . "/res/ImageResize/ImageResize.php");} $imageRes = new ImageResize($file); if (isset($aimogen_Main_Settings['resize_quality']) && $aimogen_Main_Settings['resize_quality'] !== '') { $imageRes->quality_jpg = intval($aimogen_Main_Settings['resize_quality']); } else { $imageRes->quality_jpg = 100; } if ((isset($aimogen_Main_Settings['resize_height']) && $aimogen_Main_Settings['resize_height'] !== '') && (isset($aimogen_Main_Settings['resize_width']) && $aimogen_Main_Settings['resize_width'] !== '')) { $imageRes->resizeToBestFit($aimogen_Main_Settings['resize_width'], $aimogen_Main_Settings['resize_height'], true); } elseif (isset($aimogen_Main_Settings['resize_width']) && $aimogen_Main_Settings['resize_width'] !== '') { $imageRes->resizeToWidth($aimogen_Main_Settings['resize_width'], true); } elseif (isset($aimogen_Main_Settings['resize_height']) && $aimogen_Main_Settings['resize_height'] !== '') { $imageRes->resizeToHeight($aimogen_Main_Settings['resize_height'], true); } $imageRes->save($file); } catch(Exception $e) { aimogen_log_to_file('Failed to resize featured image: ' . $image_url . ' to sizes ' . $aimogen_Main_Settings['resize_width'] . ' - ' . $aimogen_Main_Settings['resize_height'] . '. Exception thrown ' . esc_html($e->getMessage()) . '!'); } } $attach_id = wp_insert_attachment($attachment, $file, $post_id); if ($attach_id === 0) { return false; } if(!function_exists('wp_generate_attachment_metadata')) { require_once(ABSPATH . 'wp-admin/includes/image.php'); require_once(ABSPATH . 'wp-admin/includes/media.php'); } $attach_data = wp_generate_attachment_metadata($attach_id, $file); wp_update_attachment_metadata($attach_id, $attach_data); $res2 = set_post_thumbnail($post_id, $attach_id); if ($res2 === FALSE) { return false; } remove_filter('content_save_pre', 'wp_filter_post_kses'); remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');remove_filter('title_save_pre', 'wp_filter_kses'); wp_update_post(['ID' => $post_id]); add_filter('content_save_pre', 'wp_filter_post_kses'); add_filter('content_filtered_save_pre', 'wp_filter_post_kses');add_filter('title_save_pre', 'wp_filter_kses'); $post_title = get_the_title($post_id); if($post_title != '') { update_post_meta($attach_id, '_wp_attachment_image_alt', $post_title); } if($img_local === true && $old_attachment_id !== false) { $old_attachment_id = (int)$old_attachment_id; $xdeleted = wp_delete_attachment($old_attachment_id, true); if ( $xdeleted ) { } else { aimogen_log_to_file('Failed to delete old attachment ID: ' . $old_attachment_id); } } return true; } function aimogen_assign_featured_image_path($filename, $post_id) { $wp_filetype = wp_check_filetype($filename, null); if($wp_filetype['type'] == '') { $wp_filetype['type'] = 'image/png'; } $post_title = get_the_title($post_id); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => $post_title, 'post_content' => '', 'post_status' => 'inherit' ); $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if ((isset($aimogen_Main_Settings['resize_height']) && $aimogen_Main_Settings['resize_height'] !== '') || (isset($aimogen_Main_Settings['resize_width']) && $aimogen_Main_Settings['resize_width'] !== '')) { try { if(!class_exists('\Aimogen\ImageResize')){require_once (dirname(__FILE__) . "/res/ImageResize/ImageResize.php");} $imageRes = new ImageResize($filename); if (isset($aimogen_Main_Settings['resize_quality']) && $aimogen_Main_Settings['resize_quality'] !== '') { $imageRes->quality_jpg = intval($aimogen_Main_Settings['resize_quality']); } else { $imageRes->quality_jpg = 100; } if ((isset($aimogen_Main_Settings['resize_height']) && $aimogen_Main_Settings['resize_height'] !== '') && (isset($aimogen_Main_Settings['resize_width']) && $aimogen_Main_Settings['resize_width'] !== '')) { $imageRes->resizeToBestFit($aimogen_Main_Settings['resize_width'], $aimogen_Main_Settings['resize_height'], true); } elseif (isset($aimogen_Main_Settings['resize_width']) && $aimogen_Main_Settings['resize_width'] !== '') { $imageRes->resizeToWidth($aimogen_Main_Settings['resize_width'], true); } elseif (isset($aimogen_Main_Settings['resize_height']) && $aimogen_Main_Settings['resize_height'] !== '') { $imageRes->resizeToHeight($aimogen_Main_Settings['resize_height'], true); } $imageRes->save($filename); } catch(Exception $e) { aimogen_log_to_file('Failed to resize featured image: ' . $filename . ' to sizes ' . $aimogen_Main_Settings['resize_width'] . ' - ' . $aimogen_Main_Settings['resize_height'] . '. Exception thrown ' . esc_html($e->getMessage()) . '!'); } } $attach_id = wp_insert_attachment($attachment, $filename, $post_id); if ($attach_id === 0) { return false; } if(!function_exists('wp_generate_attachment_metadata')) { require_once(ABSPATH . 'wp-admin/includes/image.php'); require_once(ABSPATH . 'wp-admin/includes/media.php'); } $attach_data = wp_generate_attachment_metadata($attach_id, $filename); wp_update_attachment_metadata($attach_id, $attach_data); $res2 = set_post_thumbnail($post_id, $attach_id); if ($res2 === FALSE) { return false; } if($post_title != '') { update_post_meta($attach_id, '_wp_attachment_image_alt', $post_title); } return true; } function aimogen_get_date_now($param = 'now') { $date = new DateTime($param); $date = (array)$date; foreach ($date as $key => $value) { if ($key == 'date') { return $value; } } return ''; } function aimogen_get_session_id() { $name = md5(get_bloginfo()); if ( isset( $_COOKIE[$name . '_session_id'] ) ) { return sanitize_text_field(wp_unslash($_COOKIE[$name . '_session_id'])); } else { $unique = uniqid(); setcookie($name . "_session_id", $unique, 0); return $unique; } return "N/A"; } function aimogen_save_persona($title, $prompt, $description, $first_message, $avatar, $model) { $aimogen_result = array('status' => 'error', 'msg' => 'Something went wrong persona saving'); $persona_data = array( 'post_type' => 'aimogen_personas', 'post_title' => $title, 'post_content' => $prompt, 'post_excerpt' => $description, 'post_status' => 'publish' ); remove_filter('content_save_pre', 'wp_filter_post_kses'); remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');remove_filter('title_save_pre', 'wp_filter_kses'); $persona_id = wp_insert_post($persona_data); add_filter('content_save_pre', 'wp_filter_post_kses'); add_filter('content_filtered_save_pre', 'wp_filter_post_kses');add_filter('title_save_pre', 'wp_filter_kses'); if(is_wp_error($persona_id)) { $aimogen_result['msg'] = $persona_id->get_error_message(); } elseif($persona_id === 0) { $aimogen_result['msg'] = 'Failed to insert persona to database: ' . $title; } else { if(!empty($first_message)) { update_post_meta($persona_id, '_persona_first_message', sanitize_text_field($first_message)); } if(!empty($model)) { update_post_meta($persona_id, '_persona_model', sanitize_text_field($model)); } if(!empty($avatar)) { if(!function_exists('set_post_thumbnail')) { require_once(ABSPATH . 'wp-admin/includes/image.php'); require_once(ABSPATH . 'wp-admin/includes/media.php'); } $res2 = set_post_thumbnail($persona_id, $avatar); if ($res2 === FALSE) { $aimogen_result['msg'] = 'Failed to insert persona avatar to database: ' . $avatar; } } $aimogen_result['status'] = 'success'; $aimogen_result['id'] = $persona_id; } return $aimogen_result; } require(dirname(__FILE__) . "/res/QueryClass.php"); add_action('init', 'aimogen_create_taxonomy', 0); function aimogen_create_taxonomy() { if(AIMOGEN_IS_DEBUG === true) { $labels = array( 'name' => 'AI Training File', 'all_items' => 'All AI Training Files', 'singular_name' => 'aimogen_file', 'add_new' => 'New AI Training File' , 'add_new_item' => 'Add New AI Training File', 'edit_item' => 'Edit AI Training File', 'new_item' => 'New AI Training File', 'view_item' => 'View AI Training File', 'search_items' => 'Search AI Training Files', 'not_found' => 'No AI Training Files found', 'not_found_in_trash' => 'No AI Training File found in Trash', 'parent_item_colon' => 'Parent AI Training Files:', 'menu_name' => 'AI Training Files', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Training Files', 'supports' => array( 'title', 'editor', 'custom-fields' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'post' ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_file', $args); $labels = array( 'name' => 'AI Conversion File', 'all_items' => 'All AI Conversion Files', 'singular_name' => 'aimogen_convert', 'add_new' => 'New AI Conversion File' , 'add_new_item' => 'Add New AI Conversion File', 'edit_item' => 'Edit AI Conversion File', 'new_item' => 'New AI Conversion File', 'view_item' => 'View AI Conversion File', 'search_items' => 'Search AI Conversion Files', 'not_found' => 'No AI Conversion Files found', 'not_found_in_trash' => 'No AI Conversion File found in Trash', 'parent_item_colon' => 'Parent AI Conversion Files:', 'menu_name' => 'AI Conversion Files', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Conversion Files', 'supports' => array( 'title', 'editor', 'custom-fields' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'post' ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_convert', $args); $labels = array( 'name' => 'AI Finetune', 'all_items' => 'All AI Finetunes', 'singular_name' => 'aimogen_finetune', 'add_new' => 'New AI Finetune' , 'add_new_item' => 'Add New AI Finetune', 'edit_item' => 'Edit AI Finetune', 'new_item' => 'New AI Finetune', 'view_item' => 'View AI Finetune', 'search_items' => 'Search AI Finetunes', 'not_found' => 'No AI Finetunes found', 'not_found_in_trash' => 'No AI Finetune found in Trash', 'parent_item_colon' => 'Parent AI Finetune:', 'menu_name' => 'AI Finetune', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Finetune', 'supports' => array( 'title', 'editor', 'custom-fields' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'post' ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_finetune', $args); } $labels = array( 'name' => 'AI Video', 'all_items' => 'All AI Videos', 'singular_name' => 'aimogen_videos', 'add_new' => 'New AI Video' , 'add_new_item' => 'Add New AI Videos', 'edit_item' => 'Edit AI Videos', 'new_item' => 'New AI Videos', 'view_item' => 'View AI Videos', 'search_items' => 'Search AI Videos', 'not_found' => 'No AI Videos found', 'not_found_in_trash' => 'No AI Videos found in Trash', 'parent_item_colon' => 'Parent AI Videos:', 'menu_name' => 'AI Videos', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Videos', 'supports' => array( 'title', 'editor', 'custom-fields' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_video', $args); $labels = array( 'name' => 'AI Embedding', 'all_items' => 'All AI Embeddings', 'singular_name' => 'aimogen_embeddings', 'add_new' => 'New AI Embedding' , 'add_new_item' => 'Add New AI Embeddings', 'edit_item' => 'Edit AI Embeddings', 'new_item' => 'New AI Embeddings', 'view_item' => 'View AI Embeddings', 'search_items' => 'Search AI Embeddings', 'not_found' => 'No AI Embeddings found', 'not_found_in_trash' => 'No AI Embeddings found in Trash', 'parent_item_colon' => 'Parent AI Embeddings:', 'menu_name' => 'AI Embeddings', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Embeddings', 'supports' => array( 'title', 'editor', 'custom-fields' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_embeddings', $args); $labels = array( 'name' => 'AI Remote Chatbot', 'all_items' => 'All AI Remote Chatbot', 'singular_name' => 'aimogen_remote_chat', 'add_new' => 'New AI Remote Chatbot' , 'add_new_item' => 'Add New AI Remote Chatbots', 'edit_item' => 'Edit AI Remote Chatbots', 'new_item' => 'New AI Remote Chatbots', 'view_item' => 'View AI Remote Chatbots', 'search_items' => 'Search AI Remote Chatbots', 'not_found' => 'No AI Remote Chatbots found', 'not_found_in_trash' => 'No AI Remote Chatbots found in Trash', 'parent_item_colon' => 'Parent AI Remote Chatbots:', 'menu_name' => 'AI Remote Chatbots', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Remote Chatbots', 'supports' => array( 'title', 'editor' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => true, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'page', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_remote_chat', $args); $labels = array( 'name' => 'AI Form', 'all_items' => 'All AI Forms', 'singular_name' => 'aimogen_forms', 'add_new' => 'New AI Form' , 'add_new_item' => 'Add New AI Forms', 'edit_item' => 'Edit AI Forms', 'new_item' => 'New AI Forms', 'view_item' => 'View AI Forms', 'search_items' => 'Search AI Forms', 'not_found' => 'No AI Forms found', 'not_found_in_trash' => 'No AI Forms found in Trash', 'parent_item_colon' => 'Parent AI Forms:', 'menu_name' => 'AI Forms', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Forms', 'supports' => array( 'title', 'editor', 'custom-fields' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_forms', $args); $labels = array( 'name' => 'AI Persona', 'all_items' => 'All AI Personas', 'singular_name' => 'aimogen_personas', 'add_new' => 'New AI Persona' , 'add_new_item' => 'Add New AI Persona', 'edit_item' => 'Edit AI Persona', 'new_item' => 'New AI Persona', 'view_item' => 'View AI Persona', 'search_items' => 'Search AI Persona', 'not_found' => 'No AI Persona found', 'featured_image' => 'Persona Avatar', 'set_featured_image' => 'Set Persona Avatar', 'remove_featured_image' => 'Remove Persona Avatar', 'use_featured_image' => 'Use as Persona Avatar', 'not_found_in_trash' => 'No AI Persona found in Trash', 'parent_item_colon' => 'Parent AI Persona:', 'menu_name' => 'AI Personas', 'item_published' => 'Post published.', 'item_published_privately' => 'Post published privately.', 'item_reverted_to_draft' => 'Post reverted to draft.', 'item_trashed' => 'Post trashed.', 'item_scheduled' => 'Post scheduled.', 'item_updated' => 'Post updated.', 'item_link' => 'Post Link', 'item_link_description' => 'A link to a post.', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Personas', 'supports' => array( 'title', 'thumbnail', 'excerpt', 'editor' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_personas', $args); $labels = array( 'name' => 'AI Assistant', 'all_items' => 'All AI Assistants', 'singular_name' => 'aimogen_assistants', 'add_new' => 'New AI Assistant' , 'add_new_item' => 'Add New AI Assistant', 'edit_item' => 'Edit AI Assistant', 'new_item' => 'New AI Assistant', 'view_item' => 'View AI Assistant', 'search_items' => 'Search AI Assistant', 'not_found' => 'No AI Assistant found', 'featured_image' => 'Assistant Avatar', 'set_featured_image' => 'Set Assistant Avatar', 'remove_featured_image' => 'Remove Assistant Avatar', 'use_featured_image' => 'Use as Assistant Avatar', 'not_found_in_trash' => 'No AI Assistant found in Trash', 'parent_item_colon' => 'Parent AI Assistant:', 'menu_name' => 'AI Assistants', 'item_published' => 'Post published.', 'item_published_privately' => 'Post published privately.', 'item_reverted_to_draft' => 'Post reverted to draft.', 'item_trashed' => 'Post trashed.', 'item_scheduled' => 'Post scheduled.', 'item_updated' => 'Post updated.', 'item_link' => 'Post Link', 'item_link_description' => 'A link to a post.', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Assistants', 'supports' => array( 'title', 'thumbnail', 'excerpt', 'editor', 'custom-fields' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_assistants', $args); $labels = array( 'name' => 'AI Batch Requests', 'all_items' => 'All AI Batch Requests', 'singular_name' => 'aimogen_batch', 'add_new' => 'New AI Batch Requests' , 'add_new_item' => 'Add New AI Batch Requests', 'edit_item' => 'Edit AI Batch Requests', 'new_item' => 'New AI Batch Requests', 'view_item' => 'View AI Batch Requests', 'search_items' => 'Search AI Batch Requests', 'not_found' => 'No AI Batch Requests found', 'featured_image' => 'Batch Requests Avatar', 'set_featured_image' => 'Set Batch Requests Avatar', 'remove_featured_image' => 'Remove Batch Requests Avatar', 'use_featured_image' => 'Use as Batch Requests Avatar', 'not_found_in_trash' => 'No AI Batch Requests found in Trash', 'parent_item_colon' => 'Parent AI Batch Requests:', 'menu_name' => 'AI Batch Requests', 'item_published' => 'Post published.', 'item_published_privately' => 'Post published privately.', 'item_reverted_to_draft' => 'Post reverted to draft.', 'item_trashed' => 'Post trashed.', 'item_scheduled' => 'Post scheduled.', 'item_updated' => 'Post updated.', 'item_link' => 'Post Link', 'item_link_description' => 'A link to a post.', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Batch Requests', 'supports' => array( 'title', 'thumbnail', 'excerpt', 'editor', 'custom-fields' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_batches', $args); $labels = array( 'name' => 'OmniBlock Templates', 'all_items' => 'All OmniBlock Templates', 'singular_name' => 'aimogen_omni_temp', 'add_new' => 'New OmniBlock Template' , 'add_new_item' => 'Add New OmniBlock Template', 'edit_item' => 'Edit OmniBlock Template', 'new_item' => 'New OmniBlock Template', 'view_item' => 'View OmniBlock Template', 'search_items' => 'Search OmniBlock Templates', 'not_found' => 'No OmniBlock Templates found', 'featured_image' => 'OmniBlock Templates Avatar', 'set_featured_image' => 'Set OmniBlock Templates Avatar', 'remove_featured_image' => 'Remove OmniBlock Templates Avatar', 'use_featured_image' => 'Use as OmniBlock Templates Avatar', 'not_found_in_trash' => 'No OmniBlock Templates found in Trash', 'parent_item_colon' => 'Parent OmniBlock Templates:', 'menu_name' => 'OmniBlock Templates', 'item_published' => 'Post published.', 'item_published_privately' => 'Post published privately.', 'item_reverted_to_draft' => 'Post reverted to draft.', 'item_trashed' => 'Post trashed.', 'item_scheduled' => 'Post scheduled.', 'item_updated' => 'Post updated.', 'item_link' => 'Post Link', 'item_link_description' => 'A link to a post.', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'OmniBlock Templates', 'supports' => array( 'title', 'editor' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_omni_temp', $args); register_taxonomy( 'aimogen_template_categories', 'aimogen_omni_temp', array( 'hierarchical' => true, 'label' => 'Category', 'query_var' => true ) ); $labels = array( 'name' => 'AI Content Editor Templates', 'all_items' => 'All AI Content Editor Templates', 'singular_name' => 'aimogen_editor_temp', 'add_new' => 'New AI Content Editor Template' , 'add_new_item' => 'Add New AI Content Editor Template', 'edit_item' => 'Edit AI Content Editor Template', 'new_item' => 'New AI Content Editor Template', 'view_item' => 'View AI Content Editor Template', 'search_items' => 'Search AI Content Editor Templates', 'not_found' => 'No AI Content Editor Templates found', 'featured_image' => 'AI Content Editor Templates Avatar', 'set_featured_image' => 'Set AI Content Editor Templates Avatar', 'remove_featured_image' => 'Remove AI Content Editor Templates Avatar', 'use_featured_image' => 'Use as AI Content Editor Templates Avatar', 'not_found_in_trash' => 'No AI Content Editor Templates found in Trash', 'parent_item_colon' => 'Parent AI Content Editor Templates:', 'menu_name' => 'AI Content Editor Templates', 'item_published' => 'Post published.', 'item_published_privately' => 'Post published privately.', 'item_reverted_to_draft' => 'Post reverted to draft.', 'item_trashed' => 'Post trashed.', 'item_scheduled' => 'Post scheduled.', 'item_updated' => 'Post updated.', 'item_link' => 'Post Link', 'item_link_description' => 'A link to a post.', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI Content Editor Templates', 'supports' => array( 'title', 'editor' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_editor_temp', $args); $labels = array( 'name' => 'OmniBlock File', 'all_items' => 'All OmniBlock Files', 'singular_name' => 'aimogen_omni_file', 'add_new' => 'New OmniBlock File' , 'add_new_item' => 'Add New OmniBlock File', 'edit_item' => 'Edit OmniBlock File', 'new_item' => 'New OmniBlock File', 'view_item' => 'View OmniBlock File', 'search_items' => 'Search OmniBlock Files', 'not_found' => 'No OmniBlock Files found', 'featured_image' => 'OmniBlock File Avatar', 'set_featured_image' => 'Set OmniBlock File Avatar', 'remove_featured_image' => 'Remove OmniBlock File Avatar', 'use_featured_image' => 'Use as OmniBlock File Avatar', 'not_found_in_trash' => 'No OmniBlock Files found in Trash', 'parent_item_colon' => 'Parent OmniBlock File:', 'menu_name' => 'OmniBlock File', 'item_published' => 'Post published.', 'item_published_privately' => 'Post published privately.', 'item_reverted_to_draft' => 'Post reverted to draft.', 'item_trashed' => 'Post trashed.', 'item_scheduled' => 'Post scheduled.', 'item_updated' => 'Post updated.', 'item_link' => 'Post Link', 'item_link_description' => 'A link to a post.', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'OmniBlock File', 'supports' => array( 'title', 'editor', 'custom-fields' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_omni_file', $args); register_taxonomy( 'aimogen_file_type', 'aimogen_omni_file', array( 'hierarchical' => true, 'label' => 'Location', 'query_var' => true ) ); $labels = array( 'name' => 'Chatbot Theme', 'all_items' => 'All Chatbot Themes', 'singular_name' => 'aimogen_themes', 'add_new' => 'New Chatbot Theme' , 'add_new_item' => 'Add New Chatbot Theme', 'edit_item' => 'Edit Chatbot Theme', 'new_item' => 'New Chatbot Theme', 'view_item' => 'View Chatbot Theme', 'search_items' => 'Search Chatbot Theme', 'not_found' => 'No Chatbot Theme found', 'featured_image' => 'Theme Image', 'set_featured_image' => 'Set Theme Image', 'remove_featured_image' => 'Remove Theme Image', 'use_featured_image' => 'Use as Theme Image', 'not_found_in_trash' => 'No Chatbot Theme found in Trash', 'parent_item_colon' => 'Parent Chatbot Theme:', 'menu_name' => 'Chatbot Themes', 'item_published' => 'Post published.', 'item_published_privately' => 'Post published privately.', 'item_reverted_to_draft' => 'Post reverted to draft.', 'item_trashed' => 'Post trashed.', 'item_scheduled' => 'Post scheduled.', 'item_updated' => 'Post updated.', 'item_link' => 'Post Link', 'item_link_description' => 'A link to a post.', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'Chatbot Themes', 'supports' => array( 'title', 'editor' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_themes', $args); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'AI User Data', 'supports' => array( 'title', 'editor', 'custom-fields' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, ) ); $admin_caps = array('capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options' )); $args = array_merge($args, $admin_caps); register_post_type( 'aimogen_user_data', $args); $labels = array( 'name' => 'Leads', 'singular_name' => 'Lead', 'menu_name' => 'Leads', 'name_admin_bar' => 'Lead', 'archives' => 'Lead Archives', 'attributes' => 'Lead Attributes', 'all_items' => 'All Leads', 'add_new_item' => 'Add New Lead', 'add_new' => 'Add New', 'new_item' => 'New Lead', 'edit_item' => 'Edit Lead', 'update_item' => 'Update Lead', 'view_item' => 'View Lead', 'view_items' => 'View Leads', 'search_items' => 'Search Lead', 'not_found' => 'Not found', 'not_found_in_trash' => 'Not found in Trash' ); $args = array( 'label' => 'Lead', 'description' => 'Leads collected from chatbot', 'hierarchical' => false, 'labels' => $labels, 'supports' => array( 'title' ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'has_archive' => false, 'publicly_queryable' => false, 'show_in_rest' => false, 'exclude_from_search' => true, 'query_var' => true, 'can_export' => false, 'rewrite' => false, 'capability_type' => 'post', 'capabilities' => array( 'edit_post' => 'edit_post', 'read_post' => 'read_post', 'delete_post' => 'delete_post', 'edit_posts' => 'edit_posts', 'edit_others_posts' => 'edit_others_posts', 'publish_posts' => 'publish_posts', 'read_private_posts' => 'read_private_posts', 'create_posts' => 'do_not_allow', ), 'map_meta_cap' => true, ); register_post_type( 'aimogen_lead', $args ); } add_action('add_meta_boxes', 'aimogen_add_persona_first_message_meta_box'); function aimogen_add_persona_first_message_meta_box() { add_meta_box( 'persona_first_message_id', 'Persona First Message', 'aimogen_render_persona_first_message_meta_box', 'aimogen_personas', 'normal', 'high' ); add_meta_box( 'persona_model_id', 'Persona AI Model', 'aimogen_render_persona_model_meta_box', 'aimogen_personas', 'normal', 'high' ); } add_action('add_meta_boxes', 'aimogen_add_assistant_first_message_meta_box'); function aimogen_add_assistant_first_message_meta_box() { add_meta_box( 'assistant_first_message_id', 'AI Assistant First Message', 'aimogen_render_assistant_first_message_meta_box', 'aimogen_assistants', 'normal', 'high' ); } function aimogen_render_persona_first_message_meta_box($post) { $custom_text = get_post_meta($post->ID, '_persona_first_message', true); wp_nonce_field('aimogen_persona_nonce_action', 'aimogen_persona_nonce'); ?> ID, '_persona_model', true); $all_models = aimogen_get_all_models(); ?> ID, '_assistant_first_message', true); wp_nonce_field('aimogen_assistant_nonce_action', 'aimogen_assistant_nonce'); ?> post_type) { if ( $text === 'Excerpt' ) { $translated_text = 'Persona Role'; } if ( $text === 'Add Title' ) { $translated_text = 'Add Persona Name'; } } elseif('aimogen_assistants' === $post->post_type) { if ( $text === 'Excerpt' ) { $translated_text = 'Assistant Role'; } if ( $text === 'Add Title' ) { $translated_text = 'Add Assistant Name'; } } } return $translated_text; } add_filter( 'gettext', 'aimogen_change_excerpt', 20, 3 ); add_filter('post_updated_messages', 'aimogen_contact_updated_messages'); function aimogen_contact_updated_messages( $messages ) { if($GLOBALS['post']->post_type == 'aimogen_embeddings') { $messages['aimogen_embeddings'] = array( 0 => '', 1 => esc_html__('Embedding updated.', 'aimogen'), 2 => esc_html__('Custom field updated.', 'aimogen'), 3 => esc_html__('Custom field deleted.', 'aimogen'), 4 => esc_html__('Embedding updated.', 'aimogen'), 5 => esc_html__('Revisions', 'aimogen'), 6 => esc_html__('Embedding published.', 'aimogen'), 7 => esc_html__('Embedding saved.', 'aimogen'), 8 => esc_html__('Embedding submitted.', 'aimogen'), /* translators: %1$s is the scheduled date */ 9 => esc_html__('Embedding scheduled for: %1$s.', 'aimogen'), 10 => esc_html__('Embedding draft updated.', 'aimogen') ); } elseif($GLOBALS['post']->post_type == 'aimogen_forms') { $messages['aimogen_forms'] = array( 0 => '', 1 => esc_html__('Form updated.', 'aimogen'), 2 => esc_html__('Custom field updated.', 'aimogen'), 3 => esc_html__('Custom field deleted.', 'aimogen'), 4 => esc_html__('Form updated.', 'aimogen'), 5 => esc_html__('Revisions', 'aimogen'), 6 => esc_html__('Form published.', 'aimogen'), 7 => esc_html__('Form saved.', 'aimogen'), 8 => esc_html__('Form submitted.', 'aimogen'), /* translators: %1$s is the scheduled date */ 9 => esc_html__('Form scheduled for: %1$s.', 'aimogen'), 10 => esc_html__('Form draft updated.', 'aimogen') ); } elseif($GLOBALS['post']->post_type == 'aimogen_personas') { $messages['aimogen_personas'] = array( 0 => '', 1 => esc_html__('Persona updated.', 'aimogen'), 2 => esc_html__('Custom field updated.', 'aimogen'), 3 => esc_html__('Custom field deleted.', 'aimogen'), 4 => esc_html__('Persona updated.', 'aimogen'), 5 => esc_html__('Revisions', 'aimogen'), 6 => esc_html__('Persona published.', 'aimogen'), 7 => esc_html__('Persona saved.', 'aimogen'), 8 => esc_html__('Persona submitted.', 'aimogen'), /* translators: %1$s is the scheduled date */ 9 => esc_html__('Persona scheduled for: %1$s.', 'aimogen'), 10 => esc_html__('Persona draft updated.', 'aimogen') ); } elseif($GLOBALS['post']->post_type == 'aimogen_assistants') { $messages['aimogen_assistants'] = array( 0 => '', 1 => esc_html__('Assistant updated.', 'aimogen'), 2 => esc_html__('Custom field updated.', 'aimogen'), 3 => esc_html__('Custom field deleted.', 'aimogen'), 4 => esc_html__('Assistant updated.', 'aimogen'), 5 => esc_html__('Revisions', 'aimogen'), 6 => esc_html__('Assistant published.', 'aimogen'), 7 => esc_html__('Assistant saved.', 'aimogen'), 8 => esc_html__('Assistant submitted.', 'aimogen'), /* translators: %1$s is the scheduled date */ 9 => esc_html__('Assistant scheduled for: %1$s.', 'aimogen'), 10 => esc_html__('Assistant draft updated.', 'aimogen') ); } elseif($GLOBALS['post']->post_type == 'aimogen_batches') { $messages['aimogen_batches'] = array( 0 => '', 1 => esc_html__('AI Batch Request updated.', 'aimogen'), 2 => esc_html__('Custom field updated.', 'aimogen'), 3 => esc_html__('Custom field deleted.', 'aimogen'), 4 => esc_html__('AI Batch Request updated.', 'aimogen'), 5 => esc_html__('Revisions', 'aimogen'), 6 => esc_html__('AI Batch Request published.', 'aimogen'), 7 => esc_html__('AI Batch Request saved.', 'aimogen'), 8 => esc_html__('AI Batch Request submitted.', 'aimogen'), /* translators: %1$s is the scheduled date */ 9 => esc_html__('AI Batch Request scheduled for: %1$s.', 'aimogen'), 10 => esc_html__('AI Batch Request draft updated.', 'aimogen') ); } elseif($GLOBALS['post']->post_type == 'aimogen_omni_temp') { $messages['aimogen_omni_temp'] = array( 0 => '', 1 => esc_html__('OmniBlock Template updated.', 'aimogen'), 2 => esc_html__('Custom field updated.', 'aimogen'), 3 => esc_html__('Custom field deleted.', 'aimogen'), 4 => esc_html__('OmniBlock Template updated.', 'aimogen'), 5 => esc_html__('Revisions', 'aimogen'), 6 => esc_html__('OmniBlock Template published.', 'aimogen'), 7 => esc_html__('OmniBlock Template saved.', 'aimogen'), 8 => esc_html__('OmniBlock Template submitted.', 'aimogen'), /* translators: %1$s is the scheduled date */ 9 => esc_html__('OmniBlock Template scheduled for: %1$s.', 'aimogen'), 10 => esc_html__('OmniBlock Template draft updated.', 'aimogen') ); } elseif($GLOBALS['post']->post_type == 'aimogen_editor_temp') { $messages['aimogen_editor_temp'] = array( 0 => '', 1 => esc_html__('AI Content Editor Template updated.', 'aimogen'), 2 => esc_html__('Custom field updated.', 'aimogen'), 3 => esc_html__('Custom field deleted.', 'aimogen'), 4 => esc_html__('AI Content Editor Template updated.', 'aimogen'), 5 => esc_html__('Revisions', 'aimogen'), 6 => esc_html__('AI Content Editor Template published.', 'aimogen'), 7 => esc_html__('AI Content Editor Template saved.', 'aimogen'), 8 => esc_html__('AI Content Editor Template submitted.', 'aimogen'), /* translators: %1$s is the scheduled date */ 9 => esc_html__('AI Content Editor Template scheduled for: %1$s.', 'aimogen'), 10 => esc_html__('AI Content Editor Template draft updated.', 'aimogen') ); } elseif($GLOBALS['post']->post_type == 'aimogen_themes') { $messages['aimogen_themes'] = array( 0 => '', 1 => esc_html__('Theme updated.', 'aimogen'), 2 => esc_html__('Custom field updated.', 'aimogen'), 3 => esc_html__('Custom field deleted.', 'aimogen'), 4 => esc_html__('Theme updated.', 'aimogen'), 5 => esc_html__('Revisions', 'aimogen'), 6 => esc_html__('Theme published.', 'aimogen'), 7 => esc_html__('Theme saved.', 'aimogen'), 8 => esc_html__('Theme submitted.', 'aimogen'), /* translators: %1$s is the scheduled date */ 9 => esc_html__('Theme scheduled for: %1$s.', 'aimogen'), 10 => esc_html__('Theme draft updated.', 'aimogen') ); } return $messages; } function aimogen_disable_create_newpost() { global $wp_post_types; if(isset($wp_post_types['aimogen_embeddings']->cap)) { $wp_post_types['aimogen_embeddings']->cap->create_posts = 'do_not_allow'; } if(isset($wp_post_types['aimogen_embeddings']->cap)) { $wp_post_types['aimogen_forms']->cap->create_posts = 'do_not_allow'; } if(isset($wp_post_types['aimogen_embeddings']->cap)) { $wp_post_types['aimogen_personas']->cap->create_posts = 'do_not_allow'; } if(isset($wp_post_types['aimogen_embeddings']->cap)) { $wp_post_types['aimogen_assistants']->cap->create_posts = 'do_not_allow'; } if(isset($wp_post_types['aimogen_embeddings']->cap)) { $wp_post_types['aimogen_batches']->cap->create_posts = 'do_not_allow'; } if(isset($wp_post_types['aimogen_embeddings']->cap)) { $wp_post_types['aimogen_omni_temp']->cap->create_posts = 'do_not_allow'; } if(isset($wp_post_types['aimogen_embeddings']->cap)) { $wp_post_types['aimogen_editor_temp']->cap->create_posts = 'do_not_allow'; } if(isset($wp_post_types['aimogen_embeddings']->cap)) { $wp_post_types['aimogen_themes']->cap->create_posts = 'do_not_allow'; } } add_action('init','aimogen_disable_create_newpost'); add_action('upgrader_process_complete', 'aimogen_updatePlugin', 10, 2); function aimogen_updatePlugin(\WP_Upgrader $upgrader, array $hook_extra) { if (is_array($hook_extra) && array_key_exists('action', $hook_extra) && array_key_exists('type', $hook_extra) && array_key_exists('plugins', $hook_extra)) { if ($hook_extra['action'] == 'update' && $hook_extra['type'] == 'plugin' && is_array($hook_extra['plugins']) && !empty($hook_extra['plugins'])) { $this_plugin = plugin_basename(__FILE__); foreach ($hook_extra['plugins'] as $key => $plugin) { if ($this_plugin == $plugin) { $this_plugin_updated = true; break; } } unset($key, $plugin, $this_plugin); if (isset($this_plugin_updated) && $this_plugin_updated === true) { require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); global $wpdb; $charset_collate = $wpdb->get_charset_collate(); aimogen_register_aggregated_feed_table(); $sql_create_table = "CREATE TABLE IF NOT EXISTS {$wpdb->aimogent_shortcode_rez} ( post_id bigint(20) unsigned NOT NULL auto_increment, post_hash text default '', post_result text default '', PRIMARY KEY (post_id) ) $charset_collate; "; dbDelta( $sql_create_table ); } } } } register_activation_hook(__FILE__, 'aimogen_activation_callback'); function aimogen_activation_callback($defaults = FALSE) { if (!get_option('aimogen_posts_per_page') || $defaults === TRUE) { if ($defaults === FALSE) { add_option('aimogen_posts_per_page', '12', '', false); } else { aimogen_update_option('aimogen_posts_per_page', '12', false); } } if (!get_option('aimogen_Main_Settings') || $defaults === TRUE) { $aimogen_Main_Settings = array( 'translate' => 'disabled', 'translate_source' => 'disabled', 'second_translate' => 'disabled', 'bing_region' => '', 'video_cfg_scale' => '', 'cfg_seed' => '', 'motion_bucket_id' => '', 'custom_html2' => '', 'custom_html' => '', 'embedding_template' => '', 'comment_embedding_template' => '', 'bulk_embedding_template' => '', 'google_trans_auth' => '', 'deppl_free' => '', 'deepl_auth' => '', 'serpapi_auth' => '', 'bing_auth' => '', 'bing_auth_internet' => '', 'valueserp_auth' => '', 'spaceserp_auth' => '', 'random_serp_sources' => '', 'serper_auth' => '', 'tavily_auth' => '', 'duck_enable' => 'on', 'bing_scrape' => 'on', 'google_search_api' => '', 'google_search_cx' => '', 'yt_app_id' => '', 'copy_locally' => 'on', 'url_image' => '', 'drive_directory' => 'MyImages', 'bucket_name' => '', 'bucket_region' => '', 's3_user' => '', 's3_pass' => '', 'cloud_directory' => '', 'cloud_account' => '', 'cloud_bucket' => '', 'cloud_pass' => '', 'cloud_user' => '', 'cloud_public' => '', 'digital_directory' => '', 'digital_endpoint' => '', 'digital_pass' => '', 'digital_user' => '', 'generic_url' => '', 'generic_directory' => '', 'generic_bucket' => '', 'generic_region' => '', 'generic_user' => '', 'generic_pass' => '', 'no_img_translate' => '', 'omni_webhook' => '', 'omni_caching' => '', 'midjourney_image_model' => 'fast', 'ideogram_image_model' => 'V_2_TURBO', 'ideogram_magic_prompt' => 'AUTO', 'midjourney_image_engine' => 'midjourney', 'google_ai_image_model' => AIMOGEN_GOOGLE_IMAGE_DEFAULT_MODEL, 'replicate_image_model' => 'ac732df83cea7fff18b8472768c88ad041fa750ff7682a21affe81863cbe77e4', 'ai_resize_width' => '', 'disable_compress' => '', 'compress_quality' => '75', 'ai_resize_height' => '', 'ai_resize_quality' => '', 'request_delay' => '', 'request_delay_dalle' => '', 'player_height' => '', 'player_width' => '', 'improve_yt_kw' => 'on', 'yt_kw_model' => AIMOGEN_DEFAULT_MODEL, 'ai_writer_model' => AIMOGEN_DEFAULT_MODEL, 'writer_assistant_id' => '', 'kw_assistant_id' => '', 'hide_videos' => '', 'yt_assistant_id' => '', 'ai_writer_title_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Create a captivating and concise SEO title in English for your WordPress %%post_type%%: "%%post_title_idea%%". Boost its search engine visibility with relevant keywords for maximum impact.', 'ai_writer_seo_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Craft an enticing and succinct meta description in English for your WordPress %%post_type%%: "%%post_title_idea%%". Emphasize the notable features and advantages in just 155 characters, incorporating relevant keywords to optimize its SEO performance.', 'ai_writer_seo_title_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Craft an enticing and succinct SEO meta title in English for your WordPress %%post_type%%: "%%post_title_idea%%".', 'ai_writer_content_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Create a captivating and comprehensive English description for your WordPress %%post_type%%: "%%post_title_idea%%". Dive into specific details, highlighting its unique features of this subject, if possible, benefits, and the value it brings. Craft a compelling narrative around the %%post_type%% that captivates the audience. Use HTML for formatting, include unnumbered lists and bold. Writing Style: Creative. Tone: Neutral.', 'ai_writer_excerpt_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Write a captivating and succinct English summary for the WordPress %%post_type%%: "%%post_title_idea%%", accentuating its pivotal features, advantages, and distinctive qualities.', 'ai_writer_tags_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Suggest a series of pertinent keywords in English for your WordPress %%post_type%%: "%%post_title_idea%%". These keywords should be closely connected to the %%post_type%%, optimizing its visibility. Please present the keywords in a comma-separated format without using symbols like -, #, etc.', 'aimogen_focus_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Craft a single focus keyword in English for your WordPress post: "%%post_title_idea%%".', 'yt_kw_prompt' => 'Using which 2 keywords should I search YouTube, to get the most relevant videos for this text? Provide a single variant, write only the 2 keywords, nothing else. Don\'t act as a virtual assistant, reply only with the keywords, as they will be used automatically for search. The text is: "%%aimogen_query%%"', 'insta_kw_prompt' => 'Don\'t act as a virtual assistant, reply only with the hashtag, as it will be used automatically for search. Using which single hashtag should I search Instagram, to get the most relevant media for this text: "%%aimogen_query%%"', 'sentence_list' => 'This is one %adjective %noun %sentence_ending This is another %adjective %noun %sentence_ending I %love_it %nouns , because they are %adjective %sentence_ending My %family says this plugin is %adjective %sentence_ending These %nouns are %adjective %sentence_ending', 'sentence_list2' => 'Meet this %adjective %noun %sentence_ending This is the %adjective %noun ever %sentence_ending I %love_it %nouns , because they are the %adjective %sentence_ending My %family says this plugin is very %adjective %sentence_ending These %nouns are quite %adjective %sentence_ending', 'variable_list' => 'adjective_very => %adjective;very %adjective; adjective => clever;interesting;smart;huge;astonishing;unbelievable;nice;adorable;beautiful;elegant;fancy;glamorous;magnificent;helpful;awesome noun_with_adjective => %noun;%adjective %noun noun => plugin;WordPress plugin;item;ingredient;component;constituent;module;add-on;plug-in;addon;extension nouns => plugins;WordPress plugins;items;ingredients;components;constituents;modules;add-ons;plug-ins;addons;extensions love_it => love;adore;like;be mad for;be wild about;be nuts about;be crazy about family => %adjective %family_members;%family_members family_members => grandpa;brother;sister;mom;dad;grandma sentence_ending => .;!;!!', 'auto_clear_logs' => 'No', 'run_after' => '', 'max_len' => '', 'ai_image_size' => '512x512', 'ai_image_model' => 'gpt-image-2', 'back_color' => '#ffffff', 'form_placeholder' => 'AI Result', 'form_append' => '', 'form_prepend' => '', 'show_advanced' => '', 'store_data_forms' => 'off', 'markdown_forms' => 'off', 'default_ai_model' => AIMOGEN_DEFAULT_MODEL, 'show_rich_editor' => '', 'enable_copy' => '', 'enable_pdf' => '', 'disable_ai_form_saving' => '', 'form_max_user' => '', 'enable_download' => '', 'enable_char_count' => '', 'submit_location' => '1', 'submit_align' => '1', 'text_color' => '#000000', 'but_color' => '#424242', 'btext_color' => '#ffffff', 'min_len' => '', 'kw_lang' => 'en_US', 'kw_method' => 'ai', 'new_tab' => 'no', 'pinecone_index' => '', 'pinecone_namespace' => '', 'qdrant_index' => '', 'qdrant_name' => '', 'pinecone_topk' => '1', 'embeddings_model' => AIMOGEN_DEFAULT_MODEL_EMBEDDING, 'run_before' => '', 'enable_logging' => 'on', 'app_id' => '', 'stability_app_id' => '', 'midjourney_app_id' => '', 'replicate_app_id' => '', 'ideogram_app_id' => '', 'headlessbrowserapi_key' => '', 'multi_separator' => '', 'azure_endpoint' => '', 'azure_api_selector_embeddings' => '', 'azure_api_selector_assistants' => '', 'azure_api_selector_batch' => '', 'azure_api_selector' => '', 'app_id_claude' => '', 'custom_models' => '', 'app_id_groq' => '', 'app_id_nvidia' => '', 'app_id_xai' => '', 'openai_organization' => '', 'app_id_google' => '', 'app_id_openrouter' => '', 'app_id_huggingface' => '', 'ollama_url' => '', 'app_id_perplexity' => '', 'multiple_key' => '', 'api_selector' => 'openai', 'pinecone_app_id' => '', 'embeddings_api' => 'pinecone', 'qdrant_app_id' => '', 'elevenlabs_app_id' => '', 'google_app_id' => '', 'did_app_id' => '', 'azure_speech_id' => '', 'steps' => '50', 'cfg_scale' => '7', 'clip_guidance_preset' => 'NONE', 'clip_style_preset' => 'NONE', 'stable_model' => AIMOGEN_STABLE_DEFAULT_MODE, 'prompt_strength' => '0.8', 'num_inference_steps' => '4', 'ai_scheduler' => 'DPMSolverMultistep', 'replicate_ratio' => '', 'ideogram_ratio' => '', 'ideogram_style' => '', 'ideogram_palette' => '', 'custom_params_replicate' => '', 'sampler' => 'auto', 'enable_detailed_logging' => '', 'rule_timeout' => '36000', 'kws_case' => '', 'no_new_tab_kw' => '', 'kw_skip_ids' => '', 'partial_kws' => '', 'email_address' => '', 'send_email' => '', 'convert_gutenberg' => '', 'no_intro_image' => '', 'best_password' => '', 'best_user' => '', 'improve_keywords' => 'openai', 'image_pool' => '4', 'random_image_sources' => '', 'random_results_order' => '', 'image_query_translate_en' => '', 'kw_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Extract a comma-separated list of the most relevant keywords from the text, prioritizing specific references over general keywords. Add the highest priority to the most specific keyword that is still related to the main topic. If the article features products, select the exact product name as keyword. The text is: %%content%%.', 'kw_model' => AIMOGEN_DEFAULT_MODEL, 'keyword_model' => AIMOGEN_DEFAULT_MODEL, 'internet_model' => AIMOGEN_DEFAULT_MODEL, 'assistant_model' => AIMOGEN_DEFAULT_MODEL, 'aicontent_model' => AIMOGEN_DEFAULT_MODEL, 'comment_model' => AIMOGEN_DEFAULT_MODEL, 'comment_model_auto' => AIMOGEN_DEFAULT_MODEL, 'keyword_assistant_id' => '', 'aicontent_assistant_id' => '', 'disable_aicontent_saving' => '', 'internet_assistant_id' => '', 'wizard_assistant_id' => '', 'comment_assistant_id' => '', 'comment_assistant_id_auto' => '', 'enable_wpcli' => '', 'rest_api_init' => '', 'rest_api_keys' => '', 'rest_api_bearer' => '', 'comment_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Write a reply for %%username%%\'s comment on the post titled "%%post_title%%". The user\'s comment is: %%comment%%', 'comment_prompt_auto' => 'Don\'t act as a virtual assistant, return only the content you are asked. Write a reply for %%username%%\'s comment on the post titled "%%post_title%%". The user\'s comment is: %%comment%%', 'tax_description_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Craft an SEO-optimized description for a WordPress %%term_taxonomy_name%% titled "%%term_name%%." Ensure that the description not only provides an informative summary but also incorporates relevant keywords and phrases to enhance search engine visibility.', 'aicontent_temperature' => '1', 'aicontent_top_p' => '1', 'aicontent_presence_penalty' => '0', 'aicontent_frequency_penalty' => '0', 'keyword_prompts' => 'Do not act as a virtual assistant, ask only what you are asked. I need to find highly relevant royalty-free images for an article heading, please extract a comma-separated list of the most relevant keywords or key phrases from the heading, prioritizing specific references over general keywords. Add the highest priority to the most specific keyword that is still related to the main topic. Keep in mind also the main subject of the post title when you suggest the keywords. I need the most relevant images, based on the keywords you return. Remember, also include the general niche keyword in the key phrase, to allow images to be relevant to the current subject. For example, if the heading is about food and the article is about dogs, don\'t just return food, but instead, return \'dog food\'. By doing so, you can help me find more appropriate and targeted images for the article heading. The blog post heading title is: "%%post_title%%". Post title is: "%%original_post_title%%"', 'spin_lang' => 'English', 'exclude_words' => '', 'spin_text' => 'disabled', 'spin_what' => 'all', 'best_humanize' => '', 'no_title' => '', 'no_html_check' => 'on', 'protect_html' => 'on', 'swear_filter' => '', 'no_undetectibility' => 'on', 'no_undetectibility_bulk' => '', 'no_undetectibility_omni' => '', 'no_undetectibility_editor' => '', 'no_undetectibility_single' => '', 'no_add_chars' => '', 'no_regional' => '', 'no_parasite' => '', 'no_synonym' => '', 'no_typing_error' => '', 'no_media_library' => '', 'no_post_editor' => '', 'no_elementor' => '', 'clear_omni' => '', 'no_pre_code_remove' => '', 'no_omni_shortcode_render' => '', 'ai_seed' => '', 'responses_api' => 'on', 'store_data' => 'off', 'store_data_rules' => 'off', 'apiKey' => '', 'resize_height' => '', 'resize_width' => '', 'resize_quality' => '', 'pexels_api' => '', 'flickr_api' => '', 'flickr_license' => '', 'flickr_order' => '', 'pixabay_api' => '', 'imgtype' => '', 'img_order' => '', 'img_cat' => '', 'img_width' => '', 'img_mwidth' => '', 'img_ss' => '', 'img_editor' => '', 'img_language' => '', 'unsplash_key' => '', 'google_images' => 'on', 'google_images_api' => '', 'pixabay_scrape' => 'on', 'scrapeimgtype' => '', 'scrapeimg_orientation' => '', 'scrapeimg_order' => '', 'scrapeimg_cat' => '', 'scrapeimg_width' => '', 'scrapeimg_height' => '', 'attr_text' => '

    Images by
    %%image_source_name%%. Free for commercial use, no attribution required.', 'textrazor_key' => '', 'neuron_key' => '', 'neuron_project' => '', 'amazon_app_secret' => '', 'amazon_app_id' => '', 'bimage' => '', 'plagiarism_api' => '', 'no_royalty_skip' => '', 'proxy_url' => '', 'proxy_auth' => '', 'proxy_ai' => '', 'do_not_check_duplicates' => '', 'no_random_titles' => '', 'draft_first' => '', 'global_req_words' => '', 'require_only_one' => '', 'global_ban_words' => '', 'social_list' => array(), 'youtube_cookies' => '', 'email_notification' => '', 'image_ai_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Choose the most relevant image URL, based on its file name, for the post titled "%%post_title%%." If no matching image is found, select a random one from the list. Respond solely with the URL of the chosen image. The image URL list is: %%image_list%%', 'image_ai_model' => AIMOGEN_DEFAULT_MODEL, 'img_assistant_id' => '', 'use_image_ai' => '', 'gpt4_context_limit' => '', 'gpt35_context_limit' => '', 'claude_context_limit_200k' => '', 'fallback_models' => '', 'assist_max_completion_token' => '', 'assist_max_prompt_token' => '', 'claude_context_limit' => '', 'embeddings_related' => '', 'embeddings_forms' => '', 'embeddings_omni' => '', 'embeddings_assistant' => '', 'embeddings_edit_short' => '', 'embeddings_article_short' => '', 'embeddings_chat_short' => '', 'embeddings_edit' => '', 'embeddings_bulk' => '', 'embeddings_bulk_title' => '', 'embeddings_bulk_sections' => '', 'embeddings_bulk_intro' => '', 'embeddings_bulk_content' => '', 'embeddings_bulk_qa' => '', 'embeddings_bulk_outro' => '', 'embeddings_bulk_excerpt' => '', 'embeddings_single' => '', 'embeddings_related_namespace' => '', 'embeddings_forms_namespace' => '', 'embeddings_omni_namespace' => '', 'embeddings_assistant_namespace' => '', 'embeddings_edit_short_namespace' => '', 'embeddings_article_short_namespace' => '', 'embeddings_chat_short_namespace' => '', 'embeddings_edit_namespace' => '', 'embeddings_bulk_namespace' => '', 'embeddings_bulk_title_namespace' => '', 'embeddings_bulk_sections_namespace' => '', 'embeddings_bulk_intro_namespace' => '', 'embeddings_bulk_content_namespace' => '', 'embeddings_bulk_qa_namespace' => '', 'embeddings_bulk_outro_namespace' => '', 'embeddings_bulk_excerpt_namespace' => '', 'embeddings_single_namespace' => '', 'internet_related' => '', 'internet_edit_short' => '', 'internet_article_short' => '', 'internet_chat_short' => '', 'internet_edit' => '', 'internet_bulk' => '', 'internet_bulk_title' => '', 'internet_bulk_sections' => '', 'internet_bulk_intro' => '', 'internet_bulk_content' => '', 'internet_bulk_qa' => '', 'internet_bulk_outro' => '', 'internet_bulk_excerpt' => '', 'internet_forms' => '', 'internet_omni' => '', 'internet_assistant' => '', 'results_num' => '3', 'auto_namspace' => '', 'comment_auto_namspace' => '', 'bulk_namspace' => '', 'index_types' => array(), 'comment_index_types' => array(), 'comment_auto_types' => array(), 'no_approve' => '', 'user_list' => '', 'email_list' => '', 'url_list' => '', 'rewrite_embedding' => '', 'embedding_rw_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Rewrite the given content concisely, preserving its style and information, while ensuring the rewritten text stays within 300 words. Each paragraph should range between 60 to 120 words. Exclude non-textual elements and unnecessary repetition. Conclude with a statement directing readers to find more information at %%post_url%%. If these guidelines cannot be met, send an empty response. The content is as follows: %%post_content%%', 'embedding_rw_model' => AIMOGEN_DEFAULT_MODEL, 'emb_assistant_id' => '', 'internet_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Web search results: %%web_results%% Current date: %%current_date%% Instructions: Using the provided web search results, write a comprehensive reply to the given query. Make sure to cite results using [[number]] notation after the reference. If the provided search results refer to multiple subjects with the same name, write separate answers for each subject. Query: %%original_query%%', 'internet_single_template' => '[%%result_counter%%]: %%result_title%% %%result_snippet%% URL: %%result_link%%', 'internet_single' => '', 'internet_gl' => '', 'keyword_extractor_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Using which 2 keywords should I search the internet, so I get results related to the following text? Give me only the 2 search keywords, don\'t write anything else. Don\'t act as a virtual assistant, reply only with the keywords, as they will be used automatically for search. The text is: "%%original_prompt%%"?', 'alternate_continue' => '', 'whole_prompt' => 'on', 'rule_webhook' => '', 'external_products' => '', 'continue_prepend' => 'Continue the article from below, add new content to it. Be sure to keep the same writing style, Content should be ready to post, no editing required. Language: English, friendly tone, professional and rich with information related to post title. Add headings in

    format. Do not add texts like "Article written by...". Do not add heading for Introduction. Do not add article title in content. Do not add images in content. Don\'t add a conclusion, nor a summary to the end of the article.', 'continue_append' => '', 'markdown_parse' => 'on', 'first_embeddings' => '', 'nlbr_parse' => '', 'no_max' => '', 'no_jobs' => '', 'not_important' => '', 'php_images' => '', 'bing_off' => '', 'ai_off' => '', 'pre_code_off' => '', 'max_retry' => '1', 'max_chat_retry' => '', 'max_timeout' => '', 'rel_search' => array('post_title', 'post_content'), 'ignored_users' => 'admin', 'enable_tracking' => '', 'assistant_placement' => 'below', 'assistant_disable' => 'back', 'assistant_not_logged' => 'disable', 'assistant_image_size' => '512x512', 'assistant_temperature' => '1', 'assistant_top_p' => '1', 'assistant_ppenalty' => '0', 'assistant_fpenalty' => '0', 'no_content' => '', 'tag_name' => '', 'post_id' => '', 'post_name' => '', 'page_id' => '', 'post_parent' => '', 'post_status' => '', 'type_post' => 'post', 'pagename' => '', 'search_offset' => '', 'search_query' => '', 'meta_name' => '', 'meta_value' => '', 'year' => '', 'month' => '', 'day' => '', 'order' => '', 'orderby' => '', 'featured_image' => 'any', 'max_posts' => '', 'category_name' => '', 'author_id' => '', 'author_name' => '', 'no_twice' => 'on', 'custom_name' => 'aimogen_published', 'secret_word' => '', 'auto_edit' => 'disabled' ); if ($defaults === FALSE) { add_option('aimogen_Main_Settings', $aimogen_Main_Settings, '', false); } else { aimogen_update_option('aimogen_Main_Settings', $aimogen_Main_Settings, false); } } if (!get_option('aimogen_Spinner_Settings') || $defaults === TRUE) { $aimogen_Spinner_Settings = array( 'aimogen_spinning' => '', 'run_background' => '', 'enable_default' => 'yes', 'post_posts' => '', 'post_pages' => 'on', 'post_custom' => 'on', 'except_type' => '', 'only_type' => '', 'tax_seo_auto' => 'off', 'max_tax_nr' => '1', 'overwite_tax' => '', 'disabled_categories' => array(), 'tax_description_auto' => array(), 'tax_description_manual' => array(), 'tax_seo_assistant_id' => '', 'tax_seo_description_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Generate a concise, SEO-friendly description (maximum 50 words) for a WordPress %%term_taxonomy_name%% titled "%%term_name%%." Ensure the description effectively summarizes the term while incorporating relevant keywords to enhance search engine visibility.', 'tax_seo_description_model' => AIMOGEN_DEFAULT_MODEL, 'tax_description_model' => AIMOGEN_DEFAULT_MODEL, 'tax_assistant_id' => '', 'disable_tags' => '', 'enable_tags' => '', 'disable_users' => '', 'enable_users' => '', 'featured_status' => '', 'seo_status' => '', 'enable_field' => '', 'disable_field' => '', 'change_status' => 'no', 'change_date' => '', 'store_data' => 'off', 'delay_post' => '5', 'process_event' => 'publish', 'use_template_manual' => '', 'use_template_auto' => '', 'append_spintax' => 'disabled', 'append_location' => 'content', 'url_image_list' => '', 'ai_featured_image_edit' => 'disabled', 'ai_featured_image_edit_content' => 'disabled', 'ai_featured_image_engine' => '2', 'ai_featured_image_engine_content' => '2', 'ai_image_command_edit_content' => 'Slightly change the image, making it unique.', 'ai_image_command_edit' => 'Slightly change the image, making it unique.', 'image_strength' => '0.90', 'image_strength_content' => '0.90', 'max_edit_content' => '', 'append_toc' => 'disabled', 'when_toc' => '4', 'max_nr' => '1', 'delay_request' => '', 'title_toc' => 'Table of Contents', 'allow_hide_toc' => 'on', 'hierarchy_toc' => 'on', 'add_numbers_toc' => '', 'float_toc' => 'none', 'color_toc' => 'gray', 'heading_levels1' => 'on', 'heading_levels2' => 'on', 'heading_levels3' => 'on', 'heading_levels4' => 'on', 'heading_levels5' => 'on', 'heading_levels6' => 'on', 'social_list' => array(), 'exclude_toc' => '', 'similarity_threshold' => '0.9', 'max_to_process_in_one_go' => '300', 'duplication_template' => '%%post_content_plain_text%%', 'duplication_index' => '_aimogen_index', 'dup_titles' => 'on', 'enhance_articles' => '', 'duplicate_action' => 'delete', 'duplicate_handle' => 'keep_relevant', 'duplication_date_after' => '', 'duplication_date_before' => '', 'duplication_author_exclude' => '', 'duplication_author_include' => '', 'duplication_category_include' => '', 'duplication_category_exclude' => '', 'duplication_tag_include' => '', 'duplication_tag_exclude' => '', 'rich_embed_location' => 'bottom', 'ai_rewriter' => 'disabled', 'ai_duplication' => 'disabled', 'ai_instruction' => 'Rewrite an HTML article to be 100% unique while keeping its high quality and original meaning. Key instructions: Thoroughly paraphrase, including altering sentence structures and using synonyms; reorganize paragraphs and points for a new perspective; add relevant information like current statistics or examples; replace examples/analogies with new, equivalent ones; create new headings and subheadings that reflect the restructured content; adjust the tone to differ from the original, ensuring coherence and logical structure, and retain any specific SEO keywords. Act as a Content Writer, not as a Virtual Assistant. Return only the content requested, without any additional comments or text. The content provided will be automatically published on my website. The article is below:\n\n', 'ai_instruction_title' => 'Rewrite the article title from below to make it more engaging: ', 'ai_instruction_slug' => 'Rewrite this WordPress post slug, improve it for better SEO, but keep it short: ', 'no_slug' => 'on', 'no_add_excerpt' => '', 'no_add_title' => '', 'no_add_content' => '', 'no_add_slug' => '', 'edit_temperature' => '', 'ai_vision_add' => '', 'ai_title_vision' => '', 'title_model' => AIMOGEN_DEFAULT_MODEL, 'ai_slug_vision' => '', 'slug_model' => AIMOGEN_DEFAULT_MODEL, 'ai_excerpt_vision' => '', 'excerpt_model' => AIMOGEN_DEFAULT_MODEL, 'preppend_add' => '', 'append_add' => '', 'ai_vision_cat' => '', 'ai_vision_com' => '', 'no_approve' => '', 'ai_vision_seo' => '', 'ai_vision_tag' => '', 'add_custom' => 'disabled', 'ai_custom_field' => '', 'no_custom_field_prompt' => '', 'no_custom_tax_prompt' => '', 'ai_custom_tax' => '', 'max_custom' => '', 'skip_inexist_custom' => '', 'custom_assistant_id' => '', 'custom_model' => AIMOGEN_DEFAULT_MODEL, 'ai_vision_custom' => '', 'ai_vision' => '', 'edit_top_p' => '', 'edit_presence_penalty' => '', 'edit_frequency_penalty' => '', 'max_char_chunks' => '', 'max_char' => '', 'no_title' => 'on', 'rewrite_url' => '', 'edit_model' => AIMOGEN_DEFAULT_MODEL, 'edit_assistant_id' => '', 'enhance_model' => AIMOGEN_DEFAULT_MODEL, 'enhance_assistant_id' => '', 'ai_instruction_enhance' => 'You are an AI content editor tasked with resolving duplicate content issues on a blog. Compare the content of two posts to determine if any valuable or unique information from the duplicate post can be integrated into the post to be kept. If the duplicate post contains unique information that is not already present in the post to be kept, integrate it seamlessly into the content of the post to be kept while preserving its natural flow and meaning. Ensure that the HTML tags and structure are maintained during processing. If the duplicate post contains no new or unique information, return the content of the post to be kept unchanged. Do not make unnecessary edits. ---- Post content from where additional info should be gathered (if found): %%post_plain_text_content_to_be_removed%% ---- Post content where info should be inserted (if needed): %%post_content_to_be_kept%% ---- Process the content now, return only the edited content, nothing else.', 'append_assistant_id' => '', 'no_content' => 'yes', 'enable_gutenberg' => '1', 'enable_elementor' => '1', 'gutenberg_list' => array(), 'elementor_css_class_filter' => '', 'no_excerpt' => 'on', 'max_slug_len' => '', 'ai_instruction_excerpt' => 'Rewrite the article excerpt from below to make it more engaging while keeping the HTML tags unchanged. Edit only the visible content that is rendered in the HTML and displayed on the front end: ', 'ai_featured_image' => 'disabled', 'ai_featured_image_source' => '1', 'ai_image_command' => 'Generate a high-resolution, visually compelling image that creatively interprets the theme encapsulated by this post title: "%%post_title%%". The image should be versatile enough to fit various niches, from technology and lifestyle to nature and science. It should feature a central, eye-catching element that abstractly represents the topic, surrounded by relevant, subtler motifs that provide context and depth. The composition should be balanced and aesthetically pleasing, with a harmonious color palette that complements the mood of the title. The artwork should be suitable for use as a captivating header image for a blog post.', 'image_size' => '', 'min_char' => '', 'images' => '', 'videos' => '', 'link_juicer_prompt' => 'Don\'t act as a virtual assistant, return only the content you are asked. Generate a comma-separated list of relevant keywords for the post title (for use in the Link Juicer plugin): "%%post_title%%".', 'link_juicer_assistant_id' => '', 'link_juicer_model' => AIMOGEN_DEFAULT_MODEL, 'ai_vision_link_juicer' => '', 'add_links' => 'disabled', 'link_method' => 'aimogen', 'max_links' => '3-5', 'link_type' => 'internal', 'affiliate_id' => '', 'target_country' => 'com', 'link_list' => '', 'link_post_types' => 'post', 'force_keywords' => '', 'link_post_not_ids' => '', 'link_nofollow' => '', 'add_cats' => 'disabled', 'max_cats' => '', 'skip_inexist' => '', 'ai_cats' => 'Don\'t act as a virtual assistant, respond only with what you are asked to do. Generate a comma-separated list of relevant categories for the post title: "%%post_title%%". These categories must accurately categorize the article within the broader topics or themes of your blog, aiding in the organization and navigation of your content.', 'cats_model' => AIMOGEN_DEFAULT_MODEL, 'cats_tax' => '', 'tags_tax' => '', 'add_tags' => 'disabled', 'max_tags' => '', 'skip_inexist_tags' => '', 'ai_tags' => 'Don\'t act as a virtual assistant, respond only with what you are asked to do. Generate a comma-separated list of relevant tags for the post title: "%%post_title%%". These tags must accurately reflect the key topics, themes, or keywords associated with the article and help improve its discoverability and organization.', 'tags_model' => AIMOGEN_DEFAULT_MODEL, 'headings' => '', 'enable_ai_images' => '', 'headings_ai_command' => 'Write %%needed_heading_count%% relevant PAA (People Also Asked) related questions, each on a new line, for the title: %%post_title%%', 'headings_model' => AIMOGEN_DEFAULT_MODEL, 'headings_assistant_id' => '', 'meta_assistant_id' => '', 'categories_assistant_id' => '', 'tags_assistant_id' => '', 'comments_assistant_id' => '', 'ai_command' => 'Write a comprehensive and SEO-optimized article on the topic of "%%post_title%%". Incorporate relevant keywords naturally throughout the article to enhance search engine visibility. This article must provide valuable information to readers and be well-structured with proper headings, bullet points, and HTML formatting. If needed, you can use WordPress related CSS styling for the article. When applicable, add also HTML tables with WordPress styling (you can use WordPress table classes). If added, table data must be relevant, creative, short and simple. Don\'t add an introductory or a conclusion section to the article. You can add also some other sections, when they fit the article\'s subject, like: benefits and practical tips, case studies, first had experience. Please ensure that the article is at least 1200 words in length and adheres to best SEO practices, including proper header tags (H1, H2, H3), meta title, and meta description. Feel free to use a friendly, conversational tone and make the article as informative and engaging as possible while ensuring it remains factually accurate and well-researched. Act as a Content Writer, not as a Virtual Assistant. Return only the content requested, without any additional comments or text. The content provided will be automatically published on my website.', 'max_seed_tokens' => '', 'max_result_tokens' => '', 'max_continue_tokens' => '', 'max_tokens' => '', 'temperature' => '1', 'top_p' => '1', 'presence_penalty' => '0', 'frequency_penalty' => '0', 'store_data' => '', 'model' => AIMOGEN_DEFAULT_MODEL, 'ai_comments' => 'Write a single comment (don\'t start a new line) for the post title: %%post_title%% Previous comments are: %%previous_comments%% %%comment_author_name%%:', 'star_count' => '5', 'prev_comms' => '5', 'max_comments' => '1-2', 'add_comments' => 'disabled', 'comments_model' => AIMOGEN_DEFAULT_MODEL, 'user_list' => '%%random_user%%', 'url_list' => '', 'max_time' => '', 'min_time' => '', 'seo_model' => AIMOGEN_DEFAULT_MODEL, 'seo_max_char' => '', 'seo_copy_excerpt' => '', 'content_text_speech' => 'off', 'did_image' => '', 'audio_template' => '%%post_content%%', 'did_voice' => 'microsoft:en-US-JennyNeural:Cheerful', 'eleven_voice' => '', 'ai_seo' => 'Craft an SEO meta description that optimizes the visibility and click-through rate for the post titled "%%post_title%%" The meta description should be concise, engaging, and provide a clear and compelling summary of the article\'s content, while also incorporating relevant keywords.', 'add_seo' => 'disabled', 'add_seo_title' => 'disabled', 'meta_assistant_id_title' => '', 'seo_model_title' => '', 'ai_vision_seo_title' => '', 'ai_seo_title' => 'Craft an SEO meta title that optimizes the visibility and click-through rate for the post titled "%%post_title%%"', 'eleven_model_id' => '', 'eleven_voice_custom' => '', 'voice_stability' => '', 'voice_similarity_boost' => '', 'voice_style' => '', 'speaker_boost' => '', 'open_model_id' => 'tts-1', 'open_voice' => 'alloy', 'open_format' => 'mp3', 'open_speed' => '1', 'voice_language' => 'en-US', 'google_voice' => '', 'audio_profile' => '', 'google_voice_model' => 'latest_long', 'voice_speed' => '1', 'voice_pitch' => '0', 'text_to_audio' => '%%post_content%%', 'audio_location' => 'append', 'content_speech_text' => 'off', 'speech_model' => 'whisper-1', 'max_speech' => '', 'audio_to_text' => '%%audio_to_text%%', 'audio_to_text_prompt' => '', 'speech_temperature' => '0', 'audio_text_location' => 'append', 'publish_new' => 'no', 'prep_audio' => '', 'copy_location' => 'local', 'auto_run_interval' => 'No' ); if ($defaults === FALSE) { add_option('aimogen_Spinner_Settings', $aimogen_Spinner_Settings, '', false); } else { aimogen_update_option('aimogen_Spinner_Settings', $aimogen_Spinner_Settings, false); } } if (!get_option('aimogen_Chatbot_Settings') || $defaults === TRUE) { $aimogen_Chatbot_Settings = array( 'font_size' => '1em', 'show_header' => 'show', 'bubble_width' => 'full', 'bubble_alignment' => 'left', 'bubble_user_alignment' => 'right', 'show_ai_avatar' => 'show', 'show_user_avatar' => 'show', 'user_account_avatar' => '', 'chatbot_prepend' => '', 'chatbot_append' => '', 'chat_theme' => '', 'show_dltxt' => 'show', 'show_clear' => 'show', 'show_mute' => 'show', 'show_internet' => 'show', 'show_internet_default' => 'off', 'voice_language' => 'en-US', 'did_image' => '', 'did_height' => '300', 'did_width' => '300', 'did_voice' => 'microsoft:en-US-JennyNeural:Cheerful', 'google_voice' => '', 'audio_profile' => '', 'google_voice_model' => 'latest_long', 'voice_speed' => '1', 'voice_pitch' => '0', 'chatbot_text_speech' => 'off', 'azure_voice' => 'en-US-AvaMultilingualNeural', 'azure_voice_profile' => '', 'azure_private_endpoint' => '', 'azure_voice_endpoint' => '', 'azure_region' => 'westus2', 'azure_character' => 'lisa', 'canvas_avatar_width' => '1200px', 'azure_character_style' => 'casual-sitting', 'free_voice' => 'Google US English;en-US', 'voice_similarity_boost' => '', 'voice_style' => '', 'speaker_boost' => '', 'open_model_id' => 'tts-1', 'open_voice' => 'alloy', 'open_format' => 'mp3', 'open_speed' => '1', 'voice_stability' => '', 'eleven_model_id' => '', 'eleven_voice' => '', 'eleven_voice_custom' => '', 'width' => '100%', 'height' => 'auto', 'minheight' => '250px', 'topavatar_width' => '', 'topavatar_height' => '', 'convavatar_width' => '', 'convavatar_height' => '', 'custom_header' => '', 'custom_footer' => '', 'custom_css' => '', 'background' => '#f7f7f9', 'image_chat_size' => '512x512', 'image_chat_model' => 'gpt-image-2', 'show_gdpr' => '', 'gdpr_notice' => 'By using this chatbot, you consent to the collection and use of your data as outlined in our Privacy Policy. Your data will only be used to assist with your inquiry.', 'gdpr_checkbox' => 'I agree to the terms.', 'gdpr_button' => 'Start chatting', 'allow_chatbot_site' => '', 'remote_chat' => '', 'user_font_color' => '#ffffff', 'user_background_color' => '#0084ff', 'ai_font_color' => 'black', 'ai_background_color' => '#f0f0f0', 'input_border_color' => '#e1e3e6', 'submit_color' => '#55a7e2', 'submit_text_color' => '#ffffff', 'voice_color' => '#55a7e2', 'voice_color_activated' => '#55a7e2', 'enable_moderation' => '', 'blocked_words' => '', 'moderation_model' => 'omni-moderation-latest', 'flagged_message' => 'Your message has been flagged as potentially harmful or inappropriate. Please review your language and content to ensure it aligns with our values of respect and sensitivity towards others. Thank you for your cooperation.', 'enable_copy' => '', 'chat_editing' => 'disabled', 'enable_html' => '', 'disable_modern_chat' => '', 'allow_stream_stop' => '', 'strip_js' => '', 'scroll_bot' => '', 'chat_waveform' => '', 'waveform_color' => '', 'send_message_sound' => '', 'receive_message_sound' => '', 'response_delay' => '', 'typewriter_delay' => '50', 'instant_response' => 'on', 'voice_input' => '', 'auto_submit_voice' => '', 'chat_download_format' => 'txt', 'chat_model' => aimogen_get_default_model_name($aimogen_Main_Settings), 'temperature' => '1', 'top_p' => '1', 'max_tokens' => '', 'presence_penalty' => '0', 'frequency_penalty' => '0', 'chat_preppend_text' => 'You are Ava, a friendly and knowledgeable AI chatbot companion. You are designed to provide information, assistance, and engaging conversations on a wide range of topics. Your goal is to make the user\'s experience enjoyable and informative, always prioritizing their comfort and privacy in every interaction. If users have questions or need assistance, they can feel free to ask, and you\'ll do your best to assist them in a friendly and respectful manner. Return HTML in markdown format. If you are asked to create code or HTML, return it in plain HTML format.', 'ai_message_preppend' => 'Ava', 'ai_role' => 'AI Chatbot', 'user_message_preppend' => 'User', 'ai_first_message' => 'Hi! How can I help you?', 'assistant_id' => '', 'chat_mode' => 'text', 'user_token_cap_per_day' => '', 'additional_bots' => array(), 'god_blacklisted_functions' => '', 'strip_botname' => '', 'god_mode_enable_wp' => '', 'database_command_types' => array(), 'god_mode_enable_chart' => '', 'god_mode_enable_end' => '', 'god_mode_enable_dalle' => '', 'god_mode_enable_stable' => '', 'god_mode_enable_midjourney' => '', 'god_mode_enable_replicate' => '', 'god_mode_enable_ideogram' => '', 'god_mode_enable_google_image' => '', 'target_country' => 'com', 'max_products' => '3-4', 'sort_results' => 'none', 'bot_workflow' => '', 'enable_mcp' => array(), 'listing_template' => '%%product_counter%%. %%product_title%% - Desciption: %%product_description%% - Link: %%product_url%% - Price: %%product_price%%', 'god_mode_enable_scraper' => '', 'scrape_method' => '0', 'strip_tags' => '', 'max_chars' => '', 'god_mode_enable_rss' => '', 'max_rss_items' => '5', 'rss_template' => '[%%item_counter%%]: %%item_title%% - %%item_description%%', 'god_mode_enable_google' => '', 'max_google_items' => '5', 'google_template' => '[%%item_counter%%]: %%item_title%% - %%item_snippet%%', 'god_mode_enable_youtube_captions' => '', 'god_mode_enable_database' => '', 'god_mode_enable_omniblock' => '', 'god_omniblock_rules' => '', 'max_caption_length' => '1000', 'god_mode_enable_royalty' => '', 'god_mode_lead_capture' => '', 'god_mode_ai' => '', 'ai_models_recall' => array(), 'god_mode_enable_email' => '', 'god_mode_enable_webhook' => '', 'god_mode_enable_toubiz' => '', 'god_mode_enable_facebook_post' => '', 'facebook_post_select' => '', 'god_mode_enable_youtube' => '', 'affiliate_id' => '', 'stable_model' => '', 'ai_image_size_stable' => '', 'god_mode_dalle_failed' => '', 'god_mode_stable_failed' => '', 'god_mode_enable_stable_video' => '', 'ai_video_size_stable' => '768x768', 'god_mode_enable_amazon_details' => '', 'god_mode_enable_booking' => '', 'god_mode_enable_amazon' => '', 'ai_image_size' => '512x512', 'ai_image_model' => 'gpt-image-2', 'god_whitelisted_functions' => '', 'god_preview' => '', 'god_mode_enable_twitter_post' => '', 'god_mode_enable_threads_post' => '', 'god_mode_enable_instagram_post' => '', 'god_mode_enable_pinterest_post' => '', 'pinterest_post_select' => '', 'god_mode_enable_google_post' => '', 'god_mode_enable_youtube_post' => '', 'god_mode_enable_reddit_post' => '', 'subreddits_list' => '', 'god_mode_enable_linkedin_post' => '', 'linkedin_selected_pages' => '', 'business_post_select' => array(), 'god_mode_front_end' => 'off', 'max_input_length' => '', 'max_message_count' => '', 'max_message_context' => '', 'restriction_time' => '', 'restriction_count' => '', 'restriction_message' => 'You exceeded your requests limit. Please try again later.', 'no_empty' => '', 'persistent' => 'off', 'persistent_guests' => 'off', 'max_chat_log_not_login' => '', 'max_chat_log_login' => '', 'remember_chat_transient' => '', 'enable_vision' => 'off', 'enable_file_uploads' => 'off', 'file_expiration_pdf' => '', 'prompt_editable' => 'on', 'markdown_parse' => 'on', 'file_expiration' => '', 'prompt_templates' => '', 'placeholder' => 'Enter your chat message here', 'submit' => 'Submit', 'submit_image' => '', 'submit_full' => '', 'compliance' => '', 'select_prompt' => 'Please select a prompt', 'upload_pdf' => '', 'pdf_page' => '10', 'pdf_character' => '', 'pdf_ok' => 'PDF file uploaded successfully! You can ask questions about it.', 'pdf_end' => 'PDF file session ended.', 'pdf_fail' => 'Failed to upload the PDF file, please try again later.', 'window_location' => 'bottom-right', 'page_load_chat' => '', 'page_load_chat_delay' => '', 'page_load_chat_once' => '', 'page_load_chat_urls' => '', 'page_load_chat_message' => '', 'page_exit_chat' => '', 'page_exit_chat_once' => '', 'page_exit_chat_urls' => '', 'page_exit_chat_message' => '', 'page_scroll_chat' => '', 'page_scroll_chat_percent' => '50', 'page_scroll_chat_once' => '', 'page_scroll_chat_urls' => '', 'page_scroll_chat_message' => '', 'page_inactive_chat' => '', 'page_inactive_chat_time' => '30000', 'page_inactive_chat_once' => '', 'page_inactive_chat_urls' => '', 'page_inactive_chat_message' => '', 'enable_front_end' => 'off', 'custom_global_shortcode' => '', 'window_width' => '400px', 'not_show_urls' => '', 'only_show_urls' => '', 'max_time' => '', 'min_time' => '', 'always_show' => array(), 'never_show' => array(), 'show_content_wp' => array(), 'no_show_content_wp' => array(), 'no_show_locales' => array(), 'show_locales' => array(), 'no_show_roles' => array(), 'show_roles' => array(), 'no_show_devices' => array(), 'show_devices' => array(), 'no_show_oses' => array(), 'show_oses' => array(), 'no_show_browsers' => array(), 'show_browsers' => array(), 'no_show_ips' => '', 'show_ips' => '', 'chatbot_icon' => '1', 'chatbot_icon_html' => '', 'open_width' => '' ); if ($defaults === FALSE) { add_option('aimogen_Chatbot_Settings', $aimogen_Chatbot_Settings, '', false); } else { aimogen_update_option('aimogen_Chatbot_Settings', $aimogen_Chatbot_Settings, false); } } require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); global $wpdb; $charset_collate = $wpdb->get_charset_collate(); aimogen_register_aggregated_feed_table(); $sql_create_table = "CREATE TABLE IF NOT EXISTS {$wpdb->aimogent_shortcode_rez} ( post_id bigint(20) unsigned NOT NULL auto_increment, post_hash text default '', post_result text default '', PRIMARY KEY (post_id) ) $charset_collate; "; dbDelta( $sql_create_table ); } add_filter('aimogen_model_fallback', 'aimogen_fallback_model_detect', 10, 3); function aimogen_fallback_model_detect($model, $error, $aicontent) { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (isset($aimogen_Main_Settings['fallback_models']) && trim($aimogen_Main_Settings['fallback_models']) != '') { $fallback_arr = preg_split('/\r\n|\r|\n/', trim($aimogen_Main_Settings['fallback_models'])); $fallback_arr = array_map('trim', $fallback_arr); $fallback_arr = array_filter($fallback_arr); if(empty($fallback_arr)) { return $model; } $fallback = $fallback_arr[array_rand($fallback_arr)]; return $fallback; } return $model; } register_deactivation_hook(__FILE__,'aimogen_deactivate_plugin'); function aimogen_deactivate_plugin() { global $wpdb; $wpdb->query("DROP TABLE IF EXISTS $wpdb->aimogent_shortcode_rez");// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.NoCaching $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (isset($aimogen_Main_Settings['clear_omni']) && $aimogen_Main_Settings['clear_omni'] == 'on') { delete_option('aimogen_processed_keywords'); } } function aimogen_get_item_table_columns(){ return array( 'post_id'=> '%d', 'post_hash' => '%s', 'post_result'=> '%s' ); } add_action( 'init', 'aimogen_register_aggregated_feed_table', 1 ); add_action( 'switch_blog', 'aimogen_register_aggregated_feed_table' ); function aimogen_register_aggregated_feed_table() { global $wpdb; $wpdb->aimogent_shortcode_rez = "{$wpdb->prefix}aimogent_shortcode_rez"; } register_activation_hook(__FILE__, 'aimogen_check_version'); function aimogen_check_version() { if (!function_exists('curl_init')) { wp_die( esc_html__('Please enable the cURL PHP extension. Contact your hosting provider for assistance.', 'aimogen'), esc_html__('Plugin Activation Error', 'aimogen'), array('back_link' => true) ); } if (!current_user_can('activate_plugins')) { wp_die( esc_html__('You are not allowed to activate plugins!', 'aimogen'), esc_html__('Plugin Activation Error', 'aimogen'), array('back_link' => true) ); } $php_version_required = '5.0'; $wp_version_required = '2.7'; if (version_compare(PHP_VERSION, $php_version_required, '<')) { deactivate_plugins(plugin_basename(__FILE__)); wp_die( sprintf( /* translators: %1$s is the required PHP version, %2$s is the current version */ esc_html__('This plugin requires PHP version %1$s or higher. Your current version is %2$s.', 'aimogen'), esc_html($php_version_required), PHP_VERSION ), esc_html__('Plugin Activation Error', 'aimogen'), array('back_link' => true) ); } global $wp_version; if (version_compare($wp_version, $wp_version_required, '<')) { deactivate_plugins(plugin_basename(__FILE__)); wp_die( sprintf( /* translators: %1$s is the required WordPress version, %2$s is the current version */ esc_html__('This plugin requires WordPress version %1$s or higher. Your current version is %2$s.', 'aimogen'), esc_html($wp_version_required), esc_html($wp_version) ), esc_html__('Plugin Activation Error', 'aimogen'), array('back_link' => true) ); } } function aimogen_process_replicate_images($url, $headers) { $images = array(); $response = wp_remote_get($url, array('headers' => $headers)); if(is_wp_error($response)){ throw new Exception('Error in Replicate access: ' . esc_html($response->get_error_message())); } else{ $body = json_decode($response['body'],true); if($body['status'] == 'succeeded'){ $images = $body['output']; } elseif($body['status'] == 'processing' || $body['status'] == 'starting'){ sleep(1); $images = aimogen_process_replicate_images($url, $headers); } elseif($body['status'] == 'failed'){ throw new Exception('Replicate returned and error: ' . esc_html($body['error'])); } else{ throw new Exception('Replicate - something went wrong'); } } return $images; } function aimogen_resizeImageStringToMultipleOf64($imageString, $stable_model) { $allowedDimensions = [ 'stable-diffusion-xl-1024-v1-0' => [ [1024, 1024], [1152, 896], [1216, 832], [1344, 768], [1536, 640], [640, 1536], [768, 1344], [832, 1216], [896, 1152] ] ]; $maxPixels = 1048576; $minPixels = 262144; $factor = 64; if(!function_exists('imagecreatefromstring')) { return false; } $srcImage = imagecreatefromstring($imageString); if (!$srcImage) { return false; } $width = imagesx($srcImage); $height = imagesy($srcImage); $newWidth = round($width / $factor) * $factor; $newHeight = round($height / $factor) * $factor; while (($newWidth * $newHeight) > $maxPixels) { $newWidth -= $factor; $newHeight -= $factor; } while (($newWidth * $newHeight) < $minPixels) { $newWidth += $factor; $newHeight += $factor; } if (array_key_exists($stable_model, $allowedDimensions)) { $closest = null; $closestDiff = PHP_INT_MAX; foreach ($allowedDimensions[$stable_model] as list($allowedWidth, $allowedHeight)) { $diff = abs($newWidth - $allowedWidth) + abs($newHeight - $allowedHeight); if ($diff < $closestDiff) { $closestDiff = $diff; $closest = [$allowedWidth, $allowedHeight]; } } if ($closest !== null) { list($resizeWidth, $resizeHeight) = $closest; } else { $resizeWidth = $newWidth; $resizeHeight = $newHeight; } } else { $resizeWidth = $newWidth; $resizeHeight = $newHeight; } $newImage = imagecreatetruecolor($resizeWidth, $resizeHeight); imagecopyresampled($newImage, $srcImage, 0, 0, 0, 0, $resizeWidth, $resizeHeight, $width, $height); ob_start(); imagejpeg($newImage); $newImageString = ob_get_clean(); imagedestroy($srcImage); imagedestroy($newImage); return $newImageString; } function aimogen_sanitize_text_field($input) { return $input; } function aimogen_transformFileName($url) { $path = wp_parse_url($url, PHP_URL_PATH); $originalFileName = pathinfo($path, PATHINFO_FILENAME); return $originalFileName; } function aimogen_list_stability_engines() { $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); if (empty($aimogen_Main_Settings['stability_app_id'])) { aimogen_log_to_file('You need to enter a Stability.AI API key in the plugin\'s "Settings" menu to use this feature!'); return false; } $appids = preg_split('/\r\n|\r|\n/', trim($aimogen_Main_Settings['stability_app_id'])); $appids = array_filter($appids); $token = apply_filters('aimogen_stability_api_key', $appids[array_rand($appids)]); $url = 'https://api.stability.ai/v1/engines/list'; $args = [ 'method' => 'GET', 'timeout' => 20, 'sslverify' => false, 'headers' => [ 'Accept' => 'application/json', 'Authorization' => $token ] ]; $response = wp_remote_get($url, $args); if (is_wp_error($response)) { aimogen_log_to_file('Failed request: ' . $response->get_error_message()); return false; } $code = wp_remote_retrieve_response_code($response); $body = wp_remote_retrieve_body($response); if ($code != 200) { aimogen_log_to_file('Invalid return code from API: ' . $code); return false; } $json_resp = json_decode($body, true); if ($json_resp === null) { aimogen_log_to_file('Failed to decode AI response: ' . $body); return false; } aimogen_log_to_file( 'Results: ' . wp_json_encode( $json_resp ) ); return true; } function aimogen_sanitize_main_settings($input) { if (!is_array($input)) return aimogen_sanitize_text_field($input); $output = []; foreach ($input as $key => $value) { if ($key === 'openai_processing_region') { $value = aimogen_sanitize_text_field($value); $output[$key] = in_array($value, array('default', 'us', 'eu'), true) ? $value : 'default'; } elseif (is_array($value)) { $output[$key] = array_map('aimogen_sanitize_text_field', $value); } else { $output[$key] = aimogen_sanitize_text_field($value); } } return $output; } function aimogen_sanitize_spinner_settings($input) { return aimogen_sanitize_main_settings($input); } function aimogen_sanitize_limit_settings($input) { return aimogen_sanitize_main_settings($input); } function aimogen_sanitize_chatbot_settings($input) { return aimogen_sanitize_main_settings($input); } add_action('admin_init', 'aimogen_register_mysettings'); function aimogen_register_mysettings() { register_setting('aimogen_option_group', 'aimogen_Main_Settings', [ 'sanitize_callback' => 'aimogen_sanitize_main_settings' ]); register_setting('aimogen_option_group2', 'aimogen_Spinner_Settings', [ 'sanitize_callback' => 'aimogen_sanitize_spinner_settings' ]); register_setting('aimogen_option_group3', 'aimogen_Limit_Settings', [ 'sanitize_callback' => 'aimogen_sanitize_limit_settings' ]); register_setting('aimogen_option_group4', 'aimogen_Chatbot_Settings', [ 'sanitize_callback' => 'aimogen_sanitize_chatbot_settings' ]); if (is_multisite()) { if (!get_option('aimogen_Main_Settings')) { aimogen_activation_callback(TRUE); } } } add_action('wp_enqueue_scripts', 'aimogen_wp_load_files'); add_action('admin_enqueue_scripts', 'aimogen_wp_load_files'); add_action('admin_enqueue_scripts', 'aimogen_add_admin_scripts', 10, 1); function aimogen_wp_load_files() { $name = md5(get_bloginfo()); $reg_css_code = '.autox-thickbox.button{margin: 0 5px;}.automaticx-video-container{position:relative;padding-bottom:56.25%;height:0;overflow:hidden}.automaticx-video-container embed,.automaticx-video-container amp-youtube,.automaticx-video-container iframe,.automaticx-video-container object{position:absolute;top:0;left:0;width:100%;height:100%}.automaticx-dual-ring{width:10px;aspect-ratio:1;border-radius:50%;border:6px solid;border-color:#000 #0000;animation:1s infinite automaticxs1}@keyframes automaticxs1{to{transform:rotate(.5turn)}}#openai-chat-response{padding-top:5px}.openchat-dots-bars-2{width:28px;height:28px;--c:linear-gradient(currentColor 0 0);--r1:radial-gradient(farthest-side at bottom,currentColor 93%,#0000);--r2:radial-gradient(farthest-side at top ,currentColor 93%,#0000);background:var(--c),var(--r1),var(--r2),var(--c),var(--r1),var(--r2),var(--c),var(--r1),var(--r2);background-repeat:no-repeat;animation:1s infinite alternate automaticxdb2}@keyframes automaticxdb2{0%,25%{background-size:8px 0,8px 4px,8px 4px,8px 0,8px 4px,8px 4px,8px 0,8px 4px,8px 4px;background-position:0 50%,0 calc(50% - 2px),0 calc(50% + 2px),50% 50%,50% calc(50% - 2px),50% calc(50% + 2px),100% 50%,100% calc(50% - 2px),100% calc(50% + 2px)}50%{background-size:8px 100%,8px 4px,8px 4px,8px 0,8px 4px,8px 4px,8px 0,8px 4px,8px 4px;background-position:0 50%,0 calc(0% - 2px),0 calc(100% + 2px),50% 50%,50% calc(50% - 2px),50% calc(50% + 2px),100% 50%,100% calc(50% - 2px),100% calc(50% + 2px)}75%{background-size:8px 100%,8px 4px,8px 4px,8px 100%,8px 4px,8px 4px,8px 0,8px 4px,8px 4px;background-position:0 50%,0 calc(0% - 2px),0 calc(100% + 2px),50% 50%,50% calc(0% - 2px),50% calc(100% + 2px),100% 50%,100% calc(50% - 2px),100% calc(50% + 2px)}100%,95%{background-size:8px 100%,8px 4px,8px 4px,8px 100%,8px 4px,8px 4px,8px 100%,8px 4px,8px 4px;background-position:0 50%,0 calc(0% - 2px),0 calc(100% + 2px),50% 50%,50% calc(0% - 2px),50% calc(100% + 2px),100% 50%,100% calc(0% - 2px),100% calc(100% + 2px)}}'; wp_register_style( sanitize_key($name) . '-front-css', false, false, AIMOGEN_LITE_MAJOR_VERSION ); wp_enqueue_style( sanitize_key($name) . '-front-css' ); wp_add_inline_style( sanitize_key($name) . '-front-css', $reg_css_code ); } function aimogen_admin_load_main() { $name = md5(get_bloginfo()); wp_register_style(sanitize_key($name) . '-browser-style', plugins_url('styles/aimogen-browser.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-browser-style'); wp_register_style(sanitize_key($name) . '-custom-style', plugins_url('styles/coderevolution-style.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-custom-style'); wp_register_style(sanitize_key($name) . '-stylish-style', plugins_url('styles/aimogen-stylish.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-stylish-style'); wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('interface'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_enqueue_style('thickbox'); } function aimogen_admin_load_files() { $name = md5(get_bloginfo()); wp_register_style(sanitize_key($name) . '-browser-style', plugins_url('styles/aimogen-browser.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-browser-style'); wp_register_style(sanitize_key($name) . '-modern-style', plugins_url('styles/aimogen-modern.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-modern-style'); wp_register_style(sanitize_key($name) . '-custom-style', plugins_url('styles/coderevolution-style.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-custom-style'); wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('interface'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_enqueue_style('thickbox'); } function aimogen_admin_load_playground() { $name = md5(get_bloginfo()); wp_register_script(sanitize_key($name) . '-playground-script', plugins_url('scripts/playground.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_script(sanitize_key($name) . '-playground-script'); wp_localize_script(sanitize_key($name) . '-playground-script', 'aimogen_object', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('openai-ajax-nonce'), 'modelsvision' => aimogen_get_all_vision_models() )); } function aimogen_add_admin_scripts( $hook ) { global $post; if ( $hook == 'post-new.php' || $hook == 'post.php' ) { if ( $post && 'aimogen_personas' === $post->post_type ) { $name = md5(get_bloginfo()); wp_register_style(sanitize_key($name) . '-custom-persona-style', plugins_url('styles/aimogen-persona.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-custom-persona-style'); } } } function aimogen_admin_load_live_preview() { $name = md5(get_bloginfo()); wp_register_script(sanitize_key($name) . '-chat-live-preview-script', plugins_url('scripts/chat-live-preview.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_script(sanitize_key($name) . '-chat-live-preview-script'); wp_localize_script(sanitize_key($name) . '-chat-live-preview-script', 'aimogen_object', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('openai-ajax-nonce'), 'modelsvision' => aimogen_get_all_vision_models() )); wp_enqueue_media(); wp_enqueue_script( sanitize_key($name) . '-media-loader-js', plugins_url( 'scripts/media.js' , __FILE__ ), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION ); wp_localize_script(sanitize_key($name) . '-media-loader-js', 'aimogen_ajax_object', array( 'nonce' => wp_create_nonce('openai-single-nonce') )); wp_register_style(sanitize_key($name) . '-custom-persona-style', plugins_url('styles/aimogen-persona.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-custom-persona-style'); wp_enqueue_script('jquery-ui-sortable'); } function aimogen_admin_load_magic() { $name = md5(get_bloginfo()); wp_register_style(sanitize_key($name) . '-magic-style', plugins_url('styles/magic.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-magic-style'); } function aimogen_admin_load_assistants() { $name = md5(get_bloginfo()); wp_enqueue_media(); wp_register_script(sanitize_key($name) . '-assistants-script', plugins_url('scripts/assistants.js', __FILE__), array('jquery'), AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_script(sanitize_key($name) . '-assistants-script'); wp_localize_script(sanitize_key($name) . '-assistants-script', 'aimogen_object', array( 'ajax_url' => admin_url('admin-ajax.php'), 'maxfilesize' => wp_max_upload_size(), 'retrival_models' => AIMOGEN_RETRIEVAL_MODELS, 'nonce' => wp_create_nonce('openai-ajax-nonce'), 'singlenonce' => wp_create_nonce('openai-single-nonce') )); wp_register_style(sanitize_key($name) . '-assistants-style', plugins_url('styles/assistants.css', __FILE__), false, AIMOGEN_LITE_MAJOR_VERSION); wp_enqueue_style(sanitize_key($name) . '-assistants-style'); } function aimogen_do_bulk_post() { register_shutdown_function('aimogen_clear_flag_at_shutdown', '-1', ''); $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); $aimogen_Spinner_Settings = get_option('aimogen_Spinner_Settings', false); if (isset($aimogen_Main_Settings['rule_timeout']) && $aimogen_Main_Settings['rule_timeout'] != '') { $timeout = intval($aimogen_Main_Settings['rule_timeout']); } else { $timeout = 36000; } if (isset($aimogen_Main_Settings['enable_detailed_logging']) && $aimogen_Main_Settings['enable_detailed_logging'] == 'on') { aimogen_log_exec_time('Bulk Edit'); } { $query = array( ); if (isset($aimogen_Spinner_Settings['author_id']) && $aimogen_Spinner_Settings['author_id'] != '') { $query['author'] = $aimogen_Spinner_Settings['author_id']; } if (isset($aimogen_Spinner_Settings['author_name']) && $aimogen_Spinner_Settings['author_name'] != '') { $query['author_name'] = $aimogen_Spinner_Settings['author_name']; } $post_type = 'post'; if (isset($aimogen_Spinner_Settings['type_post']) && $aimogen_Spinner_Settings['type_post'] != '') { $post_type = trim($aimogen_Spinner_Settings['type_post']); $query['post_type'] = array_map('trim', explode(',', $aimogen_Spinner_Settings['type_post'])); } else { $query['post_type'] = 'post'; } if (isset($aimogen_Spinner_Settings['category_name']) && $aimogen_Spinner_Settings['category_name'] != '') { if($post_type === 'product') { $query['tax_query'] = array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $aimogen_Spinner_Settings['category_name'], ) ); } else { $query['category_name'] = $aimogen_Spinner_Settings['category_name']; } } if (isset($aimogen_Spinner_Settings['tag_name']) && $aimogen_Spinner_Settings['tag_name'] != '') { if($post_type === 'product') { if(isset($query['tax_query'])) { $query['tax_query'][] = array( 'taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $aimogen_Spinner_Settings['tag_name'], ); } else { $query['tax_query'] = array( array( 'taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $aimogen_Spinner_Settings['tag_name'], ) ); } } else { $query['tag'] = $aimogen_Spinner_Settings['tag_name']; } } if (isset($aimogen_Spinner_Settings['post_id']) && $aimogen_Spinner_Settings['post_id'] != '') { $postids = $aimogen_Spinner_Settings['post_id']; $postids = explode(',', $postids); $postids = array_map('trim', $postids); $query['post__in'] = $postids; } if (isset($aimogen_Spinner_Settings['post_name']) && $aimogen_Spinner_Settings['post_name'] != '') { $query['name'] = $aimogen_Spinner_Settings['post_name']; } if (isset($aimogen_Spinner_Settings['pagename']) && $aimogen_Spinner_Settings['pagename'] != '') { $query['pagename'] = $aimogen_Spinner_Settings['pagename']; } if (isset($aimogen_Spinner_Settings['year']) && $aimogen_Spinner_Settings['year'] != '') { $query['year'] = $aimogen_Spinner_Settings['year']; } if (isset($aimogen_Spinner_Settings['month']) && $aimogen_Spinner_Settings['month'] != '') { $query['monthnum'] = $aimogen_Spinner_Settings['month']; } if (isset($aimogen_Spinner_Settings['day']) && $aimogen_Spinner_Settings['day'] != '') { $query['day'] = $aimogen_Spinner_Settings['day']; } if (isset($aimogen_Spinner_Settings['post_parent']) && $aimogen_Spinner_Settings['post_parent'] != '') { $query['post_parent'] = $aimogen_Spinner_Settings['post_parent']; } if (isset($aimogen_Spinner_Settings['page_id']) && $aimogen_Spinner_Settings['page_id'] != '') { $query['page_id'] = $aimogen_Spinner_Settings['page_id']; } if (isset($aimogen_Spinner_Settings['max_nr']) && $aimogen_Spinner_Settings['max_nr'] != '') { $max_nr = intval($aimogen_Spinner_Settings['max_nr']); } else { $max_nr = 0; } if (isset($aimogen_Spinner_Settings['delay_request']) && $aimogen_Spinner_Settings['delay_request'] != '') { $delay_request = intval($aimogen_Spinner_Settings['delay_request']); } else { $delay_request = 0; } if (isset($aimogen_Spinner_Settings['max_posts']) && $aimogen_Spinner_Settings['max_posts'] != '') { if(intval($aimogen_Spinner_Settings['max_posts']) != -1 && $max_nr > intval($aimogen_Spinner_Settings['max_posts'])) { $query['posts_per_page'] = $max_nr; } else { $query['posts_per_page'] = $aimogen_Spinner_Settings['max_posts']; } } else { if($max_nr > 5) { $query['posts_per_page'] = $max_nr; } } $meta_query = []; if (isset($aimogen_Spinner_Settings['meta_name']) && $aimogen_Spinner_Settings['meta_name'] != '') { $meta_name = $aimogen_Spinner_Settings['meta_name']; $meta_value = isset($aimogen_Spinner_Settings['meta_value']) ? $aimogen_Spinner_Settings['meta_value'] : ''; if ($meta_value !== '') { $meta_query[] = [ 'key' => $meta_name, 'value' => $meta_value, 'compare' => '=', ]; } else { $meta_query[] = [ 'key' => $meta_name, 'compare' => 'EXISTS', ]; } } if (isset($aimogen_Spinner_Settings['search_offset']) && $aimogen_Spinner_Settings['search_offset'] != '') { $query['offset'] = $aimogen_Spinner_Settings['search_offset']; } if (isset($aimogen_Spinner_Settings['search_query']) && $aimogen_Spinner_Settings['search_query'] != '') { $query['s'] = $aimogen_Spinner_Settings['search_query']; } if (isset($aimogen_Spinner_Settings['order']) && $aimogen_Spinner_Settings['order'] != 'default') { $query['order'] = $aimogen_Spinner_Settings['order']; } if (isset($aimogen_Spinner_Settings['orderby']) && $aimogen_Spinner_Settings['orderby'] != 'default') { $query['orderby'] = $aimogen_Spinner_Settings['orderby']; } if (isset($aimogen_Spinner_Settings['featured_image']) && $aimogen_Spinner_Settings['featured_image'] != 'any') { if ($aimogen_Spinner_Settings['featured_image'] == 'with') { $meta_query[] = [ 'key' => '_thumbnail_id', 'compare' => 'EXISTS', ]; } elseif ($aimogen_Spinner_Settings['featured_image'] == 'without') { $meta_query[] = [ 'key' => '_thumbnail_id', 'compare' => 'NOT EXISTS', ]; } } if (isset($aimogen_Spinner_Settings['no_twice']) && $aimogen_Spinner_Settings['no_twice'] == 'on') { $custom_name = !empty($aimogen_Spinner_Settings['custom_name']) ? str_replace('%%current_date%%', gmdate('Y-m-d'), trim($aimogen_Spinner_Settings['custom_name'])) : 'aimogen_published'; $meta_query[] = [ 'key' => $custom_name, 'compare' => 'NOT EXISTS', ]; } if (!empty($meta_query)) { $query['meta_query'] = array_merge(['relation' => 'AND'], $meta_query); } if (isset($aimogen_Spinner_Settings['post_status']) && $aimogen_Spinner_Settings['post_status'] != '') { $query['post_status'] = array_map('trim', explode(',', $aimogen_Spinner_Settings['post_status'])); } else { $query['post_status'] = 'any'; } $processed = 0; $post_list = get_posts($query); if (isset($aimogen_Main_Settings['enable_detailed_logging'])) { aimogen_log_to_file('Found ' . count($post_list) . ' posts for this specific query.'); if(count($post_list) == 0) { aimogen_log_to_file('Query is: ' . wp_json_encode($query)); } } $current = 1; $display = count($post_list); if($display > $max_nr) { $display = $max_nr; } foreach ($post_list as $post) { if($max_nr > 0 && $processed == $max_nr) { break; } if (isset($aimogen_Main_Settings['enable_detailed_logging'])) { aimogen_log_to_file('Processing post ' . $current . '/' . $display . ', ID: ' . $post->ID); } $processed++; aimogen_do_post($post, true, false, false); $current++; if($delay_request > 0) { usleep($delay_request * 1000); } } } if($processed == 0) { return 'nochange'; } else { return 'ok'; } } function aimogen_do_bulk_post_test() { register_shutdown_function('aimogen_clear_flag_at_shutdown', '-1', ''); $aimogen_Main_Settings = get_option('aimogen_Main_Settings', false); $aimogen_Spinner_Settings = get_option('aimogen_Spinner_Settings', false); if (isset($aimogen_Main_Settings['rule_timeout']) && $aimogen_Main_Settings['rule_timeout'] != '') { $timeout = intval($aimogen_Main_Settings['rule_timeout']); } else { $timeout = 36000; } $ret_list = array(); { $query = array( ); if (isset($aimogen_Spinner_Settings['author_id']) && $aimogen_Spinner_Settings['author_id'] != '') { $query['author'] = $aimogen_Spinner_Settings['author_id']; } if (isset($aimogen_Spinner_Settings['author_name']) && $aimogen_Spinner_Settings['author_name'] != '') { $query['author_name'] = $aimogen_Spinner_Settings['author_name']; } $post_type = 'post'; if (isset($aimogen_Spinner_Settings['type_post']) && $aimogen_Spinner_Settings['type_post'] != '') { $post_type = trim($aimogen_Spinner_Settings['type_post']); $query['post_type'] = array_map('trim', explode(',', $aimogen_Spinner_Settings['type_post'])); } else { $query['post_type'] = 'post'; } if (isset($aimogen_Spinner_Settings['category_name']) && $aimogen_Spinner_Settings['category_name'] != '') { if($post_type === 'product') { $query['tax_query'] = array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $aimogen_Spinner_Settings['category_name'], ) ); } else { $query['category_name'] = $aimogen_Spinner_Settings['category_name']; } } if (isset($aimogen_Spinner_Settings['tag_name']) && $aimogen_Spinner_Settings['tag_name'] != '') { if($post_type === 'product') { if(isset($query['tax_query'])) { $query['tax_query'][] = array( 'taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $aimogen_Spinner_Settings['tag_name'], ); } else { $query['tax_query'] = array( array( 'taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $aimogen_Spinner_Settings['tag_name'], ) ); } } else { $query['tag'] = $aimogen_Spinner_Settings['tag_name']; } } if (isset($aimogen_Spinner_Settings['post_id']) && $aimogen_Spinner_Settings['post_id'] != '') { $postids = $aimogen_Spinner_Settings['post_id']; $postids = explode(',', $postids); $postids = array_map('trim', $postids); $query['post__in'] = $postids; } if (isset($aimogen_Spinner_Settings['post_name']) && $aimogen_Spinner_Settings['post_name'] != '') { $query['name'] = $aimogen_Spinner_Settings['post_name']; } if (isset($aimogen_Spinner_Settings['pagename']) && $aimogen_Spinner_Settings['pagename'] != '') { $query['pagename'] = $aimogen_Spinner_Settings['pagename']; } if (isset($aimogen_Spinner_Settings['year']) && $aimogen_Spinner_Settings['year'] != '') { $query['year'] = $aimogen_Spinner_Settings['year']; } if (isset($aimogen_Spinner_Settings['month']) && $aimogen_Spinner_Settings['month'] != '') { $query['monthnum'] = $aimogen_Spinner_Settings['month']; } if (isset($aimogen_Spinner_Settings['day']) && $aimogen_Spinner_Settings['day'] != '') { $query['day'] = $aimogen_Spinner_Settings['day']; } if (isset($aimogen_Spinner_Settings['post_parent']) && $aimogen_Spinner_Settings['post_parent'] != '') { $query['post_parent'] = $aimogen_Spinner_Settings['post_parent']; } if (isset($aimogen_Spinner_Settings['page_id']) && $aimogen_Spinner_Settings['page_id'] != '') { $query['page_id'] = $aimogen_Spinner_Settings['page_id']; } if (isset($aimogen_Spinner_Settings['max_nr']) && $aimogen_Spinner_Settings['max_nr'] != '') { $max_nr = intval($aimogen_Spinner_Settings['max_nr']); } else { $max_nr = 0; } if (isset($aimogen_Spinner_Settings['max_posts']) && $aimogen_Spinner_Settings['max_posts'] != '') { if(intval($aimogen_Spinner_Settings['max_posts']) != -1 && $max_nr > intval($aimogen_Spinner_Settings['max_posts'])) { $query['posts_per_page'] = $max_nr; } else { $query['posts_per_page'] = $aimogen_Spinner_Settings['max_posts']; } } else { if($max_nr > 5) { $query['posts_per_page'] = $max_nr; } } if (isset($aimogen_Spinner_Settings['search_offset']) && $aimogen_Spinner_Settings['search_offset'] != '') { $query['offset'] = $aimogen_Spinner_Settings['search_offset']; } if (isset($aimogen_Spinner_Settings['search_query']) && $aimogen_Spinner_Settings['search_query'] != '') { $query['s'] = $aimogen_Spinner_Settings['search_query']; } $meta_query = []; if (isset($aimogen_Spinner_Settings['meta_name']) && $aimogen_Spinner_Settings['meta_name'] != '') { $meta_name = $aimogen_Spinner_Settings['meta_name']; $meta_value = isset($aimogen_Spinner_Settings['meta_value']) ? $aimogen_Spinner_Settings['meta_value'] : ''; if ($meta_value !== '') { $meta_query[] = [ 'key' => $meta_name, 'value' => $meta_value, 'compare' => '=', ]; } else { $meta_query[] = [ 'key' => $meta_name, 'compare' => 'EXISTS', ]; } } if (isset($aimogen_Spinner_Settings['order']) && $aimogen_Spinner_Settings['order'] != 'default') { $query['order'] = $aimogen_Spinner_Settings['order']; } if (isset($aimogen_Spinner_Settings['orderby']) && $aimogen_Spinner_Settings['orderby'] != 'default') { $query['orderby'] = $aimogen_Spinner_Settings['orderby']; } if (isset($aimogen_Spinner_Settings['featured_image']) && $aimogen_Spinner_Settings['featured_image'] != 'any') { if ($aimogen_Spinner_Settings['featured_image'] == 'with') { $meta_query[] = [ 'key' => '_thumbnail_id', 'compare' => 'EXISTS', ]; } elseif ($aimogen_Spinner_Settings['featured_image'] == 'without') { $meta_query[] = [ 'key' => '_thumbnail_id', 'compare' => 'NOT EXISTS', ]; } } if (isset($aimogen_Spinner_Settings['no_twice']) && $aimogen_Spinner_Settings['no_twice'] == 'on') { $custom_name = !empty($aimogen_Spinner_Settings['custom_name']) ? str_replace('%%current_date%%', gmdate('Y-m-d'), trim($aimogen_Spinner_Settings['custom_name'])) : 'aimogen_published'; $meta_query[] = [ 'key' => $custom_name, 'compare' => 'NOT EXISTS', ]; } if (!empty($meta_query)) { $query['meta_query'] = array_merge(['relation' => 'AND'], $meta_query); } if (isset($aimogen_Spinner_Settings['post_status']) && $aimogen_Spinner_Settings['post_status'] != '') { $query['post_status'] = array_map('trim', explode(',', $aimogen_Spinner_Settings['post_status'])); } else { $query['post_status'] = 'any'; } $processed = 0; $post_list = get_posts($query); $current = 1; foreach ($post_list as $post) { if($max_nr > 0 && $processed == $max_nr) { break; } $processed++; $ret_list[] = '' . $post->ID . ''; $current++; } } if($processed == 0) { return 'nochange'; } else { return implode(',', $ret_list); } } function aimogen_filterClaudeForStream_local($handle) { //curl needed for STREAMING curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt curl_setopt($handle, CURLOPT_WRITEFUNCTION, function ($curl_info, $data) // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt { // cannot be escaped because of streaming // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped // added wp_strip_all_tags now! echo esc_html(wp_strip_all_tags( $data )); if (ob_get_length()) { ob_flush(); } flush(); return aimogen_strlen($data); }); } ?>