Admin
2 weeks ago
Ajax
2 weeks ago
Asset
2 weeks ago
Context
2 weeks ago
Customizer
2 weeks ago
Debug_Bar
2 weeks ago
Dialog
2 weeks ago
Documentation
2 weeks ago
Duplicate
2 weeks ago
Editor
2 weeks ago
Image
2 weeks ago
JSON_LD
2 weeks ago
Languages
2 weeks ago
Log
2 weeks ago
Meta
2 weeks ago
Models
2 weeks ago
PUE
2 weeks ago
Process
2 weeks ago
Promoter
2 weeks ago
REST
2 weeks ago
Repository
2 weeks ago
Service_Providers
2 weeks ago
Shortcode
2 weeks ago
Support
2 weeks ago
Tabbed_View
2 weeks ago
Tooltip
2 weeks ago
Traits
2 weeks ago
Utils
2 weeks ago
Validator
2 weeks ago
Widget
2 weeks ago
Abstract_Deactivation.php
2 weeks ago
Abstract_Plugin_Register.php
2 weeks ago
App_Shop.php
2 weeks ago
Assets.php
2 weeks ago
Assets_Pipeline.php
2 weeks ago
Autoloader.php
2 weeks ago
Cache.php
2 weeks ago
Cache_Listener.php
2 weeks ago
Changelog_Reader.php
2 weeks ago
Container.php
2 weeks ago
Context.php
2 weeks ago
Cost_Utils.php
2 weeks ago
Credits.php
2 weeks ago
Customizer.php
2 weeks ago
DB_Lock.php
2 weeks ago
Data.php
2 weeks ago
Date_Utils.php
2 weeks ago
Db.php
2 weeks ago
Debug.php
2 weeks ago
Dependency.php
2 weeks ago
Deprecation.php
2 weeks ago
Editor.php
2 weeks ago
Error.php
2 weeks ago
Exception.php
2 weeks ago
Extension.php
2 weeks ago
Extension_Loader.php
2 weeks ago
Feature_Detection.php
2 weeks ago
Field.php
2 weeks ago
Field_Conditional.php
2 weeks ago
Freemius.php
2 weeks ago
Log.php
2 weeks ago
Main.php
2 weeks ago
Notices.php
2 weeks ago
Plugin_Meta_Links.php
2 weeks ago
Plugins.php
2 weeks ago
Plugins_API.php
2 weeks ago
Post_History.php
2 weeks ago
Post_Transient.php
2 weeks ago
Promise.php
2 weeks ago
Repository.php
2 weeks ago
Rewrite.php
2 weeks ago
Settings.php
2 weeks ago
Settings_Manager.php
2 weeks ago
Settings_Tab.php
2 weeks ago
Simple_Table.php
2 weeks ago
Support.php
2 weeks ago
Tabbed_View.php
2 weeks ago
Template.php
2 weeks ago
Template_Factory.php
2 weeks ago
Template_Part_Cache.php
2 weeks ago
Templates.php
2 weeks ago
Terms.php
2 weeks ago
Timezones.php
2 weeks ago
Tracker.php
2 weeks ago
Updater.php
2 weeks ago
Validate.php
2 weeks ago
View_Helpers.php
2 weeks ago
Changelog_Reader.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | class Tribe__Changelog_Reader { |
| 4 | protected $version_count = 3; |
| 5 | protected $readme_file = ''; |
| 6 | |
| 7 | public function __construct( $version_count = 3, $readme_file = '' ) { |
| 8 | $this->version_count = (int) $version_count; |
| 9 | $this->readme_file = empty( $readme_file ) ? $this->default_readme_file() : $readme_file; |
| 10 | } |
| 11 | |
| 12 | protected function default_readme_file() { |
| 13 | return dirname( Tribe__Main::instance()->plugin_path ) . '/readme.txt'; |
| 14 | } |
| 15 | |
| 16 | public function get_changelog() { |
| 17 | $contents = $this->extract_changelog_section(); |
| 18 | $lines = explode( "\n", $contents ); |
| 19 | |
| 20 | $sections = []; |
| 21 | $current_section = ''; |
| 22 | foreach ( $lines as $line ) { |
| 23 | $line = trim( $line ); |
| 24 | if ( substr( $line, 0, 1 ) == '=' ) { |
| 25 | if ( count( $sections ) >= $this->version_count ) { |
| 26 | break; |
| 27 | } |
| 28 | $header = trim( $line, '= ' ); |
| 29 | $current_section = esc_html( $header ); |
| 30 | $sections[ $current_section ] = []; |
| 31 | } elseif ( strlen( $line ) > 0 ) { |
| 32 | $message = trim( $line, '* ' ); |
| 33 | $sections[ $current_section ][] = esc_html( $message ); |
| 34 | } |
| 35 | } |
| 36 | return $sections; |
| 37 | } |
| 38 | |
| 39 | protected function extract_changelog_section() { |
| 40 | $contents = $this->get_readme_file_contents(); |
| 41 | $start = strpos( $contents, '== Changelog ==' ); |
| 42 | if ( $start === false ) { |
| 43 | return ''; |
| 44 | } |
| 45 | $start += 16; // account for the length of the header |
| 46 | $end = strpos( $contents, '==', $start ); |
| 47 | return trim( substr( $contents, $start, $end - $start ) ); |
| 48 | } |
| 49 | |
| 50 | protected function get_readme_file_contents() { |
| 51 | return file_get_contents( $this->readme_file ); |
| 52 | } |
| 53 | } |
| 54 |