PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/learnpress-fill-in-blank/learnpress-fill-in-blank.php

https://gitlab.com/gregtyka/lfmawordpress
PHP | 157 lines | 88 code | 16 blank | 53 comment | 4 complexity | 3574a0f38744cb8227c1be7e555e1092 MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: LearnPress Question Fill In Blank
  4. Plugin URI: http://thimpress.com/learnpress
  5. Description: Supports type of question Fill In Blank lets user fill out the text into one ( or more than one ) space
  6. Author: ThimPress
  7. Version: 1.0
  8. Author URI: http://thimpress.com
  9. Tags: learnpress
  10. Text Domain: learnpress-fill-in-blank
  11. Domain Path: /languages/
  12. */
  13. if ( !defined( 'ABSPATH' ) ) {
  14. exit; // Exit if accessed directly
  15. }
  16. if ( !defined( 'ABSPATH' ) ) {
  17. exit; // Exit if accessed directly
  18. }
  19. if ( !defined( 'LP_QUESTION_FILL_IN_BLANK_PATH' ) ) {
  20. define( 'LP_QUESTION_FILL_IN_BLANK_FILE', __FILE__ );
  21. define( 'LP_QUESTION_FILL_IN_BLANK_PATH', dirname( __FILE__ ) );
  22. }
  23. /**
  24. * Class LP_Addon_Question_Fill_In_Blank
  25. */
  26. class LP_Addon_Question_Fill_In_Blank {
  27. /**
  28. * Initialize
  29. */
  30. static function init() {
  31. add_action( 'learn_press_ready', array( __CLASS__, 'ready' ) );
  32. add_action( 'plugins_loaded', array( __CLASS__, 'load_text_domain' ) );
  33. add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
  34. add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
  35. add_filter( 'learn_press_save_default_question_types', array( __CLASS__, 'default_types' ) );
  36. add_filter( 'learn_press_question_meta_box_args', array( __CLASS__, 'admin_options' ) );
  37. add_filter( 'learn_press_question_types', array( __CLASS__, 'register_question' ) );
  38. }
  39. /**
  40. * Add new options to question
  41. *
  42. * @param $args
  43. *
  44. * @return mixed
  45. */
  46. static function admin_options( $args ) {
  47. $args['fields'][] = array(
  48. 'name' => __( 'Mark result', 'learnpress-fill-in-blank' ),
  49. 'id' => "_lpr_fill_in_blank_mark_result",
  50. 'type' => 'radio',
  51. 'desc' => __( 'Mark result for this question', 'learnpress-fill-in-blank' ),
  52. 'options' => array(
  53. 'correct_all' => __( 'Requires correct all blanks', 'learnpress-fill-in-blank' ),
  54. 'correct_blanks' => __( 'Mark is calculated by total of correct blanks', 'learnpress-fill-in-blank' )
  55. ),
  56. 'std' => 'correct_all',
  57. 'class' => 'fill-in-blank-meta'
  58. );
  59. return $args;
  60. }
  61. static function default_types( $types ) {
  62. $types[] = 'fill_in_blank';
  63. return $types;
  64. }
  65. /**
  66. * @return mixed|void
  67. */
  68. static function admin_js_template() {
  69. ob_start();
  70. ?>
  71. <tr class="lp-list-option lp-list-option-new lp-list-option-empty <# if(data.value){ #>lp-list-option-{{data.value}}<# } #>" data-id="{{data.value}}">
  72. <td>
  73. <input class="lp-answer-text no-submit key-nav" type="text" name="learn_press_question[{{data.question_id}}][answer][text][]" value="{{data.text}}" />
  74. <input type="hidden" name="learn_press_question[{{data.question_id}}][answer][value][]" value="{{data.value}}" />
  75. </td>
  76. <td class="display-position display-position-{{data.question_id}} display-position-{{data.value}}">
  77. <span class="lp-question-sorting-choice-display-position lp-question-sorting-choice-display-position-{{data.question_id}} lp-question-sorting-choice-display-position-{{data.value}}">
  78. <input type="hidden" name="learn_press_question[{{data.question_id}}][answer][position][]" value="{{data.value}}" />
  79. <span>{{data.text}}</span>
  80. </span>
  81. </td>
  82. <td class="lp-list-option-actions lp-remove-list-option">
  83. <i class="dashicons dashicons-trash"></i>
  84. </td>
  85. <td class="lp-list-option-actions lp-move-list-option open-hand">
  86. <i class="dashicons dashicons-sort"></i>
  87. </td>
  88. </tr>
  89. <?php
  90. return apply_filters( 'learn_press_question_sorting_choice_answer_option_template', ob_get_clean(), __CLASS__ );
  91. }
  92. /**
  93. * Enqueues assets
  94. */
  95. static function enqueue_assets() {
  96. wp_enqueue_script( 'question-fill-in-blank-js', plugins_url( '/', LP_QUESTION_FILL_IN_BLANK_FILE ) . 'assets/script.js', array( 'jquery' ) );
  97. wp_enqueue_style( 'question-fill-in-blank-css', plugins_url( '/', LP_QUESTION_FILL_IN_BLANK_FILE ) . 'assets/style.css' );
  98. }
  99. /**
  100. *
  101. */
  102. static function ready() {
  103. require_once LP_QUESTION_FILL_IN_BLANK_PATH . '/inc/class-lp-question-fill-in-blank.php';
  104. }
  105. /**
  106. * Register Fill In Blank question type
  107. *
  108. * @param $types
  109. *
  110. * @return mixed
  111. */
  112. static function register_question( $types ) {
  113. $types['fill_in_blank'] = __( 'Fill In Blank', 'learn_press' );
  114. return $types;
  115. }
  116. /**
  117. * Textdomain
  118. */
  119. static function load_text_domain() {
  120. if ( function_exists( 'learn_press_load_plugin_text_domain' ) ) {
  121. learn_press_load_plugin_text_domain( LP_QUESTION_FILL_IN_BLANK_PATH );
  122. }
  123. }
  124. /**
  125. * @param $name
  126. * @param null $args
  127. */
  128. static function get_template( $name, $args = null ) {
  129. learn_press_get_template( $name, $args, get_template_directory() . '/addons/fill-in-blank/', LP_QUESTION_FILL_IN_BLANK_PATH . '/templates/' );
  130. }
  131. /**
  132. * @param $name
  133. *
  134. * @return string
  135. */
  136. static function locate_template( $name ) {
  137. return learn_press_locate_template( $name, get_template_directory() . '/addons/fill-in-blank/', LP_QUESTION_FILL_IN_BLANK_PATH . '/templates/' );
  138. }
  139. }
  140. // Sparky, run now!
  141. LP_Addon_Question_Fill_In_Blank::init();