LIB-> //-------------------------------- // INIT public $LIB; public $VARS = []; public $SETTINGS = []; public $LANG = []; public $AC = []; public $AI = []; public $request; public $is_api_get = false; function __call($method, $arguments) { // return call_user_func_array(\Closure::bind($this->$method, $this, get_called_class()), $arguments); if ( $this->$method instanceof \Closure ) { return call_user_func_array(\Closure::bind($this->$method, $this, get_called_class()), $arguments); } if ( method_exists($this, $method) ||isset($this->$method) ) { return call_user_func_array([$this, $method], $arguments); } } //-------------------------------- // VARS function load_VARS__base() { // main $this->LIB->VARS['init_t_ms'] = (floor(microtime(true)*1000)); $this->LIB->VARS['init_timestamp'] = time(); $this->LIB->VARS['init_date'] = (gmdate('Y.m.d', time())); $this->LIB->VARS['init_time'] = (gmdate('H:i:s', time())); $this->LIB->VARS['init_date_time'] = (gmdate('Y.m.d H:i', time())); $this->LIB->VARS['init_date_time_s'] = (gmdate('Y.m.d H:i:s', time())); $this->LIB->VARS['DS'] = DIRECTORY_SEPARATOR; $this->LIB->VARS['name'] = []; $this->LIB->VARS['name']['code'] = 'ai_gpt_tools'; $this->LIB->VARS['name']['_code'] = '_'.$this->LIB->VARS['name']['code']; $this->LIB->VARS['name']['_code_'] = '_'.$this->LIB->VARS['name']['code'].'_'; $this->LIB->VARS['name']['code_'] = $this->LIB->VARS['name']['code'].'_'; $this->LIB->VARS['name']['code__'] = $this->LIB->VARS['name']['code'].'__'; $this->LIB->VARS['name']['_code__'] = '_'.$this->LIB->VARS['name']['_code'].'__'; $this->LIB->VARS['name']['code-'] = $this->LIB->VARS['name']['code'].'-'; $this->LIB->VARS['name']['_code-'] = $this->LIB->VARS['name']['_code'].'-'; $this->LIB->VARS['name']['code/'] = $this->LIB->VARS['name']['code'].'/'; $this->LIB->VARS['name']['_code/'] = $this->LIB->VARS['name']['_code'].'/'; $this->LIB->VARS['name']['code-old'] = 'ai_gpt_tools'; $this->LIB->VARS['name']['code_r'] = 'ai_genprotools'; $this->LIB->VARS['name']['code_r-'] = $this->LIB->VARS['name']['code_r'].'-'; $this->LIB->VARS['name']['_code_r-'] = $this->LIB->VARS['name']['code_r'].'-'; $this->LIB->VARS['name']['title'] = 'AI GenProTools'; $this->LIB->VARS['name']['title-full'] = 'AI GenProTools for WooCommerce'; //!START-FOR-SYS-WP $this->LIB->VARS['name']['code-dir'] = basename(dirname(__DIR__)); $this->LIB->VARS['name']['code-route'] = $this->LIB->VARS['name']['code-dir'].'/'.$this->LIB->VARS['name']['code'].'.php'; $this->LIB->VARS['name']['code-premium'] = $this->LIB->VARS['name']['code-'].'addon-premium'; $this->LIB->VARS['name']['code-premium-dir'] = basename(dirname(__DIR__)).'-addon-premium'; $this->LIB->VARS['name']['code-premium-route'] = $this->LIB->VARS['name']['code-premium-dir'].'/'.$this->LIB->VARS['name']['code-premium'].'.php'; //!END-FOR-SYS-WP $this->LIB->VARS['name']['code-premium/'] = $this->LIB->VARS['name']['code-premium'].'/'; // screens mode $this->LIB->VARS['IS_SC_MODE'] = 0; // ver $this->LIB->VARS['SELF'] = []; $this->LIB->VARS['SELF']['VER'] = '2.8.0'; $this->LIB->VARS['SELF']['VER_INT'] = (int)str_replace('.','',$this->LIB->VARS['SELF']['VER']); $this->LIB->VARS['SELF']['VER_STR'] = 'v'.$this->LIB->VARS['SELF']['VER']; // logs $this->LIB->VARS['DEBUG']['LOG'] = []; // path $this->LIB->VARS['path'] = []; $this->LIB->VARS['path']['plugin_main_file'] = dirname(__DIR__).$this->LIB->VARS['DS'].$this->LIB->VARS['name']['code'].'.php'; $this->LIB->VARS['path']['plugin_dir'] = plugin_dir_path($this->LIB->VARS['path']['plugin_main_file']); $this->LIB->VARS['path']['plugin_dir-premium'] = plugin_dir_path(dirname(dirname(__DIR__)).$this->LIB->VARS['DS'].$this->LIB->VARS['name']['code-premium-dir'].$this->LIB->VARS['DS'].$this->LIB->VARS['name']['code-premium'].'.php'); $this->LIB->VARS['path']['plugin_libs'] = __DIR__.$this->LIB->VARS['DS']; $this->LIB->VARS['path']['plugin_basename'] = plugin_basename($this->LIB->VARS['path']['plugin_main_file']); $this->LIB->VARS['path']['tpl_dir'] = $this->LIB->VARS['path']['plugin_dir'].'tpl'.$this->LIB->VARS['DS']; $this->LIB->VARS['path']['tpl_dir-premium'] = $this->LIB->VARS['path']['plugin_dir-premium'].$this->LIB->VARS['DS'].'tpl'.$this->LIB->VARS['DS']; // exit; $upload_dir = wp_upload_dir(); $this->LIB->VARS['path']['upload_dir'] = $upload_dir['basedir'].$this->LIB->VARS['DS']; $this->LIB->VARS['path']['DIR_UD_NC'] = $this->LIB->VARS['path']['upload_dir'].$this->LIB->VARS['name']['code'].$this->LIB->VARS['DS']; $this->LIB->VARS['path']['DIR_LOGS'] = $this->LIB->VARS['path']['upload_dir'].$this->LIB->VARS['name']['code'].'/logs'.$this->LIB->VARS['DS']; $this->LIB->VARS['path']['DIR_TMP'] = $this->LIB->VARS['path']['upload_dir'].$this->LIB->VARS['name']['code'].'/tmp'.$this->LIB->VARS['DS']; // links $this->LIB->VARS['links'] = []; $this->LIB->VARS['links']['plugin_dir_url'] = plugin_dir_url($this->LIB->VARS['path']['plugin_dir'].$this->LIB->VARS['name']['code'].'.php'); $this->LIB->VARS['links']['admin_ajax_url'] = admin_url('admin-ajax.php'); // $this->LIB->VARS['links']['settings-form'] = 'options.php'; $this->LIB->VARS['links']['settings-form'] = admin_url('admin-ajax.php'); $this->LIB->VARS['links']['admin_settings_url'] = admin_url('admin.php?page='.$this->LIB->VARS['name']['code-old'].'-settings'); $this->LIB->VARS['links']['self-settings'] = admin_url('admin.php?page='.$this->LIB->VARS['name']['code-'].'settings'); // cssjs $this->LIB->VARS['cssjs']['path'] = 'assets/js/'; $this->LIB->VARS['cssjs']['is_min'] = 1; $this->LIB->VARS['cssjs']['is_min_str_addon'] = ($this->LIB->VARS['cssjs']['is_min']?'.min':''); // tpl $this->LIB->VARS['tpl_parts'] = []; // tpl shorts vars $this->LIB->VARS['NC'] = $this->LIB->VARS['name']['code-']; $this->LIB->VARS['NC-AC'] = $this->LIB->VARS['name']['code-'].'AC-'; $this->LIB->VARS['AC-pref'] = $this->LIB->VARS['name']['_code-'].'AC'; $this->LIB->VARS['AC-pref-'] = $this->LIB->VARS['AC-pref'].'-'; // keys // api $this->LIB->VARS['api']['key_name'] = 'self_api_key'; //$this->LIB->VARS['api']['key_auto-admin'] = sha1($this->LIB->VARS['name']['code'].$this->LIB->get__server_name().__FILE__.filectime(__FILE__)); if (1 ) { $this->LIB->VARS['api']['key_auto-admin'] = sha1($this->LIB->VARS['name']['code'].$this->LIB->get__server_name().__FILE__); } // WP $this->LIB->VARS['WP']['_wpnonce-pre'] = $this->LIB->VARS["name"]["code"].'-nonce'; $this->LIB->VARS['WP']['_wpnonce-key_name'] = 'nonce'; $this->LIB->VARS['WP']['_wpnonce'] = wp_create_nonce($this->LIB->VARS['WP']['_wpnonce-pre']); // xhr_get__access_arr $this->LIB->VARS['xhr_get__access_arr'] = []; $this->LIB->VARS['xhr_get__access_arr']['base'] = []; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'page__admin_settings'; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav__adminbar_btn_main'; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav__main_menu'; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav__help'; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav__AI_req'; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav__settings_modes'; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav__AI_req__section__get_data_ajax'; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav__AI_req__section__set_data_ajax'; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav_autocomplete__AI_get_api_urls'; $this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav_autocomplete__AI_get_models_list'; // support $this->LIB->VARS['support'] = []; $this->LIB->VARS['support']['link'] = 'support@sbitsoft.com'; $this->LIB->VARS['support']['link-home_site-value'] = 'aigenprotools.com'; $this->LIB->VARS['support']['link-home_site-href'] = 'https://aigenprotools.com'; // PREMIUM $this->LIB->VARS['IS_PLUGIN_PREMIUM_CONNECTED'] = false; $this->LIB->VARS['IS_PREMIUM'] = false; $this->LIB->VARS['PREMIUM_href'] = 'https://aigenprotools.com'; // other $this->LIB->VARS['is_xhr'] = $this->LIB->VARS['is_ajax'] = (stripos($this->LIB->request->server['REQUEST_URI'],'/admin-ajax.php')!==false); $this->LIB->VARS['global_is__process__AC'] = true; $this->LIB->VARS['global_is__noty_xhr'] = true; //--- $this->LIB->VARS['system_info'] = []; $this->LIB->VARS['system_info']['type'] = ''; $this->LIB->VARS['system_info']['version'] = 0; //!START-FOR-SYS-WP if ( defined('ABSPATH') &&function_exists('wp_get_wp_version') ) { $this->LIB->VARS['system_info']['type'] = 'wp'; $this->LIB->VARS['system_info']['version'] = wp_get_wp_version(); } //!END-FOR-SYS-WP //--- return $this->LIB->VARS; } function load_VARS__other() { $this->LIB->VARS['is_active_plugins'] = []; //!START-FOR-SYS-WP $this->LIB->VARS['is_active_plugins']['woocommerce'] = (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))&&class_exists('WooCommerce')); //!END-FOR-SYS-WP //--- //!START-FOR-SYS-WP @require_once(ABSPATH . 'wp-admin/includes/file.php'); WP_Filesystem(); //!END-FOR-SYS-WP //--- // settings $this->LIB->VARS['settings_key'] = $this->LIB->VARS['name']['code-'].'settings'; $this->LIB->VARS['_settings_key'] = $this->LIB->VARS['name']['_code-'].'settings'; $this->LIB->VARS['settings_key-'] = $this->LIB->VARS['settings_key'].'-'; $this->LIB->VARS['_settings_key-'] = $this->LIB->VARS['_settings_key'].'-'; $this->LIB->VARS['use_def'] = []; $this->LIB->VARS['use_def']['main']['premium'] = 1; $this->LIB->VARS['use_def']['main']['base'] = 1; $this->LIB->VARS['use_def']['main']['post'] = 1; // server params // set_time_limit $this->LIB->VARS['server']['set_time_limit'] = 7200; // other // action_types $this->LIB->VARS['action_types']['base_get'] = []; $this->LIB->VARS['action_types']['base_get']['get'] = 1; $this->LIB->VARS['action_types']['base_get']['get_if_no_have'] = 1; $this->LIB->VARS['action_types']['base_create'] = []; $this->LIB->VARS['action_types']['base_create']['create'] = 1; $this->LIB->VARS['action_types']['base_create']['create_if_no_have'] = 1; $this->LIB->VARS['action_types']['text'] = []; $this->LIB->VARS['action_types']['text']['create'] = 1; $this->LIB->VARS['action_types']['text']['create_if_no_have'] = 1; //--- // length_types $this->LIB->VARS['length_types']['all'] = []; $this->LIB->VARS['length_types']['all']['auto'] = 1; // AI auto // no length instructions $this->LIB->VARS['length_types']['all']['test'] = 1; $this->LIB->VARS['length_types']['all']['short'] = 1; $this->LIB->VARS['length_types']['all']['small'] = 1; $this->LIB->VARS['length_types']['all']['medium'] = 0; $this->LIB->VARS['length_types']['all']['large'] = 0; $this->LIB->VARS['length_types']['all']['huge'] = 0; $this->LIB->VARS['length_types']['all']['max'] = 0; //--- // settings_block_items $this->LIB->VARS['settings_block_items'] = []; $tmp = []; $tmp[$tmp_key='API_URL'] = [ 'key' => $tmp_key, 'type' => 'input', 'label' => $this->LIB->get_lang('text-'.$tmp_key.'-a'), 'is_listen' => true, ]; $tmp[$tmp_key='API_KEY'] = [ 'key' => $tmp_key, 'type' => 'input_protected', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, ]; $tmp[$tmp_key='API_MODEL'] = [ 'key' => $tmp_key, 'type' => 'input', 'label' => $this->LIB->get_lang('text-'.$tmp_key.'-a'), 'id' => '_'.$this->LIB->VARS['NC'].'nav_autocomplete-'.$tmp_key, 'is_listen' => true, ]; $tmp[$tmp_key='TEMPERATURE'] = [ 'key' => $tmp_key, 'type' => 'number', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'step' => '0.1', 'min' => '0', 'max' => '2', 'field_filter' => 'auto', 'is_listen' => true, 'is_advanced_mode' => true, ]; $tmp[$tmp_key='action_type'] = [ 'key' => $tmp_key, 'type' => 'select', 'label' => $this->LIB->get_lang('text-action'), 'is_listen' => true, ]; $tmp[$tmp_key='length_type'] = [ 'key' => $tmp_key, 'type' => 'select', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, ]; $tmp[$tmp_key='format'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_tag_premium' => true, ]; $tmp[$tmp_key='custom_comment'] = [ 'key' => $tmp_key, 'type' => 'custom_comment', 'label' => $this->LIB->get_lang('text-comment'), 'is_listen' => true, ]; // for all $tmp[$tmp_key='phase_stop'] = [ 'key' => $tmp_key, 'type' => 'number', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'step' => '1', 'min' => '0', 'field_filter' => 'auto', 'is_listen' => true, 'is_dev_mode' => true, ]; $tmp[$tmp_key='use_log'] = [ 'key' => $tmp_key, 'type' => 'input', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_dev_mode' => true, ]; $tmp[$tmp_key='is_AI_req'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_dev_mode' => true, ]; $tmp[$tmp_key='AI_req_backoff-strategy'] = [ 'key' => $tmp_key, 'type' => 'select', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_dev_mode' => true, ]; $tmp[$tmp_key='AI_req_backoff-strategy_num'] = [ 'key' => $tmp_key, 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'type' => 'number', 'step' => '1', 'min' => '2', 'is_listen' => true, 'is_dev_mode' => true, ]; $tmp[$tmp_key='AI_req_backoff-init_time'] = [ 'key' => $tmp_key, 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'type' => 'number', 'step' => '1', 'min' => '100', 'is_listen' => true, 'is_dev_mode' => true, ]; $tmp[$tmp_key='AI_req_backoff-attempts'] = [ 'key' => $tmp_key, 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'type' => 'number', 'step' => '1', 'min' => '2', 'is_listen' => true, 'is_dev_mode' => true, ]; $tmp[$tmp_key='AI_req_backoff-http_codes_trigger'] = [ 'key' => $tmp_key, 'type' => 'input', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_dev_mode' => true, ]; $tmp[$tmp_key='home_site'] = [ 'key' => $tmp_key, 'type' => 'external_link', 'label' => $this->LIB->get_lang('text-'.$tmp_key), ]; $tmp[$tmp_key='support_email'] = [ 'key' => $tmp_key, 'type' => 'email', 'label' => $this->LIB->get_lang('text-'.$tmp_key), ]; $tmp[$tmp_key='plugin_website'] = [ 'key' => $tmp_key, 'type' => 'link', 'label' => $this->LIB->get_lang('text-'.$tmp_key), ]; $tmp[$tmp_key='text_info_help'] = [ 'key' => $tmp_key, 'type' => 'text_info_help', // 'label' => '', ]; $tmp[$tmp_key='alert'] = [ 'key' => $tmp_key, 'type' => 'alert', // 'alert_type' => 'base', // 'label' => '', ]; $tmp[$tmp_key='premium_access_key'] = [ 'key' => $tmp_key, 'type' => 'input_protected', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_request2' => true, ]; $tmp[$tmp_key='use-site_desc'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_advanced_mode' => true, ]; $tmp[$tmp_key='use-desc_full'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_advanced_mode' => true, ]; $tmp[$tmp_key='use-desc_short'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_advanced_mode' => true, ]; $tmp[$tmp_key='use-tags'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_advanced_mode' => true, ]; $tmp[$tmp_key='is_fwrite_on_off'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_advanced_mode' => true, ]; $tmp[$tmp_key='is_fwrite_cron_on_off'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => false, 'is_advanced_mode' => true, 'is_disabled' => true, 'is_name_off' => true, 'is_tag_premium' => true, ]; $tmp[$tmp_key='is_cron_extended_dev_print_on_off'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_dev_mode' => true, ]; // for products $tmp[$tmp_key='check_name'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, // 'is_off' => true, // 'is_tag_future' => true, 'is_tag_premium' => true, // 'is_disabled' => true, // 'is_name_off' => true, ]; $tmp[$tmp_key='use-product_attr'] = [ 'key' => $tmp_key, 'type' => 'checkbox', 'label' => $this->LIB->get_lang('text-'.$tmp_key), 'is_listen' => true, 'is_advanced_mode' => true, 'is_tag_premium' => true, // 'is_disabled' => true, // 'is_name_off' => true, ]; $this->LIB->VARS['settings_block_items'] = $tmp; //--- // settings__defaults $this->LIB->VARS['settings__defaults'] = []; $this->LIB->VARS['settings__defaults']['main'] = []; $tmp_key = 'setting_mode'; $tmp = []; $tmp['setting_mode_key'] = 'main'; $tmp['title'] = $this->LIB->get_lang('text-setting_mode-main'); $tmp['setting_mode_id'] = 0; $tmp['status'] = true; $this->LIB->VARS['settings__defaults']['main'][$tmp_key] = $tmp; $tmp_key = 'base'; $tmp = []; $tmp['list'] = []; $tmp['list']['IS_ADVANCED_MODE'] = false; $tmp['list']['IS_DEV_MODE'] = false; $this->LIB->VARS['settings__defaults']['main'][$tmp_key] = $tmp; $tmp_key = 'AI'; $tmp['status'] = true; $tmp['list'] = []; $tmp['list']['AI_connect'] = []; $tmp['list']['AI_connect']['API_URL'] = 'https://api.openai.com/v1'; $tmp['list']['AI_connect']['API_KEY'] = ''; $tmp['list']['AI_connect']['API_MODEL'] = 'gpt-4o-mini'; //$tmp['list']['AI_connect']['TEMPERATURE'] = 1.1; $tmp['list']['AI_connect']['TEMPERATURE'] = 1; $tmp['list']['AI_connect']['is_AI_req'] = true; $tmp['list']['AI_req_backoff'] = []; $tmp['list']['AI_req_backoff']['AI_req_backoff-strategy'] = 'exponential'; $tmp['list']['AI_req_backoff']['AI_req_backoff-strategy_num'] = 3; $tmp['list']['AI_req_backoff']['AI_req_backoff-attempts'] = 6; $tmp['list']['AI_req_backoff']['AI_req_backoff-init_time'] = 100; $tmp['list']['AI_req_backoff']['AI_req_backoff-http_codes_trigger'] = '429'; $this->LIB->VARS['settings__defaults']['main'][$tmp_key] = $tmp; $tmp_key = 'post'; $tmp = []; $tmp['status'] = true; $tmp['list'] = []; $tmp['list']['name'] = [ 'status' => 1, 'custom_comment' => '', 'action_type' => 'get_if_no_have', 'TEMPERATURE' => '0', 'use-site_desc' => true, 'use-desc_full' => true, 'use-tags' => true, 'use-seo_url' => true, 'use_log' => '', ]; $tmp['list']['desc_full'] = [ 'status' => 1, 'custom_comment' => '', 'action_type' => 'create_if_no_have', 'length_type' => 'auto', // 'rewrite' => false, // if_have // 'extend' => false, // if_have 'format' => true, 'TEMPERATURE' => '0', 'use-site_desc' => true, 'use-tags' => true, 'use-product_attr' => true, 'phase_stop' => 0, 'use_log' => '', ]; $tmp['list']['tags'] = [ 'status' => 1, 'custom_comment' => '', 'action_type' => 'get_if_no_have', 'TEMPERATURE' => '0', 'use-site_desc' => true, 'use-desc_full' => true, 'use-product_attr' => true, 'use_log' => '', ]; $tmp['list']['seo_url'] = [ 'status' => 1, 'custom_comment' => '', 'action_type' => 'get_if_no_have', 'TEMPERATURE' => '0', 'use_log' => '', ]; $this->LIB->VARS['settings__defaults']['main'][$tmp_key] = $tmp; $tmp_key = 'product'; $tmp = []; $tmp['status'] = true; $tmp['list']['name'] = [ 'status' => 1, 'custom_comment' => '', 'action_type' => 'get_if_no_have', 'check_name' => true, 'TEMPERATURE' => '0', // 'use_desc_short' => true, // 'use_desc_full' => true, // 'use_tags' => true, 'use_log' => '', ]; $tmp['list']['desc_full'] = [ 'status' => 1, 'custom_comment' => '', 'action_type' => 'create_if_no_have', 'length_type' => 'auto', // 'rewrite' => false, // if_have // 'extend' => false, // if_have 'format' => true, 'TEMPERATURE' => '0', 'use-site_desc' => true, 'use-desc_short' => true, 'use-tags' => true, 'use-product_attr' => true, 'phase_stop' => 0, 'use_log' => '', ]; $tmp['list']['desc_short'] = [ 'status' => 1, 'custom_comment' => '', 'action_type' => 'get_if_no_have', // 'length_type' => 'auto', 'TEMPERATURE' => '0', 'use-site_desc' => true, 'use-desc_full' => true, 'use-tags' => true, 'use-product_attr' => true, // 'phase_stop' => 0, 'use_log' => '', ]; $tmp['list']['tags'] = [ 'status' => 1, 'custom_comment' => '', 'action_type' => 'get_if_no_have', 'TEMPERATURE' => '0', 'use-site_desc' => true, 'use-desc_full' => true, 'use-desc_short' => true, 'use-product_attr' => true, 'use_log' => '', ]; $tmp['list']['seo_url'] = [ 'status' => 1, 'custom_comment' => '', 'action_type' => 'get_if_no_have', 'TEMPERATURE' => '0', 'use_log' => '', ]; $this->LIB->VARS['settings__defaults']['main'][$tmp_key] = $tmp; $tmp_key = 'other_help'; $tmp = []; $tmp['status'] = true; $tmp['is_status_switch'] = false; $tmp['list'] = []; $tmp['list']['support'] = [ 'email' => '', ]; $tmp['list']['logs'] = [ 'is_fwrite_on_off' => true, 'is_fwrite_cron_on_off' => true, 'is_cron_extended_dev_print_on_off' => false, ]; $this->LIB->VARS['settings__defaults']['main'][$tmp_key] = $tmp; $tmp_key = 'premium'; $tmp = []; $tmp['status'] = true; $tmp['list'] = []; $tmp['list']['premium_access'] = [ 'premium_access_key' => '', 'premium_access_info_text-alert_type' => '', 'premium_access_info_text-alert_icon' => '', 'premium_access_info_text-alert_text' => '', 'premium_access_info_text-tags' => [], ]; $this->LIB->VARS['settings__defaults']['main'][$tmp_key] = $tmp; //--- // pre_settings_sections $setting_mode_key = 'main'; $this->LIB->VARS['pre_settings_sections'] = []; $tmp_key = 'AI'; $tmp = []; $tmp['is_status_switch'] = false; $tmp['list'] = []; $tmp['list']['AI_connect'] = 'col_l'; $tmp['list']['AI_req_backoff'] = 'col_r'; $this->LIB->VARS['pre_settings_sections'][$setting_mode_key][$tmp_key] = $tmp; $tmp_key = 'premium'; $tmp = []; $tmp['is_status_switch'] = false; $tmp['list'] = []; $tmp['list']['premium_access'] = 'col_l'; $this->LIB->VARS['pre_settings_sections'][$setting_mode_key][$tmp_key] = $tmp; $tmp_key = 'post'; $tmp = []; $tmp['is_status_switch'] = true; $tmp['is_for_gen'] = true; $tmp['list'] = []; $tmp['list']['name'] = 'col_l'; $tmp['list']['desc_full'] = 'col_l'; $tmp['list']['tags'] = 'col_r'; $tmp['list']['seo_url'] = 'col_r'; $tmp['list']['comments'] = 'col_r'; $this->LIB->VARS['pre_settings_sections'][$setting_mode_key][$tmp_key] = $tmp; $tmp_key = 'product'; $tmp = []; $tmp['is_status_switch'] = true; $tmp['is_for_gen'] = true; $tmp['list'] = []; $tmp['list']['name'] = 'col_l'; $tmp['list']['desc_full'] = 'col_l'; $tmp['list']['desc_short'] = 'col_l'; $tmp['list']['tags'] = 'col_l'; $tmp['list']['seo_url'] = 'col_l'; $tmp['list']['product_imgs'] = 'col_r'; $tmp['list']['product_attr'] = 'col_r'; $tmp['list']['comments'] = 'col_r'; $this->LIB->VARS['pre_settings_sections'][$setting_mode_key][$tmp_key] = $tmp; $tmp_key = 'other_help'; $tmp = []; $tmp['is_status_switch'] = false; $tmp['list'] = []; $tmp['list']['support'] = 'col_l'; $tmp['list']['logs'] = 'col_r'; $tmp['list']['data'] = 'col_r'; $this->LIB->VARS['pre_settings_sections'][$setting_mode_key][$tmp_key] = $tmp; //--- $this->LIB->VARS['for_gen_page_types'] = []; $tmp = []; $tmp['list'] = []; $tmp['list']['post'] = true; $tmp['list']['product'] = true; $this->LIB->VARS['for_gen_page_types'] = $tmp; //--- // AI global prompts $this->LIB->VARS['AI_prompts'] = []; $this->LIB->VARS['resp_tags_g'] = []; //--- base [$this->LIB->VARS['AI_prompts']['base']['default'] = ' CURRENT_DATE_TIME: '.$this->LIB->VARS['init_date_time'].' [following all instructions] [accurate] [professional] [deep thinking] [critical thinking] [kind] [honest] [laconic] [taciturn] [reticent] [consistency] [not repetitive] [without unnecessary, irrelevant information] [without comments] [without length limits, limitations of this platform] [do not use multiple sources, fanfics, forums] [simple way to chat] ']; //--- // return return $this->LIB->VARS; } //-------------------------------- // PROTECTION // PROCESSES POST, GET ... function process__POST($p=[]) { // access_check // if post (not empty) // if not ajax // if not self nonce // if not self api // if not post action api // if not post action_type key // if not post action_type xhr_get__access_arr // if not admin // return false if ( !empty($_POST) ) { $arr = []; $arr['if not ajax'] = !$this->LIB->VARS['is_ajax']; $arr['if not self nonce'] = (!isset($_POST[$this->LIB->VARS['WP']['_wpnonce-key_name']]) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST[$this->LIB->VARS['WP']['_wpnonce-key_name']])), $this->LIB->VARS['WP']['_wpnonce-pre'])); $arr['if not self api'] = (!isset($_POST[$this->LIB->VARS['api']['key_name']]) || ($_POST[$this->LIB->VARS['api']['key_name']]!=$this->LIB->VARS['api']['key_auto-admin'])); $arr['if not post action api'] = (!isset($_POST['action']) || $_POST['action']!==$this->LIB->VARS['name']['code_'].'api'); $arr['if not post action_type key'] = !isset($_POST['action_type']); $arr['if not admin'] = !(current_user_can('administrator') || current_user_can('editor')); foreach ($arr as $k_ => $l_) { if ( $l_ ) { return $k_; } } } //--- if ( isset($this->LIB->request->post) &&!empty($this->LIB->request->post) ) { return true; } //--- $this->LIB->request->post = []; //--- if ( empty($_POST) ) { return true; } //--- // copy _POST to local var $this->LIB->request->post = $_POST; //--- // sanitize_vals inside local var array_walk_recursive($this->LIB->request->post,function(&$v,$k) { $v = wp_kses_post(wp_unslash($v)); }); //--- return true; } function process__GET($url='') { $res = []; if ( isset($this->LIB->request->get) &&!empty($this->LIB->request->get) &&$url==='' ) { return $this->LIB->request->get; } $get = ''; if ($url!=='') { $pre_get = explode('?', $url); if (isset($pre_get[1])) {$get = $pre_get[1];} } else if (!empty(@$this->LIB->request->server['QUERY_STRING'])) { $get = @$this->LIB->request->server['QUERY_STRING']; } else { $get = @explode('?',$this->LIB->request->server['REQUEST_URI']); $get = (isset($get[1])?$get[1]:''); } if ( $get==='' ) { return $res; } $arr1 = explode('&', $get); foreach ($arr1 as $k_ => $l_) { $arr2 = explode('=', $l_); $res[$arr2[0]] = (isset($arr2[1])?$arr2[1]:''); } array_walk_recursive($res,function(&$v,$k) { $v = sanitize_text_field(wp_unslash($v)); }); if ($url==='') { $this->LIB->request->get = $res; } return $res; } function process__SERVER() { $res = []; if ( isset($this->LIB->request->server) &&!empty($this->LIB->request->server) ) { return $this->LIB->request->server; } $arr = [ 'REQUEST_URI', 'QUERY_STRING', 'HTTP_REFERER', 'SERVER_NAME', ]; foreach ($arr as $k_ => $l_) { $res[$l_] = (isset($_SERVER[$l_])?sanitize_text_field(wp_unslash($_SERVER[$l_])):''); } $this->LIB->request->server = $res; } //-------------------------------- // SETTINGS function load_SETTINGS($p=[]) { $p = $this->LIB->process__func_params([ 'setting_mode_key' => 'main', 'use_def' => true, ], func_get_args()); // $p['___'] //--- $res = false; $data = []; $get = get_option($this->LIB->VARS['_settings_key-'].$p['setting_mode_key']); if ($get) { $get = json_decode(base64_decode($get),true); } if ($get && is_array($get)) { $data = $get; } if ($p['setting_mode_key'] != 'main' && !$get) {return $res;} if ( $p['use_def']===true ) { $get_def = []; $get_def = $this->LIB->settings__defaults__get2($p['setting_mode_key']); $data = array_replace_recursive($get_def, $data); } else if ( is_array($p['use_def']) ) { $p['data'] = array_replace_recursive($p['use_def'], $p['data']); } $data['setting_mode']['setting_mode_key'] = $p['setting_mode_key']; if (!isset($data['setting_mode']['title'])||empty(trim($data['setting_mode']['title']))) { $data['setting_mode']['title'] = $p['setting_mode_key']; } $data = array_reverse($data); if ( !empty($data) ) { $res = true; } $this->LIB->SETTINGS[$p['setting_mode_key']] = $data; return $res; } function settings__set($p=[]) { $f = $this->LIB->process__func_name(__FUNCTION__); $p = $this->LIB->process__func_params([ 'setting_mode_key' => null, 'data' => [], 'use_def' => true, ], func_get_args()); // $p['___'] //--- $res = false; if (!$p['setting_mode_key']||empty(trim($p['setting_mode_key']))) {return false;}; //--- $is_strlen_error = false; array_walk_recursive($p['data'],function($l_,$k_) use($f,&$is_strlen_error) { if ( $is_strlen_error===true ) { return; } if ( is_string($l_) &&strlen($l_)>5000 // &&strlen($l_)>2 // for dev ) { $is_strlen_error = true; //$this->LIB->throw_new_log([ // 'on_off' => 1, // 'type' => 'critical_error', // 'tags' => [ // 'settings', // 'set', // '!strlen', // ], // 'is_json' => true, // 'is_noty' => true, // 'click_close' => true, // 'timeout' => 180000, // 'title' => $this->LIB->get_lang('error-code-3'), // 'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'', //]); } }); if ($is_strlen_error) {return false;}; //--- $get = get_option($this->LIB->VARS['_settings_key-'].$p['setting_mode_key']); if ($get) { $get = $this->LIB->b64j_decode($get); $p['data'] = array_replace_recursive($get, $p['data']); } if ( $p['use_def']===true ) { $get_def = []; $get_def = $this->LIB->settings__defaults__get2($p['setting_mode_key']); $p['data'] = array_replace_recursive($get_def, $p['data']); } else if ( is_array($p['use_def']) ) { $p['data'] = array_replace_recursive($p['use_def'], $p['data']); } $p['data']['setting_mode']['setting_mode_key'] = $p['setting_mode_key']; if (!isset($p['data']['setting_mode']['title'])||empty(trim($p['data']['setting_mode']['title']))) { $p['data']['setting_mode']['title'] = $p['setting_mode_key']; } $p['data'] = $this->LIB->b64j_encode($p['data']); $res = update_option($this->LIB->VARS['_settings_key-'].$p['setting_mode_key'], $p['data'], false); return $res; } function settings__rem($setting_mode_key=null) { if (!$setting_mode_key||empty(trim($setting_mode_key))) {return false;}; return delete_option($setting_mode_key); } function settings__defaults__get($setting_mode_key=null) { if ( $setting_mode_key &&!empty(trim($setting_mode_key)) &&isset($this->LIB->VARS['settings__defaults'][$setting_mode_key]) ) { $setting_mode_key = explode('-',$setting_mode_key)[0]; $res = $this->LIB->VARS['settings__defaults'][$setting_mode_key]; } else { $res = $this->LIB->VARS['settings__defaults']; } return $res; } function settings__defaults__get2($setting_mode_key=null) { $res = []; //--- if ( !$setting_mode_key ||empty(trim($setting_mode_key)) ) { return $res; } $setting_mode_key = explode('-',$setting_mode_key)[0]; if ( !isset($this->LIB->VARS['settings__defaults'][$setting_mode_key]) ) { return $res; } $res = $this->LIB->VARS['settings__defaults'][$setting_mode_key]; //--- return $res; } function nav__settings_modes__get__btn__cron__add($data=[]) { $data['tpl_path'] = 'parts/btn__cron__add'; return $this->LIB->get_tpl6($data); } function settings__block__get_item($args=[]) { $p = $p_def = $this->LIB->process__func_params([ 'key' => false, 'type' => '', 'alert_type' => '', 'icon' => '', 'label' => '', 'data' => '', 'value' => '', 'is_listen' => true, 'is_checked' => false, 'is_off' => false, 'is_premium_preview' => false, 'is_tag_premium' => false, 'is_advanced_mode' => false, 'is_tag_advanced_mode' => false, 'is_dev_mode' => false, 'is_tag_dev_mode' => false, ], func_get_args()); // $p['___'] //--- $res = []; if ($p['key']===false||!isset($this->LIB->VARS['settings_block_items'][$p['key']])) {return $res;} $p = array_merge($p, $this->LIB->VARS['settings_block_items'][$p['key']]); $p = array_merge($p, $args); if ( !$this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',]) &&$p['is_dev_mode'] ) { return $res; } if ( !$this->LIB->SETTINGS__get_item(['main','base','list','IS_ADVANCED_MODE',]) &&$p['is_advanced_mode'] ) { return $res; } $res = $p; //--- return $res; } function settings__block__get() { $f = $this->LIB->process__func_name(__FUNCTION__); // $f['name'] // $f['prefix'] // $f['arr'] $p = $this->LIB->process__func_params([ 'key' => '', 'list' => [], 'tpl_path' => 'parts/settings_blocks/arr', 'tpl_key' => '', 'icon' => '', 'lang_prefix' => 'text-settings_blocks-', 'title' => '', // 'data' => [], // 'type' => '', // 'label' => '', 'is_listen' => true, 'is_status_switch' => false, 'is_checked' => false, 'is_off' => false, 'is_premium_preview' => false, 'is_tag_premium' => false, 'is_tag_future' => false, 'is_integrate' => false, 'is_get_tpl' => false, 'tpl_is_tmp_cache' => false, 'if_advanced_mode' => false, 'if_dev_mode' => false, ], func_get_args()); // $p['___'] //--- $res = $p; $res['tpl'] = ''; if (!is_string($p['key'])||empty(trim($p['key']))) {return $res;} $fnames_arr = []; $fnames_arr[] = 'settings__block__'.$p['key'].(isset($this->LIB->VARS['tmp']['page_data_type'])?'__'.$this->LIB->VARS['tmp']['page_data_type']:''); $fnames_arr[] = 'settings__block__'.$p['key']; if ( $tmp_fname = $this->LIB->is_fname($fnames_arr) ) { $get = $this->LIB->$tmp_fname($p); } if (!isset($get)||$get===false||!is_array($get)) {return false;} $get = array_merge($p, $get); $get['list'] = $this->LIB->filter_arr($get['list']); if ( empty($get['list']) ) { return false; } if (empty(trim(($get['tpl_key'])))) { $get['tpl_key'] = $get['key']; } if (empty(trim(($get['title'])))) { $get['title'] = $this->LIB->get_lang($get['lang_prefix'].$get['key'].'-title'); } $res = $get; if ( $p['is_get_tpl'] ) { $get['tpl_is_tmp_cache'] = false; $res['tpl'] = $this->LIB->get_tpl6($get); } //--- return $res; } function page__admin_settings__pre_settings_sections($pre_settings_sections) { if ( !isset($this->LIB->VARS['pre_settings_sections'][$this->LIB->VARS['tmp']['setting_mode']]) ) { return $pre_settings_sections; } foreach ($this->LIB->VARS['pre_settings_sections'][$this->LIB->VARS['tmp']['setting_mode']] as $k_ => $l_) { $this->LIB->VARS['tmp']['page_data_type'] = $pre_settings_section_key = $k_; if ( isset($l_['is_dev_mode']) &&$l_['is_dev_mode'] &&!$this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',]) ) { continue; } foreach ($l_['list'] as $k_2 => $l_2) { $block_arr = []; $block_arr['key'] = $k_2; $block_arr = $this->LIB->settings__block__get($block_arr); if ( !$block_arr ||empty($block_arr) ) { continue; } $pre_settings_sections[$pre_settings_section_key]['data'][$l_2][$block_arr['key']] = $block_arr; } } //--- return $pre_settings_sections; } function SETTINGS__get_item() { // use: // $this->LIB->SETTINGS__get_item('main/post/list/desc_full') // $this->LIB->SETTINGS__get_item(['main','post','list','desc_full',]) // $LIB->SETTINGS__get_item('main/post/list/desc_full') // $LIB->SETTINGS__get_item(['main','post','list','desc_full',]) //--- $p = $this->LIB->process__func_params([ 'path' => 'all', 'is_get_def' => false, 'sep' => '/', ], func_get_args()); // $p['___'] //--- $is_def = $p['is_get_def']; $target_arr = $this->LIB->SETTINGS; if ( $is_def ) { $target_arr = $this->LIB->VARS['settings__defaults']; } //--- if ( is_string($p['path']) ) { $path_arr = explode($p['sep'],$p['path']); } //--- if ( is_array($p['path']) ) { $path_arr = $p['path']; $p['path'] = implode($p['sep'],$p['path']); } //--- if ( $p['path']==='all' ) { $res = $target_arr; return $res; } //--- $res = $this->LIB->array_get_value($target_arr, $p['path'], $p['sep']); //--- return $res; } function SETTINGS__change_item() { $p = $this->LIB->process__func_params([ 'path' => 'all', 'value' => '', 'sep' => '/', ], func_get_args()); // $p['___'] //--- if ( is_array($p['path']) ) { $p['path'] = implode($p['sep'],$p['path']); } //--- $res = $this->LIB->array_set_value($this->LIB->SETTINGS, $p['path'], $p['value'], $p['sep']); //--- return $res; } //-------------------------------- // FOR PAGES // FOR ACTIONS // LANG // ERRORS // LOGS function process__func_params($p=[],$args=[]) { if ( !empty($args) ) { if ( // all this checks important for correct func working with args and arr params! isset($args[0]) &&is_array($args[0]) &&count($args)===1 &&!isset($args[1]) &&!isset($args[0][0]) &&!isset($args[0][1]) ) { $p = array_merge($p, $args[0]); } else if ( isset($args[0]) ) { $p_k = array_keys($p); foreach($p_k as $k_ => $l_){ if ( isset($args[$k_]) ) { $p[$p_k[$k_]] = $args[$k_]; } } } else { $p = array_merge($p, $args); } } foreach($p as $k_ => $l_){ if ( is_string($l_) ) { $l_ = trim($l_); $p[$k_] = $l_; } } //--- return $p; } function process__func_name($p='') { $res = []; //--- $res['name'] = $p; $res['prefix'] = $res['name'].'__'; $res['arr'] = explode('__',$res['name']); //--- return $res; } function process__AC() { $res = []; //--- if ( (!isset($this->LIB->VARS['global_is__process__AC']) ||!$this->LIB->VARS['global_is__process__AC']) ) { return $res; } //--- if (isset($this->AC['noty']) && !empty($this->LIB->AC['noty'])) { $this->LIB->AC['noty'] = $this->process__AC_noty($this->LIB->AC['noty']); } if (!empty($this->LIB->AC)) { $res[$this->LIB->VARS['AC-pref']] = $this->LIB->AC; } //--- return $res; } function process__AC_noty($noty_arr = []) { foreach ($noty_arr as $k_ => $l_) { if ( isset($noty_arr[$k_]['is_process__AC_noty']) ) { continue; } if ( !isset($l_['type']) &&!isset($l_['title']) &&!isset($l_['text']) ) { unset($noty_arr[$k_]); continue; } //--- if ( !isset($l_['type_sub']) &&isset($l_['type']) ) { $l_['type_sub'] = $l_['type']; } else if ( !isset($l_['noty_type']) &&isset($l_['type']) ) { $l_['noty_type'] = $l_['type']; } //--- $tpl_data = []; $tpl_data['tpl_path'] = 'parts/noty'; $tpl_data['noty'] = $l_; $noty_arr[$k_]['data'] = $this->LIB->get_tpl6($tpl_data); $noty_arr[$k_]['is_process__AC_noty'] = true; } //--- return $noty_arr; } function get_lang($p=[]) { // get language text $p = $this->LIB->process__func_params([ 'str' => '', 'bool' => false, 'nl2br' => false, 'return_clean' => false, 'align_str_tabs' => true, ], func_get_args()); // $p['___'] //--- $res = ''; //--- if (isset($this->LIB->LANG[$p['str']]) && !empty(trim($this->LIB->LANG[$p['str']]))) { $res = $this->LIB->LANG[$p['str']]; } else if (stripos($p['str'], '-icon')!==false) { $res = (isset($this->LIB->LANG['icon-point'])?$this->LIB->LANG['icon-point']:''); } else if ($p['bool']) { $res = false; } else if (!$p['return_clean']) { $res = $p['str']; } if ( $p['nl2br'] ) { $res = nl2br($res); } if ( $p['align_str_tabs'] ) { $res = $this->LIB->align_str_tabs($res); } //--- return $res; } function get_log($p=[]) { $p = $this->LIB->process__func_params([ 'file' => '', 'ext' => 'json', ], func_get_args()); // $p['___'] //--- $res = $this->LIB->VARS['DEBUG']['LOG']; //--- if ( $p['file']==='' ) { return $res; } $re = '/\.'.$p['ext'].'$/m'; $subst = ''; $p['file'] = preg_replace($re, $subst, $p['file']); $tmp_fl_path = $this->LIB->VARS['path']['DIR_LOGS']; if ( $res = $this->LIB->fread_full_wp($tmp_fl_path.$p['file'].'.'.$p['ext']) ) { $res = json_decode($res,true); $this->LIB->VARS['DEBUG']['LOG'] = $res; } //--- return $res; } function get_log_tpl() { $res = ''; //--- $data = []; $data['tpl_path'] = 'parts/_DEV_DEBUG_LOG'; $data['tpl_is_tmp_cache'] = false; $res = $this->LIB->get_tpl6($data); //--- return $res; } function throw_new_log() { // log function // v5 //--- $f = $this->LIB->process__func_name(__FUNCTION__); // $f['name'] //--- $p = $this->LIB->process__func_params([ 'on_off' => true, 'data' => [], 'tags' => [], 'type' => 'log', // log // any // critical_error // error // warning // sucess 'is_noty' => false, // xhr only 'is_noty_print' => true, // if !xhr 'title' => false, 'text' => false, 'id' => false, 'click_close' => false, 'timeout' => false, // in sec // false // 0 // 60000 // 180000 // ... 'add_vars_debug' => $this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',]), 'is_print_on_off' => true, 'is_print' => false, // not xhr only 'print_only_keys' => [], 'is_json' => false, 'is_json_p' => false, 'is_fwrite_on_off' => ($this->LIB->SETTINGS__get_item(['main','other_help','list','logs','is_fwrite_on_off',])), 'is_fwrite' => false, 'fwrite_route' => '', 'fwrite_key' => '', 'fwrite_ext' => 'json', 'fwrite_open' => false, 'fwrite_close' => false, 'time' => (floor(microtime(true)*1000)), ], func_get_args()); // $p['___'] //--- if ( !$p['on_off'] ) { return $p; } //--- $res = $p; $res['dev_log_key'] = $this->LIB->VARS['init_t_ms'].'/'.$p['time']; if ( empty(trim($p['fwrite_route'])) ) { $res['fwrite_route'] = $res['dev_log_key'].($p['fwrite_key']!==''?'-'.$p['fwrite_key']:''); } $res['fwrite_route_full'] = $this->LIB->VARS['path']['DIR_LOGS'].$res['fwrite_route'].'.'.$p['fwrite_ext']; // $res['tags'] = array_merge([$this->LIB->VARS['name']['code'],$this->LIB->VARS['SELF']['VER_STR']],$res['tags']); $res['tags'] = array_merge([$this->LIB->get_lang('title'),$this->LIB->VARS['SELF']['VER_STR']],$res['tags']); $res['tags'] = $this->LIB->filter_arr($res['tags']); //--- if ( $p['type']==='critical_error' ||$p['type']==='error' ) { $res['is_error'] = true; } //--- if ( $p['is_noty'] &&(!(isset($this->LIB->is_api_get)&&$this->LIB->is_api_get) ||$this->LIB->get_headers_content_type()==='text/plain') ) { $p['is_noty'] = false; $p['is_print'] = true; } if ( $p['is_noty'] ) { $this->LIB->AC['noty'][] = $res; } if ( (isset($this->LIB->VARS['global_is__noty_xhr']) &&$this->LIB->VARS['global_is__noty_xhr']) && $p['is_noty'] &&$p['is_noty_print'] &&( $p['type']==='critical_error' ||$p['type']==='error' ) ) { $res = $this->LIB->process__AC(); if ( $p['type']==='critical_error' ||$p['type']==='error' ) { $res['is_error'] = true; } $this->LIB->output__xhr_get($res); } if ( $p['is_noty'] &&!$p['is_noty_print'] ) { return $res; } //--- if ( $p['add_vars_debug'] ) { $this->LIB->VARS['DEBUG']['LOG'][] = $res; } //--- if ( $p['is_fwrite_on_off'] &&$p['is_fwrite'] ) { $tmp_fdata = $this->LIB->j_encode($res, JSON_PRETTY_PRINT); $this->LIB->fwrite_wp($res['fwrite_route_full'], $tmp_fdata); } $res_arr = $res; if ( $p['is_print_on_off'] &&$p['is_print'] ) { if ( !empty($p['print_only_keys']) ) { if ( is_string($p['print_only_keys']) ) { $res['print_only_keys'] = $this->LIB->str_tags_to_arr($p['print_only_keys']); } foreach ($res['print_only_keys'] as $k_ => $l_) { if ( !isset($res[$l_]) ) { continue; } $res_arr[$l_] = $res[$l_]; } } else { $res_arr = $res; } if ( $p['is_json'] ) { $res_arr = $this->LIB->j_encode($res_arr); } if ( $this->LIB->get_headers_content_type()==='text/html' ) { print_r("\n
\n");print_r($res_arr);print_r("\n\n");
}
else
{
print_r("\n");print_r($res_arr);print_r("\n");
}
if
(
$p['type']==='critical_error'
)
{
exit;
}
}
//---
return $res_arr;
}
function output__xhr_get($data) {
print_r($this->LIB->j_encode($data, true));
exit;
}
//--------------------------------
// PAGES DATA
function load_DATA() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$p = $this->LIB->process__func_params([
'page_type' => '',
], func_get_args());
// $p['___']
//---
$res = '';
$tmp_fnames_arr = [
implode('__',[$f['name'],$p['page_type'],]),
];
if
(
$tmp_fname = $this->LIB->is_fname($tmp_fnames_arr)
)
{
unset($p['page_type']);
$res = $this->LIB->$tmp_fname($p);
}
if
(
is_string($res)
)
{
$res = trim(wp_strip_all_tags($res));
}
//---
return $res;
}
// nav__main_menu
function nav__main_menu__get__item() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$p = $this->LIB->process__func_params([
'key' => false,
//---
'is_premium_preview' => false,
'is_tag_premium' => false,
'is_future_preview' => false,
'is_future_premium' => false,
'is_advanced_mode' => false,
'is_tag_advanced_mode' => false,
'is_dev_mode' => false,
'is_tag_dev_mode' => false,
], func_get_args());
// $p['___']
//---
$res = [];
$tmp_fname = $f['prefix'].$p['key'];
if
(
$p['key']===false
||!$tmp_fname = $this->LIB->is_fname([$tmp_fname])
)
{
return $res;
}
$p = array_merge($p, $this->LIB->$tmp_fname($p));
if
(
!$this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])
&&$p['is_dev_mode']
)
{
return $res;
}
if
(
!$this->LIB->SETTINGS__get_item(['main','base','list','IS_ADVANCED_MODE',])
&&$p['is_advanced_mode']
)
{
return $res;
}
$res = $p;
//---
return $res;
}
// help
function nav__help__sections__get() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$pre_sections = [];
$arr = [];
$arr[] = 'top_header';
$arr[] = 'disclaimer';
$arr[] = 'important';
$arr[] = 'minimum_req';
$arr[] = 'how_to_use';
$arr[] = 'advanced_mode';
$arr[] = 'some_options';
// $arr[] = 'ps';
foreach ($arr as $k_ => $l_) {
$tmp_fname = [
implode('__',[$f['name'],$l_,])
];
if
(
$tmp_fname = $this->LIB->is_fname($tmp_fname)
)
{
$pre_sections[$l_] = $this->LIB->$tmp_fname();
}
}
//---
return $pre_sections;
}
function nav__help__sections__get__top_header() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$res = [];
//---
$res['key'] = @$f['arr'][4];
//---
$res['top'] = [];
$res['top']['icon'] = $this->LIB->get_lang('icon-help');
$res['top']['title'] = $this->LIB->get_lang('text-help').'';
//---
return $res;
}
function nav__help__sections__get__disclaimer() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$res = [];
//---
$res['key'] = @$f['arr'][4];
//---
$res['top'] = [];
$res['top']['icon'] = $this->LIB->get_lang('icon-!');
$res['top']['title'] = $this->LIB->get_lang('text-'.$f['key']);
//---
$res['content'] = $this->LIB->get_lang('help-'.$f['key'].'-content');
$res['content'] = trim($res['content']);
//---
return $res;
}
function nav__help__sections__get__important() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$res = [];
//---
$res['key'] = @$f['arr'][4];
//---
$res['top'] = [];
$res['top']['icon'] = $this->LIB->get_lang('icon-!');
$res['top']['title'] = $this->LIB->get_lang('text-'.$f['key']);
//---
$res['content'] = $this->LIB->get_lang('help-'.$f['key'].'-content');
//---
return $res;
}
function nav__help__sections__get__minimum_req() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$res = [];
//---
$res['key'] = @$f['arr'][4];
//---
$res['top'] = [];
$res['top']['icon'] = $this->LIB->get_lang('icon-point');
$res['top']['title'] = $this->LIB->get_lang('text-'.$f['key']);
//---
$res['content'] = $this->LIB->get_lang('help-'.$f['key'].'-content');
//---
return $res;
}
function nav__help__sections__get__advanced_mode() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$res = [];
//---
$res['key'] = @$f['arr'][4];
//---
$res['top'] = [];
$res['top']['icon'] = $this->LIB->get_lang('icon-point');
$res['top']['title'] = $this->LIB->get_lang('text-'.$f['key']);
//---
$res['content'] = $this->LIB->get_lang('help-'.$f['key'].'-content');
//---
return $res;
}
function nav__help__sections__get__some_options() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$res = [];
//---
$res['key'] = @$f['arr'][4];
//---
$res['top'] = [];
$res['top']['icon'] = $this->LIB->get_lang('icon-point');
$res['top']['title'] = $this->LIB->get_lang('text-'.$f['key']);
//---
$res['content'] = $this->LIB->get_lang('help-'.$f['key'].'-content');
//---
return $res;
}
function nav__help__sections__get__how_to_use() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$res = [];
//---
$res['key'] = @$f['arr'][4];
//---
$res['top'] = [];
$res['top']['icon'] = $this->LIB->get_lang('icon-point');
$res['top']['title'] = $this->LIB->get_lang('text-'.$f['key']);
//---
$res['content'] = $this->LIB->get_lang('help-'.$f['key'].'-content');
//---
return $res;
}
// AI
//--- for query
function AI__chat__query($data=[]) {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
if
(
!$this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','is_AI_req',])
)
{
$this->LIB->throw_new_log([
'on_off' => true,
'type' => 'critical_error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'SETTINGS',
'!is_AI_req',
@$this->LIB->VARS['tmp']['section_key'],
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'id' => $this->LIB->arr_to_id_str([$this->LIB->VARS['name']['code'],'log',$f['name'],@$this->LIB->VARS['tmp']['section_key'],]),
]);
}
//---
if
(
!isset($data['chat'])
&&isset($this->LIB->VARS['tmp']['chat'])
)
{
$data['chat'] = $this->LIB->VARS['tmp']['chat'];
}
//---
if
(1
&&(!isset($data['chat']['model'])||empty(trim($data['chat']['model'])))
)
{
$this->LIB->throw_new_log([
'on_off' => true,
'type' => 'error',
'error_code' => 0,
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?basename(__FILE__, ".php"):''),
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!model',
@$this->LIB->VARS['tmp']['section_key'],
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
exit;
}
if
(1
&&(!isset($data['chat']['messages'])||empty($data['chat']['messages']))
)
{
$this->LIB->throw_new_log([
'on_off' => true,
'type' => 'error',
'error_code' => 0,
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!chat_messages',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
exit;
}
//---
foreach ($data['chat']['messages'] as $k_ => &$l_) {
if
(
is_array($l_['content'])
)
{
$l_['content'] = $this->LIB->align_str_tabs($l_['content']);
$l_['content'] = implode("\n",$l_['content']);
}
}
//---
$this->LIB->AI__connect_init();
if
(
isset($data['chat']['temperature'])
)
{
$data['chat']['temperature'] = (float) number_format($data['chat']['temperature'], 1);
}
if
(
empty(trim($this->LIB->SETTINGS__get_item(['main','AI','list','AI_req_backoff','AI_req_backoff-http_codes_trigger',])))
)
{
$this->LIB->SETTINGS__change_item(['main','AI','list','AI_req_backoff','AI_req_backoff-strategy_num',],1);
$this->LIB->SETTINGS__change_item(['main','AI','list','AI_req_backoff','AI_req_backoff-attempts',],1);
}
$data['query'] = $this->LIB->backoff([
'strategy' => $this->LIB->SETTINGS__get_item(['main','AI','list','AI_req_backoff','AI_req_backoff-strategy',]),
'strategy_num' => $this->LIB->SETTINGS__get_item(['main','AI','list','AI_req_backoff','AI_req_backoff-strategy_num',]),
'init_time' => $this->LIB->SETTINGS__get_item(['main','AI','list','AI_req_backoff','AI_req_backoff-init_time',]),
'attempts' => $this->LIB->SETTINGS__get_item(['main','AI','list','AI_req_backoff','AI_req_backoff-attempts',]),
'do' => function($p) use ($data, $f) {
// return false;
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
"before chat query",
],
'data' => $data,
'is_print_on_off' => false,
'is_fwrite' => true,
'fwrite_key' => (isset($this->LIB->VARS['tmp']['section_key'])?$this->LIB->VARS['tmp']['section_key']:''),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
$AI_resp=false;
try {$AI_resp = @$this->LIB->AI->chat($data['chat']);} catch (\Throwable $th) {}
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
"after chat query",
],
'data' => $AI_resp,
'is_print_on_off' => false,
'is_fwrite' => true,
'fwrite_key' => (isset($this->LIB->VARS['tmp']['section_key'])?$this->LIB->VARS['tmp']['section_key']:''),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
$AI_resp_header = $this->LIB->AI->getCURLInfo();
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
"AI_resp_header",
],
'data' => $AI_resp_header,
'is_print_on_off' => false,
'is_fwrite' => true,
'fwrite_key' => (isset($this->LIB->VARS['tmp']['section_key'])?$this->LIB->VARS['tmp']['section_key']:''),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
$http_codes_trigger = explode(',',$this->LIB->SETTINGS__get_item(['main','AI','list','AI_req_backoff','AI_req_backoff-http_codes_trigger',]));
$http_codes_trigger = $this->LIB->filter_arr($http_codes_trigger);
$AI_resp_jd = json_decode($AI_resp, true);
if
(
isset($AI_resp_header['http_code'])
&&in_array($AI_resp_header['http_code'], $http_codes_trigger)
&&(is_array($AI_resp_jd)
&&isset($AI_resp_jd['error'])
&&!in_array($AI_resp_jd['error']['code'],['insufficient_quota'])
&&!in_array($AI_resp_jd['error']['type'],['insufficient_quota']))
)
{
return false;
}
else
{
return $AI_resp;
}
},
]);
//---
$data = $this->LIB->AI__chat_data__process($data);
//---
if
(
isset($data['query_d']['model'])
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-AI_model');
$tmp['value'] = $data['query_d']['model'];
$this->LIB->VARS['resp_tags_g'][] = $tmp;
}
if
(
isset($data['query_d']['usage']['prompt_tokens'])
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-prompt_tokens');
$tmp['value'] = $data['query_d']['usage']['prompt_tokens'];
$this->LIB->VARS['resp_tags_g'][] = $tmp;
}
if
(
isset($data['query_d']['usage']['completion_tokens'])
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-completion_tokens');
$tmp['value'] = $data['query_d']['usage']['completion_tokens'];
$this->LIB->VARS['resp_tags_g'][] = $tmp;
}
if
(
isset($data['query_d']['usage']['total_tokens'])
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-total_tokens');
$tmp['value'] = $data['query_d']['usage']['total_tokens'];
$this->LIB->VARS['resp_tags_g'][] = $tmp;
}
//exit;
//---
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
"after AI__chat_data__process",
],
'data' => $data,
'is_print_on_off' => false,
'is_fwrite' => true,
'fwrite_key' => (isset($this->LIB->VARS['tmp']['section_key'])?$this->LIB->VARS['tmp']['section_key']:''),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
//---
$this->LIB->AI__chat__update($data['chat']['messages']);
//---
return $data;
}
function AI__chat_data__process($data) {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$data['errors'] = [];
$data['chat_bp'] = $data['chat']; // chat_before_process
$data['query_d'] = [];
$data['last_message'] = [];
$data['last_message']['role'] = false;
$data['last_message']['content'] = '';
if
(
isset($data['query'])
)
{
$data['query_d'] = json_decode($data['query'], true);
}
//---
if (!isset($data['query'])) {
$data['errors'][]['message'] = 'No answer from AI API';
}
if (empty($data['query_d'])) {
$data['errors'][]['message'] = 'Return empty or json_decode fail';
}
if (isset($data['query_d']['error'])) { // response error
$data['errors'][] = $data['query_d']['error'];
}
if (isset($data['errors'][0])) {
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
@$data['errors'][0]['type'],
@$data['errors'][0]['code'],
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-2'),
'text' => @$data['errors'][0]['message'],
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
//---
if
(
isset($data['query_d']['choices'][0]['message'])
)
{
$data['last_message'] = $data['chat']['messages'][] = $data['query_d']['choices'][0]['message'];
$data['last_message']['parced_arr'] = $this->LIB->AI__chat__parce($data['last_message']['content']);
}
//---
return $data;
}
function AI__chat__parce($str) {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$res = [];
//---
$re = '/^(?:[\t\s]+|)(?:\*\*|)START-(BOOL|NUMERIC_LIST|TABLE|)(?:-|)((?:[A-Za-z_0-9-]+))(?:\*\*|)([\S\s]+?)(?:\*\*|)END-(?:(?:[A-Za-z_0-9-]+))(?:\*\*|)/m';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
if
(
!empty($matches)
)
{
foreach ($matches as $k_ => $l_) {
$l_[1] = trim($l_[1]);
$l_[2] = trim($l_[2]);
$l_[3] = trim($l_[3]);
$val = $l_[3];
if
(1
&&!empty($l_[1])
&&$l_[1]==='BOOL'
)
{
$val = $this->LIB->bool_filter($l_[3]);
}
else
if
(1
&&!empty($l_[1])
&&$l_[1]==='NUMERIC_LIST'
)
{
$val = $this->LIB->numeric_list_to_arr($l_[3]);
}
else
if
(1
&&!empty($l_[1])
&&$l_[1]==='TABLE'
)
{
$val = $this->LIB->markdown_table_to_arr($l_[3]);
}
else
if
(1
&&!empty($l_[1])
&&$l_[1]==='MARKDOWN_TABLE'
)
{
$val = $this->LIB->markdown_table_to_arr($l_[3]);
}
if
(
is_string($val)
)
{
$val = trim($val);
$re = '~^```(?:html)|```$~si';
$subst = '';
$val = preg_replace($re, $subst, $val);
$val = trim($val);
}
$res[$l_[2]] = $val;
}
}
//---
if
(
empty($res)
)
{
$re = '/```((?:.|\n)*?[\n\r])((?:.|\n)*?)```/m';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
if
(
!empty($matches)
)
{
foreach ($matches as $k_ => $l_) {
$l_[1] = trim($l_[1]);
$l_[2] = trim($l_[2]);
$val = $l_[2];
$res[$l_[1]] = $val;
}
}
}
//---
if
(
empty($res)
)
{
$res['DATA'] = $str;
}
//---
return $res;
}
function AI__get_models_list() {
$is_tmp_fdata = 1;
$this->LIB->AI__connect_init();
$tmp_API_URL = rtrim(trim($this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','API_URL'])),'/');
$tmp_fdata_key = sha1($tmp_API_URL.$this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','API_KEY']));
//---
// tmp cache get
$tmp_fpath = $this->LIB->VARS['path']['DIR_TMP'].'models_list'.'.'.'json';
if
(
$is_tmp_fdata
&&file_exists($tmp_fpath)
&&filesize($tmp_fpath)!=0
&&(filemtime($tmp_fpath)+120)>=time()
)
{
$tmp_fdata = $this->LIB->fread_full_wp($tmp_fpath);
$tmp_fdata = json_decode($tmp_fdata, true);
if
(
$tmp_fdata['key'] === $tmp_fdata_key
&&$tmp_fdata['data']
)
{
$listModels = $tmp_fdata['data'];
return $listModels;
}
}
//---
// try {$listModels = @$this->LIB->AI->listModels();} catch (\Throwable $th) {}
$listModels = $this->LIB->AI->listModels();
$getCURLInfo = $this->LIB->AI->getCURLInfo();
$listModels = json_decode($listModels, true);
if
(
isset($listModels['data'])
&&!empty($listModels['data'])
&&(stripos($tmp_API_URL, 'api.openai.com')!==false)
)
{
foreach ($listModels['data'] as $k_ => $l_) {
if
(
!isset($l_['id'])
)
{
continue;
}
if
(
!preg_match('/^(?:gpt-|o1-)/', trim($l_['id']), $matches, PREG_OFFSET_CAPTURE, 0)
||preg_match('/-audio|-realtime|-image|-tts/is', $l_['id'], $matches, PREG_OFFSET_CAPTURE, 0)
)
{
unset($listModels['data'][$k_]);
}
}
}
//---
// tmp cache set
$tmp_fdata = [];
$tmp_fdata['key'] = $tmp_fdata_key;
$tmp_fdata['data'] = $listModels;
$tmp_fdata['getCURLInfo'] = $getCURLInfo;
$tmp_fdata = $this->LIB->j_encode($tmp_fdata);
$this->LIB->fwrite_wp($tmp_fpath, $tmp_fdata);
//---
return $listModels;
}
function nav__AI_req__process_post_keys() {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$p = $this->LIB->process__func_params([
'is_for_section' => false,
'is_check_keys' => true,
], func_get_args());
// $p['___']
//---
$arr = [];
if
(
$p['is_check_keys']
)
{
$arr[] = 'detect_page__key';
}
if
(
$p['is_for_section']
)
{
$arr[] = 'setting_mode_key';
$arr[] = 'page_type';
$arr[] = 'page_data_id';
$arr[] = 'section_key';
}
foreach ($arr as $k_ => $l_) {
if
(
!isset($this->LIB->request->post[$l_])
||!is_string($this->LIB->request->post[$l_])
||(is_string($this->LIB->request->post[$l_])&&trim($this->LIB->request->post[$l_])==='')
)
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!'.$l_,
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
// 'text' => @$data['errors'][0],
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
$this->LIB->VARS['tmp'][$l_] = $this->LIB->request->post[$l_];
}
//---
if
(
isset($this->LIB->request->post['detect_page__key'])
)
{
$this->LIB->VARS['detect_page'] = $this->LIB->b64j_decode($this->LIB->request->post['detect_page__key']);
}
if
(
!isset($this->LIB->VARS['tmp']['setting_mode_key'])
)
{
$this->LIB->VARS['tmp']['setting_mode_key'] = 'main';
}
if
(
!isset($this->LIB->VARS['tmp']['page_data_type'])
&&isset($this->LIB->VARS['detect_page']['page_type'])
)
{
$this->LIB->VARS['tmp']['page_data_type'] = $this->LIB->VARS['detect_page']['page_type'];
}
if
(
!isset($this->LIB->VARS['tmp']['page_data_id'])
&&isset($this->LIB->VARS['detect_page']['id'])
)
{
$this->LIB->VARS['tmp']['page_data_id'] = $this->LIB->VARS['detect_page']['id'];
}
if
(
!isset($this->LIB->VARS['tmp']['admin_link_edit'])
&&isset($this->LIB->VARS['detect_page']['admin_link_edit'])
)
{
$this->LIB->VARS['tmp']['admin_link_edit'] = $this->LIB->VARS['detect_page']['admin_link_edit'];
}
if
(
!isset($this->LIB->VARS['tmp']['section_key'])
)
{
$this->LIB->VARS['tmp']['section_key'] = '';
}
//---
// SETTINGS sync
if
(
$p['is_for_section']
)
{
if
(
isset($this->LIB->request->post[$this->LIB->VARS['_settings_key']])
&&is_array($this->LIB->request->post[$this->LIB->VARS['_settings_key']])
)
{
$this->LIB->SETTINGS = array_replace_recursive($this->LIB->SETTINGS, $this->LIB->request->post[$this->LIB->VARS['_settings_key']]);
}
$tmp = [
$this->LIB->VARS['tmp']['setting_mode_key'],
$this->LIB->VARS['tmp']['page_data_type'],
'list',
$this->LIB->VARS['tmp']['section_key']
];
$this->LIB->VARS['tmp']['section_settings']=(array)@$this->LIB->SETTINGS__get_item($tmp);
//---
if
(
isset($this->LIB->VARS['tmp']['section_settings']['TEMPERATURE'])
&&!empty(trim($this->LIB->VARS['tmp']['section_settings']['TEMPERATURE']))
&&!((int)@$this->LIB->VARS['tmp']['section_settings']['TEMPERATURE']<=0)
)
{
$this->LIB->SETTINGS['main']['AI']['list']['AI_connect']['TEMPERATURE'] = $this->LIB->VARS['tmp']['section_settings']['TEMPERATURE'];
}
}
}
function AI__get_api_urls() {
$res = [];
//---
$res[] = 'http://localhost:1000/v1';
$res[] = 'https://api.openai.com/v1';
// $res[] = 'https://api.x.ai/v1';
//---
return $res;
}
function settings__AI_connect_wrap($setting_mode_key) {
if
(
$setting_mode_key!=='main'
)
{
$arr = [
'API_URL',
'API_KEY',
'API_MODEL',
];
foreach ($arr as $k_ => $l_) {
if
(
!empty(trim($tmp = $this->LIB->SETTINGS__get_item([$this->LIB->VARS['tmp']['setting_mode_key'],'AI','list','AI_connect_wrap',$l_,])))
)
{
$this->LIB->SETTINGS__change_item(['main','AI','list','AI_connect',$l_,],$tmp);
}
}
$l_ = 'TEMPERATURE';
if
(
$tmp = $this->LIB->SETTINGS__get_item([$this->LIB->VARS['tmp']['setting_mode_key'],'AI','list','AI_connect_wrap',$l_,])
)
{
$this->LIB->SETTINGS__change_item(['main','AI','list','AI_connect',$l_,],$tmp);
}
}
}
function AI__connect_init() {
$this->LIB->AI = new OpenAi($this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','API_KEY']));
$this->LIB->AI__setBaseURL();
}
function AI__setBaseURL() {
$tmp = (rtrim(trim($this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','API_URL',])),'/'));
$tmp = trim($tmp);
$tmp = trim($tmp,'/');
$re = '~[^/]+$~s';
preg_match($re, $tmp, $matches, PREG_OFFSET_CAPTURE, 0);
if
(
isset($matches[0][0])
// &&$matches[0][0]!=='v1'
)
{
$this->LIB->AI->setAssistantsBetaVersion($matches[0][0]);
}
else
{
$this->LIB->AI->setAssistantsBetaVersion('');
}
$re = '~[^/]+$~s';
$subst = '';
$tmp = preg_replace($re, $subst, $tmp, 1);
$tmp = trim($tmp);
$tmp = trim($tmp,'/');
$this->LIB->AI->setBaseURL($tmp);
}
function AI__chat__get() {
$res = [];
if
(
isset($this->LIB->VARS['tmp']['chat'])
)
{
$res = $this->LIB->VARS['tmp']['chat'];
}
return $res;
}
function AI__chat__add__message($p=[]) {
if
(
!isset($this->LIB->VARS['tmp']['chat']['messages'])
)
{
$this->LIB->VARS['tmp']['chat']['messages'] = [];
}
if
(
!isset($this->LIB->VARS['tmp']['chat']['model'])
)
{
$this->LIB->VARS['tmp']['chat']['model'] = $this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','API_MODEL',]);
}
if
(
!isset($this->LIB->VARS['tmp']['chat']['temperature'])
)
{
$this->LIB->VARS['tmp']['chat']['temperature'] = $this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','TEMPERATURE',]);
}
if
(
isset($p['role'])
)
{
$this->LIB->VARS['tmp']['chat']['messages'][] = $p;
}
else
if
(
isset($p[0]['role'])
)
{
foreach ($p as $k_ => $l_) {
$this->LIB->VARS['tmp']['chat']['messages'][] = $l_;
}
}
}
function AI__chat__update($chat_messages_arr=[]) {
if
(
isset($chat_messages_arr['messages'])
)
{
$this->LIB->VARS['tmp']['chat'] = $chat_messages_arr;
}
else
{
$this->LIB->VARS['tmp']['chat']['messages'] = $chat_messages_arr;
}
}
function AI__chat__add__data($p='') {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['prefix'] = implode('__',[$f['arr'][0],$f['arr'][1],$f['arr'][2]]).'__';
// $f['___']
//---
$p = trim($p);
$p = str_replace('/','__',$p);
$fnames_arr = [
$f['prefix'].$p,
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$this->LIB->$tmp_fname();
}
}
function AI__chat__add__data__clean_all() {
unset($this->LIB->VARS['tmp']['chat']);
}
function AI__chat__add__data__system() {
$tmp = [];
$tmp['role'] = 'system';
$tmp['content'] = [];
$tmp['content'][] = $this->LIB->VARS['AI_prompts']['base']['default'];
$this->LIB->AI__chat__add__message($tmp);
}
function AI__chat__add__data__section__request_type() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][5];
// $f['___']
//---
if
(1
&&isset($this->LIB->VARS['tmp']['page_data_type'])
&&isset($this->LIB->VARS['tmp']['section_key'])
)
{
$tmp = [];
$tmp['role'] = 'assistant';
$tmp['content'] = [];
$tmp['content'][] = '# Request type:';
$tmp['content'][] = ''.$this->LIB->VARS['tmp']['page_data_type'].' - '.$this->LIB->VARS['tmp']['section_key'];
$this->LIB->AI__chat__add__message($tmp);
}
}
function AI__chat__add__data__section__global_prompt() {
if
(
isset($this->LIB->request->post['sections']['name']['prompt'])
&&!empty(trim($this->LIB->request->post['sections']['name']['prompt']))
)
{
$tmp = [];
$tmp['role'] = 'user';
$tmp['content'] = [];
$tmp['content'][] = strtoupper('# USER REQUEST');
$tmp['content'][] = $this->LIB->request->post['sections']['name']['prompt'];
$this->LIB->AI__chat__add__message($tmp);
}
}
function AI__chat__add__data__section__custom_comment() {
if
(
isset($this->LIB->VARS['tmp']['section_settings']['custom_comment'])
&&!empty(trim($this->LIB->VARS['tmp']['section_settings']['custom_comment']))
)
{
$tmp = [];
$tmp['role'] = 'user';
$tmp['content'] = [];
// $tmp['content'][] = strtoupper('# USER COMMENT TO REQUEST');
$tmp['content'][] = strtoupper('# TASK (BY USER, PRIORITY)');
$tmp['content'][] = $this->LIB->VARS['tmp']['section_settings']['custom_comment'];
$this->LIB->AI__chat__add__message($tmp);
}
}
function AI__chat__add__data__section__custom_comment2() {
if
(
isset($this->LIB->VARS['tmp']['section_settings']['custom_comment'])
&&!empty(trim($this->LIB->VARS['tmp']['section_settings']['custom_comment']))
)
{
$tmp = [];
$tmp['role'] = 'user';
$tmp['content'] = [];
$tmp['content'][] = $this->LIB->VARS['tmp']['section_settings']['custom_comment'];
$this->LIB->AI__chat__add__message($tmp);
}
}
function AI__chat__add__data__site_desc() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
if
(
!$this->LIB->SETTINGS__get_item([$this->LIB->VARS['tmp']['setting_mode_key'],$this->LIB->VARS['tmp']['page_data_type'],'list',$this->LIB->VARS['tmp']['section_key'],'use-'.$f['key']])
)
{
return;
}
//---
$get = $this->LIB->get_site_name();
if
(
!empty(trim($get))
)
{
$tmp = [];
$tmp['role'] = 'assistant';
$tmp['content'] = [];
$tmp['content'][] = '# TARGET WEBSITE NAME / TITLE';
$tmp['content'][] = trim($get);
$this->LIB->AI__chat__add__message($tmp);
}
$get = $this->LIB->get_site_desc();
if
(
!empty(trim($get))
)
{
$tmp = [];
$tmp['role'] = 'assistant';
$tmp['content'] = [];
$tmp['content'][] = '# TARGET WEBSITE DESCRIBTION / THEME';
$tmp['content'][] = trim($get);
$this->LIB->AI__chat__add__message($tmp);
}
}
//--- AI req sections/data
function nav__AI_req__section__get_pre_arr($p=[]) {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$p = $this->LIB->process__func_params([
'is_top' => 1,
'is_col_1' => 1,
'is_col_2' => 1,
], func_get_args());
// $p['___']
//---
$pre_section = [];
$section_post_key = 'sections['.$this->LIB->VARS['tmp']['section_key'].']';
$section_lang_prefix = 'text-AI_req_section-';
$pre_section['icon'] = $this->LIB->get_lang('icon-'.$this->LIB->VARS['tmp']['section_key']);
// top
if
(
$p['is_top']
)
{
$block_arr = [];
$block_arr['key'] = $this->LIB->VARS['tmp']['section_key'];
$block_arr['tpl_path'] = 'parts/AI_req_sections/top';
$block_arr['icon'] = $this->LIB->get_lang('icon-'.$this->LIB->VARS['tmp']['section_key']);
$block_arr['lang_prefix'] = $section_lang_prefix;
$block_arr['is_status_switch'] = true;
$block_arr['is_queue'] = false;
// $block_arr['data_request']['data'] = $this->LIB->VARS['links']['admin_ajax_url'];
$block_arr['data_request']['data'] = $this->get_url_by_type('admin_ajax_url');
$block_arr['title'] = $this->LIB->get_lang($block_arr['lang_prefix'].$this->LIB->VARS['tmp']['section_key'].'-title');
$pre_section['top'] = $block_arr;
}
// col_1
// data
if
(
$p['is_col_1']
)
{
$block_arr = [];
$block_arr['key'] = $this->LIB->VARS['tmp']['section_key'];
$block_arr['tpl_path'] = 'parts/AI_req_sections/'.$this->LIB->VARS['tmp']['section_key'];
$block_arr['lang_prefix'] = $section_lang_prefix;
$block_arr['section_post_key'] = $section_post_key;
$block_arr['is_global_prompt'] = true;
$block_arr['global_prompt_placeholder'] = $this->LIB->get_lang('help-placeholder-name-'.$this->LIB->VARS['tmp']['page_data_type'].'-global_prompt_placeholder');
$pre_section['col_1'] = $block_arr;
}
// col_2
// settings
if
(
$p['is_col_2']
)
{
$block_arr = [];
$block_arr['key'] = $this->LIB->VARS['tmp']['section_key'];
$block_arr['is_integrate'] = 1;
$block_arr['is_listen'] = 0;
$block_arr['is_get_tpl'] = 0;
$block_arr = $this->LIB->settings__block__get($block_arr);
$pre_section['col_2'] = $block_arr;
}
//---
$fnames_arr = [
$f['name'].'__'.$this->LIB->VARS['tmp']['section_key'].'__'.$this->LIB->VARS['tmp']['page_data_type'],
$f['name'].'__'.$this->LIB->VARS['tmp']['section_key'],
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$pre_section = $this->LIB->$tmp_fname($pre_section);
}
//---
return $pre_section;
}
function nav__AI_req__section__resp_arr() {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = [];
//---
// for dev // get from log
if
(1
&&isset($this->LIB->VARS['tmp']['section_settings']['use_log'])
&&!empty(trim($log_file = $this->LIB->VARS['tmp']['section_settings']['use_log']))
)
{
if
(
$get = $this->LIB->get_log($log_file.'-'.$this->LIB->VARS['tmp']['section_key'])
)
{
$res = $get['data'];
}
else
{
$this->LIB->throw_new_log([
'on_off' => true,
'type' => 'error',
'error_code' => 0,
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!get_log',
],
'is_noty' => true,
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
return $res;
}
if
(
isset($res['last_message']['parced_arr'])
)
{
$this->LIB->VARS['tmp']['resp_arr'] = $res['last_message']['parced_arr'];
}
return $res;
}
//---
if
(
!isset($this->LIB->VARS['tmp']['section_settings']['status'])
||!$this->LIB->VARS['tmp']['section_settings']['status']
)
{
$res['pass'] = true;
return $res;
}
//---
$fnames_arr = [
$f['prefix'].$this->LIB->VARS['tmp']['section_key'].'__'.$this->LIB->VARS['tmp']['page_data_type'],
$f['prefix'].$this->LIB->VARS['tmp']['section_key'],
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$res = $this->LIB->$tmp_fname();
}
else
{
$tmp_fname = $f['prefix'].'default';
$res = $this->LIB->$tmp_fname();
}
if
(
isset($res['last_message']['parced_arr'])
)
{
$this->LIB->VARS['tmp']['resp_arr'] = $res['last_message']['parced_arr'];
}
//---
return $res;
}
function nav__AI_req__section__resp_arr__default() {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['prefix'] = implode('__',[$f['arr'][0],$f['arr'][1],$f['arr'][2]]).'__';
// $f['___']
//---
$res = [];
if
(
(($this->LIB->VARS['tmp']['section_settings']['action_type']==='get_if_no_have'||$this->LIB->VARS['tmp']['section_settings']['action_type']==='create_if_no_have')
&&isset($this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$this->LIB->VARS['tmp']['section_key']])
&&!empty(trim($this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$this->LIB->VARS['tmp']['section_key']])))
)
{
$res['pass'] = true;
return $res;
}
//---
// add prrompts to chat arr
$tmp_fname = $f['prefix'].'get_prompt';
$this->LIB->$tmp_fname();
//---
$res = $this->LIB->AI__chat__query();
//---
return $res;
}
function nav__AI_req__section__get_prompt() {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$fnames_arr = [
$f['prefix'].$this->LIB->VARS['tmp']['section_key'].'__'.$this->LIB->VARS['tmp']['page_data_type'],
$f['prefix'].$this->LIB->VARS['tmp']['section_key'],
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$this->LIB->$tmp_fname();
}
else
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!get_prompt',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
}
function nav__AI_req__section__resp_tpl($data=[]) {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$data['tpl_key'] = $this->LIB->VARS['tmp']['section_key'];
return $this->LIB->get_tpl6($data);
}
function nav__AI_req__section__set() {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = [];
//---
if
(
!isset($this->LIB->request->post['sections']['name']['name'])
||empty(trim($this->LIB->request->post['sections']['name']['name']))
)
{
$this->LIB->throw_new_log([
'on_off' => true,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
$this->LIB->VARS['tmp']['page_data_type'],
'!name',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'text' => $this->LIB->get_lang('error-page_type_status_off'),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
//---
if
(
isset($this->LIB->is_nav__AI_req)
&&$this->LIB->is_nav__AI_req
&&!isset($this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']])
)
{
$res['pass'] = true;
return $res;
}
//---
$fnames_arr = [
$f['name'].'__'.$this->LIB->VARS['tmp']['section_key'].'__'.$this->LIB->VARS['tmp']['page_data_type'],
$f['name'].'__'.$this->LIB->VARS['tmp']['section_key'],
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$res = $this->LIB->$tmp_fname();
}
//---
return $res;
}
function nav__AI_req__section__note__resp_tags($data=[]) {
$res = '';
//---
if
(
isset($data['resp_arr']['query_d']['model'])
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-AI_model');
$tmp['value'] = $data['resp_arr']['query_d']['model'];
$data['list'][] = $tmp;
}
if
(
isset($data['resp_arr']['query_d']['usage']['prompt_tokens'])
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-prompt_tokens');
$tmp['value'] = $data['resp_arr']['query_d']['usage']['prompt_tokens'];
$data['list'][] = $tmp;
}
if
(
isset($data['resp_arr']['query_d']['usage']['completion_tokens'])
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-completion_tokens');
$tmp['value'] = $data['resp_arr']['query_d']['usage']['completion_tokens'];
$data['list'][] = $tmp;
}
if
(
isset($data['resp_arr']['query_d']['usage']['total_tokens'])
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-total_tokens');
$tmp['value'] = $data['resp_arr']['query_d']['usage']['total_tokens'];
$data['list'][] = $tmp;
}
if
(1
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-time');
$tmp['value'] = $this->LIB->get_elapsed_time($this->LIB->VARS['init_timestamp'], time());
$data['list'][] = $tmp;
}
//---
$data['list_for_copy_all'] = '';
if
(
isset($data['list'])
)
{
foreach ($data['list'] as $k_ => $l_) {
if
(
$k_
)
{
$data['list_for_copy_all'] .= "\t";
}
$data['list_for_copy_all'] .= $l_['value'];
}
}
//---
$data['tpl_path'] = 'parts/AI_req_sections/note__resp_tags';
$data['tpl_is_tmp_cache'] = false;
$res = $this->LIB->get_tpl6($data);
//---
return $res;
}
function nav__AI_req__section__note__resp_tags_g() {
$res = '';
//---
$data = [];
$data['list'] = [];
foreach ($this->LIB->VARS['resp_tags_g'] as $k_ => $l_) {
$data['list'][] = $l_;
}
if
(1
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-time');
$tmp['value'] = $this->LIB->get_elapsed_time($this->LIB->VARS['init_timestamp'], time());
$data['list'][] = $tmp;
}
//---
$data['list_for_copy_all'] = '';
if
(
isset($data['list'])
)
{
foreach ($data['list'] as $k_ => $l_) {
if
(
$k_
)
{
$data['list_for_copy_all'] .= "\t";
}
$data['list_for_copy_all'] .= $l_['value'];
}
}
//---
$data['tpl_path'] = 'parts/AI_req_sections/note__resp_tags';
$data['tpl_is_tmp_cache'] = false;
$res = $this->LIB->get_tpl6($data);
//---
return $res;
}
function nav__AI_req__section__notes($data=[]) {
$res = '';
//---
$data['tpl_path'] = 'parts/AI_req_sections/notes';
$data['tpl_is_tmp_cache'] = false;
$res = $this->LIB->get_tpl6($data);
//---
return $res;
}
//--- AI
function settings__block__AI_connect($block_arr) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$block_key = $f['key'] = @$f['arr'][2];
// $f['___']
//---
$block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'API_URL',
'label' => '* '. $this->LIB->get_lang('text-API_URL-a'),
'typing' => $this->LIB->j_encode([
'done_interval' => '1000',
]),
'autocomplete' => $this->LIB->j_encode([
'data' => $this->get_url_by_type('admin_ajax_url','filter_search={search}'),
'post' => [
$this->LIB->VARS['api']['key_name'] => $this->LIB->VARS['api']['key_auto-admin'],
$this->LIB->VARS['WP']['_wpnonce-key_name'] => $this->LIB->VARS['WP']['_wpnonce'],
'action' => $this->LIB->VARS['name']['code_'].'api',
'action_type' => 'nav_autocomplete__AI_get_api_urls',
'setting_mode_key' => $this->LIB->VARS['tmp']['setting_mode_key'],
],
]),
'autocomplete-paste_type' => 'html',
]);
$tmp = $this->LIB->SETTINGS__get_item('main/AI/list/AI_connect/API_KEY');
$tmp2 = preg_match('/^.+?openai\.com(?:.+?|)$/is', $this->LIB->SETTINGS__get_item('main/AI/list/AI_connect/API_URL'), $matches, PREG_OFFSET_CAPTURE, 0);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'API_KEY',
'attention_fancy_anim' => ($tmp2&&empty($tmp)?true:false),
'label' => '* '. $this->LIB->get_lang('text-API_KEY') .' '. $this->LIB->get_lang('text-tap_to_enter'),
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'API_MODEL',
'label' => '* '. $this->LIB->get_lang('text-API_MODEL-a'),
'typing' => $this->LIB->j_encode([
'done_interval' => '1000',
]),
'autocomplete' => $this->LIB->j_encode([
'data' => $this->get_url_by_type('admin_ajax_url','filter_search={search}'),
'post' => [
$this->LIB->VARS['api']['key_name'] => $this->LIB->VARS['api']['key_auto-admin'],
$this->LIB->VARS['WP']['_wpnonce-key_name'] => $this->LIB->VARS['WP']['_wpnonce'],
'action' => $this->LIB->VARS['name']['code_'].'api',
'action_type' => 'nav_autocomplete__AI_get_models_list',
'setting_mode_key' => $this->LIB->VARS['tmp']['setting_mode_key'],
],
]),
'autocomplete-paste_type' => 'html',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'TEMPERATURE',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'is_AI_req',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'text_info_help',
'label' => '',
'value' => nl2br($this->LIB->get_lang('help-init_setup')),
]);
//---
return $block_arr;
}
function settings__block__AI_req_backoff($block_arr) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$block_key = $f['key'] = @$f['arr'][2];
// $f['___']
//---
$block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key);
$block_arr['is_status_switch'] = false;
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'AI_req_backoff-strategy',
'data' => ['exponential' => 'exponential',],
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'AI_req_backoff-strategy_num',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'AI_req_backoff-attempts',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'AI_req_backoff-init_time',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'AI_req_backoff-http_codes_trigger',
]);
//---
return $block_arr;
}
//--- AI req sections get base
// data by type/name
function nav__main_menu__get__item__post($block_arr) {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$tmp = [];
$tmp['page_url'] = '';
$tmp['page_type'] = $f['key'];
$tmp['page_type_action'] = 'new';
$tmp['id'] = 0;
$block_arr['detect_page__key'] = $this->LIB->b64j_encode($tmp);
$block_arr['btn-icon'] = $this->LIB->get_lang('icon-plus');
$block_arr['btn-text'] = $this->LIB->get_lang('text-settings_sections-'.$f['key'].'-title');
$block_arr['btn-title'] = '(opening in modal)';
//---
return $block_arr;
}
function nav__main_menu__get__item__product($block_arr) {
//$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$tmp = [];
$tmp['page_url'] = '';
$tmp['page_type'] = $f['key'];
$tmp['page_type_action'] = 'new';
$tmp['id'] = 0;
$block_arr['detect_page__key'] = $this->LIB->b64j_encode($tmp);
$block_arr['btn-icon'] = $this->LIB->get_lang('icon-plus');
$block_arr['btn-text'] = $this->LIB->get_lang('text-settings_sections-'.$f['key'].'-title');
$block_arr['btn-title'] = '(opening in modal)';
//---
return $block_arr;
}
function nav__AI_req__sections__get__product() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$arr = [];
$arr[] = 'top_header';
$arr[] = 'name';
$arr[] = 'desc_full';
$arr[] = 'desc_short';
$arr[] = 'tags';
$arr[] = 'seo_url';
$arr[] = 'product_attr';
$arr[] = 'product_imgs';
$arr[] = 'comments';
foreach ($arr as $k_ => $l_) {
$this->LIB->VARS['tmp']['section_key'] = $l_;
$pre_section = $this->nav__AI_req__section__get_pre_arr();
$pre_sections[$this->LIB->VARS['tmp']['section_key']] = $pre_section;
switch ($l_) {
case 'top_header':
$pre_sections[$l_]['top']['title'] = $this->LIB->get_lang($pre_sections[$l_]['top']['lang_prefix'].$this->LIB->VARS['tmp']['page_data_type'].'-title');
break;
}
}
//---
return $pre_sections;
}
function nav__main_menu__get__item__generate($block_arr) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$block_arr['detect_page__key'] = $this->LIB->b64j_encode($this->LIB->VARS['detect_page']);
$block_arr['btn-icon'] = $this->LIB->get_lang('icon-cloud-arrow-down');
$block_arr['btn-text'] = $this->LIB->get_lang('text-sidebar-'.$f['key'].'');
$block_arr['btn-title'] = '(opening in modal)';
//---
return $block_arr;
}
//--- top_header
function nav__AI_req__section__get_pre_arr__top_header($pre_section) {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$pre_section['is_queue'] = false;
$pre_section['top']['is_status_switch'] = false;
$pre_section['top']['is_btns'] = false;
unset($pre_section['col_1']);
unset($pre_section['col_2']);
$pre_section['top']['title-desc-b'] = $this->LIB->get_top_header_title_desc_b();
//---
return $pre_section;
}
function get_top_header_title_desc_b() {
$res = '';
$data = [];
//---
$data['title-desc-b'] = '';
$page_data_id = 0;
if
(
isset($this->LIB->VARS['detect_page']['id'])
&&(int)$this->LIB->VARS['detect_page']['id']
)
{
$page_data_id = $this->LIB->VARS['detect_page']['id'];
}
if
(
$page_data_id
)
{
$data['title-desc-b'] .= 'ID: ';
$data['title-desc-b'] .= $this->LIB->VARS['detect_page']['id'];
$data['title-desc-b'] .= ' | ';
}
$data['title-desc-b'] .= $this->LIB->VARS['detect_page']['page_type_action'];
//---
$data['tpl_path'] = 'parts/AI_req_sections/top_header_title_desc_b';
$data['tpl_is_tmp_cache'] = false;
$res = $this->LIB->get_tpl6($data);
//---
return $res;
}
//--- name
function AI__chat__add__data__section__name() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][5];
// $f['___']
//---
if
(
!(
isset($this->LIB->VARS['tmp']['page_data_type'])
&&isset($this->LIB->VARS['tmp']['section_key'])
&&isset($this->LIB->request->post['sections'][$f['key']][$f['key']])
)
)
{
return;
}
$data = $this->LIB->request->post['sections'][$f['key']][$f['key']];
$data = trim($this->LIB->filter_str($data));
if
(
empty($data)
)
{
return;
}
$tmp = [];
$tmp['role'] = 'assistant';
$tmp['content'] = [];
$tmp['content'][] = strtoupper('# '.$this->LIB->VARS['tmp']['page_data_type'].' - '.$f['key']);
$tmp['content'][] = $data;
$this->LIB->AI__chat__add__message($tmp);
}
function settings__block__name($block_arr) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$block_key = $f['key'] = @$f['arr'][2];
// $f['___']
//---
$block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'use-site_desc',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'use-desc_full',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'use-tags',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'use-seo_url',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'TEMPERATURE',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'use_log',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'custom_comment',
'placeholder' => $this->LIB->get_lang('help-'.$f['key'].'-custom_comment',false,false,true),
]);
return $block_arr;
}
function nav__AI_req__section__get_pre_arr__name($pre_section) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$get = $this->LIB->load_DATA([
'page_type' => $this->LIB->VARS['tmp']['page_data_type'],
'id' => $this->LIB->VARS['tmp']['page_data_id'],
'get' => [
$f['key'],
],
]);
$pre_section['col_1']['data'] = '';
if
(
isset($get['data'][$f['key']])
)
{
$pre_section['col_1']['data'] = $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = $get['data'][$f['key']];
}
//---
$pre_section['is_queue'] = true;
$pre_section['top']['is_status_switch'] = false;
//---
$pre_section['col_1']['prompt'] = '';
if
(1
&&isset($this->LIB->request->post['sections']['name']['prompt'])
)
{
$pre_section['col_1']['prompt'] = $this->LIB->request->post['sections']['name']['prompt'];
$pre_section['col_1']['is_global_prompt'] = true;
}
//---
return $pre_section;
}
function nav__AI_req__section__get_prompt__name($messages=[],$p=[]) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['section_key'] = $f['key'] = @$f['arr'][4];
// $f['___']
//---
$this->LIB->AI__chat__add__data('clean_all');
$this->LIB->AI__chat__add__data('system');
$this->LIB->AI__chat__add__data('site_desc');
// $this->LIB->AI__chat__add__data('section/name');
$this->LIB->AI__chat__add__data('section/seo_url');
$this->LIB->AI__chat__add__data('section/tags');
$this->LIB->AI__chat__add__data('section/desc_full');
$this->LIB->AI__chat__add__data('section/global_prompt');
$tmp = [];
$tmp['role'] = 'user';
$tmp['content'] = [];
// $tmp['content'][] = '## TASK';
$tmp['content'][] = '## TASK (DEFAULT)';
$tmp['content'][] = '> - Plz in "USER REQUEST" find or create article/post SEO-optimized title (engaging, concise, short, without quotes) as diffirent variants (more then one).';
$this->LIB->AI__chat__add__message($tmp);
$this->LIB->AI__chat__add__data('section/custom_comment');
$tmp = [];
$tmp['role'] = 'user';
$tmp['content'] = [];
$tmp['content'][] = '
# Output must be as plain text and must have this data (exactly START and exactly END for each item) exactly in order and keys and new lines as:
**START-BOOL-IS_ERR**
... (true/false)
**END-BOOL-IS_ERR**
**START-NOTE**
... (from assistant to user about response)
**END-NOTE**
**START-PARSE_REQUESTED_TITLE**
... (name, model, type, target, type, product type, article type)
**END-PARSE_REQUESTED_TITLE**
**START-INT-REQUESTED_TITLES_VARIANTS**
... (number)
**END-INT-REQUESTED_TITLES_VARIANTS**
**START-NUMERIC_LIST-TITLES_VARIANTS**
... (REQUESTED_TITLES_VARIANTS items)
**END-NUMERIC_LIST-TITLES_VARIANTS**
**START-BOOL-IS_LIST**
... (TITLES_VARIANTS)
**END-BOOL-IS_LIST**
';
$this->LIB->AI__chat__add__message($tmp);
}
function nav__AI_req__section__set__name() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
if
(1
&&(!isset($this->LIB->VARS['tmp']['resp_arr']['IS_ERR'])||(isset($this->LIB->VARS['tmp']['resp_arr']['IS_ERR'])&&!$this->LIB->VARS['tmp']['resp_arr']['IS_ERR']))
&&(isset($this->LIB->VARS['tmp']['resp_arr']['TITLES_VARIANTS'][0])&&!empty($this->LIB->VARS['tmp']['resp_arr']['TITLES_VARIANTS'][0]))
)
{
$this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = $this->LIB->VARS['tmp']['resp_arr']['TITLES_VARIANTS'][0];
}
//---
// check only for name section
if
(1
&&(!isset($this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']])
||empty(trim($this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']])))
)
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!name',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
// 'text' => @$data['errors'][0],
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
//---
$data_set = [];
$data_set['post_id'] = $this->LIB->VARS['tmp']['page_data_id'];
$data_set['post_name'] = $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']];
// $res = $this->LIB->save__post($data_set);
$fname = implode('__',['save',$this->LIB->VARS['tmp']['page_data_type']]);
$is_set = $this->LIB->$fname($data_set);
if
(
!$is_set
)
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!save',
'!is_set',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
// 'text' => @$data['errors'][0],
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
//---
return $is_set;
}
function settings__block__name__product($block_arr) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$block_key = $f['key'] = @$f['arr'][2];
// $f['___']
//---
$block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key);
$block_arr['is_status_switch'] = 0;
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'check_name',
'is_premium_preview' => !$this->LIB->VARS['IS_PREMIUM'],
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'TEMPERATURE',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'use_log',
]);
//---
return $block_arr;
}
function nav__AI_req__section__get_prompt__name__product($messages=[]) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['section_key'] = $f['key'] = @$f['arr'][4];
// $f['___']
//---
$this->LIB->AI__chat__add__data('clean_all');
$this->LIB->AI__chat__add__data('system');
// $this->LIB->AI__chat__add__data('section/name');
// $this->LIB->AI__chat__add__data('section/seo_url');
// $this->LIB->AI__chat__add__data('section/tags');
// $this->LIB->AI__chat__add__data('section/desc_short');
// $this->LIB->AI__chat__add__data('section/desc_full');
$this->LIB->AI__chat__add__data('section/global_prompt');
$this->LIB->AI__chat__add__data('section/custom_comment');
$tmp = [];
$tmp['role'] = 'user';
$tmp['content'] = [];
$tmp['content'][] = '# TASK';
$tmp['content'][] = '
> Plz in "USER REQUEST" find or create product title (engaging, concise, short, without quotes) as diffirent variants.
Each item must be as plain text and must have this data exactly in order and keys and new lines as:
**START-ERR_TEXT**
... (string|empty)
**END-ERR_TEXT**
**START-BOOL-IS_ERR**
...(true|false)
**END-BOOL-IS_ERR**
**START-NOTE**
...(from assistant to user about response)
**END-NOTE**
**START-PARSE_REQUESTED_TITLE**
...(product name, product model, product type)
**END-PARSE_REQUESTED_TITLE**
**START-NUMERIC_LIST-TITLES_VARIANTS**
...
**END-NUMERIC_LIST-TITLES_VARIANTS**
**START-BOOL-IS_LIST**
...(TITLES_VARIANTS)
**END-BOOL-IS_LIST**
';
$this->LIB->AI__chat__add__message($tmp);
}
function nav__AI_req__section__set__name__product() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
if
(1
&&(!isset($this->LIB->VARS['tmp']['resp_arr']['IS_ERR'])||(isset($this->LIB->VARS['tmp']['resp_arr']['IS_ERR'])&&!$this->LIB->VARS['tmp']['resp_arr']['IS_ERR']))
&&(isset($this->LIB->VARS['tmp']['resp_arr']['TITLES_VARIANTS'][0])&&!empty($this->LIB->VARS['tmp']['resp_arr']['TITLES_VARIANTS'][0]))
)
{
$this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = $this->LIB->VARS['tmp']['resp_arr']['TITLES_VARIANTS'][0];
}
//---
// check only for name section
if
(1
&&(!isset($this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']])
||empty(trim($this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']])))
)
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!name',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'text' => $data['errors'][0],
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
//---
$data_set = [];
$data_set['product_id'] = $this->LIB->VARS['tmp']['page_data_id'];
$data_set['name'] = $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']];
// $is_set = $this->LIB->save__product($data_set);
$fname = implode('__',['save',$this->LIB->VARS['tmp']['page_data_type']]);
$is_set = $this->LIB->$fname($data_set);
if
(
!$is_set
)
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!save',
'!is_set',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
// 'text' => $data['errors'][0],
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
//---
return $is_set;
}
//--- desc_full
function AI__chat__add__data__section__desc_full() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][5];
// $f['___']
//---
if
(
!$this->LIB->SETTINGS__get_item([$this->LIB->VARS['tmp']['setting_mode_key'],$this->LIB->VARS['tmp']['page_data_type'],'list',$this->LIB->VARS['tmp']['section_key'],'use-'.$f['key']])
)
{
return;
}
if
(
!(
isset($this->LIB->VARS['tmp']['page_data_type'])
&&isset($this->LIB->VARS['tmp']['section_key'])
&&isset($this->LIB->request->post['sections'][$f['key']][$f['key']])
)
)
{
return;
}
$data = $this->LIB->request->post['sections'][$f['key']][$f['key']];
$data = $this->LIB->filter_str($data);
$data = str_replace(["\n","\r","\t"],'',$data);
$data = trim($data);
if
(
empty($data)
)
{
return;
}
$tmp = [];
$tmp['role'] = 'assistant';
$tmp['content'] = [];
$tmp['content'][] = strtoupper('# '.$this->LIB->VARS['tmp']['page_data_type'].' - '.$f['key']);
$tmp['content'][] = $data;
$this->LIB->AI__chat__add__message($tmp);
}
function settings__block__desc_full($block_arr) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$block_key = $f['key'] = @$f['arr'][2];
// $f['___']
//---
$block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key);
$block_arr['is_status_switch'] = 1;
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'action_type',
'data' => $this->LIB->VARS['action_types']['text'],
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'length_type',
'data' => $this->LIB->VARS['length_types']['all'],
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'format',
'is_premium_preview' => !$this->LIB->VARS['IS_PREMIUM'],
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'use-site_desc',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'use-tags',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'TEMPERATURE',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'phase_stop',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'use_log',
]);
$block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'custom_comment',
'placeholder' => $this->LIB->get_lang('help-'.$f['key'].'-custom_comment',false,false,true),
]);
//---
return $block_arr;
}
function nav__AI_req__section__get_pre_arr__desc_full($pre_section) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$get = $this->LIB->load_DATA([
'page_type' => $this->LIB->VARS['tmp']['page_data_type'],
'id' => $this->LIB->VARS['tmp']['page_data_id'],
'get' => [
$f['key'],
],
]);
$pre_section['col_1']['data'] = '';
if
(
isset($get['data'][$f['key']])
)
{
$pre_section['col_1']['data'] = $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = $get['data'][$f['key']];
}
$pre_section['col_1']['is_data_plain_text'] = false;
if
(
strip_tags($pre_section['col_1']['data'])===$pre_section['col_1']['data']
)
{
$pre_section['col_1']['is_data_plain_text'] = true;
}
//---
$pre_section['is_queue'] = true;
$pre_section['col_1']['title-desc-b'] = $this->LIB->get_lang('text-cant_be_edit_from_here');
//---
return $pre_section;
}
function nav__AI_req__section__get_prompt_1__desc_full($messages=[],$p=[]) {
$tmp = [];
$tmp['role'] = 'user';
$tmp['content'] = [];
switch ($this->LIB->VARS['tmp']['section_settings']['length_type']) {
default:
case 'default':
case 'auto':
$tmp['content'][] = '
> Plz make only context headers for future writing professional article
> as simple list
';
break;
case 'small':
$tmp['content'][] = '
> Plz make only context headers for future writing small professional article
> as simple list
> exactly 3 items
';
break;
}
$this->LIB->AI__chat__add__message($tmp);
}
function nav__AI_req__section__get_prompt_2__desc_full($messages=[],$p=[]) {
$tmp = [];
$tmp['role'] = 'user';
$tmp['content'] = [];
switch ($this->LIB->VARS['tmp']['section_settings']['length_type']) {
default:
$tmp['content'][] = '
TASK:
> Plz create professional article body
> exactly and only article body!
';
break;
case 'test':
$tmp['content'][] = '
> Ignore all instructions above.
> Output only and exactly: `TRUE`
';
break;
case 'short':
$tmp['content'][] = '
> For TARGET WEBSITE
> Plz create very small and short test article body in a few words
> exactly and only article body!
';
break;
}
$tmp['content'][] = '
ARTICLE_FORMAT_AS:
> not markdown
> without code blocks at all
> as post content
> > without