Changeset 1538047
- Timestamp:
- 11/22/2016 03:48:12 AM (9 years ago)
- Location:
- dojo/trunk
- Files:
-
- 7 edited
-
dojo.php (modified) (1 diff)
-
extensions/class-dojo-extension-manager.php (modified) (5 diffs)
-
extensions/dojo-membership/class-dojo-membership.php (modified) (5 diffs)
-
extensions/dojo-membership/views/students-edit.php (modified) (1 diff)
-
extensions/dojo-membership/views/user-enroll.php (modified) (1 diff)
-
extensions/views/manage-extensions.php (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dojo/trunk/dojo.php
r1526448 r1538047 7 7 Text Domain: dojo 8 8 License: GPLv2 or later 9 Version: 0.2 19 Version: 0.22 10 10 */ 11 11 -
dojo/trunk/extensions/class-dojo-extension-manager.php
r1526323 r1538047 17 17 $this->register_action_handlers( array ( 18 18 array( 'plugins_loaded', 1, 0 ), 19 array( 'upgrader_process_complete', 10, 2 ),19 // array( 'upgrader_process_complete', 10, 2 ), 20 20 ) ); 21 21 … … 252 252 } 253 253 254 public function ajax_install_extension_cred() { 255 if ( ! current_user_can( 'update_plugins' ) ) { 256 return 'Access denied'; 257 } 258 259 if ( ! class_exists( 'WP_Upgrader' ) ) { 260 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 261 } 262 263 $extension = $_GET['dojo-install']; 264 265 $result = $this->install_extension( $extension ); 266 if ( 'process_success' == $result ) { 267 wp_redirect( admin_url( 'admin.php?page=dojo-settings' ) ); 268 return; 269 } 270 return $result; 271 } 272 254 273 public function ajax_activate_extension() { 255 274 if ( ! current_user_can( 'activate_plugins' ) ) { … … 274 293 if ( ! current_user_can( 'update_plugins' ) ) { 275 294 return 'Access denied'; 276 }277 278 if ( ! class_exists( 'WP_Upgrader' ) ) {279 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';280 295 } 281 296 … … 338 353 339 354 private function remove_folder( $path ) { 340 $files = array_diff( scandir( $path ), array( '.', '..' ) ); 341 foreach ( $files as $file ) { 342 ( is_dir( "$path/$file" ) ) ? $this->remove_folder( "$path/$file" ) : unlink( "$path/$file" ); 343 } 344 return rmdir( $path ); 355 if ( file_exists( $path ) ) { 356 $files = array_diff( scandir( $path ), array( '.', '..' ) ); 357 foreach ( $files as $file ) { 358 ( is_dir( "$path/$file" ) ) ? $this->remove_folder( "$path/$file" ) : unlink( "$path/$file" ); 359 } 360 return rmdir( $path ); 361 } 345 362 } 346 363 347 364 private function install_extension( $extension ) { 365 if ( ! class_exists( 'WP_Upgrader' ) ) { 366 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 367 } 368 348 369 $response = $this->call_dojosource( 'get_extension', array( 349 370 'extension' => $extension, … … 357 378 $destination = Dojo_Loader::plugin_path() . '/dojo-' . $extension; 358 379 $this->remove_folder( $destination ); 380 381 382 // capture credential form output if necessary 383 $form = ''; 384 $url = $this->ajax( 'install_extension_cred' ) . '&dojo-install=' . urlencode( $extension ); 385 ob_start(); 386 // set up credentials to access the file system 387 if ( false === ( $creds = request_filesystem_credentials( $url, '', false, false, array() ) ) ) { 388 // no credentials to be found, a credential form has been generated 389 $form = ob_get_clean(); 390 } elseif ( ! WP_Filesystem( $creds ) ) { 391 // credentials did not check out, generate the form with errors 392 request_filesystem_credentials( $url, '', true, false, array() ); 393 $form = ob_get_clean(); 394 } else { 395 ob_get_clean(); 396 } 397 398 // if we need to prompt the user with a credential form for file access 399 if ( '' != $form ) { 400 401 // append script to prevent form from submitting the outer settings form 402 $form .= " 403 <script> 404 jQuery(function($) { 405 $('.request-filesystem-credentials-action-buttons .button').click(function(ev) { 406 ev.preventDefault(); 407 $(this).closest('form').submit(); 408 }); 409 }); 410 </script>"; 411 return $form; 412 } 359 413 360 414 // use built-in upgrader -
dojo/trunk/extensions/dojo-membership/class-dojo-membership.php
r1526323 r1538047 405 405 } 406 406 407 public function ajax_change_student_contract( $is_logged_in ) { 408 $this->require_admin(); 409 410 if ( isset( $_POST['student'] ) && isset( $_POST['contract'] ) ) { 411 // get student 412 $student = $this->model()->get_student( $_POST['student'] ); 413 if ( null == $student ) { 414 return 'Student not found'; 415 } 416 417 // get current membership for given student 418 $membership = $this->model()->get_student_membership( $_POST['student'] ); 419 if ( null === $membership ) { 420 return 'Student does not have an active membership'; 421 } 422 423 // validate contract we are switching to 424 $contract = $this->model()->get_contract( $_POST['contract'] ); 425 if ( ! $this->is_valid_student_contract( $student, $membership, $contract ) ) { 426 return 'Invalid contract for this student'; 427 } 428 429 // good to go, update the membership 430 $this->model()->update_membership( $membership->ID, array( 431 'contract_id' => $_POST['contract'], 432 ) ); 433 return 'success'; 434 } 435 436 return 'Invalid request'; 437 } 438 407 439 public function ajax_save_student( $is_logged_in ) { 408 440 if ( ! $is_logged_in ) { … … 1093 1125 $this->selected_student->contract = $this->model()->get_contract( $this->selected_student->contract_id ); 1094 1126 $this->rank_types = $this->model()->get_rank_types(); 1127 $this->contracts = $this->get_contracts(); 1095 1128 foreach ( $this->rank_types as $index => $rank_type ) { 1096 1129 $ranks = $this->model()->get_ranks( $rank_type->ID ); … … 1495 1528 1496 1529 /** 1530 * Verify contract is active and student meets contract requirements. 1531 * Also checks programs available from contract and if no programs exist with compatible age 1532 * requirements then will consider the contract invalid for the student. 1533 * 1534 * @param $student Student record 1535 * @param $current_membership record 1536 * @param $contract record 1537 * 1538 * @return bool 1539 */ 1540 public function is_valid_student_contract( $student, $current_membership, $contract ) { 1541 if ( null === $contract ) { 1542 return false; 1543 } 1544 1545 if ( $current_membership->contract_id === $contract->ID ) { 1546 return true; 1547 } 1548 1549 // make sure contract is active 1550 if ( ! $contract->is_active ) { 1551 return false; 1552 } 1553 1554 // check contract membership restrictions 1555 if ( $this->is_status_past_submitted( $current_membership->status ) && $contract->new_memberships_only ) { 1556 return false; 1557 } 1558 if ( ! $this->is_status_past_submitted( $current_membership->status ) && $contract->continuing_memberships_only ) { 1559 return false; 1560 } 1561 1562 // get contract programs 1563 $programs = $this->model()->get_contract_programs( $contract->ID ); 1564 1565 // check age limits of programs to see if student qualifies for at least one 1566 $age = $this->dob_to_age( $student->dob ); 1567 $does_qualify = false; 1568 foreach ( $programs as $program ) { 1569 if ( null !== $program->min_age && 0 !== $program->min_age ) { 1570 if ( $age < $program->min_age ) { 1571 continue; 1572 } 1573 } 1574 if ( null != $program->max_age && 0 != $program->max_age ) { 1575 if ( $age > $program->max_age ) { 1576 continue; 1577 } 1578 } 1579 $does_qualify = true; 1580 break; 1581 } 1582 if ( ! $does_qualify ) { 1583 return false; 1584 } 1585 1586 return true; 1587 } 1588 1589 /** 1497 1590 * Check if given status is active in the sense that the student may continue to participate 1498 1591 * … … 1536 1629 self::MEMBERSHIP_PENDING != $status && 1537 1630 self::MEMBERSHIP_ENDED != $status 1631 ; 1632 } 1633 1634 /** 1635 * Check if status is past a submitted state, includes ended. 1636 * 1637 * @param $status 1638 * @return bool 1639 */ 1640 public function is_status_past_submitted( $status ) { 1641 return 1642 self::MEMBERSHIP_NA != $status && 1643 self::MEMBERSHIP_PENDING != $status && 1644 self::MEMBERSHIP_SUBMITTED != $status 1538 1645 ; 1539 1646 } … … 1752 1859 } 1753 1860 1861 /** 1862 * Convert date of birth to age 1863 * 1864 * @param string $dob 1865 * @return int 1866 */ 1867 public function dob_to_age( $dob ) { 1868 $dob = strtotime( $dob ); 1869 $dob_month = (int) $this->date( 'n', $dob ); 1870 $dob_day = (int) $this->date( 'j', $dob ); 1871 $dob_year = (int) $this->date( 'Y', $dob ); 1872 1873 $time = time(); 1874 $month = (int) $this->date( 'n', $time ); 1875 $day = (int) $this->date( 'j', $time ); 1876 $year = (int) $this->date( 'Y', $time ); 1877 1878 $age = $year - $dob_year; 1879 if ( $month < $dob_month || ( $month == $dob_month && $day < $dob_day) ) { 1880 $age --; 1881 } 1882 1883 return $age; 1884 } 1885 1754 1886 public function get_charge_date( $day ) 1755 1887 { -
dojo/trunk/extensions/dojo-membership/views/students-edit.php
r1526323 r1538047 24 24 <?php echo apply_filters( 'dojo_membership_admin_student_application', $this->render( 'admin-student-application' ), $student ) ?> 25 25 </div> 26 <?php elseif ( Dojo_Membership::MEMBERSHIP_DUE == $student->status || Dojo_Membership::MEMBERSHIP_CANCELED_DUE == $student->status) : ?>26 <?php elseif ( $this->is_status_active( $student->status ) ) : ?> 27 27 <div class="dojo-block"> 28 <h2>Membership Alert</h2> 29 <p>Membership: <strong><?php echo esc_html( $student->contract->title ) ?></strong></p> 30 <?php echo apply_filters( 'dojo_membership_admin_student_due', $this->render( 'admin-student-due' ), $student ) ?> 28 <?php echo apply_filters( 'dojo_membership_admin_student_contract', $this->render( 'admin-student-contract' ), $student ) ?> 31 29 </div> 32 30 <?php endif; ?> -
dojo/trunk/extensions/dojo-membership/views/user-enroll.php
r1526323 r1538047 37 37 <option value="">Please Select</option> 38 38 <?php foreach ( $contracts as $contract ) : ?> 39 <option value="<?php echo esc_attr( $contract->ID ) ?>" <?php selected( $student->membership->contract_id, $contract->ID ) ?>><?php echo esc_html( $contract->title ) ?></option> 39 <?php if ( ! $this->is_valid_student_contract( $student, $student->membership, $contract ) ) { continue; } ?> 40 <option value="<?php echo esc_attr( $contract->ID ) ?>" <?php selected( $student->membership->contract_id, $contract->ID ) ?>><?php echo esc_html( $contract->title ) ?></option> 40 41 <?php endforeach; ?> 41 42 </select> -
dojo/trunk/extensions/views/manage-extensions.php
r1526443 r1538047 30 30 } 31 31 32 32 $install_extension = ''; 33 if ( isset( $_GET['dojo-install'] ) ) { 34 $install_extension = $_GET['dojo-install']; 35 } 33 36 34 37 ?> … … 46 49 47 50 <?php foreach ( $installed_extensions as $extension_id => $extension ) : ?> 48 <div class="dojo-extension-block " data-extension="<?php echo esc_attr( $extension_id ) ?>">51 <div class="dojo-extension-block<?php echo $install_extension == $extension_id ? ' .dojo-do-update' : '' ?>" data-extension="<?php echo esc_attr( $extension_id ) ?>"> 49 52 <div class="dojo-large-icon dojo-left"> 50 53 <?php if ( isset( $info['icons'][ $extension_id ] ) ) : ?> … … 118 121 119 122 <?php foreach ( $available_extensions as $extension_id => $extension_title ) : ?> 120 <div class="dojo-extension-block " data-extension="<?php echo esc_attr( $extension_id ) ?>">123 <div class="dojo-extension-block<?php echo $install_extension == $extension_id ? ' dojo-do-install' : '' ?>" data-extension="<?php echo esc_attr( $extension_id ) ?>"> 121 124 <div class="dojo-large-icon dojo-left"> 122 125 <span class="dashicons dashicons-<?php echo $info['icons'][ $extension_id ] ?>"></span> … … 189 192 } 190 193 }); 194 195 $('.dojo-do-install .dojo-install').click(); 196 $('.dojo-do-update .dojo-update').click(); 191 197 }); 192 198 </script> 199 -
dojo/trunk/readme.txt
r1527102 r1538047 5 5 Requires at least: 4.0 6 6 Tested up to: 4.6.1 7 Stable tag: 0.2 17 Stable tag: 0.22 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 72 72 = Why am I not seeing the member page at /members? = 73 73 74 Make sure your permalinks settings at Settings -> Permalinks are notset to, "Plain".74 Make sure your permalinks settings at Settings -> Permalinks are **NOT** set to, "Plain". 75 75 76 76 = How do I get the free Invoices add-on from Dojo Source? = … … 90 90 == Changelog == 91 91 92 = 0.22 = 93 * Added option to change existing contract for a student. 94 * No longer displaying contract options for students that are not applicable to that student. 95 * Fixed issues with downloading add-ons. 96 92 97 = 0.21 = 93 * Fixed issue with nonces messing up add-on loading98 * Fixed special cases where nonces in ajax calls were causing it to break. 94 99 95 100 = 0.20 =
Note: See TracChangeset
for help on using the changeset viewer.