render_for_frontend(); } catch ( Throwable $e ) { LP_Debug::error_log( $e ); } } /** * Render curriculum AI popup template for frontend contexts (e.g. Course Builder). * * @return string * @since 4.3.0 */ public function render_for_frontend(): string { try { $this->config = Config::instance()->get( 'open-ai-modal', 'settings' ); $components = [ 'wrap-script-template' => '', ]; return Template::combine_components( $components ); } catch ( Throwable $e ) { LP_Debug::error_log( $e ); } return ''; } public function html_step_header(): string { $components = [ 'wrap' => '
', 'step_1' => sprintf( '
1%s
', esc_html__( 'Curriculum Goal', 'learnpress' ) ), 'step_2' => sprintf( '
2%s
', esc_html__( 'AI Settings', 'learnpress' ) ), 'step_3' => sprintf( '
3%s
', esc_html__( 'Prompt', 'learnpress' ) ), 'step_4' => sprintf( '
4%s
', esc_html__( 'Result', 'learnpress' ) ), 'wrap-end' => '
', ]; return Template::combine_components( $components ); } public function html_step_1(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 1 — Curriculum Goal', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Provide the main goal for the curriculum so the system can generate aligned sections and lessons.', 'learnpress' ) ), 'post-title' => sprintf( '

%s

%s

', esc_html__( 'Title refer', 'learnpress' ), esc_html__( 'You can edit the course title to better suit the curriculum generation.', 'learnpress' ), esc_html__( 'The course title is automatically imported from the previous step. It will guide the AI to build a structured curriculum.', 'learnpress' ), ), 'post-content' => sprintf( '

%s

%s

', esc_html__( 'Description refer', 'learnpress' ), esc_html__( 'You can edit the course description to better suit the curriculum generation.', 'learnpress' ), esc_html__( 'The course description is automatically imported from the previous step. It will guide the AI to build a structured curriculum.', 'learnpress' ) ), 'goal' => sprintf( '
', esc_html__( 'Goal', 'learnpress' ), esc_html__( 'Defines the main objective of your curriculum. This helps the AI generate course sections and lessons that align with the intended learning outcomes.', 'learnpress' ) ), 'form-grid' => '
', 'sections-number' => sprintf( '
', esc_html__( 'Sections number', 'learnpress' ) ), /*'sections-title-length' => sprintf( '
', esc_html__( 'Each section title length', 'learnpress' ) ), 'sections-des-length' => sprintf( '
', esc_html__( 'Each section description length', 'learnpress' ) ),*/ 'lesson-number' => sprintf( '
', esc_html__( 'Lessons per Section', 'learnpress' ) ), /*'lesson-title-length' => sprintf( '
', esc_html__( 'Each lesson title length', 'learnpress' ) ),*/ 'quizzes' => sprintf( '
', esc_html__( 'Quizzes per Section', 'learnpress' ) ), /*'quiz-title-length' => sprintf( '
', esc_html__( 'Each quiz title length', 'learnpress' ) ),*/ 'form-grid-end' => '
', 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_step_2(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 2 — AI Settings', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Configure content quality controls for ChatGPT output.', 'learnpress' ) ), 'form-grid' => '
', 'audience' => sprintf( '
%s

%s

', esc_html__( 'Target Audience', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'target_audience', 'class_name' => '', 'options' => $options['audience'] ?? [], 'default_value' => 'Students', 'multiple' => true, ] ), esc_html__( 'Identifies who will take the course so the content matches their background and skill level.', 'learnpress' ) ), 'tone' => sprintf( '
%s

%s

', esc_html__( 'Tone', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'tone', 'options' => $options['tone'] ?? [], 'multiple' => true, 'default_value' => [ 'Analytical' ], ] ), esc_html__( 'Controls the writing style (e.g., friendly, formal, story-telling) so the content matches your brand and audience.', 'learnpress' ) ), 'language' => sprintf( '
%s

%s

', esc_html__( 'Language', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'language', 'options' => $options['language'] ?? [], ] ), esc_html__( 'Sets the output language for all generated course content.', 'learnpress' ) ), 'form-grid-end' => '
', 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_step_3(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 3 — Prompt Generated', 'learnpress' ), ), 'prompt' => sprintf( '
%s %s
', esc_html__( 'Generated Prompt', 'learnpress' ), '', __( 'Shows the auto-generated AI prompt, allowing further adjustments before submission.', 'learnpress' ) ), 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_step_4(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 4 — Result', 'learnpress' ), ), 'results' => '
', 'step_close' => '
', ]; return Template::combine_components( $components ); } /** * HTML preview with data received from OpenAI * * @param array $data_received * * @return string */ public static function html_preview_with_data( array $data_received ): string { $sections = $data_received['sections'] ?? []; $html_section = ''; foreach ( $sections as $section ) { $section_title = $section['section_title'] ?? ''; $section_des = $section['section_description'] ?? ''; $lessons = $section['lessons'] ?? []; $quizzes = $section['quizzes'] ?? []; $html_lessons = ''; foreach ( $lessons as $lesson ) { $lesson_title = $lesson['lesson_title'] ?? ''; $lesson_des = $lesson['lesson_description'] ?? ''; $arr_lesson_components = [ 'wrap' => '
  • ', 'title' => sprintf( '
    %s
    ', esc_html( $lesson_title ) ), 'des' => sprintf( '
    %s
    ', esc_html( $lesson_des ) ), 'wrap-end' => '
  • ', ]; $html_lessons .= Template::combine_components( $arr_lesson_components ); } // Quizzes $html_quizzes = ''; foreach ( $quizzes as $quiz ) { $quiz_title = $quiz['quiz_title'] ?? ''; $quiz_des = $quiz['quiz_description'] ?? ''; $questions = $quiz['questions'] ?? []; $html_questions = ''; foreach ( $questions as $question ) { $question_title = $question['question_title'] ?? ''; $question_des = $question['question_description'] ?? ''; $options = $question['options'] ?? []; $html_options = ''; foreach ( $options as $option ) { $html_options .= sprintf( '
  • %s
  • ', esc_html( $option ) ); } $arr_question_components = [ 'wrap' => '
  • ', 'title' => sprintf( '
    %s
    ', esc_html( $question_title ) ), 'desc' => sprintf( '
    %s
    ', esc_html( $question_des ) ), 'options' => sprintf( '', $html_options ), 'wrap-end' => '
  • ', ]; $html_questions .= Template::combine_components( $arr_question_components ); } $arr_quiz_components = [ 'wrap' => '
    ', 'title' => sprintf( '
    %s
    ', esc_html( $quiz_title ) ), 'des' => sprintf( '
    %s
    ', esc_html( $quiz_des ) ), 'questions' => sprintf( '', $html_questions ), 'wrap-end' => '
    ', ]; $html_quizzes .= Template::combine_components( $arr_quiz_components ); } $arr_section_components = [ 'wrap' => '
  • ', 'title' => sprintf( '
    %s
    ', esc_html( $section_title ) ), 'des' => sprintf( '
    %s
    ', esc_html( $section_des ) ), 'lessons' => sprintf( '', $html_lessons ), 'quizzes' => sprintf( '', $html_quizzes ), 'wrap-end' => '
  • ', ]; $html_section .= Template::combine_components( $arr_section_components ); } $section = [ 'wrap' => '
    ', 'sections' => sprintf( '', $html_section ), 'wrap-end' => '
    ', ]; return Template::combine_components( $section ); } }