Addons.php
4 years ago
Admin.php
4 years ago
Ajax.php
4 years ago
Assets.php
4 years ago
Course.php
4 years ago
Course_Filter.php
4 years ago
Course_Settings_Tabs.php
5 years ago
Course_Widget.php
5 years ago
Custom_Validation.php
5 years ago
Dashboard.php
5 years ago
Email.php
5 years ago
FormHandler.php
5 years ago
Frontend.php
5 years ago
Gutenberg.php
4 years ago
Instructor.php
4 years ago
Instructors_List.php
4 years ago
Lesson.php
4 years ago
Options.php
4 years ago
Post_types.php
4 years ago
Private_Course_Access.php
5 years ago
Q_and_A.php
5 years ago
Question_Answers_List.php
4 years ago
Quiz.php
5 years ago
Quiz_Attempts_List.php
4 years ago
RestAPI.php
5 years ago
Rewrite_Rules.php
5 years ago
Shortcode.php
4 years ago
Student.php
5 years ago
Students_List.php
5 years ago
Taxonomies.php
5 years ago
Template.php
4 years ago
Theme_Compatibility.php
5 years ago
Tools.php
5 years ago
Tutor.php
4 years ago
TutorEDD.php
5 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
4 years ago
Tutor_Setup.php
5 years ago
Upgrader.php
5 years ago
User.php
4 years ago
Utils.php
4 years ago
Video_Stream.php
5 years ago
Withdraw.php
5 years ago
Withdraw_Requests_List.php
4 years ago
WooCommerce.php
4 years ago
RestAPI.php
316 lines
| 1 | <?php |
| 2 | /** |
| 3 | * RestAPI class |
| 4 | * |
| 5 | * @author: themeum |
| 6 | * @author_uri: https://themeum.com |
| 7 | * @package Tutor |
| 8 | * @since v.1.5.0 |
| 9 | */ |
| 10 | |
| 11 | namespace TUTOR; |
| 12 | |
| 13 | if (!defined('ABSPATH')) |
| 14 | exit; |
| 15 | |
| 16 | class RestAPI { |
| 17 | |
| 18 | use Custom_Validation; |
| 19 | |
| 20 | private $namespace = 'tutor/v1'; |
| 21 | |
| 22 | protected $course_post_type; |
| 23 | |
| 24 | private $path; |
| 25 | |
| 26 | private $courseObj; |
| 27 | |
| 28 | private $topicObj; |
| 29 | |
| 30 | private $lessonObj; |
| 31 | |
| 32 | private $annoucementObj; |
| 33 | |
| 34 | private $quizObj; |
| 35 | |
| 36 | private $authorObj; |
| 37 | |
| 38 | private $ratingObj; |
| 39 | |
| 40 | public function __construct() { |
| 41 | |
| 42 | $this->path = plugin_dir_path(TUTOR_FILE); |
| 43 | //autoloading clases |
| 44 | if (function_exists('__autoload')) { |
| 45 | spl_autoload_register('__autoload'); |
| 46 | } |
| 47 | spl_autoload_register(array($this, 'loader')); |
| 48 | |
| 49 | |
| 50 | $this->courseObj = new REST_Course; |
| 51 | $this->topicObj = new REST_Topic; |
| 52 | $this->lessonObj = new REST_Lesson; |
| 53 | $this->annoucementObj = new REST_Course_Announcement; |
| 54 | $this->quizObj = new REST_Quiz; |
| 55 | $this->authorObj = new REST_Author; |
| 56 | $this->ratingObj = new REST_Rating; |
| 57 | |
| 58 | add_action('rest_api_init', array($this, 'init_routes')); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | private function loader($className) { |
| 63 | if (!class_exists($className)) { |
| 64 | $className = preg_replace( |
| 65 | array('/([a-z])([A-Z])/', '/\\\/'), |
| 66 | array('$1$2', DIRECTORY_SEPARATOR), |
| 67 | $className |
| 68 | ); |
| 69 | |
| 70 | $className = str_replace('TUTOR' . DIRECTORY_SEPARATOR, 'restapi' . DIRECTORY_SEPARATOR, $className); |
| 71 | $file_name = $this->path . $className . '.php'; |
| 72 | |
| 73 | if (file_exists($file_name)) { |
| 74 | require_once $file_name; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | init all routes for api |
| 81 | */ |
| 82 | public function init_routes() { |
| 83 | //courses |
| 84 | register_rest_route( |
| 85 | $this->namespace, |
| 86 | '/courses', |
| 87 | array( |
| 88 | 'methods' => "GET", |
| 89 | 'callback' => array( |
| 90 | $this->courseObj, 'course' |
| 91 | ), |
| 92 | 'permission_callback' => '__return_true' |
| 93 | ) |
| 94 | ); |
| 95 | |
| 96 | //courses by terms cat and tag |
| 97 | register_rest_route( |
| 98 | $this->namespace, |
| 99 | '/course-by-terms', |
| 100 | array( |
| 101 | 'methods' => "POST", |
| 102 | 'callback' => array( |
| 103 | $this->courseObj, 'course_by_terms' |
| 104 | ), |
| 105 | 'permission_callback' => '__return_true' |
| 106 | ) |
| 107 | ); |
| 108 | |
| 109 | //courses by terms cat and tag |
| 110 | register_rest_route( |
| 111 | $this->namespace, |
| 112 | '/course-sorting-by-price', |
| 113 | array( |
| 114 | 'methods' => "GET", |
| 115 | 'callback' => array( |
| 116 | $this->courseObj, 'course_sort_by_price' |
| 117 | ), |
| 118 | 'args' => array( |
| 119 | 'order' => array( |
| 120 | 'required' => true, |
| 121 | 'type' => 'string', |
| 122 | 'validate_callback' => function ($order) { |
| 123 | return $this->validate_order($order); |
| 124 | } |
| 125 | ), |
| 126 | 'page' => array( |
| 127 | 'required' => false, |
| 128 | 'type' => 'number' |
| 129 | ) |
| 130 | ), |
| 131 | 'permission_callback' => '__return_true' |
| 132 | ) |
| 133 | ); |
| 134 | |
| 135 | //course details |
| 136 | register_rest_route( |
| 137 | $this->namespace, |
| 138 | '/course-detail/(?P<id>\d+)', |
| 139 | array( |
| 140 | 'methods' => 'GET', |
| 141 | 'callback' => array( |
| 142 | $this->courseObj, 'course_detail' |
| 143 | ), |
| 144 | 'args' => array( |
| 145 | 'id' => array( |
| 146 | 'validate_callback' => function ($param) { |
| 147 | return is_numeric($param); |
| 148 | } |
| 149 | ) |
| 150 | ), |
| 151 | 'permission_callback' => '__return_true' |
| 152 | ) |
| 153 | ); |
| 154 | |
| 155 | //course topic |
| 156 | register_rest_route( |
| 157 | $this->namespace, |
| 158 | '/course-topic/(?P<id>\d+)', |
| 159 | array( |
| 160 | 'methods' => 'GET', |
| 161 | 'callback' => array( |
| 162 | $this->topicObj, 'course_topic' |
| 163 | ), |
| 164 | 'args' => array( |
| 165 | 'id' => array( |
| 166 | 'validate_callback' => function ($param) { |
| 167 | return is_numeric($param); |
| 168 | } |
| 169 | ) |
| 170 | ), |
| 171 | 'permission_callback' => '__return_true' |
| 172 | ) |
| 173 | ); |
| 174 | |
| 175 | //lesson by topic |
| 176 | register_rest_route( |
| 177 | $this->namespace, |
| 178 | '/lesson/(?P<id>\d+)', |
| 179 | array( |
| 180 | 'methods' => 'GET', |
| 181 | 'callback' => array( |
| 182 | $this->lessonObj, 'topic_lesson' |
| 183 | ), |
| 184 | 'args' => array( |
| 185 | 'id' => array( |
| 186 | 'validate_callback' => function ($param) { |
| 187 | return is_numeric($param); |
| 188 | } |
| 189 | ) |
| 190 | ), |
| 191 | 'permission_callback' => '__return_true' |
| 192 | ) |
| 193 | ); |
| 194 | |
| 195 | //course annoucement by course id |
| 196 | register_rest_route( |
| 197 | $this->namespace, |
| 198 | '/course-annoucement/(?P<id>\d+)', |
| 199 | array( |
| 200 | 'methods' => 'GET', |
| 201 | 'callback' => array( |
| 202 | $this->annoucementObj, 'course_annoucement' |
| 203 | ), |
| 204 | 'args' => array( |
| 205 | 'id' => array( |
| 206 | 'validate_callback' => function ($param) { |
| 207 | return is_numeric($param); |
| 208 | } |
| 209 | ) |
| 210 | ), |
| 211 | 'permission_callback' => '__return_true' |
| 212 | ) |
| 213 | ); |
| 214 | |
| 215 | //quiz by topic id |
| 216 | register_rest_route( |
| 217 | $this->namespace, |
| 218 | '/quiz/(?P<id>\d+)', |
| 219 | array( |
| 220 | 'methods' => 'GET', |
| 221 | 'callback' => array( |
| 222 | $this->quizObj, 'quiz_with_settings' |
| 223 | ), |
| 224 | 'args' => array( |
| 225 | 'id' => array( |
| 226 | 'validate_callback' => function ($param) { |
| 227 | return is_numeric($param); |
| 228 | } |
| 229 | ) |
| 230 | ), |
| 231 | 'permission_callback' => '__return_true' |
| 232 | ) |
| 233 | ); |
| 234 | |
| 235 | //quiz question answer by quiz id |
| 236 | register_rest_route( |
| 237 | $this->namespace, |
| 238 | '/quiz-question-answer/(?P<id>\d+)', |
| 239 | array( |
| 240 | 'methods' => 'GET', |
| 241 | 'callback' => array( |
| 242 | $this->quizObj, 'quiz_question_ans' |
| 243 | ), |
| 244 | 'args' => array( |
| 245 | 'id' => array( |
| 246 | 'validate_callback' => function ($param) { |
| 247 | return is_numeric($param); |
| 248 | } |
| 249 | ) |
| 250 | ), |
| 251 | 'permission_callback' => '__return_true' |
| 252 | ) |
| 253 | ); |
| 254 | |
| 255 | //quiz attempt details by quiz id |
| 256 | register_rest_route( |
| 257 | $this->namespace, |
| 258 | '/quiz-attempt-details/(?P<id>\d+)', |
| 259 | array( |
| 260 | 'methods' => 'GET', |
| 261 | 'callback' => array( |
| 262 | $this->quizObj, 'quiz_attempt_details' |
| 263 | ), |
| 264 | 'args' => array( |
| 265 | 'id' => array( |
| 266 | 'validate_callback' => function ($param) { |
| 267 | return is_numeric($param); |
| 268 | } |
| 269 | ) |
| 270 | ), |
| 271 | 'permission_callback' => '__return_true' |
| 272 | ) |
| 273 | ); |
| 274 | |
| 275 | //author detail by id |
| 276 | register_rest_route( |
| 277 | $this->namespace, |
| 278 | '/author-information/(?P<id>\d+)', |
| 279 | array( |
| 280 | 'methods' => 'GET', |
| 281 | 'callback' => array( |
| 282 | $this->authorObj, 'author_detail' |
| 283 | ), |
| 284 | 'args' => array( |
| 285 | 'id' => array( |
| 286 | 'validate_callback' => function ($param) { |
| 287 | return is_numeric($param); |
| 288 | } |
| 289 | ) |
| 290 | ), |
| 291 | 'permission_callback' => '__return_true' |
| 292 | ) |
| 293 | ); |
| 294 | |
| 295 | //reviews by course id |
| 296 | register_rest_route( |
| 297 | $this->namespace, |
| 298 | '/course-rating/(?P<id>\d+)', |
| 299 | array( |
| 300 | 'methods' => 'GET', |
| 301 | 'callback' => array( |
| 302 | $this->ratingObj, 'course_rating' |
| 303 | ), |
| 304 | 'args' => array( |
| 305 | 'id' => array( |
| 306 | 'validate_callback' => function ($param) { |
| 307 | return is_numeric($param); |
| 308 | } |
| 309 | ) |
| 310 | ), |
| 311 | 'permission_callback' => '__return_true' |
| 312 | ) |
| 313 | ); |
| 314 | } |
| 315 | } |
| 316 |