| 1 |
<?php |
| 2 |
namespace Tutor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) |
| 5 |
exit; |
| 6 |
|
| 7 |
class Options { |
| 8 |
|
| 9 |
public $option; |
| 10 |
public $options_attr; |
| 11 |
|
| 12 |
public function __construct() { |
| 13 |
$this->option = (array) maybe_unserialize(get_option('tutor_option')); |
| 14 |
$this->options_attr = $this->options_attr(); |
| 15 |
|
| 16 |
//Saving option |
| 17 |
add_action('wp_ajax_tutor_option_save', array($this, 'tutor_option_save')); |
| 18 |
} |
| 19 |
|
| 20 |
private function get($key = null, $default = false){ |
| 21 |
$option = $this->option; |
| 22 |
if (empty($option) || ! is_array($option)){ |
| 23 |
return $default; |
| 24 |
} |
| 25 |
if ( ! $key){ |
| 26 |
return $option; |
| 27 |
} |
| 28 |
if (array_key_exists($key, $option)){ |
| 29 |
return apply_filters($key, $option[$key]); |
| 30 |
} |
| 31 |
//Access array value via dot notation, such as option->get('value.subvalue') |
| 32 |
if (strpos($key, '.')){ |
| 33 |
$option_key_array = explode('.', $key); |
| 34 |
$new_option = $option; |
| 35 |
foreach ($option_key_array as $dotKey){ |
| 36 |
if (isset($new_option[$dotKey])){ |
| 37 |
$new_option = $new_option[$dotKey]; |
| 38 |
}else{ |
| 39 |
return $default; |
| 40 |
} |
| 41 |
} |
| 42 |
return apply_filters($key, $new_option); |
| 43 |
} |
| 44 |
|
| 45 |
return $default; |
| 46 |
} |
| 47 |
|
| 48 |
public function tutor_option_save(){ |
| 49 |
if ( ! isset($_POST['_wpnonce']) || ! wp_verify_nonce( $_POST['_wpnonce'], 'tutor_option_save' ) ){ |
| 50 |
exit(); |
| 51 |
} |
| 52 |
|
| 53 |
$option = (array) isset($_POST['tutor_option']) ? $_POST['tutor_option'] : array(); |
| 54 |
$option = apply_filters('tutor_option_input', $option); |
| 55 |
update_option('tutor_option', $option); |
| 56 |
|
| 57 |
//re-sync settings |
| 58 |
init::tutor_activate(); |
| 59 |
|
| 60 |
wp_send_json_success( array('msg' => __('Option Updated', 'tutor') ) ); |
| 61 |
} |
| 62 |
|
| 63 |
public function options_attr(){ |
| 64 |
$pages = tutor_utils()->get_pages(); |
| 65 |
|
| 66 |
//$course_base = tutor_utils()->course_archive_page_url(); |
| 67 |
$lesson_url = site_url().'/course/'.'sample-course/<code>lessons</code>/sample-lesson/'; |
| 68 |
|
| 69 |
$student_url = tutor_utils()->profile_url(); |
| 70 |
|
| 71 |
$attempts_allowed = array(); |
| 72 |
$attempts_allowed['unlimited'] = __('Unlimited' , 'tutor'); |
| 73 |
$attempts_allowed = array_merge($attempts_allowed, array_combine(range(1,20), range(1,20))); |
| 74 |
|
| 75 |
$attr = array( |
| 76 |
'general' => array( |
| 77 |
'label' => __('General', 'tutor'), |
| 78 |
'sections' => array( |
| 79 |
'general' => array( |
| 80 |
'label' => __('General', 'tutor'), |
| 81 |
'desc' => __('General Settings', 'tutor'), |
| 82 |
'fields' => array( |
| 83 |
'enable_public_profile' => array( |
| 84 |
'type' => 'checkbox', |
| 85 |
'label' => __('Enable Public Profile', 'tutor'), |
| 86 |
'default' => '0', |
| 87 |
'desc' => __('Enable this to make a profile publicly visible', 'tutor')."<br />" .$student_url, |
| 88 |
), |
| 89 |
'load_tutor_css' => array( |
| 90 |
'type' => 'checkbox', |
| 91 |
'label' => __('Load Tutor default CSS', 'tutor'), |
| 92 |
'default' => '1', |
| 93 |
'desc' => __('If your theme has its own styling, then you can turn it off to load CSS from the plugin directory', 'tutor'), |
| 94 |
), |
| 95 |
'load_tutor_js' => array( |
| 96 |
'type' => 'checkbox', |
| 97 |
'label' => __('Load Tutor default JavaScript', 'tutor'), |
| 98 |
'default' => '1', |
| 99 |
'desc' => __('If you have put required script in your theme javascript file, then you can turn it off to load JavaScript from the plugin directory', 'tutor'), |
| 100 |
), |
| 101 |
'student_must_login_to_view_course' => array( |
| 102 |
'type' => 'checkbox', |
| 103 |
'label' => __('Course Permission', 'tutor'), |
| 104 |
'desc' => __('Students must be logged in to view course', 'tutor'), |
| 105 |
), |
| 106 |
'delete_on_uninstall' => array( |
| 107 |
'type' => 'checkbox', |
| 108 |
'label' => __('Erase upon uninstallation', 'tutor'), |
| 109 |
'desc' => __('Delete all data during uninstall', 'tutor'), |
| 110 |
), |
| 111 |
) |
| 112 |
) |
| 113 |
), |
| 114 |
), |
| 115 |
'course' => array( |
| 116 |
'label' => __('Course', 'tutor'), |
| 117 |
'sections' => array( |
| 118 |
'general' => array( |
| 119 |
'label' => __('General', 'tutor'), |
| 120 |
'desc' => __('Course Settings', 'tutor'), |
| 121 |
'fields' => array( |
| 122 |
'display_course_instructors' => array( |
| 123 |
'type' => 'checkbox', |
| 124 |
'label' => __('Display instructors profile', 'tutor'), |
| 125 |
'label_title' => __('Show the instructor profile on course single page.', 'tutor'), |
| 126 |
), |
| 127 |
'enable_q_and_a_on_course' => array( |
| 128 |
'type' => 'checkbox', |
| 129 |
'label' => __('Enable Q & A on course', 'tutor'), |
| 130 |
'default' => '0', |
| 131 |
'desc' => __('Allow student to place their questions and answers on the course page, only enrolled student can do this', 'tutor'), |
| 132 |
), |
| 133 |
), |
| 134 |
), |
| 135 |
'archive' => array( |
| 136 |
'label' => __('Archive', 'tutor'), |
| 137 |
'desc' => __('Course Archive Settings', 'tutor'), |
| 138 |
'fields' => array( |
| 139 |
'course_archive_page' => array( |
| 140 |
'type' => 'select', |
| 141 |
'label' => __('Course Archive Page', 'tutor'), |
| 142 |
'default' => '0', |
| 143 |
'options' => $pages, |
| 144 |
'desc' => __('Choose the page from the dropdown list where you want to show all of the courses', 'tutor'), |
| 145 |
), |
| 146 |
'courses_col_per_row' => array( |
| 147 |
'type' => 'slider', |
| 148 |
'label' => __('Column per row', 'tutor'), |
| 149 |
'default' => '4', |
| 150 |
'options' => array('min'=> 1, 'max' => 6), |
| 151 |
'desc' => __('Define how many column you want to show on the course single page', 'tutor'), |
| 152 |
), |
| 153 |
'courses_per_page' => array( |
| 154 |
'type' => 'slider', |
| 155 |
'label' => __('Courses Per Page', 'tutor'), |
| 156 |
'default' => '12', |
| 157 |
'options' => array('min'=> 1, 'max' => 20), |
| 158 |
'desc' => __('Define how many courses you want to show per page', 'tutor'), |
| 159 |
), |
| 160 |
), |
| 161 |
), |
| 162 |
), |
| 163 |
), |
| 164 |
'lesson' => array( |
| 165 |
'label' => __('Lessons', 'tutor'), |
| 166 |
'sections' => array( |
| 167 |
'lesson_settings' => array( |
| 168 |
'label' => __('Lesson Settings', 'tutor'), |
| 169 |
'desc' => __('Lesson settings will be here', 'tutor'), |
| 170 |
'fields' => array( |
| 171 |
'lesson_permalink_base' => array( |
| 172 |
'type' => 'text', |
| 173 |
'label' => __('Lesson Permalink Base', 'tutor'), |
| 174 |
'default' => 'lessons', |
| 175 |
'desc' => $lesson_url, |
| 176 |
), |
| 177 |
|
| 178 |
), |
| 179 |
|
| 180 |
), |
| 181 |
|
| 182 |
), |
| 183 |
), |
| 184 |
'quiz' => array( |
| 185 |
'label' => __('Quiz', 'tutor'), |
| 186 |
'sections' => array( |
| 187 |
'general' => array( |
| 188 |
'label' => __('Quiz', 'tutor'), |
| 189 |
'desc' => __('The values you set here define the default values that are used in the settings form when you create a new quiz.', 'tutor'), |
| 190 |
'fields' => array( |
| 191 |
'quiz_time_limit' => array( |
| 192 |
'type' => 'group_fields', |
| 193 |
'label' => __('Time Limit', 'tutor'), |
| 194 |
'desc' => __('Default time limit for quizzes. 0 means no time limit.', 'tutor'), |
| 195 |
'group_fields' => array( |
| 196 |
'value' => array( |
| 197 |
'type' => 'text', |
| 198 |
'default' => '0', |
| 199 |
), |
| 200 |
'time' => array( |
| 201 |
'type' => 'select', |
| 202 |
'default' => 'minutes', |
| 203 |
'select_options' => false, |
| 204 |
'options' => array( |
| 205 |
'weeks' => __('Weeks', 'tutor'), |
| 206 |
'days' => __('Days', 'tutor'), |
| 207 |
'hours' => __('Hours', 'tutor'), |
| 208 |
'minutes' => __('Minutes', 'tutor'), |
| 209 |
'seconds' => __('Seconds', 'tutor'), |
| 210 |
), |
| 211 |
), |
| 212 |
), |
| 213 |
), |
| 214 |
|
| 215 |
'quiz_when_time_expires' => array( |
| 216 |
'type' => 'radio', |
| 217 |
'label' => __('When time expires', 'tutor'), |
| 218 |
'default' => 'minutes', |
| 219 |
'select_options' => false, |
| 220 |
'options' => array( |
| 221 |
'autosubmit' => __('Current attempts are submitted automatically', 'tutor'), |
| 222 |
'graceperiod' => __('There is a grace period when current attempts can be submitted, but no more questions answered', 'tutor'), |
| 223 |
'autoabandon' => __('Attempts must be submitted before time expires, otherwise they will not be counted', 'tutor'), |
| 224 |
), |
| 225 |
'desc' => __('What should happen by default if a student does not submit the quiz before time expires.', 'tutor'), |
| 226 |
), |
| 227 |
|
| 228 |
'quiz_attempts_allowed' => array( |
| 229 |
'type' => 'number', |
| 230 |
'label' => __('Attempts allowed', 'tutor'), |
| 231 |
'default' => '10', |
| 232 |
'desc' => __('Restriction on the number of attempts students are allowed to take for a quiz. 0 for no limit', 'tutor'), |
| 233 |
), |
| 234 |
|
| 235 |
'quiz_grade_method' => array( |
| 236 |
'type' => 'select', |
| 237 |
'label' => __('Grading method', 'tutor'), |
| 238 |
'default' => 'minutes', |
| 239 |
'select_options' => false, |
| 240 |
'options' => array( |
| 241 |
'highest_grade' => __('Highest Grade', 'tutor'), |
| 242 |
'average_grade' => __('Average Grade', 'tutor'), |
| 243 |
'first_attempt' => __('First Attempt', 'tutor'), |
| 244 |
'last_attempt' => __('Last Attempt', 'tutor'), |
| 245 |
), |
| 246 |
'desc' => __('When multiple attempts are allowed, which method should be used to calculate a student\'s final grade for the quiz.', 'tutor'), |
| 247 |
), |
| 248 |
) |
| 249 |
) |
| 250 |
), |
| 251 |
), |
| 252 |
'instructors' => array( |
| 253 |
'label' => __('Instructors', 'tutor'), |
| 254 |
'sections' => array( |
| 255 |
'general' => array( |
| 256 |
'label' => __('Instructor Profile Settings', 'tutor'), |
| 257 |
'desc' => __('Enable Disable Option to on/off notification on various event', 'tutor'), |
| 258 |
'fields' => array( |
| 259 |
'instructor_register_page' => array( |
| 260 |
'type' => 'select', |
| 261 |
'label' => __('Instructor Register Page', 'tutor'), |
| 262 |
'default' => '0', |
| 263 |
'options' => $pages, |
| 264 |
'desc' => __('This will be instructor register page', 'tutor'), |
| 265 |
), |
| 266 |
'instructor_can_publish_course' => array( |
| 267 |
'type' => 'checkbox', |
| 268 |
'label' => __('Can publish course', 'tutor'), |
| 269 |
'default' => '0', |
| 270 |
'desc' => __('Define if a instructor can publish his courses directly or not, if unchecked, they can still add courses, but it will go to admin for review', 'tutor'), |
| 271 |
), |
| 272 |
), |
| 273 |
), |
| 274 |
), |
| 275 |
), |
| 276 |
|
| 277 |
'students' => array( |
| 278 |
'label' => __('Students', 'tutor'), |
| 279 |
'sections' => array( |
| 280 |
'general' => array( |
| 281 |
'label' => __('Student Profile settings', 'tutor'), |
| 282 |
'desc' => __('Enable Disable Option to on/off notification on various event', 'tutor'), |
| 283 |
'fields' => array( |
| 284 |
'student_register_page' => array( |
| 285 |
'type' => 'select', |
| 286 |
'label' => __('Student Register Page', 'tutor'), |
| 287 |
'default' => '0', |
| 288 |
'options' => $pages, |
| 289 |
'desc' => __('Choose the page for student registration page', 'tutor'), |
| 290 |
), |
| 291 |
'student_dashboard' => array( |
| 292 |
'type' => 'select', |
| 293 |
'label' => __('Student Dashboard', 'tutor'), |
| 294 |
'default' => '0', |
| 295 |
'options' => $pages, |
| 296 |
'desc' => __('This page will show students related stuff, like my courses, order, etc', 'tutor'), |
| 297 |
), |
| 298 |
|
| 299 |
'students_own_review_show_at_profile' => array( |
| 300 |
'type' => 'checkbox', |
| 301 |
'label' => __('Show reviews on profile', 'tutor'), |
| 302 |
'label_title' => __('Enable students review on their profile', 'tutor'), |
| 303 |
'default' => '0', |
| 304 |
'desc' => __('Enabling this will allow the reviews written by each individual students on their profile', 'tutor')."<br />" .$student_url, |
| 305 |
), |
| 306 |
'show_courses_completed_by_student' => array( |
| 307 |
'type' => 'checkbox', |
| 308 |
'label' => __('Show Completed Course', 'tutor'), |
| 309 |
'default' => '0', |
| 310 |
'desc' => __('Completed courses will be show on student profile', 'tutor')."<br />".$student_url, |
| 311 |
), |
| 312 |
|
| 313 |
), |
| 314 |
), |
| 315 |
), |
| 316 |
), |
| 317 |
|
| 318 |
|
| 319 |
); |
| 320 |
|
| 321 |
return apply_filters('tutor/options/attr', $attr); |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
/** |
| 326 |
* @param array $field |
| 327 |
* |
| 328 |
* @return string |
| 329 |
* |
| 330 |
* Generate Option Field |
| 331 |
*/ |
| 332 |
public function generate_field($field = array()){ |
| 333 |
ob_start(); |
| 334 |
include tutor()->path.'views/options/option_field.php'; |
| 335 |
return ob_get_clean(); |
| 336 |
} |
| 337 |
|
| 338 |
public function field_type($field = array()){ |
| 339 |
ob_start(); |
| 340 |
include tutor()->path."views/options/field-types/{$field['type']}.php"; |
| 341 |
return ob_get_clean(); |
| 342 |
} |
| 343 |
|
| 344 |
public function generate(){ |
| 345 |
ob_start(); |
| 346 |
include tutor()->path.'views/options/options_generator.php'; |
| 347 |
return ob_get_clean(); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
} |