customUrl != "") { $url = str_replace(Url::OPEN_AI_URL, $this->customUrl, $url); } } } //-------------------------------- // CLASS #[AllowDynamicProperties] class LibAiGptTools { // $this->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; } //-------------------------------- // VARS function load_VARS__base() { // main $this->LIB->VARS['init_t_ms'] = (floor(microtime(true)*1000)); $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 GPT Tools'; $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.0.4';
$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'] = 0;
$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@...';
}
// PREMIUM
$this->LIB->VARS['IS_PLUGIN_PREMIUM_CONNECTED'] = false;
$this->LIB->VARS['IS_PREMIUM'] = false;
$this->LIB->VARS['PREMIUM_href'] = 'https://aiwordpress.biz';
// 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='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/'.$this->LIB->VARS['name']['code'].'~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,
], 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);
}
//---
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'] = $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';
}
else
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';
}
else
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;
}
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]);
}
$res[$l_[2]] = $val;
}
}
//---
// new var
if
(
empty($res)
)
{
$re = '/```((?:.|\n)*?[\n\r])((?:.|\n)*?)```/m';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
if
(
!empty($matches)
)
{
foreach ($matches as $k_ => $l_) {
$l_[1] = trim($l_[1]);
$l_[2] = trim($l_[2]);
$val = $l_[2];
$res[$l_[1]] = $val;
}
}
}
//---
if
(
empty($res)
)
{
$res['DATA'] = $str;
}
//---
return $res;
}
function AI__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 = new LibAiGptTools__Custom__OpenAi($this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','API_KEY',]));
$this->LIB->AI->__module_code_class____setBaseUrl(rtrim(trim($this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','API_URL',])),'/'));
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;
$tmp_API_URL = rtrim(trim($this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','API_URL'])),'/');
$this->LIB->AI = new LibAiGptTools__Custom__OpenAi($this->LIB->SETTINGS__get_item(['main','AI','list','AI_connect','API_KEY']));
$this->LIB->AI->__module_code_class____setBaseUrl(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);
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'])
&&!preg_match('/^(?:gpt-|o1-)/', trim($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'] = json_decode(base64_decode($this->LIB->request->post['detect_page__key']),true);
}
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']];
//---
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__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__site_desc() {
$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;
}
//---
$get = $this->LIB->get_site_desc();
if
(
!empty(trim($get))
)
{
$tmp = [];
$tmp['role'] = 'user';
$tmp['content'] = [];
$tmp['content'][] = '# TARGET WEBSITE DESCRIBTION / THEME';
$tmp['content'][] = $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;
}
//---
$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__key'] = $this->LIB->b64j_encode($tmp);
$block_arr['btn-icon'] = $this->LIB->get_lang('icon-plus');
$block_arr['btn-text'] = $this->LIB->get_lang('text-settings_sections-'.$f['key'].'-title');
$block_arr['btn-title'] = '(opening in modal)';
//---
return $block_arr;
}
function nav__main_menu__get__item__product($block_arr) {
$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;
}
//--- 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('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'] = [];
switch ($this->LIB->VARS['tmp']['section_settings']['length_type']) {
default:
$tmp['content'][] = '
TASK:
> Plz create proffesional article body
> exactly and only article body!
';
break;
case 'test':
$tmp['content'][] = '
> Plz create very small and short test article body in a few words
> exactly and only article body!
';
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('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']['DATA'];
if
(
wp_strip_all_tags($tmp)===$tmp
)
{
$re = '/(^.+?$)/m';
$subst = '$1
'; $tmp = preg_replace($re, $subst, $tmp); } $res['last_message']['parced_arr']['DATA'] = $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('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.'; $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) **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' => '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;
}
//--------------------------------
// 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 ) );
}
}
?>