PluginProbe
wpForo Forum / 3.1.0
wpForo Forum v3.1.0
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / themes / classic / header.php

header.php in wpForo Forum 3.1.0, at themes/classic/header.php

119 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( ! defined( 'ABSPATH' ) ) exit;
4
5 // Check if AI Features is available (connected AND active subscription) and AI Assistant is enabled
6 $wpf_ai_connected = isset( WPF()->ai_client ) && WPF()->ai_client->is_service_available();
7 $wpf_ai_assistant_enabled = $wpf_ai_connected && wpforo_setting( 'ai', 'assistant' );
8 $wpf_ai_search_enabled = $wpf_ai_assistant_enabled && wpforo_setting( 'ai', 'search' ) && WPF()->usergroup->can( 'ai_search' );
9 // AI Chat requires Professional plan or higher
10 $wpf_ai_chatbot_enabled = $wpf_ai_assistant_enabled
11 && isset( WPF()->ai_client ) && WPF()->ai_client->is_feature_available( 'ai_assistant_chatbot' )
12 && isset( WPF()->ai_chatbot ) && WPF()->ai_chatbot->is_enabled() && WPF()->ai_chatbot->user_can_chat();
13
14 // If neither search nor chat is available for this user, disable the assistant widget
15 if ( $wpf_ai_assistant_enabled && ! $wpf_ai_search_enabled && ! $wpf_ai_chatbot_enabled ) {
16 $wpf_ai_assistant_enabled = false;
17 }
18
19 // AI Assistant toggle settings
20 $wpf_ai_assistant_highlight = $wpf_ai_assistant_enabled && wpforo_setting( 'ai', 'assistant_highlight' );
21 $wpf_ai_assistant_icon = $wpf_ai_assistant_enabled ? wpforo_setting( 'ai', 'assistant_icon' ) : '';
22 $wpf_ai_is_home = WPF()->current_object['template'] === 'forum' && empty( WPF()->current_object['forumid'] );
23 $wpf_ai_assistant_open = $wpf_ai_assistant_enabled && wpforo_setting( 'ai', 'assistant_open' ) && $wpf_ai_is_home;
24 $wpf_ai_classic_search = $wpf_ai_assistant_enabled && wpforo_setting( 'ai', 'assistant_classic_search' );
25 $wpf_ai_show_preferences = $wpf_ai_assistant_enabled && wpforo_setting( 'ai', 'assistant_preferences' );
26
27 // AI Features Preferences - only when AI is connected and for logged-in users
28 $wpf_ai_user_id = 0;
29 $wpf_ai_is_logged_in = false;
30 $wpf_ai_preferences = array();
31 $wpf_ai_languages = array();
32
33 if ( $wpf_ai_assistant_enabled ) {
34 $wpf_ai_user_id = WPF()->current_userid;
35 $wpf_ai_is_logged_in = $wpf_ai_user_id > 0;
36
37 // Get default language: AI settings > Board locale > WordPress locale
38 $wpf_ai_default_language = wpforo_setting( 'ai', 'search_language' );
39 if ( empty( $wpf_ai_default_language ) ) {
40 // Use board locale if available, otherwise WordPress locale
41 $wpf_ai_default_language = wpfval( WPF()->board, 'locale' ) ?: get_locale();
42 }
43
44 // Get default max results from AI settings
45 $wpf_ai_default_max_results = wpforo_setting( 'ai', 'search_max_results' );
46 if ( empty( $wpf_ai_default_max_results ) || $wpf_ai_default_max_results < 1 ) {
47 $wpf_ai_default_max_results = 5;
48 }
49
50 // Set defaults from AI Features settings
51 $wpf_ai_preferences = array(
52 'language' => $wpf_ai_default_language,
53 'max_results' => (int) $wpf_ai_default_max_results,
54 );
55
56 // Override with user preferences if logged in and user has saved preferences
57 if ( $wpf_ai_is_logged_in ) {
58 $saved_prefs = get_user_meta( $wpf_ai_user_id, 'wpforo_ai_search', true );
59 if ( is_array( $saved_prefs ) && ! empty( $saved_prefs ) ) {
60 // Only override if user has explicitly saved preferences
61 if ( ! empty( $saved_prefs['language'] ) ) {
62 $wpf_ai_preferences['language'] = $saved_prefs['language'];
63 }
64 if ( ! empty( $saved_prefs['max_results'] ) ) {
65 $wpf_ai_preferences['max_results'] = (int) $saved_prefs['max_results'];
66 }
67 }
68 }
69
70 // Build frontend language dropdown from master list (locale => "Native (English)")
71 $wpf_ai_languages = array( '' => __( 'Default Language', 'wpforo' ) );
72 foreach ( wpforo_get_ai_languages() as $lang ) {
73 $label = ( $lang['native'] !== $lang['name'] ) ? $lang['native'] . ' (' . $lang['name'] . ')' : $lang['name'];
74 $wpf_ai_languages[ $lang['locale'] ] = $label;
75 }
76 }
77 ?>
78
79 <?php do_action( 'wpforo_top_hook' ); ?>
80
81 <?php if( wpforo_setting( 'components', 'top_bar' ) ): ?>
82 <div id="wpforo-menu">
83 <?php do_action( 'wpforo_menu_bar_start' ); ?>
84 <div class="wpf-left" style="display:table-cell">
85 <?php if( WPF()->tpl->has_menu() ): ?>
86 <span class="wpf-res-menu"><i class="fas fa-bars"></i></span>
87 <?php WPF()->tpl->nav_menu() ?>
88 <?php endif; ?>
89 <?php do_action( 'wpforo_after_menu_items' ); ?>
90 </div>
91 <div class="wpf-bar-right wpf-search">
92 <?php do_action( 'wpforo_before_search_toggle' ); ?>
93 <?php if( wpforo_setting( 'components', 'top_bar_search' ) && !$wpf_ai_assistant_open ): ?>
94 <div class="wpf-search-form">
95 <form action="<?php echo wpforo_home_url() ?>" method="get">
96 <?php wpforo_make_hidden_fields_from_url( wpforo_home_url() ) ?>
97 <i class="fas fa-search"></i><input class="wpf-search-field" name="wpfs" type="text" value="" style="margin-right:10px;"/>
98 </form>
99 </div>
100 <?php endif; ?>
101 </div>
102 <?php do_action( 'wpforo_menu_bar_end' ); ?>
103 </div>
104 <?php endif; ?>
105 <?php if ( $wpf_ai_assistant_enabled ) : ?>
106 <?php include( wpftpl( 'widgets-ai.php' ) ) ?>
107 <?php endif; ?>
108 <div class="wpforo-subtop">
109 <?php if( wpforo_setting( 'components', 'breadcrumb' ) ): ?>
110 <?php WPF()->tpl->breadcrumb( WPF()->current_object ) ?>
111 <?php endif; ?>
112 <?php wpforo_share_buttons( 'top' ); ?>
113 <div class="wpf-clear"></div>
114 <?php if( wpforo_setting( 'notifications', 'notifications' ) ): ?>
115 <?php wpforo_notifications() ?>
116 <?php endif; ?>
117 </div>
118 <?php do_action( 'wpforo_header_hook' ); ?>
119