PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 1.7.1
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v1.7.1
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / elementor / class-betterdocs-elementor.php

class-betterdocs-elementor.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 1.7.1, at includes/elementor/class-betterdocs-elementor.php

593 lines 18.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 use Elementor\Controls_Manager;
3 use ElementorPro\Plugin;
4 use ElementorPro\Modules\ThemeBuilder as ThemeBuilder;
5
6 /**
7 * Working with elementor plugin
8 *
9 *
10 * @since 1.3.0
11 * @package BetterDocs
12 * @subpackage BetterDocs/elementor
13 * @author WPDeveloper <support@wpdeveloper.net>
14 */
15 class BetterDocs_Elementor
16 {
17 public static $pro_active;
18
19 /**
20 * Short Description. (use period)
21 *
22 * Long Description.
23 *
24 * @since 1.3.0
25 */
26 public static function init()
27 {
28 self::$pro_active = is_plugin_active('betterdocs-pro/betterdocs-pro.php');
29 add_action('elementor/editor/before_enqueue_scripts', [__CLASS__, 'editor_enqueue_scripts']);
30 if (is_plugin_active('betterdocs/betterdocs.php')) {
31 add_action('elementor/documents/register', [__CLASS__, 'register_singel_documents_page']);
32 add_action('elementor/documents/register', [__CLASS__, 'register_doc_category_archive']);
33 add_filter('elementor/theme/need_override_location', [__CLASS__, 'theme_template_include'], 10, 2);
34 add_action('elementor/widgets/widgets_registered', [__CLASS__, 'register_widgets']);
35 add_action('betterdocs/elementor/widgets/query', [__CLASS__, 'betterdocs_query'], 10, 1);
36 add_filter('elementor/editor/localize_settings', [__CLASS__, 'promote_pro_elements']);
37 add_action('wp_enqueue_scripts', [__CLASS__, 'editor_load_asset']);
38 if (is_plugin_active('elementor-pro/elementor-pro.php')) {
39 add_action('elementor/init', [__CLASS__, 'load_widget_file']);
40 add_action('elementor/theme/register_conditions', [__CLASS__, 'register_conditions']);
41 }
42 }
43
44 add_action('init', [__CLASS__, '__betterdocs_init'], -999);
45 }
46
47 /**
48 *
49 * Mange all widget for single docs
50 *
51 * @return string[]
52 * @since 1.3.0
53 */
54 public static function get_widget_list()
55 {
56 $widget_arr = [
57 'betterdocs-elementor-breadcrumbs' => 'BetterDocs_Elementor_Breadcrumbs',
58 'betterdocs-elementor-title' => 'BetterDocs_Elementor_Title',
59 'betterdocs-elementor-content' => 'BetterDocs_Elementor_Content',
60 'betterdocs-elementor-sidebar' => 'BetterDocs_Elementor_Sidebar',
61 'betterdocs-elementor-navigation' => 'BetterDocs_Elementor_Navigation',
62 'betterdocs-elementor-doc-share' => 'BetterDocs_Elementor_Doc_Share',
63 'betterdocs-elementor-feedback' => 'BetterDocs_Elementor_Feedback',
64 'betterdocs-elementor-doc-date' => 'BetterDocs_Elementor_Doc_Date',
65 'betterdocs-elementor-search-form' => 'BetterDocs_Elementor_Search_Form',
66 'betterdocs-elementor-toc' => 'BetterDocs_Elementor_Toc',
67 'betterdocs-elementor-category-archive-list' => 'BetterDocs_Category_Archive_List',
68 'betterdocs-elementor-category-grid' => 'BetterDocs_Elementor_Category_Grid',
69 'betterdocs-elementor-category-box' => 'BetterDocs_Elementor_Category_Box'
70 ];
71 if (is_plugin_active('betterdocs-pro/betterdocs-pro.php')) {
72 $widget_arr['betterdocs-elementor-reactions'] = 'BetterDocs_Elementor_Reactions';
73 }
74 return $widget_arr;
75 }
76
77 /**
78 *
79 * Load asset for elementor icon
80 *
81 * @since 1.3.0
82 */
83 public static function editor_enqueue_scripts()
84 {
85 wp_enqueue_style(
86 'betterdocs-el-icon',
87 BETTERDOCS_ADMIN_URL . 'assets/css/betterdocs-el-icon.css',
88 false,
89 BETTERDOCS_VERSION
90 );
91 }
92
93 public static function editor_load_asset()
94 {
95 wp_enqueue_style(
96 'betterdocs-el-edit',
97 BETTERDOCS_ADMIN_URL . 'assets/css/betterdocs-el-edit.css',
98 false,
99 BETTERDOCS_VERSION
100 );
101
102 if (!self::$pro_active) {
103 wp_enqueue_script(
104 'betterdocs-el-editor',
105 BETTERDOCS_ADMIN_URL . 'assets/js/betterdocs-el-editor.js',
106 ['jquery'],
107 BETTERDOCS_VERSION,
108 true
109 );
110 }
111 }
112
113 public static function load_widget_file()
114 {
115 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/template-query.php';
116 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/betterdocs-single-docs.php';
117 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/betterdocs-doc-archive.php';
118 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/betterdocs-archive-condition.php';
119 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/docs-page.php';
120 self::__register_tag();
121
122 //load widget file
123 foreach (self::get_widget_list() as $key => $value) {
124 require_once BETTERDOCS_DIR_PATH . "includes/elementor/widgets/$key.php";
125 }
126 }
127
128 public static function register_singel_documents_page($documents_manager)
129 {
130 if (class_exists('BetterDocs_Single_Docs')) {
131 $documents_manager->register_document_type('docs', BetterDocs_Single_Docs::get_class_full_name());
132 }
133 }
134
135 public static function register_doc_category_archive($documents_manager)
136 {
137 if (class_exists('Betterdocs_Doc_Archive')) {
138 $documents_manager->register_document_type('doc-archive', Betterdocs_Doc_Archive::get_class_full_name());
139 }
140 }
141
142 /**
143 * @param Conditions_Manager $conditions_manager
144 */
145 public static function register_conditions($conditions_manager)
146 {
147 $betterdocs_condition = new Betterdocs_Archive_Condition();
148
149 $conditions_manager->get_condition('general')->register_sub_condition($betterdocs_condition);
150 }
151
152 public static function theme_template_include($need_override_location, $location)
153 {
154 if (is_singular(['docs']) && 'single' === $location) {
155 $need_override_location = true;
156 }
157
158 return $need_override_location;
159 }
160
161 public static function register_widgets($widgets_manager)
162 {
163 foreach (self::get_widget_list() as $value) {
164 if (class_exists($value)) {
165 $widgets_manager->register_widget_type(new $value);
166 }
167 }
168 }
169
170 public static function __register_tag()
171 {
172 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/widgets/betterdocs-elementor-title-tag.php';
173
174 $module = Plugin::elementor()->dynamic_tags;
175 $module->register_tag(new BetterDocs_Elementor_Title_Tag());
176 }
177
178 public static function promote_pro_elements($config)
179 {
180 if (is_plugin_active('betterdocs-pro/betterdocs-pro.php')) {
181 return $config;
182 }
183
184 $promotion_widgets = [];
185
186 if (isset($config['promotionWidgets'])) {
187 $promotion_widgets = $config['promotionWidgets'];
188 }
189
190 $combine_array = array_merge($promotion_widgets, [
191 [
192 'name' => 'betterdocs-elementor-reactions',
193 'title' => __('Doc Reactions', 'betterdocs'),
194 'icon' => 'betterdocs-icon-Reactions',
195 'categories' => '["betterdocs-elements"]',
196 ],
197 ]);
198
199 $config['promotionWidgets'] = $combine_array;
200
201 return $config;
202 }
203
204 public static function __betterdocs_init()
205 {
206 add_action('elementor/init', array(__CLASS__, 'register_bd_template_instance'), 20);
207 if (defined('Elementor\Api::LIBRARY_OPTION_KEY')) {
208 add_filter('option_' . Elementor\Api::LIBRARY_OPTION_KEY, array(__CLASS__, 'prepend_categories'));
209 }
210 add_action('elementor/ajax/register_actions', array(__CLASS__, 'modified_ajax_action'), 20);
211 }
212
213 public static function register_bd_template_instance()
214 {
215 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/betterdocs-template-source.php';
216
217 $elementor = Elementor\Plugin::instance();
218 $elementor->templates_manager->register_source('BetterDocs_Template_Source');
219 }
220
221 public static function modified_ajax_action($ajax)
222 {
223 if (!isset($_REQUEST['actions'])) {
224 return;
225 }
226
227 $actions = json_decode(stripslashes($_REQUEST['actions']), true);
228 $data = false;
229
230 foreach ($actions as $id => $action_data) {
231 if (!isset($action_data['get_template_data'])) {
232 $data = $action_data;
233 }
234 }
235
236
237 if (!$data) {
238 return;
239 }
240
241 if (!isset($data['data'])) {
242 return;
243 }
244
245 $data = $data['data'];
246
247 if (empty($data['template_id'])) {
248 return;
249 }
250
251 if (false === strpos($data['template_id'], 'betterdocs_')) {
252 return;
253 }
254 $ajax->register_ajax_action('get_template_data', array(__CLASS__, 'get_bd_template_data'));
255 }
256
257 public static function prepend_categories($library_data)
258 {
259 $categories = self::get_template_categories();
260 if (!empty($categories)) {
261 $library_data['types_data']['block']['categories'] = array_merge($categories, $library_data['types_data']['block']['categories']);
262 }
263 return $library_data;
264 }
265
266 public static function get_template_categories()
267 {
268 return [
269 'Single Docs', 'Docs Archive'
270 ];
271 }
272
273 public static function get_bd_template_data($args)
274 {
275 $source = Elementor\Plugin::instance()->templates_manager->get_source('betterdocs-templates');
276
277 return $source->get_data($args);
278 }
279
280 /**
281 * Include a file with variables
282 *
283 * @param $file_path
284 * @param $variables
285 *
286 * @return string
287 * @since 4.2.2
288 */
289 public static function include_with_variable( $file_path, $variables = [])
290 {
291 if (file_exists($file_path)) {
292 extract($variables);
293
294 ob_start();
295
296 include $file_path;
297
298 return ob_get_clean();
299 }
300
301 return '';
302 }
303
304 /**
305 * This function is responsible for counting doc post under a category.
306 *
307 * @param int $term_count
308 * @param int $term_id
309 * @return int $term_count;
310 */
311 public static function get_doc_post_count($term_count = 0, $term_id)
312 {
313 $tax_terms = get_terms('doc_category', ['child_of' => $term_id]);
314
315 foreach ($tax_terms as $tax_term) {
316 $term_count += $tax_term->count;
317 }
318
319 return $term_count;
320 }
321
322 public static function get_multiple_kb_terms($prettify = false, $term_id = true)
323 {
324 $args = [
325 'taxonomy' => 'knowledge_base',
326 'hide_empty' => true,
327 'parent' => 0,
328 ];
329
330 $terms = get_terms($args);
331
332 if (is_wp_error($terms)) {
333 return [];
334 }
335
336 if ($prettify) {
337 $pretty_taxonomies = [];
338
339 foreach ($terms as $term) {
340 $pretty_taxonomies[$term_id ? $term->term_id : $term->slug] = $term->name;
341 }
342
343 return $pretty_taxonomies;
344 }
345
346 return $terms;
347 }
348
349 public static function get_betterdocs_multiple_kb_status()
350 {
351 if (\BetterDocs_DB::get_settings('multiple_kb') == 1) {
352 return 'true';
353 }
354
355 return '';
356 }
357
358 /**
359 * POst Orderby Options
360 *
361 * @return array
362 */
363 public static function get_post_orderby_options()
364 {
365 $orderby = array(
366 'ID' => 'Post ID',
367 'author' => 'Post Author',
368 'title' => 'Title',
369 'date' => 'Date',
370 'modified' => 'Last Modified Date',
371 'parent' => 'Parent Id',
372 'rand' => 'Random',
373 'comment_count' => 'Comment Count',
374 'menu_order' => 'Menu Order',
375 );
376
377 return $orderby;
378 }
379
380 /**
381 * Get Post Categories
382 *
383 * @return array
384 */
385 public static function get_terms_list($taxonomy = 'category', $key = 'term_id')
386 {
387 $options = [];
388 $terms = get_terms([
389 'taxonomy' => $taxonomy,
390 'hide_empty' => true,
391 ]);
392
393 if (!empty($terms) && !is_wp_error($terms)) {
394 foreach ($terms as $term) {
395 $options[$term->{$key}] = $term->name;
396 }
397 }
398
399 return $options;
400 }
401
402 /**
403 * Query Controls
404 *
405 */
406 public static function betterdocs_query($wb)
407 {
408 $wb->start_controls_section(
409 'eael_section_post__filters',
410 [
411 'label' => __('Query', 'betterdocs'),
412 ]
413 );
414
415 $default_multiple_kb = self::get_betterdocs_multiple_kb_status();
416
417 if ($default_multiple_kb) {
418 $multiple_kb_terms = self::get_multiple_kb_terms(true, false);
419 $default_slug = count($multiple_kb_terms) > 0 ? array_keys($multiple_kb_terms)[0] : '';
420
421 $wb->add_control(
422 'selected_knowledge_base',
423 [
424 'label' => __('Knowledge Bases', 'betterdocs'),
425 'label_block' => true,
426 'type' => Controls_Manager::SELECT2,
427 'options' => $multiple_kb_terms,
428 'multiple' => false,
429 'default' => '',
430 'select2options' => [
431 'placeholder' => __('All Knowledge Base', 'betterdocs'),
432 'allowClear' => true,
433 ],
434 ]
435 );
436 }
437
438 if ($wb->get_name() === 'betterdocs-category-grid') {
439 $wb->add_control(
440 'grid_query_heading',
441 [
442 'label' => __('Category Grid', 'betterdocs'),
443 'type' => Controls_Manager::HEADING,
444 ]
445 );
446 }
447
448 $wb->add_control(
449 'include',
450 [
451 'label' => __('Include', 'betterdocs'),
452 'label_block' => true,
453 'type' => Controls_Manager::SELECT2,
454 'options' => self::get_terms_list('doc_category', 'term_id'),
455 'multiple' => true,
456 'default' => [],
457 ]
458 );
459
460 $wb->add_control(
461 'exclude',
462 [
463 'label' => __('Exclude', 'betterdocs'),
464 'type' => Controls_Manager::SELECT2,
465 'options' => self::get_terms_list('doc_category', 'term_id'),
466 'label_block' => true,
467 'post_type' => '',
468 'multiple' => true,
469 ]
470 );
471
472 if ($wb->get_name() === 'betterdocs-category-grid') {
473 $wb->add_control(
474 'grid_per_page',
475 [
476 'label' => __('Grid Per Page', 'betterdocs'),
477 'type' => Controls_Manager::NUMBER,
478 'default' => '8',
479 ]
480 );
481 } else {
482 $wb->add_control(
483 'box_per_page',
484 [
485 'label' => __('Box Per Page', 'betterdocs'),
486 'type' => Controls_Manager::NUMBER,
487 'default' => '8',
488 ]
489 );
490 }
491
492 $wb->add_control(
493 'offset',
494 [
495 'label' => __('Offset', 'betterdocs'),
496 'type' => Controls_Manager::NUMBER,
497 'default' => '0',
498 ]
499 );
500
501 $wb->add_control(
502 'orderby',
503 [
504 'label' => __('Order By', 'betterdocs'),
505 'type' => Controls_Manager::SELECT,
506 'options' => [
507 'name' => __('Name', 'betterdocs'),
508 'slug' => __('Slug', 'betterdocs'),
509 'term_group' => __('Term Group', 'betterdocs'),
510 'term_id' => __('Term ID', 'betterdocs'),
511 'id' => __('ID', 'betterdocs'),
512 'description' => __('Description', 'betterdocs'),
513 'parent' => __('Parent', 'betterdocs'),
514 ],
515 'default' => 'name',
516 ]
517 );
518
519 $wb->add_control(
520 'order',
521 [
522 'label' => __('Order', 'betterdocs'),
523 'type' => Controls_Manager::SELECT,
524 'options' => [
525 'asc' => 'Ascending',
526 'desc' => 'Descending',
527 ],
528 'default' => 'asc',
529
530 ]
531 );
532
533 if ($wb->get_name() === 'betterdocs-category-grid') {
534 $wb->add_control(
535 'grid_posts_query_heading',
536 [
537 'label' => __('Grid List Posts', 'betterdocs'),
538 'type' => Controls_Manager::HEADING,
539 'separator' => 'before',
540 ]
541 );
542
543 $wb->add_control(
544 'post_per_page',
545 [
546 'label' => __('Post Per Page', 'betterdocs'),
547 'type' => Controls_Manager::NUMBER,
548 'default' => '6',
549 ]
550 );
551
552 $wb->add_control(
553 'post_orderby',
554 [
555 'label' => __('Order By', 'betterdocs'),
556 'type' => Controls_Manager::SELECT,
557 'options' => self::get_post_orderby_options(),
558 'default' => 'date',
559 ]
560 );
561
562 $wb->add_control(
563 'post_order',
564 [
565 'label' => __('Order', 'betterdocs'),
566 'type' => Controls_Manager::SELECT,
567 'options' => [
568 'asc' => 'Ascending',
569 'desc' => 'Descending',
570 ],
571 'default' => 'desc',
572 ]
573 );
574
575 $wb->add_control(
576 'nested_subcategory',
577 [
578 'label' => __('Enable Nested Subcategory', 'betterdocs'),
579 'type' => Controls_Manager::SWITCHER,
580 'label_on' => __('Yes', 'betterdocs'),
581 'label_off' => __('No', 'betterdocs'),
582 'return_value' => 'true',
583 'default' => '',
584 ]
585 );
586 }
587
588 $wb->end_controls_section();
589 }
590 }
591
592 BetterDocs_Elementor::init();
593