-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnuclia.php
More file actions
220 lines (187 loc) · 5.71 KB
/
nuclia.php
File metadata and controls
220 lines (187 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/**
* Plugin Name: Progress Agentic RAG
* Plugin URI: https://github.com/nuclia/wordpress-plugin
* Description: Integrate the powerful Progress Agentic RAG service with WordPress
* Version: 1.0.0
* Requires at least: 6.8
* Requires PHP: 8.1
* Author: Progress Software
* Author URI: https://www.progress.com/
* Contributors: Serge Rauber, Radek Friedl
* License: GNU General Public License v2.0 / MIT License
* Text Domain: progress-agentic-rag
* Domain Path: /languages
*
* @since 1.0.0
* @package nuclia\wordpress-plugin
*/
// Nothing to see here if not loaded in WP context.
if ( ! defined( 'WPINC' ) ) die;
// The Nuclia Search plugin version.
define( 'PROGRESS_NUCLIA_VERSION', '1.0.0' );
// The minimum required PHP version.
define( 'PROGRESS_NUCLIA_MIN_PHP_VERSION', '8.1' );
// The minimum required WordPress version.
define( 'PROGRESS_NUCLIA_MIN_WP_VERSION', '6.8' );
define( 'PROGRESS_NUCLIA_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
define( 'PROGRESS_NUCLIA_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
define( 'PROGRESS_NUCLIA_PATH', __DIR__ . '/' );
/**
* Check for required PHP version.
*
* @since 1.0.0
*
* @return bool
*/
function nuclia_php_version_check(): bool {
if ( version_compare( PHP_VERSION, PROGRESS_NUCLIA_MIN_PHP_VERSION, '<' ) ) {
return false;
}
return true;
}
/**
* Check for required WordPress version.
*
* @since 1.0.0
*
* @return bool
*/
function nuclia_wp_version_check(): bool {
if ( version_compare( $GLOBALS['wp_version'], PROGRESS_NUCLIA_MIN_WP_VERSION, '<' ) ) {
return false;
}
return true;
}
/**
* Admin notices if requirements aren't met.
*
* @since 1.0.0
*/
function nuclia_requirements_error_notice(): void {
$notices = [];
if ( ! nuclia_php_version_check() ) {
$notices[] = sprintf(
/* translators: placeholder 1 is minimum required PHP version, placeholder 2 is installed PHP version. */
esc_html__(
'Nuclia plugin requires PHP %1$s or higher. You’re still on %2$s.',
'progress-agentic-rag'
),
PROGRESS_NUCLIA_MIN_PHP_VERSION,
PHP_VERSION
);
}
if ( ! nuclia_wp_version_check() ) {
$notices[] = sprintf(
/* translators: placeholder 1 is minimum required WordPress version,
placeholder 2 is installed WordPress version. */
esc_html__(
'Nuclia plugin requires at least WordPress in version %1$s, You are on %2$s.',
'progress-agentic-rag'
),
PROGRESS_NUCLIA_MIN_WP_VERSION,
esc_html( $GLOBALS['wp_version'] )
);
}
foreach ( $notices as $notice ) {
echo '<div class="notice notice-error"><p>' . esc_html( $notice ) . '</p></div>';
}
}
/**
* I18n.
*
* @since 1.0.0
*/
function nuclia_load_textdomain(): void {
load_plugin_textdomain(
'progress-agentic-rag',
false,
plugin_basename( dirname( __FILE__ ) ) . '/languages/'
);
}
add_action( 'init', 'nuclia_load_textdomain' );
/**
* Debug log function
*
* @since 1.0.0
*
* @var string $notice The notice to log
*/
function nuclia_log( string $notice ): void {
if ( true === WP_DEBUG ) {
error_log("[PROGRESS AGENTIC RAG]: $notice\n" );
};
}
function nuclia_error_log( string $notice ): void {
error_log("[PROGRESS AGENTIC RAG]: $notice\n" );
}
// load plugin if requirements are met or display admin notice
if ( nuclia_php_version_check() && nuclia_wp_version_check() ) {
// Load Action Scheduler library for background processing
require_once PROGRESS_NUCLIA_PATH . 'includes/libraries/action-scheduler/action-scheduler.php';
require_once PROGRESS_NUCLIA_PATH . 'includes/nuclia-proxy-rest.php';
require_once PROGRESS_NUCLIA_PATH . 'includes/class-nuclia-api.php';
require_once PROGRESS_NUCLIA_PATH . 'includes/class-nuclia-settings.php';
require_once PROGRESS_NUCLIA_PATH . 'includes/class-nuclia-background-processor.php';
require_once PROGRESS_NUCLIA_PATH . 'includes/class-nuclia-label-reprocessor.php';
require_once PROGRESS_NUCLIA_PATH . 'includes/class-nuclia-plugin.php';
if ( is_admin() ) {
require_once PROGRESS_NUCLIA_PATH . 'includes/admin/class-nuclia-admin-page-settings.php';
}
$nuclia = Nuclia_Plugin_Factory::create();
} else {
add_action( 'admin_notices', 'nuclia_requirements_error_notice' );
}
/**
* Class Nuclia_Plugin_Factory
*
* Responsible for creating a shared instance of the main Nuclia_Plugin object.
*
* @since 1.0.0
*/
class Nuclia_Plugin_Factory {
/**
* Create and return a shared instance of the Nuclia_Plugin.
*
* @since 1.0.0
*
* @return Nuclia_Plugin The shared plugin instance.
*/
public static function create(): Nuclia_Plugin {
/**
* The static instance to share, else null.
*
* @since 1.0.0
*
* @var null|Nuclia_Plugin $plugin
*/
static $plugin = null;
if ( null !== $plugin ) {
return $plugin;
}
$plugin = new Nuclia_Plugin();
return $plugin;
}
}
function agentic_rag_for_wp_install() {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . 'agentic_rag_for_wp';
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
post_id mediumint(9) NOT NULL,
nuclia_rid varchar(255) NOT NULL,
nuclia_seqid varchar(255),
PRIMARY KEY (id),
INDEX idx_post_id (post_id),
INDEX idx_nuclia_rid (nuclia_rid)
) $charset_collate;";
dbDelta( $sql );
// Register path-only proxy rewrite rule and flush so /nuclia-proxy/{zone} works.
if ( function_exists( 'nuclia_proxy_add_rewrite_rules' ) ) {
nuclia_proxy_add_rewrite_rules();
flush_rewrite_rules();
}
}
register_activation_hook( __FILE__, 'agentic_rag_for_wp_install' );