Addons.php
11 months ago
Admin.php
2 months ago
Ajax.php
9 months ago
Announcements.php
1 year ago
Assets.php
2 months ago
Backend_Page_Trait.php
1 year ago
BaseController.php
1 year ago
Config.php
11 months ago
Container.php
11 months ago
Course.php
2 months ago
Course_Embed.php
3 years ago
Course_Filter.php
1 year ago
Course_List.php
5 months ago
Course_Settings_Tabs.php
1 year ago
Course_Widget.php
1 year ago
Custom_Validation.php
3 years ago
Dashboard.php
1 year ago
Earnings.php
9 months ago
FormHandler.php
2 years ago
Frontend.php
1 year ago
Gutenberg.php
1 year ago
Icon.php
8 months ago
Input.php
1 year ago
Instructor.php
2 months ago
Instructors_List.php
2 months ago
Lesson.php
2 weeks ago
Options_V2.php
7 months ago
Permalink.php
2 years ago
Post_types.php
1 year ago
Private_Course_Access.php
1 year ago
Q_And_A.php
10 months ago
Question_Answers_List.php
11 months ago
Quiz.php
2 weeks ago
QuizBuilder.php
2 weeks ago
Quiz_Attempts_List.php
9 months ago
RestAPI.php
2 years ago
Reviews.php
9 months ago
Rewrite_Rules.php
2 years ago
Shortcode.php
9 months ago
Singleton.php
1 year ago
Student.php
2 months ago
Students_List.php
1 year ago
Taxonomies.php
1 year ago
Template.php
9 months ago
Theme_Compatibility.php
3 years ago
Tools.php
1 year ago
Tools_V2.php
3 weeks ago
Tutor.php
2 months ago
TutorEDD.php
1 year ago
Tutor_Base.php
2 years ago
Tutor_Setup.php
8 months ago
Upgrader.php
9 months ago
User.php
4 months ago
Utils.php
3 weeks ago
Video_Stream.php
3 years ago
WhatsNew.php
9 months ago
Withdraw.php
1 year ago
Withdraw_Requests_List.php
11 months ago
WooCommerce.php
7 months ago
WhatsNew.php
199 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Whats new page handler |
| 4 | * |
| 5 | * @package Tutor\User |
| 6 | * @author Themeum <support@themeum.com> |
| 7 | * @link https://themeum.com |
| 8 | * @since 2.3.0 |
| 9 | */ |
| 10 | |
| 11 | namespace TUTOR; |
| 12 | |
| 13 | /** |
| 14 | * Class WhatsNew |
| 15 | */ |
| 16 | class WhatsNew { |
| 17 | |
| 18 | /** |
| 19 | * Constructor |
| 20 | * |
| 21 | * @since 3.8.0 |
| 22 | * |
| 23 | * @return void |
| 24 | */ |
| 25 | public function __construct() { |
| 26 | add_filter( 'tutor_admin_menu', array( $this, 'add_whats_new_menu_item' ) ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * What's new menu item |
| 31 | * |
| 32 | * @since 3.8.0 |
| 33 | * |
| 34 | * @param array $menu menu. |
| 35 | * |
| 36 | * @return array |
| 37 | */ |
| 38 | public function add_whats_new_menu_item( $menu ) { |
| 39 | $update_required = $this->get_plugin_version_info()[2]; |
| 40 | |
| 41 | $menu_text = __( "What's New", 'tutor' ); |
| 42 | if ( $update_required ) { |
| 43 | $menu_text .= ' <span class="update-plugins"><span class="plugin-count">1</span></span>'; |
| 44 | } |
| 45 | |
| 46 | $menu['group_three']['whats_new'] = array( |
| 47 | 'parent_slug' => 'tutor', |
| 48 | 'page_title' => __( "What's New", 'tutor' ), |
| 49 | 'menu_title' => $menu_text, |
| 50 | 'capability' => 'manage_options', |
| 51 | 'menu_slug' => 'tutor-whats-new', |
| 52 | 'callback' => array( $this, 'whats_new_page' ), |
| 53 | ); |
| 54 | |
| 55 | return $menu; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * What's new page. |
| 60 | * |
| 61 | * @since 2.2.4 |
| 62 | * |
| 63 | * @return void |
| 64 | */ |
| 65 | public function whats_new_page() { |
| 66 | list( $remote_version, $installed_version, $update_required ) = $this->get_plugin_version_info(); |
| 67 | $changelogs = self::build_changelog_array(); |
| 68 | |
| 69 | include tutor()->path . 'views/pages/whats-new.php'; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get tutor plugin version info |
| 74 | * |
| 75 | * @since 3.8.0 |
| 76 | * |
| 77 | * @return array |
| 78 | */ |
| 79 | private function get_plugin_version_info() { |
| 80 | $transient_key = 'tutor_plugin_info'; |
| 81 | $plugin_info = get_transient( $transient_key ); |
| 82 | |
| 83 | if ( false === $plugin_info ) { |
| 84 | $plugin_info = tutils()->get_remote_plugin_info(); |
| 85 | set_transient( $transient_key, $plugin_info, HOUR_IN_SECONDS ); |
| 86 | } |
| 87 | |
| 88 | $remote_version = $plugin_info->version ?? TUTOR_VERSION; |
| 89 | $installed_version = TUTOR_VERSION; |
| 90 | $update_required = version_compare( $remote_version, $installed_version, '>' ); |
| 91 | |
| 92 | return array( $remote_version, $installed_version, $update_required ); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Whats new item. |
| 97 | * |
| 98 | * @param string $type type of item. |
| 99 | * @param array $log changelog item. |
| 100 | * |
| 101 | * @return void |
| 102 | */ |
| 103 | public static function render_item( $type, $log ) { |
| 104 | $obj = (object) $log; |
| 105 | ?> |
| 106 | <li class="tutor-fs-7"><strong><?php echo esc_html( $type ); ?>:</strong> <span><?php echo esc_html( $obj->title ); ?></span> |
| 107 | <?php |
| 108 | if ( isset( $obj->is_pro ) && $obj->is_pro ) : |
| 109 | ?> |
| 110 | <span class="tutor-pro-badge">Pro</span> <?php endif; ?></li> |
| 111 | <?php |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Build changelog array for whats new page. |
| 116 | * |
| 117 | * @return array |
| 118 | */ |
| 119 | private static function build_changelog_array() { |
| 120 | $pro_regex = '/\((Pro|pro)\)\s*|\-\s*Pro|\-\s*pro$/'; |
| 121 | $new_regex = '/^New:\s?/'; |
| 122 | $update_regex = '/^Update:\s?/'; |
| 123 | $fix_regex = '/^Fix:\s?/'; |
| 124 | |
| 125 | $lines = self::get_latest_changelog(); |
| 126 | $changelogs = array(); |
| 127 | |
| 128 | foreach ( $lines as $line ) { |
| 129 | $line = trim( $line ); |
| 130 | $log = array(); |
| 131 | |
| 132 | if ( preg_match( $new_regex, $line ) ) { |
| 133 | $line = preg_replace( $new_regex, '', $line ); |
| 134 | if ( preg_match( $pro_regex, $line ) ) { |
| 135 | $line = preg_replace( $pro_regex, '', $line ); |
| 136 | $log['is_pro'] = true; |
| 137 | } |
| 138 | |
| 139 | $log['title'] = $line; |
| 140 | $changelogs['new'][] = $log; |
| 141 | } |
| 142 | |
| 143 | if ( preg_match( $update_regex, $line ) ) { |
| 144 | $line = preg_replace( $update_regex, '', $line ); |
| 145 | if ( preg_match( $pro_regex, $line ) ) { |
| 146 | $line = preg_replace( $pro_regex, '', $line ); |
| 147 | $log['is_pro'] = true; |
| 148 | } |
| 149 | |
| 150 | $log['title'] = $line; |
| 151 | $changelogs['update'][] = $log; |
| 152 | } |
| 153 | |
| 154 | if ( preg_match( $fix_regex, $line ) ) { |
| 155 | $line = preg_replace( $fix_regex, '', $line ); |
| 156 | if ( preg_match( $pro_regex, $line ) ) { |
| 157 | $line = preg_replace( $pro_regex, '', $line ); |
| 158 | $log['is_pro'] = true; |
| 159 | } |
| 160 | |
| 161 | $log['title'] = $line; |
| 162 | $changelogs['fix'][] = $log; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return $changelogs; |
| 167 | } |
| 168 | /** |
| 169 | * Get latest changelog from readme.txt file. |
| 170 | * |
| 171 | * @return array |
| 172 | */ |
| 173 | public static function get_latest_changelog() { |
| 174 | $lines = array(); |
| 175 | $readme_content = file_get_contents( __DIR__ . '/../readme.txt' ); |
| 176 | $changelog_pattern = '/== Changelog ==\s*(.*?)==/s'; |
| 177 | |
| 178 | // Perform the regex match to extract the changelog section. |
| 179 | if ( preg_match( $changelog_pattern, $readme_content, $matches ) ) { |
| 180 | $changelog_section = trim( $matches[1] ); |
| 181 | |
| 182 | // Split the changelog section into individual entries. |
| 183 | $changelog_entries = explode( '= ', $changelog_section ); |
| 184 | |
| 185 | // Get the latest changelog entry. |
| 186 | if ( ! empty( $changelog_entries[1] ) ) { |
| 187 | $latest_changelog = $changelog_entries[1]; |
| 188 | $latest_changelog = preg_replace( '/(^\d+\.\d+\.\d+).*\s+/', ' ', $latest_changelog ); |
| 189 | $latest_changelog = trim( $latest_changelog ); |
| 190 | |
| 191 | $lines = explode( "\n", $latest_changelog ); |
| 192 | $lines = array_map( 'trim', $lines ); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return $lines; |
| 197 | } |
| 198 | } |
| 199 |