LIB-> // $this->LIB->VARS // $this->LIB->SETTINGS // $this->LIB->LANG // $this->LIB->AC // $this->LIB->request // $this->LIB->AI //-------------------------------- // 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); } function __construct() { if (!isset($this->LIB)) { $this->LIB = $this; } // request $this->LIB->request = new stdClass; $this->LIB->request->get = []; $this->LIB->request->post = []; $this->LIB->request->server = []; // $this->LIB->request->request = []; // $this->LIB->request->cookie = []; } function is_active($plugin_route) { // WP // $plugin = $code.'/'.$code.'.php'; // $plugin_route = $plugin_route.'.php'; if (!function_exists('is_plugin_active')) { return in_array( $plugin_route, (array) get_option( 'active_plugins', array() ) ); } if (function_exists('is_plugin_active')) { return is_plugin_active($plugin_route); } return false; } function load_PREMIUM() { $fp = $this->LIB->VARS['path']['plugin_dir-premium']; if (!$this->LIB->is_active($this->LIB->VARS['name']['code-premium-route'])) {return;} $f = $fp.'lang/lang.php'; if (file_exists($f)) { $_ = $this->LIB->LANG; @include_once($f); if (isset($_)) { $this->LIB->LANG = array_merge($this->LIB->LANG, $_); } unset($_); } $f = $fp.'mod/mod.php'; if (file_exists($f)) { @include($f); } } //-------------------------------- // 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']['title'] = 'AI GenProTools'; $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'; // echo("\n
".__METHOD__."::".__LINE__."\n".'name'."\n");print_r($this->LIB->VARS['name']);echo("\n\n");
// screens mode
$this->LIB->VARS['IS_SC_MODE'] = 0;
// ver
$this->LIB->VARS['SELF'] = [];
$this->LIB->VARS['SELF']['VER'] = '2.2.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'];
if
(
$this->LIB->VARS['IS_SC_MODE']
)
{
$this->LIB->VARS['SELF']['VER_STR'] = 'v-.-.-';
}
// logs
$this->LIB->VARS['DEBUG']['LOG'] = [];
// path
// 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'].'tpl'.$this->LIB->VARS['DS'];
// echo("\n".__METHOD__."::".__LINE__."\n".'path'."\n");print_r($this->LIB->VARS['path']);echo("\n\n");
// exit;
$upload_dir = wp_upload_dir();
$this->LIB->VARS['path']['upload_dir'] = $upload_dir['basedir'].$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=ai_gpt_tools-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']['ext'] = '.php';
$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().'admin'.__FILE__.filectime(__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';
$this->LIB->VARS['xhr_get__access_arr']['base'][] = 'nav_autocomplete__post';
// support
$this->LIB->VARS['support'] = [];
$this->LIB->VARS['support']['link'] = 'support@sbitsoft.com';
if
(
$this->LIB->VARS['IS_SC_MODE']
)
{
$this->LIB->VARS['support']['link'] = 'support@...';
}
$this->LIB->VARS['support']['link-home_site-value'] = 'aigenprotools.com';
$this->LIB->VARS['support']['link-home_site-href'] = 'https://aigenprotools.com';
if
(
$this->LIB->VARS['IS_SC_MODE']
)
{
$this->LIB->VARS['support']['link-home_site-value'] = '...';
}
// 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);
//---
return $this->LIB->VARS;
}
function load_VARS__other() {
// ver
$this->LIB->VARS['SYS'] = [];
$this->LIB->VARS['SYS']['TYPE'] = 'WP';
$this->LIB->VARS['SYS']['VER'] = wp_get_wp_version();
//---
$this->LIB->VARS['is_active_plugins'] = [];
$this->LIB->VARS['is_active_plugins']['woocommerce'] = (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))&&class_exists('WooCommerce'));
//---
@require_once(ABSPATH . 'wp-admin/includes/file.php');
WP_Filesystem();
//---
// 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']['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,
];
$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='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-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,
];
$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']['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_short' => 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-desc_short' => 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 = 'product';
$tmp = [];
$tmp['status'] = true;
$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_status-alert_type' => '',
'premium_access_info_status-alert_icon' => '',
'premium_access_info_status-alert_text' => '',
'premium_access_info_status-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'] = [];
//--- 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 access_check__PAGE() {
$arr = [];
$arr[] = $this->LIB->VARS['name']['code-'].'settings';
if
(
(isset($this->LIB->request->get['page'])&&in_array($this->LIB->request->get['page'],$arr))
||$this->LIB->VARS['is_ajax']
||preg_match('~plugins/'.'ai-gpt-tools'.'~is', $this->LIB->request->server['REQUEST_URI'], $matches, PREG_OFFSET_CAPTURE, 0)
)
{
return true;
}
return false;
}
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)
)
{
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_list_arr() {
// @codingStandardsIgnoreStart
global $wpdb;
//---
$res = [];
//---
$search = $this->LIB->VARS['name']['_code-'].'settings-';
$sql = "SELECT option_name FROM {$wpdb->prefix}options WHERE option_name LIKE %s AND option_name NOT LIKE %s ORDER BY `option_id` DESC";
$sql = $wpdb->prepare($sql, $search.'%', $search.'main%');
$query = $wpdb->get_results($sql, ARRAY_A);
foreach ($query as $k_ => $l_) {
$get = get_option($l_['option_name']);
$get = json_decode(base64_decode($get),true);
if (!isset($get['setting_mode']['setting_mode_key'])) {continue;}
$res[] = $get;
}
//---
return $res;
// @codingStandardsIgnoreEnd
}
function nav__settings_modes__get__btn__cron__add($data=[]) {
$data['tpl_path'] = 'parts/btn__cron__add';
return $this->LIB->get_tpl5($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_tpl5($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() {
// use:
// $this->LIB->SETTINGS__get_item('main/product/list/desc_short');
//---
$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->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_tpl5($tpl_data);
$noty_arr[$k_]['is_process__AC_noty'] = true;
}
//---
return $noty_arr;
}
function load_LANG() {
require($this->LIB->VARS['path']['plugin_dir'].'lang/lang.php');
if (!isset($_)) {return [];}
$this->LIB->LANG = $_;
unset($_);
return $this->LIB->LANG;
}
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_tpl5($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
(
$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 get_tpl5($p=[]) {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['name']
// $f['prefix']
// $f['arr']
//---
$p = $this->LIB->process__func_params([
'tpl_path' => '',
'tpl_is_tmp_cache' => true,
'tpl_key' => '',
'add_data' => [],
], func_get_args());
// $p['___']
//---
$res = '';
$tmp_en_p_key = $this->LIB->j_encode($p);
//---
if
(
$p['tpl_is_tmp_cache']
&&isset($this->LIB->VARS[$f['name']][$tmp_en_p_key])
)
{return $this->LIB->VARS[$f['name']][$tmp_en_p_key];}
//---
$p['tpl_path'] = $this->LIB->slashes_fix($p['tpl_path']);
if
(
!(stripos($p['tpl_path'], $this->LIB->slashes_fix($this->LIB->VARS['path']['tpl_dir']))!==false)
&&!(stripos($p['tpl_path'], $this->LIB->slashes_fix($this->LIB->VARS['path']['tpl_dir-premium']))!==false)
)
{
$p['tpl_path'] = $this->LIB->VARS['path']['tpl_dir'].$p['tpl_path'];
}
if ($p['tpl_path'] === '') {return $res;};
$p['tpl_path'] = $p['tpl_path'].$this->LIB->VARS['tpl']['ext'];
// echo("\n".__METHOD__."::".__LINE__."\n".'tpl_dir'."\n");print_r($this->LIB->VARS['path']['tpl_dir']);echo("\n\n");
// echo("\n".__METHOD__."::".__LINE__."\n".'p'."\n");print_r($p['tpl_path']);echo("\n\n");
if (!file_exists($p['tpl_path'])) {return $res;};
//---
if (empty(trim(($p['tpl_key'])))) {
$p['tpl_key'] = basename($p['tpl_path']);
}
if
(
!empty($p['add_data'])
)
{
$p = array_merge($p['add_data'],$p);
}
unset($p['add_data']);
$tpl_data = [];
$tpl_data['data'] = $p;
// echo("\n".__METHOD__."::".__LINE__."\n".'tpl_data'."\n");print_r(@$tpl_data);echo("\n\n");
$tpl_data['LIB'] = $this->LIB;
//---
$res = $this->LIB->get_tpl_file($p['tpl_path'],$tpl_data);
$this->LIB->VARS[$f['name']][$tmp_en_p_key] = $res;
unset($tmp_data);
//---
return $res;
}
function get_tpl_file($fpath, $data=[]) {
$res = '';
//---
if ($fpath === '' || !file_exists($fpath)) {return $res;};
//---
ob_start();
foreach($data as $k_var => $l_var){$$k_var = $l_var;}
include($fpath);
foreach($data as $k_ => $l_){unset($$k_);}
$res = ob_get_contents();
ob_end_clean();
//---
return $res;
}
function output($data) {
if (isset($this->LIB->is_api_get)&&$this->LIB->is_api_get)
{
return $data;
}
else
{
print_r($data);
}
}
function output__xhr_get($data) {
print_r($this->LIB->j_encode($data, true));
exit;
}
function detect_page($p=[]) {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$p = $this->LIB->process__func_params([
'page_url' => '',
'page_type' => '',
'page_type_action' => '',
'id' => 0,
'is_access__nav__AI_req' => false,
], func_get_args());
// $p['___']
//---
if ($p['page_url']==='') {
$p['page_url'] = @$this->LIB->request->server['REQUEST_URI'];
// $p['page_url'] = @$this->LIB->request->server['HTTP_REFERER'];
if
(
(stripos($p['page_url'], '/admin-ajax.php')!==false)
)
{
$p['page_url'] = @$this->LIB->request->server['HTTP_REFERER'];
}
}
$p['page_url_arr'] = $this->LIB->process__GET($p['page_url']);
//---
$p['is_page_type'] = false;
$fnames_arr = [
$f['prefix'].'get',
'PREMIUM_'.$f['prefix'].'get',
];
foreach ($fnames_arr as $k_ => $l_) {
if
(1
&&$tmp_fname = $this->LIB->is_fname([$l_], false, false)
)
{
$p = $this->$tmp_fname($p);
$p['is_page_type'] = ($p['page_type']!=='');
}
}
$this->LIB->VARS[$f['name'].'__key'] = $this->LIB->b64j_encode($p);
$this->LIB->VARS[$f['name']] = $p;
//---
return $p;
}
function detect_page__get($p=[]) {
if
(
(stripos($p['page_url'], 'post.php')!==false)
)
{
$p['id'] = (isset($p['page_url_arr']['post'])?$p['page_url_arr']['post']:0);
$p['page_type'] = get_post_type($p['id']);
$p['page_type_action'] = 'edit';
}
if
(
(stripos($p['page_url'], 'post-new.php')!==false)
)
{
$p['id'] = 0;
$p['page_type'] = (isset($p['page_url_arr']['post_type'])?$p['page_url_arr']['post_type']:'post');
$p['page_type_action'] = 'new';
}
if
(
(stripos($p['page_url'], 'edit.php')!==false)
)
{
$p['id'] = (isset($p['page_url_arr']['post'])?$p['page_url_arr']['post']:0);
$p['page_type'] = get_post_type($p['id']);
$p['page_type_action'] = 'list';
}
//---
//if
//(
// in_array($p['page_type'],['post'])
// &&$this->LIB->SETTINGS__get_item('main/post/status')
//)
//{
// $p['is_access__nav__AI_req'] = true;
//}
$arr=[];
$arr[] = 'post';
foreach ($arr as $k_ => $l_) {
if
(
in_array($p['page_type'],[$l_])
&&$this->LIB->SETTINGS__get_item('main/'.$l_.'/status')
)
{
$p['is_access__nav__AI_req'] = true;
return $p;
}
}
//---
return $p;
}
function load_DATA() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$p = $this->LIB->process__func_params([
'page_type' => '',
], func_get_args());
// $p['___']
//---
$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;
}
function get__post($post_id=0) {
$res = get_post($post_id);
$res->post_tags = wp_get_post_tags($post_id);
$res->post_tags_input = wp_get_post_tags($post_id, array( 'fields' => 'names' ));
$res->post_tags_input = implode(', ',$res->post_tags_input);
//---
return $res;
}
function load_DATA__post() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$p = $this->LIB->process__func_params([
'id' => 0,
'get' => [],
'data' => [],
'is_return_single' => false,
], func_get_args());
// $p['___']
//---
$post_id = $p['id'] = (int)$p['id'];
if
(
!$post_id
&&isset($p['post_id'])
)
{
$post_id = $p['post_id'] = (int)$p['post_id'];
}
//---
$get = get_post($post_id);
if
(
!$get
)
{
return $p;
}
//---
$arr = [
'name',
'desc_full',
'tags',
'seo_url',
];
if
(
empty($p['get'])
||isset($p['get']['all'])
)
{
$p['get'] = $arr;
}
$p['get'] = $this->LIB->filter_arr($p['get']);
if
(
$p['is_return_single']
)
{
$p['get'] = [$p['get'][0]];
}
foreach ($p['get'] as $k_ => $l_) {
if
(
$l_ === 'name'
)
{
$p['data'][$l_] = $get->post_title;
}
if
(
$l_ === 'desc_full'
)
{
$tmp = '';
$tmp = $get->post_content;
$tmp_sc = $this->LIB->str_clean($tmp);
if
(
$tmp_sc===''
)
{
$tmp = $tmp_sc;
}
$p['data'][$l_] = $tmp;
}
if
(
$l_ === 'tags'
)
{
$p['data'][$l_] = [];
$p['data']['tags_arr'] = get_the_terms( $post_id, 'post_tag' );
if
(
is_array($p['data']['tags_arr'])
&&!empty($p['data']['tags_arr'])
)
{
foreach ($p['data']['tags_arr'] as $k_tags_arr => $l_tags_arr) {
$p['data'][$l_][] = $l_tags_arr->name;
};
}
$p['data'][$l_] = implode(', ',$p['data'][$l_]);
}
if
(
$l_ === 'seo_url'
)
{
$p['data'][$l_] = $get->post_name;
}
}
//---
if
(
$p['is_return_single']
&&!empty($p['data'])
)
{
$p = array_values($p['data'])[0];
}
else
if
(
$p['is_return_single']
&&empty($p['data'])
)
{
$p = [];
}
//---
return $p;
}
//--------------------------------
// PAGES DATA
function save__post($p=[]) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][1];
$f['key_'] = $f['key'].'_';
// $f['___']
//---
$p = array_merge([
$f['key_'].'id' => 0,
$f['key_'].'name' => NULL,
$f['key_'].'desc_full' => NULL,
$f['key_'].'seo_url' => NULL,
$f['key_'].'tags' => NULL,
], $p);
$p = $this->LIB->trim_arr($p);
//---
$res = 0;
$post_id = $p[$f['key_'].'id'] = (int)$p[$f['key_'].'id'];
//---
// create data_set
// convert params
$data_set = [];
$arr = [
$f['key_'].'id' => 'ID',
$f['key_'].'name' => 'post_title',
$f['key_'].'desc_full' => 'post_content',
$f['key_'].'seo_url' => 'post_name',
$f['key_'].'tags' => 'tags_input',
];
foreach ($arr as $k_ => $l_) {
if
(1
&&isset($p[$k_])
&&$p[$k_]!==NULL
)
{
$data_set[$l_] = $p[$k_];
}
}
//---
// update
// save
if
(
$post_id
)
{
$res = wp_update_post($data_set);
}
else
{
$res = wp_insert_post($data_set);
}
$this->LIB->VARS['tmp']['last_set_data'] = $data_set;
//---
return $res;
}
function get_all__post() {
//---
$p = $this->LIB->process__func_params([
'post_type' => 'post',
'post_status' => 'any', // array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash')
'numberposts' => -1,
'posts_per_page' => -1,
'order' => 'DESC',
// 'fields' => 'ids', // Only get post IDs
// 'p' => 42,
// 'post__in' => [42],
], func_get_args());
// $p['___']
//---
if
(
isset($p['filter_search'])
&&!empty(trim($p['filter_search']))
)
{
add_filter( 'posts_where', function( $where, &$wp_query )
{
global $wpdb;
if ( $filter_search = $wp_query->get( 'filter_search' ) ) {
// $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( like_escape( $filter_search ) ) . '%\'';
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( wpdb::esc_like( $filter_search ) ) . '%\'';
}
return $where;
}, 10, 2 );
}
//---
$res = new WP_Query($p);
//---
return $res;
}
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__parce($str) {
$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)
)
{
if
(
is_string($val)
)
{
$val = trim($val);
$re = '~^```(?:html)|```$~si';
$subst = '';
$val = preg_replace($re, $subst, $val);
$val = trim($val);
}
$res['DATA'] = $str;
}
//---
return $res;
}
function AI__chat__query($data=[]) {
$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'].'',
]);
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);
$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) {
$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__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) {}
$getCURLInfo = $this->LIB->AI->getCURLInfo();
$listModels = json_decode($listModels, true);
// echo("\n".__METHOD__."::".__LINE__."\n".'listModels'."\n");print_r(@$listModels);echo("\n\n");
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() {
$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']]);
}
//$this->LIB->VARS['tmp']['section_settings']=
//(array)@$this->LIB->SETTINGS
//[$this->LIB->VARS['tmp']['setting_mode_key']]
//[$this->LIB->VARS['tmp']['page_data_type']]
//['list']
//[$this->LIB->VARS['tmp']['section_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);
// echo("\n".__METHOD__."::".__LINE__."\n".'matches'."\n");print_r(@$matches);echo("\n\n");
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__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 AI__chat__add__data__section__seo_url() {
$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 = 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 AI__chat__add__data__section__tags() {
$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 = 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 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 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'][] = 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__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=[]) {
$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['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() {
$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() {
$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() {
$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=[]) {
$data['tpl_key'] = $this->LIB->VARS['tmp']['section_key'];
return $this->LIB->get_tpl5($data);
}
function nav__AI_req__section__set() {
$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
(
isset($data['resp_arr']['query_d']['usage']['calc_all_tokens_cost'])
)
{
$tmp = [];
$tmp['label'] = $this->LIB->get_lang('text-calc_all_tokens_cost');
$tmp['value'] = $data['resp_arr']['query_d']['usage']['calc_all_tokens_cost'];
$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'] = '';
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_tpl5($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_tpl5($data);
//---
return $res;
}
//--- AI req sections/data by type/name
function nav__main_menu__get__item__post($block_arr) {
$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__arr'] = $tmp;
$block_arr['detect_page__key'] = $this->LIB->b64j_encode($tmp);
// $block_arr['detect_page__key2'] = $this->LIB->b64j_decode($block_arr['detect_page__key']);
$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) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$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['is_premium_preview'] = true;
$block_arr['is_tag_premium'] = true;
//---
return $block_arr;
}
function nav__AI_req__sections__get__post() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
// $f['___']
//---
$pre_sections = [];
$arr = [
'top_header',
'name',
'desc_full',
'tags',
'seo_url',
'comments',
];
foreach ($arr as $k_ => $l_) {
$this->LIB->VARS['tmp']['section_key'] = $l_;
$this->LIB->request->post['section_key'] = $l_;
$pre_sections[$this->LIB->VARS['tmp']['section_key']] = $this->LIB->nav__AI_req__section__get_pre_arr();
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;
//case 'name':
// $pre_sections[$l_]['col_1']['is_global_prompt'] = true;
// $pre_sections[$l_]['col_1']['global_prompt_placeholder'] = $this->LIB->get_lang('help-placeholder-name-'.$this->LIB->VARS['tmp']['page_data_type'].'-global_prompt_placeholder');
//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;
}
//--- 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->LIB->VARS['links']['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->LIB->VARS['links']['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;
}
//--- 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_tpl5($data);
//---
return $res;
}
//--- name
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-desc_short',
]);
$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 settings__block__name__product($block_arr) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$block_key = $f['key'] = @$f['arr'][2];
// $f['___']
//---
$block_arr['tpl_path'] = 'parts/settings_blocks/premium';
$block_arr['is_tag_premium'] = true;
$block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key);
$block_arr['list'][] = 'premium';
//---
return $block_arr;
}
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_short');
$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__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__set__name__post() {
$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);
if
(
!$res
)
{
$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 $res;
}
//--- desc_full
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 settings__block__desc_full__product($block_arr) {
$f = $this->LIB->process__func_name(__FUNCTION__);
$block_key = $f['key'] = @$f['arr'][2];
// $f['___']
//---
$block_arr['tpl_path'] = 'parts/settings_blocks/premium';
$block_arr['is_tag_premium'] = true;
$block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key);
$block_arr['list'][] = 'premium';
//---
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 proffesional article
> as simple list
';
break;
case 'small':
$tmp['content'][] = '
> Plz make only context headers for future writing small proffesional 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'] = [];
$tmp['content'][] = '
TASK:
';
$tmp['content'][] = '';
switch ($this->LIB->VARS['tmp']['section_settings']['length_type']) {
default:
$tmp['content'][] = '
> For TARGET WEBSITE.
> Plz create exactly and only professional article content for this web store.
> SEO friendly.
> return product description content as plain html its very important.
> only allowed this html tags: . > without notes, after words. '; break; case 'test': $tmp['content'][] = ' > Ignore all instructions. > Output/return/response only and exactly word: TRUE. '; break; } $this->LIB->AI__chat__add__message($tmp); $this->LIB->AI__chat__add__data('section/custom_comment2'); $tmp = []; $tmp['role'] = 'user'; $tmp['content'] = []; switch ($this->LIB->VARS['tmp']['section_settings']['length_type']) { default: $tmp['content'][] = ' # OUTPUT ALL OF THIS ALWAYS EXACTLY AS **START-KEY** **END-KEY**: **START-LIST-USER_TASK_FOR_ASSISTANT** ... (compile all tasks including user task and comments into one structured unique list) **END-LIST-USER_TASK_FOR_ASSISTANT** **START-RESPONSE-POST-TITLE** ...(string) **END-RESPONSE-POST-TITLE** **START-RESPONSE-POST-TOP_HEAD_TITLE** ...(string) **END-RESPONSE-POST-TOP_HEAD_TITLE** **START-HTML-RESPONSE-POST-BODY** ...(text, without top head first title) **END-HTML-RESPONSE-POST-BODY** **START-ERR_TEXT** ... (string|empty) **END-ERR_TEXT** **START-BOOL-IS_ERR** ...(true|false) **END-BOOL-IS_ERR** **START-AFTER_NOTE** ... (simple note from assistant to user about output) **END-AFTER_NOTE** '; break; case 'test': $tmp['content'][] = ' # OUTPUT ALL OF THIS ALWAYS EXACTLY AS **START-KEY** **END-KEY**: **START-LIST-USER_TASK_FOR_ASSISTANT** ... (compile all tasks including user task and comments into one structured unique list) **END-LIST-USER_TASK_FOR_ASSISTANT** **START-HTML-RESPONSE-POST-BODY** TRUE **END-HTML-RESPONSE-POST-BODY** **START-ERR_TEXT** ... (string|empty) **END-ERR_TEXT** **START-BOOL-IS_ERR** ...(true|false) **END-BOOL-IS_ERR** '; break; } $this->LIB->AI__chat__add__message($tmp); } function nav__AI_req__section__resp_arr__desc_full() { $f = $this->LIB->process__func_name(__FUNCTION__); // $f['___'] //--- if ( !$this->LIB->VARS['tmp']['section_settings']['status'] || (($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; } //--- if ( !isset($this->LIB->VARS['tmp']['section_settings']['length_type']) ||empty($this->LIB->VARS['tmp']['section_settings']['length_type']) ) { $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__, '!length_type', ], '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->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/desc_full'); $this->LIB->AI__chat__add__data('section/desc_short'); $this->LIB->AI__chat__add__data('section/tags'); $this->LIB->AI__chat__add__data('section/product_attr'); $this->LIB->AI__chat__add__data('section/global_prompt'); // $this->LIB->AI__chat__add__data('section/custom_comment'); //--- $res = []; //--- $arr = []; $arr[] = implode('__',[$f['arr'][0],$f['arr'][1],$f['arr'][2],'get_prompt_1',$f['arr'][4]]); if ( in_array($this->LIB->VARS['tmp']['section_settings']['length_type'],[ 'default', 'auto', 'test', ]) ) { $arr = []; } $arr[] = implode('__',[$f['arr'][0],$f['arr'][1],$f['arr'][2],'get_prompt_2',$f['arr'][4]]); if ( isset($this->LIB->VARS['tmp']['section_settings']['phase_stop']) &&$this->LIB->VARS['tmp']['section_settings']['phase_stop']>0 &&isset($arr[$this->LIB->VARS['tmp']['section_settings']['phase_stop']]) ) { unset($arr[$this->LIB->VARS['tmp']['section_settings']['phase_stop']]); } foreach ($arr as $k_ => $l_) { $fnames_arr = [ $l_ ]; 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__, '!is_fname', '!prompt', ], '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'].'', ]); } $res = $this->LIB->AI__chat__query(); } //--- $tmp = $res['last_message']['parced_arr']['HTML-RESPONSE-POST-BODY']; if ( wp_strip_all_tags($tmp)===$tmp ) { $tmp = nl2br($tmp); $re = '/(^.+?$)/m'; $subst = '
$1
'; $tmp = preg_replace($re, $subst, $tmp); } $res['last_message']['parced_arr']['HTML-RESPONSE-POST-BODY'] = $tmp; //--- return $res; } function nav__AI_req__section__set__desc_full($p=[]) { $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']['DATA'])&&!empty($this->LIB->VARS['tmp']['resp_arr']['DATA'])) ) { $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = $this->LIB->VARS['tmp']['resp_arr']['DATA']; } //--- if ( !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']])) ) { // return false; $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = ''; } //--- $data_set = []; $data_set['post_id'] = $this->LIB->VARS['tmp']['page_data_id']; $data_set['post_desc_full'] = $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']]; $res = $this->LIB->save__post($data_set); //--- return $res; } //--- tags function settings__block__tags($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']['base_create'], ]); $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' => '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 settings__block__tags__product($block_arr) { $f = $this->LIB->process__func_name(__FUNCTION__); $block_key = $f['key'] = @$f['arr'][2]; // $f['___'] //--- $block_arr['tpl_path'] = 'parts/settings_blocks/premium'; $block_arr['is_tag_premium'] = true; $block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key); $block_arr['list'][] = 'premium'; //--- return $block_arr; } function nav__AI_req__section__get_pre_arr__tags($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; //--- return $pre_section; } function nav__AI_req__section__get_prompt__tags($messages=[],$p=[]) { $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/desc_full'); $this->LIB->AI__chat__add__data('section/desc_short'); // $this->LIB->AI__chat__add__data('section/tags'); $this->LIB->AI__chat__add__data('section/product_attr'); $this->LIB->AI__chat__add__data('section/global_prompt'); $tmp = []; $tmp['role'] = 'user'; $tmp['content'] = []; // $tmp['content'][] = '## TASK'; $tmp['content'][] = '## TASK (DEFAULT)'; $tmp['content'][] = '> - For TARGET WEBSITE'; $tmp['content'][] = '> - Plz generate SEO-optimized tags (highly relevant, string, separated by commas).'; $tmp['content'][] = '> - by default minimum 20 items/tags'; $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-LIST-USER_TASK_FOR_ASSISTANT** ... (compile all tasks including user task and comments into one structured unique list) **END-LIST-USER_TASK_FOR_ASSISTANT** **START-ERR_TEXT** ... (string|empty) **END-ERR_TEXT** **START-BOOL-IS_ERR** ...(true|false) **END-BOOL-IS_ERR** **START-STRING-OUTPUT-TAGS** ... (string, separated by commas) **END-STRING-OUTPUT-TAGS** **START-AFTER_NOTE** ... (simple note from assistant to user about output) **END-AFTER_NOTE** '; $this->LIB->AI__chat__add__message($tmp); } function nav__AI_req__section__set__tags__post() { $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']['TAGS'])&&!empty($this->LIB->VARS['tmp']['resp_arr']['TAGS'])) ) { $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = $this->LIB->VARS['tmp']['resp_arr']['TAGS']; } //--- if ( !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']])) ) { // return false; $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = ''; } //--- $data_set = []; $data_set['post_id'] = $this->LIB->VARS['tmp']['page_data_id']; $data_set['post_tags'] = $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']]; $res = $this->LIB->save__post($data_set); //--- return $res; } //--- seo_url function settings__block__seo_url($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']['base_create'], ]); $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 settings__block__seo_url__product($block_arr) { $f = $this->LIB->process__func_name(__FUNCTION__); $block_key = $f['key'] = @$f['arr'][2]; // $f['___'] //--- $block_arr['tpl_path'] = 'parts/settings_blocks/premium'; $block_arr['is_tag_premium'] = true; $block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key); $block_arr['list'][] = 'premium'; //--- return $block_arr; } function nav__AI_req__section__get_pre_arr__seo_url($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'], ], // 'is_return_single' => true, ]); $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; //--- return $pre_section; } function nav__AI_req__section__get_prompt__seo_url($messages=[],$p=[]) { $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/desc_full'); // $this->LIB->AI__chat__add__data('section/desc_short'); // $this->LIB->AI__chat__add__data('section/tags'); // $this->LIB->AI__chat__add__data('section/product_attr'); // $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 generate in English short SEO-optimized seo_url/slug for this '.$this->LIB->VARS['tmp']['page_data_type'].' as diffirent variants as numeric list.'; // $tmp['content'][] = '> - Must be exactly (or close) as title/name and not longer then title/name.'; // $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 (START and END for each item) exactly in order and keys and new lines as: // **START-LIST-USER_TASK_FOR_ASSISTANT** // ... (compile all tasks including user task and comments into one structured unique list) // **END-LIST-USER_TASK_FOR_ASSISTANT** // **START-ERR_TEXT** // ...(string|empty) // **END-ERR_TEXT** // **START-BOOL-IS_ERR** // ...(true|false) // **END-BOOL-IS_ERR** // **START-NUMERIC_LIST-RESPONSE** // (seo_url variants as numeric list) // 1. ...(same as title/name) // 2. ... // **END-NUMERIC_LIST-RESPONSE** // **START-BOOL-IS_LIST** // ...(seo_url variants) // **END-BOOL-IS_LIST** // **START-AFTER_NOTE** // ... (simple note from assistant to user about output) // **END-AFTER_NOTE** // '; // $this->LIB->AI__chat__add__message($tmp); $tmp = []; $tmp['role'] = 'user'; $tmp['content'] = []; $tmp['content'][] = ' TASK: '; $tmp['content'][] = ''; $tmp['content'][] = ' > Generate in English short SEO-optimized seo_url/slug for this '.$this->LIB->VARS['tmp']['page_data_type'].'. > post slag for WordPress. > as diffirent variants. > as numeric list. > first item must be exactly (or close) as title/name and not longer then title/name. > without spaces. > instead of spaces use dash symbol. > allowed only letters, numbers, dash symbol. '; $this->LIB->AI__chat__add__message($tmp); $this->LIB->AI__chat__add__data('section/custom_comment2'); $tmp = []; $tmp['role'] = 'user'; $tmp['content'] = []; $tmp['content'][] = ' # OUTPUT ALL OF THIS ALWAYS EXACTLY AS **START-KEY** **END-KEY**: **START-LIST-USER_TASK_FOR_ASSISTANT** ... (compile all tasks including user task and comments into one structured unique list) **END-LIST-USER_TASK_FOR_ASSISTANT** **START-ERR_TEXT** ...(string|empty) **END-ERR_TEXT** **START-BOOL-IS_ERR** ...(true|false) **END-BOOL-IS_ERR** **START-NUMERIC_LIST-RESPONSE** (seo_url variants as numeric list) 1. ...(same as title/name) 2. ... **END-NUMERIC_LIST-RESPONSE** **START-BOOL-IS_LIST** ...(seo_url variants) **END-BOOL-IS_LIST** **START-AFTER_NOTE** ... (simple note from assistant to user about output) **END-AFTER_NOTE** '; $this->LIB->AI__chat__add__message($tmp); } function nav__AI_req__section__set__seo_url__post() { $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']['RESPONSE'][0])&&!empty($this->LIB->VARS['tmp']['resp_arr']['RESPONSE'][0])) ) { $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = $this->LIB->VARS['tmp']['resp_arr']['RESPONSE'][0]; } //--- if ( !isset($this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']]) ) { // return false; $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']] = ''; } //--- $data_set = []; $data_set['post_id'] = $this->LIB->VARS['tmp']['page_data_id']; $data_set['post_seo_url'] = $this->LIB->request->post['sections'][$this->LIB->VARS['tmp']['section_key']][$f['key']]; $res = $this->LIB->save__post($data_set); //--- return $res; } //--- desc_short // Premium function settings__block__desc_short__product($block_arr) { $f = $this->LIB->process__func_name(__FUNCTION__); $block_key = $f['key'] = @$f['arr'][2]; // $f['___'] //--- $block_arr['tpl_path'] = 'parts/settings_blocks/premium'; $block_arr['is_tag_premium'] = true; $block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key); $block_arr['is_status_switch'] = 1; $block_arr['list'][] = 'premium'; //--- return $block_arr; } //--- comments // Premium function settings__block__comments($block_arr) { $f = $this->LIB->process__func_name(__FUNCTION__); $block_key = $f['key'] = @$f['arr'][2]; // $f['___'] //--- $block_arr['tpl_path'] = 'parts/settings_blocks/premium'; $block_arr['is_tag_premium'] = true; $block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key); $block_arr['list'][] = 'premium'; //--- return $block_arr; } function nav__AI_req__section__get_pre_arr__comments__post($pre_section) { $f = $this->LIB->process__func_name(__FUNCTION__); // $f['___'] //--- $pre_section['is_dim'] = true; $pre_section['icon'] = $this->LIB->get_lang('icon-'.$this->LIB->VARS['tmp']['section_key']); $pre_section['top']['is_status_switch'] = false; $pre_section['top']['is_btns'] = false; $pre_section['top']['is_premium'] = true; unset($pre_section['col_1']); unset($pre_section['col_2']); //--- return $pre_section; } //--- product_attr // Premium function settings__block__product_attr__product($block_arr) { $f = $this->LIB->process__func_name(__FUNCTION__); $block_key = $f['key'] = @$f['arr'][2]; // $f['___'] //--- $block_arr['tpl_path'] = 'parts/settings_blocks/premium'; $block_arr['is_tag_premium'] = true; $block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key); $block_arr['list'][] = 'premium'; //--- return $block_arr; } //--- product_imgs // Premium function settings__block__product_imgs__product($block_arr) { $f = $this->LIB->process__func_name(__FUNCTION__); $block_key = $f['key'] = @$f['arr'][2]; // $f['___'] //--- $block_arr['tpl_path'] = 'parts/settings_blocks/premium'; $block_arr['is_tag_premium'] = true; $block_arr['icon'] = $this->LIB->get_lang('icon-'.$block_key); $block_arr['list'][] = 'premium'; //--- return $block_arr; } //--- other_helps function settings__block__support($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' => 'text_info_help', 'label' => '', 'value' => nl2br($this->LIB->get_lang('help-support')), ]); $block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'home_site', 'value' => $this->LIB->VARS['support']['link-home_site-value'], 'href' => $this->LIB->VARS['support']['link-home_site-href'], ]); $block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'support_email', 'value' => $this->LIB->VARS['support']['link'], ]); //--- return $block_arr; } function settings__block__data($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; //--- return $block_arr; } function settings__block__logs($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' => 'is_fwrite_on_off', ]); $block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'is_fwrite_cron_on_off', 'is_premium_preview' => !$this->LIB->VARS['IS_PREMIUM'], ]); $block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'is_cron_extended_dev_print_on_off', ]); //--- return $block_arr; } //--- premium_access function settings__block__premium_access($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['is_tag_premium'] = true; $block_arr['list'][] = $this->LIB->settings__block__get_item(['key' => 'premium_access_key', ]); $tmp=[]; $tmp['key']='alert'; $tmp['label']=$this->LIB->get_lang('text-premium_status'); $tmp['alert_type']='info2 text'; $tmp['icon']=$this->LIB->get_lang('icon-key'); $tmp['value']=nl2br($this->LIB->get_lang('help-premium-get')); $tmp['tags_hide']=''; if ( $this->LIB->VARS['IS_PLUGIN_PREMIUM_CONNECTED'] ) { $tmp1 = $this->LIB->SETTINGS__get_item('main/premium/list/premium_access/premium_access_info_status-alert_type'); $tmp2 = $this->LIB->SETTINGS__get_item('main/premium/list/premium_access/premium_access_info_status-alert_icon'); $tmp3 = $this->LIB->SETTINGS__get_item('main/premium/list/premium_access/premium_access_info_status-alert_text'); $tmp4 = $this->LIB->SETTINGS__get_item('main/premium/list/premium_access/premium_access_info_status-tags'); if ( empty($tmp3) ) { $tmp1='info2 text'; $tmp2='icon-key'; } $tmp['alert_type']=(!empty($tmp1)?$tmp1:'info2 text'); $tmp['icon']=$this->LIB->get_lang((!empty($tmp2)?$tmp2:'icon-key')); $tmp['value']=nl2br($this->LIB->get_lang((!empty($tmp3)?$tmp3:'help-premium-get'))); $tmp['tags_hide']=(!empty($tmp4)&&$this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$tmp4:[]); } $block_arr['list'][] = $this->LIB->settings__block__get_item($tmp); // echo("\n".__METHOD__."::".__LINE__."\n".'block_arr'."\n");print_r(@$block_arr);echo("\n\n");
//---
return $block_arr;
}
//--------------------------------
// API ACTION PAGES
function nav__adminbar_btn_main() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$data = [];
$data['is_active'] = true;
//---
$data['tpl_path'] = 'navs/'.__FUNCTION__;
return $this->LIB->output($this->LIB->get_tpl5($data));
}
function nav__main_menu() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = [];
$data = [];
$data['body'] = [];
$data['body']['list'] = [];
//---
$tmp = [];
$tmp['title'] = $this->LIB->get_lang('text-current');
// echo("\n".__METHOD__."::".__LINE__."\n".'detect_page'."\n");print_r($this->LIB->VARS['detect_page']);echo("\n\n");
if
(
isset($this->LIB->VARS['detect_page']['page_type'])
)
{
$tmp['title'] .= ' - '.$this->LIB->get_lang('text-settings_sections-'.$this->LIB->VARS['detect_page']['page_type'].'-title');
}
$arr = [];
$arr['list'] = [];
$arr['list']['generate'] = true;
// $arr['list']['translate'] = true;
foreach ($arr['list'] as $k_ => $l_) {
if
(
$k_==='generate'
&&!$this->LIB->SETTINGS__get_item(['main',$this->LIB->VARS['detect_page']['page_type'].'','status',])
)
{
continue;
}
//if
//(
// $k_==='translate'
// &&!$this->LIB->SETTINGS__get_item(['main',$this->LIB->VARS['detect_page']['page_type'].'_translate','status',])
//)
//{
// continue;
//}
$tmp2 = $this->LIB->nav__main_menu__get__item($k_);
// echo("\n".__METHOD__."::".__LINE__."\n".'tmp2'."\n");print_r(@$tmp2);echo("\n\n");
if
(
!empty($tmp2)
)
{
if
(
isset($this->LIB->request->post['is_nav__AI_req_open'])
&&$this->LIB->request->post['is_nav__AI_req_open']
)
{
$tmp2['btn-is_disabled'] = true;
}
$tmp['list'][] = $tmp2;
}
}
if
(
isset($tmp['list'])
&&
(
isset($this->LIB->VARS['detect_page']['page_type'])
&&in_array($this->LIB->VARS['detect_page']['page_type'],['post','product'])
&&isset($this->LIB->VARS['detect_page']['page_type_action'])
&&in_array($this->LIB->VARS['detect_page']['page_type_action'],['edit'])
)
)
{
$data['body']['list'][] = $tmp;
}
//$tmp = [];
//$tmp['title'] = $this->LIB->get_lang('text-add_create_new');
//foreach ($this->LIB->VARS['for_gen_page_types']['list'] as $k_ => $l_) {
// $tmp2 = $this->LIB->nav__main_menu__get__item($k_);
// if
// (
// !empty($tmp2)
// )
// {
// if
// (
// isset($this->LIB->request->post['is_nav__AI_req_open'])
// &&$this->LIB->request->post['is_nav__AI_req_open']
// )
// {
// $tmp2['btn-is_disabled'] = true;
// }
// $tmp['list'][] = $tmp2;
// }
//}
$tmp = [];
$tmp['title'] = $this->LIB->get_lang('text-add_create_new');
$arr=[];
$arr['post']=1;
$arr['product']=1;
foreach ($arr as $k_ => $l_) {
if
(
!$this->LIB->SETTINGS__get_item(['main',$k_,'status',])
)
{
continue;
}
$tmp2 = $this->LIB->nav__main_menu__get__item($k_);
if
(
!empty($tmp2)
)
{
if
(
isset($this->LIB->request->post['is_nav__AI_req_open'])
&&$this->LIB->request->post['is_nav__AI_req_open']
)
{
$tmp2['btn-is_disabled'] = true;
}
$tmp['list'][] = $tmp2;
}
// echo("\n".__METHOD__."::".__LINE__."\n".'tmp'."\n");print_r(@$tmp);echo("\n\n");
}
if
(
isset($tmp['list'])
)
{
$data['body']['list'][] = $tmp;
}
//---
$data['footer_btns'] = [];
$data['footer_btns']['list'] = [];
$tmp = [];
$tmp['title'] = $this->LIB->get_lang('text-links');
$tmp2 = [];
$tmp2['btn-text'] = 'OpenAI';
$tmp2['btn-icon'] = $this->LIB->get_lang('icon-openai');
$tmp2['btn-icon-size'] = 14;
$tmp2['btn-href'] = 'https://openai.com/';
$tmp2['btn-target'] = '_blank';
$tmp2['btn-title'] = 'OpenAI
'.$tmp2['btn-href'].'
(opening on new tab)';
$tmp['list'][] = $tmp2;
//$tmp2 = [];
//$tmp2['btn-icon'] = $this->LIB->get_lang('icon-xai');
//$tmp2['btn-icon-size'] = 15;
//$tmp2['btn-href'] = 'https://x.ai/';
//$tmp2['btn-target'] = '_blank';
//$tmp2['btn-title'] = 'xAI'.'
'.$tmp2['btn-href'].'
(opening on new tab)';
//$tmp['list'][] = $tmp2;
$tmp2 = [];
// $tmp2['btn-icon'] = $this->LIB->get_lang('icon-bars-staggered');
$tmp2['btn-text'] = 'LM Studio';
$tmp2['btn-href'] = 'https://lmstudio.ai/';
$tmp2['btn-target'] = '_blank';
$tmp2['btn-title'] = 'LM Studio'.'
Discover, download, and run free local LLMs'.'
'.$tmp2['btn-href'].'
(opening on new tab)';
$tmp['list'][] = $tmp2;
if
(
isset($tmp['list'])
)
{
$data['footer_btns']['list'][] = $tmp;
}
$tmp = [];
$tmp['title'] = $this->LIB->get_lang('text-module');
$tmp2 = [];
$tmp2['btn-text'] = $this->LIB->VARS['SELF']['VER_STR'];
$tmp2['btn-is_copy'] = true;
$tmp['list'][] = $tmp2;
$tmp2 = [];
$tmp2['btn-icon'] = $this->LIB->get_lang('icon-cog');
$tmp2['btn-href'] = $this->LIB->VARS['links']['self-settings'];
$tmp2['btn-title'] = $this->LIB->get_lang('text-module_settings').'';
if
(
isset($this->LIB->request->post['is_nav__AI_req_open'])
&&$this->LIB->request->post['is_nav__AI_req_open']
)
{
$tmp2['btn-target'] = '_blank';
$tmp2['btn-title'] = $this->LIB->get_lang('text-module_settings').'
(opening on new tab)';
}
$tmp['list'][] = $tmp2;
$tmp2 = [];
$tmp2['btn-icon'] = $this->LIB->get_lang('icon-help');
$tmp2['btn-title'] = $this->LIB->get_lang('text-help').'
(opening in modal)';
$tmp2['btn-is_modal'] = true;
$tmp2['btn-modal-action_type'] = 'nav__help';
$tmp2['btn-modal-class'] = '_'.$this->LIB->VARS['NC'].'nav__modal';
$tmp['list'][] = $tmp2;
if
(
isset($tmp['list'])
)
{
$data['footer_btns']['list'][] = $tmp;
}
//---
$data['tpl_path'] = 'navs/'.__FUNCTION__;
return $this->LIB->output($this->LIB->get_tpl5($data));
}
function page__admin_settings() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
if
(
$this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])
&&(isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='0'
||isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='false'
||isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='off')
)
{
$tmp = [];
$tmp['base']['list']['IS_DEV_MODE'] = false;
$this->LIB->settings__set('main', $tmp);
}
else
if
(
!$this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])
&&(isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='1'
||isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='on'
||isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='')
)
{
$tmp = [];
$tmp['base']['list']['IS_DEV_MODE'] = true;
$this->LIB->settings__set('main', $tmp);
}
// get pre setting_mode_key
$setting_mode_key = 'main';
if (isset($this->LIB->request->post['setting_mode_key']))
{
$setting_mode_key = $this->LIB->request->post['setting_mode_key'];
}
else
if (isset($this->LIB->request->get['type']))
{
$setting_mode_key = $this->LIB->request->get['type'];
}
// save // post
$is_reload_premium = false;
if (!empty($this->LIB->request->post)) {
if (isset($this->LIB->request->post[$this->LIB->VARS['_settings_key']])) {
$this->LIB->VARS[$f['name']]['action_set'] = true;
$is_show_noty = 1;
if (isset($this->LIB->request->post['is_show_noty'])) {
$is_show_noty = $this->LIB->request->post['is_show_noty'];
}
if
(
isset($this->LIB->request->post[$this->LIB->VARS['_settings_key']]['main']['premium']['list']['premium_access']['premium_access_key'])
&&$this->LIB->request->post[$this->LIB->VARS['_settings_key']]['main']['premium']['list']['premium_access']['premium_access_key']!==$this->LIB->SETTINGS__get_item('main/premium/list/premium_access/premium_access_key')
)
{
$is_reload_premium = true;
}
$res_set = [];
foreach ($this->LIB->request->post[$this->LIB->VARS['_settings_key']] as $k_settings => $l_settings) {
// $res_set[] = $this->LIB->settings__set($k_settings, $l_settings);
$tmp_fname = [];
$tmp_fname[] = 'settings__set';
if
(
$tmp_fname = $this->LIB->is_fname($tmp_fname)
)
{
// echo("\n".__METHOD__."::".__LINE__."\n".'tmp_fname'."\n");print_r(@$tmp_fname);echo("\n\n");
// exit;
$res_set[] = $this->LIB->$tmp_fname($k_settings, $l_settings);
}
}
$res_set = !array_search('false', $res_set);
if ($res_set===true)
{
$this->LIB->VARS[$f['name']]['action_set_done'] = true;
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'success',
'type_sub' => 'save',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
"save",
"success",
],
'data' => $res_set,
'is_noty' => true,
'click_close' => true,
'timeout' => 5000,
'id' => $this->LIB->VARS['name']['_code-'].'log-'.$f['name'].'',
]);
}
else
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'critical_error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
"!save",
],
'data' => $res,
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'id' => $this->LIB->VARS['name']['_code-'].'log-'.$f['name'].'',
]);
}
}
}
// page data
// $startTime = microtime(true);
$res = [];
$data = [];
// load_SETTINGS by setting_mode_key (not main - already loaded) // get true setting_mode_key
$is_load_SETTINGS = $this->LIB->load_SETTINGS($setting_mode_key);
// redirect to main
if ($is_load_SETTINGS===false) {
wp_redirect(admin_url('admin.php?page=ai_gpt_tools-settings'));
}
// reload_premium
if
(
$is_reload_premium
)
{
$this->LIB->load_PREMIUM();
if
(
$this->LIB->VARS['IS_PREMIUM']
)
{
$this->LIB->AC['doc_scroll_reset'] = true;
}
}
$this->LIB->VARS['tmp']['setting_mode_key'] = $setting_mode_key;
$this->LIB->VARS['tmp']['setting_mode'] = explode('-',$this->LIB->VARS['tmp']['setting_mode_key'])[0];
$this->LIB->VARS['tmp']['settings_post_key'] = $this->LIB->VARS['_settings_key'].'['.$this->LIB->SETTINGS__get_item([$this->LIB->VARS['tmp']['setting_mode_key'],'setting_mode','setting_mode_key',]).']';
//---
// breadcrumbs
$data['breadcrumbs'] = [];
$data['breadcrumbs']['title'] = [
'text' => $this->LIB->VARS['name']['title'],
'href' => '',
];
$setting_mode__prefix = '';
if
(
$this->LIB->VARS['tmp']['setting_mode']==='main'
)
{
$setting_mode__prefix = 'Settings mode > ';
}
$data['breadcrumbs'][] = [
'text' => $setting_mode__prefix.$this->LIB->SETTINGS__get_item([$this->LIB->VARS['tmp']['setting_mode_key'],'setting_mode','title',]),
'href' => '',
];
// nav_t
$data['tpl_path'] = 'parts/settings_blocks/nav_t';
$data['nav_t'] = $this->LIB->get_tpl5($data);
// page
$pre_settings_sections = [];
$fnames_arr = [
$f['prefix'].'pre_settings_sections',
'PREMIUM_'.$f['prefix'].'pre_settings_sections',
];
foreach ($fnames_arr as $k_ => $l_) {
if
(
$tmp_fname = $this->LIB->is_fname([$l_])
)
{
$pre_settings_sections = $this->LIB->$tmp_fname($pre_settings_sections);
}
}
//---
// redirect to main
if (empty($pre_settings_sections)) {
wp_redirect(admin_url('admin.php?page=ai_gpt_tools-settings'));
}
//---
// pre_settings_sections process
foreach ($pre_settings_sections as $k_ => &$l_) {
if (!isset($l_['lang_prefix'])) {
$l_['lang_prefix'] = 'text-settings_sections-';
}
if (!isset($l_['title'])) {
$l_['title'] = $this->LIB->get_lang($l_['lang_prefix'].$k_.'-title');
}
foreach ($l_['data'] as $k_d => &$l_d) {
foreach ($l_d as $k_2 => &$block_arr) {
$this->LIB->VARS['tmp']['page_data_type'] = $k_;
$block_arr['tpl_is_tmp_cache'] = 0;
$block_arr['tpl'] = $this->LIB->get_tpl5($block_arr);
if
(
$block_arr['tpl']===''
)
{
unset($block_arr);
}
}
}
}
$data['sections'] = $pre_settings_sections;
$this->LIB->VARS['tmp']['page_data_type'] = $f['name'];
// cssjs
$arr = [];
$arr[$this->LIB->VARS['cssjs']['path']."main".$this->LIB->VARS['cssjs']['is_min_str_addon'].".css"] = 'css';
$this->LIB->add__cssjs($arr);
// tpl
// $startTime = microtime(true);
$data['tpl_path'] = 'pages/'.$f['name'];
// echo("\n".__METHOD__."::".__LINE__."\n".'data'."\n");print_r(@$data);echo("\n\n");
$output = $this->LIB->output($this->LIB->get_tpl5($data));
// echo("\n".__METHOD__."::".__LINE__."\n".'dev__get_func_log'."\n");print_r($this->LIB->dev__get_func_log());echo("\n\n");
return $output;
// echo "Elapsed time is: ". ((microtime(true) - $startTime) * 1000) ." seconds";
}
function nav__settings_modes() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = [];
$data = [];
$data['post_key'] = $this->LIB->VARS['_settings_key'];
//---
if (!empty($this->LIB->request->post)) {
$res_post = [];
$fnames_arr = [
$f['prefix'].'post',
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$res_post = $this->LIB->$tmp_fname($data);
}
if
(
isset($res_post['is_return'])
&&$res_post['is_return']
)
{
return $res_post;
}
}
//---
$data['btn__cron__add'] = '';
$fnames_arr = [
$f['prefix'].'get__btn__cron__add',
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$data['btn__cron__add'] = $this->LIB->$tmp_fname();
}
//---
// get other
$data['settings_modes_arr'] = '';
$fnames_arr = [
$f['prefix'].'get_list_arr',
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$data['settings_modes_arr'] = $this->LIB->$tmp_fname();
}
//---
// add main item first
// cant be delete or change
// $data['settings_modes_arr'] = array_reverse();
$tmp_key = 'main';
$tmp = [];
$tmp[$tmp_key] = [];
$tmp[$tmp_key]['setting_mode']['setting_mode_key'] = $tmp_key;
$tmp[$tmp_key]['setting_mode']['title'] = $this->LIB->get_lang('text-setting_mode-'.$tmp_key);
$tmp[$tmp_key]['setting_mode']['setting_mode_id'] = 0;
array_splice($data['settings_modes_arr'], 0, 0, $tmp);
//---
// tpl
$data['tpl_path'] = 'navs/'.$f['name'];
$res = $this->LIB->get_tpl5($data);
//---
return $res;
}
function nav__help() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = [];
$data = [];
$sections = [];
$tmp_fname = [
implode('__',[$f['name'],'sections','get',])
];
if
(
$tmp_fname = $this->LIB->is_fname($tmp_fname)
)
{
$sections = $this->LIB->$tmp_fname();
}
$data['sections'] = $sections;
//---
// echo("\n".__METHOD__."::".__LINE__."\n".'data'."\n");print_r(@$data);echo("\n\n");
$data['tpl_path'] = 'navs/'.__FUNCTION__;
return $this->LIB->output($this->LIB->get_tpl5($data));
}
function nav__AI_req() {
// echo("\n".__METHOD__."::".__LINE__."\n".'detect_page__key'."\n");print_r(json_decode(base64_decode($this->LIB->request->post['detect_page__key']),true));echo("\n\n");
$this->LIB->dev__func_log(__METHOD__,__LINE__);
//---
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$this->LIB->is_nav__AI_req = true;
//---
// check/get importat params
$this->LIB->nav__AI_req__process_post_keys();
//---
$res = [];
$data = [];
$sections = [];
$this->LIB->VARS['tmp']['settings_post_key'] = $this->LIB->VARS['_settings_key'].'['.$this->LIB->VARS['tmp']['setting_mode_key'].']';
// echo("\n".__METHOD__."::".__LINE__."\n".'page_data_type'."\n");print_r($this->LIB->VARS['tmp']['page_data_type']);echo("\n\n");
if
(
isset($this->LIB->VARS['tmp']['page_data_type'])
&&!$this->LIB->SETTINGS__get_item(['main',$this->LIB->VARS['tmp']['page_data_type'],'status',])
)
{
$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'],
'!status',
],
'is_print' => true,
'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'].'',
]);
}
//---
$sections = [];
$tmp_fname = [
$f['name'].'__sections__get__'.$this->LIB->VARS['tmp']['page_data_type'],
];
if
(
$tmp_fname = $this->LIB->is_fname($tmp_fname)
)
{
$sections = $this->LIB->$tmp_fname($this->LIB->VARS['tmp']['page_data_id']);
}
else
{
$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__,
'!sections',
],
'is_print' => true,
'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;
}
$this->LIB->throw_new_log([
'on_off' => 0,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'sections',
],
'data' => $sections,
'is_print' => true,
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
$this->LIB->throw_new_log([
'on_off' => 0,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
$this->LIB->VARS['tmp']['page_data_type'],
'after get_pre_arr',
'request post',
],
'data' => $this->LIB->request->post,
'is_print' => true,
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
$this->LIB->throw_new_log([
'on_off' => 0,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'tmp',
],
'data' => $this->LIB->VARS['tmp'],
'is_print' => true,
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
// pre_sections process
foreach ($sections as $k_section => &$section) {
// $this->LIB->VARS['DEBUG']['LOG'] = $section;
if
(
isset($section['col_1']['data'])
)
{
$this->LIB->VARS['DEBUG']['LOG'] = $section['col_1']['data'];
}
foreach ($section as $k_col => &$block_arr) {
if (!in_array($k_col, ['top','col_1','col_2'])) {continue;};
$block_arr['tpl_is_tmp_cache'] = 0;
// echo("\n".__METHOD__."::".__LINE__."\n".'block_arr'."\n");print_r(@$block_arr);echo("\n\n");
$block_arr['tpl'] = $this->LIB->get_tpl5($block_arr);
}
}
$data['sections'] = $sections;
//---
$data['tpl_path'] = 'navs/'.__FUNCTION__;
$res = $this->LIB->output($this->LIB->get_tpl5($data));
//---
// echo("\n".__METHOD__."::".__LINE__."\n".'dev__get_func_log'."\n");print_r($this->LIB->dev__get_func_log());echo("\n\n");
//---
return $res;
}
function nav__AI_req__section__get_data_ajax() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['prefix'] = implode('__',[$f['arr'][0],$f['arr'][1],$f['arr'][2],]).'__';
// $f['___']
//---
// check importat params
$this->LIB->nav__AI_req__process_post_keys(true);
//---
$res = '---pass---';
$data = [];
$this->LIB->VARS['tmp']['post_key']=
$this->LIB->VARS['tmp']['section_post_key']=
$data['post_key']=
'sections['.$this->LIB->VARS['tmp']['section_key'].']';
//---
if
(
isset($this->LIB->VARS['tmp']['page_data_type'])
&&!$this->LIB->SETTINGS__get_item(['main',$this->LIB->VARS['tmp']['page_data_type'],'status',])
)
{
$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'],
'!status',
],
'is_print' => true,
'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'].'',
]);
}
//---
// status check
if
(
!$this->LIB->VARS['tmp']['section_settings']['status']
)
{
return $res;
}
//---
// get resp arr
$tmp_fname = $f['prefix'].'resp_arr';
$data['resp_arr'] = $this->LIB->$tmp_fname();
if
(1
&&empty($data['resp_arr'])
)
{
$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__,
'!resp_arr',
'empty',
],
'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'].'',
]);
}
// get resp // if resp_arr return pass
if
(1
&&isset($data['resp_arr']['pass'])
&&$data['resp_arr']['pass']
)
{
return $res;
}
//---
// get resp tpl
$data['tpl_path'] = 'parts/AI_req_sections/'.$this->LIB->VARS['tmp']['section_key'].'-resp';
$fnames_arr = [
$f['prefix'].'resp_tpl'.'__'.$this->LIB->VARS['tmp']['section_key'].'__'.$this->LIB->VARS['tmp']['page_data_type'],
$f['prefix'].'resp_tpl'.'__'.$this->LIB->VARS['tmp']['section_key'],
$f['prefix'].'resp_tpl',
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$res = $this->LIB->$tmp_fname($data);
}
// echo("\n".__METHOD__."::".__LINE__."\n".'dev__get_func_log'."\n");print_r($this->LIB->dev__get_func_log());echo("\n\n");
// exit;
//---
return $res;
}
function nav__AI_req__section__set_data_ajax() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
$f['prefix2'] = implode('__',[$f['arr'][0],$f['arr'][1],$f['arr'][2],]).'__';
// $f['___']
//---
// check importat params
$this->LIB->nav__AI_req__process_post_keys(true);
//---
$res = '---pass---';
$data = [];
$this->LIB->VARS['tmp']['post_key']=
$this->LIB->VARS['tmp']['section_post_key']=
$data['post_key']=
'sections['.$this->LIB->VARS['tmp']['section_key'].']';
//---
if
(
isset($this->LIB->VARS['tmp']['page_data_type'])
&&!$this->LIB->SETTINGS__get_item(['main',$this->LIB->VARS['tmp']['page_data_type'],'status',])
)
{
$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'],
'!status',
],
'is_print' => true,
'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'].'',
]);
}
//---
// status check
if
(
!$this->LIB->VARS['tmp']['section_settings']['status']
)
{
return $res;
}
//---
$fnames_arr = [
$f['prefix2'].'set'
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$set = $this->LIB->$tmp_fname($this->LIB->request->post);
}
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__,
'!is_fname',
],
'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'].'',
]);
}
if
(
isset($set['pass'])
)
{
return $res;
}
if
(
!(int)$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__,
$this->LIB->VARS['tmp']['section_key'],
'!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'].'',
]);
}
$this->LIB->VARS['tmp']['page_data_id'] = $set;
$this->LIB->VARS['tmp']['admin_link_edit'] = $this->LIB->get_post_admin_link_edit($set);
$this->LIB->detect_page([
'page_url' => $this->LIB->VARS['tmp']['admin_link_edit'],
]);
//---
$section = $this->LIB->nav__AI_req__section__get_pre_arr();
foreach ($section as $k_col => $block_arr) {
if (!in_array($k_col, ['col_1'])) {continue;};
$block_arr['tpl_is_tmp_cache'] = 0;
$res = $block_arr['tpl'] = $this->LIB->get_tpl5($block_arr);
}
//---
return $res;
}
function nav_autocomplete__AI_get_api_urls() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][1];
// $f['___']
//---
$res = '';
$get = $this->LIB->AI__get_api_urls();
$data['list'] = [];
foreach ($get as $k_ => $l_) {
$data['list'][$k_]['value'] = $l_;
$data['list'][$k_]['text'] = $l_;
if
(
isset($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search']))
)
{
$data['list'][$k_]['text'] = $this->LIB->search_str_highlight($data['list'][$k_]['text'], $this->LIB->request->get['filter_search']);
}
}
sort($data['list']);
$data['tpl_path'] = 'parts/autocomplete';
$res = $this->LIB->get_tpl5($data);
//---
return $res;
}
function nav_autocomplete__AI_get_models_list() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = '';
if
(
isset($this->LIB->request->post['setting_mode_key'])
)
{
$this->LIB->VARS['tmp']['setting_mode_key'] = $this->LIB->request->post['setting_mode_key'];
}
$this->LIB->load_SETTINGS($this->LIB->VARS['tmp']['setting_mode_key']);
$this->LIB->settings__AI_connect_wrap($this->LIB->VARS['tmp']['setting_mode_key']);
$list = $this->LIB->AI__get_models_list();
if
(
!isset($list['data'])
||empty($list['data'])
)
{
return $res;
}
$data = [];
$data['id'] = '_'.$this->LIB->VARS['NC'].$f['name'];
if
(
isset($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search']))
)
{
$input = $this->LIB->request->get['filter_search'];
$tmp = array_filter($list['data'], function ($item) use ($input) {
if (stripos($item['id'], $input) !== false) {
return true;
}
return false;
});
if
(
!empty($tmp)
&&count($tmp)>1
)
{
$list['data'] = $tmp;
}
}
$data['list'] = [];
foreach ($list['data'] as $k_ => $l_) {
$data['list'][$k_]['value'] = $l_['id'];
$data['list'][$k_]['text'] = $l_['id'];
if
(
isset($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search']))
)
{
$data['list'][$k_]['text'] = $this->LIB->search_str_highlight($l_['id'], $this->LIB->request->get['filter_search']);
}
}
sort($data['list']);
$data['tpl_path'] = 'parts/autocomplete';
$res = $this->LIB->get_tpl5($data);
//---
return $res;
}
function nav_autocomplete__post() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][1];
// $f['___']
//---
$res = '';
$get_params = [];
$get_params['post_type'] = $f['key'];
$get_params['numberposts'] = 25;
if
(
!(isset($this->LIB->request->get['filter_search'])
&&is_string($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search'])))
)
{
$get = $this->LIB->get_all__post($get_params);
}
if
(
is_numeric(trim($this->LIB->request->get['filter_search']))
)
{
$get_params['post__in'] = [$this->LIB->request->get['filter_search']];
}
else
{
$get_params['filter_search'] = $this->LIB->request->get['filter_search'];
}
if
(
!empty($get_params)
)
{
$get = $this->LIB->get_all__post($get_params);
}
$data['list'] = [];
foreach ($get->posts as $k_ => $l_) {
$data['list'][$k_]['id'] = $l_->ID;
$data['list'][$k_]['value'] = $l_->ID.' // '.$l_->post_title;
$data['list'][$k_]['text'] = $l_->post_title;
if
(
isset($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search']))
)
{
$data['list'][$k_]['text'] = $this->LIB->search_str_highlight($data['list'][$k_]['text'], $this->LIB->request->get['filter_search']);
}
}
sort($data['list']);
$data['tpl_path'] = 'parts/autocomplete';
$res = $this->LIB->get_tpl5($data);
//---
return $res;
}
//--------------------------------
// OTHER
function fread_full_wp($fpath) {
global $wp_filesystem;
// Initialize the WP filesystem, no more using 'file-put-contents' function
//if (empty($wp_filesystem)) {
// require_once ($this->LIB->VARS['path']['SYS_ROOT'] . '/wp-admin/includes/file.php');
// WP_Filesystem();
//}
//$file = $wp_filesystem->exists($fpath);
$file = $wp_filesystem->get_contents($fpath);
return $file;
}
function fwrite_wp($fpath, $fdata) {
global $wp_filesystem;
// Initialize the WP filesystem, no more using 'file-put-contents' function
//if (empty($wp_filesystem)) {
// require_once ($this->LIB->VARS['path']['SYS_ROOT'] . '/wp-admin/includes/file.php');
// WP_Filesystem();
//}
$pathinfo = pathinfo($fpath);
wp_mkdir_p($pathinfo['dirname']);
$file = $wp_filesystem->put_contents($fpath, $fdata, FS_CHMOD_FILE);
if ($file)
{
// File created successfully
return true;
}
else
{
// Error creating file
return false;
}
}
function create_dir($path) {
if (is_dir($path) === false) {
// mkdir($path, 0777, true);
wp_mkdir_p($path, 0777, true);
}
}
function create_dirs_in_path($path, $path2 = '', $is_absolute_pathes = true) {
$tmp = $path;
if
(
$ext = pathinfo($tmp, PATHINFO_EXTENSION)
)
{
$tmp = dirname($tmp);
}
$tmp = rtrim($tmp, "/");
$tmp_arr = preg_split('@[\/\\\\]@', $tmp);
$tmp_str = '';
$tmp_arr2 = array();
foreach ($tmp_arr as $k => $l) {
$tmp_str = $tmp_str.$l;
$tmp_str = rtrim($tmp_str, "/");
$tmp_str = $tmp_str.'/';
$tmp_arr2[] = $tmp_str;
}
if ($is_absolute_pathes) {
$path2 = '';
}
foreach ($tmp_arr2 as $k => $l) {
if (!file_exists($path2.$l)) {
$this->create_dir($path2.$l);
}
}
return $path;
}
function get_site_address_arr() {
$res = [];
//---
$res['address'] = get_option('home');
$res['address'] = trim($res['address']);
$res['short'] = str_replace(['https://','http://'],'',$res['address']);
$res['short'] = explode('.',$res['short'])[0];
//---
return $res;
}
function get_site_name() {
$res = get_option('blogname');
$res = trim($res);
//---
return $res;
}
function get_site_desc() {
$res = get_option('blogdescription');
$res = trim($res);
//---
return $res;
}
function get_site_locale() {
$res = get_locale();
//---
return $res;
}
function get_site_creation_date() {
$res = mysql2date('Y.m.d', get_user_option('user_registered', 1));
//---
return $res;
}
function get_post_statuses() {
$res = get_post_statuses();
//---
return $res;
}
function get_post_admin_link_edit($id) {
$res = get_edit_post_link($id);
//---
return $res;
}
function is_fname($fnames_arr=[], $target=false, $is_addon=true) {
$res = false;
//---
$fnames_arr = $this->LIB->filter_arr($fnames_arr);
if
(1
&&$res === false
&&$is_addon
&&isset($this->LIB->VARS['IS_PREMIUM'])
&&$this->LIB->VARS['IS_PREMIUM']
)
{
$p_prefix = 'PREMIUM_';
foreach ($fnames_arr as $k_ => $l_) {
if
(
stripos($l_, 'product')!==false
&&
!$this->LIB->VARS['is_active_plugins']['woocommerce']
)
{
continue;
}
if
(
substr($l_, 0, strlen($p_prefix))===$p_prefix
)
{
continue;
}
$tmp_fname = $p_prefix.$l_;
if
(
(stripos($l_, $p_prefix)!==false)
)
{
$tmp_fname = $l_;
}
if
(
$res !== false
)
{
continue;
}
if
(
$res === false
&&(
($target!==false && isset($target->$tmp_fname) && $target->$tmp_fname instanceof Closure)
||(isset($this->LIB->$tmp_fname) && $this->LIB->$tmp_fname instanceof Closure)
)
)
{
$res = $tmp_fname;
}
}
}
if
(1
&&$res === false
)
{
foreach ($fnames_arr as $k_ => $l_) {
$tmp_fname = $l_;
if
(
$res !== false
)
{
continue;
}
if
(
$res === false
&&(
($target!==false && method_exists($target, $tmp_fname))
||($target!==false && isset($target->$tmp_fname) && $target->$tmp_fname instanceof Closure)
||method_exists($this->LIB, $tmp_fname)
||(isset($this->LIB->$tmp_fname) && $this->LIB->$tmp_fname instanceof Closure)
)
)
{
$res = $tmp_fname;
}
}
}
//---
return $res;
}
function backoff($p=[]) {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$p = $this->LIB->process__func_params([
'do' => function(){},
'strategy' => (string)'exponential',
'strategy_num' => (int)3,
'init_time' => (int)100,
'attempts' => (int)5,
], func_get_args());
$do = $p['do'];
unset($p['do']);
// $p['___']
//---
$res;
//---
if
(
$p['strategy_num']<1
)
{
$p['strategy_num'] = 2;
}
$p['init_time'] = ($p['init_time']*1000);
$p['attempt'] = 1;
while ($p['attempt']<=$p['attempts']) {
$res = $do($p);
if
(
// !$res
$res===false
)
{
usleep($p['init_time']);
$p['attempt'] = $p['attempt']+1;
switch ($p['strategy']) {
default:
case 'exponential':
$p['init_time'] = $p['init_time']*$p['strategy_num'];
break;
}
}
else
{
return $res;
}
}
//---
return $res;
}
//--------------------------------
// OTHER small
function add__cssjs($arr=[], $is_plugins_url=true) {
// for WP
if (empty($arr)) {return false;}
//---
foreach ($arr as $k_ => $l_) {
$url = $k_;
$filemtime = false;
if ($is_plugins_url) {
// if (!file_exists($this->LIB->VARS['path']['plugin_dir'].$k_)) {return false;}
if (!file_exists($this->LIB->VARS['path']['plugin_dir'].$k_)) {continue;}
$url = plugins_url($k_, $this->LIB->VARS['path']['plugin_main_file']);
$filemtime = filemtime($this->LIB->VARS['path']['plugin_dir'].$k_);
}
switch ($l_) {
default:
return false;
break;
case 'css':
case 'style':
case 'wp_enqueue_style':
wp_enqueue_style($this->LIB->VARS['name']['title'].'-'.$this->LIB->get__rand_int(), $url, [], $filemtime, false);
break;
case 'js':
case 'script':
case 'wp_enqueue_script':
wp_enqueue_script($this->LIB->VARS['name']['title'].'-'.$this->LIB->get__rand_int(), $url, ['jquery'], $filemtime, false);
break;
}
}
//---
return true;
}
function get__rand_int($min = null, $max = null) {
// return rand($min, $max);
return wp_rand($min, $max);
}
function get__server_name() {
return @$this->LIB->request->server['SERVER_NAME'];
}
function str_to_class_name($str) {
$class = $str;
$class = str_replace('_',' ',$class);
$class = str_replace('-',' ',$class);
$class = str_replace(' ','',ucwords($class));
//---
return $class;
}
function get__array_first_item($arr=[]) {
return (!empty($arr)?array_values($arr)[0]:[]);
}
function get__array_last_item($arr=[]) {
return (!empty($arr)?array_reverse(array_values($arr))[0]:[]);
}
function get__array_first_key($arr=[]) {
return (!empty($arr)?array_keys($arr)[0]:[]);
}
function get__array_last_key($arr=[]) {
return (!empty($arr)?array_reverse(array_keys($arr))[0]:[]);
}
function align_str_tabs($data) {
if
(
$is_string = is_string($data)
)
{
$tmp = $data;
$data = [];
$data[] = $tmp;
}
array_walk_recursive($data,function(&$_l,$_k) {
$arr = explode("\n", $_l);
if
(
isset($arr[1])
)
{
$re = '/^\t+/s';
preg_match_all($re, $arr[1], $matches, PREG_SET_ORDER, 0);
if (!empty($matches)) {
$_l = str_replace($matches[0],'',$_l);
}
$_l = trim($_l);
}
});
if
(
$is_string
)
{
$data = $data[0];
}
//---
return $data;
}
function str_has_json_inside($str,$bool=true) {
// https://stackoverflow.com/a/21995025
$re = '/
\{ # { character
(?: # non-capturing group
[^{}] # anything that is not a { or }
| # OR
(?R) # recurses the entire pattern
)* # previous group zero or more times
\} # } character
/x';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
if
(
$bool
)
{
$res = false;
}
else
{
$res = '';
}
if
(
$bool
&&isset($matches[0][0])
)
{
$res = true;
}
else
if
(
!$bool
&&isset($matches[0][0])
)
{
$res = $matches[0][0];
}
//---
return $res;
}
function str_remove_json($str) {
$re = '/\{(?:[^{}]|(?R))*\}/x';
$subst = '';
$str = preg_replace($re, $subst, $str);
//---
return $str;
}
function markdown_table_to_arr__simple($str='') {
$res = [];
//---
$str = trim($str);
$arr1 = explode("\n",$str);
unset($arr1[0]);
unset($arr1[1]);
foreach ($arr1 as $k_ => $l_) {
$l_ = trim($l_);
$l_ = trim($l_, '|');
$arr2 = explode("|",$l_);
$res[] = $arr2;
}
//---
return $res;
}
function markdown_table_to_arr($str='') {
$res = [];
$res['header'] = [];
$res['row'] = [];
$res['rows'] = [];
$res['num_rows'] = 0;
//---
$str = trim($str);
$arr1 = explode("\n",$str);
$theader = $arr1[0];
$theader = trim($theader);
$theader = trim($theader, '|');
$theader = explode("|",$theader);
$theader = array_map('trim', $theader);
$res['header'] = $theader;
unset($arr1[0]);
unset($arr1[1]);
foreach ($arr1 as $k_ => $l_) {
if
(
!preg_match('/^\|(?:[\s\t]+)\d+(?:[\s\t]+)\|/', $l_, $matches, PREG_OFFSET_CAPTURE, 0)
)
{
continue;
}
$l_ = trim($l_);
$l_ = trim($l_, '|');
$arr2 = explode("|",$l_);
$arr2 = array_map('trim', $arr2);
$arr3 = [];
foreach ($arr2 as $k_2 => $l_2) {
$arr3[$theader[$k_2]] = $l_2;
}
$res['rows'][] = $arr3;
}
$res['num_rows'] = count($res['rows']);
if
(
isset($res['rows'][0])
)
{
$res['row'] = $res['rows'][0];
}
//---
return $res;
}
function numeric_list_to_arr($str_input='') {
$str_input = trim($str_input);
$str = $str_input;
$re = '/^\d+\. (.+?)$|^(?!\d+\. )(?:.|\n)+?$|/m';
$subst = '$1';
$str = preg_replace($re, $subst, $str);
$re = '/[\n\r]$/m';
$subst = '';
$str = preg_replace($re, $subst, $str);
if
(
!empty(trim($str))
)
{
$arr = explode("\n",$str);
}
else
{
$arr = explode("\n",$str_input);
}
$arr = $this->LIB->filter_arr($arr);
foreach ($arr as $k_ => $l_) {
$l_ = trim($l_,'"');
$l_ = trim($l_,"'");
$l_ = trim($l_,"`");
$arr[$k_] = $l_;
}
$res = $arr;
//---
return $res;
}
function bool_filter($str='') {
$str = trim($str);
$re = '/^(?:(?:\s+?|)(false(.+?|)|0(.+?|)|no(.+?|)))$/is';
$subst = '0';
$str = preg_replace($re, $subst, $str, 1);
$re = '/^(?:(?:\s+?|)(true(.+?|)|1(.+?|)|yes(.+?|)))$/is';
$subst = '1';
$str = preg_replace($re, $subst, $str, 1);
$re = '/[^01]+/is';
$subst = '0';
$str = preg_replace($re, $subst, $str, 1);
$res = (int)$str;
//---
return $res;
}
function slashes_fix($str='') {
$re = '/[\/\\\\]+/';
$subst = '/';
$str = preg_replace($re, $subst, $str);
//---
return $str;
}
function filter_str($str='') {
$str = wp_strip_all_tags($str);
//---
return $str;
}
function filter_arr($arr=[]) {
$res = [];
//---
if
(
is_array($arr)
)
{
$res = $arr;
// $res = @array_map('trim',$res);
foreach($res as $k_ => $l_){
if
(
is_string($l_)
)
{
$l_ = trim($l_);
$res[$k_] = $l_;
}
}
$res = array_filter($res);
$res = array_unique($res, SORT_REGULAR);
}
//---
return $res;
}
function trim_arr($arr=[]) {
$res = [];
//---
if
(
is_array($arr)
)
{
$res = $arr;
// $res = @array_map('trim',$res);
foreach($res as $k_ => $l_){
if
(
is_string($l_)
)
{
$l_ = trim($l_);
$res[$k_] = $l_;
}
}
}
//---
return $res;
}
function search_str_highlight($str, $request_search = '', $is_equal = false) {
if ($request_search==='') {
return $str;
}
$title_hl_class = '';
if ((!$is_equal && ($str != $request_search)) || $is_equal) {
$title_hl_class = '_'.$this->LIB->VARS['name']['code'].'-text_highlight';
}
// regex escape
$re = '/([\\\\\/$*()^.+|])/m';
$re_str = $request_search;
$re_subst = '\\\\$1';
$re_res = preg_replace($re, $re_subst, $re_str);
$re = '/('.$request_search.')/ui';
$subst = '$1';
$str = preg_replace($re, $subst, $str, 1);
//---
return $str;
}
function b64j_encode($data) {
$data = base64_encode($this->LIB->j_encode($data));
//---
return $data;
}
function b64j_decode($data) {
$data = json_decode(base64_decode($data),true);
//---
return $data;
}
function get_headers_content_type() {
$contentType = '';
//---
$headers = headers_list();
// get the content type header
foreach($headers as $header){
if (substr(strtolower($header),0,13) == "content-type:"){
list($contentType, $charset) = explode(";", trim(substr($header, 14), 2));
$contentType = trim($contentType);
}
}
//---
return $contentType;
}
function str_tags_to_arr($str='',$sep=',') {
$res = [];
//---
$res = explode($sep,$str);
$res = $this->LIB->filter_arr($res);
//---
return $res;
}
function arr_to_id_str($arr=[],$sep='-') {
$res = [];
//---
$arr = $this->LIB->filter_arr($arr);
$arr = implode($sep,$arr);
$res = $arr;
//---
return $res;
}
function j_encode($data=[]) {
// $data = json_encode($data);
$data = wp_json_encode($data, true);
//---
return $data;
}
function str_clean($str='') {
$str = wp_strip_all_tags($str);
$str = html_entity_decode($str);
$str = preg_replace('/\W+/', '', $str);
//---
return $str;
}
/**
* https://stackoverflow.com/a/44189105
* drupal 7.x
* @param array $array
* @param array|string $parents
* @param string $glue
* @return mixed
*/
function array_get_value(array &$array, $parents, $glue = '.')
{
if (!is_array($parents)) {
$parents = explode($glue, $parents);
}
$ref = &$array;
foreach ((array) $parents as $parent) {
if (is_array($ref) && array_key_exists($parent, $ref)) {
$ref = &$ref[$parent];
} else {
return null;
}
}
return $ref;
}
/**
* https://stackoverflow.com/a/44189105
* drupal 7.x
* @param array $array
* @param array|string $parents
* @param mixed $value
* @param string $glue
*/
function array_set_value(array &$array, $parents, $value, $glue = '.')
{
if (!is_array($parents)) {
$parents = explode($glue, (string) $parents);
}
$ref = &$array;
foreach ($parents as $parent) {
if (isset($ref) && !is_array($ref)) {
$ref = array();
}
$ref = &$ref[$parent];
}
$ref = $value;
}
/**
* https://stackoverflow.com/a/44189105
* drupal 7.x
* @param array $array
* @param array|string $parents
* @param string $glue
*/
function array_unset_value(&$array, $parents, $glue = '.')
{
if (!is_array($parents)) {
$parents = explode($glue, $parents);
}
$key = array_shift($parents);
if (empty($parents)) {
unset($array[$key]);
} else {
array_unset_value($array[$key], $parents);
}
}
/**
* Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
* to the end of the array.
*
* @param array $array
* @param string $key
* @param array $new
*
* @return array
*/
function array_insert_after( array $array, $key, array $new ) {
$keys = array_keys( $array );
$index = array_search( $key, $keys );
$pos = false === $index ? count( $array ) : $index + 1;
return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
}
function get_elapsed_time($timestamp1, $timestamp2) {
// phi-4
// Calculate the difference in seconds between the two timestamps
$diffInSeconds = abs($timestamp2 - $timestamp1);
// Determine the largest unit of time that fits into the difference
if ($diffInSeconds >= 3600) { // More than or equal to one hour
$hours = floor($diffInSeconds / 3600);
return "$hours" . "h";
} elseif ($diffInSeconds >= 600) { // More than or equal to ten minutes
$minutes = floor($diffInSeconds / 60);
return "$minutes" . "m";
} else { // Less than ten minutes
$seconds = floor($diffInSeconds);
return "$seconds" . "s";
}
}
}
?>