625 lines
24 KiB
PHP
625 lines
24 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace CropLogic;
|
||
|
|
|
||
|
|
use Elementor\Controls_Manager;
|
||
|
|
use Elementor\Group_Control_Typography;
|
||
|
|
use Elementor\Repeater;
|
||
|
|
use Elementor\Widget_Base;
|
||
|
|
|
||
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
|
||
|
|
class AI_Chat_Widget extends Widget_Base {
|
||
|
|
public function get_name() {
|
||
|
|
return 'crop-logic-ai-chat';
|
||
|
|
}
|
||
|
|
|
||
|
|
public function get_title() {
|
||
|
|
return __( 'چت هوشمند کراپ لاجیک', 'crop-logic' );
|
||
|
|
}
|
||
|
|
|
||
|
|
public function get_icon() {
|
||
|
|
return 'eicon-chat';
|
||
|
|
}
|
||
|
|
|
||
|
|
public function get_keywords() {
|
||
|
|
return [ 'crop', 'logic', 'ai', 'assistant', 'chat' ];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function get_categories() {
|
||
|
|
return [ 'crop-logic' ];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function get_style_depends() {
|
||
|
|
return [ 'crop-logic-ai-chat' ];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function get_script_depends() {
|
||
|
|
return [ 'crop-logic-ai-chat' ];
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function register_controls() {
|
||
|
|
$this->register_content_controls();
|
||
|
|
$this->register_style_controls();
|
||
|
|
}
|
||
|
|
|
||
|
|
private function register_content_controls(): void {
|
||
|
|
$this->start_controls_section(
|
||
|
|
'section_content',
|
||
|
|
[
|
||
|
|
'label' => __( 'محتوا', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'title',
|
||
|
|
[
|
||
|
|
'label' => __( 'عنوان', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'دستیار هوشمند کشاورزی', 'crop-logic' ),
|
||
|
|
'label_block' => true,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'subtitle',
|
||
|
|
[
|
||
|
|
'label' => __( 'زیرعنوان', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'در مورد آبیاری، کوددهی، تنش گیاه یا بیماری سؤال بپرسید.', 'crop-logic' ),
|
||
|
|
'label_block' => true,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'assistant_name',
|
||
|
|
[
|
||
|
|
'label' => __( 'نام دستیار', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'هوش مصنوعی کراپ لاجیک', 'crop-logic' ),
|
||
|
|
'label_block' => true,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'assistant_id',
|
||
|
|
[
|
||
|
|
'label' => __( 'شناسه دستیار', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => '',
|
||
|
|
'label_block' => true,
|
||
|
|
'description' => __( 'شناسه اختیاری دستیار که به بکاند شما ارسال میشود.', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'empty_title',
|
||
|
|
[
|
||
|
|
'label' => __( 'عنوان حالت خالی', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'یک گفتگوی جدید کشاورزی را شروع کنید', 'crop-logic' ),
|
||
|
|
'label_block' => true,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'empty_subtitle',
|
||
|
|
[
|
||
|
|
'label' => __( 'زیرعنوان حالت خالی', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'از پیشنهادهای زیر استفاده کنید یا سؤال خودتان را بپرسید.', 'crop-logic' ),
|
||
|
|
'label_block' => true,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'input_placeholder',
|
||
|
|
[
|
||
|
|
'label' => __( 'متن راهنمای ورودی', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'مشکل مزرعه را بنویسید یا درخواست پیشنهاد بدهید...', 'crop-logic' ),
|
||
|
|
'label_block' => true,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'sidebar_title',
|
||
|
|
[
|
||
|
|
'label' => __( 'عنوان سایدبار', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'گفتگوهای اخیر', 'crop-logic' ),
|
||
|
|
'label_block' => true,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'new_chat_label',
|
||
|
|
[
|
||
|
|
'label' => __( 'برچسب گفتگوی جدید', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'گفتگوی جدید', 'crop-logic' ),
|
||
|
|
'label_block' => true,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'enable_sidebar',
|
||
|
|
[
|
||
|
|
'label' => __( 'فعالسازی تاریخچه سایدبار', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::SWITCHER,
|
||
|
|
'label_on' => __( 'نمایش', 'crop-logic' ),
|
||
|
|
'label_off' => __( 'مخفی', 'crop-logic' ),
|
||
|
|
'return_value' => 'yes',
|
||
|
|
'default' => 'yes',
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'show_media_tools',
|
||
|
|
[
|
||
|
|
'label' => __( 'نمایش دکمه دوربین', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::SWITCHER,
|
||
|
|
'label_on' => __( 'نمایش', 'crop-logic' ),
|
||
|
|
'label_off' => __( 'مخفی', 'crop-logic' ),
|
||
|
|
'return_value' => 'yes',
|
||
|
|
'default' => 'yes',
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'show_voice_button',
|
||
|
|
[
|
||
|
|
'label' => __( 'نمایش دکمه صدا', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::SWITCHER,
|
||
|
|
'label_on' => __( 'نمایش', 'crop-logic' ),
|
||
|
|
'label_off' => __( 'مخفی', 'crop-logic' ),
|
||
|
|
'return_value' => 'yes',
|
||
|
|
'default' => '',
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->end_controls_section();
|
||
|
|
|
||
|
|
$this->start_controls_section(
|
||
|
|
'section_auth_modal',
|
||
|
|
[
|
||
|
|
'label' => __( 'مودال احراز هویت', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_title',
|
||
|
|
[
|
||
|
|
'label' => __( 'عنوان مودال', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'ورود یا ثبت نام', 'crop-logic' ),
|
||
|
|
'label_block' => true,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_description',
|
||
|
|
[
|
||
|
|
'label' => __( 'توضیح مودال', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXTAREA,
|
||
|
|
'default' => __( 'برای ادامه گفتگو ابتدا وارد حساب خود شوید.', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_login_tab',
|
||
|
|
[
|
||
|
|
'label' => __( 'تب ورود', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'ورود', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_register_tab',
|
||
|
|
[
|
||
|
|
'label' => __( 'تب ثبت نام', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'ثبت نام', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_forgot_tab',
|
||
|
|
[
|
||
|
|
'label' => __( 'تب فراموشی رمز', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'فراموشی رمز', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_reset_tab',
|
||
|
|
[
|
||
|
|
'label' => __( 'تب ریست رمز', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'ریست رمز', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_login_button',
|
||
|
|
[
|
||
|
|
'label' => __( 'دکمه ورود', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'ورود', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_register_button',
|
||
|
|
[
|
||
|
|
'label' => __( 'دکمه ثبت نام', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'ثبت نام', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_forgot_button',
|
||
|
|
[
|
||
|
|
'label' => __( 'دکمه فراموشی رمز', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'ارسال لینک بازیابی', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'auth_reset_button',
|
||
|
|
[
|
||
|
|
'label' => __( 'دکمه ریست رمز', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::TEXT,
|
||
|
|
'default' => __( 'ثبت رمز جدید', 'crop-logic' ),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->end_controls_section();
|
||
|
|
}
|
||
|
|
|
||
|
|
private function register_style_controls(): void {
|
||
|
|
$this->start_controls_section(
|
||
|
|
'section_style_colors',
|
||
|
|
[
|
||
|
|
'label' => __( 'Colors', 'crop-logic' ),
|
||
|
|
'tab' => Controls_Manager::TAB_STYLE,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'primary_color',
|
||
|
|
[
|
||
|
|
'label' => __( 'Primary', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => '#2b8a3e',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-primary: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'accent_color',
|
||
|
|
[
|
||
|
|
'label' => __( 'Accent', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => '#2d9cdb',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-accent: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'page_background',
|
||
|
|
[
|
||
|
|
'label' => __( 'Background', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => '#f5f7f1',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-bg: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'surface_color',
|
||
|
|
[
|
||
|
|
'label' => __( 'Surface', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => '#ffffff',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-surface: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'border_color',
|
||
|
|
[
|
||
|
|
'label' => __( 'Border', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => 'rgba(43, 138, 62, 0.15)',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-border: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'text_color',
|
||
|
|
[
|
||
|
|
'label' => __( 'Text', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => '#16331b',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-text: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'muted_text_color',
|
||
|
|
[
|
||
|
|
'label' => __( 'Muted Text', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => '#5f6f62',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-muted: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'user_bubble_color',
|
||
|
|
[
|
||
|
|
'label' => __( 'User Bubble', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => 'rgba(43, 138, 62, 0.12)',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-user-bubble: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'assistant_bubble_color',
|
||
|
|
[
|
||
|
|
'label' => __( 'Assistant Bubble', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => '#ffffff',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-assistant-bubble: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_control(
|
||
|
|
'input_background',
|
||
|
|
[
|
||
|
|
'label' => __( 'Composer Background', 'crop-logic' ),
|
||
|
|
'type' => Controls_Manager::COLOR,
|
||
|
|
'default' => '#ffffff',
|
||
|
|
'selectors' => [
|
||
|
|
'{{WRAPPER}} .crop-logic-chat' => '--cl-input-bg: {{VALUE}};',
|
||
|
|
],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->end_controls_section();
|
||
|
|
|
||
|
|
$this->start_controls_section(
|
||
|
|
'section_style_typography',
|
||
|
|
[
|
||
|
|
'label' => __( 'Typography', 'crop-logic' ),
|
||
|
|
'tab' => Controls_Manager::TAB_STYLE,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_group_control(
|
||
|
|
Group_Control_Typography::get_type(),
|
||
|
|
[
|
||
|
|
'name' => 'title_typography',
|
||
|
|
'label' => __( 'عنوان', 'crop-logic' ),
|
||
|
|
'selector' => '{{WRAPPER}} .crop-logic-chat__title',
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->add_group_control(
|
||
|
|
Group_Control_Typography::get_type(),
|
||
|
|
[
|
||
|
|
'name' => 'body_typography',
|
||
|
|
'label' => __( 'Body', 'crop-logic' ),
|
||
|
|
'selector' => '{{WRAPPER}} .crop-logic-chat, {{WRAPPER}} .crop-logic-chat__input',
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->end_controls_section();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function render() {
|
||
|
|
$settings = $this->get_settings_for_display();
|
||
|
|
$chips = [];
|
||
|
|
|
||
|
|
$suggestions = isset( $settings['suggestions'] ) && is_array( $settings['suggestions'] ) ? $settings['suggestions'] : [];
|
||
|
|
|
||
|
|
foreach ( $suggestions as $item ) {
|
||
|
|
if ( ! empty( $item['label'] ) ) {
|
||
|
|
$chips[] = (string) $item['label'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$client_settings = [
|
||
|
|
'threadsUrl' => esc_url_raw( rest_url( 'crop-logic/v1/threads' ) ),
|
||
|
|
'messagesUrlTemplate' => esc_url_raw( rest_url( 'crop-logic/v1/threads/%conversation_id%/messages' ) ),
|
||
|
|
'sendUrlTemplate' => esc_url_raw( rest_url( 'crop-logic/v1/threads/%conversation_id%/send' ) ),
|
||
|
|
'deleteThreadUrlTemplate' => esc_url_raw( rest_url( 'crop-logic/v1/threads/%conversation_id%' ) ),
|
||
|
|
'verifyUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/verify' ) ),
|
||
|
|
'loginUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/login' ) ),
|
||
|
|
'registerUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/register' ) ),
|
||
|
|
'forgotUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/forgot-password' ) ),
|
||
|
|
'resetUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/reset-password' ) ),
|
||
|
|
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||
|
|
'widgetId' => $this->get_id(),
|
||
|
|
'assistantId' => sanitize_text_field( (string) $settings['assistant_id'] ),
|
||
|
|
'title' => (string) $settings['title'],
|
||
|
|
'assistantName' => (string) $settings['assistant_name'],
|
||
|
|
'emptyTitle' => (string) $settings['empty_title'],
|
||
|
|
'emptySubtitle' => (string) $settings['empty_subtitle'],
|
||
|
|
'inputPlaceholder' => (string) $settings['input_placeholder'],
|
||
|
|
'sidebarTitle' => (string) $settings['sidebar_title'],
|
||
|
|
'newChatLabel' => (string) $settings['new_chat_label'],
|
||
|
|
'enableSidebar' => 'yes' === $settings['enable_sidebar'],
|
||
|
|
'showMediaTools' => 'yes' === $settings['show_media_tools'],
|
||
|
|
'showVoiceButton' => 'yes' === $settings['show_voice_button'],
|
||
|
|
'suggestions' => $chips,
|
||
|
|
'i18n' => [
|
||
|
|
'error' => __( 'در حال حاضر ارتباط با دستیار هوش مصنوعی برقرار نشد.', 'crop-logic' ),
|
||
|
|
'typing' => __( 'در حال فکر کردن...', 'crop-logic' ),
|
||
|
|
'sidebarEmpty' => __( 'هنوز گفتگویی ذخیره نشده است.', 'crop-logic' ),
|
||
|
|
'attachmentLabel' => __( 'تصویر پیوستشده', 'crop-logic' ),
|
||
|
|
'attachmentsLabel' => __( 'تصاویر پیوستشده', 'crop-logic' ),
|
||
|
|
'removeFile' => __( 'حذف فایل', 'crop-logic' ),
|
||
|
|
'deleteMessage' => __( 'حذف پیام', 'crop-logic' ),
|
||
|
|
'loading' => __( 'در حال بارگذاری گفتگوها...', 'crop-logic' ),
|
||
|
|
'loadingSubtitle' => __( 'لطفا کمی صبر کنید.', 'crop-logic' ),
|
||
|
|
'frequency' => __( 'تناوب', 'crop-logic' ),
|
||
|
|
'amount' => __( 'مقدار', 'crop-logic' ),
|
||
|
|
'timing' => __( 'زمان', 'crop-logic' ),
|
||
|
|
'whyThis' => __( 'چرا این پیشنهاد؟', 'crop-logic' ),
|
||
|
|
'attachmentPrompt' => __( 'لطفا تصویر پیوستشده را بررسی کن.', 'crop-logic' ),
|
||
|
|
'authTitle' => (string) $settings['auth_title'],
|
||
|
|
'authNeeded' => (string) $settings['auth_description'],
|
||
|
|
'loginTab' => (string) $settings['auth_login_tab'],
|
||
|
|
'registerTab' => (string) $settings['auth_register_tab'],
|
||
|
|
'forgotTab' => (string) $settings['auth_forgot_tab'],
|
||
|
|
'resetTab' => (string) $settings['auth_reset_tab'],
|
||
|
|
'loginHeading' => __( 'ورود به حساب کاربری', 'crop-logic' ),
|
||
|
|
'registerHeading' => __( 'ایجاد حساب جدید', 'crop-logic' ),
|
||
|
|
'forgotHeading' => __( 'بازیابی رمز عبور', 'crop-logic' ),
|
||
|
|
'resetHeading' => __( 'تنظیم رمز عبور جدید', 'crop-logic' ),
|
||
|
|
'registerHelp' => __( 'حساب خود را بسازید تا گفتگوها و پیشنهادهای کشاورزی برای شما ذخیره شود.', 'crop-logic' ),
|
||
|
|
'forgotHelp' => __( 'ایمیل حساب را وارد کنید تا لینک بازیابی برای شما ارسال شود.', 'crop-logic' ),
|
||
|
|
'resetHelp' => __( 'توکن بازیابی و رمز عبور جدید را وارد کنید تا دوباره وارد حساب شوید.', 'crop-logic' ),
|
||
|
|
'identifier' => __( 'ایمیل یا نام کاربری یا موبایل', 'crop-logic' ),
|
||
|
|
'email' => __( 'ایمیل', 'crop-logic' ),
|
||
|
|
'password' => __( 'رمز عبور', 'crop-logic' ),
|
||
|
|
'name' => __( 'نام', 'crop-logic' ),
|
||
|
|
'lastName' => __( 'نام خانوادگی', 'crop-logic' ),
|
||
|
|
'username' => __( 'نام کاربری', 'crop-logic' ),
|
||
|
|
'phone' => __( 'شماره موبایل', 'crop-logic' ),
|
||
|
|
'confirmPassword' => __( 'تکرار رمز عبور', 'crop-logic' ),
|
||
|
|
'resetToken' => __( 'توکن ریست', 'crop-logic' ),
|
||
|
|
'noAccount' => __( 'حساب کاربری ندارید؟', 'crop-logic' ),
|
||
|
|
'haveAccount' => __( 'قبلا ثبت نام کردهاید؟', 'crop-logic' ),
|
||
|
|
'rememberedPassword'=> __( 'رمز عبور را به خاطر آوردید؟', 'crop-logic' ),
|
||
|
|
'resetHint' => __( 'توکن بازیابی دارید؟ رمز را ریست کنید', 'crop-logic' ),
|
||
|
|
'submitLogin' => (string) $settings['auth_login_button'],
|
||
|
|
'submitRegister' => (string) $settings['auth_register_button'],
|
||
|
|
'submitForgot' => (string) $settings['auth_forgot_button'],
|
||
|
|
'submitReset' => (string) $settings['auth_reset_button'],
|
||
|
|
'logout' => __( 'خروج', 'crop-logic' ),
|
||
|
|
'deleteConversation'=> __( 'حذف گفتگو', 'crop-logic' ),
|
||
|
|
'closeModal' => __( 'بستن', 'crop-logic' ),
|
||
|
|
'notLoggedIn' => __( 'وارد نشده', 'crop-logic' ),
|
||
|
|
'loggedIn' => __( 'وارد شده', 'crop-logic' ),
|
||
|
|
],
|
||
|
|
];
|
||
|
|
?>
|
||
|
|
<div class="crop-logic-chat" data-settings="<?php echo esc_attr( wp_json_encode( $client_settings ) ); ?>">
|
||
|
|
<div class="crop-logic-chat__overlay"></div>
|
||
|
|
<div class="crop-logic-chat__auth-modal" data-role="auth-modal" hidden>
|
||
|
|
<div class="crop-logic-chat__auth-dialog">
|
||
|
|
<div class="crop-logic-chat__auth-head">
|
||
|
|
<strong><?php echo esc_html__( 'ورود یا ثبت نام', 'crop-logic' ); ?></strong>
|
||
|
|
<button type="button" class="crop-logic-chat__icon-button" data-action="close-auth" aria-label="<?php echo esc_attr__( 'بستن', 'crop-logic' ); ?>">
|
||
|
|
<?php echo $this->get_icon_svg( 'close' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
<div class="crop-logic-chat__auth-body" data-role="auth-body"></div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<aside class="crop-logic-chat__sidebar">
|
||
|
|
<div class="crop-logic-chat__sidebar-head">
|
||
|
|
<strong><?php echo esc_html( $settings['sidebar_title'] ); ?></strong>
|
||
|
|
<button type="button" class="crop-logic-chat__icon-button" data-action="close-sidebar" aria-label="<?php echo esc_attr__( 'بستن سایدبار', 'crop-logic' ); ?>">
|
||
|
|
<?php echo $this->get_icon_svg( 'close' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
<div class="crop-logic-chat__sidebar-body" data-role="sidebar-list"></div>
|
||
|
|
</aside>
|
||
|
|
<div class="crop-logic-chat__header">
|
||
|
|
<div class="crop-logic-chat__header-actions">
|
||
|
|
<button type="button" class="crop-logic-chat__icon-button" data-action="toggle-sidebar" aria-label="<?php echo esc_attr__( 'باز و بسته کردن سایدبار', 'crop-logic' ); ?>">
|
||
|
|
<?php echo $this->get_icon_svg( 'menu' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
|
|
</button>
|
||
|
|
<button type="button" class="crop-logic-chat__new-chat" data-action="new-chat">
|
||
|
|
<?php echo $this->get_icon_svg( 'plus' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
|
|
<span><?php echo esc_html( $settings['new_chat_label'] ); ?></span>
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
<div class="crop-logic-chat__assistant-badge">
|
||
|
|
<?php echo $this->get_icon_svg( 'leaf' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
|
|
</div>
|
||
|
|
<div class="crop-logic-chat__header-copy">
|
||
|
|
<h3 class="crop-logic-chat__title"><?php echo esc_html( $settings['title'] ); ?></h3>
|
||
|
|
<p class="crop-logic-chat__subtitle"><?php echo esc_html( $settings['subtitle'] ); ?></p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="crop-logic-chat__messages" data-role="messages"></div>
|
||
|
|
<div class="crop-logic-chat__chips" data-role="chips">
|
||
|
|
<?php foreach ( $chips as $chip ) : ?>
|
||
|
|
<button type="button" class="crop-logic-chat__chip" data-suggestion="<?php echo esc_attr( $chip ); ?>"><?php echo esc_html( $chip ); ?></button>
|
||
|
|
<?php endforeach; ?>
|
||
|
|
</div>
|
||
|
|
<div class="crop-logic-chat__composer-wrap">
|
||
|
|
<div class="crop-logic-chat__attachments" data-role="attachments"></div>
|
||
|
|
<div class="crop-logic-chat__composer">
|
||
|
|
<?php if ( 'yes' === $settings['show_media_tools'] ) : ?>
|
||
|
|
<label class="crop-logic-chat__icon-button crop-logic-chat__file-button">
|
||
|
|
<?php echo $this->get_icon_svg( 'camera' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
|
|
<input type="file" accept="image/*" multiple data-role="file-input" hidden />
|
||
|
|
</label>
|
||
|
|
<?php endif; ?>
|
||
|
|
<?php if ( 'yes' === $settings['show_voice_button'] ) : ?>
|
||
|
|
<button type="button" class="crop-logic-chat__icon-button" disabled aria-hidden="true">
|
||
|
|
<?php echo $this->get_icon_svg( 'mic' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
|
|
</button>
|
||
|
|
<?php endif; ?>
|
||
|
|
<textarea class="crop-logic-chat__input" data-role="input" rows="1" placeholder="<?php echo esc_attr( $settings['input_placeholder'] ); ?>"></textarea>
|
||
|
|
<button type="button" class="crop-logic-chat__send" data-action="send" aria-label="<?php echo esc_attr__( 'ارسال پیام', 'crop-logic' ); ?>">
|
||
|
|
<?php echo $this->get_icon_svg( 'send' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<?php
|
||
|
|
}
|
||
|
|
|
||
|
|
private function get_icon_svg( string $icon ): string {
|
||
|
|
$icons = [
|
||
|
|
'leaf' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18.8 4.2C12.6 4.3 7.6 7 5.2 12.1c-1.1 2.2-1.5 4.7-1.2 7.2.1.6.6 1.1 1.3 1.1 2.5.2 5-.3 7.2-1.4 5.1-2.5 7.8-7.6 7.5-13.7 0-.7-.6-1.2-1.2-1.1ZM7.8 17.2c.3-2.2 1.3-4.3 3-6 1.7-1.7 3.7-2.8 6-3.1-2.3 1.6-4.3 3.6-5.9 6-.8 1.2-1.5 2.4-2 3.6h-1Z" fill="currentColor"/></svg>',
|
||
|
|
'menu' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="1.8"/></svg>',
|
||
|
|
'plus' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14" fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="1.8"/></svg>',
|
||
|
|
'close' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18" fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="1.8"/></svg>',
|
||
|
|
'camera' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 8h2l1.5-2h5L16.5 8H18a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2Zm6 8a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Z" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="1.7"/></svg>',
|
||
|
|
'mic' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 15a3 3 0 0 0 3-3V8a3 3 0 0 0-6 0v4a3 3 0 0 0 3 3Zm0 0v4m-4-7a4 4 0 0 0 8 0" fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="1.8"/></svg>',
|
||
|
|
'send' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m5 12 14-7-3.5 14-3-5.5L5 12Z" fill="currentColor"/></svg>',
|
||
|
|
'chevron' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"/></svg>',
|
||
|
|
'droplet' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3c3.5 4 6 7 6 10a6 6 0 0 1-12 0c0-3 2.5-6 6-10Z" fill="currentColor"/></svg>',
|
||
|
|
'calendar' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 4v3m10-3v3M5 9h14M6 6h12a1 1 0 0 1 1 1v11a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1Z" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.7"/></svg>',
|
||
|
|
'fertilizer' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4h6l1 3h1a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1l1-3Zm3 5v6m-3-3h6" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.7"/></svg>',
|
||
|
|
'warning' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 4 3.5 19h17L12 4Zm0 5v4m0 3h.01" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"/></svg>',
|
||
|
|
];
|
||
|
|
|
||
|
|
return $icons[ $icon ] ?? $icons['leaf'];
|
||
|
|
}
|
||
|
|
}
|