LIB-> //-------------------------------- // INIT private $initiated = false; private $is__wp_register_scripts__admin = false; private $LIB; function __call($method, $arguments) { return call_user_func_array(Closure::bind($this->$method, $this, get_called_class()), $arguments); } function init() { if ($this->initiated) {return;} $this->initiated = true; if (!current_user_can('administrator')) {return;} // load base $this->load_LIB(); $this->LIB->is_api_get = false; $this->LIB->process__SERVER(); $this->LIB->process__GET(); $this->LIB->load_VARS__base(); $this->LIB->load_LANG(); $this->wp_register_scripts__admin(); if ($this->LIB->process__POST()!==true) {return;} if ($this->LIB->access_check__PAGE()!==true) {return;} // load next $this->LIB->load_VARS__other(); $this->LIB->load_SETTINGS(); $this->load_PREMIUM(); $this->LIB->detect_page(); // echo("\n
".__METHOD__."::".__LINE__."\n".'WP debug error_get_last'."\n");print_r(error_get_last(),true);echo("\n\n");wp_die();
}
private function load_LIB($registry=false) {
// WP
$lib = 'libs/lib';
$lib_class = 'LibAiGptTools';
$path_base = realpath(dirname(__FILE__) . '/..');
$lib_file = ($path_base.'/'.str_replace('\\', '/', strtolower($lib)).'.php');
require_once($lib_file);
$lib_load = $lib_class;
$this->LIB = new $lib_load();
}
private function load_PREMIUM() {
$fp = $this->LIB->VARS['path']['plugin_dir-premium'];
if (!$this->LIB->is_active($this->LIB->VARS['name']['code-premium'])) {return;}
$f = $fp.'lang/lang.php';
if (file_exists($f)) {
$_ = $this->LIB->LANG;
@include_once($f);
if (isset($_)) {
$this->LIB->LANG = array_merge($this->LIB->LANG, $_);
}
unset($_);
}
$f = $fp.'mod/mod.php';
if (file_exists($f)) {
@include($f);
}
}
//--------------------------------
// WP register scripts
function wp_register_scripts__admin() {
if ($this->is__wp_register_scripts__admin) {return;} $this->is__wp_register_scripts__admin = true;
// admin plugin settings
add_action( 'admin_init', function($admin_bar) {
// as one field (json, base64)
// @codingStandardsIgnoreStart
register_setting($this->LIB->VARS['name']['_code-'].'settings-group', $this->LIB->VARS['name']['_code-'].'settings', array(
'type' => 'string',
'sanitize_callback' => array($this, 'wp_register_setting__sanitize_text_field'),
'default' => NULL,
));
// @codingStandardsIgnoreEnd
});
// admin menu
add_action( 'admin_menu', function($admin_bar) {
// top
// admin_bar_menu
$this->LIB->VARS['adminbar_btn_main'] = [];
add_action('admin_bar_menu', function($admin_bar){
$admin_bar->add_node([
'id' => $this->LIB->VARS['name']['_code'],
'title' => $this->LIB->get_tpl5('navs/'.'nav__adminbar_btn_main'),
]);
}, 999);
// side
add_menu_page($this->LIB->VARS['name']['title'], $this->LIB->VARS['name']['title'], 'manage_options', $this->LIB->VARS['name']['code'].'-settings', array( $this, 'page__admin_settings' ), 'data:image/svg+xml;base64,' . base64_encode($this->LIB->get_lang('icon-module_logo-w')));
});
// plugins page
add_filter( "plugin_action_links_".$this->LIB->VARS['path']['plugin_basename'], function($links) {
// $links = array_reverse($links);
array_push($links, 'Settings');
if
(
!$this->LIB->is_active($this->LIB->VARS['name']['code-premium'])
)
{
array_push($links, 'Get Premium');
}
// $links = array_reverse($links);
return $links;
});
// ajax // xhr
$arr = [
'api',
];
foreach ($arr as $k_ => $l_) {
add_action('wp_ajax_'.$this->LIB->VARS['name']['code_'].$l_, array($this, $l_));
}
// cssjs
$arr = [];
$arr[$this->LIB->VARS['cssjs']['path']."AWIT_Core7/AWIT.Core7".$this->LIB->VARS['cssjs']['is_min_str_addon'].".css"] = 'css';
$arr[$this->LIB->VARS['cssjs']['path']."AWIT_Core7/AWIT.Core7".$this->LIB->VARS['cssjs']['is_min_str_addon'].".js"] = 'js';
$arr[$this->LIB->VARS['cssjs']['path']."fonts".$this->LIB->VARS['cssjs']['is_min_str_addon'].".css"] = 'css';
$arr[$this->LIB->VARS['cssjs']['path']."inject".$this->LIB->VARS['cssjs']['is_min_str_addon'].".css"] = 'css';
$arr[$this->LIB->VARS['cssjs']['path']."inject".$this->LIB->VARS['cssjs']['is_min_str_addon'].".js"] = 'js';
$this->LIB->add__cssjs($arr);
}
function wp_register_setting__sanitize_text_field($input) {
return sanitize_text_field($input);
}
//--------------------------------
// PAGES // ACTIONS
function api($p=[]) {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['name']
//---
$this->LIB->is_api_get = true;
if ($this->LIB->process__POST()!==true) {wp_die(__METHOD__.':'.__FUNCTION__.':'.__LINE__);}
if
(
empty($p)
)
{
$p = $this->LIB->request->post;
}
else
{
$p = func_get_args();
}
$p = $this->LIB->process__func_params([
'is_post_check' => true,
'is_set_time_limit' => 7200,
'is_ignore_user_abort' => false,
'is_stream_start' => true,
'is_process__AC' => true,
'is_process__data' => true,
'is_return' => true,
'action_type' => '',
], $p);
// $p['___']
//---
$res = [];
$data = false;
//---
// type filter by key
if
(
!in_array($p['action_type'],$this->LIB->VARS['xhr_get__access_arr']['base'])
)
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'critical_error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!access',
],
'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'].'',
]);
}
if
(
$this->LIB->VARS['tmp'][$f['name']]['tmp_fname'] = $tmp_fname = $this->LIB->is_fname([$p['action_type']], $this)
)
{
if ($p['is_ignore_user_abort']) {
ignore_user_abort(true);
}
if ($p['is_set_time_limit']!==false) {
// @codingStandardsIgnoreStart
// set_time_limit($p['is_set_time_limit']);
// @codingStandardsIgnoreEnd
}
if ($p['is_stream_start']) {
$this->xhr_stream_start();
}
$data = $this->$tmp_fname();
}
else
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'critical_error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!access_f',
],
'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'].'',
]);
}
//---
// res AC data key
if ($p['is_process__data']) {
if (is_string($data) || !isset($data['data'])) {$res['data'] = $data;}
}
// AC addon
if ($p['is_process__AC']) {
$res = array_merge($res, $this->LIB->process__AC());
}
//---
// result // output
if ($p['is_return']) {
$this->LIB->output__xhr_get($res);
}
}
private function xhr_stream_start() {
// stream init
@header('Content-Encoding: none'); // Disable gzip compression
ob_end_flush(); // Stop buffer
ob_implicit_flush(1); // Implicit flush at each output command
// this is to make the buffer achieve the minimum size in order to flush data
echo esc_html(str_repeat(' ',1024*64));
}
function nav__help() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = [];
$data = [];
$sections = [];
$tmp_fname = [
implode('__',[$f['name'],'sections','get',])
];
if
(
$tmp_fname = $this->LIB->is_fname($tmp_fname)
)
{
$sections = $this->LIB->$tmp_fname();
}
$data['sections'] = $sections;
//---
$data['tpl_path'] = 'navs/'.__FUNCTION__;
return $this->LIB->output($this->LIB->get_tpl5($data));
}
function nav__adminbar_btn_main() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$data = [];
$data['is_active'] = true;
//---
$data['tpl_path'] = 'navs/'.__FUNCTION__;
return $this->LIB->output($this->LIB->get_tpl5($data));
}
function nav__main_menu() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = [];
$data = [];
$data['body'] = [];
$data['body']['list'] = [];
//---
$tmp = [];
$tmp['title'] = $this->LIB->get_lang('text-add_create_new');
foreach ($this->LIB->VARS['for_gen_page_types']['list'] as $k_ => $l_) {
$tmp2 = $this->LIB->nav__main_menu__get__item($k_);
if
(
!empty($tmp2)
)
{
if
(
isset($this->LIB->request->post['is_nav__AI_req_open'])
&&$this->LIB->request->post['is_nav__AI_req_open']
)
{
$tmp2['btn-is_disabled'] = true;
}
$tmp['list'][] = $tmp2;
}
}
if
(
isset($tmp['list'])
)
{
$data['body']['list'][] = $tmp;
}
//---
$data['footer_btns'] = [];
$data['footer_btns']['list'] = [];
$tmp = [];
$tmp['title'] = $this->LIB->get_lang('text-links');
$tmp2 = [];
$tmp2['btn-icon'] = $this->LIB->get_lang('icon-openai');
$tmp2['btn-icon-size'] = 14;
$tmp2['btn-href'] = 'https://openai.com/';
$tmp2['btn-target'] = '_blank';
$tmp2['btn-title'] = 'OpenAI
'.$tmp2['btn-href'].'
(opening on new tab)';
$tmp['list'][] = $tmp2;
//$tmp2 = [];
//$tmp2['btn-icon'] = $this->LIB->get_lang('icon-xai');
//$tmp2['btn-icon-size'] = 15;
//$tmp2['btn-href'] = 'https://x.ai/';
//$tmp2['btn-target'] = '_blank';
//$tmp2['btn-title'] = 'xAI'.'
'.$tmp2['btn-href'].'
(opening on new tab)';
//$tmp['list'][] = $tmp2;
$tmp2 = [];
// $tmp2['btn-icon'] = $this->LIB->get_lang('icon-bars-staggered');
$tmp2['btn-text'] = 'LM Studio';
$tmp2['btn-href'] = 'https://lmstudio.ai/';
$tmp2['btn-target'] = '_blank';
$tmp2['btn-title'] = 'LM Studio'.'
Discover, download, and run free local LLMs'.'
'.$tmp2['btn-href'].'
(opening on new tab)';
$tmp['list'][] = $tmp2;
if
(
isset($tmp['list'])
)
{
$data['footer_btns']['list'][] = $tmp;
}
$tmp = [];
$tmp['title'] = $this->LIB->get_lang('text-module');
$tmp2 = [];
$tmp2['btn-text'] = $this->LIB->VARS['SELF']['VER_STR'];
$tmp2['btn-is_copy'] = true;
$tmp['list'][] = $tmp2;
$tmp2 = [];
$tmp2['btn-icon'] = $this->LIB->get_lang('icon-cog');
$tmp2['btn-href'] = $this->LIB->VARS['links']['self-settings'];
$tmp2['btn-title'] = $this->LIB->get_lang('text-module_settings').'
(opening on new tab)';
$tmp2['btn-target'] = '_blank';
$tmp['list'][] = $tmp2;
$tmp2 = [];
$tmp2['btn-icon'] = $this->LIB->get_lang('icon-help');
$tmp2['btn-title'] = $this->LIB->get_lang('text-help').'
(opening in modal)';
$tmp2['btn-is_modal'] = true;
$tmp2['btn-modal-action_type'] = 'nav__help';
$tmp['list'][] = $tmp2;
if
(
isset($tmp['list'])
)
{
$data['footer_btns']['list'][] = $tmp;
}
//---
$data['tpl_path'] = 'navs/'.__FUNCTION__;
return $this->LIB->output($this->LIB->get_tpl5($data));
}
function page__admin_settings() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
if
(
$this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])
&&(isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='0'
||isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='false'
||isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='off')
)
{
$tmp = [];
$tmp['base']['list']['IS_DEV_MODE'] = false;
$this->LIB->settings__set('main', $tmp);
}
else
if
(
!$this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])
&&(isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='1'
||isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='on'
||isset($this->LIB->request->get['DEV'])&&$this->LIB->request->get['DEV']=='')
)
{
$tmp = [];
$tmp['base']['list']['IS_DEV_MODE'] = true;
$this->LIB->settings__set('main', $tmp);
}
// get pre setting_mode_key
$setting_mode_key = 'main';
if (isset($this->LIB->request->post['setting_mode_key']))
{
$setting_mode_key = $this->LIB->request->post['setting_mode_key'];
}
else
if (isset($this->LIB->request->get['type']))
{
$setting_mode_key = $this->LIB->request->get['type'];
}
// save // post
$is_reload_premium = false;
if (!empty($this->LIB->request->post)) {
if (isset($this->LIB->request->post[$this->LIB->VARS['_settings_key']])) {
$this->LIB->VARS[$f['name']]['action_set'] = true;
$is_show_noty = 1;
if (isset($this->LIB->request->post['is_show_noty'])) {
$is_show_noty = $this->LIB->request->post['is_show_noty'];
}
if
(
isset($this->LIB->request->post[$this->LIB->VARS['_settings_key']]['main']['premium']['list']['premium_access']['premium_access_key'])
&&$this->LIB->request->post[$this->LIB->VARS['_settings_key']]['main']['premium']['list']['premium_access']['premium_access_key']!==$this->LIB->SETTINGS__get_item('main/premium/list/premium_access/premium_access_key')
)
{
$is_reload_premium = true;
}
$res_set = [];
foreach ($this->LIB->request->post[$this->LIB->VARS['_settings_key']] as $k_settings => $l_settings) {
// $res_set[] = $this->LIB->settings__set($k_settings, $l_settings);
$tmp_fname = [];
$tmp_fname[] = 'settings__set';
if
(
$tmp_fname = $this->LIB->is_fname($tmp_fname)
)
{
// echo("\n".__METHOD__."::".__LINE__."\n".'tmp_fname'."\n");print_r(@$tmp_fname);echo("\n\n");
// exit;
$res_set[] = $this->LIB->$tmp_fname($k_settings, $l_settings);
}
}
$res_set = !array_search('false', $res_set);
if ($res_set===true)
{
$this->LIB->VARS[$f['name']]['action_set_done'] = true;
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'success',
'type_sub' => 'save',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
"save",
"success",
],
'data' => $res_set,
'is_noty' => true,
'click_close' => true,
'timeout' => 5000,
'id' => $this->LIB->VARS['name']['_code-'].'log-'.$f['name'].'',
]);
}
else
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'critical_error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
"!save",
],
'data' => $res,
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'id' => $this->LIB->VARS['name']['_code-'].'log-'.$f['name'].'',
]);
}
}
}
// page data
// $startTime = microtime(true);
$res = [];
$data = [];
// load_SETTINGS by setting_mode_key (not main - already loaded) // get true setting_mode_key
$is_load_SETTINGS = $this->LIB->load_SETTINGS($setting_mode_key);
// redirect to main
if ($is_load_SETTINGS===false) {
wp_redirect(admin_url('admin.php?page=ai_gpt_tools-settings'));
}
// reload_premium
if
(
$is_reload_premium
)
{
$this->load_PREMIUM();
if
(
$this->LIB->VARS['IS_PREMIUM']
)
{
$this->LIB->AC['doc_scroll_reset'] = true;
}
}
$this->LIB->VARS['tmp']['setting_mode_key'] = $setting_mode_key;
$this->LIB->VARS['tmp']['setting_mode'] = explode('-',$this->LIB->VARS['tmp']['setting_mode_key'])[0];
$this->LIB->VARS['tmp']['settings_post_key'] = $this->LIB->VARS['_settings_key'].'['.$this->LIB->SETTINGS__get_item([$this->LIB->VARS['tmp']['setting_mode_key'],'setting_mode','setting_mode_key',]).']';
//---
// breadcrumbs
$data['breadcrumbs'] = [];
$data['breadcrumbs']['title'] = [
'text' => $this->LIB->VARS['name']['title'],
'href' => '',
];
$data['breadcrumbs'][] = [
'text' => $this->LIB->SETTINGS__get_item([$this->LIB->VARS['tmp']['setting_mode_key'],'setting_mode','title',]),
'href' => '',
];
// nav_t
$data['tpl_path'] = 'parts/settings_blocks/nav_t';
$data['nav_t'] = $this->LIB->get_tpl5($data);
// page
$pre_settings_sections = [];
$fnames_arr = [
$f['prefix'].'pre_settings_sections',
'PREMIUM_'.$f['prefix'].'pre_settings_sections',
];
foreach ($fnames_arr as $k_ => $l_) {
if
(
$tmp_fname = $this->LIB->is_fname([$l_])
)
{
$pre_settings_sections = $this->LIB->$tmp_fname($pre_settings_sections);
}
}
//---
// redirect to main
if (empty($pre_settings_sections)) {
wp_redirect(admin_url('admin.php?page=ai_gpt_tools-settings'));
}
//---
// pre_settings_sections process
foreach ($pre_settings_sections as $k_ => &$l_) {
if (!isset($l_['lang_prefix'])) {
$l_['lang_prefix'] = 'text-settings_sections-';
}
if (!isset($l_['title'])) {
$l_['title'] = $this->LIB->get_lang($l_['lang_prefix'].$k_.'-title');
}
foreach ($l_['data'] as $k_d => &$l_d) {
foreach ($l_d as $k_2 => &$block_arr) {
$this->LIB->VARS['tmp']['page_data_type'] = $k_;
$block_arr['tpl_is_tmp_cache'] = 0;
$block_arr['tpl'] = $this->LIB->get_tpl5($block_arr);
if
(
$block_arr['tpl']===''
)
{
unset($block_arr);
}
}
}
}
$data['sections'] = $pre_settings_sections;
$this->LIB->VARS['tmp']['page_data_type'] = $f['name'];
// cssjs
$arr = [];
$arr[$this->LIB->VARS['cssjs']['path']."main".$this->LIB->VARS['cssjs']['is_min_str_addon'].".css"] = 'css';
$this->LIB->add__cssjs($arr);
// tpl
// $startTime = microtime(true);
$data['tpl_path'] = 'pages/'.$f['name'];
return $this->LIB->output($this->LIB->get_tpl5($data));
// echo "Elapsed time is: ". ((microtime(true) - $startTime) * 1000) ." seconds";
}
function nav__settings_modes() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = [];
$data = [];
$data['post_key'] = $this->LIB->VARS['_settings_key'];
//---
if (!empty($this->LIB->request->post)) {
$res_post = [];
$fnames_arr = [
$f['prefix'].'post',
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$res_post = $this->LIB->$tmp_fname($data);
}
if
(
isset($res_post['is_return'])
&&$res_post['is_return']
)
{
return $res_post;
}
}
//---
$data['btn__cron__add'] = '';
$fnames_arr = [
$f['prefix'].'get__btn__cron__add',
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$data['btn__cron__add'] = $this->LIB->$tmp_fname();
}
//---
// get other
$data['settings_modes_arr'] = '';
$fnames_arr = [
$f['prefix'].'get_list_arr',
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$data['settings_modes_arr'] = $this->LIB->$tmp_fname();
}
//---
// add main item first
// cant be delete or change
// $data['settings_modes_arr'] = array_reverse();
$tmp_key = 'main';
$tmp = [];
$tmp[$tmp_key] = [];
$tmp[$tmp_key]['setting_mode']['setting_mode_key'] = $tmp_key;
$tmp[$tmp_key]['setting_mode']['title'] = $this->LIB->get_lang('text-setting_mode-'.$tmp_key);
$tmp[$tmp_key]['setting_mode']['setting_mode_id'] = 0;
array_splice($data['settings_modes_arr'], 0, 0, $tmp);
//---
// tpl
$data['tpl_path'] = 'navs/'.$f['name'];
$res = $this->LIB->get_tpl5($data);
//---
return $res;
}
function nav__AI_req() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$this->LIB->is_nav__AI_req = true;
//---
// check/get importat params
$this->LIB->nav__AI_req__process_post_keys();
//---
$res = [];
$data = [];
$sections = [];
$this->LIB->VARS['tmp']['settings_post_key'] = $this->LIB->VARS['_settings_key'].'['.$this->LIB->VARS['tmp']['setting_mode_key'].']';
if
(
isset($this->LIB->VARS['tmp']['page_data_type'])
&&!$this->LIB->SETTINGS__get_item(['main',$this->LIB->VARS['tmp']['page_data_type'],'status',])
)
{
$this->LIB->throw_new_log([
'on_off' => true,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
$this->LIB->VARS['tmp']['page_data_type'],
'!status',
],
'is_print' => true,
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'text' => $this->LIB->get_lang('error-page_type_status_off'),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
//---
$sections = [];
$tmp_fname = [
$f['name'].'__sections__get__'.$this->LIB->VARS['tmp']['page_data_type'],
];
if
(
$tmp_fname = $this->LIB->is_fname($tmp_fname)
)
{
$sections = $this->LIB->$tmp_fname($this->LIB->VARS['tmp']['page_data_id']);
}
else
{
$this->LIB->throw_new_log([
'on_off' => true,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!sections',
],
'is_print' => true,
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
exit;
}
$this->LIB->throw_new_log([
'on_off' => 0,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'sections',
],
'data' => $sections,
'is_print' => true,
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
$this->LIB->throw_new_log([
'on_off' => 0,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
$this->LIB->VARS['tmp']['page_data_type'],
'after get_pre_arr',
'request post',
],
'data' => $this->LIB->request->post,
'is_print' => true,
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
$this->LIB->throw_new_log([
'on_off' => 0,
'type' => 'log',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'tmp',
],
'data' => $this->LIB->VARS['tmp'],
'is_print' => true,
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
// pre_sections process
foreach ($sections as $k_section => &$section) {
// $this->LIB->VARS['DEBUG']['LOG'] = $section;
if
(
isset($section['col_1']['data'])
)
{
$this->LIB->VARS['DEBUG']['LOG'] = $section['col_1']['data'];
}
foreach ($section as $k_col => &$block_arr) {
if (!in_array($k_col, ['top','col_1','col_2'])) {continue;};
$block_arr['tpl_is_tmp_cache'] = 0;
// echo("\n".__METHOD__."::".__LINE__."\n".'block_arr'."\n");print_r(@$block_arr);echo("\n\n");
$block_arr['tpl'] = $this->LIB->get_tpl5($block_arr);
}
}
$data['sections'] = $sections;
//---
$data['tpl_path'] = 'navs/'.__FUNCTION__;
return $this->LIB->output($this->LIB->get_tpl5($data));
}
function nav__AI_req__section__get_data_ajax() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['prefix'] = implode('__',[$f['arr'][0],$f['arr'][1],$f['arr'][2],]).'__';
// $f['___']
//---
// check importat params
$this->LIB->nav__AI_req__process_post_keys(true);
//---
$res = '---pass---';
$data = [];
$this->LIB->VARS['tmp']['post_key']=
$this->LIB->VARS['tmp']['section_post_key']=
$data['post_key']=
'sections['.$this->LIB->VARS['tmp']['section_key'].']';
//---
if
(
isset($this->LIB->VARS['tmp']['page_data_type'])
&&!$this->LIB->SETTINGS__get_item(['main',$this->LIB->VARS['tmp']['page_data_type'],'status',])
)
{
$this->LIB->throw_new_log([
'on_off' => true,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
$this->LIB->VARS['tmp']['page_data_type'],
'!status',
],
'is_print' => true,
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'text' => $this->LIB->get_lang('error-page_type_status_off'),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
//---
// status check
if
(
!$this->LIB->VARS['tmp']['section_settings']['status']
)
{
return $res;
}
//---
// get resp arr
$tmp_fname = $f['prefix'].'resp_arr';
$data['resp_arr'] = $this->LIB->$tmp_fname();
if
(1
&&empty($data['resp_arr'])
)
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!resp_arr',
'empty',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'text' => $data['errors'][0],
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
// get resp // if resp_arr return pass
if
(1
&&isset($data['resp_arr']['pass'])
&&$data['resp_arr']['pass']
)
{
return $res;
}
//---
// get resp tpl
$data['tpl_path'] = 'parts/AI_req_sections/'.$this->LIB->VARS['tmp']['section_key'].'-resp';
$fnames_arr = [
$f['prefix'].'resp_tpl'.'__'.$this->LIB->VARS['tmp']['section_key'].'__'.$this->LIB->VARS['tmp']['page_data_type'],
$f['prefix'].'resp_tpl'.'__'.$this->LIB->VARS['tmp']['section_key'],
$f['prefix'].'resp_tpl',
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$res = $this->LIB->$tmp_fname($data);
}
//---
return $res;
}
function nav__AI_req__section__set_data_ajax() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][4];
$f['prefix2'] = implode('__',[$f['arr'][0],$f['arr'][1],$f['arr'][2],]).'__';
// $f['___']
//---
// check importat params
$this->LIB->nav__AI_req__process_post_keys(true);
//---
$res = '---pass---';
$data = [];
$this->LIB->VARS['tmp']['post_key']=
$this->LIB->VARS['tmp']['section_post_key']=
$data['post_key']=
'sections['.$this->LIB->VARS['tmp']['section_key'].']';
//---
if
(
isset($this->LIB->VARS['tmp']['page_data_type'])
&&!$this->LIB->SETTINGS__get_item(['main',$this->LIB->VARS['tmp']['page_data_type'],'status',])
)
{
$this->LIB->throw_new_log([
'on_off' => true,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
$this->LIB->VARS['tmp']['page_data_type'],
'!status',
],
'is_print' => true,
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'text' => $this->LIB->get_lang('error-page_type_status_off'),
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
//---
// status check
if
(
!$this->LIB->VARS['tmp']['section_settings']['status']
)
{
return $res;
}
//---
$fnames_arr = [
$f['prefix2'].'set'
];
if
(
$tmp_fname = $this->LIB->is_fname($fnames_arr)
)
{
$set = $this->LIB->$tmp_fname($this->LIB->request->post);
}
else
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
'!is_fname',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'text' => $data['errors'][0],
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
if
(
isset($set['pass'])
)
{
return $res;
}
if
(
!(int)$set
)
{
$this->LIB->throw_new_log([
'on_off' => 1,
'type' => 'error',
'tags' => [
($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''),
__LINE__,
$this->LIB->VARS['tmp']['section_key'],
'!set',
],
'is_noty' => true,
'click_close' => true,
'timeout' => 180000,
'title' => $this->LIB->get_lang('error-code-0'),
'text' => $data['errors'][0],
'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'',
]);
}
$this->LIB->VARS['tmp']['page_data_id'] = $set;
$this->LIB->VARS['tmp']['admin_link_edit'] = $this->LIB->get_post_admin_link_edit($set);
$this->LIB->detect_page([
'page_url' => $this->LIB->VARS['tmp']['admin_link_edit'],
]);
//---
$section = $this->LIB->nav__AI_req__section__get_pre_arr();
foreach ($section as $k_col => $block_arr) {
if (!in_array($k_col, ['col_1'])) {continue;};
$block_arr['tpl_is_tmp_cache'] = 0;
$res = $block_arr['tpl'] = $this->LIB->get_tpl5($block_arr);
}
//---
return $res;
}
function nav_autocomplete__AI_get_api_urls() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][1];
// $f['___']
//---
$res = '';
$get = $this->LIB->AI__get_api_urls();
$data['list'] = [];
foreach ($get as $k_ => $l_) {
$data['list'][$k_]['value'] = $l_;
$data['list'][$k_]['text'] = $l_;
if
(
isset($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search']))
)
{
$data['list'][$k_]['text'] = $this->LIB->search_str_highlight($data['list'][$k_]['text'], $this->LIB->request->get['filter_search']);
}
}
sort($data['list']);
$data['tpl_path'] = 'parts/autocomplete';
$res = $this->LIB->get_tpl5($data);
//---
return $res;
}
function nav_autocomplete__AI_get_models_list() {
$f = $this->LIB->process__func_name(__FUNCTION__);
// $f['___']
//---
$res = '';
if
(
isset($this->LIB->request->post['setting_mode_key'])
)
{
$this->LIB->VARS['tmp']['setting_mode_key'] = $this->LIB->request->post['setting_mode_key'];
}
$this->LIB->load_SETTINGS($this->LIB->VARS['tmp']['setting_mode_key']);
$this->LIB->settings__AI_connect_wrap($this->LIB->VARS['tmp']['setting_mode_key']);
$list = $this->LIB->AI__get_models_list();
if
(
!isset($list['data'])
||empty($list['data'])
)
{
return $res;
}
$data = [];
$data['id'] = '_'.$this->LIB->VARS['NC'].$f['name'];
if
(
isset($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search']))
)
{
$input = $this->LIB->request->get['filter_search'];
$tmp = array_filter($list['data'], function ($item) use ($input) {
if (stripos($item['id'], $input) !== false) {
return true;
}
return false;
});
if
(
!empty($tmp)
&&count($tmp)>1
)
{
$list['data'] = $tmp;
}
}
$data['list'] = [];
foreach ($list['data'] as $k_ => $l_) {
$data['list'][$k_]['value'] = $l_['id'];
$data['list'][$k_]['text'] = $l['id'];
if
(
isset($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search']))
)
{
$data['list'][$k_]['text'] = $this->LIB->search_str_highlight($l_['id'], $this->LIB->request->get['filter_search']);
}
}
sort($data['list']);
$data['tpl_path'] = 'parts/autocomplete';
$res = $this->LIB->get_tpl5($data);
//---
return $res;
}
function nav_autocomplete__post() {
$f = $this->LIB->process__func_name(__FUNCTION__);
$f['key'] = @$f['arr'][1];
// $f['___']
//---
$res = '';
$get_params = [];
$get_params['post_type'] = $f['key'];
$get_params['numberposts'] = 25;
if
(
!(isset($this->LIB->request->get['filter_search'])
&&is_string($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search'])))
)
{
$get = $this->LIB->get_all__post($get_params);
}
if
(
is_numeric(trim($this->LIB->request->get['filter_search']))
)
{
$get_params['post__in'] = [$this->LIB->request->get['filter_search']];
}
else
{
$get_params['filter_search'] = $this->LIB->request->get['filter_search'];
}
if
(
!empty($get_params)
)
{
$get = $this->LIB->get_all__post($get_params);
}
$data['list'] = [];
foreach ($get->posts as $k_ => $l_) {
$data['list'][$k_]['id'] = $l_->ID;
$data['list'][$k_]['value'] = $l_->ID.' // '.$l_->post_title;
$data['list'][$k_]['text'] = $l_->post_title;
if
(
isset($this->LIB->request->get['filter_search'])
&&!empty(trim($this->LIB->request->get['filter_search']))
)
{
$data['list'][$k_]['text'] = $this->LIB->search_str_highlight($data['list'][$k_]['text'], $this->LIB->request->get['filter_search']);
}
}
sort($data['list']);
$data['tpl_path'] = 'parts/autocomplete';
$res = $this->LIB->get_tpl5($data);
//---
return $res;
}
}
?>